~ubuntu-branches/ubuntu/hardy/monodevelop/hardy

« back to all changes in this revision

Viewing changes to Extras/VersionControl/MonoDevelop.VersionControl.Subversion/MonoDevelop.VersionControl.Subversion.Gui/UserPasswordDialog.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2007-07-16 13:29:54 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20070716132954-pzjpp1tbvotxw30v
Tags: 0.14+dfsg-1ubuntu1
* Sync with Debian, remaining changes:
  + debian/control:
    - Build depend on firefox-dev, depend on firefox.
    - Adjust Maintainer field.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
using System;
 
3
using System.Threading;
 
4
using MonoDevelop.Core;
 
5
 
 
6
namespace MonoDevelop.VersionControl.Subversion.Gui
 
7
{
 
8
        public partial class UserPasswordDialog : Gtk.Dialog
 
9
        {
 
10
                public UserPasswordDialog (string user, string realm, bool mayRemember, bool showPassword)
 
11
                {
 
12
                        Build ();
 
13
                        if (user != null && user.Length > 0) {
 
14
                                entryUser.Text = user;
 
15
                                entryPwd.HasFocus = true;
 
16
                        }
 
17
                        
 
18
                        labelRealm.Text = GettextCatalog.GetString ("Authentication realm: ") + realm;
 
19
                        if (!mayRemember)
 
20
                                checkSavePwd.Visible = false;
 
21
                        
 
22
                        if (!showPassword)
 
23
                                entryPwd.Visible = labelPwd.Visible = false;
 
24
                }
 
25
                
 
26
                public string User {
 
27
                        get { return entryUser.Text; }
 
28
                }
 
29
                
 
30
                public string Password {
 
31
                        get { return entryPwd.Text; }
 
32
                }
 
33
                
 
34
                public bool SavePassword {
 
35
                        get { return checkSavePwd.Visible && checkSavePwd.Active; }
 
36
                }
 
37
                
 
38
                
 
39
                internal static bool Show (string realm, bool may_save, out LibSvnClient.svn_auth_cred_username_t data)
 
40
                {
 
41
                        data = new LibSvnClient.svn_auth_cred_username_t ();
 
42
                        int save;
 
43
                        string pwd, user = "";
 
44
                        bool ret = Show (false, realm, may_save, ref user, out pwd, out save);
 
45
                        data.username = user;
 
46
                        data.may_save = save;
 
47
                        return ret;
 
48
                }
 
49
                
 
50
                internal static bool Show (string user_name, string realm, bool may_save, out LibSvnClient.svn_auth_cred_simple_t data)
 
51
                {
 
52
                        data = new LibSvnClient.svn_auth_cred_simple_t ();
 
53
                        int save;
 
54
                        string pwd;
 
55
                        bool ret = Show (true, realm, may_save, ref user_name, out pwd, out save);
 
56
                        data.username = user_name;
 
57
                        data.password = pwd;
 
58
                        data.may_save = save;
 
59
                        return ret;
 
60
                }
 
61
                
 
62
                internal static bool Show (bool showPwd, string realm, bool may_save, ref string user_name, out string password, out int save)
 
63
                {
 
64
                        string pwd = "", user = user_name;
 
65
                        int s = 0;
 
66
                        
 
67
                        bool res = false;
 
68
                        object monitor = new Object ();
 
69
                        
 
70
                        EventHandler del = delegate {
 
71
                                        try {
 
72
                                                UserPasswordDialog dlg = new UserPasswordDialog (user, realm, may_save, showPwd);
 
73
                                                res = (dlg.Run () == (int) Gtk.ResponseType.Ok);
 
74
                                                if (res) {
 
75
                                                        s = dlg.SavePassword ? 1 : 0;
 
76
                                                        pwd = dlg.Password;
 
77
                                                        user = dlg.User;
 
78
                                                }
 
79
                                                dlg.Destroy ();
 
80
                                        } finally {
 
81
                                                lock (monitor) {
 
82
                                                        System.Threading.Monitor.Pulse (monitor);
 
83
                                                }
 
84
                                        }
 
85
                        };
 
86
                        
 
87
                        if (GLib.MainContext.Depth > 0) {
 
88
                                // Already in GUI thread
 
89
                                del (null, null);
 
90
                        }
 
91
                        else {
 
92
                                lock (monitor) {
 
93
                                        Gtk.Application.Invoke (del);
 
94
                                        System.Threading.Monitor.Wait (monitor);
 
95
                                }
 
96
                        }
 
97
                        
 
98
                        user_name = user;
 
99
                        save = s;
 
100
                        password = pwd;
 
101
                        return res;
 
102
                }
 
103
        }
 
104
}