protocols/demo/purpledemocommands.c

changeset 43066
850400fb36c0
child 43100
e6df74d36862
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/protocols/demo/purpledemocommands.c	Fri Nov 15 02:23:29 2024 -0600
@@ -0,0 +1,81 @@
+/*
+ * Purple - Internet Messaging Library
+ * Copyright (C) Pidgin Developers <devel@pidgin.im>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n-lib.h>
+
+#include "purpledemocommands.h"
+
+#define PURPLE_DEMO_COMMAND_SOURCE N_("Demo Protocol")
+
+/******************************************************************************
+ * Command Implementations
+ *****************************************************************************/
+static void
+purple_demo_command_edited_executed(G_GNUC_UNUSED PurpleCommand *command,
+                                    PurpleConversation *conversation,
+                                    GStrv params,
+                                    G_GNUC_UNUSED gpointer data)
+{
+	PurpleAccount *account = NULL;
+	PurpleContactInfo *info = NULL;
+	PurpleMessage *message = NULL;
+	char *contents = NULL;
+
+	account = purple_conversation_get_account(conversation);
+	info = purple_account_get_contact_info(account);
+
+	contents = g_strjoinv(" ", params);
+
+	message = purple_message_new(info, contents);
+	purple_message_set_edited(message, TRUE);
+
+	g_clear_pointer(&contents, g_free);
+
+	purple_conversation_send_message_async(conversation, message, NULL, NULL,
+	                                       NULL);
+	g_clear_object(&message);
+}
+
+/******************************************************************************
+ * Public API
+ *****************************************************************************/
+void
+purple_demo_commands_add(void) {
+	PurpleCommand *command = NULL;
+	PurpleCommandManager *manager = NULL;
+	PurpleTags *tags = NULL;
+
+	manager = purple_command_manager_get_default();
+
+	command = purple_command_new("edited", PURPLE_DEMO_COMMAND_SOURCE, 1000);
+	purple_command_set_summary(command,
+	                           N_("Sends the contents as an edited message"));
+	g_signal_connect(command, "executed",
+	                 G_CALLBACK(purple_demo_command_edited_executed), NULL);
+	tags = purple_command_get_tags(command);
+	purple_tags_add(tags, "protocol-id:prpl-demo");
+	purple_command_manager_add(manager, command);
+}
+
+void
+purple_demo_commands_remove(void) {
+	PurpleCommandManager *manager = purple_command_manager_get_default();
+
+	purple_command_manager_remove_all_with_source(manager,
+	                                              PURPLE_DEMO_COMMAND_SOURCE);
+}
\ No newline at end of file

mercurial