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.
9 // This file is part of OpenTween.
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)
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
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.
27 using System.Collections.Generic;
28 using System.ComponentModel;
33 using System.Threading.Tasks;
34 using System.Windows.Forms;
35 using OpenTween.Models;
39 public partial class ListAvailable : OTBaseForm
41 private ListElement _selectedList = null;
42 public ListElement SelectedList
50 public ListAvailable()
52 InitializeComponent();
55 private void OK_Button_Click(object sender, EventArgs e)
57 if (this.ListsList.SelectedIndex > -1) {
58 _selectedList = (ListElement)this.ListsList.SelectedItem;
59 this.DialogResult = System.Windows.Forms.DialogResult.OK;
64 private void Cancel_Button_Click(object sender, EventArgs e)
67 this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
71 private async void ListAvailable_Shown(object sender, EventArgs e)
73 using (ControlTransaction.Disabled(this))
77 var lists = (IReadOnlyList<ListElement>)TabInformations.GetInstance().SubscribableLists;
79 lists = await this.FetchListsAsync();
81 this.UpdateListsListBox(lists);
83 catch (OperationCanceledException)
85 this.DialogResult = DialogResult.Cancel;
88 catch (WebApiException)
90 this.DialogResult = DialogResult.Abort;
96 private void ListsList_SelectedIndexChanged(object sender, EventArgs e)
99 if (this.ListsList.SelectedIndex > -1)
101 lst = (ListElement)this.ListsList.SelectedItem;
109 this.UsernameLabel.Text = "";
110 this.NameLabel.Text = "";
111 this.StatusLabel.Text = "";
112 this.MemberCountLabel.Text = "0";
113 this.SubscriberCountLabel.Text = "0";
114 this.DescriptionText.Text = "";
118 this.UsernameLabel.Text = lst.Username + " / " + lst.Nickname;
119 this.NameLabel.Text = lst.Name;
122 this.StatusLabel.Text = "Public";
126 this.StatusLabel.Text = "Private";
128 this.MemberCountLabel.Text = lst.MemberCount.ToString("#,##0");
129 this.SubscriberCountLabel.Text = lst.SubscriberCount.ToString("#,##0");
130 this.DescriptionText.Text = lst.Description;
134 private async void RefreshButton_Click(object sender, EventArgs e)
136 using (ControlTransaction.Disabled(this))
140 var lists = await this.FetchListsAsync();
141 this.UpdateListsListBox(lists);
143 catch (OperationCanceledException) { }
144 catch (WebApiException ex)
146 MessageBox.Show("Failed to get lists. (" + ex.Message + ")");
151 private async Task<IReadOnlyList<ListElement>> FetchListsAsync()
153 using (var dialog = new WaitingDialog("Getting Lists..."))
155 var cancellationToken = dialog.EnableCancellation();
157 var tw = ((TweenMain)this.Owner).TwitterInstance;
158 var task = tw.GetListsApi();
159 await dialog.WaitForAsync(this, task);
161 cancellationToken.ThrowIfCancellationRequested();
164 return TabInformations.GetInstance().SubscribableLists;
167 private void UpdateListsListBox(IEnumerable<ListElement> lists)
169 using (ControlTransaction.Update(this.ListsList))
171 this.ListsList.Items.Clear();
172 this.ListsList.Items.AddRange(lists.ToArray());
173 if (this.ListsList.Items.Count > 0)
175 this.ListsList.SelectedIndex = 0;
179 this.UsernameLabel.Text = "";
180 this.NameLabel.Text = "";
181 this.StatusLabel.Text = "";
182 this.MemberCountLabel.Text = "0";
183 this.SubscriberCountLabel.Text = "0";
184 this.DescriptionText.Text = "";