[network-manager-applet/dcbw/editor-bt: 2/2] editor: show Bluetooth tab for PAN/DUN connections



commit 8f68df00c4758df41e7308a3eac7e2648a128198
Author: Dan Williams <dcbw redhat com>
Date:   Mon Nov 24 14:58:42 2014 -0600

    editor: show Bluetooth tab for PAN/DUN connections

 src/connection-editor/connection-helpers.c |  123 +++++++++++----------------
 src/connection-editor/connection-helpers.h |    2 +-
 src/connection-editor/nm-connection-list.c |   43 +++++++---
 3 files changed, 81 insertions(+), 87 deletions(-)
---
diff --git a/src/connection-editor/connection-helpers.c b/src/connection-editor/connection-helpers.c
index 1d74867..23942e8 100644
--- a/src/connection-editor/connection-helpers.c
+++ b/src/connection-editor/connection-helpers.c
@@ -75,21 +75,41 @@ sort_types (gconstpointer a, gconstpointer b)
        else if (typeb->virtual && !typea->virtual)
                return -1;
 
-       if (typea->setting_type == NM_TYPE_SETTING_VPN &&
-           typeb->setting_type != NM_TYPE_SETTING_VPN)
+       if (typea->setting_types[0] == NM_TYPE_SETTING_VPN &&
+           typeb->setting_types[0] != NM_TYPE_SETTING_VPN)
                return 1;
-       else if (typeb->setting_type == NM_TYPE_SETTING_VPN &&
-                typea->setting_type != NM_TYPE_SETTING_VPN)
+       else if (typeb->setting_types[0] == NM_TYPE_SETTING_VPN &&
+                typea->setting_types[0] != NM_TYPE_SETTING_VPN)
                return -1;
 
        return g_utf8_collate (typea->name, typeb->name);
 }
 
