[rst-commit] r126 - in /redwax-signtext/trunk/src/linux: Makefile.am config.h.in configure.ac crypto.c crypto.h main.c message.c message.h redwax-signtext.spec.in signtext.c signtext.h

rst-commit at redwax.eu rst-commit at redwax.eu
Sun May 5 13:13:26 CEST 2024


Author: minfrin at redwax.eu
Date: Sun May  5 13:13:25 2024
New Revision: 126

Log:
Add support for GTK4.

Modified:
    redwax-signtext/trunk/src/linux/Makefile.am
    redwax-signtext/trunk/src/linux/config.h.in
    redwax-signtext/trunk/src/linux/configure.ac
    redwax-signtext/trunk/src/linux/crypto.c
    redwax-signtext/trunk/src/linux/crypto.h
    redwax-signtext/trunk/src/linux/main.c
    redwax-signtext/trunk/src/linux/message.c
    redwax-signtext/trunk/src/linux/message.h
    redwax-signtext/trunk/src/linux/redwax-signtext.spec.in
    redwax-signtext/trunk/src/linux/signtext.c
    redwax-signtext/trunk/src/linux/signtext.h

Modified: redwax-signtext/trunk/src/linux/Makefile.am
==============================================================================
--- redwax-signtext/trunk/src/linux/Makefile.am	(original)
+++ redwax-signtext/trunk/src/linux/Makefile.am	Sun May  5 13:13:25 2024
@@ -12,12 +12,14 @@
 	$(AM_CPPFLAGS)
 
 redwax_signtext_native_CFLAGS = \
+	   $(ADW_CFLAGS)        \
+	   $(GIO_UNIX_CFLAGS)   \
 	   $(GLIB2_CFLAGS)      \
 	   $(GTK3_CFLAGS)	\
 	   $(GTK4_CFLAGS)	\
 	   $(JSON_GLIB_CFLAGS)	\
-	   $(GCK1_CFLAGS)	\
-	   $(GCR3_CFLAGS)	\
+	   $(GCK2_CFLAGS)	\
+	   $(GCR4_CFLAGS)	\
 	   $(KSBA_CFLAGS)	\
 	   $(GCRYPT_CFLAGS)	\
 	   $(WARN_CFLAGS)	\
@@ -27,12 +29,14 @@
 	$(AM_LDFLAGS)
 
 redwax_signtext_native_LDADD =	\
+	$(ADW_LIBS)             \
+	$(GIO_UNIX_LIBS)        \
 	$(GLIB2_LIBS)           \
 	$(GTK3_LIBS)		\
 	$(GTK4_LIBS)		\
 	$(JSON_GLIB_LIBS)	\
-	$(GCK1_LIBS)		\
-	$(GCR3_LIBS)		\
+	$(GCK2_LIBS)		\
+	$(GCR4_LIBS)		\
 	$(KSBA_LIBS)		\
 	$(GCRYPT_LIBS)		\
  	$(INTLLIBS)

Modified: redwax-signtext/trunk/src/linux/config.h.in
==============================================================================
--- redwax-signtext/trunk/src/linux/config.h.in	(original)
+++ redwax-signtext/trunk/src/linux/config.h.in	Sun May  5 13:13:25 2024
@@ -2,6 +2,9 @@
 
 /* Define to the gettext package name. */
 #undef GETTEXT_PACKAGE
+
+/* Define to 1 if you have the 'adw_entry_row_set_max_length' function. */
+#undef HAVE_ADW_ENTRY_ROW_SET_MAX_LENGTH
 
 /* Define to 1 if you have the <dlfcn.h> header file. */
 #undef HAVE_DLFCN_H

Modified: redwax-signtext/trunk/src/linux/configure.ac
==============================================================================
--- redwax-signtext/trunk/src/linux/configure.ac	(original)
+++ redwax-signtext/trunk/src/linux/configure.ac	Sun May  5 13:13:25 2024
@@ -6,22 +6,28 @@
 
 AC_PROG_CC
 
+PKG_CHECK_MODULES([ADW],
+   [libadwaita-1])
+
+PKG_CHECK_MODULES([GIO_UNIX],
+   [gio-unix-2.0])
+
 PKG_CHECK_MODULES([GLIB2],
    [glib-2.0 >= 2.66])
 
-PKG_CHECK_MODULES([GTK3],
-   [gtk+-3.0 >= 3])
-#PKG_CHECK_MODULES([GTK4],
-#   [gtk4 >= 4.4])
+#PKG_CHECK_MODULES([GTK3],
+#   [gtk+-3.0 >= 3])
+PKG_CHECK_MODULES([GTK4],
+   [gtk4 >= 4.4])
 
 PKG_CHECK_MODULES([JSON_GLIB],
    [json-glib-1.0 >= 1.4.2])
 
-PKG_CHECK_MODULES([GCK1],
-   [gck-1 >= 3])
+PKG_CHECK_MODULES([GCK2],
+   [gck-2 >= 3])
 
-PKG_CHECK_MODULES([GCR3],
-   [gcr-3 >= 3])
+PKG_CHECK_MODULES([GCR4],
+   [gcr-4 >= 3])
 
 PKG_CHECK_MODULES([GPGE],
    [gpg-error >= 1])
@@ -47,7 +53,7 @@
    ]
 )
 
-AC_CHECK_FUNCS([gtk_box_append gtk_window_set_child])
+AC_CHECK_FUNCS([gtk_box_append gtk_window_set_child adw_entry_row_set_max_length])
 
 IT_PROG_INTLTOOL([0.40.0])
 

Modified: redwax-signtext/trunk/src/linux/crypto.c
==============================================================================
--- redwax-signtext/trunk/src/linux/crypto.c	(original)
+++ redwax-signtext/trunk/src/linux/crypto.c	Sun May  5 13:13:25 2024
@@ -63,6 +63,12 @@
   return TRUE;
 }
 
+#if 0
+
+/*
+ * This needs to be ported to GTK4
+ */
+
 static gboolean
 crypto_filter_match (GObject *obj,
                     gpointer data)
@@ -154,18 +160,25 @@
   return TRUE;
 }
 
