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.
This commit is contained in:
parent
0ffda1fe27
commit
ddf2f60e3f
4 changed files with 45 additions and 5 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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__ */
|
||||
|
|
Loading…
Reference in a new issue