comparison libpurple/core.c @ 15373:5fe8042783c1

Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author Sean Egan <seanegan@gmail.com>
date Sat, 20 Jan 2007 02:32:10 +0000
parents
children b0471b2a1de9
comparison
equal deleted inserted replaced
15372:f79e0f4df793 15373:5fe8042783c1
1 /**
2 * @file core.c Gaim Core API
3 * @ingroup core
4 *
5 * gaim
6 *
7 * Gaim is the legal property of its developers, whose names are too numerous
8 * to list here. Please refer to the COPYRIGHT file distributed with this
9 * source distribution.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25 #include "internal.h"
26 #include "cipher.h"
27 #include "connection.h"
28 #include "conversation.h"
29 #include "core.h"
30 #include "debug.h"
31 #include "dnsquery.h"
32 #include "ft.h"
33 #include "idle.h"
34 #include "network.h"
35 #include "notify.h"
36 #include "plugin.h"
37 #include "pounce.h"
38 #include "prefs.h"
39 #include "privacy.h"
40 #include "proxy.h"
41 #include "savedstatuses.h"
42 #include "signals.h"
43 #include "sound.h"
44 #include "sslconn.h"
45 #include "status.h"
46 #include "stun.h"
47
48 #ifdef HAVE_DBUS
49 # include "dbus-server.h"
50 #endif
51
52 struct GaimCore
53 {
54 char *ui;
55
56 void *reserved;
57 };
58
59 static GaimCoreUiOps *_ops = NULL;
60 static GaimCore *_core = NULL;
61
62 STATIC_PROTO_INIT
63
64 gboolean
65 gaim_core_init(const char *ui)
66 {
67 GaimCoreUiOps *ops;
68 GaimCore *core;
69
70 g_return_val_if_fail(ui != NULL, FALSE);
71 g_return_val_if_fail(gaim_get_core() == NULL, FALSE);
72
73 #ifdef _WIN32
74 wgaim_init();
75 #endif
76
77 _core = core = g_new0(GaimCore, 1);
78 core->ui = g_strdup(ui);
79 core->reserved = NULL;
80
81 ops = gaim_core_get_ui_ops();
82
83 /* The signals subsystem is important and should be first. */
84 gaim_signals_init();
85
86 gaim_signal_register(core, "quitting", gaim_marshal_VOID, NULL, 0);
87
88 /* The prefs subsystem needs to be initialized before static protocols
89 * for protocol prefs to work. */
90 gaim_prefs_init();
91
92 gaim_debug_init();
93
94 if (ops != NULL)
95 {
96 if (ops->ui_prefs_init != NULL)
97 ops->ui_prefs_init();
98
99 if (ops->debug_ui_init != NULL)
100 ops->debug_ui_init();
101 }
102
103 #ifdef HAVE_DBUS
104 gaim_dbus_init();
105 #endif
106
107 /* Initialize all static protocols. */
108 static_proto_init();
109
110 /* Since plugins get probed so early we should probably initialize their
111 * subsystem right away too.
112 */
113 gaim_plugins_init();
114 gaim_plugins_probe(G_MODULE_SUFFIX);
115
116 /* Accounts use status and buddy icons, so initialize these before accounts */
117 gaim_status_init();
118 gaim_buddy_icons_init();
119
120 gaim_accounts_init();
121 gaim_savedstatuses_init();
122 gaim_ciphers_init();
123 gaim_notify_init();
124 gaim_connections_init();
125 gaim_conversations_init();
126 gaim_blist_init();
127 gaim_log_init();
128 gaim_network_init();
129 gaim_privacy_init();
130 gaim_pounces_init();
131 gaim_proxy_init();
132 gaim_dnsquery_init();
133 gaim_sound_init();
134 gaim_ssl_init();
135 gaim_stun_init();
136 gaim_xfers_init();
137 gaim_idle_init();
138
139 /*
140 * Call this early on to try to auto-detect our IP address and
141 * hopefully save some time later.
142 */
143 gaim_network_get_my_ip(-1);
144
145 if (ops != NULL && ops->ui_init != NULL)
146 ops->ui_init();
147
148 return TRUE;
149 }
150
151 void
152 gaim_core_quit(void)
153 {
154 GaimCoreUiOps *ops;
155 GaimCore *core = gaim_get_core();
156
157 g_return_if_fail(core != NULL);
158
159 /* The self destruct sequence has been initiated */
160 gaim_signal_emit(gaim_get_core(), "quitting");
161
162 /* Transmission ends */
163 gaim_connections_disconnect_all();
164
165 /* Save .xml files, remove signals, etc. */
166 gaim_idle_uninit();
167 gaim_ssl_uninit();
168 gaim_pounces_uninit();
169 gaim_blist_uninit();
170 gaim_ciphers_uninit();
171 gaim_notify_uninit();
172 gaim_conversations_uninit();
173 gaim_connections_uninit();
174 gaim_buddy_icons_uninit();
175 gaim_accounts_uninit();
176 gaim_savedstatuses_uninit();
177 gaim_status_uninit();
178 gaim_prefs_uninit();
179 gaim_xfers_uninit();
180 gaim_proxy_uninit();
181 gaim_dnsquery_uninit();
182
183 gaim_debug_info("main", "Unloading all plugins\n");
184 gaim_plugins_destroy_all();
185
186 ops = gaim_core_get_ui_ops();
187 if (ops != NULL && ops->quit != NULL)
188 ops->quit();
189
190 /*
191 * gaim_sound_uninit() should be called as close to
192 * shutdown as possible. This is because the call
193 * to ao_shutdown() can sometimes leave our
194 * environment variables in an unusable state, which
195 * can cause a crash when getenv is called (by gettext
196 * for example). See the complete bug report at
197 * http://trac.xiph.org/cgi-bin/trac.cgi/ticket/701
198 *
199 * TODO: Eventually move this call higher up with the others.
200 */
201 gaim_sound_uninit();
202
203 gaim_plugins_uninit();
204 gaim_signals_uninit();
205
206 #ifdef HAVE_DBUS
207 gaim_dbus_uninit();
208 #endif
209
210 g_free(core->ui);
211 g_free(core);
212
213 #ifdef _WIN32
214 wgaim_cleanup();
215 #endif
216
217 _core = NULL;
218 }
219
220 gboolean
221 gaim_core_quit_cb(gpointer unused)
222 {
223 gaim_core_quit();
224
225 return FALSE;
226 }
227
228 const char *
229 gaim_core_get_version(void)
230 {
231 return VERSION;
232 }
233
234 const char *
235 gaim_core_get_ui(void)
236 {
237 GaimCore *core = gaim_get_core();
238
239 g_return_val_if_fail(core != NULL, NULL);
240
241 return core->ui;
242 }
243
244 GaimCore *
245 gaim_get_core(void)
246 {
247 return _core;
248 }
249
250 void
251 gaim_core_set_ui_ops(GaimCoreUiOps *ops)
252 {
253 _ops = ops;
254 }
255
256 GaimCoreUiOps *
257 gaim_core_get_ui_ops(void)
258 {
259 return _ops;
260 }