-GcrCollection *
-crypto_filter(SignTextInstance *instance, GcrCollection *certificates)
-{
-  GcrCollection *collection;
-
+GListStore *
+crypto_filter(SignTextInstance *instance, GListStore *certificates)
+{
+  GListStore *collection;
+
+#if 0
   collection = gcr_filter_collection_new_with_callback (GCR_COLLECTION (certificates),
 			crypto_filter_match,
 			instance, NULL);
+#endif
 
 
   return collection;
 }
+
+#endif
+
+
+
 
 static void
 crypto_slots_count (gpointer data, gpointer user_data)
@@ -193,6 +206,17 @@
 
 static gboolean
 crypto_chain_do (gpointer user_data);
+
+static gint
+crypto_certificate_compare (gconstpointer a, gconstpointer b, gpointer user_data)
+{
+  GcrCertificate *cert_a = GCR_CERTIFICATE ((gpointer)a);
+  GcrCertificate *cert_b = GCR_CERTIFICATE ((gpointer)b);
+  const char *c_a =  gcr_certificate_get_subject_name (cert_a);
+  const char *c_b =  gcr_certificate_get_subject_name (cert_b);
+
+  return g_strcmp0 (c_a, c_b);
+}
 
 static void
 crypto_chain_done (GObject *source_object,
@@ -233,33 +257,37 @@
 
   signtext->incoming_len++;
 
-  if (signtext->incoming_len < gcr_collection_get_length(signtext->incoming)) {
+  if (signtext->incoming_len < g_list_model_get_n_items(G_LIST_MODEL(signtext->incoming))) {
     g_idle_add((GSourceFunc)crypto_chain_do, signtext);
   }
   else {
 
-    GList *incoming, *current, *l;
-
-    incoming = gcr_collection_get_objects(signtext->incoming);
-
-    for (l = incoming; l; l = g_list_next (l)) {
-     if (!gcr_collection_contains(signtext->certificates, l->data)) {
-        g_object_ref(l->data);
-        gcr_simple_collection_add(GCR_SIMPLE_COLLECTION(signtext->certificates), l->data);
-      }
-    }
-
-    current = gcr_collection_get_objects(signtext->certificates);
-
-    for (l = current; l; l = g_list_next (l)) {
-      if (!gcr_collection_contains(signtext->incoming, l->data)) {
-        gcr_simple_collection_remove(GCR_SIMPLE_COLLECTION(signtext->certificates), l->data);
-        g_object_unref(l->data);
+    guint i;
+
+    i = 0;
+
+    while ((certificate = g_list_model_get_item (G_LIST_MODEL(signtext->incoming), i))) {
+      if (!g_list_store_find(signtext->certificates, certificate, NULL)) {
+        g_object_ref(certificate);
+        g_list_store_insert_sorted(G_LIST_STORE(signtext->certificates), certificate, crypto_certificate_compare, NULL);
+      }
+      i++;
+    }
+
+    i = 0;
+
+    while ((certificate = g_list_model_get_item (G_LIST_MODEL(signtext->certificates), i))) {
+      if (!g_list_store_find(signtext->incoming, certificate, NULL)) {
+        g_list_store_remove(signtext->certificates, i);
+        g_object_unref(certificate);
+      }
+      else {
+        i++;
       }
     }
 
     g_object_unref(signtext->incoming);
-    signtext->incoming = gcr_simple_collection_new();
+    signtext->incoming = g_list_store_new(GCR_TYPE_CERTIFICATE);
 
     g_printerr("Smartcard Summary: We scanned %u modules, in which we found %u slots with tokens, containing %u certificates, of which %u certificates had emailProtection, and %u certificates were anchored correctly.\n", signtext->modules_len, signtext->slots_len, signtext->certificates_len, signtext->chains_len, signtext->anchored_len);
 
@@ -279,21 +307,15 @@
 {
   SignTextData *signtext = user_data;
 
-  GList *incoming = gcr_collection_get_objects (signtext->incoming);
-
-  GList *current = g_list_nth (incoming, signtext->incoming_len);
-
   GcrCertificateChain *chain = gcr_certificate_chain_new();
 
 #if 0
   g_printerr("crypto_chain_do\n");
 #endif
 
-  gcr_certificate_chain_add (chain, current->data);
+  gcr_certificate_chain_add (chain, g_list_model_get_item(G_LIST_MODEL(signtext->incoming), signtext->incoming_len));
 
   gcr_certificate_chain_build_async(chain, GCR_PURPOSE_EMAIL, NULL, GCR_CERTIFICATE_CHAIN_NONE, signtext->cancellable, crypto_chain_done, signtext);
-
-  g_list_free(incoming);
 
   return FALSE;
 }
@@ -328,7 +350,7 @@
       }
     }
 
-    if (!gcr_collection_contains(signtext->incoming, l->data)) {
+    if (!g_list_store_find(signtext->incoming, l->data, NULL)) {
       g_object_ref(l->data);
 
       g_object_set_data_full(l->data, "slot",
@@ -339,11 +361,12 @@
                              gck_token_info_copy(signtext_token->token_info),
                              (GDestroyNotify)gck_token_info_free);
 
-      gcr_simple_collection_add(GCR_SIMPLE_COLLECTION(signtext->incoming), l->data);
-    }
-  }
-
-  gck_list_unref_free(incoming);
+      g_list_store_append(G_LIST_STORE(signtext->incoming), l->data);
+    }
+
+  }
+
+  g_list_free_full (g_steal_pointer (&incoming), g_object_unref);
 
   signtext->certificates_len += certificates_len;
 
@@ -440,7 +463,7 @@
   }
 
   else {
-    gck_list_unref_free(slots);
+    g_list_free_full (g_steal_pointer (&slots), g_object_unref);
   }
 
   g_timeout_add_seconds(2, crypto_slots_do, signtext);
@@ -502,10 +525,17 @@
   g_printerr("crypto_start\n");
 #endif
 
+#if 0
+volatile int done = 0;
+while (!done) sleep(1);
+/* inside gdb: set var done = 1 */
+#endif
+
   gck_modules_initialize_registered_async(signtext->cancellable, (GAsyncReadyCallback)crypto_init_done, signtext);
 }
 
