changeset 11064:e4459e8ccfb5

[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 <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Thu, 07 Jul 2005 02:47:49 +0000
parents 7a11ff12eb4b
children 8e97c8befc0b
files doc/conversation-signals.dox plugins/ChangeLog.API plugins/signals-test.c src/conversation.c src/server.c src/signals.c src/signals.h
diffstat 7 files changed, 57 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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
--- 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
--- 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),
--- 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,
--- 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)
--- 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);