[Xfce4-commits] <midori:master> Rename Paths.get_config_dir/filename _for_reading/writing

Christian Dywan noreply at xfce.org
Fri Sep 28 20:16:03 CEST 2012


Updating branch refs/heads/master
         to a363a6dcc05113d874e8dd1a4062b9df51d3873f (commit)
       from 47df922547169395f60ef72676df3a1b91e45f2d (commit)

commit a363a6dcc05113d874e8dd1a4062b9df51d3873f
Author: Christian Dywan <christian at twotoasts.de>
Date:   Fri Sep 28 19:23:07 2012 +0200

    Rename Paths.get_config_dir/filename _for_reading/writing
    
    And document the expected behavior.

 katze/midori-paths.vala   |   16 +++++++++++---
 midori/main.c             |   48 ++++++++++++++++++++++----------------------
 midori/midori-app.c       |    2 +-
 midori/midori-bookmarks.c |    4 +-
 midori/midori-extension.c |    2 +-
 midori/midori-view.c      |    2 +-
 midori/sokoke.c           |    2 +-
 7 files changed, 42 insertions(+), 34 deletions(-)

diff --git a/katze/midori-paths.vala b/katze/midori-paths.vala
index d60f242..0792559 100644
--- a/katze/midori-paths.vala
+++ b/katze/midori-paths.vala
@@ -41,12 +41,14 @@ namespace Midori {
         static string? user_data_dir = null;
         static string? tmp_dir = null;
 
-        public static string get_readonly_config_dir () {
+        public static string get_config_dir_for_reading () {
             assert (mode != RuntimeMode.UNDEFINED);
             return readonly_dir ?? config_dir;
         }
 
-        public static string get_readonly_config_filename (string filename) {
+        /* returns the path to a user configuration file whose contents should not be modified.
+        to get the path to save settings, use get_config_filename() */
+        public static string get_config_filename_for_reading (string filename) {
             assert (mode != RuntimeMode.UNDEFINED);
             return Path.build_path (Path.DIR_SEPARATOR_S,
                 readonly_dir ?? config_dir, filename);
@@ -92,12 +94,15 @@ namespace Midori {
             }
         }
 
-        public static unowned string get_config_dir () {
+        public static unowned string get_config_dir_for_writing () {
             assert (config_dir != null);
             return config_dir;
         }
 
-        public static string get_config_filename (string filename) {
+        /* returns the path to a user configuration file to which it is permitted to write.
+        this is also necessary for files whose state is synchronized to disk by a manager,
+        e.g. cookies. */
+        public static string get_config_filename_for_writing (string filename) {
             assert (mode != RuntimeMode.UNDEFINED);
             assert (config_dir != null);
             return Path.build_path (Path.DIR_SEPARATOR_S, config_dir, filename);
@@ -198,6 +203,8 @@ namespace Midori {
             #endif
         }
 
+        /* returns the path to a file containing read-only data installed with the application
+        if @res is true, looks in the midori resource folder specifically */
         public static string get_data_filename (string filename, bool res) {
             assert (command_line != null);
             string res1 = res ? PACKAGE_NAME : "";
@@ -220,6 +227,7 @@ namespace Midori {
             #endif
         }
 
+        /* returns the path to a file containing system default configuration */
         public static string get_preset_filename (string? folder, string filename) {
             assert (config_dir != null);
 
diff --git a/midori/main.c b/midori/main.c
index a23f274..0b1897f 100644
--- a/midori/main.c
+++ b/midori/main.c
@@ -56,7 +56,7 @@ static MidoriWebSettings*
 settings_and_accels_new (gchar*** extensions)
 {
     MidoriWebSettings* settings = midori_web_settings_new ();
-    gchar* config_file = midori_paths_get_readonly_config_filename ("config");
+    gchar* config_file = midori_paths_get_config_filename_for_reading ("config");
     GKeyFile* key_file = g_key_file_new ();
     GError* error = NULL;
     GObjectClass* class;
@@ -149,7 +149,7 @@ settings_and_accels_new (gchar*** extensions)
     g_key_file_free (key_file);
 
     /* Load accelerators */
-    katze_assign (config_file, midori_paths_get_config_filename ("accels"));
+    katze_assign (config_file, midori_paths_get_config_filename_for_reading ("accels"));
     if (g_access (config_file, F_OK) != 0)
         katze_assign (config_file, midori_paths_get_preset_filename (NULL, "accels"));
     gtk_accel_map_load (config_file);
@@ -331,7 +331,7 @@ search_engines_new_from_file (const gchar* filename,
 static KatzeArray*
 search_engines_new_from_folder (GString* error_messages)
 {
-    gchar* config_file = midori_paths_get_config_filename ("search");
+    gchar* config_file = midori_paths_get_config_filename_for_reading ("search");
     GError* error = NULL;
     KatzeArray* search_engines;
 
@@ -477,7 +477,7 @@ midori_history_initialize (KatzeArray*  array,
                       "COMMIT;",
                       NULL, NULL, errmsg);
 
-    bookmarks_filename = midori_paths_get_config_filename ("bookmarks_v2.db");
+    bookmarks_filename = midori_paths_get_config_filename_for_writing ("bookmarks_v2.db");
     sql = g_strdup_printf ("ATTACH DATABASE '%s' AS bookmarks", bookmarks_filename);
     g_free (bookmarks_filename);
     sqlite3_exec (db, sql, NULL, NULL, errmsg);
@@ -521,7 +521,7 @@ settings_notify_cb (MidoriWebSettings* settings,
     if (pspec && midori_settings_delay_saving (MIDORI_SETTINGS (settings), pspec->name))
         return;
 
-    config_file = midori_paths_get_config_filename ("config");
+    config_file = midori_paths_get_config_filename_for_writing ("config");
     if (!settings_save_to_file (settings, app, config_file, &error))
     {
         g_warning (_("The configuration couldn't be saved. %s"), error->message);
@@ -536,7 +536,7 @@ accel_map_changed_cb (GtkAccelMap*    accel_map,
                       guint           accel_key,
                       GdkModifierType accel_mods)
 {
-    gchar* config_file = midori_paths_get_config_filename ("accels");
+    gchar* config_file = midori_paths_get_config_filename_for_writing ("accels");
     gtk_accel_map_save (config_file);
     g_free (config_file);
 }
@@ -546,7 +546,7 @@ midori_search_engines_modify_cb (KatzeArray* array,
                                  gpointer    item,
                                  KatzeArray* search_engines)
 {
-    gchar* config_file = midori_paths_get_config_filename ("search");
+    gchar* config_file = midori_paths_get_config_filename_for_writing ("search");
     GError* error = NULL;
     if (!search_engines_save_to_file (search_engines, config_file, &error))
     {
@@ -581,7 +581,7 @@ static void
 midori_trash_remove_item_cb (KatzeArray* trash,
                              GObject*    item)
 {
-    gchar* config_file = midori_paths_get_config_filename ("tabtrash.xbel");
+    gchar* config_file = midori_paths_get_config_filename_for_writing ("tabtrash.xbel");
     GError* error = NULL;
     midori_trash_add_item_no_save_cb (trash, item);
     if (!midori_array_to_file (trash, config_file, "xbel", &error))
@@ -746,7 +746,7 @@ static guint save_timeout = 0;
 static gboolean
 midori_session_save_timeout_cb (KatzeArray* session)
 {
-    gchar* config_file = midori_paths_get_config_filename ("session.xbel");
+    gchar* config_file = midori_paths_get_config_filename_for_writing ("session.xbel");
     GError* error = NULL;
     if (!midori_array_to_file (session, config_file, "xbel", &error))
     {
@@ -778,7 +778,7 @@ static void
 midori_app_quit_cb (MidoriBrowser* browser,
                     KatzeArray*    session)
 {
-    gchar* config_file = midori_paths_get_config_filename ("running");
+    gchar* config_file = midori_paths_get_config_filename_for_writing ("running");
     g_unlink (config_file);
     g_free (config_file);
 
@@ -1022,7 +1022,7 @@ midori_load_soup_session (gpointer settings)
         G_CALLBACK (midori_soup_session_settings_accept_language_cb), settings);
 
     soup_session_add_feature (session, SOUP_SESSION_FEATURE (
-        midori_hsts_new (midori_paths_get_readonly_config_filename ("hsts"))));
+        midori_hsts_new (midori_paths_get_config_filename_for_reading ("hsts"))));
 
     midori_soup_session_debug (session);
 
@@ -1155,7 +1155,7 @@ midori_load_soup_session_full (gpointer settings)
 
     midori_load_soup_session (settings);
 
-    config_file = midori_paths_get_config_filename ("logins");
+    config_file = midori_paths_get_config_filename_for_writing ("logins");
     feature = g_object_new (KATZE_TYPE_HTTP_AUTH, "filename", config_file, NULL);
     soup_session_add_feature (session, feature);
     g_object_unref (feature);
@@ -1165,7 +1165,7 @@ midori_load_soup_session_full (gpointer settings)
     soup_session_add_feature (session, SOUP_SESSION_FEATURE (jar));
     g_object_unref (jar);
 
-    katze_assign (config_file, midori_paths_get_config_filename ("cookies.db"));
+    katze_assign (config_file, midori_paths_get_config_filename_for_writing ("cookies.db"));
     have_new_cookies = g_access (config_file, F_OK) == 0;
     feature = g_object_new (KATZE_TYPE_HTTP_COOKIES_SQLITE, NULL);
     g_object_set_data_full (G_OBJECT (feature), "filename",
@@ -1175,7 +1175,7 @@ midori_load_soup_session_full (gpointer settings)
 
     if (!have_new_cookies)
     {
-        katze_assign (config_file, midori_paths_get_config_filename ("cookies.txt"));
+        katze_assign (config_file, midori_paths_get_config_filename_for_writing ("cookies.txt"));
         if (g_access (config_file, F_OK) == 0)
         {
             g_message ("Importing cookies from txt to sqlite3");
@@ -1278,7 +1278,7 @@ midori_browser_action_last_session_activate_cb (GtkAction*     action,
                                                 MidoriBrowser* browser)
 {
     KatzeArray* old_session = katze_array_new (KATZE_TYPE_ITEM);
-    gchar* config_file = midori_paths_get_readonly_config_filename ("session.old.xbel");
+    gchar* config_file = midori_paths_get_config_filename_for_reading ("session.old.xbel");
     GError* error = NULL;
     if (midori_array_from_file (old_session, config_file, "xbel", &error))
     {
@@ -1320,7 +1320,7 @@ midori_load_session (gpointer data)
     g_signal_connect_after (katze_object_get_object (app, "settings"), "notify",
         G_CALLBACK (settings_notify_cb), app);
 
-    config_file = midori_paths_get_readonly_config_filename ("session.old.xbel");
+    config_file = midori_paths_get_config_filename_for_reading ("session.old.xbel");
     if (g_access (config_file, F_OK) == 0)
     {
         GtkActionGroup* action_group = midori_browser_get_action_group (browser);
@@ -1332,7 +1332,7 @@ midori_load_session (gpointer data)
     midori_app_add_browser (app, browser);
     gtk_widget_show (GTK_WIDGET (browser));
 
-    katze_assign (config_file, midori_paths_get_readonly_config_filename ("accels"));
+    katze_assign (config_file, midori_paths_get_config_filename_for_reading ("accels"));
     g_signal_connect_after (gtk_accel_map_get (), "changed",
         G_CALLBACK (accel_map_changed_cb), NULL);
 
@@ -1376,8 +1376,8 @@ midori_load_session (gpointer data)
 
     g_object_unref (settings);
     g_object_unref (_session);
+    g_free (config_file);
 
-    katze_assign (config_file, midori_paths_get_readonly_config_filename ("session.xbel"));
     g_signal_connect_after (browser, "add-tab",
         G_CALLBACK (midori_browser_session_cb), session);
     g_signal_connect_after (browser, "remove-tab",
@@ -1452,7 +1452,7 @@ midori_remove_config_file (gint         clear_prefs,
 {
     if ((clear_prefs & flag) == flag)
     {
-        gchar* config_file = midori_paths_get_config_filename (filename);
+        gchar* config_file = midori_paths_get_config_filename_for_writing (filename);
         g_unlink (config_file);
         g_free (config_file);
     }
@@ -1652,10 +1652,10 @@ static void
 midori_clear_saved_logins_cb (void)
 {
     sqlite3* db;
-    gchar* path = g_build_filename (midori_paths_get_config_dir (), "logins", NULL);
+    gchar* path = g_build_filename (midori_paths_get_config_dir_for_writing (), "logins", NULL);
     g_unlink (path);
     /* Form History database, written by the extension */
-    katze_assign (path, g_build_filename (midori_paths_get_config_dir (),
+    katze_assign (path, g_build_filename (midori_paths_get_config_dir_for_writing (),
         "extensions", MIDORI_MODULE_PREFIX "formhistory." G_MODULE_SUFFIX, "forms.db", NULL));
     if (sqlite3_open (path, &db) == SQLITE_OK)
     {
@@ -2217,7 +2217,6 @@ main (int    argc,
         midori_paths_init (MIDORI_RUNTIME_MODE_NORMAL, config);
 
     app = midori_app_new ();
-    katze_assign (config, g_strdup (midori_paths_get_config_dir ()));
     midori_startup_timer ("App created: \t%f");
 
     /* FIXME: The app might be 'running' but actually showing a dialog
@@ -2258,6 +2257,7 @@ main (int    argc,
         return 1;
     }
 
+    katze_assign (config, g_strdup (midori_paths_get_config_dir_for_writing ()));
     katze_mkdir_with_parents (config, 0700);
     /* Load configuration file */
     error_messages = g_string_new (NULL);
@@ -2297,7 +2297,7 @@ main (int    argc,
     #if HAVE_LIBXML
     if (load_on_startup >= MIDORI_STARTUP_LAST_OPEN_PAGES)
     {
-        katze_assign (config_file, midori_paths_get_readonly_config_filename ("session.xbel"));
+        katze_assign (config_file, midori_paths_get_config_filename_for_reading ("session.xbel"));
         error = NULL;
         if (!midori_array_from_file (_session, config_file, "xbel", &error))
         {
@@ -2512,7 +2512,7 @@ main (int    argc,
     load_on_startup = katze_object_get_int (settings, "load-on-startup");
     if (load_on_startup < MIDORI_STARTUP_LAST_OPEN_PAGES)
     {
-        katze_assign (config_file, midori_paths_get_config_filename ("session.xbel"));
+        katze_assign (config_file, midori_paths_get_config_filename_for_writing ("session.xbel"));
         g_unlink (config_file);
     }
 
diff --git a/midori/midori-app.c b/midori/midori-app.c
index e6b5a20..2344df4 100644
--- a/midori/midori-app.c
+++ b/midori/midori-app.c
@@ -751,7 +751,7 @@ midori_app_create_instance (MidoriApp* app)
 
     {
         #if HAVE_UNIQUE
-        const gchar* config = midori_paths_get_config_dir ();
+        const gchar* config = midori_paths_get_config_dir_for_reading ();
         gchar* name_hash;
         name_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, config, -1);
         katze_assign (app_name, g_strconcat ("midori", "_", name_hash, NULL));
diff --git a/midori/midori-bookmarks.c b/midori/midori-bookmarks.c
index bbcb3ed..381749d 100644
--- a/midori/midori-bookmarks.c
+++ b/midori/midori-bookmarks.c
@@ -143,9 +143,9 @@ midori_bookmarks_initialize (KatzeArray*  array,
 
     g_return_val_if_fail (errmsg != NULL, NULL);
 
-    oldfile = g_build_filename (midori_paths_get_config_dir (), "bookmarks.db", NULL);
+    oldfile = g_build_filename (midori_paths_get_config_dir_for_writing (), "bookmarks.db", NULL);
     oldfile_exists = g_access (oldfile, F_OK) == 0;
-    newfile = g_build_filename (midori_paths_get_config_dir (), "bookmarks_v2.db", NULL);
+    newfile = g_build_filename (midori_paths_get_config_dir_for_writing (), "bookmarks_v2.db", NULL);
     newfile_did_exist = g_access (newfile, F_OK) == 0;
 
     /* sqlite3_open will create the file if it did not exists already */
diff --git a/midori/midori-extension.c b/midori/midori-extension.c
index 663d88d..39643b7 100644
--- a/midori/midori-extension.c
+++ b/midori/midori-extension.c
@@ -751,7 +751,7 @@ midori_extension_get_config_dir (MidoriExtension* extension)
         gchar* filename = g_object_get_data (G_OBJECT (extension), "filename");
         if (filename != NULL)
             extension->priv->config_dir = g_build_filename (
-                midori_paths_get_config_dir (), "extensions", filename, NULL);
+                midori_paths_get_config_dir_for_writing (), "extensions", filename, NULL);
         else
             extension->priv->config_dir = NULL;
     }
diff --git a/midori/midori-view.c b/midori/midori-view.c
index cb392f0..16c04e5 100644
--- a/midori/midori-view.c
+++ b/midori/midori-view.c
@@ -4114,7 +4114,7 @@ midori_view_set_uri (MidoriView*  view,
                     "<p>cache: <code>%s</code></p>"
                     "<p>tmp: <code>%s</code></p>"
                     "</body>",
-                    uri, midori_paths_get_config_dir (), res_dir,
+                    uri, midori_paths_get_config_dir_for_reading (), res_dir,
                     lib_dir, midori_paths_get_cache_dir (), midori_paths_get_tmp_dir ());
                 g_free (res_dir);
                 g_free (lib_dir);
diff --git a/midori/sokoke.c b/midori/sokoke.c
index dc7506b..1257190 100644
--- a/midori/sokoke.c
+++ b/midori/sokoke.c
@@ -507,7 +507,7 @@ sokoke_spawn_app (const gchar* uri,
     gchar* argument;
     if (private)
     {
-        gchar* config_quoted = g_shell_quote (midori_paths_get_config_dir ());
+        gchar* config_quoted = g_shell_quote (midori_paths_get_config_dir_for_reading ());
         argument = g_strconcat ("-c ", config_quoted,
                                 " -p ", uri_quoted, NULL);
     }


More information about the Xfce4-commits mailing list