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-07 11:09:21.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) { @@ -226,6 +236,12 @@ if (dlg) gtk_widget_destroy (dlg); + if ( clock->format_string != NULL ) + g_free( clock->format_string ); + + if ( clock->launch_command != NULL ) + g_free( clock->launch_command ); + g_source_remove (clock->timeout_id); g_object_unref (G_OBJECT (clock->tips)); panel_slice_free (Clock, clock); @@ -237,13 +253,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 +277,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 +291,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 +346,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_BUTTON_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 +393,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 +408,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 +478,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 +511,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 +652,68 @@ 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); + if ( cd->clock->format_string != NULL ) + 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); }