]> git.0d.be Git - empathy.git/commitdiff
empathy-chat: register the Handler when the app is activated
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Tue, 23 Nov 2010 09:40:21 +0000 (10:40 +0100)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Tue, 23 Nov 2010 09:40:21 +0000 (10:40 +0100)
This avoid to raise warnings when the app is launched a second time.

src/empathy-chat.c

index 0c6406591fd5bd540ef278c8424e437e1eee39ab..ebe0a9003369a7719eb21be87961e61dbffc9ca8 100644 (file)
@@ -45,6 +45,8 @@ static GtkApplication *app = NULL;
 static gboolean activated = FALSE;
 static gboolean use_timer = TRUE;
 
+static EmpathyChatManager *chat_mgr = NULL;
+
 static void
 handled_chats_changed_cb (EmpathyChatManager *mgr,
     guint nb_chats,
@@ -61,12 +63,22 @@ handled_chats_changed_cb (EmpathyChatManager *mgr,
 static void
 activate_cb (GApplication *application)
 {
-  if (!use_timer && !activated)
+  if (activated)
+    return;
+
+  activated = TRUE;
+
+  if (!use_timer)
     {
       /* keep a 'ref' to the application */
       g_application_hold (G_APPLICATION (application));
-      activated = TRUE;
     }
+
+  g_assert (chat_mgr == NULL);
+  chat_mgr = empathy_chat_manager_dup_singleton ();
+
+  g_signal_connect (chat_mgr, "handled-chats-changed",
+      G_CALLBACK (handled_chats_changed_cb), GUINT_TO_POINTER (1));
 }
 
 int
@@ -81,7 +93,6 @@ main (int argc,
   TpDebugSender *debug_sender;
 #endif
   GError *error = NULL;
-  EmpathyChatManager *chat_mgr;
   EmpathyIdle *idle;
   gint retval;
 
@@ -120,11 +131,6 @@ main (int argc,
   /* Setting up Idle */
   idle = empathy_idle_dup_singleton ();
 
-  chat_mgr = empathy_chat_manager_dup_singleton ();
-
-  g_signal_connect (chat_mgr, "handled-chats-changed",
-      G_CALLBACK (handled_chats_changed_cb), GUINT_TO_POINTER (1));
-
   if (g_getenv ("EMPATHY_PERSIST") != NULL)
     {
       DEBUG ("Disable timer");
@@ -143,7 +149,7 @@ main (int argc,
 
   g_object_unref (app);
   g_object_unref (idle);
-  g_object_unref (chat_mgr);
+  tp_clear_object (&chat_mgr);
 
 #ifdef ENABLE_DEBUG
   g_object_unref (debug_sender);