[gnome-control-center] network: Convert NetProxy to GtkTemplate
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] network: Convert NetProxy to GtkTemplate
- Date: Tue, 5 Nov 2019 23:07:55 +0000 (UTC)
commit b3e372becd1536f919319a12c1e03415deb6127b
Author: Robert Ancell <robert ancell canonical com>
Date: Thu Oct 24 14:17:17 2019 +1300
network: Convert NetProxy to GtkTemplate
This whole widget was added to a size group with some elements of the mobile
devices. This seems a mistake, but can be added back later if found to be
necessary.
panels/network/cc-network-panel.c | 3 +-
panels/network/net-proxy.c | 78 ++++++++++++++-------------------------
panels/network/net-proxy.h | 9 ++---
panels/network/network-proxy.ui | 4 +-
4 files changed, 34 insertions(+), 60 deletions(-)
---
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index e4861b038..22332c037 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -755,7 +755,8 @@ cc_network_panel_init (CcNetworkPanel *self)
/* add the virtual proxy device */
proxy = net_proxy_new ();
- add_object (self, NET_OBJECT (proxy), GTK_CONTAINER (self->box_proxy));
+ gtk_widget_show (GTK_WIDGET (proxy));
+ gtk_container_add (GTK_CONTAINER (self->box_proxy), GTK_WIDGET (proxy));
/* Create and store a NMClient instance if it doesn't exist yet */
if (!cc_object_storage_has_object (CC_OBJECT_NMCLIENT)) {
diff --git a/panels/network/net-proxy.c b/panels/network/net-proxy.c
index 29f326627..9d044d69d 100644
--- a/panels/network/net-proxy.c
+++ b/panels/network/net-proxy.c
@@ -36,13 +36,11 @@ typedef enum
struct _NetProxy
{
- NetObject parent;
+ GtkFrame parent;
- GtkBuilder *builder;
GtkRadioButton *automatic_radio;
GtkDialog *dialog;
GtkButton *dialog_button;
- GtkFrame *main_widget;
GtkRadioButton *manual_radio;
GtkRadioButton *none_radio;
GtkEntry *proxy_ftp_entry;
@@ -62,7 +60,7 @@ struct _NetProxy
GSettings *settings;
};
-G_DEFINE_TYPE (NetProxy, net_proxy, NET_TYPE_OBJECT)
+G_DEFINE_TYPE (NetProxy, net_proxy, GTK_TYPE_FRAME)
static const gchar *
panel_get_string_for_value (ProxyMode mode)
@@ -188,30 +186,16 @@ panel_proxy_mode_radio_changed_cb (NetProxy *self, GtkRadioButton *radio)
static void
show_dialog_cb (NetProxy *self)
{
- gtk_window_set_transient_for (GTK_WINDOW (self->dialog), GTK_WINDOW (gtk_widget_get_toplevel
(GTK_WIDGET (self->main_widget))));
+ gtk_window_set_transient_for (GTK_WINDOW (self->dialog), GTK_WINDOW (gtk_widget_get_toplevel
(GTK_WIDGET (self))));
gtk_window_present (GTK_WINDOW (self->dialog));
}
-static GtkWidget *
-net_proxy_get_widget (NetObject *object,
- GtkSizeGroup *heading_size_group)
-{
- NetProxy *self = NET_PROXY (object);
-
- gtk_size_group_add_widget (heading_size_group, GTK_WIDGET (self->main_widget));
-
- return GTK_WIDGET (self->main_widget);
-}
-
static void
net_proxy_finalize (GObject *object)
{
NetProxy *self = NET_PROXY (object);
- gtk_widget_destroy (GTK_WIDGET (self->dialog));
-
g_clear_object (&self->settings);
- g_clear_object (&self->builder);
G_OBJECT_CLASS (net_proxy_parent_class)->finalize (object);
}
@@ -220,10 +204,30 @@ static void
net_proxy_class_init (NetProxyClass *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_proxy_finalize;
- parent_class->get_widget = net_proxy_get_widget;
+
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/network/network-proxy.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, automatic_radio);
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, dialog);
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, dialog_button);
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, manual_radio);
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, none_radio);
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, proxy_ftp_entry);
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, proxy_http_entry);
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, proxy_https_entry);
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, proxy_ignore_entry);
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, proxy_port_ftp_adjustment);
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, proxy_port_http_adjustment);
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, proxy_port_https_adjustment);
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, proxy_port_socks_adjustment);
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, proxy_socks_entry);
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, proxy_url_entry);
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, proxy_warning_label);
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, stack);
+ gtk_widget_class_bind_template_child (widget_class, NetProxy, status_label);
}
static gboolean
@@ -282,36 +286,8 @@ net_proxy_init (NetProxy *self)
g_autoptr(GSettings) ftp_settings = NULL;
g_autoptr(GSettings) socks_settings = NULL;
ProxyMode value;
- g_autoptr(GError) error = NULL;
-
- self->builder = gtk_builder_new ();
- gtk_builder_add_from_resource (self->builder,
- "/org/gnome/control-center/network/network-proxy.ui",
- &error);
- if (error != NULL) {
- g_warning ("Could not load interface file: %s", error->message);
- return;
- }
- self->automatic_radio = GTK_RADIO_BUTTON (gtk_builder_get_object (self->builder, "automatic_radio"));
- self->dialog = GTK_DIALOG (gtk_builder_get_object (self->builder, "dialog"));
- self->dialog_button = GTK_BUTTON (gtk_builder_get_object (self->builder, "dialog_button"));
- self->main_widget = GTK_FRAME (gtk_builder_get_object (self->builder, "main_widget"));
- self->manual_radio = GTK_RADIO_BUTTON (gtk_builder_get_object (self->builder, "manual_radio"));
- self->none_radio = GTK_RADIO_BUTTON (gtk_builder_get_object (self->builder, "none_radio"));
- self->proxy_ftp_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "proxy_ftp_entry"));
- self->proxy_http_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "proxy_http_entry"));
- self->proxy_https_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "proxy_https_entry"));
- self->proxy_ignore_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "proxy_ignore_entry"));
- self->proxy_port_ftp_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (self->builder,
"proxy_port_ftp_adjustment"));
- self->proxy_port_http_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (self->builder,
"proxy_port_http_adjustment"));
- self->proxy_port_https_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (self->builder,
"proxy_port_https_adjustment"));
- self->proxy_port_socks_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (self->builder,
"proxy_port_socks_adjustment"));
- self->proxy_socks_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "proxy_socks_entry"));
- self->proxy_url_entry = GTK_ENTRY (gtk_builder_get_object (self->builder, "proxy_url_entry"));
- self->proxy_warning_label = GTK_LABEL (gtk_builder_get_object (self->builder,
"proxy_warning_label"));
- self->stack = GTK_STACK (gtk_builder_get_object (self->builder, "stack"));
- self->status_label = GTK_LABEL (gtk_builder_get_object (self->builder, "status_label"));
+ gtk_widget_init_template (GTK_WIDGET (self));
self->settings = g_settings_new ("org.gnome.system.proxy");
g_signal_connect_swapped (self->settings,
@@ -406,5 +382,5 @@ net_proxy_init (NetProxy *self)
NetProxy *
net_proxy_new (void)
{
- return g_object_new (NET_TYPE_PROXY, NULL);
+ return g_object_new (net_proxy_get_type (), NULL);
}
diff --git a/panels/network/net-proxy.h b/panels/network/net-proxy.h
index dab0b37ca..d0e019a33 100644
--- a/panels/network/net-proxy.h
+++ b/panels/network/net-proxy.h
@@ -21,15 +21,12 @@
#pragma once
-#include <glib-object.h>
-
-#include "net-object.h"
+#include <gtk/gtk.h>
G_BEGIN_DECLS
-#define NET_TYPE_PROXY (net_proxy_get_type ())
-G_DECLARE_FINAL_TYPE (NetProxy, net_proxy, NET, PROXY, NetObject)
+G_DECLARE_FINAL_TYPE (NetProxy, net_proxy, NET, PROXY, GtkFrame)
-NetProxy *net_proxy_new (void);
+NetProxy *net_proxy_new (void);
G_END_DECLS
diff --git a/panels/network/network-proxy.ui b/panels/network/network-proxy.ui
index b3a764488..4771716e1 100644
--- a/panels/network/network-proxy.ui
+++ b/panels/network/network-proxy.ui
@@ -17,7 +17,7 @@
<property name="upper">65535</property>
<property name="step_increment">1</property>
</object>
- <object class="GtkFrame" id="main_widget">
+ <template class="NetProxy" parent="GtkFrame">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
@@ -82,7 +82,7 @@
</child>
</object>
</child>
- </object>
+ </template>
<object class="GtkDialog" id="dialog">
<property name="use_header_bar">1</property>
<property name="can_focus">False</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]