[PATCH 8/9] clock: binary: add new mode option

Felipe Contreras felipe.contreras at gmail.com
Fri Jun 14 02:40:43 CEST 2019


Switch from 'true-binary' to this new mode. The 'true-binary' is the
sexadecimal mode.

The normal mode is what is called binary-coded decimal (BCD).

Signed-off-by: Felipe Contreras <felipe.contreras at gmail.com>
---
 plugins/clock/clock-binary.c     | 67 ++++++++++++++++++++++----------
 plugins/clock/clock-dialog.glade | 60 ++++++++++++++++++++++++----
 plugins/clock/clock.c            |  4 +-
 3 files changed, 101 insertions(+), 30 deletions(-)

diff --git a/plugins/clock/clock-binary.c b/plugins/clock/clock-binary.c
index e790f4d5..e2b05590 100644
--- a/plugins/clock/clock-binary.c
+++ b/plugins/clock/clock-binary.c
@@ -54,13 +54,19 @@ enum
 {
   PROP_0,
   PROP_SHOW_SECONDS,
-  PROP_TRUE_BINARY,
+  PROP_MODE,
   PROP_SHOW_INACTIVE,
   PROP_SHOW_GRID,
   PROP_SIZE_RATIO,
   PROP_ORIENTATION
 };
 
