[gnome-settings-daemon] media-keys: Clean up app launching



commit b7e7c90c3c9acc2fd78492fe5a39411dec3ae133
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Sep 13 15:40:58 2011 +0100

    media-keys: Clean up app launching
    
    To use spinny spinny spinners, and the likes.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=141379

 configure.ac                                |    6 ++
 plugins/media-keys/Makefile.am              |    4 +
 plugins/media-keys/gsd-media-keys-manager.c |  126 ++++++++++++--------------
 3 files changed, 68 insertions(+), 68 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8cac11d..1128b3c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -207,6 +207,12 @@ dnl ---------------------------------------------------------------------------
 PKG_CHECK_MODULES(GIOUNIX, [gio-unix-2.0])
 
 dnl ---------------------------------------------------------------------------
+dnl - media-keys plugin stuff
+dnl ---------------------------------------------------------------------------
+
+PKG_CHECK_MODULES(MEDIA_KEYS, [gio-unix-2.0])
+
+dnl ---------------------------------------------------------------------------
 dnl - GConf<->GSettings bridge
 dnl ---------------------------------------------------------------------------
 
diff --git a/plugins/media-keys/Makefile.am b/plugins/media-keys/Makefile.am
index ad286da..546db35 100644
--- a/plugins/media-keys/Makefile.am
+++ b/plugins/media-keys/Makefile.am
@@ -95,6 +95,7 @@ libmedia_keys_la_CFLAGS = \
 	$(PLUGIN_CFLAGS)		\
 	$(SETTINGS_PLUGIN_CFLAGS)	\
 	$(UPOWER_CFLAGS)		\
+	$(MEDIA_KEYS_CFLAGS)		\
 	$(AM_CFLAGS)
 
 libmedia_keys_la_LDFLAGS = 		\
@@ -104,6 +105,7 @@ libmedia_keys_la_LIBADD  = 		\
 	$(top_builddir)/plugins/common/libcommon.la			\
 	$(top_builddir)/plugins/media-keys/cut-n-paste/libgvc.la	\
 	$(UPOWER_LIBS)							\
+	$(MEDIA_KEYS_LIBS)						\
 	$(SETTINGS_PLUGIN_LIBS)						\
 	-lm
 
@@ -173,6 +175,7 @@ test_media_keys_CPPFLAGS = \
 
 test_media_keys_CFLAGS = \
 	$(SETTINGS_PLUGIN_CFLAGS)	\
+	$(MEDIA_KEYS_CFLAGS)		\
 	$(AM_CFLAGS)
 
 test_media_keys_LDADD = \
@@ -180,6 +183,7 @@ test_media_keys_LDADD = \
 	$(top_builddir)/plugins/common/libcommon.la			\
 	$(SETTINGS_DAEMON_LIBS)			\
 	$(SETTINGS_PLUGIN_LIBS)			\
+	$(MEDIA_KEYS_LIBS)			\
 	$(UPOWER_LIBS)				\
 	$(GST_LIBS)				\
 	-lm
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index 391e116..4a83b75 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -37,6 +37,7 @@
 #include <gdk/gdk.h>
 #include <gdk/gdkx.h>
 #include <gtk/gtk.h>
+#include <gio/gdesktopappinfo.h>
 
 #include "gnome-settings-profile.h"
 #include "gsd-marshal.h"
@@ -469,41 +470,53 @@ dialog_show (GsdMediaKeysManager *manager)
 }
 
 static void
+launch_app (GAppInfo *app_info,
+	    gint64    timestamp)
+{
+	GError *error = NULL;
+        GdkAppLaunchContext *launch_context;
+
+        /* setup the launch context so the startup notification is correct */
+        launch_context = gdk_display_get_app_launch_context (gdk_display_get_default ());
+        gdk_app_launch_context_set_timestamp (launch_context, timestamp);
+
+	if (!g_app_info_launch (app_info, NULL, G_APP_LAUNCH_CONTEXT (launch_context), &error)) {
+		g_warning ("Could not launch '%s': %s",
+			   g_app_info_get_commandline (app_info),
+			   error->message);
+		g_error_free (error);
+	}
+        g_object_unref (launch_context);
+}
+
+static void
 do_url_action (GsdMediaKeysManager *manager,
-               const char          *scheme)
+               const char          *scheme,
+               gint64               timestamp)
 {
         GAppInfo *app_info;
 
         app_info = g_app_info_get_default_for_uri_scheme (scheme);
         if (app_info != NULL) {
-                GError *error = NULL;
-
-                if (!g_app_info_launch (app_info, NULL, NULL, &error)) {
-                        g_warning ("Could not launch '%s': %s",
-                                   g_app_info_get_commandline (app_info),
-                                   error->message);
-                        g_error_free (error);
-                }
+                launch_app (app_info, timestamp);
+                g_object_unref (app_info);
         } else {
                 g_warning ("Could not find default application for '%s' scheme", scheme);
-        }
+	}
 }
 
 static void
