2 // Radegast Metaverse Client
3 // Copyright (c) 2009-2013, Radegast Development Team
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 // * Neither the name of the application "Radegast", nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 // $Id: FriendshipOfferNotification.cs 175 2009-08-29 13:52:32Z latifer@gmail.com $
32 using System.Collections.Generic;
33 using System.ComponentModel;
38 using System.Windows.Forms;
40 using OpenMetaverse.Assets;
41 using OpenMetaverse.Packets;
45 public partial class ntfInventoryOffer : Notification
47 private RadegastInstance instance;
48 private GridClient client { get { return instance.Client; } }
49 private InstantMessage msg;
50 private AssetType type = AssetType.Unknown;
51 private UUID objectID = UUID.Zero;
52 UUID destinationFolderID;
54 public ntfInventoryOffer(RadegastInstance instance, InstantMessage msg)
55 : base (NotificationType.InventoryOffer)
57 InitializeComponent();
58 Disposed += new EventHandler(ntfInventoryOffer_Disposed);
60 this.instance = instance;
63 instance.Names.NameUpdated += new EventHandler<UUIDNameReplyEventArgs>(Avatars_UUIDNameReply);
65 if (msg.BinaryBucket.Length > 0)
67 type = (AssetType)msg.BinaryBucket[0];
68 destinationFolderID = client.Inventory.FindFolderForType(type);
70 if (msg.BinaryBucket.Length == 17)
72 objectID = new UUID(msg.BinaryBucket, 1);
75 if (msg.Dialog == InstantMessageDialog.InventoryOffered)
77 txtInfo.Text = string.Format("{0} has offered you {1} \"{2}\".", msg.FromAgentName, type.ToString(), msg.Message);
79 else if (msg.Dialog == InstantMessageDialog.TaskInventoryOffered)
81 txtInfo.Text = objectOfferText();
85 NotificationEventArgs args = new NotificationEventArgs(instance);
86 args.Text = txtInfo.Text;
87 args.Buttons.Add(btnAccept);
88 args.Buttons.Add(btnDiscard);
89 args.Buttons.Add(btnIgnore);
90 FireNotificationCallback(args);
94 Logger.Log("Wrong format of the item offered", Helpers.LogLevel.Warning, client);
98 void ntfInventoryOffer_Disposed(object sender, EventArgs e)
100 instance.Names.NameUpdated -= new EventHandler<UUIDNameReplyEventArgs>(Avatars_UUIDNameReply);
103 void Avatars_UUIDNameReply(object sender, UUIDNameReplyEventArgs e)
105 if (e.Names.Keys.Contains(msg.FromAgentID))
107 instance.Names.NameUpdated -= new EventHandler<UUIDNameReplyEventArgs>(Avatars_UUIDNameReply);
108 BeginInvoke(new MethodInvoker(() => txtInfo.Text = objectOfferText()));
112 private string objectOfferText()
114 return string.Format("Object \"{0}\" owned by {1} has offered you {2}", msg.FromAgentName, instance.Names.Get(msg.FromAgentID), msg.Message);
117 private void SendReply(InstantMessageDialog dialog, byte[] bucket)
119 client.Self.InstantMessage(client.Self.Name, msg.FromAgentID, string.Empty, msg.IMSessionID, dialog, InstantMessageOnline.Offline, client.Self.SimPosition, client.Network.CurrentSim.RegionID, bucket);
121 if (dialog == InstantMessageDialog.InventoryAccepted)
123 client.Inventory.RequestFetchInventory(objectID, client.Self.AgentID);
127 private void btnAccept_Click(object sender, EventArgs e)
129 if (type == AssetType.Unknown) return;
131 if (msg.Dialog == InstantMessageDialog.InventoryOffered)
133 SendReply(InstantMessageDialog.InventoryAccepted, destinationFolderID.GetBytes());
135 else if (msg.Dialog == InstantMessageDialog.TaskInventoryOffered)
137 SendReply(InstantMessageDialog.TaskInventoryAccepted, destinationFolderID.GetBytes());
139 instance.MainForm.RemoveNotification(this);
142 private void btnDiscard_Click(object sender, EventArgs e)
144 if (type == AssetType.Unknown) return;
146 if (msg.Dialog == InstantMessageDialog.InventoryOffered)
148 SendReply(InstantMessageDialog.InventoryDeclined, Utils.EmptyBytes);
151 client.Inventory.Move(
152 client.Inventory.Store.Items[objectID].Data,
153 (InventoryFolder)client.Inventory.Store.Items[client.Inventory.FindFolderForType(AssetType.TrashFolder)].Data);
155 catch (Exception) { }
157 else if (msg.Dialog == InstantMessageDialog.TaskInventoryOffered)
159 SendReply(InstantMessageDialog.TaskInventoryDeclined, Utils.EmptyBytes);
161 instance.MainForm.RemoveNotification(this);
164 private void btnIgnore_Click(object sender, EventArgs e)
166 instance.MainForm.RemoveNotification(this);
169 private void txtInfo_LinkClicked(object sender, LinkClickedEventArgs e)
171 instance.MainForm.ProcessLink(e.LinkText, true);