[evince/wip/gpoo/gtk4-rebase-port: 32/65] shell: port EvPasswordView to gtk4
- From: Germán Poo-Caamaño <gpoo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/gpoo/gtk4-rebase-port: 32/65] shell: port EvPasswordView to gtk4
- Date: Mon, 21 Mar 2022 02:57:02 +0000 (UTC)
commit 150fa879a79071e126fec7edd32c1eae2b057e1f
Author: Qiu Wenbo <qiuwenbo kylinos com cn>
Date: Sun Aug 15 20:27:00 2021 +0800
shell: port EvPasswordView to gtk4
shell/ev-password-view.c | 63 ++++++++++++++++++++++---------------------
shell/ev-password-view.h | 4 +--
shell/evince-password-view.ui | 63 +++++++++++++++++++++++--------------------
3 files changed, 68 insertions(+), 62 deletions(-)
---
diff --git a/shell/ev-password-view.c b/shell/ev-password-view.c
index 8a467f880..ef0317fec 100644
--- a/shell/ev-password-view.c
+++ b/shell/ev-password-view.c
@@ -53,8 +53,7 @@ typedef struct {
static guint password_view_signals [LAST_SIGNAL] = { 0 };
-
-G_DEFINE_TYPE_WITH_PRIVATE (EvPasswordView, ev_password_view, GTK_TYPE_VIEWPORT)
+G_DEFINE_TYPE_WITH_PRIVATE (EvPasswordView, ev_password_view, GTK_TYPE_BOX)
static void ev_password_view_clicked_cb (GtkWidget *button,
EvPasswordView *password_view);
@@ -79,6 +78,13 @@ ev_password_view_finalize (GObject *object)
G_OBJECT_CLASS (ev_password_view_parent_class)->finalize (object);
}
+static void
+on_clicked (GtkWidget *button,
+ EvPasswordView *password_view)
+{
+ ev_password_view_ask_password (password_view);
+}
+
static void
ev_password_view_class_init (EvPasswordViewClass *class)
{
@@ -88,6 +94,10 @@ ev_password_view_class_init (EvPasswordViewClass *class)
g_object_class = G_OBJECT_CLASS (class);
widget_class = GTK_WIDGET_CLASS (class);
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/evince/ui/password-view.ui");
+ gtk_widget_class_bind_template_callback (widget_class, on_clicked);
+
password_view_signals[UNLOCK] =
g_signal_new ("unlock",
G_TYPE_FROM_CLASS (g_object_class),
@@ -114,13 +124,6 @@ ev_password_view_class_init (EvPasswordViewClass *class)
g_object_class->finalize = ev_password_view_finalize;
}
-static void
-ev_password_view_clicked_cb (GtkWidget *button,
- EvPasswordView *password_view)
-{
- ev_password_view_ask_password (password_view);
-}
-
static void
ev_password_view_init (EvPasswordView *password_view)
{
@@ -166,7 +169,7 @@ ev_password_dialog_got_response (GtkDialog *dialog,
if (response_id == GTK_RESPONSE_OK) {
g_free (priv->password);
priv->password =
- g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->password_entry)));
+ g_strdup (gtk_editable_get_text (GTK_EDITABLE (priv->password_entry)));
g_signal_emit (password_view, password_view_signals[UNLOCK], 0);
} else if (response_id == GTK_RESPONSE_CANCEL ||
@@ -175,7 +178,7 @@ ev_password_dialog_got_response (GtkDialog *dialog,
g_signal_emit (password_view, password_view_signals[CANCELLED], 0);
}
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ // gtk_widget_destroy (GTK_WIDGET (dialog));
}
static void
@@ -200,7 +203,7 @@ ev_password_dialog_entry_changed_cb (GtkEditable *editable,
{
const char *text;
- text = gtk_entry_get_text (GTK_ENTRY (editable));
+ text = gtk_editable_get_text (GTK_EDITABLE (editable));
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK,
(text != NULL && *text != '\0'));
@@ -247,8 +250,8 @@ ev_password_view_ask_password (EvPasswordView *password_view)
grid = gtk_grid_new ();
gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
- gtk_box_pack_start (GTK_BOX (message_area), grid,
- FALSE, FALSE, 0);
+ gtk_box_prepend (GTK_BOX (message_area), grid);
+
gtk_widget_set_halign (grid, GTK_ALIGN_CENTER);
gtk_widget_show (grid);
@@ -279,51 +282,50 @@ ev_password_view_ask_password (EvPasswordView *password_view)
if (ev_keyring_is_available ()) {
GtkWidget *choice;
GtkWidget *remember_box;
- GSList *group;
+ GtkWidget *group;
remember_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
- gtk_box_pack_start (GTK_BOX (message_area), remember_box,
- FALSE, FALSE, 0);
+ gtk_box_prepend (GTK_BOX (message_area), remember_box);
gtk_widget_set_halign (remember_box, GTK_ALIGN_CENTER);
- choice = gtk_radio_button_new_with_mnemonic (NULL, _("Forget password _immediately"));
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (choice),
+ choice = gtk_check_button_new_with_mnemonic (_("Forget password _immediately"));
+ gtk_check_button_set_active (GTK_CHECK_BUTTON (choice),
priv->password_save == G_PASSWORD_SAVE_NEVER);
g_object_set_data (G_OBJECT (choice), "password-save",
GINT_TO_POINTER (G_PASSWORD_SAVE_NEVER));
g_signal_connect (choice, "toggled",
G_CALLBACK (ev_password_dialog_remember_button_toggled),
password_view);
- gtk_box_pack_start (GTK_BOX (remember_box), choice, FALSE, FALSE, 0);
+ gtk_box_prepend (GTK_BOX (remember_box), choice);
- group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (choice));
- choice = gtk_radio_button_new_with_mnemonic (group, _("Remember password until you _log
out"));
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (choice),
+ group = choice;
+ choice = gtk_check_button_new_with_mnemonic (_("Remember password until you _log out"));
+ gtk_check_button_set_group (GTK_CHECK_BUTTON (choice), GTK_CHECK_BUTTON (group));
+ gtk_check_button_set_active (GTK_CHECK_BUTTON (choice),
priv->password_save == G_PASSWORD_SAVE_FOR_SESSION);
g_object_set_data (G_OBJECT (choice), "password-save",
GINT_TO_POINTER (G_PASSWORD_SAVE_FOR_SESSION));
g_signal_connect (choice, "toggled",
G_CALLBACK (ev_password_dialog_remember_button_toggled),
password_view);
- gtk_box_pack_start (GTK_BOX (remember_box), choice, FALSE, FALSE, 0);
+ gtk_box_prepend (GTK_BOX (remember_box), choice);
- group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (choice));
- choice = gtk_radio_button_new_with_mnemonic (group, _("Remember _forever"));
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (choice),
+ group = choice;
+ choice = gtk_check_button_new_with_mnemonic (_("Remember _forever"));
+ gtk_check_button_set_group (GTK_CHECK_BUTTON (choice), GTK_CHECK_BUTTON (group));
+ gtk_check_button_set_active (GTK_CHECK_BUTTON (choice),
priv->password_save == G_PASSWORD_SAVE_PERMANENTLY);
g_object_set_data (G_OBJECT (choice), "password-save",
GINT_TO_POINTER (G_PASSWORD_SAVE_PERMANENTLY));
g_signal_connect (choice, "toggled",
G_CALLBACK (ev_password_dialog_remember_button_toggled),
password_view);
- gtk_box_pack_start (GTK_BOX (remember_box), choice, FALSE, FALSE, 0);
+ gtk_box_prepend (GTK_BOX (remember_box), choice);
}
g_signal_connect (dialog, "response",
G_CALLBACK (ev_password_dialog_got_response),
password_view);
-
- gtk_widget_show_all (GTK_WIDGET (dialog));
}
const gchar *
@@ -361,4 +363,3 @@ ev_password_view_new (GtkWindow *parent)
return GTK_WIDGET (retval);
}
-
diff --git a/shell/ev-password-view.h b/shell/ev-password-view.h
index a68ff2a72..fd6518fd0 100644
--- a/shell/ev-password-view.h
+++ b/shell/ev-password-view.h
@@ -32,11 +32,11 @@ typedef struct _EvPasswordView EvPasswordView;
typedef struct _EvPasswordViewClass EvPasswordViewClass;
struct _EvPasswordView {
- GtkViewport parent_instance;
+ GtkBox parent_instance;
};
struct _EvPasswordViewClass {
- GtkViewportClass parent_class;
+ GtkBoxClass parent_class;
/* signals */
void (*unlock) (EvPasswordView *self);
diff --git a/shell/evince-password-view.ui b/shell/evince-password-view.ui
index 5afb89227..c570046a1 100644
--- a/shell/evince-password-view.ui
+++ b/shell/evince-password-view.ui
@@ -1,36 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <!-- interface-requires gtk+ 3.22 -->
- <template class="EvPasswordView" parent="GtkViewport">
- <child>
- <object class="GtkBox">
- <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
- <property name="spacing">24</property>
- <property name="halign">GTK_ALIGN_CENTER</property>
- <property name="valign">GTK_ALIGN_CENTER</property>
- <child>
- <object class="GtkImage">
- <property name="icon-name">dialog-password-symbolic</property>
- <property name="icon-size">6</property>
- </object>
- </child>
- <child>
- <object class="GtkLabel">
- <property name="label" translatable="yes">This document is locked and can only be read by
entering the correct password.</property>
- <property name="wrap">True</property>
- <property name="max-width-chars">64</property>
- <property name="wrap-mode">char</property>
- </object>
- </child>
+ <requires lib="gtk" version="4.0"/>
+ <template class="EvPasswordView" parent="GtkBox">
+ <property name="orientation">vertical</property>
+ <child type="start">
+ <object class="GtkViewport">
<child>
<object class="GtkBox">
- <property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
- <property name="halign">GTK_ALIGN_CENTER</property>
- <child>
- <object class="GtkButton">
- <property name="use-underline">True</property>
- <property name="label" translatable="yes">_Unlock Document</property>
- <signal name="clicked" handler="ev_password_view_clicked_cb" />
+ <property name="orientation">vertical</property>
+ <property name="spacing">24</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <child type="start">
+ <object class="GtkImage">
+ <property name="icon-name">dialog-password-symbolic</property>
+ <property name="icon-size">6</property>
+ </object>
+ </child>
+ <child type="start">
+ <object class="GtkLabel">
+ <property name="label" translatable="yes">This document is locked and can only be read by
entering the correct password.</property>
+ <property name="wrap">True</property>
+ <property name="max-width-chars">64</property>
+ <property name="wrap-mode">char</property>
+ </object>
+ </child>
+ <child type="start">
+ <object class="GtkBox">
+ <property name="orientation">horizontal</property>
+ <property name="halign">center</property>
+ <child>
+ <object class="GtkButton">
+ <property name="use-underline">True</property>
+ <property name="label" translatable="yes">_Unlock Document</property>
+ <signal name="clicked" handler="on_clicked" />
+ </object>
+ </child>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]