]> git.0d.be Git - empathy.git/commitdiff
notify-manager: cache the notification GSettings
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Mon, 29 Nov 2010 15:03:07 +0000 (16:03 +0100)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Mon, 29 Nov 2010 15:03:07 +0000 (16:03 +0100)
libempathy-gtk/empathy-notify-manager.c

index 80383975545a990e41050f6b232ba04f6894425e..7a4374c4864ce3605efd36d6e221e48c4e1618e7 100644 (file)
@@ -42,6 +42,7 @@ typedef struct
   /* owned (gchar *) => TRUE */
   GHashTable *capabilities;
   TpAccountManager *account_manager;
+  GSettings *gsettings_notif;
 } EmpathyNotifyManagerPriv;
 
 G_DEFINE_TYPE (EmpathyNotifyManager, empathy_notify_manager, G_TYPE_OBJECT);
@@ -78,6 +79,8 @@ notify_manager_dispose (GObject *object)
       priv->account_manager = NULL;
     }
 
+  tp_clear_object (&priv->gsettings_notif);
+
   G_OBJECT_CLASS (empathy_notify_manager_parent_class)->dispose (object);
 }
 
@@ -128,6 +131,8 @@ empathy_notify_manager_init (EmpathyNotifyManager *self)
 
   self->priv = priv;
 
+  priv->gsettings_notif = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
+
   priv->capabilities = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
       NULL);
 
@@ -184,20 +189,17 @@ gboolean
 empathy_notify_manager_notification_is_enabled  (EmpathyNotifyManager *self)
 {
   EmpathyNotifyManagerPriv *priv = GET_PRIV (self);
-  GSettings *gsettings = g_settings_new (EMPATHY_PREFS_NOTIFICATIONS_SCHEMA);
   TpConnectionPresenceType presence;
-  gboolean ret = FALSE;
 
-  if (!g_settings_get_boolean (gsettings, EMPATHY_PREFS_NOTIFICATIONS_ENABLED))
-    goto finally;
+  if (!g_settings_get_boolean (priv->gsettings_notif,
+        EMPATHY_PREFS_NOTIFICATIONS_ENABLED))
+    return FALSE;
 
   if (!tp_account_manager_is_prepared (priv->account_manager,
         TP_ACCOUNT_MANAGER_FEATURE_CORE))
     {
       DEBUG ("account manager is not ready yet; display the notification");
-      ret = TRUE;
-
-      goto finally;
+      return TRUE;
     }
 
   presence = tp_account_manager_get_most_available_presence (
@@ -207,15 +209,10 @@ empathy_notify_manager_notification_is_enabled  (EmpathyNotifyManager *self)
   if (presence != TP_CONNECTION_PRESENCE_TYPE_AVAILABLE &&
       presence != TP_CONNECTION_PRESENCE_TYPE_UNSET)
     {
-      if (g_settings_get_boolean (gsettings,
+      if (g_settings_get_boolean (priv->gsettings_notif,
             EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY))
-        goto finally;
+        return FALSE;
     }
 
-  ret = TRUE;
-
-finally:
-  g_object_unref (gsettings);
-
-  return ret;
+  return TRUE;
 }