~cszikszoy/do-plugins/pastebin

« back to all changes in this revision

Viewing changes to GMailContacts/src/Configuration.cs

  • Committer: David Siegel
  • Date: 2008-06-02 16:09:11 UTC
  • Revision ID: dave@x-20080602160911-5bc56q3okv27pg7y
Added GNOME Terminal plugin.

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.Text.RegularExpressions;
 
24
using Gtk;
 
25
using Do.Addins;
 
26
 
 
27
namespace GMailContacts
 
28
{
 
29
        public partial class Configuration : Gtk.Bin
 
30
        {               
 
31
                public Configuration()
 
32
                {
 
33
                        this.Build();
 
34
                        string username, password;
 
35
                        
 
36
                        GMail.GetUserAndPassFromKeyring (out username, out password,
 
37
                                                        GMail.GAppName);
 
38
                        username_entry.Text = username;
 
39
                        passwd_entry.Text = password;
 
40
                }
 
41
 
 
42
                protected virtual void OnNewAcctClicked (object sender, System.EventArgs e)
 
43
                {
 
44
                        Util.Environment.Open ("https://www.google.com/accounts/NewAccount?service=mail");
 
45
                }
 
46
 
 
47
                protected virtual void OnApplyBtnClicked (object sender, System.EventArgs e)
 
48
                {
 
49
                        string username = username_entry.Text.Trim ();
 
50
                        string password = passwd_entry.Text.Trim ();
 
51
                        apply_btn.Label = "Validating...";
 
52
                        apply_btn.Sensitive = false;
 
53
                        if (ValidateUsername (username) && ValidatePassword (password)
 
54
                            && GMail.TryConnect (username, password)) {
 
55
                                valid_lbl.Markup = "<i>Account validation succeeded</i>!";
 
56
                                GMail.WriteAccountToKeyring (username, password, GMail.GAppName);
 
57
                        } else {                        
 
58
                                valid_lbl.Markup = "<i>Account validation failed!</i>";
 
59
                        }
 
60
                        apply_btn.Label = "_Apply";
 
61
                        apply_btn.Sensitive = true;
 
62
                }
 
63
                
 
64
                private bool ValidateUsername (string username)
 
65
                {
 
66
                        const string emailPattern = @"[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\."
 
67
            + @"[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*"
 
68
            + @"[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?";
 
69
                        
 
70
                        Regex validEmail = new Regex (emailPattern, RegexOptions.Compiled);
 
71
                        return validEmail.IsMatch (username);
 
72
                }
 
73
                
 
74
                private bool ValidatePassword (string password)
 
75
                {
 
76
                        return password.Length >= 8;
 
77
                }
 
78
                
 
79
        }
 
80
}
 
 
b'\\ No newline at end of file'