* Shop + Plugin is now functionnal, sample Plugin provided to connect to the default...
[circ.git] / Circ.Frontend.GtkSharp / ChannelPanelImpl.cs
blob83e555a6890dfc881696c3a7f7d21d40d52e212f
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;
16 namespace Circ.Frontend.GtkSharp
18 public partial class ChannelPanel: IDiscussionPanel
20 bool emoticon, url;
21 TransformationPool<GtkText> pool = new TransformationPool<GtkText>();
23 public void SendMessage(string message)
25 ctrl.Backend.SendMessage(message);
28 public void AddNewMessage(DateTime timestamp, string author, string mess, bool hl)
30 Gtk.Application.Invoke( delegate {
31 TextIter end = buffer.EndIter;
32 string message = mess + Environment.NewLine;
34 buffer.InsertWithTagsByName(ref end, FormatDate(ref timestamp), "time");
35 buffer.InsertWithTagsByName(ref end, author + " : ", "author");
36 if (hl) {
37 buffer.InsertWithTagsByName(ref end, message, "hl");
38 RenderHl();
40 else
41 buffer.InsertWithTagsByName(ref end, message, "message");
42 messages.ScrollToEnd();
43 });
46 public void AddSelfMessage(string whoami, string message)
48 Gtk.Application.Invoke( delegate {
49 TextIter end = buffer.EndIter;
50 string mess = message + Environment.NewLine;
52 DateTime timestamp = DateTime.Now;
53 buffer.InsertWithTagsByName(ref end, FormatDate(ref timestamp), "time");
54 buffer.InsertWithTagsByName(ref end, whoami + mess, "itsme");
56 messages.ScrollToEnd();
57 });
60 string FormatDate(ref DateTime timestamp)
62 return '[' + timestamp.ToString("T") + "] ";
65 void RenderHl()
67 ((Window)this.Toplevel).UrgencyHint = true;
68 // TODO: reorganize notebook tabs like lasts said
69 /*Label tmp = (Label)((ServerPanel)this.Parent).GetMenuWidget(this);
70 tmp.Markup = "<span foreground=\"red\">" + tmp.Text + "</span>";*/
72 /*string FormatMessage(string timestamp, string author, string message)
74 System.Text.StringBuilder sb = new System.Text.StringBuilder(timestamp.Length +
75 author.Length + message.Length + 10)
76 sb.Append('[');
77 sb.Append(timestamp);
78 sb.Append(']');
79 sb.Append(" ");
80 sb.Append(author);
81 sb.Append(':');
82 sb.Append(" ");
83 sb.AppendLine(message);
85 return sb.ToString();
86 }*/
88 public void AddNewNotice(string notice)
90 Gtk.Application.Invoke( delegate(object sen, EventArgs ee) {
91 TextIter end = buffer.EndIter;
92 buffer.InsertWithTagsByName(ref end, '*' + notice + Environment.NewLine,
93 "notice");
94 messages.ScrollToEnd();
95 });
98 public void ChangeTopic(string topic, string author, DateTime timestamp)
100 Gtk.Application.Invoke(delegate {
101 System.Text.StringBuilder sb = new System.Text.StringBuilder(topic);
102 sb.Replace('\n', ' ');
103 sb.Replace('\r', ' ');
104 sb.Replace(Environment.NewLine, " ");
105 this.topicEntry.Text = sb.ToString();
109 public void AddUser(string[] users)
111 this.users.AddUser(users);
114 public void AddUser(string user)
116 this.users.AddUser(user);
119 public void RemoveUser(string users)
121 this.users.RemoveUser(users);
124 public bool UseEmoticons {
125 get {
126 return emoticon;
128 set {
129 emoticon = value;
133 public bool UseUrlHighlight {
134 get {
135 return url;
137 set {
138 url = value;
142 public void DoAutocompletation(object sender, KeyPressEventArgs e)
144 if (e.Event.Key != Gdk.Key.Tab)
145 return;
147 Entry temp = (Entry) sender;
148 // TODO: build it using the Nick Tree
149 foreach (string user in users.Users) {
150 if (user.Length > temp.Text.Length && (user.StartsWith(temp.Text, StringComparison.Ordinal) ||
151 user.Equals(temp.Text, StringComparison.Ordinal)))
152 temp.Text = user + ": ";
154 temp.Position = -1;
155 e.RetVal = true;
158 internal string ChannelName {
159 get {
160 return ctrl.Backend.Name;
164 internal ServerPanel ServerPanel {
165 get {
166 return servPanel;