PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/giver-0.1.8-username_face.patch

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