changes to the clock plugin in libxfcegui4-4.0.5 and xfce4-panel-4.0.5

Wayne Tucker wtucker at donobi.com
Mon Jun 7 03:34:18 CEST 2004


Greetings,

I just finished modifying the clock plugin to allow the time to be
displayed in UTC instead of the local time zone.  I am using one clock
to display local time, and another to show UTC since that time zone is
used on a lot of my network systems (calculating it mentally is a
nuisance, especially with offset changes for DST).

I believe this is a feature that others will also find useful, so I am
submitting the patches to the XFCE project.  Please consider including
this feature into the next version of XFCE.

Best wishes,

Wayne


-- 
Wayne A. Tucker       Sr. Network Engineer, Aspiring Guru
wtucker at donobi.com    DONOBI, Inc. <http://www.donobi.com/>
+1-360-473-1169       "The Internet Solutions Company"




-------------- next part --------------
diff -cr libxfcegui4-4.0.5.orig/libxfcegui4/xfce_clock.c libxfcegui4-4.0.5/libxfcegui4/xfce_clock.c
*** libxfcegui4-4.0.5.orig/libxfcegui4/xfce_clock.c	Wed Jun  4 09:47:30 2003
--- libxfcegui4-4.0.5/libxfcegui4/xfce_clock.c	Sun Jun  6 17:58:50 2004
***************
*** 401,406 ****
--- 401,407 ----
      clock->military_time = 0;	/* use 12 hour mode by default */
      clock->display_am_pm = 1;	/* display am or pm by default. */
      clock->display_secs = 0;	/* do not display secs by default */
+     clock->display_utc = 0;     /* use localtime() by default */
      clock->interval = 100;	/* 1/10 seconds update interval by default */
      clock->led_size = DIGIT_MEDIUM;
      clock->digits_bmap = NULL;
***************
*** 525,530 ****
--- 526,568 ----
  }
  
  void
+ xfce_clock_show_utc (XfceClock * clock, gboolean show)
+ {
+     g_return_if_fail (clock != NULL);
+     g_return_if_fail (XFCE_IS_CLOCK (clock));
+     clock->display_utc = show;
+     if (GTK_WIDGET_VISIBLE (GTK_WIDGET (clock)))
+     {
+         gtk_widget_queue_draw (GTK_WIDGET (clock));
+     }
+ }
+    
+ void
+ xfce_clock_utc_toggle (XfceClock * clock)
+ {
+     g_return_if_fail (clock != NULL);
+     g_return_if_fail (XFCE_IS_CLOCK (clock));
+ 
+     if (clock->display_utc)
+         clock->display_utc = 0;
+     else
+         clock->display_utc = 1;
+     if (GTK_WIDGET_VISIBLE (GTK_WIDGET (clock)))
+     {
+         gtk_widget_queue_draw (GTK_WIDGET (clock));
+     }
+ }
+ 
+ gboolean
+ xfce_clock_utc_shown (XfceClock * clock)
+ {
+     g_return_val_if_fail (clock != NULL, FALSE);
+     g_return_val_if_fail (XFCE_IS_CLOCK (clock), FALSE);
+     return (clock->display_utc);
+ }
+ 
+ 
+ void
  xfce_clock_show_military (XfceClock * clock, gboolean show)
  {
      g_return_if_fail (clock != NULL);
***************
*** 1021,1027 ****
      clock = XFCE_CLOCK (widget);
  
      ticks = time (0);
!     tm = localtime (&ticks);
      h = tm->tm_hour;
      m = tm->tm_min;
      s = tm->tm_sec;
--- 1059,1072 ----
      clock = XFCE_CLOCK (widget);
  
      ticks = time (0);
!     if (clock->display_utc)
!     {
!         tm = gmtime (&ticks);
!     }
!     else
!     {
!         tm = localtime (&ticks);
!     }
      h = tm->tm_hour;
      m = tm->tm_min;
      s = tm->tm_sec;
***************
*** 1199,1205 ****
      clock = XFCE_CLOCK (widget);
  
      ticks = time (0);
!     tm = localtime (&ticks);
      h = tm->tm_hour;
      m = tm->tm_min;
      s = tm->tm_sec;
--- 1244,1257 ----
      clock = XFCE_CLOCK (widget);
  
      ticks = time (0);
!     if (clock->display_utc)
!     {
!         tm = gmtime (&ticks);
!     }
!     else
!     {
!         tm = localtime (&ticks);
!     }
      h = tm->tm_hour;
      m = tm->tm_min;
      s = tm->tm_sec;
***************
*** 1391,1397 ****
      g_return_val_if_fail (XFCE_IS_CLOCK (clock), FALSE);
  
      ticks = time (0);
!     tm = localtime (&ticks);
      h = tm->tm_hour;
      m = tm->tm_min;
      s = tm->tm_sec;
--- 1443,1456 ----
      g_return_val_if_fail (XFCE_IS_CLOCK (clock), FALSE);
  
      ticks = time (0);
!     if (clock->display_utc)
!     {
!         tm = gmtime (&ticks);
!     }
!     else
!     {
!         tm = localtime (&ticks);
!     }
      h = tm->tm_hour;
      m = tm->tm_min;
      s = tm->tm_sec;
diff -cr libxfcegui4-4.0.5.orig/libxfcegui4/xfce_clock.h libxfcegui4-4.0.5/libxfcegui4/xfce_clock.h
*** libxfcegui4-4.0.5.orig/libxfcegui4/xfce_clock.h	Sat May 17 15:22:22 2003
--- libxfcegui4-4.0.5/libxfcegui4/xfce_clock.h	Sun Jun  6 17:59:17 2004
***************
*** 77,82 ****
--- 77,83 ----
  	gboolean military_time;	/* true=24 hour clock, false = 12 hour clock. */
  	gboolean display_am_pm;
  	gboolean display_secs;
+         gboolean display_utc; /* true: tm = gmtime(), false: tm = localtime() */
  	XfceClockLedSize led_size;
  
  	/* Private data */
***************
*** 106,111 ****
--- 107,115 ----
      void xfce_clock_show_secs (XfceClock * clock, gboolean show);
      void xfce_clock_secs_toggle (XfceClock * clock);
      gboolean xfce_clock_secs_shown (XfceClock * clock);
+     void xfce_clock_show_utc (XfceClock * clock, gboolean show);
+     void xfce_clock_utc_toggle (XfceClock * clock);
+     gboolean xfce_clock_utc_shown (XfceClock * clock);
      void xfce_clock_show_military (XfceClock * clock, gboolean show);
      void xfce_clock_military_toggle (XfceClock * clock);
      gboolean xfce_clock_military_shown (XfceClock * clock);
-------------- next part --------------
diff -rc xfce4-panel-4.0.5.orig/plugins/clock/clock.c xfce4-panel-4.0.5/plugins/clock/clock.c
*** xfce4-panel-4.0.5.orig/plugins/clock/clock.c	Fri Jul 18 08:58:49 2003
--- xfce4-panel-4.0.5/plugins/clock/clock.c	Sun Jun  6 18:01:57 2004
***************
*** 100,105 ****
--- 100,106 ----
      int military;
      int ampm;
      int secs;
+     int utc;
  
      /* controls dialog */
      GtkWidget *dialog;
***************
*** 112,117 ****
--- 113,119 ----
      GtkWidget *ampm_rb;
  
      GtkWidget *seconds_cb;
+     GtkWidget *utc_cb;
  }
  ClockDialog;
  
