changeset 6837:f098765ac919

[gaim-migrate @ 7382] The pounces subsystem now registers signal callbacks for all the pounce types. The calls to pounce code in server.c, and therefore in all the rest of gaim, have been removed. The pounce code is now more like its own separate island. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sun, 14 Sep 2003 21:05:11 +0000
parents e2483c5f53bd
children 551a8111977a
files src/conversation.c src/core.c src/pounce.c src/pounce.h src/server.c
diffstat 5 files changed, 110 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/conversation.c	Sun Sep 14 19:54:15 2003 +0000
+++ b/src/conversation.c	Sun Sep 14 21:05:11 2003 +0000
@@ -2731,6 +2731,11 @@
 						 gaim_value_new(GAIM_TYPE_SUBTYPE,
 										GAIM_SUBTYPE_CONVERSATION));
 
+	gaim_signal_register(handle, "buddy-typing-stopped",
+						 gaim_marshal_VOID__POINTER, NULL, 1,
+						 gaim_value_new(GAIM_TYPE_SUBTYPE,
+										GAIM_SUBTYPE_CONVERSATION));
+
 	gaim_signal_register(handle, "chat-buddy-joining",
 						 gaim_marshal_VOID__POINTER_POINTER, NULL, 2,
 						 gaim_value_new(GAIM_TYPE_SUBTYPE,
--- a/src/core.c	Sun Sep 14 19:54:15 2003 +0000
+++ b/src/core.c	Sun Sep 14 21:05:11 2003 +0000
@@ -124,6 +124,7 @@
 	gaim_plugins_destroy_all();
 
 	gaim_ssl_uninit();
+	gaim_pounces_uninit();
 	gaim_blist_uninit();
 	gaim_conversations_uninit();
 	gaim_connections_uninit();
--- a/src/pounce.c	Sun Sep 14 19:54:15 2003 +0000
+++ b/src/pounce.c	Sun Sep 14 21:05:11 2003 +0000
@@ -1,10 +1,11 @@
 /**
  * @file pounce.c Buddy Pounce API
+ * @ingroup core
  *
  * gaim
  *
  * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org>
- * 
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -18,9 +19,9 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
  */
 #include "internal.h"
+#include "conversation.h"
 #include "debug.h"
 #include "pounce.h"
 
@@ -929,9 +930,74 @@
 	g_free(handler);
 }
 
+static void
+buddy_state_cb(GaimBuddy *buddy, GaimPounceEvent event)
+{
+	gaim_pounce_execute(buddy->account, buddy->name, event);
+}
+
+static void
+buddy_typing_cb(GaimConversation *conv, void *data)
+{
+	GaimAccount *account = gaim_conversation_get_account(conv);
+	const char *name     = gaim_conversation_get_name(conv);
+
+	if (gaim_find_buddy(account, name) != NULL)
+	{
+		GaimPounceEvent event;
+
+		event = (gaim_im_get_typing_state(GAIM_IM(conv)) == GAIM_TYPING
+				 ? GAIM_POUNCE_TYPING : GAIM_POUNCE_TYPING_STOPPED);
+
+		gaim_pounce_execute(account, name, event);
+	}
+}
+
+void *
+gaim_pounces_get_handle(void)
+{
+	static int pounce_handle;
+
+	return &pounce_handle;
+}
+
 void
 gaim_pounces_init(void)
 {
+	void *blist_handle = gaim_blist_get_handle();
+	void *conv_handle  = gaim_conversations_get_handle();
+	void *handle       = gaim_pounces_get_handle();
+
 	pounce_handlers = g_hash_table_new_full(g_str_hash, g_str_equal,
 											g_free, free_pounce_handler);
+
+	gaim_signal_connect(blist_handle, "buddy-idle",
+						handle, GAIM_CALLBACK(buddy_state_cb),
+						GINT_TO_POINTER(GAIM_POUNCE_IDLE));
+	gaim_signal_connect(blist_handle, "buddy-unidle",
+						handle, GAIM_CALLBACK(buddy_state_cb),
+						GINT_TO_POINTER(GAIM_POUNCE_IDLE));
+	gaim_signal_connect(blist_handle, "buddy-away",
+						handle, GAIM_CALLBACK(buddy_state_cb),
+						GINT_TO_POINTER(GAIM_POUNCE_AWAY));
+	gaim_signal_connect(blist_handle, "buddy-back",
+						handle, GAIM_CALLBACK(buddy_state_cb),
+						GINT_TO_POINTER(GAIM_POUNCE_AWAY_RETURN));
+	gaim_signal_connect(blist_handle, "buddy-signed-on",
+						handle, GAIM_CALLBACK(buddy_state_cb),
+						GINT_TO_POINTER(GAIM_POUNCE_SIGNON));
+	gaim_signal_connect(blist_handle, "buddy-signed-off",
+						handle, GAIM_CALLBACK(buddy_state_cb),
+						GINT_TO_POINTER(GAIM_POUNCE_SIGNOFF));
+
+	gaim_signal_connect(conv_handle, "buddy-typing",
+						handle, GAIM_CALLBACK(buddy_typing_cb), NULL);
+	gaim_signal_connect(conv_handle, "buddy-typing-stopped",
+						handle, GAIM_CALLBACK(buddy_typing_cb), NULL);
 }
+
+void
+gaim_pounces_uninit()
+{
+	gaim_signals_disconnect_by_handle(gaim_pounces_get_handle());
+}
--- a/src/pounce.h	Sun Sep 14 19:54:15 2003 +0000
+++ b/src/pounce.h	Sun Sep 14 21:05:11 2003 +0000
@@ -5,7 +5,7 @@
  * gaim
  *
  * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org>
- * 
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -255,7 +255,7 @@
 /*@}*/
 
 /**************************************************************************/
-/** @name Buddy Pounces API                                               */
+/** @name Buddy Pounce Subsystem API                                      */
 /**************************************************************************/
 /*@{*/
 
@@ -273,11 +273,6 @@
 
 
 /**
- * Initializes the pounces subsystem.
- */
-void gaim_pounces_init(void);
-
-/**
  * Loads the pounces.
  *
  * @return @c TRUE if the pounces could be loaded.
@@ -315,6 +310,23 @@
  */
 GList *gaim_pounces_get_all(void);
 
+/**
+ * Returns the buddy pounce subsystem handle.
+ *
+ * @return The subsystem handle.
+ */
+void *gaim_pounces_get_handle(void);
+
+/**
+ * Initializes the pounces subsystem.
+ */
+void gaim_pounces_init(void);
+
+/**
+ * Uninitializes the pounces subsystem.
+ */
+void gaim_pounces_uninit(void);
+
 /*@}*/
 
 #ifdef __cplusplus
--- a/src/server.c	Sun Sep 14 19:54:15 2003 +0000
+++ b/src/server.c	Sun Sep 14 21:05:11 2003 +0000
@@ -24,7 +24,6 @@
 #include "log.h"
 #include "multi.h"
 #include "notify.h"
-#include "pounce.h"
 #include "prefs.h"
 #include "prpl.h"
 #include "request.h"
@@ -1117,11 +1116,9 @@
 	}
 
 	if (!b->idle && idle) {
-		gaim_pounce_execute(gc->account, b->name, GAIM_POUNCE_IDLE);
 		gaim_signal_emit(gaim_blist_get_handle(), "buddy-idle", b);
 		system_log(log_idle, gc, b, OPT_LOG_BUDDY_IDLE);
 	} else if (b->idle && !idle) {
-		gaim_pounce_execute(gc->account, b->name, GAIM_POUNCE_IDLE_RETURN);
 		gaim_signal_emit(gaim_blist_get_handle(), "buddy-unidle", b);
 		system_log(log_unidle, gc, b, OPT_LOG_BUDDY_IDLE);
 	}
