aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2009-11-26 23:25:08 +0800
committerMatthew Barnes <mbarnes@redhat.com>2009-11-26 23:28:31 +0800
commitaa3152a2ec7b38232d71b32d085958e899cdc7c5 (patch)
treede50f0dd73d001b5a05724a80b6342be2be7d12e
parent00e1de6f7d333da5177548cc45be669b1e4e2195 (diff)
downloadgsoc2013-evolution-aa3152a2ec7b38232d71b32d085958e899cdc7c5.tar
gsoc2013-evolution-aa3152a2ec7b38232d71b32d085958e899cdc7c5.tar.gz
gsoc2013-evolution-aa3152a2ec7b38232d71b32d085958e899cdc7c5.tar.bz2
gsoc2013-evolution-aa3152a2ec7b38232d71b32d085958e899cdc7c5.tar.lz
gsoc2013-evolution-aa3152a2ec7b38232d71b32d085958e899cdc7c5.tar.xz
gsoc2013-evolution-aa3152a2ec7b38232d71b32d085958e899cdc7c5.tar.zst
gsoc2013-evolution-aa3152a2ec7b38232d71b32d085958e899cdc7c5.zip
Add a --quit command-line option.
This -asks- an existing Evolution process to quit. It is equivalent to selecting File->Quit in the main window. It does not kill the process. My plan is to use this as part of a new --force-shutdown implementation.
-rw-r--r--doc/reference/shell/tmpl/e-shell.sgml1
-rw-r--r--shell/e-shell.c75
-rw-r--r--shell/e-shell.h2
-rw-r--r--shell/main.c8
4 files changed, 64 insertions, 22 deletions
diff --git a/doc/reference/shell/tmpl/e-shell.sgml b/doc/reference/shell/tmpl/e-shell.sgml
index c2697cc65a..ce167e2725 100644
--- a/doc/reference/shell/tmpl/e-shell.sgml
+++ b/doc/reference/shell/tmpl/e-shell.sgml
@@ -297,6 +297,7 @@ EShell
</para>
@shell:
+@Returns:
<!-- ##### FUNCTION e_shell_cancel_quit ##### -->
diff --git a/shell/e-shell.c b/shell/e-shell.c
index 1e5fecfe67..e03efb49cf 100644
--- a/shell/e-shell.c
+++ b/shell/e-shell.c
@@ -606,7 +606,7 @@ shell_constructed (GObject *object)
shell_add_backend, object);
}
-static gboolean
+static UniqueResponse
shell_message_handle_new (EShell *shell,
UniqueMessageData *data)
{
@@ -616,10 +616,10 @@ shell_message_handle_new (EShell *shell,
e_shell_create_shell_window (shell, view_name);
g_free (view_name);
- return TRUE;
+ return UNIQUE_RESPONSE_OK;
}
-static gboolean
+static UniqueResponse
shell_message_handle_open (EShell *shell,
UniqueMessageData *data)
{
@@ -645,16 +645,21 @@ shell_message_handle_open (EShell *shell,
}
g_strfreev (uris);
- return TRUE;
+ return UNIQUE_RESPONSE_OK;
}
-static gboolean
+static UniqueResponse
shell_message_handle_close (EShell *shell,
UniqueMessageData *data)
{
- e_shell_quit (shell);
+ UniqueResponse response;
- return TRUE;
+ if (e_shell_quit (shell))
+ response = UNIQUE_RESPONSE_OK;
+ else
+ response = UNIQUE_RESPONSE_CANCEL;
+
+ return response;
}
static UniqueResponse
@@ -670,19 +675,13 @@ shell_message_received (UniqueApp *app,
break; /* use the default behavior */
case UNIQUE_NEW:
- if (shell_message_handle_new (shell, data))
- return UNIQUE_RESPONSE_OK;
- break;
+ return shell_message_handle_new (shell, data);
case UNIQUE_OPEN:
- if (shell_message_handle_open (shell, data))
- return UNIQUE_RESPONSE_OK;
- break;
+ return shell_message_handle_open (shell, data);
case UNIQUE_CLOSE:
- if (shell_message_handle_close (shell, data))
- return UNIQUE_RESPONSE_OK;
- break;
+ return shell_message_handle_close (shell, data);
default:
break;
@@ -1611,15 +1610,53 @@ e_shell_event (EShell *shell,
g_signal_emit (shell, signals[EVENT], detail, event_data);
}
-void
+/**
+ * e_shell_quit:
+ * @shell: an #EShell
+ *
+ * Requests an application shutdown. This happens in two phases: the
+ * first is synchronous, the second is asynchronous.
+ *
+ * In the first phase, the @shell emits a #EShell::quit-requested signal
+ * to potentially give the user a chance to cancel shutdown. If the user
+ * cancels shutdown, the function returns %FALSE. Otherwise it proceeds
+ * into the second phase.
+ *
+ * In the second phase, the @shell emits a #EShell::prepare-for-quit
+ * signal and immediately returns %TRUE. Signal handlers may delay the
+ * actual application shutdown while they clean up resources, but there
+ * is no way to cancel shutdown at this point.
+ *
+ * Consult the documentation for these two signals for details on how
+ * to handle them.
+ *
+ * Returns: %TRUE if shutdown is underway, %FALSE if it was cancelled
+ **/
+gboolean
e_shell_quit (EShell *shell)
{
- g_return_if_fail (E_IS_SHELL (shell));
+ UniqueApp *app;
+ UniqueResponse response;
+
+ g_return_val_if_fail (E_IS_SHELL (shell), FALSE);
+
+ app = UNIQUE_APP (shell);
+
+ if (unique_app_is_running (app))
+ goto unique;
if (!shell_request_quit (shell))
- return;
+ return FALSE;
shell_prepare_for_quit (shell);
+
+ return TRUE;
+
+unique: /* Send a message to the other Evolution process. */
+
+ response = unique_app_send_message (app, UNIQUE_CLOSE, NULL);
+
+ return (response == UNIQUE_RESPONSE_OK);
}
/**
diff --git a/shell/e-shell.h b/shell/e-shell.h
index 468cc3a6f1..94821bb2b8 100644
--- a/shell/e-shell.h
+++ b/shell/e-shell.h
@@ -106,7 +106,7 @@ GtkWidget * e_shell_get_preferences_window (EShell *shell);
void e_shell_event (EShell *shell,
const gchar *event_name,
gpointer event_data);
-void e_shell_quit (EShell *shell);
+gboolean e_shell_quit (EShell *shell);
void e_shell_cancel_quit (EShell *shell);
G_END_DECLS
diff --git a/shell/main.c b/shell/main.c
index e96620ab24..3e3268b673 100644
--- a/shell/main.c
+++ b/shell/main.c
@@ -87,7 +87,7 @@ static gboolean force_migrate = FALSE;
static gboolean disable_eplugin = FALSE;
static gboolean disable_preview = FALSE;
static gboolean import_uris = FALSE;
-static gboolean idle_cb (gchar **uris);
+static gboolean quit = FALSE;
static gchar *geometry = NULL;
static gchar *requested_view = NULL;
@@ -237,7 +237,9 @@ idle_cb (gchar **uris)
/* These calls do the right thing when another Evolution
* process is running. */
- if (uris != NULL && *uris != NULL) {
+ if (quit)
+ e_shell_quit (shell);
+ else if (uris != NULL && *uris != NULL) {
if (e_shell_handle_uris (shell, uris, import_uris) == 0)
gtk_main_quit ();
} else
@@ -334,6 +336,8 @@ static GOptionEntry entries[] = {
&setup_only, NULL, NULL },
{ "import", 'i', 0, G_OPTION_ARG_NONE, &import_uris,
N_("Import URIs or file names given as rest of arguments."), NULL },
+ { "quit", 'q', 0, G_OPTION_ARG_NONE, &quit,
+ N_("Request a running Evolution process to quit"), NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining_args, NULL, NULL },
{ NULL }
};