[Goodies-commits] r2344 - in xfce4-datetime-plugin/branches/enhanced_configdialog: . panel-plugin

Remco den Breeje stacium at xfce.org
Fri Jan 12 17:03:26 CET 2007


Author: stacium
Date: 2007-01-12 16:03:26 +0000 (Fri, 12 Jan 2007)
New Revision: 2344

Modified:
   xfce4-datetime-plugin/branches/enhanced_configdialog/ChangeLog
   xfce4-datetime-plugin/branches/enhanced_configdialog/panel-plugin/datetime-dialog.c
   xfce4-datetime-plugin/branches/enhanced_configdialog/panel-plugin/datetime.c
   xfce4-datetime-plugin/branches/enhanced_configdialog/panel-plugin/datetime.h
Log:
datetime-plugin: User-readable format in config-dialog



Modified: xfce4-datetime-plugin/branches/enhanced_configdialog/ChangeLog
===================================================================
--- xfce4-datetime-plugin/branches/enhanced_configdialog/ChangeLog	2007-01-12 11:10:30 UTC (rev 2343)
+++ xfce4-datetime-plugin/branches/enhanced_configdialog/ChangeLog	2007-01-12 16:03:26 UTC (rev 2344)
@@ -1,5 +1,11 @@
-2005-12-26  Remco den Breeje <remco at sx.mine.nu>
-    * Version 0.5.0 - User can choose a layout, added built-in formats of date
+2007-01-12  Remco den Breeje <remco at sx.mine.nu>
+    * Show actual date and times instead of the format codes in the
+    config-dialog. 
+    * Created general strftime function for the datetime plugin
+      
+
+2006-12-26  Remco den Breeje <remco at sx.mine.nu>
+    * Trial Version 0.5.0 - User can choose a layout, added built-in formats of date
       and time. Based on the patch for the clock-plugin by Nick Schermer and 
       Brian Tarricone. 
       See http://foo-projects.org/~nick/patches/xfce4-panel-clock.patch

Modified: xfce4-datetime-plugin/branches/enhanced_configdialog/panel-plugin/datetime-dialog.c
===================================================================
--- xfce4-datetime-plugin/branches/enhanced_configdialog/panel-plugin/datetime-dialog.c	2007-01-12 11:10:30 UTC (rev 2343)
+++ xfce4-datetime-plugin/branches/enhanced_configdialog/panel-plugin/datetime-dialog.c	2007-01-12 16:03:26 UTC (rev 2344)
@@ -62,6 +62,9 @@
   N_("Custom...")
 };
 
+/* example timestamp to show in the dialog */
+const time_t example_time_t = 946684799;
+
 /*
  * show and read fonts and inform datetime about it
  */
