[gnome-online-accounts] google: Change how the "Identity" is shown is for an account



commit 93debe10ee88f2cc44a814f1e84dad25ea9e9ad0
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Mar 12 17:47:53 2012 +0100

    google: Change how the "Identity" is shown is for an account
    
    Implemented design:
    http://ur1.ca/8m05c
    https://live.gnome.org/Design/SystemSettings/OnlineAccounts
    
    Fixes: https://bugzilla.gnome.org/671982

 src/goabackend/goagoogleprovider.c |    2 +-
 src/goabackend/goaprovider.c       |  134 ++++++++++++++++++++++++------------
 src/goabackend/goaprovider.h       |    4 +-
 3 files changed, 94 insertions(+), 46 deletions(-)
---
diff --git a/src/goabackend/goagoogleprovider.c b/src/goabackend/goagoogleprovider.c
index 4047cce..33c5d04 100644
--- a/src/goabackend/goagoogleprovider.c
+++ b/src/goabackend/goagoogleprovider.c
@@ -422,7 +422,7 @@ show_account (GoaProvider         *provider,
   /* Chain up */
   GOA_PROVIDER_CLASS (goa_google_provider_parent_class)->show_account (provider, client, object, vbox, table);
 
-  goa_util_add_row_editable_label_from_keyfile (table, object, _("Email Address"), "Identity", FALSE);
+  goa_util_add_account_info (table, object);
   goa_util_add_heading (table, _("Use this account for"));
   goa_util_add_row_switch_from_keyfile (table, object, _("Mail"), "MailEnabled");
   goa_util_add_row_switch_from_keyfile (table, object, _("Calendar"), "CalendarEnabled");
diff --git a/src/goabackend/goaprovider.c b/src/goabackend/goaprovider.c
index 3d08387..0775749 100644
--- a/src/goabackend/goaprovider.c
+++ b/src/goabackend/goaprovider.c
@@ -1,6 +1,6 @@
 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 /*
- * Copyright (C) 2011 Red Hat, Inc.
+ * Copyright (C) 2011, 2012 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -21,6 +21,7 @@
  */
 
 #include "config.h"
+
 #include <glib/gi18n-lib.h>
 #include <gnome-keyring.h>
 
@@ -1036,6 +1037,90 @@ goa_util_lookup_keyfile_boolean (GoaObject    *object,
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+static gchar *
+get_value_from_keyfile (GoaAccount *account, const gchar *key)
+{
+  GError *error = NULL;
+  GKeyFile *key_file;
+  gchar *group;
+  gchar *path;
+  gchar *value = NULL;
+
+  path = g_strdup_printf ("%s/goa-1.0/accounts.conf", g_get_user_config_dir ());
+  group = g_strdup_printf ("Account %s", goa_account_get_id (account));
+
+  key_file = g_key_file_new ();
+  error = NULL;
+  if (!g_key_file_load_from_file (key_file,
+                                  path,
+                                  G_KEY_FILE_NONE,
+                                  &error))
+    {
+      goa_warning ("Error loading keyfile %s: %s (%s, %d)",
+                   path,
+                   error->message, g_quark_to_string (error->domain), error->code);
+      g_error_free (error);
+      goto out;
+    }
+
+  value = g_key_file_get_string (key_file, group, key, &error);
+  if (value == NULL)
+    {
+      /* this is not fatal (think upgrade-path) */
+      goa_debug ("Error getting value for key %s in group `%s' from keyfile %s: %s (%s, %d)",
+                 key,
+                 group,
+                 path,
+                 error->message, g_quark_to_string (error->domain), error->code);
+      g_error_free (error);
+      goto out;
+    }
+
+ out:
+  g_key_file_free (key_file);
+  g_free (group);
+  g_free (path);
+  return value;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+void
+goa_util_add_account_info (GtkTable *table, GoaObject *object)
+{
+  GIcon *icon;
+  GoaAccount *account;
+  GtkWidget *image;
+  GtkWidget *label;
+  const gchar *icon_str;
+  const gchar *name;
+  gchar *markup;
+  gchar *value;
+  guint num_rows;
+
+  gtk_table_get_size (table, &num_rows, NULL);
+  account = goa_object_peek_account (object);
+
+  icon_str = goa_account_get_provider_icon (account);
+  icon = g_icon_new_for_string (icon_str, NULL);
+  image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_DIALOG);
+  g_object_unref (icon);
+  gtk_misc_set_alignment (GTK_MISC (image), 1.0, 0.5);
+  gtk_table_attach (table, image, 0, 1, num_rows, num_rows + 1, GTK_FILL, GTK_FILL, 0, 0);
+
+  name = goa_account_get_provider_name (account);
+  value = get_value_from_keyfile (account, "Identity");
+  markup = g_strdup_printf ("<b>%s</b>\n%s", name, (value == NULL || value[0] == '\0') ? "\xe2\x80\x94" : value);
+  g_free (value);
+  label = gtk_label_new (NULL);
+  gtk_label_set_markup (GTK_LABEL (label), markup);
+  gtk_table_attach (table, label, 1, 2, num_rows, num_rows + 1, GTK_FILL, GTK_FILL, 0, 0);
+
+  return;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
 typedef struct {
   GoaObject *object;
   gchar *key;
@@ -1155,52 +1240,17 @@ goa_util_add_row_editable_label_from_keyfile (GtkTable     *table,
 {
   GoaAccount *account;
   GtkWidget *elabel;
-  GKeyFile *key_file;
-  gchar *path;
-  gchar *group;
-  GError *error;
   gchar *value;
 
-  key_file = NULL;
-  value = NULL;
-
   account = goa_object_peek_account (object);
   elabel = goa_editable_label_new ();
-  path = g_strdup_printf ("%s/goa-1.0/accounts.conf", g_get_user_config_dir ());
-  group = g_strdup_printf ("Account %s", goa_account_get_id (account));
 
-  key_file = g_key_file_new ();
-  error = NULL;
-  if (!g_key_file_load_from_file (key_file,
-                                  path,
-                                  G_KEY_FILE_NONE,
-                                  &error))
-    {
-      goa_warning ("Error loading keyfile %s: %s (%s, %d)",
-                   path,
-                   error->message, g_quark_to_string (error->domain), error->code);
-      g_error_free (error);
-      goto out;
-    }
-  value = g_key_file_get_string (key_file,
-                                 group,
-                                 key,
-                                 &error);
+  value = get_value_from_keyfile (account, key);
   if (value == NULL)
-    {
-      /* this is not fatal (think upgrade-path) */
-      goa_debug ("Error getting value for key %s in group `%s' from keyfile %s: %s (%s, %d)",
-                 key,
-                 group,
-                 path,
-                 error->message, g_quark_to_string (error->domain), error->code);
-      g_error_free (error);
-      goto out;
-    }
+    goto out;
 
   goa_editable_label_set_text (GOA_EDITABLE_LABEL (elabel), value);
-
- out:
+  g_free (value);
 
   if (editable)
     {
@@ -1213,11 +1263,7 @@ goa_util_add_row_editable_label_from_keyfile (GtkTable     *table,
                              0); /* GConnectFlags */
     }
 
-  g_free (value);
-  g_free (group);
-  g_free (path);
-  if (key_file != NULL)
-    g_key_file_free (key_file);
+ out:
   return goa_util_add_row_widget (table, label_text, elabel);
 }
 
diff --git a/src/goabackend/goaprovider.h b/src/goabackend/goaprovider.h
index 590850b..75992b7 100644
--- a/src/goabackend/goaprovider.h
+++ b/src/goabackend/goaprovider.h
@@ -1,6 +1,6 @@
 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 /*
- * Copyright (C) 2011 Red Hat, Inc.
+ * Copyright (C) 2011, 2012 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -194,6 +194,8 @@ gboolean
 goa_util_lookup_keyfile_boolean (GoaObject    *object,
                                  const gchar  *key);
 
+void       goa_util_add_account_info (GtkTable *table, GoaObject *object);
+
 GtkWidget *goa_util_add_row_editable_label_from_keyfile (GtkTable     *table,
                                                          GoaObject    *object,
                                                          const gchar  *label_text,



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