***************
*** 253,258 ****
--- 255,262 ----
      xmlSetProp (root, "Toggle_am_pm", value);
      g_snprintf (value, 2, "%d", clock->display_secs);
      xmlSetProp (root, "Toggle_secs", value);
+     g_snprintf (value, 2, "%d", clock->display_utc);
+     xmlSetProp (root, "Toggle_utc", value);
  }
  
  /* Read the configuration file at init */
***************
*** 293,298 ****
--- 297,307 ----
  	XFCE_CLOCK (cl->clock)->display_secs = atoi (value);
  	g_free (value);
      }
+     if ((value = xmlGetProp (node, (const xmlChar *) "Toggle_utc")))
+     {
+         XFCE_CLOCK (cl->clock)->display_utc = atoi (value);
+         g_free (value);
+     }
  
      /* Try to resize the clock to fit the user settings */
      clock_set_size (control, settings.size);
***************
*** 502,507 ****
--- 511,551 ----
      g_signal_connect (cb, "toggled", G_CALLBACK (clock_seconds_changed), cd);
  }
  
+ /* show time in UTC */
+ static void
+ clock_utc_changed (GtkToggleButton * tb, ClockDialog * cd)
+ {
+     XfceClock *xclock = XFCE_CLOCK (cd->clock->clock);
+ 
+     xfce_clock_show_utc (xclock, gtk_toggle_button_get_active (tb));
+     update_clock_size (xclock, settings.size);
+ }
+     
+ static void
+ add_utc_box (GtkWidget * vbox, GtkSizeGroup * sg, ClockDialog * cd)
+ {
+     GtkWidget *hbox, *label, *cb;
+     XfceClock *xclock = XFCE_CLOCK (cd->clock->clock);
+ 
+     hbox = gtk_hbox_new (FALSE, BORDER);
+     gtk_widget_show (hbox);
+     gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+      
+     label = gtk_label_new (_("Show time in UTC:"));
+     gtk_widget_show (label);
+     gtk_size_group_add_widget (sg, label);
+     gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+     gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+         
+     cb = cd->utc_cb = gtk_check_button_new ();
+     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb),
+                                   xclock->display_utc);
+     gtk_widget_show (cb);
+     gtk_box_pack_start (GTK_BOX (hbox), cb, FALSE, FALSE, 0);
+ 
+     g_signal_connect (cb, "toggled", G_CALLBACK (clock_utc_changed), cd);
+ }
+ 
  #if 0
  /* backup */
  static void
***************
*** 515,520 ****
--- 559,565 ----
      cd->military = clock->military_time;
      cd->ampm = clock->display_am_pm;
      cd->secs = clock->display_secs;
+     cd->utc = clock->display_utc;
  }
  
  static void
***************
*** 535,543 ****
  
      gtk_toggle_button_set_active (tb, TRUE);
  
!     /* seconds */
      tb = GTK_TOGGLE_BUTTON (cd->seconds_cb);
      gtk_toggle_button_set_active (tb, cd->secs);
  }
  #endif
  
--- 580,592 ----
  
      gtk_toggle_button_set_active (tb, TRUE);
  
!     /* seconds and UTC */
      tb = GTK_TOGGLE_BUTTON (cd->seconds_cb);
      gtk_toggle_button_set_active (tb, cd->secs);
+ 
+     tb = GTK_TOGGLE_BUTTON (cd->utc_cb);
+     gtk_toggle_button_set_actibe (tb, cd->utc);
+ 
  }
  #endif
  
***************
*** 569,574 ****
--- 618,625 ----
      add_hour_mode_box (vbox, sg, cd);
  
      add_seconds_box (vbox, sg, cd);
+     
+     add_utc_box (vbox, sg, cd);
  
      gtk_container_add (container, vbox);
  }
Only in xfce4-panel-4.0.5/plugins/clock: clock.c.orig


More information about the Xfce4-dev mailing list