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.
10 // This file is part of OpenTween.
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)
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
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.
30 using System.Collections.Generic;
31 using System.ComponentModel;
36 using System.Threading.Tasks;
37 using System.Windows.Forms;
40 namespace OpenTween.Setting.Panel
42 public partial class ShortUrlPanel : SettingPanelBase
44 public ShortUrlPanel()
45 => this.InitializeComponent();
47 public void LoadConfig(SettingCommon settingCommon)
49 this.CheckTinyURL.Checked = settingCommon.TinyUrlResolve;
51 // 使われていない設定項目 (Tween v1.0.5.0)
52 this.CheckAutoConvertUrl.Checked = false;
53 this.ShortenTcoCheck.Enabled = this.CheckAutoConvertUrl.Checked;
55 this.ComboBoxAutoShortUrlFirst.SelectedIndex = (int)settingCommon.AutoShortUrlFirst;
56 this.TextBitlyAccessToken.Text = settingCommon.BitlyAccessToken;
57 this.TextBitlyAccessToken.Modified = false;
60 public void SaveConfig(SettingCommon settingCommon)
62 settingCommon.TinyUrlResolve = this.CheckTinyURL.Checked;
63 settingCommon.UrlConvertAuto = this.CheckAutoConvertUrl.Checked;
64 settingCommon.AutoShortUrlFirst = (MyCommon.UrlConverter)this.ComboBoxAutoShortUrlFirst.SelectedIndex;
65 settingCommon.BitlyAccessToken = this.TextBitlyAccessToken.Text;
68 private void ComboBoxAutoShortUrlFirst_SelectedIndexChanged(object sender, EventArgs e)
70 if (this.ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Bitly ||
71 this.ComboBoxAutoShortUrlFirst.SelectedIndex == (int)MyCommon.UrlConverter.Jmp)
73 this.Label77.Enabled = true;
74 this.TextBitlyAccessToken.Enabled = true;
75 this.ButtonBitlyAuthorize.Enabled = true;
79 this.Label77.Enabled = false;
80 this.TextBitlyAccessToken.Enabled = false;
81 this.ButtonBitlyAuthorize.Enabled = false;
85 private void CheckAutoConvertUrl_CheckedChanged(object sender, EventArgs e)
86 => this.ShortenTcoCheck.Enabled = this.CheckAutoConvertUrl.Checked;
88 private void ButtonBitlyAuthorize_Click(object sender, EventArgs e)
90 using var dialog = new LoginDialog();
92 const string DialogText = "Bitly Login";
93 dialog.Text = DialogText;
95 string? accessToken = null;
96 dialog.LoginCallback = async () =>
100 var bitly = new BitlyApi();
101 accessToken = await bitly.GetAccessTokenAsync(dialog.LoginName, dialog.Password);
104 catch (WebApiException ex)
106 var text = string.Format(Properties.Resources.BitlyAuthorize_ErrorText, ex.Message);
107 MessageBox.Show(dialog, text, DialogText, MessageBoxButtons.OK, MessageBoxIcon.Error);
112 if (dialog.ShowDialog(this.ParentForm) == DialogResult.OK)
114 this.TextBitlyAccessToken.Text = accessToken;