Cosmetic change, plugin work, various reaorganization (Frontend, Control, CilBackend)
[circ.git] / CirC / CilControls / ConnectionControl.cs
blob84e5c487d89f59ea912ade8438911f50b77d5f45
2 using System;
3 using System.Collections.Generic;
4 using Circ.Backend;
5 using Circ.Frontend;
6 using Circ.Controller;
8 namespace Circ
11 public class ConnectionControl: IConnectionControl
13 IrcConnection connection;
14 IServerPanel server;
15 IList<ChannelControl> chanControls = new List<ChannelControl>();
16 IParser parser = new DefaultParser();
17 MainControl mainCtrl;
19 public ConnectionControl(IrcConnection connection, MainControl mainCtrl)
21 this.connection = connection;
22 this.mainCtrl = mainCtrl;
24 UpdatePresentation();
25 connection.MessageReceived += MessageReceivedHandler;
26 connection.ChannelCreated += ChannelCreatedHandler;
27 //connection.MessageSent += delegate(object sender, MessageEventArgs e) {
28 // Console.WriteLine("Message sent : " + e.Message);
29 // };
30 connection.Connect();
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
37 // list
38 foreach (ChannelControl ctrls in chanControls)
39 ctrls.CloseChannel();
42 public void JoinChannel (string chanName)
44 connection.JoinChannel(chanName);
47 public IrcConnection Connection {
48 get {
49 return connection;
53 public string ServerName {
54 get {
55 return connection.Server;
59 public string Nickname {
60 get {
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) {
71 temp = ctrl;
72 break;
76 return temp;
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
83 // upper parent.
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 {
89 get {
90 return server;
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));