diff options
author | Christian Persch <chpe@gnome.org> | 2007-07-11 02:46:08 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2007-07-11 02:46:08 +0800 |
commit | e87efd3cf2ee40071d643f54451461a6ecea8e85 (patch) | |
tree | 893817acdf19fc5436c3a0c60849fd4bb66a4e5d | |
parent | dd039744f9f164ac9afeaa39ca13cf5db37f422a (diff) | |
download | gsoc2013-epiphany-e87efd3cf2ee40071d643f54451461a6ecea8e85.tar gsoc2013-epiphany-e87efd3cf2ee40071d643f54451461a6ecea8e85.tar.gz gsoc2013-epiphany-e87efd3cf2ee40071d643f54451461a6ecea8e85.tar.bz2 gsoc2013-epiphany-e87efd3cf2ee40071d643f54451461a6ecea8e85.tar.lz gsoc2013-epiphany-e87efd3cf2ee40071d643f54451461a6ecea8e85.tar.xz gsoc2013-epiphany-e87efd3cf2ee40071d643f54451461a6ecea8e85.tar.zst gsoc2013-epiphany-e87efd3cf2ee40071d643f54451461a6ecea8e85.zip |
Use the new gtk functions to persist and load the print settings and page
2007-07-10 Christian Persch <chpe@gnome.org>
* embed/ephy-embed-shell.c: (ephy_embed_shell_set_page_setup),
(ephy_embed_shell_get_page_setup),
(ephy_embed_shell_set_print_settings),
(ephy_embed_shell_get_print_settings):
* lib/ephy-print-utils.c:
* lib/ephy-print-utils.h:
Use the new gtk functions to persist and load the print settings and
page setup. Migrate our old settings, if present.
svn path=/trunk/; revision=7144
-rw-r--r-- | embed/ephy-embed-shell.c | 76 |
1 files changed, 59 insertions, 17 deletions
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c index 163cad18f..65d2fe243 100644 --- a/embed/ephy-embed-shell.c +++ b/embed/ephy-embed-shell.c @@ -18,30 +18,38 @@ * $Id$ */ -#include "config.h" +#include <config.h> +#include <glib.h> +#include <glib/gstdio.h> + +#include <glib/gi18n.h> +#include <gtk/gtkmessagedialog.h> + +#include "downloader-view.h" +#include "ephy-adblock-manager.h" +#include "ephy-debug.h" +#include "ephy-embed-factory.h" #include "ephy-embed-shell.h" #include "ephy-embed-single.h" -#include "ephy-embed-factory.h" -#include "ephy-marshal.h" +#include "ephy-encodings.h" +#include "ephy-favicon-cache.h" #include "ephy-file-helpers.h" #include "ephy-history.h" -#include "ephy-favicon-cache.h" +#include "ephy-marshal.h" #include "mozilla-embed-single.h" -#include "downloader-view.h" -#include "ephy-encodings.h" -#include "ephy-debug.h" -#include "ephy-adblock-manager.h" -#include "ephy-print-utils.h" -#include <glib/gi18n.h> -#include <gtk/gtkmessagedialog.h> +#include "ephy-print-utils.h" -#define PAGE_SETUP_FILENAME "page-setup.ini" +#define PAGE_SETUP_FILENAME "page-setup-gtk.ini" #define PRINT_SETTINGS_FILENAME "print-settings.ini" +#define LEGACY_PAGE_SETUP_FILENAME "page-setup.ini" + #define EPHY_EMBED_SHELL_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_EMBED_SHELL, EphyEmbedShellPrivate)) +#define ENABLE_MIGRATION + struct _EphyEmbedShellPrivate { EphyHistory *global_history; @@ -391,16 +399,20 @@ ephy_embed_shell_set_page_setup (EphyEmbedShell *shell, { g_object_ref (page_setup); } + else + { + page_setup = gtk_page_setup_new (); + } if (priv->page_setup != NULL) { g_object_unref (priv->page_setup); } - priv->page_setup = page_setup ? page_setup : gtk_page_setup_new (); + priv->page_setup = page_setup; path = g_build_filename (ephy_dot_dir (), PAGE_SETUP_FILENAME, NULL); - ephy_print_utils_page_setup_to_file (page_setup, path, NULL); + gtk_page_setup_to_file (page_setup, path, NULL); g_free (path); } @@ -414,12 +426,37 @@ ephy_embed_shell_get_page_setup (EphyEmbedShell *shell) if (priv->page_setup == NULL) { + GError *error = NULL; char *path; path = g_build_filename (ephy_dot_dir (), PAGE_SETUP_FILENAME, NULL); - priv->page_setup = ephy_print_utils_page_setup_new_from_file (path, NULL); + priv->page_setup = gtk_page_setup_new_from_file (path, &error); g_free (path); +#ifdef ENABLE_MIGRATION + /* If the file doesn't exist, try to fall back to the old format */ + if (error != NULL && + error->domain == G_FILE_ERROR && + error->code == G_FILE_ERROR_NOENT) + { + path = g_build_filename (ephy_dot_dir (), LEGACY_PAGE_SETUP_FILENAME, NULL); + priv->page_setup = ephy_print_utils_page_setup_new_from_file (path, NULL); + if (priv->page_setup != NULL) + { + /* Delete the old file, so we don't migrate again */ + g_unlink (path); + } + g_free (path); + } else if (error != NULL) + g_warning ("error: %s\n", error->message); +#endif /* ENABLE_MIGRATION */ + + if (error) + { + g_error_free (error); + } + + /* If that still didn't work, create a new, empty one */ if (priv->page_setup == NULL) { priv->page_setup = gtk_page_setup_new (); @@ -452,7 +489,7 @@ ephy_embed_shell_set_print_settings (EphyEmbedShell *shell, priv->print_settings = settings ? settings : gtk_print_settings_new (); path = g_build_filename (ephy_dot_dir (), PRINT_SETTINGS_FILENAME, NULL); - ephy_print_utils_settings_to_file (settings, path, NULL); + gtk_print_settings_to_file (settings, path, NULL); g_free (path); } @@ -466,12 +503,17 @@ ephy_embed_shell_get_print_settings (EphyEmbedShell *shell) if (priv->print_settings == NULL) { + GError *error = NULL; char *path; path = g_build_filename (ephy_dot_dir (), PRINT_SETTINGS_FILENAME, NULL); - priv->print_settings = ephy_print_utils_settings_new_from_file (path, NULL); + priv->print_settings = gtk_print_settings_new_from_file (path, &error); g_free (path); + /* Note: the gtk print settings file format is the same as our legacy one, + * so no need to migrate here. + */ + if (priv->print_settings == NULL) { priv->print_settings = gtk_print_settings_new (); |