OSDN Git Service

プロフィール画面へのD&Dによるアイコン変更時に確認ダイアログを表示するように変更
[opentween/open-tween.git] / OpenTween / ListAvailable.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 // All rights reserved.
8 // 
9 // This file is part of OpenTween.
10 // 
11 // This program is free software; you can redistribute it and/or modify it
12 // under the terms of the GNU General Public License as published by the Free
13 // Software Foundation; either version 3 of the License, or (at your option)
14 // any later version.
15 // 
16 // This program is distributed in the hope that it will be useful, but
17 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 // for more details. 
20 // 
21 // You should have received a copy of the GNU General Public License along
22 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
23 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
24 // Boston, MA 02110-1301, USA.
25
26 using System;
27 using System.Collections.Generic;
28 using System.ComponentModel;
29 using System.Data;
30 using System.Drawing;
31 using System.Linq;
32 using System.Text;
33 using System.Windows.Forms;
34
35 namespace OpenTween
36 {
37     public partial class ListAvailable : OTBaseForm
38     {
39         private ListElement _selectedList = null;
40         public ListElement SelectedList
41         {
42             get
43             {
44                 return _selectedList;
45             }
46         }
47
48         public ListAvailable()
49         {
50             InitializeComponent();
51         }
52
53         private void OK_Button_Click(object sender, EventArgs e)
54         {
55             if (this.ListsList.SelectedIndex > -1) {
56                 _selectedList = (ListElement)this.ListsList.SelectedItem;
57                 this.DialogResult = System.Windows.Forms.DialogResult.OK;
58                 this.Close();
59             }
60         }
61
62         private void Cancel_Button_Click(object sender, EventArgs e)
63         {
64             _selectedList = null;
65             this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
66             this.Close();
67         }
68
69         private void ListAvailable_Shown(object sender, EventArgs e)
70         {
71             if (TabInformations.GetInstance().SubscribableLists.Count == 0) this.RefreshLists();
72             this.ListsList.Items.AddRange(TabInformations.GetInstance().SubscribableLists.ToArray());
73             if (this.ListsList.Items.Count > 0)
74             {
75                 this.ListsList.SelectedIndex = 0;
76             }
77             else
78             {
79                 this.UsernameLabel.Text = "";
80                 this.NameLabel.Text = "";
81                 this.StatusLabel.Text = "";
82                 this.MemberCountLabel.Text = "0";
83                 this.SubscriberCountLabel.Text = "0";
84                 this.DescriptionText.Text = "";
85             }
86         }
87
88         private void ListsList_SelectedIndexChanged(object sender, EventArgs e)
89         {
90             ListElement lst;
91             if (this.ListsList.SelectedIndex > -1)
92             {
93                 lst = (ListElement)this.ListsList.SelectedItem;
94             }
95             else
96             {
97                 lst = null;
98             }
99             if (lst == null)
100             {
101                 this.UsernameLabel.Text = "";
102                 this.NameLabel.Text = "";
103                 this.StatusLabel.Text = "";
104                 this.MemberCountLabel.Text = "0";
105                 this.SubscriberCountLabel.Text = "0";
106                 this.DescriptionText.Text = "";
107             }
108             else
109             {
110                 this.UsernameLabel.Text = lst.Username + " / " + lst.Nickname;
111                 this.NameLabel.Text = lst.Name;
112                 if (lst.IsPublic)
113                 {
114                     this.StatusLabel.Text = "Public";
115                 }
116                 else
117                 {
118                     this.StatusLabel.Text = "Private";
119                 }
120                 this.MemberCountLabel.Text = lst.MemberCount.ToString("#,##0");
121                 this.SubscriberCountLabel.Text = lst.SubscriberCount.ToString("#,##0");
122                 this.DescriptionText.Text = lst.Description;
123             }
124         }
125
126         private void RefreshButton_Click(object sender, EventArgs e)
127         {
128             this.RefreshLists();
129             this.ListsList.Items.Clear();
130             this.ListsList.Items.AddRange(TabInformations.GetInstance().SubscribableLists.ToArray());
131             if (this.ListsList.Items.Count > 0)
132             {
133                 this.ListsList.SelectedIndex = 0;
134             }
135         }
136
137         private void RefreshLists()
138         {
139             using (FormInfo dlg = new FormInfo(this, "Getting Lists...", RefreshLists_DoWork))
140             {
141                 dlg.ShowDialog();
142                 if (!String.IsNullOrEmpty(dlg.Result as String))
143                 {
144                     MessageBox.Show("Failed to get lists. (" + (String)dlg.Result + ")");
145                     return;
146                 }
147             }
148         }
149
150         private void RefreshLists_DoWork(object sender, DoWorkEventArgs e)
151         {
152             try
153             {
154                 e.Result = ((TweenMain)this.Owner).TwitterInstance.GetListsApi();
155             }
156             catch (InvalidCastException)
157             {
158                 return;
159             }
160         }
161     }
162 }