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.
This commit is contained in:
Matthew Barnes
2009-11-26 10:25:08 -05:00
parent 00e1de6f7d
commit aa3152a2ec
4 changed files with 64 additions and 22 deletions

View File

@ -297,6 +297,7 @@ EShell
</para>
@shell:
@Returns:
<!-- ##### FUNCTION e_shell_cancel_quit ##### -->

View File

@ -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);
}
/**

View File

@ -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

View File

@ -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 }
};