# HG changeset patch # User Mark Doliner # Date 1104357239 0 # Node ID 6feef0a9098ab6bbd199d86e4e481b8035d243bb # Parent 904d03bfcccefb8626fa82678b51717c61399915 [gaim-migrate @ 11712] A few minor improvements and some documentation updates. Conscious evolution in the back of your mind... committer: Tailor Script diff -r 904d03bfccce -r 6feef0a9098a po/POTFILES.in --- a/po/POTFILES.in Wed Dec 29 20:01:48 2004 +0000 +++ b/po/POTFILES.in Wed Dec 29 21:53:59 2004 +0000 @@ -59,8 +59,8 @@ src/gtkprivacy.c src/gtkrequest.c src/gtkroomlist.c +src/gtksavedstatuses.c src/gtksound.c -src/gtksavedstatuses.c src/gtkstatusselector.c src/gtkstock.c src/gtkutils.c diff -r 904d03bfccce -r 6feef0a9098a src/account.c --- a/src/account.c Wed Dec 29 20:01:48 2004 +0000 +++ b/src/account.c Wed Dec 29 21:53:59 2004 +0000 @@ -583,13 +583,13 @@ account->presence = gaim_presence_new_for_account(account); - prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); + prpl = gaim_find_prpl(protocol_id); if (prpl == NULL) return account; prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); - if ( prpl_info != NULL && prpl_info->status_types != NULL ) + if (prpl_info != NULL && prpl_info->status_types != NULL ) gaim_account_set_status_types(account, prpl_info->status_types(account)); gaim_presence_set_status_active(account->presence, "offline", TRUE); @@ -1699,12 +1699,12 @@ gaim_value_new(GAIM_TYPE_UINT)); gaim_signal_register(handle, "account-added", - gaim_marshal_VOID__POINTER, NULL, 1, - gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_ACCOUNT)); + gaim_marshal_VOID__POINTER, NULL, 1, + gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_ACCOUNT)); gaim_signal_register(handle, "account-removed", - gaim_marshal_VOID__POINTER, NULL, 1, - gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_ACCOUNT)); + gaim_marshal_VOID__POINTER, NULL, 1, + gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_ACCOUNT)); } void diff -r 904d03bfccce -r 6feef0a9098a src/connection.c --- a/src/connection.c Wed Dec 29 20:01:48 2004 +0000 +++ b/src/connection.c Wed Dec 29 21:53:59 2004 +0000 @@ -147,15 +147,12 @@ gaim_connection_connect(GaimConnection *gc, GaimStatus *status) { GaimAccount *account; - GaimConnectionUiOps *ops; GaimPluginProtocolInfo *prpl_info = NULL; g_return_if_fail(gc != NULL); gaim_debug_info("connection", "Connecting. gc = %p\n", gc); - ops = gaim_connections_get_ui_ops(); - if (gc->prpl != NULL) prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); else { diff -r 904d03bfccce -r 6feef0a9098a src/gtkmain.c --- a/src/gtkmain.c Wed Dec 29 20:01:48 2004 +0000 +++ b/src/gtkmain.c Wed Dec 29 21:53:59 2004 +0000 @@ -438,7 +438,7 @@ char *opt_login_arg = NULL; char *opt_session_arg = NULL; int dologin_ret = -1; - char *plugin_search_paths[3]; + char *search_path; #if HAVE_SIGNAL_H int sig_indx; /* for setting up signal catching */ sigset_t sigset; @@ -594,6 +594,13 @@ gaim_core_set_ui_ops(gaim_gtk_core_get_ui_ops()); gaim_eventloop_set_ui_ops(gaim_gtk_eventloop_get_ui_ops()); + /* Set plugin search directories */ + gaim_plugins_add_search_path(LIBDIR); + gaim_plugins_add_search_path(gaim_user_dir()); + search_path = g_build_filename(gaim_user_dir(), "plugins", NULL); + gaim_plugins_add_search_path(search_path); + g_free(search_path); + if (!gaim_core_init(GAIM_GTK_UI)) { fprintf(stderr, "Initialization of the Gaim core failed. Dumping core.\n" @@ -603,18 +610,7 @@ gaim_debug_set_enabled(debug_enabled); - plugin_search_paths[0] = g_strdup(LIBDIR); - plugin_search_paths[1] = g_strdup(gaim_user_dir()); - plugin_search_paths[2] = g_build_filename(gaim_user_dir(), "plugins", NULL); - - gaim_plugins_set_search_paths(sizeof(plugin_search_paths) / - sizeof(*plugin_search_paths), - plugin_search_paths); - - g_free(plugin_search_paths[0]); - g_free(plugin_search_paths[1]); - g_free(plugin_search_paths[2]); - + /* TODO: Do this in gaim_core_init() instead of here */ gaim_plugins_probe(NULL); /* TODO: Remove this check. Maybe in 2005. --KingAnt, 25 Jul 2004 */ diff -r 904d03bfccce -r 6feef0a9098a src/gtksavedstatuses.h --- a/src/gtksavedstatuses.h Wed Dec 29 20:01:48 2004 +0000 +++ b/src/gtksavedstatuses.h Wed Dec 29 21:53:59 2004 +0000 @@ -39,7 +39,11 @@ void gaim_gtk_status_window_hide(void); /** - * Shows a status editor (used for editing a single saved status). + * Shows a status editor (used for adding a new saved status or + * editing an already existing saved status). + * + * @param status The saved status to edit, or @c NULL if you + * want to add a new saved status. */ void gaim_gtk_status_editor_show(GaimSavedStatus *status); diff -r 904d03bfccce -r 6feef0a9098a src/gtkstatusselector.c --- a/src/gtkstatusselector.c Wed Dec 29 20:01:48 2004 +0000 +++ b/src/gtkstatusselector.c Wed Dec 29 21:53:59 2004 +0000 @@ -25,6 +25,7 @@ #include "internal.h" #include "gtkgaim.h" #include "gtkimhtml.h" +#include "gtksavedstatuses.h" #include "gtkstatusselector.h" #include "gtkutils.h" @@ -262,6 +263,10 @@ return FALSE; } +/* + * TODO: Get rid of the duplication in this function and + * insert_text_timeout_cb() + */ static void status_switched_cb(GtkWidget *combo, GaimGtkStatusSelector *selector) { @@ -275,7 +280,7 @@ { if (!strcmp(text, _("New Status"))) { - /* TODO */ + gaim_gtk_status_editor_show(NULL); } } else @@ -344,7 +349,7 @@ { if (!strcmp(text, _("New Status"))) { - /* TODO */ + gaim_gtk_status_editor_show(NULL); } } else @@ -518,14 +523,17 @@ * If no accounts are enabled then gray ourself out and get * outta hee. */ - for(accounts = gaim_accounts_get_all(); accounts; accounts = accounts->next) { + for (accounts = gaim_accounts_get_all(); accounts != NULL; + accounts = accounts->next) + { GaimAccount *a = accounts->data; - if (gaim_account_get_enabled(a, GAIM_GTK_UI)) { + if (gaim_account_get_enabled(a, GAIM_GTK_UI)) + { enabled = TRUE; break; } } - + if (enabled == FALSE) { gtk_widget_set_sensitive(GTK_WIDGET(selector), FALSE); @@ -580,7 +588,7 @@ continue; /* - * TODO Find a way to fallback to the GaimStatusPrimitive + * TODO: Find a way to fallback to the GaimStatusPrimitive * if an icon for this id does not exist. */ g_snprintf(filename, sizeof(filename), "%s.png", @@ -594,6 +602,7 @@ } else { + /* TODO: Add "online" and "offline" here? */ add_item(selector, "available", _("Available"), load_icon("online.png")); add_item(selector, "away", _("Away"), load_icon("away.png")); diff -r 904d03bfccce -r 6feef0a9098a src/plugin.c --- a/src/plugin.c Wed Dec 29 20:01:48 2004 +0000 +++ b/src/plugin.c Wed Dec 29 21:53:59 2004 +0000 @@ -58,14 +58,12 @@ } GaimPluginIpcCommand; +static GList *search_paths = NULL; +static GList *plugins = NULL; +static GList *load_queue = NULL; static GList *loaded_plugins = NULL; -static GList *plugins = NULL; static GList *plugin_loaders = NULL; static GList *protocol_plugins = NULL; -static GList *load_queue = NULL; - -static size_t search_path_count = 0; -static char **search_paths = NULL; static void (*probe_cb)(void *) = NULL; static void *probe_cb_data = NULL; @@ -79,13 +77,14 @@ gaim_plugins_get_handle(void) { static int handle; + return &handle; } #ifdef GAIM_PLUGINS -static int -is_so_file(const char *filename, const char *ext) +static gboolean +has_file_extension(const char *filename, const char *ext) { int len, extlen; @@ -98,7 +97,7 @@ if (len < 0) return 0; - return (!strncmp(filename + len, ext, extlen)); + return (strncmp(filename + len, ext, extlen) == 0); } static gboolean @@ -107,7 +106,7 @@ GList *exts; for (exts = GAIM_PLUGIN_LOADER_INFO(loader)->exts; exts != NULL; exts = exts->next) { - if (is_so_file(filename, (char *)exts->data)) { + if (has_file_extension(filename, (char *)exts->data)) { return TRUE; } } @@ -141,10 +140,12 @@ #endif /* GAIM_PLUGINS */ +/** + * Negative if a before b, 0 if equal, positive if a after b. + */ static gint compare_prpl(GaimPlugin *a, GaimPlugin *b) { - /* neg if a before b, 0 if equal, pos if a after b */ if(GAIM_IS_PROTOCOL_PLUGIN(a)) { if(GAIM_IS_PROTOCOL_PLUGIN(b)) return strcmp(a->info->name, b->info->name); @@ -186,21 +187,22 @@ if (!g_file_test(filename, G_FILE_TEST_EXISTS)) return NULL; + /* If this plugin has already been probed then exit */ plugin = gaim_plugins_find_with_filename(filename); - if (plugin != NULL) return plugin; - plugin = gaim_plugin_new(is_so_file(filename, PLUGIN_EXT), filename); + plugin = gaim_plugin_new(has_file_extension(filename, PLUGIN_EXT), filename); if (plugin->native_plugin) { const char *error; plugin->handle = g_module_open(filename, 0); - if (plugin->handle == NULL) { + if (plugin->handle == NULL) + { error = g_module_error(); - gaim_debug(GAIM_DEBUG_ERROR, "plugins", "%s is unloadable: %s\n", - plugin->path, error ? error : "Unknown error."); + gaim_debug_error("plugins", "%s is unloadable: %s\n", + plugin->path, error ? error : "Unknown error."); gaim_plugin_destroy(plugin); @@ -208,13 +210,14 @@ } if (!g_module_symbol(plugin->handle, "gaim_init_plugin", - &unpunned)) { + &unpunned)) + { g_module_close(plugin->handle); plugin->handle = NULL; error = g_module_error(); - gaim_debug(GAIM_DEBUG_ERROR, "plugins", "%s is unloadable: %s\n", - plugin->path, error ? error : "Unknown error."); + gaim_debug_error("plugins", "%s is unloadable: %s\n", + plugin->path, error ? error : "Unknown error."); gaim_plugin_destroy(plugin); @@ -401,8 +404,7 @@ g_return_val_if_fail(gaim_plugin_is_loaded(plugin), FALSE); - gaim_debug(GAIM_DEBUG_INFO, "plugins", "Unloading plugin %s\n", - plugin->info->name); + gaim_debug_info("plugins", "Unloading plugin %s\n", plugin->info->name); /* cancel any pending dialogs the plugin has */ gaim_request_close_with_handle(plugin); @@ -455,7 +457,6 @@ if (unload_cb != NULL) unload_cb(plugin, unload_cb_data); - /* I suppose this is the right place to call this... */ gaim_signal_emit(gaim_plugins_get_handle(), "plugin-unload", plugin); gaim_prefs_disconnect_by_handle(plugin); @@ -536,7 +537,7 @@ p2 = l->data; if (p2->path != NULL && - is_so_file(p2->path, exts->data)) + has_file_extension(p2->path, exts->data)) { gaim_plugin_destroy(p2); } @@ -787,30 +788,14 @@ * Plugins subsystem **************************************************************************/ void -gaim_plugins_set_search_paths(size_t count, char **paths) +gaim_plugins_add_search_path(const char *path) { - size_t s; - - g_return_if_fail(count > 0); - g_return_if_fail(paths != NULL); - - if (search_paths != NULL) { - for (s = 0; s < search_path_count; s++) - g_free(search_paths[s]); + g_return_if_fail(path != NULL); - g_free(search_paths); - } - - search_paths = g_new0(char *, count); + if (g_list_find_custom(search_paths, path, (GCompareFunc)strcmp)) + return; - for (s = 0; s < count; s++) { - if (paths[s] == NULL) - search_paths[s] = NULL; - else - search_paths[s] = g_strdup(paths[s]); - } - - search_path_count = count; + search_paths = g_list_append(search_paths, strdup(path)); } void @@ -835,6 +820,7 @@ #endif /* GAIM_PLUGINS */ } +/* TODO: Change this to accept a GList* */ void gaim_plugins_load_saved(const char *key) { @@ -883,7 +869,8 @@ const gchar *file; gchar *path; GaimPlugin *plugin; - size_t i; + GList *cur; + const char *search_path; void *handle; @@ -892,6 +879,7 @@ handle = gaim_plugins_get_handle(); + /* TODO: These signals need to be registered in an init function */ gaim_debug_info("plugins", "registering plugin-load signal\n"); gaim_signal_register(handle, "plugin-load", gaim_marshal_VOID__POINTER, NULL, 1, gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_PLUGIN)); @@ -901,17 +889,20 @@ 1, gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_PLUGIN)); - for (i = 0; i < search_path_count; i++) { - if (search_paths[i] == NULL) - continue; + /* Probe plugins */ + for (cur = search_paths; cur != NULL; cur = cur->next) + { + search_path = cur->data; - dir = g_dir_open(search_paths[i], 0, NULL); + dir = g_dir_open(search_path, 0, NULL); - if (dir != NULL) { - while ((file = g_dir_read_name(dir)) != NULL) { - path = g_build_filename(search_paths[i], file, NULL); + if (dir != NULL) + { + while ((file = g_dir_read_name(dir)) != NULL) + { + path = g_build_filename(search_path, file, NULL); - if (ext == NULL || is_so_file(file, ext)) + if (ext == NULL || has_file_extension(file, ext)) plugin = gaim_plugin_probe(path); g_free(path); @@ -921,7 +912,7 @@ } } - /* See if we have any plugins waiting to load. */ + /* See if we have any plugins waiting to load */ while (load_queue != NULL) { plugin = (GaimPlugin *)load_queue->data; @@ -933,8 +924,6 @@ if (plugin->info->type == GAIM_PLUGIN_LOADER) { - GList *exts; - /* We'll just load this right now. */ if (!gaim_plugin_load(plugin)) { @@ -945,11 +934,11 @@ plugin_loaders = g_list_append(plugin_loaders, plugin); - for (exts = GAIM_PLUGIN_LOADER_INFO(plugin)->exts; - exts != NULL; - exts = exts->next) + for (cur = GAIM_PLUGIN_LOADER_INFO(plugin)->exts; + cur != NULL; + cur = cur->next) { - gaim_plugins_probe(exts->data); + gaim_plugins_probe(cur->data); } } else if (plugin->info->type == GAIM_PLUGIN_PROTOCOL) @@ -975,12 +964,6 @@ } } - if (load_queue != NULL) - { - g_list_free(load_queue); - load_queue = NULL; - } - if (probe_cb != NULL) probe_cb(probe_cb_data); @@ -992,9 +975,11 @@ { g_return_val_if_fail(plugin != NULL, FALSE); + /* If this plugin has been registered already then exit */ if (g_list_find(plugins, plugin)) return TRUE; + /* Ensure the plugin has the requisite information */ if (plugin->info->type == GAIM_PLUGIN_LOADER) { GaimPluginLoaderInfo *loader_info; @@ -1003,12 +988,10 @@ if (loader_info == NULL) { - gaim_debug(GAIM_DEBUG_ERROR, "plugins", "%s is unloadable\n", + gaim_debug_error("plugins", "%s is unloadable\n", plugin->path); return FALSE; } - - load_queue = g_list_append(load_queue, plugin); } else if (plugin->info->type == GAIM_PLUGIN_PROTOCOL) { @@ -1018,13 +1001,14 @@ if (prpl_info == NULL) { - gaim_debug(GAIM_DEBUG_ERROR, "plugins", "%s is unloadable\n", + gaim_debug_error("plugins", "%s is unloadable\n", plugin->path); return FALSE; } + } - load_queue = g_list_append(load_queue, plugin); - } + /* This plugin should be probed and maybe loaded--add it to the queue */ + load_queue = g_list_append(load_queue, plugin); plugins = g_list_append(plugins, plugin); @@ -1198,4 +1182,3 @@ return act; } - diff -r 904d03bfccce -r 6feef0a9098a src/plugin.h --- a/src/plugin.h Wed Dec 29 20:01:48 2004 +0000 +++ b/src/plugin.h Wed Dec 29 21:53:59 2004 +0000 @@ -224,8 +224,14 @@ * Registers a plugin and prepares it for loading. * * This shouldn't be called by anything but the internal module code. + * Plugins should use the GAIM_INIT_PLUGIN() macro to register themselves + * with the core. * * @param plugin The plugin to register. + * + * @return @c TRUE if the plugin was registered successfully. Otherwise + * @c FALSE is returned (this happens if the plugin does not contain + * the necessary information). */ gboolean gaim_plugin_register(GaimPlugin *plugin); @@ -359,12 +365,11 @@ /*@{*/ /** - * Sets the search paths for plugins. + * Add a new directory to search for plugins * - * @param count The number of search paths. - * @param paths The search paths. + * @param paths The new search path. */ -void gaim_plugins_set_search_paths(size_t count, char **paths); +void gaim_plugins_add_search_path(const char *path); /** * Unloads all loaded plugins. diff -r 904d03bfccce -r 6feef0a9098a src/prpl.c --- a/src/prpl.c Wed Dec 29 20:01:48 2004 +0000 +++ b/src/prpl.c Wed Dec 29 21:53:59 2004 +0000 @@ -326,13 +326,15 @@ } void -gaim_prpl_set_account_status(GaimAccount *account, GaimStatus *status) +gaim_prpl_change_account_status(GaimAccount *account, + GaimStatus *old_status, GaimStatus *new_status) { GaimPlugin *prpl; GaimPluginProtocolInfo *prpl_info; - g_return_if_fail(account != NULL); - g_return_if_fail(status != NULL); + g_return_if_fail(account != NULL); + g_return_if_fail(old_status != NULL); + g_return_if_fail(new_status != NULL); prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); @@ -342,7 +344,7 @@ prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); if (prpl_info->set_status != NULL) - prpl_info->set_status(account, status); + prpl_info->set_status(account, new_status); } GList * @@ -354,7 +356,7 @@ GList *l; GaimStatus *status; - g_return_val_if_fail(account != NULL, NULL); + g_return_val_if_fail(account != NULL, NULL); g_return_val_if_fail(presence != NULL, NULL); prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); diff -r 904d03bfccce -r 6feef0a9098a src/prpl.h --- a/src/prpl.h Wed Dec 29 20:01:48 2004 +0000 +++ b/src/prpl.h Wed Dec 29 21:53:59 2004 +0000 @@ -414,11 +414,14 @@ /** * Informs the server that an account's status changed. * - * @param account The account the user is on. - * @param status The status that was activated, or deactivated - * (in the case of independent statuses). + * @param account The account the user is on. + * @param old_status The previous status. + * @param new_status The status that was activated, or deactivated + * (in the case of independent statuses). */ -void gaim_prpl_set_account_status(GaimAccount *account, GaimStatus *status); +void gaim_prpl_change_account_status(GaimAccount *account, + GaimStatus *old_status, + GaimStatus *new_status); /** * Retrieves the list of stock status types from a prpl. diff -r 904d03bfccce -r 6feef0a9098a src/savedstatuses.h --- a/src/savedstatuses.h Wed Dec 29 20:01:48 2004 +0000 +++ b/src/savedstatuses.h Wed Dec 29 21:53:59 2004 +0000 @@ -35,6 +35,8 @@ typedef struct _GaimSavedStatus GaimSavedStatus; typedef struct _GaimSavedStatusSub GaimSavedStatusSub; +#include "status.h" + /**************************************************************************/ /** @name Saved status subsystem */ /**************************************************************************/ diff -r 904d03bfccce -r 6feef0a9098a src/status.c --- a/src/status.c Wed Dec 29 20:01:48 2004 +0000 +++ b/src/status.c Wed Dec 29 21:53:59 2004 +0000 @@ -628,8 +628,6 @@ } } - - if (ops != NULL && ops->update != NULL) ops->update(gaim_get_blist(), (GaimBlistNode*)buddy); } @@ -646,20 +644,7 @@ GaimAccountUiOps *ops = gaim_accounts_get_ui_ops(); if (gaim_account_get_enabled(account, gaim_core_get_ui())) - { - GaimPluginProtocolInfo *prpl_info = NULL; - GaimPlugin *prpl; - - prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); - - if (prpl != NULL) - { - prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); - - if (prpl_info != NULL && prpl_info->set_status != NULL) - prpl_info->set_status(account, new_status); - } - } + gaim_prpl_change_account_status(account, old_status, new_status); if (ops != NULL && ops->status_changed != NULL) {