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



Alex and the list, sorry for my slow response to this thread, these days I am too busy to following here :)

Now I have updated my patch according our discussion. The patch was generated using master branch in today's git tree.
Please review it. Thanks!

Regards,
jf.ding


On Thu, Apr 23, 2009 at 5:03 PM, Alexander Larsson <alexl redhat com> wrote:
On Tue, 2009-04-21 at 15:42 +0800, JF Ding wrote:
>
>
> On Tue, Apr 21, 2009 at 3:29 PM, Alexander Larsson <alexl redhat com>
> wrote:
>
>         On Tue, 2009-04-21 at 15:21 +0800, JF Ding wrote:
>         >
>         >
>         > On Tue, Apr 21, 2009 at 3:03 PM, Alexander Larsson
>         <alexl redhat com>
>         > wrote:
>         >         On Tue, 2009-04-21 at 14:55 +0800, JF Ding wrote:
>         >         >
>         >         >
>         >         >
>         >         >         +
>         >         >
>         >
>          <key>/schemas/apps/nautilus/preferences/daemon_enable</key>
>         >         >         +
>         >         >
>         >
>          <applyto>/apps/nautilus/preferences/daemon_enable</applyto>
>         >         >
>         >         >         +#define
>         >         >         NAUTILUS_PREFERENCES_DAEMON_ENABLE
>         >         >          "preferences/daemon_enable"
>         >         >
>         >         >         A better name would be "daemon_mode"
>         >         >
>         >         >         +static gboolean allow_daemon = FALSE;
>         >         >
>         >         >         Same here, call it "daemon_mode".
>         >         >
>         >         > About the variable names, including gconf key and
>         the two
>         >         new vars,
>         >         > the name does be indicating the usage.
>         >         > In fact, in my first design, the name of gconf key
>         is
>         >         "daemon_mode",
>         >         > but I think it is not precise, because the key
>         >         > is to indicate whether nautilus can run as a
>         daemon. I
>         >         rename it to
>         >         > "daemon_enable".
>         >         > The static global "allow_daemon", the same cause.
>         >         > And the stack variable in main(), "daemon_mode" to
>         be sync
>         >         with
>         >         > command line option "--daemon", its meaning
>         >         > is whether it run in "daemon mode", which will not
>         created
>         >         desktop and
>         >         > default window.
>         >         > I hope this can be explained clearly. Of course I
>         will
>         >         rename them if
>         >         > you cannot agree with the usage of them.
>         >
>         >
>         >         Well, I disagree with all that because I think
>         having the
>         >         command line
>         >         option at all is a bad idea. We should just have a
>         gconf key.
>         >
>         > OK, I will following it. Just discard the command line
>         option. But for
>         > the meaning
>         > of "daemon_mode", I feel it should stand for "only daemon
>         without
>         > window" mode.
>         > So, should we think over the names?
>
>
>         Well, I'm not particularly fond of the "daemon_mode" name. I
>         tried to
>         think of a name that described what it does, like
>         "exit_with_last_window" (default TRUE), but everything I could
>         come up
>         with was too long to be sensible. Can you think of something
>         better?
>
>
> Em, how about "windowless_enable"?

Having "enable" in the name is generally unnecessary. You're looking at
a boolean configure option, what would it do other than enable
something? What we want to do is describe exactly what the option does,
without inventing to much new terminology, and "windowless" is new
terminology that is used nowhere else and isn't totally obvious.

"exit_if_no_windows" maybe?

No, I think "exit_with_last_window" is the best I've seen so far. Lets
go with that.








--
?切有為法
如夢幻泡影
如露亦如電
應?如是觀
diff --git a/libnautilus-private/apps_nautilus_preferences.schemas.in b/libnautilus-private/apps_nautilus_preferences.schemas.in
index 6a70aec..7bd8426 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 child windows 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..78a234c 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,18 @@ 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 reach here, nautilus must run in "daemon" mode,
+			 * or with exit_with_last_window being FALSE. Just
+			 * call eel_gtk_main_quit_all to 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 +472,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 +534,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]