[gnome-online-accounts] Add API to enable/disable Mail, Calendar, Contacts, Chat & Documents



commit 68ee3e50f97ea6dd3e57ab2dd1d21d2ffd44d8b6
Author: Debarshi Ray <debarshir gnome org>
Date:   Sat Mar 31 17:07:34 2012 +0200

    Add API to enable/disable Mail, Calendar, Contacts, Chat & Documents
    
    The following properties were added to the
    org.gnome.OnlineAccounts.Account interface:
      * MailDisabled
      * CalendarDisabled
      * ContactsDisabled
      * ChatDisabled
      * DocumentsDisabled
    
    The switches in the control center panel now use these properties
    instead of changing the values directly in the accounts.conf file. The
    providers register signal handlers to update the file when the
    properties are toggled.
    
    https://bugzilla.gnome.org/657905

 data/dbus-interfaces.xml                |   52 ++++++
 src/daemon/goadaemon.c                  |    2 +-
 src/goabackend/goafacebookprovider.c    |   21 ++-
 src/goabackend/goagoogleprovider.c      |   41 ++++-
 src/goabackend/goaoauth2provider.c      |    1 +
 src/goabackend/goaoauthprovider.c       |    1 +
 src/goabackend/goaprovider.c            |  300 +++++++------------------------
 src/goabackend/goaprovider.h            |    8 +-
 src/goabackend/goatwitterprovider.c     |    2 +
 src/goabackend/goawindowsliveprovider.c |   29 +++-
 src/goabackend/goayahooprovider.c       |    2 +
 11 files changed, 213 insertions(+), 246 deletions(-)
---
diff --git a/data/dbus-interfaces.xml b/data/dbus-interfaces.xml
index 2e0c5ef..fe0aa24 100644
--- a/data/dbus-interfaces.xml
+++ b/data/dbus-interfaces.xml
@@ -98,6 +98,58 @@
     -->
     <property name="PresentationIdentity" type="s" access="read"/>
 
+    <!-- MailDisabled:
+         If %TRUE, the account will not expose any
+         #org.gnome.OnlineAccounts.Mail interface. If the account does not
+         provide email-like messaging capabilities, this property does
+         nothing.
+
+         Note that the #org.gnomeOnlineAccounts.Mail interface is added or
+         removed from the account asynchronously.
+    -->
+    <property name="MailDisabled" type="b" access="readwrite"/>
+
+    <!-- CalendarDisabled:
+         If %TRUE, the account will not expose any
+         #org.gnome.OnlineAccounts.Calendar interface. If the account does not
+         provide calendar-like capabilities, this property does nothing.
+
+         Note that the #org.gnomeOnlineAccounts.Calendar interface is added or
+         removed from the account asynchronously.
+    -->
+    <property name="CalendarDisabled" type="b" access="readwrite"/>
+
+    <!-- ContactsDisabled:
+         If %TRUE, the account will not expose any
+         #org.gnome.OnlineAccounts.Contacts interface. If the account does not
+         provide contacts-like capabilities, this property does nothing.
+
+         Note that the #org.gnomeOnlineAccounts.Contacts interface is added or
+         removed from the account asynchronously.
+    -->
+    <property name="ContactsDisabled" type="b" access="readwrite"/>
+
+    <!-- ChatDisabled:
+         If %TRUE, the account will not expose any
+         #org.gnome.OnlineAccounts.Chat interface. If the account does not
+         provide chat-like messaging capabilities, this property does
+         nothing.
+
+         Note that the #org.gnomeOnlineAccounts.Chat interface is added or
+         removed from the account asynchronously.
+    -->
+    <property name="ChatDisabled" type="b" access="readwrite"/>
+
+    <!-- DocumentsDisabled:
+         If %TRUE, the account will not expose any
+         #org.gnome.OnlineAccounts.Documents interface. If the account does not
+         provide documents-like capabilities, this property does nothing.
+
+         Note that the #org.gnomeOnlineAccounts.Documents interface is added or
+         removed from the account asynchronously.
+    -->
+    <property name="DocumentsDisabled" type="b" access="readwrite"/>
+
     <!--
         Remove:
 
diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c
index ccdf35d..0d3b290 100644
--- a/src/daemon/goadaemon.c
+++ b/src/daemon/goadaemon.c
@@ -448,7 +448,7 @@ update_account_object (GoaDaemon           *daemon,
   goa_account_set_presentation_identity (account, presentation_identity);
 
   error = NULL;
-  if (!goa_provider_build_object (provider, object, key_file, group, &error))
+  if (!goa_provider_build_object (provider, object, key_file, group, just_added, &error))
     {
       goa_warning ("Error parsing account: %s (%s, %d)",
                    error->message, g_quark_to_string (error->domain), error->code);
diff --git a/src/goabackend/goafacebookprovider.c b/src/goabackend/goafacebookprovider.c
index 7560024..832e61a 100644
--- a/src/goabackend/goafacebookprovider.c
+++ b/src/goabackend/goafacebookprovider.c
@@ -255,20 +255,27 @@ build_object (GoaProvider         *provider,
               GoaObjectSkeleton   *object,
               GKeyFile            *key_file,
               const gchar         *group,
+              gboolean             just_added,
               GError             **error)
 {
+  GoaAccount *account;
   GoaChat *chat = NULL;
   gboolean chat_enabled;
   gboolean ret = FALSE;
 
+  account = NULL;
+
   /* Chain up */
   if (!GOA_PROVIDER_CLASS (goa_facebook_provider_parent_class)->build_object (provider,
                                                                               object,
                                                                               key_file,
                                                                               group,
+                                                                              just_added,
                                                                               error))
     goto out;
 
+  account = goa_object_get_account (GOA_OBJECT (object));
+
   /* Chat */
   chat = goa_object_get_chat (GOA_OBJECT (object));
   chat_enabled = g_key_file_get_boolean (key_file, group, "ChatEnabled", NULL);
@@ -286,12 +293,22 @@ build_object (GoaProvider         *provider,
         goa_object_skeleton_set_chat (object, NULL);
     }
 
+  if (just_added)
+    {
+      goa_account_set_chat_disabled (account, !chat_enabled);
+      g_signal_connect (account,
+                        "notify::chat-disabled",
+                        G_CALLBACK (goa_util_account_notify_property_cb),
+                        "ChatEnabled");
+    }
+
   ret = TRUE;
 
  out:
   if (chat != NULL)
     g_object_unref (chat);
-
+  if (account != NULL)
+    g_object_unref (account);
   return ret;
 }
 
@@ -317,7 +334,7 @@ show_account (GoaProvider         *provider,
 
   goa_util_add_row_switch_from_keyfile_with_blurb (GTK_TABLE (table), object,
                                                    _("Use for"),
-                                                   "ChatEnabled",
+                                                   "chat-disabled",
                                                    _("Chat"));
 }
 
diff --git a/src/goabackend/goagoogleprovider.c b/src/goabackend/goagoogleprovider.c
index 0b34a8b..92c0958 100644
--- a/src/goabackend/goagoogleprovider.c
+++ b/src/goabackend/goagoogleprovider.c
@@ -268,6 +268,7 @@ build_object (GoaProvider         *provider,
               GoaObjectSkeleton   *object,
               GKeyFile            *key_file,
               const gchar         *group,
+              gboolean             just_added,
               GError             **error)
 {
   GoaAccount *account;
@@ -296,6 +297,7 @@ build_object (GoaProvider         *provider,
                                                                             object,
                                                                             key_file,
                                                                             group,
+                                                                            just_added,
                                                                             error))
     goto out;
 
@@ -400,6 +402,35 @@ build_object (GoaProvider         *provider,
         goa_object_skeleton_set_documents (object, NULL);
     }
 
+  if (just_added)
+    {
+      goa_account_set_mail_disabled (account, !mail_enabled);
+      goa_account_set_calendar_disabled (account, !calendar_enabled);
+      goa_account_set_contacts_disabled (account, !contacts_enabled);
+      goa_account_set_chat_disabled (account, !chat_enabled);
+      goa_account_set_documents_disabled (account, !documents_enabled);
+
+      g_signal_connect (account,
+                        "notify::mail-disabled",
+                        G_CALLBACK (goa_util_account_notify_property_cb),
+                        "MailEnabled");
+      g_signal_connect (account,
+                        "notify::calendar-disabled",
+                        G_CALLBACK (goa_util_account_notify_property_cb),
+                        "CalendarEnabled");
+      g_signal_connect (account,
+                        "notify::contacts-disabled",
+                        G_CALLBACK (goa_util_account_notify_property_cb),
+                        "ContactsEnabled");
+      g_signal_connect (account,
+                        "notify::chat-disabled",
+                        G_CALLBACK (goa_util_account_notify_property_cb),
+                        "ChatEnabled");
+      g_signal_connect (account,
+                        "notify::documents-disabled",
+                        G_CALLBACK (goa_util_account_notify_property_cb),
+                        "DocumentsEnabled");
+    }
 
   ret = TRUE;
 
@@ -443,27 +474,27 @@ show_account (GoaProvider         *provider,
 
   goa_util_add_row_switch_from_keyfile_with_blurb (GTK_TABLE (table), object,
                                                    _("Use for"),
-                                                   "MailEnabled",
+                                                   "mail-disabled",
                                                    _("Mail"));
 
   goa_util_add_row_switch_from_keyfile_with_blurb (GTK_TABLE (table), object,
                                                    NULL,
-                                                   "CalendarEnabled",
+                                                   "calendar-disabled",
                                                    _("Calendar"));
 
   goa_util_add_row_switch_from_keyfile_with_blurb (GTK_TABLE (table), object,
                                                    NULL,
-                                                   "ContactsEnabled",
+                                                   "contacts-disabled",
                                                    _("Contacts"));
 
   goa_util_add_row_switch_from_keyfile_with_blurb (GTK_TABLE (table), object,
                                                    NULL,
-                                                   "ChatEnabled",
+                                                   "chat-disabled",
                                                    _("Chat"));
 
   goa_util_add_row_switch_from_keyfile_with_blurb (GTK_TABLE (table), object,
                                                    NULL,
-                                                   "DocumentsEnabled",
+                                                   "documents-disabled",
                                                    _("Documents"));
 }
 
diff --git a/src/goabackend/goaoauth2provider.c b/src/goabackend/goaoauth2provider.c
index 92cc9f2..468989c 100644
--- a/src/goabackend/goaoauth2provider.c
+++ b/src/goabackend/goaoauth2provider.c
@@ -1483,6 +1483,7 @@ goa_oauth2_provider_build_object (GoaProvider         *provider,
                                   GoaObjectSkeleton   *object,
                                   GKeyFile            *key_file,
                                   const gchar         *group,
+                                  gboolean             just_added,
                                   GError             **error)
 {
   GoaOAuth2Based *oauth2_based;
diff --git a/src/goabackend/goaoauthprovider.c b/src/goabackend/goaoauthprovider.c
index 4aa3fd6..383ebf1 100644
--- a/src/goabackend/goaoauthprovider.c
+++ b/src/goabackend/goaoauthprovider.c
@@ -1466,6 +1466,7 @@ goa_oauth_provider_build_object (GoaProvider         *provider,
                                  GoaObjectSkeleton   *object,
                                  GKeyFile            *key_file,
                                  const gchar         *group,
+                                 gboolean             just_added,
                                  GError             **error)
 {
   GoaOAuthBased *oauth_based;
diff --git a/src/goabackend/goaprovider.c b/src/goabackend/goaprovider.c
index a88cbd7..0bd6241 100644
--- a/src/goabackend/goaprovider.c
+++ b/src/goabackend/goaprovider.c
@@ -17,7 +17,8 @@
  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  * Boston, MA 02111-1307, USA.
  *
- * Author: David Zeuthen <davidz redhat com>
+ * Authors: David Zeuthen <davidz redhat com>
+ *          Debarshi Ray <debarshir gnome org>
  */
 
 #include "config.h"
@@ -53,6 +54,7 @@ static gboolean goa_provider_build_object_real (GoaProvider         *provider,
                                                 GoaObjectSkeleton   *object,
                                                 GKeyFile            *key_file,
                                                 const gchar         *group,
+                                                gboolean             just_added,
                                                 GError             **error);
 
 static void goa_provider_show_account_real (GoaProvider         *provider,
@@ -318,6 +320,7 @@ goa_provider_show_account_real (GoaProvider         *provider,
  * @object: The #GoaObjectSkeleton that is being built.
  * @key_file: The #GKeyFile with configuation data.
  * @group: The group in @key_file to get data from.
+ * @just_added: Whether the account was newly created or being updated.
  * @error: Return location for error or %NULL.
  *
  * This method is called when construction account #GoaObject<!-- -->
@@ -341,6 +344,7 @@ goa_provider_build_object (GoaProvider         *provider,
                            GoaObjectSkeleton   *object,
                            GKeyFile            *key_file,
                            const gchar         *group,
+                           gboolean             just_added,
                            GError             **error)
 {
   g_return_val_if_fail (GOA_IS_PROVIDER (provider), FALSE);
@@ -348,7 +352,7 @@ goa_provider_build_object (GoaProvider         *provider,
   g_return_val_if_fail (key_file != NULL, FALSE);
   g_return_val_if_fail (group != NULL, FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
-  return GOA_PROVIDER_GET_CLASS (provider)->build_object (provider, object, key_file, group, error);
+  return GOA_PROVIDER_GET_CLASS (provider)->build_object (provider, object, key_file, group, just_added, error);
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
@@ -531,6 +535,7 @@ goa_provider_build_object_real (GoaProvider         *provider,
                                 GoaObjectSkeleton   *object,
                                 GKeyFile            *key_file,
                                 const gchar         *group,
+                                gboolean             just_added,
                                 GError             **error)
 {
   /* does nothing */
@@ -1104,14 +1109,17 @@ goa_util_lookup_keyfile_boolean (GoaObject    *object,
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-static gboolean
-get_boolean_from_keyfile (GoaAccount *account, const gchar *key)
+static void
+goa_util_set_keyfile_boolean (GoaAccount *account, const gchar *key, gboolean value)
 {
-  GError *error = NULL;
+  GError *error;
   GKeyFile *key_file;
+  gchar *contents;
   gchar *group;
   gchar *path;
-  gboolean value = FALSE;
+  gsize length;
+
+  contents = 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));
@@ -1120,36 +1128,57 @@ get_boolean_from_keyfile (GoaAccount *account, const gchar *key)
   error = NULL;
   if (!g_key_file_load_from_file (key_file,
                                   path,
-                                  G_KEY_FILE_NONE,
+                                  G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
                                   &error))
     {
       goa_warning ("Error loading keyfile %s: %s (%s, %d)",
                    path,
-                   error->message, g_quark_to_string (error->domain), error->code);
+                   error->message,
+                   g_quark_to_string (error->domain),
+                   error->code);
       g_error_free (error);
       goto out;
     }
 
-  value = g_key_file_get_boolean (key_file, group, key, &error);
-  if (error != NULL)
+  g_key_file_set_boolean (key_file, group, key, value);
+  contents = g_key_file_to_data (key_file, &length, NULL);
+
+  error = NULL;
+  if (!g_file_set_contents (path, contents, length, &error))
     {
-      /* 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_prefix_error (&error, "Error writing key-value-file %s: ", path);
+      goa_warning ("%s (%s, %d)", error->message, g_quark_to_string (error->domain), error->code);
       g_error_free (error);
       goto out;
     }
 
  out:
+  g_free (contents);
   g_key_file_free (key_file);
   g_free (group);
   g_free (path);
-  return value;
 }
 
+void
+goa_util_account_notify_property_cb (GObject *object, GParamSpec *pspec, gpointer user_data)
+{
+  GoaAccount *account;
+  gboolean value;
+  const gchar *key;
+  const gchar *name;
+
+  g_return_if_fail (GOA_IS_ACCOUNT (object));
+
+  account = GOA_ACCOUNT (object);
+  key = user_data;
+  name = g_param_spec_get_name (pspec);
+
+  g_object_get (account, name, &value, NULL);
+  goa_util_set_keyfile_boolean (account, key, !value);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
 static gchar *
 get_string_from_keyfile (GoaAccount *account, const gchar *key)
 {
@@ -1386,85 +1415,12 @@ goa_util_add_row_editable_label_from_keyfile (GtkTable     *table,
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-static void
-keyfile_switch_on_notify_active (GObject      *object,
-                                 GParamSpec   *pspec,
-                                 gpointer      user_data)
-{
-  KeyFileEditableData *data = user_data;
-  GoaAccount *account;
-  GError *error;
-  GKeyFile *key_file;
-  gchar *path;
-  gchar *group;
-  gchar *contents;
-  gsize length;
-
-  account = goa_object_peek_account (data->object);
-  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_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
-                                  &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;
-    }
-
-  g_key_file_set_boolean (key_file,
-                          group,
-                          data->key,
-                          gtk_switch_get_active (GTK_SWITCH (object)));
-
-  error = NULL;
-  contents = g_key_file_to_data (key_file,
-                                 &length,
-                                 &error);
-  if (contents == NULL)
-    {
-      g_prefix_error (&error,
-                      "Error generating key-value-file %s: ",
-                      path);
-      goa_warning ("%s (%s, %d)",
-                   error->message, g_quark_to_string (error->domain), error->code);
-      g_error_free (error);
-      goto out;
-    }
-
-  error = NULL;
-  if (!g_file_set_contents (path,
-                            contents,
-                            length,
-                            &error))
-    {
-      g_prefix_error (&error,
-                      "Error writing key-value-file %s: ",
-                      path);
-      goa_warning ("%s (%s, %d)",
-                   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);
-}
-
 /**
  * goa_util_add_row_switch_from_keyfile:
  * @table: A #GtkTable.
  * @object: A #GoaObject for an account.
  * @label_text: (allow-none): The text to insert on the left side or %NULL for no label.
- * @key: The key in the key-value file for @object to look up.
+ * @property: The property of @object to be bound to the new widget.
  *
  * Adds a #GtkSwitch to @table that reads its #GtkSwitch:active value
  * from the key-value file for @object using @key. If it's switched,
@@ -1476,7 +1432,7 @@ GtkWidget *
 goa_util_add_row_switch_from_keyfile (GtkTable     *table,
                                       GoaObject    *object,
                                       const gchar  *label_text,
-                                      const gchar  *key)
+                                      const gchar  *property)
 {
   GoaAccount *account;
   GtkWidget *hbox;
@@ -1484,16 +1440,13 @@ goa_util_add_row_switch_from_keyfile (GtkTable     *table,
   gboolean value;
 
   account = goa_object_peek_account (object);
-  value = get_boolean_from_keyfile (account, key);
+  g_object_get (account, property, &value, NULL);
   switch_ = gtk_switch_new ();
-  gtk_switch_set_active (GTK_SWITCH (switch_), value);
+  gtk_switch_set_active (GTK_SWITCH (switch_), !value);
 
-  g_signal_connect_data (switch_,
-                         "notify::active",
-                         G_CALLBACK (keyfile_switch_on_notify_active),
-                         keyfile_editable_data_new (object, key),
-                         (GClosureNotify) keyfile_editable_data_free,
-                         0); /* GConnectFlags */
+  g_object_bind_property (switch_, "active",
+                          account, property,
+                          G_BINDING_BIDIRECTIONAL | G_BINDING_INVERT_BOOLEAN);
 
   hbox = gtk_hbox_new (0, FALSE);
   gtk_box_pack_start (GTK_BOX (hbox), switch_, FALSE, TRUE, 0);
@@ -1505,7 +1458,7 @@ GtkWidget *
 goa_util_add_row_switch_from_keyfile_with_blurb (GtkTable     *table,
                                                  GoaObject    *object,
                                                  const gchar  *label_text,
-                                                 const gchar  *key,
+                                                 const gchar  *property,
                                                  const gchar  *blurb)
 {
   GoaAccount *account;
@@ -1514,16 +1467,13 @@ goa_util_add_row_switch_from_keyfile_with_blurb (GtkTable     *table,
   gboolean value;
 
   account = goa_object_peek_account (object);
-  value = get_boolean_from_keyfile (account, key);
+  g_object_get (account, property, &value, NULL);
   switch_ = gtk_switch_new ();
-  gtk_switch_set_active (GTK_SWITCH (switch_), value);
+  gtk_switch_set_active (GTK_SWITCH (switch_), !value);
 
-  g_signal_connect_data (switch_,
-                         "notify::active",
-                         G_CALLBACK (keyfile_switch_on_notify_active),
-                         keyfile_editable_data_new (object, key),
-                         (GClosureNotify) keyfile_editable_data_free,
-                         0); /* GConnectFlags */
+  g_object_bind_property (switch_, "active",
+                          account, property,
+                          G_BINDING_BIDIRECTIONAL | G_BINDING_INVERT_BOOLEAN);
 
   hbox = gtk_hbox_new (0, FALSE);
 
@@ -1543,85 +1493,12 @@ goa_util_add_row_switch_from_keyfile_with_blurb (GtkTable     *table,
 
 /* ---------------------------------------------------------------------------------------------------- */
 
-static void
-keyfile_check_button_on_notify_active (GObject      *object,
-                                       GParamSpec   *pspec,
-                                       gpointer      user_data)
-{
-  KeyFileEditableData *data = user_data;
-  GoaAccount *account;
-  GError *error;
-  GKeyFile *key_file;
-  gchar *path;
-  gchar *group;
-  gchar *contents;
-  gsize length;
-
-  account = goa_object_peek_account (data->object);
-  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_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
-                                  &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;
-    }
-
-  g_key_file_set_boolean (key_file,
-                          group,
-                          data->key,
-                          gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (object)));
-
-  error = NULL;
-  contents = g_key_file_to_data (key_file,
-                                 &length,
-                                 &error);
-  if (contents == NULL)
-    {
-      g_prefix_error (&error,
-                      "Error generating key-value-file %s: ",
-                      path);
-      goa_warning ("%s (%s, %d)",
-                   error->message, g_quark_to_string (error->domain), error->code);
-      g_error_free (error);
-      goto out;
-    }
-
-  error = NULL;
-  if (!g_file_set_contents (path,
-                            contents,
-                            length,
-                            &error))
-    {
-      g_prefix_error (&error,
-                      "Error writing key-value-file %s: ",
-                      path);
-      goa_warning ("%s (%s, %d)",
-                   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);
-}
-
 /**
  * goa_util_add_row_check_button_from_keyfile:
  * @table: A #GtkTable.
  * @object: A #GoaObject for an account.
  * @label_text: (allow-none): The text to insert on the left side or %NULL for no label.
- * @key: The key in the key-value file for @object to look up.
+ * @property: The property of @object to be bound to the new widget.
  * @value_mnemonic: The mnemonic text to use for the check button.
  *
  * Adds a #GtkCheckButton to @table that reads its value from the
@@ -1634,66 +1511,21 @@ GtkWidget *
 goa_util_add_row_check_button_from_keyfile (GtkTable     *table,
                                             GoaObject    *object,
                                             const gchar  *label_text,
-                                            const gchar  *key,
+                                            const gchar  *property,
                                             const gchar  *value_mnemonic)
 {
   GoaAccount *account;
   GtkWidget *check_button;
-  GKeyFile *key_file;
-  gchar *path;
-  gchar *group;
-  GError *error;
   gboolean value;
 
-  key_file = NULL;
-
   account = goa_object_peek_account (object);
+  g_object_get (account, property, &value, NULL);
   check_button = gtk_check_button_new_with_mnemonic (value_mnemonic);
-  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_boolean (key_file,
-                                  group,
-                                  key,
-                                  &error);
-  if (error != NULL)
-    {
-      /* this is not fatal (think upgrade-path) */
-      goa_debug ("Error getting boolean 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;
-    }
-
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), value);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), !value);
 
- out:
-  g_signal_connect_data (check_button,
-                         "notify::active",
-                         G_CALLBACK (keyfile_check_button_on_notify_active),
-                         keyfile_editable_data_new (object, key),
-                         (GClosureNotify) keyfile_editable_data_free,
-                         0); /* GConnectFlags */
-  if (key_file != NULL)
-    g_key_file_free (key_file);
-  g_free (group);
-  g_free (path);
+  g_object_bind_property (check_button, "active",
+                          account, property,
+                          G_BINDING_BIDIRECTIONAL | G_BINDING_INVERT_BOOLEAN);
 
   return goa_util_add_row_widget (table, label_text, check_button);
 }
diff --git a/src/goabackend/goaprovider.h b/src/goabackend/goaprovider.h
index 0a97e09..d1d65b8 100644
--- a/src/goabackend/goaprovider.h
+++ b/src/goabackend/goaprovider.h
@@ -17,7 +17,8 @@
  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  * Boston, MA 02111-1307, USA.
  *
- * Author: David Zeuthen <davidz redhat com>
+ * Authors: David Zeuthen <davidz redhat com>
+ *          Debarshi Ray <debarshir gnome org>
  */
 
 #if !defined (__GOA_BACKEND_INSIDE_GOA_BACKEND_H__) && !defined (GOA_BACKEND_COMPILATION)
@@ -92,6 +93,7 @@ struct _GoaProviderClass
                                      GoaObjectSkeleton  *object,
                                      GKeyFile           *key_file,
                                      const gchar        *group,
+                                     gboolean            just_added,
                                      GError            **error);
 
   /* virtual but with default implementation */
@@ -137,6 +139,7 @@ gboolean     goa_provider_build_object              (GoaProvider         *provid
                                                      GoaObjectSkeleton   *object,
                                                      GKeyFile            *key_file,
                                                      const gchar         *group,
+                                                     gboolean             just_added,
                                                      GError             **error);
 gboolean     goa_provider_store_credentials_sync    (GoaProvider         *provider,
                                                      GoaObject           *object,
@@ -198,6 +201,9 @@ gboolean
 goa_util_lookup_keyfile_boolean (GoaObject    *object,
                                  const gchar  *key);
 
+void
+goa_util_account_notify_property_cb (GObject *object, GParamSpec *pspec, gpointer user_data);
+
 void       goa_util_add_account_info (GtkTable *table, GoaObject *object);
 
 GtkWidget *goa_util_add_row_editable_label_from_keyfile (GtkTable     *table,
diff --git a/src/goabackend/goatwitterprovider.c b/src/goabackend/goatwitterprovider.c
index 8808375..0fd96ed 100644
--- a/src/goabackend/goatwitterprovider.c
+++ b/src/goabackend/goatwitterprovider.c
@@ -218,6 +218,7 @@ build_object (GoaProvider         *provider,
               GoaObjectSkeleton   *object,
               GKeyFile            *key_file,
               const gchar         *group,
+              gboolean             just_added,
               GError             **error)
 {
   gboolean ret;
@@ -228,6 +229,7 @@ build_object (GoaProvider         *provider,
                                                                              object,
                                                                              key_file,
                                                                              group,
+                                                                             just_added,
                                                                              error))
     goto out;
 
diff --git a/src/goabackend/goawindowsliveprovider.c b/src/goabackend/goawindowsliveprovider.c
index dbf287a..425c714 100644
--- a/src/goabackend/goawindowsliveprovider.c
+++ b/src/goabackend/goawindowsliveprovider.c
@@ -244,22 +244,29 @@ build_object (GoaProvider         *provider,
               GoaObjectSkeleton   *object,
               GKeyFile            *key_file,
               const gchar         *group,
+              gboolean             just_added,
               GError             **error)
 {
+  GoaAccount *account;
   GoaChat *chat = NULL;
   GoaDocuments *documents;
   gboolean chat_enabled;
   gboolean documents_enabled;
   gboolean ret = FALSE;
 
+  account = NULL;
+
   /* Chain up */
   if (!GOA_PROVIDER_CLASS (goa_windows_live_provider_parent_class)->build_object (provider,
                                                                               object,
                                                                               key_file,
                                                                               group,
+                                                                              just_added,
                                                                               error))
     goto out;
 
+  account = goa_object_get_account (GOA_OBJECT (object));
+
   /* Chat */
   chat = goa_object_get_chat (GOA_OBJECT (object));
   chat_enabled = g_key_file_get_boolean (key_file, group, "ChatEnabled", NULL);
@@ -295,12 +302,28 @@ build_object (GoaProvider         *provider,
         goa_object_skeleton_set_documents (object, NULL);
     }
 
+  if (just_added)
+    {
+      goa_account_set_chat_disabled (account, !chat_enabled);
+      goa_account_set_documents_disabled (account, !documents_enabled);
+
+      g_signal_connect (account,
+                        "notify::chat-disabled",
+                        G_CALLBACK (goa_util_account_notify_property_cb),
+                        "ChatEnabled");
+      g_signal_connect (account,
+                        "notify::documents-disabled",
+                        G_CALLBACK (goa_util_account_notify_property_cb),
+                        "DocumentsEnabled");
+    }
+
   ret = TRUE;
 
  out:
   if (chat != NULL)
     g_object_unref (chat);
-
+  if (account != NULL)
+    g_object_unref (account);
   return ret;
 }
 
@@ -326,12 +349,12 @@ show_account (GoaProvider         *provider,
 
   goa_util_add_row_switch_from_keyfile_with_blurb (GTK_TABLE (table), object,
                                                    _("Use for"),
-                                                   "ChatEnabled",
+                                                   "chat-disabled",
                                                    _("Chat"));
 
   goa_util_add_row_switch_from_keyfile_with_blurb (GTK_TABLE (table), object,
                                                    NULL,
-                                                   "DocumentsEnabled",
+                                                   "documents-disabled",
                                                    _("Documents"));
 }
 
diff --git a/src/goabackend/goayahooprovider.c b/src/goabackend/goayahooprovider.c
index f56ba48..9000bc7 100644
--- a/src/goabackend/goayahooprovider.c
+++ b/src/goabackend/goayahooprovider.c
@@ -282,6 +282,7 @@ build_object (GoaProvider         *provider,
               GoaObjectSkeleton   *object,
               GKeyFile            *key_file,
               const gchar         *group,
+              gboolean             just_added,
               GError             **error)
 {
   gboolean ret;
@@ -293,6 +294,7 @@ build_object (GoaProvider         *provider,
                                                                            object,
                                                                            key_file,
                                                                            group,
+                                                                           just_added,
                                                                            error))
     goto out;
 



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