[nautilus] Support daemon mode (exit_with_last_window preference)



commit 3d8011ca8c095be884b603ccea261b955fa6518b
Author: JF Ding <jfding gmail com>
Date:   Mon May 25 12:18:36 2009 +0200

    Support daemon mode (exit_with_last_window preference)
    
    This can be used if you want to run nautilus just to handle volume
    monitoring, etc.
---
 .../apps_nautilus_preferences.schemas.in           |   17 ++++++++++++
 libnautilus-private/nautilus-global-preferences.c  |    4 +++
 libnautilus-private/nautilus-global-preferences.h  |    3 ++
 src/nautilus-main.c                                |   27 +++++++++++++++++++-
 4 files changed, 50 insertions(+), 1 deletions(-)

diff --git a/libnautilus-private/apps_nautilus_preferences.schemas.in b/libnautilus-private/apps_nautilus_preferences.schemas.in
index 6a70aec..23d7990 100644
--- a/libnautilus-private/apps_nautilus_preferences.schemas.in
+++ b/libnautilus-private/apps_nautilus_preferences.schemas.in
@@ -7,6 +7,23 @@
     <!-- General preferences -->
 
     <schema>
+      <key>/schemas/apps/nautilus/preferences/exit_with_last_window</key>
+      <applyto>/apps/nautilus/preferences/exit_with_last_window</applyto>
+      <owner>nautilus</owner>
+      <type>bool</type>
+      <default>true</default>
+      <locale name="C">
+         <short>Nautilus will exit when last window destroyed.</short>
+         <long>
+          If set to true, then Nautilus will exit when all windows are destroyed.
+          This is the default setting. If set to false, it can be started without
+          any window, so nautilus can serve as a daemon to monitor media automount,
+          or similar tasks.
+         </long>
+      </locale>
+    </schema>
+
+    <schema>
       <key>/schemas/desktop/gnome/file_views/show_hidden_files</key>
       <applyto>/desktop/gnome/file_views/show_hidden_files</applyto>
       <owner>nautilus</owner>
diff --git a/libnautilus-private/nautilus-global-preferences.c b/libnautilus-private/nautilus-global-preferences.c
index e216c2e..b018655 100644
--- a/libnautilus-private/nautilus-global-preferences.c
+++ b/libnautilus-private/nautilus-global-preferences.c
@@ -235,6 +235,10 @@ typedef struct
  * YOU SHOULD EDIT THE SCHEMAS FILE TO CHANGE DEFAULTS.
  */
 static const PreferenceDefault preference_defaults[] = {
+	{ NAUTILUS_PREFERENCES_EXIT_WITH_LAST_WINDOW,
+	  PREFERENCE_BOOLEAN,
+	  GINT_TO_POINTER (TRUE)
+	},
 	{ NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
 	  PREFERENCE_BOOLEAN,
 	  GINT_TO_POINTER (FALSE)
diff --git a/libnautilus-private/nautilus-global-preferences.h b/libnautilus-private/nautilus-global-preferences.h
index 65e63d9..38c1dc2 100644
--- a/libnautilus-private/nautilus-global-preferences.h
+++ b/libnautilus-private/nautilus-global-preferences.h
@@ -30,6 +30,9 @@
 
 G_BEGIN_DECLS
 
+/* Whether exit when last window destroyed */
+#define NAUTILUS_PREFERENCES_EXIT_WITH_LAST_WINDOW				"preferences/exit_with_last_window"
+
 /* Which theme is active */
 #define NAUTILUS_PREFERENCES_THEME				"/desktop/gnome/file_views/icon_theme"
 
diff --git a/src/nautilus-main.c b/src/nautilus-main.c
index 60273d7..a64fbf4 100644
--- a/src/nautilus-main.c
+++ b/src/nautilus-main.c
@@ -68,10 +68,12 @@
 /* Keeps track of everyone who wants the main event loop kept active */
 static GSList *event_loop_registrants;
 
+static gboolean exit_with_last_window = TRUE;
+
 static gboolean
 is_event_loop_needed (void)
 {
-	return event_loop_registrants != NULL;
+	return event_loop_registrants != NULL || !exit_with_last_window;
 }
 
 static int
@@ -132,6 +134,19 @@ nautilus_main_event_loop_quit (gboolean explicit)
 {
 	if (explicit) {
 		/* Explicit --quit, make sure we don't restart */
+
+		/* To quit all instances, reset exit_with_last_window */
+		exit_with_last_window = TRUE;
+
+		if (event_loop_registrants == NULL) {
+			/* If this is reached, nautilus must run in "daemon" mode
+			 * (i.e. !exit_with_last_window) with no windows open.
+			 * We need to quit_all here because the below loop won't
+			 * trigger a quit.
+			 */
+			eel_gtk_main_quit_all();
+		}
+
 		/* TODO: With the old session we needed to set restart
 		   style to GNOME_RESTART_IF_RUNNING here, but i don't think we need
 		   that now since gnome-session doesn't restart apps except on startup. */
@@ -458,6 +473,11 @@ main (int argc, char *argv[])
 	 * happens.
 	 */
 	nautilus_global_preferences_init ();
+
+	/* exit_with_last_window being FALSE, nautilus can run without window. */
+	exit_with_last_window =
+		eel_preferences_get_boolean (NAUTILUS_PREFERENCES_EXIT_WITH_LAST_WINDOW);
+
 	if (no_desktop) {
 		eel_preferences_set_is_invisible
 			(NAUTILUS_PREFERENCES_SHOW_DESKTOP, TRUE);
@@ -515,6 +535,11 @@ main (int argc, char *argv[])
 			 uris);
 		g_strfreev (uris);
 
+		if (unique_app_is_running (application->unique_app) ||
+		    kill_shell) {
+			exit_with_last_window = TRUE;
+		}
+
 		if (is_event_loop_needed ()) {
 			gtk_main ();
 		}



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