[nautilus/wip/csoriano/destktop-split2: 14/33] desktop: move to a different binary



commit 6a09aee16d5f6a6702be1c1da3c199f47bb24dc3
Author: Carlos Soriano <csoriano gnome org>
Date:   Tue Mar 15 22:20:27 2016 +0100

    desktop: move to a different binary
    
    We wanted to do this for long time. This will allow to handle the
    desktop process in a different binary.
    The ultimate goal is to make the desktop code completely split from
    nautilus code.
    
    This is the first and minimal step towards that goal.
    
    In this patch we create a desktop application separated from nautilus
    application, and remove the desktop handling in nautilus application.

 data/nautilus-autostart.desktop.in |    2 +-
 src/Makefile.am                    |   20 ++++-
 src/main-desktop.c                 |   41 +++++++++
 src/nautilus-application.c         |  156 ++---------------------------------
 src/nautilus-desktop-application.c |  158 ++++++++++++++++++++++++++++++++++++
 src/nautilus-desktop-application.h |   36 ++++++++
 6 files changed, 262 insertions(+), 151 deletions(-)
---
diff --git a/data/nautilus-autostart.desktop.in b/data/nautilus-autostart.desktop.in
index 7252f87..d161ffe 100644
--- a/data/nautilus-autostart.desktop.in
+++ b/data/nautilus-autostart.desktop.in
@@ -1,6 +1,6 @@
 [Desktop Entry]
 Type=Application
 Name=Files
-Exec=nautilus -n
+Exec=nautilus-desktop
 OnlyShowIn=GNOME;Unity;
 AutostartCondition=GSettings org.gnome.desktop.background show-desktop-icons
diff --git a/src/Makefile.am b/src/Makefile.am
index 608e6a6..6445aa0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,6 +2,7 @@ include $(top_srcdir)/Makefile.shared
 
 bin_PROGRAMS=                                  \
        nautilus                                \
+       nautilus-desktop                        \
        nautilus-autorun-software               \
        $(NULL)
 
@@ -134,7 +135,7 @@ nautilus_built_sources = \
        nautilus-enum-types.c \
        $(NULL)
 
-nautilus_SOURCES = \
+nautilus_no_main_sources = \
        gtk/nautilusgtkplacesview.c                     \
        gtk/nautilusgtkplacesviewprivate.h              \
        gtk/nautilusgtkplacesviewrow.c                  \
@@ -178,7 +179,6 @@ nautilus_SOURCES = \
        nautilus-list-view-dnd.h                \
        nautilus-location-entry.c               \
        nautilus-location-entry.h               \
-       nautilus-main.c                         \
        nautilus-mime-actions.c                 \
        nautilus-mime-actions.h                 \
        nautilus-notebook.c                     \
@@ -221,10 +221,26 @@ nautilus_SOURCES = \
        nautilus-x-content-bar.h                \
        $(NULL)
 
+nautilus_SOURCES = \
+       $(nautilus_no_main_sources)             \
+       nautilus-main.c                         \
+       $(NULL)
+
+nautilus_desktop_SOURCES=                              \
+       $(nautilus_no_main_sources)                     \
+       main-desktop.c                                  \
+       nautilus-desktop-application.c                  \
+       nautilus-desktop-application.h                  \
+       $(NULL)
+
 nodist_nautilus_SOURCES = \
        $(nautilus_built_sources) \
        $(NULL)
 
+nodist_nautilus_desktop_SOURCES = \
+       $(nautilus_built_sources) \
+       $(NULL)
+
 EMPTY_VIEW_SOURCES = \
        nautilus-empty-view.c                   \
        nautilus-empty-view.h
