[evolution-data-server/wip/mcrha/gtk4] Cover ECredentialsPrompterImplPassword
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/wip/mcrha/gtk4] Cover ECredentialsPrompterImplPassword
- Date: Fri, 15 Oct 2021 09:15:28 +0000 (UTC)
commit fc2c0b0c0ac26c179e9812b9508abc5792e206cc
Author: Milan Crha <mcrha redhat com>
Date: Fri Oct 15 11:15:06 2021 +0200
Cover ECredentialsPrompterImplPassword
.../e-credentials-prompter-impl-password.c | 109 ++++++++++++++++++++-
1 file changed, 105 insertions(+), 4 deletions(-)
---
diff --git a/src/libedataserverui/e-credentials-prompter-impl-password.c
b/src/libedataserverui/e-credentials-prompter-impl-password.c
index bb22386ee..84ec68528 100644
--- a/src/libedataserverui/e-credentials-prompter-impl-password.c
+++ b/src/libedataserverui/e-credentials-prompter-impl-password.c
@@ -196,6 +196,80 @@ credentials_prompter_impl_password_get_prompt_strings (ESourceRegistry *registry
g_free (host_name);
}
+#if GTK_CHECK_VERSION(4, 0, 0)
+typedef struct
+{
+ gint response_id;
+ GMainLoop *loop;
+} RunInfo;
+
+static void
+shutdown_loop (RunInfo *run_info)
+{
+ if (g_main_loop_is_running (run_info->loop))
+ g_main_loop_quit (run_info->loop);
+}
+
+static void
+unmap_cb (GtkDialog *dialog,
+ RunInfo *run_info)
+{
+ shutdown_loop (run_info);
+}
+
+static void
+response_cb (GtkDialog *dialog,
+ gint response_id,
+ RunInfo *run_info)
+{
+ run_info->response_id = response_id;
+ gtk_window_destroy (GTK_WINDOW (dialog));
+ shutdown_loop (run_info);
+}
+
+static gboolean
+close_requested_cb (GtkDialog *dialog,
+ RunInfo *run_info)
+{
+ shutdown_loop (run_info);
+ return GDK_EVENT_PROPAGATE;
+}
+
+static gint
+gtk_dialog_run (GtkDialog *dialog)
+{
+ RunInfo run_info;
+
+ g_signal_connect (dialog, "close-request", G_CALLBACK (close_requested_cb), &run_info);
+ g_signal_connect (dialog, "response", G_CALLBACK (response_cb), &run_info);
+ g_signal_connect (dialog, "unmap", G_CALLBACK (unmap_cb), &run_info);
+
+ run_info.response_id = GTK_RESPONSE_NONE;
+ run_info.loop = g_main_loop_new (NULL, FALSE);
+
+ if (!gtk_widget_get_visible (GTK_WIDGET (dialog)))
+ gtk_window_present (GTK_WINDOW (dialog));
+
+ g_main_loop_run (run_info.loop);
+ g_clear_pointer (&run_info.loop, g_main_loop_unref);
+
+ return run_info.response_id;
+}
+
+static const gchar *
+gtk_entry_get_text (GtkEntry *entry)
+{
+ return gtk_entry_buffer_get_text (gtk_entry_get_buffer (entry));
+}
+
+static void
+gtk_entry_set_text (GtkEntry *entry,
+ const gchar *text)
+{
+ gtk_entry_buffer_set_text (gtk_entry_get_buffer (entry), text, -1);
+}
+#endif /* GTK_CHECK_VERSION(4, 0, 0) */
+
static gboolean
e_credentials_prompter_impl_password_show_dialog (ECredentialsPrompterImplPassword *prompter_password)
{
@@ -241,23 +315,44 @@ e_credentials_prompter_impl_password_show_dialog (ECredentialsPrompterImplPasswo
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
if (dialog_parent)
gtk_window_set_transient_for (GTK_WINDOW (dialog), dialog_parent);
- gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ON_PARENT);
- gtk_container_set_border_width (GTK_CONTAINER (dialog), 12);
content_area = gtk_dialog_get_content_area (prompter_password->priv->dialog);
+ g_object_set (G_OBJECT (content_area),
+ "margin-start", 12,
+ "margin-end", 12,
+ "margin-top", 12,
+ "margin-bottom", 12,
+ NULL);
+
+#if !GTK_CHECK_VERSION(4, 0, 0)
+ gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ON_PARENT);
+ gtk_container_set_border_width (GTK_CONTAINER (content_area), 0);
+#endif
/* Override GtkDialog defaults */
gtk_box_set_spacing (GTK_BOX (content_area), 12);
- gtk_container_set_border_width (GTK_CONTAINER (content_area), 0);
grid = GTK_GRID (gtk_grid_new ());
gtk_grid_set_column_spacing (grid, 12);
gtk_grid_set_row_spacing (grid, 6);
+#if GTK_CHECK_VERSION(4, 0, 0)
+ g_object_set (G_OBJECT (grid),
+ "halign", GTK_ALIGN_FILL,
+ "valign", GTK_ALIGN_FILL,
+ NULL);
+ gtk_box_append (GTK_BOX (content_area), GTK_WIDGET (grid));
+#else
gtk_box_pack_start (GTK_BOX (content_area), GTK_WIDGET (grid), FALSE, TRUE, 0);
+#endif
/* Password Image */
+#if GTK_CHECK_VERSION(4, 0, 0)
+ widget = gtk_image_new_from_icon_name ("dialog-password");
+ gtk_image_set_pixel_size (GTK_IMAGE (widget), 48);
+#else
widget = gtk_image_new_from_icon_name ("dialog-password", GTK_ICON_SIZE_DIALOG);
+#endif
g_object_set (
G_OBJECT (widget),
"halign", GTK_ALIGN_START,
@@ -269,7 +364,11 @@ e_credentials_prompter_impl_password_show_dialog (ECredentialsPrompterImplPasswo
/* Password Label */
widget = gtk_label_new (NULL);
+#if GTK_CHECK_VERSION(4, 0, 0)
+ gtk_label_set_wrap (GTK_LABEL (widget), TRUE);
+#else
gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE);
+#endif
gtk_label_set_markup (GTK_LABEL (widget), info_markup->str);
g_object_set (
G_OBJECT (widget),
@@ -393,7 +492,9 @@ e_credentials_prompter_impl_password_show_dialog (ECredentialsPrompterImplPasswo
gtk_grid_attach (grid, widget, 1, row, 1, 1);
}
+#if !GTK_CHECK_VERSION(4, 0, 0)
gtk_widget_show_all (GTK_WIDGET (grid));
+#endif
success = gtk_dialog_run (prompter_password->priv->dialog) == GTK_RESPONSE_OK;
@@ -410,7 +511,7 @@ e_credentials_prompter_impl_password_show_dialog (ECredentialsPrompterImplPasswo
}
}
- gtk_widget_destroy (dialog);
+ g_object_unref (dialog);
prompter_password->priv->dialog = NULL;
g_string_free (info_markup, TRUE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]