Skip to content

Commit 28c5512

Browse files
yetistraveit65
authored andcommitted
get/set user face icon use accounts service
- If get icon from AccountsService failed, fallback to use ~/.face file. - If not setup user icon file, use "avatar-default" icon as default image to show. - Check dependencies of accountsservice, default is enable when accountsservice dependency exists. Added by raveit65 <[email protected]>.
1 parent 4de92a5 commit 28c5512

File tree

3 files changed

+85
-6
lines changed

3 files changed

+85
-6
lines changed

‎capplets/about-me/Makefile.am‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ marshal.c: fprintd-marshal.list
2828
bin_PROGRAMS = mate-about-me
2929

3030
mate_about_me_LDADD = $(MATECC_CAPPLETS_LIBS)
31+
if HAVE_ACCOUNTSSERVICE
32+
mate_about_me_LDADD += $(ACCOUNTSSERVICE_LIBS)
33+
endif
3134
mate_about_me_LDFLAGS = -export-dynamic
3235

3336
@INTLTOOL_DESKTOP_RULE@
@@ -47,6 +50,11 @@ AM_CPPFLAGS = \
4750
-DMATECC_PIXMAP_DIR="\"$(pkgdatadir)/pixmaps\"" \
4851
-DMATELOCALEDIR="\"$(datadir)/locale\""
4952

53+
if HAVE_ACCOUNTSSERVICE
54+
AM_CPPFLAGS += \
55+
$(ACCOUNTSSERVICE_CFLAGS)
56+
endif
57+
5058
CLEANFILES = $(MATECC_CAPPLETS_CLEANFILES) $(desktop_DATA) $(MARSHALFILES)
5159
EXTRA_DIST = $(ui_files) fprintd-marshal.list
5260

‎capplets/about-me/mate-about-me.c‎

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
#include <unistd.h>
2929
#include <dbus/dbus-glib-bindings.h>
3030

31+
#if HAVE_ACCOUNTSSERVICE
32+
#include <act/act.h>
33+
#endif
34+
3135
#define MATE_DESKTOP_USE_UNSTABLE_API
3236
#include <libmate-desktop/mate-desktop-thumbnail.h>
3337

@@ -48,6 +52,9 @@ typedef struct {
4852
GtkWidget *disable_fingerprint_button;
4953
GtkWidget *image_chooser;
5054
GdkPixbuf *image;
55+
#if HAVE_ACCOUNTSSERVICE
56+
ActUser *user;
57+
#endif
5158

5259
GdkScreen *screen;
5360
GtkIconTheme *theme;
@@ -84,10 +91,20 @@ about_me_destroy (void)
8491
static void
8592
about_me_load_photo (MateAboutMe *me)
8693
{
87-
gchar *file;
94+
gchar *file = NULL;
8895
GError *error = NULL;
96+
#if HAVE_ACCOUNTSSERVICE
97+
const gchar *act_file;
98+
99+
act_file = act_user_get_icon_file (me->user);
100+
if ( act_file != NULL && strlen (act_file) > 1) {
101+
file = g_strdup (act_file);
102+
}
103+
#endif
104+
if (file == NULL) {
105+
file = g_build_filename (g_get_home_dir (), ".face", NULL);
106+
}
89107

90-
file = g_build_filename (g_get_home_dir (), ".face", NULL);
91108
me->image = gdk_pixbuf_new_from_file(file, &error);
92109

93110
if (me->image != NULL) {
@@ -96,9 +113,9 @@ about_me_load_photo (MateAboutMe *me)
96113
} else {
97114
me->have_image = FALSE;
98115
g_warning ("Could not load %s: %s", file, error->message);
116+
e_image_chooser_set_from_file (E_IMAGE_CHOOSER (me->image_chooser), me->person);
99117
g_error_free (error);
100118
}
101-
102119
g_free (file);
103120
}
104121

@@ -172,6 +189,9 @@ about_me_update_photo (MateAboutMe *me)
172189
file = g_build_filename (g_get_home_dir (), ".face", NULL);
173190
if (g_file_set_contents (file, (gchar *)data, length, &error) == TRUE) {
174191
g_chmod (file, 0644);
192+
#if HAVE_ACCOUNTSSERVICE
193+
act_user_set_icon_file (me->user, file);
194+
#endif
175195
} else {
176196
g_warning ("Could not create %s: %s", file, error->message);
177197
g_error_free (error);
@@ -186,6 +206,9 @@ about_me_update_photo (MateAboutMe *me)
186206
g_unlink (file);
187207

188208
g_free (file);
209+
#if HAVE_ACCOUNTSSERVICE
210+
act_user_set_icon_file (me->user, "");
211+
#endif
189212
}
190213
}
191214

