Hi all,

Gtk3 3.12.0 introduced the GTK_DIALOG_USE_HEADER_BAR dialogue flag which looks, 
well, confusing at best if Balsa is used in environments like xfce.

The attached patch implements a simple way to disable the header bars by 
inspecting an environment variable.  IMO, this is a better approach than 
passing a config item downstream to all libbalsa dialogues...

Basically, a new function libbalsa_dialog_flags() is added to libbalsa.c (or 
simply expanded to 0 for older Gtk versions than 3.12.0).  When being called 
for the first time, the function checks if the environment variable 
BALSA_DIALOG_HEADERBAR exists and is set to 0.  Only in this case, the header 
bars are disabled.  The function call replaces the macro BALSA_DIALOG_FLAGS.

Note that I had to implement the same code in src/ab-main.c, as otherwise the 
linker tries to drag in a bunch of additional libraries for balsa-ab.

Opinions?

Best,
Albrecht.
diff --git a/configure.ac b/configure.ac
index eb48db3..d7a3a12 100644
--- a/configure.ac
+++ b/configure.ac
@@ -301,11 +301,6 @@ PKG_CHECK_MODULES(BALSA_AB, [
    $gnome_extras
 ])
 
-PKG_CHECK_MODULES(GTK3_12, [gtk+-3.0 >= 3.12.0],
-	[AC_DEFINE([BALSA_DIALOG_FLAGS], [GTK_DIALOG_USE_HEADER_BAR], [Create dialog with actions in header bar instead of action area])],
-	[AC_DEFINE([BALSA_DIALOG_FLAGS], [0], [])])
-
-
 AC_MSG_CHECKING(whether res_init is available)
 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <resolv.h>;]],
                                [[res_init();]])],
