From 14e56a441c3377613fe37bc2d16bf6592c1d2e52 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Sun, 25 Oct 2009 17:32:01 +0000 Subject: [shell] Don't exit with non-writable $HOME Allow running without out dot dir. Also, don't warn when loading the print settings and the file just doesn't exist yet. --- (limited to 'shell') diff --git a/shell/ev-application.c b/shell/ev-application.c index 2c6b509..812adae 100644 --- a/shell/ev-application.c +++ b/shell/ev-application.c @@ -884,10 +884,6 @@ ev_application_init (EvApplication *ev_application) "evince", NULL); - /* FIXME: why make this fatal? */ - if (!ev_dir_ensure_exists (ev_application->dot_dir, 0700, NULL)) - exit (1); - #ifdef G_OS_WIN32 { gchar *dir; @@ -998,8 +994,12 @@ ev_application_screensaver_disable (EvApplication *application) } const gchar * -ev_application_get_dot_dir (EvApplication *application) +ev_application_get_dot_dir (EvApplication *application, + gboolean create) { + if (create) + g_mkdir_with_parents (application->dot_dir, 0700); + return application->dot_dir; } diff --git a/shell/ev-application.h b/shell/ev-application.h index c08d3e8..831f8ec 100644 --- a/shell/ev-application.h +++ b/shell/ev-application.h @@ -76,7 +76,8 @@ const gchar *ev_application_get_filechooser_uri (EvApplication *application, GtkFileChooserAction action); void ev_application_screensaver_enable (EvApplication *application); void ev_application_screensaver_disable (EvApplication *application); -const gchar *ev_application_get_dot_dir (EvApplication *application); +const gchar *ev_application_get_dot_dir (EvApplication *application, + gboolean create); const gchar *ev_application_get_data_dir (EvApplication *application); G_END_DECLS diff --git a/shell/ev-window.c b/shell/ev-window.c index 042b4f9..8356ead 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -2617,24 +2617,25 @@ get_print_settings_file (void) { GKeyFile *print_settings_file; gchar *filename; + GError *error = NULL; print_settings_file = g_key_file_new (); - filename = g_build_filename (ev_application_get_dot_dir (EV_APP), - EV_PRINT_SETTINGS_FILE, NULL); - if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) { - GError *error = NULL; - - g_key_file_load_from_file (print_settings_file, - filename, - G_KEY_FILE_KEEP_COMMENTS | - G_KEY_FILE_KEEP_TRANSLATIONS, - &error); - if (error) { + filename = g_build_filename (ev_application_get_dot_dir (EV_APP, FALSE), + EV_PRINT_SETTINGS_FILE, NULL); + if (!g_key_file_load_from_file (print_settings_file, + filename, + G_KEY_FILE_KEEP_COMMENTS | + G_KEY_FILE_KEEP_TRANSLATIONS, + &error)) { + + /* Don't warn if the file simply doesn't exist */ + if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) g_warning ("%s", error->message); - g_error_free (error); - } + + g_error_free (error); } + g_free (filename); return print_settings_file; @@ -2645,15 +2646,15 @@ save_print_setting_file (GKeyFile *key_file) { gchar *filename; gchar *data; - gssize data_length; + gsize data_length; GError *error = NULL; - filename = g_build_filename (ev_application_get_dot_dir (EV_APP), + filename = g_build_filename (ev_application_get_dot_dir (EV_APP, TRUE), EV_PRINT_SETTINGS_FILE, NULL); - data = g_key_file_to_data (key_file, (gsize *)&data_length, NULL); + data = g_key_file_to_data (key_file, &data_length, NULL); g_file_set_contents (filename, data, data_length, &error); if (error) { - g_warning ("%s", error->message); + g_warning ("Failed to save print settings: %s", error->message); g_error_free (error); } g_free (data); @@ -3801,7 +3802,7 @@ ev_window_cmd_edit_toolbar_cb (GtkDialog *dialog, toolbar = EGG_EDITABLE_TOOLBAR (ev_window->priv->toolbar); egg_editable_toolbar_set_edit_mode (toolbar, FALSE); - toolbars_file = g_build_filename (ev_application_get_dot_dir (EV_APP), + toolbars_file = g_build_filename (ev_application_get_dot_dir (EV_APP, TRUE), "evince_toolbar.xml", NULL); egg_toolbars_model_save_toolbars (egg_editable_toolbar_get_model (toolbar), toolbars_file, "1.0"); @@ -5922,7 +5923,7 @@ get_toolbars_model (void) toolbars_model = egg_toolbars_model_new (); - toolbars_file = g_build_filename (ev_application_get_dot_dir (EV_APP), + toolbars_file = g_build_filename (ev_application_get_dot_dir (EV_APP, FALSE), "evince_toolbar.xml", NULL); toolbars_path = g_build_filename (ev_application_get_data_dir (EV_APP), "evince-toolbar.xml", NULL); @@ -5930,8 +5931,8 @@ get_toolbars_model (void) if (!egg_toolbars_model_load_toolbars (toolbars_model, toolbars_file)) { egg_toolbars_model_load_toolbars (toolbars_model, toolbars_path); + goto skip_conversion; } - g_free (toolbars_path); /* Open item doesn't exist anymore, * convert it to OpenRecent for compatibility @@ -5948,7 +5949,10 @@ get_toolbars_model (void) break; } } + + skip_conversion: g_free (toolbars_file); + g_free (toolbars_path); egg_toolbars_model_set_flags (toolbars_model, 0, EGG_TB_MODEL_NOT_REMOVABLE); -- cgit v0.9.1