1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Collabora Ltd.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Authors: Xavier Claessens <xclaesse@gmail.com>
30 #include <libtelepathy/tp-helpers.h>
32 #include <libmissioncontrol/mc-account.h>
33 #include <libmissioncontrol/mc-account-monitor.h>
34 #include <libmissioncontrol/mission-control.h>
36 #include <libempathy/gossip-debug.h>
37 #include <libempathy/gossip-presence.h>
38 #include <libempathy-gtk/empathy-main-window.h>
39 #include <libempathy-gtk/empathy-status-icon.h>
40 #include <libempathy-gtk/gossip-accounts-dialog.h>
42 #include "empathy-filter.h"
44 #define DEBUG_DOMAIN "EmpathyMain"
46 static void error_cb (MissionControl *mc,
49 static void service_ended_cb (MissionControl *mc,
51 static void start_mission_control (MissionControl *mc);
52 static void destroy_cb (GtkWidget *window,
54 static void icon_activate_cb (EmpathyStatusIcon *icon,
58 error_cb (MissionControl *mc,
63 gossip_debug (DEBUG_DOMAIN, "Error: %s", error->message);
68 service_ended_cb (MissionControl *mc,
71 gossip_debug (DEBUG_DOMAIN, "Mission Control stopped");
75 account_enabled_cb (McAccountMonitor *monitor,
79 gossip_debug (DEBUG_DOMAIN, "Account enabled: %s", unique_name);
80 start_mission_control (mc);
84 start_mission_control (MissionControl *mc)
88 presence = mission_control_get_presence_actual (mc, NULL);
90 if (presence > MC_PRESENCE_OFFLINE) {
91 /* MC is already running and online, nothing to do */
95 gossip_debug (DEBUG_DOMAIN, "Starting Mission Control...");
97 mission_control_set_presence (mc,
98 MC_PRESENCE_AVAILABLE,
100 (McCallback) error_cb,
105 destroy_cb (GtkWidget *window,
108 mission_control_set_presence (mc,
116 icon_activate_cb (EmpathyStatusIcon *icon,
119 if (GTK_WIDGET_VISIBLE (window)) {
120 gtk_widget_hide (window);
122 gtk_widget_show (window);
127 new_channel_cb (EmpathyFilter *filter,
130 guint context_handle,
133 gossip_debug (DEBUG_DOMAIN, "Filtering context handle: %d",
135 empathy_filter_process (filter, context_handle, TRUE);
139 main (int argc, char *argv[])
142 EmpathyStatusIcon *icon;
145 McAccountMonitor *monitor;
146 EmpathyFilter *filter;
148 gtk_init (&argc, &argv);
150 /* Setting up channel filter */
151 filter = empathy_filter_new ();
152 g_signal_connect (filter, "new-channel",
153 G_CALLBACK (new_channel_cb),
157 monitor = mc_account_monitor_new ();
158 mc = mission_control_new (tp_get_bus ());
159 g_signal_connect (monitor, "account-enabled",
160 G_CALLBACK (account_enabled_cb),
162 g_signal_connect (mc, "ServiceEnded",
163 G_CALLBACK (service_ended_cb),
165 start_mission_control (mc);
167 /* Setting up the main window */
168 window = empathy_main_window_show ();
169 g_signal_connect (window, "destroy",
170 G_CALLBACK (destroy_cb),
172 g_signal_connect (window, "delete-event",
173 G_CALLBACK (gtk_widget_hide_on_delete),
176 /* Setting up the status icon */
177 icon = empathy_status_icon_new ();
178 g_signal_connect (icon, "activate",
179 G_CALLBACK (icon_activate_cb),
182 /* Show the accounts dialog if there is no enabled accounts */
183 accounts = mc_accounts_list_by_enabled (TRUE);
185 mc_accounts_list_free (accounts);
187 gossip_accounts_dialog_show ();
192 g_object_unref (monitor);
194 g_object_unref (icon);