From cf945fcde2d0ee22a0d63e8ba73f7f198eeeb549 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Wed, 20 Feb 2002 03:51:20 +0000 Subject: Prompt the user to find out if he/she wants to go to the next folder with 2002-02-19 Jeffrey Stedfast * mail-callbacks.c (confirm_goto_next_folder): Prompt the user to find out if he/she wants to go to the next folder with unread mail in it. (find_current_folder): Find a given CamelFolderInfo node based on a given uri. (find_next_folder_r): Recursively look for a CamelFOlderInfo node which has unread messages. (find_next_folder): Given a currently selected CamelFolderInfo node, look for the next node containing unread messages. (do_evil_kludgy_goto_next_folder_hack): Find the currently selected folder and then find the very next folder after it that contains unread messages and then select it via a CORBA call to the shell. (next_unread_msg): If we fail to find an unread message in the message-list, prompt the user to find out if we should jump to the next fodler containing unread messages. If so, call do_evil_kludgy_goto_next_folder_hack(). * message-list.c (message_list_select): Return a boolean value based on whether the call was successfull or not. * mail-config.c (mail_config_get_confirm_goto_next_folder): (mail_config_set_confirm_goto_next_folder): (mail_config_get_goto_next_folder): (mail_config_set_goto_next_folder): All new functions, yay. (config_read): Read in the confirm_goto_next_folder and goto_next_folder config options. (mail_config_write_on_exit): Same the options here. svn path=/trunk/; revision=15770 --- mail/mail-callbacks.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 149 insertions(+), 2 deletions(-) (limited to 'mail/mail-callbacks.c') diff --git a/mail/mail-callbacks.c b/mail/mail-callbacks.c index fa59e0e254..41733c7f23 100644 --- a/mail/mail-callbacks.c +++ b/mail/mail-callbacks.c @@ -2331,6 +2331,151 @@ undelete_msg (GtkWidget *button, gpointer user_data) flag_messages (FOLDER_BROWSER (user_data), CAMEL_MESSAGE_DELETED, 0); } + +static gboolean +confirm_goto_next_folder (FolderBrowser *fb) +{ + GtkWidget *dialog, *label, *checkbox; + int button; + + if (!mail_config_get_confirm_goto_next_folder ()) + return mail_config_get_goto_next_folder (); + + dialog = gnome_dialog_new (_("Go to next folder with unread messages?"), + GNOME_STOCK_BUTTON_YES, + GNOME_STOCK_BUTTON_NO, + NULL); + + e_gnome_dialog_set_parent (GNOME_DIALOG (dialog), FB_WINDOW (fb)); + + label = gtk_label_new (_("There are no more new messages in this folder.\n" + "Would you like to go to the next folder?")); + + gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); + gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); + gtk_widget_show (label); + gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), label, TRUE, TRUE, 4); + + checkbox = gtk_check_button_new_with_label (_("Do not ask me again.")); + gtk_object_ref (GTK_OBJECT (checkbox)); + gtk_widget_show (checkbox); + gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), checkbox, TRUE, TRUE, 4); + + button = gnome_dialog_run_and_close (GNOME_DIALOG (dialog)); + + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbox))) + mail_config_set_confirm_goto_next_folder (FALSE); + + gtk_object_unref (GTK_OBJECT (checkbox)); + + if (button == 0) { + mail_config_set_goto_next_folder (TRUE); + return TRUE; + } else { + mail_config_set_goto_next_folder (FALSE); + return FALSE; + } +} + +static CamelFolderInfo * +find_current_folder (CamelFolderInfo *root, const char *current_uri) +{ + CamelFolderInfo *node, *current = NULL; + + node = root; + while (node) { + if (!strcmp (current_uri, node->url)) { + current = node; + break; + } + + current = find_current_folder (node->child, current_uri); + if (current) + break; + + node = node->sibling; + } + + return current; +} + +static CamelFolderInfo * +find_next_folder_r (CamelFolderInfo *node) +{ + CamelFolderInfo *next; + + while (node) { + if (node->unread_message_count > 0) + return node; + + next = find_next_folder_r (node->child); + if (next) + return next; + + node = node->sibling; + } + + return NULL; +} + +static CamelFolderInfo * +find_next_folder (CamelFolderInfo *current) +{ + CamelFolderInfo *next; + + /* first search subfolders... */ + next = find_next_folder_r (current->child); + if (next) + return next; + + /* now search siblings... */ + next = find_next_folder_r (current->sibling); + if (next) + return next; + + /* now go up one level (if we can) and search... */ + if (current->parent && current->parent->sibling) { + return find_next_folder_r (current->parent->sibling); + } else { + return NULL; + } +} + +static void +do_evil_kludgy_goto_next_folder_hack (FolderBrowser *fb) +{ + CamelFolderInfo *root, *current, *node; + CORBA_Environment ev; + CamelStore *store; + + store = camel_folder_get_parent_store (fb->folder); + + /* FIXME: loop over all available mail stores? */ + + root = camel_store_get_folder_info (store, "", CAMEL_STORE_FOLDER_INFO_RECURSIVE | + CAMEL_STORE_FOLDER_INFO_SUBSCRIBED, NULL); + + if (!root) + return; + + current = find_current_folder (root, fb->uri); + g_assert (current != NULL); + + node = find_next_folder (current); + if (node) { + g_warning ("doin' my thang..."); + CORBA_exception_init (&ev); + GNOME_Evolution_ShellView_changeCurrentView (fb->shell_view, "evolution:/local/Inbox", &ev); + if (ev._major != CORBA_NO_EXCEPTION) + g_warning ("got an exception"); + CORBA_exception_free (&ev); + } else { + g_warning ("can't find a folder with unread mail?"); + } + + camel_store_free_folder_info (store, root); +} + void next_msg (GtkWidget *button, gpointer user_data) { @@ -2350,8 +2495,10 @@ next_unread_msg (GtkWidget *button, gpointer user_data) if (FOLDER_BROWSER_IS_DESTROYED (fb)) return; - message_list_select (fb->message_list, MESSAGE_LIST_SELECT_NEXT, - 0, CAMEL_MESSAGE_SEEN, TRUE); + if (!message_list_select (fb->message_list, MESSAGE_LIST_SELECT_NEXT, 0, CAMEL_MESSAGE_SEEN, TRUE)) { + if (confirm_goto_next_folder (fb)) + do_evil_kludgy_goto_next_folder_hack (fb); + } } void -- cgit v1.2.3