2012-12-09 19:38:32 -05:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Red Hat, Inc
|
|
|
|
*
|
|
|
|
* Licensed under the GNU General Public License Version 2
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
#include <NetworkManager.h>
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
#include <net/if_arp.h>
|
|
|
|
|
|
|
|
#include "ce-page-wifi.h"
|
2014-08-07 18:32:34 +02:00
|
|
|
#include "ui-helpers.h"
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
G_DEFINE_TYPE (CEPageWifi, ce_page_wifi, CE_TYPE_PAGE)
|
|
|
|
|
|
|
|
static void
|
|
|
|
connect_wifi_page (CEPageWifi *page)
|
|
|
|
{
|
2016-04-29 16:05:54 +02:00
|
|
|
GBytes *ssid;
|
2019-09-12 11:40:48 +12:00
|
|
|
g_autofree gchar *utf8_ssid = NULL;
|
2012-12-09 19:38:32 -05:00
|
|
|
GPtrArray *bssid_array;
|
|
|
|
gchar **bssid_list;
|
2016-04-29 16:05:54 +02:00
|
|
|
const char *s_bssid_str;
|
2012-12-09 19:38:32 -05:00
|
|
|
gchar **mac_list;
|
2016-04-29 16:05:54 +02:00
|
|
|
const gchar *s_mac_str;
|
|
|
|
const gchar *cloned_mac;
|
2012-12-09 19:38:32 -05:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
ssid = nm_setting_wireless_get_ssid (page->setting);
|
|
|
|
if (ssid)
|
2016-04-29 16:05:54 +02:00
|
|
|
utf8_ssid = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid));
|
2012-12-09 19:38:32 -05:00
|
|
|
else
|
|
|
|
utf8_ssid = g_strdup ("");
|
2019-10-15 12:25:48 +13:00
|
|
|
gtk_entry_set_text (page->ssid_entry, utf8_ssid);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-15 12:25:48 +13:00
|
|
|
g_signal_connect_swapped (page->ssid_entry, "changed", G_CALLBACK (ce_page_changed), page);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
bssid_array = g_ptr_array_new ();
|
|
|
|
for (i = 0; i < nm_setting_wireless_get_num_seen_bssids (page->setting); i++) {
|
|
|
|
g_ptr_array_add (bssid_array, g_strdup (nm_setting_wireless_get_seen_bssid (page->setting, i)));
|
|
|
|
}
|
|
|
|
g_ptr_array_add (bssid_array, NULL);
|
|
|
|
bssid_list = (gchar **) g_ptr_array_free (bssid_array, FALSE);
|
2016-04-29 16:05:54 +02:00
|
|
|
s_bssid_str = nm_setting_wireless_get_bssid (page->setting);
|
2019-10-15 12:25:48 +13:00
|
|
|
ce_page_setup_mac_combo (page->bssid_combo, s_bssid_str, bssid_list);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_strfreev (bssid_list);
|
2019-10-15 12:25:48 +13:00
|
|
|
g_signal_connect_swapped (page->bssid_combo, "changed", G_CALLBACK (ce_page_changed), page);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
mac_list = ce_page_get_mac_list (CE_PAGE (page)->client, NM_TYPE_DEVICE_WIFI,
|
|
|
|
NM_DEVICE_WIFI_PERMANENT_HW_ADDRESS);
|
2016-04-29 16:05:54 +02:00
|
|
|
s_mac_str = nm_setting_wireless_get_mac_address (page->setting);
|
2019-10-15 12:25:48 +13:00
|
|
|
ce_page_setup_mac_combo (page->mac_combo, s_mac_str, mac_list);
|
2012-12-09 19:38:32 -05:00
|
|
|
g_strfreev (mac_list);
|
2019-10-15 12:25:48 +13:00
|
|
|
g_signal_connect_swapped (page->mac_combo, "changed", G_CALLBACK (ce_page_changed), page);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2016-04-29 16:05:54 +02:00
|
|
|
cloned_mac = nm_setting_wireless_get_cloned_mac_address (page->setting);
|
2019-10-15 12:25:48 +13:00
|
|
|
ce_page_setup_cloned_mac_combo (page->cloned_mac_combo, cloned_mac);
|
|
|
|
g_signal_connect_swapped (page->cloned_mac_combo, "changed", G_CALLBACK (ce_page_changed), page);
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ui_to_setting (CEPageWifi *page)
|
|
|
|
{
|
2019-09-12 11:53:42 +12:00
|
|
|
g_autoptr(GBytes) ssid = NULL;
|
2016-04-29 16:05:54 +02:00
|
|
|
const gchar *utf8_ssid, *bssid;
|
2012-12-09 19:38:32 -05:00
|
|
|
GtkWidget *entry;
|
2019-09-12 11:40:48 +12:00
|
|
|
g_autofree gchar *device_mac = NULL;
|
|
|
|
g_autofree gchar *cloned_mac = NULL;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-15 12:25:48 +13:00
|
|
|
utf8_ssid = gtk_entry_get_text (page->ssid_entry);
|
2012-12-09 19:38:32 -05:00
|
|
|
if (!utf8_ssid || !*utf8_ssid)
|
|
|
|
ssid = NULL;
|
|
|
|
else {
|
2016-04-29 16:05:54 +02:00
|
|
|
ssid = g_bytes_new_static (utf8_ssid, strlen (utf8_ssid));
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
2019-10-15 12:25:48 +13:00
|
|
|
entry = gtk_bin_get_child (GTK_BIN (page->bssid_combo));
|
2016-04-29 16:05:54 +02:00
|
|
|
bssid = gtk_entry_get_text (GTK_ENTRY (entry));
|
2016-06-07 17:26:41 +02:00
|
|
|
if (*bssid == '\0')
|
|
|
|
bssid = NULL;
|
2019-10-15 12:25:48 +13:00
|
|
|
entry = gtk_bin_get_child (GTK_BIN (page->mac_combo));
|
2016-04-29 16:05:54 +02:00
|
|
|
device_mac = ce_page_trim_address (gtk_entry_get_text (GTK_ENTRY (entry)));
|
2019-10-15 12:25:48 +13:00
|
|
|
cloned_mac = ce_page_cloned_mac_get (page->cloned_mac_combo);
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
g_object_set (page->setting,
|
|
|
|
NM_SETTING_WIRELESS_SSID, ssid,
|
|
|
|
NM_SETTING_WIRELESS_BSSID, bssid,
|
|
|
|
NM_SETTING_WIRELESS_MAC_ADDRESS, device_mac,
|
|
|
|
NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, cloned_mac,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2019-10-15 12:25:48 +13:00
|
|
|
validate (CEPage *parent,
|
2012-12-09 19:38:32 -05:00
|
|
|
NMConnection *connection,
|
|
|
|
GError **error)
|
|
|
|
{
|
2019-10-15 12:25:48 +13:00
|
|
|
CEPageWifi *page = (CEPageWifi *) parent;
|
2012-12-09 19:38:32 -05:00
|
|
|
GtkWidget *entry;
|
2014-08-13 13:46:03 +02:00
|
|
|
gboolean ret = TRUE;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-15 12:25:48 +13:00
|
|
|
entry = gtk_bin_get_child (GTK_BIN (page->bssid_combo));
|
2016-04-29 16:05:54 +02:00
|
|
|
if (!ce_page_address_is_valid (gtk_entry_get_text (GTK_ENTRY (entry)))) {
|
2014-08-07 18:32:34 +02:00
|
|
|
widget_set_error (entry);
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
|
|
|
} else {
|
|
|
|
widget_unset_error (entry);
|
2014-08-07 18:32:34 +02:00
|
|
|
}
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-15 12:25:48 +13:00
|
|
|
entry = gtk_bin_get_child (GTK_BIN (page->mac_combo));
|
2016-04-29 16:05:54 +02:00
|
|
|
if (!ce_page_address_is_valid (gtk_entry_get_text (GTK_ENTRY (entry)))) {
|
2014-08-07 18:32:34 +02:00
|
|
|
widget_set_error (entry);
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
|
|
|
} else {
|
|
|
|
widget_unset_error (entry);
|
2014-08-07 18:32:34 +02:00
|
|
|
}
|
2012-12-09 19:38:32 -05:00
|
|
|
|
2019-10-15 12:25:48 +13:00
|
|
|
if (!ce_page_cloned_mac_combo_valid (page->cloned_mac_combo)) {
|
|
|
|
widget_set_error (gtk_bin_get_child (GTK_BIN (page->cloned_mac_combo)));
|
2014-08-13 13:46:03 +02:00
|
|
|
ret = FALSE;
|
|
|
|
} else {
|
2019-10-15 12:25:48 +13:00
|
|
|
widget_unset_error (gtk_bin_get_child (GTK_BIN (page->cloned_mac_combo)));
|
2014-08-07 18:32:34 +02:00
|
|
|
}
|
2014-08-13 13:46:03 +02:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
return ret;
|
2012-12-09 19:38:32 -05:00
|
|
|
|
|
|
|
ui_to_setting (CE_PAGE_WIFI (page));
|
|
|
|
|
2014-08-13 13:46:03 +02:00
|
|
|
return ret;
|
2012-12-09 19:38:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ce_page_wifi_init (CEPageWifi *page)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ce_page_wifi_class_init (CEPageWifiClass *class)
|
|
|
|
{
|
|
|
|
CEPageClass *page_class= CE_PAGE_CLASS (class);
|
|
|
|
|
|
|
|
page_class->validate = validate;
|
|
|
|
}
|
|
|
|
|
|
|
|
CEPage *
|
|
|
|
ce_page_wifi_new (NMConnection *connection,
|
2016-04-29 16:05:54 +02:00
|
|
|
NMClient *client)
|
2012-12-09 19:38:32 -05:00
|
|
|
{
|
|
|
|
CEPageWifi *page;
|
|
|
|
|
|
|
|
page = CE_PAGE_WIFI (ce_page_new (CE_TYPE_PAGE_WIFI,
|
|
|
|
connection,
|
|
|
|
client,
|
|
|
|
"/org/gnome/control-center/network/wifi-page.ui",
|
|
|
|
_("Identity")));
|
|
|
|
|
2019-10-15 12:25:48 +13:00
|
|
|
page->bssid_combo = GTK_COMBO_BOX_TEXT (gtk_builder_get_object (CE_PAGE (page)->builder, "bssid_combo"));
|
|
|
|
page->cloned_mac_combo = GTK_COMBO_BOX_TEXT (gtk_builder_get_object (CE_PAGE (page)->builder, "cloned_mac_combo"));
|
|
|
|
page->mac_combo = GTK_COMBO_BOX_TEXT (gtk_builder_get_object (CE_PAGE (page)->builder, "mac_combo"));
|
|
|
|
page->ssid_entry = GTK_ENTRY (gtk_builder_get_object (CE_PAGE (page)->builder, "ssid_entry"));
|
|
|
|
|
2012-12-09 19:38:32 -05:00
|
|
|
page->setting = nm_connection_get_setting_wireless (connection);
|
|
|
|
|
|
|
|
connect_wifi_page (page);
|
|
|
|
|
|
|
|
return CE_PAGE (page);
|
|
|
|
}
|