-do_media_action (GsdMediaKeysManager *manager)
+do_media_action (GsdMediaKeysManager *manager,
+		 gint64               timestamp)
 {
         GAppInfo *app_info;
 
         app_info = g_app_info_get_default_for_type ("audio/x-vorbis+ogg", FALSE);
         if (app_info != NULL) {
-                GError *error = NULL;
-
-                if (!g_app_info_launch (app_info, NULL, NULL, &error)) {
-                        g_warning ("Could not launch '%s': %s",
-                                   g_app_info_get_commandline (app_info),
-                                   error->message);
-                        g_error_free (error);
-                }
+                launch_app (app_info, timestamp);
+                g_object_unref (app_info);
+        } else {
+                g_warning ("Could not find default application for '%s' mime-type", "audio/x-vorbis+ogg");
         }
 }
 
@@ -604,6 +617,22 @@ do_home_key_action (GsdMediaKeysManager *manager,
 }
 
 static void
+do_execute_desktop (GsdMediaKeysManager *manager,
+		    const char          *desktop,
+		    gint64               timestamp)
+{
+        GDesktopAppInfo *app_info;
+
+        app_info = g_desktop_app_info_new (desktop);
+        if (app_info != NULL) {
+                launch_app (G_APP_INFO (app_info), timestamp);
+                g_object_unref (app_info);
+        } else {
+                g_warning ("Could not find application '%s'", desktop);
+	}
+}
+
+static void
 do_touchpad_osd_action (GsdMediaKeysManager *manager, gboolean state)
 {
         dialog_init (manager);
@@ -1377,44 +1406,6 @@ do_keyboard_brightness_action (GsdMediaKeysManager *manager,
                            manager);
 }
 
-static void
-exec_battery_info (GsdMediaKeysManager *manager)
-{
-        gboolean ret;
-        GError *error = NULL;
-        GAppInfo *app_info;
-        GdkAppLaunchContext *launch_context;
-
-        /* setup the launch context so the startup notification is correct */
-        launch_context = gdk_display_get_app_launch_context (gdk_display_get_default ());
-        app_info = g_app_info_create_from_commandline (BINDIR "/gnome-power-statistics",
-                                                       "gnome-power-statistics",
-                                                       G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION,
-                                                       &error);
-        if (app_info == NULL) {
-                g_warning ("failed to create application info: %s",
-                           error->message);
-                g_error_free (error);
-                goto out;
-        }
-
-        /* launch gnome-control-center */
-        ret = g_app_info_launch (app_info,
-                                 NULL,
-                                 G_APP_LAUNCH_CONTEXT (launch_context),
-                                 &error);
-        if (!ret) {
-                g_warning ("failed to launch gnome-power-statistics: %s",
-                           error->message);
-                g_error_free (error);
-                goto out;
-        }
-out:
-        g_object_unref (launch_context);
-        if (app_info != NULL)
-                g_object_unref (app_info);
-}
-
 static gboolean
 do_action (GsdMediaKeysManager *manager,
            MediaKeyType         type,
@@ -1467,15 +1458,14 @@ do_action (GsdMediaKeysManager *manager,
                 break;
         case SEARCH_KEY:
                 cmd = NULL;
-                if ((cmd = g_find_program_in_path ("tracker-search-tool"))) {
-                        execute (manager, "tracker-search-tool", FALSE, FALSE);
-                } else {
-                        execute (manager, "gnome-search-tool", FALSE, FALSE);
-                }
+                if ((cmd = g_find_program_in_path ("tracker-search-tool")))
+                        do_execute_desktop (manager, "tracker-needle.desktop", timestamp);
+                else
+                        do_execute_desktop (manager, "gnome-search-tool.desktop", timestamp);
                 g_free (cmd);
                 break;
         case EMAIL_KEY:
-                do_url_action (manager, "mailto");
+                do_url_action (manager, "mailto", timestamp);
                 break;
         case SCREENSAVER_KEY:
         case SCREENSAVER2_KEY:
@@ -1488,16 +1478,16 @@ do_action (GsdMediaKeysManager *manager,
                 g_free (cmd);
                 break;
         case HELP_KEY:
-                do_url_action (manager, "ghelp");
+                do_url_action (manager, "ghelp", timestamp);
                 break;
         case WWW_KEY:
-                do_url_action (manager, "http");
+                do_url_action (manager, "http", timestamp);
                 break;
         case MEDIA_KEY:
-                do_media_action (manager);
+                do_media_action (manager, timestamp);
                 break;
         case CALCULATOR_KEY:
-                execute (manager, "gcalctool", FALSE, FALSE);
+                do_execute_desktop (manager, "gcalctool.desktop", timestamp);
                 break;
         case PLAY_KEY:
                 return do_multimedia_player_action (manager, "Play");
@@ -1566,7 +1556,7 @@ do_action (GsdMediaKeysManager *manager,
                 do_keyboard_brightness_action (manager, type);
                 break;
         case BATTERY_KEY:
-                exec_battery_info (manager);
+                do_execute_desktop (manager, "gnome-power-statistics.desktop", timestamp);
                 break;
         case HANDLED_KEYS:
                 g_assert_not_reached ();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]