diff -urN xfce_orig/libxfcegui4/libxfcegui4/xfce_clock.c xfce/libxfcegui4/libxfcegui4/xfce_clock.c --- xfce_orig/libxfcegui4/libxfcegui4/xfce_clock.c 2006-09-02 17:50:21.000000000 +0300 +++ xfce/libxfcegui4/libxfcegui4/xfce_clock.c 2006-09-02 17:52:32.000000000 +0300 @@ -42,8 +42,10 @@ #include #endif + #include #include +#include #include "xfce_clock.h" @@ -410,6 +412,8 @@ clock->old_hour = 0; clock->old_minute = 0; clock->old_second = 0; + clock->show_formatted = 0; + clock->format_string = NULL; } GtkWidget * @@ -695,10 +699,42 @@ return (clock->mode); } +void +xfce_clock_set_format (XfceClock * clock, const gchar * format) +{ + if (clock->format_string != NULL) + { + g_free (clock->format_string); + clock->format_string = NULL; + } + + clock->format_string = NULL; + if (format != NULL) + { + clock->format_string = g_strdup (format); + } +} + +static void +xfce_clock_format_time_to_utf8 (gchar * dest, gsize dst_size, + const gchar * fmt, struct tm *tm) +{ + if (dest == NULL || fmt == NULL || tm == NULL) + return; + + gchar *dummy = g_locale_from_utf8 (fmt, -1, NULL, NULL, NULL); + + strftime (dest, 256, dummy, tm); + g_free (dummy); + dummy = g_locale_to_utf8 (dest, -1, NULL, NULL, NULL); + g_strlcpy (dest, dummy, dst_size); + g_free (dummy); +} + static void xfce_clock_size_request (GtkWidget * widget, GtkRequisition * requisition) { - gchar buffer[16]; + gchar buffer[256]; XfceClock *clock; guint ln = 0; guint width = 0; @@ -714,7 +750,17 @@ switch (clock->mode) { case XFCE_CLOCK_DIGITAL: - if (clock->military_time) + if (clock->show_formatted) + { + + time_t ticks = time (0); + struct tm *tm = localtime (&ticks); + + xfce_clock_format_time_to_utf8 (buffer, 256, + clock->format_string, tm); + + } + else if (clock->military_time) { if (clock->display_secs) { @@ -1013,7 +1059,7 @@ gint h, m, s; gint x, y; gchar ampm[3] = "AM"; - gchar time_buf[24]; + gchar time_buf[256]; gint width, height; /* to measure out string. */ PangoLayout *layout = NULL; @@ -1028,6 +1074,8 @@ m = tm->tm_min; s = tm->tm_sec; + time_buf[0] = '\0'; + if (h >= 12) ampm[0] = 'P'; @@ -1039,7 +1087,14 @@ h = 12; } - if (clock->military_time) + if (clock->show_formatted && + clock->format_string != NULL && strlen (clock->format_string) != 0) + { + xfce_clock_format_time_to_utf8 (time_buf, 256, clock->format_string, + tm); + + } + else if (clock->military_time) { if (clock->display_secs) sprintf (time_buf, "%d:%02d:%02d", h, m, s); @@ -1104,6 +1159,25 @@ } } +void +xfce_clock_set_formatted_view (XfceClock * clock, gboolean formatted) +{ + g_return_if_fail (clock != NULL); + g_return_if_fail (XFCE_IS_CLOCK (clock)); + + clock->show_formatted = formatted; +} + +gboolean +xfce_clock_get_formatted_view (XfceClock * clock) +{ + g_return_val_if_fail (clock != NULL, 0); + g_return_val_if_fail (XFCE_IS_CLOCK (clock), 0); + + return clock->show_formatted; +} + + static void xfce_clock_draw_analog (GtkWidget * widget, GdkRectangle * area) { diff -urN xfce_orig/libxfcegui4/libxfcegui4/xfce_clock.h xfce/libxfcegui4/libxfcegui4/xfce_clock.h --- xfce_orig/libxfcegui4/libxfcegui4/xfce_clock.h 2006-09-02 17:50:21.000000000 +0300 +++ xfce/libxfcegui4/libxfcegui4/xfce_clock.h 2006-09-02 17:52:32.000000000 +0300 @@ -74,6 +74,9 @@ gboolean display_secs; XfceClockLedSize led_size; + gboolean show_formatted; + gchar *format_string; + /* Private data */ GdkBitmap *digits_bmap; @@ -110,6 +113,9 @@ void xfce_clock_resume (XfceClock * clock); void xfce_clock_set_mode (XfceClock * clock, XfceClockMode mode); void xfce_clock_toggle_mode (XfceClock * clock); +void xfce_clock_set_format (XfceClock * clock, const gchar * format); +void xfce_clock_set_formatted_view (XfceClock * clock, gboolean formatted); +gboolean xfce_clock_get_formatted_view (XfceClock * clock); XfceClockMode xfce_clock_get_mode (XfceClock * clock); G_END_DECLS diff -urN xfce_orig/xfce4-panel/plugins/clock/clock.c xfce/xfce4-panel/plugins/clock/clock.c --- xfce_orig/xfce4-panel/plugins/clock/clock.c 2006-09-02 17:54:02.000000000 +0300 +++ xfce/xfce4-panel/plugins/clock/clock.c 2006-09-02 16:10:45.000000000 +0300 @@ -1,6 +1,6 @@ /* vim: set expandtab ts=8 sw=4: */ -/* $Id$ +/* $Id: clock.c 22739 2006-08-13 09:10:57Z jasper $ * * Copyright © 2005 The Xfce Development Team * @@ -67,6 +67,11 @@ gboolean military; gboolean ampm; gboolean secs; + gchar *launch_command; + gboolean use_sn; + gboolean in_terminal; + gboolean show_formatted; + gchar *format_string; gboolean show_frame; } @@ -81,14 +86,20 @@ GtkWidget *cb_military; GtkWidget *cb_ampm; GtkWidget *cb_secs; + GtkWidget *cb_in_terminal; + GtkWidget *cb_use_sn; + GtkWidget *cb_launch_command; + GtkWidget *cb_format_string; + GtkWidget *cb_show_formatted; } ClockDialog; +static const gchar *default_application = "orage"; + static void clock_properties_dialog (XfcePanelPlugin * plugin, Clock * clock); static void clock_construct (XfcePanelPlugin * plugin); - /* -------------------------------------------------------------------- * * Clock * * -------------------------------------------------------------------- */ @@ -209,7 +220,6 @@ /* Interface Implementation */ - static gboolean clock_set_size (XfcePanelPlugin * plugin, int size, Clock * clock) { @@ -237,13 +247,17 @@ char *file; XfceRc *rc; int mode; - gboolean military, ampm, secs, show_frame; + gboolean military, ampm, secs, show_frame, in_terminal, use_sn, + show_formatted; + const gchar *launch_command, *format_string; mode = XFCE_CLOCK_DIGITAL; military = TRUE; ampm = FALSE; secs = FALSE; show_frame = FALSE; + launch_command = format_string = NULL; + show_formatted = use_sn = in_terminal = FALSE; if ((file = xfce_panel_plugin_lookup_rc_file (plugin)) != NULL) { @@ -257,6 +271,12 @@ 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", FALSE); + in_terminal = xfce_rc_read_bool_entry (rc, "in_terminal", FALSE); + use_sn = xfce_rc_read_bool_entry (rc, "use_sn", FALSE); + launch_command = xfce_rc_read_entry (rc, "launch_command", NULL); + show_formatted = + xfce_rc_read_bool_entry (rc, "show_formatted", FALSE); + format_string = xfce_rc_read_entry (rc, "format_string", NULL); xfce_rc_close (rc); } } @@ -265,6 +285,26 @@ clock->military = military; clock->ampm = ampm; clock->secs = secs; + clock->in_terminal = in_terminal; + clock->use_sn = use_sn; + clock->show_formatted = show_formatted; + + if (launch_command == NULL || strlen (launch_command) == 0) + { + launch_command = default_application; + } + + clock->launch_command = g_strdup (launch_command); + + if (format_string != NULL && strlen (format_string) != 0) + { + clock->format_string = g_strdup (format_string); + } + else + { + clock->format_string = NULL; + } + xfce_clock_set_mode (XFCE_CLOCK (clock->clock), mode); xfce_clock_show_military (XFCE_CLOCK (clock->clock), military); @@ -300,10 +340,31 @@ 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); + xfce_rc_write_bool_entry (rc, "in_terminal", clock->in_terminal); + xfce_rc_write_bool_entry (rc, "use_sn", clock->use_sn); + if (clock->launch_command != NULL) + xfce_rc_write_entry (rc, "launch_command", clock->launch_command); + xfce_rc_write_bool_entry (rc, "show_formatted", clock->show_formatted); + if (clock->format_string != NULL) + xfce_rc_write_entry (rc, "format_string", clock->format_string); xfce_rc_close (rc); } +static gboolean +clock_launch_on_click (XfcePanelPlugin * plugin, GdkEventButton * event, + Clock * clock) +{ + if (event->type == GDK_2BUTTON_PRESS && clock->launch_command) + xfce_exec (clock->launch_command, clock->in_terminal, clock->use_sn, + NULL); + + return TRUE; +} + + + + /* Create widgets and connect to signals */ static void @@ -326,6 +387,9 @@ g_signal_connect (plugin, "configure-plugin", G_CALLBACK (clock_properties_dialog), clock); + g_signal_connect (plugin, "button-press-event", + G_CALLBACK (clock_launch_on_click), clock); + clock->frame = gtk_frame_new (NULL); gtk_widget_show (clock->frame); gtk_container_add (GTK_CONTAINER (plugin), clock->frame); @@ -338,6 +402,15 @@ clock_read_rc_file (plugin, clock); + xfce_clock_set_format (XFCE_CLOCK (clock->clock), clock->format_string); + xfce_clock_set_formatted_view (XFCE_CLOCK (clock->clock), + clock->show_formatted); + + clock_update_size (clock, + xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN + (clock->plugin))); + + clock->tips = gtk_tooltips_new (); g_object_ref (G_OBJECT (clock->tips)); gtk_object_sink (GTK_OBJECT (clock->tips)); @@ -399,6 +472,19 @@ cd->clock->secs = active; xfce_clock_show_secs (XFCE_CLOCK (cd->clock->clock), active); } + else if (cb == cd->cb_in_terminal) + { + cd->clock->in_terminal = active; + } + else if (cb == cd->cb_use_sn) + { + cd->clock->use_sn = active; + } + else if (cb == cd->cb_show_formatted) + { + cd->clock->show_formatted = active; + xfce_clock_set_formatted_view (XFCE_CLOCK (cd->clock->clock), active); + } clock_update_size (cd->clock, xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN @@ -419,6 +505,62 @@ } static void +clock_launch_name_changed (GtkEntry * cb, ClockDialog * cd) +{ + Clock *clock = cd->clock; + + if (clock->launch_command != NULL) + g_free (cd->clock->launch_command); + + clock->launch_command = g_strdup (gtk_entry_get_text (cb)); +} + +static void +clock_format_changed (GtkEntry * cb, ClockDialog * cd) +{ + const gchar *entry_text = gtk_entry_get_text (GTK_ENTRY (cb)); + + if (cd->clock->format_string != NULL) + { + g_free (cd->clock->format_string); + cd->clock->format_string = NULL; + } + + + if (entry_text != NULL && strlen (entry_text) != 0) + { + cd->clock->format_string = g_strdup (entry_text); + } + else + { + cd->clock->show_formatted = FALSE; + xfce_clock_set_formatted_view (XFCE_CLOCK (cd->clock->clock), FALSE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (cd->cb_show_formatted), FALSE); + } + + xfce_clock_set_format (XFCE_CLOCK (cd->clock->clock), + cd->clock->format_string); + + gboolean secs = FALSE; + + if (strstr (entry_text, "%S") != NULL + || strstr (entry_text, "%OS") != NULL + || strstr (entry_text, "%T") != NULL + || strstr (entry_text, "%r") != NULL) + { + secs = TRUE; + } + + cd->clock->secs = secs; + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cd->cb_secs), secs); + + clock_update_size (cd->clock, + xfce_panel_plugin_get_size (XFCE_PANEL_PLUGIN + (cd->clock->plugin))); +} + +static void clock_dialog_response (GtkWidget * dlg, int reponse, ClockDialog * cd) { g_object_set_data (G_OBJECT (cd->clock->plugin), "dialog", NULL); @@ -504,8 +646,67 @@ clock_set_sensative (cd); + frame = xfce_create_framebox (_("Launch on click options"), &bin); + gtk_container_set_border_width (GTK_CONTAINER (frame), 6); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), frame, + FALSE, FALSE, 0); + + vbox = gtk_vbox_new (FALSE, 8); + gtk_container_add (GTK_CONTAINER (bin), vbox); + + + cb = gtk_label_new (_("Program name")); + gtk_misc_set_alignment (GTK_MISC (cb), 0.f, 0.f); + gtk_box_pack_start (GTK_BOX (vbox), cb, FALSE, FALSE, 0); + + cd->cb_launch_command = cb = gtk_entry_new (); + gtk_box_pack_start (GTK_BOX (vbox), cb, FALSE, FALSE, 0); + gtk_entry_set_text (GTK_ENTRY (cb), cd->clock->launch_command); + + g_signal_connect (cb, "changed", + G_CALLBACK (clock_launch_name_changed), cd); + + cd->cb_in_terminal = cb = + gtk_check_button_new_with_mnemonic (_("Run in _terminal")); + gtk_box_pack_start (GTK_BOX (vbox), cb, FALSE, FALSE, 0); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb), clock->in_terminal); + g_signal_connect (cb, "toggled", G_CALLBACK (clock_button_toggled), cd); + + cd->cb_use_sn = cb = + gtk_check_button_new_with_mnemonic (_("Use startup _notification")); + gtk_box_pack_start (GTK_BOX (vbox), cb, FALSE, FALSE, 0); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb), clock->use_sn); + g_signal_connect (cb, "toggled", G_CALLBACK (clock_button_toggled), cd); + g_signal_connect (dlg, "response", G_CALLBACK (clock_dialog_response), cd); + frame = xfce_create_framebox (_("User defined view"), &bin); + gtk_container_set_border_width (GTK_CONTAINER (frame), 6); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), frame, + FALSE, FALSE, 0); + + vbox = gtk_vbox_new (FALSE, 8); + gtk_container_add (GTK_CONTAINER (bin), vbox); + + cb = gtk_label_new (_("Format string (see strftime for details)")); + gtk_misc_set_alignment (GTK_MISC (cb), 0.f, 0.f); + gtk_box_pack_start (GTK_BOX (vbox), cb, FALSE, FALSE, 0); + + cd->cb_format_string = cb = gtk_entry_new (); + gtk_box_pack_start (GTK_BOX (vbox), cb, FALSE, FALSE, 0); + gtk_entry_set_text (GTK_ENTRY (cb), cd->clock->format_string); + + g_signal_connect (cb, "changed", G_CALLBACK (clock_format_changed), cd); + + + cd->cb_show_formatted = cb = + gtk_check_button_new_with_mnemonic (_("Show _custom string")); + gtk_box_pack_start (GTK_BOX (vbox), cb, FALSE, FALSE, 0); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb), + clock->show_formatted); + g_signal_connect (cb, "toggled", G_CALLBACK (clock_button_toggled), cd); + + gtk_widget_show_all (dlg); }