~cszikszoy/do-plugins/pastebin

« back to all changes in this revision

Viewing changes to Twitter/src/Configuration.cs

  • Committer: David Siegel
  • Date: 2008-06-02 19:48:18 UTC
  • Revision ID: dave@x-20080602194818-i7rtmvlbq2461ey3
Added repo.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Configuration.cs
 
3
 * 
 
4
 * GNOME Do is the legal property of its developers, whose names are too numerous
 
5
 * to list here.  Please refer to the COPYRIGHT file distributed with this
 
6
 * source distribution.
 
7
 * 
 
8
 * This program is free software: you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation, either version 3 of the License, or
 
11
 * (at your option) any later version.
 
12
 * 
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 * 
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
 */
 
21
 
 
22
using System;
 
23
using System.Threading;
 
24
using Gtk;
 
25
using GConf;
 
26
using Do.Addins;
 
27
 
 
28
namespace DoTwitter
 
29
{
 
30
        public partial class Configuration : Gtk.Bin
 
31
        {               
 
32
                public Configuration()
 
33
                {
 
34
                        this.Build();
 
35
                        string username, password;
 
36
                        
 
37
                        GConf.Client gconf = new GConf.Client ();
 
38
                        try {
 
39
                                username = gconf.Get (TwitterAction.GConfKeyBase + "username") as string;
 
40
                                password = gconf.Get (TwitterAction.GConfKeyBase + "password") as string;
 
41
                        } catch (GConf.NoSuchKeyException) {
 
42
                                username = "";
 
43
                                password = "";
 
44
                        }
 
45
                        
 
46
                        username_entry.Text = username;
 
47
                        passwd_entry.Text = password;
 
48
                }
 
49
 
 
50
                protected virtual void OnNewAcctClicked (object sender, System.EventArgs e)
 
51
                {
 
52
                        Util.Environment.Open ("https://twitter.com/signup");
 
53
                }
 
54
 
 
55
                protected virtual void OnApplyBtnClicked (object sender, System.EventArgs e)
 
56
                {
 
57
                        string username = username_entry.Text.Trim ();
 
58
                        string password = passwd_entry.Text.Trim ();
 
59
                        
 
60
                        apply_btn.Label = "Validating...";
 
61
                        apply_btn.Sensitive = false;
 
62
                        
 
63
                        new Thread ((ThreadStart) delegate {
 
64
                                bool valid = TwitterAction.TryConnect (username, password);
 
65
                                
 
66
                                Gtk.Application.Invoke (delegate {
 
67
                                        if (valid) {
 
68
                                                valid_lbl.Markup = "<i>Account validation succeeded</i>!";
 
69
                                                TwitterAction.SetAccountData (username, password);
 
70
                                        } else {
 
71
                                                valid_lbl.Markup = "<i>Account validation failed!</i>";
 
72
                                        }
 
73
                                        apply_btn.Label = "Apply";
 
74
                                        apply_btn.Sensitive = true;
 
75
                                });
 
76
                        }).Start ();
 
77
                }
 
78
        }
 
79
}