OSDN Git Service

* Fixed up friends console
authorLatif Khalifa <latifer@streamgrid.net>
Sat, 29 Aug 2009 15:15:04 +0000 (15:15 +0000)
committerLatif Khalifa <latifer@streamgrid.net>
Sat, 29 Aug 2009 15:15:04 +0000 (15:15 +0000)
* 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
Radegast/GUI/Consoles/FriendsConsole.cs

index e7c23c6..a1def48 100644 (file)
@@ -64,13 +64,14 @@ namespace Radegast
             this.btnIM = new System.Windows.Forms.Button();\r
             this.btnProfile = new System.Windows.Forms.Button();\r
             this.groupBox1 = new System.Windows.Forms.GroupBox();\r
+            this.btnPay = new System.Windows.Forms.Button();\r
             this.btnOfferTeleport = new System.Windows.Forms.Button();\r
             this.label1 = new System.Windows.Forms.Label();\r
             this.chkSeeMeOnline = new System.Windows.Forms.CheckBox();\r
             this.chkSeeMeOnMap = new System.Windows.Forms.CheckBox();\r
             this.chkModifyMyObjects = new System.Windows.Forms.CheckBox();\r
             this.timInitDelay = new System.Windows.Forms.Timer(this.components);\r
-            this.btnPay = new System.Windows.Forms.Button();\r
+            this.btnRemove = new System.Windows.Forms.Button();\r
             this.groupBox1.SuspendLayout();\r
             this.SuspendLayout();\r
             // \r
@@ -125,6 +126,7 @@ namespace Radegast
             // \r
             this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)\r
                         | System.Windows.Forms.AnchorStyles.Right)));\r
+            this.groupBox1.Controls.Add(this.btnRemove);\r
             this.groupBox1.Controls.Add(this.btnPay);\r
             this.groupBox1.Controls.Add(this.btnOfferTeleport);\r
             this.groupBox1.Controls.Add(this.lblFriendName);\r
@@ -136,6 +138,17 @@ namespace Radegast
             this.groupBox1.TabIndex = 4;\r
             this.groupBox1.TabStop = false;\r
             // \r
+            // btnPay\r
+            // \r
+            this.btnPay.Enabled = false;\r
+            this.btnPay.Location = new System.Drawing.Point(286, 46);\r
+            this.btnPay.Name = "btnPay";\r
+            this.btnPay.Size = new System.Drawing.Size(75, 23);\r
+            this.btnPay.TabIndex = 5;\r
+            this.btnPay.Text = "Pay...";\r
+            this.btnPay.UseVisualStyleBackColor = true;\r
+            this.btnPay.Click += new System.EventHandler(this.btnPay_Click);\r
+            // \r
             // btnOfferTeleport\r
             // \r
             this.btnOfferTeleport.Enabled = false;\r
@@ -198,16 +211,16 @@ namespace Radegast
             this.timInitDelay.Interval = 3000;\r
             this.timInitDelay.Tick += new System.EventHandler(this.timInitDelay_Tick);\r
             // \r
-            // btnPay\r
+            // btnRemove\r
             // \r
-            this.btnPay.Enabled = false;\r
-            this.btnPay.Location = new System.Drawing.Point(286, 46);\r
-            this.btnPay.Name = "btnPay";\r
-            this.btnPay.Size = new System.Drawing.Size(75, 23);\r
-            this.btnPay.TabIndex = 5;\r
-            this.btnPay.Text = "Pay...";\r
-            this.btnPay.UseVisualStyleBackColor = true;\r
-            this.btnPay.Click += new System.EventHandler(this.btnPay_Click);\r
+            this.btnRemove.Enabled = false;\r
+            this.btnRemove.Location = new System.Drawing.Point(367, 46);\r
+            this.btnRemove.Name = "btnRemove";\r
+            this.btnRemove.Size = new System.Drawing.Size(75, 23);\r
+            this.btnRemove.TabIndex = 6;\r
+            this.btnRemove.Text = "Remove";\r
+            this.btnRemove.UseVisualStyleBackColor = true;\r
+            this.btnRemove.Click += new System.EventHandler(this.btnRemove_Click);\r
             // \r
             // FriendsConsole\r
             // \r
@@ -241,5 +254,6 @@ namespace Radegast
         private System.Windows.Forms.Button btnOfferTeleport;\r
         private System.Windows.Forms.Timer timInitDelay;\r
         private System.Windows.Forms.Button btnPay;\r
