Commit 1b65f00f authored by Konstantin's avatar Konstantin

widget: port <icon> property from upstream (now only for vala-panel)

parent 142d6937
Pipeline #207696482 passed with stage
in 3 minutes and 21 seconds
......@@ -40,6 +40,8 @@ enum
PROP_IS_TITLE_DISPAYED,
PROP_UPDATE_INTERVAL_MS,
PROP_FONT_VALUE,
/* icon size for panels */
PROP_ICON_SIZE,
/* orientable */
PROP_ORIENTATION,
......@@ -68,6 +70,9 @@ struct _GenMonWidget
char *value_click_command;
char *cmd_result; /* Commandline resulting string */
/* icon size for panels */
uint32_t icon_size;
/* Configurable parameters */
char *command; /* Commandline to spawn */
bool is_title_displayed;
......@@ -174,6 +179,45 @@ void genmon_widget_display_command_output(GenMonWidget *self)
gtk_widget_hide(GTK_WIDGET(self->image));
}
/* Test if the result is an Icon */
begin = strstr(self->cmd_result, "<icon>");
end = strstr(self->cmd_result, "</icon>");
if (begin && end && begin < end)
{
/* Get the image path */
char *buf = g_strndup(begin + 5, end - begin - 5);
gtk_image_set_from_icon_name(GTK_IMAGE(self->image), buf, GTK_ICON_SIZE_INVALID);
gtk_image_set_from_icon_name(GTK_IMAGE(self->button_image),
buf,
GTK_ICON_SIZE_INVALID);
gtk_widget_show(GTK_WIDGET(self->button_image));
g_free(buf);
/* Test if the result has a clickable Icon (button) */
begin = strstr(self->cmd_result, "<iconclick>");
end = strstr(self->cmd_result, "</iconclick>");
if (begin && end && begin < end)
{
/* Get the command path */
g_free(self->click_command);
self->click_command = g_strndup(begin + 11, end - begin - 11);
gtk_widget_show(GTK_WIDGET(self->button));
gtk_widget_hide(GTK_WIDGET(self->image));
}
else
{
gtk_widget_hide(GTK_WIDGET(self->button));
gtk_widget_show(GTK_WIDGET(self->image));
}
newVersion = true;
}
else
{
gtk_widget_hide(GTK_WIDGET(self->button));
gtk_widget_hide(GTK_WIDGET(self->image));
}
/* Test if the result is a Text */
begin = strstr(self->cmd_result, "<txt>");
end = strstr(self->cmd_result, "</txt>");
......@@ -314,6 +358,16 @@ static void genmon_widget_build(GenMonWidget *self)
self->title_label,
"visible",
(GBindingFlags)(G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE));
g_object_bind_property(self,
GENMON_ICON_SIZE,
self->image,
"pixel-size",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
g_object_bind_property(self,
GENMON_ICON_SIZE,
self->button_image,
"pixel-size",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
// xfce_panel_plugin_add_action_widget(plugin, self->button);
......@@ -458,6 +512,10 @@ static void genmon_widget_set_property(GObject *object, uint prop_id, const GVal
self->is_title_displayed = g_value_get_boolean(value);
g_object_notify_by_pspec(object, pspec);
break;
case PROP_ICON_SIZE:
self->icon_size = g_value_get_uint(value);
g_object_notify_by_pspec(object, pspec);
break;
case PROP_ORIENTATION:
orient = (GtkOrientation)g_value_get_enum(value);
invert_orient = orient == GTK_ORIENTATION_HORIZONTAL ? GTK_ORIENTATION_VERTICAL
......@@ -497,6 +555,9 @@ static void genmon_widget_get_property(GObject *object, uint prop_id, GValue *va
case PROP_IS_TITLE_DISPAYED:
g_value_set_boolean(value, self->is_title_displayed);
break;
case PROP_ICON_SIZE:
g_value_set_uint(value, self->icon_size);
break;
case PROP_ORIENTATION:
g_value_set_enum(value,
gtk_orientable_get_orientation(GTK_ORIENTABLE(self->main_box)));
......@@ -581,6 +642,15 @@ static void genmon_widget_class_init(GenMonWidgetClass *klass)
FALSE,
(GParamFlags)(G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
pspecs[PROP_ICON_SIZE] =
g_param_spec_uint(GENMON_ICON_SIZE,
GENMON_ICON_SIZE,
GENMON_ICON_SIZE,
GTK_ICON_SIZE_MENU,
1000,
GTK_ICON_SIZE_MENU,
(GParamFlags)(G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
g_object_class_install_properties(oclass, LAST_PROP, pspecs);
gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS(klass), "/org/genmon/main.ui");
gtk_widget_class_bind_template_child_full(GTK_WIDGET_CLASS(klass),
......
......@@ -33,6 +33,7 @@ G_BEGIN_DECLS
#define GENMON_CMD "command"
#define GENMON_UPDATE_PERIOD "update-period"
#define GENMON_FONT "font"
#define GENMON_ICON_SIZE "icon-size"
G_DECLARE_FINAL_TYPE(GenMonWidget, genmon_widget, GENMON, WIDGET, GtkEventBox)
......
......@@ -71,6 +71,11 @@ static void genmon_applet_constructed(GObject *obj)
widget,
VP_KEY_ORIENTATION,
G_BINDING_SYNC_CREATE);
g_object_bind_property(toplevel,
VP_KEY_ICON_SIZE,
widget,
GENMON_ICON_SIZE,
G_BINDING_SYNC_CREATE);
gtk_container_add(GTK_CONTAINER(self), GTK_WIDGET(widget));
gtk_widget_show(GTK_WIDGET(widget));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment