From ddf2f60e3f485d8b33d4e7b6c1eef86974ab6c04 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Thu, 9 Apr 2009 19:28:36 +0200 Subject: [PATCH] Implement "-c" or "--config" to specify a different config folder If this option is specified the folder is used in place of the default ~/.config/midori including extension settings. --- midori/main.c | 17 +++++++++++++---- midori/midori-extension.c | 2 +- midori/sokoke.c | 28 ++++++++++++++++++++++++++++ midori/sokoke.h | 3 +++ 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/midori/main.c b/midori/main.c index 6d92ba3b..7943b970 100644 --- a/midori/main.c +++ b/midori/main.c @@ -65,10 +65,7 @@ typedef enum static gchar* build_config_filename (const gchar* filename) { - static gchar* path = NULL; - - if (!path) - path = g_build_filename (g_get_user_config_dir (), PACKAGE_NAME, NULL); + const gchar* path = sokoke_set_config_dir (NULL); g_mkdir_with_parents (path, 0700); return g_build_filename (path, filename, NULL); } @@ -1325,6 +1322,7 @@ int main (int argc, char** argv) { + gchar* config; gboolean run; gboolean version; gchar** uris; @@ -1333,6 +1331,8 @@ main (int argc, GError* error; GOptionEntry entries[] = { + { "config", 'c', 0, G_OPTION_ARG_FILENAME, &config, + N_("Use FOLDER as configuration folder"), N_("FOLDER") }, { "run", 'r', 0, G_OPTION_ARG_NONE, &run, N_("Run the specified filename as javascript"), NULL }, { "version", 'V', 0, G_OPTION_ARG_NONE, &version, @@ -1373,6 +1373,7 @@ main (int argc, #endif /* Parse cli options */ + config = NULL; run = FALSE; version = FALSE; uris = NULL; @@ -1411,6 +1412,14 @@ main (int argc, if (run) return midori_run_script (uris ? *uris : NULL); + if (config && !g_path_is_absolute (config)) + { + g_critical (_("The specified configuration folder is invalid.")); + return 1; + } + sokoke_set_config_dir (config); + g_free (config); + #if HAVE_HILDON osso_context = osso_initialize (PACKAGE_NAME, PACKAGE_VERSION, FALSE, NULL); diff --git a/midori/midori-extension.c b/midori/midori-extension.c index 99030c34..0bbcfef7 100644 --- a/midori/midori-extension.c +++ b/midori/midori-extension.c @@ -474,7 +474,7 @@ midori_extension_get_config_dir (MidoriExtension* extension) if (!extension->priv->config_dir) extension->priv->config_dir = g_build_filename ( - g_get_user_config_dir (), PACKAGE_NAME, "extensions", + sokoke_set_config_dir (NULL), "extensions", extension->priv->name, NULL); return extension->priv->config_dir; diff --git a/midori/sokoke.c b/midori/sokoke.c index d0731931..c9639ca5 100644 --- a/midori/sokoke.c +++ b/midori/sokoke.c @@ -801,3 +801,31 @@ sokoke_register_stock_items (void) gtk_icon_factory_add_default (factory); g_object_unref (factory); } + +/** + * sokoke_set_config_dir: + * @new_config_dir: an absolute path, or %NULL + * + * Retrieves and/ or sets the base configuration folder. + * + * Return value: the configuration folder, or %NULL + **/ +const gchar* +sokoke_set_config_dir (const gchar* new_config_dir) +{ + static gchar* config_dir = NULL; + + if (config_dir) + return config_dir; + + if (!new_config_dir) + config_dir = g_build_filename (g_get_user_config_dir (), + PACKAGE_NAME, NULL); + else + { + g_return_val_if_fail (g_path_is_absolute (new_config_dir), NULL); + katze_assign (config_dir, g_strdup (new_config_dir)); + } + + return config_dir; +} diff --git a/midori/sokoke.h b/midori/sokoke.h index 4212f7e6..79eec084 100644 --- a/midori/sokoke.h +++ b/midori/sokoke.h @@ -127,4 +127,7 @@ sokoke_time_t_to_julian (const time_t* timestamp); void sokoke_register_stock_items (void); +const gchar* +sokoke_set_config_dir (const gchar* new_config_dir); + #endif /* !__SOKOKE_H__ */ -- 2.39.5