-void crypto_selector_changed(GcrComboSelector *selector,
+void crypto_selector_changed(AdwComboRow *selector,
+                             GParamSpec *pspec,
                              gpointer user_data)
 {
   GObject *selected;
@@ -515,7 +545,7 @@
   g_printerr("crypto_selector_changed\n");
 #endif
 
-  selected = gcr_combo_selector_get_selected(selector);
+  selected = adw_combo_row_get_selected_item(selector);
 
   if (selected && GCR_IS_PKCS11_CERTIFICATE(selected)) {
 
@@ -527,56 +557,58 @@
 
     if (token_info) {
 
-      gboolean can_sign = FALSE;
-      gboolean can_pin = FALSE;
-
-      gtk_entry_set_max_length(instance->pin, token_info->max_pin_len);
+      instance->can_sign = FALSE;
+      instance->can_pin = FALSE;
+
+#if HAVE_ADW_ENTRY_ROW_SET_MAX_LENGTH
+      adw_entry_row_set_max_length(ADW_ENTRY_ROW(instance->pinrow), token_info->max_pin_len);
+#endif
 
       if (token_info->flags & CKF_PROTECTED_AUTHENTICATION_PATH) {
-        gtk_entry_set_icon_from_icon_name(instance->pin, GTK_ENTRY_ICON_PRIMARY, "accessories-calculator-symbolic");
-        gtk_entry_set_placeholder_text(GTK_ENTRY(instance->pin), "Use pinpad to enter PIN");
-        gtk_entry_set_text(GTK_ENTRY(instance->pin), "");
-
-        can_sign = TRUE;
-        can_pin = FALSE;
+        gtk_image_set_from_icon_name(GTK_IMAGE(instance->pinicon), "accessories-calculator-symbolic");
+        adw_preferences_row_set_title(ADW_PREFERENCES_ROW(instance->pinrow), "Use pinpad to enter PIN");
+        gtk_editable_set_text(GTK_EDITABLE(instance->pinrow), "");
+
+        instance->can_sign = TRUE;
+        instance->can_pin = FALSE;
       }
       else {
-        gtk_entry_set_icon_from_icon_name(instance->pin, GTK_ENTRY_ICON_PRIMARY, "dialog-password-symbolic");
-        gtk_entry_set_placeholder_text(GTK_ENTRY(instance->pin), "Enter your PIN");
-        gtk_entry_set_text(GTK_ENTRY(instance->pin), "");
-
-        can_sign = token_info->min_pin_len ? FALSE : TRUE;
-        can_pin = TRUE;
+        gtk_image_set_from_icon_name(GTK_IMAGE(instance->pinicon), "dialog-password-symbolic");
+        adw_preferences_row_set_title(ADW_PREFERENCES_ROW(instance->pinrow), "Enter your PIN");
+        gtk_editable_set_text(GTK_EDITABLE(instance->pinrow), "");
+
+        instance->can_sign = token_info->min_pin_len ? FALSE : TRUE;
+        instance->can_pin = TRUE;
       }
 
       if (!(token_info->flags & CKF_USER_PIN_INITIALIZED)) {
-        gtk_entry_set_icon_from_icon_name(instance->pin, GTK_ENTRY_ICON_PRIMARY, "dialog-error-symbolic");
-        gtk_entry_set_placeholder_text(GTK_ENTRY(instance->pin), "PIN is not initialised");
-
-        can_sign = FALSE;
-        can_pin = FALSE;
+        gtk_image_set_from_icon_name(GTK_IMAGE(instance->pinicon), "dialog-error-symbolic");
+        adw_preferences_row_set_title(ADW_PREFERENCES_ROW(instance->pinrow), "PIN is not initialised");
+
+        instance->can_sign = FALSE;
+        instance->can_pin = FALSE;
       }
       else if (token_info->flags & CKF_USER_PIN_LOCKED) {
-        gtk_entry_set_icon_from_icon_name(instance->pin, GTK_ENTRY_ICON_PRIMARY, "dialog-error-symbolic");
-        gtk_entry_set_placeholder_text(GTK_ENTRY(instance->pin), "PIN is locked");
-
-        can_sign = FALSE;
-        can_pin = FALSE;
+        gtk_image_set_from_icon_name(GTK_IMAGE(instance->pinicon), "dialog-error-symbolic");
+        adw_preferences_row_set_title(ADW_PREFERENCES_ROW(instance->pinrow), "PIN is locked");
+
+        instance->can_sign = FALSE;
+        instance->can_pin = FALSE;
       }
       else if (token_info->flags & CKF_USER_PIN_TO_BE_CHANGED) {
-        gtk_entry_set_icon_from_icon_name(instance->pin, GTK_ENTRY_ICON_PRIMARY, "dialog-unavailable-symbolic");
-        gtk_entry_set_placeholder_text(GTK_ENTRY(instance->pin), "PIN must be changed before use");
-
-        can_sign = FALSE;
-        can_pin = FALSE;
+        gtk_image_set_from_icon_name(GTK_IMAGE(instance->pinicon), "dialog-unavailable-symbolic");
+        adw_preferences_row_set_title(ADW_PREFERENCES_ROW(instance->pinrow), "PIN must be changed before use");
+
+        instance->can_sign = FALSE;
+        instance->can_pin = FALSE;
       }
       else if (token_info->flags & CKF_USER_PIN_FINAL_TRY) {
-        gtk_entry_set_icon_from_icon_name(instance->pin, GTK_ENTRY_ICON_PRIMARY, "dialog-warning-symbolic");
-        gtk_entry_set_placeholder_text(GTK_ENTRY(instance->pin), "Final try on PIN");
+        gtk_image_set_from_icon_name(GTK_IMAGE(instance->pinicon), "dialog-warning-symbolic");
+        adw_preferences_row_set_title(ADW_PREFERENCES_ROW(instance->pinrow), "Final try on PIN");
       }
       else if (token_info->flags & CKF_USER_PIN_COUNT_LOW) {
-        gtk_entry_set_icon_from_icon_name(instance->pin, GTK_ENTRY_ICON_PRIMARY, "dialog-warning-symbolic");
-        gtk_entry_set_placeholder_text(GTK_ENTRY(instance->pin), "PIN retries are low");
+        gtk_image_set_from_icon_name(GTK_IMAGE(instance->pinicon), "dialog-warning-symbolic");
+        adw_preferences_row_set_title(ADW_PREFERENCES_ROW(instance->pinrow), "PIN retries are low");
       }
 #if 0
       else {
@@ -584,8 +616,8 @@
       }
 #endif
 
-      gtk_widget_set_sensitive(GTK_WIDGET(instance->sign), can_sign);
-      gtk_widget_set_sensitive(GTK_WIDGET(instance->pin), can_pin);
+      gtk_widget_set_sensitive(GTK_WIDGET(instance->signtext->sign), instance->can_sign);
+      gtk_widget_set_sensitive(GTK_WIDGET(instance->pinrow), instance->can_pin);
 
     }
   }
@@ -602,7 +634,7 @@
   g_printerr("crypto_pin_changed\n");
 #endif
 
-  certificate = GCR_PKCS11_CERTIFICATE(gcr_combo_selector_get_selected(instance->selector));
+  certificate = GCR_PKCS11_CERTIFICATE(adw_combo_row_get_selected_item(instance->selectorrow));
 
   if (certificate) {
 
@@ -612,13 +644,13 @@
 
     if (token_info) {
 
-      gboolean can_sign = FALSE;
-
-      if (gtk_entry_get_text_length(instance->pin) >= token_info->min_pin_len) {
-        can_sign = TRUE;
-      }
-
-      gtk_widget_set_sensitive(GTK_WIDGET(instance->sign), can_sign);
+      instance->can_sign = FALSE;
+
+      if (adw_entry_row_get_text_length(ADW_ENTRY_ROW(instance->pinrow)) >= token_info->min_pin_len) {
+        instance->can_sign = TRUE;
+      }
+
+      gtk_widget_set_sensitive(GTK_WIDGET(instance->signtext->sign), instance->can_sign);
 
     }
 
@@ -627,13 +659,18 @@
 }
 
 void
-crypto_instance_start(SignTextInstance *instance, GcrCollection *certificates)
-{
-
-  instance->selector = gcr_combo_selector_new(certificates);
-
-  g_signal_connect(instance->selector, "changed", (GCallback)crypto_selector_changed, instance);
-  g_signal_connect(instance->pin, "changed", (GCallback)crypto_pin_changed, instance);
+crypto_instance_start(SignTextInstance *instance, GListStore *certificates)
+{
+
+#if 0
+  g_printerr("crypto_instance_start\n");
+#endif
+
+  g_signal_connect(instance->selectorrow, "notify::selected", (GCallback)crypto_selector_changed, instance);
+
+  g_signal_connect(instance->pinrow, "changed", (GCallback)crypto_pin_changed, instance);
+
+  adw_combo_row_set_model(instance->selectorrow, G_LIST_MODEL(certificates));
 
 }
 
@@ -1069,7 +1106,7 @@
     g_error_free (gerror);
   }
 
-  crypto_selector_changed(instance->selector, instance);
+  crypto_selector_changed(instance->selectorrow, NULL, instance);
 
 }
 
@@ -1099,8 +1136,8 @@
     }
     else {
 
-      const guchar *pin = (guchar *)gtk_entry_buffer_get_text(instance->pin_buffer);
-      gsize n_pin = gtk_entry_buffer_get_bytes(instance->pin_buffer);
+      const guchar *pin = (guchar *)gtk_editable_get_text(GTK_EDITABLE(instance->pinrow));
+      gsize n_pin = adw_entry_row_get_text_length(ADW_ENTRY_ROW(instance->pinrow));
 
       gck_session_login_async(instance->session, CKU_USER, pin, n_pin, instance->signtext->cancellable, crypto_find_key, instance);
 
@@ -1311,18 +1348,27 @@
  * issuer of that cert.
  */
 void
-crypto_sign(SignTextInstance *instance)
+crypto_sign(SignTextData *signtext)
 {
   GError *gerror = NULL;
   const guint8 *der;
   gsize der_len;
   gpg_error_t err;
 
+  const char *uuid = adw_view_stack_get_visible_child_name(signtext->stack);
+
+  SignTextInstance *instance = g_object_get_data(G_OBJECT (signtext->stack), uuid);
+
 #if 0
   g_printerr("crypto_sign\n");
 #endif
 
-  instance->certificate = GCR_PKCS11_CERTIFICATE(g_object_ref(gcr_combo_selector_get_selected(instance->selector)));
+  if (!instance) {
+    gerror = g_error_new(RST_CORE_ERROR, RST_CORE_ERROR_SIGN_ERROR, "No views to sign");
+    goto fatal;
+  }
+
+  instance->certificate = GCR_PKCS11_CERTIFICATE(g_object_ref(adw_combo_row_get_selected_item(instance->selectorrow)));
   if (!instance->certificate) {
     gerror = g_error_new(RST_CORE_ERROR, RST_CORE_ERROR_SIGN_ERROR, "No certificate selected");
     goto fatal;
@@ -1426,9 +1472,9 @@
   g_timeout_add(250, crypto_sign_pulse, instance->progress);
   gtk_widget_set_visible(GTK_WIDGET(instance->progress), TRUE);
 
-  gtk_widget_set_sensitive(GTK_WIDGET(instance->selector), FALSE);
-  gtk_widget_set_sensitive(GTK_WIDGET(instance->pin), FALSE);
-  gtk_widget_set_sensitive(GTK_WIDGET(instance->sign), FALSE);
+  gtk_widget_set_sensitive(GTK_WIDGET(instance->selectorrow), FALSE);
+  gtk_widget_set_sensitive(GTK_WIDGET(instance->pinrow), FALSE);
+  gtk_widget_set_sensitive(GTK_WIDGET(instance->signtext->sign), FALSE);
 
   if (gerror) {
 fatal:

Modified: redwax-signtext/trunk/src/linux/crypto.h
==============================================================================
--- redwax-signtext/trunk/src/linux/crypto.h	(original)
+++ redwax-signtext/trunk/src/linux/crypto.h	Sun May  5 13:13:25 2024
@@ -25,17 +25,17 @@
 void
 crypto_start(SignTextData *signtext);
 
-GcrCollection *
-crypto_filter(SignTextInstance *instance, GcrCollection *certificates);
+GListStore *
+crypto_filter(SignTextInstance *instance, GListStore *certificates);
 
 void
-crypto_instance_start(SignTextInstance *instance, GcrCollection *certificates);
+crypto_instance_start(SignTextInstance *instance, GListStore *certificates);
 
 gboolean
 crypto_instance_append_ca(SignTextInstance *instance, const gchar *ca, GError **gerror);
 
 void
-crypto_sign(SignTextInstance *instance);
+crypto_sign(SignTextData *signtext);
 
 void
 crypto_sign_continue(SignTextInstance *instance);

Modified: redwax-signtext/trunk/src/linux/main.c
==============================================================================
--- redwax-signtext/trunk/src/linux/main.c	(original)
+++ redwax-signtext/trunk/src/linux/main.c	Sun May  5 13:13:25 2024
@@ -15,6 +15,7 @@
  */
 
 
+#include <adwaita.h>
 
 #include <gtk/gtk.h>
 #include <gio/gunixinputstream.h>
@@ -24,6 +25,33 @@
 #include "signtext.h"
 #include "crypto.h"
 #include "message.h"
+
+
+void sign_clicked(GtkButton *button,
+                  gpointer user_data)
+{
+  SignTextData *signtext = user_data;
+
+#if 0     
+  g_printerr("sign_clicked\n");
+#endif    
+
+  crypto_sign(signtext);
+
+}       
+
+void cancel_clicked(GtkButton *button,
+                    gpointer user_data)
+{ 
+  SignTextData *signtext = user_data;
+
+#if 0   
+  g_printerr("cancel_clicked\n");
+#endif  
+  
+  message_cancel(signtext);
+     
+}
 
 /*
  * The activate signal is fired at the end of the command line handler. At this
@@ -42,34 +70,49 @@
 
   signtext->cancellable = g_cancellable_new();
 
-  signtext->stack = GTK_STACK(gtk_stack_new ());
-  gtk_widget_show (GTK_WIDGET(signtext->stack));
+  signtext->stack = ADW_VIEW_STACK(adw_view_stack_new ());
+//  gtk_widget_set_vexpand (GTK_WIDGET(signtext->stack), 1);
+  gtk_widget_set_valign (GTK_WIDGET(signtext->stack), GTK_ALIGN_FILL);
+  gtk_widget_set_visible (GTK_WIDGET(signtext->stack), 1);
 
-  signtext->switcher = GTK_STACK_SWITCHER(gtk_stack_switcher_new ());
-  gtk_stack_switcher_set_stack (signtext->switcher, signtext->stack);
-  gtk_widget_show (GTK_WIDGET(signtext->switcher));
+  signtext->switcher = ADW_VIEW_SWITCHER(adw_view_switcher_new ());
+  adw_view_switcher_set_stack (signtext->switcher, signtext->stack);
+  gtk_widget_set_visible (GTK_WIDGET(signtext->switcher), 1);
 
-  signtext->box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 6));
-#ifdef HAVE_GTK_BOX_APPEND
-  gtk_box_append (signtext->box, GTK_WIDGET(signtext->switcher));
-  gtk_box_append (signtext->box, GTK_WIDGET(signtext->stack));
-#else
-  gtk_box_pack_start (signtext->box, GTK_WIDGET(signtext->switcher), FALSE, FALSE, 0);
-  gtk_box_pack_start (signtext->box, GTK_WIDGET(signtext->stack), TRUE, TRUE, 0);
-#endif
-  gtk_widget_show (GTK_WIDGET(signtext->box));
+//  signtext->box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 6));
+//  gtk_box_append (signtext->box, GTK_WIDGET(signtext->switcher));
+//  gtk_box_append (signtext->box, GTK_WIDGET(signtext->stack));
 
-  signtext->window = gtk_application_window_new (app);
+//  gtk_widget_set_vexpand (GTK_WIDGET(signtext->box), 1);
+//  gtk_widget_set_visible (GTK_WIDGET(signtext->box), 1);
+
+//  signtext->pin = ADW_PASSWORD_ENTRY_ROW(adw_password_entry_row_new());
+
+  signtext->actionbar = GTK_ACTION_BAR(gtk_action_bar_new());
+
+  signtext->cancel = GTK_BUTTON(gtk_button_new_with_label("Cancel"));
+  gtk_widget_set_hexpand (GTK_WIDGET(signtext->cancel), 1);
+  gtk_widget_set_halign (GTK_WIDGET(signtext->cancel), GTK_ALIGN_FILL);
+  signtext->sign = GTK_BUTTON(gtk_button_new_with_label("Sign"));
+  gtk_widget_set_hexpand (GTK_WIDGET(signtext->sign), 1);
+  gtk_widget_set_halign (GTK_WIDGET(signtext->sign), GTK_ALIGN_FILL);
+  gtk_widget_set_sensitive(GTK_WIDGET(signtext->sign), FALSE);
+  
+  gtk_action_bar_pack_start (GTK_ACTION_BAR(signtext->actionbar), GTK_WIDGET(signtext->cancel));
+  gtk_action_bar_pack_end (GTK_ACTION_BAR(signtext->actionbar), GTK_WIDGET(signtext->sign));
+
+  signtext->toolbar = ADW_TOOLBAR_VIEW(adw_toolbar_view_new());
+  adw_toolbar_view_add_top_bar (ADW_TOOLBAR_VIEW(signtext->toolbar), GTK_WIDGET(signtext->switcher));
+  adw_toolbar_view_set_content (ADW_TOOLBAR_VIEW(signtext->toolbar), GTK_WIDGET(signtext->stack));
+  adw_toolbar_view_add_bottom_bar (ADW_TOOLBAR_VIEW(signtext->toolbar), GTK_WIDGET(signtext->actionbar));
+
+  signtext->window = adw_application_window_new (app);
   gtk_window_set_title (GTK_WINDOW (signtext->window), "Redwax SignText");
   gtk_window_set_default_size (GTK_WINDOW (signtext->window), -1, -1);
-#ifdef HAVE_GTK_WINDOW_SET_CHILD
-  gtk_window_set_child (GTK_WINDOW(signtext->window), GTK_WIDGET(signtext->box));
-#else
-  gtk_container_add(GTK_CONTAINER(signtext->window), GTK_WIDGET(signtext->box));
-#endif
+  adw_application_window_set_content (ADW_APPLICATION_WINDOW(signtext->window), GTK_WIDGET(signtext->toolbar));
 
-//  gtk_widget_show (GTK_WIDGET(signtext->window));
-//  gtk_widget_show_all(GTK_WIDGET(signtext->window));
+  g_signal_connect(signtext->cancel, "clicked", (GCallback)cancel_clicked, signtext);
+  g_signal_connect(signtext->sign, "clicked", (GCallback)sign_clicked, signtext);
 
   /* go fetch our smartcards */
   crypto_start(signtext);
@@ -122,12 +165,12 @@
 
 int main (int argc, char **argv)
 {
-  GtkApplication *app;
+  AdwApplication *app;
   int status;
 
   SignTextData *signtext = signtext_data_new();
 
-  app = gtk_application_new("eu.redwax.signtext", G_APPLICATION_NON_UNIQUE | G_APPLICATION_HANDLES_COMMAND_LINE);
+  app = adw_application_new("eu.redwax.signtext", G_APPLICATION_NON_UNIQUE | G_APPLICATION_HANDLES_COMMAND_LINE);
 
   g_signal_connect(app, "activate", G_CALLBACK (activate), signtext);
   g_signal_connect(app, "command-line", G_CALLBACK (command_line), signtext);

Modified: redwax-signtext/trunk/src/linux/message.c
==============================================================================
--- redwax-signtext/trunk/src/linux/message.c	(original)
+++ redwax-signtext/trunk/src/linux/message.c	Sun May  5 13:13:25 2024
@@ -16,7 +16,6 @@
 
 
 #include <gtk/gtk.h>
-#include <gtk/gtkdialog.h>
 #include <gio/gunixinputstream.h>
 #include <gio/gunixoutputstream.h>
 #include <json-glib/json-glib.h>
@@ -26,36 +25,26 @@
 #include "message.h"
 #include "config.h"
 
-void message_sign_clicked(GtkButton *button,
-                          gpointer user_data)
-{
-  SignTextInstance *instance = user_data;
-
-#if 0
-  g_printerr("message_sign_clicked\n");
-#endif
-
-  crypto_sign(instance);
-
-}
-
-void message_cancel_clicked(GtkButton *button,
-                            gpointer user_data)
-{
-  SignTextInstance *instance = user_data;
-
-#if 0
-  g_printerr("message_cancel_clicked\n");
-#endif
-
-  /*
-   * Send an error to show we cancelled.
-   */
-  message_send_error(instance, "error:userCancel");
-
-  signtext_instance_free(instance);
-
-}
+void
+message_cancel(SignTextData *signtext)
+{
+  const char *uuid = adw_view_stack_get_visible_child_name(signtext->stack);
+
+  SignTextInstance *instance = g_object_get_data(G_OBJECT (signtext->stack), uuid);
+
+  if (instance) {
+
+    /*
+     * Send an error to show we cancelled.
+     */
+    message_send_error(instance, "error:userCancel");
+
+    signtext_instance_free(instance);
+
+  }
+
+}
+
 
 /*
  * After receiving a parsed JSON message read from stdin, we end up here in the main UI
@@ -136,9 +125,15 @@
     else {
       instance = signtext_instance_new(signtext, id, uuid, uri);
 
-      instance->box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 6));
-
-      g_object_set_data_full(G_OBJECT (signtext->stack), instance->uuid, instance, (GDestroyNotify)signtext_instance_free);
+//      instance->box = GTK_LIST_BOX(gtk_list_box_new());
+//      gtk_widget_set_vexpand (GTK_WIDGET(instance->box), 1);
+
+//      g_object_set_data_full(G_OBJECT (signtext->stack), instance->uuid, instance, (GDestroyNotify)signtext_instance_free);
+
+//      adw_view_stack_add_titled(signtext->stack, GTK_WIDGET (instance->page), instance->uuid, g_uri_get_host(instance->uri));
+
+//      instance->stack = signtext->stack;
+
     }
 
     /*
@@ -169,7 +164,7 @@
      */
     else if (json_node_get_node_type(request) == JSON_NODE_OBJECT) {
 
-        GcrCollection *certificates;
+        GListStore *certificates;
 
         JsonArray *cas = json_object_get_array_member(json_node_get_object(request), "CAs");
 
@@ -185,41 +180,18 @@
 
         }
 
+#if 0
+        /* port to gtk4 */
         certificates = crypto_filter(instance, signtext->certificates);
+#endif
+
+        certificates = signtext->certificates;
 
         crypto_instance_start(instance, certificates);
  
-#ifdef HAVE_GTK_BOX_APPEND
-        gtk_box_append (instance->box, GTK_WIDGET(instance->progress));
-        gtk_box_append (instance->box, GTK_WIDGET(instance->label));
-  	gtk_box_append (instance->box, GTK_WIDGET(instance->textview));
-        gtk_box_append (instance->box, GTK_WIDGET(instance->label_agree));
-        gtk_box_append (instance->box, GTK_WIDGET(instance->selector));
-        gtk_box_append (instance->box, GTK_WIDGET(instance->pin));
-        gtk_box_append (instance->box, GTK_WIDGET(instance->buttons));
-#else
-        gtk_box_pack_start (instance->box, GTK_WIDGET(instance->progress), FALSE, FALSE, 0);
-        gtk_box_pack_start (instance->box, GTK_WIDGET(instance->label), FALSE, FALSE, 0);
-        gtk_box_pack_start (instance->box, GTK_WIDGET(instance->textview), TRUE, TRUE, 0);
-        gtk_box_pack_start (instance->box, GTK_WIDGET(instance->label_agree), FALSE, FALSE, 0);
-        gtk_box_pack_start (instance->box, GTK_WIDGET(instance->selector), FALSE, FALSE, 0);
-        gtk_box_pack_start (instance->box, GTK_WIDGET(instance->pin), FALSE, FALSE, 0);
-        gtk_box_pack_start (instance->box, GTK_WIDGET(instance->buttons), FALSE, FALSE, 0);
-#endif
-
-        gtk_stack_add_titled(signtext->stack, GTK_WIDGET (instance->box), instance->uuid, g_uri_get_host(instance->uri));
-
-        instance->stack = signtext->stack;
-
-        g_signal_connect(instance->cancel, "clicked", (GCallback)message_cancel_clicked, instance);
-        g_signal_connect(instance->sign, "clicked", (GCallback)message_sign_clicked, instance);
-
-//        gtk_widget_show_all (GTK_WIDGET(instance->box));
-
-        
-        gtk_widget_show_all(GTK_WIDGET(signtext->window));
+        gtk_widget_set_visible (GTK_WIDGET(signtext->window), 1);
+        gtk_window_present(GTK_WINDOW(signtext->window));
         gtk_widget_set_visible(GTK_WIDGET(instance->progress), FALSE);
-
 
     }
 
@@ -255,21 +227,21 @@
   }
 
   if (gerror) {
-    GtkWidget* dialog;
-
+
+    AdwDialog* dialog;
+ 
 fatal:
-
-    dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
-                                                GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
-                                                "%s", ("Redwax SignText - Error"));
-    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-                                                  ("Error: %s"),
-                                                  gerror->message);
+ 
+    dialog = adw_alert_dialog_new ("Redwax SignText - Error", NULL);
+    adw_alert_dialog_format_body (ADW_ALERT_DIALOG (dialog),
+                                           ("Error: %s"),
+                                           gerror->message);
+
+    adw_alert_dialog_add_response(ADW_ALERT_DIALOG (dialog), "Ok", "Ok");
+
+    adw_dialog_present (dialog, instance->signtext->window);
 
     g_error_free (gerror);
-
-    gtk_widget_show (dialog);
-
   }
 
 }
