]> git.0d.be Git - empathy.git/commitdiff
notify-manager: use the account mgr directly instead of empathy_check_available_state
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Tue, 17 Nov 2009 17:09:22 +0000 (17:09 +0000)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Wed, 18 Nov 2009 23:12:11 +0000 (23:12 +0000)
libempathy-gtk/empathy-notify-manager.c

index b87bb4965142e912c9b6fac3a111486c484602a7..67e39ef1befb972511aa8044e0fcad8da67e6478 100644 (file)
@@ -23,6 +23,8 @@
 #include <libnotify/notification.h>
 #include <libnotify/notify.h>
 
+#include <telepathy-glib/account-manager.h>
+
 #include <libempathy/empathy-utils.h>
 
 #include <libempathy-gtk/empathy-ui-utils.h>
@@ -39,6 +41,7 @@ typedef struct
 {
   /* owned (gchar *) => TRUE */
   GHashTable *capabilities;
+  TpAccountManager *account_manager;
 } EmpathyNotifyManagerPriv;
 
 G_DEFINE_TYPE (EmpathyNotifyManager, empathy_notify_manager, G_TYPE_OBJECT);
@@ -85,6 +88,22 @@ empathy_notify_manager_class_init (EmpathyNotifyManagerClass *klass)
   g_type_class_add_private (object_class, sizeof (EmpathyNotifyManagerPriv));
 }
 
+static void
+account_manager_prepared_cb (GObject *source_object,
+    GAsyncResult *result,
+    gpointer user_data)
+{
+  TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
+  GError *error = NULL;
+
+  if (!tp_account_manager_prepare_finish (account_manager, result, &error))
+    {
+      DEBUG ("Failed to prepare account manager: %s", error->message);
+      g_error_free (error);
+      return;
+    }
+}
+
 static void
 empathy_notify_manager_init (EmpathyNotifyManager *self)
 {
@@ -108,6 +127,11 @@ empathy_notify_manager_init (EmpathyNotifyManager *self)
       g_hash_table_insert (priv->capabilities, cap, GUINT_TO_POINTER (TRUE));
     }
   g_list_free (list);
+
+  priv->account_manager = tp_account_manager_dup ();
+
+  tp_account_manager_prepare_async (priv->account_manager, NULL,
+      account_manager_prepared_cb, self);
 }
 
 EmpathyNotifyManager *
@@ -144,8 +168,10 @@ empathy_notify_manager_get_pixbuf_for_notification (EmpathyNotifyManager *self,
 gboolean
 empathy_notify_manager_notification_is_enabled  (EmpathyNotifyManager *self)
 {
+  EmpathyNotifyManagerPriv *priv = GET_PRIV (self);
   EmpathyConf *conf;
   gboolean res;
+  TpConnectionPresenceType presence;
 
   conf = empathy_conf_get ();
   res = FALSE;
@@ -155,7 +181,19 @@ empathy_notify_manager_notification_is_enabled  (EmpathyNotifyManager *self)
   if (!res)
     return FALSE;
 
-  if (!empathy_check_available_state ())
+  if (!tp_account_manager_is_prepared (priv->account_manager,
+        TP_ACCOUNT_MANAGER_FEATURE_CORE))
+    {
+      DEBUG ("account manager is not ready yet; display the notification");
+      return TRUE;
+    }
+
+  presence = tp_account_manager_get_most_available_presence (
+      priv->account_manager,
+      NULL, NULL);
+
+  if (presence != TP_CONNECTION_PRESENCE_TYPE_AVAILABLE &&
+      presence != TP_CONNECTION_PRESENCE_TYPE_UNSET)
     {
       empathy_conf_get_bool (conf, EMPATHY_PREFS_NOTIFICATIONS_DISABLED_AWAY,
           &res);