[gnome-control-center] user: Move the language chooser to common



commit 60c8f11a122d88d215a1d479f3cf9923096ccad9
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 20 02:17:06 2011 -0400

    user: Move the language chooser to common
    
    It will soon be used in the region panel as well.

 panels/common/Makefile.am                          |   11 ++-
 .../cc-language-chooser.c}                         |  126 ++++++++++++++------
 .../cc-language-chooser.h}                         |   13 +-
 .../data => common}/language-chooser.ui            |    0
 panels/user-accounts/Makefile.am                   |    2 -
 panels/user-accounts/data/Makefile.am              |    1 -
 panels/user-accounts/um-user-panel.c               |   13 +-
 7 files changed, 108 insertions(+), 58 deletions(-)
---
diff --git a/panels/common/Makefile.am b/panels/common/Makefile.am
index 6f9790f..55227b6 100644
--- a/panels/common/Makefile.am
+++ b/panels/common/Makefile.am
@@ -8,7 +8,7 @@ AM_CPPFLAGS =						\
 	$(PANEL_CFLAGS)					\
 	$(LIBLANGUAGE_CFLAGS)				\
 	-DDATADIR=\""$(datadir)"\"			\
-	-DUIDIR=\""$(pkgdatadir)/ui/user-accounts"\"	\
+	-DUIDIR=\""$(pkgdatadir)/ui"\"			\
 	-DLIBLOCALEDIR=\""$(prefix)/lib/locale"\"       \
 	-DGNOMELOCALEDIR=\""$(datadir)/locale"\"        \
 	-DUM_PIXMAP_DIR=\""$(pkgdatadir)/pixmaps"\"
@@ -18,7 +18,9 @@ liblanguage_la_SOURCES =		\
 	gdm-languages.c 		\
 	locarchive.h			\
 	cc-common-language.c		\
-	cc-common-language.h
+	cc-common-language.h		\
+	cc-language-chooser.c		\
+	cc-language-chooser.h
 
 liblanguage_la_LIBADD = 		\
 	$(PANEL_LIBS)			\
@@ -40,4 +42,9 @@ list_languages_SOURCES = list-languages.c
 list_languages_LDADD = liblanguage.la
 list_languages_CFLAGS = $(LIBLANGUAGE_CFLAGS)
 
+uidir = $(pkgdatadir)/ui
+
+ui_DATA = \
+	language-chooser.ui
+
 -include $(top_srcdir)/git.mk
diff --git a/panels/user-accounts/um-language-dialog.c b/panels/common/cc-language-chooser.c
similarity index 74%
rename from panels/user-accounts/um-language-dialog.c
rename to panels/common/cc-language-chooser.c
index 945eb72..7e3d3a9 100644
--- a/panels/user-accounts/um-language-dialog.c
+++ b/panels/common/cc-language-chooser.c
@@ -26,18 +26,17 @@
 
 #include <glib.h>
 #include <glib/gi18n.h>
+#include <gio/gio.h>
 #include <gtk/gtk.h>
 
 #include <fontconfig/fontconfig.h>
 
-#include "um-language-dialog.h"
-#include "um-user-manager.h"
+#include "cc-language-chooser.h"
 #include "cc-common-language.h"
-
 #include "gdm-languages.h"
 
 gchar *
-um_language_chooser_get_language (GtkWidget *chooser)
+cc_language_chooser_get_language (GtkWidget *chooser)
 {
         GtkTreeView *tv;
         GtkTreeSelection *selection;
@@ -56,7 +55,7 @@ um_language_chooser_get_language (GtkWidget *chooser)
 }
 
 void
