]> git.0d.be Git - empathy.git/blob - launcher/empathy-launcher.c
[darcs-to-svn @ Connect accounts in empathy-launcher, not in empathy-contact-list]
[empathy.git] / launcher / empathy-launcher.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007 Collabora Ltd.
4  *
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.
9  *
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.
14  *
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.
19  * 
20  * Authors: Xavier Claessens <xclaesse@gmail.com>
21  */
22
23 #include <config.h>
24 #include <stdlib.h>
25 #include <glib.h>
26
27 #include <libtelepathy/tp-helpers.h>
28 #include <libmissioncontrol/mc-account-monitor.h>
29 #include <libmissioncontrol/mission-control.h>
30
31 #include <libempathy/gossip-debug.h>
32
33 #define DEBUG_DOMAIN "Launcher"
34
35 static void error_cb              (MissionControl *mc,
36                                    GError         *error,
37                                    gpointer        data);
38 static void service_ended_cb      (MissionControl *mc,
39                                    gpointer        user_data);
40 static void start_mission_control (MissionControl *mc);
41
42
43
44
45 static void
46 error_cb (MissionControl *mc,
47           GError         *error,
48           gpointer        data)
49 {
50         if (error) {
51                 gossip_debug (DEBUG_DOMAIN, "Error: %s", error->message);
52         }
53 }
54
55 static void
56 service_ended_cb (MissionControl *mc,
57                   gpointer        user_data)
58 {
59         gossip_debug (DEBUG_DOMAIN, "Mission Control stopped");
60 }
61
62 static void
63 account_enabled_cb (McAccountMonitor *monitor,
64                     gchar            *unique_name,
65                     MissionControl   *mc)
66 {
67         gossip_debug (DEBUG_DOMAIN, "Account enabled: %s", unique_name);
68         start_mission_control (mc);
69 }
70
71 static void
72 start_mission_control (MissionControl *mc)
73 {
74         McPresence presence;
75
76         presence = mission_control_get_presence_actual (mc, NULL);
77
78         if (presence != MC_PRESENCE_UNSET &&
79             presence != MC_PRESENCE_OFFLINE) {
80                 /* MC is already running and online, nothing to do */
81                 return;
82         }
83
84         gossip_debug (DEBUG_DOMAIN, "Starting Mission Control...");
85
86         /* FIXME: Save/Restore status message */
87         mission_control_set_presence (mc, MC_PRESENCE_AVAILABLE,
88                                       NULL,
89                                       (McCallback) error_cb,
90                                       NULL);
91
92         mission_control_connect_all_with_default_presence (mc,
93                                                            (McCallback) error_cb,
94                                                            NULL);
95 }
96
97 int
98 main (int argc, char *argv[])
99 {
100         GMainLoop        *main_loop;
101         MissionControl   *mc;
102         McAccountMonitor *monitor;
103
104         g_type_init ();
105
106         main_loop = g_main_loop_new (NULL, FALSE);
107         monitor = mc_account_monitor_new ();
108         mc = mission_control_new (tp_get_bus ());
109
110         g_signal_connect (monitor, "account-enabled",
111                           G_CALLBACK (account_enabled_cb),
112                           mc);
113         g_signal_connect (mc, "ServiceEnded",
114                           G_CALLBACK (service_ended_cb),
115                           NULL);
116
117         start_mission_control (mc);
118
119         g_main_loop_run (main_loop);
120
121         g_object_unref (monitor);
122         g_object_unref (mc);
123
124         return 0;
125 }
126