[Xfce4-commits] <midori:master> Accept setting=value in activate_action/ --execute
Christian Dywan
noreply at xfce.org
Sat Mar 23 12:40:01 CET 2013
Updating branch refs/heads/master
to f428709f174ec2bdba5d4acebe010ffd33e1ea56 (commit)
from 3de3a71f4fb26c3c77802d5dd25f241cc216245f (commit)
commit f428709f174ec2bdba5d4acebe010ffd33e1ea56
Author: Christian Dywan <christian at twotoasts.de>
Date: Sat Mar 23 12:37:27 2013 +0100
Accept setting=value in activate_action/ --execute
--help-execute lists supported settings and values.
midori/main.c | 49 ++++++++++++++++++++++++++++++++++++++++++----
midori/midori-browser.c | 29 +++++++++++++++++++++++++++
2 files changed, 73 insertions(+), 5 deletions(-)
diff --git a/midori/main.c b/midori/main.c
index f0ea8a0..adc93b0 100644
--- a/midori/main.c
+++ b/midori/main.c
@@ -192,14 +192,16 @@ main (int argc,
GtkActionGroup* action_group = midori_browser_get_action_group (browser);
GList* actions = gtk_action_group_list_actions (action_group);
GList* temp = actions;
+ GObjectClass* class = G_OBJECT_GET_CLASS (midori_browser_get_settings (browser));
+ guint i, n_properties;
+ GParamSpec** pspecs = g_object_class_list_properties (class, &n_properties);
guint length = 1;
gchar* space;
for (; temp; temp = g_list_next (temp))
- {
- GtkAction* action = temp->data;
- length = MAX (length, 1 + strlen (gtk_action_get_name (action)));
- }
+ length = MAX (length, 1 + strlen (gtk_action_get_name (temp->data)));
+ for (i = 0; i < n_properties; i++)
+ length = MAX (length, 1 + strlen (g_param_spec_get_name (pspecs[i])));
space = g_strnfill (length, ' ');
for (; actions; actions = g_list_next (actions))
@@ -217,8 +219,45 @@ main (int argc,
g_free (label);
g_free (stripped);
}
- g_free (space);
g_list_free (actions);
+ g_print ("\n");
+
+ for (i = 0; i < n_properties; i++)
+ {
+ GParamSpec* pspec = pspecs[i];
+ if (!(pspec->flags & G_PARAM_WRITABLE))
+ continue;
+ const gchar* property = g_param_spec_get_name (pspec);
+ gchar* padding = g_strndup (space, strlen (space) - strlen (property));
+ GType type = G_PARAM_SPEC_TYPE (pspec);
+ const gchar* tname;
+ GString* tname_string = NULL;
+ if (type == G_TYPE_PARAM_STRING)
+ tname = "string";
+ else if (type == G_TYPE_PARAM_BOOLEAN)
+ tname = "true/ false";
+ else if (type == G_TYPE_PARAM_ENUM)
+ {
+ GEnumClass* enum_class = G_ENUM_CLASS (g_type_class_peek (pspec->value_type));
+ gint j = 0;
+ tname_string = g_string_new ("");
+ for (j = 0; j < enum_class->n_values; j++)
+ {
+ g_string_append (tname_string, enum_class->values[j].value_name);
+ g_string_append (tname_string, j == 2 ? "\n " : " ");
+ }
+ tname = tname_string->str;
+ }
+ else
+ tname = "number";
+ g_print ("%s%s%s\n", property, padding, tname);
+ if (tname_string != NULL)
+ g_string_free (tname_string, TRUE);
+ g_free (padding);
+ }
+ g_free (pspecs);
+
+ g_free (space);
gtk_widget_destroy (GTK_WIDGET (browser));
return 0;
}
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index d9b70f0..c8981c1 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -536,6 +536,35 @@ _midori_browser_activate_action (MidoriBrowser* browser,
GtkAction* action = _action_by_name (browser, name);
if (action)
gtk_action_activate (action);
+ else if (strchr (name, '='))
+ {
+ gchar** parts = g_strsplit (name, "=", 0);
+ GObjectClass* class = G_OBJECT_GET_CLASS (browser->settings);
+ GParamSpec* pspec = g_object_class_find_property (class, parts[0]);
+ GType type = pspec ? G_PARAM_SPEC_TYPE (pspec) : G_TYPE_INVALID;
+ if (type == G_TYPE_PARAM_BOOLEAN && !strcmp ("true", parts[1]))
+ g_object_set (browser->settings, parts[0], TRUE, NULL);
+ else if (type == G_TYPE_PARAM_BOOLEAN && !strcmp ("false", parts[1]))
+ g_object_set (browser->settings, parts[0], FALSE, NULL);
+ else if (type == G_TYPE_PARAM_STRING)
+ g_object_set (browser->settings, parts[0], parts[1], NULL);
+ else if (type == G_TYPE_PARAM_INT || type == G_TYPE_PARAM_UINT)
+ g_object_set (browser->settings, parts[0], atoi (parts[1]), NULL);
+ else if (type == G_TYPE_PARAM_FLOAT)
+ g_object_set (browser->settings, parts[0], g_ascii_strtod (parts[1], NULL), NULL);
+ else if (type == G_TYPE_PARAM_ENUM)
+ {
+ GEnumClass* enum_class = G_ENUM_CLASS (g_type_class_peek (pspec->value_type));
+ GEnumValue* enum_value = g_enum_get_value_by_name (enum_class, parts[1]);
+ if (enum_value != NULL)
+ g_object_set (browser->settings, parts[0], enum_value->value, NULL);
+ else
+ g_warning (_("Value '%s' is invalid for %s"), parts[1], parts[0]);
+ }
+ else if (pspec != NULL)
+ g_warning (_("Value '%s' is invalid for %s"), parts[1], parts[0]);
+ g_strfreev (parts);
+ }
else
g_warning (_("Unexpected action '%s'."), name);
}
More information about the Xfce4-commits
mailing list