#define BUS_NAME "org.gnome.Empathy.ChatChandler"
#define OBJECT_PATH "/org/gnome/Empathy/ChatChandler"
+static guint nb_chats = 0;
+
+static void
+chat_chandler_weak_notify (gpointer data,
+ GObject *where_the_object_was)
+{
+ nb_chats--;
+ if (nb_chats == 0) {
+ empathy_debug (DEBUG_DOMAIN, "No more chats, leaving...");
+ gtk_main_quit ();
+ }
+}
+
static void
chat_chandler_new_channel_cb (EmpathyChandler *chandler,
TpConn *tp_conn,
TpChan *tp_chan,
MissionControl *mc)
{
- McAccount *account;
- EmpathyChat *chat;
- gchar *id;
+ EmpathyTpChat *tp_chat;
+ McAccount *account;
+ EmpathyChat *chat;
+ gchar *id;
account = mission_control_get_account_for_connection (mc, tp_conn, NULL);
id = empathy_inspect_channel (account, tp_chan);
if (chat) {
/* The chat already exists */
if (!empathy_chat_is_connected (chat)) {
- EmpathyTpChat *tp_chat;
-
/* The chat died, give him the new text channel */
if (empathy_chat_is_group_chat (chat)) {
tp_chat = EMPATHY_TP_CHAT (empathy_tp_chatroom_new (account, tp_chan));
if (tp_chan->handle_type == TP_HANDLE_TYPE_CONTACT) {
/* We have a new private chat channel */
- chat = EMPATHY_CHAT (empathy_private_chat_new (account, tp_chan));
+ tp_chat = empathy_tp_chat_new (account, tp_chan);
+ chat = EMPATHY_CHAT (empathy_private_chat_new (tp_chat));
}
else if (tp_chan->handle_type == TP_HANDLE_TYPE_ROOM) {
/* We have a new group chat channel */
- chat = EMPATHY_CHAT (empathy_group_chat_new (account, tp_chan));
+ tp_chat = EMPATHY_TP_CHAT (empathy_tp_chatroom_new (account, tp_chan));
+ chat = EMPATHY_CHAT (empathy_group_chat_new (EMPATHY_TP_CHATROOM (tp_chat)));
+ } else {
+ empathy_debug (DEBUG_DOMAIN,
+ "Unknown handle type (%d) for Text channel",
+ tp_chan->handle_type);
+ g_object_unref (account);
+ return;
}
- empathy_chat_present (EMPATHY_CHAT (chat));
+ nb_chats++;
+ g_object_weak_ref (G_OBJECT (chat), chat_chandler_weak_notify, NULL);
+ empathy_chat_present (chat);
g_object_unref (chat);
g_object_unref (account);
+ g_object_unref (tp_chat);
}
int