+        private System.Windows.Forms.Button btnRemove;\r
     }\r
 }\r
index 4296029..0ff1d87 100644 (file)
@@ -32,6 +32,7 @@ using System;
 using System.Collections.Generic;\r
 using System.Drawing;\r
 using System.Windows.Forms;\r
+using System.Threading;\r
 using OpenMetaverse;\r
 \r
 namespace Radegast\r
@@ -54,6 +55,7 @@ namespace Radegast
             // Callbacks\r
             client.Friends.OnFriendOffline += new FriendsManager.FriendOfflineEvent(Friends_OnFriendOffline);\r
             client.Friends.OnFriendOnline += new FriendsManager.FriendOnlineEvent(Friends_OnFriendOnline);\r
+            client.Friends.OnFriendshipTerminated += new FriendsManager.FriendshipTerminatedEvent(Friends_OnFriendshipTerminated);\r
 \r
         }\r
 \r
@@ -61,6 +63,7 @@ namespace Radegast
         {\r
             client.Friends.OnFriendOffline -= new FriendsManager.FriendOfflineEvent(Friends_OnFriendOffline);\r
             client.Friends.OnFriendOnline -= new FriendsManager.FriendOnlineEvent(Friends_OnFriendOnline);\r
+            client.Friends.OnFriendshipTerminated -= new FriendsManager.FriendshipTerminatedEvent(Friends_OnFriendshipTerminated);\r
         }\r
 \r
         private void InitializeFriendsList()\r
@@ -68,7 +71,7 @@ namespace Radegast
             List<FriendInfo> friends = client.Friends.FriendList.FindAll(delegate(FriendInfo f) { return true; });\r
 \r
             lbxFriends.BeginUpdate();\r
-\r
+            lbxFriends.Items.Clear();\r
             foreach (FriendInfo friend in friends)\r
                 lbxFriends.Items.Add(new FriendsListItem(friend));\r
 \r
@@ -77,20 +80,68 @@ namespace Radegast
 \r
         private void RefreshFriendsList()\r
         {\r
-            lbxFriends.Refresh();\r
+            InitializeFriendsList();\r
             SetFriend(selectedFriend);\r
         }\r
 \r
-        //Separate thread\r
         private void Friends_OnFriendOffline(FriendInfo friend)\r
         {\r
-            BeginInvoke(new MethodInvoker(RefreshFriendsList));\r
+            if (InvokeRequired)\r
+            {\r
+                BeginInvoke(new MethodInvoker(() => Friends_OnFriendOffline(friend)));\r
+                return;\r
+            }\r
+\r
+            instance.MainForm.TabConsole.DisplayNotificationInChat(friend.Name + " is offline");\r
+            RefreshFriendsList();\r
         }\r
 \r
-        //Separate thread\r
         private void Friends_OnFriendOnline(FriendInfo friend)\r
         {\r
-            BeginInvoke(new MethodInvoker(RefreshFriendsList));\r
+            if (InvokeRequired)\r
+            {\r
+                BeginInvoke(new MethodInvoker(() => Friends_OnFriendOnline(friend)));\r
+                return;\r
+            }\r
+\r
+            instance.MainForm.TabConsole.DisplayNotificationInChat(friend.Name + " is online");\r
+            RefreshFriendsList();\r
+        }\r
+\r
+        void Friends_OnFriendshipTerminated(UUID agentID, string agentName)\r
+        {\r
+            if (agentName == string.Empty)\r
+            {\r
+                using (ManualResetEvent done = new ManualResetEvent(false))\r
+                {\r
+\r
+                    AvatarManager.AvatarNamesCallback callback = delegate(Dictionary<UUID, string> names)\r
+                    {\r
+                        if (names.ContainsKey(agentID))\r
+                        {\r
+                            agentName = names[agentID];\r
+                            done.Set();\r
+                        }\r
+                    };\r
+\r
+                    client.Avatars.OnAvatarNames += callback;\r
+                    agentName = instance.getAvatarName(agentID);\r
+                    if (agentName == RadegastInstance.INCOMPLETE_NAME)\r
+                    {\r
+                        done.WaitOne(3000, false);\r
+                    }\r
+                    client.Avatars.OnAvatarNames -= callback;\r
+                }\r
+            }\r
+\r
+            if (InvokeRequired)\r
+            {\r
+                BeginInvoke(new MethodInvoker(() => Friends_OnFriendshipTerminated(agentID, agentName)));\r
+                return;\r
+            }\r
+\r
+            instance.MainForm.TabConsole.DisplayNotificationInChat(agentName + " is no longer on your friend list");\r
+            RefreshFriendsList();\r
         }\r
 \r
         private void SetFriend(FriendInfo friend)\r
