[Xfce4-commits] [apps/xfdashboard] 02/05: Implement full configuration dialog for clock view plugin
noreply at xfce.org
noreply at xfce.org
Tue Feb 23 22:35:13 CET 2016
This is an automated email from the git hooks/post-receive script.
nomad pushed a commit to branch master
in repository apps/xfdashboard.
commit af246d5d9458e71bef2cef0eb8ecf9d5a6451d71
Author: Stephan Haller <nomad at froevel.de>
Date: Tue Feb 23 22:28:28 2016 +0100
Implement full configuration dialog for clock view plugin
---
plugins/clock-view/plugin.c | 198 ++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 193 insertions(+), 5 deletions(-)
diff --git a/plugins/clock-view/plugin.c b/plugins/clock-view/plugin.c
index 221c565..6911542 100644
--- a/plugins/clock-view/plugin.c
+++ b/plugins/clock-view/plugin.c
@@ -36,19 +36,207 @@
#include <gtk/gtk.h>
-/* IMPLEMENTATION: XfdashboardPlugin */
-
/* Forward declarations */
G_MODULE_EXPORT void plugin_init(XfdashboardPlugin *self);
+
+/* IMPLEMENTATION: XfdashboardPlugin */
+
+#define CONFIGURATION_MAPPING "xfdashboard-plugin-clock_view-configuration-mapping"
+
+typedef struct _PluginWidgetSettingsMap PluginWidgetSettingsMap;
+struct _PluginWidgetSettingsMap
+{
+ XfdashboardClockViewSettings *settings;
+ gchar *property;
+ guint settingsPropertyChangedSignalID;
+};
+
+/* Free mapping data */
+static void _plugin_widget_settings_map_free(PluginWidgetSettingsMap *inData)
+{
+ g_return_if_fail(inData);
+
+ /* Release allocated resources */
+ if(inData->settingsPropertyChangedSignalID) g_signal_handler_disconnect(inData->settings, inData->settingsPropertyChangedSignalID);
+ if(inData->property) g_free(inData->property);
+ if(inData->settings) g_object_unref(inData->settings);
+ g_free(inData);
+}
+
+/* Color has changed at settings */
+static void _plugin_on_settings_color_change(GObject *inObject,
+ GParamSpec *inSpec,
+ gpointer inUserData)
+{
+ XfdashboardClockViewSettings *settings;
+ GtkColorButton *button;
+ ClutterColor *settingsColor;
+ GdkRGBA widgetColor;
+
+ g_return_if_fail(XFDASHBOARD_IS_CLOCK_VIEW_SETTINGS(inObject));
+ g_return_if_fail(GTK_IS_COLOR_BUTTON(inUserData));
+
+ settings=XFDASHBOARD_CLOCK_VIEW_SETTINGS(inObject);
+ button=GTK_COLOR_BUTTON(inUserData);
+
+ /* Get current color from settings */
+ g_object_get(G_OBJECT(settings), g_param_spec_get_name(inSpec), &settingsColor, NULL);
+
+ /* Convert color for color button */
+ widgetColor.red=settingsColor->red/255.0f;
+ widgetColor.green=settingsColor->green/255.0f;
+ widgetColor.blue=settingsColor->blue/255.0f;
+ widgetColor.alpha=settingsColor->alpha/255.0f;
+
+ /* Set converted color at color button */
+ gtk_color_button_set_rgba(button, &widgetColor);
+}
+
+/* A new color was chosen at color button */
+static void _plugin_on_color_button_color_chosen(GtkColorButton *inButton,
+ gpointer inUserData)
+{
+ GdkRGBA widgetColor;
+ ClutterColor settingsColor;
+ PluginWidgetSettingsMap *mapping;
+
+ g_return_if_fail(GTK_IS_COLOR_BUTTON(inButton));
+
+ /* Get color from color button */
+ gtk_color_button_get_rgba(inButton, &widgetColor);
+
+ /* Convert color for settings */
+ settingsColor.red=MIN(255, (gint)(widgetColor.red*255.0f));
+ settingsColor.green=MIN(255, (gint)(widgetColor.green*255.0f));
+ settingsColor.blue=MIN(255, (gint)(widgetColor.blue*255.0f));
+ settingsColor.alpha=MIN(255, (gint)(widgetColor.alpha*255.0f));
+
+ /* Set converted color at settings */
+ mapping=XFDASHBOARD_CLOCK_VIEW_SETTINGS(g_object_get_data(G_OBJECT(inButton), CONFIGURATION_MAPPING));
+ if(mapping) g_object_set(G_OBJECT(mapping->settings), mapping->property, &settingsColor, NULL);
+}
+
+/* Set up color button, e.g. set initial color from settings, connect signals
+ * to store newly chosen color or to reflect changed color from settings
+ * in widget etc.
+ */
+static void _plugin_configure_setup_color_button(GtkColorButton *inButton,
+ XfdashboardClockViewSettings *inSettings,
+ const gchar *inProperty)
+{
+ ClutterColor *settingsColor;
+ GdkRGBA widgetColor;
+ gchar *signalName;
+ guint signalID;
+ PluginWidgetSettingsMap *mapping;
+
+ g_return_if_fail(GTK_IS_COLOR_BUTTON(inButton));
+ g_return_if_fail(XFDASHBOARD_IS_CLOCK_VIEW_SETTINGS(inSettings));
+ g_return_if_fail(inProperty && *inProperty);
+
+ /* Create data for later use at color button */
+ mapping=g_new0(PluginWidgetSettingsMap,1);
+ if(!mapping)
+ {
+ g_critical(_("Cannot allocate memory for mapping"));
+ return;
+ }
+
+ /* Get current color from settings */
+ g_object_get(G_OBJECT(inSettings), inProperty, &settingsColor, NULL);
+
+ /* Convert color for color button */
+ widgetColor.red=settingsColor->red/255.0f;
+ widgetColor.green=settingsColor->green/255.0f;
+ widgetColor.blue=settingsColor->blue/255.0f;
+ widgetColor.alpha=settingsColor->alpha/255.0f;
+
+ /* Set converted color at color button */
+ gtk_color_button_set_rgba(inButton, &widgetColor);
+
+ /* Connect signal to store color of new one was chosen at color button */
+ g_signal_connect(inButton,
+ "color-set",
+ G_CALLBACK(_plugin_on_color_button_color_chosen),
+ NULL);
+
+ signalName=g_strdup_printf("notify::%s", inProperty);
+ signalID=g_signal_connect(inSettings,
+ signalName,
+ G_CALLBACK(_plugin_on_settings_color_change),
+ inButton);
+
+ /* Set mapping data at color button */
+ mapping->settings=g_object_ref(inSettings);
+ mapping->property=g_strdup(inProperty);
+ mapping->settingsPropertyChangedSignalID=signalID;
+ g_object_set_data_full(G_OBJECT(inButton),
+ CONFIGURATION_MAPPING,
+ mapping,
+ (GDestroyNotify)_plugin_widget_settings_map_free);
+
+ /* Release allocated resources */
+ if(settingsColor) clutter_color_free(settingsColor);
+ if(signalName) g_free(signalName);
+}
+
/* Plugin configuration function */
static GObject* plugin_configure(XfdashboardPlugin *self, gpointer inUserData)
{
- GtkWidget *label;
+ GtkWidget *layout;
+ GtkWidget *widgetLabel;
+ GtkWidget *widgetValue;
+ XfdashboardClockViewSettings *settings;
+
+ /* Get settings of plugin */
+ settings=xfdashboard_clock_view_settings_new();
+
+ /* Create layout widget */
+ layout=gtk_grid_new();
+
+ /* Add widget to choose hour color */
+ widgetLabel=gtk_label_new(_("Hour color:"));
+ gtk_grid_attach(GTK_GRID(layout), widgetLabel, 0, 0, 1, 1);
+
+ widgetValue=gtk_color_button_new();
+ gtk_color_button_set_use_alpha(GTK_COLOR_BUTTON(widgetValue), TRUE);
+ gtk_color_button_set_title(GTK_COLOR_BUTTON(widgetValue), _("Choose color for hour hand"));
+ _plugin_configure_setup_color_button(GTK_COLOR_BUTTON(widgetValue), settings, "hour-color");
+ gtk_grid_attach_next_to(GTK_GRID(layout), widgetValue, widgetLabel, GTK_POS_RIGHT, 1, 1);
+
+ /* Add widget to choose minute color */
+ widgetLabel=gtk_label_new(_("Minute color:"));
+ gtk_grid_attach(GTK_GRID(layout), widgetLabel, 0, 1, 1, 1);
+
+ widgetValue=gtk_color_button_new();
+ gtk_color_button_set_use_alpha(GTK_COLOR_BUTTON(widgetValue), TRUE);
+ gtk_color_button_set_title(GTK_COLOR_BUTTON(widgetValue), _("Choose color for minute hand"));
+ _plugin_configure_setup_color_button(GTK_COLOR_BUTTON(widgetValue), settings, "minute-color");
+ gtk_grid_attach_next_to(GTK_GRID(layout), widgetValue, widgetLabel, GTK_POS_RIGHT, 1, 1);
+
+ /* Add widget to choose second color */
+ widgetLabel=gtk_label_new(_("Second color:"));
+ gtk_grid_attach(GTK_GRID(layout), widgetLabel, 0, 2, 1, 1);
+
+ widgetValue=gtk_color_button_new();
+ gtk_color_button_set_use_alpha(GTK_COLOR_BUTTON(widgetValue), TRUE);
+ gtk_color_button_set_title(GTK_COLOR_BUTTON(widgetValue), _("Choose color for second hand"));
+ _plugin_configure_setup_color_button(GTK_COLOR_BUTTON(widgetValue), settings, "second-color");
+ gtk_grid_attach_next_to(GTK_GRID(layout), widgetValue, widgetLabel, GTK_POS_RIGHT, 1, 1);
+
+ /* Add widget to choose minute color */
+ widgetLabel=gtk_label_new(_("Background color:"));
+ gtk_grid_attach(GTK_GRID(layout), widgetLabel, 0, 3, 1, 1);
- label=gtk_label_new("Not yet implemented!");
+ widgetValue=gtk_color_button_new();
+ gtk_color_button_set_use_alpha(GTK_COLOR_BUTTON(widgetValue), TRUE);
+ gtk_color_button_set_title(GTK_COLOR_BUTTON(widgetValue), _("Choose color for background of second hand"));
+ _plugin_configure_setup_color_button(GTK_COLOR_BUTTON(widgetValue), settings, "background-color");
+ gtk_grid_attach_next_to(GTK_GRID(layout), widgetValue, widgetLabel, GTK_POS_RIGHT, 1, 1);
- return(G_OBJECT(label));
+ /* Return layout widget containing all other widgets */
+ return(G_OBJECT(layout));
}
/* Plugin enable function */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list