#include "midori-app.h"
#include <katze/katze.h>
+#include "sokoke.h"
+#include <glib/gi18n.h>
G_DEFINE_TYPE (MidoriExtension, midori_extension, G_TYPE_OBJECT);
gchar* config_dir;
GList* lsettings;
GHashTable* settings;
+ GKeyFile* key_file;
};
typedef struct
MidoriApp* app)
{
GList* lsettings = g_list_first (extension->priv->lsettings);
+
+ /* If a configuration directory was requested before activation we
+ assume we should load and save settings. This is a detail that
+ extension writers shouldn't worry about. */
+ extension->priv->key_file = lsettings && extension->priv->config_dir
+ ? g_key_file_new () : NULL;
+ if (extension->priv->key_file)
+ {
+ gchar* config_file;
+ GError* error = NULL;
+
+ config_file = g_build_filename (extension->priv->config_dir, "config", NULL);
+ if (!g_key_file_load_from_file (extension->priv->key_file, config_file,
+ G_KEY_FILE_KEEP_COMMENTS, &error))
+ {
+ if (error->code != G_FILE_ERROR_NOENT)
+ printf (_("The configuration of the extension '%s' couldn't be loaded: %s\n"),
+ extension->priv->name, error->message);
+ g_error_free (error);
+ }
+ }
+
while (lsettings)
{
MESettingString* setting = (MESettingString*)lsettings->data;
if (setting->type == G_TYPE_BOOLEAN)
{
MESettingBoolean* setting_ = (MESettingBoolean*)setting;
- setting_->value = setting_->default_value;
+ if (extension->priv->key_file)
+ setting_->value = sokoke_key_file_get_boolean_default (
+ extension->priv->key_file,
+ "settings", setting->name, setting_->default_value, NULL);
+ else
+ setting_->value = setting_->default_value;
}
else if (setting->type == G_TYPE_INT)
{
MESettingInteger* setting_ = (MESettingInteger*)setting;
- setting_->value = setting_->default_value;
+ if (extension->priv->key_file)
+ setting_->value = sokoke_key_file_get_integer_default (
+ extension->priv->key_file,
+ "settings", setting->name, setting_->default_value, NULL);
+ else
+ setting_->value = setting_->default_value;
}
else if (setting->type == G_TYPE_STRING)
- setting->value = g_strdup (setting->default_value);
+ {
+ if (extension->priv->key_file)
+ setting->value = sokoke_key_file_get_string_default (
+ extension->priv->key_file,
+ "settings", setting->name, setting->default_value, NULL);
+ else
+ setting->value = g_strdup (setting->default_value);
+ }
else
g_assert_not_reached ();
extension->priv->lsettings = NULL;
extension->priv->settings = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, me_setting_free);
+ extension->priv->key_file = NULL;
g_signal_connect (extension, "activate",
G_CALLBACK (midori_extension_activate_cb), NULL);
katze_assign (extension->priv->config_dir, NULL);
g_list_free (extension->priv->lsettings);
g_hash_table_destroy (extension->priv->settings);
+ if (extension->priv->key_file)
+ g_key_file_free (extension->priv->key_file);
}
static void
* files specific to the extension. For that purpose the 'name'
* of the extension is actually part of the path.
*
- * The path is actually created if it doesn't already exist.
+ * If settings are installed on the extension, they will be
+ * loaded from and saved to a file "config" in this path.
*
* Return value: a path, such as ~/.config/midori/extensions/name
**/
g_get_user_config_dir (), PACKAGE_NAME, "extensions",
extension->priv->name, NULL);
- g_mkdir_with_parents (extension->priv->config_dir, 0700);
return extension->priv->config_dir;
}
me_setting_type (setting, G_TYPE_BOOLEAN, return);
setting->value = value;
+ if (extension->priv->key_file)
+ {
+ GError* error = NULL;
+ /* FIXME: Handle readonly folder/ file */
+ gchar* config_file = g_build_filename (extension->priv->config_dir,
+ "config", NULL);
+ g_mkdir_with_parents (extension->priv->config_dir, 0700);
+ g_key_file_set_boolean (extension->priv->key_file,
+ "settings", name, value);
+ sokoke_key_file_save_to_file (extension->priv->key_file, config_file, &error);
+ if (error)
+ {
+ printf (_("The configuration of the extension '%s' couldn't be saved: %s\n"),
+ extension->priv->name, error->message);
+ g_error_free (error);
+ }
+ }
}
/**
me_setting_type (setting, G_TYPE_INT, return);
setting->value = value;
+ if (extension->priv->key_file)
+ {
+ GError* error = NULL;
+ /* FIXME: Handle readonly folder/ file */
+ gchar* config_file = g_build_filename (extension->priv->config_dir,
+ "config", NULL);
+ g_mkdir_with_parents (extension->priv->config_dir, 0700);
+ g_key_file_set_integer (extension->priv->key_file,
+ "settings", name, value);
+ sokoke_key_file_save_to_file (extension->priv->key_file, config_file, &error);
+ if (error)
+ {
+ printf (_("The configuration of the extension '%s' couldn't be saved: %s\n"),
+ extension->priv->name, error->message);
+ g_error_free (error);
+ }
+ }
}
/**
me_setting_type (setting, G_TYPE_STRING, return);
katze_assign (setting->value, g_strdup (value));
+ if (extension->priv->key_file)
+ {
+ GError* error = NULL;
+ /* FIXME: Handle readonly folder/ file */
+ gchar* config_file = g_build_filename (extension->priv->config_dir,
+ "config", NULL);
+ g_mkdir_with_parents (extension->priv->config_dir, 0700);
+ g_key_file_set_string (extension->priv->key_file,
+ "settings", name, value);
+ sokoke_key_file_save_to_file (extension->priv->key_file, config_file, &error);
+ if (error)
+ {
+ printf (_("The configuration of the extension '%s' couldn't be saved: %s\n"),
+ extension->priv->name, error->message);
+ g_error_free (error);
+ }
+ }
}