/pidgin/main: caf372ae8882: Fix up the commands execute stuff

Gary Kramlich <[email protected]> Sat, 20 Aug 2016 14:36:48 -0400
Newsgroups gmane.comp.gnome.gaim.cvs
Message-ID <[email protected]>
Changeset: caf372ae8882d06ad425702f2e6c5dc3d30bbdf9
Author:	 Gary Kramlich <[email protected]>
Date:	 2016-08-19 23:38 -0500
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/caf372ae8882

Description:

Fix up the commands execute stuff

diffstat:

 libpurple/cmds.c |  38 ++++++++++++++++++++++++++------------
 libpurple/cmds.h |  21 +++++++++++++++++++--
 2 files changed, 45 insertions(+), 14 deletions(-)

diffs (139 lines):

diff --git a/libpurple/cmds.c b/libpurple/cmds.c
--- a/libpurple/cmds.c
+++ b/libpurple/cmds.c
@@ -26,7 +26,7 @@ static PurpleCommandsUiOps *cmds_ui_ops 
 static GList *cmds = NULL;
 static guint next_id = 1;
 
-struct _PurpleCmd {
+typedef struct _PurpleCmd {
 	PurpleCmdId id;
 	gchar *cmd;
 	gchar *args;
@@ -36,7 +36,7 @@ struct _PurpleCmd {
 	PurpleCmdFunc func;
 	gchar *help;
 	void *data;
-};
+} PurpleCmd;
 
 
 static gint cmds_compare_func(const PurpleCmd *a, const PurpleCmd *b)
@@ -78,7 +78,7 @@ PurpleCmdId purple_cmd_register(const gc
 
 	ops = purple_cmds_get_ui_ops();
 	if (ops && ops->register_command)
-		ops->register_command(cmd, p, f, prpl_id, helpstr, c);
+		ops->register_command(cmd, p, f, protocol_id, helpstr, c->id);
 
 	purple_signal_emit(purple_cmds_get_handle(), "cmd-added", cmd, p, f);
 
@@ -105,7 +105,7 @@ void purple_cmd_unregister(PurpleCmdId i
 		if (c->id == id) {
 			PurpleCommandsUiOps *ops = purple_cmds_get_ui_ops();
 			if (ops && ops->unregister_command)
-				ops->unregister_command(c->cmd, c->prpl_id);
+				ops->unregister_command(c->cmd, c->protocol_id);
 
 			cmds = g_list_remove(cmds, c);
 			purple_signal_emit(purple_cmds_get_handle(), "cmd-removed", c->cmd);
@@ -302,19 +302,33 @@ PurpleCmdStatus purple_cmd_do_command(Pu
 
 }
 
-gboolean purple_cmd_execute(PurpleCmd *c, PurpleConversation *conv,
+gboolean purple_cmd_execute(PurpleCmdId id, PurpleConversation *conv,
 			    const gchar *cmdline)
 {
+	PurpleCmd *cmd = NULL;
+	PurpleCmdRet ret = PURPLE_CMD_RET_CONTINUE;
+	GList *l = NULL;
 	gchar *err = NULL;
 	gchar **args = NULL;
-	PurpleCmdRet ret = PURPLE_CMD_RET_CONTINUE;
 
-	if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) {
-		if (!(c->flags & PURPLE_CMD_FLAG_IM))
+	for(l = cmds; l; l = l->next) {
+		cmd = (PurpleCmd*)l->data;
+
+		if(cmd->id == id) {
+			break;
+		}
+		cmd = NULL;
+	}
+	if(cmd == NULL) {
+		return FALSE;
+	}
+
+	if (PURPLE_IS_IM_CONVERSATION(conv)) {
+		if (!(cmd->flags & PURPLE_CMD_FLAG_IM))
 			return FALSE;
 	}
-	else if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT) {
-		if (!(c->flags & PURPLE_CMD_FLAG_CHAT))
+	else if (PURPLE_IS_CHAT_CONVERSATION(conv)) {
+		if (!(cmd->flags & PURPLE_CMD_FLAG_CHAT))
 			return FALSE;
 	}
 	else
@@ -323,12 +337,12 @@ gboolean purple_cmd_execute(PurpleCmd *c
 	/* XXX: Don't worry much about the markup version of the command
 	   line, there's not a single use case... */
 	/* this checks the allow bad args flag for us */
-	if (!purple_cmd_parse_args(c, cmdline, cmdline, &args)) {
+	if (!purple_cmd_parse_args(cmd, cmdline, cmdline, &args)) {
 		g_strfreev(args);
 		return FALSE;
 	}
 
-	ret = c->func(conv, c->cmd, args, &err, c->data);
+	ret = cmd->func(conv, cmd->cmd, args, &err, cmd->data);
 
 	g_free(err);
 	g_strfreev(args);
diff --git a/libpurple/cmds.h b/libpurple/cmds.h
--- a/libpurple/cmds.h
+++ b/libpurple/cmds.h
@@ -131,7 +131,7 @@ typedef struct
 	/* @see purple_cmd_register for the argument values. */
 	void (*register_command)(const gchar *name, PurpleCmdPriority priority,
 				 PurpleCmdFlag flags, const gchar *prpl_id,
-				 const gchar *help, PurpleCmd *cmd);
+				 const gchar *help, PurpleCmdId id);
 
 	/** Should be implemented if register_command is implemented.
 	 *  name and prpl_id will have the same value that were used
@@ -259,7 +259,7 @@ PurpleCmdStatus purple_cmd_do_command(Pu
  *            in plain text (no HTML entities).
  * @return TRUE if the command handled the @a cmdline, FALSE otherwise.
  */
-gboolean purple_cmd_execute(PurpleCmd *c, PurpleConversation *conv,
+gboolean purple_cmd_execute(PurpleCmdId id, PurpleConversation *conv,
 			    const gchar *cmdline);
 
 /**
@@ -305,6 +305,23 @@ GList *purple_cmd_help(PurpleConversatio
 gpointer purple_cmds_get_handle(void);
 
 /**
+ * Sets the UI operations structure to be used when registering and
+ * unregistering commands.  The UI operations need only be set if the
+ * UI wants to handle the commands itself; otherwise, leave it as NULL.
+ *
+ * @param ops The UI operations structure.
+ */
+void purple_cmds_set_ui_ops(PurpleCommandsUiOps *ops);
+
+/**
+ * Returns the UI operations structure to be used when registering and
+ * unregistering commands.
+ *
+ * @return The UI operations structure.
+ */
+PurpleCommandsUiOps *purple_cmds_get_ui_ops(void);
+
+/**
  * purple_cmds_init:
  *
  * Initialize the commands subsystem.

_______________________________________________
Commits mailing list
[email protected]
https://pidgin.im/cgi-bin/mailman/listinfo/commits