@@ -1129,13 +1126,10 @@
 	gaim_blist_update_buddy_idle(b, idle);
 	gaim_blist_update_buddy_evil(b, evil);
 
-	if ((b->uc & UC_UNAVAILABLE) && !(type & UC_UNAVAILABLE)) {
-		gaim_pounce_execute(gc->account, b->name, GAIM_POUNCE_AWAY_RETURN);
+	if ((b->uc & UC_UNAVAILABLE) && !(type & UC_UNAVAILABLE))
 		system_log(log_back, gc, b, OPT_LOG_BUDDY_AWAY);
-	} else if (!(b->uc & UC_UNAVAILABLE) && (type & UC_UNAVAILABLE)) {
-		gaim_pounce_execute(gc->account, b->name, GAIM_POUNCE_AWAY);
+	else if (!(b->uc & UC_UNAVAILABLE) && (type & UC_UNAVAILABLE))
 		system_log(log_away, gc, b, OPT_LOG_BUDDY_AWAY);
-	}
 
 	gaim_blist_update_buddy_status(b, type);
 
@@ -1164,7 +1158,6 @@
 				}
 			}
 			gaim_sound_play_event(GAIM_SOUND_BUDDY_ARRIVE);
-			gaim_pounce_execute(gc->account, b->name, GAIM_POUNCE_SIGNON);
 			system_log(log_signon, gc, b, OPT_LOG_BUDDY_SIGNON);
 		}
 	} else {
@@ -1192,7 +1185,6 @@
 			}
 			serv_got_typing_stopped(gc, name); /* obviously not typing */
 			gaim_sound_play_event(GAIM_SOUND_BUDDY_LEAVE);
-			gaim_pounce_execute(gc->account, b->name, GAIM_POUNCE_SIGNOFF);
 			system_log(log_signoff, gc, b, OPT_LOG_BUDDY_SIGNON);
 		}
 	}
@@ -1256,13 +1248,18 @@
 
 	b = gaim_find_buddy(gc->account, name);
 
-	gaim_signal_emit(gaim_conversations_get_handle(), "buddy-typing", cnv);
-
-	if (b != NULL) {
+	if (b != NULL)
+	{
 		if (state == GAIM_TYPING)
-			gaim_pounce_execute(gc->account, name, GAIM_POUNCE_TYPING);
+		{
+			gaim_signal_emit(gaim_conversations_get_handle(),
+							 "buddy-typing", cnv);
+		}
 		else
-			gaim_pounce_execute(gc->account, name, GAIM_POUNCE_TYPING_STOPPED);
+		{
+			gaim_signal_emit(gaim_conversations_get_handle(),
+							 "buddy-typing-stopped", cnv);
+		}
 	}
 
 	if (timeout > 0)
@@ -1290,7 +1287,10 @@
 	b = gaim_find_buddy(gc->account, name);
 
 	if (b != NULL)
-		gaim_pounce_execute(gc->account, name, GAIM_POUNCE_TYPING_STOPPED);
+	{
+		gaim_signal_emit(gaim_conversations_get_handle(),
+						 "buddy-typing-stopped", c);
+	}
 }
 
 struct chat_invite_data {
@@ -1371,7 +1371,7 @@
 		g_snprintf(filename, 100, "%s.chat", gaim_conversation_get_name(conv));
 
 		fd = open_log_file(filename, TRUE);
-		
+
 		if (fd) {
 			if (!gaim_prefs_get_bool("/gaim/gtk/logging/strip_html"))
 				fprintf(fd,