[NetworkManager-libreswan/lr/gtk-4.0: 5/7] editor: rework the response handling of the advanced dialog
- From: Lubomir Rintel <lkundrak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [NetworkManager-libreswan/lr/gtk-4.0: 5/7] editor: rework the response handling of the advanced dialog
- Date: Wed, 20 Oct 2021 09:43:20 +0000 (UTC)
commit 9e697f7a3a9933dbb020fb38ff913b3a0b075907
Author: Lubomir Rintel <lkundrak v3 sk>
Date: Tue Oct 19 16:35:11 2021 +0200
editor: rework the response handling of the advanced dialog
This utilizes the actions and the response callback to deal with the
dialog response and differentate between a positive and a negative
response.
It also switches to using the HeaderBar, because that's looks better and
works better with Gtk4.
properties/nm-libreswan-dialog.ui | 68 ++++++++++++++++++++++++++++++---------
properties/nm-libreswan-editor.c | 44 +++++++++++++++----------
2 files changed, 79 insertions(+), 33 deletions(-)
---
diff --git a/properties/nm-libreswan-dialog.ui b/properties/nm-libreswan-dialog.ui
index e355c08..a98d6a5 100644
--- a/properties/nm-libreswan-dialog.ui
+++ b/properties/nm-libreswan-dialog.ui
@@ -464,26 +464,15 @@
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
- <object class="GtkButton" id="apply_button">
- <property name="label">gtk-apply</property>
- <property name="use_action_appearance">False</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="margin_top">10</property>
- <property name="use_stock">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
- <property name="fill">True</property>
- <property name="pack_type">end</property>
+ <property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
@@ -885,5 +874,52 @@ config: narrowing <yes/no></property>
</child>
</object>
</child>
+ <action-widgets>
+ <action-widget response="-6">cancel_button</action-widget>
+ <action-widget response="-10">apply_button</action-widget>
+ </action-widgets>
+ <child type="titlebar">
+ <object class="GtkHeaderBar">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="show-close-button">False</property>
+ <child type="title">
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="label" translatable="yes">Advanced Properties</property>
+ <style>
+ <class name="title"/>
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="cancel_button">
+ <property name="label" translatable="yes">_Cancel</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">True</property>
+ <property name="use-underline">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton" id="apply_button">
+ <property name="label" translatable="yes">_Apply</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">True</property>
+ <property name="use-underline">True</property>
+ <style>
+ <class name="default"/>
+ <class name="suggested-action"/>
+ </style>
+ </object>
+ <packing>
+ <property name="pack-type">end</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
</object>
</interface>
diff --git a/properties/nm-libreswan-editor.c b/properties/nm-libreswan-editor.c
index e3e8397..a7ec64d 100644
--- a/properties/nm-libreswan-editor.c
+++ b/properties/nm-libreswan-editor.c
@@ -255,14 +255,27 @@ advanced_button_clicked_cb (GtkWidget *button, gpointer user_data)
LibreswanEditorPrivate *priv = LIBRESWAN_EDITOR_GET_PRIVATE (user_data);
GtkWidget *toplevel;
- if (gtk_widget_get_visible (priv->advanced_dialog))
- gtk_widget_hide (priv->advanced_dialog);
- else {
- toplevel = gtk_widget_get_toplevel (priv->widget);
- if (gtk_widget_is_toplevel (toplevel))
- gtk_window_set_transient_for (GTK_WINDOW (priv->advanced_dialog), GTK_WINDOW
(toplevel));
- gtk_widget_show_all (priv->advanced_dialog);
- }
+ toplevel = gtk_widget_get_toplevel (priv->widget);
+ if (gtk_widget_is_toplevel (toplevel))
+ gtk_window_set_transient_for (GTK_WINDOW (priv->advanced_dialog), GTK_WINDOW (toplevel));
+ gtk_widget_show_all (priv->advanced_dialog);
+}
+
+static void update_adv_settings (LibreswanEditor *self, NMSettingVpn *s_vpn);
+static void populate_adv_dialog (LibreswanEditor *self);
+
+static void
+advanced_dialog_response_cb (GtkWidget *dialog, gint response, gpointer user_data)
+{
+ LibreswanEditor *self = LIBRESWAN_EDITOR (user_data);
+ LibreswanEditorPrivate *priv = LIBRESWAN_EDITOR_GET_PRIVATE (self);
+
+ gtk_widget_hide (priv->advanced_dialog);
+
+ if (response == GTK_RESPONSE_APPLY)
+ update_adv_settings (self, priv->s_vpn);
+ else
+ populate_adv_dialog (self);
}
static GObject *
@@ -451,11 +464,10 @@ init_editor_plugin (LibreswanEditor *self,
g_signal_connect (G_OBJECT (priv->advanced_dialog), "delete-event",
G_CALLBACK (gtk_widget_hide_on_delete), self);
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "advanced_button"));
- g_return_val_if_fail (widget != NULL, FALSE);
- g_signal_connect (G_OBJECT (widget), "clicked", G_CALLBACK (advanced_button_clicked_cb), self);
+ g_signal_connect (G_OBJECT (priv->advanced_dialog), "response",
+ G_CALLBACK (advanced_dialog_response_cb), self);
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "apply_button"));
+ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "advanced_button"));
g_return_val_if_fail (widget != NULL, FALSE);
g_signal_connect (G_OBJECT (widget), "clicked", G_CALLBACK (advanced_button_clicked_cb), self);
@@ -756,11 +768,9 @@ dispose (GObject *object)
(GCallback) password_storage_changed_cb,
plugin);
- if (priv->widget)
- g_object_unref (priv->widget);
-
- if (priv->builder)
- g_object_unref (priv->builder);
+ g_clear_object (&priv->widget);
+ g_clear_object (&priv->builder);
+ g_clear_object (&priv->s_vpn);
G_OBJECT_CLASS (libreswan_editor_parent_class)->dispose (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]