diff options
author | Rodney Dawes <dobey@novell.com> | 2005-05-14 05:29:28 +0800 |
---|---|---|
committer | Rodney Dawes <dobey@src.gnome.org> | 2005-05-14 05:29:28 +0800 |
commit | d88e794ded5fc1ea72af2a3d0ec4c46442a992cf (patch) | |
tree | 33b921e3906bc3990d30eeb0195c0fe13181cee6 /mail/em-folder-tree.c | |
parent | c006784d0d4612e4c682732c7db0fea35e9407e0 (diff) | |
download | gsoc2013-evolution-d88e794ded5fc1ea72af2a3d0ec4c46442a992cf.tar.gz gsoc2013-evolution-d88e794ded5fc1ea72af2a3d0ec4c46442a992cf.tar.zst gsoc2013-evolution-d88e794ded5fc1ea72af2a3d0ec4c46442a992cf.zip |
Add profiler so that it gets disted properly
2005-05-13 Rodney Dawes <dobey@novell.com>
* plugins/Makefile.am (DIST_SUBDIRS): Add profiler so that it gets
disted properly
2005-05-13 Rodney Dawes <dobey@novell.com>
* Makefile.am: Add new em-folder-utils.[ch] abstraction
* em-folder-browser.c: Update for new menu layout
Add new methods to handle the actions that were previously only
available from the context menu when right-clicking on a folder
* em-folder-selector.c (emfs_response): Just call emfu_folder_create
if the user wants to create a new folder in the selector dialog
(em_folder_selector_get_selected_path): Clean up the code to fix a
couple potential crashes
* em-folder-tree.[ch]: Add methods to get pointers to a CamelFolder or
CamelFolderInfo object for the selected item in the tree
Add a method to get a pointer to an EMFolderTreeModelStoreInfo object
for the selected store in the tree
Move folder operations out into em-folder-utils.[ch] so that they
are abstracted from the tree and can be used by methods other than
the internal context menu
* em-folder-utils.[ch]: Move the folder operations code to here
* em-folder-view.c: Update for the new menu layout
Fix Mark as Read/Unread in the context menu to only show up in the list
* mail-component.c (create_item): Just call emfu_folder_create here
when the user requests to create a new folder from the New toolbar item
2005-05-13 Rodney Dawes <dobey@novell.com>
* org-gnome-mailing-list-actions.xml: Update for the new menu layout
2005-05-13 Rodney Dawes <dobey@novell.com>
* org-gnome-plugin-manager.xml: Update for new menu layout
2005-05-13 Rodney Dawes <dobey@novell.com>
* org-gnome-save-attachments.xml: Update for new menu layout
2005-05-13 Rodney Dawes <dobey@novell.com>
* e-shell-window.c (setup_widgets): Update for the new menu layout by
putting the "component" switching items under the "Tools" menu
2005-05-13 Rodney Dawes <dobey@novell.com>
* *.xml: Update to the new menu layout
2005-05-13 Rodney Dawes <dobey@novell.com>
* e-filter-bar.[ch]: Update for the new menu layout
svn path=/trunk/; revision=29354
Diffstat (limited to 'mail/em-folder-tree.c')
-rw-r--r-- | mail/em-folder-tree.c | 800 |
1 files changed, 86 insertions, 714 deletions
diff --git a/mail/em-folder-tree.c b/mail/em-folder-tree.c index d0e34e9e83..c584f1f138 100644 --- a/mail/em-folder-tree.c +++ b/mail/em-folder-tree.c @@ -67,6 +67,7 @@ #include "em-popup.h" #include "em-marshal.h" #include "em-folder-tree.h" +#include "em-folder-utils.h" #include "em-folder-selector.h" #include "em-folder-selection.h" #include "em-folder-properties.h" @@ -2003,597 +2004,40 @@ emft_popup_open_new (GtkWidget *item, EMFolderTree *emft) #endif -struct _EMCopyFolders { - struct _mail_msg msg; - - /* input data */ - CamelStore *fromstore; - CamelStore *tostore; - - char *frombase; - char *tobase; - - int delete; -}; - -static char * -emft_copy_folders__desc (struct _mail_msg *mm, int complete) -{ - struct _EMCopyFolders *m = (struct _EMCopyFolders *) mm; - - return g_strdup_printf (_("Copying `%s' to `%s'"), m->frombase, m->tobase); -} - -static void -emft_copy_folders__copy (struct _mail_msg *mm) -{ - struct _EMCopyFolders *m = (struct _EMCopyFolders *) mm; - guint32 flags = CAMEL_STORE_FOLDER_INFO_FAST | CAMEL_STORE_FOLDER_INFO_RECURSIVE; - GList *pending = NULL, *deleting = NULL, *l; - GString *fromname, *toname; - CamelFolderInfo *fi; - const char *tmp; - int fromlen; - - if (camel_store_supports_subscriptions (m->fromstore)) - flags |= CAMEL_STORE_FOLDER_INFO_SUBSCRIBED; - - if (!(fi = camel_store_get_folder_info (m->fromstore, m->frombase, flags, &mm->ex))) - return; - - pending = g_list_append (pending, fi); - - toname = g_string_new (""); - fromname = g_string_new (""); - - tmp = strrchr (m->frombase, '/'); - if (tmp == NULL) - fromlen = 0; - else - fromlen = tmp - m->frombase + 1; - - d(printf ("top name is '%s'\n", fi->full_name)); - - while (pending) { - CamelFolderInfo *info = pending->data; - - pending = g_list_remove_link (pending, pending); - while (info) { - CamelFolder *fromfolder, *tofolder; - GPtrArray *uids; - int deleted = 0; - - if (info->child) - pending = g_list_append (pending, info->child); - - if (m->tobase[0]) - g_string_printf (toname, "%s/%s", m->tobase, info->full_name + fromlen); - else - g_string_printf (toname, "%s", info->full_name + fromlen); - - d(printf ("Copying from '%s' to '%s'\n", info->full_name, toname->str)); - - /* This makes sure we create the same tree, e.g. from a nonselectable source */ - /* Not sure if this is really the 'right thing', e.g. for spool stores, but it makes the ui work */ - if ((info->flags & CAMEL_FOLDER_NOSELECT) == 0) { - d(printf ("this folder is selectable\n")); - if (m->tostore == m->fromstore && m->delete) { - camel_store_rename_folder (m->fromstore, info->full_name, toname->str, &mm->ex); - if (camel_exception_is_set (&mm->ex)) - goto exception; - - /* this folder no longer exists, unsubscribe it */ - if (camel_store_supports_subscriptions (m->fromstore)) - camel_store_unsubscribe_folder (m->fromstore, info->full_name, NULL); - - deleted = 1; - } else { - if (!(fromfolder = camel_store_get_folder (m->fromstore, info->full_name, 0, &mm->ex))) - goto exception; - - if (!(tofolder = camel_store_get_folder (m->tostore, toname->str, CAMEL_STORE_FOLDER_CREATE, &mm->ex))) { - camel_object_unref (fromfolder); - goto exception; - } - - uids = camel_folder_get_uids (fromfolder); - camel_folder_transfer_messages_to (fromfolder, uids, tofolder, NULL, m->delete, &mm->ex); - camel_folder_free_uids (fromfolder, uids); - - if (m->delete) - camel_folder_sync(fromfolder, TRUE, NULL); - - camel_object_unref (fromfolder); - camel_object_unref (tofolder); - } - } - - if (camel_exception_is_set (&mm->ex)) - goto exception; - else if (m->delete && !deleted) - deleting = g_list_prepend (deleting, info); - - /* subscribe to the new folder if appropriate */ - if (camel_store_supports_subscriptions (m->tostore) - && !camel_store_folder_subscribed (m->tostore, toname->str)) - camel_store_subscribe_folder (m->tostore, toname->str, NULL); - - info = info->next; - } - } - - /* delete the folders in reverse order from how we copyied them, if we are deleting any */ - l = deleting; - while (l) { - CamelFolderInfo *info = l->data; - - d(printf ("deleting folder '%s'\n", info->full_name)); - - /* FIXME: we need to do something with the exception - since otherwise the users sees a failed operation - with no error message or even any warnings */ - if (camel_store_supports_subscriptions (m->fromstore)) - camel_store_unsubscribe_folder (m->fromstore, info->full_name, NULL); - - camel_store_delete_folder (m->fromstore, info->full_name, NULL); - l = l->next; - } - - exception: - - camel_store_free_folder_info (m->fromstore, fi); - g_list_free (deleting); - - g_string_free (toname, TRUE); - g_string_free (fromname, TRUE); -} - -static void -emft_copy_folders__free (struct _mail_msg *mm) -{ - struct _EMCopyFolders *m = (struct _EMCopyFolders *) mm; - - camel_object_unref (m->fromstore); - camel_object_unref (m->tostore); - - g_free (m->frombase); - g_free (m->tobase); -} - -static struct _mail_msg_op copy_folders_op = { - emft_copy_folders__desc, - emft_copy_folders__copy, - NULL, - emft_copy_folders__free, -}; - -static void -emft_copy_folders (CamelStore *tostore, const char *tobase, CamelStore *fromstore, const char *frombase, int delete) -{ - struct _EMCopyFolders *m; - - m = mail_msg_new (©_folders_op, NULL, sizeof (struct _EMCopyFolders)); - camel_object_ref (fromstore); - m->fromstore = fromstore; - camel_object_ref (tostore); - m->tostore = tostore; - m->frombase = g_strdup (frombase); - m->tobase = g_strdup (tobase); - m->delete = delete; - - e_thread_put (mail_thread_new, (EMsg *) m); -} - -struct _copy_folder_data { - EMFolderTree *emft; - gboolean delete; -}; - -static void -emft_popup_copy_folder_selected (const char *uri, void *data) -{ - struct _copy_folder_data *cfd = data; - struct _EMFolderTreePrivate *priv; - CamelStore *fromstore = NULL, *tostore = NULL; - char *tobase = NULL, *frombase = NULL, *fromuri = NULL; - CamelException ex; - CamelURL *url; - - if (uri == NULL) { - g_free (cfd); - return; - } - - priv = cfd->emft->priv; - - camel_exception_init (&ex); - - fromuri = em_folder_tree_get_selected_uri(cfd->emft); - g_return_if_fail(fromuri != NULL); - frombase = em_folder_tree_get_selected_path(cfd->emft); - g_return_if_fail(frombase != NULL); - - if (!(fromstore = camel_session_get_store (session, fromuri, &ex))) { - e_error_run((GtkWindow *)gtk_widget_get_toplevel((GtkWidget *) cfd->emft), - cfd->delete?"mail:no-move-folder-notexist":"mail:no-copy-folder-notexist", frombase, uri, ex.desc, NULL); - goto fail; - } - - if (cfd->delete && fromstore == mail_component_peek_local_store (NULL) && is_special_local_folder (frombase)) { - e_error_run((GtkWindow *)gtk_widget_get_toplevel((GtkWidget *) cfd->emft), - "mail:no-rename-special-folder", frombase, NULL); - goto fail; - } - - if (!(tostore = camel_session_get_store (session, uri, &ex))) { - e_error_run((GtkWindow *)gtk_widget_get_toplevel((GtkWidget *) cfd->emft), - cfd->delete?"mail:no-move-folder-to-notexist":"mail:no-copy-folder-to-notexist", frombase, uri, ex.desc, NULL); - goto fail; - } - - url = camel_url_new (uri, NULL); - if (((CamelService *)tostore)->provider->url_flags & CAMEL_URL_FRAGMENT_IS_PATH) - tobase = url->fragment; - else if (url->path && url->path[0]) - tobase = url->path+1; - if (tobase == NULL) - tobase = ""; - - emft_copy_folders (tostore, tobase, fromstore, frombase, cfd->delete); - - camel_url_free (url); -fail: - if (fromstore) - camel_object_unref(fromstore); - if (tostore) - camel_object_unref(tostore); - g_free(frombase); - g_free(fromuri); - camel_exception_clear (&ex); - g_free (cfd); -} - -/* tree here is the 'destination' selector, not 'self' */ -static gboolean -emft_popup_copy_folder_exclude(EMFolderTree *tree, GtkTreeModel *model, GtkTreeIter *iter, void *data) -{ - struct _copy_folder_data *cfd = data; - int fromvfolder, tovfolder; - char *fromuri, *touri; - guint flags; - gboolean is_store; - - /* handles moving to/from vfolders */ - - fromuri = em_folder_tree_get_selected_uri(cfd->emft); - fromvfolder = strncmp(fromuri, "vfolder:", 8) == 0; - gtk_tree_model_get(model, iter, COL_STRING_URI, &touri, COL_UINT_FLAGS, &flags, COL_BOOL_IS_STORE, &is_store, -1); - tovfolder = strncmp(touri, "vfolder:", 8) == 0; - g_free(fromuri); - g_free(touri); - - /* moving from vfolder to normal- not allowed */ - if (fromvfolder && !tovfolder && cfd->delete) - return FALSE; - /* copy/move from normal folder to vfolder - not allowed */ - if (!fromvfolder && tovfolder) - return FALSE; - /* copying to vfolder - not allowed */ - if (tovfolder && !cfd->delete) - return FALSE; - - return (flags & EMFT_EXCLUDE_NOINFERIORS) == 0; -} - static void emft_popup_copy(EPopup *ep, EPopupItem *item, void *data) { EMFolderTree *emft = data; - struct _copy_folder_data *cfd; - - cfd = g_malloc (sizeof (*cfd)); - cfd->emft = emft; - cfd->delete = FALSE; - - em_select_folder (NULL, _("Select folder"), _("C_opy"), - NULL, emft_popup_copy_folder_exclude, emft_popup_copy_folder_selected, cfd); -} + CamelFolderInfo *fi = NULL; -static void -emft_popup_move(EPopup *ep, EPopupItem *item, void *data) -{ - EMFolderTree *emft = data; - struct _copy_folder_data *cfd; - - cfd = g_malloc (sizeof (*cfd)); - cfd->emft = emft; - cfd->delete = TRUE; - - em_select_folder (NULL, _("Select folder"), _("_Move"), - NULL, emft_popup_copy_folder_exclude, emft_popup_copy_folder_selected, cfd); -} - - -struct _EMCreateFolder { - struct _mail_msg msg; - - /* input data */ - CamelStore *store; - char *full_name; - char *parent; - char *name; - - /* output data */ - CamelFolderInfo *fi; - - /* callback data */ - void (* done) (CamelFolderInfo *fi, void *user_data); - void *user_data; -}; - -static char * -emft_create_folder__desc (struct _mail_msg *mm, int done) -{ - struct _EMCreateFolder *m = (struct _EMCreateFolder *) mm; - - return g_strdup_printf (_("Creating folder `%s'"), m->full_name); -} - -static void -emft_create_folder__create (struct _mail_msg *mm) -{ - struct _EMCreateFolder *m = (struct _EMCreateFolder *) mm; - - d(printf ("creating folder parent='%s' name='%s' full_name='%s'\n", m->parent, m->name, m->full_name)); - - if ((m->fi = camel_store_create_folder (m->store, m->parent, m->name, &mm->ex))) { - if (camel_store_supports_subscriptions (m->store)) - camel_store_subscribe_folder (m->store, m->full_name, &mm->ex); + if ((fi = em_folder_tree_get_selected_folder_info (emft)) != NULL) { + emfu_copy_folder (fi); } } static void -emft_create_folder__created (struct _mail_msg *mm) -{ - struct _EMCreateFolder *m = (struct _EMCreateFolder *) mm; - - if (m->done) - m->done (m->fi, m->user_data); -} - -static void -emft_create_folder__free (struct _mail_msg *mm) -{ - struct _EMCreateFolder *m = (struct _EMCreateFolder *) mm; - - camel_store_free_folder_info (m->store, m->fi); - camel_object_unref (m->store); - g_free (m->full_name); - g_free (m->parent); - g_free (m->name); -} - -static struct _mail_msg_op create_folder_op = { - emft_create_folder__desc, - emft_create_folder__create, - emft_create_folder__created, - emft_create_folder__free, -}; - - -static int -emft_create_folder (CamelStore *store, const char *full_name, void (* done) (CamelFolderInfo *fi, void *user_data), void *user_data) -{ - char *name, *namebuf = NULL; - struct _EMCreateFolder *m; - const char *parent; - int id; - - namebuf = g_strdup (full_name); - if (!(name = strrchr (namebuf, '/'))) { - name = namebuf; - parent = ""; - } else { - *name++ = '\0'; - parent = namebuf; - } - - m = mail_msg_new (&create_folder_op, NULL, sizeof (struct _EMCreateFolder)); - camel_object_ref (store); - m->store = store; - m->full_name = g_strdup (full_name); - m->parent = g_strdup (parent); - m->name = g_strdup (name); - m->user_data = user_data; - m->done = done; - - g_free (namebuf); - - id = m->msg.seq; - e_thread_put (mail_thread_new, (EMsg *) m); - - return id; -} - -static void -created_cb (CamelFolderInfo *fi, void *user_data) -{ - gboolean *created = user_data; - - *created = fi ? TRUE : FALSE; -} - -gboolean -em_folder_tree_create_folder (EMFolderTree *emft, const char *full_name, const char *uri) -{ - struct _EMFolderTreePrivate *priv = emft->priv; - struct _EMFolderTreeModelStoreInfo *si; - gboolean created = FALSE; - CamelStore *store; - CamelException ex; - - d(printf ("Creating folder: %s (%s)\n", full_name, uri)); - - camel_exception_init (&ex); - if (!(store = (CamelStore *) camel_session_get_service (session, uri, CAMEL_PROVIDER_STORE, &ex))) { - e_error_run((GtkWindow *)gtk_widget_get_toplevel((GtkWidget *)emft), - "mail:no-create-folder-nostore", full_name, ex.desc, NULL); - goto fail; - } - - if (!(si = g_hash_table_lookup (priv->model->store_hash, store))) { - abort(); - camel_object_unref (store); - goto fail; - } - - camel_object_unref (store); - - mail_msg_wait (emft_create_folder (si->store, full_name, created_cb, &created)); -fail: - camel_exception_clear(&ex); - - return created; -} - -static void -new_folder_created_cb (CamelFolderInfo *fi, void *user_data) -{ - EMFolderSelector *emfs = user_data; - - if (fi) - gtk_widget_destroy ((GtkWidget *) emfs); - - g_object_unref (emfs); -} - -static void -emft_popup_new_folder_response (EMFolderSelector *emfs, int response, EMFolderTree *emft) +emft_popup_move(EPopup *ep, EPopupItem *item, void *data) { - struct _EMFolderTreePrivate *priv = emft->priv; - struct _EMFolderTreeModelStoreInfo *si; - const char *uri, *path; - CamelException ex; - CamelStore *store; - - if (response != GTK_RESPONSE_OK) { - gtk_widget_destroy ((GtkWidget *) emfs); - return; - } - - uri = em_folder_selector_get_selected_uri (emfs); - path = em_folder_selector_get_selected_path (emfs); - - d(printf ("Creating new folder: %s (%s)\n", path, uri)); - - camel_exception_init (&ex); - if (!(store = (CamelStore *) camel_session_get_service (session, uri, CAMEL_PROVIDER_STORE, &ex))) { - camel_exception_clear (&ex); - return; - } - - if (!(si = g_hash_table_lookup (priv->model->store_hash, store))) { - g_assert_not_reached (); - camel_object_unref (store); - return; - } - - /* HACK: we need to create vfolders using the vfolder editor */ - if (CAMEL_IS_VEE_STORE(store)) { - EMVFolderRule *rule; + EMFolderTree *emft = data; + CamelFolderInfo *fi = NULL; - rule = em_vfolder_rule_new(); - filter_rule_set_name((FilterRule *)rule, path); - vfolder_gui_add_rule(rule); - gtk_widget_destroy((GtkWidget *)emfs); - } else { - g_object_ref (emfs); - emft_create_folder (si->store, path, new_folder_created_cb, emfs); + if ((fi = em_folder_tree_get_selected_folder_info (emft)) != NULL) { + emfu_copy_folder (fi); } - - camel_object_unref (store); } static void emft_popup_new_folder (EPopup *ep, EPopupItem *pitem, void *data) { EMFolderTree *emft = data; + CamelFolderInfo *fi; - EMFolderTree *folder_tree; - GtkWidget *dialog; - char *uri; - - folder_tree = (EMFolderTree *) em_folder_tree_new_with_model (emft->priv->model); - - dialog = em_folder_selector_create_new (folder_tree, 0, _("Create folder"), _("Specify where to create the folder:")); - uri = em_folder_tree_get_selected_uri(emft); - em_folder_selector_set_selected ((EMFolderSelector *) dialog, uri); - g_free(uri); - g_signal_connect (dialog, "response", G_CALLBACK (emft_popup_new_folder_response), emft); - gtk_widget_show (dialog); -} - -static void -emft_popup_delete_rec (CamelStore *store, CamelFolderInfo *fi, CamelException *ex) -{ - while (fi) { - CamelFolder *folder; - - if (fi->child) { - emft_popup_delete_rec (store, fi->child, ex); - if (camel_exception_is_set (ex)) - return; - } - - d(printf ("deleting folder '%s'\n", fi->full_name)); - - /* shouldn't camel do this itself? */ - if (camel_store_supports_subscriptions (store)) - camel_store_unsubscribe_folder (store, fi->full_name, NULL); - - if (!(folder = camel_store_get_folder (store, fi->full_name, 0, ex))) - return; - - if (!CAMEL_IS_VEE_FOLDER (folder)) { - GPtrArray *uids = camel_folder_get_uids (folder); - int i; - - camel_folder_freeze (folder); - for (i = 0; i < uids->len; i++) - camel_folder_delete_message (folder, uids->pdata[i]); - - camel_folder_free_uids (folder, uids); - - camel_folder_sync (folder, TRUE, NULL); - camel_folder_thaw (folder); - } - - camel_store_delete_folder (store, fi->full_name, ex); - if (camel_exception_is_set (ex)) - return; - - fi = fi->next; + if ((fi = em_folder_tree_get_selected_folder_info (emft)) != NULL) { + emfu_folder_create (fi); } } static void -emft_popup_delete_folders (CamelStore *store, const char *full_name, CamelException *ex) -{ - guint32 flags = CAMEL_STORE_FOLDER_INFO_RECURSIVE | CAMEL_STORE_FOLDER_INFO_FAST; - CamelFolderInfo *fi; - - if (camel_store_supports_subscriptions (store)) - flags |= CAMEL_STORE_FOLDER_INFO_SUBSCRIBED; - - fi = camel_store_get_folder_info (store, full_name, flags, ex); - if (camel_exception_is_set (ex)) - return; - - emft_popup_delete_rec (store, fi, ex); - camel_store_free_folder_info (store, fi); -} - -static void selfunc (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { struct _emft_selection_data *dat = (struct _emft_selection_data *) data; @@ -2620,163 +2064,25 @@ emft_selection_get_selected (GtkTreeSelection *selection, GtkTreeModel **model, } static void -emft_popup_delete_response (GtkWidget *dialog, int response, EMFolderTree *emft) -{ - CamelStore *store; - CamelException ex; - char *full_name; - - full_name = g_object_get_data ((GObject *) dialog, "full_name"); - store = g_object_get_data ((GObject *) dialog, "store"); - - if (response == GTK_RESPONSE_OK) { - camel_exception_init (&ex); - emft_popup_delete_folders (store, full_name, &ex); - if (camel_exception_is_set (&ex)) { - e_error_run((GtkWindow *)gtk_widget_get_toplevel((GtkWidget *)emft), - "mail:no-delete-folder", full_name, ex.desc, NULL); - camel_exception_clear (&ex); - } - } - - gtk_widget_destroy (dialog); -} - -static void emft_popup_delete_folder (EPopup *ep, EPopupItem *pitem, void *data) { EMFolderTree *emft = data; - struct _EMFolderTreePrivate *priv = emft->priv; - GtkTreeSelection *selection; - CamelStore *local, *store; - GtkTreeModel *model; - GtkTreeIter iter; - GtkWidget *dialog; - char *full_name; - - selection = gtk_tree_view_get_selection (priv->treeview); - if (!emft_selection_get_selected (selection, &model, &iter)) - return; - - gtk_tree_model_get (model, &iter, COL_POINTER_CAMEL_STORE, &store, - COL_STRING_FULL_NAME, &full_name, -1); - - local = mail_component_peek_local_store (NULL); - - if (store == local && is_special_local_folder (full_name)) { - e_error_run(NULL, "mail:no-delete-special-folder", full_name, NULL); - return; - } - - camel_object_ref (store); + CamelFolder *folder; - dialog = e_error_new((GtkWindow *)gtk_widget_get_toplevel((GtkWidget *)emft), - (store && CAMEL_IS_VEE_STORE(store))?"mail:ask-delete-vfolder":"mail:ask-delete-folder", - full_name, NULL); - g_object_set_data_full ((GObject *) dialog, "full_name", full_name, g_free); - g_object_set_data_full ((GObject *) dialog, "store", store, camel_object_unref); - g_signal_connect (dialog, "response", G_CALLBACK (emft_popup_delete_response), emft); - gtk_widget_show (dialog); + if ((folder = em_folder_tree_get_selected_folder (emft)) != NULL) { + emfu_delete_folder (folder); + } } static void emft_popup_rename_folder (EPopup *ep, EPopupItem *pitem, void *data) { EMFolderTree *emft = data; - struct _EMFolderTreePrivate *priv = emft->priv; - char *prompt, *full_name, *name, *new_name, *uri; - GtkTreeSelection *selection; - const char *p; - CamelStore *local, *store; - gboolean done = FALSE; - GtkTreeModel *model; - GtkTreeIter iter; - size_t base_len; - - local = mail_component_peek_local_store (NULL); - - selection = gtk_tree_view_get_selection (priv->treeview); - if (!emft_selection_get_selected (selection, &model, &iter)) - return; - - gtk_tree_model_get (model, &iter, COL_STRING_FULL_NAME, &full_name, - COL_STRING_DISPLAY_NAME, &name, - COL_POINTER_CAMEL_STORE, &store, - COL_STRING_URI, &uri, -1); - - /* don't allow user to rename one of the special local folders */ - if (store == local && is_special_local_folder (full_name)) { - e_error_run((GtkWindow *)gtk_widget_get_toplevel((GtkWidget *)emft), - "mail:no-rename-special-folder", full_name, NULL); - g_free (full_name); - g_free (name); - g_free (uri); - return; - } - - if ((p = strrchr (full_name, '/'))) - base_len = (size_t) (p - full_name); - else - base_len = 0; - - prompt = g_strdup_printf (_("Rename the \"%s\" folder to:"), name); - while (!done) { - new_name = e_request_string (NULL, _("Rename Folder"), prompt, name); - if (new_name == NULL || !strcmp (name, new_name)) { - /* old name == new name */ - done = TRUE; - } else if (strchr(new_name, '/') != NULL) { - e_error_run((GtkWindow *)gtk_widget_get_toplevel((GtkWidget *)emft), - "mail:no-rename-folder", name, new_name, _("Folder names cannot contain '/'"), NULL); - done = TRUE; - } else { - CamelFolderInfo *fi; - CamelException ex; - char *path, *p; - - if (base_len > 0) { - path = g_malloc (base_len + strlen (new_name) + 2); - memcpy (path, full_name, base_len); - p = path + base_len; - *p++ = '/'; - strcpy (p, new_name); - } else { - path = g_strdup (new_name); - } - - camel_exception_init (&ex); - if ((fi = camel_store_get_folder_info (store, path, CAMEL_STORE_FOLDER_INFO_FAST, &ex)) != NULL) { - camel_store_free_folder_info (store, fi); - e_error_run((GtkWindow *)gtk_widget_get_toplevel((GtkWidget *)emft), - "mail:no-rename-folder-exists", name, new_name, NULL); - } else { - const char *oldpath, *newpath; - - oldpath = full_name; - newpath = path; - - d(printf ("renaming %s to %s\n", oldpath, newpath)); - - camel_exception_clear (&ex); - camel_store_rename_folder (store, oldpath, newpath, &ex); - if (camel_exception_is_set (&ex)) { - e_error_run((GtkWindow *)gtk_widget_get_toplevel((GtkWidget *)emft), - "mail:no-rename-folder", oldpath, newpath, ex.desc, NULL); - camel_exception_clear (&ex); - } - - done = TRUE; - } - - g_free (path); - } - - g_free (new_name); + CamelFolder *folder; + + if ((folder = em_folder_tree_get_selected_folder (emft)) != NULL) { + emfu_rename_folder (folder); } - - g_free (full_name); - g_free (name); - g_free (uri); } @@ -3030,6 +2336,60 @@ em_folder_tree_get_selected_path (EMFolderTree *emft) return name; } +CamelFolder * +em_folder_tree_get_selected_folder (EMFolderTree *emft) +{ + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreeIter iter; + char *full_name = NULL; + CamelException ex; + CamelStore *store = NULL; + CamelFolder *folder = NULL; + + g_return_val_if_fail (EM_IS_FOLDER_TREE (emft), NULL); + + camel_exception_init (&ex); + + selection = gtk_tree_view_get_selection(emft->priv->treeview); + if (gtk_tree_selection_get_selected(selection, &model, &iter)) + gtk_tree_model_get (model, &iter, COL_POINTER_CAMEL_STORE, &store, + COL_STRING_FULL_NAME, &full_name, -1); + + folder = camel_store_get_folder (store, full_name, CAMEL_STORE_FOLDER_INFO_FAST, &ex); + + camel_exception_clear (&ex); + + return folder; +} + +CamelFolderInfo * +em_folder_tree_get_selected_folder_info (EMFolderTree *emft) +{ + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreeIter iter; + char *full_name = NULL; + CamelException ex; + CamelStore *store = NULL; + CamelFolderInfo *fi = NULL; + + g_return_val_if_fail (EM_IS_FOLDER_TREE (emft), NULL); + + camel_exception_init (&ex); + + selection = gtk_tree_view_get_selection(emft->priv->treeview); + if (gtk_tree_selection_get_selected(selection, &model, &iter)) + gtk_tree_model_get (model, &iter, COL_POINTER_CAMEL_STORE, &store, + COL_STRING_FULL_NAME, &full_name, -1); + + fi = camel_store_get_folder_info (store, full_name, CAMEL_STORE_FOLDER_INFO_FAST, &ex); + + camel_exception_clear (&ex); + + return fi; +} + EMFolderTreeModel * em_folder_tree_get_model (EMFolderTree *emft) { @@ -3038,6 +2398,18 @@ em_folder_tree_get_model (EMFolderTree *emft) return emft->priv->model; } +EMFolderTreeModelStoreInfo * +em_folder_tree_get_model_storeinfo (EMFolderTree *emft, CamelStore *store) +{ + struct _EMFolderTreePrivate *priv = emft->priv; + struct _EMFolderTreeModelStoreInfo *si; + + if (!(si = g_hash_table_lookup (priv->model->store_hash, store))) { + g_assert_not_reached (); + return NULL; + } + return si; +} static gboolean emft_save_state (EMFolderTree *emft) |