1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
|
--- Utilities.cs
+++ Utilities.cs
@@ -25,6 +25,7 @@
using System.Net;
using System.IO;
using System.Security.Cryptography;
+using Mono.Unix;
namespace Giver
@@ -247,5 +248,43 @@
}
+ public static Gdk.Pixbuf GetUserFaceIcon(int size)
+ {
+ try {
+ Gdk.Pixbuf ret = new Gdk.Pixbuf (Utilities.GetUserFacePath());
+ return ret.ScaleSimple (size, size, Gdk.InterpType.Bilinear);
+ } catch (ArgumentException) {}
+
+ Logger.Debug ("Unable to load user face.");
+ return null;
+ }
+
+ public static bool UserFaceExists()
+ {
+ return File.Exists(Utilities.GetUserFacePath());
+ }
+
+ public static string GetUserFacePath()
+ {
+ /*
+ TODO this can be extended to also check for user faces at /opt/gnome/share/pixmaps/faces
+ or whatever face file/directories supported by other login managers
+ */
+ return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),".face");
+ }
+
+ public static string GetUserName()
+ {
+ UnixUserInfo user = UnixUserInfo.GetRealUser();
+ string username = null;
+ if ( user.RealName != null && user.RealName.Length > 0)
+ username = user.RealName.Split(new char[]{','})[0];
+
+ if ( username == null || username == "")
+ username = Environment.UserName;
+
+ return username;
+ }
+
}
}
Index: PreferencesDialog.cs
===================================================================
--- PreferencesDialog.cs (revision 76)
+++ PreferencesDialog.cs (working copy)
@@ -31,6 +31,7 @@
private FileChooserButton fileLocationButton;
private Gtk.Entry nameEntry;
private Gtk.RadioButton noneButton;
+ private Gtk.RadioButton faceButton;
private Gtk.RadioButton localButton;
private Gtk.RadioButton webButton;
private Gtk.RadioButton gravatarButton;
@@ -107,7 +108,7 @@
label.Markup = "<span weight=\"bold\" size=\"large\">Your Picture</span>";
mainVBox.PackStart(label, true, true, 0);
- Gtk.Table table = new Table(4, 3, false);
+ Gtk.Table table = new Table(5, 3, false);
table.Show();
// None Entry
noneButton = new RadioButton((Gtk.RadioButton)null);
@@ -126,10 +127,36 @@
vbox.Show();
table.Attach(vbox, 2,3,1,2, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Expand | AttachOptions.Fill, 0, 0);
+ // Face Entry
+ if (Utilities.UserFaceExists())
+ {
+
+ faceButton = new RadioButton(noneButton);
+ faceButton.Show();
+ table.Attach(faceButton, 0, 1, 1, 2, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
+
+ vbox = new VBox();
+ vbox.Show();
+
+ image = new Image(Utilities.GetUserFaceIcon(48));
+ image.Show();
+ vbox.PackStart(image, false, false, 0);
+
+ label = new Label("Login photo");
+ label.Show();
+ vbox.PackStart(label, false, false, 0);
+ table.Attach(vbox, 1, 2, 1 ,2, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
+
+ vbox = new VBox();
+ vbox.Show();
+ table.Attach(vbox, 2,3,2,3, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Expand | AttachOptions.Fill, 0, 0);
+
+ }
+
// Local Entry
- localButton = new RadioButton(noneButton);
+ localButton = new RadioButton(faceButton ?? noneButton);
localButton.Show();
- table.Attach(localButton, 0, 1, 1, 2, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
+ table.Attach(localButton, 0, 1, 2, 3, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
vbox = new VBox();
vbox.Show();
localImage = new Image(Utilities.GetIcon("stock_person", 48));
@@ -138,15 +165,15 @@
label = new Label("File");
label.Show();
vbox.PackStart(label, false, false, 0);
- table.Attach(vbox, 1, 2, 1 ,2, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
+ table.Attach(vbox, 1, 2, 2 ,3, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
photoButton = new Button("Change Photo");
photoButton.Show();
- table.Attach(photoButton, 2,3,1,2, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Shrink, 0, 0);
+ table.Attach(photoButton, 2,3,2,3, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Shrink, 0, 0);
// Web Entry
webButton = new RadioButton(noneButton);
webButton.Show();
- table.Attach(webButton, 0, 1, 2, 3, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
+ table.Attach(webButton, 0, 1, 3, 4, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
vbox = new VBox();
vbox.Show();
image = new Image(Utilities.GetIcon("web-browser", 48));
@@ -155,15 +182,15 @@
label = new Label("Web Link");
label.Show();
vbox.PackStart(label, false, false, 0);
- table.Attach(vbox, 1, 2, 2 ,3, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
+ table.Attach(vbox, 1, 2, 3, 4, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
webEntry = new Entry();
webEntry.Show();
- table.Attach(webEntry, 2,3,2,3, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Expand | AttachOptions.Fill, 0, 0);
+ table.Attach(webEntry, 2,3,3,4, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Expand | AttachOptions.Fill, 0, 0);
// Gravatar Entry
gravatarButton = new RadioButton(noneButton);
gravatarButton.Show();
- table.Attach(gravatarButton, 0, 1, 3, 4, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
+ table.Attach(gravatarButton, 0, 1, 4, 5, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
vbox = new VBox();
vbox.Show();
image = new Image(Utilities.GetIcon("gravatar", 48));
@@ -172,10 +199,10 @@
label = new Label("Gravatar");
label.Show();
vbox.PackStart(label, false, false, 0);
- table.Attach(vbox, 1, 2, 3 ,4, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
+ table.Attach(vbox, 1, 2, 4 ,5, AttachOptions.Shrink, AttachOptions.Shrink, 0, 0);
gravatarEntry = new Entry();
gravatarEntry.Show();
- table.Attach(gravatarEntry, 2,3,3,4, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Expand | AttachOptions.Fill, 0, 0);
+ table.Attach(gravatarEntry, 2,3,4,5, AttachOptions.Expand | AttachOptions.Fill, AttachOptions.Expand | AttachOptions.Fill, 0, 0);
mainVBox.PackStart(table, true, true, 0);
@@ -230,6 +257,8 @@
photoButton
localImage
*/
+ } else if (Giver.Application.Preferences.PhotoType.CompareTo(Giver.Preferences.UserFace) == 0) {
+ faceButton.Active = true;
} else if(Giver.Application.Preferences.PhotoType.CompareTo(Giver.Preferences.Uri) == 0) {
webButton.Active = true;
webEntry.Text = Giver.Application.Preferences.PhotoLocation;
@@ -239,7 +268,13 @@
gravatarEntry.Text = Giver.Application.Preferences.PhotoLocation;
} else {
// make this none
- noneButton.Active = true;
+ if (Utilities.UserFaceExists())
+ {
+ faceButton.Active = true;
+ Giver.Application.Preferences.PhotoType = Preferences.UserFace;
+ }
+ else
+ noneButton.Active = true;
}
}
@@ -264,6 +299,17 @@
}
};
+ if (faceButton != null)
+ faceButton.Toggled += delegate {
+ if (faceButton.Active)
+ {
+ Application.Preferences.PhotoType = Preferences.UserFace;
+ photoButton.Sensitive = false;
+ webEntry.Sensitive = false;
+ gravatarEntry.Sensitive = false;
+ }
+ };
+
localButton.Toggled += delegate {
if(localButton.Active)
{
Index: ServiceLocator.cs
===================================================================
--- ServiceLocator.cs (revision 76)
+++ ServiceLocator.cs (working copy)
@@ -241,7 +241,8 @@
if(serviceInfo.PhotoType.CompareTo(Preferences.Local) == 0 ||
serviceInfo.PhotoType.CompareTo (Preferences.Gravatar) == 0 ||
- serviceInfo.PhotoType.CompareTo (Preferences.Uri) == 0) {
+ serviceInfo.PhotoType.CompareTo (Preferences.Gravatar) == 0 ||
+ serviceInfo.PhotoType.CompareTo(Preferences.UserFace) == 0) {
// Queue the resolution of the photo
PhotoService.QueueResolve (serviceInfo);
}
Index: RequestHandler.cs
===================================================================
--- RequestHandler.cs (revision 76)
+++ RequestHandler.cs (working copy)
@@ -428,7 +428,8 @@
private void HandlePhoto(HttpListenerContext context)
{
// get the information about what wants to be sent
- if(Application.Preferences.PhotoType.CompareTo(Preferences.Local) != 0)
+ if(Application.Preferences.PhotoType.CompareTo(Preferences.Local) != 0 &&
+ Application.Preferences.PhotoType.CompareTo(Preferences.UserFace) != 0)
{
context.Response.StatusCode = (int)HttpStatusCode.NotFound;
context.Response.StatusDescription = Application.Preferences.PhotoLocation;
@@ -438,8 +439,12 @@
try
{
+ string location = Application.Preferences.PhotoLocation;
+ if (Application.Preferences.PhotoType.CompareTo(Preferences.UserFace) == 0)
+ location = Utilities.GetUserFacePath();
+
FileStream fs =
- File.Open(Application.Preferences.PhotoLocation, FileMode.Open, FileAccess.Read);
+ File.Open(location, FileMode.Open, FileAccess.Read);
Stream stream = context.Response.OutputStream;
context.Response.ContentLength64 = fs.Length;
context.Response.StatusCode = (int)HttpStatusCode.OK;
Index: GiverService.cs
===================================================================
--- GiverService.cs (revision 76)
+++ GiverService.cs (working copy)
@@ -121,6 +121,12 @@
"Version=" + Defines.Version,
"PhotoType=" + Preferences.Local,
"Photo=none" };
+ } else if (Application.Preferences.PhotoType.CompareTo(Preferences.UserFace) == 0) {
+ txtStrings = new string[] { "User Name=" + Application.Preferences.UserName,
+ "Machine Name=" + Environment.MachineName,
+ "Version=" + Defines.Version,
+ "PhotoType=" + Preferences.UserFace,
+ "Photo=none" };
} else if( Application.Preferences.PhotoType.CompareTo(Preferences.Gravatar) == 0) {
txtStrings = new string[] { "User Name=" + Application.Preferences.UserName,
"Machine Name=" + Environment.MachineName,
Index: Preferences.cs
===================================================================
--- Preferences.cs (revision 76)
+++ Preferences.cs (working copy)
@@ -31,6 +31,7 @@
public class Preferences
{
public const string None = "none";
+ public const string UserFace = "face";
public const string Local = "local";
public const string Gravatar = "gravatar";
public const string Uri = "uri";
@@ -48,9 +49,21 @@
XmlNodeList list = document.GetElementsByTagName("PhotoType");
XmlElement element = (XmlElement) list[0];
if(element == null)
- return Preferences.None;
- else
+ {
+ if (Utilities.UserFaceExists())
+ return Preferences.UserFace;
+ else
+ return Preferences.None;
+ }
+ else
+ {
+ if (element.InnerText.CompareTo(Preferences.UserFace) == 0 && !Utilities.UserFaceExists())
+ {
+ element.InnerText = Preferences.None;
+ SavePrefs();
+ }
return element.InnerText;
+ }
}
set
@@ -91,7 +104,6 @@
}
}
-
public string UserName
{
get
@@ -99,7 +111,7 @@
XmlNodeList list = document.GetElementsByTagName("UserName");
XmlElement element = (XmlElement) list[0];
if( (element == null) || (element.InnerText.Length < 1) )
- return Environment.UserName;
+ return Utilities.GetUserName();
else
return element.InnerText;
}
@@ -113,7 +125,7 @@
document.DocumentElement.AppendChild(element);
}
if(value == null)
- element.InnerText = Environment.UserName;
+ element.InnerText = Utilities.GetUserName();
else
element.InnerText = value;
SavePrefs();
Index: PhotoService.cs
===================================================================
--- PhotoService.cs (revision 76)
+++ PhotoService.cs (working copy)
@@ -64,7 +64,8 @@
Logger.Debug ("Resolving photo for: {0}", serviceInfo.UserName);
try {
- if (serviceInfo.PhotoType.CompareTo(Preferences.Local) == 0 ) {
+ if (serviceInfo.PhotoType.CompareTo(Preferences.Local) == 0 ||
+ serviceInfo.PhotoType.CompareTo(Preferences.UserFace) == 0) {
SendingHandler.GetPhoto (serviceInfo);
serviceInfo.Photo = serviceInfo.Photo.ScaleSimple(48, 48, Gdk.InterpType.Bilinear);
} else if (serviceInfo.PhotoType.CompareTo (Preferences.Gravatar) == 0 ){
|