/giver-0.1.8-username_face.patch
Patch | 335 lines | 318 code | 17 blank | 0 comment | 0 complexity | 82629e2ba12399bb2f7f23e99f7432d9 MD5 | raw file
- diff -up giver-0.1.8/src/GiverService.cs.username_face giver-0.1.8/src/GiverService.cs
- --- giver-0.1.8/src/GiverService.cs.username_face 2007-08-03 01:17:45.000000000 -0400
- +++ giver-0.1.8/src/GiverService.cs 2008-12-02 14:48:39.000000000 -0500
- @@ -128,6 +128,12 @@ namespace Giver
- "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,
- diff -up giver-0.1.8/src/PhotoService.cs.username_face giver-0.1.8/src/PhotoService.cs
- --- giver-0.1.8/src/PhotoService.cs.username_face 2007-08-03 01:18:10.000000000 -0400
- +++ giver-0.1.8/src/PhotoService.cs 2008-12-02 14:48:39.000000000 -0500
- @@ -92,7 +92,8 @@ namespace Giver
-
- 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 ){
- diff -up giver-0.1.8/src/Preferences.cs.username_face giver-0.1.8/src/Preferences.cs
- --- giver-0.1.8/src/Preferences.cs.username_face 2007-08-03 01:18:25.000000000 -0400
- +++ giver-0.1.8/src/Preferences.cs 2008-12-02 14:48:39.000000000 -0500
- @@ -38,6 +38,7 @@ namespace Giver
- 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";
- @@ -55,9 +56,21 @@ namespace Giver
- 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
- @@ -98,7 +111,6 @@ namespace Giver
- }
- }
-
- -
- public string UserName
- {
- get
- @@ -106,7 +118,7 @@ namespace Giver
- 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;
- }
- @@ -120,7 +132,7 @@ namespace Giver
- document.DocumentElement.AppendChild(element);
- }
- if(value == null)
- - element.InnerText = Environment.UserName;
- + element.InnerText = Utilities.GetUserName();
- else
- element.InnerText = value;
- SavePrefs();
- diff -up giver-0.1.8/src/PreferencesDialog.cs.username_face giver-0.1.8/src/PreferencesDialog.cs
- --- giver-0.1.8/src/PreferencesDialog.cs.username_face 2007-08-03 01:33:12.000000000 -0400
- +++ giver-0.1.8/src/PreferencesDialog.cs 2008-12-02 14:48:39.000000000 -0500
- @@ -38,6 +38,7 @@ namespace Giver
- 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;
- @@ -114,7 +115,7 @@ namespace Giver
- 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);
- @@ -133,10 +134,36 @@ namespace Giver
- 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));
- @@ -145,15 +172,15 @@ namespace Giver
- 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));
- @@ -162,15 +189,15 @@ namespace Giver
- 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));
- @@ -179,10 +206,10 @@ namespace Giver
- 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);
-
- @@ -237,6 +264,8 @@ namespace Giver
- 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;
- @@ -246,7 +275,13 @@ namespace Giver
- 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;
- }
- }
-
- @@ -271,6 +306,17 @@ namespace Giver
- }
- };
-
- + 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)
- {
- diff -up giver-0.1.8/src/RequestHandler.cs.username_face giver-0.1.8/src/RequestHandler.cs
- --- giver-0.1.8/src/RequestHandler.cs.username_face 2007-08-03 01:19:01.000000000 -0400
- +++ giver-0.1.8/src/RequestHandler.cs 2008-12-02 14:48:39.000000000 -0500
- @@ -437,7 +437,8 @@ namespace Giver
- 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;
- @@ -447,8 +448,12 @@ namespace Giver
-
- 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;
- diff -up giver-0.1.8/src/ServiceLocator.cs.username_face giver-0.1.8/src/ServiceLocator.cs
- --- giver-0.1.8/src/ServiceLocator.cs.username_face 2007-08-03 01:19:17.000000000 -0400
- +++ giver-0.1.8/src/ServiceLocator.cs 2008-12-02 14:50:58.000000000 -0500
- @@ -271,6 +271,7 @@ namespace Giver {
-
- if(serviceInfo.PhotoType.CompareTo(Preferences.Local) == 0 ||
- serviceInfo.PhotoType.CompareTo (Preferences.Gravatar) == 0 ||
- + serviceInfo.PhotoType.CompareTo(Preferences.UserFace) == 0 ||
- serviceInfo.PhotoType.CompareTo (Preferences.Uri) == 0) {
- // Queue the resolution of the photo
- PhotoService.QueueResolve (serviceInfo);
- diff -up giver-0.1.8/src/Utilities.cs.username_face giver-0.1.8/src/Utilities.cs
- --- giver-0.1.8/src/Utilities.cs.username_face 2007-08-03 01:20:05.000000000 -0400
- +++ giver-0.1.8/src/Utilities.cs 2008-12-02 14:48:39.000000000 -0500
- @@ -32,6 +32,7 @@ using System.Text;
- using System.Net;
- using System.IO;
- using System.Security.Cryptography;
- +using Mono.Unix;
-
-
- namespace Giver
- @@ -254,5 +255,43 @@ namespace Giver
- }
-
-
- + 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;
- + }
- +
- }
- }