# HG changeset patch # User Luke Schierer # Date 1082740413 0 # Node ID 5205743477bba2905b6173b6bed601d0cc472656 # Parent 1d7416e8db5f2d812e5d57e3a9e4982187594152 [gaim-migrate @ 9536] Christopher (siege) O'Brien was very patient as we waffled and rethought the option he wrote to supress disconnect dialogs committer: Tailor Script diff -r 1d7416e8db5f -r 5205743477bb ChangeLog --- a/ChangeLog Fri Apr 23 15:48:21 2004 +0000 +++ b/ChangeLog Fri Apr 23 17:13:33 2004 +0000 @@ -1,5 +1,13 @@ Gaim: The Pimpin' Penguin IM Client that's good for the soul! +version 0.78cvs + New Features: + * Option to suppress the disconnect notification when using + the autoreconnect plugin (Christopher (siege) O'Brien) + + Bug Fixes: + + version 0.77 (04/22/2004): New Features: * The System Log returns (Ka-Hing Cheung) diff -r 1d7416e8db5f -r 5205743477bb plugins/autorecon.c --- a/plugins/autorecon.c Fri Apr 23 15:48:21 2004 +0000 +++ b/plugins/autorecon.c Fri Apr 23 17:13:33 2004 +0000 @@ -2,14 +2,17 @@ #include "connection.h" #include "debug.h" +#include "pluginpref.h" #include "prpl.h" #include "signals.h" + #define AUTORECON_PLUGIN_ID "core-autorecon" #define INITIAL 8000 #define MAXTIME 2048000 + typedef struct { int delay; guint timeout; @@ -17,6 +20,46 @@ static GHashTable *hash = NULL; + +#define AUTORECON_OPT "/plugins/core/autorecon" +#define OPT_HIDE_CONNECTED AUTORECON_OPT "/hide_connected_error" +#define OPT_HIDE_CONNECTING AUTORECON_OPT "/hide_connecting_error" + + +/* storage of original (old_ops) and modified (new_ops) ui ops to allow us to + intercept calls to report_disconnect */ +static GaimConnectionUiOps *old_ops = NULL; +static GaimConnectionUiOps *new_ops = NULL; + + +static void report_disconnect(GaimConnection *gc, const char *text) { + + if(old_ops == NULL || old_ops->report_disconnect == NULL) { + /* there's nothing to call through to, so don't bother + checking prefs */ + return; + + } else if(gc->state == GAIM_CONNECTED + && gaim_prefs_get_bool(OPT_HIDE_CONNECTED)) { + /* this is a connected error, and we're hiding those */ + gaim_debug(GAIM_DEBUG_INFO, "autorecon", + "hid disconnect error message\n"); + return; + + } else if(gc->state == GAIM_CONNECTING + && gaim_prefs_get_bool(OPT_HIDE_CONNECTING)) { + /* this is a connecting error, and we're hiding those */ + gaim_debug(GAIM_DEBUG_INFO, "autorecon", + "hid error message while connecting\n"); + return; + } + + /* if we haven't returned by now, then let's pass to the real + function */ + old_ops->report_disconnect(gc, text); +} + + static gboolean do_signon(gpointer data) { GaimAccount *account = data; GaimAutoRecon *info; @@ -38,6 +81,7 @@ return FALSE; } + static void reconnect(GaimConnection *gc, void *m) { GaimAccount *account; GaimAutoRecon *info; @@ -62,6 +106,7 @@ } } + static void free_auto_recon(gpointer data) { @@ -73,18 +118,38 @@ g_free(info); } + static gboolean plugin_load(GaimPlugin *plugin) { + + /* this was the suggested way to override a single function of the + real ui ops. However, there's a mild concern of having more than one + bit of code making a new ui op call-through copy. If plugins A and B + both override the ui ops (in that order), B thinks that the + overridden ui ops A created was the original. If A unloads first, + and swaps out and frees its overridden version, then B is calling + through to a free'd ui op. There needs to be a way to "stack up" + overridden ui ops or something... I have a good idea of how to write + such a creature if someone wants it done. - siege 2004-04-20 */ + + /* get old ops, make a copy with a minor change */ + old_ops = gaim_connections_get_ui_ops(); + new_ops = (GaimConnectionUiOps *) g_memdup(old_ops, + sizeof(GaimConnectionUiOps)); + new_ops->report_disconnect = report_disconnect; + gaim_connections_set_ui_ops(new_ops); + hash = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, - free_auto_recon); + free_auto_recon); gaim_signal_connect(gaim_connections_get_handle(), "signed-off", - plugin, GAIM_CALLBACK(reconnect), NULL); + plugin, GAIM_CALLBACK(reconnect), NULL); return TRUE; } + static gboolean plugin_unload(GaimPlugin *plugin) { @@ -94,9 +159,38 @@ g_hash_table_destroy(hash); hash = NULL; + gaim_connections_set_ui_ops(old_ops); + g_free(new_ops); + old_ops = new_ops = NULL; + return TRUE; } + +static GaimPluginPrefFrame *get_plugin_pref_frame(GaimPlugin *plugin) { + GaimPluginPrefFrame *frame = gaim_plugin_pref_frame_new(); + GaimPluginPref *pref; + + pref = gaim_plugin_pref_new_with_label(_("Error Message Suppression")); + gaim_plugin_pref_frame_add(frame, pref); + + pref = gaim_plugin_pref_new_with_name_and_label(OPT_HIDE_CONNECTED, + _("Hide Disconnect Errors")); + gaim_plugin_pref_frame_add(frame, pref); + + pref = gaim_plugin_pref_new_with_name_and_label(OPT_HIDE_CONNECTING, + _("Hide Login Errors")); + gaim_plugin_pref_frame_add(frame, pref); + + return frame; +} + + +static GaimPluginUiInfo pref_info = { + get_plugin_pref_frame +}; + + static GaimPluginInfo info = { GAIM_PLUGIN_API_VERSION, /**< api_version */ @@ -121,12 +215,18 @@ NULL, /**< destroy */ NULL, /**< ui_info */ - NULL /**< extra_info */ + NULL, /**< extra_info */ + &pref_info /**< prefs_info */ }; + static void init_plugin(GaimPlugin *plugin) { + gaim_prefs_add_none(AUTORECON_OPT); + gaim_prefs_add_bool(OPT_HIDE_CONNECTED, FALSE); + gaim_prefs_add_bool(OPT_HIDE_CONNECTING, FALSE); } GAIM_INIT_PLUGIN(autorecon, init_plugin, info) +