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 <libmissioncontrol/mc-account.h>
31 #include <libmissioncontrol/mc-account-monitor.h>
32 #include <libmissioncontrol/mission-control.h>
34 #include <libempathy/gossip-debug.h>
35 #include <libempathy/gossip-utils.h>
36 #include <libempathy/gossip-presence.h>
37 #include <libempathy-gtk/empathy-main-window.h>
38 #include <libempathy-gtk/empathy-status-icon.h>
39 #include <libempathy-gtk/gossip-accounts-dialog.h>
41 #include "empathy-filter.h"
43 #define DEBUG_DOMAIN "EmpathyMain"
45 static void error_cb (MissionControl *mc,
48 static void service_ended_cb (MissionControl *mc,
50 static void operation_error_cb (MissionControl *mc,
54 static void start_mission_control (MissionControl *mc);
57 error_cb (MissionControl *mc,
62 gossip_debug (DEBUG_DOMAIN, "Error: %s", error->message);
67 service_ended_cb (MissionControl *mc,
70 gossip_debug (DEBUG_DOMAIN, "Mission Control stopped");
74 operation_error_cb (MissionControl *mc,
79 gossip_debug (DEBUG_DOMAIN, "Error code %d during operation %d",
85 account_enabled_cb (McAccountMonitor *monitor,
89 gossip_debug (DEBUG_DOMAIN, "Account enabled: %s", unique_name);
90 start_mission_control (mc);
94 start_mission_control (MissionControl *mc)
98 presence = mission_control_get_presence_actual (mc, NULL);
100 if (presence > MC_PRESENCE_OFFLINE) {
101 /* MC is already running and online, nothing to do */
105 gossip_debug (DEBUG_DOMAIN, "Starting Mission Control...");
107 mission_control_set_presence (mc,
108 MC_PRESENCE_AVAILABLE,
110 (McCallback) error_cb,
115 new_channel_cb (EmpathyFilter *filter,
118 guint context_handle,
121 gossip_debug (DEBUG_DOMAIN, "Filtering context handle: %d",
123 empathy_filter_process (filter, context_handle, TRUE);
127 main (int argc, char *argv[])
130 EmpathyStatusIcon *icon;
133 McAccountMonitor *monitor;
134 EmpathyFilter *filter;
136 gtk_init (&argc, &argv);
138 /* Setting up channel filter */
139 filter = empathy_filter_new ();
140 g_signal_connect (filter, "new-channel",
141 G_CALLBACK (new_channel_cb),
145 monitor = mc_account_monitor_new ();
146 mc = gossip_mission_control_new ();
147 g_signal_connect (monitor, "account-enabled",
148 G_CALLBACK (account_enabled_cb),
150 g_signal_connect (mc, "ServiceEnded",
151 G_CALLBACK (service_ended_cb),
153 g_signal_connect (mc, "Error",
154 G_CALLBACK (operation_error_cb),
156 start_mission_control (mc);
159 window = empathy_main_window_show ();
160 icon = empathy_status_icon_new (GTK_WINDOW (window));
162 /* Show the accounts dialog if there is no enabled accounts */
163 accounts = mc_accounts_list_by_enabled (TRUE);
165 mc_accounts_list_free (accounts);
167 gossip_accounts_dialog_show ();
172 mission_control_set_presence (mc,
176 g_object_unref (monitor);
178 g_object_unref (icon);