#include <tny-account-store.h>
#include <tny-account.h>
#include <tny-folder.h>
+#include <tny-camel-folder.h>
#include <modest-tny-folder.h>
#include <modest-marshal.h>
#include <modest-icon-names.h>
-#include <modest-icon-factory.h>
#include <modest-tny-account-store.h>
#include <modest-text-utils.h>
-
+#include <modest-runtime.h>
#include "modest-folder-view.h"
/* 'private'/'protected' functions */
static gboolean update_model_empty (ModestFolderView *self);
static void on_selection_changed (GtkTreeSelection *sel, gpointer data);
-static void on_subscription_changed (TnyStoreAccount *store_account, TnyFolder *folder,
- ModestFolderView *self);
-
-static gboolean modest_folder_view_update_model (ModestFolderView *self,
- TnyAccountStore *account_store);
-
-static void modest_folder_view_disconnect_store_account_handlers (GtkTreeView *self);
+/* static void on_subscription_changed (TnyStoreAccount *store_account, TnyFolder *folder, */
+/* ModestFolderView *self); */
static gint cmp_rows (GtkTreeModel *tree_model, GtkTreeIter *iter1, GtkTreeIter *iter2,
gpointer user_data);
typedef struct _ModestFolderViewPrivate ModestFolderViewPrivate;
struct _ModestFolderViewPrivate {
-
TnyAccountStore *account_store;
TnyFolder *cur_folder;
gulong sig1, sig2;
- gulong *store_accounts_handlers;
GMutex *lock;
GtkTreeSelection *cur_selection;
TnyFolderStoreQuery *query;
}
+
static void
text_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer,
GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
gchar *fname;
gint unread;
TnyFolderType type;
+ TnyFolder *folder;
g_return_if_fail (column);
g_return_if_fail (tree_model);
TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &fname,
TNY_GTK_FOLDER_STORE_TREE_MODEL_UNREAD_COLUMN, &unread,
TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
+ TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder,
-1);
rendobj = G_OBJECT(renderer);
if (!fname)
return;
-
+
+ if (folder && type != TNY_FOLDER_TYPE_ROOT) { /* FIXME: tnymail bug? crashes with root folders */
+ if (modest_tny_folder_is_local_folder (folder)) {
+ TnyFolderType type;
+ type = modest_tny_folder_get_local_folder_type (folder);
+ if (type != TNY_FOLDER_TYPE_UNKNOWN) {
+ g_free (fname);
+ fname = g_strdup(modest_local_folder_info_get_type_display_name (type));
+ }
+ }
+ } else if (folder && type == TNY_FOLDER_TYPE_ROOT) {
+ if (strcmp (fname, MODEST_LOCAL_FOLDERS_ACCOUNT_NAME) == 0) {/* FIXME: hack */
+ g_free (fname);
+ fname = g_strdup (MODEST_LOCAL_FOLDERS_DISPLAY_NAME);
+ }
+ }
+
if (unread > 0) {
gchar *folder_title = g_strdup_printf ("%s (%d)", fname, unread);
g_object_set (rendobj,"text", folder_title, "weight", 800, NULL);
}
+static GdkPixbuf*
+get_cached_icon (const gchar *name)
+{
+ GError *err = NULL;
+ gpointer pixbuf;
+ gpointer orig_key;
+ static GHashTable *icon_cache = NULL;
+
+ g_return_val_if_fail (name, NULL);
+
+ if (G_UNLIKELY(!icon_cache))
+ icon_cache = modest_cache_mgr_get_cache (modest_runtime_get_cache_mgr(),
+ MODEST_CACHE_MGR_CACHE_TYPE_PIXBUF);
+
+ if (!icon_cache || !g_hash_table_lookup_extended (icon_cache, name, &orig_key, &pixbuf)) {
+ pixbuf = (gpointer)gdk_pixbuf_new_from_file (name, &err);
+ if (!pixbuf) {
+ g_printerr ("modest: error in icon factory while loading '%s': %s\n",
+ name, err->message);
+ g_error_free (err);
+ }
+ /* if we cannot find it, we still insert (if we have a cache), so we get the error
+ * only once */
+ if (icon_cache)
+ g_hash_table_insert (icon_cache, g_strdup(name),(gpointer)pixbuf);
+ }
+ return GDK_PIXBUF(pixbuf);
+}
+
static void
icon_cell_data (GtkTreeViewColumn *column, GtkCellRenderer *renderer,
TNY_GTK_FOLDER_STORE_TREE_MODEL_UNREAD_COLUMN, &unread, -1);
rendobj = G_OBJECT(renderer);
- if (type == TNY_FOLDER_TYPE_NORMAL || type == TNY_FOLDER_TYPE_UNKNOWN)
+ if (type == TNY_FOLDER_TYPE_NORMAL || type == TNY_FOLDER_TYPE_UNKNOWN) {
type = modest_tny_folder_guess_folder_type_from_name (fname);
+ }
g_free (fname);
switch (type) {
case TNY_FOLDER_TYPE_ROOT:
- pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_ACCOUNT);
+ pixbuf = get_cached_icon (MODEST_FOLDER_ICON_ACCOUNT);
break;
case TNY_FOLDER_TYPE_INBOX:
- pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_INBOX);
+ pixbuf = get_cached_icon (MODEST_FOLDER_ICON_INBOX);
break;
case TNY_FOLDER_TYPE_OUTBOX:
- pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_OUTBOX);
+ pixbuf = get_cached_icon (MODEST_FOLDER_ICON_OUTBOX);
break;
case TNY_FOLDER_TYPE_JUNK:
- pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_JUNK);
+ pixbuf = get_cached_icon (MODEST_FOLDER_ICON_JUNK);
break;
case TNY_FOLDER_TYPE_SENT:
- pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_SENT);
+ pixbuf = get_cached_icon (MODEST_FOLDER_ICON_SENT);
+ break;
+ case TNY_FOLDER_TYPE_TRASH:
+ pixbuf = get_cached_icon (MODEST_FOLDER_ICON_TRASH);
break;
case TNY_FOLDER_TYPE_DRAFTS:
- pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_DRAFTS);
+ pixbuf = get_cached_icon (MODEST_FOLDER_ICON_DRAFTS);
break;
case TNY_FOLDER_TYPE_NOTES:
- pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_NOTES);
+ pixbuf = get_cached_icon (MODEST_FOLDER_ICON_NOTES);
break;
case TNY_FOLDER_TYPE_CALENDAR:
- pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_CALENDAR);
+ pixbuf = get_cached_icon (MODEST_FOLDER_ICON_CALENDAR);
break;
case TNY_FOLDER_TYPE_CONTACTS:
- pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_CONTACTS);
+ pixbuf = get_cached_icon (MODEST_FOLDER_ICON_CONTACTS);
break;
case TNY_FOLDER_TYPE_NORMAL:
default:
- pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_NORMAL);
- break;
+ pixbuf = get_cached_icon (MODEST_FOLDER_ICON_NORMAL);
+ break;
}
-
- g_object_set (rendobj,
- "pixbuf-expander-open",
- modest_icon_factory_get_icon (MODEST_FOLDER_ICON_OPEN),
- "pixbuf-expander-closed",
- modest_icon_factory_get_icon (MODEST_FOLDER_ICON_CLOSED),
- "pixbuf", pixbuf,
- NULL);
+ g_object_set (rendobj, "pixbuf", pixbuf, NULL);
}
static void
}
static void
-modest_folder_view_disconnect_store_account_handlers (GtkTreeView *self)
-{
- TnyIterator *iter;
- ModestFolderViewPrivate *priv;
- GtkTreeModel *model;
- GtkTreeModelSort *sortable;
- gint i = 0;
-
- sortable = GTK_TREE_MODEL_SORT (gtk_tree_view_get_model (self));
- if (!sortable)
- return;
-
- model = gtk_tree_model_sort_get_model (sortable);
- if (!model)
- return;
-
- priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
- iter = tny_list_create_iterator (TNY_LIST (model));
- while (!tny_iterator_is_done (iter)) {
- g_signal_handler_disconnect (G_OBJECT (tny_iterator_get_current (iter)),
- priv->store_accounts_handlers [i++]);
- tny_iterator_next (iter);
- }
- g_object_unref (G_OBJECT (iter));
-}
-
-
-static void
modest_folder_view_finalize (GObject *obj)
{
ModestFolderViewPrivate *priv;
priv->lock = NULL;
}
- if (priv->store_accounts_handlers) {
- modest_folder_view_disconnect_store_account_handlers (GTK_TREE_VIEW (obj));
- g_free (priv->store_accounts_handlers);
- priv->store_accounts_handlers = NULL;
- }
-
if (priv->query) {
g_object_unref (G_OBJECT (priv->query));
priv->query = NULL;
g_return_val_if_fail (self, FALSE);
priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
- /* Disconnect old handlers */
- if (priv->store_accounts_handlers) {
- modest_folder_view_disconnect_store_account_handlers (GTK_TREE_VIEW (self));
- g_free (priv->store_accounts_handlers);
- priv->store_accounts_handlers = NULL;
- }
-
g_signal_emit (G_OBJECT(self), signals[FOLDER_SELECTION_CHANGED_SIGNAL], 0,
NULL, TRUE);
return TRUE;
}
+/* this feels dirty; any other way to expand all the root items? */
static void
-update_store_account_handlers (ModestFolderView *self, TnyList *account_list)
+expand_root_items (ModestFolderView *self)
{
- ModestFolderViewPrivate *priv;
- TnyIterator *iter;
- guint len;
-
- priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
-
- /* Listen to subscription changes */
- len = tny_list_get_length (TNY_LIST (account_list));
+ GtkTreePath *path;
+ path = gtk_tree_path_new_first ();
- g_assert (priv->store_accounts_handlers == NULL); /* don't leak */
- priv->store_accounts_handlers = g_malloc0 (sizeof (guint) * len);
- iter = tny_list_create_iterator (account_list);
+ /* all folders should have child items, so.. */
+ while (gtk_tree_view_expand_row (GTK_TREE_VIEW(self), path, FALSE))
+ gtk_tree_path_next (path);
- if (!tny_iterator_is_done (iter)) {
- gint i = 0;
-
- do {
-
- priv->store_accounts_handlers [i++] =
- g_signal_connect (G_OBJECT (tny_iterator_get_current (iter)),
- "subscription_changed",
- G_CALLBACK (on_subscription_changed),
- self);
- tny_iterator_next (iter);
- } while (!tny_iterator_is_done (iter));
- }
- g_object_unref (G_OBJECT (iter));
+ gtk_tree_path_free (path);
}
g_return_val_if_fail (account_store, FALSE);
- update_model_empty (self);
-
priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
- model = tny_gtk_folder_store_tree_model_new (FALSE, NULL);
+ /* Notify that there is no folder selected */
+ update_model_empty (self);
+
+ model = tny_gtk_folder_store_tree_model_new (TRUE, NULL);
account_list = TNY_LIST(model);
tny_account_store_get_accounts (TNY_ACCOUNT_STORE(account_store),
account_list,
- TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
-
-
+ TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
if (account_list) {
sortable = gtk_tree_model_sort_new_with_model (model);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(sortable),
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sortable),
TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN,
cmp_rows, NULL, NULL);
+
+ /* Set new model */
gtk_tree_view_set_model (GTK_TREE_VIEW(self), sortable);
- update_store_account_handlers (self, account_list);
+ expand_root_items (self); /* expand all account folders */
+
}
g_object_unref (model);
g_signal_emit (G_OBJECT(tree_view), signals[FOLDER_SELECTION_CHANGED_SIGNAL], 0,
folder, TRUE);
if (priv->cur_folder)
- tny_folder_expunge (priv->cur_folder, NULL); /* FIXME */
+ tny_folder_sync (priv->cur_folder, TRUE, NULL); /* FIXME */
priv->cur_folder = folder;
}
-static void
-on_subscription_changed (TnyStoreAccount *store_account,
- TnyFolder *folder,
- ModestFolderView *self)
-{
- /* TODO: probably we won't need a full reload, just the store
- account or even the parent of the folder */
+/* static void */
+/* on_subscription_changed (TnyStoreAccount *store_account, */
+/* TnyFolder *folder, */
+/* ModestFolderView *self) */
+/* { */
+/* /\* TODO: probably we won't need a full reload, just the store */
+/* account or even the parent of the folder *\/ */
- ModestFolderViewPrivate *priv;
+/* ModestFolderViewPrivate *priv; */
- priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
- update_model (self, MODEST_TNY_ACCOUNT_STORE (priv->account_store));
-}
+/* priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self); */
+/* update_model (self, MODEST_TNY_ACCOUNT_STORE (priv->account_store)); */
+/* } */
-static gboolean
+gboolean
modest_folder_view_update_model (ModestFolderView *self, TnyAccountStore *account_store)
{
g_return_val_if_fail (MODEST_IS_FOLDER_VIEW (self), FALSE);
return priv->cur_folder;
}
-
static gint
cmp_rows (GtkTreeModel *tree_model, GtkTreeIter *iter1, GtkTreeIter *iter2,
gpointer user_data)
cmp = -1;
else
cmp = modest_text_utils_utf8_strcmp (name1, name2, TRUE);
- } else {
+ } else
cmp = modest_text_utils_utf8_strcmp (name1, name2, TRUE);
- }
+
g_free (name1);
g_free (name2);