]> www.fi.muni.cz Git - evince.git/commitdiff
[shell] Don't exit with non-writable $HOME
authorChristian Persch <chpe@gnome.org>
Sun, 25 Oct 2009 17:32:01 +0000 (18:32 +0100)
committerChristian Persch <chpe@gnome.org>
Sun, 25 Oct 2009 18:38:31 +0000 (19:38 +0100)
Allow running without out dot dir.
Also, don't warn when loading the print settings and the file just
doesn't exist yet.

shell/ev-application.c
shell/ev-application.h
shell/ev-window.c

index 2c6b5097296abb0790cdd89805b1c5cc6244248d..812adae4d89517ac96a488344011dc92db8170f1 100644 (file)
@@ -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;
 }
 
index c08d3e8ef18c789d89d8c2542ec0625671498159..831f8ec549024246ef586c1577f33f5e7f91e9ed 100644 (file)
@@ -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
index 042b4f93ba81988b881d3a85e37dc19287c6feec..8356ead31c3ac10a535273346e22dc5aa5ebd3d3 100644 (file)
@@ -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);