3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #include "connection.h"
24 #include "conversation.h"
28 #include "glibcompat.h"
30 #include "image-store.h"
39 #include "savedstatuses.h"
41 #include "smiley-custom.h"
42 #include "smiley-parser.h"
43 #include "smiley-theme.h"
45 #include "sound-theme-loader.h"
49 #include "theme-manager.h"
59 static PurpleCoreUiOps
*_ops
= NULL
;
60 static PurpleCore
*_core
= NULL
;
63 purple_core_print_version(void)
65 GHashTable
*ui_info
= purple_core_get_ui_info();
67 const gchar
*ui_version
;
68 gchar
*ui_full_name
= NULL
;
70 ui_name
= ui_info
? g_hash_table_lookup(ui_info
, "name") : NULL
;
71 ui_version
= ui_info
? g_hash_table_lookup(ui_info
, "version") : NULL
;
75 ui_full_name
= g_strdup_printf("%s %s", ui_name
, ui_version
);
77 ui_full_name
= g_strdup(ui_name
);
81 purple_debug_info("main", "Launching %s%slibpurple %s",
82 ui_full_name
? ui_full_name
: "",
83 ui_full_name
? " with " : "",
84 purple_core_get_version());
90 purple_core_init(const char *ui
)
95 g_return_val_if_fail(ui
!= NULL
, FALSE
);
96 g_return_val_if_fail(purple_get_core() == NULL
, FALSE
);
98 bindtextdomain(PACKAGE
, PURPLE_LOCALEDIR
);
104 _core
= core
= g_new0(PurpleCore
, 1);
105 core
->ui
= g_strdup(ui
);
106 core
->reserved
= NULL
;
108 ops
= purple_core_get_ui_ops();
110 /* The signals subsystem is important and should be first. */
111 purple_signals_init();
115 purple_signal_register(core
, "uri-handler",
116 purple_marshal_BOOLEAN__POINTER_POINTER_POINTER
,
118 G_TYPE_STRING
, /* Protocol */
119 G_TYPE_STRING
, /* Command */
120 G_TYPE_POINTER
); /* Parameters (GHashTable *) */
122 purple_signal_register(core
, "quitting", purple_marshal_VOID
, G_TYPE_NONE
,
124 purple_signal_register(core
, "core-initialized", purple_marshal_VOID
,
127 purple_core_print_version();
129 /* The prefs subsystem needs to be initialized before static protocols
130 * for protocol prefs to work. */
137 if (ops
->ui_prefs_init
!= NULL
)
138 ops
->ui_prefs_init();
140 if (ops
->debug_ui_init
!= NULL
)
141 ops
->debug_ui_init();
145 purple_protocols_init();
147 /* Since plugins get probed so early we should probably initialize their
148 * subsystem right away too.
150 purple_plugins_init();
152 purple_keyring_init(); /* before accounts */
153 purple_theme_manager_init();
155 /* The buddy icon code uses the image store, so init it early. */
156 _purple_image_store_init();
158 /* Accounts use status, buddy icons and connection signals, so
159 * initialize these before accounts
161 purple_statuses_init();
162 purple_buddy_icons_init();
163 purple_connections_init();
165 purple_accounts_init();
166 purple_savedstatuses_init();
167 purple_notify_init();
168 _purple_message_init();
169 purple_conversations_init();
172 purple_network_init();
173 purple_pounces_init();
179 _purple_smiley_custom_init();
180 _purple_smiley_parser_init();
183 * Call this early on to try to auto-detect our IP address and
184 * hopefully save some time later.
186 purple_network_get_my_ip(-1);
188 if (ops
!= NULL
&& ops
->ui_init
!= NULL
)
191 /* The UI may have registered some theme types, so refresh them */
192 purple_theme_manager_refresh();
194 /* Load the buddy list after UI init */
197 purple_signal_emit(purple_get_core(), "core-initialized");
203 purple_core_quit(void)
205 PurpleCoreUiOps
*ops
;
206 PurpleCore
*core
= purple_get_core();
208 g_return_if_fail(core
!= NULL
);
210 /* The self destruct sequence has been initiated */
211 purple_signal_emit(purple_get_core(), "quitting");
213 /* Transmission ends */
214 purple_connections_disconnect_all();
216 /* Save .xml files, remove signals, etc. */
217 _purple_smiley_theme_uninit();
218 _purple_smiley_custom_uninit();
219 _purple_smiley_parser_uninit();
220 purple_idle_uninit();
221 purple_pounces_uninit();
222 purple_conversations_uninit();
223 purple_blist_uninit();
224 purple_notify_uninit();
225 purple_connections_uninit();
226 purple_buddy_icons_uninit();
227 purple_savedstatuses_uninit();
228 purple_statuses_uninit();
229 purple_accounts_uninit();
230 purple_keyring_uninit(); /* after accounts */
231 purple_sound_uninit();
232 purple_theme_manager_uninit();
233 purple_xfers_uninit();
234 purple_proxy_uninit();
235 _purple_image_store_uninit();
236 purple_network_uninit();
238 ops
= purple_core_get_ui_ops();
239 if (ops
!= NULL
&& ops
->quit
!= NULL
)
242 /* Everything after prefs_uninit must not try to read any prefs */
243 purple_prefs_uninit();
244 purple_plugins_uninit();
246 purple_protocols_uninit();
248 purple_cmds_uninit();
250 _purple_message_uninit();
251 /* Everything after util_uninit cannot try to write things to the
252 * confdir nor use purple_escape_js
254 purple_util_uninit();
256 purple_signals_uninit();
269 purple_core_quit_cb(gpointer unused
)
277 purple_core_get_version(void)
283 purple_core_get_ui(void)
285 PurpleCore
*core
= purple_get_core();
287 g_return_val_if_fail(core
!= NULL
, NULL
);
293 purple_get_core(void)
298 static PurpleCoreUiOps
*
299 purple_core_ui_ops_copy(PurpleCoreUiOps
*ops
)
301 PurpleCoreUiOps
*ops_new
;
303 g_return_val_if_fail(ops
!= NULL
, NULL
);
305 ops_new
= g_new(PurpleCoreUiOps
, 1);
312 purple_core_ui_ops_get_type(void)
314 static GType type
= 0;
317 type
= g_boxed_type_register_static("PurpleCoreUiOps",
318 (GBoxedCopyFunc
)purple_core_ui_ops_copy
,
319 (GBoxedFreeFunc
)g_free
);
326 purple_core_set_ui_ops(PurpleCoreUiOps
*ops
)
332 purple_core_get_ui_ops(void)
337 GHashTable
* purple_core_get_ui_info() {
338 PurpleCoreUiOps
*ops
= purple_core_get_ui_ops();
340 if(NULL
== ops
|| NULL
== ops
->get_ui_info
)
343 return ops
->get_ui_info();
346 #define MIGRATE_TO_XDG_DIR(xdg_base_dir, legacy_path) \
348 gboolean migrate_res; \
350 migrate_res = purple_move_to_xdg_base_dir(xdg_base_dir, legacy_path); \
351 if (!migrate_res) { \
352 purple_debug_error("core", "Error migrating %s to %s\n", \
353 legacy_path, xdg_base_dir); \
359 purple_core_migrate_to_xdg_base_dirs(void)
361 gboolean xdg_dir_exists
;
363 xdg_dir_exists
= g_file_test(purple_data_dir(), G_FILE_TEST_EXISTS
);
364 if (!xdg_dir_exists
) {
365 MIGRATE_TO_XDG_DIR(purple_data_dir(), "certificates");
366 MIGRATE_TO_XDG_DIR(purple_data_dir(), "custom_smiley");
367 MIGRATE_TO_XDG_DIR(purple_data_dir(), "logs");
368 MIGRATE_TO_XDG_DIR(purple_config_dir(), "accounts.xml");
369 MIGRATE_TO_XDG_DIR(purple_config_dir(), "blist.xml");
370 MIGRATE_TO_XDG_DIR(purple_config_dir(), "fs-codec.conf");
371 MIGRATE_TO_XDG_DIR(purple_config_dir(), "fs-element.conf");
372 MIGRATE_TO_XDG_DIR(purple_config_dir(), "pounces.xml");
373 MIGRATE_TO_XDG_DIR(purple_config_dir(), "prefs.xml");
374 MIGRATE_TO_XDG_DIR(purple_config_dir(), "smileys.xml");
375 MIGRATE_TO_XDG_DIR(purple_config_dir(), "status.xml");