Help: Use stable 'if' namespace instead of experimental
[empathy-mirror.git] / src / empathy-chat.c
blob202caa8c5266bc84e11516c60d025eea877a9a11
1 /*
2 * Copyright (C) 2007-2010 Collabora Ltd.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
20 * Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
23 #include "config.h"
25 #include <glib/gi18n.h>
26 #include <libnotify/notify.h>
28 #include "empathy-bus-names.h"
29 #include "empathy-chat-manager.h"
30 #include "empathy-chat-resources.h"
31 #include "empathy-presence-manager.h"
32 #include "empathy-theme-manager.h"
33 #include "empathy-ui-utils.h"
34 #include "empathy-utils.h"
36 #define DEBUG_FLAG EMPATHY_DEBUG_CHAT
37 #include "empathy-debug.h"
39 /* Exit after $TIMEOUT seconds if not displaying any call window */
40 #define TIMEOUT 60
42 static GtkApplication *app = NULL;
43 static gboolean activated = FALSE;
44 static gboolean use_timer = TRUE;
46 static EmpathyChatManager *chat_mgr = NULL;
48 static void
49 displayed_chats_changed_cb (EmpathyChatManager *mgr,
50 guint nb_chats,
51 gpointer user_data)
53 DEBUG ("New chat count: %u", nb_chats);
55 if (nb_chats == 0)
56 g_application_release (G_APPLICATION (app));
57 else
58 g_application_hold (G_APPLICATION (app));
61 static void
62 activate_cb (GApplication *application)
64 if (activated)
65 return;
67 activated = TRUE;
68 empathy_gtk_init ();
70 if (!use_timer)
72 /* keep a 'ref' to the application */
73 g_application_hold (G_APPLICATION (application));
76 g_assert (chat_mgr == NULL);
77 chat_mgr = empathy_chat_manager_dup_singleton ();
79 empathy_chat_window_present_chat(NULL, 0);
81 g_signal_connect (chat_mgr, "displayed-chats-changed",
82 G_CALLBACK (displayed_chats_changed_cb), GUINT_TO_POINTER (1));