-um_language_chooser_clear_filter (GtkWidget *chooser)
+cc_language_chooser_clear_filter (GtkWidget *chooser)
 {
 	GtkEntry *entry;
 
@@ -73,50 +72,97 @@ row_activated (GtkTreeView       *tree_view,
         gtk_dialog_response (GTK_DIALOG (chooser), GTK_RESPONSE_OK);
 }
 
+static void
+add_other_users_language (GHashTable *ht)
+{
+        GVariant *variant;
+        GVariantIter *vi;
+        GError *error = NULL;
+        const char *str;
+	GDBusProxy *proxy;
+
+        proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+                                               G_DBUS_PROXY_FLAGS_NONE,
+                                               NULL,
+                                               "org.freedesktop.Accounts",
+                                               "/org/freedesktop/Accounts",
+                                               "org.freedesktop.Accounts",
+                                               NULL,
+                                               NULL);
+
+        if (proxy == NULL)
+                return;
+
+        variant = g_dbus_proxy_call_sync (proxy,
+                                          "ListCachedUsers",
+                                          NULL,
+                                          G_DBUS_CALL_FLAGS_NONE,
+                                          -1,
+                                          NULL,
+                                          &error);
+        if (variant == NULL) {
+                g_warning ("Failed to list existing users: %s", error->message);
+                g_error_free (error);
+		g_object_unref (proxy);
+                return;
+        }
+        g_variant_get (variant, "(ao)", &vi);
+        while (g_variant_iter_loop (vi, "o", &str)) {
+                GDBusProxy *user;
+                GVariant *props;
+		const char *lang;
+                char *name;
+                char *language;
+
+                user = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+                                                      G_DBUS_PROXY_FLAGS_NONE,
+                                                      NULL,
+                                                      "org.freedesktop.Accounts",
+                                                      str,
+                                                      "org.freedesktop.Accounts.User",
+                                                      NULL,
+                                                      &error);
+                if (user == NULL) {
+                        g_warning ("Failed to get proxy for user '%s': %s",
+                                   str, error->message);
+                        g_error_free (error);
+                        error = NULL;
+                        continue;
+                }
+                props = g_dbus_proxy_get_cached_property (user, "Language");
+                lang = g_variant_get_string (props, NULL);
+                if (lang != NULL && *lang != '\0' &&
+		    cc_common_language_has_font (lang)) {
+                	name = gdm_normalize_language_name (lang);
+                        language = gdm_get_language_from_name (name, NULL);
+                        g_hash_table_insert (ht, name, language);
+                }
+                g_variant_unref (props);
+                g_object_unref (user);
+        }
+        g_variant_iter_free (vi);
+        g_variant_unref (variant);
+
+	g_object_unref (proxy);
+}
+
 static GHashTable *
 new_ht_for_user_languages (void)
 {
 	GHashTable *ht;
-        UmUserManager *manager;
-        GSList *users, *l;
-        UmUser *user;
         char *name;
 
         ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
 
-	/* Add some common languages here */
+	/* Add some common languages first */
 	g_hash_table_insert (ht, g_strdup ("en_US.utf8"), g_strdup (_("English"))); 
 	g_hash_table_insert (ht, g_strdup ("de_DE.utf8"), g_strdup (_("German"))); 
 	g_hash_table_insert (ht, g_strdup ("fr_FR.utf8"), g_strdup (_("French"))); 
 	g_hash_table_insert (ht, g_strdup ("es_ES.utf8"), g_strdup (_("Spanish"))); 
 	g_hash_table_insert (ht, g_strdup ("zh_CN.utf8"), g_strdup (_("Chinese"))); 
 
-        manager = um_user_manager_ref_default ();
-        users = um_user_manager_list_users (manager);
-        g_object_unref (manager);
-
-        for (l = users; l; l = l->next) {
-		const char *lang;
-		char *language;
-
-                user = l->data;
-                lang = um_user_get_language (user);
-                if (!lang || !cc_common_language_has_font (lang)) {
-                        continue;
-                }
-
-                name = gdm_normalize_language_name (lang);
-                if (g_hash_table_lookup (ht, name) != NULL) {
-                        g_free (name);
-                        continue;
-                }
-
-                language = gdm_get_language_from_name (name, NULL);
-
-                g_hash_table_insert (ht, name, language);
-        }
-
-        g_slist_free (users);
+	/* Add the languages used by other users on the system */
+        add_other_users_language (ht);
 
         /* Make sure the current locale is present */
         name = cc_common_language_get_current_language ();
@@ -149,7 +195,7 @@ languages_foreach_cb (gpointer key,
 }
 
 void
-um_add_user_languages (GtkTreeModel *model)
+cc_add_user_languages (GtkTreeModel *model)
 {
         char *name;
         GtkTreeIter iter;
@@ -197,7 +243,7 @@ remove_async (gpointer data)
 }
 
 static gboolean
-finish_um_language_chooser (gpointer user_data)
+finish_language_chooser (gpointer user_data)
 {
 	GtkWidget *chooser = (GtkWidget *) user_data;
 	GtkWidget *list;
@@ -301,7 +347,7 @@ filter_languages (GtkTreeModel *model,
 }
 
 GtkWidget *
-um_language_chooser_new (GtkWidget *parent)
+cc_language_chooser_new (GtkWidget *parent)
 {
         GtkBuilder *builder;
         const char *filename;
@@ -358,9 +404,11 @@ um_language_chooser_new (GtkWidget *parent)
         gdk_window_set_cursor (gtk_widget_get_window (parent), cursor);
         g_object_unref (cursor);
 
+	gtk_window_set_transient_for (GTK_WINDOW (chooser), GTK_WINDOW (parent));
+
 	g_object_set_data_full (G_OBJECT (chooser), "user-langs",
 				user_langs, (GDestroyNotify) g_hash_table_destroy);
-        timeout = g_idle_add ((GSourceFunc) finish_um_language_chooser, chooser);
+        timeout = g_idle_add ((GSourceFunc) finish_language_chooser, chooser);
         g_object_set_data (G_OBJECT (chooser), "timeout", GUINT_TO_POINTER (timeout));
         g_object_weak_ref (G_OBJECT (chooser), (GWeakNotify) remove_timeout, GUINT_TO_POINTER (timeout));
 
diff --git a/panels/user-accounts/um-language-dialog.h b/panels/common/cc-language-chooser.h
similarity index 74%
rename from panels/user-accounts/um-language-dialog.h
rename to panels/common/cc-language-chooser.h
index 9b476e3..4929436 100644
--- a/panels/user-accounts/um-language-dialog.h
+++ b/panels/common/cc-language-chooser.h
@@ -19,19 +19,18 @@
  * Written by: Matthias Clasen <mclasen redhat com>
  */
 
-#ifndef __UM_LANGUAGE_DIALOG_H__
-#define __UM_LANGUAGE_DIALOG_H__
+#ifndef __CC_LANGUAGE_CHOOSER_H__
+#define __CC_LANGUAGE_CHOOSER_H__
 
 #include <gtk/gtk.h>
-#include "um-user.h"
 
 G_BEGIN_DECLS
 
-void              um_add_user_languages            (GtkTreeModel *model);
+void              cc_add_user_languages            (GtkTreeModel *model);
 
-GtkWidget        *um_language_chooser_new          (GtkWidget *parent);
-void              um_language_chooser_clear_filter (GtkWidget *chooser);
-gchar            *um_language_chooser_get_language (GtkWidget *chooser);
+GtkWidget        *cc_language_chooser_new          (GtkWidget *parent);
+void              cc_language_chooser_clear_filter (GtkWidget *chooser);
+gchar            *cc_language_chooser_get_language (GtkWidget *chooser);
 
 G_END_DECLS
 
diff --git a/panels/user-accounts/data/language-chooser.ui b/panels/common/language-chooser.ui
similarity index 100%
rename from panels/user-accounts/data/language-chooser.ui
rename to panels/common/language-chooser.ui
diff --git a/panels/user-accounts/Makefile.am b/panels/user-accounts/Makefile.am
index 6bc4f39..6a3f298 100644
--- a/panels/user-accounts/Makefile.am
+++ b/panels/user-accounts/Makefile.am
@@ -40,8 +40,6 @@ libuser_accounts_la_SOURCES =		\
 	um-user-manager.c 		\
 	um-account-dialog.h		\
 	um-account-dialog.c		\
-	um-language-dialog.h 		\
-	um-language-dialog.c		\
 	um-password-dialog.h		\
 	um-password-dialog.c		\
 	um-photo-dialog.h		\
diff --git a/panels/user-accounts/data/Makefile.am b/panels/user-accounts/data/Makefile.am
index bccb64e..dbc17c6 100644
--- a/panels/user-accounts/data/Makefile.am
+++ b/panels/user-accounts/data/Makefile.am
@@ -3,7 +3,6 @@ SUBDIRS = faces icons
 uidir = $(pkgdatadir)/ui/user-accounts
 ui_DATA = \
 	account-dialog.ui	\
-	language-chooser.ui	\
 	password-dialog.ui	\
 	photo-dialog.ui		\
 	user-accounts-dialog.ui \
diff --git a/panels/user-accounts/um-user-panel.c b/panels/user-accounts/um-user-panel.c
index 4510924..26efdcc 100644
--- a/panels/user-accounts/um-user-panel.c
+++ b/panels/user-accounts/um-user-panel.c
@@ -49,7 +49,7 @@
 #include "um-editable-combo.h"
 
 #include "um-account-dialog.h"
-#include "um-language-dialog.h"
+#include "cc-language-chooser.h"
 #include "um-password-dialog.h"
 #include "um-photo-dialog.h"
 #include "um-fingerprint-dialog.h"
@@ -582,7 +582,7 @@ show_user (UmUser *user, UmUserPanelPrivate *d)
 
         widget = get_widget (d, "account-language-combo");
         model = um_editable_combo_get_model (UM_EDITABLE_COMBO (widget));
-        um_add_user_languages (model);
+        cc_add_user_languages (model);
 
         lang = g_strdup (um_user_get_language (user));
         if (!lang)
@@ -673,7 +673,7 @@ language_response (GtkDialog         *dialog,
         model = um_editable_combo_get_model (UM_EDITABLE_COMBO (combo));
 
         if (response_id == GTK_RESPONSE_OK) {
-                lang = um_language_chooser_get_language (GTK_WIDGET (dialog));
+                lang = cc_language_chooser_get_language (GTK_WIDGET (dialog));
                 um_user_set_language (user, lang);
         }
         else {
@@ -714,15 +714,14 @@ language_changed (UmEditableCombo    *combo,
         }
 
         if (d->language_chooser) {
-		um_language_chooser_clear_filter (d->language_chooser);
+		cc_language_chooser_clear_filter (d->language_chooser);
                 gtk_window_present (GTK_WINDOW (d->language_chooser));
                 gtk_widget_set_sensitive (GTK_WIDGET (combo), FALSE);
                 return;
         }
 
-        d->language_chooser = um_language_chooser_new (gtk_widget_get_toplevel (d->main_box));
-        gtk_window_set_transient_for (GTK_WINDOW (d->language_chooser),
-                                      GTK_WINDOW (gtk_widget_get_toplevel (d->main_box)));
+        d->language_chooser = cc_language_chooser_new (gtk_widget_get_toplevel (d->main_box));
+
         g_signal_connect (d->language_chooser, "response",
                           G_CALLBACK (language_response), d);
         g_signal_connect (d->language_chooser, "delete-event",



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