@@ -341,15 +364,19 @@ about_me_icon_theme_changed (GtkWindow *window,
341364
{
342365
GtkIconInfo *icon;
343366

344-
icon = gtk_icon_theme_lookup_icon (me->theme, "stock_person", 80, 0);
367+
icon = gtk_icon_theme_lookup_icon (me->theme, "avatar-default", 80, 0);
345368
if (icon != NULL) {
346369
g_free (me->person);
347370
me->person = g_strdup (gtk_icon_info_get_filename (icon));
348371
g_object_unref (icon);
349372
}
350373

351-
if (me->have_image)
374+
if (me->have_image) {
375+
#if HAVE_ACCOUNTSSERVICE
376+
act_user_set_icon_file (me->user, me->person);
377+
#endif
352378
e_image_chooser_set_from_file (E_IMAGE_CHOOSER (me->image_chooser), me->person);
379+
}
353380
}
354381

355382
static void
@@ -380,6 +407,18 @@ about_me_fingerprint_button_clicked_cb (GtkWidget *button, MateAboutMe *me)
380407
me->disable_fingerprint_button);
381408
}
382409

410+
#if HAVE_ACCOUNTSSERVICE
411+
static void on_user_is_loaded_changed (ActUser *user, GParamSpec *pspec, MateAboutMe* me)
412+
{
413+
if (act_user_is_loaded (user)) {
414+
about_me_load_photo (me);
415+
g_signal_handlers_disconnect_by_func (G_OBJECT (user),
416+
G_CALLBACK (on_user_is_loaded_changed),
417+
me);
418+
}
419+
}
420+
#endif
421+
383422
static gint
384423
about_me_setup_dialog (void)
385424
{
@@ -388,6 +427,10 @@ about_me_setup_dialog (void)
388427
GtkIconInfo *icon;
389428
GtkBuilder *dialog;
390429
gchar *str;
430+
#if HAVE_ACCOUNTSSERVICE
431+
ActUserManager* manager;
432+
gboolean loaded;
433+
#endif
391434

392435
me = g_new0 (MateAboutMe, 1);
393436
me->image = NULL;
@@ -417,7 +460,7 @@ about_me_setup_dialog (void)
417460
me->screen = gtk_window_get_screen (GTK_WINDOW (main_dialog));
418461
me->theme = gtk_icon_theme_get_for_screen (me->screen);
419462

420-
icon = gtk_icon_theme_lookup_icon (me->theme, "stock_person", 80, 0);
463+
icon = gtk_icon_theme_lookup_icon (me->theme, "avatar-default", 80, 0);
421464
if (icon != NULL) {
422465
me->person = g_strdup (gtk_icon_info_get_filename (icon));
423466
g_object_unref (icon);
@@ -431,6 +474,15 @@ about_me_setup_dialog (void)
431474
me->login = g_strdup (g_get_user_name ());
432475
me->username = g_strdup (g_get_real_name ());
433476

477+
#if HAVE_ACCOUNTSSERVICE
478+
manager = act_user_manager_get_default ();
479+
me->user = act_user_manager_get_user (manager, me->login);
480+
g_object_get (manager, "is-loaded", &loaded, NULL);
481+
if (!loaded) {
482+
g_signal_connect (me->user, "notify::is-loaded", G_CALLBACK (on_user_is_loaded_changed), me);
483+
}
484+
#endif
485+
434486
/* Contact Tab */
435487
about_me_load_photo (me);
436488

‎configure.ac‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,24 @@ AC_SUBST(WARN_CFLAGS)
171171

172172
AM_CONDITIONAL(HAVE_LIBMATESLAB, [test $have_libmateslab = yes])
173173

174+
dnl
175+
dnl Check dependencies of accountsservice
176+
dnl
177+
178+
ACCOUNTSSERVICE_REQUIRED=0.6.21
179+
180+
AC_ARG_WITH([accountsservice], AC_HELP_STRING([--without-accountsservice], [disable accountsservice support]))
181+
have_accountsservice=no
182+
if test x$with_accountsservice != xno; then
183+
PKG_CHECK_MODULES(ACCOUNTSSERVICE, accountsservice >= $ACCOUNTSSERVICE_REQUIRED, have_accountsservice=yes, have_accountsservice=no)
184+
fi
185+
if test "x$have_accountsservice" = "xyes"; then
186+
AC_DEFINE(HAVE_ACCOUNTSSERVICE, 1, [ACCOUNTSSERVICE Support.])
187+
fi
188+
189+
AM_CONDITIONAL([HAVE_ACCOUNTSSERVICE], [test "x$have_accountsservice" = xyes])
190+
191+
174192
PKG_CHECK_MODULES(FONT_CAPPLET, $COMMON_MODULES pango)
175193
PKG_CHECK_MODULES(FONT_VIEWER, $COMMON_MODULES fontconfig freetype2 mate-desktop-2.0)
176194

@@ -311,4 +329,5 @@ echo "
311329

312330
Appindicator: ${enable_appindicator}
313331
Libmate-slab: ${have_libmateslab}
332+
Accountsservice: ${have_accountsservice}
314333
"

0 commit comments

Comments
 (0)