static NMConnection * get_connection_for_active (NMApplet *applet, NMActiveConnection *active) { GSList *list, *iter; NMConnection *connection = NULL; NMConnectionScope scope; const char *path; scope = nm_active_connection_get_scope (active); g_return_val_if_fail (scope != NM_CONNECTION_SCOPE_UNKNOWN, NULL); path = nm_active_connection_get_connection (active); g_return_val_if_fail (path != NULL, NULL); list = applet_get_all_connections (applet); for (iter = list; iter; iter = g_slist_next (iter)) { NMConnection *candidate = NM_CONNECTION (iter->data); if ( (nm_connection_get_scope (candidate) == scope) && !strcmp (nm_connection_get_path (candidate), path)) { connection = candidate; break; } } g_slist_free (list); return connection; }
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); }