OSDN Git Service

TweetPrvPanelに対する設定値の設定・取得を LoadConfing/SaveConfig メソッドに移動
[opentween/open-tween.git] / OpenTween / Setting / Panel / TweetPrvPanel.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 //           (c) 2008-2011 Moz (@syo68k)
4 //           (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 //           (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 //           (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7 //           (c) 2014      kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
8 // All rights reserved.
9 //
10 // This file is part of OpenTween.
11 //
12 // This program is free software; you can redistribute it and/or modify it
13 // under the terms of the GNU General Public License as published by the Free
14 // Software Foundation; either version 3 of the License, or (at your option)
15 // any later version.
16 //
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 // for more details.
21 //
22 // You should have received a copy of the GNU General Public License along
23 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25 // Boston, MA 02110-1301, USA.
26
27 using System;
28 using System.Collections.Generic;
29 using System.ComponentModel;
30 using System.Drawing;
31 using System.Data;
32 using System.Linq;
33 using System.Text;
34 using System.Windows.Forms;
35
36 namespace OpenTween.Setting.Panel
37 {
38     public partial class TweetPrvPanel : SettingPanelBase
39     {
40         public TweetPrvPanel()
41         {
42             InitializeComponent();
43         }
44
45         public void LoadConfig(SettingCommon settingCommon)
46         {
47             switch (settingCommon.IconSize)
48             {
49                 case MyCommon.IconSizes.IconNone:
50                     this.IconSize.SelectedIndex = 0;
51                     break;
52                 case MyCommon.IconSizes.Icon16:
53                     this.IconSize.SelectedIndex = 1;
54                     break;
55                 case MyCommon.IconSizes.Icon24:
56                     this.IconSize.SelectedIndex = 2;
57                     break;
58                 case MyCommon.IconSizes.Icon48:
59                     this.IconSize.SelectedIndex = 3;
60                     break;
61                 case MyCommon.IconSizes.Icon48_2:
62                     this.IconSize.SelectedIndex = 4;
63                     break;
64             }
65
66             this.OneWayLv.Checked = settingCommon.OneWayLove;
67             this.CheckSortOrderLock.Checked = settingCommon.SortOrderLock;
68             this.CheckViewTabBottom.Checked = settingCommon.ViewTabBottom;
69             this.chkUnreadStyle.Checked = settingCommon.UseUnreadStyle;
70
71             //書式指定文字列エラーチェック
72             var dateTimeFormat = settingCommon.DateTimeFormat;
73             try
74             {
75                 if (DateTime.Now.ToString(dateTimeFormat).Length == 0)
76                 {
77                     // このブロックは絶対に実行されないはず
78                     // 変換が成功した場合にLengthが0にならない
79                     dateTimeFormat = "yyyy/MM/dd H:mm:ss";
80                 }
81             }
82             catch (FormatException)
83             {
84                 // FormatExceptionが発生したら初期値を設定 (=yyyy/MM/dd H:mm:ssとみなされる)
85                 dateTimeFormat = "yyyy/MM/dd H:mm:ss";
86             }
87             this.CmbDateTimeFormat.Text = dateTimeFormat;
88
89             this.CheckShowGrid.Checked = settingCommon.ShowGrid;
90             this.HideDuplicatedRetweetsCheck.Checked = settingCommon.HideDuplicatedRetweets;
91             this.IsListsIncludeRtsCheckBox.Checked = settingCommon.IsListsIncludeRts;
92         }
93
94         public void SaveConfig(SettingCommon settingCommon)
95         {
96             switch (this.IconSize.SelectedIndex)
97             {
98                 case 0:
99                     settingCommon.IconSize = MyCommon.IconSizes.IconNone;
100                     break;
101                 case 1:
102                     settingCommon.IconSize = MyCommon.IconSizes.Icon16;
103                     break;
104                 case 2:
105                     settingCommon.IconSize = MyCommon.IconSizes.Icon24;
106                     break;
107                 case 3:
108                     settingCommon.IconSize = MyCommon.IconSizes.Icon48;
109                     break;
110                 case 4:
111                     settingCommon.IconSize = MyCommon.IconSizes.Icon48_2;
112                     break;
113             }
114
115             settingCommon.OneWayLove = this.OneWayLv.Checked;
116             settingCommon.SortOrderLock = this.CheckSortOrderLock.Checked;
117             settingCommon.ViewTabBottom = this.CheckViewTabBottom.Checked;
118             settingCommon.UseUnreadStyle = this.chkUnreadStyle.Checked;
119             settingCommon.DateTimeFormat = this.CmbDateTimeFormat.Text;
120             settingCommon.ShowGrid = this.CheckShowGrid.Checked;
121             settingCommon.HideDuplicatedRetweets = this.HideDuplicatedRetweetsCheck.Checked;
122             settingCommon.IsListsIncludeRts = this.IsListsIncludeRtsCheckBox.Checked;
123         }
124
125         private bool CreateDateTimeFormatSample()
126         {
127             try
128             {
129                 LabelDateTimeFormatApplied.Text = DateTime.Now.ToString(CmbDateTimeFormat.Text);
130             }
131             catch (FormatException)
132             {
133                 LabelDateTimeFormatApplied.Text = Properties.Resources.CreateDateTimeFormatSampleText1;
134                 return false;
135             }
136             return true;
137         }
138
139         private void CmbDateTimeFormat_TextUpdate(object sender, EventArgs e)
140         {
141             CreateDateTimeFormatSample();
142         }
143
144         private void CmbDateTimeFormat_SelectedIndexChanged(object sender, EventArgs e)
145         {
146             CreateDateTimeFormatSample();
147         }
148
149         private void CmbDateTimeFormat_Validating(object sender, CancelEventArgs e)
150         {
151             if (!CreateDateTimeFormatSample())
152             {
153                 MessageBox.Show(Properties.Resources.CmbDateTimeFormat_Validating);
154                 e.Cancel = true;
155             }
156         }
157
158         private void LabelDateTimeFormatApplied_VisibleChanged(object sender, EventArgs e)
159         {
160             CreateDateTimeFormatSample();
161         }
162     }
163 }