Fri, 23 Dec 2005 19:26:04 +0000
[gaim-migrate @ 14983]
SF Patch #1314512 from Sadrul (who has a patch for everything)
"This patch introduces a flag for protocol plugins that
support offline messages (like Y!M and ICQ). This was
encouraged by the following conversation:
<sadrul> should offline buddies be listed/enabled in
the send-to menu?
<rekkanoryo> i would think only for protocols that
support offline messaging, if it's indicated that the
buddy is offline
-- <snip> --
<Bleeter> sadrul: personally, I'd like to see a
'supports offline' flag of some description
<Bleeter> one could then redirect (via plugins) through
email or alternative methods
<Bleeter> just a thought
<Paco-Paco> yeah, that sounds like a reasonble thing to have
This patch uses this flag to disable the buddies in the
send-to menu who are offline and the protocol doesn't
support offline messages."
I made this make the label insensitive instead of the whole menuitem. This
should address SimGuy's concerns about inconsistency (i.e. you could create a
conversation with someone via the buddy list that you couldn't create via the
Send To menu). I also hacked up some voodoo to show the label as sensitive when
moused-over, as that looks better (given the label-insensitive thing is itself a
hack). I think this works quite well.
BUG NOTE:
This makes more obvious an existing bug. The Send To menu isn't updated when
buddies sign on or off or change status (at least under some circumstances).
We need to fix that anyway, so I'm not going to let it hold up this commit.
Switching tabs will clear it up. I'm thinking we just might want to build the
contents of that menu when it is selected. That would save us a mess of
inefficient signal callbacks that update the Send To menus in open windows all
the time.
AIM NOTE:
This assumes that AIM can't offline message. That's not strictly true. You can
message invisible users on AIM. However, by design, we can't tell when a user
is invisible without resorting to dirty hackery. In practice, this isn't a
problem, as you can still select the AIM user from the menu. And really, how
often will you be choosing the Invisible contact, rather than the user going
Invisible in the middle of a conversation or IMing you while they're Invisible?
JABBER NOTE:
This assumes that Jabber can always offline message. This isn't strictly true.
Sadrul said:
I have updated Jabber according to this link which seems to
talk about how to determine the existence offline-message
support in a server:
http://www.jabber.org/jeps/jep-0013.html#discover
However, jabber.org doesn't seem to send the required
info. So I am not sure about it.
He later said:
I talked to Nathan and he said offline message support is
mostly assumed for most jabber servers. GTalk doesn't yet
support it, but they are working on it. So I have made
jabber to always return TRUE.
If there is truly no way to detect offline messaging capability, then this is
an acceptable solution. We could special case Google Talk because of its
popularity, and remove that later. It's probably not worth it though.
MSN NOTE:
This assumes that MSN can never offline message. That's effectively true, but
to be technically correct, MSN can offline message if there's already a
switchboard conversation open with a user. We could write an offline_message
function in the MSN prpl to detect that, but it'd be of limited usefulness,
especially given that under most circumstances (where this might matter), the
switchboard connection will be closed almost immediately.
CVS NOTE:
I'm writing to share a tragic little story.
I have a PC that I use for Gaim development. One day, I was writing a commit
message on it, when all of a suddent it went berserk. The screen started
flashing, and the whole commit message just disappeared. All of it. And it was
a good commit message! I had to cram and rewrite it really quickly. Needless to
say, my rushed commit message wasn't nearly as good, and I blame the PC for that.
Seriously, though, what kind of version control system loses your commit
message on a broken connection to the server? Stupid!
committer: Richard Laager <rlaager@pidgin.im>
#include "perl-common.h" #include "perl-handlers.h" #include "debug.h" #include "signals.h" static GList *timeout_handlers = NULL; static GList *signal_handlers = NULL; static char *perl_plugin_pref_cb; static char *perl_gtk_plugin_pref_cb; extern PerlInterpreter *my_perl; /* perl < 5.8.0 doesn't define PERL_MAGIC_ext */ #ifndef PERL_MAGIC_ext #define PERL_MAGIC_ext '~' #endif /* For now a plugin can only have one action */ void gaim_perl_plugin_action_cb(GaimPluginAction * gpa) { dSP; ENTER; SAVETMPS; PUSHMARK(sp); /* We put the plugin handle on the stack so it can pass it along */ /* to anythng called from the callback. It is supposed to pass */ /* the Action, but there is no way to access the plugin handle from */ /* the GaimPluginAction in perl...yet. */ XPUSHs(gaim_perl_bless_object(gpa->plugin, "Gaim::Plugin")); PUTBACK; /* gaim_perl_plugin_action_callback_sub defined in the header is set */ /* in perl.c during plugin probe by a PLUGIN_INFO hash value limiting */ /* us to only one action for right now even though the action member of */ /* GaimPluginInfo can take (does take) a GList. */ call_pv(gaim_perl_plugin_action_callback_sub, G_EVAL | G_SCALAR); SPAGAIN; PUTBACK; FREETMPS; LEAVE; } GList *gaim_perl_plugin_action(GaimPlugin *plugin, gpointer context) { GaimPluginAction *act = NULL; GList *gl = NULL; /* TODO: Fix the way we create action handlers so we can have mroe than */ /* one action in perl. Maybe there is a clever work around, but so far */ /* I have not figured it out. There is no way to tie the perl sub's */ /* name to the callback function without these global variables and */ /* there is no way to create a callback on the fly so each would have */ /* to be hardcoded--more than one would just be arbitrary. */ act = gaim_plugin_action_new(gaim_perl_plugin_action_label, gaim_perl_plugin_action_cb); gl = g_list_append(gl, act); return gl; } GaimGtkPluginUiInfo *gaim_perl_gtk_plugin_pref(const char * frame_cb) { GaimGtkPluginUiInfo *ui_info; ui_info = g_new0(GaimGtkPluginUiInfo, 1); perl_gtk_plugin_pref_cb = g_strdup(frame_cb); ui_info->get_config_frame = gaim_perl_gtk_get_plugin_frame; return ui_info; } GtkWidget *gaim_perl_gtk_get_plugin_frame(GaimPlugin *plugin) { SV * sv; GtkWidget *ret; MAGIC *mg; dSP; int count; ENTER; SAVETMPS; count = call_pv(perl_gtk_plugin_pref_cb, G_SCALAR | G_NOARGS); if (count != 1) croak("call_pv: Did not return the correct number of values.\n"); /* the frame was created in a perl sub and is returned */ SPAGAIN; /* We have a Gtk2::Frame on top of the stack */ sv = POPs; /* The magic field hides the pointer to the actuale GtkWidget */ mg = mg_find(SvRV(sv), PERL_MAGIC_ext); ret = (GtkWidget *)mg->mg_ptr; PUTBACK; FREETMPS; LEAVE; return ret; } /* Called to create a pointer to GaimPluginUiInfo for the GaimPluginInfo */ /* It will then inturn create ui_info with the C function pointer */ /* that will eventually do a call_pv to call a perl functions so users */ /* can create their own frames in the prefs */ GaimPluginUiInfo *gaim_perl_plugin_pref(const char * frame_cb) { GaimPluginUiInfo *ui_info; ui_info = g_new0(GaimPluginUiInfo, 1); perl_plugin_pref_cb = g_strdup(frame_cb); ui_info->get_plugin_pref_frame = gaim_perl_get_plugin_frame; return ui_info; } GaimPluginPrefFrame *gaim_perl_get_plugin_frame(GaimPlugin *plugin) { /* Sets up the Perl Stack for our call back into the script to run the */ /* plugin_pref... sub */ GaimPluginPrefFrame *ret_frame; dSP; int count; ENTER; SAVETMPS; /* Some perl magic to run perl_plugin_pref_frame_SV perl sub and return */ /* the frame */ PUSHMARK(SP); PUTBACK; count = call_pv(perl_plugin_pref_cb, G_SCALAR | G_NOARGS); SPAGAIN; if (count != 1) croak("call_pv: Did not return the correct number of values.\n"); /* the frame was created in a perl sub and is returned */ ret_frame = (GaimPluginPrefFrame *)gaim_perl_ref_object(POPs); /* Tidy up the Perl stack */ PUTBACK; FREETMPS; LEAVE; return ret_frame; } static void destroy_timeout_handler(GaimPerlTimeoutHandler *handler) { timeout_handlers = g_list_remove(timeout_handlers, handler); if (handler->callback != NULL) SvREFCNT_dec(handler->callback); if (handler->data != NULL) SvREFCNT_dec(handler->data); g_free(handler); } static void destroy_signal_handler(GaimPerlSignalHandler *handler) { signal_handlers = g_list_remove(signal_handlers, handler); if (handler->callback != NULL) SvREFCNT_dec(handler->callback); if (handler->data != NULL) SvREFCNT_dec(handler->data); g_free(handler->signal); g_free(handler); } static int perl_timeout_cb(gpointer data) { GaimPerlTimeoutHandler *handler = (GaimPerlTimeoutHandler *)data; dSP; ENTER; SAVETMPS; PUSHMARK(sp); XPUSHs((SV *)handler->data); PUTBACK; call_sv(handler->callback, G_EVAL | G_SCALAR); SPAGAIN; PUTBACK; FREETMPS; LEAVE; destroy_timeout_handler(handler); return 0; } typedef void *DATATYPE; static void * perl_signal_cb(va_list args, void *data) { GaimPerlSignalHandler *handler = (GaimPerlSignalHandler *)data; void *ret_val = NULL; int i; int count; int value_count; GaimValue *ret_value, **values; SV **sv_args; DATATYPE **copy_args; STRLEN na; dSP; ENTER; SAVETMPS; PUSHMARK(sp); gaim_signal_get_values(handler->instance, handler->signal, &ret_value, &value_count, &values); sv_args = g_new(SV *, value_count); copy_args = g_new(void **, value_count); for (i = 0; i < value_count; i++) { sv_args[i] = sv_2mortal(gaim_perl_sv_from_vargs(values[i], (va_list*)&args, ©_args[i])); XPUSHs(sv_args[i]); } XPUSHs((SV *)handler->data); PUTBACK; if (ret_value != NULL) { count = call_sv(handler->callback, G_EVAL | G_SCALAR); SPAGAIN; if (count != 1) croak("Uh oh! call_sv returned %i != 1", i); else ret_val = gaim_perl_data_from_sv(ret_value, POPs); } else { call_sv(handler->callback, G_SCALAR); SPAGAIN; } if (SvTRUE(ERRSV)) { gaim_debug_error("perl", "Perl function exited abnormally: %s\n", SvPV(ERRSV, na)); } /* See if any parameters changed. */ for (i = 0; i < value_count; i++) { if (gaim_value_is_outgoing(values[i])) { switch (gaim_value_get_type(values[i])) { case GAIM_TYPE_BOOLEAN: *((gboolean *)copy_args[i]) = SvIV(sv_args[i]); break; case GAIM_TYPE_INT: *((int *)copy_args[i]) = SvIV(sv_args[i]); break; case GAIM_TYPE_UINT: *((unsigned int *)copy_args[i]) = SvUV(sv_args[i]); break; case GAIM_TYPE_LONG: *((long *)copy_args[i]) = SvIV(sv_args[i]); break; case GAIM_TYPE_ULONG: *((unsigned long *)copy_args[i]) = SvUV(sv_args[i]); break; case GAIM_TYPE_INT64: *((gint64 *)copy_args[i]) = SvIV(sv_args[i]); break; case GAIM_TYPE_UINT64: *((guint64 *)copy_args[i]) = SvUV(sv_args[i]); break; case GAIM_TYPE_STRING: if (strcmp(*((char **)copy_args[i]), SvPVX(sv_args[i]))) { g_free(*((char **)copy_args[i])); *((char **)copy_args[i]) = g_strdup(SvPV(sv_args[i], na)); } break; case GAIM_TYPE_POINTER: *((void **)copy_args[i]) = (void *)SvIV(sv_args[i]); break; case GAIM_TYPE_BOXED: *((void **)copy_args[i]) = (void *)SvIV(sv_args[i]); break; default: break; } #if 0 *((void **)copy_args[i]) = gaim_perl_data_from_sv(values[i], sv_args[i]); #endif } } PUTBACK; FREETMPS; LEAVE; g_free(sv_args); g_free(copy_args); gaim_debug_misc("perl", "ret_val = %p\n", ret_val); return ret_val; } static GaimPerlSignalHandler * find_signal_handler(GaimPlugin *plugin, void *instance, const char *signal) { GaimPerlSignalHandler *handler; GList *l; for (l = signal_handlers; l != NULL; l = l->next) { handler = (GaimPerlSignalHandler *)l->data; if (handler->plugin == plugin && handler->instance == instance && !strcmp(handler->signal, signal)) { return handler; } } return NULL; } void gaim_perl_timeout_add(GaimPlugin *plugin, int seconds, SV *callback, SV *data) { GaimPerlTimeoutHandler *handler; if (plugin == NULL) { croak("Invalid handle in adding perl timeout handler.\n"); return; } handler = g_new0(GaimPerlTimeoutHandler, 1); handler->plugin = plugin; handler->callback = (callback != NULL && callback != &PL_sv_undef ? newSVsv(callback) : NULL); handler->data = (data != NULL && data != &PL_sv_undef ? newSVsv(data) : NULL); timeout_handlers = g_list_append(timeout_handlers, handler); handler->iotag = g_timeout_add(seconds * 1000, perl_timeout_cb, handler); } void gaim_perl_timeout_clear_for_plugin(GaimPlugin *plugin) { GaimPerlTimeoutHandler *handler; GList *l, *l_next; for (l = timeout_handlers; l != NULL; l = l_next) { l_next = l->next; handler = (GaimPerlTimeoutHandler *)l->data; if (handler->plugin == plugin) destroy_timeout_handler(handler); } } void gaim_perl_timeout_clear(void) { while (timeout_handlers != NULL) destroy_timeout_handler(timeout_handlers->data); } void gaim_perl_signal_connect(GaimPlugin *plugin, void *instance, const char *signal, SV *callback, SV *data) { GaimPerlSignalHandler *handler; handler = g_new0(GaimPerlSignalHandler, 1); handler->plugin = plugin; handler->instance = instance; handler->signal = g_strdup(signal); handler->callback = (callback != NULL && callback != &PL_sv_undef ? newSVsv(callback) : NULL); handler->data = (data != NULL && data != &PL_sv_undef ? newSVsv(data) : NULL); signal_handlers = g_list_append(signal_handlers, handler); gaim_signal_connect_vargs(instance, signal, plugin, GAIM_CALLBACK(perl_signal_cb), handler); } void gaim_perl_signal_disconnect(GaimPlugin *plugin, void *instance, const char *signal) { GaimPerlSignalHandler *handler; handler = find_signal_handler(plugin, instance, signal); if (handler == NULL) { croak("Invalid signal handler information in " "disconnecting a perl signal handler.\n"); return; } destroy_signal_handler(handler); } void gaim_perl_signal_clear_for_plugin(GaimPlugin *plugin) { GaimPerlSignalHandler *handler; GList *l, *l_next; for (l = signal_handlers; l != NULL; l = l_next) { l_next = l->next; handler = (GaimPerlSignalHandler *)l->data; if (handler->plugin == plugin) destroy_signal_handler(handler); } } void gaim_perl_signal_clear(void) { while (signal_handlers != NULL) destroy_signal_handler(signal_handlers->data); }