[gnome-control-center/wip/benzea/wifi-panel-with-editor-changes: 1/19] connection-editor: Use GtkTemplate
- From: Benjamin Berg <bberg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/benzea/wifi-panel-with-editor-changes: 1/19] connection-editor: Use GtkTemplate
- Date: Thu, 13 Dec 2018 17:09:22 +0000 (UTC)
commit 1a822b6faa54c2fef3ac33d6609dc88c0181be4f
Author: Adrien Plazas <kekun plazas laposte net>
Date: Fri Nov 30 09:02:57 2018 +0100
connection-editor: Use GtkTemplate
panels/network/cc-network-panel.c | 9 --
.../network/connection-editor/connection-editor.ui | 8 +-
.../connection-editor/net-connection-editor.c | 104 ++++++++-------------
.../connection-editor/net-connection-editor.h | 12 ++-
panels/network/net-device-ethernet.c | 1 -
panels/network/net-device-wifi.c | 9 --
panels/network/net-vpn.c | 1 -
7 files changed, 53 insertions(+), 91 deletions(-)
---
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index 2651edccd..15f0f93f0 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -800,14 +800,6 @@ panel_check_network_manager_version (CcNetworkPanel *panel)
}
}
-static void
-editor_done (NetConnectionEditor *editor,
- gboolean success,
- gpointer user_data)
-{
- g_object_unref (editor);
-}
-
static void
create_connection_cb (GtkWidget *button,
CcNetworkPanel *self)
@@ -817,7 +809,6 @@ create_connection_cb (GtkWidget *button,
toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)));
editor = net_connection_editor_new (toplevel, NULL, NULL, NULL, self->client);
- g_signal_connect (editor, "done", G_CALLBACK (editor_done), self);
net_connection_editor_run (editor);
}
diff --git a/panels/network/connection-editor/connection-editor.ui
b/panels/network/connection-editor/connection-editor.ui
index 4495c728d..4773a5d58 100644
--- a/panels/network/connection-editor/connection-editor.ui
+++ b/panels/network/connection-editor/connection-editor.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
- <object class="GtkDialog" id="details_dialog">
+ <template class="NetConnectionEditor" parent="GtkDialog">
<property name="can_focus">False</property>
<property name="border_width">0</property>
<property name="resizable">False</property>
@@ -9,7 +9,9 @@
<property name="default_width">500</property>
<property name="default_height">300</property>
<property name="type_hint">dialog</property>
+ <!-- This doesn't seem to work for a template, so it is also hardcoded. -->
<property name="use_header_bar">1</property>
+ <signal name="delete-event" handler="delete_event_cb"/>
<child type="action">
<object class="GtkButton" id="details_cancel_button">
<property name="label" translatable="yes">_Cancel</property>
@@ -17,6 +19,7 @@
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
+ <signal name="clicked" handler="cancel_clicked_cb" object="NetConnectionEditor" swapped="yes"/>
</object>
</child>
<child type="action">
@@ -27,6 +30,7 @@
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
+ <signal name="clicked" handler="apply_clicked_cb" object="NetConnectionEditor" swapped="yes"/>
</object>
</child>
<child internal-child="vbox">
@@ -126,5 +130,5 @@
<action-widget response="cancel">details_cancel_button</action-widget>
<action-widget response="apply" default="true">details_apply_button</action-widget>
</action-widgets>
- </object>
+ </template>
</interface>
diff --git a/panels/network/connection-editor/net-connection-editor.c
b/panels/network/connection-editor/net-connection-editor.c
index 556b57fb8..c515fe289 100644
--- a/panels/network/connection-editor/net-connection-editor.c
+++ b/panels/network/connection-editor/net-connection-editor.c
@@ -47,14 +47,14 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
-G_DEFINE_TYPE (NetConnectionEditor, net_connection_editor, G_TYPE_OBJECT)
+G_DEFINE_TYPE (NetConnectionEditor, net_connection_editor, GTK_TYPE_DIALOG)
static void page_changed (CEPage *page, gpointer user_data);
static void
cancel_editing (NetConnectionEditor *editor)
{
- gtk_widget_hide (editor->window);
+ gtk_widget_hide (GTK_WIDGET (editor));
g_signal_emit (editor, signals[DONE], 0, FALSE);
}
@@ -72,7 +72,7 @@ static void
update_complete (NetConnectionEditor *editor,
gboolean success)
{
- gtk_widget_hide (editor->window);
+ gtk_widget_hide (GTK_WIDGET (editor));
g_signal_emit (editor, signals[DONE], 0, success);
}
@@ -145,38 +145,7 @@ apply_edits (NetConnectionEditor *editor)
static void
net_connection_editor_init (NetConnectionEditor *editor)
{
- GError *error = NULL;
-
- editor->builder = gtk_builder_new ();
-
- gtk_builder_add_from_resource (editor->builder,
- "/org/gnome/control-center/network/connection-editor.ui",
- &error);
- if (error != NULL) {
- g_warning ("Could not load ui file: %s", error->message);
- g_error_free (error);
- return;
- }
-
- editor->window = GTK_WIDGET (gtk_builder_get_object (editor->builder, "details_dialog"));
-}
-
-void
-net_connection_editor_run (NetConnectionEditor *editor)
-{
- GtkWidget *button;
-
- button = GTK_WIDGET (gtk_builder_get_object (editor->builder, "details_cancel_button"));
- g_signal_connect_swapped (button, "clicked",
- G_CALLBACK (cancel_editing), editor);
- g_signal_connect_swapped (editor->window, "delete-event",
- G_CALLBACK (cancel_editing), editor);
-
- button = GTK_WIDGET (gtk_builder_get_object (editor->builder, "details_apply_button"));
- g_signal_connect_swapped (button, "clicked",
- G_CALLBACK (apply_edits), editor);
-
- net_connection_editor_present (editor);
+ gtk_widget_init_template (GTK_WIDGET (editor));
}
static void
@@ -192,12 +161,7 @@ net_connection_editor_finalize (GObject *object)
g_signal_handler_disconnect (editor->client, editor->permission_id);
g_clear_object (&editor->connection);
g_clear_object (&editor->orig_connection);
- if (editor->window) {
- gtk_widget_destroy (editor->window);
- editor->window = NULL;
- }
g_clear_object (&editor->parent_window);
- g_clear_object (&editor->builder);
g_clear_object (&editor->device);
g_clear_object (&editor->client);
g_clear_object (&editor->ap);
@@ -209,6 +173,7 @@ static void
net_connection_editor_class_init (NetConnectionEditorClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
g_resources_register (net_connection_editor_get_resource ());
@@ -221,6 +186,17 @@ net_connection_editor_class_init (NetConnectionEditorClass *class)
NULL, NULL,
NULL,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/network/connection-editor.ui");
+
+ gtk_widget_class_bind_template_child (widget_class, NetConnectionEditor,
details_add_connection_frame);
+ gtk_widget_class_bind_template_child (widget_class, NetConnectionEditor, details_apply_button);
+ gtk_widget_class_bind_template_child (widget_class, NetConnectionEditor, details_cancel_button);
+ gtk_widget_class_bind_template_child (widget_class, NetConnectionEditor, details_notebook);
+ gtk_widget_class_bind_template_child (widget_class, NetConnectionEditor, details_toplevel_notebook);
+ gtk_widget_class_bind_template_callback_full (widget_class, "delete_event_cb", G_CALLBACK
(cancel_editing));
+ gtk_widget_class_bind_template_callback_full (widget_class, "cancel_clicked_cb", G_CALLBACK
(cancel_editing));
+ gtk_widget_class_bind_template_callback_full (widget_class, "apply_clicked_cb", G_CALLBACK
(apply_edits));
}
static void
@@ -231,8 +207,8 @@ net_connection_editor_error_dialog (NetConnectionEditor *editor,
GtkWidget *dialog;
GtkWindow *parent;
- if (gtk_widget_is_visible (editor->window))
- parent = GTK_WINDOW (editor->window);
+ if (gtk_widget_is_visible (GTK_WIDGET (editor)))
+ parent = GTK_WINDOW (editor);
else
parent = GTK_WINDOW (editor->parent_window);
@@ -304,7 +280,7 @@ net_connection_editor_update_title (NetConnectionEditor *editor)
id = g_strdup (nm_connection_get_id (editor->connection));
}
}
- gtk_window_set_title (GTK_WINDOW (editor->window), id);
+ gtk_window_set_title (GTK_WINDOW (editor), id);
g_free (id);
}
@@ -365,7 +341,7 @@ validate (NetConnectionEditor *editor)
update_sensitivity (editor);
done:
- gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (editor->builder,
"details_apply_button")), valid && editor->is_changed);
+ gtk_widget_set_sensitive (editor->details_apply_button, valid && editor->is_changed);
}
static void
@@ -394,11 +370,11 @@ recheck_initialization (NetConnectionEditor *editor)
if (!editor_is_initialized (editor))
return;
- notebook = GTK_NOTEBOOK (gtk_builder_get_object (editor->builder, "details_notebook"));
+ notebook = GTK_NOTEBOOK (editor->details_notebook);
gtk_notebook_set_current_page (notebook, 0);
if (editor->show_when_initialized)
- gtk_window_present (GTK_WINDOW (editor->window));
+ gtk_window_present (GTK_WINDOW (editor));
g_idle_add (idle_validate, editor);
}
@@ -413,7 +389,7 @@ page_initialized (CEPage *page, GError *error, NetConnectionEditor *editor)
GList *children, *l;
gint i;
- notebook = GTK_NOTEBOOK (gtk_builder_get_object (editor->builder, "details_notebook"));
+ notebook = GTK_NOTEBOOK (editor->details_notebook);
widget = ce_page_get_page (page);
position = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (page), "position"));
g_object_set_data (G_OBJECT (widget), "position", GINT_TO_POINTER (position));
@@ -513,10 +489,7 @@ net_connection_editor_set_connection (NetConnectionEditor *editor,
nm_connection_get_uuid (connection));
if (editor->is_new_connection) {
- GtkWidget *button;
-
- button = GTK_WIDGET (gtk_builder_get_object (editor->builder, "details_apply_button"));
- gtk_button_set_label (GTK_BUTTON (button), _("_Add"));
+ gtk_button_set_label (GTK_BUTTON (editor->details_apply_button), _("_Add"));
editor->is_changed = TRUE;
}
@@ -628,12 +601,12 @@ finish_add_connection (NetConnectionEditor *editor, NMConnection *connection)
GtkNotebook *notebook;
GtkBin *frame;
- frame = GTK_BIN (gtk_builder_get_object (editor->builder, "details_add_connection_frame"));
+ frame = GTK_BIN (editor->details_add_connection_frame);
gtk_widget_destroy (gtk_bin_get_child (frame));
- notebook = GTK_NOTEBOOK (gtk_builder_get_object (editor->builder, "details_toplevel_notebook"));
+ notebook = GTK_NOTEBOOK (editor->details_toplevel_notebook);
gtk_notebook_set_current_page (notebook, 0);
- gtk_widget_show (GTK_WIDGET (gtk_builder_get_object (editor->builder, "details_apply_button")));
+ gtk_widget_show (editor->details_apply_button);
if (connection)
net_connection_editor_set_connection (editor, connection);
@@ -663,7 +636,7 @@ vpn_type_activated (GtkListBox *list, GtkWidget *row, NetConnectionEditor *edito
NMSettingConnection *s_con;
if (!strcmp (service_name, "import")) {
- vpn_import (GTK_WINDOW (editor->window), vpn_import_complete, editor);
+ vpn_import (GTK_WINDOW (editor), vpn_import_complete, editor);
return;
}
@@ -768,8 +741,8 @@ net_connection_editor_add_connection (NetConnectionEditor *editor)
GtkContainer *frame;
GtkListBox *list;
- notebook = GTK_NOTEBOOK (gtk_builder_get_object (editor->builder, "details_toplevel_notebook"));
- frame = GTK_CONTAINER (gtk_builder_get_object (editor->builder, "details_add_connection_frame"));
+ notebook = GTK_NOTEBOOK (editor->details_toplevel_notebook);
+ frame = GTK_CONTAINER (editor->details_add_connection_frame);
list = GTK_LIST_BOX (gtk_list_box_new ());
gtk_list_box_set_selection_mode (list, GTK_SELECTION_NONE);
@@ -781,8 +754,8 @@ net_connection_editor_add_connection (NetConnectionEditor *editor)
gtk_container_add (frame, GTK_WIDGET (list));
gtk_notebook_set_current_page (notebook, 1);
- gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (editor->builder, "details_apply_button")));
- gtk_window_set_title (GTK_WINDOW (editor->window), _("Add VPN"));
+ gtk_widget_hide (editor->details_apply_button);
+ gtk_window_set_title (GTK_WINDOW (editor), _("Add VPN"));
}
static void
@@ -811,11 +784,14 @@ net_connection_editor_new (GtkWindow *parent_window,
{
NetConnectionEditor *editor;
- editor = g_object_new (NET_TYPE_CONNECTION_EDITOR, NULL);
+ editor = g_object_new (NET_TYPE_CONNECTION_EDITOR,
+ /* This doesn't seem to work for a template, so it is also hardcoded. */
+ "use-header-bar", 1,
+ NULL);
if (parent_window) {
editor->parent_window = GTK_WIDGET (g_object_ref (parent_window));
- gtk_window_set_transient_for (GTK_WINDOW (editor->window),
+ gtk_window_set_transient_for (GTK_WINDOW (editor),
parent_window);
}
if (ap)
@@ -837,13 +813,13 @@ net_connection_editor_new (GtkWindow *parent_window,
}
void
-net_connection_editor_present (NetConnectionEditor *editor)
+net_connection_editor_run (NetConnectionEditor *editor)
{
if (!editor_is_initialized (editor)) {
editor->show_when_initialized = TRUE;
return;
}
- gtk_window_present (GTK_WINDOW (editor->window));
+ gtk_window_present (GTK_WINDOW (editor));
}
static void
@@ -888,6 +864,6 @@ void
net_connection_editor_set_title (NetConnectionEditor *editor,
const gchar *title)
{
- gtk_window_set_title (GTK_WINDOW (editor->window), title);
+ gtk_window_set_title (GTK_WINDOW (editor), title);
editor->title_set = TRUE;
}
diff --git a/panels/network/connection-editor/net-connection-editor.h
b/panels/network/connection-editor/net-connection-editor.h
index 431edf2d4..4527b2ed6 100644
--- a/panels/network/connection-editor/net-connection-editor.h
+++ b/panels/network/connection-editor/net-connection-editor.h
@@ -41,7 +41,7 @@ typedef struct _NetConnectionEditorClass NetConnectionEditorClass;
struct _NetConnectionEditor
{
- GObject parent;
+ GtkDialog parent;
GtkWidget *parent_window;
NMClient *client;
@@ -53,8 +53,11 @@ struct _NetConnectionEditor
gboolean is_changed;
NMAccessPoint *ap;
- GtkBuilder *builder;
- GtkWidget *window;
+ GtkWidget *details_cancel_button;
+ GtkWidget *details_apply_button;
+ GtkWidget *details_notebook;
+ GtkWidget *details_add_connection_frame;
+ GtkWidget *details_toplevel_notebook;
GSList *initializing_pages;
GSList *pages;
@@ -68,7 +71,7 @@ struct _NetConnectionEditor
struct _NetConnectionEditorClass
{
- GObjectClass parent_class;
+ GtkDialogClass parent_class;
void (*done) (NetConnectionEditor *details, gboolean success);
};
@@ -82,7 +85,6 @@ NetConnectionEditor *net_connection_editor_new (GtkWindow *parent_wi
void net_connection_editor_set_title (NetConnectionEditor *editor,
const gchar *title);
void net_connection_editor_run (NetConnectionEditor *editor);
-void net_connection_editor_present (NetConnectionEditor *editor);
void net_connection_editor_forget (NetConnectionEditor *editor);
void net_connection_editor_reset (NetConnectionEditor *editor);
diff --git a/panels/network/net-device-ethernet.c b/panels/network/net-device-ethernet.c
index 816653017..f4722a693 100644
--- a/panels/network/net-device-ethernet.c
+++ b/panels/network/net-device-ethernet.c
@@ -247,7 +247,6 @@ editor_done (NetConnectionEditor *editor,
gboolean success,
NetDeviceEthernet *device)
{
- g_object_unref (editor);
device_ethernet_refresh_ui (device);
}
diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c
index 262e8122f..3c0317dd0 100644
--- a/panels/network/net-device-wifi.c
+++ b/panels/network/net-device-wifi.c
@@ -1982,14 +1982,6 @@ ap_sort (gconstpointer a, gconstpointer b, gpointer data)
return 0;
}
-static void
-editor_done (NetConnectionEditor *editor,
- gboolean success,
- NetDeviceWifi *device_wifi)
-{
- g_object_unref (editor);
-}
-
static void
show_details_for_row (GtkButton *button, NetDeviceWifi *device_wifi)
{
@@ -2010,7 +2002,6 @@ show_details_for_row (GtkButton *button, NetDeviceWifi *device_wifi)
device = net_device_get_nm_device (NET_DEVICE (device_wifi));
client = net_object_get_client (NET_OBJECT (device_wifi));
editor = net_connection_editor_new (GTK_WINDOW (window), connection, device, ap, client);
- g_signal_connect (editor, "done", G_CALLBACK (editor_done), device_wifi);
net_connection_editor_run (editor);
}
diff --git a/panels/network/net-vpn.c b/panels/network/net-vpn.c
index 55133f2b0..d2203b669 100644
--- a/panels/network/net-vpn.c
+++ b/panels/network/net-vpn.c
@@ -270,7 +270,6 @@ editor_done (NetConnectionEditor *editor,
gboolean success,
NetVpn *vpn)
{
- g_object_unref (editor);
net_object_refresh (NET_OBJECT (vpn));
g_object_unref (vpn);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]