root/lang/csharp/Criw-0/MainForm.cs

Revision 1736, 31.5 kB (checked in by mayuki, 14 months ago)

lang/csharp: WZERO3などで動くIRCクライアントのサンプル実装 Criw-0 を追加。

  • Property svn:keywords set to Id
Line 
1using System;
2using System.Collections;
3using System.Collections.Specialized;
4using System.Collections.Generic;
5using System.ComponentModel;
6using System.Data;
7using System.Drawing;
8using System.Text;
9using System.Windows.Forms;
10using System.Threading;
11using System.IO;
12using System.Net;
13using System.Net.Sockets;
14using Circuit.Net.Irc;
15using System.Diagnostics;
16using System.Text.RegularExpressions;
17using System.Runtime.InteropServices;
18
19namespace Misuzilla.Applications.Mobile.Criw0
20{
21    public partial class MainForm : Form
22    {
23        private readonly String VersionString = String.Format("Criw-0/{0}; {1}; .NET CLR {2}", "2006-12-23", Environment.OSVersion, Environment.Version.ToString());
24        private const String ConsoleName = "*Console*";
25        //private Regex _uriRegex = new Regex("(?:(?<uri>(urn:[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+|https?://[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+))|(?<text>(?:(?!h?ttps?://[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+).)+))", RegexOptions.Compiled);
26        private Regex _uriRegex = new Regex("h?ttp(s?://[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+)");
27
28        private IRCConnection _ircConnection;
29        private String _selfNickname = "";
30        private String _connectionName = "";
31        private String _connectionHost = "";
32        private StringDictionary _channelLogs;
33        private StringDictionary _channelTopics;
34        private String _currentLogName = ConsoleName;
35        private List<String> _autoJoinChannels = null;
36        private Dictionary<String, List<String>> _nicknameList = null;
37        private Dictionary<String, Boolean> _nicknameListUpdating = null;
38
39        //
40        // Messages
41        //
42        private readonly String PartMessageText = String.Format("Leaving");
43        public String QuitMesssageText { get { return String.Format("Connection Closing; {1}", VersionString); } }
44        public String QuitMesssageTextOnApplicationExit { get { return String.Format("Application Exit; {0}", VersionString); } }
45        //
46
47        public static void Main(String[] args)
48        {
49            //Thread.CurrentThread.SetApartmentState(ApartmentState.STA);
50            Application.Run(new MainForm());
51        }
52
53        public MainForm()
54        {
55            InitializeComponent();
56            SettingManager.Load();
57        }
58
59        private void Form1_Load(object sender, EventArgs e)
60        {
61            _ircConnection = new IRCConnection();
62            _ircConnection.Connecting += new EventHandler(_ircConnection_Connecting);
63            _ircConnection.Connected += new EventHandler(_ircConnection_Connected);
64            _ircConnection.Disconnected += new EventHandler(_ircConnection_Disconnected);
65            _ircConnection.MessageReceived += new EventHandler<IRCConnection.MessageReceivedEventArgs>(_ircConnection_MessageReceived);
66
67            _channelLogs = new StringDictionary();
68            _nicknameList = new Dictionary<string, List<String>>();
69            _nicknameListUpdating = new Dictionary<string, Boolean>();
70            _channelTopics = new StringDictionary();
71
72            MessageProcessChain += new MessageReceivedDelegate(ProcessNick);
73            MessageProcessChain += new MessageReceivedDelegate(ProcessJoin);
74            MessageProcessChain += new MessageReceivedDelegate(ProcessPart);
75            MessageProcessChain += new MessageReceivedDelegate(ProcessPrivMsg);
76            MessageProcessChain += new MessageReceivedDelegate(ProcessPing);
77            MessageProcessChain += new MessageReceivedDelegate(ProcessNotice);
78            MessageProcessChain += new MessageReceivedDelegate(ProcessNumericReply);
79            MessageProcessChain += new MessageReceivedDelegate(ProcessTopic);
80            MessageProcessChain += new MessageReceivedDelegate(ProcessQuit);
81            MessageProcessChain += new MessageReceivedDelegate(ProcessNumReply353);
82            MessageProcessChain += new MessageReceivedDelegate(ProcessNumReply366);
83           //MessageProcessChain += new MessageReceivedDelegate(ProcessOtherMessage);
84
85            listChannels.Items.Add(new ListViewItem(ConsoleName));
86            textLog.ContextMenu = new ContextMenu();
87            MenuItem menuItemContextOpenUrl = new MenuItem();
88            MenuItem menuItemContextCopy = new MenuItem();
89            textLog.ContextMenu.MenuItems.Add(menuItemContextOpenUrl);
90            textLog.ContextMenu.MenuItems.Add(menuItemContextCopy);
91            menuItemContextOpenUrl.Text = "URL���(&O)...";
92            menuItemContextOpenUrl.Click += delegate(Object _sender, EventArgs _e)
93            {
94                ProcessStartInfo startInfo = new ProcessStartInfo();
95                Match m = _uriRegex.Match(textLog.SelectedText);
96                if (!m.Success) return;
97                startInfo.Verb = "open";
98                //startInfo.UseShellExecute = true;
99                startInfo.FileName = "http" + m.Groups[1].Captures[0].Value;
100                Process.Start(startInfo);
101            };
102            menuItemContextCopy.Text = "�R�s�[(&C)";
103            menuItemContextCopy.Click += delegate(Object _sender, EventArgs _e)
104            {
105                Clipboard.SetDataObject(textLog.SelectedText);
106            };
107            //SendMessage(textLog.Handle, 0x00CF, 1, 0);
108
109            textAllLog.Font = new Font(textAllLog.Font.Name, SettingManager.Setting.ChannelLogTextFontSize, textAllLog.Font.Style);
110            textLog.Font = new Font(textLog.Font.Name, SettingManager.Setting.ChannelLogTextFontSize, textLog.Font.Style);
111        }
112
113        void _ircConnection_Connecting(object sender, EventArgs e)
114        {
115            AddLogText(ConsoleName, String.Format("�T�[�o '{0}' �ɐڑ����Ă��܂�...", _connectionHost));
116        }
117
118        void _ircConnection_Connected(object sender, EventArgs e)
119        {
120            //throw new Exception("The method or operation is not implemented.");
121            menuItemConnectDisconnect.Enabled = true;
122            menuItemChannel.Enabled = true;
123            menuItemNext.Enabled = true;
124            timerPing.Enabled = true;
125
126            // ����JOIN
127            if (_autoJoinChannels != null)
128            {
129                foreach (String channel in _autoJoinChannels)
130                {
131                    _ircConnection.Send("JOIN :" + channel);
132                }
133            }
134        }
135        void _ircConnection_Disconnected(object sender, EventArgs e)
136        {
137            AddLogText(ConsoleName, String.Format("�T�[�o�����f���܂���", _connectionHost));
138
139            // ����            // FIXME: ���O�̔���
140            String consoleLog = _channelLogs[ConsoleName];
141            _currentLogName = ConsoleName;
142            _channelLogs = new StringDictionary();
143            _channelLogs[ConsoleName] = consoleLog;
144           
145            _nicknameList.Clear();
146
147            listChannels.Items.Clear();
148            listChannels.Items.Add(new ListViewItem(ConsoleName)).SubItems.Add("");
149
150            menuItemChannel.Enabled = false;
151            menuItemConnectDisconnect.Enabled = false;
152            menuItemNext.Enabled = false;
153            timerPing.Enabled = false;
154
155            this.Text = "Criw";
156        }
157
158        void _ircConnection_MessageReceived(object sender, IRCConnection.MessageReceivedEventArgs e)
159        {
160            this.Invoke(new MessageReceivedDelegate(MessageReceivedOnForm), new Object[] { e.Message });
161        }
162
163        private delegate void MessageReceivedDelegate(IRCMessage m);
164        private event MessageReceivedDelegate MessageProcessChain;
165        private void MessageReceivedOnForm(IRCMessage m)
166        {
167            MessageProcessChain(m);
168
169            //_channelLogs[ConsoleName] += m.ToString() + "\r\n";
170        }
171        /// <summary>
172        ///
173        /// </summary>
174        /// <param name="m"></param>
175        private void ProcessNumReply366(IRCMessage m)
176        {
177            NumericReplyMessage numReply = m as NumericReplyMessage;
178            if (numReply == null || numReply.ReplyNumber != (Int32)NumericReply.RPL_ENDOFNAMES) return;
179            if (!_nicknameListUpdating.ContainsKey(numReply.CommandParams[1].ToLower())) return;
180            _nicknameListUpdating[numReply.CommandParams[1].ToLower()] = false;
181            UpdateUserList();
182        }
183        /// <summary>
184        ///
185        /// </summary>
186        /// <param name="m"></param>
187        private void ProcessNumReply353(IRCMessage m)
188        {
189            NumericReplyMessage numReply = m as NumericReplyMessage;
190            if (numReply == null || numReply.ReplyNumber != (Int32)NumericReply.RPL_NAMREPLY) return;
191            String channel = numReply.CommandParams[2].ToLower();
192
193            // JOIN���ĂȂ��Ƃ�
194            if (!_nicknameListUpdating.ContainsKey(channel)) return;
195
196            if (!_nicknameListUpdating[channel])
197            {
198                _nicknameList[channel].Clear();
199                _nicknameListUpdating[channel] = true;
200            }
201
202            foreach (String nick in numReply.CommandParams[3].Split(new Char[] { ' ' }))
203            {
204                // FIXME: �Ȃ�
205                if (nick.StartsWith("@"))
206                {
207                    _nicknameList[channel].Add(nick.Substring(1));
208                }
209                else
210                {
211                    _nicknameList[channel].Add(nick);
212                }
213            }
214
215            AddLogText(channel, String.Format("* Names: {0}",
216               numReply.CommandParams[3]));
217
218        }
219        /// <summary>
220        ///
221        /// </summary>
222        /// <param name="m"></param>
223        private void ProcessNick(IRCMessage m)
224        {
225            NickMessage nickMsg = m as NickMessage;
226            if (nickMsg == null || nickMsg.Sender == null || nickMsg.Sender.Length == 0) return; // �����ő��M�̏ꍇ�Ƃ�
227
228            if (nickMsg.SenderNick == _selfNickname)
229            {
230                _selfNickname = nickMsg.NewNick;
231                this.Text = String.Format("{0} @ {1} - Criw", _selfNickname, _connectionName);
232            }
233            else
234            {
235                //�ق��̃��[�U
236            }
237
238            foreach (String channel in _nicknameList.Keys)
239            {
240                if (_nicknameList[channel].Contains(nickMsg.SenderNick))
241                {
242                    _nicknameList[channel].Remove(nickMsg.SenderNick);
243                    _nicknameList[channel].Add(nickMsg.NewNick);
244                }
245            }
246            UpdateUserList();
247
248            AddLogText(ConsoleName, String.Format("* Nick {0} �� {1}",
249                nickMsg.SenderNick
250                , nickMsg.NewNick), true);
251        }
252        /// <summary>
253        ///
254        /// </summary>
255        /// <param name="m"></param>
256        private void ProcessJoin(IRCMessage m)
257        {
258            JoinMessage joinMsg = m as JoinMessage;
259            if (joinMsg == null) return;
260
261            if (joinMsg.SenderNick == _selfNickname)
262            {
263                _nicknameList[joinMsg.Channel.ToLower()] = new List<string>();
264                _nicknameListUpdating[joinMsg.Channel.ToLower()] = false;
265                ListViewItem item = listChannels.Items.Add(new ListViewItem(joinMsg.Channel));
266                item.SubItems.Add("");
267            }
268            else
269            {
270                //�ق��̃��[�U
271            }
272
273            String channel = joinMsg.Channel.ToLower();
274            if (!_nicknameList[channel].Contains(joinMsg.SenderNick))
275            {
276                _nicknameList[channel].Add(joinMsg.SenderNick);
277            }
278            UpdateUserList();
279
280            AddLogText(joinMsg.Channel, String.Format("* Join {0} ({1})",
281               joinMsg.SenderNick
282               , joinMsg.Sender));
283        }
284        /// <summary>
285        ///
286        /// </summary>
287        /// <param name="m"></param>
288        private void ProcessPart(IRCMessage m)
289        {
290            PartMessage partMsg = m as PartMessage;
291            if (partMsg == null) return;
292
293            if (partMsg.SenderNick == _selfNickname)
294            {
295                ListViewItem lvItem = null;
296                foreach (ListViewItem item in listChannels.Items)
297                {
298                    if (String.Compare(item.Text, partMsg.Channel, true) == 0)
299                    {
300                        lvItem = item;
301                    }
302                }
303                if (lvItem != null)
304                {
305                    listChannels.Items.Remove(lvItem);
306                }
307            }
308            else
309            {
310                //�ق��̃��[�U
311            }
312           
313            String channel = partMsg.Channel.ToLower();
314            if (_nicknameList[channel].Contains(partMsg.SenderNick))
315            {
316                _nicknameList[channel].Remove(partMsg.SenderNick);
317            }
318            UpdateUserList();
319
320            AddLogText(partMsg.Channel, String.Format("* Part {0} ({1})",
321              partMsg.SenderNick
322              , partMsg.Message));
323        }
324        /// <summary>
325        ///
326        /// </summary>
327        /// <param name="m"></param>
328        private void ProcessQuit(IRCMessage m)
329        {
330            QuitMessage quitMsg = m as QuitMessage;
331            if (quitMsg == null) return;
332
333            if (quitMsg.SenderNick == _selfNickname)
334            {
335            }
336            else
337            {
338                //�ق��̃��[�U
339            }
340
341            foreach (String channel in _nicknameList.Keys)
342            {
343                if (_nicknameList[channel].Contains(quitMsg.SenderNick))
344                {
345                    _nicknameList[channel].Remove(quitMsg.SenderNick);
346                }
347            }
348            UpdateUserList();
349
350            AddLogText(ConsoleName, String.Format("* Quit {0} ({1})",
351              quitMsg.SenderNick
352              , quitMsg.Message), true);
353        }
354        /// <summary>
355        ///
356        /// </summary>
357        /// <param name="m"></param>
358        private void ProcessPrivMsg(IRCMessage m)
359        {
360            PrivMsgMessage prvMsg = m as PrivMsgMessage;
361            if (prvMsg == null) return;
362
363            if (String.Compare(prvMsg.Receiver, _selfNickname, true) == 0)
364            {
365                // Priv
366            }
367            else
368            {
369                // channel
370            }
371            if (prvMsg.SenderNick.Length == 0 ||
372                String.Compare(prvMsg.SenderNick, _selfNickname, true) == 0)
373            {
374                //�����Ŕ���
375                AddLogText(prvMsg.Receiver, String.Format(">{0}< {1}",
376                    _selfNickname
377                    , prvMsg.Content));
378            }
379            else
380            {
381                UnreadCountIncrement(prvMsg.Receiver);
382                AddLogText(prvMsg.Receiver, String.Format("<{0}> {1}",
383                    prvMsg.SenderNick
384                    , prvMsg.Content));
385            }
386        }
387        /// <summary>
388        ///
389        /// </summary>
390        /// <param name="m"></param>
391        private void ProcessNotice(IRCMessage m)
392        {
393            NoticeMessage noticeMsg = m as NoticeMessage;
394            if (noticeMsg == null) return;
395
396            if (String.Compare(noticeMsg.Receiver, _selfNickname, true) == 0)
397            {
398                // Priv
399            }
400            else
401            {
402                // channel
403            }
404
405            if (noticeMsg.IsServerMessage || noticeMsg.Receiver == _selfNickname)
406            {
407                AddLogText(ConsoleName, noticeMsg.ToString());
408            }
409            else
410            {
411                AddLogText(noticeMsg.Receiver, String.Format("({0}) {1}", noticeMsg.SenderNick, noticeMsg.Content));
412            }
413        }
414        /// <summary>
415        ///
416        /// </summary>
417        /// <param name="m"></param>
418        private void ProcessPing(IRCMessage m)
419        {
420            if (String.Compare(m.Command, "PING", true) != 0) return;
421
422            // PONG
423            _ircConnection.Send("PONG :" + m.CommandParam);
424        }
425        /// <summary>
426        ///
427        /// </summary>
428        /// <param name="m"></param>
429        void ProcessNumericReply(IRCMessage m)
430        {
431            NumericReplyMessage numMsg = m as NumericReplyMessage;
432            if (numMsg == null) return;
433
434            switch (numMsg.ReplyNumber)
435            {
436                //case (Int32)NumericReply.RPL_TOPICWHOTIME:
437                case (Int32)NumericReply.RPL_TOPIC:
438                    AddLogText(numMsg.CommandParams[1], "* Topic: " + numMsg.CommandParams[2]);
439                    ChangeChannelTopic(numMsg.CommandParams[1], numMsg.CommandParams[2]);
440                    break;
441                default:
442                    AddLogText(ConsoleName, numMsg.ToString());
443                    break;
444            }
445        }
446        /// <summary>
447        ///
448        /// </summary>
449        /// <param name="m"></param>
450        void ProcessTopic(IRCMessage m)
451        {
452            TopicMessage topicMsg = m as TopicMessage;
453            if (topicMsg == null) return;
454            if (topicMsg.IsServerMessage)
455            {
456                AddLogText(topicMsg.CommandParams[0], "Topic: " + topicMsg.CommandParams[1]);
457                ChangeChannelTopic(topicMsg.CommandParams[0], topicMsg.CommandParams[1]);
458            }
459        }
460
461        void ChangeChannelTopic(String channel, String text)
462        {
463            _channelTopics[channel.ToLower()] = text;
464            //this.Text = String.Format("{0} @ {1} - Criw", _selfNickname, _connectionName);
465        }
466
467        private void textInput_KeyDown_Old(object sender, KeyEventArgs e)
468        {
469            if (!_ircConnection.IsConnected) return;
470
471            if (e.KeyCode == Keys.Enter && textInput.Text.Length > 0)
472            {
473                //AllLogUpdateDelegate("Send: "+textBox1.Text);
474                if (textInput.Text.StartsWith("/"))
475                {
476                    // ���ő��M
477                    try
478                    {
479                        IRCMessage m = IRCMessage.CreateMessage(textInput.Text.Substring(1));
480                        _ircConnection.Send(m.RawMessage);
481                        MessageReceivedOnForm(m);
482                    }
483                    catch (IRCInvalidMessageException ex)
484                    {
485                        MessageBox.Show(ex.ToString());
486                    }
487                }
488                else
489                {
490                    // �I��Ă�������PrivMsg
491                    if (_currentLogName != ConsoleName)
492                    {
493                        // �R���\�[���ȊO
494                        PrivMsgMessage privMsg = new PrivMsgMessage(_currentLogName, textInput.Text);
495                        _ircConnection.Send(privMsg.RawMessage);
496                        MessageReceivedOnForm(privMsg);
497                    }
498                    else
499                    {
500                        // �R���\�[���ł͑��M�ł��Ȃ�
501                        return;
502                    }
503                }
504                textInput.Text = "";
505                e.Handled = true;
506            }
507        }
508
509        private void button3_Click(object sender, EventArgs e)
510        {
511            _ircConnection.Close();
512            this.Close();
513        }
514
515        private void listChannels_SelectedIndexChanged(object sender, EventArgs e)
516        {
517            if (listChannels.SelectedIndices.Count > 0)
518            {
519                Int32 index = listChannels.SelectedIndices[0];
520                System.Diagnostics.Debug.WriteLine(listChannels.Items[index].Text);
521                SetLogView(listChannels.Items[index].Text);
522
523                if (index != 0)
524                {
525                    listChannels.Items[index].SubItems[1].Text = "";
526                }
527
528                UpdateUserList();
529            }
530        }
531
532        /// <summary>
533        ///
534        /// </summary>
535        /// <param name="channel"></param>
536        private void UnreadCountClear(String channel)
537        {
538            foreach (ListViewItem item in listChannels.Items)
539            {
540                if (String.Compare(item.Text, channel, true) == 0)
541                {
542                    item.SubItems[1].Text = "";
543                    break;
544                }
545            }
546        }
547
548        /// <summary>
549        ///
550        /// </summary>
551        /// <param name="channel"></param>
552        private void UnreadCountIncrement(String channel)
553        {
554
555            // ���ǂ�����E���g���Ȃ�
556            if (channel == _currentLogName)
557                return;
558
559            // �I��܂���           foreach (ListViewItem item in listChannels.Items)
560            {
561                if (String.Compare(item.Text, channel, true) == 0)
562                {
563                    // ����
564                    Int32 count = 0;
565                    try
566                    {
567                        if (item.SubItems[1].Text != "")
568                        {
569
570                            count = Int32.Parse(item.SubItems[1].Text);
571                        }
572                    }
573                    catch (FormatException) { }
574
575                    item.SubItems[1].Text = (count + 1).ToString();
576                    break;
577                }
578            }
579        }
580
581        private void UpdateUserList()
582        {
583            listUsers.Items.Clear();
584            if (!_nicknameList.ContainsKey(_currentLogName.ToLower())) return;
585            foreach (String name in _nicknameList[_currentLogName.ToLower()])
586            {
587                listUsers.Items.Add(name);
588            }
589        }
590
591        private void SetLogView(String logName)
592        {
593            textLog.Text = _channelLogs[logName.ToLower()];
594            _currentLogName = logName;
595            textLog.SelectionStart = textLog.Text.Length;
596            textLog.SelectionLength = 0;
597            textLog.ScrollToCaret();
598        }
599
600        private void AddLogText(String logName, String line)
601        {
602            AddLogText(logName, line, false);
603        }
604        private void AddLogText(String logName, String line, Boolean broadcast)
605        {
606            String time = "[" + DateTime.Now.ToString("HH:mm:ss") + "]: ";
607            if (String.Compare(_currentLogName, logName, true) == 0)
608            {
609                // ���I��܂�
610                textLog.SelectionStart = textLog.Text.Length;
611                textLog.SelectionLength = 0;
612                textLog.SelectedText = time + line + "\r\n";
613                textLog.ScrollToCaret();
614            }
615            else
616            {
617                // �I��܂���           }
618
619            if (logName != ConsoleName || broadcast)
620            {
621                if (textAllLog.Text.Length > 2000)
622                {
623                    textAllLog.Text = textAllLog.Text.Substring(500);
624                }
625                textAllLog.SelectionStart = textAllLog.Text.Length;
626                textAllLog.SelectionLength = 0;
627                textAllLog.SelectedText = time + logName + ": " + line + "\r\n";
628                textAllLog.ScrollToCaret();
629            }
630
631            _channelLogs[logName.ToLower()] += time + line + "\r\n";
632            String channelLog = _channelLogs[logName.ToLower()];
633            if (channelLog.Length > 30000)
634            {
635                _channelLogs[logName.ToLower()] = channelLog.Substring(channelLog.Length - 30000);
636            }
637        }
638
639        private void menuItemConnect_Popup(object sender, EventArgs e)
640        {
641            menuItemConnectServers.MenuItems.Clear();
642            menuItemConnectServers.MenuItems.Add(menuItemConnectForm);
643            menuItemConnectServers.MenuItems.Add(menuItemConnectSep);
644            foreach (Connection c in SettingManager.Setting.Connections)
645            {
646                MenuItem m = new MenuItem();
647                m.Text = c.Name;
648                m.Click += new EventHandler(menuItemConnectServerItem_Click);
649                menuItemConnectServers.MenuItems.Add(m);
650            }
651        }
652
653        void menuItemConnectServerItem_Click(object sender, EventArgs e)
654        {
655            MenuItem m = sender as MenuItem;
656
657            if (_ircConnection.IsConnected)
658            {
659                _ircConnection.Disconnect(QuitMesssageText);
660            }
661
662            // �T��...
663            Connection c = SettingManager.Setting.Connections.Find(
664                delegate(Connection con) { return con.Name == m.Text; }
665            );
666            if (c != null)
667            {
668                _autoJoinChannels = c.AutoJoinChannels;
669                _selfNickname = c.NickName;
670                _connectionName = c.Name;
671                _connectionHost = c.Host + ":" + c.Port.ToString();
672                _ircConnection.Connect(c.Host, c.Port, c.UserName, c.Password, c.NickName, c.UserInfo);
673                this.Text = String.Format("{0} @ {1} - Criw", _selfNickname, _connectionName);
674
675                return;
676            }
677        }
678
679        private void menuItemConnectForm_Click(object sender, EventArgs e)
680        {
681            (new ConnectionForm()).ShowDialog();
682        }
683
684        private void menuItemExit_Click(object sender, EventArgs e)
685        {
686            if (_ircConnection.IsConnected)
687            {
688                _ircConnection.Disconnect(QuitMesssageTextOnApplicationExit);
689            }
690            this.Close();
691        }
692
693        private void menuItemChannelJoin_Click(object sender, EventArgs e)
694        {
695            if (_ircConnection.IsConnected)
696            {
697                JoinForm joinForm = new JoinForm();
698                if (joinForm.ShowDialog() == DialogResult.OK)
699                {
700                    _ircConnection.Send(new JoinMessage(joinForm.ChannelName, "").RawMessage);
701                }
702            }
703        }
704
705        private void menuItemChannelPart_Click(object sender, EventArgs e)
706        {
707            if (_ircConnection.IsConnected && _currentLogName != ConsoleName)
708            {
709                _ircConnection.Send(new PartMessage(_currentLogName, PartMessageText).RawMessage);
710            }
711        }
712
713        private void menuItemChannelTopic_Click(object sender, EventArgs e)
714        {
715
716        }
717
718        private void menuItemConnectDisconnect_Click(object sender, EventArgs e)
719        {
720            if (_ircConnection.IsConnected)
721            {
722                _ircConnection.Disconnect(QuitMesssageText);
723            }
724        }
725
726        private void textInput_KeyPress(object sender, KeyPressEventArgs e)
727        {
728            if (!_ircConnection.IsConnected) return;
729
730            if (e.KeyChar == '\r')
731            {
732                if (textInput.Text.Length > 0)
733                {
734                    // ���b�Z�[�W���M
735                    //AllLogUpdateDelegate("Send: "+textBox1.Text);
736                    if (textInput.Text.StartsWith("/"))
737                    {
738                        if (textInput.Text.StartsWith("/font "))
739                        {
740                            // �t�H���g�T�C�Y�ݒ�                            try
741                            {
742                                Single fontSize = Single.Parse(textInput.Text.Substring(6));
743                                textAllLog.Font = new Font(textAllLog.Font.Name, fontSize, textAllLog.Font.Style);
744                                textLog.Font = new Font(textLog.Font.Name, fontSize, textLog.Font.Style);
745                                SettingManager.Setting.ChannelLogTextFontSize = fontSize;
746                                SettingManager.Save();
747                            }
748                            catch (FormatException)
749                            {
750                            }
751                        }
752                        else
753                        {
754                            // ���ő��M
755                            try
756                            {
757                                IRCMessage m = IRCMessage.CreateMessage(textInput.Text.Substring(1));
758                                _ircConnection.Send(m.RawMessage);
759                                MessageReceivedOnForm(m);
760                            }
761                            catch (IRCInvalidMessageException ex)
762                            {
763                                MessageBox.Show(ex.ToString());
764                            }
765                        }
766                    }
767                    else
768                    {
769                        // �I��Ă�������PrivMsg
770                        if (_currentLogName != ConsoleName)
771                        {
772                            // �R���\�[���ȊO
773                            PrivMsgMessage privMsg = new PrivMsgMessage(_currentLogName, textInput.Text);
774                            _ircConnection.Send(privMsg.RawMessage);
775                            MessageReceivedOnForm(privMsg);
776                        }
777                        else
778                        {
779                            // �R���\�[���ł͑��M�ł��Ȃ�
780                            return;
781                        }
782                    }
783                    textInput.Text = "";
784                    e.Handled = true;
785                }
786            }
787        }
788
789        /// <summary>
790        ///
791        /// </summary>
792        /// <param name="reverse"></param>
793        private void NextChannel(bool reverse)
794        {
795            // �`�����l���؂���
796            Debug.Assert(listChannels.Items.Count != 0);
797            Int32 selectedIndex =
798                listChannels.SelectedIndices.Count == 0 ?
799                    0 : listChannels.SelectedIndices[0];
800
801            // �܂���
802            listChannels.Items[selectedIndex].Selected = false;
803
804            selectedIndex += (reverse ? -1 : 1);
805
806            if (selectedIndex == -1)
807            {
808                listChannels.Items[listChannels.Items.Count - 1].Selected = true;
809            }
810            else if (selectedIndex == listChannels.Items.Count)
811            {
812                listChannels.Items[0].Selected = true;
813            }
814            else
815            {
816                listChannels.Items[selectedIndex].Selected = true;
817            }
818        }
819
820        /// <summary>
821        ///
822        /// </summary>
823        /// <param name="sender"></param>
824        /// <param name="e"></param>
825        private void textInput_KeyUp(object sender, KeyEventArgs e)
826        {
827            if (e.Shift && (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down))
828            {
829                NextChannel(e.KeyCode == Keys.Up);
830            }
831        }
832
833        [DllImport("coredll.dll")]
834        private extern static UInt32 SendMessage(IntPtr hWnd, UInt32 Msg, UInt32 wParam, UInt32 lParam);
835
836        /// <summary>
837        ///
838        /// </summary>
839        /// <param name="sender"></param>
840        /// <param name="e"></param>
841        private void menuItemNext_Click(object sender, EventArgs e)
842        {
843            NextChannel(false);
844        }
845
846        /// <summary>
847        ///
848        /// </summary>
849        /// <param name="sender"></param>
850        /// <param name="e"></param>
851        private void menuItemChannelPrev_Click(object sender, EventArgs e)
852        {
853            NextChannel(true);
854        }
855
856        /// <summary>
857        ///
858        /// </summary>
859        /// <param name="sender"></param>
860        /// <param name="e"></param>
861        private void timerPing_Tick(object sender, EventArgs e)
862        {
863            if (_ircConnection.IsConnected)
864            {
865                _ircConnection.Send("PONG :"+_selfNickname);
866            }
867        }
868    }
869}
Note: See TracBrowser for help on using the browser.