[nautilus-open-terminal] Port the terminal launching to GAppInfo



commit ce56165ed58b225804f50a01dc101097b7892efd
Author: Kalev Lember <kalevlember gmail com>
Date:   Wed Feb 27 21:05:47 2013 +0100

    Port the terminal launching to GAppInfo
    
    ... dropping the use of eel-gnome-extensions and libgnome-desktop.
    
    This fixes the build with libgnome-desktop 3.7.90 where the terminal
    launching functionality was dropped. Instead, we use GAppInfo with the
    G_APP_INFO_CREATE_NEEDS_TERMINAL flag as a replacement.

 configure.in                 |    5 -
 src/Makefile.am              |    7 +-
 src/eel-gnome-extensions.c   |  219 ------------------------------------------
 src/eel-gnome-extensions.h   |   40 --------
 src/nautilus-open-terminal.c |   45 ++++++++-
 5 files changed, 45 insertions(+), 271 deletions(-)
---
diff --git a/configure.in b/configure.in
index 420f990..3674dec 100644
--- a/configure.in
+++ b/configure.in
@@ -29,7 +29,6 @@ fi
 # Dependency checks
 
 NAUTILUS_REQUIRED=2.91.90
-LIBGNOME_DESKTOP_REQUIRED=2.91.90
 GLIB_REQUIRED=2.16.0
 
 PKG_CHECK_MODULES(NAUTILUS, [
@@ -39,7 +38,6 @@ PKG_CHECK_MODULES(NAUTILUS, [
        gconf-2.0
 ])
 PKG_CHECK_MODULES(GCONF, gconf-2.0)
-PKG_CHECK_MODULES(GNOMEDESKTOP, gnome-desktop-3.0 >= $LIBGNOME_DESKTOP_REQUIRED)
 
 
 # Make dependency CFLAGS and LIBS available
@@ -50,9 +48,6 @@ AC_SUBST(NAUTILUS_LIBS)
 AC_SUBST(GCONF_CFLAGS)
 AC_SUBST(GCONF_LIBS)
 
-AC_SUBST(GNOMEDESKTOP_CFLAGS)
-AC_SUBST(GNOMEDESKTOP_LIBS)
-
 AM_MAINTAINER_MODE([enable])
 GNOME_MAINTAINER_MODE_DEFINES
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 2457826..412ffea 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,20 +8,17 @@ INCLUDES =                                            \
        -Werror                                         \
        $(DISABLE_DEPRECATED)                           \
        $(NAUTILUS_CFLAGS)                              \
-       $(GCONF_CFLAGS)                                 \
-       $(GNOMEDESKTOP_CFLAGS)
+       $(GCONF_CFLAGS)
 
 nautilus_extensiondir=$(NAUTILUS_EXTENSION_DIR)
 
 nautilus_extension_LTLIBRARIES=libnautilus-open-terminal.la
 
 libnautilus_open_terminal_la_SOURCES = \
-       eel-gnome-extensions.c       \
-       eel-gnome-extensions.h       \
        nautilus-open-terminal.h       \
        nautilus-open-terminal.c       \
        nautilus-open-terminal.h       \
        open-terminal.c
 
 libnautilus_open_terminal_la_LDFLAGS = -module -avoid-version
-libnautilus_open_terminal_la_LIBADD  = $(NAUTILUS_LIBS) $(GCONF_LIBS) $(GNOMEDESKTOP_LIBS)
+libnautilus_open_terminal_la_LIBADD  = $(NAUTILUS_LIBS) $(GCONF_LIBS)
diff --git a/src/nautilus-open-terminal.c b/src/nautilus-open-terminal.c
index 5043aed..af4b75b 100644
--- a/src/nautilus-open-terminal.c
+++ b/src/nautilus-open-terminal.c
@@ -26,7 +26,6 @@
 #endif
 
 #include "nautilus-open-terminal.h"
-#include "eel-gnome-extensions.h"
 
 #include <libnautilus-extension/nautilus-menu-provider.h>
 
@@ -313,6 +312,48 @@ get_terminal_command_for_file_info (NautilusFileInfo *file_info,
        return command;
 }
 
+static char *
+make_shell_command (const char *command)
+{
+       char *quoted, *shell_command;
+
+       quoted = g_shell_quote (command);
+       shell_command = g_strconcat ("/bin/sh -c ", quoted, NULL);
+       g_free (quoted);
+       return shell_command;
+}
+
+static void
+open_terminal_on_screen (const char *command,
+                        GdkScreen  *screen)
+{
+       GAppInfo *app;
+       GdkAppLaunchContext *ctx;
+       GdkDisplay *display;
+       GError *error = NULL;
+       char *command_line;
+
+       command_line = make_shell_command (command);
+       app = g_app_info_create_from_commandline (command_line, NULL, G_APP_INFO_CREATE_NEEDS_TERMINAL, 
&error);
+       g_free (command_line);
+
+       if (app != NULL) {
+               display = gdk_screen_get_display (screen);
+               ctx = gdk_display_get_app_launch_context (display);
+               gdk_app_launch_context_set_screen (ctx, screen);
+
+               g_app_info_launch (app, NULL, G_APP_LAUNCH_CONTEXT (ctx), &error);
+
+               g_object_unref (app);
+               g_object_unref (ctx);
+       }
+
+       if (error != NULL) {
+               g_message ("Could not start application on terminal: %s", error->message);
+               g_error_free (error);
+       }
+}
+
 
 static void
 open_terminal (NautilusMenuItem *item,
@@ -328,7 +369,7 @@ open_terminal (NautilusMenuItem *item,
 
        terminal_command = get_terminal_command_for_file_info (file_info, command_to_run, remote_terminal);
        if (terminal_command != NULL) {
-               _not_eel_gnome_open_terminal_on_screen (terminal_command, screen);
+               open_terminal_on_screen (terminal_command, screen);
        }
        g_free (terminal_command);
 }


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