]> www.fi.muni.cz Git - evince.git/commitdiff
Move ev_dot_dir() from libdocument to shell, since it shouldn't be public
authorChristian Persch <chpe@src.gnome.org>
Mon, 26 Jan 2009 18:29:31 +0000 (18:29 +0000)
committerChristian Persch <chpe@src.gnome.org>
Mon, 26 Jan 2009 18:29:31 +0000 (18:29 +0000)
* libdocument/ev-file-helpers.c: (ev_dir_ensure_exists),
(ev_tmp_dir), (ev_file_helpers_init), (ev_file_helpers_shutdown):
* libdocument/ev-file-helpers.h:
* shell/ev-application.c: (ev_application_shutdown),
(ev_application_init), (ev_application_screensaver_disable),
(ev_application_save_print_settings),
(ev_application_set_page_setup):
* shell/ev-application.h:
* shell/ev-metadata-manager.c: (load_values),
(ev_metadata_manager_save): Move ev_dot_dir() from libdocument to
shell, since it shouldn't be public API. Bug #569120.

* libdocument/ev-file-helpers.c: (ev_tmp_filename): Use
g_get_prgname() instead of hardcoding "evince" for the tmpdir name.

svn path=/trunk/; revision=3383

ChangeLog
libdocument/ev-file-helpers.c
libdocument/ev-file-helpers.h
shell/ev-application.c
shell/ev-application.h
shell/ev-metadata-manager.c

index 6cf8b24417b957e55c338d881bab858abf993942..d025a11e5f43c7446697601845bdaaafa78a5838 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2009-01-26  Christian Persch  <chpe@gnome.org>
+
+       * libdocument/ev-file-helpers.c: (ev_dir_ensure_exists),
+       (ev_tmp_dir), (ev_file_helpers_init), (ev_file_helpers_shutdown):
+       * libdocument/ev-file-helpers.h:
+       * shell/ev-application.c: (ev_application_shutdown),
+       (ev_application_init), (ev_application_screensaver_disable),
+       (ev_application_save_print_settings),
+       (ev_application_set_page_setup):
+       * shell/ev-application.h:
+       * shell/ev-metadata-manager.c: (load_values),
+       (ev_metadata_manager_save): Move ev_dot_dir() from libdocument to
+       shell, since it shouldn't be public API. Bug #569120.
+
+       * libdocument/ev-file-helpers.c: (ev_tmp_filename): Use
+       g_get_prgname() instead of hardcoding "evince" for the tmpdir name.
+
 2009-01-25  Christian Persch  <chpe@gnome.org>
 
         Bug 569082 – use versioned directory for backends
index b2451ac5fd19a3130e115fedf6e933ef9faefd4d..9c65aa5e9e445d37e0ccd20a900082254b7035bb 100644 (file)
 
 #include "ev-file-helpers.h"
 
-static gchar *dot_dir = NULL;
 static gchar *tmp_dir = NULL;
 static gint   count = 0;
 
-static gboolean
-ensure_dir_exists (const char *dir)
+gboolean
+ev_dir_ensure_exists (const gchar *dir,
+                      int          mode)
 {
-       if (g_file_test (dir, G_FILE_TEST_IS_DIR))
-               return TRUE;
-       
-       if (g_mkdir_with_parents (dir, 488) == 0)
+       if (g_mkdir_with_parents (dir, mode) == 0)
                return TRUE;
 
        if (errno == EEXIST)
                return g_file_test (dir, G_FILE_TEST_IS_DIR);
        
-       g_warning ("Failed to create directory %s: %s", dir, strerror (errno));
+       g_warning ("Failed to create directory %s: %s", dir, g_strerror (errno));
        return FALSE;
 }
 
-const gchar *
-ev_dot_dir (void)
-{
-       if (dot_dir == NULL) {
-               gboolean exists;
-
-               dot_dir = g_build_filename (g_get_home_dir (),
-                                           ".gnome2",
-                                           "evince",
-                                           NULL);
-
-               exists = ensure_dir_exists (dot_dir);
-               if (!exists)
-                       exit (1);
-       }
-
-       return dot_dir;
-}
-
 const gchar *
 ev_tmp_dir (void)
 {
        if (tmp_dir == NULL) {
                gboolean exists;
-               gchar   *dirname;
+               gchar   *dirname, *prgname;
 
-               dirname = g_strdup_printf ("evince-%u", getpid ());
+                prgname = g_get_prgname ();
+               dirname = g_strdup_printf ("%s-%u", prgname ? prgname : "unknown", getpid ());
                tmp_dir = g_build_filename (g_get_tmp_dir (),
                                            dirname,
                                            NULL);
                g_free (dirname);
 
-               exists = ensure_dir_exists (tmp_dir);
+               exists = ev_dir_ensure_exists (tmp_dir, 0700);
                g_assert (exists);
        }
 
@@ -107,9 +86,6 @@ ev_file_helpers_shutdown (void)
                g_rmdir (tmp_dir);
 
        g_free (tmp_dir);
-       g_free (dot_dir);
-
-       dot_dir = NULL;
        tmp_dir = NULL;
 }
 
index 2c27b389c4475095075c1282dde89298c177e4d7..51d763db75b5ff2917eccd7d6259ee9786102dd4 100644 (file)
@@ -36,14 +36,15 @@ typedef enum {
        EV_COMPRESSION_GZIP
 } EvCompressionType;
 
-const gchar *ev_dot_dir               (void);
-
 const gchar *ev_tmp_dir               (void);
 
 void         ev_file_helpers_init     (void);
 
 void         ev_file_helpers_shutdown (void);
 
