OSDN Git Service

RAD-104: Make AV names in group chat clickable to open profile
authorLatif Khalifa <latifer@streamgrid.net>
Sun, 8 Jul 2012 15:29:04 +0000 (17:29 +0200)
committerLatif Khalifa <latifer@streamgrid.net>
Sun, 8 Jul 2012 15:29:04 +0000 (17:29 +0200)
Also for local chat

Radegast/Core/ChatTextManager.cs
Radegast/Core/IMTextManager.cs
Radegast/Core/ITextPrinter.cs
Radegast/Core/RichTextBoxPrinter.cs
Radegast/Core/Types/RRichTextBox.cs
Radegast/GUI/Dialogs/MainForm.cs
Radegast/GUI/Dialogs/Settings.Designer.cs
Radegast/GUI/Dialogs/Settings.cs

index 7305768..4ecf4a6 100644 (file)
@@ -187,7 +187,15 @@ namespace Radegast
                         break;
                 }
 
-                textPrinter.PrintTextLine(item.From + item.Text);
+                if (item.Style == ChatBufferTextStyle.Normal && item.ID != UUID.Zero && !instance.GlobalSettings["disable_av_name_link"])
+                {
+                    textPrinter.InsertLink(item.From, string.Format("secondlife:///app/agent/{0}/about", item.ID));
+                    textPrinter.PrintTextLine(item.Text);
+                }
+                else
+                {
+                    textPrinter.PrintTextLine(item.From + item.Text);
+                }
             }
         }
 
index 26f3b13..df8306c 100644 (file)
@@ -129,7 +129,7 @@ namespace Radegast
 
         private void ProcessOutgoingIM(InstantMessageSentEventArgs e)
         {
-            PrintIM(e.Timestamp, netcom.LoginOptions.FullName, e.Message);
+            PrintIM(e.Timestamp, netcom.LoginOptions.FullName, instance.Client.Self.AgentID, e.Message);
         }
 
         private void ProcessIncomingIM(InstantMessageEventArgs e)
@@ -154,7 +154,7 @@ namespace Radegast
                 }
             }
 
-            PrintIM(DateTime.Now, instance.Names.Get(e.IM.FromAgentID, e.IM.FromAgentName), msg);
+            PrintIM(DateTime.Now, instance.Names.Get(e.IM.FromAgentID, e.IM.FromAgentName), e.IM.FromAgentID, msg);
 
             if (!AutoResponseSent && Type == IMTextManagerType.Agent && e.IM.FromAgentID != UUID.Zero && e.IM.FromAgentName != "Second Life")
             {
@@ -181,7 +181,7 @@ namespace Radegast
                         instance.Client.Network.CurrentSim.ID,
                         null);
 
-                    PrintIM(DateTime.Now, instance.Client.Self.Name, instance.GlobalSettings["auto_response_text"].AsString());
+                    PrintIM(DateTime.Now, instance.Client.Self.Name, instance.Client.Self.AgentID, instance.GlobalSettings["auto_response_text"].AsString());
                 }
             }
         }
@@ -205,7 +205,7 @@ namespace Radegast
             textPrinter.PrintTextLine(message);
         }
 