@@ -279,6 +282,8 @@
 datetime_properties_dialog(XfcePanelPlugin *plugin, t_datetime * datetime)
 {
   gint i;
+  gchar *utf8str;
+  struct tm *exampletm;
   GtkWidget *dlg,
 	    *frame,
 	    *vbox,
@@ -381,11 +386,16 @@
   /* 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++)
   {
-    gtk_combo_box_append_text(GTK_COMBO_BOX(time_combobox), time_format[i]);
+    utf8str = datetime_do_utf8strftime(time_format[i], exampletm);
+    gtk_combo_box_append_text(GTK_COMBO_BOX(time_combobox), utf8str);
+    g_free(utf8str);
 
-    /* set active - strcmp isn't fast, but it is done once opening the dialog */
+    /* 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)
       gtk_combo_box_set_active(GTK_COMBO_BOX(time_combobox), i);
   }
@@ -453,11 +463,16 @@
   /* 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++)
-  {
-    gtk_combo_box_append_text(GTK_COMBO_BOX(date_combobox), date_format[i]);
+  {  
+    utf8str = datetime_do_utf8strftime(date_format[i], exampletm);
+    gtk_combo_box_append_text(GTK_COMBO_BOX(date_combobox), utf8str);
+    g_free(utf8str);
 
-    /* set active - strcmp isn't fast, but it is done once opening the dialog */
+    /* 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)
       gtk_combo_box_set_active(GTK_COMBO_BOX(date_combobox), i);
   }

Modified: xfce4-datetime-plugin/branches/enhanced_configdialog/panel-plugin/datetime.c
===================================================================
--- xfce4-datetime-plugin/branches/enhanced_configdialog/panel-plugin/datetime.c	2007-01-12 11:10:30 UTC (rev 2343)
+++ xfce4-datetime-plugin/branches/enhanced_configdialog/panel-plugin/datetime.c	2007-01-12 16:03:26 UTC (rev 2344)
@@ -35,14 +35,34 @@
 #include "datetime-dialog.h"
 
 /*
+ * Get date/time string
+ */
+gchar * datetime_do_utf8strftime(const char *format, const struct tm *tm)
+{
+  int len;
+  gchar buf[256];
+  gchar *utf8str = NULL;
+
+  /* get formatted date/time */
+  len = strftime(buf, sizeof(buf)-1, format, tm);
+  if (len == 0)
+    return g_strdup(_("Invalid format"));
+
+  buf[len] = '\0';  /* make sure nul terminated string */
+  utf8str = g_locale_to_utf8(buf, -1, NULL, NULL, NULL);
+  if(utf8str == NULL)
+    return g_strdup(_("Error"));
+
+  return utf8str;
+}
+
+/*
  * set date and time labels
  */
 gboolean datetime_update(gpointer data)
 {
   GTimeVal timeval;
-  gchar buf[256];
   gchar *utf8str;
-  int len;
   struct tm *current;
   t_datetime *datetime;
 
@@ -57,40 +77,16 @@
   current = localtime((time_t *)&timeval.tv_sec);
   if (datetime->date_format != NULL && GTK_IS_LABEL(datetime->date_label))
   {
-    len = strftime(buf, sizeof(buf) - 1, datetime->date_format, current);
-    if (len != 0)
-    {
-      buf[len] = '\0';  /* make sure nul terminated string */
-      utf8str = g_locale_to_utf8(buf, len, NULL, NULL, NULL);
-      if (utf8str != NULL)
-      {
-	gtk_label_set_text(GTK_LABEL(datetime->date_label), utf8str);
-	g_free(utf8str);
-      }
-    }
-    else
-    {
-      gtk_label_set_text(GTK_LABEL(datetime->date_label), _("Error"));
-    }
+    utf8str = datetime_do_utf8strftime(datetime->date_format, current);
+    gtk_label_set_text(GTK_LABEL(datetime->date_label), utf8str);
+    g_free(utf8str);
   }
 
   if (datetime->time_format != NULL && GTK_IS_LABEL(datetime->time_label))
   {
-    len = strftime(buf, sizeof(buf) - 1, datetime->time_format, current);
-    if (len != 0)
-    {
-      buf[len] = '\0';  /* make sure nul terminated string */
-      utf8str = g_locale_to_utf8(buf, len, NULL, NULL, NULL);
-      if (utf8str != NULL)
-      {
-	gtk_label_set_text(GTK_LABEL(datetime->time_label), utf8str);
-	g_free(utf8str);
-      }
-    }
-    else
-    {
-      gtk_label_set_text(GTK_LABEL(datetime->time_label), _("Error"));
-    }
+    utf8str = datetime_do_utf8strftime(datetime->time_format, current);
+    gtk_label_set_text(GTK_LABEL(datetime->time_label), utf8str);
+    g_free(utf8str);
   }
 
   /* hide labels based on layout-selection */

Modified: xfce4-datetime-plugin/branches/enhanced_configdialog/panel-plugin/datetime.h
===================================================================
--- xfce4-datetime-plugin/branches/enhanced_configdialog/panel-plugin/datetime.h	2007-01-12 11:10:30 UTC (rev 2343)
+++ xfce4-datetime-plugin/branches/enhanced_configdialog/panel-plugin/datetime.h	2007-01-12 16:03:26 UTC (rev 2344)
@@ -68,6 +68,11 @@
 gboolean
 datetime_update(gpointer data);
 
+gchar * 
+datetime_do_utf8strftime(
+    const char *format, 
+    const struct tm *tm);
+
 void
 datetime_apply_font(t_datetime *datetime,
     const gchar *date_font_name,




More information about the Goodies-commits mailing list