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

Revision 1736, 4.4 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.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8
9namespace Misuzilla.Applications.Mobile.Criw0
10{
11    public partial class ConnectionForm : Form
12    {
13        private List<String> _autoJoinChannels;
14
15        public ConnectionForm()
16        {
17            InitializeComponent();
18
19            foreach (Connection c in SettingManager.Setting.Connections)
20            {
21                comboConnectionName.Items.Add(c);
22            }
23            comboConnectionName.SelectedIndexChanged += new EventHandler(comboConnectionName_SelectedIndexChanged);
24        }
25
26        void comboConnectionName_SelectedIndexChanged(object sender, EventArgs e)
27        {
28            Connection c = comboConnectionName.SelectedItem as Connection;
29            textHost.Text = c.Host;
30            textNickname.Text = c.NickName;
31            textPassword.Text = c.Password;
32            textUserInfo.Text = c.UserInfo;
33            textUserName.Text = c.UserName;
34            numPort.Value = c.Port;
35            _autoJoinChannels = c.AutoJoinChannels;
36        }
37
38        private void menuItemClose_Click(object sender, EventArgs e)
39        {
40            this.Close();
41        }
42
43        private void menuItemSave_Click(object sender, EventArgs e)
44        {
45            if (!ValidateInputValues()) return;
46
47            Connection connSetting = null;
48            String name = comboConnectionName.Text.Trim();
49
50            foreach (Connection c in SettingManager.Setting.Connections)
51            {
52                if (c.Name == name)
53                {
54                    connSetting = c;
55                    break;
56                }
57            }
58
59            if (connSetting == null)
60            {
61                connSetting = new Connection();
62                connSetting.Name = name;
63                comboConnectionName.Items.Add(connSetting);
64                SettingManager.Setting.Connections.Add(connSetting);
65            }
66            connSetting.Host = textHost.Text;
67            connSetting.NickName = textNickname.Text;
68            connSetting.Port = (Int32)numPort.Value;
69            connSetting.UserInfo = textUserInfo.Text;
70            connSetting.UserName = textUserName.Text;
71            connSetting.Password = textPassword.Text;
72            connSetting.AutoJoinChannels = _autoJoinChannels;
73
74            SettingManager.Save();
75        }
76
77        private Boolean ValidateInputValues()
78        {
79            if (comboConnectionName.Text.Trim().Length == 0)
80            {
81                MessageBox.Show("�ڑ�����肵�Ă��������B", "�ڑ��̐ݒ����[ - Criw", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
82                return false;
83            }
84            if (textHost.Text.Trim().Length == 0)
85            {
86                MessageBox.Show("�z�X�g����肵�Ă��������B", "�ڑ��̐ݒ����[ - Criw", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
87                return false;
88            }
89            if (numPort.Value == 0)
90            {
91                MessageBox.Show("�|�[�g���ȏ�535�ȉ��̒l��肵�Ă��������B", "�ڑ��̐ݒ����[ - Criw", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
92                return false;
93            }
94            if (textUserName.Text.Trim().Length == 0)
95            {
96                MessageBox.Show("���[�U����肵�Ă��������B", "�ڑ��̐ݒ����[ - Criw", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
97                return false;
98            }
99            if (textNickname.Text.Trim().Length == 0)
100            {
101                MessageBox.Show("�j�b�N�l�[����肵�Ă��������B", "�ڑ��̐ݒ����[ - Criw", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
102                return false;
103            }
104
105            // TODO: �������Ƃ�����`�F�b�N����
106            return true;
107
108        }
109
110        private void buttonAutoJoin_Click(object sender, EventArgs e)
111        {
112            AutoJoinSettingForm autoJoinForm = new AutoJoinSettingForm();
113            autoJoinForm.Channels = _autoJoinChannels;
114            if (autoJoinForm.ShowDialog() == DialogResult.OK)
115            {
116                _autoJoinChannels = autoJoinForm.Channels;
117            }
118        }
119    }
120}
Note: See TracBrowser for help on using the browser.