From 1b959ac00f91620ea6292b4d98d33f11454a8e56 Mon Sep 17 00:00:00 2001 From: Rob Day Date: Sat, 12 Oct 2019 12:51:21 +0100 Subject: [PATCH] Validate the timezone and display an error if it is invalid --- plugins/clock/clock.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/plugins/clock/clock.c b/plugins/clock/clock.c index 64a10735..a152872c 100644 --- a/plugins/clock/clock.c +++ b/plugins/clock/clock.c @@ -791,6 +791,42 @@ clock_plugin_validate_entry_text (GtkEditable *entry, plugin); } +static void +clock_plugin_validate_timezone (GtkEntry *entry, const gchar *format, ClockPlugin *plugin) +{ + GtkStyleContext *context; + gchar *filename; + + context = gtk_widget_get_style_context (GTK_WIDGET (entry)); + + if (strcmp(format, "") != 0) + { + filename = g_build_filename (ZONEINFO_DIR, format, NULL); + + if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) + gtk_style_context_add_class (context, "error"); + else + gtk_style_context_remove_class (context, "error"); + } + else + { + gtk_style_context_remove_class (context, "error"); + } +} + + + +static void +clock_plugin_validate_entry_tz (GtkEditable *entry, + gpointer user_data) +{ + ClockPlugin *plugin = user_data; + + clock_plugin_validate_timezone (GTK_ENTRY (entry), + gtk_entry_get_text (GTK_ENTRY (entry)), + plugin); +} + static void @@ -1026,6 +1062,8 @@ clock_plugin_configure_plugin (XfcePanelPlugin *panel_plugin) object = gtk_builder_get_object (builder, "timezone-name"); panel_return_if_fail (GTK_IS_ENTRY (object)); + g_signal_connect (G_OBJECT (object), "changed", + G_CALLBACK (clock_plugin_validate_entry_tz), plugin); g_object_bind_property (G_OBJECT (plugin->time), "timezone", G_OBJECT (object), "text", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); -- 2.23.0