-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSettingsForm.cs
197 lines (168 loc) · 9.21 KB
/
SettingsForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace uTorrentNotifier
{
public partial class SettingsForm : Form
{
//private Version _Version;
private oAuthTwitter oAuth;
private ClassRegistry ClassRegistry;
public SettingsForm(ClassRegistry classRegistry)
{
this.ClassRegistry = classRegistry;
InitializeComponent();
}
private void SettingsForm_Shown(object sender, System.EventArgs e)
{
this.lblVersion.Text = ClassRegistry.Version.ToString();
this.SetConfig();
}
private void SetConfig()
{
this.tbPassword.Text = this.ClassRegistry.Config.Password;
this.tbUsername.Text = this.ClassRegistry.Config.UserName;
this.tbWebUI_URL.Text = this.ClassRegistry.Config.Uri;
this.cbRunOnStartup.Checked = this.ClassRegistry.Config.RunOnStartup;
this.cbShowBalloonTips.Checked = this.ClassRegistry.Config.ShowBalloonTips;
this.cbCheckForUpdates.Checked = this.ClassRegistry.Config.CheckForUpdates;
this.tbProwlAPIKey.Text = this.ClassRegistry.Config.Prowl.ApiKey;
this.cbProwlEnable.Checked = this.ClassRegistry.Config.Prowl.Enable;
this.cbGrowlEnable.Checked = this.ClassRegistry.Config.Growl.Enable;
this.tbGrowlPassword.Text = this.ClassRegistry.Config.Growl.Password;
this.tbGrowlHost.Text = this.ClassRegistry.Config.Growl.Host;
this.tbGrowlPort.Text = this.ClassRegistry.Config.Growl.Port;
this.tbTwitterPIN.Text = this.ClassRegistry.Config.Twitter.Pin;
this.tbTwitterPrefixTweet.Text = this.ClassRegistry.Config.Twitter.PrefixTweet;
this.cbTwitterEnable.Checked = this.ClassRegistry.Config.Twitter.Enable;
this.cbBoxcarEnable.Checked = this.ClassRegistry.Config.Boxcar.Enable;
this.tbBoxcarEmail.Text = this.ClassRegistry.Config.Boxcar.Email;
this.tbBoxcarAPIKey.Text = this.ClassRegistry.Config.Boxcar.APIKey;
this.cbProwlNotification_TorentAdded.Checked = this.ClassRegistry.Config.Notifications.TorrentAdded;
this.cbTorrentNotification_DownloadComplete.Checked = this.ClassRegistry.Config.Notifications.DownloadComplete;
}
private void btnSave_Click(object sender, EventArgs e)
{
this.ClassRegistry.Config.Uri = this.tbWebUI_URL.Text;
this.ClassRegistry.Config.UserName = this.tbUsername.Text;
this.ClassRegistry.Config.Password = this.tbPassword.Text;
this.ClassRegistry.Config.RunOnStartup = this.cbRunOnStartup.Checked;
this.ClassRegistry.Config.ShowBalloonTips = this.cbShowBalloonTips.Checked;
this.ClassRegistry.Config.CheckForUpdates = this.cbCheckForUpdates.Checked;
this.ClassRegistry.Config.Prowl.ApiKey = this.tbProwlAPIKey.Text;
this.ClassRegistry.Config.Prowl.Enable = this.cbProwlEnable.Checked;
this.ClassRegistry.Config.Growl.Enable = this.cbGrowlEnable.Checked;
this.ClassRegistry.Config.Growl.Password = this.tbGrowlPassword.Text;
this.ClassRegistry.Config.Growl.Host = this.tbGrowlHost.Text;
this.ClassRegistry.Config.Growl.Port = this.tbGrowlPort.Text;
this.ClassRegistry.Config.Twitter.PrefixTweet = this.tbTwitterPrefixTweet.Text;
this.ClassRegistry.Config.Twitter.Enable = this.cbTwitterEnable.Checked;
this.ClassRegistry.Config.Boxcar.Enable = this.cbBoxcarEnable.Checked;
this.ClassRegistry.Config.Boxcar.Email = this.tbBoxcarEmail.Text;
this.ClassRegistry.Config.Boxcar.APIKey = this.tbBoxcarAPIKey.Text;
this.ClassRegistry.Config.Notifications.TorrentAdded = this.cbProwlNotification_TorentAdded.Checked;
this.ClassRegistry.Config.Notifications.DownloadComplete = this.cbTorrentNotification_DownloadComplete.Checked;
this.ClassRegistry.Config.Save();
this.Hide();
if (!this.ClassRegistry.uTorrent.Stopped)
this.ClassRegistry.uTorrent.Stop();
this.ClassRegistry.uTorrent.Start();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Hide();
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start("http://ejholmes.github.com/uTorrent-Notifier/");
}
private void btnStartAuthorization_Click(object sender, EventArgs e)
{
oAuth = new oAuthTwitter();
oAuth.ConsumerKey = this.ClassRegistry.Config.Twitter.ConsumerKey;
oAuth.ConsumerSecret = this.ClassRegistry.Config.Twitter.ConsumerSecret;
this.ClassRegistry.Config.Twitter.Pin = String.Empty;
this.ClassRegistry.Config.Twitter.Token = String.Empty;
this.ClassRegistry.Config.Twitter.TokenSecret = String.Empty;
string oAuthLink = oAuth.AuthorizationLinkGet();
try
{
Process.Start(oAuthLink);
tbTwitterPIN.Text = String.Empty;
tbTwitterPIN.Enabled = true;
lblTwitterPIN.Enabled = true;
btnTwitterAuthorize.Enabled = true;
}
catch
{
tbTwitterPIN.Text = String.Empty;
lblTwitterPIN.Enabled = false;
tbTwitterPIN.Enabled = false;
btnTwitterAuthorize.Enabled = false;
MessageBox.Show("An error occurred trying to authenticate. Check your network settings and browser config, and try again.", "uTorrent Notifier - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnTwitterAuthorize_Click(object sender, EventArgs e)
{
string PIN = tbTwitterPIN.Text;
if (!string.IsNullOrEmpty(PIN))
{
PIN = PIN.Trim();
}
else
{
MessageBox.Show("Copy and paste the authentication PIN code from Twitter", "uTorrent Notifier - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
oAuth.AccessTokenGet(oAuth.OAuthToken, PIN);
this.ClassRegistry.Config.Twitter.Token = oAuth.Token;
this.ClassRegistry.Config.Twitter.TokenSecret = oAuth.TokenSecret;
this.ClassRegistry.Config.Twitter.Pin = PIN;
tbTwitterPIN.Enabled = false;
btnTwitterAuthorize.Enabled = false;
MessageBox.Show("Successfully authenticated with Twitter", "uTorrent Notifier - Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch
{
this.ClassRegistry.Config.Twitter.Pin = String.Empty;
tbTwitterPIN.Text = String.Empty;
lblTwitterPIN.Enabled = false;
tbTwitterPIN.Enabled = false;
btnTwitterAuthorize.Enabled = false;
MessageBox.Show("An error occurred trying to authenticate. Check your network settings and browser config, and try again.", "uTorrent Notifier - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnSendTestTweet_Click(object sender, EventArgs e)
{
bool bCanSend=true;
if (this.ClassRegistry.Twitter == null) bCanSend = false;
if(!this.cbTwitterEnable.Checked) bCanSend=false;
if(bCanSend)
{
this.ClassRegistry.Twitter.Update("Congratulations! Twitter notifications from uTorrent Notifier are working correctly :)");
MessageBox.Show("A test tweet has been sent...", "uTorrent Notifier - Test sent", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("uTorrent Notifier must be authenticated and enabled before testing. Please check your settings, and try again.", "uTorrent Notifier - Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void btnBoxcarGetAPIKey_Click(object sender, EventArgs e)
{
Process.Start("http://boxcar.io/site/providers/new");
}
}
}