OSDN Git Service

enum Materialの順序を間違えているのを直す
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / LogDialog.cs
1 // Copyright (C) 2014 Kazuhiro Fujieda <fujieda@users.sourceforge.jp>\r
2 // \r
3 // This program is part of KancolleSniffer.\r
4 //\r
5 // KancolleSniffer is free software: you can redistribute it and/or modify\r
6 // it under the terms of the GNU General Public License as published by\r
7 // the Free Software Foundation, either version 3 of the License, or\r
8 // (at your option) any later version.\r
9 //\r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 //\r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, see <http://www.gnu.org/licenses/>.\r
17 \r
18 using System;\r
19 using System.Windows.Forms;\r
20 \r
21 namespace KancolleSniffer\r
22 {\r
23     public partial class LogDialog : Form\r
24     {\r
25         private readonly LogConfig _config;\r
26         private readonly MainForm _main;\r
27 \r
28         public LogDialog(LogConfig config, MainForm main)\r
29         {\r
30             InitializeComponent();\r
31             numericUpDownMaterialLogInterval.Maximum = 1440;\r
32             _config = config;\r
33             _main = main;\r
34         }\r
35 \r
36         private void LogDialog_Load(object sender, EventArgs e)\r
37         {\r
38             checkBoxOutput.Checked = _config.On;\r
39             textBoxOutput.Text = _config.OutputDir;\r
40             textBoxOutput.Select(textBoxOutput.Text.Length, 0);\r
41             folderBrowserDialogOutputDir.SelectedPath = _config.OutputDir;\r
42             numericUpDownMaterialLogInterval.Value = _config.MaterialLogInterval;\r
43             (_config.ServerOn ? radioButtonServerOn : radioButtonServerOff).PerformClick();\r
44             textBoxListen.Text = _config.Listen.ToString("D");\r
45         }\r
46 \r
47         private void radioButtonServerOn_CheckedChanged(object sender, EventArgs e)\r
48         {\r
49             var on = ((RadioButton)sender).Checked;\r
50             textBoxListen.Enabled = on;\r
51             labelListen.Enabled = on;\r
52         }\r
53 \r
54         private void buttonOk_Click(object sender, EventArgs e)\r
55         {\r
56             var listen = -1;\r
57             if (radioButtonServerOn.Checked && !ValidatePortNumber(textBoxListen, out listen))\r
58                 return;\r
59             _config.ServerOn = radioButtonServerOn.Checked;\r
60             if (_config.ServerOn)\r
61                 _config.Listen = listen;\r
62             _config.MaterialLogInterval = (int)numericUpDownMaterialLogInterval.Value;\r
63             _config.OutputDir = textBoxOutput.Text;\r
64             _main.ApplyLogSetting();\r
65             DialogResult = DialogResult.OK;\r
66         }\r
67 \r
68         private bool ValidatePortNumber(TextBox textBox, out int result)\r
69         {\r
70             var s = textBox.Text;\r
71             if (!int.TryParse(s, out result))\r
72             {\r
73                 ShowToolTip("数字を入力してください。", textBox);\r
74                 return false;\r
75             }\r
76             if (result <= 0)\r
77             {\r
78                 ShowToolTip("0より大きい数字を入力してください。", textBox);\r
79                 return false;\r
80             }\r
81             return true;\r
82         }\r
83 \r
84         private void ShowToolTip(string message, Control control)\r
85         {\r
86             toolTipError.Show(message, control, 0, control.Height, 3000);\r
87         }\r
88 \r
89         private void buttonOutputDir_Click(object sender, EventArgs e)\r
90         {\r
91             if (folderBrowserDialogOutputDir.ShowDialog(this) == DialogResult.OK)\r
92                 textBoxOutput.Text = folderBrowserDialogOutputDir.SelectedPath;\r
93             textBoxOutput.Select(textBoxOutput.Text.Length, 0);\r
94         }\r
95     }\r
96 }\r