[gnome-boxes] Use fdo.Accounts service to retrive avatar



commit d304b1c7cbdf341fa9139e05b3d72d9a721694b9
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Fri Feb 24 14:51:01 2012 +0100

    Use fdo.Accounts service to retrive avatar
    
    We use avatar-default when setting up the UI, then we query Accounts
    and replace it.  I couldn't find how the unattended installer was
    making use of it. Perhaps it's something still on the todo list
    
    Reviewed and modified by Zeeshan Ali (Khattak) <zeeshanak gnome org>.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=670388

 src/unattended-installer.vala |   36 +++++++++++++++++++++++++++++-------
 src/util.vala                 |   23 +++++++++++++++++++++++
 2 files changed, 52 insertions(+), 7 deletions(-)
---
diff --git a/src/unattended-installer.vala b/src/unattended-installer.vala
index 900185c..6f61d45 100644
--- a/src/unattended-installer.vala
+++ b/src/unattended-installer.vala
@@ -50,6 +50,7 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
     private static Regex timezone_regex;
     private static Regex kbd_regex;
     private static Regex lang_regex;
+    private static Fdo.Accounts accounts;
 
     static construct {
         try {
@@ -58,6 +59,11 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
             timezone_regex = new Regex ("BOXES_TZ");
             kbd_regex = new Regex ("BOXES_KBD");
             lang_regex = new Regex ("BOXES_LANG");
+            try {
+                accounts = Bus.get_proxy_sync (BusType.SYSTEM, "org.freedesktop.Accounts", "/org/freedesktop/Accounts");
+            } catch (GLib.Error error) {
+                warning ("Failed to connect to D-Bus service '%s': %s", "org.freedesktop.Accounts", error.message);
+            }
         } catch (RegexError error) {
             // This just can't fail
             assert_not_reached ();
@@ -163,15 +169,11 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
         setup_table.attach_defaults (express_toggle, 2, 3, 0, 1);
 
         // 2nd row (while user avatar spans over 2 rows)
-        var avatar_file = "/var/lib/AccountsService/icons/" + Environment.get_user_name ();
-        var file = File.new_for_path (avatar_file);
-        Gtk.Image avatar;
-        if (file.query_exists ())
-            avatar = new Gtk.Image.from_file (avatar_file);
-        else
-            avatar = new Gtk.Image.from_icon_name ("avatar-default", 0);
+        var avatar = new Gtk.Image.from_icon_name ("avatar-default", 0);
         avatar.pixel_size = 128;
         setup_table.attach_defaults (avatar, 0, 1, 1, 3);
+        avatar.show_all ();
+        fetch_user_avatar.begin (avatar);
 
         label = new Gtk.Label (_("Username"));
         label.halign = Gtk.Align.END;
@@ -347,4 +349,24 @@ private abstract class Boxes.UnattendedInstaller: InstallerMedia {
         if (exit_status != 0)
             throw new UnattendedInstallerError.COMMAND_FAILED ("Failed to execute: %s", string.joinv (" ", argv));
     }
+
+    private async void fetch_user_avatar (Gtk.Image avatar) {
+        if (accounts == null)
+            return;
+
+        var username = Environment.get_user_name ();
+        var avatar_file = "/var/lib/AccountsService/icons/" + username;
+
+        try {
+            var path = yield accounts.FindUserByName (Environment.get_user_name ());
+            Fdo.AccountsUser user = yield Bus.get_proxy (BusType.SYSTEM, "org.freedesktop.Accounts", path);
+            avatar_file = user.IconFile;
+        } catch (GLib.IOError error) {
+            warning ("Failed to retrieve information about user '%s': %s", username, error.message);
+        }
+
+        var file = File.new_for_path (avatar_file);
+        if (file.query_exists ())
+            avatar.file = avatar_file;
+    }
 }
diff --git a/src/util.vala b/src/util.vala
index d4495f8..2388b2b 100644
--- a/src/util.vala
+++ b/src/util.vala
@@ -369,4 +369,27 @@ namespace Boxes {
         else
             return get_logo_path (product, extensions[1:extensions.length]);
     }
+
+    [DBus (name = "org.freedesktop.Accounts")]
+    interface Fdo.Accounts : Object {
+        public abstract async string FindUserByName(string name) throws IOError;
+    }
+
+    [DBus (name = "org.freedesktop.Accounts.User")]
+    interface Fdo.AccountsUser : Object {
+        public abstract bool AutomaticLogin { get; }
+        public abstract bool Locked { get; }
+        public abstract bool SystemAccount { get; }
+        public abstract int32 AccountType { get; }
+        public abstract int32 PasswordMode { get; }
+        public abstract string Email { owned get; }
+        public abstract string HomeDirectory { owned get; }
+        public abstract string IconFile { owned get; }
+        public abstract string Language { owned get; }
+        public abstract string Location { owned get; }
+        public abstract string RealName { owned get; }
+        public abstract string Shell { owned get; }
+        public abstract string UserName { owned get; }
+        public abstract string XSession { owned get; }
+    }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]