static GSList * valid_connections_for_device (NMRemoteSettings *remote_settings, NMDevice *device) { GSList *all, *filtered, *iterator, *valid; NMConnection *connection; NMSettingConnection *s_con; all = nm_remote_settings_list_connections (remote_settings); filtered = nm_device_filter_connections (device, all); g_slist_free (all); valid = NULL; for (iterator = filtered; iterator; iterator = iterator->next) { connection = iterator->data; s_con = nm_connection_get_setting_connection (connection); if (!s_con) continue; if (nm_setting_connection_get_master (s_con)) continue; valid = g_slist_prepend (valid, connection); } g_slist_free (filtered); return g_slist_reverse (valid); }
static void bt_add_menu_item (NMDevice *device, guint32 n_devices, NMConnection *active, GtkWidget *menu, NMApplet *applet) { const char *text; GtkWidget *item; GSList *connections, *all; all = applet_get_all_connections (applet); connections = nm_device_filter_connections (device, all); g_slist_free (all); text = nm_device_bt_get_name (NM_DEVICE_BT (device)); if (!text) { text = utils_get_device_description (device); if (!text) text = nm_device_get_iface (device); g_assert (text); } item = applet_menu_item_create_device_item_helper (device, applet, text); gtk_widget_set_sensitive (item, FALSE); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); if (g_slist_length (connections)) add_connection_items (device, connections, active, ADD_ACTIVE, menu, applet); /* Notify user of unmanaged or unavailable device */ item = nma_menu_device_get_menu_item (device, applet, NULL); if (item) { gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); } if (!nma_menu_device_check_unusable (device)) { /* Add menu items for existing bluetooth connections for this device */ if (g_slist_length (connections)) { applet_menu_item_add_complex_separator_helper (menu, applet, _("Available"), -1); add_connection_items (device, connections, active, ADD_INACTIVE, menu, applet); } } g_slist_free (connections); }
static void add_menu_item (NMDevice *device, guint32 n_devices, NMConnection *active, GtkWidget *menu, NMApplet *applet) { BroadbandDeviceInfo *info; char *text; GtkWidget *item; GSList *connections, *all, *iter; info = g_object_get_data (G_OBJECT (device), "devinfo"); all = applet_get_all_connections (applet); connections = nm_device_filter_connections (device, all); g_slist_free (all); if (n_devices > 1) { const char *desc; desc = nma_utils_get_device_description (device); text = g_strdup_printf (_("Mobile Broadband (%s)"), desc); } else { text = g_strdup (_("Mobile Broadband")); } item = applet_menu_item_create_device_item_helper (device, applet, text); gtk_widget_set_sensitive (item, FALSE); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); g_free (text); /* Add the active connection */ if (active) { NMSettingConnection *s_con; s_con = nm_connection_get_setting_connection (active); g_assert (s_con); item = nm_mb_menu_item_new (nm_setting_connection_get_id (s_con), mm_modem_get_signal_quality (info->mm_modem, NULL), info->operator_name, TRUE, broadband_act_to_mb_act (info), broadband_state_to_mb_state (info), mm_modem_get_state (info->mm_modem) >= MM_MODEM_STATE_ENABLED, applet); gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE); add_connection_item (device, active, item, menu, applet); } /* Notify user of unmanaged or unavailable device */ if (nm_device_get_state (device) > NM_DEVICE_STATE_DISCONNECTED) { item = nma_menu_device_get_menu_item (device, applet, NULL); if (item) { gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); } } else { /* Otherwise show idle registration state or disabled */ item = nm_mb_menu_item_new (NULL, mm_modem_get_signal_quality (info->mm_modem, NULL), info->operator_name, FALSE, broadband_act_to_mb_act (info), broadband_state_to_mb_state (info), mm_modem_get_state (info->mm_modem) >= MM_MODEM_STATE_ENABLED, applet); gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); } /* Add the default / inactive connection items */ if (!nma_menu_device_check_unusable (device)) { if ((!active && g_slist_length (connections)) || (active && g_slist_length (connections) > 1)) applet_menu_item_add_complex_separator_helper (menu, applet, _("Available"), -1); if (g_slist_length (connections)) { for (iter = connections; iter; iter = g_slist_next (iter)) { NMConnection *connection = NM_CONNECTION (iter->data); if (connection != active) { item = applet_new_menu_item_helper (connection, NULL, FALSE); add_connection_item (device, connection, item, menu, applet); } } } else { /* Default connection item */ item = gtk_check_menu_item_new_with_label (_("New Mobile Broadband connection...")); add_connection_item (device, NULL, item, menu, applet); } } g_slist_free (connections); }
static void wimax_add_menu_item (NMDevice *device, guint32 n_devices, NMConnection *active, GtkWidget *menu, NMApplet *applet) { NMDeviceWimax *wimax = NM_DEVICE_WIMAX (device); char *text; GtkWidget *item; GSList *connections, *all, *iter, *sorted = NULL; const GPtrArray *nsps; NMWimaxNsp *active_nsp = NULL; gboolean wimax_enabled, wimax_hw_enabled; int i; nsps = nm_device_wimax_get_nsps (wimax); if (n_devices > 1) { const char *desc; desc = nma_utils_get_device_description (device); text = g_strdup_printf (_("WiMAX Mobile Broadband (%s)"), desc); } else { text = g_strdup (_("WiMAX Mobile Broadband")); } item = applet_menu_item_create_device_item_helper (device, applet, text); gtk_widget_set_sensitive (item, FALSE); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); g_free (text); /* Add the active NSP if we're connected to something and the device is available */ if (!nma_menu_device_check_unusable (device)) { active_nsp = nm_device_wimax_get_active_nsp (wimax); if (active_nsp) { item = new_nsp_menu_item (wimax, active, TRUE, active_nsp, applet); if (item) { gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); } } } /* Notify user of unmanaged or unavailable device */ wimax_enabled = nm_client_wimax_get_enabled (applet->nm_client); wimax_hw_enabled = nm_client_wimax_hardware_get_enabled (applet->nm_client); item = nma_menu_device_get_menu_item (device, applet, wimax_hw_enabled ? (wimax_enabled ? NULL : _("WiMAX is disabled")) : _("WiMAX is disabled by hardware switch")); if (item) { gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); } /* If disabled or rfkilled or whatever, nothing left to do */ if (nma_menu_device_check_unusable (device)) return; /* Create a sorted list of NSPs */ for (i = 0; nsps && (i < nsps->len); i++) { NMWimaxNsp *nsp = g_ptr_array_index (nsps, i); if (nsp != active_nsp) sorted = g_slist_insert_sorted (sorted, nsp, sort_nsps); } if (g_slist_length (sorted)) { applet_menu_item_add_complex_separator_helper (menu, applet, _("Available"), -1); all = applet_get_all_connections (applet); connections = nm_device_filter_connections (device, all); g_slist_free (all); /* And add menu items for each NSP */ for (iter = sorted; iter; iter = g_slist_next (iter)) { NMWimaxNsp *nsp = NM_WIMAX_NSP (iter->data); NMConnection *connection = NULL; connection = get_connection_for_nsp (connections, nsp); item = new_nsp_menu_item (wimax, connection, FALSE, nsp, applet); if (item) { gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); gtk_widget_show (item); } } g_slist_free (connections); } g_slist_free (sorted); }
static void row_activated (GtkListBox *box, GtkListBoxRow *row, GisNetworkPage *page) { GisNetworkPagePrivate *priv = gis_network_page_get_instance_private (page); gchar *object_path; GSList *list, *filtered, *l; NMConnection *connection; NMConnection *connection_to_activate; NMSettingWireless *setting; const GByteArray *ssid_target; const GByteArray *ssid; GtkWidget *child; if (priv->refreshing) return; child = gtk_bin_get_child (GTK_BIN (row)); object_path = g_object_get_data (G_OBJECT (child), "object-path"); ssid_target = g_object_get_data (G_OBJECT (child), "ssid"); if (g_strcmp0 (object_path, "ap-other...") == 0) { connect_to_hidden_network (page); goto out; } list = nm_remote_settings_list_connections (priv->nm_settings); filtered = nm_device_filter_connections (priv->nm_device, list); connection_to_activate = NULL; for (l = filtered; l; l = l->next) { connection = NM_CONNECTION (l->data); setting = nm_connection_get_setting_wireless (connection); if (!NM_IS_SETTING_WIRELESS (setting)) continue; ssid = nm_setting_wireless_get_ssid (setting); if (ssid == NULL) continue; if (nm_utils_same_ssid (ssid, ssid_target, TRUE)) { connection_to_activate = connection; break; } } g_slist_free (list); g_slist_free (filtered); if (connection_to_activate != NULL) { nm_client_activate_connection (priv->nm_client, connection_to_activate, priv->nm_device, NULL, connection_activate_cb, page); goto out; } nm_client_add_and_activate_connection (priv->nm_client, NULL, priv->nm_device, object_path, connection_add_activate_cb, page); out: refresh_wireless_list (page); }