changeset 23412:b5f679e95666

cmd-added and cmd-removed signals to emit when commands are registered/unregistered.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 02 Jul 2008 23:50:59 +0000
parents 3c2963654752
children a2c625152c52
files ChangeLog.API libpurple/cmds.c libpurple/cmds.h libpurple/core.c
diffstat 4 files changed, 53 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Wed Jul 02 16:54:03 2008 +0000
+++ b/ChangeLog.API	Wed Jul 02 23:50:59 2008 +0000
@@ -18,6 +18,8 @@
 		* purple_notify_user_info_prepend_section_break
 		* purple_notify_user_info_prepend_section_header
 		* "website" and "dev_website" items to the ui_info hash table
+		* purple_cmds_get_handle, purple_cmds_init, purple_cmds_uninit
+		* cmd-added and cmd-removed signals
 
 		Deprecated:
 		* purple_blist_update_buddy_icon
--- a/libpurple/cmds.c	Wed Jul 02 16:54:03 2008 +0000
+++ b/libpurple/cmds.c	Wed Jul 02 23:50:59 2008 +0000
@@ -81,6 +81,8 @@
 
 	cmds = g_list_insert_sorted(cmds, c, (GCompareFunc)cmds_compare_func);
 
+	purple_signal_emit(purple_cmds_get_handle(), "cmd-added", cmd, p, f);
+
 	return id;
 }
 
@@ -103,6 +105,7 @@
 
 		if (c->id == id) {
 			cmds = g_list_remove(cmds, c);
+			purple_signal_emit(purple_cmds_get_handle(), "cmd-removed", c->cmd);
 			purple_cmd_free(c);
 			return;
 		}
@@ -361,3 +364,28 @@
 	return ret;
 }
 
+gpointer purple_cmds_get_handle(void)
+{
+	static int handle;
+	return &handle;
+}
+
+void purple_cmds_init(void)
+{
+	gpointer handle = purple_cmds_get_handle();
+
+	purple_signal_register(handle, "cmd-added",
+			purple_marshal_VOID__POINTER_INT_INT, NULL, 3,
+			purple_value_new(PURPLE_TYPE_STRING),
+			purple_value_new(PURPLE_TYPE_INT),
+			purple_value_new(PURPLE_TYPE_INT));
+	purple_signal_register(handle, "cmd-removed",
+			purple_marshal_VOID__POINTER, NULL, 1,
+			purple_value_new(PURPLE_TYPE_STRING));
+}
+
+void purple_cmds_uninit(void)
+{
+	purple_signals_unregister_by_instance(purple_cmds_get_handle());
+}
+
--- a/libpurple/cmds.h	Wed Jul 02 16:54:03 2008 +0000
+++ b/libpurple/cmds.h	Wed Jul 02 23:50:59 2008 +0000
@@ -1,6 +1,7 @@
 /**
  * @file cmds.h Commands API
  * @ingroup core
+ * @see @ref cmd-signals
  */
 
 /* Copyright (C) 2003 Timothy Ringenbach <omarvo@hotmail.com>
@@ -221,6 +222,25 @@
  */
 GList *purple_cmd_help(PurpleConversation *conv, const gchar *cmd);
 
+/**
+ * Get the handle for the commands API
+ * @return The handle
+ * @since 2.5.0
+ */
+gpointer purple_cmds_get_handle(void);
+
+/**
+ * Initialize the commands subsystem.
+ * @since 2.5.0
+ */
+void purple_cmds_init(void);
+
+/**
+ * Uninitialize the commands subsystem.
+ * @since 2.5.0
+ */
+void purple_cmds_uninit(void);
+
 /*@}*/
 
 #ifdef __cplusplus
--- a/libpurple/core.c	Wed Jul 02 16:54:03 2008 +0000
+++ b/libpurple/core.c	Wed Jul 02 23:50:59 2008 +0000
@@ -26,6 +26,7 @@
 #include "internal.h"
 #include "cipher.h"
 #include "certificate.h"
+#include "cmds.h"
 #include "connection.h"
 #include "conversation.h"
 #include "core.h"
@@ -169,6 +170,7 @@
 	purple_xfers_init();
 	purple_idle_init();
 	purple_smileys_init();
+	purple_cmds_init();
 
 	/*
 	 * Call this early on to try to auto-detect our IP address and
@@ -197,6 +199,7 @@
 	purple_connections_disconnect_all();
 
 	/* Save .xml files, remove signals, etc. */
+	purple_cmds_uninit();
 	purple_smileys_uninit();
 	purple_idle_uninit();
 	purple_ssl_uninit();