# HG changeset patch # User Richard Laager # Date 1120704469 0 # Node ID e4459e8ccfb5d92e8cf52a6eac9ed3709690062c # Parent 7a11ff12eb4bdf5573a6f18656dac42b70e8f162 [gaim-migrate @ 13035] Patch #1208082 from Levi Bard (tak_tak) This patch modifies the chat-invited signal so plugins can programmatically accept or reject chat invitations. committer: Tailor Script diff -r 7a11ff12eb4b -r e4459e8ccfb5 doc/conversation-signals.dox --- a/doc/conversation-signals.dox Thu Jul 07 02:35:23 2005 +0000 +++ b/doc/conversation-signals.dox Thu Jul 07 02:47:49 2005 +0000 @@ -431,7 +431,7 @@ @signaldef chat-invited @signalproto -void (*chat_invited)(GaimAccount *account, const char *inviter, +gint (*chat_invited)(GaimAccount *account, const char *inviter, const char *chat, const char *invite_message const GHastTable *components); @endsignalproto @@ -443,6 +443,9 @@ @param invite_message The optional invite message. @param components The components necessary if you want to call serv_join_chat + @return Less than zero if the invitation should be rejected, greater than + zero if the invitation should be accepted. If zero is returned, the + default behavior will be maintained: the user will be prompted. @endsignaldef @signaldef chat-joined diff -r 7a11ff12eb4b -r e4459e8ccfb5 plugins/ChangeLog.API --- a/plugins/ChangeLog.API Thu Jul 07 02:35:23 2005 +0000 +++ b/plugins/ChangeLog.API Thu Jul 07 02:47:49 2005 +0000 @@ -76,6 +76,9 @@ non-NULL value. This value is now returned. Previously, all registered handlers were called and the value from the last handler was used. + * Changed: "chat-invited" handlers can now return a value to control + what happens to the invite (accept, reject, prompt the user). + See the Doxygen documentation for the details. version 1.0.0 (09/17/2004): * Added: get_chat_name to the GaimPluginProtocolInfo struct diff -r 7a11ff12eb4b -r e4459e8ccfb5 plugins/signals-test.c --- a/plugins/signals-test.c Thu Jul 07 02:35:23 2005 +0000 +++ b/plugins/signals-test.c Thu Jul 07 02:47:49 2005 +0000 @@ -417,7 +417,7 @@ gaim_conversation_get_name(conv), name, reason); } -static void +static gint chat_invited_cb(GaimAccount *account, const char *inviter, const char *room_name, const char *message, const GHashTable *components, void *data) @@ -425,6 +425,8 @@ gaim_debug_misc("signals test", "chat-invited (%s, %s, %s, %s)\n", gaim_account_get_username(account), inviter, room_name, message); + + return 0; } static void diff -r 7a11ff12eb4b -r e4459e8ccfb5 src/conversation.c --- a/src/conversation.c Thu Jul 07 02:35:23 2005 +0000 +++ b/src/conversation.c Thu Jul 07 02:47:49 2005 +0000 @@ -2967,7 +2967,7 @@ gaim_value_new(GAIM_TYPE_STRING)); gaim_signal_register(handle, "chat-invited", - gaim_marshal_VOID__POINTER_POINTER_POINTER_POINTER_POINTER, + gaim_marshal_INT__POINTER_POINTER_POINTER_POINTER_POINTER, NULL, 5, gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_ACCOUNT), diff -r 7a11ff12eb4b -r e4459e8ccfb5 src/server.c --- a/src/server.c Thu Jul 07 02:35:23 2005 +0000 +++ b/src/server.c Thu Jul 07 02:47:49 2005 +0000 @@ -999,30 +999,40 @@ GaimAccount *account; char buf2[BUF_LONG]; struct chat_invite_data *cid = g_new0(struct chat_invite_data, 1); + int plugin_return; account = gaim_connection_get_account(gc); - gaim_signal_emit(gaim_conversations_get_handle(), - "chat-invited", account, who, name, message, data); - - if (message != NULL) - { - g_snprintf(buf2, sizeof(buf2), - _("%s has invited %s to the chat room %s:\n%s"), - who, gaim_account_get_username(account), name, message); - } - else - g_snprintf(buf2, sizeof(buf2), - _("%s has invited %s to the chat room %s\n"), - who, gaim_account_get_username(account), name); + plugin_return = GPOINTER_TO_INT(gaim_signal_emit_return_1( + gaim_conversations_get_handle(), + "chat-invited", account, who, name, message, data)); cid->gc = gc; cid->components = data; - gaim_request_accept_cancel(gc, NULL, _("Accept chat invitation?"), buf2, + if (plugin_return == 0) + { + if (message != NULL) + { + g_snprintf(buf2, sizeof(buf2), + _("%s has invited %s to the chat room %s:\n%s"), + who, gaim_account_get_username(account), name, message); + } + else + g_snprintf(buf2, sizeof(buf2), + _("%s has invited %s to the chat room %s\n"), + who, gaim_account_get_username(account), name); + + + gaim_request_accept_cancel(gc, NULL, _("Accept chat invitation?"), buf2, GAIM_DEFAULT_ACTION_NONE, cid, G_CALLBACK(chat_invite_accept), G_CALLBACK(chat_invite_reject)); + } + else if (plugin_return > 0) + chat_invite_accept(cid); + else + chat_invite_reject(cid); } GaimConversation *serv_got_joined_chat(GaimConnection *gc, diff -r 7a11ff12eb4b -r e4459e8ccfb5 src/signals.c --- a/src/signals.c Thu Jul 07 02:35:23 2005 +0000 +++ b/src/signals.c Thu Jul 07 02:47:49 2005 +0000 @@ -777,6 +777,26 @@ *return_val = GINT_TO_POINTER(ret_val); } + +void +gaim_marshal_INT__POINTER_POINTER_POINTER_POINTER_POINTER( + GaimCallback cb, va_list args, void *data, void **return_val) +{ + gint ret_val; + void *arg1 = va_arg(args, void *); + void *arg2 = va_arg(args, void *); + void *arg3 = va_arg(args, void *); + void *arg4 = va_arg(args, void *); + void *arg5 = va_arg(args, void *); + + ret_val = + ((gint (*)(void *, void *, void *, void *, void *, void *))cb)( + arg1, arg2, arg3, arg4, arg5, data); + + if (return_val != NULL) + *return_val = GINT_TO_POINTER(ret_val); +} + void gaim_marshal_BOOLEAN__POINTER(GaimCallback cb, va_list args, void *data, void **return_val) diff -r 7a11ff12eb4b -r e4459e8ccfb5 src/signals.h --- a/src/signals.h Thu Jul 07 02:35:23 2005 +0000 +++ b/src/signals.h Thu Jul 07 02:47:49 2005 +0000 @@ -303,6 +303,8 @@ GaimCallback cb, va_list args, void *data, void **return_val); void gaim_marshal_INT__INT_INT( GaimCallback cb, va_list args, void *data, void **return_val); +void gaim_marshal_INT__POINTER_POINTER_POINTER_POINTER_POINTER( + GaimCallback cb, va_list args, void *data, void **return_val); void gaim_marshal_BOOLEAN__POINTER( GaimCallback cb, va_list args, void *data, void **return_val);