-        private void PrintIM(DateTime timestamp, string fromName, string message)
+        private void PrintIM(DateTime timestamp, string fromName, UUID fromID, string message)
         {
             if (showTimestamps)
             {
@@ -215,16 +215,23 @@ namespace Radegast
 
             textPrinter.ForeColor = SystemColors.WindowText;
 
+            if (!instance.GlobalSettings["disable_av_name_link"])
+            {
+                textPrinter.InsertLink(fromName, string.Format("secondlife:///app/agent/{0}/about", fromID));
+            }
+            else
+            {
+                textPrinter.PrintText(fromName);
+            }
+
             StringBuilder sb = new StringBuilder();
 
             if (message.StartsWith("/me "))
             {
-                sb.Append(fromName);
                 sb.Append(message.Substring(3));
             }
             else
             {
-                sb.Append(fromName);
                 sb.Append(": ");
                 sb.Append(message);
             }
index 96b0bf2..f890b03 100644 (file)
@@ -34,6 +34,8 @@ namespace Radegast
 {
     public interface ITextPrinter
     {
+        void InsertLink(string text);
+        void InsertLink(string text, string hyperlink);
         void PrintText(string text);
         void PrintTextLine(string text);
         void PrintTextLine(string text, Color color);
index c5585b1..8a1d552 100644 (file)
@@ -59,6 +59,16 @@ namespace Radegast
 
         }
 
+        public void InsertLink(string text)
+        {
+            rtb.InsertLink(text);
+        }
+
+        public void InsertLink(string text, string hyperlink)
+        {
+            rtb.InsertLink(text, hyperlink);
+        }
+
         private void FindURLs(string text)
         {
             Match m = urlRegex.Match(text);
index 066d4b6..6f9c83f 100644 (file)
@@ -519,6 +519,23 @@ namespace Radegast
         //public const char LinkSeparator = (char)0x1970;
         public const char LinkSeparator = (char)0x8D;
 
+        private string RtfUnicode(string s)
+        {
+            StringBuilder sb = new StringBuilder();
+            for (int i = 0; i < s.Length; i++)
+            {
+                if (s[i] > (char)255)
+                {
+                    sb.Append(string.Format("\\u{0}?", (short)s[i]));
+                }
+                else
+                {
+                    sb.Append(s[i]);
+                }
+            }
+            return sb.ToString();
+        }
+
         /// <summary>
         /// Insert a given text at a given position as a link. The link text is followed by
         /// a hash (#) and the given hyperlink text, both of them invisible.
@@ -542,7 +559,7 @@ namespace Radegast
             }
             else
             {
-                this.SelectedRtf = /* @"{\rtf1\ansi "*/ rtfHeader + text + @"\v " + LinkSeparator + hyperlink + @"\v0}";
+                this.SelectedRtf = rtfHeader + RtfUnicode(text) + @"\v " + LinkSeparator + hyperlink + @"\v0}";
                 this.Select(position, text.Length + hyperlink.Length + 1);
                 this.SetSelectionLink(true);
                 this.Select(position + text.Length + hyperlink.Length + 1, 0);
index 58520b2..e6d5d70 100644 (file)
@@ -849,8 +849,27 @@ namespace Radegast
                 if (UUID.TryParse(m.Groups["id"].Value, out id))
                 {
                     ShowGroupProfile(id);
+                    return true;
                 }
+                return false;
             }
+
+            // Is it user profile link
+            r = new Regex(@"^secondlife:///app/agent/(?<id>[^/]+)/about",
+                RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
+            m = r.Match(link);
+
+            if (m.Success)
+            {
+                UUID id;
+                if (UUID.TryParse(m.Groups["id"].Value, out id))
+                {
+                    ShowAgentProfile(instance.Names.Get(id), id);
+                    return true;
+                }
+                return false;
+            }
+
             return false;
         }
 
@@ -864,7 +883,7 @@ namespace Radegast
             var pos = link.IndexOf(RRichTextBox.LinkSeparator);
             if (pos > 0)
             {
-                link = link.Substring(pos);
+                link = link.Substring(pos + 1);
             }
 
             if (link.StartsWith("secondlife://"))
index 9cf34ea..3da7ba4 100644 (file)
@@ -82,6 +82,7 @@ namespace Radegast
             this.cbRadegastClientTag = new System.Windows.Forms.CheckBox();
             this.cbSyntaxHighlight = new System.Windows.Forms.CheckBox();
             this.Chat = new System.Windows.Forms.GroupBox();
+            this.cbDisableNameLinks = new System.Windows.Forms.CheckBox();
             this.cbDisableChatIMLog = new System.Windows.Forms.CheckBox();
             this.cbChatTimestamps = new System.Windows.Forms.CheckBox();
             this.cbIMTimeStamps = new System.Windows.Forms.CheckBox();
@@ -105,11 +106,13 @@ namespace Radegast
             this.tbpGraphics = new System.Windows.Forms.TabPage();
             this.tbpBot = new System.Windows.Forms.TabPage();
             this.pseudoHome = new System.Windows.Forms.GroupBox();
-            this.pseudoHomeLocation = new System.Windows.Forms.TextBox();
-            this.pseudoHomeEnabled = new System.Windows.Forms.CheckBox();
-            this.pseudoHomeTP = new System.Windows.Forms.Button();
             this.pseudoHomeSet = new System.Windows.Forms.Button();
+            this.pseudoHomeTolerance = new System.Windows.Forms.NumericUpDown();
+            this.pseudoHomeTP = new System.Windows.Forms.Button();
+            this.pseudoHomeLocation = new System.Windows.Forms.TextBox();
             this.pseudoHomeClear = new System.Windows.Forms.Button();
+            this.pseudoHomeToleranceLabel = new System.Windows.Forms.Label();
+            this.pseudoHomeEnabled = new System.Windows.Forms.CheckBox();
             this.autoSit = new System.Windows.Forms.GroupBox();
             this.autoSitEnabled = new System.Windows.Forms.CheckBox();
             this.autoSitSit = new System.Windows.Forms.Button();
@@ -118,8 +121,6 @@ namespace Radegast
             this.autoSitUUID = new System.Windows.Forms.TextBox();
             this.autoSitName = new System.Windows.Forms.TextBox();
             this.autoSitNameLabel = new System.Windows.Forms.Label();
-            this.pseudoHomeToleranceLabel = new System.Windows.Forms.Label();
-            this.pseudoHomeTolerance = new System.Windows.Forms.NumericUpDown();
             this.tcGraphics.SuspendLayout();
             this.tbpGeneral.SuspendLayout();
             this.cbHighLight.SuspendLayout();
@@ -131,8 +132,8 @@ namespace Radegast
             this.gbAutoResponse.SuspendLayout();
             this.tbpBot.SuspendLayout();
             this.pseudoHome.SuspendLayout();
-            this.autoSit.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.pseudoHomeTolerance)).BeginInit();
+            this.autoSit.SuspendLayout();
             this.SuspendLayout();
             // 
             // tcGraphics
@@ -170,7 +171,7 @@ namespace Radegast
             this.cbHighLight.Controls.Add(this.cbHighlightChat);
             this.cbHighLight.Controls.Add(this.cbFriendsHighlight);
             this.cbHighLight.Controls.Add(this.cbTaskBarHighLight);
-            this.cbHighLight.Location = new System.Drawing.Point(8, 160);
+            this.cbHighLight.Location = new System.Drawing.Point(8, 180);
             this.cbHighLight.Name = "cbHighLight";
             this.cbHighLight.Size = new System.Drawing.Size(256, 136);
             this.cbHighLight.TabIndex = 1;
@@ -387,6 +388,7 @@ namespace Radegast
             // 
             // Chat
             // 
+            this.Chat.Controls.Add(this.cbDisableNameLinks);
             this.Chat.Controls.Add(this.cbDisableChatIMLog);
             this.Chat.Controls.Add(this.cbChatTimestamps);
             this.Chat.Controls.Add(this.cbIMTimeStamps);
@@ -396,11 +398,21 @@ namespace Radegast
             this.Chat.Controls.Add(this.label1);
             this.Chat.Location = new System.Drawing.Point(8, 5);
             this.Chat.Name = "Chat";
-            this.Chat.Size = new System.Drawing.Size(256, 149);
+            this.Chat.Size = new System.Drawing.Size(256, 169);
             this.Chat.TabIndex = 0;
             this.Chat.TabStop = false;
             this.Chat.Text = "Chat";
             // 
+            // cbDisableNameLinks
+            // 
+            this.cbDisableNameLinks.AutoSize = true;
+            this.cbDisableNameLinks.Location = new System.Drawing.Point(8, 144);
+            this.cbDisableNameLinks.Name = "cbDisableNameLinks";
+            this.cbDisableNameLinks.Size = new System.Drawing.Size(147, 17);
+            this.cbDisableNameLinks.TabIndex = 9;
+            this.cbDisableNameLinks.Text = "Disable avatar name links";
+            this.cbDisableNameLinks.UseVisualStyleBackColor = true;
+            // 
             // cbDisableChatIMLog
             // 
             this.cbDisableChatIMLog.AutoSize = true;
@@ -673,24 +685,38 @@ namespace Radegast
             this.pseudoHome.TabStop = false;
             this.pseudoHome.Text = "Pseudo Home";
             // 
-            // pseudoHomeLocation
+            // pseudoHomeSet
             // 
-            this.pseudoHomeLocation.Location = new System.Drawing.Point(87, 40);
-            this.pseudoHomeLocation.Name = "pseudoHomeLocation";
-            this.pseudoHomeLocation.ReadOnly = true;
-            this.pseudoHomeLocation.Size = new System.Drawing.Size(170, 20);
-            this.pseudoHomeLocation.TabIndex = 5;
+            this.pseudoHomeSet.Location = new System.Drawing.Point(94, 73);
+            this.pseudoHomeSet.Name = "pseudoHomeSet";
+            this.pseudoHomeSet.Size = new System.Drawing.Size(75, 23);
+            this.pseudoHomeSet.TabIndex = 1;
+            this.pseudoHomeSet.Text = "Set";
+            this.pseudoHomeSet.UseVisualStyleBackColor = true;
+            this.pseudoHomeSet.Click += new System.EventHandler(this.pseudoHomeSet_Click);
             // 
-            // pseudoHomeEnabled
+            // pseudoHomeTolerance
             // 
-            this.pseudoHomeEnabled.AutoSize = true;
-            this.pseudoHomeEnabled.Location = new System.Drawing.Point(6, 77);
-            this.pseudoHomeEnabled.Name = "pseudoHomeEnabled";
-            this.pseudoHomeEnabled.Size = new System.Drawing.Size(65, 17);
-            this.pseudoHomeEnabled.TabIndex = 3;
-            this.pseudoHomeEnabled.Text = "Enabled";
-            this.pseudoHomeEnabled.UseVisualStyleBackColor = true;
-            this.pseudoHomeEnabled.CheckedChanged += new System.EventHandler(this.pseudoHomeEnabled_CheckedChanged);
+            this.pseudoHomeTolerance.Location = new System.Drawing.Point(87, 14);
+            this.pseudoHomeTolerance.Maximum = new decimal(new int[] {
+            256,
+            0,
+            0,
+            0});
+            this.pseudoHomeTolerance.Minimum = new decimal(new int[] {
+            1,
+            0,
+            0,
+            0});
+            this.pseudoHomeTolerance.Name = "pseudoHomeTolerance";
+            this.pseudoHomeTolerance.Size = new System.Drawing.Size(40, 20);
+            this.pseudoHomeTolerance.TabIndex = 7;
+            this.pseudoHomeTolerance.Value = new decimal(new int[] {
+            256,
+            0,
+            0,
+            0});
+            this.pseudoHomeTolerance.ValueChanged += new System.EventHandler(this.pseudoHomeTolerance_ValueChanged);
             // 
             // pseudoHomeTP
             // 
@@ -702,15 +728,13 @@ namespace Radegast
             this.pseudoHomeTP.UseVisualStyleBackColor = true;
             this.pseudoHomeTP.Click += new System.EventHandler(this.pseudoHomeTP_Click);
             // 
-            // pseudoHomeSet
+            // pseudoHomeLocation
             // 
-            this.pseudoHomeSet.Location = new System.Drawing.Point(94, 73);
-            this.pseudoHomeSet.Name = "pseudoHomeSet";
-            this.pseudoHomeSet.Size = new System.Drawing.Size(75, 23);
-            this.pseudoHomeSet.TabIndex = 1;
-            this.pseudoHomeSet.Text = "Set";
-            this.pseudoHomeSet.UseVisualStyleBackColor = true;
-            this.pseudoHomeSet.Click += new System.EventHandler(this.pseudoHomeSet_Click);
+            this.pseudoHomeLocation.Location = new System.Drawing.Point(87, 40);
+            this.pseudoHomeLocation.Name = "pseudoHomeLocation";
+            this.pseudoHomeLocation.ReadOnly = true;
+            this.pseudoHomeLocation.Size = new System.Drawing.Size(170, 20);
+            this.pseudoHomeLocation.TabIndex = 5;
             // 
             // pseudoHomeClear
             // 
@@ -721,6 +745,26 @@ namespace Radegast
             this.pseudoHomeClear.Text = "Clear";
             this.pseudoHomeClear.UseVisualStyleBackColor = true;
             // 
+            // pseudoHomeToleranceLabel
+            // 
+            this.pseudoHomeToleranceLabel.AutoSize = true;
+            this.pseudoHomeToleranceLabel.Location = new System.Drawing.Point(6, 16);
+            this.pseudoHomeToleranceLabel.Name = "pseudoHomeToleranceLabel";
+            this.pseudoHomeToleranceLabel.Size = new System.Drawing.Size(55, 13);
+            this.pseudoHomeToleranceLabel.TabIndex = 6;
+            this.pseudoHomeToleranceLabel.Text = "Tolerance";
+            // 
+            // pseudoHomeEnabled
+            // 
+            this.pseudoHomeEnabled.AutoSize = true;
+            this.pseudoHomeEnabled.Location = new System.Drawing.Point(6, 77);
+            this.pseudoHomeEnabled.Name = "pseudoHomeEnabled";
+            this.pseudoHomeEnabled.Size = new System.Drawing.Size(65, 17);
+            this.pseudoHomeEnabled.TabIndex = 3;
+            this.pseudoHomeEnabled.Text = "Enabled";
+            this.pseudoHomeEnabled.UseVisualStyleBackColor = true;
+            this.pseudoHomeEnabled.CheckedChanged += new System.EventHandler(this.pseudoHomeEnabled_CheckedChanged);
+            // 
             // autoSit
             // 
             this.autoSit.Controls.Add(this.autoSitEnabled);
@@ -805,38 +849,6 @@ namespace Radegast
             this.autoSitNameLabel.Text = "Name";
             this.autoSitNameLabel.Click += new System.EventHandler(this.autoSitNameLabel_Click);
             // 
-            // pseudoHomeToleranceLabel
-            // 
-            this.pseudoHomeToleranceLabel.AutoSize = true;
-            this.pseudoHomeToleranceLabel.Location = new System.Drawing.Point(6, 16);
-            this.pseudoHomeToleranceLabel.Name = "pseudoHomeToleranceLabel";
-            this.pseudoHomeToleranceLabel.Size = new System.Drawing.Size(55, 13);
-            this.pseudoHomeToleranceLabel.TabIndex = 6;
-            this.pseudoHomeToleranceLabel.Text = "Tolerance";
-            // 
-            // pseudoHomeTolerance
-            // 
-            this.pseudoHomeTolerance.Location = new System.Drawing.Point(87, 14);
-            this.pseudoHomeTolerance.Maximum = new decimal(new int[] {
-            256,
-            0,
-            0,
-            0});
-            this.pseudoHomeTolerance.Minimum = new decimal(new int[] {
-            1,
-            0,
-            0,
-            0});
-            this.pseudoHomeTolerance.Name = "pseudoHomeTolerance";
-            this.pseudoHomeTolerance.Size = new System.Drawing.Size(40, 20);
-            this.pseudoHomeTolerance.TabIndex = 7;
-            this.pseudoHomeTolerance.Value = new decimal(new int[] {
-            256,
-            0,
-            0,
-            0});
-            this.pseudoHomeTolerance.ValueChanged += new System.EventHandler(this.pseudoHomeTolerance_ValueChanged);
-            // 
             // frmSettings
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -864,9 +876,9 @@ namespace Radegast
             this.tbpBot.ResumeLayout(false);
             this.pseudoHome.ResumeLayout(false);
             this.pseudoHome.PerformLayout();
+            ((System.ComponentModel.ISupportInitialize)(this.pseudoHomeTolerance)).EndInit();
             this.autoSit.ResumeLayout(false);
             this.autoSit.PerformLayout();
-            ((System.ComponentModel.ISupportInitialize)(this.pseudoHomeTolerance)).EndInit();
             this.ResumeLayout(false);
 
         }
