Dissolve keyfile "default" wrappers into Midori.Extension

This commit is contained in:
Christian Dywan 2012-09-09 21:40:46 +02:00
parent f715e11ebf
commit 1ad675e24e
3 changed files with 18 additions and 122 deletions

View file

@ -341,29 +341,32 @@ midori_extension_activate_cb (MidoriExtension* extension,
if (setting->type == G_TYPE_BOOLEAN)
{
MESettingBoolean* setting_ = (MESettingBoolean*)setting;
if (extension->priv->key_file)
setting_->value = sokoke_key_file_get_boolean_default (
extension->priv->key_file,
"settings", setting->name, setting_->default_value, NULL);
if (extension->priv->key_file
&& g_key_file_has_key (extension->priv->key_file, "settings", setting_->name, NULL))
setting_->value = g_key_file_get_boolean (extension->priv->key_file,
"settings", setting->name, NULL);
else
setting_->value = setting_->default_value;
}
else if (setting->type == G_TYPE_INT)
{
MESettingInteger* setting_ = (MESettingInteger*)setting;
if (extension->priv->key_file)
setting_->value = sokoke_key_file_get_integer_default (
extension->priv->key_file,
"settings", setting->name, setting_->default_value, NULL);
if (extension->priv->key_file
&& g_key_file_has_key (extension->priv->key_file, "settings", setting_->name, NULL))
setting_->value = g_key_file_get_integer (extension->priv->key_file,
"settings", setting_->name, NULL);
else
setting_->value = setting_->default_value;
}
else if (setting->type == G_TYPE_STRING)
{
if (extension->priv->key_file)
setting->value = sokoke_key_file_get_string_default (
extension->priv->key_file,
"settings", setting->name, setting->default_value, NULL);
{
setting->value = g_key_file_get_string (
extension->priv->key_file, "settings", setting->name, NULL);
if (setting->value == NULL)
setting->value = setting->default_value;
}
else
setting->value = g_strdup (setting->default_value);
}
@ -372,10 +375,10 @@ midori_extension_activate_cb (MidoriExtension* extension,
MESettingStringList* setting_ = (MESettingStringList*)setting;
if (extension->priv->key_file)
{
setting_->value = sokoke_key_file_get_string_list_default (
extension->priv->key_file,
"settings", setting->name, &setting_->length,
setting_->default_value, &setting_->default_length, NULL);
setting_->value = g_key_file_get_string_list (extension->priv->key_file,
"settings", setting->name, &setting_->length, NULL);
if (setting_->value == NULL)
setting_->value = g_strdupv (setting_->default_value);
}
else
setting_->value = g_strdupv (setting_->default_value);

View file

@ -785,72 +785,6 @@ sokoke_xfce_header_new (const gchar* icon,
return NULL;
}
gchar*
sokoke_key_file_get_string_default (GKeyFile* key_file,
const gchar* group,
const gchar* key,
const gchar* default_value,
GError** error)
{
gchar* value = g_key_file_get_string (key_file, group, key, error);
return value == NULL ? g_strdup (default_value) : value;
}
gint
sokoke_key_file_get_integer_default (GKeyFile* key_file,
const gchar* group,
const gchar* key,
const gint default_value,
GError** error)
{
if (!g_key_file_has_key (key_file, group, key, NULL))
return default_value;
return g_key_file_get_integer (key_file, group, key, error);
}
gdouble
sokoke_key_file_get_double_default (GKeyFile* key_file,
const gchar* group,
const gchar* key,
const gdouble default_value,
GError** error)
{
if (!g_key_file_has_key (key_file, group, key, NULL))
return default_value;
return g_key_file_get_double (key_file, group, key, error);
}
gboolean
sokoke_key_file_get_boolean_default (GKeyFile* key_file,
const gchar* group,
const gchar* key,
const gboolean default_value,
GError** error)
{
if (!g_key_file_has_key (key_file, group, key, NULL))
return default_value;
return g_key_file_get_boolean (key_file, group, key, error);
}
gchar**
sokoke_key_file_get_string_list_default (GKeyFile* key_file,
const gchar* group,
const gchar* key,
gsize* length,
gchar** default_value,
gsize* default_length,
GError* error)
{
gchar** value = g_key_file_get_string_list (key_file, group, key, length, NULL);
if (!value)
{
value = g_strdupv (default_value);
if (length)
*length = *default_length;
}
return value;
}
gboolean
sokoke_key_file_save_to_file (GKeyFile* key_file,
const gchar* filename,

View file

@ -72,47 +72,6 @@ GtkWidget*
sokoke_xfce_header_new (const gchar* icon,
const gchar* title);
void
sokoke_entry_set_default_text (GtkEntry* entry,
const gchar* default_text);
gchar*
sokoke_key_file_get_string_default (GKeyFile* key_file,
const gchar* group,
const gchar* key,
const gchar* default_value,
GError** error);
gint
sokoke_key_file_get_integer_default (GKeyFile* key_file,
const gchar* group,
const gchar* key,
const gint default_value,
GError** error);
gdouble
sokoke_key_file_get_double_default (GKeyFile* key_file,
const gchar* group,
const gchar* key,
gdouble default_value,
GError** error);
gboolean
sokoke_key_file_get_boolean_default (GKeyFile* key_file,
const gchar* group,
const gchar* key,
gboolean default_value,
GError** error);
gchar**
sokoke_key_file_get_string_list_default (GKeyFile* key_file,
const gchar* group,
const gchar* key,
gsize* length,
gchar** default_value,
gsize* default_length,
GError* error);
gboolean
sokoke_key_file_save_to_file (GKeyFile* key_file,
const gchar* filename,