2 /* Circ.Frontend.GtkSharp : GTK# frontend for Circ
3 * Copyright (C) 2007 LAVAL Jérémie
5 * This file is licensed under the terms of the LGPL.
7 * For the complete licence see the file COPYING.
12 using Circ
.Controller
;
15 using System
.Text
.RegularExpressions
;
17 namespace Circ
.Frontend
.GtkSharp
19 public partial class ChannelPanel
: IChannelPanel
22 TransformationPool
<TextView
> pool
= new TransformationPool
<TextView
>();
23 static Regex urlRegex
= new Regex(@"(?#WebOrIP)((?#protocol)((http|https):\/\/)?(?#subDomain)(([a-zA-Z0-9]+\.(?#domain)[a-zA-Z0-9\-]+(?#TLD)(\.[a-zA-Z]+){1,2})|(?#IPAddress)((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])))+(?#Port)(:[1-9][0-9]*)?)+(?#Path)((\/((?#dirOrFileName)[a-zA-Z0-9_\-\%\~\+]+)?)*)?(?#extension)(\.([a-zA-Z0-9_]+))?(?#parameters)(\?([a-zA-Z0-9_\-]+\=[a-z-A-Z0-9_\-\%\~\+]+)?(?#additionalParameters)(\&([a-zA-Z0-9_\-]+\=[a-z-A-Z0-9_\-\%\~\+]+)?)*)?", RegexOptions
.Compiled
);
26 public void SendMessage(string message
)
28 ctrl
.Backend
.SendMessage(message
);
31 public void AddNewMessage(DateTime timestamp
, string author
, string mess
, MessageFlags flags
)
33 Gtk
.Application
.Invoke( delegate {
34 TextIter end
= buffer
.EndIter
;
35 /*MatchCollections matches = urlRegex.Matches(mess);
36 foreach (Match match in matches) {
39 string message
= mess
+ Environment
.NewLine
;
41 buffer
.InsertWithTagsByName(ref end
, FormatDate(ref timestamp
), "time");
42 buffer
.InsertWithTagsByName(ref end
, author
+ " : ", "author");
43 if ((flags
& MessageFlags
.Hl
) > 0) {
44 buffer
.InsertWithTagsByName(ref end
, message
, "hl");
48 buffer
.InsertWithTagsByName(ref end
, message
, "message");
49 messages
.ScrollToEnd();
53 public void AddSelfMessage(string whoami
, string message
)
55 Gtk
.Application
.Invoke( delegate {
56 TextIter end
= buffer
.EndIter
;
57 string mess
= message
+ Environment
.NewLine
;
59 DateTime timestamp
= DateTime
.Now
;
60 buffer
.InsertWithTagsByName(ref end
, FormatDate(ref timestamp
), "time");
61 buffer
.InsertWithTagsByName(ref end
, whoami
+ mess
, "itsme");
63 messages
.ScrollToEnd();
67 string FormatDate(ref DateTime timestamp
)
69 return '[' + timestamp
.ToString("T") + "] ";
72 void InsertUrl(string url
)
74 TextIter iter
= this.messages
.Buffer
.EndIter
;
75 TextChildAnchor temp
= this.messages
.Buffer
.CreateChildAnchor(ref iter
);
76 //Sexy.UrlLabel urlLabel = new Sexy.UrlLabel();
77 //urlLabel.Markup = url;
78 //this.messages.AddChildAtAnchor(urlLabel, temp);
86 ((Window
)this.Toplevel
).UrgencyHint
= true;
87 GLib
.Timeout
.Add(2000, delegate {
88 Window win
= ((Window
)this.Toplevel
);
92 if (win
.GdkWindow
.State
!= Gdk
.WindowState
.Withdrawn
&& win
.IsActive
&& this == MainWindow
.CurrentChannelPanel
) {
93 //System.Console.WriteLine("Current window state" + win.GdkWindow.State.ToString());
94 win
.UrgencyHint
= false;
102 /*string FormatMessage(string timestamp, string author, string message)
104 System.Text.StringBuilder sb = new System.Text.StringBuilder(timestamp.Length +
105 author.Length + message.Length + 10)
107 sb.Append(timestamp);
113 sb.AppendLine(message);
115 return sb.ToString();
118 public void AddNewNotice(string notice
)
120 Gtk
.Application
.Invoke( delegate(object sen
, EventArgs ee
) {
121 TextIter end
= buffer
.EndIter
;
122 buffer
.InsertWithTagsByName(ref end
, '*' + notice
+ Environment
.NewLine
,
124 messages
.ScrollToEnd();
128 public void ChangeTopic(string topic
, string author
, DateTime timestamp
)
130 Gtk
.Application
.Invoke(delegate {
131 System
.Text
.StringBuilder sb
= new System
.Text
.StringBuilder(topic
);
132 sb
.Replace('\n', ' ');
133 sb
.Replace('\r', ' ');
134 sb
.Replace(Environment
.NewLine
, " ");
135 this.topicEntry
.Text
= sb
.ToString();
139 public void AddUser(string[] users
)
141 this.users
.AddUser(users
);
144 public void AddUser(string user
)
146 this.AddNewNotice(user
+ " joined the channel");
147 this.users
.AddUser(user
);
150 public void RemoveUser(string user
, string quitMessage
)
152 this.AddNewNotice(user
+ " has left channel : " + quitMessage
);
153 this.users
.RemoveUser(user
);
156 public bool UseEmoticons
{
165 public bool UseUrlHighlight
{
175 internal Circ
.Frontend
.GtkSharp
.TabWidget Tab
{
184 public void DoAutocompletation(object sender
, KeyPressEventArgs e
)
186 if (e
.Event
.Key
!= Gdk
.Key
.Tab
)
189 Entry temp
= (Entry
) sender
;
190 // TODO: build it using the Nick Tree
191 foreach (string user
in users
.Users
) {
192 if (user
.Length
> temp
.Text
.Length
&& (user
.StartsWith(temp
.Text
, StringComparison
.Ordinal
) ||
193 user
.Equals(temp
.Text
, StringComparison
.Ordinal
)))
194 temp
.Text
= user
+ ": ";
200 internal string ChannelName
{
202 return ctrl
.Backend
.Name
;
206 internal ServerPanel ServerPanel
{
212 internal IChannelControl ChannelControl
{