diff --git a/src/main-desktop.c b/src/main-desktop.c
new file mode 100644
index 0000000..27202ef
--- /dev/null
+++ b/src/main-desktop.c
@@ -0,0 +1,41 @@
+#include <config.h>
+
+#include "nautilus-desktop-application.h"
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <gio/gdesktopappinfo.h>
+
+#include <libxml/parser.h>
+
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int
+main (int argc, char *argv[])
+{
+  NautilusDesktopApplication *application;
+  int retval;
+
+  /* Initialize gettext support */
+  bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
+  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+  textdomain (GETTEXT_PACKAGE);
+
+  g_set_prgname ("nautilus-desktop");
+  g_print ("main desktop\n");
+
+  /* Run the nautilus application. */
+  application = nautilus_desktop_application_new ();
+
+  retval = g_application_run (G_APPLICATION (application),
+                              argc, argv);
+
+  g_object_unref (application);
+
+  return retval;
+}
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index 7fce4d6..9bfee01 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -30,7 +30,6 @@
 #include "nautilus-application.h"
 
 #include "nautilus-dbus-manager.h"
-#include "nautilus-desktop-window.h"
 #include "nautilus-freedesktop-dbus.h"
 #include "nautilus-image-properties-page.h"
 #include "nautilus-previewer.h"
