]> git.0d.be Git - empathy.git/blobdiff - src/empathy-call-chandler.c
It's now safe to call emp_cli_init multiple times. Move that call to empathy_tp_call_...
[empathy.git] / src / empathy-call-chandler.c
index bb88747f436ee5ba6c9bedf8150001c0eed3006a..e1568c18cf2cb21b2d3c71b37c1b594b7fd1bbd5 100644 (file)
  *  Authors: Elliot Fairweather <elliot.fairweather@collabora.co.uk>
  */
 
-#include <stdlib.h>
-
 #include <gtk/gtk.h>
 
 #include <libmissioncontrol/mission-control.h>
 
-#include <libempathy/empathy-chandler.h>
-#include <libempathy/empathy-utils.h>
 #include <libempathy/empathy-tp-call.h>
+#include <libempathy/empathy-chandler.h>
 #include <libempathy/empathy-debug.h>
+#include <libempathy/empathy-utils.h>
 
 #include <libempathy-gtk/empathy-call-window.h>
 
-#define DEBUG_DOMAIN "EmpathyCall"
+#define DEBUG_DOMAIN "CallChandler"
 
-#define BUS_NAME "org.gnome.Empathy.Call"
-#define OBJECT_PATH "/org/freedesktop/Telepathy/ChannelHandler"
+static guint nb_calls = 0;
 
 static void
-call_chandler_new_channel_cb (EmpathyChandler *chandler,
-                             TpConn          *tp_conn,
-                             TpChan          *tp_chan,
-                             MissionControl  *mc)
+weak_notify (gpointer data,
+             GObject *where_the_object_was)
 {
-       EmpathyTpCall *call;
-       McAccount     *account;
+  nb_calls--;
+  if (nb_calls == 0)
+    {
+      empathy_debug (DEBUG_DOMAIN, "No more calls, leaving...");
+      gtk_main_quit ();
+    }
+}
 
-       account = mission_control_get_account_for_connection (mc, tp_conn, NULL);
+static void
+new_channel_cb (EmpathyChandler *chandler,
+                TpConn *connection,
+                TpChan *channel,
+                MissionControl *mc)
+{
+  EmpathyTpCall *call;
+
+  call = empathy_tp_call_new (connection, channel);
+  empathy_call_window_new (call);
+  g_object_unref (call);
 
-       call = empathy_tp_call_new (account, tp_chan);
-       empathy_call_window_show (call);
-       g_object_unref (account);
-       g_object_unref (call);
+  nb_calls++;
+  g_object_weak_ref (G_OBJECT (call), weak_notify, NULL);
 }
 
 int
 main (int argc, char *argv[])
 {
-       EmpathyChandler *chandler;
-       MissionControl  *mc;
+  MissionControl *mc;
+  EmpathyChandler *chandler;
 
-       gtk_init (&argc, &argv);
+  gtk_init (&argc, &argv);
 
-       mc = empathy_mission_control_new ();
-       chandler = empathy_chandler_new (BUS_NAME, OBJECT_PATH);
-       g_signal_connect (chandler, "new-channel",
-                         G_CALLBACK (call_chandler_new_channel_cb),
-                         mc);
+  mc = empathy_mission_control_new ();
 
-       empathy_debug (DEBUG_DOMAIN, "Ready to handle new streamed media channels");
+  chandler = empathy_chandler_new ("org.gnome.Empathy.CallChandler",
+      "/org/gnome/Empathy/CallChandler");
+  g_signal_connect (chandler, "new-channel",
+      G_CALLBACK (new_channel_cb), mc);
 
-       gtk_main ();
+  empathy_debug (DEBUG_DOMAIN, "Ready to handle new streamed media channels");
 
-       g_object_unref (chandler);
-       g_object_unref (mc);
+  gtk_main ();
 
-       return EXIT_SUCCESS;
-}
+  g_object_unref (chandler);
+  g_object_unref (mc);
 
+  return EXIT_SUCCESS;
+}