libpidgin: Handle command line URIs using GApplication

Fri, 02 Nov 2018 19:17:24 -0500

author
Mike Ruprecht <cmaiku@gmail.com>
date
Fri, 02 Nov 2018 19:17:24 -0500
changeset 39321
e4ba787be39c
parent 39302
64aabebb476b
child 39322
0d0d1ab4eba6

libpidgin: Handle command line URIs using GApplication

This patch adds support for handling URIs from GApplication's command
line via purple_got_protocol_handler_uri(). This affects non-Windows
versions as the Windows version uses its own method and stock
GApplication uses DBus to handle command line arguments from
subsequent calls of an application.

Unfortunately, purple_got_protocol_handler_uri() doesn't indicate
whether URI was successfully handled. That can be an improvement for
another patch. Also, there aren't many URI handler implementations
as of yet. Those are to be added in separate patches.

pidgin/libpidgin.c file | annotate | diff | comparison | revisions
--- a/pidgin/libpidgin.c	Thu Nov 15 14:32:09 2018 -0600
+++ b/pidgin/libpidgin.c	Fri Nov 02 19:17:24 2018 -0500
@@ -369,6 +369,26 @@
 	purple_blist_set_visible(TRUE);
 }
 
+static gint
+pidgin_command_line_cb(GApplication *application,
+		GApplicationCommandLine *cmdline, gpointer user_data)
+{
+	gchar **argv;
+	int argc;
+	int i;
+
+	argv = g_application_command_line_get_arguments(cmdline, &argc);
+
+	/* Start at 1 to skip the executable name */
+	for (i = 1; i < argc; ++i) {
+		purple_got_protocol_handler_uri(argv[i]);
+	}
+
+	g_strfreev(argv);
+
+	return 0;
+}
+
 static gchar *opt_config_dir_arg = NULL;
 static gboolean opt_nologin = FALSE;
 static gboolean opt_login = FALSE;
@@ -703,11 +723,9 @@
 
 	app = G_APPLICATION(gtk_application_new("im.pidgin.Pidgin",
 #if GLIB_CHECK_VERSION(2, 48, 0)
-				G_APPLICATION_CAN_OVERRIDE_APP_ID
-#else
-				G_APPLICATION_FLAGS_NONE
+				G_APPLICATION_CAN_OVERRIDE_APP_ID |
 #endif
-				));
+				G_APPLICATION_HANDLES_COMMAND_LINE));
 
 	summary = g_strdup_printf("%s %s", PIDGIN_NAME, DISPLAY_VERSION);
 	g_application_set_option_context_summary(app, summary);
@@ -727,6 +745,8 @@
 			G_CALLBACK(pidgin_startup_cb), NULL);
 	g_signal_connect(app, "activate",
 			G_CALLBACK(pidgin_activate_cb), NULL);
+	g_signal_connect(app, "command-line",
+			G_CALLBACK(pidgin_command_line_cb), NULL);
 
 	ret = g_application_run(app, argc, argv);
 

mercurial