+#define add_type_data_full(a, n, new_func, type0, type1, type2, v) \
+{ \
+       ConnectionTypeData data; \
+ \
+       memset (&data, 0, sizeof (data)); \
+       data.name = n; \
+       data.new_connection_func = new_func; \
+       data.setting_types[0] = type0; \
+       data.setting_types[1] = type1; \
+       data.setting_types[2] = type2; \
+       data.setting_types[3] = G_TYPE_INVALID; \
+       data.virtual = v; \
+       g_array_append_val (a, data); \
+}
+
+#define add_type_data_real(a, n, new_func, type0) \
+       add_type_data_full(a, n, new_func, type0, G_TYPE_INVALID, G_TYPE_INVALID, FALSE)
+
+#define add_type_data_virtual(a, n, new_func, type0) \
+       add_type_data_full(a, n, new_func, type0, G_TYPE_INVALID, G_TYPE_INVALID, TRUE)
+
 ConnectionTypeData *
 get_connection_type_list (void)
 {
        GArray *array;
-       ConnectionTypeData data;
        static ConnectionTypeData *list;
        GHashTable *vpn_plugins_hash;
        gboolean have_vpn_plugins;
@@ -99,65 +119,22 @@ get_connection_type_list (void)
 
        array = g_array_new (TRUE, FALSE, sizeof (ConnectionTypeData));
 
-       data.name = _("Ethernet");
-       data.new_connection_func = ethernet_connection_new;
-       data.setting_type = NM_TYPE_SETTING_WIRED;
-       data.virtual = FALSE;
-       g_array_append_val (array, data);
-
-       data.name = _("Wi-Fi");
-       data.new_connection_func = wifi_connection_new;
-       data.setting_type = NM_TYPE_SETTING_WIRELESS;
-       data.virtual = FALSE;
-       g_array_append_val (array, data);
-
-       data.name = _("Mobile Broadband");
-       data.new_connection_func = mobile_connection_new;
-       data.setting_type = NM_TYPE_SETTING_GSM;
-       data.virtual = FALSE;
-       g_array_append_val (array, data);
-
-       data.name = _("WiMAX");
-       data.new_connection_func = wimax_connection_new;
-       data.setting_type = NM_TYPE_SETTING_WIMAX;
-       data.virtual = FALSE;
-       g_array_append_val (array, data);
-
-       data.name = _("DSL");
-       data.new_connection_func = dsl_connection_new;
-       data.setting_type = NM_TYPE_SETTING_PPPOE;
-       data.virtual = FALSE;
-       g_array_append_val (array, data);
-
-       data.name = _("InfiniBand");
-       data.new_connection_func = infiniband_connection_new;
-       data.setting_type = NM_TYPE_SETTING_INFINIBAND;
-       data.virtual = FALSE;
-       g_array_append_val (array, data);
-
-       data.name = _("Bond");
-       data.new_connection_func = bond_connection_new;
-       data.setting_type = NM_TYPE_SETTING_BOND;
-       data.virtual = TRUE;
-       g_array_append_val (array, data);
-
-       data.name = _("Team");
-       data.new_connection_func = team_connection_new;
-       data.setting_type = NM_TYPE_SETTING_TEAM;
-       data.virtual = TRUE;
-       g_array_append_val (array, data);
-
-       data.name = _("Bridge");
-       data.new_connection_func = bridge_connection_new;
-       data.setting_type = NM_TYPE_SETTING_BRIDGE;
-       data.virtual = TRUE;
-       g_array_append_val (array, data);
-
-       data.name = _("VLAN");
-       data.new_connection_func = vlan_connection_new;
-       data.setting_type = NM_TYPE_SETTING_VLAN;
-       data.virtual = TRUE;
-       g_array_append_val (array, data);
+       add_type_data_real (array, _("Ethernet"), ethernet_connection_new, NM_TYPE_SETTING_WIRED);
+       add_type_data_real (array, _("Wi-Fi"), wifi_connection_new, NM_TYPE_SETTING_WIRELESS);
+       add_type_data_full (array,
+                           _("Mobile Broadband"),
+                           mobile_connection_new,
+                           NM_TYPE_SETTING_GSM,
+                           NM_TYPE_SETTING_CDMA,
+                           NM_TYPE_SETTING_BLUETOOTH,
+                           FALSE);
+       add_type_data_real (array, _("WiMAX"), wimax_connection_new, NM_TYPE_SETTING_WIMAX);
+       add_type_data_real (array, _("DSL"), dsl_connection_new, NM_TYPE_SETTING_PPPOE);
+       add_type_data_real (array, _("InfiniBand"), infiniband_connection_new, NM_TYPE_SETTING_INFINIBAND);
+       add_type_data_virtual (array, _("Bond"), bond_connection_new, NM_TYPE_SETTING_BOND);
+       add_type_data_virtual (array, _("Team"), team_connection_new, NM_TYPE_SETTING_TEAM);
+       add_type_data_virtual (array, _("Bridge"), bridge_connection_new, NM_TYPE_SETTING_BRIDGE);
+       add_type_data_virtual (array, _("VLAN"), vlan_connection_new, NM_TYPE_SETTING_VLAN);
 
        /* Add "VPN" only if there are plugins */
        vpn_plugins_hash = vpn_get_plugins (NULL);
@@ -166,11 +143,7 @@ get_connection_type_list (void)
                GHashTableIter iter;
                gpointer name, plugin;
 
-               data.name = _("VPN");
-               data.new_connection_func = vpn_connection_new;
-               data.setting_type = NM_TYPE_SETTING_VPN;
-               data.virtual = TRUE;
-               g_array_append_val (array, data);
+               add_type_data_virtual (array, _("VPN"), vpn_connection_new, NM_TYPE_SETTING_VPN);
 
                vpn_plugins = NULL;
                g_hash_table_iter_init (&iter, vpn_plugins_hash);
@@ -266,13 +239,17 @@ set_up_connection_type_combo (GtkComboBox *combo,
        }
 
        for (i = 0; list[i].name; i++) {
-               if (type_filter_func && !type_filter_func (list[i].setting_type, user_data))
-                       continue;
+               if (type_filter_func) {
+                       if (   !type_filter_func (list[i].setting_types[0], user_data)
+                           && !type_filter_func (list[i].setting_types[1], user_data)
+                           && !type_filter_func (list[i].setting_types[2], user_data))
+                               continue;
+               }
 
-               if (list[i].setting_type == NM_TYPE_SETTING_VPN) {
+               if (list[i].setting_types[0] == NM_TYPE_SETTING_VPN) {
                        vpn_index = i;
                        continue;
-               } else if (list[i].setting_type == NM_TYPE_SETTING_WIRED)
+               } else if (list[i].setting_types[0] == NM_TYPE_SETTING_WIRED)
                        active = added;
 
                if (list[i].virtual && !added_virtual_header && show_headers) {
diff --git a/src/connection-editor/connection-helpers.h b/src/connection-editor/connection-helpers.h
index ae60ec0..92b8325 100644
--- a/src/connection-editor/connection-helpers.h
+++ b/src/connection-editor/connection-helpers.h
@@ -26,7 +26,7 @@
 
 typedef struct {
        const char *name;
-       GType setting_type;
+       GType setting_types[4];
        PageNewConnectionFunc new_connection_func;
        gboolean virtual;
 } ConnectionTypeData;
diff --git a/src/connection-editor/nm-connection-list.c b/src/connection-editor/nm-connection-list.c
index 1e6846a..c8c3a15 100644
--- a/src/connection-editor/nm-connection-list.c
+++ b/src/connection-editor/nm-connection-list.c
@@ -68,8 +68,10 @@ static guint list_signals[LIST_LAST_SIGNAL] = { 0 };
 #define COL_LAST_USED  1
 #define COL_TIMESTAMP  2
 #define COL_CONNECTION 3
-#define COL_GTYPE      4
-#define COL_ORDER      5
+#define COL_GTYPE0     4
+#define COL_GTYPE1     5
+#define COL_GTYPE2     6
+#define COL_ORDER      7
 
 static NMRemoteConnection *
 get_active_connection (GtkTreeView *treeview)
@@ -608,7 +610,14 @@ initialize_treeview (NMConnectionList *self)
        int i;
 
        /* Model */
-       self->model = GTK_TREE_MODEL (gtk_tree_store_new (6, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, 
G_TYPE_OBJECT, G_TYPE_GTYPE, G_TYPE_INT));
+       self->model = GTK_TREE_MODEL (gtk_tree_store_new (8, G_TYPE_STRING,
+                                                            G_TYPE_STRING,
+                                                            G_TYPE_UINT64,
+                                                            G_TYPE_OBJECT,
+                                                            G_TYPE_GTYPE,
+                                                            G_TYPE_GTYPE,
+                                                            G_TYPE_GTYPE,
+                                                            G_TYPE_INT));
 
        /* Filter */
        self->filter = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (self->model, NULL));
@@ -661,7 +670,9 @@ initialize_treeview (NMConnectionList *self)
                gtk_tree_store_append (GTK_TREE_STORE (self->model), &iter, NULL);
                gtk_tree_store_set (GTK_TREE_STORE (self->model), &iter,
                                    COL_ID, id,
-                                   COL_GTYPE, types[i].setting_type,
+                                   COL_GTYPE0, types[i].setting_types[0],
+                                   COL_GTYPE1, types[i].setting_types[1],
+                                   COL_GTYPE2, types[i].setting_types[2],
                                    COL_ORDER, i,
                                    -1);
                g_free (id);
@@ -746,7 +757,7 @@ get_parent_iter_for_connection (NMConnectionList *list,
 {
        NMSettingConnection *s_con;
        const char *str_type;
-       GType type, row_type;
+       GType type, row_type0, row_type1, row_type2;
 
        s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
        g_assert (s_con);
@@ -756,16 +767,16 @@ get_parent_iter_for_connection (NMConnectionList *list,
                return FALSE;
        }
 
-       if (!strcmp (str_type, NM_SETTING_CDMA_SETTING_NAME))
-               str_type = NM_SETTING_GSM_SETTING_NAME;
        type = nm_connection_lookup_setting_type (str_type);
 
        if (gtk_tree_model_get_iter_first (list->model, iter)) {
                do {
                        gtk_tree_model_get (list->model, iter,
-                                           COL_GTYPE, &row_type,
+                                           COL_GTYPE0, &row_type0,
+                                           COL_GTYPE1, &row_type1,
+                                           COL_GTYPE2, &row_type2,
                                            -1);
-                       if (row_type == type)
+                       if (row_type0 == type || row_type1 == type || row_type2 == type)
                                return TRUE;
                } while (gtk_tree_model_iter_next (list->model, iter));
        }
@@ -803,12 +814,16 @@ connection_added (NMRemoteSettings *settings,
        g_free (last_used);
 
        if (self->displayed_type) {
-               GType added_type;
+               GType added_type0, added_type1, added_type2;
 
                gtk_tree_model_get (self->model, &parent_iter,
-                                   COL_GTYPE, &added_type,
+                                   COL_GTYPE0, &added_type0,
+                                   COL_GTYPE1, &added_type1,
+                                   COL_GTYPE2, &added_type2,
                                    -1);
-               if (added_type != self->displayed_type)
+               if (   added_type0 != self->displayed_type
+                   && added_type1 != self->displayed_type
+                   && added_type2 != self->displayed_type)
                        expand = FALSE;
        }
 
@@ -925,7 +940,9 @@ nm_connection_list_create (NMConnectionList *self, GType ctype, const char *deta
 
        types = get_connection_type_list ();
        for (i = 0; types[i].name; i++) {
-               if (types[i].setting_type == ctype)
+               if (   types[i].setting_types[0] == ctype
+                   || types[i].setting_types[1] == ctype
+                   || types[i].setting_types[2] == ctype)
                        break;
        }
        if (!types[i].name) {


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