[PATCH] enable nautilus to run as a daemon without any window created



Hi list,
  Recently I have added one new feature to nautilus in my local branch: run nautilus as a daemon without any
window created (file explorer or desktop) and can monitor media automount events.
  As we know, nautilus cannot startup with both --no-desktop and --no-default-window options. But in the desktop
session of our current project, we need nautilus as the default file manager but need not its desktop window. This
patch is to enable this requirement.
 Also this request and patch are files to bugzilla, the link is http://bugzilla.gnome.org/show_bug.cgi?id=579574
and with the following details:
This patch is tested in my local buildings. 
It includes two major modification:
1. add one new cmd line option: --daemon, which can be used in first startup,
to enable nautilus run as a daemon without any window
2. add one new gconf key: apps/nautilus/preferences/daemon_enable, to enable
nautilus to run with both '--no-desktop' and '--no-default-window' without quit
instantly.
In another word, 'nautilus --daemon' is mostly equal 'nautilus --no-desktop
--no-default-window' with gconf/daemon_enabel being TRUE.

The following cases are tested:
1. case: before any nautilus instance exist, start nautilus with '--daemon'
expect: run in background without any window

2. case: before any nautilus instance exist, start nautilus with '--no-desktop
--no-default-window', with gconf/preferences/daemon_enable being TRUE
expect: run in background without any window

3. case: after nautilus run with daemon mode, run 'nautilus --quit'
expect: all nautilus windows and daemon should be killed

4. case: after nautilus run with daemon mode (with automount preference TRUE),
plugin usb storage device
expect: a file explorer window popup and show the content of usb storage

5. case: with nautilus running with any mode, start nautilus with any
acceptable options
expect: nautilus should not create new instance, send request msg to exist
instance and quit

As for ChangeLog, it seems there's some changing of how to modify it, along with git repos applying. I didn't
include ChangeLog in this pathc.
 
Please review it.  Thanks.

Regards,
Jianfeng Ding

diff --git a/libnautilus-private/apps_nautilus_preferences.schemas.in b/libnautilus-private/apps_nautilus_preferences.schemas.in
index edb2d5e..aaed0fe 100644
--- a/libnautilus-private/apps_nautilus_preferences.schemas.in
+++ b/libnautilus-private/apps_nautilus_preferences.schemas.in
@@ -7,6 +7,21 @@
     <!-- General preferences -->
 
     <schema>
+      <key>/schemas/apps/nautilus/preferences/daemon_enable</key>
+      <applyto>/apps/nautilus/preferences/daemon_enable</applyto>
+      <owner>nautilus</owner>
+      <type>bool</type>
+      <default>false</default>
+      <locale name="C">
+         <short>Nautilus can run as a daemon for media automounting.</short>
+	 <long>
+	  If set to true, then Nautilus can be started as a daemon to monitor
+      media automount only, without any window.
+      </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.h b/libnautilus-private/nautilus-global-preferences.h
index 3a3fe32..7fa40ba 100644
--- a/libnautilus-private/nautilus-global-preferences.h
+++ b/libnautilus-private/nautilus-global-preferences.h
@@ -30,6 +30,9 @@
 
 G_BEGIN_DECLS
 
+/* Whether can run as a daemon */
+#define NAUTILUS_PREFERENCES_DAEMON_ENABLE			"preferences/daemon_enable"
+
 /* 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 a3ef577..e0cec94 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 allow_daemon = FALSE;
+
 static gboolean
 is_event_loop_needed (void)
 {
-	return event_loop_registrants != NULL;
+	return event_loop_registrants != NULL || allow_daemon;
 }
 
 static int
@@ -139,6 +141,12 @@ nautilus_main_event_loop_quit (gboolean explicit)
 	while (event_loop_registrants != NULL) {
 		gtk_object_destroy (event_loop_registrants->data);
 	}
+
+	/* To quit all instances, disable daemon */
+	if (allow_daemon) {
+		allow_daemon = FALSE;
+		eel_gtk_main_quit_all ();
+	}
 }
 
 static void
@@ -314,6 +322,7 @@ main (int argc, char *argv[])
 	gchar *geometry;
 	const gchar **remaining;
 	gboolean perform_self_check;
+	gboolean daemon_mode;
 	NautilusApplication *application;
 	GOptionContext *context;
 	GFile *file;
@@ -338,6 +347,8 @@ main (int argc, char *argv[])
 		  N_("Do not manage the desktop (ignore the preference set in the preferences dialog)."), NULL },
 		{ "browser", '\0', 0, G_OPTION_ARG_NONE, &browser_window, 
 		  N_("open a browser window."), NULL },
+		{ "daemon", '\0', 0, G_OPTION_ARG_NONE, &daemon_mode,
+		  N_("Start Nautilus as a daemon for media automount."), NULL },
 		{ "quit", 'q', 0, G_OPTION_ARG_NONE, &kill_shell, 
 		  N_("Quit Nautilus."), NULL },
 		{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining, NULL,  N_("[URI...]") },
@@ -389,6 +400,7 @@ main (int argc, char *argv[])
 	no_desktop = FALSE;
 	perform_self_check = FALSE;
 	browser_window = FALSE;
+	daemon_mode = FALSE;
 
 	g_set_prgname ("nautilus");
 	if (g_file_test (DATADIR "/applications/nautilus.desktop", G_FILE_TEST_EXISTS)) {
@@ -429,6 +441,15 @@ main (int argc, char *argv[])
 		no_desktop = FALSE;
 	}
 
+	/* If user specified --daemon explicitly, nautilus should start without
+	 * any window created.
+	 */
+	if (daemon_mode) {
+		no_default_window = TRUE;
+		no_desktop = TRUE;
+		allow_daemon = TRUE;
+	}
+
 	if (perform_self_check && remaining != NULL) {
 		/* translators: %s is an option (e.g. --check) */
 		fprintf (stderr, _("nautilus: %s cannot be used with URIs.\n"),
@@ -457,6 +478,15 @@ main (int argc, char *argv[])
 	 * happens.
 	 */
 	nautilus_global_preferences_init ();
+
+	/* Once "preferences/daemon_enable" be TRUE, nautilus can run without
+	 * window.
+	 */
+	if (!daemon_mode &&
+	    eel_preferences_get_boolean (NAUTILUS_PREFERENCES_DAEMON_ENABLE)) {
+		allow_daemon = TRUE;
+	}
+
 	if (no_desktop) {
 		eel_preferences_set_is_invisible
 			(NAUTILUS_PREFERENCES_SHOW_DESKTOP, TRUE);
@@ -514,6 +544,11 @@ main (int argc, char *argv[])
 			 uris);
 		g_strfreev (uris);
 
+		if (unique_app_is_running (application->unique_app) ||
+		    kill_shell) {
+			allow_daemon = FALSE;
+		}
+
 		if (is_event_loop_needed ()) {
 			gtk_main ();
 		}


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