@@ -382,16 +354,16 @@
 
   if (gerror) {
 
-    GtkWidget* dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
-                                                GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
-                                                "%s", ("Redwax SignText - Error"));
-    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-                                                  ("Error: %s"),
-                                                  gerror->message);
+    AdwDialog* dialog;    
+ 
+    dialog = adw_alert_dialog_new ("Redwax SignText - Error", NULL);
+    adw_alert_dialog_format_body (ADW_ALERT_DIALOG (dialog),
+                                           ("Error: %s"),
+                                           gerror->message);
+  
+    adw_dialog_present (dialog, signtext->window);
 
     g_error_free (gerror);
-
-    gtk_widget_show (dialog);
 
   }
   else {

Modified: redwax-signtext/trunk/src/linux/message.h
==============================================================================
--- redwax-signtext/trunk/src/linux/message.h	(original)
+++ redwax-signtext/trunk/src/linux/message.h	Sun May  5 13:13:25 2024
@@ -23,6 +23,9 @@
 #define MESSAGE_H
 
 void
+message_cancel(SignTextData *signtext);
+
+void
 message_receive(SignTextData *signtext);
 
 //void

Modified: redwax-signtext/trunk/src/linux/redwax-signtext.spec.in
==============================================================================
--- redwax-signtext/trunk/src/linux/redwax-signtext.spec.in	(original)
+++ redwax-signtext/trunk/src/linux/redwax-signtext.spec.in	Sun May  5 13:13:25 2024
@@ -13,10 +13,12 @@
 BuildRequires: automake
 BuildRequires: libtool
 BuildRequires: intltool
+BuildRequires: pkgconfig(libadwaita-1)
+BuildRequires: pkgconfig(gio-unix-2.0)
 BuildRequires: pkgconfig(glib-2.0) >= 2.66
-BuildRequires: pkgconfig(gtk+-3.0)
+BuildRequires: pkgconfig(gtk4)
 BuildRequires: pkgconfig(json-glib-1.0)
-BuildRequires: pkgconfig(gck-1)
+BuildRequires: pkgconfig(gck-2)
 BuildRequires: pkgconfig(gpg-error)
 BuildRequires: pkgconfig(ksba)
 BuildRequires: pkgconfig(libgcrypt)

Modified: redwax-signtext/trunk/src/linux/signtext.c
==============================================================================
--- redwax-signtext/trunk/src/linux/signtext.c	(original)
+++ redwax-signtext/trunk/src/linux/signtext.c	Sun May  5 13:13:25 2024
@@ -17,6 +17,7 @@
 
 
 #include <gtk/gtk.h>
+#include <gtk/gtkbox.h>
 
 #include "signtext.h"
 
@@ -34,8 +35,8 @@
 
   memset(signtext, 0, sizeof(SignTextData));
 
-  signtext->incoming = gcr_simple_collection_new();
-  signtext->certificates = gcr_simple_collection_new();
+  signtext->incoming = g_list_store_new(GCR_TYPE_CERTIFICATE);
+  signtext->certificates = g_list_store_new(GCR_TYPE_CERTIFICATE);
 
   return signtext;
 }
