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"
31 #include "image-store.h"
40 #include "savedstatuses.h"
42 #include "smiley-custom.h"
43 #include "smiley-parser.h"
44 #include "smiley-theme.h"
46 #include "sound-theme-loader.h"
50 #include "theme-manager.h"
60 static PurpleCoreUiOps
*_ops
= NULL
;
61 static PurpleCore
*_core
= NULL
;
64 purple_core_print_version(void)
66 GHashTable
*ui_info
= purple_core_get_ui_info();
68 const gchar
*ui_version
;
69 gchar
*ui_full_name
= NULL
;
71 ui_name
= ui_info
? g_hash_table_lookup(ui_info
, "name") : NULL
;
72 ui_version
= ui_info
? g_hash_table_lookup(ui_info
, "version") : NULL
;
75 ui_full_name
= g_strdup_printf("%s%s%s", ui_name
,
76 ui_version
? " " : "", ui_version
);
79 purple_debug_info("main", "Launching %s%slibpurple %s",
80 ui_full_name
? ui_full_name
: "",
81 ui_full_name
? " with " : "",
82 purple_core_get_version());
87 purple_core_init(const char *ui
)
92 g_return_val_if_fail(ui
!= NULL
, FALSE
);
93 g_return_val_if_fail(purple_get_core() == NULL
, FALSE
);
95 bindtextdomain(PACKAGE
, PURPLE_LOCALEDIR
);
101 _core
= core
= g_new0(PurpleCore
, 1);
102 core
->ui
= g_strdup(ui
);
103 core
->reserved
= NULL
;
105 ops
= purple_core_get_ui_ops();
107 /* The signals subsystem is important and should be first. */
108 purple_signals_init();
112 purple_signal_register(core
, "uri-handler",
113 purple_marshal_BOOLEAN__POINTER_POINTER_POINTER
,
115 G_TYPE_STRING
, /* Protocol */
116 G_TYPE_STRING
, /* Command */
117 G_TYPE_POINTER
); /* Parameters (GHashTable *) */
119 purple_signal_register(core
, "quitting", purple_marshal_VOID
, G_TYPE_NONE
,
121 purple_signal_register(core
, "core-initialized", purple_marshal_VOID
,
124 purple_core_print_version();
126 /* The prefs subsystem needs to be initialized before static protocols
127 * for protocol prefs to work. */
134 if (ops
->ui_prefs_init
!= NULL
)
135 ops
->ui_prefs_init();
137 if (ops
->debug_ui_init
!= NULL
)
138 ops
->debug_ui_init();
142 purple_protocols_init();
144 /* Since plugins get probed so early we should probably initialize their
145 * subsystem right away too.
147 purple_plugins_init();
149 purple_keyring_init(); /* before accounts */
150 purple_theme_manager_init();
152 /* The buddy icon code uses the image store, so init it early. */
153 _purple_image_store_init();
155 /* Accounts use status, buddy icons and connection signals, so
156 * initialize these before accounts
158 purple_statuses_init();
159 purple_buddy_icons_init();
160 purple_connections_init();
162 purple_accounts_init();
163 purple_savedstatuses_init();
164 purple_notify_init();
165 _purple_message_init();
166 purple_conversations_init();
169 purple_network_init();
170 purple_pounces_init();
177 _purple_smiley_custom_init();
178 _purple_smiley_parser_init();
181 * Call this early on to try to auto-detect our IP address and
182 * hopefully save some time later.
184 purple_network_get_my_ip(-1);
186 if (ops
!= NULL
&& ops
->ui_init
!= NULL
)
189 /* The UI may have registered some theme types, so refresh them */
190 purple_theme_manager_refresh();
192 /* Load the buddy list after UI init */
195 purple_signal_emit(purple_get_core(), "core-initialized");
201 purple_core_quit(void)
203 PurpleCoreUiOps
*ops
;
204 PurpleCore
*core
= purple_get_core();
206 g_return_if_fail(core
!= NULL
);
208 /* The self destruct sequence has been initiated */
209 purple_signal_emit(purple_get_core(), "quitting");
211 /* Transmission ends */
212 purple_connections_disconnect_all();
214 /* Save .xml files, remove signals, etc. */
215 _purple_smiley_theme_uninit();
216 _purple_smiley_custom_uninit();
217 _purple_smiley_parser_uninit();
218 purple_http_uninit();
219 purple_idle_uninit();
220 purple_pounces_uninit();
221 purple_conversations_uninit();
222 purple_blist_uninit();
223 purple_notify_uninit();
224 purple_connections_uninit();
225 purple_buddy_icons_uninit();
226 purple_savedstatuses_uninit();
227 purple_statuses_uninit();
228 purple_accounts_uninit();
229 purple_keyring_uninit(); /* after accounts */
230 purple_sound_uninit();
231 purple_theme_manager_uninit();
232 purple_xfers_uninit();
233 purple_proxy_uninit();
234 _purple_image_store_uninit();
235 purple_network_uninit();
237 ops
= purple_core_get_ui_ops();
238 if (ops
!= NULL
&& ops
->quit
!= NULL
)
241 /* Everything after prefs_uninit must not try to read any prefs */
242 purple_prefs_uninit();
243 purple_plugins_uninit();
245 purple_protocols_uninit();
247 purple_cmds_uninit();
249 _purple_message_uninit();
250 /* Everything after util_uninit cannot try to write things to the
251 * confdir nor use purple_escape_js
253 purple_util_uninit();
255 purple_signals_uninit();
268 purple_core_quit_cb(gpointer unused
)
276 purple_core_get_version(void)
282 purple_core_get_ui(void)
284 PurpleCore
*core
= purple_get_core();
286 g_return_val_if_fail(core
!= NULL
, NULL
);
292 purple_get_core(void)
297 static PurpleCoreUiOps
*
298 purple_core_ui_ops_copy(PurpleCoreUiOps
*ops
)
300 PurpleCoreUiOps
*ops_new
;
302 g_return_val_if_fail(ops
!= NULL
, NULL
);
304 ops_new
= g_new(PurpleCoreUiOps
, 1);
311 purple_core_ui_ops_get_type(void)
313 static GType type
= 0;
316 type
= g_boxed_type_register_static("PurpleCoreUiOps",
317 (GBoxedCopyFunc
)purple_core_ui_ops_copy
,
318 (GBoxedFreeFunc
)g_free
);
325 purple_core_set_ui_ops(PurpleCoreUiOps
*ops
)
331 purple_core_get_ui_ops(void)
336 GHashTable
* purple_core_get_ui_info() {
337 PurpleCoreUiOps
*ops
= purple_core_get_ui_ops();
339 if(NULL
== ops
|| NULL
== ops
->get_ui_info
)
342 return ops
->get_ui_info();
345 #define MIGRATE_TO_XDG_DIR(xdg_base_dir, legacy_path) \
347 gboolean migrate_res; \
349 migrate_res = purple_move_to_xdg_base_dir(xdg_base_dir, legacy_path); \
350 if (!migrate_res) { \
351 purple_debug_error("core", "Error migrating %s to %s\n", \
352 legacy_path, xdg_base_dir); \
358 purple_core_migrate_to_xdg_base_dirs(void)
360 gboolean xdg_dir_exists
;
362 xdg_dir_exists
= g_file_test(purple_data_dir(), G_FILE_TEST_EXISTS
);
363 if (!xdg_dir_exists
) {
364 MIGRATE_TO_XDG_DIR(purple_data_dir(), "certificates");
365 MIGRATE_TO_XDG_DIR(purple_data_dir(), "custom_smiley");
366 MIGRATE_TO_XDG_DIR(purple_data_dir(), "logs");
367 MIGRATE_TO_XDG_DIR(purple_config_dir(), "accounts.xml");
368 MIGRATE_TO_XDG_DIR(purple_config_dir(), "blist.xml");
369 MIGRATE_TO_XDG_DIR(purple_config_dir(), "fs-codec.conf");
370 MIGRATE_TO_XDG_DIR(purple_config_dir(), "fs-element.conf");
371 MIGRATE_TO_XDG_DIR(purple_config_dir(), "pounces.xml");
372 MIGRATE_TO_XDG_DIR(purple_config_dir(), "prefs.xml");
373 MIGRATE_TO_XDG_DIR(purple_config_dir(), "smileys.xml");
374 MIGRATE_TO_XDG_DIR(purple_config_dir(), "status.xml");