From 1668f4b4cf59d409fecf0d6e6948f0bd3547a6f8 Mon Sep 17 00:00:00 2001 From: Latif Khalifa Date: Sat, 29 Aug 2009 15:15:04 +0000 Subject: [PATCH] * Fixed up friends console * Added online/offline notifications in chat * Added possibility to remove a person from friends list git-svn-id: https://radegast.googlecode.com/svn/trunk@176 f7a694da-4d33-11de-9ad6-1127a62b9fcd --- Radegast/GUI/Consoles/FriendsConsole.Designer.cs | 34 +++++++--- Radegast/GUI/Consoles/FriendsConsole.cs | 86 ++++++++++++++++++++---- 2 files changed, 96 insertions(+), 24 deletions(-) diff --git a/Radegast/GUI/Consoles/FriendsConsole.Designer.cs b/Radegast/GUI/Consoles/FriendsConsole.Designer.cs index e7c23c6..a1def48 100644 --- a/Radegast/GUI/Consoles/FriendsConsole.Designer.cs +++ b/Radegast/GUI/Consoles/FriendsConsole.Designer.cs @@ -64,13 +64,14 @@ namespace Radegast this.btnIM = new System.Windows.Forms.Button(); this.btnProfile = new System.Windows.Forms.Button(); this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.btnPay = new System.Windows.Forms.Button(); this.btnOfferTeleport = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.chkSeeMeOnline = new System.Windows.Forms.CheckBox(); this.chkSeeMeOnMap = new System.Windows.Forms.CheckBox(); this.chkModifyMyObjects = new System.Windows.Forms.CheckBox(); this.timInitDelay = new System.Windows.Forms.Timer(this.components); - this.btnPay = new System.Windows.Forms.Button(); + this.btnRemove = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); // @@ -125,6 +126,7 @@ namespace Radegast // this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.btnRemove); this.groupBox1.Controls.Add(this.btnPay); this.groupBox1.Controls.Add(this.btnOfferTeleport); this.groupBox1.Controls.Add(this.lblFriendName); @@ -136,6 +138,17 @@ namespace Radegast this.groupBox1.TabIndex = 4; this.groupBox1.TabStop = false; // + // btnPay + // + this.btnPay.Enabled = false; + this.btnPay.Location = new System.Drawing.Point(286, 46); + this.btnPay.Name = "btnPay"; + this.btnPay.Size = new System.Drawing.Size(75, 23); + this.btnPay.TabIndex = 5; + this.btnPay.Text = "Pay..."; + this.btnPay.UseVisualStyleBackColor = true; + this.btnPay.Click += new System.EventHandler(this.btnPay_Click); + // // btnOfferTeleport // this.btnOfferTeleport.Enabled = false; @@ -198,16 +211,16 @@ namespace Radegast this.timInitDelay.Interval = 3000; this.timInitDelay.Tick += new System.EventHandler(this.timInitDelay_Tick); // - // btnPay + // btnRemove // - this.btnPay.Enabled = false; - this.btnPay.Location = new System.Drawing.Point(286, 46); - this.btnPay.Name = "btnPay"; - this.btnPay.Size = new System.Drawing.Size(75, 23); - this.btnPay.TabIndex = 5; - this.btnPay.Text = "Pay..."; - this.btnPay.UseVisualStyleBackColor = true; - this.btnPay.Click += new System.EventHandler(this.btnPay_Click); + this.btnRemove.Enabled = false; + this.btnRemove.Location = new System.Drawing.Point(367, 46); + this.btnRemove.Name = "btnRemove"; + this.btnRemove.Size = new System.Drawing.Size(75, 23); + this.btnRemove.TabIndex = 6; + this.btnRemove.Text = "Remove"; + this.btnRemove.UseVisualStyleBackColor = true; + this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click); // // FriendsConsole // @@ -241,5 +254,6 @@ namespace Radegast private System.Windows.Forms.Button btnOfferTeleport; private System.Windows.Forms.Timer timInitDelay; private System.Windows.Forms.Button btnPay; + private System.Windows.Forms.Button btnRemove; } } diff --git a/Radegast/GUI/Consoles/FriendsConsole.cs b/Radegast/GUI/Consoles/FriendsConsole.cs index 4296029..0ff1d87 100644 --- a/Radegast/GUI/Consoles/FriendsConsole.cs +++ b/Radegast/GUI/Consoles/FriendsConsole.cs @@ -32,6 +32,7 @@ using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; +using System.Threading; using OpenMetaverse; namespace Radegast @@ -54,6 +55,7 @@ namespace Radegast // Callbacks client.Friends.OnFriendOffline += new FriendsManager.FriendOfflineEvent(Friends_OnFriendOffline); client.Friends.OnFriendOnline += new FriendsManager.FriendOnlineEvent(Friends_OnFriendOnline); + client.Friends.OnFriendshipTerminated += new FriendsManager.FriendshipTerminatedEvent(Friends_OnFriendshipTerminated); } @@ -61,6 +63,7 @@ namespace Radegast { client.Friends.OnFriendOffline -= new FriendsManager.FriendOfflineEvent(Friends_OnFriendOffline); client.Friends.OnFriendOnline -= new FriendsManager.FriendOnlineEvent(Friends_OnFriendOnline); + client.Friends.OnFriendshipTerminated -= new FriendsManager.FriendshipTerminatedEvent(Friends_OnFriendshipTerminated); } private void InitializeFriendsList() @@ -68,7 +71,7 @@ namespace Radegast List friends = client.Friends.FriendList.FindAll(delegate(FriendInfo f) { return true; }); lbxFriends.BeginUpdate(); - + lbxFriends.Items.Clear(); foreach (FriendInfo friend in friends) lbxFriends.Items.Add(new FriendsListItem(friend)); @@ -77,20 +80,68 @@ namespace Radegast private void RefreshFriendsList() { - lbxFriends.Refresh(); + InitializeFriendsList(); SetFriend(selectedFriend); } - //Separate thread private void Friends_OnFriendOffline(FriendInfo friend) { - BeginInvoke(new MethodInvoker(RefreshFriendsList)); + if (InvokeRequired) + { + BeginInvoke(new MethodInvoker(() => Friends_OnFriendOffline(friend))); + return; + } + + instance.MainForm.TabConsole.DisplayNotificationInChat(friend.Name + " is offline"); + RefreshFriendsList(); } - //Separate thread private void Friends_OnFriendOnline(FriendInfo friend) { - BeginInvoke(new MethodInvoker(RefreshFriendsList)); + if (InvokeRequired) + { + BeginInvoke(new MethodInvoker(() => Friends_OnFriendOnline(friend))); + return; + } + + instance.MainForm.TabConsole.DisplayNotificationInChat(friend.Name + " is online"); + RefreshFriendsList(); + } + + void Friends_OnFriendshipTerminated(UUID agentID, string agentName) + { + if (agentName == string.Empty) + { + using (ManualResetEvent done = new ManualResetEvent(false)) + { + + AvatarManager.AvatarNamesCallback callback = delegate(Dictionary names) + { + if (names.ContainsKey(agentID)) + { + agentName = names[agentID]; + done.Set(); + } + }; + + client.Avatars.OnAvatarNames += callback; + agentName = instance.getAvatarName(agentID); + if (agentName == RadegastInstance.INCOMPLETE_NAME) + { + done.WaitOne(3000, false); + } + client.Avatars.OnAvatarNames -= callback; + } + } + + if (InvokeRequired) + { + BeginInvoke(new MethodInvoker(() => Friends_OnFriendshipTerminated(agentID, agentName))); + return; + } + + instance.MainForm.TabConsole.DisplayNotificationInChat(agentName + " is no longer on your friend list"); + RefreshFriendsList(); } private void SetFriend(FriendInfo friend) @@ -100,7 +151,7 @@ namespace Radegast lblFriendName.Text = friend.Name + (friend.IsOnline ? " (online)" : " (offline)"); - btnIM.Enabled = btnProfile.Enabled = btnOfferTeleport.Enabled = btnPay.Enabled = true; + btnIM.Enabled = btnProfile.Enabled = btnOfferTeleport.Enabled = btnPay.Enabled = btnRemove.Enabled = true; chkSeeMeOnline.Enabled = chkSeeMeOnMap.Enabled = chkModifyMyObjects.Enabled = true; chkSeeMeOnMap.Enabled = friend.CanSeeMeOnline; @@ -120,7 +171,7 @@ namespace Radegast FriendsListItem itemToDraw = (FriendsListItem)lbxFriends.Items[e.Index]; Brush textBrush = null; Font textFont = null; - + if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { textBrush = new SolidBrush(Color.FromKnownColor(KnownColor.HighlightText)); @@ -140,7 +191,7 @@ namespace Radegast e.Graphics.DrawImage(Properties.Resources.GreenOrb_16, e.Bounds.Left + 2, e.Bounds.Top + 2); else e.Graphics.DrawImage(Properties.Resources.GreenOrbFaded_16, e.Bounds.Left + 2, e.Bounds.Top + 2); - + e.Graphics.DrawString(itemToDraw.Friend.Name, textFont, textBrush, stringX, stringY); e.DrawFocusRectangle(); @@ -180,9 +231,7 @@ namespace Radegast if (settingFriend) return; selectedFriend.CanSeeMeOnline = chkSeeMeOnline.Checked; - client.Friends.GrantRights(selectedFriend.UUID, FriendRights.CanSeeOnline); - - chkSeeMeOnMap.Enabled = chkSeeMeOnline.Checked; + client.Friends.GrantRights(selectedFriend.UUID, selectedFriend.TheirFriendRights); } private void chkSeeMeOnMap_CheckedChanged(object sender, EventArgs e) @@ -190,7 +239,7 @@ namespace Radegast if (settingFriend) return; selectedFriend.CanSeeMeOnMap = chkSeeMeOnMap.Checked; - // client.Friends.GrantRights(selectedFriend.UUID); + client.Friends.GrantRights(selectedFriend.UUID, selectedFriend.TheirFriendRights); } private void chkModifyMyObjects_CheckedChanged(object sender, EventArgs e) @@ -198,7 +247,7 @@ namespace Radegast if (settingFriend) return; selectedFriend.CanModifyMyObjects = chkModifyMyObjects.Checked; - // client.Friends.GrantRights(selectedFriend.UUID); + client.Friends.GrantRights(selectedFriend.UUID, selectedFriend.TheirFriendRights); } private void btnOfferTeleport_Click(object sender, EventArgs e) @@ -218,5 +267,14 @@ namespace Radegast { (new frmPay(instance, selectedFriend.UUID, selectedFriend.Name, false)).ShowDialog(); } + + private void btnRemove_Click(object sender, EventArgs e) + { + client.Friends.TerminateFriendship(selectedFriend.UUID); + if (lbxFriends.Items.Count > 0) + { + lbxFriends.SelectedIndex = 0; + } + } } } -- 2.11.0