[Xfce4-commits] <xfce4-panel:devel> * Fuzzy clock updates.

Nick Schermer nick at xfce.org
Tue Aug 11 20:26:14 CEST 2009


Updating branch refs/heads/devel
         to 90df609105573996d316db36c115d63b6f2afdc8 (commit)
       from 8acba611903a745fb8ea43f8388409ae2b606739 (commit)

commit 90df609105573996d316db36c115d63b6f2afdc8
Author: Nick Schermer <nick at xfce.org>
Date:   Sun Nov 9 20:06:06 2008 +0100

    * Fuzzy clock updates.

 STATUS                           |    1 +
 plugins/clock/clock-dialog.glade |    3 +-
 plugins/clock/clock-fuzzy.c      |   73 ++++++++++++++++++++++++++++++--------
 plugins/clock/clock.c            |   19 +++++-----
 4 files changed, 70 insertions(+), 26 deletions(-)

diff --git a/STATUS b/STATUS
index a200ba9..2efffe6 100644
--- a/STATUS
+++ b/STATUS
@@ -7,6 +7,7 @@ New features
   External plugins now run inside a wrapper program. As a result
   a lot of code has been removed from libxfce4panel.
 - Support for alpha transparent panels.
+- Clock plugin tooltips is only updated when pointer is above the clock.
 
 
 Bugs Fixed
diff --git a/plugins/clock/clock-dialog.glade b/plugins/clock/clock-dialog.glade
index eaeb043..dbc1734 100644
--- a/plugins/clock/clock-dialog.glade
+++ b/plugins/clock/clock-dialog.glade
@@ -327,8 +327,7 @@
     </data>
   </object>
   <object class="GtkAdjustment" id="fuzziness">
-    <property name="value">1</property>
-    <property name="upper">4</property>
+    <property name="upper">3</property>
     <property name="step_increment">1</property>
     <property name="page_increment">1</property>
     <property name="page_size">1</property>
diff --git a/plugins/clock/clock-fuzzy.c b/plugins/clock/clock-fuzzy.c
index 846fc17..f786d20 100644
--- a/plugins/clock/clock-fuzzy.c
+++ b/plugins/clock/clock-fuzzy.c
@@ -49,11 +49,10 @@ enum
   FUZZINESS_5_MINS = 0,
   FUZZINESS_15_MINS,
   FUZZINESS_DAY,
-  FUZZINESS_WEEK,
 
   FUZZINESS_MIN = FUZZINESS_5_MINS,
-  FUZZINESS_MAX = FUZZINESS_WEEK,
-  FUZZINESS_DEFAULT = FUZZINESS_15_MINS
+  FUZZINESS_MAX = FUZZINESS_DAY,
+  FUZZINESS_DEFAULT = FUZZINESS_5_MINS
 };
 
 enum
@@ -75,6 +74,34 @@ struct _XfceClockFuzzy
   guint fuzziness;
 };
 
+const gchar *i18n_day_sectors[] =
+{
+  N_("Night"),   N_("Early morning"),
+  N_("Morning"), N_("Almost noon"),
+  N_("Noon"),    N_("Afternoon"),
+  N_("Evening"), N_("Late evening")
+};
+
+const gchar *i18n_hour_sectors[] =
+{
+  N_("five past %s"),        N_("ten past %s"),
+  N_("quarter past %s"),     N_("twenty past %s"),
+  N_("twenty five past %s"), N_("half past %s"),
+  N_("twenty five to %s"),   N_("twenty to %s"),
+  N_("quarter to %s"),       N_("ten to %s"),
+  N_("five to %s"),          N_("%s o'clock")
+};
+
+const gchar *i18n_hour_names[] =
+{
+  N_("one"),    N_("two"),
+  N_("three"),  N_("four"),
+  N_("five"),   N_("six"),
+  N_("seven"),  N_("eight"),
+  N_("nine"),   N_("ten"),
+  N_("eleven"), N_("twelve")
+};
+
 
 
 G_DEFINE_TYPE (XfceClockFuzzy, xfce_clock_fuzzy, GTK_TYPE_LABEL);
