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);
}
main (int argc,
char** argv)
{
+ gchar* config;
gboolean run;
gboolean version;
gchar** uris;
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,
#endif
/* Parse cli options */
+ config = NULL;
run = FALSE;
version = FALSE;
uris = NULL;
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);
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;
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;
+}