1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Xavier Claessens <xclaesse@gmail.com>
5 * This library 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 library 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 library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
25 #include <libtelepathy/tp-helpers.h>
27 #include <libmissioncontrol/mc-account-monitor.h>
29 #include "empathy-session.h"
30 #include "gossip-debug.h"
32 #define DEBUG_DOMAIN "Session"
34 static void session_start_mission_control (void);
35 static void session_error_cb (MissionControl *mc,
38 static void session_account_enabled_cb (McAccountMonitor *monitor,
41 static void session_service_ended_cb (MissionControl *mc,
44 static MissionControl *mission_control = NULL;
45 static EmpathyContactManager *contact_manager = NULL;
48 empathy_session_connect (void)
51 McAccountMonitor *monitor;
52 static gboolean started = FALSE;
58 mc = empathy_session_get_mission_control ();
59 monitor = mc_account_monitor_new ();
61 g_signal_connect (monitor, "account-enabled",
62 G_CALLBACK (session_account_enabled_cb),
64 g_signal_connect (mc, "ServiceEnded",
65 G_CALLBACK (session_service_ended_cb),
68 g_object_unref (monitor);
69 session_start_mission_control ();
75 empathy_session_finalize (void)
77 if (mission_control) {
78 g_object_unref (mission_control);
79 mission_control = NULL;
82 if (contact_manager) {
83 g_object_unref (contact_manager);
84 contact_manager = NULL;
89 empathy_session_get_mission_control (void)
91 if (!mission_control) {
92 mission_control = mission_control_new (tp_get_bus ());
95 return mission_control;
98 EmpathyContactManager *
99 empathy_session_get_contact_manager (void)
101 if (!contact_manager) {
102 contact_manager = empathy_contact_manager_new ();
105 return contact_manager;
109 session_start_mission_control (void)
114 mc = empathy_session_get_mission_control ();
115 presence = mission_control_get_presence_actual (mc, NULL);
117 if (presence != MC_PRESENCE_UNSET &&
118 presence != MC_PRESENCE_OFFLINE) {
119 /* MC is already running and online, nothing to do */
123 gossip_debug (DEBUG_DOMAIN, "Starting Mission Control...");
125 /* FIXME: Save/Restore status message */
126 mission_control_set_presence (mc, MC_PRESENCE_AVAILABLE,
128 (McCallback) session_error_cb,
131 mission_control_connect_all_with_default_presence (mc,
132 (McCallback) session_error_cb,
137 session_error_cb (MissionControl *mc,
142 gossip_debug (DEBUG_DOMAIN, "Error: %s", error->message);
147 session_account_enabled_cb (McAccountMonitor *monitor,
151 gossip_debug (DEBUG_DOMAIN, "Account enabled: %s", unique_name);
152 session_start_mission_control ();
156 session_service_ended_cb (MissionControl *mc,
159 gossip_debug (DEBUG_DOMAIN, "Mission Control stopped");