[balsa/gtk4: 193/294] libinit-balsa: Build with gtk4




commit 4f0017a1599e694c54da076dfa2dd778aa9d235b
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Thu Oct 15 12:38:33 2020 -0400

    libinit-balsa: Build with gtk4

 libinit_balsa/assistant_helper.c       |  2 +-
 libinit_balsa/assistant_init.c         | 78 ++++++++++++++++++++--------------
 libinit_balsa/assistant_init.h         |  2 +-
 libinit_balsa/assistant_page_user.c    | 41 ++++++++++--------
 libinit_balsa/assistant_page_welcome.c |  2 +-
 5 files changed, 73 insertions(+), 52 deletions(-)
---
diff --git a/libinit_balsa/assistant_helper.c b/libinit_balsa/assistant_helper.c
index 7a98e423c..b75c942ab 100644
--- a/libinit_balsa/assistant_helper.c
+++ b/libinit_balsa/assistant_helper.c
@@ -77,7 +77,7 @@ balsa_init_add_grid_entry(GtkGrid * grid, guint num, const gchar * ltext,
 
         ed->controller->donemask = (ed->controller->donemask << 1) | 1;
     }
-    gtk_entry_set_text(GTK_ENTRY(e), etext);
+    gtk_editable_set_text(GTK_EDITABLE(e), etext);
     return e;
 }
 
diff --git a/libinit_balsa/assistant_init.c b/libinit_balsa/assistant_init.c
index bce6509ce..3507bc37d 100644
--- a/libinit_balsa/assistant_init.c
+++ b/libinit_balsa/assistant_init.c
@@ -5,14 +5,14 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option) 
+ * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, see <https://www.gnu.org/licenses/>.
  */
@@ -36,26 +36,46 @@
 #include "assistant_page_defclient.h"
 #include "assistant_page_finish.h"
 
