From e0f6d44e6f945b457098797f272e7479166a6c48 Mon Sep 17 00:00:00 2001 From: Andre Miranda Date: Sun, 16 Nov 2014 00:44:24 -0300 Subject: [PATCH] Add option to set date and time label colors --- panel-plugin/datetime-dialog.c | 56 ++++++++++++++++++++++++++++++++++++++++++ panel-plugin/datetime.c | 39 ++++++++++++++++++++++++++++- panel-plugin/datetime.h | 7 ++++++ 3 files changed, 101 insertions(+), 1 deletion(-) diff --git a/panel-plugin/datetime-dialog.c b/panel-plugin/datetime-dialog.c index ede858f..07de57b 100644 --- a/panel-plugin/datetime-dialog.c +++ b/panel-plugin/datetime-dialog.c @@ -275,6 +275,30 @@ time_format_changed(GtkComboBox *cbox, t_datetime *dt) } /* + * Read color from color button and set foreground color + */ +static void +date_color_changed(GtkWidget *widget, t_datetime *dt) +{ + GdkColor color; + gtk_color_button_get_color((GtkColorButton *)widget, &color); + + datetime_apply_color(dt, gdk_color_to_string(&color), NULL); +} + +/* + * Read color from color button and set background color + */ +static void +time_color_changed(GtkWidget *widget, t_datetime *dt) +{ + GdkColor color; + gtk_color_button_get_color((GtkColorButton *)widget, &color); + + datetime_apply_color(dt, NULL, gdk_color_to_string(&color)); +} + +/* * read values from date and time entry and inform datetime about it */ static gboolean @@ -442,6 +466,22 @@ datetime_properties_dialog(XfcePanelPlugin *plugin, t_datetime * datetime) hbox = gtk_hbox_new(FALSE, 2); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + /* color label */ + label = gtk_label_new(_("Color:")); + gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + gtk_size_group_add_widget(sg, label); + + /* color button */ + button = gtk_color_button_new(); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(button), "color-set", + G_CALLBACK(date_color_changed), datetime); + + /* hbox */ + hbox = gtk_hbox_new(FALSE, 2); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + /* format label */ label = gtk_label_new(_("Format:")); gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); @@ -543,6 +583,22 @@ datetime_properties_dialog(XfcePanelPlugin *plugin, t_datetime * datetime) hbox = gtk_hbox_new(FALSE, 2); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + /* color label */ + label = gtk_label_new(_("Color:")); + gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + gtk_size_group_add_widget(sg, label); + + /* color button */ + button = gtk_color_button_new(); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(button), "color-set", + G_CALLBACK(time_color_changed), datetime); + + /* hbox */ + hbox = gtk_hbox_new(FALSE, 2); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + /* format label */ label = gtk_label_new(_("Format:")); gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); diff --git a/panel-plugin/datetime.c b/panel-plugin/datetime.c index 181c273..5e2195b 100644 --- a/panel-plugin/datetime.c +++ b/panel-plugin/datetime.c @@ -503,6 +503,34 @@ void datetime_apply_format(t_datetime *datetime, } /* + * set the date and time foreground color + */ +void datetime_apply_color(t_datetime *datetime, + const gchar *date_color, + const gchar *time_color) +{ + GdkColor color; + + if (date_color != NULL) + { + g_free(datetime->date_color); + datetime->date_color = g_strdup(date_color); + + gdk_color_parse (datetime->date_color, &color); + gtk_widget_modify_fg (datetime->date_label, GTK_STATE_NORMAL, &color); + } + + if (time_color != NULL) + { + g_free(datetime->time_color); + datetime->time_color = g_strdup(time_color); + + gdk_color_parse (datetime->time_color, &color); + gtk_widget_modify_fg (datetime->time_label, GTK_STATE_NORMAL, &color); + } +} + +/* * Function only called by the signal handler. */ static int datetime_set_size(XfcePanelPlugin *plugin, @@ -521,7 +549,7 @@ static void datetime_read_rc_file(XfcePanelPlugin *plugin, t_datetime *dt) gchar *file; XfceRc *rc = NULL; t_layout layout; - const gchar *date_font, *time_font, *date_format, *time_format; + const gchar *date_font, *time_font, *date_format, *time_format, *date_color, *time_color; /* load defaults */ layout = LAYOUT_DATE_TIME; @@ -529,6 +557,8 @@ static void datetime_read_rc_file(XfcePanelPlugin *plugin, t_datetime *dt) time_font = "Bitstream Vera Sans 8"; date_format = "%Y-%m-%d"; time_format = "%H:%M"; + date_color = "#000000000000"; + time_color = "#000000000000"; /* open file */ if((file = xfce_panel_plugin_lookup_rc_file(plugin)) != NULL) @@ -543,6 +573,8 @@ static void datetime_read_rc_file(XfcePanelPlugin *plugin, t_datetime *dt) time_font = xfce_rc_read_entry(rc, "time_font", time_font); date_format = xfce_rc_read_entry(rc, "date_format", date_format); time_format = xfce_rc_read_entry(rc, "time_format", time_format); + date_color = xfce_rc_read_entry(rc, "date_color", date_color); + time_color = xfce_rc_read_entry(rc, "time_color", time_color); } } @@ -550,6 +582,8 @@ static void datetime_read_rc_file(XfcePanelPlugin *plugin, t_datetime *dt) time_font = g_strdup(time_font); date_format = g_strdup(date_format); time_format = g_strdup(time_format); + date_color = g_strdup(date_color); + time_color = g_strdup(time_color); if(rc != NULL) xfce_rc_close(rc); @@ -558,6 +592,7 @@ static void datetime_read_rc_file(XfcePanelPlugin *plugin, t_datetime *dt) datetime_apply_layout(dt, layout); datetime_apply_font(dt, date_font, time_font); datetime_apply_format(dt, date_format, time_format); + datetime_apply_color(dt, date_color, time_color); } /* @@ -581,6 +616,8 @@ void datetime_write_rc_file(XfcePanelPlugin *plugin, t_datetime *dt) xfce_rc_write_entry(rc, "time_font", dt->time_font); xfce_rc_write_entry(rc, "date_format", dt->date_format); xfce_rc_write_entry(rc, "time_format", dt->time_format); + xfce_rc_write_entry(rc, "date_color", dt->date_color); + xfce_rc_write_entry(rc, "time_color", dt->time_color); xfce_rc_close(rc); } diff --git a/panel-plugin/datetime.h b/panel-plugin/datetime.h index 5f09f83..5f5bc38 100644 --- a/panel-plugin/datetime.h +++ b/panel-plugin/datetime.h @@ -54,6 +54,8 @@ typedef struct { gchar *time_font; gchar *date_format; gchar *time_format; + gchar *date_color; + gchar *time_color; t_layout layout; /* option widgets */ @@ -93,6 +95,11 @@ datetime_apply_format(t_datetime *datetime, const gchar *time_format); void +datetime_apply_color(t_datetime *datetime, + const gchar *date_color, + const gchar *time_color); + +void datetime_apply_layout(t_datetime *datetime, t_layout layout); -- 2.1.3