Represents a TabPage that can communicate with an IRC server
상속: System.Windows.Forms.TabPage
예제 #1
0
        /// <summary>
        /// Sends the message to the associated server.
        /// </summary>
        /// <param name="sender">The source tab page.</param>
        /// <param name="message">The message to send.</param>
        public void Send(IRCTabPage sender, Message message)
        {
            message = MessageFactory.AssimilateMessage(message);
            if (this.Connection.IsConnected)
            {
                if ((message is PrivMsgMessage) || (message is NoticeMessage))
                {
                    IRCTabPage tabPage = null;
                    string source = this.Connection.Nickname;

                    if (message is PrivMsgMessage)
                    {
                        IRCChannel channel = this.Channels.Find(i => i.Name.Equals(message.Target, StringComparison.OrdinalIgnoreCase));
                        if (channel == null)
                        {
                            channel = this.CreateChannel(message.Target, true);
                        }

                        tabPage = channel.TabPage;
                    }
                    else
                    {
                        source = string.Format("to({0})", message.Target);
                        tabPage = sender;
                    }

                    tabPage.AppendMessage(message.Command, source, message.Content, message.Type);
                }
                else if (message is JoinMessage)
                {
                    IRCChannel channel = this.Channels.Find(i => i.Name.Equals(message.Parameters[0], StringComparison.OrdinalIgnoreCase));
                    if (channel == null)
                    {
                        channel = this.CreateChannel(message.Parameters[0], true);
                    }
                    else
                    {
                        // If we're already in the channel, just switch tabs.
                        this.TabHost.InvokeAction(() => this.TabHost.SelectedTab = channel.TabPage);
                    }
                }
                else if (message is NickMessage)
                {
                    this.previousNickName = this.connection.Nickname;
                    this.connection.Nickname = (message as NickMessage).NewNickname;
                }

                if (message is QuitMessage)
                {
                    this.disconnecting = true;
                }

                this.Connection.Send(message.ToString());
            }

            if (message is QuitMessage)
            {
                this.Dispose();
            }
        }
예제 #2
0
        /// <summary>
        /// Creates a new channel and tab.
        /// </summary>
        /// <param name="displayName">The name of the channel.</param>
        /// <param name="switchTo">A value indicating whether or not to switch to the new channel.</param>
        /// <returns>The new channel.</returns>
        public IRCChannel CreateChannel(string displayName, bool switchTo)
        {
            IRCChannel retval = new IRCChannel(this, this.Connection);
            retval.Disposed += new IRCChannel.DisposedHandler(this.ChannelDisposed);

            IRCTabType type = IRCTabType.Channel;
            Regex regex = new Regex(@"(?<channel>[#&][^\x07\x2C\s]{1,199})", RegexOptions.IgnoreCase);
            if (!regex.Match(displayName).Success)
            {
                type = IRCTabType.PM;
            }

            this.TabHost.InvokeAction(() =>
                {
                    string tabName = string.Format("{0}_{1}", this.Connection.ToString(), displayName);
                    IRCTabPage tabPage = new IRCTabPage(this.ServerTab.OwningForm, tabName, displayName, type);
                    tabPage.Connection = this.Connection;
                    tabPage.ConnectionSpecificName = displayName;

                    retval.TabPage = tabPage;
                    retval.TabPage.Marshal = this;
                    retval.Name = displayName;

                    // Iterate through the tab pages to figure out how to place
                    // this channels tab page in a group of other ones on the
                    // same network, in alphabetical order.
                    int index = this.TabHost.TabPages.IndexOf(this.ServerTab) + 1;
                    for (int i = index; i < this.TabHost.TabPages.Count; i++)
                    {
                        IRCTabPage tab = this.TabHost.TabPages[i] as IRCTabPage;
                        if (tab != null && tab.Marshal == this && tab.Text.CompareTo(retval.TabPage.Text) < 0)
                        {
                            index = i + 1;
                        }
                        else if (tab != null && tab.Marshal != this)
                        {
                            break;
                        }
                    }
                    
                    this.TabHost.TabPages.Insert(index, tabPage);
                    if (switchTo)
                    {
                        this.TabHost.SelectedTab = tabPage;
                    }
                });

            this.Channels.Add(retval);

            if (this.channelCreated != null)
            {
                this.channelCreated.Invoke(this, retval);
            }

            return retval;
        }
예제 #3
0
        /// <summary>
        /// Sets up the console page and initiates an update check.
        /// </summary>
        public void SetupForm()
        {
            IRCTabPage consoleTabPage = new IRCTabPage(this, "consoleTabPage", "yaircc", IRCTabType.Console);
            consoleTabPage.WebViewInitialised += () => this.ShowForm();
            this.channelsTabControl.TabPages.Add(consoleTabPage);

            GlobalSettings settings = GlobalSettings.Instance;
            if (settings.CheckForUpdateOnStart == GlobalSettings.Boolean.Yes)
            {
                this.autoCheckingForUpdate = true;
                this.CheckForUpdatesToolStripMenuItem_Click(this, EventArgs.Empty);
            }

            this.inputTextBox.Focus();

            // Connect to any favourite servers marked for auto connection.
            FavouriteServers.Instance.Servers.Where(t => t.AutomaticallyConnect).ToList().ForEach(t => this.ProcessConnectionRequest(t));
            this.BuildFavouriteButtons();
        }
예제 #4
0
        /// <summary>
        /// Processes a connection request and creates marshals and tabs were needed.
        /// </summary>
        /// <param name="input">The raw connection command.</param>
        /// <param name="server">The associated server, null if not applicable.</param>
        private void ProcessConnectionRequest(string input, Server server)
        {
            Connection connection = new Connection();
            ParseResult result = connection.Parse(input);
            Action<IRCTabPage> connectAction = (t) =>
            {
                IRCTabPage serverTab;
                if (t == null)
                {
                    serverTab = new IRCTabPage(this, connection.ToString(), server == null ? connection.Server : server.Alias, IRCTabType.Server);
                    serverTab.Connection = connection;
                    serverTab.Connection.UserName = server == null ? GlobalSettings.Instance.UserName : server.UserName;
                    serverTab.Connection.RealName = server == null ? GlobalSettings.Instance.RealName : server.RealName;
                    serverTab.Connection.Nickname = server == null ? GlobalSettings.Instance.NickName : server.NickName;
                    serverTab.Connection.Mode = server == null ? GlobalSettings.Instance.Mode : server.Mode;

                    List<string> commands = null;

                    if (server != null)
                    {
                        commands = server.Commands;
                    }

                    IRCMarshal marshal = new IRCMarshal(connection, this.channelsTabControl, commands, this);
                    marshal.ChannelCreated += new IRCMarshal.ChannelCreatedHandler(this.ChannelCreated);
                    marshal.NetworkRegistered += (s, e) => this.InvokeAction(() => this.UpdateStatusBarText());

                    serverTab.Marshal = marshal;
                    marshal.ServerTab = serverTab;

                    channelsTabControl.TabPages.Add(serverTab);
                    this.ConfigureNewIRCMarshal(this, marshal);
                }
                else
                {
                    serverTab = t;
                }

                channelsTabControl.SelectedTab = serverTab;
                serverTab.Connection.Connect();
            };

            if (result.Success)
            {
                if (this.channelsTabControl.TabPages.ContainsKey(connection.ToString()))
                {
                    IRCTabPage tabPage = this.channelsTabControl.TabPages[connection.ToString()] as IRCTabPage;
                    if (tabPage.Marshal.IsConnected)
                    {
                        this.channelsTabControl.SelectedTab = tabPage;
                    }
                    else
                    {
                        connectAction.Invoke(tabPage);
                    }
                }
                else
                {
                    connectAction.Invoke(null);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Sends the message to the associated server.
        /// </summary>
        /// <param name="sender">The source tab page.</param>
        /// <param name="message">The message to send.</param>
        public void Send(IRCTabPage sender, Message message)
        {
            message = MessageFactory.AssimilateMessage(message);
            if (this.Connection.IsConnected)
            {
                if ((message is PrivMsgMessage) || (message is NoticeMessage))
                {
                    IRCTabPage tabPage = null;
                    string source = this.Connection.Nickname;

                    if (message is PrivMsgMessage)
                    {
                        IRCChannel channel = this.Channels.Find(i => i.Name.Equals(message.Target, StringComparison.OrdinalIgnoreCase));
                        if (channel == null)
                        {
                            channel = this.CreateChannel(message.Target, true);
                        }

                        tabPage = channel.TabPage;
                    }
                    else
                    {
                        source = string.Format("to({0})", message.Target);
                        tabPage = sender;
                    }

                    tabPage.AppendMessage(message.Command, source, message.Content, message.Type);
                }
                else if (message is JoinMessage)
                {
                    IRCChannel channel = this.Channels.Find(i => i.Name.Equals(message.Parameters[0], StringComparison.OrdinalIgnoreCase));
                    if (channel == null)
                    {
                        channel = this.CreateChannel(message.Parameters[0], true);
                    }
                    else
                    {
                        // If we're already in the channel, just switch tabs.
                        this.TabHost.InvokeAction(() => this.TabHost.SelectedTab = channel.TabPage);
                    }
                }
                else if (message is NickMessage)
                {
                    this.previousNickName = this.connection.Nickname;
                    this.connection.Nickname = (message as NickMessage).NewNickname;
                }

                if (message is QuitMessage)
                {
                    this.disconnecting = true;
                }

                this.Connection.Send(message.ToString());
            }

            if (message is QuitMessage)
            {
                this.Dispose();
            }
        }
예제 #6
0
 /// <summary>
 /// Gets a channel using the tab it is linked to.
 /// </summary>
 /// <param name="tab">The tab to find the channel by.</param>
 /// <returns>The matching channel.</returns>
 public IRCChannel GetChannelByTab(IRCTabPage tab)
 {
     return this.channels.Find(i => i.TabPage == tab);
 }
예제 #7
0
        /// <summary>
        /// Creates a new channel and tab.
        /// </summary>
        /// <param name="displayName">The name of the channel.</param>
        /// <param name="switchTo">A value indicating whether or not to switch to the new channel.</param>
        /// <returns>The new channel.</returns>
        public IRCChannel CreateChannel(string displayName, bool switchTo)
        {
            IRCChannel retval = new IRCChannel(this, this.Connection);
            retval.Disposed += new IRCChannel.DisposedHandler(this.ChannelDisposed);

            IRCTabType type = IRCTabType.Channel;
            Regex regex = new Regex(@"(?<channel>[#&][^\x07\x2C\s]{1,199})", RegexOptions.IgnoreCase);
            if (!regex.Match(displayName).Success)
            {
                type = IRCTabType.PM;
            }

            this.TabHost.InvokeAction(() =>
                {
                    string tabName = string.Format("{0}_{1}", this.Connection.ToString(), displayName);
                    IRCTabPage tabPage = new IRCTabPage(this.ServerTab.OwningForm, tabName, displayName, type);
                    tabPage.Connection = this.Connection;
                    tabPage.ConnectionSpecificName = displayName;

                    retval.TabPage = tabPage;
                    retval.TabPage.Marshal = this;
                    retval.Name = displayName;

                    // Iterate through the tab pages to figure out how to place
                    // this channels tab page in a group of other ones on the
                    // same network, in alphabetical order.
                    int index = this.TabHost.TabPages.IndexOf(this.ServerTab) + 1;
                    for (int i = index; i < this.TabHost.TabPages.Count; i++)
                    {
                        IRCTabPage tab = this.TabHost.TabPages[i] as IRCTabPage;
                        if (tab != null && tab.Marshal == this && tab.Text.CompareTo(retval.TabPage.Text) < 0)
                        {
                            index = i + 1;
                        }
                        else if (tab != null && tab.Marshal != this)
                        {
                            break;
                        }
                    }

                    this.TabHost.TabPages.Insert(index, tabPage);
                    if (switchTo)
                    {
                        this.TabHost.SelectedTab = tabPage;
                    }
                });

            this.Channels.Add(retval);

            if (this.channelCreated != null)
            {
                this.channelCreated.Invoke(this, retval);
            }

            return retval;
        }
예제 #8
0
 /// <summary>
 /// Initialises a new instance of the <see cref="ChromiumMarshal"/> class.
 /// </summary>
 /// <param name="initialisationAction">The action to invoke after the DOM has been loaded.</param>
 /// <param name="owner">The owning form.</param>
 public ChromiumMarshal(Action initialisationAction, IRCTabPage owner)
 {
     this.initialisationAction = initialisationAction;
     this.owner = owner;
 }
예제 #9
0
 /// <summary>
 /// Gets a channel using the tab it is linked to.
 /// </summary>
 /// <param name="tab">The tab to find the channel by.</param>
 /// <returns>The matching channel.</returns>
 public IRCChannel GetChannelByTab(IRCTabPage tab)
 {
     return this.channels.Find(i => i.TabPage == tab);
 }
예제 #10
0
 /// <summary>
 /// Initialises a new instance of the <see cref="ChromiumMarshal"/> class.
 /// </summary>
 /// <param name="initialisationAction">The action to invoke after the DOM has been loaded.</param>
 /// <param name="owner">The owning form.</param>
 public ChromiumMarshal(Action initialisationAction, IRCTabPage owner)
 {
     this.initialisationAction = initialisationAction;
     this.owner = owner;
 }