#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 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);
TnyFolder *cur_folder;
gulong sig1, sig2;
- gulong *store_accounts_handlers;
GMutex *lock;
GtkTreeSelection *cur_selection;
TnyFolderStoreQuery *query;
}
+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;
}
-static void
-update_store_account_handlers (ModestFolderView *self, TnyList *account_list)
-{
- 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));
-
- 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);
-
- 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));
-}
-
-
-
/* this feels dirty; any other way to expand all the root items? */
static void
expand_root_items (ModestFolderView *self)
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),
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);
expand_root_items (self); /* expand all account folders */
- update_store_account_handlers (self, account_list);
}
g_object_unref (model);
}
-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)); */
+/* } */
gboolean
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);