#include <modest-icon-names.h>
#include <modest-icon-factory.h>
#include <modest-tny-account-store.h>
+#include <modest-text-utils.h>
#include "modest-folder-view.h"
static void modest_folder_view_disconnect_store_account_handlers (GtkTreeView *self);
+static gint cmp_rows (GtkTreeModel *tree_model, GtkTreeIter *iter1, GtkTreeIter *iter2,
+ gpointer user_data);
+
+
enum {
FOLDER_SELECTION_CHANGED_SIGNAL,
LAST_SIGNAL
TnyAccountStore *account_store;
TnyFolder *cur_folder;
- gboolean view_is_empty;
gulong sig1, sig2;
gulong *store_accounts_handlers;
gint unread;
TnyFolderType type;
+ g_return_if_fail (column);
+ g_return_if_fail (tree_model);
+
gtk_tree_model_get (tree_model, iter,
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_UNREAD_COLUMN, &unread, -1);
+ -1);
rendobj = G_OBJECT(renderer);
+ if (!fname)
+ return;
+
if (unread > 0) {
gchar *folder_title = g_strdup_printf ("%s (%d)", fname, unread);
g_object_set (rendobj,"text", folder_title, "weight", 800, NULL);
pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_ACCOUNT);
break;
case TNY_FOLDER_TYPE_INBOX:
- pixbuf = modest_icon_factory_get_small_icon (MODEST_FOLDER_ICON_INBOX);
+ pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_INBOX);
break;
case TNY_FOLDER_TYPE_OUTBOX:
- pixbuf = modest_icon_factory_get_small_icon (MODEST_FOLDER_ICON_OUTBOX);
+ pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_OUTBOX);
break;
case TNY_FOLDER_TYPE_JUNK:
- pixbuf = modest_icon_factory_get_small_icon (MODEST_FOLDER_ICON_JUNK);
+ pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_JUNK);
break;
case TNY_FOLDER_TYPE_SENT:
- pixbuf = modest_icon_factory_get_small_icon (MODEST_FOLDER_ICON_SENT);
+ pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_SENT);
break;
case TNY_FOLDER_TYPE_DRAFTS:
- pixbuf = modest_icon_factory_get_small_icon (MODEST_FOLDER_ICON_DRAFTS);
+ pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_DRAFTS);
break;
case TNY_FOLDER_TYPE_NOTES:
- pixbuf = modest_icon_factory_get_small_icon (MODEST_FOLDER_ICON_NOTES);
+ pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_NOTES);
break;
case TNY_FOLDER_TYPE_CALENDAR:
- pixbuf = modest_icon_factory_get_small_icon (MODEST_FOLDER_ICON_CALENDAR);
+ pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_CALENDAR);
break;
case TNY_FOLDER_TYPE_CONTACTS:
- pixbuf = modest_icon_factory_get_small_icon (MODEST_FOLDER_ICON_CONTACTS);
+ pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_CONTACTS);
break;
case TNY_FOLDER_TYPE_NORMAL:
default:
- pixbuf = modest_icon_factory_get_small_icon (MODEST_FOLDER_ICON_NORMAL);
+ pixbuf = modest_icon_factory_get_icon (MODEST_FOLDER_ICON_NORMAL);
break;
}
priv = MODEST_FOLDER_VIEW_GET_PRIVATE(obj);
- priv->view_is_empty = TRUE;
priv->account_store = NULL;
priv->cur_folder = NULL;
priv->query = NULL;
on_account_update (TnyAccountStore *account_store, const gchar *account,
gpointer user_data)
{
- update_model_empty (MODEST_FOLDER_VIEW(user_data));
-
if (!update_model (MODEST_FOLDER_VIEW(user_data),
MODEST_TNY_ACCOUNT_STORE(account_store)))
g_printerr ("modest: failed to update model for changes in '%s'",
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(self));
priv->sig2 = g_signal_connect (sel, "changed",
G_CALLBACK(on_selection_changed), self);
-
return GTK_WIDGET(self);
}
static gboolean
update_model_empty (ModestFolderView *self)
{
- GtkTreeIter iter;
- GtkTreeStore *store;
ModestFolderViewPrivate *priv;
g_return_val_if_fail (self, FALSE);
priv->store_accounts_handlers = NULL;
}
- /* Create the new model */
- store = gtk_tree_store_new (1, G_TYPE_STRING);
- gtk_tree_store_append (store, &iter, NULL);
-
- gtk_tree_store_set (store, &iter, 0, _("(empty)"), -1);
-
- gtk_tree_view_set_model (GTK_TREE_VIEW(self),
- GTK_TREE_MODEL(store));
- g_object_unref (store);
- priv->view_is_empty = TRUE;
-
g_signal_emit (G_OBJECT(self), signals[FOLDER_SELECTION_CHANGED_SIGNAL], 0,
NULL, TRUE);
return TRUE;
if (!tny_iterator_is_done (iter)) {
gint i = 0;
- priv->view_is_empty = FALSE;
do {
priv->store_accounts_handlers [i++] =
priv = MODEST_FOLDER_VIEW_GET_PRIVATE(self);
- model = tny_gtk_folder_store_tree_model_new (TRUE, NULL);
+ model = tny_gtk_folder_store_tree_model_new (FALSE, NULL);
account_list = TNY_LIST(model);
tny_account_store_get_accounts (TNY_ACCOUNT_STORE(account_store),
account_list,
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_column_id (GTK_TREE_SORTABLE(sortable),
TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN,
GTK_SORT_ASCENDING);
+ gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sortable),
+ TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN,
+ cmp_rows, NULL, NULL);
gtk_tree_view_set_model (GTK_TREE_VIEW(self), sortable);
-
update_store_account_handlers (self, account_list);
}
-
+
g_object_unref (model);
return TRUE;
}
priv = MODEST_FOLDER_VIEW_GET_PRIVATE(user_data);
priv->cur_selection = sel;
- /* is_empty means that there is only the 'empty' item */
- if (priv->view_is_empty)
- return;
-
/* folder was _un_selected if true */
if (!gtk_tree_selection_get_selected (sel, &model, &iter)) {
priv->cur_folder = NULL; /* FIXME: need this? */
priv->cur_folder, FALSE);
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 */
priv->cur_folder = folder;
g_signal_emit (G_OBJECT(self), signals[FOLDER_SELECTION_CHANGED_SIGNAL],
0, NULL, TRUE);
-
return update_model (self, MODEST_TNY_ACCOUNT_STORE(account_store)); /* ugly */
}
return priv->cur_folder;
}
+
+
+static gint
+cmp_rows (GtkTreeModel *tree_model, GtkTreeIter *iter1, GtkTreeIter *iter2,
+ gpointer user_data)
+{
+ gint cmp;
+ gchar *name1, *name2;
+ TnyFolderType type;
+ TnyFolder *folder1, *folder2;
+
+ gtk_tree_model_get (tree_model, iter1,
+ TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &name1,
+ TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
+ TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder1,
+ -1);
+ gtk_tree_model_get (tree_model, iter2,
+ TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &name2,
+ TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder2,
+ -1);
+
+ /* local_folders should be the last one */
+ if (type == TNY_FOLDER_TYPE_ROOT) {
+ /* the account name is also the name of the root folder
+ * in case of local folders */
+ if (strcmp (name1, MODEST_LOCAL_FOLDERS_ACCOUNT_NAME) == 0)
+ cmp = +1;
+ else if (strcmp (name2, MODEST_LOCAL_FOLDERS_ACCOUNT_NAME) == 0)
+ cmp = -1;
+ else
+ cmp = modest_text_utils_utf8_strcmp (name1, name2, TRUE);
+ } else {
+ cmp = modest_text_utils_utf8_strcmp (name1, name2, TRUE);
+ }
+ g_free (name1);
+ g_free (name2);
+
+ return cmp;
+}