diff --git a/libbalsa/identity.c b/libbalsa/identity.c
index 6d8aa03..3401467 100644
--- a/libbalsa/identity.c
+++ b/libbalsa/identity.c
@@ -484,7 +484,7 @@ libbalsa_identity_select_dialog(GtkWindow * parent,
     sdi->dialog = dialog =
         gtk_dialog_new_with_buttons(prompt, parent,
                                     GTK_DIALOG_DESTROY_WITH_PARENT |
-                                    BALSA_DIALOG_FLAGS,
+									libbalsa_dialog_flags(),
                                     _("_Cancel"), GTK_RESPONSE_CANCEL,
                                     _("_OK"),     GTK_RESPONSE_OK,
                                     NULL);
@@ -1729,7 +1729,7 @@ libbalsa_identity_config_dialog(GtkWindow *parent, GList **identities,
         gtk_dialog_new_with_buttons(_("Manage Identities"),
                                     parent, /* must NOT be modal */
                                     GTK_DIALOG_DESTROY_WITH_PARENT |
-                                    BALSA_DIALOG_FLAGS,
+									libbalsa_dialog_flags(),
                                     _("_Help"),   IDENTITY_RESPONSE_HELP,
                                     _("_New"),    IDENTITY_RESPONSE_NEW,
                                     _("_Remove"), IDENTITY_RESPONSE_REMOVE,
diff --git a/libbalsa/libbalsa-gpgme-cb.c b/libbalsa/libbalsa-gpgme-cb.c
index 327afab..ed36739 100644
--- a/libbalsa/libbalsa-gpgme-cb.c
+++ b/libbalsa/libbalsa-gpgme-cb.c
@@ -165,7 +165,7 @@ lb_gpgme_select_key(const gchar * user_name, lb_key_sel_md_t mode, GList * keys,
     dialog = gtk_dialog_new_with_buttons(_("Select key"),
 					 parent,
 					 GTK_DIALOG_DESTROY_WITH_PARENT |
-                                         BALSA_DIALOG_FLAGS,
+					 libbalsa_dialog_flags(),
                                          _("_OK"),     GTK_RESPONSE_OK,
                                          _("_Cancel"), GTK_RESPONSE_CANCEL,
                                          NULL);
@@ -377,7 +377,7 @@ get_passphrase_real(const gchar * uid_hint, const gchar * passphrase_info,
     /* FIXME: create dialog according to the Gnome HIG */
     dialog = gtk_dialog_new_with_buttons(_("Enter Passphrase"), parent,
 					 GTK_DIALOG_DESTROY_WITH_PARENT |
-                                         BALSA_DIALOG_FLAGS,
+					 libbalsa_dialog_flags(),
                                          _("_OK"),     GTK_RESPONSE_OK,
                                          _("_Cancel"), GTK_RESPONSE_CANCEL,
                                          NULL);
diff --git a/libbalsa/libbalsa.c b/libbalsa/libbalsa.c
index 4b4d590..cef36d7 100644
--- a/libbalsa/libbalsa.c
+++ b/libbalsa/libbalsa.c
@@ -578,7 +578,7 @@ ask_cert_real(void *data)
     dialog = gtk_dialog_new_with_buttons(_("SSL/TLS certificate"),
                                          NULL, /* FIXME: NULL parent */
                                          GTK_DIALOG_MODAL |
-                                         BALSA_DIALOG_FLAGS,
+										 libbalsa_dialog_flags(),
                                          _("_Accept Once"), 0,
                                          _("Accept&_Save"), 1,
                                          _("_Reject"), GTK_RESPONSE_CANCEL, 
@@ -960,3 +960,23 @@ libbalsa_image_error_quark(void)
         quark = g_quark_from_static_string("libbalsa-image-error-quark");
     return quark;
 }
+
+#if GTK_CHECK_VERSION(3, 12, 0)
+GtkDialogFlags
+libbalsa_dialog_flags(void)
+{
+	static GtkDialogFlags dialog_flags = GTK_DIALOG_USE_HEADER_BAR;
+	static gint check_done = 0;
+
+	if (g_atomic_int_get(&check_done) == 0) {
+		const gchar *dialog_env;
+
+		dialog_env = g_getenv("BALSA_DIALOG_HEADERBAR");
+		if ((dialog_env != NULL) && (atoi(dialog_env) == 0)) {
+			dialog_flags = (GtkDialogFlags) 0;
+		}
+		g_atomic_int_set(&check_done, 0);
+	}
+	return dialog_flags;
+}
+#endif
diff --git a/libbalsa/libbalsa.h b/libbalsa/libbalsa.h
index b43ed49..b2a18e0 100644
--- a/libbalsa/libbalsa.h
+++ b/libbalsa/libbalsa.h
@@ -208,6 +208,12 @@ enum LibBalsaImageError {
 #endif                          /* HAVE_COMPFACE */
 };
 
+#if GTK_CHECK_VERSION(3, 12, 0)
+GtkDialogFlags libbalsa_dialog_flags(void);
+#else
+#define libbalsa_dialog_flags()		(GtkDialogFlags) (0)
+#endif
+
 #if HAVE_GTKSOURCEVIEW
 GtkWidget *libbalsa_source_view_new(gboolean highlight_phrases);
 #endif                          /* HAVE_GTKSOURCEVIEW */
diff --git a/libbalsa/send.c b/libbalsa/send.c
index 559111a..0dcf9a3 100644
--- a/libbalsa/send.c
+++ b/libbalsa/send.c
@@ -254,7 +254,7 @@ ensure_send_progress_dialog(GtkWindow * parent)
     send_dialog = gtk_dialog_new_with_buttons(_("Sending Mail..."), 
                                               parent,
                                               GTK_DIALOG_DESTROY_WITH_PARENT |
-                                              BALSA_DIALOG_FLAGS,
+											  libbalsa_dialog_flags(),
                                               _("_Hide"), GTK_RESPONSE_CLOSE,
                                               NULL);
     gtk_window_set_wmclass(GTK_WINDOW(send_dialog), "send_dialog", "Balsa");
diff --git a/libbalsa/smtp-server.c b/libbalsa/smtp-server.c
index 36f2004..5c2daa2 100644
--- a/libbalsa/smtp-server.c
+++ b/libbalsa/smtp-server.c
@@ -538,7 +538,7 @@ libbalsa_smtp_server_dialog(LibBalsaSmtpServer * smtp_server,
         gtk_dialog_new_with_buttons(_("SMTP Server"),
                                     parent,
                                     GTK_DIALOG_DESTROY_WITH_PARENT |
-                                    BALSA_DIALOG_FLAGS,
+									libbalsa_dialog_flags(),
                                     _("_OK"),     GTK_RESPONSE_OK,
                                     _("_Cancel"), GTK_RESPONSE_CANCEL,
                                     _("_Help"),   GTK_RESPONSE_HELP,
diff --git a/src/ab-main.c b/src/ab-main.c
index c66e299..9a36552 100644
--- a/src/ab-main.c
+++ b/src/ab-main.c
@@ -1047,6 +1047,26 @@ bab_set_intial_address_book(LibBalsaAddressBook * ab,
     g_action_change_state(action, g_variant_new_string(ab->name));
 }
 
+#if GTK_CHECK_VERSION(3, 12, 0)
+GtkDialogFlags
+libbalsa_dialog_flags(void)
+{
+	static GtkDialogFlags dialog_flags = GTK_DIALOG_USE_HEADER_BAR;
+	static gint check_done = 0;
+
+	if (g_atomic_int_get(&check_done) == 0) {
+		const gchar *dialog_env;
+
+		dialog_env = g_getenv("BALSA_DIALOG_HEADERBAR");
+		if ((dialog_env != NULL) && (atoi(dialog_env) == 0)) {
+			dialog_flags = (GtkDialogFlags) 0;
+		}
+		g_atomic_int_set(&check_done, 0);
+	}
+	return dialog_flags;
+}
+#endif
+
 int
 main(int argc, char *argv[])
 {
diff --git a/src/address-book-config.c b/src/address-book-config.c
index dc673f8..f9b3a53 100644
--- a/src/address-book-config.c
+++ b/src/address-book-config.c
@@ -332,7 +332,7 @@ create_generic_dialog(AddressBookConfig * abc, const gchar * type)
 
     dialog =
         gtk_dialog_new_with_buttons(title, abc->parent,
-                                    BALSA_DIALOG_FLAGS,
+        							libbalsa_dialog_flags(),
                                     _("_Help"), GTK_RESPONSE_HELP,
                                     action, GTK_RESPONSE_APPLY,
                                     _("_Cancel"), GTK_RESPONSE_CANCEL,
diff --git a/src/balsa-app.c b/src/balsa-app.c
index 2efd2bd..c282d79 100644
--- a/src/balsa-app.c
+++ b/src/balsa-app.c
@@ -88,7 +88,7 @@ ask_password_real(LibBalsaServer * server, LibBalsaMailbox * mbox)
     dialog = gtk_dialog_new_with_buttons(_("Password needed"),
                                          GTK_WINDOW(balsa_app.main_window),
                                          GTK_DIALOG_DESTROY_WITH_PARENT |
-                                         BALSA_DIALOG_FLAGS,
+										 libbalsa_dialog_flags(),
                                          _("_OK"), GTK_RESPONSE_OK,
                                          _("_Cancel"), GTK_RESPONSE_CANCEL,
                                          NULL); 
diff --git a/src/balsa-index.c b/src/balsa-index.c
index b24d6ef..b41eab6 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -2640,7 +2640,7 @@ balsa_index_pipe(BalsaIndex * index)
         gtk_dialog_new_with_buttons(_("Pipe message through a program"),
                                     GTK_WINDOW(balsa_app.main_window),
                                     GTK_DIALOG_DESTROY_WITH_PARENT |
-                                    BALSA_DIALOG_FLAGS,
+									libbalsa_dialog_flags(),
                                     _("_Run"), GTK_RESPONSE_OK,
                                     _("_Cancel"), GTK_RESPONSE_CANCEL,
                                     NULL);
diff --git a/src/balsa-mblist.c b/src/balsa-mblist.c
index 6df7ab5..94d720f 100644
--- a/src/balsa-mblist.c
+++ b/src/balsa-mblist.c
@@ -1874,7 +1874,7 @@ bmbl_mru_show_tree(GtkWidget * widget, gpointer data)
         gtk_dialog_new_with_buttons(_("Choose destination folder"),
                                     mru->window,
                                     GTK_DIALOG_MODAL |
-                                    BALSA_DIALOG_FLAGS,
+									libbalsa_dialog_flags(),
                                     _("_Cancel"), GTK_RESPONSE_CANCEL,
                                     NULL);
 #if HAVE_MACOSX_DESKTOP
diff --git a/src/filter-edit-callbacks.c b/src/filter-edit-callbacks.c
index ec4be7b..841901e 100644
--- a/src/filter-edit-callbacks.c
+++ b/src/filter-edit-callbacks.c
@@ -1240,7 +1240,7 @@ fe_edit_condition(GtkWidget * throwaway,gpointer is_new_cnd)
             gtk_dialog_new_with_buttons("",
                                         GTK_WINDOW(fe_window),
                                         GTK_DIALOG_DESTROY_WITH_PARENT |
-                                        BALSA_DIALOG_FLAGS,
+										libbalsa_dialog_flags(),
                                         _("_OK"), GTK_RESPONSE_OK,
                                         _("_Cancel"), GTK_RESPONSE_CANCEL,
                                         _("_Help"), GTK_RESPONSE_HELP,
diff --git a/src/filter-edit-dialog.c b/src/filter-edit-dialog.c
index 9f46b65..0995669 100644
--- a/src/filter-edit-dialog.c
+++ b/src/filter-edit-dialog.c
@@ -568,7 +568,7 @@ filters_edit_dialog(GtkWindow * parent)
 
     fe_window = gtk_dialog_new_with_buttons(_("Filters"),
                                             parent,
-                                            BALSA_DIALOG_FLAGS,
+											libbalsa_dialog_flags(),
                                             _("_OK"), GTK_RESPONSE_OK,
                                             _("_Cancel"), GTK_RESPONSE_CANCEL,
                                             _("_Help"), GTK_RESPONSE_HELP,
diff --git a/src/filter-export-dialog.c b/src/filter-export-dialog.c
index a57717a..36543aa 100644
--- a/src/filter-export-dialog.c
+++ b/src/filter-export-dialog.c
@@ -76,7 +76,7 @@ filters_export_dialog(GtkWindow * parent)
     fex_window =
         gtk_dialog_new_with_buttons(_("Export Filters"),
                                     parent,
-                                    BALSA_DIALOG_FLAGS,
+									libbalsa_dialog_flags(),
                                     _("_OK"), GTK_RESPONSE_OK,
                                     _("_Cancel"), GTK_RESPONSE_CANCEL,
                                     _("_Help"), GTK_RESPONSE_HELP,
diff --git a/src/folder-conf.c b/src/folder-conf.c
index 85a07ce..9877165 100644
--- a/src/folder-conf.c
+++ b/src/folder-conf.c
@@ -301,7 +301,7 @@ folder_conf_imap_node(BalsaMailboxNode *mn)
                    (_("Remote IMAP folder"),
                     GTK_WINDOW(balsa_app.main_window),
                     GTK_DIALOG_DESTROY_WITH_PARENT |
-                    BALSA_DIALOG_FLAGS,
+					libbalsa_dialog_flags(),
                     mn ? _("_Update") : _("C_reate"), GTK_RESPONSE_OK,
                     _("_Cancel"), GTK_RESPONSE_CANCEL,
                     _("_Help"), GTK_RESPONSE_HELP,
@@ -565,7 +565,7 @@ browse_button_cb(GtkWidget * widget, SubfolderDialogData * sdd)
         gtk_dialog_new_with_buttons(_("Select parent folder"),
                                     GTK_WINDOW(sdd->dialog),
                                     GTK_DIALOG_DESTROY_WITH_PARENT |
-                                    BALSA_DIALOG_FLAGS,
+									libbalsa_dialog_flags(),
                                     _("_Cancel"), GTK_RESPONSE_CANCEL,
                                     _("_Help"), GTK_RESPONSE_HELP,
                                     NULL);
@@ -651,7 +651,7 @@ folder, parent);
                     gtk_dialog_new_with_buttons(_("Question"),
                                                 GTK_WINDOW(sdd->dialog),
                                                 GTK_DIALOG_MODAL |
-                                                BALSA_DIALOG_FLAGS,
+												libbalsa_dialog_flags(),
                                                 _("Rename INBOX"),
                                                 GTK_RESPONSE_OK,
                                                 _("Cancel"),
@@ -797,7 +797,7 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
                    (_("Remote IMAP subfolder"), 
                     GTK_WINDOW(balsa_app.main_window),
                     GTK_DIALOG_DESTROY_WITH_PARENT | /* must NOT be modal */
-                    BALSA_DIALOG_FLAGS,
+					libbalsa_dialog_flags(),
                     mn ? _("_Update") : _("_Create"), GTK_RESPONSE_OK,
                     _("_Cancel"), GTK_RESPONSE_CANCEL,
                     _("_Help"), GTK_RESPONSE_HELP,
diff --git a/src/information-dialog.c b/src/information-dialog.c
index 82be3cd..19ae48f 100644
--- a/src/information-dialog.c
+++ b/src/information-dialog.c
@@ -233,7 +233,7 @@ balsa_information_list(GtkWindow *parent, LibBalsaInformationType type,
 	    gtk_dialog_new_with_buttons(_("Information - Balsa"), 
                                         parent,
                                         GTK_DIALOG_DESTROY_WITH_PARENT |
-                                        BALSA_DIALOG_FLAGS,
+										libbalsa_dialog_flags(),
                                         _("_Clear"), GTK_RESPONSE_APPLY,
                                         _("Cl_ose"), GTK_RESPONSE_CANCEL,
                                         NULL);
diff --git a/src/mailbox-conf.c b/src/mailbox-conf.c
index 85b5103..e75bf35 100644
--- a/src/mailbox-conf.c
+++ b/src/mailbox-conf.c
@@ -1152,7 +1152,7 @@ create_generic_dialog(MailboxConfWindow * mcw)
         gtk_dialog_new_with_buttons(_("Remote Mailbox Configurator"),
                                     GTK_WINDOW(balsa_app.main_window),
                                     GTK_DIALOG_DESTROY_WITH_PARENT |
-                                    BALSA_DIALOG_FLAGS,
+									libbalsa_dialog_flags(),
                                     mcw->ok_button_name, MCW_RESPONSE,
                                     _("_Close"), GTK_RESPONSE_CLOSE,
                                     NULL);
diff --git a/src/main-window.c b/src/main-window.c
index 040c665..b26b3e7 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -3260,7 +3260,7 @@ ensure_check_mail_dialog(BalsaWindow * window)
 	gtk_dialog_new_with_buttons(_("Checking Mail..."),
                                     GTK_WINDOW(window),
                                     GTK_DIALOG_DESTROY_WITH_PARENT |
-                                    BALSA_DIALOG_FLAGS,
+									libbalsa_dialog_flags(),
                                     _("_Hide"), GTK_RESPONSE_CLOSE,
                                     NULL);
 #if HAVE_MACOSX_DESKTOP
@@ -3990,7 +3990,7 @@ bw_find_real(BalsaWindow * window, BalsaIndex * bindex, gboolean again)
             gtk_dialog_new_with_buttons(_("Search mailbox"),
                                         GTK_WINDOW(window),
                                         GTK_DIALOG_DESTROY_WITH_PARENT |
-                                        BALSA_DIALOG_FLAGS,
+										libbalsa_dialog_flags(),
 					_("_Help"),   GTK_RESPONSE_HELP,
                                         _("_Close"), GTK_RESPONSE_CLOSE,
                                         NULL);
diff --git a/src/pref-manager.c b/src/pref-manager.c
index 1dec5ea..1d256d2 100644
--- a/src/pref-manager.c
+++ b/src/pref-manager.c
@@ -502,7 +502,7 @@ open_preferences_manager(GtkWidget * widget, gpointer data)
         gtk_dialog_new_with_buttons(_("Balsa Preferences"),
                                     GTK_WINDOW(active_win),
                                     GTK_DIALOG_DESTROY_WITH_PARENT |
-                                    BALSA_DIALOG_FLAGS,
+									libbalsa_dialog_flags(),
                                     _("_OK"), GTK_RESPONSE_OK,
                                     _("_Apply"), GTK_RESPONSE_APPLY,
                                     _("_Cancel"), GTK_RESPONSE_CANCEL,
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index 5f5dd9f..acc0eb0 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -1541,7 +1541,7 @@ sw_get_user_codeset(BalsaSendmsg * bsmsg, gboolean * change_type,
         gtk_dialog_new_with_buttons(_("Choose charset"),
                                     GTK_WINDOW(bsmsg->window),
                                     GTK_DIALOG_DESTROY_WITH_PARENT |
-                                    BALSA_DIALOG_FLAGS,
+									libbalsa_dialog_flags(),
                                     _("_OK"), GTK_RESPONSE_OK,
                                     _("_Cancel"), GTK_RESPONSE_CANCEL,
                                     NULL);
@@ -3334,7 +3334,7 @@ quote_parts_select_dlg(GtkTreeStore *tree_store, GtkWindow * parent)
     dialog = gtk_dialog_new_with_buttons(_("Select parts for quotation"),
 					 parent,
 					 GTK_DIALOG_DESTROY_WITH_PARENT |
-                                         BALSA_DIALOG_FLAGS,
+					 libbalsa_dialog_flags(),
 					 _("_OK"), GTK_RESPONSE_OK,
 					 _("_Cancel"), GTK_RESPONSE_CANCEL,
 					 NULL);
@@ -4979,7 +4979,7 @@ subject_not_empty(BalsaSendmsg * bsmsg)
         gtk_dialog_new_with_buttons(_("No Subject"),
                                     GTK_WINDOW(bsmsg->window),
                                     GTK_DIALOG_MODAL |
-                                    BALSA_DIALOG_FLAGS,
+									libbalsa_dialog_flags(),
                                     _("_Cancel"), GTK_RESPONSE_CANCEL,
                                     _("_Send"),   GTK_RESPONSE_OK,
                                     NULL);
diff --git a/src/store-address.c b/src/store-address.c
index 48893af..84e96b6 100644
--- a/src/store-address.c
+++ b/src/store-address.c
@@ -206,7 +206,7 @@ store_address_dialog(StoreAddressInfo * info)
         gtk_dialog_new_with_buttons(_("Store Address"),
                                     GTK_WINDOW(balsa_app.main_window),
                                     GTK_DIALOG_DESTROY_WITH_PARENT |
-                                    BALSA_DIALOG_FLAGS,
+									libbalsa_dialog_flags(),
                                     _("_Cancel"), GTK_RESPONSE_CANCEL,
                                     _("_OK"), GTK_RESPONSE_OK,
                                     NULL);
diff --git a/src/toolbar-prefs.c b/src/toolbar-prefs.c
index 233f57c..a26992c 100644
--- a/src/toolbar-prefs.c
+++ b/src/toolbar-prefs.c
@@ -138,7 +138,7 @@ customize_dialog_cb(GtkWidget * widget, gpointer data)
         gtk_dialog_new_with_buttons(_("Customize Toolbars"),
                                     GTK_WINDOW(active_window),
                                     GTK_DIALOG_DESTROY_WITH_PARENT |
-                                    BALSA_DIALOG_FLAGS,
+									libbalsa_dialog_flags(),
                                     _("_Close"), GTK_RESPONSE_CLOSE,
                                     _("_Help"),  GTK_RESPONSE_HELP,
                                     NULL);

Attachment: pgp1OHpHc8939.pgp
Description: PGP signature

_______________________________________________
balsa-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/balsa-list

Reply via email to