[gnome-control-center/network-widget-references: 9/13] network: Move non-shared code into the one module that uses it



commit 9360a3269ab326414c6e6b267516a4cb60779b3e
Author: Robert Ancell <robert ancell canonical com>
Date:   Tue Oct 15 11:23:20 2019 +1300

    network: Move non-shared code into the one module that uses it

 panels/network/wireless-security/meson.build  |  2 +-
 panels/network/wireless-security/utils.c      | 75 ---------------------------
 panels/network/wireless-security/utils.h      | 11 ----
 panels/network/wireless-security/ws-wep-key.c | 25 +++++++--
 4 files changed, 21 insertions(+), 92 deletions(-)
---
diff --git a/panels/network/wireless-security/meson.build b/panels/network/wireless-security/meson.build
index 47def7a63..182ac1e14 100644
--- a/panels/network/wireless-security/meson.build
+++ b/panels/network/wireless-security/meson.build
@@ -36,7 +36,7 @@ nm_applet_sources = [
   'ws-wpa-psk.c'
 ]
 
-sources = files(nm_applet_sources) + files('utils.c')
+sources = files(nm_applet_sources)
 
 nm_resource_data = [
   'eap-method-fast.ui',
diff --git a/panels/network/wireless-security/utils.h b/panels/network/wireless-security/utils.h
index d3a684ecf..4465ca611 100644
--- a/panels/network/wireless-security/utils.h
+++ b/panels/network/wireless-security/utils.h
@@ -23,22 +23,11 @@
 #include <nm-setting-wired.h>
 #include <nm-setting-connection.h>
 
-gboolean utils_char_is_ascii_print (char character);
-
 #define NMA_ERROR (g_quark_from_static_string ("nma-error-quark"))
 
 typedef enum  {
        NMA_ERROR_GENERIC
 } NMAError;
 
-typedef gboolean (*UtilsFilterGtkEditableFunc) (char character);
-gboolean utils_filter_editable_on_insert_text (GtkEditable *editable,
-                                              const gchar *text,
-                                              gint length,
-                                              gint *position,
-                                              void *user_data,
-                                              UtilsFilterGtkEditableFunc validate_character,
-                                              gpointer block_func);
-
 extern void widget_set_error (GtkWidget *widget);
 extern void widget_unset_error (GtkWidget *widget);
diff --git a/panels/network/wireless-security/ws-wep-key.c b/panels/network/wireless-security/ws-wep-key.c
index 14db40b08..c4e257add 100644
--- a/panels/network/wireless-security/ws-wep-key.c
+++ b/panels/network/wireless-security/ws-wep-key.c
@@ -126,7 +126,7 @@ validate (WirelessSecurity *parent, GError **error)
                        }
                } else if ((strlen (key) == 5) || (strlen (key) == 13)) {
                        for (i = 0; i < strlen (key); i++) {
-                               if (!utils_char_is_ascii_print (key[i])) {
+                               if (!g_ascii_isprint (key[i])) {
                                        widget_set_error (entry);
                                        g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, _("invalid wep-key: 
key with a length of %zu must contain only ascii characters"), strlen (key));
                                        return FALSE;
@@ -222,10 +222,25 @@ wep_entry_filter_cb (GtkEditable *editable,
        WirelessSecurityWEPKey *sec = (WirelessSecurityWEPKey *) data;
 
        if (sec->type == NM_WEP_KEY_TYPE_KEY) {
-               utils_filter_editable_on_insert_text (editable,
-                                                     text, length, position, data,
-                                                     utils_char_is_ascii_print,
-                                                     wep_entry_filter_cb);
+               int i, count = 0;
+               g_autofree gchar *result = g_new (gchar, length+1);
+
+               for (i = 0; i < length; i++) {
+                       if (g_ascii_isprint (text[i]))
+                               result[count++] = text[i];
+               }
+               result[count] = 0;
+
+               if (count > 0) {
+                       g_signal_handlers_block_by_func (G_OBJECT (editable),
+                                                        G_CALLBACK (wep_entry_filter_cb),
+                                                        data);
+                       gtk_editable_insert_text (editable, result, count, position);
+                       g_signal_handlers_unblock_by_func (G_OBJECT (editable),
+                                                          G_CALLBACK (wep_entry_filter_cb),
+                                                          data);
+               }
+               g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text");
        }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]