+enum
+{
+  MODE_DECIMAL,
+  MODE_SEXADECIMAL
+};
+
 struct _XfceClockBinaryClass
 {
   GtkImageClass __parent__;
@@ -73,7 +79,7 @@ struct _XfceClockBinary
   ClockTimeTimeout *timeout;
 
   guint     show_seconds : 1;
-  guint     true_binary : 1;
+  guint     mode;
   guint     show_inactive : 1;
   guint     show_grid : 1;
 
@@ -123,11 +129,11 @@ xfce_clock_binary_class_init (XfceClockBinaryClass *klass)
                                                          | G_PARAM_STATIC_STRINGS));
 
   g_object_class_install_property (gobject_class,
-                                   PROP_TRUE_BINARY,
-                                   g_param_spec_boolean ("true-binary", NULL, NULL,
-                                                         FALSE,
-                                                         G_PARAM_READWRITE
-                                                         | G_PARAM_STATIC_STRINGS));
+                                   PROP_MODE,
+                                   g_param_spec_uint ("binary-mode", NULL, NULL,
+                                                      MODE_DECIMAL, MODE_SEXADECIMAL, MODE_DECIMAL,
+                                                      G_PARAM_READWRITE
+                                                      | G_PARAM_STATIC_STRINGS));
 
   g_object_class_install_property (gobject_class,
                                    PROP_SHOW_INACTIVE,
@@ -150,7 +156,7 @@ static void
 xfce_clock_binary_init (XfceClockBinary *binary)
 {
   binary->show_seconds = FALSE;
-  binary->true_binary = FALSE;
+  binary->mode = MODE_DECIMAL;
   binary->show_inactive = TRUE;
   binary->show_grid = FALSE;
 
@@ -176,8 +182,8 @@ xfce_clock_binary_set_property (GObject      *object,
       g_object_notify (object, "size-ratio");
       break;
 
-    case PROP_TRUE_BINARY:
-      binary->true_binary = g_value_get_boolean (value);
+    case PROP_MODE:
+      binary->mode = g_value_get_uint (value);
       g_object_notify (object, "size-ratio");
       break;
 
@@ -217,8 +223,8 @@ xfce_clock_binary_get_property (GObject    *object,
       g_value_set_boolean (value, binary->show_seconds);
       break;
 
-    case PROP_TRUE_BINARY:
-      g_value_set_boolean (value, binary->true_binary);
+    case PROP_MODE:
+      g_value_set_uint (value, binary->mode);
       break;
 
     case PROP_SHOW_INACTIVE:
@@ -230,10 +236,16 @@ xfce_clock_binary_get_property (GObject    *object,
       break;
 
     case PROP_SIZE_RATIO:
-      if (binary->true_binary)
-        ratio = binary->show_seconds ? 2.0 : 3.0;
-      else
+      switch (binary->mode) {
+      case MODE_DECIMAL:
         ratio = binary->show_seconds ? 1.5 : 1.0;
+        break;
+      case MODE_SEXADECIMAL:
+        ratio = binary->show_seconds ? 2.0 : 3.0;
+        break;
+      default:
+        return;
+      }
       g_value_set_double (value, ratio);
       break;
 
@@ -359,14 +371,25 @@ xfce_clock_binary_draw (GtkWidget *widget,
   alloc.x = pad_x + 1;
   alloc.y = pad_y + 1;
 
+  switch (binary->mode) {
+  case MODE_DECIMAL:
+    cols = binary->show_seconds ? 6 : 4;
+    rows = 4;
+    break;
+  case MODE_SEXADECIMAL:
+    cols = 6;
+    rows = binary->show_seconds ? 3 : 2;
+    break;
+  default:
+    return FALSE;
+  }
+
   /* align columns and fix rounding */
-  cols = binary->true_binary ? 6 : (binary->show_seconds ? 6 : 4);
   diff = alloc.width - (floor ((gdouble) alloc.width / cols) * cols);
   alloc.width -= diff;
   alloc.x += diff / 2;
 
   /* align rows and fix rounding */
-  rows = binary->true_binary ? (binary->show_seconds ? 3 : 2) : 4;
   diff = alloc.height - (floor ((gdouble) alloc.height / rows) * rows);
   alloc.height -= diff;
   alloc.y += diff / 2;
@@ -407,10 +430,14 @@ xfce_clock_binary_draw (GtkWidget *widget,
   table = g_new0 (typeof(*table), cols);
   time = clock_time_get_time (binary->time);
 
-  if (binary->true_binary)
-    binary_coded_sexadecimal (table, time, cols, rows);
-  else
+  switch (binary->mode) {
+  case MODE_DECIMAL:
     binary_coded_decimal (table, time, cols, rows);
+    break;
+  case MODE_SEXADECIMAL:
+    binary_coded_sexadecimal (table, time, cols, rows);
+    break;
+  }
 
   inactive_rgba = active_rgba;
   active_rgba.alpha = 1.0;
diff --git a/plugins/clock/clock-dialog.glade b/plugins/clock/clock-dialog.glade
index 51495d1a..83348c82 100644
--- a/plugins/clock/clock-dialog.glade
+++ b/plugins/clock/clock-dialog.glade
@@ -47,6 +47,20 @@
       </row>
     </data>
   </object>
+  <object class="GtkListStore" id="binary-mode-model">
+    <columns>
+      <!-- column-name title -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Decimal</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Sexadecimal</col>
+      </row>
+    </data>
+  </object>
   <object class="XfceTitledDialog" id="dialog">
     <property name="can_focus">False</property>
     <property name="title" translatable="yes">Clock</property>
@@ -359,17 +373,47 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkCheckButton" id="true-binary">
-                        <property name="label" translatable="yes">True _binary clock</property>
+                      <object class="GtkGrid" id="binary-box">
                         <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">False</property>
-                        <property name="use_underline">True</property>
-                        <property name="draw_indicator">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="hexpand">True</property>
+                        <property name="row_spacing">6</property>
+                        <property name="column_spacing">12</property>
+                        <child>
+                          <object class="GtkComboBox" id="binary-mode">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="hexpand">True</property>
+                            <property name="model">binary-mode-model</property>
+                            <child>
+                              <object class="GtkCellRendererText" id="cellrenderertext4"/>
+                              <attributes>
+                                <attribute name="text">0</attribute>
+                              </attributes>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="top_attach">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="label10">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label" translatable="yes">_Binary mode:</property>
+                            <property name="use_underline">True</property>
+                            <property name="xalign">0</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">0</property>
+                            <property name="top_attach">0</property>
+                          </packing>
+                        </child>
                       </object>
                       <packing>
                         <property name="left_attach">0</property>
-                        <property name="top_attach">1</property>
+                        <property name="top_attach">0</property>
                         <property name="width">2</property>
                       </packing>
                     </child>
@@ -384,7 +428,7 @@
                       </object>
                       <packing>
                         <property name="left_attach">0</property>
-                        <property name="top_attach">0</property>
+                        <property name="top_attach">1</property>
                         <property name="width">2</property>
                       </packing>
                     </child>
diff --git a/plugins/clock/clock.c b/plugins/clock/clock.c
index 64a10735..355de72d 100644
--- a/plugins/clock/clock.c
+++ b/plugins/clock/clock.c
@@ -644,7 +644,7 @@ clock_plugin_configure_plugin_mode_changed (GtkComboBox       *combo,
     const gchar *property;
   } names[] = {
     { "show-seconds", "show-seconds", "active" },
-    { "true-binary", "true-binary", "active" },
+    { "binary-box", "binary-mode", "active" },
     { "show-military", "show-military", "active" },
     { "flash-separators", "flash-separators", "active" },
     { "show-meridiem", "show-meridiem", "active" },
@@ -1076,7 +1076,7 @@ clock_plugin_set_mode (ClockPlugin *plugin)
     },
     { /* binary */
       { "show-seconds", G_TYPE_BOOLEAN },
-      { "true-binary", G_TYPE_BOOLEAN },
+      { "binary-mode", G_TYPE_UINT },
       { "show-inactive", G_TYPE_BOOLEAN },
       { "show-grid", G_TYPE_BOOLEAN },
       { NULL },
-- 
2.22.0.rc2.dirty



More information about the Xfce4-dev mailing list