diff options
author | Xan Lopez <xan@igalia.com> | 2012-04-12 19:31:09 +0800 |
---|---|---|
committer | Xan Lopez <xan@igalia.com> | 2012-04-12 19:31:09 +0800 |
commit | bb759160ad593489d9b51488916a0fd8734136ca (patch) | |
tree | 71f82a0838b61b2f2ac601fb33a07e5313926478 | |
parent | 94f2fb5c7a80dc2e904d8296bda14a0e0324ccc1 (diff) | |
download | gsoc2013-epiphany-bb759160ad593489d9b51488916a0fd8734136ca.tar gsoc2013-epiphany-bb759160ad593489d9b51488916a0fd8734136ca.tar.gz gsoc2013-epiphany-bb759160ad593489d9b51488916a0fd8734136ca.tar.bz2 gsoc2013-epiphany-bb759160ad593489d9b51488916a0fd8734136ca.tar.lz gsoc2013-epiphany-bb759160ad593489d9b51488916a0fd8734136ca.tar.xz gsoc2013-epiphany-bb759160ad593489d9b51488916a0fd8734136ca.tar.zst gsoc2013-epiphany-bb759160ad593489d9b51488916a0fd8734136ca.zip |
Add a setting to control whether the session is automatically restored
We add a new gsettings key, 'restore-session-policy', with two valid
values: 'always' and 'never'. A brief explanation of our session state
mechanism follows.
There are three ways to exit Epiphany:
1) Activate 'Quit' in the application menu
2) Close the last application window
3) Kill the process manually, SIGSEGV, or other similar unexpected
event.
For 1) and 2), we'll now do the same thing:
a) Call ephy_session_close
b) Exit the application manually
ephy_session_close will check the new restore-session-policy setting,
and only save the session state if it's set to 'always'. Before it
used to manually destroy all present windows. We now let EphyShell or
EphyWindow do this, EphySession only manages the session state saving.
For 3), the process will die with the state saved up to that point,
there's nothing we can do. For that reason, on startup also check the
new setting; if it's set to 'never' ignore the session state, open a
window in the homepage, and delete the old state file.
https://bugzilla.gnome.org/show_bug.cgi?id=673453
-rw-r--r-- | data/org.gnome.epiphany.gschema.xml | 5 | ||||
-rw-r--r-- | lib/ephy-prefs.h | 7 | ||||
-rw-r--r-- | src/ephy-session.c | 72 | ||||
-rw-r--r-- | src/ephy-window.c | 1 |
4 files changed, 33 insertions, 52 deletions
diff --git a/data/org.gnome.epiphany.gschema.xml b/data/org.gnome.epiphany.gschema.xml index f286277f6..d39fc3849 100644 --- a/data/org.gnome.epiphany.gschema.xml +++ b/data/org.gnome.epiphany.gschema.xml @@ -59,6 +59,11 @@ <default>true</default> <summary>Don't use an external application to view page source.</summary> </key> + <key name="restore-session-policy" enum="org.gnome.Epiphany.EphyPrefsRestoreSessionPolicy"> + <default>'always'</default> + <summary>Whether to automatically restore the last session</summary> + <description>Defines how the session will be restored during startup. Allowed values are 'always' (the previous state of the application is always restored) and 'never' (the homepage is always shown).</description> + </key> </schema> <schema path="/org/gnome/epiphany/ui/" id="org.gnome.Epiphany.ui"> <key type="b" name="show-toolbars"> diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h index d5daaa034..e16f82c6a 100644 --- a/lib/ephy-prefs.h +++ b/lib/ephy-prefs.h @@ -37,6 +37,12 @@ typedef enum typedef enum { + EPHY_PREFS_RESTORE_SESSION_POLICY_ALWAYS, + EPHY_PREFS_RESTORE_SESSION_POLICY_NEVER +} EphyPrefsRestoreSessionPolicy; + +typedef enum +{ EPHY_PREFS_WEB_COOKIES_POLICY_ALWAYS, EPHY_PREFS_WEB_COOKIES_POLICY_NO_THIRD_PARTY, EPHY_PREFS_WEB_COOKIES_POLICY_NEVER @@ -105,6 +111,7 @@ typedef enum #define EPHY_PREFS_ENABLE_CARET_BROWSING "enable-caret-browsing" #define EPHY_PREFS_ENABLED_EXTENSIONS "enabled-extensions" #define EPHY_PREFS_INTERNAL_VIEW_SOURCE "internal-view-source" +#define EPHY_PREFS_RESTORE_SESSION_POLICY "restore-session-policy" #define EPHY_PREFS_LOCKDOWN_SCHEMA "org.gnome.Epiphany.lockdown" #define EPHY_PREFS_LOCKDOWN_FULLSCREEN "disable-fullscreen" diff --git a/src/ephy-session.c b/src/ephy-session.c index 6bdc993c2..f7579ef8d 100644 --- a/src/ephy-session.c +++ b/src/ephy-session.c @@ -231,6 +231,7 @@ session_command_autoresume (EphySession *session, GFile *saved_session_file; char *saved_session_file_path; gboolean crashed_session; + EphyPrefsRestoreSessionPolicy policy; LOG ("ephy_session_autoresume"); @@ -241,10 +242,20 @@ session_command_autoresume (EphySession *session, g_free (saved_session_file_path); + policy = g_settings_get_enum (EPHY_SETTINGS_MAIN, + EPHY_PREFS_RESTORE_SESSION_POLICY); + if (crashed_session == FALSE || + policy == EPHY_PREFS_RESTORE_SESSION_POLICY_NEVER || priv->windows != NULL || priv->tool_windows != NULL) { + /* If we are auto-resuming, and we never want to + * restore the session, clobber the session state + * file. */ + if (policy == EPHY_PREFS_RESTORE_SESSION_POLICY_NEVER) + session_delete (session, SESSION_STATE); + ephy_session_queue_command (session, EPHY_SESSION_CMD_MAYBE_OPEN_WINDOW, NULL, NULL, user_time, FALSE); @@ -614,67 +625,26 @@ ephy_session_class_init (EphySessionClass *class) /* Implementation */ -static void -close_dialog (GtkWidget *widget) -{ - if (GTK_IS_DIALOG (widget)) - { - /* don't destroy them, someone might have a ref on them */ - gtk_dialog_response (GTK_DIALOG (widget), - GTK_RESPONSE_DELETE_EVENT); - } -} - void ephy_session_close (EphySession *session) { - EphySessionPrivate *priv = session->priv; - GList *windows; + EphyPrefsRestoreSessionPolicy policy; LOG ("ephy_session_close"); - /* we have to ref the shell or else we may get finalised between - * destroying the windows and destroying the tool windows - */ - g_object_ref (ephy_shell_get_default ()); - - priv->dont_save = TRUE; - - /* Clear command queue */ - session_command_queue_clear (session); - - ephy_embed_shell_prepare_close (embed_shell); - - /* there may still be windows open, like dialogues posed from - * web pages, etc. Try to kill them, but be sure NOT to destroy - * the gtkmozembed offscreen window! - * Here, we just check if it's a dialogue and close it if it is one. - */ - windows = gtk_window_list_toplevels (); - g_list_foreach (windows, (GFunc) close_dialog, NULL); - g_list_free (windows); - - windows = ephy_session_get_windows (session); - g_list_foreach (windows, (GFunc) gtk_widget_destroy, NULL); - g_list_free (windows); - - windows = g_list_copy (session->priv->tool_windows); - g_list_foreach (windows, (GFunc) gtk_widget_destroy, NULL); - g_list_free (windows); - - ephy_embed_shell_prepare_close (embed_shell); + policy = g_settings_get_enum (EPHY_SETTINGS_MAIN, + EPHY_PREFS_RESTORE_SESSION_POLICY); + if (policy == EPHY_PREFS_RESTORE_SESSION_POLICY_ALWAYS) + { + EphySessionPrivate *priv = session->priv; - /* Just to be really sure, do it again: */ - windows = gtk_window_list_toplevels (); - g_list_foreach (windows, (GFunc) close_dialog, NULL); - g_list_free (windows); + priv->dont_save = TRUE; - session->priv->dont_save = FALSE; + session_command_queue_clear (session); - /* Clear command queue */ - session_command_queue_clear (session); + ephy_embed_shell_prepare_close (embed_shell); - g_object_unref (ephy_shell_get_default ()); + } } static int diff --git a/src/ephy-window.c b/src/ephy-window.c index 36243a3ad..16bda79eb 100644 --- a/src/ephy-window.c +++ b/src/ephy-window.c @@ -1064,7 +1064,6 @@ ephy_window_delete_event (GtkWidget *widget, if (number_windows == 1) { ephy_session_close (session); - return TRUE; } /* See bug #114689 */ |