@@ -934,6 +946,7 @@ namespace Radegast
         private System.Windows.Forms.Button pseudoHomeClear;
         private System.Windows.Forms.NumericUpDown pseudoHomeTolerance;
         private System.Windows.Forms.Label pseudoHomeToleranceLabel;
+        private System.Windows.Forms.CheckBox cbDisableNameLinks;
 
 
     }
index 086c309..49acacc 100644 (file)
@@ -128,6 +128,8 @@ namespace Radegast
             if (!s.ContainsKey("highlight_on_im")) s["highlight_on_im"] = true;
 
             if (!s.ContainsKey("highlight_on_group_im")) s["highlight_on_group_im"] = true;
+
+            if (!s.ContainsKey("disable_av_name_link")) s["disable_av_name_link"] = false;
         }
 
         public frmSettings(RadegastInstance instance)
@@ -281,6 +283,20 @@ namespace Radegast
                 s["highlight_on_group_im"] = cbHighlightGroupIM.Checked;
             };
 
+            // disable_av_name_link
+            if (instance.MonoRuntime)
+            {
+                cbDisableNameLinks.Visible = false;
+            }
+            else
+            {
+                cbDisableNameLinks.Checked = s["disable_av_name_link"];
+                cbDisableNameLinks.CheckedChanged += (sender, e) =>
+                {
+                    s["disable_av_name_link"] = cbDisableNameLinks.Checked;
+                };
+            }
+
             autoSitPrefsUpdate();
             pseudoHomePrefsUpdated();