@@ -71,8 +70,6 @@ typedef struct {
        NautilusDBusManager *dbus_manager;
        NautilusFreedesktopDBus *fdb_manager;
 
-       gboolean desktop_override;
-
        NautilusBookmarkList *bookmark_list;
 
        NautilusShellSearchProvider *search_provider;
@@ -125,7 +122,6 @@ static gboolean
 check_required_directories (NautilusApplication *self)
 {
        char *user_directory;
-       char *desktop_directory;
        GSList *directories;
        gboolean ret;
 
@@ -136,7 +132,6 @@ check_required_directories (NautilusApplication *self)
        ret = TRUE;
 
        user_directory = nautilus_get_user_directory ();
-       desktop_directory = nautilus_get_desktop_directory ();
 
        directories = NULL;
 
@@ -144,10 +139,6 @@ check_required_directories (NautilusApplication *self)
                directories = g_slist_prepend (directories, user_directory);
        }
 
-       if (!g_file_test (desktop_directory, G_FILE_TEST_IS_DIR)) {
-               directories = g_slist_prepend (directories, desktop_directory);
-       }
-
        if (directories != NULL) {
                int failed_count;
                GString *directories_as_string;
@@ -188,7 +179,6 @@ check_required_directories (NautilusApplication *self)
 
        g_slist_free (directories);
        g_free (user_directory);
-       g_free (desktop_directory);
        nautilus_profile_end (NULL);
 
        return ret;
@@ -390,22 +380,6 @@ real_open_location_full (NautilusApplication     *self,
         if (target_slot != NULL)
                 target_window = nautilus_window_slot_get_window (target_slot);
 
-        if ((target_window && NAUTILUS_IS_DESKTOP_WINDOW (target_window)) ||
-            (!target_window && NAUTILUS_IS_DESKTOP_WINDOW (active_window))) {
-                NautilusWindow *desktop_target_window;
-
-                desktop_target_window = target_window ? target_window : active_window;
-               use_same = !nautilus_desktop_window_loaded (NAUTILUS_DESKTOP_WINDOW (desktop_target_window));
-
-               /* if we're requested to open a new tab on the desktop, open a window
-                * instead.
-                */
-               if (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) {
-                       flags ^= NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB;
-                       flags |= NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW;
-               }
-       }
-
        g_assert (!((flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_WINDOW) != 0 &&
                    (flags & NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB) != 0));
 
@@ -434,16 +408,14 @@ real_open_location_full (NautilusApplication     *self,
 
        /* close the current window if the flags say so */
        if ((flags & NAUTILUS_WINDOW_OPEN_FLAG_CLOSE_BEHIND) != 0) {
-               if (!NAUTILUS_IS_DESKTOP_WINDOW (active_window)) {
-                       if (gtk_widget_get_visible (GTK_WIDGET (target_window))) {
-                               nautilus_window_close (active_window);
-                       } else {
-                               g_signal_connect_object (target_window,
-                                                        "show",
-                                                        G_CALLBACK (new_window_show_callback),
-                                                        active_window,
-                                                        G_CONNECT_AFTER);
-                       }
+               if (gtk_widget_get_visible (GTK_WIDGET (target_window))) {
+                       nautilus_window_close (active_window);
+               } else {
+                       g_signal_connect_object (target_window,
+                                                "show",
+                                                G_CALLBACK (new_window_show_callback),
+                                                active_window,
+                                                G_CONNECT_AFTER);
                }
        }
 
@@ -599,13 +571,6 @@ do_cmdline_sanity_checks (NautilusApplication *self,
                goto out;
        }
 
-       if (g_variant_dict_contains (options, "force-desktop") &&
-           g_variant_dict_contains (options, "no-desktop")) {
-               g_printerr ("%s\n",
-                           _("--no-desktop and --force-desktop cannot be used together."));
-               goto out;
-       }
-
        retval = TRUE;
 
  out:
@@ -728,27 +693,6 @@ action_help (GSimpleAction *action,
 }
 
 static void
-action_open_desktop (GSimpleAction *action,
-                     GVariant      *parameter,
-                     gpointer       user_data)
-{
-        nautilus_desktop_window_ensure ();
-}
-
-static void
-action_close_desktop (GSimpleAction *action,
-                      GVariant      *parameter,
-                      gpointer       user_data)
-{
-        GtkWidget *desktop_window;
-
-        desktop_window = nautilus_desktop_window_get ();
-        if (desktop_window != NULL) {
-                gtk_widget_destroy (desktop_window);
-        }
-}
-
-static void
 action_kill (GSimpleAction *action,
              GVariant      *parameter,
              gpointer       user_data)
@@ -767,7 +711,6 @@ action_quit (GSimpleAction *action,
         NautilusApplication *self = NAUTILUS_APPLICATION (user_data);
         GList *windows, *l;
 
-        /* nautilus_window_close() doesn't do anything for desktop windows */
         windows = nautilus_application_get_windows (self);
         /* make a copy, since the original list will be modified when destroying
          * a window, making this list invalid */
@@ -818,8 +761,6 @@ static GActionEntry app_entries[] = {
         { "help", action_help, NULL, NULL, NULL },
         { "quit", action_quit, NULL, NULL, NULL },
         { "kill", action_kill, NULL, NULL, NULL },
-        { "open-desktop", action_open_desktop, NULL, NULL, NULL },
-        { "close-desktop", action_close_desktop, NULL, NULL, NULL },
         { "show-help-overlay", action_show_help_overlay, NULL, NULL, NULL },
 };
 
@@ -868,10 +809,6 @@ const GOptionEntry options[] = {
           N_("Always open a new window for browsing specified URIs"), NULL },
         { "no-default-window", 'n', 0, G_OPTION_ARG_NONE, NULL,
           N_("Only create windows for explicitly specified URIs."), NULL },
-        { "no-desktop", '\0', 0, G_OPTION_ARG_NONE, NULL,
-          N_("Never manage the desktop (ignore the GSettings preference)."), NULL },
-        { "force-desktop", '\0', 0, G_OPTION_ARG_NONE, NULL,
-          N_("Always manage the desktop (ignore the GSettings preference)."), NULL },
         { "quit", 'q', 0, G_OPTION_ARG_NONE, NULL,
           N_("Quit Nautilus."), NULL },
         { "select", 's', 0, G_OPTION_ARG_NONE, NULL,
@@ -989,30 +926,6 @@ nautilus_application_command_line (GApplication            *application,
                goto out;
        }
 
-       if (g_variant_dict_contains (options, "force-desktop")) {
-               DEBUG ("Forcing desktop, as requested");
-               priv->desktop_override = TRUE;
-               g_action_group_activate_action (G_ACTION_GROUP (application),
-                                               "open-desktop", NULL);
-       } else if (g_variant_dict_contains (options, "no-desktop")) {
-               if (g_application_get_is_remote (application)) {
-                       DEBUG ("Not primary instance. Ignoring --no-desktop.");
-               } else {
-                       DEBUG ("Forcing desktop off, as requested");
-                       priv->desktop_override = TRUE;
-                       g_action_group_activate_action (G_ACTION_GROUP (application),
-                                                       "close-desktop", NULL);
-               }
-       }
-
-       if (g_variant_dict_contains (options, "no-default-window")) {
-               /* Do nothing. If icons on desktop are enabled, it will create
-                * the desktop window which will hold the application. If not,
-                * it will just exit. */
-               retval = EXIT_SUCCESS;
-               goto out;
-       }
-
        retval = nautilus_application_handle_file_args (self, options);
 
  out:
@@ -1037,58 +950,6 @@ nautilus_application_init (NautilusApplication *self)
 }
 
 static void
-nautilus_application_set_desktop_visible (NautilusApplication *self,
-                                         gboolean             visible)
-{
-       const gchar *action_name;
-
-       action_name = visible ? "open-desktop" : "close-desktop";
-       g_action_group_activate_action (G_ACTION_GROUP (self),
-                                       action_name, NULL);
-}
-
-static void
-update_desktop_from_gsettings (NautilusApplication *self)
-{
-        NautilusApplicationPrivate *priv;
-       GdkDisplay *display;
-       gboolean visible;
-
-        priv = nautilus_application_get_instance_private (self);
-       /* desktop GSetting was overridden - don't do anything */
-       if (priv->desktop_override) {
-               return;
-       }
-
-#ifdef GDK_WINDOWING_X11
-       display = gdk_display_get_default ();
-       visible = g_settings_get_boolean (gnome_background_preferences,
-                                          NAUTILUS_PREFERENCES_SHOW_DESKTOP);
-       if (!GDK_IS_X11_DISPLAY (display)) {
-               if (visible)
-                       g_warning ("Desktop icons only supported on X11. Desktop not created");
-
-               return;
-       }
-
-       nautilus_application_set_desktop_visible (self, visible);
-
-       return;
-#endif
-
-       g_warning ("Desktop icons only supported on X11. Desktop not created");
-}
-
-static void
-init_desktop (NautilusApplication *self)
-{
-       g_signal_connect_swapped (gnome_background_preferences, "changed::" NAUTILUS_PREFERENCES_SHOW_DESKTOP,
-                                 G_CALLBACK (update_desktop_from_gsettings),
-                                 self);
-       update_desktop_from_gsettings (self);
-}
-
-static void
 theme_changed (GtkSettings *settings)
 {
        static GtkCssProvider *provider = NULL;
@@ -1251,7 +1112,6 @@ nautilus_application_startup_common (NautilusApplication *self)
        check_required_directories (self);
 
        nautilus_init_application_actions (self);
-       init_desktop (self);
 
        nautilus_profile_end (NULL);
 
diff --git a/src/nautilus-desktop-application.c b/src/nautilus-desktop-application.c
new file mode 100644
index 0000000..62d7579
--- /dev/null
+++ b/src/nautilus-desktop-application.c
@@ -0,0 +1,158 @@
+/* nautilus-desktop-application.c
+ *
+ * Copyright (C) 2016 Carlos Soriano <csoriano gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "nautilus-desktop-application.h"
+#include "nautilus-desktop-window.h"
+
+#include <libnautilus-private/nautilus-global-preferences.h>
+#include <eel/eel.h>
+#include <gdk/gdkx.h>
+
+struct _NautilusDesktopApplication
+{
+  NautilusApplication parent_instance;
+};
+
+G_DEFINE_TYPE (NautilusDesktopApplication, nautilus_desktop_application, NAUTILUS_TYPE_APPLICATION)
+
+
+static void
+open_location_full (NautilusApplication     *self,
+                    GFile                   *location,
+                    NautilusWindowOpenFlags  flags,
+                    GList                   *selection,
+                    NautilusWindow          *target_window,
+                    NautilusWindowSlot      *target_slot)
+{
+  gchar *uri;
+
+  g_print ("open location full %s\n", g_file_get_uri (location));
+  uri = g_file_get_uri (location);
+  if (eel_uri_is_desktop (uri) && target_window &&
+      NAUTILUS_IS_DESKTOP_WINDOW (target_window))
+    {
+      nautilus_window_open_location_full (target_window, location, flags, selection, NULL);
+    }
+  else
+    {
+      g_print ("other location, use dbus to communicate with nautilus. This process is only for the 
desktop\n");
+    }
+  g_free (uri);
+}
+
+static void
+nautilus_application_set_desktop_visible (NautilusDesktopApplication *self,
+                                          gboolean                    visible)
+{
+  GtkWidget *desktop_window;
+
+  if (visible)
+    {
+        g_print ("set desktop visible\n");
+        nautilus_desktop_window_ensure ();
+    }
+  else
+    {
+        desktop_window = nautilus_desktop_window_get ();
+        if (desktop_window != NULL) {
+                gtk_widget_destroy (desktop_window);
+        }
+    }
+}
+
+static void
+update_desktop_from_gsettings (NautilusDesktopApplication *self)
+{
+  GdkDisplay *display;
+  gboolean visible;
+
+#ifdef GDK_WINDOWING_X11
+  display = gdk_display_get_default ();
+  visible = g_settings_get_boolean (gnome_background_preferences,
+                                    NAUTILUS_PREFERENCES_SHOW_DESKTOP);
+  if (!GDK_IS_X11_DISPLAY (display)) {
+    if (visible)
+      g_warning ("Desktop icons only supported on X11. Desktop not created");
+
+    return;
+    }
+
+  nautilus_application_set_desktop_visible (self, visible);
+
+  return;
+#endif
+
+  g_warning ("Desktop icons only supported on X11. Desktop not created");
+}
+
+static void
+init_desktop (NautilusDesktopApplication *self)
+{
+  g_signal_connect_swapped (gnome_background_preferences, "changed::" NAUTILUS_PREFERENCES_SHOW_DESKTOP,
+                            G_CALLBACK (update_desktop_from_gsettings),
+                            self);
+  update_desktop_from_gsettings (self);
+}
+
+static void
+nautilus_desktop_application_activate (GApplication *app)
+{
+}
+
+static void
+nautilus_desktop_application_startup (GApplication *app)
+{
+  NautilusDesktopApplication *self = NAUTILUS_DESKTOP_APPLICATION (app);
+
+  g_print ("startup desktop\n");
+
+  nautilus_application_startup_common (NAUTILUS_APPLICATION (app));
+  init_desktop (self);
+}
+
+static void
+nautilus_desktop_application_class_init (NautilusDesktopApplicationClass *klass)
+{
+  GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
+  NautilusApplicationClass *parent_class = NAUTILUS_APPLICATION_CLASS (klass);
+
+  g_print ("desktop application class init\n");
+
+  parent_class->open_location_full = open_location_full;
+
+  application_class->startup = nautilus_desktop_application_startup;
+  application_class->activate = nautilus_desktop_application_activate;
+}
+
+static void
+nautilus_desktop_application_init (NautilusDesktopApplication *self)
+{
+  g_print ("desktop application init\n");
+}
+
+NautilusDesktopApplication *
+nautilus_desktop_application_new (void)
+{
+  g_print ("desktop application new\n");
+  return g_object_new (NAUTILUS_TYPE_DESKTOP_APPLICATION,
+                       "application-id", "org.gnome.NautilusDesktop",
+                        NULL);
+}
+
diff --git a/src/nautilus-desktop-application.h b/src/nautilus-desktop-application.h
new file mode 100644
index 0000000..4f4c62c
--- /dev/null
+++ b/src/nautilus-desktop-application.h
@@ -0,0 +1,36 @@
+/* nautilus-desktop-application.h
+ *
+ * Copyright (C) 2016 Carlos Soriano <csoriano gnome org>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NAUTILUS_DESKTOP_APPLICATION_H
+#define NAUTILUS_DESKTOP_APPLICATION_H
+
+#include <glib.h>
+#include "nautilus-application.h"
+
+G_BEGIN_DECLS
+
+#define NAUTILUS_TYPE_DESKTOP_APPLICATION (nautilus_desktop_application_get_type())
+
+G_DECLARE_FINAL_TYPE (NautilusDesktopApplication, nautilus_desktop_application, NAUTILUS, 
DESKTOP_APPLICATION, NautilusApplication)
+
+NautilusDesktopApplication *nautilus_desktop_application_new (void);
+
+G_END_DECLS
+
+#endif /* NAUTILUS_DESKTOP_APPLICATION_H */
+


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