static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { GtkWidget *entry; GByteArray *ignore; gboolean invalid; gchar *security; NMSettingWireless *setting; gboolean ret = TRUE; entry = gtk_bin_get_child (GTK_BIN (gtk_builder_get_object (page->builder, "combo_bssid"))); ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); if (invalid) { widget_set_error (entry); ret = FALSE; } else { if (ignore) g_byte_array_free (ignore, TRUE); widget_unset_error (entry); } entry = gtk_bin_get_child (GTK_BIN (gtk_builder_get_object (page->builder, "combo_mac"))); ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); if (invalid) { widget_set_error (entry); ret = FALSE; } else { if (ignore) g_byte_array_free (ignore, TRUE); widget_unset_error (entry); } entry = GTK_WIDGET (gtk_builder_get_object (page->builder, "entry_cloned_mac")); ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); if (invalid) { widget_set_error (entry); ret = FALSE; } else { if (ignore) g_byte_array_free (ignore, TRUE); widget_unset_error (entry); } if (!ret) return ret; ui_to_setting (CE_PAGE_WIFI (page)); /* A hack to not check the wifi security here */ setting = CE_PAGE_WIFI (page)->setting; security = g_strdup (nm_setting_wireless_get_security (setting)); g_object_set (setting, NM_SETTING_WIRELESS_SEC, NULL, NULL); ret = nm_setting_verify (NM_SETTING (setting), NULL, error); g_object_set (setting, NM_SETTING_WIRELESS_SEC, security, NULL); g_free (security); return ret; }
static gboolean ce_page_validate_v (CEPage *page, NMConnection *connection, GError **error) { CEPageWifi *self = CE_PAGE_WIFI (page); CEPageWifiPrivate *priv = CE_PAGE_WIFI_GET_PRIVATE (self); gboolean success; GtkWidget *entry; entry = gtk_bin_get_child (GTK_BIN (priv->bssid)); if (entry) { if (!ce_page_mac_entry_valid (GTK_ENTRY (entry), ARPHRD_ETHER, _("bssid"), error)) return FALSE; } entry = gtk_bin_get_child (GTK_BIN (priv->device_combo)); if (entry) { if (!ce_page_device_entry_get (GTK_ENTRY (entry), ARPHRD_ETHER, TRUE, NULL, NULL, _("Wi-Fi device"), error)) return FALSE; } if (!ce_page_mac_entry_valid (priv->cloned_mac, ARPHRD_ETHER, _("cloned MAC"), error)) return FALSE; ui_to_setting (self); success = nm_setting_verify (NM_SETTING (priv->setting), NULL, error); return success; }
static void mode_combo_changed_cb (GtkComboBox *combo, gpointer user_data) { CEPageWifi *self = CE_PAGE_WIFI (user_data); CEPageWifiPrivate *priv = CE_PAGE_WIFI_GET_PRIVATE (self); CEPage *parent = CE_PAGE (self); GtkWidget *widget_band_label, *widget_chan_label, *widget_bssid_label; gboolean adhoc; switch (gtk_combo_box_get_active (GTK_COMBO_BOX (combo))) { case 1: /* adhoc */ adhoc = TRUE; break; default: /* infrastructure */ adhoc = FALSE; break; } widget_band_label = GTK_WIDGET (gtk_builder_get_object (parent->builder, "wifi_band_label")); widget_chan_label = GTK_WIDGET (gtk_builder_get_object (parent->builder, "wifi_channel_label")); widget_bssid_label = GTK_WIDGET (gtk_builder_get_object (parent->builder, "wifi_bssid_label")); if (adhoc) { /* For Ad-Hoc show Band and Channel */ gtk_widget_show (widget_band_label); gtk_widget_show (GTK_WIDGET (priv->band)); gtk_widget_show (widget_chan_label); gtk_widget_show (GTK_WIDGET (priv->channel)); /* and hide BSSID * BSSID is random and is created by kernel for Ad-Hoc networks * http://lxr.linux.no/linux+v3.7.6/net/mac80211/ibss.c#L685 */ gtk_widget_hide (widget_bssid_label); gtk_widget_hide (GTK_WIDGET (priv->bssid)); } else { /* Do opposite for Infrastructure mode */ gtk_widget_hide (widget_band_label); gtk_widget_hide (GTK_WIDGET (priv->band)); gtk_widget_hide (widget_chan_label); gtk_widget_hide (GTK_WIDGET (priv->channel)); gtk_widget_show (widget_bssid_label); gtk_widget_show (GTK_WIDGET (priv->bssid)); } gtk_widget_set_sensitive (widget_band_label, adhoc); gtk_widget_set_sensitive (GTK_WIDGET (priv->band), adhoc); gtk_widget_set_sensitive (widget_chan_label, adhoc); gtk_widget_set_sensitive (GTK_WIDGET (priv->channel), adhoc); gtk_widget_set_sensitive (widget_bssid_label, !adhoc); gtk_widget_set_sensitive (GTK_WIDGET (priv->bssid), !adhoc); ce_page_changed (CE_PAGE (self)); }
static gint channel_spin_output_cb (GtkSpinButton *spin, gpointer user_data) { CEPageWifi *self = CE_PAGE_WIFI (user_data); CEPageWifiPrivate *priv = CE_PAGE_WIFI_GET_PRIVATE (self); int channel; gchar *buf = NULL; guint32 freq; gboolean aband = TRUE; gboolean gband = TRUE; if (!band_helper (self, &aband, &gband)) buf = g_strdup (_("default")); else { channel = gtk_spin_button_get_value_as_int (spin); if (channel == 0) buf = g_strdup (_("default")); else { int direction = 0; freq = nm_utils_wifi_channel_to_freq (channel, aband ? "a" : "bg"); if (freq == -1) { if (priv->last_channel < channel) direction = 1; else if (priv->last_channel > channel) direction = -1; channel = nm_utils_wifi_find_next_channel (channel, direction, aband ? "a" : "bg"); gtk_spin_button_set_value (spin, channel); freq = nm_utils_wifi_channel_to_freq (channel, aband ? "a" : "bg"); if (freq == -1) { g_warning ("%s: invalid channel %d!", __func__, channel); gtk_spin_button_set_value (spin, 0); goto out; } } /* Set spin button to zero to go to "default" from the lowest channel */ if (direction == -1 && priv->last_channel == channel) { buf = g_strdup_printf (_("default")); gtk_spin_button_set_value (spin, 0); channel = 0; } else buf = g_strdup_printf (_("%u (%u MHz)"), channel, freq); } priv->last_channel = channel; } if (strcmp (buf, gtk_entry_get_text (GTK_ENTRY (spin)))) gtk_entry_set_text (GTK_ENTRY (spin), buf); out: g_free (buf); return 1; }
static void mode_combo_changed_cb (GtkComboBox *combo, gpointer user_data) { CEPageWifi *self = CE_PAGE_WIFI (user_data); CEPageWifiPrivate *priv = CE_PAGE_WIFI_GET_PRIVATE (self); CEPage *parent = CE_PAGE (self); GtkWidget *widget_band_label, *widget_chan_label, *widget_bssid_label; gboolean show_freq = FALSE; gboolean show_bssid = TRUE; gboolean hotspot = FALSE; switch (gtk_combo_box_get_active (GTK_COMBO_BOX (combo))) { case 1: /* hotspot */ hotspot = TRUE; /* fallthrough */ case 2: /* adhoc */ /* BSSID is random and is created by kernel for Ad-Hoc networks * http://lxr.linux.no/linux+v3.7.6/net/mac80211/ibss.c#L685 * For AP-mode, the BSSID is the MAC address of the device. */ show_bssid = FALSE; show_freq = TRUE; break; default: /* infrastructure */ show_freq = FALSE; break; } nm_connection_editor_inter_page_set_value (parent->editor, INTER_PAGE_CHANGE_WIFI_MODE, GUINT_TO_POINTER (hotspot)); widget_band_label = GTK_WIDGET (gtk_builder_get_object (parent->builder, "wifi_band_label")); widget_chan_label = GTK_WIDGET (gtk_builder_get_object (parent->builder, "wifi_channel_label")); widget_bssid_label = GTK_WIDGET (gtk_builder_get_object (parent->builder, "wifi_bssid_label")); gtk_widget_set_visible (widget_band_label, show_freq); gtk_widget_set_sensitive (widget_band_label, show_freq); gtk_widget_set_visible (GTK_WIDGET (priv->band), show_freq); gtk_widget_set_sensitive (GTK_WIDGET (priv->band), show_freq); gtk_widget_set_visible (widget_chan_label, show_freq); gtk_widget_set_sensitive (widget_chan_label, show_freq); gtk_widget_set_visible (GTK_WIDGET (priv->channel), show_freq); gtk_widget_set_sensitive (GTK_WIDGET (priv->channel), show_freq); gtk_widget_set_visible (widget_bssid_label, show_bssid); gtk_widget_set_sensitive (widget_bssid_label, show_bssid); gtk_widget_set_visible (GTK_WIDGET (priv->bssid), show_bssid); gtk_widget_set_sensitive (GTK_WIDGET (priv->bssid), show_bssid); ce_page_changed (CE_PAGE (self)); }
static gboolean validate (CEPage *page, NMConnection *connection, GError **error) { CEPageWifi *self = CE_PAGE_WIFI (page); CEPageWifiPrivate *priv = CE_PAGE_WIFI_GET_PRIVATE (self); char *security; gboolean success; gboolean invalid = FALSE; GByteArray *ignore; GtkWidget *entry; entry = gtk_bin_get_child (GTK_BIN (priv->bssid)); if (entry) { ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); if (invalid) return FALSE; if (ignore) g_byte_array_free (ignore, TRUE); } entry = gtk_bin_get_child (GTK_BIN (priv->device_mac)); if (entry) { ignore = ce_page_entry_to_mac (GTK_ENTRY (entry), ARPHRD_ETHER, &invalid); if (invalid) return FALSE; if (ignore) g_byte_array_free (ignore, TRUE); } ignore = ce_page_entry_to_mac (priv->cloned_mac, ARPHRD_ETHER, &invalid); if (invalid) return FALSE; if (ignore) g_byte_array_free (ignore, TRUE); ui_to_setting (self); /* A hack to not check the wifi security here */ security = g_strdup (nm_setting_wireless_get_security (priv->setting)); g_object_set (priv->setting, NM_SETTING_WIRELESS_SEC, NULL, NULL); success = nm_setting_verify (NM_SETTING (priv->setting), NULL, error); g_object_set (priv->setting, NM_SETTING_WIRELESS_SEC, security, NULL); g_free (security); return success; }
CEPage * ce_page_wifi_new (NMConnectionEditor *editor, NMConnection *connection, GtkWindow *parent_window, NMClient *client, const char **out_secrets_setting_name, GError **error) { CEPageWifi *self; CEPageWifiPrivate *priv; g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); self = CE_PAGE_WIFI (ce_page_new (CE_TYPE_PAGE_WIFI, editor, connection, parent_window, client, UIDIR "/ce-page-wifi.ui", "WifiPage", _("Wi-Fi"))); if (!self) { g_set_error_literal (error, NMA_ERROR, NMA_ERROR_GENERIC, _("Could not load Wi-Fi user interface.")); return NULL; } wifi_private_init (self); priv = CE_PAGE_WIFI_GET_PRIVATE (self); priv->setting = nm_connection_get_setting_wireless (connection); if (!priv->setting) { priv->setting = NM_SETTING_WIRELESS (nm_setting_wireless_new ()); nm_connection_add_setting (connection, NM_SETTING (priv->setting)); } g_signal_connect (self, "initialized", G_CALLBACK (finish_setup), NULL); return CE_PAGE (self); }
static void band_value_changed_cb (GtkComboBox *box, gpointer user_data) { CEPageWifi *self = CE_PAGE_WIFI (user_data); CEPageWifiPrivate *priv = CE_PAGE_WIFI_GET_PRIVATE (self); gboolean sensitive; priv->last_channel = 0; gtk_spin_button_set_value (priv->channel, 0); switch (gtk_combo_box_get_active (GTK_COMBO_BOX (box))) { case 1: /* A */ case 2: /* B/G */ sensitive = TRUE; break; default: sensitive = FALSE; break; } gtk_widget_set_sensitive (GTK_WIDGET (priv->channel), sensitive); ce_page_changed (CE_PAGE (self)); }
static gint channel_spin_input_cb (GtkSpinButton *spin, gdouble *new_val, gpointer user_data) { CEPageWifi *self = CE_PAGE_WIFI (user_data); gdouble channel; guint32 int_channel = 0; gboolean aband = TRUE; gboolean gband = TRUE; if (!band_helper (self, &aband, &gband)) return GTK_INPUT_ERROR; channel = g_strtod (gtk_entry_get_text (GTK_ENTRY (spin)), NULL); if (channel - floor (channel) < ceil (channel) - channel) int_channel = floor (channel); else int_channel = ceil (channel); if (nm_utils_wifi_channel_to_freq (int_channel, aband ? "a" : "bg") == -1) return GTK_INPUT_ERROR; *new_val = channel; return 1; }