07-use-accountsservice.patch 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. Description: get user icon from accountsservice instead of looking in ~/.face
  2. Author: Marc Deslauriers <marc.deslauriers@canonical.com>
  3. Forwarded: yes
  4. Bug: https://bugzilla.gnome.org/show_bug.cgi?id=669857
  5. Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/policykit-1-gnome/+bug/928249
  6. Index: policykit-1-gnome-0.105/src/polkitgnomeauthenticationdialog.c
  7. ===================================================================
  8. --- policykit-1-gnome-0.105.orig/src/polkitgnomeauthenticationdialog.c 2012-02-11 00:10:48.850913210 -0500
  9. +++ policykit-1-gnome-0.105/src/polkitgnomeauthenticationdialog.c 2012-02-11 00:22:04.462930509 -0500
  10. @@ -135,6 +135,102 @@
  11. }
  12. }
  13. +static GdkPixbuf *
  14. +get_user_icon (char *username)
  15. +{
  16. + GError *error;
  17. + GDBusConnection *connection;
  18. + GVariant *find_user_result;
  19. + GVariant *get_icon_result;
  20. + GVariant *icon_result_variant;
  21. + const gchar *user_path;
  22. + const gchar *icon_filename;
  23. + GdkPixbuf *pixbuf;
  24. +
  25. + error = NULL;
  26. + connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
  27. +
  28. + if (connection == NULL)
  29. + {
  30. + g_warning ("Unable to connect to system bus: %s", error->message);
  31. + g_error_free (error);
  32. + return NULL;
  33. + }
  34. +
  35. + find_user_result = g_dbus_connection_call_sync (connection,
  36. + "org.freedesktop.Accounts",
  37. + "/org/freedesktop/Accounts",
  38. + "org.freedesktop.Accounts",
  39. + "FindUserByName",
  40. + g_variant_new ("(s)",
  41. + username),
  42. + G_VARIANT_TYPE ("(o)"),
  43. + G_DBUS_CALL_FLAGS_NONE,
  44. + -1,
  45. + NULL,
  46. + &error);
  47. +
  48. + if (find_user_result == NULL)
  49. + {
  50. + g_warning ("Accounts couldn't find user: %s", error->message);
  51. + g_error_free (error);
  52. + return NULL;
  53. + }
  54. +
  55. + user_path = g_variant_get_string (g_variant_get_child_value (find_user_result, 0),
  56. + NULL);
  57. +
  58. + get_icon_result = g_dbus_connection_call_sync (connection,
  59. + "org.freedesktop.Accounts",
  60. + user_path,
  61. + "org.freedesktop.DBus.Properties",
  62. + "Get",
  63. + g_variant_new ("(ss)",
  64. + "org.freedesktop.Accounts.User",
  65. + "IconFile"),
  66. + G_VARIANT_TYPE ("(v)"),
  67. + G_DBUS_CALL_FLAGS_NONE,
  68. + -1,
  69. + NULL,
  70. + &error);
  71. +
  72. + g_variant_unref (find_user_result);
  73. +
  74. + if (get_icon_result == NULL)
  75. + {
  76. + g_warning ("Accounts couldn't find user icon: %s", error->message);
  77. + g_error_free (error);
  78. + return NULL;
  79. + }
  80. +
  81. + g_variant_get_child (get_icon_result, 0, "v", &icon_result_variant);
  82. + icon_filename = g_variant_get_string (icon_result_variant, NULL);
  83. +
  84. + if (icon_filename == NULL)
  85. + {
  86. + g_warning ("Accounts didn't return a valid filename for user icon");
  87. + pixbuf = NULL;
  88. + }
  89. + else
  90. + {
  91. + /* TODO: we probably shouldn't hard-code the size to 16x16 */
  92. + pixbuf = gdk_pixbuf_new_from_file_at_size (icon_filename,
  93. + 16,
  94. + 16,
  95. + &error);
  96. + if (pixbuf == NULL)
  97. + {
  98. + g_warning ("Couldn't open user icon: %s", error->message);
  99. + g_error_free (error);
  100. + }
  101. + }
  102. +
  103. + g_variant_unref (icon_result_variant);
  104. + g_variant_unref (get_icon_result);
  105. +
  106. + return pixbuf;
  107. +}
  108. +
  109. static void
  110. create_user_combobox (PolkitGnomeAuthenticationDialog *dialog)
  111. {
  112. @@ -197,16 +293,7 @@
  113. g_free (gecos);
  114. /* Load users face */
  115. - pixbuf = NULL;
  116. - if (passwd->pw_dir != NULL)
  117. - {
  118. - gchar *path;
  119. - path = g_strdup_printf ("%s/.face", passwd->pw_dir);
  120. - /* TODO: we probably shouldn't hard-code the size to 16x16 */
  121. - pixbuf = gdk_pixbuf_new_from_file_at_scale (path, 16, 16, TRUE, NULL);
  122. - g_free (path);
  123. - }
  124. -
  125. + pixbuf = get_user_icon (dialog->priv->users[n]);
  126. /* fall back to avatar-default icon */
  127. if (pixbuf == NULL)
  128. {