diff options
Diffstat (limited to 'mail/em-folder-tree.c')
-rw-r--r-- | mail/em-folder-tree.c | 882 |
1 files changed, 300 insertions, 582 deletions
diff --git a/mail/em-folder-tree.c b/mail/em-folder-tree.c index e7063e9fed..128e2fe164 100644 --- a/mail/em-folder-tree.c +++ b/mail/em-folder-tree.c @@ -48,6 +48,7 @@ #include <camel/camel-file-utils.h> #include <camel/camel-stream-fs.h> +#include "e-util/e-account-utils.h" #include "e-util/e-mktemp.h" #include "e-util/e-request.h" #include "e-util/e-icon-factory.h" @@ -60,7 +61,6 @@ #include "mail-ops.h" #include "mail-tools.h" #include "mail-config.h" -#include "mail-component.h" #include "mail-send-recv.h" #include "mail-vfolder.h" @@ -73,8 +73,14 @@ #include "em-folder-properties.h" #include "em-event.h" +#include "e-mail-shell-backend.h" + #define d(x) +#define EM_FOLDER_TREE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE \ + ((obj), EM_TYPE_FOLDER_TREE, EMFolderTreePrivate)) + struct _selected_uri { char *key; /* store:path or account/path */ char *uri; @@ -83,7 +89,6 @@ struct _selected_uri { }; struct _EMFolderTreePrivate { - GtkTreeView *treeview; EMFolderTreeModel *model; GSList *select_uris; /* selected_uri structures of each path pending selection. */ @@ -114,6 +119,7 @@ struct _EMFolderTreePrivate { enum { FOLDER_ACTIVATED, /* aka double-clicked or user hit enter */ FOLDER_SELECTED, + POPUP_EVENT, LAST_SIGNAL }; @@ -151,11 +157,6 @@ static guint signals[LAST_SIGNAL] = { 0 }; extern CamelSession *session; -static void em_folder_tree_class_init (EMFolderTreeClass *klass); -static void em_folder_tree_init (EMFolderTree *emft); -static void em_folder_tree_destroy (GtkObject *obj); -static void em_folder_tree_finalize (GObject *obj); - static gboolean emft_save_state (EMFolderTree *emft); static void emft_queue_save_state (EMFolderTree *emft); @@ -175,68 +176,170 @@ struct _emft_selection_data { gboolean set; }; -static GtkVBoxClass *parent_class = NULL; +static gpointer parent_class = NULL; -GType -em_folder_tree_get_type (void) +static void +folder_tree_emit_popup_event (EMFolderTree *emft, + GdkEvent *event) { - static GType type = 0; + g_signal_emit (emft, signals[POPUP_EVENT], 0, event); +} - if (!type) { - static const GTypeInfo info = { - sizeof (EMFolderTreeClass), - NULL, /* base_class_init */ - NULL, /* base_class_finalize */ - (GClassInitFunc) em_folder_tree_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (EMFolderTree), - 0, /* n_preallocs */ - (GInstanceInitFunc) em_folder_tree_init, - }; +static void +emft_free_select_uri (struct _selected_uri *u) +{ + g_free (u->uri); + if (u->store) + camel_object_unref (u->store); + g_free (u->key); + g_free (u->path); + g_free (u); +} - type = g_type_register_static (GTK_TYPE_VBOX, "EMFolderTree", &info, 0); +static void +folder_tree_finalize (GObject *object) +{ + EMFolderTreePrivate *priv; + + priv = EM_FOLDER_TREE_GET_PRIVATE (object); + + if (priv->select_uris != NULL) { + g_slist_foreach ( + priv->select_uris, + (GFunc) emft_free_select_uri, NULL); + g_slist_free (priv->select_uris); + g_hash_table_destroy (priv->select_uris_table); + priv->select_uris = NULL; } - return type; + /* Chain up to parent's finalize() method. */ + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static void +em_folder_tree_destroy (GtkObject *object) +{ + EMFolderTreePrivate *priv; + + priv = EM_FOLDER_TREE_GET_PRIVATE (object); + + if (priv->loaded_row_id != 0) { + g_signal_handler_disconnect (priv->model, priv->loaded_row_id); + priv->loaded_row_id = 0; + } + + if (priv->save_state_id != 0) { + g_source_remove (priv->save_state_id); + emft_save_state (EM_FOLDER_TREE (object)); + } + + if (priv->autoscroll_id != 0) { + g_source_remove (priv->autoscroll_id); + priv->autoscroll_id = 0; + } + + if (priv->autoexpand_id != 0) { + gtk_tree_row_reference_free (priv->autoexpand_row); + priv->autoexpand_row = NULL; + + g_source_remove (priv->autoexpand_id); + priv->autoexpand_id = 0; + } + + priv->model = NULL; + + /* Chain up to parent's destroy() method. */ + GTK_OBJECT_CLASS (parent_class)->destroy (object); } static void -em_folder_tree_class_init (EMFolderTreeClass *klass) +folder_tree_class_init (EMFolderTreeClass *class) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GObjectClass *object_class; + GtkObjectClass *gtk_object_class; + GtkWidgetClass *widget_class; - parent_class = g_type_class_ref (GTK_TYPE_VBOX); + parent_class = g_type_class_peek_parent (class); + g_type_class_add_private (class, sizeof (EMFolderTreePrivate)); - object_class->finalize = em_folder_tree_finalize; + object_class = G_OBJECT_CLASS (class); + object_class->finalize = folder_tree_finalize; + + gtk_object_class = GTK_OBJECT_CLASS (class); gtk_object_class->destroy = em_folder_tree_destroy; + widget_class = GTK_WIDGET_CLASS (class); widget_class->popup_menu = emft_popup_menu; - signals[FOLDER_SELECTED] = - g_signal_new ("folder-selected", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (EMFolderTreeClass, folder_selected), - NULL, NULL, - e_marshal_VOID__STRING_STRING_UINT, - G_TYPE_NONE, 3, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_UINT); - - signals[FOLDER_ACTIVATED] = - g_signal_new ("folder-activated", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (EMFolderTreeClass, folder_activated), - NULL, NULL, - e_marshal_VOID__STRING_STRING, - G_TYPE_NONE, 2, - G_TYPE_STRING, - G_TYPE_STRING); + signals[FOLDER_SELECTED] = g_signal_new ( + "folder-selected", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (EMFolderTreeClass, folder_selected), + NULL, NULL, + e_marshal_VOID__STRING_STRING_UINT, + G_TYPE_NONE, 3, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_UINT); + + signals[FOLDER_ACTIVATED] = g_signal_new ( + "folder-activated", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (EMFolderTreeClass, folder_activated), + NULL, NULL, + e_marshal_VOID__STRING_STRING, + G_TYPE_NONE, 2, + G_TYPE_STRING, + G_TYPE_STRING); + + signals[POPUP_EVENT] = g_signal_new ( + "popup-event", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (EMFolderTreeClass, popup_event), + NULL, NULL, + g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, 1, + GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); +} + +static void +folder_tree_init (EMFolderTree *emft) +{ + GHashTable *select_uris_table; + + select_uris_table = g_hash_table_new (g_str_hash, g_str_equal); + + emft->priv = EM_FOLDER_TREE_GET_PRIVATE (emft); + emft->priv->select_uris_table = select_uris_table; +} + +GType +em_folder_tree_get_type (void) +{ + static GType type = 0; + + if (G_UNLIKELY (type == 0)) { + static const GTypeInfo type_info = { + sizeof (EMFolderTreeClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) folder_tree_class_init, + (GClassFinalizeFunc) NULL, + NULL, /* class_data */ + sizeof (EMFolderTree), + 0, /* n_preallocs */ + (GInstanceInitFunc) folder_tree_init, + NULL /* value_table */ + }; + + type = g_type_register_static ( + GTK_TYPE_TREE_VIEW, "EMFolderTree", &type_info, 0); + } + + return type; } static gboolean @@ -261,87 +364,6 @@ subdirs_contain_unread (GtkTreeModel *model, GtkTreeIter *root) return FALSE; } - -enum { - FOLDER_ICON_NORMAL, - FOLDER_ICON_INBOX, - FOLDER_ICON_OUTBOX, - FOLDER_ICON_TRASH, - FOLDER_ICON_JUNK, - FOLDER_ICON_SHARED_TO_ME, - FOLDER_ICON_SHARED_BY_ME, - FOLDER_ICON_SENT, - FOLDER_ICON_VIRTUAL, - FOLDER_ICON_LAST -}; - -static GdkPixbuf *folder_icons[FOLDER_ICON_LAST]; - -static void -render_pixbuf (GtkTreeViewColumn *column, GtkCellRenderer *renderer, - GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) -{ - static gboolean initialised = FALSE; - GdkPixbuf *pixbuf = NULL; - gboolean is_store; - guint32 flags; - EMEventTargetCustomIcon *target; - const char *folder_name; - - if (!initialised) { - folder_icons[FOLDER_ICON_NORMAL] = e_icon_factory_get_icon ("folder", E_ICON_SIZE_MENU); - folder_icons[FOLDER_ICON_INBOX] = e_icon_factory_get_icon ("mail-inbox", E_ICON_SIZE_MENU); - folder_icons[FOLDER_ICON_OUTBOX] = e_icon_factory_get_icon ("mail-outbox", E_ICON_SIZE_MENU); - folder_icons[FOLDER_ICON_TRASH] = e_icon_factory_get_icon ("user-trash", E_ICON_SIZE_MENU); - folder_icons[FOLDER_ICON_JUNK] = e_icon_factory_get_icon ("mail-mark-junk", E_ICON_SIZE_MENU); - folder_icons[FOLDER_ICON_SHARED_TO_ME] = e_icon_factory_get_icon ("stock_shared-to-me", E_ICON_SIZE_MENU); - folder_icons[FOLDER_ICON_SHARED_BY_ME] = e_icon_factory_get_icon ("stock_shared-by-me", E_ICON_SIZE_MENU); - folder_icons[FOLDER_ICON_SENT] = e_icon_factory_get_icon ("mail-sent", E_ICON_SIZE_MENU); - folder_icons[FOLDER_ICON_VIRTUAL] = e_icon_factory_get_icon ("folder-saved-search", E_ICON_SIZE_MENU); - - initialised = TRUE; - } - - gtk_tree_model_get (model, iter, COL_BOOL_IS_STORE, &is_store, COL_UINT_FLAGS, &flags, -1); - - if (!is_store) { - switch((flags & CAMEL_FOLDER_TYPE_MASK)) { - case CAMEL_FOLDER_TYPE_INBOX: - pixbuf = folder_icons[FOLDER_ICON_INBOX]; - break; - case CAMEL_FOLDER_TYPE_OUTBOX: - pixbuf = folder_icons[FOLDER_ICON_OUTBOX]; - break; - case CAMEL_FOLDER_TYPE_TRASH: - pixbuf = folder_icons[FOLDER_ICON_TRASH]; - break; - case CAMEL_FOLDER_TYPE_JUNK: - pixbuf = folder_icons[FOLDER_ICON_JUNK]; - break; - case CAMEL_FOLDER_TYPE_SENT: - pixbuf = folder_icons[FOLDER_ICON_SENT]; - break; - default: - if (flags & CAMEL_FOLDER_SHARED_TO_ME) - pixbuf = folder_icons[FOLDER_ICON_SHARED_TO_ME]; - else if (flags & CAMEL_FOLDER_SHARED_BY_ME) - pixbuf = folder_icons[FOLDER_ICON_SHARED_BY_ME]; - else if (flags & CAMEL_FOLDER_VIRTUAL) - pixbuf = folder_icons[FOLDER_ICON_VIRTUAL]; - else { - pixbuf = folder_icons[FOLDER_ICON_NORMAL]; - g_object_set (renderer, "pixbuf", pixbuf, "visible", !is_store, NULL); - gtk_tree_model_get (model, iter, COL_STRING_FULL_NAME, &folder_name, -1); - target = em_event_target_new_custom_icon (em_event_peek(), renderer, folder_name, EM_EVENT_CUSTOM_ICON); - e_event_emit ((EEvent *)em_event_peek (), "folder.customicon", (EEventTarget *) target); - return; - } - } - } - - g_object_set (renderer, "pixbuf", pixbuf, "visible", !is_store, NULL); -} - static void render_display_name (GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) @@ -413,90 +435,6 @@ emft_select_func(GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath * return (flags & emft->priv->excluded) == 0; } -static void -emft_free_select_uri(void *v, void *data) -{ - struct _selected_uri *u = v; - - g_free(u->uri); - if (u->store) - camel_object_unref(u->store); - g_free(u->key); - g_free(u->path); - g_free(u); -} - -static void -em_folder_tree_init (EMFolderTree *emft) -{ - struct _EMFolderTreePrivate *priv; - - priv = g_new0 (struct _EMFolderTreePrivate, 1); - priv->select_uris_table = g_hash_table_new(g_str_hash, g_str_equal); - priv->treeview = NULL; - priv->model = NULL; - priv->drag_row = NULL; - - emft->priv = priv; -} - -static void -em_folder_tree_finalize (GObject *obj) -{ - EMFolderTree *emft = (EMFolderTree *) obj; - - if (emft->priv->select_uris) { - g_slist_foreach(emft->priv->select_uris, emft_free_select_uri, emft); - g_slist_free(emft->priv->select_uris); - g_hash_table_destroy(emft->priv->select_uris_table); - emft->priv->select_uris = NULL; - } - - g_free (emft->priv); - - G_OBJECT_CLASS (parent_class)->finalize (obj); -} - -static void -em_folder_tree_destroy (GtkObject *obj) -{ - EMFolderTree *emft = (EMFolderTree *) obj; - struct _EMFolderTreePrivate *priv = emft->priv; - - if (priv->loading_row_id != 0) { - g_signal_handler_disconnect (priv->model, priv->loading_row_id); - priv->loading_row_id = 0; - } - - if (priv->loaded_row_id != 0) { - g_signal_handler_disconnect (priv->model, priv->loaded_row_id); - priv->loaded_row_id = 0; - } - - if (priv->save_state_id != 0) { - g_source_remove (priv->save_state_id); - emft_save_state (emft); - } - - if (priv->autoscroll_id != 0) { - g_source_remove (priv->autoscroll_id); - priv->autoscroll_id = 0; - } - - if (priv->autoexpand_id != 0) { - gtk_tree_row_reference_free (priv->autoexpand_row); - priv->autoexpand_row = NULL; - - g_source_remove (priv->autoexpand_id); - priv->autoexpand_id = 0; - } - - priv->treeview = NULL; - priv->model = NULL; - - GTK_OBJECT_CLASS (parent_class)->destroy (obj); -} - static GtkTreeView * folder_tree_new (EMFolderTree *emft, EMFolderTreeModel *model) { @@ -510,7 +448,10 @@ folder_tree_new (EMFolderTree *emft, EMFolderTreeModel *model) gconf = mail_config_get_gconf_client (); side_bar_search = gconf_client_get_bool (gconf, "/apps/evolution/mail/display/side_bar_search", NULL); - tree = gtk_tree_view_new_with_model ((GtkTreeModel *) model); + /* FIXME[KILL-BONOBO] Gross hack */ + tree = GTK_WIDGET (emft); + gtk_tree_view_set_model ( + GTK_TREE_VIEW (tree), GTK_TREE_MODEL (model)); GTK_WIDGET_SET_FLAGS(tree, GTK_CAN_FOCUS); column = gtk_tree_view_column_new (); @@ -518,7 +459,10 @@ folder_tree_new (EMFolderTree *emft, EMFolderTreeModel *model) renderer = gtk_cell_renderer_pixbuf_new (); gtk_tree_view_column_pack_start (column, renderer, FALSE); - gtk_tree_view_column_set_cell_data_func (column, renderer, render_pixbuf, NULL, NULL); + gtk_tree_view_column_add_attribute ( + column, renderer, "icon-name", COL_STRING_ICON_NAME); + gtk_tree_view_column_add_attribute ( + column, renderer, "visible", COL_BOOL_IS_FOLDER); renderer = gtk_cell_renderer_text_new (); if (!gconf_client_get_bool (gconf, "/apps/evolution/mail/display/no_folder_dots", NULL)) @@ -542,39 +486,31 @@ em_folder_tree_construct (EMFolderTree *emft, EMFolderTreeModel *model) { struct _EMFolderTreePrivate *priv = emft->priv; GtkTreeSelection *selection; - GtkWidget *scrolled; - - scrolled = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); priv->model = model; - priv->treeview = folder_tree_new (emft, model); - gtk_widget_show ((GtkWidget *) priv->treeview); + folder_tree_new (emft, model); + gtk_widget_show (GTK_WIDGET (emft)); - g_signal_connect (priv->treeview, "row-expanded", G_CALLBACK (emft_tree_row_expanded), emft); - g_signal_connect (priv->treeview, "test-collapse-row", G_CALLBACK (emft_tree_test_collapse_row), emft); - g_signal_connect (priv->treeview, "row-activated", G_CALLBACK (emft_tree_row_activated), emft); - g_signal_connect (priv->treeview, "button-press-event", G_CALLBACK (emft_tree_button_press), emft); - g_signal_connect (priv->treeview, "key-press-event", G_CALLBACK (emft_tree_user_event), emft); + g_signal_connect (emft, "row-expanded", G_CALLBACK (emft_tree_row_expanded), emft); + g_signal_connect (emft, "test-collapse-row", G_CALLBACK (emft_tree_test_collapse_row), emft); + g_signal_connect (emft, "row-activated", G_CALLBACK (emft_tree_row_activated), emft); + g_signal_connect (emft, "button-press-event", G_CALLBACK (emft_tree_button_press), emft); + g_signal_connect (emft, "key-press-event", G_CALLBACK (emft_tree_user_event), emft); - selection = gtk_tree_view_get_selection ((GtkTreeView *) priv->treeview); + selection = gtk_tree_view_get_selection ((GtkTreeView *) emft); g_signal_connect (selection, "changed", G_CALLBACK (emft_tree_selection_changed), emft); - - gtk_container_add ((GtkContainer *) scrolled, (GtkWidget *) priv->treeview); - gtk_widget_show (scrolled); - - gtk_box_pack_start ((GtkBox *) emft, scrolled, TRUE, TRUE, 0); } GtkWidget * -em_folder_tree_new (void) +em_folder_tree_new (EMailShellBackend *mail_shell_backend) { EMFolderTreeModel *model; EMFolderTree *emft; - model = em_folder_tree_model_new (e_get_user_data_dir ()); + g_return_val_if_fail ( + E_IS_MAIL_SHELL_BACKEND (mail_shell_backend), NULL); + + model = e_mail_shell_backend_get_folder_tree_model (mail_shell_backend); emft = (EMFolderTree *) em_folder_tree_new_with_model (model); g_object_unref (model); @@ -586,18 +522,20 @@ static void emft_select_uri(EMFolderTree *emft, GtkTreePath *path, struct _selected_uri *u) { struct _EMFolderTreePrivate *priv = emft->priv; + GtkTreeView *tree_view; GtkTreeSelection *selection; - selection = gtk_tree_view_get_selection(priv->treeview); + tree_view = GTK_TREE_VIEW (emft); + selection = gtk_tree_view_get_selection (tree_view); gtk_tree_selection_select_path(selection, path); if (!priv->cursor_set) { - gtk_tree_view_set_cursor (priv->treeview, path, NULL, FALSE); + gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE); priv->cursor_set = TRUE; } - gtk_tree_view_scroll_to_cell (priv->treeview, path, NULL, TRUE, 0.8f, 0.0f); + gtk_tree_view_scroll_to_cell (tree_view, path, NULL, TRUE, 0.8f, 0.0f); g_hash_table_remove(priv->select_uris_table, u->key); priv->select_uris = g_slist_remove(priv->select_uris, u); - emft_free_select_uri((void *)u, NULL); + emft_free_select_uri(u); } static void @@ -606,7 +544,9 @@ emft_expand_node (EMFolderTreeModel *model, const char *key, EMFolderTree *emft) struct _EMFolderTreePrivate *priv = emft->priv; struct _EMFolderTreeModelStoreInfo *si; extern CamelStore *vfolder_store; + EMailShellBackend *mail_shell_backend; GtkTreeRowReference *row; + GtkTreeView *tree_view; GtkTreePath *path; EAccount *account; CamelStore *store; @@ -624,7 +564,10 @@ emft_expand_node (EMFolderTreeModel *model, const char *key, EMFolderTree *emft) memcpy (uid, key, n); uid[n] = '\0'; - if ((account = mail_config_get_account_by_uid (uid)) && account->enabled) { + tree_view = GTK_TREE_VIEW (emft); + mail_shell_backend = em_folder_tree_model_get_mail_shell_backend (model); + + if ((account = e_get_account_by_uid (uid)) && account->enabled) { CamelException ex; camel_exception_init (&ex); @@ -639,7 +582,7 @@ emft_expand_node (EMFolderTreeModel *model, const char *key, EMFolderTree *emft) camel_object_ref (store); } else if (!strcmp (uid, "local")) { - if (!(store = mail_component_peek_local_store (NULL))) + if (!(store = e_mail_shell_backend_get_local_store (mail_shell_backend))) return; camel_object_ref (store); @@ -661,7 +604,7 @@ emft_expand_node (EMFolderTreeModel *model, const char *key, EMFolderTree *emft) row = si->row; path = gtk_tree_row_reference_get_path (row); - gtk_tree_view_expand_to_path (priv->treeview, path); + gtk_tree_view_expand_to_path (tree_view, path); u = g_hash_table_lookup(emft->priv->select_uris_table, key); if (u) @@ -675,6 +618,7 @@ emft_maybe_expand_row (EMFolderTreeModel *model, GtkTreePath *tree_path, GtkTree { struct _EMFolderTreePrivate *priv = emft->priv; struct _EMFolderTreeModelStoreInfo *si; + GtkTreeView *tree_view; gboolean is_store; CamelStore *store; EAccount *account; @@ -683,6 +627,8 @@ emft_maybe_expand_row (EMFolderTreeModel *model, GtkTreePath *tree_path, GtkTree struct _selected_uri *u; gboolean is_expanded; + tree_view = GTK_TREE_VIEW (emft); + gtk_tree_model_get ((GtkTreeModel *) model, iter, COL_STRING_FULL_NAME, &full_name, COL_POINTER_CAMEL_STORE, &store, @@ -690,7 +636,7 @@ emft_maybe_expand_row (EMFolderTreeModel *model, GtkTreePath *tree_path, GtkTree -1); si = g_hash_table_lookup (model->store_hash, store); - if ((account = mail_config_get_account_by_name (si->display_name))) { + if ((account = e_get_account_by_name (si->display_name))) { key = g_strdup_printf ("%s/%s", account->uid, full_name ? full_name : ""); } else if (CAMEL_IS_VEE_STORE (store)) { /* vfolder store */ @@ -704,8 +650,8 @@ emft_maybe_expand_row (EMFolderTreeModel *model, GtkTreePath *tree_path, GtkTree u = g_hash_table_lookup(priv->select_uris_table, key); if (is_expanded || u) { if (is_expanded) { - gtk_tree_view_expand_to_path (priv->treeview, tree_path); - gtk_tree_view_expand_row (priv->treeview, tree_path, FALSE); + gtk_tree_view_expand_to_path (tree_view, tree_path); + gtk_tree_view_expand_row (tree_view, tree_path, FALSE); } else { char *c = strrchr (key, '/'); @@ -736,7 +682,7 @@ em_folder_tree_new_with_model (EMFolderTreeModel *model) emft->priv->loading_row_id = g_signal_connect (model, "loading-row", G_CALLBACK (emft_maybe_expand_row), emft); emft->priv->loaded_row_id = g_signal_connect (model, "loaded-row", G_CALLBACK (emft_maybe_expand_row), emft); - a11y = gtk_widget_get_accessible (GTK_WIDGET (emft->priv->treeview)); + a11y = gtk_widget_get_accessible (GTK_WIDGET (emft)); atk_object_set_name (a11y, _("Mail Folder Tree")); return (GtkWidget *) emft; @@ -1018,6 +964,7 @@ tree_drag_data_received(GtkWidget *widget, GdkDragContext *context, int x, int y { struct _EMFolderTreePrivate *priv = emft->priv; GtkTreeViewDropPosition pos; + GtkTreeView *tree_view; GtkTreePath *dest_path; struct _DragDataReceivedAsync *m; gboolean is_store; @@ -1026,7 +973,9 @@ tree_drag_data_received(GtkWidget *widget, GdkDragContext *context, int x, int y char *full_name; int i; - if (!gtk_tree_view_get_dest_row_at_pos (priv->treeview, x, y, &dest_path, &pos)) + tree_view = GTK_TREE_VIEW (emft); + + if (!gtk_tree_view_get_dest_row_at_pos (tree_view, x, y, &dest_path, &pos)) return; /* this means we are receiving no data */ @@ -1104,6 +1053,7 @@ emft_drop_target(EMFolderTree *emft, GdkDragContext *context, GtkTreePath *path) struct _EMFolderTreePrivate *p = emft->priv; char *full_name = NULL, *uri = NULL, *src_uri = NULL; CamelStore *local, *sstore, *dstore; + EMailShellBackend *mail_shell_backend; GdkAtom atom = GDK_NONE; gboolean is_store; GtkTreeIter iter; @@ -1121,7 +1071,8 @@ emft_drop_target(EMFolderTree *emft, GdkDragContext *context, GtkTreePath *path) COL_POINTER_CAMEL_STORE, &dstore, COL_STRING_URI, &uri, -1); - local = mail_component_peek_local_store (NULL); + mail_shell_backend = em_folder_tree_model_get_mail_shell_backend (p->model); + local = e_mail_shell_backend_get_local_store (mail_shell_backend); targets = context->targets; @@ -1299,10 +1250,13 @@ tree_drag_drop (GtkWidget *widget, GdkDragContext *context, int x, int y, guint { struct _EMFolderTreePrivate *priv = emft->priv; GtkTreeViewColumn *column; + GtkTreeView *tree_view; int cell_x, cell_y; GtkTreePath *path; GdkAtom target; + tree_view = GTK_TREE_VIEW (emft); + if (priv->autoscroll_id != 0) { g_source_remove (priv->autoscroll_id); priv->autoscroll_id = 0; @@ -1316,7 +1270,7 @@ tree_drag_drop (GtkWidget *widget, GdkDragContext *context, int x, int y, guint priv->autoexpand_id = 0; } - if (!gtk_tree_view_get_path_at_pos (priv->treeview, x, y, &path, &column, &cell_x, &cell_y)) + if (!gtk_tree_view_get_path_at_pos (tree_view, x, y, &path, &column, &cell_x, &cell_y)) return FALSE; target = emft_drop_target(emft, context, path); @@ -1344,6 +1298,9 @@ static void tree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time, EMFolderTree *emft) { struct _EMFolderTreePrivate *priv = emft->priv; + GtkTreeView *tree_view; + + tree_view = GTK_TREE_VIEW (emft); if (priv->autoscroll_id != 0) { g_source_remove (priv->autoscroll_id); @@ -1358,7 +1315,7 @@ tree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time, EMFolde priv->autoexpand_id = 0; } - gtk_tree_view_set_drag_dest_row(emft->priv->treeview, NULL, GTK_TREE_VIEW_DROP_BEFORE); + gtk_tree_view_set_drag_dest_row(tree_view, NULL, GTK_TREE_VIEW_DROP_BEFORE); } @@ -1367,19 +1324,20 @@ tree_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time, EMFolde static gboolean tree_autoscroll (EMFolderTree *emft) { - struct _EMFolderTreePrivate *priv = emft->priv; GtkAdjustment *vadjustment; + GtkTreeView *tree_view; GdkRectangle rect; GdkWindow *window; int offset, y; float value; /* get the y pointer position relative to the treeview */ - window = gtk_tree_view_get_bin_window (priv->treeview); + tree_view = GTK_TREE_VIEW (emft); + window = gtk_tree_view_get_bin_window (tree_view); gdk_window_get_pointer (window, NULL, &y, NULL); /* rect is in coorinates relative to the scrolled window relative to the treeview */ - gtk_tree_view_get_visible_rect (priv->treeview, &rect); + gtk_tree_view_get_visible_rect (tree_view, &rect); /* move y into the same coordinate system as rect */ y += rect.y; @@ -1391,7 +1349,7 @@ tree_autoscroll (EMFolderTree *emft) return TRUE; } - vadjustment = gtk_tree_view_get_vadjustment (priv->treeview); + vadjustment = gtk_tree_view_get_vadjustment (tree_view); value = CLAMP (vadjustment->value + offset, 0.0, vadjustment->upper - vadjustment->page_size); gtk_adjustment_set_value (vadjustment, value); @@ -1403,10 +1361,12 @@ static gboolean tree_autoexpand (EMFolderTree *emft) { struct _EMFolderTreePrivate *priv = emft->priv; + GtkTreeView *tree_view; GtkTreePath *path; + tree_view = GTK_TREE_VIEW (emft); path = gtk_tree_row_reference_get_path (priv->autoexpand_row); - gtk_tree_view_expand_row (priv->treeview, path, FALSE); + gtk_tree_view_expand_row (tree_view, path, FALSE); gtk_tree_path_free (path); return TRUE; @@ -1418,13 +1378,16 @@ tree_drag_motion (GtkWidget *widget, GdkDragContext *context, int x, int y, guin struct _EMFolderTreePrivate *priv = emft->priv; GtkTreeModel *model = (GtkTreeModel *) priv->model; GtkTreeViewDropPosition pos; + GtkTreeView *tree_view; GdkDragAction action = 0; GtkTreePath *path; GtkTreeIter iter; GdkAtom target; int i; - if (!gtk_tree_view_get_dest_row_at_pos(priv->treeview, x, y, &path, &pos)) + tree_view = GTK_TREE_VIEW (emft); + + if (!gtk_tree_view_get_dest_row_at_pos(tree_view, x, y, &path, &pos)) return FALSE; if (priv->autoscroll_id == 0) @@ -1432,7 +1395,7 @@ tree_drag_motion (GtkWidget *widget, GdkDragContext *context, int x, int y, guin gtk_tree_model_get_iter (model, &iter, path); - if (gtk_tree_model_iter_has_child (model, &iter) && !gtk_tree_view_row_expanded (priv->treeview, path)) { + if (gtk_tree_model_iter_has_child (model, &iter) && !gtk_tree_view_row_expanded (tree_view, path)) { if (priv->autoexpand_id != 0) { GtkTreePath *autoexpand_path; @@ -1468,10 +1431,10 @@ tree_drag_motion (GtkWidget *widget, GdkDragContext *context, int x, int y, guin action = context->suggested_action; if (action == GDK_ACTION_COPY && (context->actions & GDK_ACTION_MOVE)) action = GDK_ACTION_MOVE; - gtk_tree_view_set_drag_dest_row(priv->treeview, path, GTK_TREE_VIEW_DROP_INTO_OR_AFTER); + gtk_tree_view_set_drag_dest_row(tree_view, path, GTK_TREE_VIEW_DROP_INTO_OR_AFTER); break; default: - gtk_tree_view_set_drag_dest_row(priv->treeview, path, GTK_TREE_VIEW_DROP_INTO_OR_AFTER); + gtk_tree_view_set_drag_dest_row(tree_view, path, GTK_TREE_VIEW_DROP_INTO_OR_AFTER); action = context->suggested_action; break; } @@ -1491,11 +1454,14 @@ void em_folder_tree_enable_drag_and_drop (EMFolderTree *emft) { struct _EMFolderTreePrivate *priv; + GtkTreeView *tree_view; static int setup = 0; int i; g_return_if_fail (EM_IS_FOLDER_TREE (emft)); + tree_view = GTK_TREE_VIEW (emft); + priv = emft->priv; if (!setup) { for (i=0; i<NUM_DRAG_TYPES; i++) @@ -1507,23 +1473,27 @@ em_folder_tree_enable_drag_and_drop (EMFolderTree *emft) setup = 1; } - gtk_drag_source_set((GtkWidget *)priv->treeview, GDK_BUTTON1_MASK, drag_types, NUM_DRAG_TYPES, GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK); - gtk_drag_dest_set((GtkWidget *)priv->treeview, GTK_DEST_DEFAULT_ALL, drop_types, NUM_DROP_TYPES, GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK); + gtk_drag_source_set((GtkWidget *)tree_view, GDK_BUTTON1_MASK, drag_types, NUM_DRAG_TYPES, GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK); + gtk_drag_dest_set((GtkWidget *)tree_view, GTK_DEST_DEFAULT_ALL, drop_types, NUM_DROP_TYPES, GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK); - g_signal_connect (priv->treeview, "drag-begin", G_CALLBACK (tree_drag_begin), emft); - g_signal_connect (priv->treeview, "drag-data-delete", G_CALLBACK (tree_drag_data_delete), emft); - g_signal_connect (priv->treeview, "drag-data-get", G_CALLBACK (tree_drag_data_get), emft); - g_signal_connect (priv->treeview, "drag-data-received", G_CALLBACK (tree_drag_data_received), emft); - g_signal_connect (priv->treeview, "drag-drop", G_CALLBACK (tree_drag_drop), emft); - g_signal_connect (priv->treeview, "drag-end", G_CALLBACK (tree_drag_end), emft); - g_signal_connect (priv->treeview, "drag-leave", G_CALLBACK (tree_drag_leave), emft); - g_signal_connect (priv->treeview, "drag-motion", G_CALLBACK (tree_drag_motion), emft); + g_signal_connect (tree_view, "drag-begin", G_CALLBACK (tree_drag_begin), emft); + g_signal_connect (tree_view, "drag-data-delete", G_CALLBACK (tree_drag_data_delete), emft); + g_signal_connect (tree_view, "drag-data-get", G_CALLBACK (tree_drag_data_get), emft); + g_signal_connect (tree_view, "drag-data-received", G_CALLBACK (tree_drag_data_received), emft); + g_signal_connect (tree_view, "drag-drop", G_CALLBACK (tree_drag_drop), emft); + g_signal_connect (tree_view, "drag-end", G_CALLBACK (tree_drag_end), emft); + g_signal_connect (tree_view, "drag-leave", G_CALLBACK (tree_drag_leave), emft); + g_signal_connect (tree_view, "drag-motion", G_CALLBACK (tree_drag_motion), emft); } void em_folder_tree_set_multiselect (EMFolderTree *tree, gboolean mode) { - GtkTreeSelection *sel = gtk_tree_view_get_selection ((GtkTreeView *) tree->priv->treeview); + GtkTreeSelection *sel; + GtkTreeView *tree_view; + + tree_view = GTK_TREE_VIEW (tree); + sel = gtk_tree_view_get_selection (tree_view); tree->priv->do_multiselect = mode; gtk_tree_selection_set_mode (sel, mode ? GTK_SELECTION_MULTIPLE : GTK_SELECTION_SINGLE); @@ -1543,10 +1513,14 @@ void em_folder_tree_set_excluded_func(EMFolderTree *emft, EMFTExcludeFunc exclud GList * em_folder_tree_get_selected_uris (EMFolderTree *emft) { - GtkTreeSelection *selection = gtk_tree_view_get_selection (emft->priv->treeview); + GtkTreeSelection *selection; + GtkTreeView *tree_view; + GtkTreeModel *model; GList *list = NULL, *rows, *l; GSList *sl; - GtkTreeModel *model; + + tree_view = GTK_TREE_VIEW (emft); + selection = gtk_tree_view_get_selection (tree_view); /* at first, add lost uris */ for (sl = emft->priv->select_uris; sl; sl = g_slist_next(sl)) @@ -1583,9 +1557,13 @@ get_selected_uris_path_iterate (GtkTreeModel *model, GtkTreePath *treepath, GtkT GList * em_folder_tree_get_selected_paths (EMFolderTree *emft) { - GtkTreeSelection *selection = gtk_tree_view_get_selection (emft->priv->treeview); + GtkTreeSelection *selection; + GtkTreeView *tree_view; GList *list = NULL; + tree_view = GTK_TREE_VIEW (emft); + selection = gtk_tree_view_get_selection (tree_view); + gtk_tree_selection_selected_foreach (selection, get_selected_uris_path_iterate, &list); return list; @@ -1596,7 +1574,7 @@ emft_clear_selected_list(EMFolderTree *emft) { struct _EMFolderTreePrivate *priv = emft->priv; - g_slist_foreach(priv->select_uris, emft_free_select_uri, emft); + g_slist_foreach(priv->select_uris, (GFunc) emft_free_select_uri, NULL); g_slist_free(priv->select_uris); g_hash_table_destroy(priv->select_uris_table); priv->select_uris = NULL; @@ -1734,13 +1712,13 @@ emft_get_folder_info__done (struct _EMFolderTreeGetFolderInfo *m) struct _EMFolderTreeModelStoreInfo *si; GtkTreeIter root, iter, titer; CamelFolderInfo *fi; + GtkTreeView *tree_view; GtkTreeStore *model; GtkTreePath *path; gboolean is_store; /* check that we haven't been destroyed */ - if (priv->treeview == NULL) - return; + g_return_if_fail (GTK_IS_TREE_VIEW (m->emft)); /* check that our parent folder hasn't been deleted/unsubscribed */ if (!gtk_tree_row_reference_valid (m->root)) @@ -1751,7 +1729,8 @@ emft_get_folder_info__done (struct _EMFolderTreeGetFolderInfo *m) return; } - model = (GtkTreeStore *) gtk_tree_view_get_model (priv->treeview); + tree_view = GTK_TREE_VIEW (m->emft); + model = (GtkTreeStore *) gtk_tree_view_get_model (tree_view); path = gtk_tree_row_reference_get_path (m->root); gtk_tree_model_get_iter ((GtkTreeModel *) model, &root, path); @@ -1759,7 +1738,7 @@ emft_get_folder_info__done (struct _EMFolderTreeGetFolderInfo *m) /* if we had an error, then we need to re-set the load subdirs state and collapse the node */ if (!m->fi && camel_exception_is_set(&m->base.ex)) { gtk_tree_store_set(model, &root, COL_BOOL_LOAD_SUBDIRS, TRUE, -1); - gtk_tree_view_collapse_row (priv->treeview, path); + gtk_tree_view_collapse_row (tree_view, path); gtk_tree_path_free (path); return; } @@ -1798,7 +1777,7 @@ emft_get_folder_info__done (struct _EMFolderTreeGetFolderInfo *m) if (is_store) { path = gtk_tree_model_get_path ((GtkTreeModel *) model, &root); - gtk_tree_view_collapse_row (priv->treeview, path); + gtk_tree_view_collapse_row (tree_view, path); emft_queue_save_state (m->emft); gtk_tree_path_free (path); return; @@ -1854,7 +1833,7 @@ emft_update_model_expanded_state (struct _EMFolderTreePrivate *priv, GtkTreeIter -1); si = g_hash_table_lookup (priv->model->store_hash, store); - if ((account = mail_config_get_account_by_name (si->display_name))) { + if ((account = e_get_account_by_name (si->display_name))) { key = g_strdup_printf ("%s/%s", account->uid, full_name ? full_name : ""); } else if (CAMEL_IS_VEE_STORE (store)) { /* vfolder store */ @@ -1957,53 +1936,6 @@ emft_tree_row_activated (GtkTreeView *treeview, GtkTreePath *tree_path, GtkTreeV g_free(uri); } -#if 0 -static void -emft_popup_view (GtkWidget *item, EMFolderTree *emft) -{ - -} - -static void -emft_popup_open_new (GtkWidget *item, EMFolderTree *emft) -{ -} -#endif - -static void -emft_popup_copy(EPopup *ep, EPopupItem *item, void *data) -{ - EMFolderTree *emft = data; - CamelFolderInfo *fi = NULL; - - /* FIXME: use async apis */ - if ((fi = em_folder_tree_get_selected_folder_info (emft)) != NULL) - em_folder_utils_copy_folder(fi, FALSE); -} - -static void -emft_popup_move(EPopup *ep, EPopupItem *item, void *data) -{ - EMFolderTree *emft = data; - CamelFolderInfo *fi = NULL; - - /* FIXME: use async apis */ - if ((fi = em_folder_tree_get_selected_folder_info (emft)) != NULL) - em_folder_utils_copy_folder(fi, TRUE); -} - -static void -emft_popup_new_folder (EPopup *ep, EPopupItem *pitem, void *data) -{ - EMFolderTree *emft = data; - CamelFolderInfo *fi; - - if ((fi = em_folder_tree_get_selected_folder_info (emft)) != NULL) { - em_folder_utils_create_folder (fi, emft, NULL); - camel_folder_info_free(fi); - } -} - static void selfunc (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { @@ -2030,247 +1962,15 @@ emft_selection_get_selected (GtkTreeSelection *selection, GtkTreeModel **model, } } -static void -emft_popup_delete_folder (EPopup *ep, EPopupItem *pitem, void *data) -{ - EMFolderTree *emft = data; - CamelFolder *folder; - - if ((folder = em_folder_tree_get_selected_folder (emft)) != NULL) { - em_folder_utils_delete_folder(folder); - } -} - -static void -emft_popup_rename_folder (EPopup *ep, EPopupItem *pitem, void *data) -{ - EMFolderTree *emft = data; - CamelFolder *folder; - - if ((folder = em_folder_tree_get_selected_folder (emft)) != NULL) { - em_folder_utils_rename_folder(folder); - } -} - -static void -emft_popup_refresh_folder (EPopup *ep, EPopupItem *pitem, void *data) -{ - EMFolderTree *emft = data; - CamelFolder *folder; - - if ((folder = em_folder_tree_get_selected_folder (emft)) != NULL) - mail_refresh_folder(folder, NULL, NULL); -} - -static void -emft_popup_flush_outbox (EPopup *ep, EPopupItem *pitem, void *data) -{ - mail_send (); -} - -static void -emft_popup_empty_trash (EPopup *ep, EPopupItem *pitem, void *data) -{ - em_utils_empty_trash (data); -} - -static void -emft_popup_properties (EPopup *ep, EPopupItem *pitem, void *data) -{ - EMFolderTree *emft = data; - struct _EMFolderTreePrivate *priv = emft->priv; - GtkTreeSelection *selection; - GtkTreeModel *model; - GtkTreeIter iter; - char *uri; - - 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_URI, &uri, -1); - em_folder_properties_show (NULL, NULL, uri); - g_free (uri); -} - -static void -emft_popup_uvfolder (EPopup *ep, EPopupItem *pitem, void *data) -{ - EMFolderTree *emft = data; - CamelFolder *folder; - - if ((folder = em_folder_tree_get_selected_folder (emft)) != NULL) { - char *meta = camel_object_meta_get(folder, "vfolder:unread"); - if (!meta || strcmp(meta, "false") == 0) - camel_object_meta_set(folder, "vfolder:unread", "true"); - else - camel_object_meta_set(folder, "vfolder:unread", "false"); - camel_object_state_write (folder); - g_free (meta); - } -} - -static EPopupItem emft_popup_items[] = { -#if 0 - { E_POPUP_ITEM, "00.emc.00", N_("_View"), emft_popup_view, NULL, NULL, EM_POPUP_FOLDER_SELECT }, - { E_POPUP_ITEM, "00.emc.01", N_("Open in _New Window"), emft_popup_open_new, NULL, NULL, EM_POPUP_FOLDER_SELECT }, - - { E_POPUP_BAR, "10.emc" }, -#endif - /* FIXME: need to disable for nochildren folders */ - { E_POPUP_ITEM, "10.emc.00", N_("_New Folder..."), emft_popup_new_folder, NULL, "folder-new", 0, EM_POPUP_FOLDER_INFERIORS }, - - { E_POPUP_ITEM, "10.emc.05", N_("_Copy..."), emft_popup_copy, NULL, "folder-copy", 0, EM_POPUP_FOLDER_FOLDER|EM_POPUP_FOLDER_SELECT }, - { E_POPUP_ITEM, "10.emc.06", N_("_Move..."), emft_popup_move, NULL, "folder-move", 0, EM_POPUP_FOLDER_FOLDER|EM_POPUP_FOLDER_DELETE }, - - /* FIXME: need to disable for undeletable folders */ - { E_POPUP_BAR, "20.emc" }, - { E_POPUP_ITEM, "20.emc.01", N_("_Delete"), emft_popup_delete_folder, NULL, "edit-delete", 0, EM_POPUP_FOLDER_FOLDER|EM_POPUP_FOLDER_DELETE }, - - { E_POPUP_BAR, "30.emc" }, - { E_POPUP_ITEM, "30.emc.02", N_("_Rename..."), emft_popup_rename_folder, NULL, NULL, 0, EM_POPUP_FOLDER_FOLDER|EM_POPUP_FOLDER_DELETE }, - { E_POPUP_ITEM, "30.emc.03", N_("Re_fresh"), emft_popup_refresh_folder, NULL, "view-refresh", EM_POPUP_FOLDER_NONSTATIC, EM_POPUP_FOLDER_FOLDER|EM_POPUP_FOLDER_SELECT}, - { E_POPUP_ITEM, "30.emc.04", N_("Fl_ush Outbox"), emft_popup_flush_outbox, NULL, "mail-send", EM_POPUP_FOLDER_OUTBOX, 0 }, - - - { E_POPUP_BAR, "99.emc" }, - { E_POPUP_ITEM, "99.emc.00", N_("_Properties"), emft_popup_properties, NULL, "document-properties", 0, EM_POPUP_FOLDER_FOLDER|EM_POPUP_FOLDER_SELECT } -}; -static EPopupItem trash_popup_item = {E_POPUP_ITEM, "30.emc.05", N_("_Empty Trash"), emft_popup_empty_trash,NULL,NULL, 1, EM_POPUP_FOLDER_FOLDER|EM_POPUP_FOLDER_SELECT}; - -static void -emft_popup_free(EPopup *ep, GSList *items, void *data) -{ - g_slist_free(items); -} - static gboolean -emft_popup (EMFolderTree *emft, GdkEvent *event) +emft_popup_menu (GtkWidget *widget) { - GtkTreeView *treeview; - GtkTreeSelection *selection; - CamelStore *local, *store; - EMPopupTargetFolder *target; - GtkTreeModel *model; - GtkTreeIter iter; - GSList *menus = NULL; - guint32 info_flags = 0; - guint32 flags = 0; - guint32 folder_type_flags = 0; - gboolean isstore; - char *uri, *full_name; - GtkMenu *menu; - EMPopup *emp; - CamelFolder *selfolder = NULL; - int i; - - treeview = emft->priv->treeview; - - /* this centralises working out when the user's done something */ - emft_tree_user_event(treeview, (GdkEvent *)event, emft); - - /* FIXME: we really need the folderinfo to build a proper menu */ - selection = gtk_tree_view_get_selection (treeview); - if (!emft_selection_get_selected (selection, &model, &iter)) - return FALSE; - - gtk_tree_model_get (model, &iter, COL_POINTER_CAMEL_STORE, &store, - COL_STRING_URI, &uri, COL_STRING_FULL_NAME, &full_name, - COL_BOOL_IS_STORE, &isstore, COL_UINT_FLAGS, &folder_type_flags, -1); - - /* Stores have full_name == NULL, otherwise its just a placeholder */ - /* NB: This is kind of messy */ - if (!isstore && full_name == NULL) { - g_free (uri); - return FALSE; - } - - /* TODO: em_popup_target_folder_new? */ - if (isstore) { - flags |= EM_POPUP_FOLDER_STORE; - } else { - flags |= EM_POPUP_FOLDER_FOLDER; - - local = mail_component_peek_local_store (NULL); - - /* don't allow deletion of special local folders */ - if (!(store == local && is_special_local_folder (full_name))) - flags |= EM_POPUP_FOLDER_DELETE; - - /* hack for vTrash/vJunk */ - if (!strcmp (full_name, CAMEL_VTRASH_NAME) || !strcmp (full_name, CAMEL_VJUNK_NAME)) - info_flags |= CAMEL_FOLDER_VIRTUAL | CAMEL_FOLDER_NOINFERIORS; - - selfolder = em_folder_tree_get_selected_folder (emft); - - if (folder_type_flags & CAMEL_FOLDER_SYSTEM) - flags &= ~EM_POPUP_FOLDER_DELETE; - - if (em_utils_folder_is_outbox (selfolder, NULL)) - info_flags |= CAMEL_FOLDER_TYPE_OUTBOX; - } - - /** @HookPoint-EMPopup: Folder Tree Context Menu - * @Id: org.gnome.evolution.mail.foldertree.popup - * @Class: org.gnome.evolution.mail.popup:1.0 - * @Target: EMPopupTargetFolder - * - * This is the context menu shown on the folder tree. - */ - emp = em_popup_new ("org.gnome.evolution.mail.foldertree.popup"); - - /* FIXME: pass valid fi->flags here */ - target = em_popup_target_new_folder (emp, uri, info_flags, flags); - - for (i = 0; i < sizeof (emft_popup_items) / sizeof (emft_popup_items[0]); i++) - menus = g_slist_prepend (menus, &emft_popup_items[i]); - - if ((folder_type_flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_TRASH) - menus = g_slist_prepend (menus, &trash_popup_item); - if (!isstore && strstr(uri, "vfolder")) { - /* This is a vfolder, so lets add hacked up menu item. */ - static EPopupItem *item = NULL; - char *meta = camel_object_meta_get (selfolder, "vfolder:unread"); - - if (!item) - item = g_malloc0(sizeof(*item)); - if (meta && (strcmp (meta, "true") == 0)) - item->type = E_POPUP_TOGGLE | E_POPUP_ACTIVE; - else - item->type = E_POPUP_TOGGLE & ~E_POPUP_ACTIVE; - item->path = "99.emc.99"; - item->label = _("_Unread Search Folder"); - item->activate = emft_popup_uvfolder; - item->visible = EM_POPUP_FOLDER_SELECT; - item->user_data = NULL; - menus = g_slist_prepend (menus, item); - g_free (meta); - } - - e_popup_add_items ((EPopup *)emp, menus, NULL, emft_popup_free, emft); - - menu = e_popup_create_menu_once ((EPopup *)emp, (EPopupTarget *)target, 0); - - if (event == NULL || event->type == GDK_KEY_PRESS) { - /* FIXME: menu pos function */ - gtk_menu_popup (menu, NULL, NULL, NULL, NULL, 0, gtk_get_current_event_time()); - } else { - gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event->button.button, event->button.time); - } - - g_free (full_name); - g_free (uri); + folder_tree_emit_popup_event (EM_FOLDER_TREE (widget), NULL); return TRUE; } static gboolean -emft_popup_menu (GtkWidget *widget) -{ - return emft_popup (EM_FOLDER_TREE (widget), NULL); -} - -static gboolean emft_tree_button_press (GtkTreeView *treeview, GdkEventButton *event, EMFolderTree *emft) { GtkTreeSelection *selection; @@ -2298,7 +1998,9 @@ emft_tree_button_press (GtkTreeView *treeview, GdkEventButton *event, EMFolderTr gtk_tree_path_free (tree_path); - return emft_popup (emft, (GdkEvent *)event); + folder_tree_emit_popup_event (emft, (GdkEvent *) event); + + return TRUE; } /* This is called for keyboard and mouse events, it seems the only way @@ -2357,6 +2059,7 @@ em_folder_tree_set_selected (EMFolderTree *emft, const char *uri, gboolean expan void em_folder_tree_select_next_path (EMFolderTree *emft, gboolean skip_read_folders) { + GtkTreeView *tree_view; GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeIter iter, parent, child; @@ -2366,7 +2069,8 @@ em_folder_tree_select_next_path (EMFolderTree *emft, gboolean skip_read_folders) g_return_if_fail (EM_IS_FOLDER_TREE (emft)); - selection = gtk_tree_view_get_selection(emft->priv->treeview); + tree_view = GTK_TREE_VIEW (emft); + selection = gtk_tree_view_get_selection(tree_view); if (gtk_tree_selection_get_selected(selection, &model, &iter)) { current_path = gtk_tree_model_get_path (model, &iter); @@ -2401,16 +2105,16 @@ em_folder_tree_select_next_path (EMFolderTree *emft, gboolean skip_read_folders) } if (path) { - if (!gtk_tree_view_row_expanded (emft->priv->treeview, path)) - gtk_tree_view_expand_to_path (emft->priv->treeview, path); + if (!gtk_tree_view_row_expanded (tree_view, path)) + gtk_tree_view_expand_to_path (tree_view, path); gtk_tree_selection_select_path(selection, path); if (!priv->cursor_set) { - gtk_tree_view_set_cursor (priv->treeview, path, NULL, FALSE); + gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE); priv->cursor_set = TRUE; } - gtk_tree_view_scroll_to_cell (priv->treeview, path, NULL, TRUE, 0.5f, 0.0f); + gtk_tree_view_scroll_to_cell (tree_view, path, NULL, TRUE, 0.5f, 0.0f); } return; } @@ -2436,6 +2140,7 @@ get_last_child (GtkTreeModel *model, GtkTreeIter *iter) void em_folder_tree_select_prev_path (EMFolderTree *emft, gboolean skip_read_folders) { + GtkTreeView *tree_view; GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeIter iter, child; @@ -2445,7 +2150,8 @@ em_folder_tree_select_prev_path (EMFolderTree *emft, gboolean skip_read_folders) g_return_if_fail (EM_IS_FOLDER_TREE (emft)); - selection = gtk_tree_view_get_selection(emft->priv->treeview); + tree_view = GTK_TREE_VIEW (emft); + selection = gtk_tree_view_get_selection (tree_view); if (gtk_tree_selection_get_selected(selection, &model, &iter)){ @@ -2479,17 +2185,17 @@ em_folder_tree_select_prev_path (EMFolderTree *emft, gboolean skip_read_folders) } if (path) { - if (!gtk_tree_view_row_expanded (priv->treeview, path)) { - gtk_tree_view_expand_to_path (priv->treeview, path); + if (!gtk_tree_view_row_expanded (tree_view, path)) { + gtk_tree_view_expand_to_path (tree_view, path); } gtk_tree_selection_select_path(selection, path); if (!priv->cursor_set) { - gtk_tree_view_set_cursor (priv->treeview, path, NULL, FALSE); + gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE); priv->cursor_set = TRUE; } - gtk_tree_view_scroll_to_cell (priv->treeview, path, NULL, TRUE, 0.5f, 0.0f); + gtk_tree_view_scroll_to_cell (tree_view, path, NULL, TRUE, 0.5f, 0.0f); } return; } @@ -2498,6 +2204,7 @@ em_folder_tree_select_prev_path (EMFolderTree *emft, gboolean skip_read_folders) char * em_folder_tree_get_selected_uri (EMFolderTree *emft) { + GtkTreeView *tree_view; GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeIter iter; @@ -2505,7 +2212,9 @@ em_folder_tree_get_selected_uri (EMFolderTree *emft) g_return_val_if_fail (EM_IS_FOLDER_TREE (emft), NULL); - selection = gtk_tree_view_get_selection(emft->priv->treeview); + tree_view = GTK_TREE_VIEW (emft); + selection = gtk_tree_view_get_selection (tree_view); + if (gtk_tree_selection_get_selected(selection, &model, &iter)) gtk_tree_model_get(model, &iter, COL_STRING_URI, &uri, -1); @@ -2515,6 +2224,7 @@ em_folder_tree_get_selected_uri (EMFolderTree *emft) char * em_folder_tree_get_selected_path (EMFolderTree *emft) { + GtkTreeView *tree_view; GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeIter iter; @@ -2522,7 +2232,9 @@ em_folder_tree_get_selected_path (EMFolderTree *emft) g_return_val_if_fail (EM_IS_FOLDER_TREE (emft), NULL); - selection = gtk_tree_view_get_selection(emft->priv->treeview); + tree_view = GTK_TREE_VIEW (emft); + selection = gtk_tree_view_get_selection (tree_view); + if (gtk_tree_selection_get_selected(selection, &model, &iter)) gtk_tree_model_get(model, &iter, COL_STRING_FULL_NAME, &name, -1); @@ -2532,6 +2244,7 @@ em_folder_tree_get_selected_path (EMFolderTree *emft) CamelFolder * em_folder_tree_get_selected_folder (EMFolderTree *emft) { + GtkTreeView *tree_view; GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeIter iter; @@ -2544,7 +2257,9 @@ em_folder_tree_get_selected_folder (EMFolderTree *emft) camel_exception_init (&ex); - selection = gtk_tree_view_get_selection(emft->priv->treeview); + tree_view = GTK_TREE_VIEW (emft); + selection = gtk_tree_view_get_selection (tree_view); + 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); @@ -2560,6 +2275,7 @@ em_folder_tree_get_selected_folder (EMFolderTree *emft) CamelFolderInfo * em_folder_tree_get_selected_folder_info (EMFolderTree *emft) { + GtkTreeView *tree_view; GtkTreeSelection *selection; GtkTreeModel *model; GtkTreeIter iter; @@ -2572,7 +2288,9 @@ em_folder_tree_get_selected_folder_info (EMFolderTree *emft) camel_exception_init (&ex); - selection = gtk_tree_view_get_selection(emft->priv->treeview); + tree_view = GTK_TREE_VIEW (emft); + selection = gtk_tree_view_get_selection (tree_view); + 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, |