* Corrected small things to make Circ-git compile from within MonoDevelop
[circ.git] / Circ.Frontend.GtkSharp / ChannelPanelImpl.cs
blob81085a87ae23e9c81a9a33186e1f23e7b3041d4c
1 #region License
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.
8 */
9 #endregion
10 using System;
11 using Gtk;
12 using Circ.Controller;
13 using Circ.Frontend;
14 using Circ.Lib;
15 using System.Text.RegularExpressions;
17 namespace Circ.Frontend.GtkSharp
19 public partial class ChannelPanel: IChannelPanel
21 bool emoticon, url;
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);
24 TabWidget tab;
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) {
37 match.
38 }*/
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");
45 RenderHl();
47 else
48 buffer.InsertWithTagsByName(ref end, message, "message");
49 messages.ScrollToEnd();
50 });
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();
64 });
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);
81 void RenderHl()
83 if (tab != null)
84 tab.IsHl = true;
86 ((Window)this.Toplevel).UrgencyHint = true;
87 GLib.Timeout.Add(2000, delegate {
88 Window win = ((Window)this.Toplevel);
89 if (!win.UrgencyHint)
90 return false;
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;
95 if (tab != null)
96 tab.IsHl = false;
97 return false;
99 return true;
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)
106 sb.Append('[');
107 sb.Append(timestamp);
108 sb.Append(']');
109 sb.Append(" ");
110 sb.Append(author);
111 sb.Append(':');
112 sb.Append(" ");
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,
123 "notice");
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 {
157 get {
158 return emoticon;
160 set {
161 emoticon = value;
165 public bool UseUrlHighlight {
166 get {
167 return url;
169 set {
170 url = value;
175 internal Circ.Frontend.GtkSharp.TabWidget Tab {
176 get {
177 return tab;
179 set {
180 tab = value;
184 public void DoAutocompletation(object sender, KeyPressEventArgs e)
186 if (e.Event.Key != Gdk.Key.Tab)
187 return;
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 + ": ";
196 temp.Position = -1;
197 e.RetVal = true;
200 internal string ChannelName {
201 get {
202 return ctrl.Backend.Name;
206 internal ServerPanel ServerPanel {
207 get {
208 return servPanel;
212 internal IChannelControl ChannelControl {
213 get {
214 return ctrl;