@@ -45,8 +46,8 @@
   if (data) {
     if (data->incoming) g_object_unref(data->incoming);
     if (data->certificates) g_object_unref(data->certificates);
-    if (data->modules) gck_list_unref_free(data->modules);
-    if (data->slots) gck_list_unref_free(data->slots);
+    if (data->modules) g_list_free_full (g_steal_pointer (&data->modules), g_object_unref);
+    if (data->slots) g_list_free_full (g_steal_pointer (&data->slots), g_object_unref);
   }
   g_free(data);
 }
@@ -66,8 +67,56 @@
   g_free(signtext_token);
 }
 
+static char *
+get_certificate_display_name (GcrCertificate *certificate)
+{
+  GDateTime *expiry = gcr_certificate_get_expiry_date(certificate);
+  char *display;
+  char *exp = NULL;
+
+  if (expiry) {
+    exp = g_date_time_format(expiry, (const gchar*)"%d %B %Y");
+  }
+
+#if 0
+  if (exp) {
+  display = g_markup_printf_escaped ("<big>%s</big>\r<small>%s</small>\r<small>%s</small>",
+                                     gcr_certificate_get_subject_name (certificate),
+                                     gcr_certificate_get_issuer_name (certificate),
+                                     exp);
+  }
+  else {
+    display = g_markup_printf_escaped ("<big>%s</big>\r<small>%s</small>",
+                                       gcr_certificate_get_subject_name (certificate),
+                                       gcr_certificate_get_issuer_name (certificate));
+  }
+#else
+  /* workaround until https://gitlab.gnome.org/GNOME/libadwaita/-/issues/849 is fixed */
+  if (exp) {
+    display = g_strdup_printf ("%s\rIssuer: %s\rExpiry: %s", 
+                               gcr_certificate_get_subject_name (certificate),
+                               gcr_certificate_get_issuer_name (certificate),
+                               exp);
+  }
+  else {
+    display = g_strdup_printf ("%s\rIssuer: %s",
+                               gcr_certificate_get_subject_name (certificate),
+                               gcr_certificate_get_issuer_name (certificate));
+  }
+#endif
+  if (exp) {
+    g_free(exp);
+  }
+  if (expiry) {
+//    g_date_time_unref(expiry);
+  }
+  return display;
+}
+
 SignTextInstance *signtext_instance_new(SignTextData *signtext, gint64 id, const gchar *uuid, GUri *uri)
 {
+  GtkExpression *expression;
+
   SignTextInstance *instance = g_new (SignTextInstance, 1);
 
   memset(instance, 0, sizeof(SignTextInstance));
@@ -82,87 +131,99 @@
 
   instance->detached = TRUE;
 
+
+  instance->page = ADW_PREFERENCES_PAGE(adw_preferences_page_new());
+
+  instance->textgroup = ADW_PREFERENCES_GROUP(adw_preferences_group_new());
+  adw_preferences_page_add (ADW_PREFERENCES_PAGE(instance->page), ADW_PREFERENCES_GROUP(instance->textgroup));
+
+  instance->buffer = gtk_text_buffer_new (gtk_text_tag_table_new ());
+  instance->textviewrow = GTK_TEXT_VIEW (gtk_text_view_new_with_buffer(instance->buffer));
+
+  gtk_text_view_set_editable(instance->textviewrow, FALSE);
+  gtk_text_view_set_cursor_visible(instance->textviewrow, FALSE);
+  gtk_text_view_set_wrap_mode(instance->textviewrow, GTK_WRAP_WORD_CHAR);
+  gtk_widget_set_vexpand (GTK_WIDGET(instance->textviewrow), 1);
+  gtk_widget_set_valign (GTK_WIDGET(instance->textviewrow), GTK_ALIGN_FILL);
+  gtk_widget_set_visible(GTK_WIDGET(instance->textviewrow), TRUE);
+
+  instance->scrolled = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new ());
+  gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW(instance->scrolled), GTK_WIDGET(instance->textviewrow));
+
+  adw_preferences_group_add (ADW_PREFERENCES_GROUP(instance->textgroup), GTK_WIDGET(instance->scrolled));
+
+  adw_preferences_group_set_description(ADW_PREFERENCES_GROUP(instance->textgroup), g_markup_printf_escaped("The site <b>%s</b> has requested you sign the following text message.", g_uri_get_host(instance->uri)));
+
+
+
+  instance->signgroup = ADW_PREFERENCES_GROUP(adw_preferences_group_new());
+  adw_preferences_page_add (ADW_PREFERENCES_PAGE(instance->page), ADW_PREFERENCES_GROUP(instance->signgroup));
+
+  /*
+   * Work around adw combo row lack of support for pango markup in dropdowns.
+   */
+
+
+  expression = gtk_cclosure_expression_new (G_TYPE_STRING,
+                                            NULL, 0, NULL,
+                                            G_CALLBACK (get_certificate_display_name),
+                                            instance, NULL);
+
+  instance->selectorrow = ADW_COMBO_ROW(adw_combo_row_new());
+  adw_combo_row_set_expression (ADW_COMBO_ROW(instance->selectorrow), expression);
+  adw_combo_row_set_use_subtitle(ADW_COMBO_ROW(instance->selectorrow), TRUE);
+#if 0
+  /* disabled until https://gitlab.gnome.org/GNOME/libadwaita/-/issues/849 is fixed */
+  adw_preferences_row_set_use_markup(ADW_PREFERENCES_ROW(instance->selectorrow), TRUE);
+#endif
+  adw_preferences_group_add (ADW_PREFERENCES_GROUP(instance->signgroup), GTK_WIDGET(instance->selectorrow));
+
+  instance->pinrow = ADW_PASSWORD_ENTRY_ROW (adw_password_entry_row_new());
+  instance->pinicon = GTK_IMAGE(gtk_image_new());
+  adw_entry_row_add_suffix(ADW_ENTRY_ROW(instance->pinrow), GTK_WIDGET(instance->pinicon));
+  gtk_widget_set_sensitive(GTK_WIDGET(instance->pinrow), FALSE);
+  adw_preferences_group_add (ADW_PREFERENCES_GROUP(instance->signgroup), GTK_WIDGET(instance->pinrow));
+
+  adw_preferences_group_set_description(ADW_PREFERENCES_GROUP(instance->signgroup), "If you agree with the text message above, and are happy with the identity of the site, select a certificate and enter your PIN.");
+
+
   instance->progress = GTK_PROGRESS_BAR(gtk_progress_bar_new());
   gtk_widget_set_visible(GTK_WIDGET(instance->progress), FALSE);
 