+#define ASSISTANT_CALLBACK "assistant-callback"
+
+static void
+cancel_response(GtkDialog *dialog,
+                int        response_id,
+                gpointer   user_data)
+{
+    if (response_id == GTK_RESPONSE_YES) {
+        libbalsa_conf_drop_all();
+        g_application_quit(G_APPLICATION(balsa_app.application));
+    } else {
+        gtk_window_destroy(GTK_WINDOW(dialog));
+    }
+}
+
 static void
 balsa_initdruid_cancel(GtkAssistant * druid)
 {
     GtkWidget *dialog =
         gtk_message_dialog_new(GTK_WINDOW(gtk_widget_get_ancestor
-                                          (GTK_WIDGET(druid), 
+                                          (GTK_WIDGET(druid),
                                            GTK_TYPE_WINDOW)),
                                GTK_DIALOG_MODAL,
                                GTK_MESSAGE_QUESTION,
                                GTK_BUTTONS_YES_NO,
                                _("This will exit Balsa.\n"
                                  "Do you really want to do this?"));
-    GtkResponseType reply = 
-        gtk_dialog_run(GTK_DIALOG(dialog));
-    gtk_widget_destroy(dialog);
 
-    if (reply == GTK_RESPONSE_YES) {
-        libbalsa_conf_drop_all();
-        exit(0);
-    }
+    g_signal_connect(dialog, "response", G_CALLBACK(cancel_response), NULL);
+    gtk_widget_show(dialog);
+}
+
+static gboolean
+dismiss_the_druid(gpointer user_data)
+{
+    GtkWindow *druid = user_data;
+
+    gtk_window_destroy(druid);
+
+    return G_SOURCE_REMOVE;
 }
 
 static void
@@ -63,6 +83,7 @@ balsa_initdruid_apply(GtkAssistant * druid)
 {
     gchar *address_book;
     LibBalsaAddressBook *ab = NULL;
+    void (*callback)(void);
 
     address_book = g_build_filename(g_get_home_dir(), "GnomeCard.gcrd", NULL);
     if (g_file_test(address_book, G_FILE_TEST_EXISTS))
@@ -70,7 +91,7 @@ balsa_initdruid_apply(GtkAssistant * druid)
                                              address_book);
     g_free(address_book);
     if(!ab) {
-        address_book = g_build_filename(g_get_home_dir(), 
+        address_book = g_build_filename(g_get_home_dir(),
                                    ".addressbook.ldif", NULL);
         if (g_file_test(address_book, G_FILE_TEST_EXISTS))
             ab = libbalsa_address_book_ldif_new(_("Address Book"),
@@ -79,10 +100,10 @@ balsa_initdruid_apply(GtkAssistant * druid)
     }
     if(!ab) {
         /* This will be the default address book and its location */
-        address_book = g_build_filename(g_get_home_dir(), 
+        address_book = g_build_filename(g_get_home_dir(),
                                         ".balsa", "addressbook.ldif", NULL);
         ab = libbalsa_address_book_ldif_new(_("Address Book"),
-                                            address_book); 
+                                            address_book);
         g_free(address_book);
         libbalsa_assure_balsa_dir();
    }
@@ -98,7 +119,13 @@ balsa_initdruid_apply(GtkAssistant * druid)
     libbalsa_conf_set_bool("LibBalsaAddressView", TRUE);
     libbalsa_conf_pop_group();
     config_save();
-    gtk_main_quit();
+
+    /* we do not want to destroy druid immediately to avoid confusing
+       delay between the druid that left and balsa that entered. */
+    g_idle_add(dismiss_the_druid, druid);
+
+    callback = g_object_get_data(G_OBJECT(druid), ASSISTANT_CALLBACK);
+    callback();
 }
 
 static void
@@ -118,27 +145,16 @@ balsa_initdruid(GtkAssistant * assistant)
 
 
 /* The external interface code */
-static gboolean
-dismiss_the_wizard(GtkWidget *wizard)
-{
-    gtk_widget_destroy(wizard);
-    return FALSE;
-}
 
 void
-balsa_init_begin(void)
+balsa_init_begin(void (*callback)(void))
 {
     GtkWidget *assistant;
 
     assistant = gtk_assistant_new();
     gtk_window_set_title(GTK_WINDOW(assistant), _("Configure Balsa"));
 
+    g_object_set_data(G_OBJECT(assistant), ASSISTANT_CALLBACK, callback);
     balsa_initdruid(GTK_ASSISTANT(assistant));
-    gtk_widget_show_all(assistant);
-
-    gtk_main();
-
-    /* we do not want to destroy wizard immediately to avoid confusing
-       delay between the wizard that left and balsa that entered. */
-    g_idle_add((GSourceFunc)dismiss_the_wizard, assistant);
+    gtk_widget_show(assistant);
 }
diff --git a/libinit_balsa/assistant_init.h b/libinit_balsa/assistant_init.h
index bfc4a0b7f..660db4334 100644
--- a/libinit_balsa/assistant_init.h
+++ b/libinit_balsa/assistant_init.h
@@ -31,7 +31,7 @@ G_BEGIN_DECLS
  * Public methods
  */
 
-void balsa_init_begin( void );
+void balsa_init_begin(void (*callback)(void));
 
 G_END_DECLS
 
diff --git a/libinit_balsa/assistant_page_user.c b/libinit_balsa/assistant_page_user.c
index 303b4d1b8..14d2c6f72 100644
--- a/libinit_balsa/assistant_page_user.c
+++ b/libinit_balsa/assistant_page_user.c
@@ -86,10 +86,10 @@ balsa_druid_page_user_init(BalsaDruidPageUser * user,
     user->ed3.controller = &(user->econtroller);
     user->ed4.controller = &(user->econtroller);
     label = GTK_LABEL(gtk_label_new(_(header2)));
-    gtk_label_set_line_wrap(label, TRUE);
+    gtk_label_set_wrap(label, TRUE);
     gtk_widget_set_vexpand(GTK_WIDGET(label), TRUE);
     gtk_widget_set_valign(GTK_WIDGET(label), GTK_ALIGN_FILL);
-    gtk_container_add(GTK_CONTAINER(page), GTK_WIDGET(label));
+    gtk_box_append(GTK_BOX(page), GTK_WIDGET(label));
 
     grid = GTK_GRID(gtk_grid_new());
     gtk_grid_set_row_spacing(grid, 2);
@@ -98,7 +98,7 @@ balsa_druid_page_user_init(BalsaDruidPageUser * user,
 #if 0
     label = GTK_LABEL(gtk_label_new(_(header21)));
     gtk_label_set_justify(label, GTK_JUSTIFY_CENTER);
-    gtk_label_set_line_wrap(label, TRUE);
+    gtk_label_set_wrap(label, TRUE);
     gtk_grid_attach(grid, GTK_WIDGET(label), 0, 2, 0, 1,
                      GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 8, 4);
 #endif
@@ -155,7 +155,7 @@ balsa_druid_page_user_init(BalsaDruidPageUser * user,
 
     gtk_widget_set_margin_top(GTK_WIDGET(grid), 3);
     gtk_widget_set_margin_bottom(GTK_WIDGET(grid), 3);
-    gtk_container_add(GTK_CONTAINER(page), GTK_WIDGET(grid));
+    gtk_box_append(GTK_BOX(page), GTK_WIDGET(grid));
 
     user->need_set = FALSE;
 }
@@ -245,6 +245,14 @@ create_imap_mbx(const gchar *name, const gchar* host, NetClientCryptMode securit
     g_object_unref(mbnode);
 }
 
+static void
+user_next_error_response(GtkDialog *dialog,
+                         int        response_id,
+                         gpointer   user_data)
+{
+    gtk_window_destroy(GTK_WINDOW(dialog));
+}
+
 static void
 balsa_druid_page_user_next(GtkAssistant * druid, GtkWidget * page,
                            BalsaDruidPageUser * user)
@@ -254,19 +262,13 @@ balsa_druid_page_user_next(GtkAssistant * druid, GtkWidget * page,
     LibBalsaIdentity *ident;
     InternetAddress *ia;
     LibBalsaSmtpServer *smtp_server;
-    
-#if 0
-    printf("USER next ENTER %p %p\n", page, user->page);
-    if(page != user->page)
-        return;
-#endif
 
     /* incoming mail */
-    host = gtk_entry_get_text(GTK_ENTRY(user->incoming_srv));
+    host = gtk_editable_get_text(GTK_EDITABLE(user->incoming_srv));
     if(host && *host) {
         LibBalsaMailbox *mbx = NULL;
-        const gchar *login = gtk_entry_get_text(GTK_ENTRY(user->login));
-        const gchar *passwd = gtk_entry_get_text(GTK_ENTRY(user->passwd));
+        const gchar *login = gtk_editable_get_text(GTK_EDITABLE(user->login));
+        const gchar *passwd = gtk_editable_get_text(GTK_EDITABLE(user->passwd));
         NetClientCryptMode security = balsa_option_get_active(user->security) + NET_CLIENT_CRYPT_ENCRYPTED;
         gboolean remember = 
             balsa_option_get_active(user->remember_passwd) == 0;
@@ -285,7 +287,7 @@ balsa_druid_page_user_next(GtkAssistant * druid, GtkWidget * page,
 
     /* identity */
 
-    mailbox = gtk_entry_get_text(GTK_ENTRY(user->name));
+    mailbox = gtk_editable_get_text(GTK_EDITABLE(user->name));
     if (balsa_app.identities == NULL) {
        gchar *domain = strrchr(mailbox, '@');
         ident = LIBBALSA_IDENTITY(libbalsa_identity_new_with_name
@@ -298,7 +300,7 @@ balsa_druid_page_user_next(GtkAssistant * druid, GtkWidget * page,
         ident = balsa_app.current_ident;
     }
     
-    ia = internet_address_mailbox_new (mailbox, gtk_entry_get_text(GTK_ENTRY(user->email)));
+    ia = internet_address_mailbox_new (mailbox, gtk_editable_get_text(GTK_EDITABLE(user->email)));
     libbalsa_identity_set_address (ident, ia);
 
     /* outgoing mail */
@@ -311,7 +313,7 @@ balsa_druid_page_user_next(GtkAssistant * druid, GtkWidget * page,
        smtp_server = balsa_app.smtp_servers->data;
     }
     libbalsa_server_set_host(LIBBALSA_SERVER(smtp_server),
-                             gtk_entry_get_text(GTK_ENTRY(user->smtp)),
+                             gtk_editable_get_text(GTK_EDITABLE(user->smtp)),
                              FALSE);   // FIXME!!
 
     g_free(balsa_app.local_mail_directory);
@@ -328,9 +330,12 @@ balsa_druid_page_user_next(GtkAssistant * druid, GtkWidget * page,
                                    GTK_MESSAGE_ERROR,
                                    GTK_BUTTONS_OK,
                                    _("Local Mail Problem\n%s"), uhoh);
-        gtk_dialog_run(GTK_DIALOG(err));
-        gtk_widget_destroy(err);
+
         g_free(uhoh);
+
+        g_signal_connect(err, "response", G_CALLBACK(user_next_error_response), NULL);
+        gtk_widget_show(err);
+
         return; /* FIXME! Do not go to the next page! */
     }
 
diff --git a/libinit_balsa/assistant_page_welcome.c b/libinit_balsa/assistant_page_welcome.c
index 5e36a032b..5554e1ba3 100644
--- a/libinit_balsa/assistant_page_welcome.c
+++ b/libinit_balsa/assistant_page_welcome.c
@@ -37,7 +37,7 @@ balsa_druid_page_welcome(GtkAssistant * druid)
          "connect to the network.");
 
     page = gtk_label_new(_(text));
-    gtk_label_set_line_wrap(GTK_LABEL(page), TRUE);
+    gtk_label_set_wrap(GTK_LABEL(page), TRUE);
     
     gtk_assistant_append_page(druid, page);
     gtk_assistant_set_page_title(druid, page, _(title));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]