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>
27 #include <libtelepathy/tp-helpers.h>
29 #include <libmissioncontrol/mc-account-monitor.h>
31 #include "empathy-session.h"
32 #include "gossip-debug.h"
34 #define DEBUG_DOMAIN "Session"
36 static void session_start_mission_control (void);
37 static void session_error_cb (MissionControl *mc,
40 static void session_account_enabled_cb (McAccountMonitor *monitor,
43 static void session_service_ended_cb (MissionControl *mc,
46 static MissionControl *mission_control = NULL;
47 static EmpathyContactManager *contact_manager = NULL;
50 empathy_session_connect (void)
53 McAccountMonitor *monitor;
54 static gboolean started = FALSE;
60 mc = empathy_session_get_mission_control ();
61 monitor = mc_account_monitor_new ();
63 g_signal_connect (monitor, "account-enabled",
64 G_CALLBACK (session_account_enabled_cb),
66 g_signal_connect (mc, "ServiceEnded",
67 G_CALLBACK (session_service_ended_cb),
70 g_object_unref (monitor);
71 session_start_mission_control ();
77 empathy_session_finalize (void)
79 if (mission_control) {
80 g_object_unref (mission_control);
81 mission_control = NULL;
84 if (contact_manager) {
85 g_object_unref (contact_manager);
86 contact_manager = NULL;
91 empathy_session_get_mission_control (void)
93 if (!mission_control) {
94 mission_control = mission_control_new (tp_get_bus ());
97 return mission_control;
100 EmpathyContactManager *
101 empathy_session_get_contact_manager (void)
103 if (!contact_manager) {
104 contact_manager = empathy_contact_manager_new ();
107 return contact_manager;
111 session_start_mission_control (void)
116 mc = empathy_session_get_mission_control ();
117 presence = mission_control_get_presence_actual (mc, NULL);
119 if (presence != MC_PRESENCE_UNSET &&
120 presence != MC_PRESENCE_OFFLINE) {
121 /* MC is already running and online, nothing to do */
125 gossip_debug (DEBUG_DOMAIN, "Starting Mission Control...");
127 /* FIXME: Save/Restore status message */
128 mission_control_set_presence (mc, MC_PRESENCE_AVAILABLE,
130 (McCallback) session_error_cb,
133 mission_control_connect_all_with_default_presence (mc,
134 (McCallback) session_error_cb,
139 session_error_cb (MissionControl *mc,
144 gossip_debug (DEBUG_DOMAIN, "Error: %s", error->message);
149 session_account_enabled_cb (McAccountMonitor *monitor,
153 gossip_debug (DEBUG_DOMAIN, "Account enabled: %s", unique_name);
154 session_start_mission_control ();
158 session_service_ended_cb (MissionControl *mc,
161 gossip_debug (DEBUG_DOMAIN, "Mission Control stopped");