[balsa] Improve IMAP folder configuration
- From: Peter Bloomfield <peterb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa] Improve IMAP folder configuration
- Date: Sat, 11 Aug 2018 22:15:07 +0000 (UTC)
commit b821fb65cec529f52fee7757c870fb9ef131d653
Author: Albrecht Dreß <albrecht dress arcor de>
Date: Sat Aug 11 18:11:56 2018 -0400
Improve IMAP folder configuration
* src/folder-conf.c: simplify folder_conf_imap_sub_node()
which is now used only for modifying an existing folder,
not for creating a new one;
put the logic for the latter into folder_conf_add_imap_sub_cb().
Note that folder_conf_imap_sub_node() still needs some refactoring…
* src/mailbox-node.[ch]: replace empty items by separators in add_menu_entry();
export helper balsa_mailbox_node_is_imap()
indicating if a BalsaMailboxNode is on an IMAP server;
in balsa_mailbox_node_get_context_menu() remove the “Remote IMAP folder”
and show “Remote IMAP subfolder” for IMAP BalsaMailboxNodes only
* src/main-window.c: “Remote IMAP folder”, activate “Remote IMAP subfolder”
for selected IMAP BalsaMailboxNodes only
* ui/main-window.ui: remove “Remote IMAP folder” from the ui
Signed-off-by: Peter Bloomfield <PeterBloomfield bellsouth net>
src/folder-conf.c | 92 ++++++++++++++++++++++++++++++++++++++++--------------
src/mailbox-node.c | 18 ++++++++---
src/mailbox-node.h | 3 ++
src/main-window.c | 16 ++++------
ui/main-window.ui | 5 ---
5 files changed, 91 insertions(+), 43 deletions(-)
---
diff --git a/src/folder-conf.c b/src/folder-conf.c
index 167c417b1..d39b8f40d 100644
--- a/src/folder-conf.c
+++ b/src/folder-conf.c
@@ -795,15 +795,15 @@ set_ok_sensitive(GtkDialog * dialog)
void
folder_conf_imap_sub_node(BalsaMailboxNode * mn)
{
- GtkWidget *content, *grid, *button, *label, *hbox;
+ GtkWidget *grid, *button, *label, *hbox;
SubfolderDialogData *sdd;
static SubfolderDialogData *sdd_new = NULL;
guint row;
- /* Allow only one dialog per mailbox node, and one with mn == NULL
- * for creating a new subfolder. */
- sdd = mn ? g_object_get_data(G_OBJECT(mn), BALSA_FOLDER_CONF_IMAP_KEY)
- : sdd_new;
+ g_assert(mn != NULL);
+
+ /* Allow only one dialog per mailbox node */
+ sdd = g_object_get_data(G_OBJECT(mn), BALSA_FOLDER_CONF_IMAP_KEY);
if (sdd) {
gtk_window_present(GTK_WINDOW(sdd->dialog));
return;
@@ -812,7 +812,7 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
sdd = g_new(SubfolderDialogData, 1);
sdd->ok = (CommonDialogFunc) subfolder_conf_clicked_ok;
- if ((sdd->mbnode = mn)) {
+ sdd->mbnode = mn;
/* update */
if (!mn->mailbox) {
balsa_information(LIBBALSA_INFORMATION_ERROR,
@@ -823,11 +823,6 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
}
sdd->parent = mn->parent;
sdd->old_folder = mn->mailbox->name;
- } else {
- /* create */
- sdd->old_folder = NULL;
- sdd->parent = NULL;
- }
sdd->old_parent = sdd->mbnode ? sdd->mbnode->parent->dir : NULL;
sdd->dialog =
@@ -836,7 +831,7 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
GTK_WINDOW(balsa_app.main_window),
GTK_DIALOG_DESTROY_WITH_PARENT | /* must NOT be modal */
libbalsa_dialog_flags(),
- mn ? _("_Update") : _("_Create"), GTK_RESPONSE_OK,
+ _("_Update"), GTK_RESPONSE_OK,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Help"), GTK_RESPONSE_HELP,
NULL));
@@ -863,14 +858,8 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
gtk_grid_set_row_spacing(GTK_GRID(grid), 6);
gtk_grid_set_column_spacing(GTK_GRID(grid), 12);
gtk_container_set_border_width(GTK_CONTAINER(grid), 12);
- if (mn)
- content = grid;
- else {
- content = gtk_frame_new(_("Create subfolder"));
- gtk_container_add(GTK_CONTAINER(content), grid);
- }
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(sdd->dialog)),
- content, TRUE, TRUE, 0);
+ grid, TRUE, TRUE, 0);
row = 0;
/* INPUT FIELD CREATION */
@@ -904,9 +893,7 @@ folder_conf_imap_sub_node(BalsaMailboxNode * mn)
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
gtk_grid_attach(GTK_GRID(grid), hbox, 1, row, 1, 1);
- if (!mn)
- validate_sub_folder(NULL, sdd);
- else {
+ {
static const char *std_acls[] = {
"lrs", N_("read-only"),
"lrswipkxte", N_("read-write"),
@@ -1075,7 +1062,66 @@ folder_conf_add_imap_cb(GtkWidget * widget, gpointer data)
void
folder_conf_add_imap_sub_cb(GtkWidget * widget, gpointer data)
{
- folder_conf_imap_sub_node(NULL);
+ BalsaMailboxNode *mbnode = BALSA_MAILBOX_NODE(data);
+
+ if (mbnode != NULL) {
+ GtkWidget *dialog;
+ GtkWidget *grid;
+ GtkWidget *plabel;
+ GtkWidget *label;
+ GtkWidget *name_entry;
+ gint row;
+ int result;
+
+ dialog = gtk_dialog_new_with_buttons(_("Create IMAP subfolder"),
+ GTK_WINDOW(balsa_app.main_window),
+ GTK_DIALOG_DESTROY_WITH_PARENT | libbalsa_dialog_flags(),
+ _("_Create"), GTK_RESPONSE_ACCEPT,
+ _("_Cancel"), GTK_RESPONSE_REJECT,
+ NULL);
+ gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_REJECT);
+ grid = libbalsa_create_grid();
+ gtk_grid_set_row_spacing(GTK_GRID(grid), 6);
+ gtk_grid_set_column_spacing(GTK_GRID(grid), 12);
+ gtk_container_set_border_width(GTK_CONTAINER(grid), 12);
+ gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), grid, TRUE, TRUE, 0);
+
+ row = 0;
+ (void) libbalsa_create_grid_label(_("Subfolder of:"), grid, row);
+ plabel = gtk_label_new(mbnode->mailbox != NULL ? mbnode->dir : _("server (top level)"));
+ gtk_widget_set_halign(plabel, GTK_ALIGN_START);
+ gtk_widget_set_hexpand(plabel, TRUE);
+ gtk_grid_attach(GTK_GRID(grid), plabel, 1, row++, 1, 1);
+ label = libbalsa_create_grid_label(_("_Folder name:"), grid, row);
+ name_entry = libbalsa_create_grid_entry(grid, NULL, NULL, row, NULL, label);
+ gtk_widget_show_all(grid);
+
+ result = gtk_dialog_run(GTK_DIALOG(dialog));
+ if (result == GTK_RESPONSE_ACCEPT) {
+ const gchar *new_name;
+
+ new_name = gtk_entry_get_text(GTK_ENTRY(name_entry));
+ if ((mbnode->delim != 0) && (strchr(new_name, mbnode->delim) != NULL)) {
+ balsa_information(LIBBALSA_INFORMATION_ERROR,
+ _("The character “%c” is used as hierarchy separator by the server "
+ "and therefore not permitted in the folder name."),
+ mbnode->delim);
+ } else {
+ GError *err = NULL;
+
+ if (libbalsa_imap_new_subfolder(mbnode->dir, new_name, mbnode->subscribed,
mbnode->server, &err)) {
+ /* see it as server sees it: */
+ balsa_mailbox_node_rescan(mbnode);
+ } else {
+ balsa_information(LIBBALSA_INFORMATION_ERROR,
+ _("Folder creation failed. Reason: %s"),
+ err ? err->message : "unknown");
+ g_clear_error(&err);
+ }
+ }
+ }
+ gtk_widget_destroy(dialog);
+ }
}
void
diff --git a/src/mailbox-node.c b/src/mailbox-node.c
index e946d75fd..d0c9f0b00 100644
--- a/src/mailbox-node.c
+++ b/src/mailbox-node.c
@@ -916,7 +916,7 @@ add_menu_entry(GtkWidget * menu, const gchar * label, GCallback cb,
GtkWidget *menuitem;
menuitem = label ? gtk_menu_item_new_with_mnemonic(label)
- : gtk_menu_item_new();
+ : gtk_separator_menu_item_new();
if (cb)
g_signal_connect(G_OBJECT(menuitem), "activate",
@@ -1037,6 +1037,14 @@ mb_empty_trash_cb(GtkWidget * widget, BalsaMailboxNode * mbnode)
empty_trash(balsa_app.main_window);
}
+gboolean
+balsa_mailbox_node_is_imap(const BalsaMailboxNode *mbnode)
+{
+ return (mbnode != NULL) &&
+ (mbnode->server != NULL) &&
+ (strcmp(mbnode->server->protocol, "imap") == 0);
+}
+
GtkWidget *
balsa_mailbox_node_get_context_menu(BalsaMailboxNode * mbnode)
{
@@ -1060,13 +1068,13 @@ balsa_mailbox_node_get_context_menu(BalsaMailboxNode * mbnode)
G_CALLBACK(mailbox_conf_add_maildir_cb), NULL);
add_menu_entry(submenu, _("Local M_H mailbox…"),
G_CALLBACK(mailbox_conf_add_mh_cb), NULL);
- add_menu_entry(submenu, _("Remote _IMAP mailbox…"),
- G_CALLBACK(mailbox_conf_add_imap_cb), NULL);
add_menu_entry(submenu, NULL, NULL, mbnode);
add_menu_entry(submenu, _("Remote IMAP _folder…"),
G_CALLBACK(folder_conf_add_imap_cb), NULL);
- add_menu_entry(submenu, _("Remote IMAP _subfolder…"),
- G_CALLBACK(folder_conf_add_imap_sub_cb), NULL);
+ if (balsa_mailbox_node_is_imap(mbnode)) {
+ add_menu_entry(submenu, _("Remote IMAP _subfolder…"),
+ G_CALLBACK(folder_conf_add_imap_sub_cb), mbnode);
+ }
gtk_widget_show(submenu);
/* Translators: popup menu item "New" mailbox or folder */
diff --git a/src/mailbox-node.h b/src/mailbox-node.h
index 20e8b2b76..a77dbc3b5 100644
--- a/src/mailbox-node.h
+++ b/src/mailbox-node.h
@@ -111,4 +111,7 @@ void balsa_mailbox_node_clear_children_cache(BalsaMailboxNode * mbnode);
/* applicable to any mailbox node */
void balsa_mailbox_node_scan_children(BalsaMailboxNode * mbnode);
+/* return if the passed node resides on a remote IMAP server */
+gboolean balsa_mailbox_node_is_imap(const BalsaMailboxNode *mbnode);
+
#endif
diff --git a/src/main-window.c b/src/main-window.c
index fd5d012de..709383a41 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -866,14 +866,6 @@ new_mh_activated(GSimpleAction * action,
mailbox_conf_new(LIBBALSA_TYPE_MAILBOX_MH);
}
-static void
-new_imap_box_activated(GSimpleAction * action,
- GVariant * parameter,
- gpointer user_data)
-{
- mailbox_conf_new(LIBBALSA_TYPE_MAILBOX_IMAP);
-}
-
static void
new_imap_folder_activated(GSimpleAction * action,
GVariant * parameter,
@@ -887,7 +879,11 @@ new_imap_subfolder_activated(GSimpleAction * action,
GVariant * parameter,
gpointer user_data)
{
- folder_conf_imap_sub_node(NULL);
+ BalsaMailboxNode *mbnode = balsa_mblist_get_selected_node(balsa_app.mblist);
+
+ if (balsa_mailbox_node_is_imap(mbnode)) {
+ folder_conf_add_imap_sub_cb(NULL, mbnode);
+ }
}
static void
@@ -1926,7 +1922,6 @@ bw_add_app_action_entries(GActionMap * action_map, gpointer user_data)
{"new-mbox", new_mbox_activated},
{"new-maildir", new_maildir_activated},
{"new-mh", new_mh_activated},
- {"new-imap-box", new_imap_box_activated},
{"new-imap-folder", new_imap_folder_activated},
{"new-imap-subfolder", new_imap_subfolder_activated},
{"toolbars", toolbars_activated},
@@ -2454,6 +2449,7 @@ bw_enable_mailbox_menus(BalsaWindow * window, BalsaIndex * index)
bw_actions_set_enabled(window, mailbox_actions,
G_N_ELEMENTS(mailbox_actions), enable);
+ bw_action_set_enabled(window, "new-imap-subfolder", balsa_mailbox_node_is_imap(mbnode));
bw_action_set_enabled(window, "next-message",
index && index->next_message);
bw_action_set_enabled(window, "previous-message",
diff --git a/ui/main-window.ui b/ui/main-window.ui
index 487aede6f..13f73a8f4 100644
--- a/ui/main-window.ui
+++ b/ui/main-window.ui
@@ -24,11 +24,6 @@
translatable='yes'>Local MH mailbox…</attribute>
<attribute name='action'>app.new-mh</attribute>
</item>
- <item>
- <attribute name='label'
- translatable='yes'>Remote IMAP mailbox…</attribute>
- <attribute name='action'>app.new-imap-box</attribute>
- </item>
</section>
<section>
<item>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]