~ubuntu-branches/ubuntu/lucid/beagle/lucid

« back to all changes in this revision

Viewing changes to Util/KdeUtils.cs

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2008-05-04 00:31:32 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20080504003132-2tkm5o8moo5952ri
Tags: 0.3.7-2ubuntu1
 * Merge from Debian unstable. (LP: #225746) Remaining Ubuntu changes:
  - debian/control:
    + Rename ice{weasel,dove}-beagle to {mozilla,thunderbird}-beagle and
      and update the dependencies accordingly.
    + Change Maintainer to Ubuntu Mono Team.
  - debian/rules:
    + Install the mozilla-beagle and thunderbird-beagle extensions.
  - ice{dove,weasel}.dirs:
    + Renamed to {mozilla,thunderbird}-beagle.dirs.
    + Fixed paths to point to usr/lib/{firefox,thunderbird}

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
// KdeUtils.cs
3
3
//
4
4
// Copyright (C) 2005 Novell, Inc.
 
5
// Copyright (C) 2008 D Bera <dbera.web@gmail.com>
5
6
//
6
7
 
7
8
//
30
31
using System.Text;
31
32
 
32
33
namespace Beagle.Util {
33
 
        public class KdeUtils {
34
 
 
35
 
                // No instantiation
36
 
                private KdeUtils () { }
 
34
        public static class KdeUtils {
37
35
 
38
36
                private static string [] icon_sizes = { "128x128", "64x64", "48x48", "32x32", "22x22", "16x16" };
39
37
                private static string [] kde_locations = { ExternalStringsHack.KdePrefix, Environment.GetEnvironmentVariable ("KDEDIR"), "/opt/kde3", "/usr" };
110
108
                        return null;
111
109
                }
112
110
 
 
111
                public static string ReadPasswordKDEWallet (string folder, string username)
 
112
                {
 
113
                        if (String.IsNullOrEmpty (folder) || String.IsNullOrEmpty (username))
 
114
                                throw new ArgumentException ("folder, username", "cannot be empty");
 
115
 
 
116
                        // Get name of the local wallet
 
117
                        SafeProcess pc = new SafeProcess ();
 
118
                        pc.Arguments = new string[] { "dcop", "kded", "kwalletd", "localWallet" };
 
119
                        pc.RedirectStandardOutput = true;
 
120
                        pc.RedirectStandardError = false;
 
121
                        pc.UseLangC = true;
 
122
 
 
123
                        pc.Start ();
 
124
                        string localWallet = null;
 
125
                        using (StreamReader pout = new StreamReader (pc.StandardOutput))
 
126
                                localWallet = pout.ReadLine ();
 
127
                        pc.Close ();
 
128
 
 
129
                        if (String.IsNullOrEmpty (localWallet) || localWallet == "-1")
 
130
                                throw new ArgumentException ("kwalletd", "Unable to reach local KDE wallet");
 
131
 
 
132
                        // Open local wallet
 
133
                        pc = new SafeProcess ();
 
134
                        pc.Arguments = new string[] {"dcop", "kded", "kwalletd", "open", localWallet, "K" };
 
135
                        pc.RedirectStandardOutput = true;
 
136
                        pc.RedirectStandardError = false;
 
137
                        pc.UseLangC = true;
 
138
 
 
139
                        pc.Start ();
 
140
                        string wallet_id = null;
 
141
                        using (StreamReader pout = new StreamReader (pc.StandardOutput))
 
142
                                wallet_id = pout.ReadLine ();
 
143
                        pc.Close ();
 
144
 
 
145
                        if (String.IsNullOrEmpty (wallet_id) || wallet_id == "-1")
 
146
                                throw new ArgumentException ("kwalletd", "Unable to open local KDE wallet");
 
147
 
 
148
                        // Read password from the given folder and for the given username
 
149
                        pc = new SafeProcess ();
 
150
                        pc.Arguments = new string[] {"dcop", "kded", "kwalletd", "readPassword", wallet_id, folder, username };
 
151
                        pc.RedirectStandardOutput = true;
 
152
                        pc.RedirectStandardError = false;
 
153
                        pc.UseLangC = true;
 
154
 
 
155
                        pc.Start ();
 
156
                        string password = null;
 
157
                        using (StreamReader pout = new StreamReader (pc.StandardOutput))
 
158
                                password = pout.ReadLine ();
 
159
                        pc.Close ();
 
160
 
 
161
                        if (String.IsNullOrEmpty (password))
 
162
                                throw new ArgumentException ("kwalletd", "Unable to read password.");
 
163
 
 
164
                        return password;
 
165
                }
 
166
 
 
167
                public static void StorePasswordKDEWallet (string folder, string username, string password)
 
168
                {
 
169
                        if (String.IsNullOrEmpty (folder) || String.IsNullOrEmpty (username) || String.IsNullOrEmpty (password))
 
170
                                throw new ArgumentException ("folder, username or password", "cannot be empty");
 
171
 
 
172
                        // Get name of the local wallet
 
173
                        SafeProcess pc = new SafeProcess ();
 
174
                        pc.Arguments = new string[] { "dcop", "kded", "kwalletd", "localWallet" };
 
175
                        pc.RedirectStandardOutput = true;
 
176
                        pc.RedirectStandardError = false;
 
177
                        pc.UseLangC = true;
 
178
 
 
179
                        pc.Start ();
 
180
                        string localWallet = null;
 
181
                        using (StreamReader pout = new StreamReader (pc.StandardOutput))
 
182
                                localWallet = pout.ReadLine ();
 
183
                        pc.Close ();
 
184
 
 
185
                        if (String.IsNullOrEmpty (localWallet) || localWallet == "-1")
 
186
                                throw new ArgumentException ("kwalletd", "Local KDE Wallet is not found. Please run kwalletmanager to enable KDE Wallet.");
 
187
 
 
188
                        // Open local wallet
 
189
                        pc = new SafeProcess ();
 
190
                        pc.Arguments = new string[] {"dcop", "kded", "kwalletd", "open", localWallet, "K" };
 
191
                        pc.RedirectStandardOutput = true;
 
192
                        pc.RedirectStandardError = false;
 
193
                        pc.UseLangC = true;
 
194
 
 
195
                        pc.Start ();
 
196
                        string wallet_id = null;
 
197
                        using (StreamReader pout = new StreamReader (pc.StandardOutput))
 
198
                                wallet_id = pout.ReadLine ();
 
199
                        pc.Close ();
 
200
 
 
201
                        if (String.IsNullOrEmpty (wallet_id) || wallet_id == "-1")
 
202
                                throw new ArgumentException ("kwalletd", "Unable to open local KDE wallet");
 
203
 
 
204
                        // Write given password for the given folder and username
 
205
                        pc = new SafeProcess ();
 
206
                        pc.Arguments = new string[] {"dcop", "kded", "kwalletd", "writePassword", wallet_id, folder, username, password };
 
207
                        pc.RedirectStandardOutput = true;
 
208
                        pc.RedirectStandardError = false;
 
209
                        pc.UseLangC = true;
 
210
 
 
211
                        pc.Start ();
 
212
                        string ret = null;
 
213
                        using (StreamReader pout = new StreamReader (pc.StandardOutput))
 
214
                                password = pout.ReadLine ();
 
215
                        pc.Close ();
 
216
 
 
217
                        if (ret != "0")
 
218
                                throw new ArgumentException ("kwalletd", "Unable to save password.");
 
219
                }
 
220
 
113
221
        }
114
222
}
115
223