+gboolean     ev_dir_ensure_exists     (const gchar       *dir,
+                                       int                mode);
+
 GFile       *ev_tmp_file_get          (const gchar       *prefix);
 gchar       *ev_tmp_filename          (const char        *prefix);
 void         ev_tmp_filename_unlink   (const gchar       *filename);
index bfd3f4ecff47ef0178b1fc9d6f7f7d52f0e097c3..4164d0b92c57a26729e955a8033d6d1094ad6a66 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <config.h>
 
+#include <stdlib.h>
 #include <string.h>
 
 #include <glib.h>
@@ -52,8 +53,8 @@ static void ev_application_save_print_settings      (EvApplication *application)
 struct _EvApplication {
        GObject base_instance;
 
+       gchar *dot_dir;
        gchar *accel_map_file;
-       
        gchar *toolbars_file;
 
        EggToolbarsModel *toolbars_model;
@@ -731,7 +732,11 @@ ev_application_shutdown (EvApplication *application)
        }
 #endif /* ENABLE_DBUS */
        
+        g_free (application->dot_dir);
+        application->dot_dir = NULL;
        g_free (application->last_chooser_uri);
+        application->last_chooser_uri = NULL;
+
        g_object_unref (application);
        
        gtk_main_quit ();
@@ -750,6 +755,15 @@ ev_application_init (EvApplication *ev_application)
        
        ev_application_init_session (ev_application);
 
+        ev_application->dot_dir = g_build_filename (g_get_home_dir (),
+                                                    ".gnome2",
+                                                    "evince",
+                                                    NULL);
+
+        /* FIXME: why make this fatal? */
+        if (!ev_dir_ensure_exists (ev_application->dot_dir, 0700))
+                exit (1);
+
        home_dir = g_get_home_dir ();
        if (home_dir) {
                ev_application->accel_map_file = g_build_filename (home_dir,
@@ -763,7 +777,7 @@ ev_application_init (EvApplication *ev_application)
        ev_application->toolbars_model = egg_toolbars_model_new ();
 
        ev_application->toolbars_file = g_build_filename
-                       (ev_dot_dir (), "evince_toolbar.xml", NULL);
+                       (ev_application->dot_dir, "evince_toolbar.xml", NULL);
 
        egg_toolbars_model_load_names (ev_application->toolbars_model,
                                       DATADIR "/evince-toolbar.xml");
@@ -893,7 +907,7 @@ ev_application_get_print_settings_file (EvApplication *application)
 
        application->print_settings_file = g_key_file_new ();
        
-       filename = g_build_filename (ev_dot_dir (), EV_PRINT_SETTINGS_FILE, NULL);
+       filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
        if (g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
                GError *error = NULL;
 
@@ -934,7 +948,7 @@ ev_application_save_print_settings (EvApplication *application)
                                            key_file,
                                            EV_PAGE_SETUP_GROUP);
        
-       filename = g_build_filename (ev_dot_dir (), EV_PRINT_SETTINGS_FILE, NULL);
+       filename = g_build_filename (ev_application_get_dot_dir (application), EV_PRINT_SETTINGS_FILE, NULL);
        data = g_key_file_to_data (key_file, (gsize *)&data_length, NULL);
        g_file_set_contents (filename, data, data_length, &error);
        if (error) {
@@ -1022,3 +1036,9 @@ ev_application_set_page_setup (EvApplication *application,
        application->page_setup = g_object_ref (page_setup);
        gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
 }
+
+const gchar *
+ev_application_get_dot_dir (EvApplication   *application)
+{
+       return application->dot_dir;
+}
index 1dfa321cb8799e5251a17c5135b379a96af126a8..1b96ca57b57f2a10da3faa24319de2294d897459 100644 (file)
@@ -92,6 +92,7 @@ void              ev_application_set_print_settings  (EvApplication   *applicati
 GtkPageSetup     *ev_application_get_page_setup      (EvApplication   *application);
 void              ev_application_set_page_setup      (EvApplication   *application,
                                                      GtkPageSetup    *page_setup);
+const gchar      *ev_application_get_dot_dir         (EvApplication   *application);
 
 G_END_DECLS
 
index ce164ad56a3284f85e1ad80653d5221f4cc1b62e..c5235fafd2a5829781db95a450e3ed27a4b23215 100644 (file)
@@ -37,6 +37,7 @@
 #include <libxml/xmlreader.h>
 
 #include "ev-metadata-manager.h"
+#include "ev-application.h"
 #include "ev-file-helpers.h"
 
 #define METADATA_FILE  "ev-metadata.xml"
@@ -271,7 +272,7 @@ load_values ()
        xmlKeepBlanksDefault (0);
 
        /* FIXME: file locking - Paolo */
-       file_name = g_build_filename (ev_dot_dir (), METADATA_FILE, NULL);
+       file_name = g_build_filename (ev_application_get_dot_dir (EV_APP), METADATA_FILE, NULL);
        if (!g_file_test (file_name, G_FILE_TEST_EXISTS))
        {
                g_free (file_name);
@@ -670,7 +671,7 @@ ev_metadata_manager_save (gpointer data)
                          (GHFunc)save_item, root);        
 
        /* FIXME: lock file - Paolo */
-       file_name = g_build_filename (ev_dot_dir (), METADATA_FILE, NULL);
+       file_name = g_build_filename (ev_application_get_dot_dir (EV_APP), METADATA_FILE, NULL);
        xmlSaveFormatFile (file_name, doc, 1);
        g_free (file_name);