Index: plugins/clock/clock.c =================================================================== --- plugins/clock/clock.c (revision 18423) +++ plugins/clock/clock.c (working copy) @@ -1,486 +1,1030 @@ -/* vim: set expandtab ts=8 sw=4: */ - -/* $Id$ +/* + * clock plugin for the xfce4 panel * - * Copyright © 2005 The Xfce Development Team + * Copyright (c) 2005 Brian Tarricone * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Library General Public License as published - * by the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Authors: - * Jasper Huijsmans - * Jannis Pohlmann + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License ONLY. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifdef HAVE_CONFIG_H #include #endif -#ifdef HAVE_SYS_STAT_H -#include +#ifdef HAVE_TIME_H +#include #endif -#ifdef HAVE_MEMORY_H -#include -#endif -#include #ifdef HAVE_STRING_H #include #endif -#ifdef HAVE_TIME_H -#include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif -#include -#include - #include #include #include +typedef enum +{ + CLOCK_LAYOUT_DATE_ONLY = 0, + CLOCK_LAYOUT_TIME_ONLY, + CLOCK_LAYOUT_DATE_TIME, + CLOCK_LAYOUT_TIME_DATE, + CLOCK_LAYOUT_DATE_ABOVE_TIME, + CLOCK_LAYOUT_TIME_ABOVE_DATE, + N_CLOCK_LAYOUTS, +} XfceClockLayout; + +static const gchar *clock_layout_strs[] = { + N_("Date only"), + N_("Time only"), + N_("Date, then time"), + N_("Time, then date"), + N_("Date above time"), + N_("Time above date"), +}; + typedef struct { XfcePanelPlugin *plugin; - + + GtkWidget *evtbox; GtkWidget *frame; - GtkWidget *clock; - GtkTooltips *tips; - - int timeout_id; - - /* Settings */ - int mode; - gboolean military; - gboolean ampm; - gboolean secs; - + GtkWidget *label; + GtkTooltips *tooltip; + + guint clock_timeout; + gchar *overall_format; + gint max_width; + gboolean show_frame; -} -Clock; + + guint builtin_time_format; + gboolean use_custom_time_format; + gchar *custom_time_format; + gboolean use_custom_time_font; + PangoFontDescription *time_font; + GdkColor time_color; + + guint builtin_date_format; + gboolean use_custom_date_format; + gchar *custom_date_format; + gboolean use_custom_date_font; + PangoFontDescription *date_font; + GdkColor date_color; + + XfceClockLayout layout; +} XfceClockPlugin; -static void clock_properties_dialog (XfcePanelPlugin *plugin, - Clock *clock); +typedef struct +{ + XfceClockPlugin *clock_plugin; + + GtkWidget *dlg; + + GtkWidget *date_frame; + GtkWidget *date_custom_box; + GtkWidget *date_fontbtn; + GtkWidget *date_colorbtn; + + GtkWidget *time_frame; + GtkWidget *time_custom_box; + GtkWidget *time_fontbtn; + GtkWidget *time_colorbtn; +} XfceClockConfig; -static void clock_construct (XfcePanelPlugin *plugin); +static const gchar *builtin_time_formats[] = { + "%H:%M", + "%H:%M:%S", + "%I:%M %P", + "%I:%M:%S %P", +}; +#define N_TIME_FORMATS 4 +#define DEFAULT_TIME_FORMAT 1 +static const gchar *builtin_date_formats[] = { + "%Y/%m/%d", + "%m/%d/%Y", + "%B %d, %Y", + "%b %d, %Y", + "%A, %B %d, %Y", + "%a, %b %d, %Y", + "%d/%m/%Y", + "%d %B %Y", + "%d %b %Y", + "%A, %d %B %Y", + "%a, %d %b %Y", +}; +#define N_DATE_FORMATS 11 +#define DEFAULT_DATE_FORMAT 0 -/* -------------------------------------------------------------------- * - * Clock * - * -------------------------------------------------------------------- */ +#define BORDER 8 -static gboolean -clock_date_tooltip (Clock *clock) +static inline gchar * +xfclock_do_strftime(const gchar *fmt) { - time_t ticks; - struct tm *tm; - static gint mday = -1; - char date_s[255]; - char *utf8date = NULL; - - ticks = time (0); - tm = localtime (&ticks); - - if (mday != tm->tm_mday) - { - mday = tm->tm_mday; - - /* Use format characters from strftime(3) - * to get the proper string for your locale. - * I used these: - * %A : full weekday name - * %d : day of the month - * %B : full month name - * %Y : four digit year - */ - strftime(date_s, 255, _("%A %d %B %Y"), tm); - - /* Conversion to utf8 - * Patch by Oliver M. Bolzer - */ - if (!g_utf8_validate(date_s, -1, NULL)) - { - utf8date = g_locale_to_utf8(date_s, -1, NULL, NULL, NULL); + gchar buf[2048], *buf_utf8 = NULL; + time_t now = time(NULL); +#ifdef HAVE_LOCALTIME_R + struct tm real_tm; + struct tm *tm_now = &real_tm; + + localtime_r(&now, tm_now); +#else + struct *tm tm_now = localtime(&now); +#endif + + if(strftime(buf, 2048, fmt, tm_now) == 0) + return g_strdup(_("(Invalid format)")); + + if(!g_utf8_validate(buf, -1, NULL)) { + gsize read, written; + GError *err = NULL; + + buf_utf8 = g_locale_to_utf8(buf, -1, &read, &written, &err); + if(!buf_utf8) { + g_critical("System strftime() returned string in strange locale (%d): %s", + err->code, err->message); + g_error_free(err); + buf_utf8 = g_strdup(_("(UTF-8 conversion failed)")); } + } + + return buf_utf8 ? buf_utf8 : g_strdup(buf); +} - if (utf8date) - { - gtk_tooltips_set_tip (clock->tips, GTK_WIDGET (clock->plugin), - utf8date, NULL); - g_free (utf8date); - } - else - { - gtk_tooltips_set_tip (clock->tips, GTK_WIDGET (clock->plugin), - date_s, NULL); - } - } - - return TRUE; +static inline gchar * +xfclock_gdkcolor_to_htmlstr(const GdkColor *color) +{ + return g_strdup_printf("#%02x%02x%02x", + color->red / 256, + color->green / 256, + color->blue / 256); } static void -clock_update_size (Clock *clock, int size) +xfclock_set_tooltip(XfceClockPlugin *clock_plugin) { - XfceClock *clk = XFCE_CLOCK (clock->clock); + gchar *str = NULL; + + if(clock_plugin->layout == CLOCK_LAYOUT_DATE_ONLY) { + if(clock_plugin->use_custom_time_format) + str = xfclock_do_strftime(clock_plugin->custom_time_format); + else + str = xfclock_do_strftime(builtin_time_formats[clock_plugin->builtin_time_format]); + } else if(clock_plugin->layout == CLOCK_LAYOUT_TIME_ONLY) { + if(clock_plugin->use_custom_date_format) + str = xfclock_do_strftime(clock_plugin->custom_date_format); + else + str = xfclock_do_strftime(builtin_date_formats[clock_plugin->builtin_date_format]); + } else { + gtk_tooltips_set_tip(clock_plugin->tooltip, clock_plugin->evtbox, NULL, NULL); + return; + } + + gtk_tooltips_set_tip(clock_plugin->tooltip, clock_plugin->evtbox, str, NULL); + g_free(str); +} - g_return_if_fail (clk != NULL); - g_return_if_fail (GTK_IS_WIDGET (clk)); - - /* keep in sync with systray */ - if (size > 26) - { - gtk_container_set_border_width (GTK_CONTAINER (clock->frame), 2); - size -= 3; - } +static gchar * +xfclock_get_overall_format(XfceClockPlugin *clock_plugin) +{ + gchar *overall_format = NULL; + const gchar *date_str, *time_str; + gchar *date_str_head = NULL, *date_str_foot = "", *time_str_head = NULL, + *time_str_foot = ""; + + if(clock_plugin->use_custom_date_format) + date_str = clock_plugin->custom_date_format; else - { - gtk_container_set_border_width (GTK_CONTAINER (clock->frame), 0); - size -= 1; + date_str = builtin_date_formats[clock_plugin->builtin_date_format]; + if(!date_str) + date_str = " "; + + if(clock_plugin->use_custom_time_format) + time_str = clock_plugin->custom_time_format; + else + time_str = builtin_time_formats[clock_plugin->builtin_time_format]; + if(!time_str) + time_str = " "; + + if(clock_plugin->use_custom_date_font && clock_plugin->date_font) { + gchar *str = pango_font_description_to_string(clock_plugin->date_font); + gchar *color_str = xfclock_gdkcolor_to_htmlstr(&clock_plugin->date_color); + date_str_head = g_strconcat("", NULL); + date_str_foot = ""; + g_free(str); + g_free(color_str); } - /* Replaced old 4-stage switch; Perhaps DIGIT_*_HEIGHT - * should be moved from xfce_clock.c to xfce_clock.h so we - * can use them here (e.g. 10*2 => DIGIT_SMALL_HEIGHT*2) - * */ - - if (size <= 10*2) - { - xfce_clock_set_led_size (clk, DIGIT_SMALL); + if(clock_plugin->use_custom_time_font && clock_plugin->time_font) { + gchar *str = pango_font_description_to_string(clock_plugin->time_font); + gchar *color_str = xfclock_gdkcolor_to_htmlstr(&clock_plugin->time_color); + time_str_head = g_strconcat("", NULL); + time_str_foot = ""; + g_free(str); + g_free(color_str); } - else if (size <= 14*2) - { - xfce_clock_set_led_size (clk, DIGIT_MEDIUM); - } - else if (size <= 20*2) - { - xfce_clock_set_led_size (clk, DIGIT_LARGE); + + switch(clock_plugin->layout) { + case CLOCK_LAYOUT_DATE_ONLY: + overall_format = g_strconcat(date_str_head?date_str_head:"", + date_str, date_str_foot, NULL); + break; + + case CLOCK_LAYOUT_TIME_ONLY: + overall_format = g_strconcat(time_str_head?time_str_head:"", + time_str, time_str_foot, NULL); + break; + + case CLOCK_LAYOUT_DATE_TIME: + overall_format = g_strconcat(date_str_head?date_str_head:"", + date_str, date_str_foot, " ", + time_str_head?time_str_head:"", + time_str, time_str_foot, NULL); + break; + + case CLOCK_LAYOUT_TIME_DATE: + overall_format = g_strconcat(time_str_head?time_str_head:"", + time_str, time_str_foot, " ", + date_str_head?date_str_head:"", + date_str, date_str_foot, NULL); + break; + + case CLOCK_LAYOUT_DATE_ABOVE_TIME: + overall_format = g_strconcat(date_str_head?date_str_head:"", + date_str, date_str_foot, "\n", + time_str_head?time_str_head:"", + time_str, time_str_foot, NULL); + break; + + case CLOCK_LAYOUT_TIME_ABOVE_DATE: + overall_format = g_strconcat(time_str_head?time_str_head:"", + time_str, time_str_foot, "\n", + date_str_head?date_str_head:"", + date_str, date_str_foot, NULL); + break; + + default: + g_critical("Invalid XfceClockLayout: %d", clock_plugin->layout); + overall_format = g_strdup(builtin_time_formats[DEFAULT_TIME_FORMAT]); + break; } - else - { - xfce_clock_set_led_size (clk, DIGIT_HUGE); - } + + g_free(date_str_head); + g_free(time_str_head); + + return overall_format; +} - if ((xfce_clock_get_mode (clk) == XFCE_CLOCK_LEDS) || - (xfce_clock_get_mode (clk) == XFCE_CLOCK_DIGITAL)) - { - gtk_widget_set_size_request (GTK_WIDGET (clk), -1, -1); +static gboolean +xfclock_timeout(XfceClockPlugin *clock_plugin) +{ + gchar *timestr; + GtkRequisition req; + gint w, h; + + timestr = xfclock_do_strftime(clock_plugin->overall_format); + gtk_label_set_markup(GTK_LABEL(clock_plugin->label), timestr); + g_free(timestr); + + xfclock_set_tooltip(clock_plugin); + + /* the idea here is to force the plugin to allocate as much width as it + * will ever need, and always keep that width. that way, we will never + * resize second-to-second if the text takes up more or less space due to + * a changing value */ + gtk_widget_get_size_request(clock_plugin->label, &w, &h); + gtk_widget_set_size_request(clock_plugin->label, -1, -1); + gtk_widget_size_request(clock_plugin->label, &req); + if(req.width > clock_plugin->max_width) + clock_plugin->max_width = req.width; + else { + gtk_widget_set_size_request(clock_plugin->label, + clock_plugin->max_width, h); } - else - { - gtk_widget_set_size_request (GTK_WIDGET (clk), size, size); - } + + return TRUE; +} - gtk_widget_queue_resize (GTK_WIDGET (clk)); +static void +xfclock_config_changed(XfceClockPlugin *clock_plugin) +{ + g_free(clock_plugin->overall_format); + clock_plugin->overall_format = xfclock_get_overall_format(clock_plugin); + + clock_plugin->max_width = -1; + + xfclock_timeout(clock_plugin); } - -/* -------------------------------------------------------------------- * - * Panel Plugin Interface * - * -------------------------------------------------------------------- */ - -/* Register with the panel */ - -XFCE_PANEL_PLUGIN_REGISTER_INTERNAL (clock_construct); - - -/* Interface Implementation */ - -static gboolean -clock_set_size (XfcePanelPlugin *plugin, int size, Clock *clock) +static gboolean +xfclock_read_config(XfceClockPlugin *clock_plugin) { - clock_update_size(clock, size); - + XfceRc *rcfile; + char *filename; + const gchar *str; + GdkColor *default_color; + + filename = xfce_panel_plugin_save_location(clock_plugin->plugin, FALSE); + if(!filename) + return FALSE; + + rcfile = xfce_rc_simple_open(filename, TRUE); + if(!rcfile) { + g_free(filename); + return FALSE; + } + + default_color = &(GTK_WIDGET(clock_plugin->plugin)->style->text[GTK_STATE_NORMAL]); + + xfce_rc_set_group(rcfile, "plugin"); + clock_plugin->show_frame = xfce_rc_read_bool_entry(rcfile, "show_frame", + TRUE); + clock_plugin->layout = xfce_rc_read_int_entry(rcfile, "layout", + CLOCK_LAYOUT_TIME_ONLY); + if(clock_plugin->layout >= N_CLOCK_LAYOUTS) + clock_plugin->layout = CLOCK_LAYOUT_TIME_ONLY; + + xfce_rc_set_group(rcfile, "date"); + clock_plugin->builtin_date_format = xfce_rc_read_int_entry(rcfile, + "builtin_format", + DEFAULT_DATE_FORMAT); + if(clock_plugin->builtin_date_format >= N_DATE_FORMATS) + clock_plugin->builtin_date_format = DEFAULT_DATE_FORMAT; + clock_plugin->use_custom_date_format = xfce_rc_read_bool_entry(rcfile, + "use_custom_format", + FALSE); + str = xfce_rc_read_entry(rcfile, "custom_format", NULL); + if(str) + clock_plugin->custom_date_format = g_strdup(str); + clock_plugin->use_custom_date_font = xfce_rc_read_bool_entry(rcfile, + "use_custom_font", + FALSE); + str = xfce_rc_read_entry(rcfile, "font", NULL); + if(str) + clock_plugin->date_font = pango_font_description_from_string(str); + clock_plugin->date_color.red = xfce_rc_read_int_entry(rcfile, "color_r", + default_color->red); + clock_plugin->date_color.green = xfce_rc_read_int_entry(rcfile, "color_g", + default_color->green); + clock_plugin->date_color.blue = xfce_rc_read_int_entry(rcfile, "color_b", + default_color->blue); + + xfce_rc_set_group(rcfile, "time"); + clock_plugin->builtin_time_format = xfce_rc_read_int_entry(rcfile, + "builtin_format", + DEFAULT_TIME_FORMAT); + if(clock_plugin->builtin_time_format >= N_TIME_FORMATS) + clock_plugin->builtin_time_format = DEFAULT_TIME_FORMAT; + clock_plugin->use_custom_time_format = xfce_rc_read_bool_entry(rcfile, + "use_custom_format", + FALSE); + str = xfce_rc_read_entry(rcfile, "custom_format", NULL); + if(str) + clock_plugin->custom_time_format = g_strdup(str); + clock_plugin->use_custom_time_font = xfce_rc_read_bool_entry(rcfile, + "use_custom_font", + FALSE); + str = xfce_rc_read_entry(rcfile, "font", NULL); + if(str) + clock_plugin->time_font = pango_font_description_from_string(str); + clock_plugin->time_color.red = xfce_rc_read_int_entry(rcfile, "color_r", + default_color->red); + clock_plugin->time_color.green = xfce_rc_read_int_entry(rcfile, "color_g", + default_color->green); + clock_plugin->time_color.blue = xfce_rc_read_int_entry(rcfile, "color_b", + default_color->blue); + + xfce_rc_close(rcfile); + g_free(filename); + + clock_plugin->overall_format = xfclock_get_overall_format(clock_plugin); + return TRUE; } -static void -clock_free_data (XfcePanelPlugin *plugin, Clock *clock) +static XfceClockPlugin * +xfclock_plugin_new(XfcePanelPlugin *plugin) { - g_source_remove (clock->timeout_id); - g_object_unref (clock->tips); - g_free (clock); + XfceClockPlugin *clock_plugin = g_new0(XfceClockPlugin, 1); + + clock_plugin->plugin = plugin; + clock_plugin->tooltip = gtk_tooltips_new(); + + if(!xfclock_read_config(clock_plugin)) { + clock_plugin->show_frame = TRUE; + clock_plugin->layout = CLOCK_LAYOUT_TIME_ONLY; + clock_plugin->builtin_date_format = DEFAULT_DATE_FORMAT; + clock_plugin->builtin_time_format = DEFAULT_TIME_FORMAT; + clock_plugin->overall_format = g_strdup(builtin_time_formats[DEFAULT_TIME_FORMAT]); + } + + clock_plugin->evtbox = gtk_event_box_new(); + gtk_widget_show(clock_plugin->evtbox); + + clock_plugin->frame = gtk_frame_new(NULL); + gtk_container_set_border_width(GTK_CONTAINER(clock_plugin->frame), BORDER/2); + gtk_frame_set_shadow_type(GTK_FRAME(clock_plugin->frame), + clock_plugin->show_frame + ? GTK_SHADOW_IN : GTK_SHADOW_NONE); + gtk_widget_show(clock_plugin->frame); + gtk_container_add(GTK_CONTAINER(clock_plugin->evtbox), clock_plugin->frame); + + clock_plugin->label = gtk_label_new(""); + gtk_label_set_justify(GTK_LABEL(clock_plugin->label), GTK_JUSTIFY_CENTER); + gtk_misc_set_alignment(GTK_MISC(clock_plugin->label), 0.5, 0.5); + gtk_widget_show(clock_plugin->label); + gtk_container_add(GTK_CONTAINER(clock_plugin->frame), clock_plugin->label); + + return clock_plugin; } static void -clock_read_rc_file (XfcePanelPlugin *plugin, Clock* clock) +xfclock_config_layout_changed_cb(GtkComboBox *combo, + XfceClockConfig *clock_config) { - char *file; - XfceRc *rc; - int mode; - gboolean military, ampm, secs, show_frame; - - mode = XFCE_CLOCK_DIGITAL; - military = TRUE; - ampm = FALSE; - secs = FALSE; - show_frame = TRUE; + clock_config->clock_plugin->layout = gtk_combo_box_get_active(combo); - if ((file = xfce_panel_plugin_lookup_rc_file (plugin)) != NULL) - { - rc = xfce_rc_simple_open (file, TRUE); - g_free (file); - - if (rc != NULL) - { - mode = xfce_rc_read_int_entry (rc, "mode", XFCE_CLOCK_DIGITAL); - military = xfce_rc_read_bool_entry (rc, "military", TRUE); - ampm = xfce_rc_read_bool_entry (rc, "ampm", FALSE); - secs = xfce_rc_read_bool_entry (rc, "secs", FALSE); - show_frame = xfce_rc_read_bool_entry (rc, "show_frame", TRUE); - xfce_rc_close (rc); - } + if(clock_config->clock_plugin->layout == CLOCK_LAYOUT_DATE_ONLY) { + gtk_widget_set_sensitive(clock_config->date_frame, TRUE); + gtk_widget_set_sensitive(clock_config->time_frame, FALSE); + if(!clock_config->clock_plugin->use_custom_date_format) + gtk_widget_set_sensitive(clock_config->date_custom_box, FALSE); + } else if(clock_config->clock_plugin->layout == CLOCK_LAYOUT_TIME_ONLY) { + gtk_widget_set_sensitive(clock_config->date_frame, FALSE); + gtk_widget_set_sensitive(clock_config->time_frame, TRUE); + if(!clock_config->clock_plugin->use_custom_time_format) + gtk_widget_set_sensitive(clock_config->time_custom_box, FALSE); + } else { + gtk_widget_set_sensitive(clock_config->date_frame, TRUE); + gtk_widget_set_sensitive(clock_config->time_frame, TRUE); + if(!clock_config->clock_plugin->use_custom_date_format) + gtk_widget_set_sensitive(clock_config->date_custom_box, FALSE); + if(!clock_config->clock_plugin->use_custom_time_format) + gtk_widget_set_sensitive(clock_config->time_custom_box, FALSE); } + + xfclock_config_changed(clock_config->clock_plugin); +} - clock->mode = mode; - clock->military = military; - clock->ampm = ampm; - clock->secs = secs; +static void +xfclock_config_frame_toggled_cb(GtkToggleButton *tb, + XfceClockConfig *clock_config) +{ + clock_config->clock_plugin->show_frame = gtk_toggle_button_get_active(tb); + gtk_frame_set_shadow_type(GTK_FRAME(clock_config->clock_plugin->frame), + clock_config->clock_plugin->show_frame + ? GTK_SHADOW_IN : GTK_SHADOW_NONE); +} - xfce_clock_set_mode (XFCE_CLOCK (clock->clock), mode); - xfce_clock_show_military (XFCE_CLOCK (clock->clock), military); - xfce_clock_show_ampm (XFCE_CLOCK (clock->clock), ampm); - xfce_clock_show_secs (XFCE_CLOCK (clock->clock), secs); +static void +xfclock_config_time_fmt_changed_cb(GtkComboBox *combo, + XfceClockConfig *clock_config) +{ + gint setting = gtk_combo_box_get_active(combo); - clock->show_frame = show_frame; - gtk_frame_set_shadow_type (GTK_FRAME (clock->frame), - show_frame ? GTK_SHADOW_IN : GTK_SHADOW_NONE); + if(setting == N_TIME_FORMATS) { + clock_config->clock_plugin->use_custom_time_format = TRUE; + gtk_widget_set_sensitive(clock_config->time_custom_box, TRUE); + } else { + clock_config->clock_plugin->builtin_time_format = setting; + clock_config->clock_plugin->use_custom_time_format = FALSE; + gtk_widget_set_sensitive(clock_config->time_custom_box, FALSE); + } - clock_update_size (clock, - xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (plugin))); + xfclock_config_changed(clock_config->clock_plugin); } static void -clock_write_rc_file (XfcePanelPlugin *plugin, Clock *clock) +xfclock_config_date_fmt_changed_cb(GtkComboBox *combo, + XfceClockConfig *clock_config) { - char *file; - XfceRc *rc; + gint setting = gtk_combo_box_get_active(combo); - if (!(file = xfce_panel_plugin_save_location (plugin, TRUE))) - return; + if(setting == N_DATE_FORMATS) { + clock_config->clock_plugin->use_custom_date_format = TRUE; + gtk_widget_set_sensitive(clock_config->date_custom_box, TRUE); + } else { + clock_config->clock_plugin->builtin_date_format = setting; + clock_config->clock_plugin->use_custom_date_format = FALSE; + gtk_widget_set_sensitive(clock_config->date_custom_box, FALSE); + } + + xfclock_config_changed(clock_config->clock_plugin); +} - rc = xfce_rc_simple_open (file, FALSE); - g_free (file); - - if (!rc) - return; - - xfce_rc_write_int_entry (rc, "mode", clock->mode); - xfce_rc_write_bool_entry (rc, "military", clock->military); - xfce_rc_write_bool_entry (rc, "ampm", clock->ampm); - xfce_rc_write_bool_entry (rc, "secs", clock->secs); - xfce_rc_write_bool_entry (rc, "show_frame", clock->show_frame); +static gboolean +xfclock_config_custom_time_focus_out_cb(GtkWidget *w, + GdkEventFocus *evt, + XfceClockConfig *clock_config) +{ + gchar *str = gtk_editable_get_chars(GTK_EDITABLE(w), 0, -1); - xfce_rc_close (rc); + if(str && clock_config->clock_plugin->custom_time_format + && strcmp(str, clock_config->clock_plugin->custom_time_format)) + { + /* hasn't changed */ + g_free(str); + return FALSE; + } + + g_free(clock_config->clock_plugin->custom_time_format); + clock_config->clock_plugin->custom_time_format = str; + + xfclock_config_changed(clock_config->clock_plugin); + + return FALSE; } -/* Create widgets and connect to signals */ - -static void -clock_construct (XfcePanelPlugin *plugin) +static gboolean +xfclock_config_custom_date_focus_out_cb(GtkWidget *w, + GdkEventFocus *evt, + XfceClockConfig *clock_config) { - Clock *clock = g_new0 (Clock, 1); - - clock->plugin = plugin; - - g_signal_connect (plugin, "size-changed", - G_CALLBACK (clock_set_size), clock); + gchar *str = gtk_editable_get_chars(GTK_EDITABLE(w), 0, -1); - g_signal_connect (plugin, "free-data", - G_CALLBACK (clock_free_data), clock); + if(str && clock_config->clock_plugin->custom_date_format + && strcmp(str, clock_config->clock_plugin->custom_date_format)) + { + /* hasn't changed */ + g_free(str); + return FALSE; + } - g_signal_connect (plugin, "save", - G_CALLBACK (clock_write_rc_file), clock); + g_free(clock_config->clock_plugin->custom_date_format); + clock_config->clock_plugin->custom_date_format = str; - xfce_panel_plugin_menu_show_configure (plugin); - g_signal_connect (plugin, "configure-plugin", - G_CALLBACK (clock_properties_dialog), clock); + xfclock_config_changed(clock_config->clock_plugin); + + return FALSE; +} - clock->frame = gtk_frame_new (NULL); - gtk_widget_show (clock->frame); - gtk_container_add (GTK_CONTAINER (plugin), clock->frame); - - clock->clock = xfce_clock_new (); - gtk_widget_show (clock->clock); - gtk_container_add (GTK_CONTAINER (clock->frame), clock->clock); - - clock_read_rc_file (plugin, clock); +static void +xfclock_config_custom_time_font_cb(GtkToggleButton *tb, + XfceClockConfig *clock_config) +{ + gboolean setting = gtk_toggle_button_get_active(tb); - clock->tips = gtk_tooltips_new (); - g_object_ref (clock->tips); - gtk_object_sink (GTK_OBJECT (clock->tips)); - - clock_date_tooltip (clock); - - clock->timeout_id = - g_timeout_add (60000, (GSourceFunc) clock_date_tooltip, clock); + clock_config->clock_plugin->use_custom_time_font = setting; + + if(setting) { + gtk_widget_set_sensitive(clock_config->time_fontbtn, TRUE); + gtk_widget_set_sensitive(clock_config->time_colorbtn, TRUE); + } else { + gtk_widget_set_sensitive(clock_config->time_fontbtn, FALSE); + gtk_widget_set_sensitive(clock_config->time_colorbtn, FALSE); + } + + xfclock_config_changed(clock_config->clock_plugin); } -/* -------------------------------------------------------------------- * - * Configuration Dialog * - * -------------------------------------------------------------------- */ - static void -clock_show_frame_toggled (GtkToggleButton *cb, Clock *clock) +xfclock_config_time_font_set_cb(GtkFontButton *btn, + XfceClockConfig *clock_config) { - clock->show_frame = gtk_toggle_button_get_active (cb); - - gtk_frame_set_shadow_type (GTK_FRAME (clock->frame), clock->show_frame ? - GTK_SHADOW_IN : GTK_SHADOW_NONE); + const gchar *fontname = gtk_font_button_get_font_name(btn); + + if(clock_config->clock_plugin->time_font) + pango_font_description_free(clock_config->clock_plugin->time_font); + clock_config->clock_plugin->time_font = pango_font_description_from_string(fontname); + + xfclock_config_changed(clock_config->clock_plugin); } static void -clock_military_toggled (GtkToggleButton *cb, Clock *clock) +xfclock_config_time_color_set_cb(GtkColorButton *btn, + XfceClockConfig *clock_config) { - clock->military = gtk_toggle_button_get_active (cb); - xfce_clock_show_military (XFCE_CLOCK (clock->clock), clock->military); + GdkColor color; - clock_update_size (clock, - xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (clock->plugin))); + gtk_color_button_get_color(btn, &color); + memcpy(&clock_config->clock_plugin->time_color, &color, sizeof(color)); + + xfclock_config_changed(clock_config->clock_plugin); } static void -clock_ampm_toggled (GtkToggleButton *cb, Clock *clock) +xfclock_config_custom_date_font_cb(GtkToggleButton *tb, + XfceClockConfig *clock_config) { - clock->ampm = gtk_toggle_button_get_active(cb); - xfce_clock_show_ampm (XFCE_CLOCK (clock->clock), clock->ampm); + gboolean setting = gtk_toggle_button_get_active(tb); - clock_update_size (clock, - xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (clock->plugin))); + clock_config->clock_plugin->use_custom_date_font = setting; + + if(setting) { + gtk_widget_set_sensitive(clock_config->date_fontbtn, TRUE); + gtk_widget_set_sensitive(clock_config->date_colorbtn, TRUE); + } else { + gtk_widget_set_sensitive(clock_config->date_fontbtn, FALSE); + gtk_widget_set_sensitive(clock_config->date_colorbtn, FALSE); + } + + xfclock_config_changed(clock_config->clock_plugin); } static void -clock_secs_toggled (GtkToggleButton *cb, Clock *clock) +xfclock_config_date_font_set_cb(GtkFontButton *btn, + XfceClockConfig *clock_config) { - clock->secs = gtk_toggle_button_get_active(cb); - xfce_clock_show_secs (XFCE_CLOCK (clock->clock), clock->secs); + const gchar *fontname = gtk_font_button_get_font_name(btn); - clock_update_size (clock, - xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (clock->plugin))); + if(clock_config->clock_plugin->date_font) + pango_font_description_free(clock_config->clock_plugin->date_font); + clock_config->clock_plugin->date_font = pango_font_description_from_string(fontname); + + xfclock_config_changed(clock_config->clock_plugin); } static void -clock_mode_changed (GtkComboBox *cb, Clock *clock) +xfclock_config_date_color_set_cb(GtkColorButton *btn, + XfceClockConfig *clock_config) { - clock->mode = gtk_combo_box_get_active(cb); - xfce_clock_set_mode (XFCE_CLOCK (clock->clock), clock->mode); + GdkColor color; - clock_update_size (clock, - xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN (clock->plugin))); + gtk_color_button_get_color(btn, &color); + memcpy(&clock_config->clock_plugin->date_color, &color, sizeof(color)); + + xfclock_config_changed(clock_config->clock_plugin); } static void -clock_dialog_response (GtkWidget *dlg, int reponse, - Clock *clock) +xfclock_configure_plugin_cb(XfcePanelPlugin *plugin, + XfceClockPlugin *clock_plugin) { - gtk_widget_destroy (dlg); - xfce_panel_plugin_unblock_menu (clock->plugin); - clock_write_rc_file (clock->plugin, clock); + XfceClockConfig *clock_config = g_new0(XfceClockConfig, 1); + GtkWidget *header, *frame, *frame_bin, *topvbox, *vbox, *hbox, *lbl, *chk, + *combo, *entry, *btn, *colorbtn; + gint i; + gchar *str; + PangoFontDescription *font_desc; + + clock_config->clock_plugin = clock_plugin; + + clock_config->dlg = gtk_dialog_new_with_buttons(_("Clock Properties"), + GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(plugin))), + GTK_DIALOG_DESTROY_WITH_PARENT + | GTK_DIALOG_NO_SEPARATOR, + GTK_STOCK_CLOSE, + GTK_RESPONSE_ACCEPT, NULL); + g_signal_connect(G_OBJECT(clock_config->dlg), "response", + G_CALLBACK(gtk_widget_destroy), NULL); + g_signal_connect_swapped(G_OBJECT(clock_config->dlg), "destroy", + G_CALLBACK(g_free), clock_config); + topvbox = GTK_DIALOG(clock_config->dlg)->vbox; + + header = xfce_create_header(NULL, _("Clock")); + gtk_widget_set_size_request(GTK_BIN(header)->child, 200, 32); + gtk_container_set_border_width(GTK_CONTAINER(header), BORDER/2); + gtk_widget_show(header); + gtk_box_pack_start(GTK_BOX(topvbox), header, FALSE, TRUE, 0); + + frame = xfce_create_framebox(_("Appearance"), &frame_bin); + gtk_widget_show(frame); + gtk_box_pack_start(GTK_BOX(topvbox), frame, FALSE, FALSE, 0); + + vbox = gtk_vbox_new(FALSE, BORDER/2); + gtk_widget_show(vbox); + gtk_container_add(GTK_CONTAINER(frame_bin), vbox); + + chk = gtk_check_button_new_with_mnemonic(_("Show _Frame")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk), + clock_plugin->show_frame); + gtk_widget_show(chk); + gtk_box_pack_start(GTK_BOX(vbox), chk, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(chk), "toggled", + G_CALLBACK(xfclock_config_frame_toggled_cb), clock_config); + + hbox = gtk_hbox_new(FALSE, BORDER/2); + gtk_widget_show(hbox); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + + lbl = gtk_label_new(_("Display Layout:")); + gtk_widget_show(lbl); + gtk_box_pack_start(GTK_BOX(hbox), lbl, FALSE, FALSE, 0); + + combo = gtk_combo_box_new_text(); + for(i = 0; i < N_CLOCK_LAYOUTS; i++) + gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _(clock_layout_strs[i])); + gtk_combo_box_set_active(GTK_COMBO_BOX(combo), clock_plugin->layout); + gtk_widget_show(combo); + gtk_box_pack_start(GTK_BOX(hbox), combo, TRUE, TRUE, 0); + g_signal_connect(G_OBJECT(combo), "changed", + G_CALLBACK(xfclock_config_layout_changed_cb), clock_config); + + clock_config->time_frame = frame = xfce_create_framebox(_("Time Format"), + &frame_bin); + gtk_widget_show(frame); + gtk_box_pack_start(GTK_BOX(topvbox), frame, FALSE, FALSE, 0); + + vbox = gtk_vbox_new(FALSE, BORDER/2); + gtk_widget_show(vbox); + gtk_container_add(GTK_CONTAINER(frame_bin), vbox); + + combo = gtk_combo_box_new_text(); + for(i = 0; i < N_TIME_FORMATS; i++) { + str = xfclock_do_strftime(builtin_time_formats[i]); + gtk_combo_box_append_text(GTK_COMBO_BOX(combo), str); + g_free(str); + } + gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Custom...")); + if(clock_plugin->use_custom_time_format) + gtk_combo_box_set_active(GTK_COMBO_BOX(combo), N_TIME_FORMATS); + else { + gtk_combo_box_set_active(GTK_COMBO_BOX(combo), + clock_plugin->builtin_time_format); + } + gtk_widget_show(combo); + gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(combo), "changed", + G_CALLBACK(xfclock_config_time_fmt_changed_cb), clock_config); + + clock_config->time_custom_box = hbox = gtk_hbox_new(FALSE, BORDER/2); + gtk_widget_show(hbox); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + + lbl = gtk_label_new_with_mnemonic(_("Custom _time format:")); + gtk_widget_show(lbl); + gtk_box_pack_start(GTK_BOX(hbox), lbl, FALSE, FALSE, 0); + + entry = gtk_entry_new(); + if(clock_plugin->custom_time_format) + gtk_entry_set_text(GTK_ENTRY(entry), clock_plugin->custom_time_format); + gtk_widget_show(entry); + gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); + g_signal_connect(G_OBJECT(entry), "focus-out-event", + G_CALLBACK(xfclock_config_custom_time_focus_out_cb), + clock_config); + gtk_label_set_mnemonic_widget(GTK_LABEL(lbl), entry); + + if(clock_plugin->layout == CLOCK_LAYOUT_DATE_ONLY) + gtk_widget_set_sensitive(frame, FALSE); + else if(!clock_plugin->use_custom_time_format) + gtk_widget_set_sensitive(hbox, FALSE); + + hbox = gtk_hbox_new(FALSE, BORDER/2); + gtk_widget_show(hbox); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + + chk = gtk_check_button_new_with_mnemonic(_("_Custom font:")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk), + clock_plugin->use_custom_time_font); + gtk_widget_show(chk); + gtk_box_pack_start(GTK_BOX(hbox), chk, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(chk), "toggled", + G_CALLBACK(xfclock_config_custom_time_font_cb), + clock_config); + + if(clock_plugin->time_font) + font_desc = clock_plugin->time_font; + else + font_desc = clock_plugin->label->style->font_desc; + str = pango_font_description_to_string(font_desc); + + clock_config->time_fontbtn = btn = gtk_font_button_new_with_font(str); + if(!clock_plugin->use_custom_time_font) + gtk_widget_set_sensitive(btn, FALSE); + gtk_widget_show(btn); + gtk_box_pack_start(GTK_BOX(hbox), btn, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(btn), "font-set", + G_CALLBACK(xfclock_config_time_font_set_cb), clock_config); + g_free(str); + + clock_config->time_colorbtn = colorbtn + = gtk_color_button_new_with_color(&clock_plugin->time_color); + if(!clock_plugin->use_custom_time_font) + gtk_widget_set_sensitive(colorbtn, FALSE); + gtk_widget_show(colorbtn); + gtk_box_pack_start(GTK_BOX(hbox), colorbtn, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(colorbtn), "color-set", + G_CALLBACK(xfclock_config_time_color_set_cb), clock_config); + + clock_config->date_frame = frame = xfce_create_framebox(_("Date Format"), + &frame_bin); + gtk_widget_show(frame); + gtk_box_pack_start(GTK_BOX(topvbox), frame, FALSE, FALSE, 0); + + vbox = gtk_vbox_new(FALSE, BORDER/2); + gtk_widget_show(vbox); + gtk_container_add(GTK_CONTAINER(frame_bin), vbox); + + combo = gtk_combo_box_new_text(); + for(i = 0; i < N_DATE_FORMATS; i++) { + str = xfclock_do_strftime(builtin_date_formats[i]); + gtk_combo_box_append_text(GTK_COMBO_BOX(combo), str); + g_free(str); + } + gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Custom...")); + if(clock_plugin->use_custom_date_format) + gtk_combo_box_set_active(GTK_COMBO_BOX(combo), N_DATE_FORMATS); + else { + gtk_combo_box_set_active(GTK_COMBO_BOX(combo), + clock_plugin->builtin_date_format); + } + gtk_widget_show(combo); + gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(combo), "changed", + G_CALLBACK(xfclock_config_date_fmt_changed_cb), clock_config); + + clock_config->date_custom_box = hbox = gtk_hbox_new(FALSE, BORDER/2); + gtk_widget_show(hbox); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + + lbl = gtk_label_new_with_mnemonic(_("Custom _date format:")); + gtk_widget_show(lbl); + gtk_box_pack_start(GTK_BOX(hbox), lbl, FALSE, FALSE, 0); + + entry = gtk_entry_new(); + if(clock_plugin->custom_date_format) + gtk_entry_set_text(GTK_ENTRY(entry), clock_plugin->custom_date_format); + gtk_widget_show(entry); + gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); + g_signal_connect(G_OBJECT(entry), "focus-out-event", + G_CALLBACK(xfclock_config_custom_date_focus_out_cb), + clock_config); + gtk_label_set_mnemonic_widget(GTK_LABEL(lbl), entry); + + if(clock_plugin->layout == CLOCK_LAYOUT_TIME_ONLY) + gtk_widget_set_sensitive(frame, FALSE); + else if(!clock_plugin->use_custom_date_format) + gtk_widget_set_sensitive(hbox, FALSE); + + hbox = gtk_hbox_new(FALSE, BORDER/2); + gtk_widget_show(hbox); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + + chk = gtk_check_button_new_with_mnemonic(_("Custom _font:")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk), + clock_plugin->use_custom_date_font); + gtk_widget_show(chk); + gtk_box_pack_start(GTK_BOX(hbox), chk, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(chk), "toggled", + G_CALLBACK(xfclock_config_custom_date_font_cb), + clock_config); + + if(clock_plugin->date_font) + font_desc = clock_plugin->date_font; + else + font_desc = clock_plugin->label->style->font_desc; + str = pango_font_description_to_string(font_desc); + + clock_config->date_fontbtn = btn = gtk_font_button_new_with_font(str); + if(!clock_plugin->use_custom_date_font) + gtk_widget_set_sensitive(btn, FALSE); + gtk_widget_show(btn); + gtk_box_pack_start(GTK_BOX(hbox), btn, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(btn), "font-set", + G_CALLBACK(xfclock_config_date_font_set_cb), clock_config); + g_free(str); + + clock_config->date_colorbtn = colorbtn + = gtk_color_button_new_with_color(&clock_plugin->date_color); + if(!clock_plugin->use_custom_date_font) + gtk_widget_set_sensitive(colorbtn, FALSE); + gtk_widget_show(colorbtn); + gtk_box_pack_start(GTK_BOX(hbox), colorbtn, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(colorbtn), "color-set", + G_CALLBACK(xfclock_config_date_color_set_cb), clock_config); + + gtk_widget_show(clock_config->dlg); } static void -clock_properties_dialog (XfcePanelPlugin *plugin, Clock *clock) +xfclock_free_data_cb(XfcePanelPlugin *plugin, + XfceClockPlugin *clock_plugin) { - GtkWidget *dlg, *header, *frame, *bin, *vbox, *cb; - - xfce_panel_plugin_block_menu (plugin); + if(clock_plugin->clock_timeout) + g_source_remove(clock_plugin->clock_timeout); - dlg = gtk_dialog_new_with_buttons (_("Properties"), - GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin))), - GTK_DIALOG_DESTROY_WITH_PARENT | - GTK_DIALOG_NO_SEPARATOR, - GTK_STOCK_CLOSE, GTK_RESPONSE_OK, - NULL); + gtk_object_sink(GTK_OBJECT(clock_plugin->tooltip)); - g_signal_connect (dlg, "response", G_CALLBACK (clock_dialog_response), - clock); + g_free(clock_plugin->overall_format); + g_free(clock_plugin->custom_time_format); + g_free(clock_plugin->custom_date_format); + if(clock_plugin->time_font) + pango_font_description_free(clock_plugin->time_font); + if(clock_plugin->date_font) + pango_font_description_free(clock_plugin->date_font); + + g_free(clock_plugin); +} - gtk_container_set_border_width (GTK_CONTAINER (dlg), 2); +static void +xfclock_save_cb(XfcePanelPlugin *plugin, + XfceClockPlugin *clock_plugin) +{ + XfceRc *rcfile; + char *filename; - header = xfce_create_header (NULL, _("Clock")); - gtk_widget_set_size_request (GTK_BIN (header)->child, 200, 32); - gtk_container_set_border_width (GTK_CONTAINER (header), 6); - gtk_widget_show (header); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), header, - FALSE, TRUE, 0); + filename = xfce_panel_plugin_save_location(plugin, TRUE); + if(!filename) + return; - frame = xfce_create_framebox (_("Appearance"), &bin); - gtk_container_set_border_width (GTK_CONTAINER (frame), 6); - gtk_widget_show (frame); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), frame, - FALSE, FALSE, 0); + rcfile = xfce_rc_simple_open(filename, FALSE); + if(!rcfile) { + g_free(filename); + return; + } - vbox = gtk_vbox_new (FALSE, 8); - gtk_widget_show (vbox); - gtk_container_add (GTK_CONTAINER (bin), vbox); + xfce_rc_set_group(rcfile, "plugin"); + xfce_rc_write_bool_entry(rcfile, "show_frame", clock_plugin->show_frame); + xfce_rc_write_int_entry(rcfile, "layout", clock_plugin->layout); + + xfce_rc_set_group(rcfile, "date"); + xfce_rc_write_int_entry(rcfile, "builtin_format", + clock_plugin->builtin_date_format); + xfce_rc_write_bool_entry(rcfile, "use_custom_format", + clock_plugin->use_custom_date_format); + if(clock_plugin->custom_date_format) { + xfce_rc_write_entry(rcfile, "custom_format", + clock_plugin->custom_date_format); + } + xfce_rc_write_bool_entry(rcfile, "use_custom_font", + clock_plugin->use_custom_date_font); + if(clock_plugin->date_font) { + gchar *str = pango_font_description_to_string(clock_plugin->date_font); + xfce_rc_write_entry(rcfile, "font", str); + g_free(str); + } + xfce_rc_write_int_entry(rcfile, "color_r", clock_plugin->date_color.red); + xfce_rc_write_int_entry(rcfile, "color_g", clock_plugin->date_color.green); + xfce_rc_write_int_entry(rcfile, "color_b", clock_plugin->date_color.blue); + + xfce_rc_set_group(rcfile, "time"); + xfce_rc_write_int_entry(rcfile, "builtin_format", + clock_plugin->builtin_time_format); + xfce_rc_write_bool_entry(rcfile, "use_custom_format", + clock_plugin->use_custom_time_format); + if(clock_plugin->custom_time_format) { + xfce_rc_write_entry(rcfile, "custom_format", + clock_plugin->custom_time_format); + } + xfce_rc_write_bool_entry(rcfile, "use_custom_font", + clock_plugin->use_custom_time_font); + if(clock_plugin->time_font) { + gchar *str = pango_font_description_to_string(clock_plugin->time_font); + xfce_rc_write_entry(rcfile, "font", str); + g_free(str); + } + xfce_rc_write_int_entry(rcfile, "color_r", clock_plugin->time_color.red); + xfce_rc_write_int_entry(rcfile, "color_g", clock_plugin->time_color.green); + xfce_rc_write_int_entry(rcfile, "color_b", clock_plugin->time_color.blue); + + xfce_rc_close(rcfile); + g_free(filename); +} - cb = gtk_combo_box_new_text (); - gtk_widget_show (cb); - gtk_box_pack_start (GTK_BOX (vbox), cb, FALSE, FALSE, 0); +static gboolean +xfclock_size_changed_cb(XfcePanelPlugin *plugin, + gint size, + XfceClockPlugin *clock_plugin) +{ + if(GTK_ORIENTATION_HORIZONTAL == xfce_panel_plugin_get_orientation(plugin)) { + /* ensure the clock doesn't force the panel larger */ + gtk_widget_set_size_request(clock_plugin->frame, -1, size); + return TRUE; + } + + return FALSE; +} - /* Keep order in sync with XfceClockMode */ - gtk_combo_box_append_text (GTK_COMBO_BOX (cb), _("Analog")); - gtk_combo_box_append_text (GTK_COMBO_BOX (cb), _("Digital")); - gtk_combo_box_append_text (GTK_COMBO_BOX (cb), _("LED")); - gtk_combo_box_set_active (GTK_COMBO_BOX (cb), clock->mode); - g_signal_connect (cb, "changed", - G_CALLBACK (clock_mode_changed), clock); - - cb = gtk_check_button_new_with_mnemonic (_("Show _frame")); - gtk_widget_show (cb); - gtk_box_pack_start (GTK_BOX (vbox), cb, FALSE, FALSE, 0); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb), - clock->show_frame); - g_signal_connect (cb, "toggled", G_CALLBACK (clock_show_frame_toggled), - clock); +static void +xfclock_construct(XfcePanelPlugin *plugin) +{ + XfceClockPlugin *clock_plugin; - frame = xfce_create_framebox (_("Clock Options"), &bin); - gtk_container_set_border_width (GTK_CONTAINER (frame), 6); - gtk_widget_show (frame); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), frame, - FALSE, FALSE, 0); + xfce_textdomain(GETTEXT_PACKAGE, LOCALEDIR, "UTF-8"); - vbox = gtk_vbox_new (FALSE, 8); - gtk_widget_show (vbox); - gtk_container_add (GTK_CONTAINER (bin), vbox); - - cb = gtk_check_button_new_with_mnemonic (_("Use 24-_hour clock")); - gtk_widget_show (cb); - gtk_box_pack_start (GTK_BOX (vbox), cb, FALSE, FALSE, 0); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb), - clock->military); - g_signal_connect (cb, "toggled", G_CALLBACK (clock_military_toggled), - clock); - - cb = gtk_check_button_new_with_mnemonic (_("Show AM/PM")); - gtk_widget_show (cb); - gtk_box_pack_start (GTK_BOX (vbox), cb, FALSE, FALSE, 0); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb), - clock->ampm); - g_signal_connect (cb, "toggled", G_CALLBACK (clock_ampm_toggled), - clock); - - cb = gtk_check_button_new_with_mnemonic (_("Display seconds")); - gtk_widget_show (cb); - gtk_box_pack_start (GTK_BOX (vbox), cb, FALSE, FALSE, 0); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb), - clock->secs); - g_signal_connect (cb, "toggled", G_CALLBACK (clock_secs_toggled), - clock); - - gtk_widget_show (dlg); + clock_plugin = xfclock_plugin_new(plugin); + gtk_container_add(GTK_CONTAINER(plugin), clock_plugin->evtbox); + + xfce_panel_plugin_add_action_widget(plugin, clock_plugin->evtbox); + xfce_panel_plugin_menu_show_configure(plugin); + + g_signal_connect(G_OBJECT(plugin), "configure-plugin", + G_CALLBACK(xfclock_configure_plugin_cb), clock_plugin); + g_signal_connect(G_OBJECT(plugin), "free-data", + G_CALLBACK(xfclock_free_data_cb), clock_plugin); + g_signal_connect(G_OBJECT(plugin), "save", + G_CALLBACK(xfclock_save_cb), clock_plugin); + g_signal_connect(G_OBJECT(plugin), "size-changed", + G_CALLBACK(xfclock_size_changed_cb), clock_plugin); + + clock_plugin->clock_timeout = g_timeout_add(1000, + (GSourceFunc)xfclock_timeout, + clock_plugin); + } +XFCE_PANEL_PLUGIN_REGISTER_INTERNAL(xfclock_construct) Index: configure.ac =================================================================== --- configure.ac (revision 18423) +++ configure.ac (working copy) @@ -44,7 +44,7 @@ dnl Check for standard header files AC_HEADER_STDC AC_CHECK_HEADERS([signal.h stddef.h sys/wait.h time.h]) -AC_CHECK_FUNCS([sigaction]) +AC_CHECK_FUNCS([localtime_r sigaction]) dnl Check for i18n support XDT_I18N([ar az be bg bn_IN ca cs de el en_GB eo es_MX es et eu fa fi fr