network: Convert NetDeviceWifi to GtkTemplate
This commit is contained in:
parent
7e84af0d6d
commit
7b01c11840
4 changed files with 42 additions and 71 deletions
|
@ -149,7 +149,6 @@ add_wifi_device (CcWifiPanel *self,
|
||||||
{
|
{
|
||||||
GtkWidget *header_widget;
|
GtkWidget *header_widget;
|
||||||
NetDeviceWifi *net_device;
|
NetDeviceWifi *net_device;
|
||||||
GtkWidget *widget;
|
|
||||||
|
|
||||||
/* Only manage Wi-Fi devices */
|
/* Only manage Wi-Fi devices */
|
||||||
if (!NM_IS_DEVICE_WIFI (device) || !nm_device_get_managed (device))
|
if (!NM_IS_DEVICE_WIFI (device) || !nm_device_get_managed (device))
|
||||||
|
@ -159,6 +158,7 @@ add_wifi_device (CcWifiPanel *self,
|
||||||
net_device = net_device_wifi_new (CC_PANEL (self),
|
net_device = net_device_wifi_new (CC_PANEL (self),
|
||||||
self->client,
|
self->client,
|
||||||
device);
|
device);
|
||||||
|
gtk_widget_show (GTK_WIDGET (net_device));
|
||||||
|
|
||||||
/* And add to the header widgets */
|
/* And add to the header widgets */
|
||||||
header_widget = net_device_wifi_get_header_widget (net_device);
|
header_widget = net_device_wifi_get_header_widget (net_device);
|
||||||
|
@ -171,8 +171,7 @@ add_wifi_device (CcWifiPanel *self,
|
||||||
update_devices_names (self);
|
update_devices_names (self);
|
||||||
|
|
||||||
/* Needs to be added after the device is added to the self->devices array */
|
/* Needs to be added after the device is added to the self->devices array */
|
||||||
widget = net_object_get_widget (NET_OBJECT (net_device), self->sizegroup);
|
gtk_stack_add_titled (self->stack, GTK_WIDGET (net_device),
|
||||||
gtk_stack_add_titled (self->stack, widget,
|
|
||||||
nm_device_get_udi (device),
|
nm_device_get_udi (device),
|
||||||
nm_device_get_description (device));
|
nm_device_get_description (device));
|
||||||
}
|
}
|
||||||
|
@ -714,7 +713,7 @@ cc_wifi_panel_init (CcWifiPanel *self)
|
||||||
gtk_widget_init_template (GTK_WIDGET (self));
|
gtk_widget_init_template (GTK_WIDGET (self));
|
||||||
|
|
||||||
self->cancellable = g_cancellable_new ();
|
self->cancellable = g_cancellable_new ();
|
||||||
self->devices = g_ptr_array_new_with_free_func (g_object_unref);
|
self->devices = g_ptr_array_new ();
|
||||||
|
|
||||||
/* Create and store a NMClient instance if it doesn't exist yet */
|
/* Create and store a NMClient instance if it doesn't exist yet */
|
||||||
if (!cc_object_storage_has_object (CC_OBJECT_NMCLIENT))
|
if (!cc_object_storage_has_object (CC_OBJECT_NMCLIENT))
|
||||||
|
|
|
@ -56,14 +56,14 @@ static void show_details_for_row (NetDeviceWifi *self, CcWifiConnectionRow *row,
|
||||||
|
|
||||||
struct _NetDeviceWifi
|
struct _NetDeviceWifi
|
||||||
{
|
{
|
||||||
NetObject parent;
|
GtkStack parent;
|
||||||
|
|
||||||
GtkBuilder *builder;
|
|
||||||
GtkBox *center_box;
|
GtkBox *center_box;
|
||||||
GtkButton *connect_hidden_button;
|
GtkButton *connect_hidden_button;
|
||||||
GtkSwitch *device_off_switch;
|
GtkSwitch *device_off_switch;
|
||||||
GtkBox *header_box;
|
GtkBox *header_box;
|
||||||
GtkButton *history_button;
|
GtkButton *history_button;
|
||||||
|
GtkBox *hotspot_box;
|
||||||
GtkLabel *hotspot_network_name_heading_label;
|
GtkLabel *hotspot_network_name_heading_label;
|
||||||
GtkLabel *hotspot_network_name_label;
|
GtkLabel *hotspot_network_name_label;
|
||||||
GtkSwitch *hotspot_off_switch;
|
GtkSwitch *hotspot_off_switch;
|
||||||
|
@ -72,7 +72,6 @@ struct _NetDeviceWifi
|
||||||
GtkLabel *hotspot_security_key_label;
|
GtkLabel *hotspot_security_key_label;
|
||||||
GtkLabel *hotspot_security_label;
|
GtkLabel *hotspot_security_label;
|
||||||
GtkBox *listbox_box;
|
GtkBox *listbox_box;
|
||||||
GtkNotebook *notebook;
|
|
||||||
GtkButton *start_hotspot_button;
|
GtkButton *start_hotspot_button;
|
||||||
GtkLabel *status_label;
|
GtkLabel *status_label;
|
||||||
GtkLabel *title_label;
|
GtkLabel *title_label;
|
||||||
|
@ -100,16 +99,7 @@ enum {
|
||||||
PROP_LAST,
|
PROP_LAST,
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE (NetDeviceWifi, net_device_wifi, NET_TYPE_OBJECT)
|
G_DEFINE_TYPE (NetDeviceWifi, net_device_wifi, GTK_TYPE_STACK)
|
||||||
|
|
||||||
static GtkWidget *
|
|
||||||
device_wifi_proxy_get_widget (NetObject *object,
|
|
||||||
GtkSizeGroup *heading_size_group)
|
|
||||||
{
|
|
||||||
NetDeviceWifi *self = NET_DEVICE_WIFI (object);
|
|
||||||
|
|
||||||
return GTK_WIDGET (self->notebook);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
disable_scan_timeout (NetDeviceWifi *self)
|
disable_scan_timeout (NetDeviceWifi *self)
|
||||||
|
@ -408,7 +398,7 @@ connect_to_hidden_network (NetDeviceWifi *self)
|
||||||
{
|
{
|
||||||
GtkWidget *toplevel;
|
GtkWidget *toplevel;
|
||||||
|
|
||||||
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self->notebook));
|
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
|
||||||
cc_network_panel_connect_to_hidden_network (toplevel, self->client);
|
cc_network_panel_connect_to_hidden_network (toplevel, self->client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -603,7 +593,7 @@ static void
|
||||||
show_hotspot_ui (NetDeviceWifi *self)
|
show_hotspot_ui (NetDeviceWifi *self)
|
||||||
{
|
{
|
||||||
/* show hotspot tab */
|
/* show hotspot tab */
|
||||||
gtk_notebook_set_current_page (self->notebook, 1);
|
gtk_stack_set_visible_child (GTK_STACK (self), GTK_WIDGET (self->hotspot_box));
|
||||||
|
|
||||||
/* force switch to on as this succeeded */
|
/* force switch to on as this succeeded */
|
||||||
self->updating_device = TRUE;
|
self->updating_device = TRUE;
|
||||||
|
@ -711,7 +701,7 @@ start_hotspot (NetDeviceWifi *self)
|
||||||
g_autofree gchar *ssid = NULL;
|
g_autofree gchar *ssid = NULL;
|
||||||
gint response;
|
gint response;
|
||||||
|
|
||||||
window = gtk_widget_get_toplevel (GTK_WIDGET (self->notebook));
|
window = gtk_widget_get_toplevel (GTK_WIDGET (self));
|
||||||
|
|
||||||
if (!self->hotspot_dialog)
|
if (!self->hotspot_dialog)
|
||||||
self->hotspot_dialog = cc_wifi_hotspot_dialog_new (GTK_WINDOW (window));
|
self->hotspot_dialog = cc_wifi_hotspot_dialog_new (GTK_WINDOW (window));
|
||||||
|
@ -802,7 +792,7 @@ switch_hotspot_changed_cb (NetDeviceWifi *self)
|
||||||
if (self->updating_device)
|
if (self->updating_device)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
window = gtk_widget_get_toplevel (GTK_WIDGET (self->notebook));
|
window = gtk_widget_get_toplevel (GTK_WIDGET (self));
|
||||||
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
|
||||||
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||||
GTK_MESSAGE_OTHER,
|
GTK_MESSAGE_OTHER,
|
||||||
|
@ -820,7 +810,7 @@ switch_hotspot_changed_cb (NetDeviceWifi *self)
|
||||||
static void
|
static void
|
||||||
show_wifi_list (NetDeviceWifi *self)
|
show_wifi_list (NetDeviceWifi *self)
|
||||||
{
|
{
|
||||||
gtk_notebook_set_current_page (self->notebook, 0);
|
gtk_stack_set_visible_child (GTK_STACK (self), GTK_WIDGET (self->listbox_box));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -832,7 +822,6 @@ net_device_wifi_finalize (GObject *object)
|
||||||
g_clear_object (&self->cancellable);
|
g_clear_object (&self->cancellable);
|
||||||
disable_scan_timeout (self);
|
disable_scan_timeout (self);
|
||||||
|
|
||||||
g_clear_object (&self->builder);
|
|
||||||
g_clear_object (&self->client);
|
g_clear_object (&self->client);
|
||||||
g_clear_object (&self->device);
|
g_clear_object (&self->device);
|
||||||
g_clear_pointer (&self->selected_ssid_title, g_free);
|
g_clear_pointer (&self->selected_ssid_title, g_free);
|
||||||
|
@ -864,11 +853,10 @@ static void
|
||||||
net_device_wifi_class_init (NetDeviceWifiClass *klass)
|
net_device_wifi_class_init (NetDeviceWifiClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
NetObjectClass *parent_class = NET_OBJECT_CLASS (klass);
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||||
|
|
||||||
object_class->finalize = net_device_wifi_finalize;
|
object_class->finalize = net_device_wifi_finalize;
|
||||||
object_class->get_property = net_device_wifi_get_property;
|
object_class->get_property = net_device_wifi_get_property;
|
||||||
parent_class->get_widget = device_wifi_proxy_get_widget;
|
|
||||||
|
|
||||||
g_object_class_install_property (object_class,
|
g_object_class_install_property (object_class,
|
||||||
PROP_SCANNING,
|
PROP_SCANNING,
|
||||||
|
@ -877,6 +865,26 @@ net_device_wifi_class_init (NetDeviceWifiClass *klass)
|
||||||
"Whether the device is scanning for access points",
|
"Whether the device is scanning for access points",
|
||||||
FALSE,
|
FALSE,
|
||||||
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/network/network-wifi.ui");
|
||||||
|
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceWifi, center_box);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceWifi, connect_hidden_button);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceWifi, device_off_switch);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceWifi, header_box);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceWifi, history_button);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceWifi, hotspot_box);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceWifi, hotspot_network_name_heading_label);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceWifi, hotspot_network_name_label);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceWifi, hotspot_off_switch);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceWifi, hotspot_security_heading_label);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceWifi, hotspot_security_key_heading_label);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceWifi, hotspot_security_key_label);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceWifi, hotspot_security_label);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceWifi, listbox_box);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceWifi, start_hotspot_button);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceWifi, status_label);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, NetDeviceWifi, title_label);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1092,7 +1100,7 @@ open_history (NetDeviceWifi *self)
|
||||||
GList *list_rows;
|
GList *list_rows;
|
||||||
|
|
||||||
dialog = g_object_new (HDY_TYPE_DIALOG, "use-header-bar", 1, NULL);
|
dialog = g_object_new (HDY_TYPE_DIALOG, "use-header-bar", 1, NULL);
|
||||||
window = gtk_widget_get_toplevel (GTK_WIDGET (self->notebook));
|
window = gtk_widget_get_toplevel (GTK_WIDGET (self));
|
||||||
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
|
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));
|
||||||
gtk_window_set_title (GTK_WINDOW (dialog), _("Known Wi-Fi Networks"));
|
gtk_window_set_title (GTK_WINDOW (dialog), _("Known Wi-Fi Networks"));
|
||||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
||||||
|
@ -1214,34 +1222,7 @@ ap_activated (NetDeviceWifi *self, GtkListBoxRow *row)
|
||||||
static void
|
static void
|
||||||
net_device_wifi_init (NetDeviceWifi *self)
|
net_device_wifi_init (NetDeviceWifi *self)
|
||||||
{
|
{
|
||||||
g_autoptr(GError) error = NULL;
|
gtk_widget_init_template (GTK_WIDGET (self));
|
||||||
|
|
||||||
self->builder = gtk_builder_new ();
|
|
||||||
gtk_builder_add_from_resource (self->builder,
|
|
||||||
"/org/gnome/control-center/network/network-wifi.ui",
|
|
||||||
&error);
|
|
||||||
if (error != NULL) {
|
|
||||||
g_warning ("Could not load interface file: %s", error->message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self->center_box = GTK_BOX (gtk_builder_get_object (self->builder, "center_box"));
|
|
||||||
self->connect_hidden_button = GTK_BUTTON (gtk_builder_get_object (self->builder, "connect_hidden_button"));
|
|
||||||
self->device_off_switch = GTK_SWITCH (gtk_builder_get_object (self->builder, "device_off_switch"));
|
|
||||||
self->header_box = GTK_BOX (gtk_builder_get_object (self->builder, "header_box"));
|
|
||||||
self->history_button = GTK_BUTTON (gtk_builder_get_object (self->builder, "history_button"));
|
|
||||||
self->hotspot_network_name_heading_label = GTK_LABEL (gtk_builder_get_object (self->builder, "hotspot_network_name_heading_label"));
|
|
||||||
self->hotspot_network_name_label = GTK_LABEL (gtk_builder_get_object (self->builder, "hotspot_network_name_label"));
|
|
||||||
self->hotspot_off_switch = GTK_SWITCH (gtk_builder_get_object (self->builder, "hotspot_off_switch"));
|
|
||||||
self->hotspot_security_heading_label = GTK_LABEL (gtk_builder_get_object (self->builder, "hotspot_security_heading_label"));
|
|
||||||
self->hotspot_security_key_heading_label = GTK_LABEL (gtk_builder_get_object (self->builder, "hotspot_security_key_heading_label"));
|
|
||||||
self->hotspot_security_key_label = GTK_LABEL (gtk_builder_get_object (self->builder, "hotspot_security_key_label"));
|
|
||||||
self->hotspot_security_label = GTK_LABEL (gtk_builder_get_object (self->builder, "hotspot_security_label"));
|
|
||||||
self->listbox_box = GTK_BOX (gtk_builder_get_object (self->builder, "listbox_box"));
|
|
||||||
self->notebook = GTK_NOTEBOOK (gtk_builder_get_object (self->builder, "notebook"));
|
|
||||||
self->start_hotspot_button = GTK_BUTTON (gtk_builder_get_object (self->builder, "start_hotspot_button"));
|
|
||||||
self->status_label = GTK_LABEL (gtk_builder_get_object (self->builder, "status_label"));
|
|
||||||
self->title_label = GTK_LABEL (gtk_builder_get_object (self->builder, "title_label"));
|
|
||||||
|
|
||||||
self->cancellable = g_cancellable_new ();
|
self->cancellable = g_cancellable_new ();
|
||||||
|
|
||||||
|
@ -1249,10 +1230,6 @@ net_device_wifi_init (NetDeviceWifi *self)
|
||||||
g_signal_connect_swapped (self->device_off_switch, "notify::active",
|
g_signal_connect_swapped (self->device_off_switch, "notify::active",
|
||||||
G_CALLBACK (device_off_toggled), self);
|
G_CALLBACK (device_off_toggled), self);
|
||||||
|
|
||||||
/* setup view */
|
|
||||||
gtk_notebook_set_show_tabs (self->notebook, FALSE);
|
|
||||||
gtk_notebook_set_current_page (self->notebook, 0);
|
|
||||||
|
|
||||||
g_signal_connect_swapped (self->start_hotspot_button, "clicked",
|
g_signal_connect_swapped (self->start_hotspot_button, "clicked",
|
||||||
G_CALLBACK (start_hotspot), self);
|
G_CALLBACK (start_hotspot), self);
|
||||||
|
|
||||||
|
@ -1274,7 +1251,7 @@ net_device_wifi_new (CcPanel *panel, NMClient *client, NMDevice *device)
|
||||||
NMDeviceWifiCapabilities caps;
|
NMDeviceWifiCapabilities caps;
|
||||||
GtkWidget *list;
|
GtkWidget *list;
|
||||||
|
|
||||||
self = g_object_new (NET_TYPE_DEVICE_WIFI, NULL);
|
self = g_object_new (net_device_wifi_get_type (), NULL);
|
||||||
self->panel = panel;
|
self->panel = panel;
|
||||||
self->client = g_object_ref (client);
|
self->client = g_object_ref (client);
|
||||||
self->device = g_object_ref (device);
|
self->device = g_object_ref (device);
|
||||||
|
|
|
@ -21,14 +21,13 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glib-object.h>
|
#include <gtk/gtk.h>
|
||||||
|
#include <shell/cc-panel.h>
|
||||||
#include "net-object.h"
|
#include <NetworkManager.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#define NET_TYPE_DEVICE_WIFI (net_device_wifi_get_type ())
|
G_DECLARE_FINAL_TYPE (NetDeviceWifi, net_device_wifi, NET, DEVICE_WIFI, GtkStack)
|
||||||
G_DECLARE_FINAL_TYPE (NetDeviceWifi, net_device_wifi, NET, DEVICE_WIFI, NetObject)
|
|
||||||
|
|
||||||
NetDeviceWifi *net_device_wifi_new (CcPanel *panel,
|
NetDeviceWifi *net_device_wifi_new (CcPanel *panel,
|
||||||
NMClient *client,
|
NMClient *client,
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<interface>
|
<interface>
|
||||||
<!-- interface-requires gtk+ 3.0 -->
|
<!-- interface-requires gtk+ 3.0 -->
|
||||||
<object class="GtkNotebook" id="notebook">
|
<template class="NetDeviceWifi" parent="GtkStack">
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="show_tabs">False</property>
|
|
||||||
<property name="show_border">False</property>
|
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox" id="listbox_box">
|
<object class="GtkBox" id="listbox_box">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
@ -14,7 +10,7 @@
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkBox">
|
<object class="GtkBox" id="hotspot_box">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="border_width">12</property>
|
<property name="border_width">12</property>
|
||||||
|
@ -220,7 +216,7 @@
|
||||||
<property name="position">1</property>
|
<property name="position">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</template>
|
||||||
|
|
||||||
<!-- Center widget -->
|
<!-- Center widget -->
|
||||||
<object class="GtkBox" id="center_box">
|
<object class="GtkBox" id="center_box">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue