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>
28 #include <glib/gi18n.h>
31 #include <libgnome/gnome-program.h>
32 #include <libgnomeui/gnome-ui-init.h>
34 #include <libmissioncontrol/mc-account.h>
35 #include <libmissioncontrol/mc-account-monitor.h>
36 #include <libmissioncontrol/mission-control.h>
38 #include <libempathy/gossip-debug.h>
39 #include <libempathy/gossip-utils.h>
40 #include <libempathy/gossip-presence.h>
41 #include <libempathy-gtk/empathy-main-window.h>
42 #include <libempathy-gtk/empathy-status-icon.h>
44 #define DEBUG_DOMAIN "EmpathyMain"
46 static void error_cb (MissionControl *mc,
49 static void service_ended_cb (MissionControl *mc,
51 static void operation_error_cb (MissionControl *mc,
55 static void start_mission_control (MissionControl *mc);
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 operation_error_cb (MissionControl *mc,
80 gossip_debug (DEBUG_DOMAIN, "Error code %d during operation %d",
86 account_enabled_cb (McAccountMonitor *monitor,
90 gossip_debug (DEBUG_DOMAIN, "Account enabled: %s", unique_name);
91 start_mission_control (mc);
95 start_mission_control (MissionControl *mc)
99 presence = mission_control_get_presence_actual (mc, NULL);
101 if (presence > MC_PRESENCE_OFFLINE) {
102 /* MC is already running and online, nothing to do */
106 gossip_debug (DEBUG_DOMAIN, "Starting Mission Control...");
108 mission_control_set_presence (mc,
109 MC_PRESENCE_AVAILABLE,
111 (McCallback) error_cb,
116 main (int argc, char *argv[])
118 EmpathyStatusIcon *icon;
121 McAccountMonitor *monitor;
122 GnomeProgram *program;
123 gboolean no_connect = FALSE;
124 GOptionContext *context;
125 GOptionEntry options[] = {
127 0, G_OPTION_ARG_NONE, &no_connect,
128 N_("Don't connect on startup"),
132 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
133 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
134 textdomain (GETTEXT_PACKAGE);
136 context = g_option_context_new (_("- Empathy Instant Messenger"));
137 g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
139 g_set_application_name (PACKAGE_NAME);
141 program = gnome_program_init ("empathy",
145 GNOME_PROGRAM_STANDARD_PROPERTIES,
146 "goption-context", context,
147 GNOME_PARAM_HUMAN_READABLE_NAME, PACKAGE_NAME,
150 gtk_window_set_default_icon_name ("empathy");
151 gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
152 DATADIR G_DIR_SEPARATOR_S "empathy");
155 monitor = mc_account_monitor_new ();
156 mc = gossip_mission_control_new ();
157 g_signal_connect (monitor, "account-enabled",
158 G_CALLBACK (account_enabled_cb),
160 g_signal_connect (mc, "ServiceEnded",
161 G_CALLBACK (service_ended_cb),
163 g_signal_connect (mc, "Error",
164 G_CALLBACK (operation_error_cb),
168 start_mission_control (mc);
172 window = empathy_main_window_show ();
173 icon = empathy_status_icon_new (GTK_WINDOW (window));
177 mission_control_set_presence (mc,
181 g_object_unref (monitor);
183 g_object_unref (icon);
184 g_object_unref (program);