-  instance->label = GTK_LABEL(gtk_label_new (NULL));
-  instance->label_text = g_markup_printf_escaped("The site <b>%s</b> has requested you sign the following text message.", g_uri_get_host(instance->uri));
-  gtk_label_set_markup(instance->label, instance->label_text);
-  gtk_label_set_justify(instance->label, GTK_JUSTIFY_LEFT);
-  gtk_label_set_line_wrap(instance->label, TRUE);
-  gtk_label_set_line_wrap_mode(instance->label, PANGO_WRAP_WORD_CHAR);
-  gtk_label_set_selectable(instance->label, TRUE);
-
-  instance->buffer = gtk_text_buffer_new (gtk_text_tag_table_new ());
-
-  instance->textview = GTK_TEXT_VIEW (gtk_text_view_new_with_buffer(instance->buffer));
-
-  gtk_text_view_set_editable(instance->textview, FALSE);
-  gtk_text_view_set_cursor_visible(instance->textview, FALSE);
-  gtk_text_view_set_wrap_mode(instance->textview, GTK_WRAP_WORD_CHAR);
-
-  instance->label_agree = GTK_LABEL(gtk_label_new (NULL));
-  gtk_label_set_markup(instance->label_agree, "If you agree with the text message above, and are happy with the identity of the site, select a certificate and enter your PIN.");
-  gtk_label_set_justify(instance->label_agree, GTK_JUSTIFY_LEFT);
-  gtk_label_set_line_wrap(instance->label_agree, TRUE);
-  gtk_label_set_line_wrap_mode(instance->label_agree, PANGO_WRAP_WORD_CHAR);
-  gtk_label_set_selectable(instance->label_agree, TRUE);
-
-  instance->pin_buffer = gcr_secure_entry_buffer_new();
-  instance->pin = GTK_ENTRY(gtk_entry_new_with_buffer(instance->pin_buffer));
-  gtk_entry_set_visibility(GTK_ENTRY(instance->pin), FALSE);
-//  gtk_entry_set_icon_from_icon_name(instance->pin, GTK_ENTRY_ICON_PRIMARY, "dialog-password-symbolic");
-
-  instance->buttons = GTK_BUTTON_BOX(gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL));
-  gtk_button_box_set_layout(instance->buttons, GTK_BUTTONBOX_EXPAND);
-  instance->cancel = GTK_BUTTON(gtk_button_new_with_label("Cancel"));
-  instance->sign = GTK_BUTTON(gtk_button_new_with_label("Sign"));
-  gtk_widget_set_sensitive(GTK_WIDGET(instance->sign), FALSE);
-
-#ifdef HAVE_GTK_BOX_APPEND
-  gtk_box_append (GTK_BOX(instance->buttons), GTK_WIDGET(instance->cancel));
-  gtk_box_append (GTK_BOX(instance->buttons), GTK_WIDGET(instance->sign));
-#else
-  gtk_box_pack_start (GTK_BOX(instance->buttons), GTK_WIDGET(instance->cancel), TRUE, TRUE, 0);
-  gtk_box_pack_start (GTK_BOX(instance->buttons), GTK_WIDGET(instance->sign), TRUE, TRUE, 0);
+
+  instance->overlay = GTK_OVERLAY(gtk_overlay_new());
+  gtk_overlay_set_child (GTK_OVERLAY(instance->overlay), GTK_WIDGET (instance->page));
+  gtk_overlay_add_overlay (GTK_OVERLAY(instance->overlay), GTK_WIDGET (instance->progress));
+
+  g_object_set_data_full(G_OBJECT (signtext->stack), instance->uuid, instance, (GDestroyNotify)signtext_instance_free);
+    
+  adw_view_stack_add_titled(signtext->stack, GTK_WIDGET (instance->overlay), instance->uuid, g_uri_get_host(instance->uri));
+
+//  instance->stack = signtext->stack;
+
+  return instance;
+}
+
+void signtext_instance_free(SignTextInstance *instance)
+{
+  if (instance) {
+
+    adw_view_stack_remove(instance->signtext->stack, GTK_WIDGET (instance->overlay));
+
+    if (!adw_view_stack_get_visible_child_name(instance->signtext->stack)) {
+
+      gtk_widget_set_visible (GTK_WIDGET(instance->signtext->window), 0);
+
+#if 0
+      gtk_widget_destroy(instance->signtext->window);
 #endif
 
-  return instance;
-}
-
-void signtext_instance_free(SignTextInstance *instance)
-{
-  if (instance) {
-
-    GList *pages;
-
-#ifdef HAVE_GTK_STACK_REMOVE
-    gtk_stack_remove(instance->signtext->stack, GTK_WIDGET (instance->box));
-#else
-    gtk_container_remove(GTK_CONTAINER(instance->stack), GTK_WIDGET(instance->box));
-#endif
+    }
 
     g_object_steal_data(G_OBJECT (instance->signtext->stack), instance->uuid);
-
-    pages = gtk_container_get_children(GTK_CONTAINER(instance->stack));
-    if (!g_list_length(pages)) {
-      gtk_widget_destroy(instance->signtext->window);
-    }
-    g_list_free(pages);
 
     if (instance->uuid) g_free(instance->uuid);
     if (instance->uri) g_uri_unref(instance->uri);
-//    if (instance->label) g_object_unref(instance->label);
-    if (instance->label_text) g_free(instance->label_text);
-//    if (instance->textview) g_object_unref(instance->textview);
-//    if (instance->label_agree) g_object_unref(instance->label_agree);
-//    if (instance->buffer) g_object_unref(instance->buffer);
-//    if (instance->pin) g_object_unref(instance->pin);
-//    if (instance->buttons) g_object_unref(instance->buttons);
-//    if (instance->cancel) g_object_unref(instance->cancel);
-//    if (instance->sign) g_object_unref(instance->sign);
-//    if (instance->box) g_object_unref(instance->box);
-//    if (instance->certificate) g_object_unref(instance->certificate);
 
     if (instance->w) {
       ksba_writer_release(instance->w);
@@ -184,22 +245,22 @@
  */
 void signtext_error(SignTextInstance *instance, GError *gerror)
 {
-  GtkWidget* dialog;
+  AdwDialog* dialog;
 
   if (instance) {
     gtk_widget_set_visible(GTK_WIDGET(instance->progress), FALSE);
 
-    gtk_widget_set_sensitive(GTK_WIDGET(instance->selector), TRUE);
-    gtk_widget_set_sensitive(GTK_WIDGET(instance->sign), TRUE);
-  }
-
-  dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
-                                   GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
-                                   "%s", ("Redwax SignText - Error"));
-  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+//    gtk_widget_set_sensitive(GTK_WIDGET(instance->selectorrow), TRUE);
+//    gtk_widget_set_sensitive(GTK_WIDGET(instance->sign), TRUE);
+  }
+
+  dialog = adw_alert_dialog_new ("Redwax SignText - Error", NULL);
+  adw_alert_dialog_format_body (ADW_ALERT_DIALOG (dialog),
                                            ("Error: %s"),
                                            gerror->message);
 
-  gtk_widget_show (dialog);
-}
-
+  adw_alert_dialog_add_response(ADW_ALERT_DIALOG (dialog), "Ok", "Ok");
+
+  adw_dialog_present (dialog, instance->signtext->window);
+}
+

Modified: redwax-signtext/trunk/src/linux/signtext.h
==============================================================================
--- redwax-signtext/trunk/src/linux/signtext.h	(original)
+++ redwax-signtext/trunk/src/linux/signtext.h	Sun May  5 13:13:25 2024
@@ -18,9 +18,10 @@
 
 #include <gtk/gtk.h>
 
+#include <adwaita.h>
+
 #define GCR_API_SUBJECT_TO_CHANGE
-#include <gcr/gcr-base.h>
-#include <ui/gcr-ui.h>
+#include <gcr/gcr.h>
 
 #include <ksba.h>
 #include <gcrypt.h>
@@ -51,14 +52,17 @@
 
 typedef struct SignTextData {
   GtkWidget *window;
+  AdwToolbarView *toolbar;
   GCancellable *cancellable;
-  GtkBox *box;
-  GtkStackSwitcher *switcher;
-  GtkStack *stack;
+  AdwViewSwitcher *switcher;
+  AdwViewStack *stack;
+  GtkActionBar *actionbar;
+  GtkButton *cancel;
+  GtkButton *sign;
   GList *modules;
   GList *slots;
-  GcrCollection *incoming;
-  GcrCollection *certificates;
+  GListStore *incoming;
+  GListStore *certificates;
   guint modules_len;
   guint slots_len;
   guint certificates_len;
@@ -85,20 +89,18 @@
 
   GList *cas;
 
-  GtkStack *stack;
+  GtkOverlay *overlay;
   GtkProgressBar *progress;
-  GtkLabel *label;
-  gchar *label_text;
-  GtkBox *box;
+
+  AdwPreferencesPage *page;
+  AdwPreferencesGroup *textgroup;
+  GtkScrolledWindow *scrolled;
   GtkTextBuffer *buffer;
-  GtkTextView *textview;
-  GcrComboSelector *selector;
-  GtkLabel *label_agree;
-  GtkEntryBuffer *pin_buffer;
-  GtkEntry *pin;
-  GtkButtonBox *buttons;
-  GtkButton *cancel;
-  GtkButton *sign;
+  GtkTextView *textviewrow;
+  AdwPreferencesGroup *signgroup;
+  AdwComboRow *selectorrow;
+  AdwPasswordEntryRow *pinrow;
+  GtkImage *pinicon;
 
   GcrPkcs11Certificate *certificate;
   GckSession *session;
@@ -118,6 +120,10 @@
   gint state;
   gint save;
   gboolean done;
+
+  gboolean can_sign;
+  gboolean can_pin;
+
 } SignTextInstance;
 
 SignTextData *signtext_data_new();



More information about the rst-commit mailing list