Merged in default (pull request #432)

Wed, 28 Nov 2018 04:42:47 +0000

author
Gary Kramlich <grim@reaperworld.com>
date
Wed, 28 Nov 2018 04:42:47 +0000
changeset 39329
39de37ec6c64
parent 39327
47553363eabd (current diff)
parent 39328
4a49d2904542 (diff)
child 39331
845d3ef390be

Merged in default (pull request #432)

gg: Implement URI handler

Approved-by: Gary Kramlich
Approved-by: Eion Robb

--- a/libpurple/protocols/gg/gg.c	Wed Nov 28 03:16:35 2018 +0000
+++ b/libpurple/protocols/gg/gg.c	Wed Nov 28 04:42:47 2018 +0000
@@ -33,6 +33,7 @@
 #include "notify.h"
 #include "buddylist.h"
 #include "accountopt.h"
+#include "core.h"
 #include "debug.h"
 #include "util.h"
 #include "request.h"
@@ -591,6 +592,56 @@
 	gg_free_event(ev);
 }
 
+static gint
+gg_uri_handler_find_account(gconstpointer a, gconstpointer b)
+{
+	PurpleAccount *account = PURPLE_ACCOUNT(a);
+	const gchar *protocol_id;
+
+	protocol_id = purple_account_get_protocol_id(account);
+
+	if (purple_strequal(protocol_id, "prpl-gg") &&
+			purple_account_is_connected(account)) {
+		return 0;
+	} else {
+		return -1;
+	}
+}
+
+static gboolean
+gg_uri_handler(const gchar *scheme, const gchar *screenname,
+		GHashTable *params)
+{
+	GList *accounts;
+	GList *account_node;
+	PurpleIMConversation *im;
+
+	g_return_val_if_fail(screenname != NULL, FALSE);
+
+	if (!purple_strequal(scheme, "gg")) {
+		return FALSE;
+	}
+
+	if (screenname[0] == '\0') {
+		purple_debug_warning("gg", "Invalid empty screenname in URI");
+		return FALSE;
+	}
+
+	/* Find online Gadu-Gadu account */
+	accounts = purple_accounts_get_all();
+	account_node = g_list_find_custom(accounts, NULL,
+			gg_uri_handler_find_account);
+
+	if (account_node == NULL) {
+		return FALSE;
+	}
+
+	im = purple_im_conversation_new(account_node->data, screenname);
+	purple_conversation_present(PURPLE_CONVERSATION(im));
+
+	return TRUE;
+}
+
 /* ---------------------------------------------------------------------- */
 /* ----- PurpleProtocol ----------------------------------------- */
 /* ---------------------------------------------------------------------- */
@@ -1154,12 +1205,18 @@
 	ggp_html_setup();
 	ggp_message_setup_global();
 
+	purple_signal_connect(purple_get_core(), "uri-handler", plugin,
+			PURPLE_CALLBACK(gg_uri_handler), NULL);
+
 	return TRUE;
 }
 
 static gboolean
 plugin_unload(PurplePlugin *plugin, GError **error)
 {
+	purple_signal_disconnect(purple_get_core(), "uri-handler", plugin,
+			PURPLE_CALLBACK(gg_uri_handler));
+
 	ggp_servconn_cleanup();
 	ggp_html_cleanup();
 	ggp_message_cleanup_global();

mercurial