@@ -100,7 +151,7 @@ namespace Radegast
 \r
             lblFriendName.Text = friend.Name + (friend.IsOnline ? " (online)" : " (offline)");\r
 \r
-            btnIM.Enabled = btnProfile.Enabled = btnOfferTeleport.Enabled = btnPay.Enabled = true;\r
+            btnIM.Enabled = btnProfile.Enabled = btnOfferTeleport.Enabled = btnPay.Enabled = btnRemove.Enabled = true;\r
             chkSeeMeOnline.Enabled = chkSeeMeOnMap.Enabled = chkModifyMyObjects.Enabled = true;\r
             chkSeeMeOnMap.Enabled = friend.CanSeeMeOnline;\r
 \r
@@ -120,7 +171,7 @@ namespace Radegast
             FriendsListItem itemToDraw = (FriendsListItem)lbxFriends.Items[e.Index];\r
             Brush textBrush = null;\r
             Font textFont = null;\r
-            \r
+\r
             if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)\r
             {\r
                 textBrush = new SolidBrush(Color.FromKnownColor(KnownColor.HighlightText));\r
@@ -140,7 +191,7 @@ namespace Radegast
                 e.Graphics.DrawImage(Properties.Resources.GreenOrb_16, e.Bounds.Left + 2, e.Bounds.Top + 2);\r
             else\r
                 e.Graphics.DrawImage(Properties.Resources.GreenOrbFaded_16, e.Bounds.Left + 2, e.Bounds.Top + 2);\r
-            \r
+\r
             e.Graphics.DrawString(itemToDraw.Friend.Name, textFont, textBrush, stringX, stringY);\r
 \r
             e.DrawFocusRectangle();\r
@@ -180,9 +231,7 @@ namespace Radegast
             if (settingFriend) return;\r
 \r
             selectedFriend.CanSeeMeOnline = chkSeeMeOnline.Checked;\r
-            client.Friends.GrantRights(selectedFriend.UUID, FriendRights.CanSeeOnline);\r
-\r
-            chkSeeMeOnMap.Enabled = chkSeeMeOnline.Checked;\r
+            client.Friends.GrantRights(selectedFriend.UUID, selectedFriend.TheirFriendRights);\r
         }\r
 \r
         private void chkSeeMeOnMap_CheckedChanged(object sender, EventArgs e)\r
@@ -190,7 +239,7 @@ namespace Radegast
             if (settingFriend) return;\r
 \r
             selectedFriend.CanSeeMeOnMap = chkSeeMeOnMap.Checked;\r
-            // client.Friends.GrantRights(selectedFriend.UUID);\r
+            client.Friends.GrantRights(selectedFriend.UUID, selectedFriend.TheirFriendRights);\r
         }\r
 \r
         private void chkModifyMyObjects_CheckedChanged(object sender, EventArgs e)\r
@@ -198,7 +247,7 @@ namespace Radegast
             if (settingFriend) return;\r
 \r
             selectedFriend.CanModifyMyObjects = chkModifyMyObjects.Checked;\r
-            // client.Friends.GrantRights(selectedFriend.UUID);\r
+            client.Friends.GrantRights(selectedFriend.UUID, selectedFriend.TheirFriendRights);\r
         }\r
 \r
         private void btnOfferTeleport_Click(object sender, EventArgs e)\r
@@ -218,5 +267,14 @@ namespace Radegast
         {\r
             (new frmPay(instance, selectedFriend.UUID, selectedFriend.Name, false)).ShowDialog();\r
         }\r
+\r
+        private void btnRemove_Click(object sender, EventArgs e)\r
+        {\r
+            client.Friends.TerminateFriendship(selectedFriend.UUID);\r
+            if (lbxFriends.Items.Count > 0)\r
+            {\r
+                lbxFriends.SelectedIndex = 0;\r
+            }\r
+        }\r
     }\r
 }\r