~iwarford/do-plugins/fart-plugin-fwiw

« back to all changes in this revision

Viewing changes to RememberTheMilk/src/Configuration.cs

  • Committer: Jason Jones
  • Date: 2008-12-24 04:45:02 UTC
  • mfrom: (335.1.9 do-plugins)
  • Revision ID: jasonedwardjones@gmail.com-20081224044502-ra56ym06cp1iqs7t
MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Configuration.cs
 
2
 *
 
3
 * GNOME Do is the legal property of its developers. Please refer to the
 
4
 * COPYRIGHT file distributed with this source distribution.
 
5
 *
 
6
 * This program is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
using System;
 
21
using Mono.Unix;
 
22
using RtmNet;
 
23
using Do.Platform;
 
24
 
 
25
using Gtk;
 
26
 
 
27
 
 
28
namespace Do.Addins.RTM
 
29
{
 
30
        public partial class Configuration : Gtk.Bin
 
31
        {
 
32
                private static IPreferences prefs;
 
33
                private LinkButton rtm_ref_btn;
 
34
                private string frob;
 
35
                
 
36
                public Configuration ()
 
37
                {
 
38
                        this.Build();
 
39
                        rtm_ref_btn = new LinkButton ("Visit Remember The Milk website for more information.",
 
40
                                                      "List of available operators");
 
41
                        info_hbox.Add (rtm_ref_btn);
 
42
                        Box.BoxChild wInt = info_hbox [rtm_ref_btn] as Box.BoxChild;
 
43
                        wInt.Position = 1;
 
44
                        rtm_ref_btn.Clicked += OnRtmRefBtnClicked;
 
45
                        
 
46
                        if (!System.String.IsNullOrEmpty (AuthToken)) {
 
47
                                SetStateComplete ();
 
48
                        }
 
49
                }
 
50
                
 
51
                static Configuration ()
 
52
                {
 
53
                        prefs = Do.Platform.Services.Preferences.Get<Do.Addins.RTM.Configuration>();
 
54
                }
 
55
                
 
56
                public static string AuthToken {
 
57
                        get { return prefs.Get("Token", ""); }
 
58
                        set { prefs.Set("Token", value); }
 
59
                }
 
60
                
 
61
                public static string Username {
 
62
                        get { return prefs.Get("Username", ""); }
 
63
                        set { prefs.Set("Username",value); }
 
64
                }
 
65
                
 
66
                public static string Filter {
 
67
                        get { return prefs.Get<string> ("Filter", "status:incomplete"); }
 
68
                        set { prefs.Set<string> ("Filter", value); }
 
69
                }
 
70
                
 
71
                public static bool OverdueNotification {
 
72
                        get { return prefs.Get<bool> ("OverdueNotification", true); }
 
73
                        set { prefs.Set<bool> ("OverdueNotification", value); }
 
74
                }
 
75
                
 
76
                public static bool ActionNotification {
 
77
                        get { return prefs.Get<bool> ("ActionNotification", true); }
 
78
                        set { prefs.Set<bool> ("ActionNotification", value); }
 
79
                }
 
80
 
 
81
                protected virtual void OnConfirmChkbtnClicked (object sender, System.EventArgs e)
 
82
                {
 
83
                        ActionNotification = confirm_chkbtn.Active;
 
84
                }
 
85
 
 
86
                protected virtual void OnOverdueChkbtnClicked (object sender, System.EventArgs e)
 
87
                {
 
88
                        OverdueNotification = overdue_chkbtn.Active;
 
89
                }
 
90
 
 
91
                protected virtual void OnAuthBtnClicked (object sender, System.EventArgs e)
 
92
                {
 
93
                        frob = RTM.AuthInit ();
 
94
                        authinfo_lbl.Text = Catalog.GetString ("A webpage from Remember The Milk should be opened"
 
95
                             + " in your web browser now. Please follow the instructions there and come back to complete"
 
96
                             + " the authrozation by clicking the button below.");
 
97
                        AuthToken = "";
 
98
                        Username = "";
 
99
                        //notification_frm.Visible = false;
 
100
                        //filter_frm.Visible = false;
 
101
                        Widget image = auth_btn.Image;
 
102
                        auth_btn.Label = Catalog.GetString ("Complete authorization");
 
103
                        auth_btn.Image = image;
 
104
                        auth_btn.Clicked -= new EventHandler (OnAuthBtnClicked);
 
105
                        auth_btn.Clicked += new EventHandler (OnCompleteBtnClicked);
 
106
                }
 
107
                
 
108
                protected virtual void OnCompleteBtnClicked (object sender, EventArgs e)
 
109
                {
 
110
                        Auth auth;
 
111
                        auth = RTM.AuthComplete (frob);
 
112
                        if (auth != null ) {
 
113
                                AuthToken = auth.Token;
 
114
                                Username = auth.User.Username;
 
115
                                auth_btn.Clicked -= new EventHandler (OnCompleteBtnClicked);
 
116
                                auth_btn.Clicked += new EventHandler (OnAuthBtnClicked);
 
117
                                SetStateComplete ();
 
118
                        } else {
 
119
                                authinfo_lbl.Text = Catalog.GetString ("Fail to complete authorization.");
 
120
                                auth_btn.Clicked -= new EventHandler (OnCompleteBtnClicked);
 
121
                                auth_btn.Clicked += new EventHandler (OnAuthBtnClicked);
 
122
                                auth_btn.Label = Catalog.GetString ("Authorize again");
 
123
                        }
 
124
                }
 
125
                
 
126
                private void SetStateComplete ()
 
127
                {
 
128
                        authinfo_lbl.Text = String.Format (Catalog.GetString ("Thank you {0}, "
 
129
                            + "RTM plugin is now authorized to operate on your account."), Username);
 
130
                        auth_btn.Label = "Sign in as a different user";
 
131
                        notification_frm.Visible = true;
 
132
                        filter_frm.Visible = true;
 
133
                        confirm_chkbtn.Active = ActionNotification;
 
134
                        overdue_chkbtn.Active = OverdueNotification;
 
135
                        filter_entry.Text = Filter;     
 
136
                }
 
137
 
 
138
                protected virtual void OnFilterEntryChanged (object sender, System.EventArgs e)
 
139
                {
 
140
                        Filter = filter_entry.Text;
 
141
                }
 
142
 
 
143
                protected virtual void OnRtmRefBtnClicked (object sender, EventArgs e)
 
144
                {
 
145
                        Do.Platform.Services.Environment.OpenUrl("http://www.rememberthemilk.com/help/answers/search/advanced.rtm");
 
146
                }
 
147
        }
 
148
}