[gnome-control-center] network: Add utils from network-manager-applet



commit 280cff67db82c27cef7016ef2a62e2da67f8b725
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Jun 7 11:23:16 2016 +0200

    network: Add utils from network-manager-applet
    
    The minimum necessary utilities from
    network-manager-applet/src/utils/utils.[ch]
    for the wireless-security rebase.

 panels/network/wireless-security/Makefile.am |    4 +-
 panels/network/wireless-security/utils.c     |   77 ++++++++++++++++++++++++++
 panels/network/wireless-security/utils.h     |   44 +++++++++++++++
 3 files changed, 124 insertions(+), 1 deletions(-)
---
diff --git a/panels/network/wireless-security/Makefile.am b/panels/network/wireless-security/Makefile.am
index 7c8ea36..6bd8f09 100644
--- a/panels/network/wireless-security/Makefile.am
+++ b/panels/network/wireless-security/Makefile.am
@@ -36,7 +36,9 @@ NM_APPLET_SOURCES = \
 
 libwireless_security_la_SOURCES = \
        $(BUILT_SOURCES) \
-       $(NM_APPLET_SOURCES)
+       $(NM_APPLET_SOURCES) \
+       utils.c \
+       utils.h
 
 libwireless_security_la_CPPFLAGS = \
        $(NETWORK_PANEL_CFLAGS) \
diff --git a/panels/network/wireless-security/utils.c b/panels/network/wireless-security/utils.c
new file mode 100644
index 0000000..b74424d
--- /dev/null
+++ b/panels/network/wireless-security/utils.c
@@ -0,0 +1,77 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Applet -- allow user control over networking
+ *
+ * Dan Williams <dcbw redhat com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2007 - 2015 Red Hat, Inc.
+ */
+
+#include "nm-default.h"
+
+#include <string.h>
+#include <netinet/ether.h>
+
+#include "utils.h"
+
+/**
+ * Filters the characters from a text that was just input into GtkEditable.
+ * Returns FALSE, if after filtering no characters were left. TRUE means,
+ * that valid characters were added and the content of the GtkEditable changed.
+ **/
+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)
+{
+       int i, count = 0;
+       gchar *result = g_new (gchar, length+1);
+
+       for (i = 0; i < length; i++) {
+               if (validate_character (text[i]))
+                       result[count++] = text[i];
+       }
+       result[count] = 0;
+
+       if (count > 0) {
+               if (block_func) {
+                       g_signal_handlers_block_by_func (G_OBJECT (editable),
+                                                        G_CALLBACK (block_func),
+                                                        user_data);
+               }
+               gtk_editable_insert_text (editable, result, count, position);
+               if (block_func) {
+                       g_signal_handlers_unblock_by_func (G_OBJECT (editable),
+                                                          G_CALLBACK (block_func),
+                                                          user_data);
+               }
+       }
+       g_signal_stop_emission_by_name (G_OBJECT (editable), "insert-text");
+
+       g_free (result);
+
+       return count > 0;
+}
+
+gboolean
+utils_char_is_ascii_print (char character)
+{
+       return g_ascii_isprint (character);
+}
diff --git a/panels/network/wireless-security/utils.h b/panels/network/wireless-security/utils.h
new file mode 100644
index 0000000..d3a684e
--- /dev/null
+++ b/panels/network/wireless-security/utils.h
@@ -0,0 +1,44 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Applet -- allow user control over networking
+ *
+ * Dan Williams <dcbw redhat com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Copyright 2007 - 2015 Red Hat, Inc.
+ */
+
+#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);


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