changeset 8078:ab0750ac5154

[gaim-migrate @ 8777] I've been staring at this convo signals stuff for too long. Can someone double check this? committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 11 Jan 2004 23:45:23 +0000
parents abee07bc573f
children 8766b6a6641b
files doc/conversation-signals.dox src/conversation.c src/protocols/oscar/ft.c
diffstat 3 files changed, 105 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/doc/conversation-signals.dox	Sun Jan 11 21:43:43 2004 +0000
+++ b/doc/conversation-signals.dox	Sun Jan 11 23:45:23 2004 +0000
@@ -28,6 +28,37 @@
   @signal chat-left
  @endsignals
 
+ @signaldef writing-im-msg
+  @signalproto
+gboolean (*writing_im_msg)(GaimAccount *account, GaimConversation *conv, char **message);
+  @endsignalproto
+  @signaldesc
+   Emitted before a message is displayed in an IM conversation or sent to a remote user.
+   @a message is a pointer to a string, so the plugin can replace the
+   message that will be displayed along with the message that will be sent. 
+   This can also be used to cancel an outgoing message by returning @c TRUE.
+  @note
+   Make sure to free @a *message before you replace it!
+  @param account The account the message is being displayed and sent on.
+  @param conv    The conversation the message is being displayed and sent on.
+  @param message A pointer to the message that will be displayed and sent.
+  @return @c TRUE if the message should be canceled, or @c FALSE otherwise.
+ @endsignaldef
+
+ @signaldef wrote-im-msg
+  @signalproto
+void (*wrote_im_msg)(GaimAccount *account, GaimConversation *conv, const char *message);
+  @endsignalproto
+  @signaldesc
+   Emitted after a message is entered by the user, but before it is sent and displyed.  
+   When sending an IM, the order that the im-msg callbacks will be called is:
+   writing-im-msg, wrote-im-msg, displaying-im-msg, displayed-im-msg, sending-im-msg, 
+   sending-im-msg, and finally sent-im-msg.
+  @param account The account the message was displayed on.
+  @param conv    The conversation the message was displayed on.
+  @param message The message that was displayed.
+ @endsignaldef
+
  @signaldef displaying-im-msg
   @signalproto
 gboolean (*displaying_im_msg)(GaimAccount *account, GaimConversation *conv, char **message);
@@ -101,6 +132,38 @@
   @param message A pointer to the message that was sent.
  @endsignaldef
 
+ @signaldef writing-chat-msg
+  @signalproto
+gboolean (*writing_chat_msg)(GaimAccount *account, GaimConversation *conv, char **message);
+  @endsignalproto
+  @signaldesc
+   Emitted before a message is displayed in a chat conversation or sent to 
+   a remote chat.  @a message is a pointer to a string, so the plugin can 
+   replace the message that will be displayed along with the message that 
+   will be sent.  This can also be used to cancel an outgoing message by 
+   returning @c TRUE.
+  @note
+   Make sure to free @a *message before you replace it!
+  @param account The account the message is being displayed and sent on.
+  @param conv    The conversation the message is being displayed and sent on.
+  @param message A pointer to the message that will be displayed and sent.
+  @return @c TRUE if the message should be canceled, or @c FALSE otherwise.
+ @endsignaldef
+
+ @signaldef wrote-im-msg
+  @signalproto
+void (*wrote_im_msg)(GaimAccount *account, GaimConversation *conv, const char *message);
+  @endsignalproto
+  @signaldesc
+   Emitted after a message is entered by the user, but before it is sent and displyed.  
+   When sending an IM, the order that the im-msg callbacks will be called is:
+   writing-im-msg, wrote-im-msg, displaying-im-msg, displayed-im-msg, sending-im-msg, 
+   sending-im-msg, and finally sent-im-msg.
+  @param account The account the message was displayed on.
+  @param conv    The conversation the message was displayed on.
+  @param message The message that was displayed.
+ @endsignaldef
+
  @signaldef displaying-chat-msg
   @signalproto
 gboolean (*displaying_chat_msg)(GaimAccount *account, GaimConversation *conv, char **message);
--- a/src/conversation.c	Sun Jan 11 21:43:43 2004 +0000
+++ b/src/conversation.c	Sun Jan 11 23:45:23 2004 +0000
@@ -243,21 +243,15 @@
 			"displaying-im-msg" : "displaying-chat-msg"),
 			gaim_conversation_get_account(conv), conv, &displayed));
 
