[Xfce4-commits] [xfce/xfce4-panel] 01/01: clock: Add a validator for digital custom formats (Bug #11527)

noreply at xfce.org noreply at xfce.org
Thu Nov 16 00:28:18 CET 2017


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository xfce/xfce4-panel.

commit a25624c894e93e1ff354f597975639ef0c2822c2
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Thu Nov 16 00:26:51 2017 +0100

    clock: Add a validator for digital custom formats (Bug #11527)
---
 plugins/clock/clock.c | 41 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/plugins/clock/clock.c b/plugins/clock/clock.c
index 7fc8537..0fd3867 100644
--- a/plugins/clock/clock.c
+++ b/plugins/clock/clock.c
@@ -772,6 +772,38 @@ clock_plugin_configure_plugin_chooser_separator (GtkTreeModel *model,
 
 
 static void
+clock_plugin_validate_format_specifier (GtkEntry *entry, gchar *format, ClockPlugin *plugin)
+{
+  GtkStyleContext *context;
+
+  context = gtk_widget_get_style_context (GTK_WIDGET (entry));
+
+  if (!clock_time_strdup_strftime (plugin->time, format))
+    gtk_style_context_add_class (context, "error");
+  else
+    gtk_style_context_remove_class (context, "error");
+}
+
+
+
+static void
+clock_plugin_validate_entry_text (GtkEntry *entry,
+                                  const gchar *text,
+                                  gint length,
+                                  gint *position,
+                                  ClockPlugin *plugin)
+{
+  gchar *format;
+
+  format = g_strdup_printf ("%s%s",gtk_entry_get_text(entry), text);
+  clock_plugin_validate_format_specifier (entry, format, plugin);
+
+  g_free (format);
+}
+
+
+
+static void
 clock_plugin_configure_plugin_chooser_fill (ClockPlugin *plugin,
                                             GtkComboBox *combo,
                                             GtkEntry    *entry,
@@ -818,8 +850,8 @@ clock_plugin_configure_plugin_chooser_fill (ClockPlugin *plugin,
             }
         }
       else
-        g_warning ("Getting a time preview failed for format specifier %s, so"
-                    "omitting it from the list of default formats", formats[i]);
+        g_warning ("Getting a time preview failed for format specifier %s, so "
+                    "omitting it from the list of default formats.", formats[i]);
     }
 
   gtk_list_store_insert_with_values (store, NULL, i++,
@@ -831,6 +863,9 @@ clock_plugin_configure_plugin_chooser_fill (ClockPlugin *plugin,
     {
       gtk_combo_box_set_active_iter (combo, &iter);
       gtk_widget_show (GTK_WIDGET (entry));
+      clock_plugin_validate_format_specifier (entry,
+                                              gtk_entry_get_text (entry),
+                                              plugin);
     }
 
   g_signal_connect (G_OBJECT (combo), "changed",
@@ -1027,6 +1062,8 @@ clock_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
                                               tooltip_formats);
 
   object = gtk_builder_get_object (builder, "digital-format");
+  g_signal_connect (G_OBJECT (object), "insert_text",
+                    G_CALLBACK (clock_plugin_validate_entry_text), plugin);
   combo = gtk_builder_get_object (builder, "digital-chooser");
   clock_plugin_configure_plugin_chooser_fill (plugin,
                                               GTK_COMBO_BOX (combo),

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list