Index: new2/panel-plugin/datetime-dialog.c =================================================================== --- new2/panel-plugin/datetime-dialog.c (revision 54) +++ new2/panel-plugin/datetime-dialog.c (working copy) @@ -44,27 +44,49 @@ N_("Time, then date") }; -/* builtin formats - derived from xfce4-panel-clock.patch by Nick Schermer */ -#define TIME_FORMAT_COUNT 6 -static const char *time_format[] = { - "%H:%M", "%H:%M:%S", - "%l:%M %P", "%l:%M:%S %P", - "---", - N_("Custom...") +typedef struct dt_format { + char* format; /* date or time format string */ + char* text; /* text displayed in combobox */ +} dt_format_t; + +/* + * Builtin formats - derived from xfce4-panel-clock.patch by Nick Schermer. + * NULL entries are filled in at runtime. + */ +static dt_format_t time_format[] = { + "%X", N_("System"), + "%H:%M", NULL, + "%H:%M:%S", NULL, + "%l:%M %P", NULL, + "%l:%M:%S %P", NULL, + "---", "---", /* dummy entry for separator */ + NULL, N_("Custom...") }; +#define TIME_FORMAT_COUNT (sizeof(time_format)/sizeof(dt_format_t)) -#define DATE_FORMAT_COUNT 13 -static const char *date_format[] = { - "%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", "---", - N_("Custom...") +static dt_format_t date_format[] = { + "%x", N_("System"), + "%F", NULL, + "%m/%d/%Y", NULL, + "%B %d, %Y", NULL, + "%b %d, %Y", NULL, + "%A, %B %d, %Y", NULL, + "%a, %b %d, %Y", NULL, + "%d/%m/%Y", NULL, + "%d %B %Y", NULL, + "%d %b %Y", NULL, + "%A, %d %B %Y", NULL, + "%a, %d %b %Y", NULL, + "---", "---", /* dummy entry for separator */ + NULL, N_("Custom...") }; +#define DATE_FORMAT_COUNT (sizeof(date_format)/sizeof(dt_format_t)) -/* example timestamp to show in the dialog */ +/* + * Example timestamp to show in the dialog. + * Compute with: + * date +%s -u -d 'dec 31 1999 23:59:59' + */ static const time_t example_time_t = 946684799; /* @@ -93,12 +115,12 @@ dialog = gtk_font_selection_dialog_new(_("Select font")); gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(dialog), - fontname); + fontname); if (G_LIKELY (previewtext != NULL)) { gtk_font_selection_dialog_set_preview_text(GTK_FONT_SELECTION_DIALOG(dialog), - previewtext); + previewtext); } result = gtk_dialog_run(GTK_DIALOG(dialog)); @@ -112,9 +134,9 @@ gtk_button_set_label(GTK_BUTTON(widget), font_name); if(target == DATE) - datetime_apply_font(dt, font_name, NULL); + datetime_apply_font(dt, font_name, NULL); else - datetime_apply_font(dt, NULL, font_name); + datetime_apply_font(dt, NULL, font_name); g_free (font_name); } @@ -136,30 +158,30 @@ switch(layout) { case LAYOUT_DATE: - gtk_widget_set_sensitive(dt->date_font_selector, TRUE); + gtk_widget_set_sensitive(dt->date_font_selector, TRUE); gtk_widget_set_sensitive(dt->date_format_combobox, TRUE); - gtk_widget_set_sensitive(dt->date_format_entry, TRUE); - gtk_widget_set_sensitive(dt->time_font_selector, FALSE); + gtk_widget_set_sensitive(dt->date_format_entry, TRUE); + gtk_widget_set_sensitive(dt->time_font_selector, FALSE); gtk_widget_set_sensitive(dt->time_format_combobox, FALSE); - gtk_widget_set_sensitive(dt->time_format_entry, FALSE); + gtk_widget_set_sensitive(dt->time_format_entry, FALSE); break; case LAYOUT_TIME: - gtk_widget_set_sensitive(dt->date_font_selector, FALSE); + gtk_widget_set_sensitive(dt->date_font_selector, FALSE); gtk_widget_set_sensitive(dt->date_format_combobox, FALSE); - gtk_widget_set_sensitive(dt->date_format_entry, FALSE); - gtk_widget_set_sensitive(dt->time_font_selector, TRUE); + gtk_widget_set_sensitive(dt->date_format_entry, FALSE); + gtk_widget_set_sensitive(dt->time_font_selector, TRUE); gtk_widget_set_sensitive(dt->time_format_combobox, TRUE); - gtk_widget_set_sensitive(dt->time_format_entry, TRUE); + gtk_widget_set_sensitive(dt->time_format_entry, TRUE); break; default: - gtk_widget_set_sensitive(dt->date_font_selector, TRUE); + gtk_widget_set_sensitive(dt->date_font_selector, TRUE); gtk_widget_set_sensitive(dt->date_format_combobox, TRUE); - gtk_widget_set_sensitive(dt->date_format_entry, TRUE); - gtk_widget_set_sensitive(dt->time_font_selector, TRUE); + gtk_widget_set_sensitive(dt->date_format_entry, TRUE); + gtk_widget_set_sensitive(dt->time_font_selector, TRUE); gtk_widget_set_sensitive(dt->time_format_combobox, TRUE); - gtk_widget_set_sensitive(dt->time_format_entry, TRUE); + gtk_widget_set_sensitive(dt->time_format_entry, TRUE); } datetime_apply_layout(dt, layout); @@ -167,29 +189,23 @@ } /* - * Row seperator for format-comboboxes of date and time + * Row separator for format-comboboxes of date and time * derived from xfce4-panel-clock.patch by Nick Schermer */ static gboolean combo_box_row_separator (GtkTreeModel *model, - GtkTreeIter *iter, - gpointer data) + GtkTreeIter *iter, + gpointer data) { - /* Hack: the 2nd item from the end will be a separator */ - - gint total, current; + dt_format_t *fmt = (dt_format_t *)data; GtkTreePath *path; + gint current; path = gtk_tree_model_get_path (model, iter); current = gtk_tree_path_get_indices (path)[0]; gtk_tree_path_free (path); - total = gtk_tree_model_iter_n_children (model, NULL); - - if (total == (current + 2)) - return TRUE; - else - return FALSE; + return(fmt[current].text != NULL && fmt[current].text[0] == '-'); } /* @@ -211,7 +227,7 @@ { /* disable custom-text-field and tell datetime which format we choose */ gtk_widget_hide(dt->date_format_entry); - datetime_apply_format(dt, date_format[active], NULL); + datetime_apply_format(dt, date_format[active].format, NULL); } datetime_update(dt); @@ -236,7 +252,7 @@ { /* disable custom-text-field and tell datetime which format we choose */ gtk_widget_hide(dt->time_format_entry); - datetime_apply_format(dt, NULL, time_format[active]); + datetime_apply_format(dt, NULL, time_format[active].format); } datetime_update(dt); @@ -252,9 +268,9 @@ format = gtk_entry_get_text(GTK_ENTRY(widget)); if (format != NULL) { - if(widget == dt->date_format_entry) /* date */ + if(widget == dt->date_format_entry) /* date */ datetime_apply_format(dt, format, NULL); - else if(widget == dt->time_format_entry) /* or time */ + else if(widget == dt->time_format_entry) /* or time */ datetime_apply_format(dt, NULL, format); } datetime_update(dt); @@ -285,19 +301,19 @@ { gint i; gchar *utf8str; - struct tm *exampletm; + struct tm *exampletm = gmtime(&example_time_t); GtkWidget *dlg, - *frame, - *vbox, - *hbox, - *layout_combobox, - *time_combobox, - *date_combobox, - *label, - *image, - *button, - *entry, - *bin; + *frame, + *vbox, + *hbox, + *layout_combobox, + *time_combobox, + *date_combobox, + *label, + *image, + *button, + *entry, + *bin; GtkSizeGroup *sg; xfce_textdomain (GETTEXT_PACKAGE, LOCALEDIR, "UTF-8"); @@ -395,32 +411,32 @@ /* format combobox */ date_combobox = gtk_combo_box_new_text(); gtk_box_pack_start(GTK_BOX(hbox), date_combobox, TRUE, TRUE, 0); - exampletm = gmtime(&example_time_t); for(i=0; i < DATE_FORMAT_COUNT; i++) { - if(i < DATE_FORMAT_COUNT - 1) - { - utf8str = datetime_do_utf8strftime(date_format[i], exampletm); + if (date_format[i].format == NULL) + date_format[i].format = g_strdup(""); + + if(date_format[i].text == NULL) { + utf8str = datetime_do_utf8strftime(date_format[i].format, exampletm); gtk_combo_box_append_text(GTK_COMBO_BOX(date_combobox), utf8str); g_free(utf8str); + } else { + gtk_combo_box_append_text(GTK_COMBO_BOX(date_combobox), _(date_format[i].text)); } - else - { - gtk_combo_box_append_text(GTK_COMBO_BOX(date_combobox), _(date_format[i])); - } /* set active * strcmp isn't fast, but it is done only once while opening the dialog */ - if(strcmp(datetime->date_format,date_format[i]) == 0) + if(strcmp(datetime->date_format,date_format[i].format) == 0) gtk_combo_box_set_active(GTK_COMBO_BOX(date_combobox), i); } - /* if no field selected -> select custom field */ if(gtk_combo_box_get_active(GTK_COMBO_BOX(date_combobox)) < 0) gtk_combo_box_set_active(GTK_COMBO_BOX(date_combobox), DATE_FORMAT_COUNT-1); + gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(date_combobox), - combo_box_row_separator, - NULL, NULL); + combo_box_row_separator, + date_format, NULL); + g_signal_connect(G_OBJECT(date_combobox), "changed", G_CALLBACK(date_format_changed), datetime); datetime->date_format_combobox = date_combobox; @@ -481,32 +497,33 @@ /* format combobox */ time_combobox = gtk_combo_box_new_text(); gtk_box_pack_start(GTK_BOX(hbox), time_combobox, TRUE, TRUE, 0); - exampletm = gmtime(&example_time_t); for(i=0; i < TIME_FORMAT_COUNT; i++) { - if(i < TIME_FORMAT_COUNT - 1) - { - utf8str = datetime_do_utf8strftime(time_format[i], exampletm); + if (time_format[i].format == NULL) + time_format[i].format = g_strdup(""); + + if(time_format[i].text == NULL) { + utf8str = datetime_do_utf8strftime(time_format[i].format, exampletm); gtk_combo_box_append_text(GTK_COMBO_BOX(time_combobox), utf8str); g_free(utf8str); + } else { + gtk_combo_box_append_text(GTK_COMBO_BOX(time_combobox), _(time_format[i].text)); } - else - { - gtk_combo_box_append_text(GTK_COMBO_BOX(time_combobox), _(time_format[i])); - } /* set active * strcmp isn't fast, but it is done only once while opening the dialog */ - if(strcmp(datetime->time_format,time_format[i]) == 0) + if(strcmp(datetime->time_format,time_format[i].format) == 0) gtk_combo_box_set_active(GTK_COMBO_BOX(time_combobox), i); } /* if no field selected -> select custom field */ if(gtk_combo_box_get_active(GTK_COMBO_BOX(time_combobox)) < 0) gtk_combo_box_set_active(GTK_COMBO_BOX(time_combobox), TIME_FORMAT_COUNT-1); + gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(time_combobox), - combo_box_row_separator, - NULL, NULL); + combo_box_row_separator, + time_format, NULL); + g_signal_connect(G_OBJECT(time_combobox), "changed", G_CALLBACK(time_format_changed), datetime); datetime->time_format_combobox = time_combobox; @@ -547,7 +564,7 @@ label = gtk_label_new(NULL); gtk_label_set_markup(GTK_LABEL(label), _("The information on which day the calendar week " - "starts is derived from the locale.")); + "starts is derived from the locale.")); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); Index: new2/panel-plugin/datetime.c =================================================================== --- new2/panel-plugin/datetime.c (revision 54) +++ new2/panel-plugin/datetime.c (working copy) @@ -455,8 +455,8 @@ layout = LAYOUT_DATE_TIME; date_font = "Bitstream Vera Sans 8"; time_font = "Bitstream Vera Sans 10"; - date_format = "%Y/%m/%d"; - time_format = "%H:%M"; + date_format = "%x"; + time_format = "%X"; /* open file */ if((file = xfce_panel_plugin_lookup_rc_file(plugin)) != NULL)