-	if (displayed == NULL) {
-		g_free(sent);
-		return;
-	}
-
 	if (plugin_return) {
 		g_free(displayed);
-		g_free(sent);
-		return;
+		displayed = NULL;
+	} else {
+		gaim_signal_emit(gaim_conversations_get_handle(),
+			(type == GAIM_CONV_IM ? "displayed-im-msg" : "displayed-chat-msg"),
+			gaim_conversation_get_account(conv), conv, displayed);
 	}
 
-	gaim_signal_emit(gaim_conversations_get_handle(),
-		(type == GAIM_CONV_IM ? "displayed-im-msg" : "displayed-chat-msg"),
-		gaim_conversation_get_account(conv), conv, displayed);
-
 	if (type == GAIM_CONV_IM) {
 		GaimConvIm *im = GAIM_CONV_IM(conv);
 
@@ -277,7 +271,7 @@
 			err = serv_send_im(gc, gaim_conversation_get_name(conv),
 							    sent, imflags);
 
-			if (err > 0)
+			if ((err > 0) && (displayed != NULL))
 				gaim_conv_im_write(im, NULL, displayed, msgflags, time(NULL));
 
 			if (im->images != NULL) {
@@ -2583,6 +2577,24 @@
 	/**********************************************************************
 	 * Register signals
 	 **********************************************************************/
+	gaim_signal_register(handle, "writing-im-msg",
+						 gaim_marshal_BOOLEAN__POINTER_POINTER_POINTER,
+						 gaim_value_new(GAIM_TYPE_BOOLEAN), 3,
+						 gaim_value_new(GAIM_TYPE_SUBTYPE,
+										GAIM_SUBTYPE_ACCOUNT),
+						 gaim_value_new(GAIM_TYPE_SUBTYPE,
+										GAIM_SUBTYPE_CONVERSATION),
+						 gaim_value_new_outgoing(GAIM_TYPE_STRING));
+
+	gaim_signal_register(handle, "wrote-im-msg",
+						 gaim_marshal_VOID__POINTER_POINTER_POINTER,
+						 NULL, 3,
+						 gaim_value_new(GAIM_TYPE_SUBTYPE,
+										GAIM_SUBTYPE_ACCOUNT),
+						 gaim_value_new(GAIM_TYPE_SUBTYPE,
+										GAIM_SUBTYPE_CONVERSATION),
+						 gaim_value_new(GAIM_TYPE_STRING));
+
 	gaim_signal_register(handle, "displaying-im-msg",
 						 gaim_marshal_BOOLEAN__POINTER_POINTER_POINTER,
 						 gaim_value_new(GAIM_TYPE_BOOLEAN), 3,
@@ -2626,6 +2638,24 @@
 						 gaim_value_new_outgoing(GAIM_TYPE_STRING),
 						 gaim_value_new_outgoing(GAIM_TYPE_UINT));
 
+	gaim_signal_register(handle, "writing-chat-msg",
+						 gaim_marshal_BOOLEAN__POINTER_POINTER_POINTER,
+						 gaim_value_new(GAIM_TYPE_BOOLEAN), 3,
+						 gaim_value_new(GAIM_TYPE_SUBTYPE,
+										GAIM_SUBTYPE_ACCOUNT),
+						 gaim_value_new(GAIM_TYPE_SUBTYPE,
+										GAIM_SUBTYPE_CONVERSATION),
+						 gaim_value_new_outgoing(GAIM_TYPE_STRING));
+
+	gaim_signal_register(handle, "wrote-chat-msg",
+						 gaim_marshal_VOID__POINTER_POINTER_POINTER,
+						 NULL, 3,
+						 gaim_value_new(GAIM_TYPE_SUBTYPE,
+										GAIM_SUBTYPE_ACCOUNT),
+						 gaim_value_new(GAIM_TYPE_SUBTYPE,
+										GAIM_SUBTYPE_CONVERSATION),
+						 gaim_value_new(GAIM_TYPE_STRING));
+
 	gaim_signal_register(handle, "displaying-chat-msg",
 						 gaim_marshal_BOOLEAN__POINTER_POINTER_POINTER,
 						 gaim_value_new(GAIM_TYPE_BOOLEAN), 3,
--- a/src/protocols/oscar/ft.c	Sun Jan 11 21:43:43 2004 +0000
+++ b/src/protocols/oscar/ft.c	Sun Jan 11 23:45:23 2004 +0000
@@ -664,7 +664,6 @@
 			ret = userfunc(sess, &fr, snptr, 0);
 	}
 
-	/* Is the second half of this really needed?  I'm skeptical. */
 	if ((payloadlength != 0) && (payloadlength != UINT_MAX)) {
 		char *msg;
 		int recvd = 0;