[network-manager-applet/bg/unsupported-properties-bgo777225: 3/4] editor: add utility functions to notify about unsupported properties



commit 1db4109eff48e7eaebc2f576255d828a73ce19a2
Author: Beniamino Galvani <bgalvani redhat com>
Date:   Tue Jan 17 18:21:10 2017 +0100

    editor: add utility functions to notify about unsupported properties
    
    Add functions to notify users about properties that are not supported
    by the editor and that will be cleared if the user saves the
    connection.

 src/connection-editor/nm-connection-editor.c  |   63 +++++++++++++++++++++++++
 src/connection-editor/nm-connection-editor.h  |    6 ++
 src/connection-editor/nm-connection-editor.ui |   13 +++++
 3 files changed, 82 insertions(+), 0 deletions(-)
---
diff --git a/src/connection-editor/nm-connection-editor.c b/src/connection-editor/nm-connection-editor.c
index 70f008e..739c439 100644
--- a/src/connection-editor/nm-connection-editor.c
+++ b/src/connection-editor/nm-connection-editor.c
@@ -353,6 +353,9 @@ dispose (GObject *object)
                editor->inter_page_hash = NULL;
        }
 
+       g_slist_free_full (editor->unsupported_properties, g_free);
+       editor->unsupported_properties = NULL;
+
        G_OBJECT_CLASS (nm_connection_editor_parent_class)->dispose (object);
 }
 
@@ -521,6 +524,7 @@ static void
 recheck_initialization (NMConnectionEditor *editor)
 {
        GtkNotebook *notebook;
+       GtkLabel *label;
 
        if (!editor_is_initialized (editor) || editor->init_run)
                return;
@@ -542,6 +546,27 @@ recheck_initialization (NMConnectionEditor *editor)
        if (editor->validate_id)
                g_source_remove (editor->validate_id);
        editor->validate_id = g_idle_add (idle_validate, editor);
+
+       if (editor->unsupported_properties) {
+               GString *str;
+               GSList *iter;
+               gs_free char *tooltip = NULL;
+
+               str = g_string_new ("Unsupported properties: ");
+
+               for (iter = editor->unsupported_properties; iter; iter = g_slist_next (iter)) {
+                       g_string_append (str, (char *) iter->data);
+                       if (iter->next)
+                               g_string_append (str, ", ");
+               }
+               tooltip = g_string_free (str, FALSE);
+
+               label = GTK_LABEL (gtk_builder_get_object (editor->builder, "message_label"));
+               gtk_label_set_text (label,
+                                   _("Warning: the connection contains some properties not supported by the 
editor. "
+                                     "They will be cleared upon save."));
+               gtk_widget_set_tooltip_text (GTK_WIDGET (label), tooltip);
+       }
 }
 
 static void
@@ -709,6 +734,44 @@ add_page (NMConnectionEditor *editor,
        return !!page;
 }
 
+void
+nm_connection_editor_add_unsupported_property (NMConnectionEditor *editor, const char *name)
+{
+       editor->unsupported_properties = g_slist_append (editor->unsupported_properties, g_strdup (name));
+}
+
+void
+nm_connection_editor_check_unsupported_properties (NMConnectionEditor *editor,
+                                                   NMSetting *setting,
+                                                   const char * const *known_props)
+{
+       gs_free GParamSpec **property_specs = NULL;
+       GParamSpec *prop_spec;
+       guint n_property_specs;
+       guint i;
+       char tmp[1024];
+
+       if (!setting)
+               return;
+
+       property_specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (setting),
+                                                        &n_property_specs);
+       for (i = 0; i < n_property_specs; i++) {
+               prop_spec = property_specs[i];
+               if (   !g_strv_contains (known_props, prop_spec->name)
+                   && !nm_streq0 (prop_spec->name, NM_SETTING_NAME)) {
+                       nm_auto_unset_gvalue GValue value = G_VALUE_INIT;
+
+                       g_value_init (&value, prop_spec->value_type);
+                       g_object_get_property (G_OBJECT (setting), prop_spec->name, &value);
+                       if (!g_param_value_defaults (prop_spec, &value)) {
+                               nm_sprintf_buf (tmp, "%s.%s", nm_setting_get_name (setting), prop_spec->name);
+                               nm_connection_editor_add_unsupported_property (editor, tmp);
+                       }
+               }
+       }
+}
+
 static gboolean
 nm_connection_editor_set_connection (NMConnectionEditor *editor,
                                      NMConnection *orig_connection,
diff --git a/src/connection-editor/nm-connection-editor.h b/src/connection-editor/nm-connection-editor.h
index ff762df..b7833be 100644
--- a/src/connection-editor/nm-connection-editor.h
+++ b/src/connection-editor/nm-connection-editor.h
@@ -68,6 +68,7 @@ typedef struct {
        char *last_validation_error;
 
        GHashTable *inter_page_hash;
+       GSList *unsupported_properties;
 } NMConnectionEditor;
 
 typedef struct {
@@ -113,4 +114,9 @@ gboolean           nm_connection_editor_inter_page_get_value (NMConnectionEditor
                                                               gpointer *value);
 void               nm_connection_editor_inter_page_clear_data (NMConnectionEditor *editor);
 
+void               nm_connection_editor_add_unsupported_property (NMConnectionEditor *editor,
+                                                                  const char *name);
+void               nm_connection_editor_check_unsupported_properties (NMConnectionEditor *editor,
+                                                                      NMSetting *setting,
+                                                                      const char *const *known_props);
 #endif
diff --git a/src/connection-editor/nm-connection-editor.ui b/src/connection-editor/nm-connection-editor.ui
index 292972e..35cbf08 100644
--- a/src/connection-editor/nm-connection-editor.ui
+++ b/src/connection-editor/nm-connection-editor.ui
@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.0 -->
 <interface>
   <requires lib="gtk+" version="3.4"/>
   <object class="GtkDialog" id="NMConnectionList">
@@ -254,6 +255,18 @@
                 <property name="position">1</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkLabel" id="message_label">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="wrap">True</property>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>


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