@@ -171,25 +198,41 @@ xfce_clock_fuzzy_update (gpointer user_data)
 {
   XfceClockFuzzy *clock = XFCE_CLOCK_FUZZY (user_data);
   struct tm       tm;
-  const gchar    *strings_day[] = { N_("Night"),   N_("Early morning"),
-                                    N_("Morning"), N_("Almost noon"),
-                                    N_("Noon"),    N_("Afternoon"),
-                                    N_("Evening"), N_("Late evening") };
+  gint            hour_sector;
+  gint            minutes, hour;
+  gchar          *string;
 
   panel_return_val_if_fail (XFCE_CLOCK_IS_FUZZY (clock), FALSE);
 
   /* get the local time */
   clock_plugin_get_localtime (&tm);
 
-  switch (clock->fuzziness)
+  if (clock->fuzziness == FUZZINESS_5_MINS
+      || clock->fuzziness == FUZZINESS_15_MINS)
     {
-      case FUZZINESS_5_MINS:
-      case FUZZINESS_15_MINS:
-      case FUZZINESS_DAY:
-      case FUZZINESS_WEEK:
-        gtk_label_set_text (GTK_LABEL (clock), _(strings_day[tm.tm_hour / 3]));
-        break;
-    };
+      /* set the time */
+      minutes = tm.tm_min;
+      hour = tm.tm_hour > 12 ? tm.tm_hour - 12 : tm.tm_hour;
+
+      /* get the hour sector */
+      if (clock->fuzziness == FUZZINESS_5_MINS)
+        hour_sector = minutes >= 3 ? (minutes - 3) / 5 : 11;
+      else
+        hour_sector = minutes > 7 ? ((minutes - 7) / 15 + 1) * 3 - 1 : 11;
+
+      /* advance 1 hour, if we're half past */
+      if (hour_sector <= 6)
+        hour--;
+
+      /* set the time string */
+      string = g_strdup_printf (_(i18n_hour_sectors[hour_sector]), _(i18n_hour_names[hour]));
+      gtk_label_set_text (GTK_LABEL (clock), string);
+      g_free (string);
+    }
+  else /* FUZZINESS_DAY */
+    {
+      gtk_label_set_text (GTK_LABEL (clock), _(i18n_day_sectors[tm.tm_hour / 3]));
+    }
 
   return TRUE;
 }
diff --git a/plugins/clock/clock.c b/plugins/clock/clock.c
index d180e01..6f27a5f 100644
--- a/plugins/clock/clock.c
+++ b/plugins/clock/clock.c
@@ -407,19 +407,20 @@ clock_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
       object = gtk_builder_get_object (builder, "mode");
       g_signal_connect (G_OBJECT (object), "changed", G_CALLBACK (clock_plugin_configure_plugin_visibility), builder);
 
-      #define create_binding(property, type) \
+      #define create_binding(property, type, name) \
         object = gtk_builder_get_object (builder, property); \
         panel_return_if_fail (G_IS_OBJECT (object)); \
-        xfconf_g_property_bind (plugin->channel, "/" property, type, object, "active")
+        xfconf_g_property_bind (plugin->channel, "/" property, type, object, name)
 
       /* create bindings */
-      create_binding ("mode", G_TYPE_UINT);
-      create_binding ("show-frame", G_TYPE_BOOLEAN);
-      create_binding ("show-seconds", G_TYPE_BOOLEAN);
-      create_binding ("true-binary", G_TYPE_BOOLEAN);
-      create_binding ("show-military", G_TYPE_BOOLEAN);
-      create_binding ("flash-separators", G_TYPE_BOOLEAN);
-      create_binding ("show-meridiem", G_TYPE_BOOLEAN);
+      create_binding ("mode", G_TYPE_UINT, "active");
+      create_binding ("show-frame", G_TYPE_BOOLEAN, "active");
+      create_binding ("show-seconds", G_TYPE_BOOLEAN, "active");
+      create_binding ("true-binary", G_TYPE_BOOLEAN, "active");
+      create_binding ("show-military", G_TYPE_BOOLEAN, "active");
+      create_binding ("flash-separators", G_TYPE_BOOLEAN, "active");
+      create_binding ("show-meridiem", G_TYPE_BOOLEAN, "active");
+      create_binding ("fuzziness", G_TYPE_UINT, "value");
 
       /* TODO remove when implemented by glade */
       GtkCellRenderer *cell1 = gtk_cell_renderer_text_new ();



More information about the Xfce4-commits mailing list