3 using System
.Collections
.Generic
;
11 public class ConnectionControl
: IConnectionControl
13 IrcConnection connection
;
15 IList
<ChannelControl
> chanControls
= new List
<ChannelControl
>();
16 IParser parser
= new DefaultParser();
19 public ConnectionControl(IrcConnection connection
, MainControl mainCtrl
)
21 this.connection
= connection
;
22 this.mainCtrl
= mainCtrl
;
25 connection
.MessageReceived
+= MessageReceivedHandler
;
26 connection
.ChannelCreated
+= ChannelCreatedHandler
;
27 //connection.MessageSent += delegate(object sender, MessageEventArgs e) {
28 // Console.WriteLine("Message sent : " + e.Message);
31 Logger
.Debug("New Connection set up");
34 public void CloseConnection()
36 // TODO: need to throw a event when disposing a channel so that I can update the
38 foreach (ChannelControl ctrls
in chanControls
)
42 public void JoinChannel (string chanName
)
44 connection
.JoinChannel(chanName
);
47 public IrcConnection Connection
{
53 public string ServerName
{
55 return connection
.Server
;
59 public string Nickname
{
61 return connection
.Info
.Pseudo
;
65 public IChannelControl
GetChannelControl(string channelName
)
67 IChannelControl temp
= null;
69 foreach (IChannelControl ctrl
in chanControls
) {
70 if (channelName
== ctrl
.ChannelName
) {
79 internal void AddChildDiscussion(IDiscussionPanel panel
)
81 // TODO: refractoring is needed
82 // Basically the chain is MainCtrl -> ConnCtrl -> ChanCtrl and each element should only know it's
84 // So instead of a Frontend&Backend property in MainCtrl do a static class Session and put them there
85 mainCtrl
.Frontend
.AddDiscussion(panel
);
88 internal IServerPanel Presentation
{
94 void UpdatePresentation()
96 server
= GuiFactory
.Factory
.GetServerPanel(this);
97 mainCtrl
.Frontend
.AddServer(server
);
98 Logger
.Debug("GUI updated");
101 void MessageReceivedHandler(object sender
, MessageEventArgs e
)
103 // Logger.Instance.Debug("Message received from server");
104 if (parser
.RetrieveMessageType(e
.Message
) != MessageType
.PrivateMessage
)
105 server
.AddNewMessage(parser
.RetrieveMessage(e
.Message
));
108 void ChannelCreatedHandler(object sender
, ChannelEventArgs e
)
110 chanControls
.Add(new ChannelControl(e
.Channel
, this));