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-gtk/empathy-main-window.h>
38 #include <libempathy-gtk/empathy-images.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 start_mission_control (MissionControl *mc);
51 static void destroy_cb (GtkWidget *window,
53 static void icon_activate_cb (GtkStatusIcon *status_icon,
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 account_enabled_cb (McAccountMonitor *monitor,
78 gossip_debug (DEBUG_DOMAIN, "Account enabled: %s", unique_name);
79 start_mission_control (mc);
83 start_mission_control (MissionControl *mc)
87 presence = mission_control_get_presence_actual (mc, NULL);
89 if (presence > MC_PRESENCE_OFFLINE) {
90 /* MC is already running and online, nothing to do */
94 gossip_debug (DEBUG_DOMAIN, "Starting Mission Control...");
96 mission_control_set_presence (mc,
97 MC_PRESENCE_AVAILABLE,
99 (McCallback) error_cb,
104 destroy_cb (GtkWidget *window,
107 mission_control_set_presence (mc,
115 icon_activate_cb (GtkStatusIcon *status_icon,
118 if (GTK_WIDGET_VISIBLE (window)) {
119 gtk_widget_hide (window);
121 gtk_widget_show (window);
126 new_channel_cb (EmpathyFilter *filter,
129 guint context_handle,
132 gossip_debug (DEBUG_DOMAIN, "Filtering context handle: %d",
134 empathy_filter_process (filter, context_handle, TRUE);
138 main (int argc, char *argv[])
144 McAccountMonitor *monitor;
145 EmpathyFilter *filter;
147 gtk_init (&argc, &argv);
149 /* Setting up channel filter */
150 filter = empathy_filter_new ();
151 g_signal_connect (filter, "new-channel",
152 G_CALLBACK (new_channel_cb),
156 monitor = mc_account_monitor_new ();
157 mc = mission_control_new (tp_get_bus ());
158 g_signal_connect (monitor, "account-enabled",
159 G_CALLBACK (account_enabled_cb),
161 g_signal_connect (mc, "ServiceEnded",
162 G_CALLBACK (service_ended_cb),
164 start_mission_control (mc);
166 /* Setting up the main window */
167 window = empathy_main_window_show ();
168 g_signal_connect (window, "destroy",
169 G_CALLBACK (destroy_cb),
171 g_signal_connect (window, "delete-event",
172 G_CALLBACK (gtk_widget_hide_on_delete),
175 /* Setting up the tray icon */
176 icon = gtk_status_icon_new_from_icon_name (EMPATHY_IMAGE_MESSAGE);
177 gtk_status_icon_set_tooltip (icon, "Empathy - click here to show/hide the main window");
178 gtk_status_icon_set_visible (icon, TRUE);
179 g_signal_connect (icon, "activate",
180 G_CALLBACK (icon_activate_cb),
183 /* Show the accounts dialog if there is no enabled accounts */
184 accounts = mc_accounts_list_by_enabled (TRUE);
186 mc_accounts_list_free (accounts);
188 gossip_accounts_dialog_show ();
193 g_object_unref (monitor);
195 g_object_unref (icon);