From 53cde0f5fcb8ec01edd2d003587f036b58f6b2e3 Mon Sep 17 00:00:00 2001 From: Stephan Arts Date: Sun, 18 Mar 2012 15:27:55 +0100 Subject: [PATCH] Add a query mechanism to determine the preferred application [Bug #8579] --- exo-helper/main.c | 25 ++++++++++++++++++++++++- 1 files changed, 24 insertions(+), 1 deletions(-) diff --git a/exo-helper/main.c b/exo-helper/main.c index f67d8b2..2d8dbb7 100644 --- a/exo-helper/main.c +++ b/exo-helper/main.c @@ -61,6 +61,7 @@ main (int argc, char **argv) gboolean opt_version = FALSE; gboolean opt_configure = FALSE; gchar *opt_launch_type = NULL; + gchar *opt_query_type = NULL; GdkNativeWindow opt_socket_id = 0; GOptionContext *opt_ctx; @@ -70,6 +71,7 @@ main (int argc, char **argv) { "configure", 'c', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &opt_configure, N_("Open the Preferred Applications\nconfiguration dialog"), NULL, }, { "socket-id", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT, &opt_socket_id, N_("Settings manager socket"), N_("SOCKET ID"), }, { "launch", 'l', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &opt_launch_type, N_("Launch the default helper of TYPE with the optional PARAMETER, where TYPE is one of the following values."), N_("TYPE [PARAMETER]"), }, + { "query", 'q', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &opt_query_type, N_("Query the default helper of TYPE, where TYPE is one of the following values."), N_("TYPE [PARAMETER]"), }, { NULL, }, }; @@ -93,7 +95,7 @@ main (int argc, char **argv) * not accept localized TYPEs. */ g_option_context_set_description (opt_ctx, - _("The following TYPEs are supported for the --launch command:\n\n" + _("The following TYPEs are supported for the --launch and --query commands:\n\n" " WebBrowser - The preferred Web Browser.\n" " MailReader - The preferred Mail Reader.\n" " FileManager - The preferred File Manager.\n" @@ -205,6 +207,27 @@ main (int argc, char **argv) gtk_major_version, gtk_minor_version, gtk_micro_version, PACKAGE_BUGREPORT); } + else if (opt_query_type != NULL) + { + /* try to parse the type */ + if (!exo_helper_category_from_string (opt_query_type, &category)) + { + g_warning (_("Invalid helper type \"%s\""), opt_query_type); + return EXIT_FAILURE; + } + + /* determine the default helper for the category */ + database = exo_helper_database_get (); + helper = exo_helper_database_get_default (database, category); + + if (G_UNLIKELY (helper == NULL)) + { + g_printerr (_("No helper defined for \"%s\"."), opt_launch_type); + return EXIT_FAILURE; + } + + g_print ("%s\n", exo_helper_get_id (helper)); + } else { result = EXIT_FAILURE; -- 1.7.9.1