[balsa/gtk4: 278/294] Various: Use libbalsa-file-chooser-button functions
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/gtk4: 278/294] Various: Use libbalsa-file-chooser-button functions
- Date: Sun, 20 Jun 2021 23:36:44 +0000 (UTC)
commit 45a75443f273b90d487337bceaa5b44be59e4455
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Mon Dec 14 14:50:10 2020 -0500
Various: Use libbalsa-file-chooser-button functions
to replace GtkFileChooserButton
libbalsa/identity.c | 25 ++++++-------
libbalsa/server-config.c | 18 +++++----
src/address-book-config.c | 94 ++++++++++++++++++++++++++++++++---------------
src/filter-edit-dialog.c | 3 +-
src/folder-conf.c | 2 +
src/pref-manager.c | 47 ++++--------------------
6 files changed, 98 insertions(+), 91 deletions(-)
---
diff --git a/libbalsa/identity.c b/libbalsa/identity.c
index a1900cdaa..9dd21cccf 100644
--- a/libbalsa/identity.c
+++ b/libbalsa/identity.c
@@ -23,6 +23,7 @@
#include "identity.h"
#include "rfc3156.h"
+#include "file-chooser-button.h"
#include "libbalsa.h"
#include "information.h"
#include "libbalsa-conf.h"
@@ -1157,8 +1158,6 @@ static void
file_chooser_check_cb(GtkCheckButton * button, GtkWidget * chooser)
{
gtk_widget_set_sensitive(chooser, gtk_check_button_get_active(button));
- /* Force validation of current path, if any. */
- g_signal_emit_by_name(chooser, "file-set");
}
static void
@@ -1278,7 +1277,7 @@ file_chooser_cb(GtkWidget * chooser, gpointer data)
GtkCheckButton *check;
gboolean active;
- file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(chooser));
+ file = libbalsa_file_chooser_button_get_file(chooser);
filename = g_file_get_path(file);
g_object_unref(file);
@@ -1316,20 +1315,22 @@ ident_dialog_add_file_chooser_button(GtkWidget * grid, gint row,
gtk_check_button_new_with_mnemonic(_(path_info[type].mnemonic));
gtk_grid_attach(GTK_GRID(grid), check, 0, row, 1, 1);
- filename =
- g_build_filename(g_get_home_dir(), path_info[type].basename, NULL);
title = g_strdup_printf("Choose %s file", _(path_info[type].info));
- button = gtk_file_chooser_button_new(title,
- GTK_FILE_CHOOSER_ACTION_OPEN);
+ button = libbalsa_file_chooser_button_new(title,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ G_CALLBACK(file_chooser_cb),
+ dialog);
g_free(title);
+ filename =
+ g_build_filename(g_get_home_dir(), path_info[type].basename, NULL);
file = g_file_new_for_path(filename);
g_free(filename);
- gtk_file_chooser_set_file(GTK_FILE_CHOOSER(button), file, NULL);
+
+ libbalsa_file_chooser_button_set_file(button, file);
g_object_unref(file);
gtk_widget_set_hexpand(button, TRUE);
- gtk_widget_set_vexpand(button, TRUE);
gtk_grid_attach(GTK_GRID(grid), button, 1, row, 1, 1);
g_object_set_data(G_OBJECT(dialog), path_info[type].path_key, button);
@@ -1338,8 +1339,6 @@ ident_dialog_add_file_chooser_button(GtkWidget * grid, gint row,
GUINT_TO_POINTER(type));
g_signal_connect(check, "toggled",
G_CALLBACK(file_chooser_check_cb), button);
- g_signal_connect(button, "file-set",
- G_CALLBACK(file_chooser_cb), dialog);
}
static void
@@ -1541,7 +1540,7 @@ ident_dialog_get_path(GObject * dialog, const char * key)
if (!gtk_widget_get_sensitive(chooser))
return NULL;
- file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(chooser));
+ file = libbalsa_file_chooser_button_get_file(chooser);
path = g_file_get_path(file);
g_object_unref(file);
@@ -1921,7 +1920,7 @@ display_frame_set_path(GObject *dialog,
if (set) {
if (use_chooser) {
GFile *file = g_file_new_for_path(value);
- gtk_file_chooser_set_file(GTK_FILE_CHOOSER(chooser), file, NULL);
+ libbalsa_file_chooser_button_set_file(chooser, file);
g_object_unref(file);
} else {
gtk_editable_set_text(GTK_EDITABLE(chooser), value);
diff --git a/libbalsa/server-config.c b/libbalsa/server-config.c
index cd6ad92cd..7e4061acd 100644
--- a/libbalsa/server-config.c
+++ b/libbalsa/server-config.c
@@ -23,6 +23,7 @@
#endif /* HAVE_CONFIG_H */
#include <glib/gi18n.h>
+#include "file-chooser-button.h"
#include "misc.h"
#include "server-config.h"
@@ -160,16 +161,19 @@ libbalsa_server_cfg_new(LibBalsaServer *server, const gchar *name)
server_cfg->require_cert = server_cfg_add_check(server_cfg->advanced_grid, server_cfg->advanced_rows++,
_("Server _requires client certificate"),
libbalsa_server_get_client_cert(server), G_CALLBACK(on_server_cfg_changed), server_cfg);
- server_cfg->cert_file = gtk_file_chooser_button_new(_("Choose Client Certificate"),
GTK_FILE_CHOOSER_ACTION_OPEN);
+ server_cfg->cert_file =
+ libbalsa_file_chooser_button_new(_("Choose Client Certificate"),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ G_CALLBACK(on_server_cfg_changed),
+ server_cfg);
server_cfg_add_widget(server_cfg->advanced_grid, server_cfg->advanced_rows++, _("Certificate _File:"),
server_cfg->cert_file);
cert_file = libbalsa_server_get_cert_file(server);
if (cert_file != NULL) {
GFile *file = g_file_new_for_path(cert_file);
- gtk_file_chooser_set_file(GTK_FILE_CHOOSER(server_cfg->cert_file), file, NULL);
+ libbalsa_file_chooser_button_set_file(server_cfg->cert_file, file);
g_object_unref(file);
}
- g_signal_connect(server_cfg->cert_file, "file-set", G_CALLBACK(on_server_cfg_changed), server_cfg);
server_cfg->cert_pass = server_cfg_add_entry(server_cfg->advanced_grid, server_cfg->advanced_rows++,
_("Certificate _Pass Phrase:"),
libbalsa_server_get_cert_passphrase(server), G_CALLBACK(on_server_cfg_changed), server_cfg);
@@ -303,7 +307,7 @@ libbalsa_server_cfg_assign_server(LibBalsaServerCfg *server_cfg, LibBalsaServer
/* client certificate */
libbalsa_server_set_client_cert(server,
gtk_check_button_get_active(GTK_CHECK_BUTTON(server_cfg->require_cert)));
- file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(server_cfg->cert_file));
+ file = libbalsa_file_chooser_button_get_file(server_cfg->cert_file);
cert_file = g_file_get_path(file);
g_object_unref(file);
@@ -435,10 +439,10 @@ on_server_cfg_changed(GtkWidget *widget, LibBalsaServerCfg *server_cfg)
/* invalid configuration if a certificate is required, but no file name given */
if (sensitive) {
- GFile *file;
- gchar *cert_file;
+ GFile *file;
+ char *cert_file;
- file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(server_cfg->cert_file));
+ file = libbalsa_file_chooser_button_get_file(server_cfg->cert_file);
cert_file = g_file_get_path(file);
g_object_unref(file);
diff --git a/src/address-book-config.c b/src/address-book-config.c
index c25a294f5..9313a855a 100644
--- a/src/address-book-config.c
+++ b/src/address-book-config.c
@@ -22,9 +22,8 @@
#endif /* HAVE_CONFIG_H */
#include "address-book-config.h"
-#include <gtk/gtk.h>
-
#include "balsa-app.h"
+#include "file-chooser-button.h"
#include <glib/gi18n.h>
#if HAVE_MACOSX_DESKTOP
@@ -87,7 +86,7 @@ static GtkWidget *create_osmo_dialog(AddressBookConfig *abc);
static void help_button_cb(AddressBookConfig * abc);
static gboolean handle_close(AddressBookConfig * abc);
-static gboolean bad_path(GtkWindow * window, gint type);
+static gboolean bad_path(GtkWidget * window, gint type);
static gboolean create_book(AddressBookConfig * abc);
static void modify_book(AddressBookConfig * abc);
@@ -469,9 +468,10 @@ create_externq_dialog(AddressBookConfig * abc)
gtk_widget_set_halign(label, GTK_ALIGN_END);
gtk_grid_attach(GTK_GRID(grid), label, 0, 1, 1, 1);
abc->ab_specific.externq.load =
- gtk_file_chooser_button_new
- (_("Select load program for address book"),
- GTK_FILE_CHOOSER_ACTION_OPEN);
+ libbalsa_file_chooser_button_new(_("Select load program for address book"),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ NULL,
+ NULL);
gtk_widget_set_hexpand(abc->ab_specific.externq.load, TRUE);
gtk_grid_attach(GTK_GRID(grid), abc->ab_specific.externq.load,
1, 1, 1, 1);
@@ -482,9 +482,10 @@ create_externq_dialog(AddressBookConfig * abc)
gtk_widget_set_halign(label, GTK_ALIGN_START);
gtk_grid_attach(GTK_GRID(grid), label, 0, 2, 1, 1);
abc->ab_specific.externq.save =
- gtk_file_chooser_button_new
- (_("Select save program for address book"),
- GTK_FILE_CHOOSER_ACTION_OPEN);
+ libbalsa_file_chooser_button_new(_("Select save program for address book"),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ NULL,
+ NULL);
gtk_widget_set_hexpand(abc->ab_specific.externq.save, TRUE);
gtk_grid_attach(GTK_GRID(grid), abc->ab_specific.externq.save,
1, 2, 1, 1);
@@ -497,11 +498,11 @@ create_externq_dialog(AddressBookConfig * abc)
GFile *file;
file = g_file_new_for_path(libbalsa_address_book_externq_get_load(ab_externq));
- gtk_file_chooser_set_file(GTK_FILE_CHOOSER(GTK_FILE_CHOOSER(abc->ab_specific.externq.load)), file,
NULL);
+ libbalsa_file_chooser_button_set_file(abc->ab_specific.externq.load, file);
g_object_unref(file);
file = g_file_new_for_path(libbalsa_address_book_externq_get_save(ab_externq));
- gtk_file_chooser_set_file(GTK_FILE_CHOOSER(GTK_FILE_CHOOSER(abc->ab_specific.externq.save)), file,
NULL);
+ libbalsa_file_chooser_button_set_file(abc->ab_specific.externq.save, file);
g_object_unref(file);
}
@@ -660,14 +661,13 @@ enum {
* correct it.
*/
static gboolean
-chooser_bad_path(GtkFileChooser * chooser, GtkWindow * window, gint type)
+file_bad_path(GFile *file,
+ GtkWidget *window,
+ int type)
{
- GFile *file;
char *path;
- file = gtk_file_chooser_get_file(chooser);
path = g_file_get_path(file);
- g_object_unref(file);
if (path != NULL) {
g_free(path);
@@ -677,28 +677,62 @@ chooser_bad_path(GtkFileChooser * chooser, GtkWindow * window, gint type)
return bad_path(window, type);
}
+static gboolean
+chooser_bad_path(GtkWidget *chooser,
+ GtkWidget *window,
+ int type)
+{
+ GFile *file;
+ gboolean retval;
+
+ file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(chooser));
+ retval = file_bad_path(file, window, type);
+ g_object_unref(file);
+
+ return retval;
+}
+
+static gboolean
+button_bad_path(GtkWidget *chooser,
+ GtkWidget *window,
+ int type)
+{
+ GFile *file;
+ gboolean retval;
+
+ file = libbalsa_file_chooser_button_get_file(chooser);
+ retval = file_bad_path(file, window, type);
+ g_object_unref(file);
+
+ return retval;
+}
+
static gboolean
handle_close(AddressBookConfig * abc)
{
if (abc->type == LIBBALSA_TYPE_ADDRESS_BOOK_VCARD) {
- if (chooser_bad_path(GTK_FILE_CHOOSER(abc->window),
- GTK_WINDOW(abc->window),
- ADDRESS_BOOK_CONFIG_PATH_FILE))
+ if (chooser_bad_path(abc->window,
+ abc->window,
+ ADDRESS_BOOK_CONFIG_PATH_FILE)) {
return FALSE;
+ }
} else if (abc->type == LIBBALSA_TYPE_ADDRESS_BOOK_LDIF) {
- if (chooser_bad_path(GTK_FILE_CHOOSER(abc->window),
- GTK_WINDOW(abc->window),
- ADDRESS_BOOK_CONFIG_PATH_FILE))
+ if (chooser_bad_path(abc->window,
+ abc->window,
+ ADDRESS_BOOK_CONFIG_PATH_FILE)) {
return FALSE;
+ }
} else if (abc->type == LIBBALSA_TYPE_ADDRESS_BOOK_EXTERNQ) {
- if (chooser_bad_path(GTK_FILE_CHOOSER(abc->ab_specific.externq.load),
- GTK_WINDOW(abc->window),
- ADDRESS_BOOK_CONFIG_PATH_LOAD))
+ if (button_bad_path(abc->ab_specific.externq.load,
+ abc->window,
+ ADDRESS_BOOK_CONFIG_PATH_LOAD)) {
return FALSE;
- if (chooser_bad_path(GTK_FILE_CHOOSER(abc->ab_specific.externq.save),
- GTK_WINDOW(abc->window),
- ADDRESS_BOOK_CONFIG_PATH_SAVE))
+ }
+ if (button_bad_path(abc->ab_specific.externq.save,
+ abc->window,
+ ADDRESS_BOOK_CONFIG_PATH_SAVE)) {
return FALSE;
+ }
}
if (abc->address_book == NULL)
@@ -717,7 +751,7 @@ handle_close(AddressBookConfig * abc)
typedef struct {
GMutex lock;
GCond cond;
- GtkWindow *window;
+ GtkWidget *window;
int type;
int clicked_button;
} bad_path_data;
@@ -743,7 +777,7 @@ bad_path_idle(gpointer user_data)
bad_path_data *data = user_data;
GtkWidget *ask;
- ask = gtk_message_dialog_new(data->window,
+ ask = gtk_message_dialog_new(GTK_WINDOW(data->window),
GTK_DIALOG_MODAL|
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
@@ -761,7 +795,7 @@ bad_path_idle(gpointer user_data)
}
static gboolean
-bad_path(GtkWindow * window, int type)
+bad_path(GtkWidget * window, int type)
{
bad_path_data data;
diff --git a/src/filter-edit-dialog.c b/src/filter-edit-dialog.c
index 9b4bcc4d5..9451d8742 100644
--- a/src/filter-edit-dialog.c
+++ b/src/filter-edit-dialog.c
@@ -22,6 +22,7 @@
#endif /* HAVE_CONFIG_H */
#include "balsa-app.h"
+#include "file-chooser-button.h"
#include "filter-edit.h"
#include "filter-funcs.h"
#include "message.h"
@@ -411,7 +412,7 @@ build_action_page(GtkWindow * window)
NULL);
gtk_dialog_set_default_response(GTK_DIALOG(dialog),
GTK_RESPONSE_ACCEPT);
- fe_sound_entry = gtk_file_chooser_button_new_with_dialog(dialog);
+ fe_sound_entry = libbalsa_file_chooser_button_new_with_dialog(dialog);
gtk_widget_set_hexpand(fe_sound_entry, TRUE);
gtk_grid_attach(GTK_GRID(grid), fe_sound_entry, 1, 0, 1, 1);
/* fe_sound_entry is initially sensitive, so to be consistent
diff --git a/src/folder-conf.c b/src/folder-conf.c
index a5d8d2f4f..351b821bf 100644
--- a/src/folder-conf.c
+++ b/src/folder-conf.c
@@ -131,6 +131,8 @@ folder_conf_response_thread(gpointer user_data)
break;
/* ...or fall over */
default:
+ g_object_remove_weak_pointer(G_OBJECT(common_data->dialog),
+ (gpointer *) &common_data->dialog);
g_idle_add((GSourceFunc) gtk_window_destroy, common_data->dialog);
common_data->dialog = NULL;
g_clear_object(&common_data->store);
diff --git a/src/pref-manager.c b/src/pref-manager.c
index a2b4fa9bb..ab1a8cb8c 100644
--- a/src/pref-manager.c
+++ b/src/pref-manager.c
@@ -26,6 +26,7 @@
#include "balsa-app.h"
#include "mailbox-conf.h"
+#include "file-chooser-button.h"
#include "folder-conf.h"
#include "main-window.h"
#include "save-restore.h"
@@ -402,7 +403,7 @@ apply_prefs(GtkDialog * pbox)
update_view_defaults, NULL);
- file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(pui->mail_directory));
+ file = libbalsa_file_chooser_button_get_file(pui->mail_directory);
g_free(balsa_app.local_mail_directory);
balsa_app.local_mail_directory = g_file_get_path(file);
g_object_unref(file);
@@ -676,7 +677,7 @@ set_prefs(void)
balsa_app.send_progress_dialog);
file = g_file_new_for_path(balsa_app.local_mail_directory);
- gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(pui->mail_directory), file, NULL);
+ libbalsa_file_chooser_button_set_file(pui->mail_directory, file);
g_object_unref(file);
gtk_check_button_set_active(GTK_CHECK_BUTTON(pui->previewpane),
@@ -2058,8 +2059,10 @@ pm_grid_add_local_mail_group(GtkWidget * grid_widget)
pm_grid_attach(grid, pm_group_label(_("Local mail directory")), 0, row, 3, 1);
pui->mail_directory =
- gtk_file_chooser_button_new(_("Select your local mail directory"),
- GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
+ libbalsa_file_chooser_button_new(_("Select your local mail directory"),
+ GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
+ G_CALLBACK(properties_modified_cb),
+ property_box);
pm_grid_attach(grid, pui->mail_directory, 1, ++row, 2, 1);
pm_grid_set_next_row(grid, ++row);
@@ -3262,37 +3265,6 @@ create_display_section(GtkTreeStore * store,
* End of sections
*/
-/*
- * Idle handler for open_preferences_manager
- */
-
-static gboolean
-open_preferences_manager_idle(void)
-{
- GFile *file;
- char *name;
-
- if (pui == NULL) {
- return FALSE;
- }
-
- file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(pui->mail_directory));
- name = g_file_get_path(file);
- g_object_unref(file);
-
- if (g_strcmp0(name, balsa_app.local_mail_directory) != 0) {
- /* Chooser still hasn't been initialized. */
- g_free(name);
- return TRUE;
- }
- g_free(name);
-
- g_signal_connect(pui->mail_directory, "file-set",
- G_CALLBACK(properties_modified_cb), property_box);
-
- return FALSE;
-} /* open_preferences_manager_idle */
-
/****************
*
* Public methods
@@ -3438,11 +3410,6 @@ open_preferences_manager(GtkWidget * widget, gpointer data)
G_CALLBACK(properties_modified_cb), property_box);
#endif /* !(HAVE_GSPELL || HAVE_GTKSPELL) */
- /* Connect signal in an idle handler, after the file chooser has
- * been initialized. */
- g_idle_add_full(G_PRIORITY_LOW,
- (GSourceFunc) open_preferences_manager_idle,
- NULL, NULL);
g_signal_connect(pui->check_mail_auto, "toggled",
G_CALLBACK(timer_modified_cb), property_box);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]