Mercurial > pidgin.yaz
comparison libgaim/core.c @ 14192:60b1bc8dbf37
[gaim-migrate @ 16863]
Renamed 'core' to 'libgaim'
committer: Tailor Script <tailor@pidgin.im>
author | Evan Schoenberg <evan.s@dreskin.net> |
---|---|
date | Sat, 19 Aug 2006 01:50:10 +0000 |
parents | |
children | ab8a105eff62 |
comparison
equal
deleted
inserted
replaced
14191:009db0b357b5 | 14192:60b1bc8dbf37 |
---|---|
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 "ft.h" | |
32 #include "idle.h" | |
33 #include "network.h" | |
34 #include "notify.h" | |
35 #include "plugin.h" | |
36 #include "pounce.h" | |
37 #include "prefs.h" | |
38 #include "privacy.h" | |
39 #include "proxy.h" | |
40 #include "savedstatuses.h" | |
41 #include "signals.h" | |
42 #include "sslconn.h" | |
43 #include "status.h" | |
44 #include "stun.h" | |
45 #include "sound.h" | |
46 | |
47 #ifdef HAVE_DBUS | |
48 # include "dbus-server.h" | |
49 #endif | |
50 | |
51 struct GaimCore | |
52 { | |
53 char *ui; | |
54 | |
55 void *reserved; | |
56 }; | |
57 | |
58 static GaimCoreUiOps *_ops = NULL; | |
59 static GaimCore *_core = NULL; | |
60 | |
61 STATIC_PROTO_INIT | |
62 | |
63 gboolean | |
64 gaim_core_init(const char *ui) | |
65 { | |
66 GaimCoreUiOps *ops; | |
67 GaimCore *core; | |
68 | |
69 g_return_val_if_fail(ui != NULL, FALSE); | |
70 g_return_val_if_fail(gaim_get_core() == NULL, FALSE); | |
71 | |
72 _core = core = g_new0(GaimCore, 1); | |
73 core->ui = g_strdup(ui); | |
74 core->reserved = NULL; | |
75 | |
76 ops = gaim_core_get_ui_ops(); | |
77 | |
78 /* The signals subsystem is important and should be first. */ | |
79 gaim_signals_init(); | |
80 | |
81 gaim_signal_register(core, "quitting", gaim_marshal_VOID, NULL, 0); | |
82 | |
83 /* The prefs subsystem needs to be initialized before static protocols | |
84 * for protocol prefs to work. */ | |
85 gaim_prefs_init(); | |
86 | |
87 gaim_debug_init(); | |
88 | |
89 if (ops != NULL) | |
90 { | |
91 if (ops->ui_prefs_init != NULL) | |
92 ops->ui_prefs_init(); | |
93 | |
94 if (ops->debug_ui_init != NULL) | |
95 ops->debug_ui_init(); | |
96 } | |
97 | |
98 #ifdef HAVE_DBUS | |
99 gaim_dbus_init(); | |
100 #endif | |
101 | |
102 /* Initialize all static protocols. */ | |
103 static_proto_init(); | |
104 | |
105 /* Since plugins get probed so early we should probably initialize their | |
106 * subsystem right away too. | |
107 */ | |
108 gaim_plugins_init(); | |
109 gaim_plugins_probe(G_MODULE_SUFFIX); | |
110 | |
111 /* Accounts use status and buddy icons, so initialize these before accounts */ | |
112 gaim_status_init(); | |
113 gaim_buddy_icons_init(); | |
114 | |
115 gaim_accounts_init(); | |
116 gaim_savedstatuses_init(); | |
117 gaim_ciphers_init(); | |
118 gaim_notify_init(); | |
119 gaim_connections_init(); | |
120 gaim_conversations_init(); | |
121 gaim_blist_init(); | |
122 gaim_log_init(); | |
123 gaim_network_init(); | |
124 gaim_privacy_init(); | |
125 gaim_pounces_init(); | |
126 gaim_proxy_init(); | |
127 gaim_sound_init(); | |
128 gaim_ssl_init(); | |
129 gaim_stun_init(); | |
130 gaim_xfers_init(); | |
131 gaim_idle_init(); | |
132 | |
133 /* Call this early on to try to auto-detect our IP address */ | |
134 gaim_network_get_my_ip(-1); | |
135 | |
136 if (ops != NULL && ops->ui_init != NULL) | |
137 ops->ui_init(); | |
138 | |
139 return TRUE; | |
140 } | |
141 | |
142 void | |
143 gaim_core_quit(void) | |
144 { | |
145 GaimCoreUiOps *ops; | |
146 GaimCore *core = gaim_get_core(); | |
147 | |
148 g_return_if_fail(core != NULL); | |
149 | |
150 /* The self destruct sequence has been initiated */ | |
151 gaim_signal_emit(gaim_get_core(), "quitting"); | |
152 | |
153 /* Transmission ends */ | |
154 gaim_connections_disconnect_all(); | |
155 | |
156 /* Save .xml files, remove signals, etc. */ | |
157 gaim_idle_uninit(); | |
158 gaim_ssl_uninit(); | |
159 gaim_pounces_uninit(); | |
160 gaim_blist_uninit(); | |
161 gaim_ciphers_uninit(); | |
162 gaim_notify_uninit(); | |
163 gaim_conversations_uninit(); | |
164 gaim_connections_uninit(); | |
165 gaim_buddy_icons_uninit(); | |
166 gaim_accounts_uninit(); | |
167 gaim_savedstatuses_uninit(); | |
168 gaim_status_uninit(); | |
169 gaim_prefs_uninit(); | |
170 gaim_xfers_uninit(); | |
171 | |
172 gaim_debug_info("main", "Unloading all plugins\n"); | |
173 gaim_plugins_destroy_all(); | |
174 | |
175 ops = gaim_core_get_ui_ops(); | |
176 if (ops != NULL && ops->quit != NULL) | |
177 ops->quit(); | |
178 | |
179 /* | |
180 * gaim_sound_uninit() should be called as close to | |
181 * shutdown as possible. This is because the call | |
182 * to ao_shutdown() can sometimes leave our | |
183 * environment variables in an unusable state, which | |
184 * can cause a crash when getenv is called (by gettext | |
185 * for example). See the complete bug report at | |
186 * http://trac.xiph.org/cgi-bin/trac.cgi/ticket/701 | |
187 * | |
188 * TODO: Eventually move this call higher up with the others. | |
189 */ | |
190 gaim_sound_uninit(); | |
191 | |
192 gaim_plugins_uninit(); | |
193 gaim_signals_uninit(); | |
194 | |
195 #ifdef HAVE_DBUS | |
196 gaim_dbus_uninit(); | |
197 #endif | |
198 | |
199 g_free(core->ui); | |
200 g_free(core); | |
201 | |
202 _core = NULL; | |
203 } | |
204 | |
205 gboolean | |
206 gaim_core_quit_cb(gpointer unused) | |
207 { | |
208 gaim_core_quit(); | |
209 | |
210 return FALSE; | |
211 } | |
212 | |
213 const char * | |
214 gaim_core_get_version(void) | |
215 { | |
216 return VERSION; | |
217 } | |
218 | |
219 const char * | |
220 gaim_core_get_ui(void) | |
221 { | |
222 GaimCore *core = gaim_get_core(); | |
223 | |
224 g_return_val_if_fail(core != NULL, NULL); | |
225 | |
226 return core->ui; | |
227 } | |
228 | |
229 GaimCore * | |
230 gaim_get_core(void) | |
231 { | |
232 return _core; | |
233 } | |
234 | |
235 void | |
236 gaim_core_set_ui_ops(GaimCoreUiOps *ops) | |
237 { | |
238 _ops = ops; | |
239 } | |
240 | |
241 GaimCoreUiOps * | |
242 gaim_core_get_ui_ops(void) | |
243 { | |
244 return _ops; | |
245 } |