#include <gdk/gdkkeysyms.h>
#include <tny-account-store-view.h>
#include <tny-gtk-account-list-model.h>
+#ifdef MODEST_TOOLKIT_HILDON2
+#include <tny-gtk-folder-list-store.h>
+#else
#include <tny-gtk-folder-store-tree-model.h>
+#endif
#include <tny-gtk-header-list-model.h>
#include <tny-folder.h>
#include <tny-folder-store-observer.h>
{ GTK_TREE_PATH_AS_STRING_LIST, GTK_TARGET_SAME_APP, MODEST_HEADER_ROW }
};
+/* Default icon sizes for Fremantle style are different */
+#ifdef MODEST_TOOLKIT_HILDON2
+#define FOLDER_ICON_SIZE MODEST_ICON_SIZE_BIG
+#else
+#define FOLDER_ICON_SIZE MODEST_ICON_SIZE_SMALL
+#endif
+
+/* Column names depending on we use list store or tree store */
+#ifdef MODEST_TOOLKIT_HILDON2
+#define NAME_COLUMN TNY_GTK_FOLDER_LIST_STORE_NAME_COLUMN
+#define UNREAD_COLUMN TNY_GTK_FOLDER_LIST_STORE_UNREAD_COLUMN
+#define ALL_COLUMN TNY_GTK_FOLDER_LIST_STORE_ALL_COLUMN
+#define TYPE_COLUMN TNY_GTK_FOLDER_LIST_STORE_TYPE_COLUMN
+#define INSTANCE_COLUMN TNY_GTK_FOLDER_LIST_STORE_INSTANCE_COLUMN
+#else
+#define NAME_COLUMN TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN
+#define UNREAD_COLUMN TNY_GTK_FOLDER_STORE_TREE_MODEL_UNREAD_COLUMN
+#define ALL_COLUMN TNY_GTK_FOLDER_STORE_TREE_MODEL_ALL_COLUMN
+#define TYPE_COLUMN TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN
+#define INSTANCE_COLUMN TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN
+#endif
+
/* 'private'/'protected' functions */
static void modest_folder_view_class_init (ModestFolderViewClass *klass);
static void modest_folder_view_init (ModestFolderView *obj);
GObject *instance = NULL;
gtk_tree_model_get (model, iter,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &instance,
+ INSTANCE_COLUMN, &instance,
-1);
if (!instance)
GObject *instance = NULL;
gtk_tree_model_get (tree_model, iter,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &fname,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &instance,
+ NAME_COLUMN, &fname,
+ TYPE_COLUMN, &type,
+ INSTANCE_COLUMN, &instance,
-1);
if (!fname || !instance)
goto end;
ThreePixbufs *retval;
if (!*pixbuf)
- *pixbuf = gdk_pixbuf_copy (modest_platform_get_icon (icon_code, MODEST_ICON_SIZE_SMALL));
+ *pixbuf = gdk_pixbuf_copy (modest_platform_get_icon (icon_code, FOLDER_ICON_SIZE));
if (!*pixbuf_open)
*pixbuf_open = get_composite_pixbuf ("qgn_list_gene_fldr_exp",
- MODEST_ICON_SIZE_SMALL,
+ FOLDER_ICON_SIZE,
*pixbuf);
if (!*pixbuf_close)
*pixbuf_close = get_composite_pixbuf ("qgn_list_gene_fldr_clp",
- MODEST_ICON_SIZE_SMALL,
+ FOLDER_ICON_SIZE,
*pixbuf);
retval = g_slice_new0 (ThreePixbufs);
rendobj = (GObject *) renderer;
gtk_tree_model_get (tree_model, iter,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &instance,
+ TYPE_COLUMN, &type,
+ INSTANCE_COLUMN, &instance,
-1);
if (!instance)
priv = MODEST_FOLDER_VIEW_GET_PRIVATE (data);
gtk_tree_model_get (model, iter,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &instance,
+ TYPE_COLUMN, &type,
+ INSTANCE_COLUMN, &instance,
-1);
/* Do not show if there is no instance, this could indeed
if (!instance)
return FALSE;
- if (type == TNY_FOLDER_TYPE_ROOT) {
- /* TNY_FOLDER_TYPE_ROOT means that the instance is an
- account instead of a folder. */
- if (TNY_IS_ACCOUNT (instance)) {
- TnyAccount *acc = TNY_ACCOUNT (instance);
- const gchar *account_id = tny_account_get_id (acc);
-
- /* If it isn't a special folder,
- * don't show it unless it is the visible account: */
- if (priv->style == MODEST_FOLDER_VIEW_STYLE_SHOW_ONE &&
- !modest_tny_account_is_virtual_local_folders (acc) &&
- strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) {
-
- /* Show only the visible account id */
- if (priv->visible_account_id) {
- if (strcmp (account_id, priv->visible_account_id))
- retval = FALSE;
- } else {
+ if (TNY_IS_ACCOUNT (instance)) {
+ TnyAccount *acc = TNY_ACCOUNT (instance);
+ const gchar *account_id = tny_account_get_id (acc);
+
+ /* If it isn't a special folder,
+ * don't show it unless it is the visible account: */
+ if (priv->style == MODEST_FOLDER_VIEW_STYLE_SHOW_ONE &&
+ !modest_tny_account_is_virtual_local_folders (acc) &&
+ strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) {
+
+ /* Show only the visible account id */
+ if (priv->visible_account_id) {
+ if (strcmp (account_id, priv->visible_account_id))
retval = FALSE;
- }
+ } else {
+ retval = FALSE;
}
+ }
+
+ /* Never show these to the user. They are merged into one folder
+ * in the local-folders account instead: */
+ if (retval && MODEST_IS_TNY_OUTBOX_ACCOUNT (acc))
+ retval = FALSE;
+ } else {
+ GtkTreeIter parent;
- /* Never show these to the user. They are merged into one folder
- * in the local-folders account instead: */
- if (retval && MODEST_IS_TNY_OUTBOX_ACCOUNT (acc))
- retval = FALSE;
+ if (priv->style == MODEST_FOLDER_VIEW_STYLE_SHOW_ONE &&
+ !gtk_tree_model_iter_parent (model, iter, &parent)) {
+ /* Only show special folders for current account if needed */
+ if (TNY_IS_FOLDER (instance)) {
+ TnyAccount *account;
+
+ account = tny_folder_get_account (TNY_FOLDER (instance));
+
+ if (TNY_IS_ACCOUNT (account)) {
+ const gchar *account_id = tny_account_get_id (account);
+
+ if (!modest_tny_account_is_virtual_local_folders (account) &&
+ strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) {
+ /* Show only the visible account id */
+ if (priv->visible_account_id) {
+ if (strcmp (account_id, priv->visible_account_id))
+ retval = FALSE;
+ }
+ }
+ g_object_unref (account);
+ }
+ }
+
}
}
/* FIXME: the local accounts are not shown when the query
selects only the subscribed folders */
+#ifdef MODEST_TOOLKIT_HILDON2
+ model = tny_gtk_folder_list_store_new_with_flags (NULL,
+ TNY_GTK_FOLDER_LIST_STORE_FLAG_SHOW_PATH);
+#else
model = tny_gtk_folder_store_tree_model_new (NULL);
+#endif
/* Get the accounts: */
tny_account_store_get_accounts (TNY_ACCOUNT_STORE(account_store),
sortable = gtk_tree_model_sort_new_with_model (model);
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(sortable),
- TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN,
+ NAME_COLUMN,
GTK_SORT_ASCENDING);
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sortable),
- TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN,
+ NAME_COLUMN,
cmp_rows, NULL, NULL);
/* Create filter model */
if (selected) {
gtk_tree_model_get (model, &iter,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder,
+ INSTANCE_COLUMN, &folder,
-1);
/* If the folder is the same do not notify */
return;
gtk_tree_model_get (model, &iter,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder,
+ INSTANCE_COLUMN, &folder,
-1);
g_signal_emit (G_OBJECT(self),
}
static gint
-get_cmp_subfolder_type_pos (TnyFolderType t)
+get_cmp_pos (TnyFolderType t)
{
/* Inbox, Outbox, Drafts, Sent, User */
/* 0, 1, 2, 3, 4 */
}
}
+static gint
+compare_account_names (TnyAccount *a1, TnyAccount *a2)
+{
+ const gchar *a1_name, *a2_name;
+
+ a1_name = tny_account_get_name (a1);
+ a2_name = tny_account_get_name (a2);
+
+ return modest_text_utils_utf8_strcmp (a1_name, a2_name, TRUE);
+}
+
+static gint
+compare_accounts (TnyFolderStore *s1, TnyFolderStore *s2)
+{
+ TnyAccount *a1, *a2;
+ gint cmp;
+
+ if (TNY_IS_ACCOUNT (s1)) {
+ a1 = TNY_ACCOUNT (g_object_ref (s1));
+ } else {
+ a1 = tny_folder_get_account (TNY_FOLDER (s1));
+ }
+
+ if (TNY_IS_ACCOUNT (s2)) {
+ a2 = TNY_ACCOUNT (g_object_ref (s2));
+ } else {
+ a2 = tny_folder_get_account (TNY_FOLDER (s2));
+ }
+
+ if (a1 == a2) {
+ cmp = 0;
+ goto finish;
+ }
+ /* First we sort with the type of account */
+ cmp = get_cmp_rows_type_pos (G_OBJECT (a1)) - get_cmp_rows_type_pos (G_OBJECT (a2));
+ if (cmp != 0)
+ goto finish;
+
+ cmp = compare_account_names (a1, a2);
+
+finish:
+ g_object_unref (a1);
+ g_object_unref (a2);
+
+ return cmp;
+}
+
+static gint
+compare_accounts_first (TnyFolderStore *s1, TnyFolderStore *s2)
+{
+ gint is_account1, is_account2;
+
+ is_account1 = TNY_IS_ACCOUNT (s1)?1:0;
+ is_account2 = TNY_IS_ACCOUNT (s2)?1:0;
+
+ return is_account2 - is_account1;
+}
+
/*
* This function orders the mail accounts according to these rules:
* 1st - remote accounts
GObject *folder2 = NULL;
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,
+ NAME_COLUMN, &name1,
+ TYPE_COLUMN, &type,
+ 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_TYPE_COLUMN, &type2,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder2,
+ NAME_COLUMN, &name2,
+ TYPE_COLUMN, &type2,
+ INSTANCE_COLUMN, &folder2,
-1);
/* Return if we get no folder. This could happen when folder
if (!folder1 || !folder2)
goto finish;
- if (type == TNY_FOLDER_TYPE_ROOT) {
- /* Compare the types, so that
- * Remote accounts -> Local account -> MMC account .*/
- const gint pos1 = get_cmp_rows_type_pos (folder1);
- const gint pos2 = get_cmp_rows_type_pos (folder2);
- /* printf ("DEBUG: %s:\n type1=%s, pos1=%d\n type2=%s, pos2=%d\n",
- __FUNCTION__, G_OBJECT_TYPE_NAME(folder1), pos1, G_OBJECT_TYPE_NAME(folder2), pos2); */
- if (pos1 < pos2)
- cmp = -1;
- else if (pos1 > pos2)
- cmp = 1;
- else {
- /* Compare items of the same type: */
-
- TnyAccount *account1 = NULL;
- if (TNY_IS_ACCOUNT (folder1))
- account1 = TNY_ACCOUNT (folder1);
-
- TnyAccount *account2 = NULL;
- if (TNY_IS_ACCOUNT (folder2))
- account2 = TNY_ACCOUNT (folder2);
-
- const gchar *account_id = account1 ? tny_account_get_id (account1) : NULL;
- const gchar *account_id2 = account2 ? tny_account_get_id (account2) : NULL;
-
- if (!account_id && !account_id2) {
- cmp = 0;
- } else if (!account_id) {
- cmp = -1;
- } else if (!account_id2) {
- cmp = +1;
- } else if (!strcmp (account_id, MODEST_MMC_ACCOUNT_ID)) {
- cmp = +1;
- } else {
- cmp = modest_text_utils_utf8_strcmp (name1, name2, TRUE);
- }
- }
- } else {
- gint cmp1 = 0, cmp2 = 0;
- /* get the parent to know if it's a local folder */
-
- GtkTreeIter parent;
- gboolean has_parent;
- has_parent = gtk_tree_model_iter_parent (tree_model, &parent, iter1);
- if (has_parent) {
- GObject *parent_folder;
- TnyFolderType parent_type = TNY_FOLDER_TYPE_UNKNOWN;
- gtk_tree_model_get (tree_model, &parent,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &parent_type,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &parent_folder,
- -1);
- if ((parent_type == TNY_FOLDER_TYPE_ROOT) &&
- TNY_IS_ACCOUNT (parent_folder)) {
- if (modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (parent_folder))) {
- cmp1 = get_cmp_subfolder_type_pos (modest_tny_folder_get_local_or_mmc_folder_type
- (TNY_FOLDER (folder1)));
- cmp2 = get_cmp_subfolder_type_pos (modest_tny_folder_get_local_or_mmc_folder_type
- (TNY_FOLDER (folder2)));
- } else if (modest_tny_account_is_memory_card_account (TNY_ACCOUNT (parent_folder))) {
- if (modest_local_folder_info_get_type (tny_folder_get_name (TNY_FOLDER (folder1))) == TNY_FOLDER_TYPE_ARCHIVE) {
- cmp1 = 0;
- cmp2 = 1;
- } else if (modest_local_folder_info_get_type (tny_folder_get_name (TNY_FOLDER (folder2))) == TNY_FOLDER_TYPE_ARCHIVE) {
- cmp1 = 1;
- cmp2 = 0;
- }
- }
- }
- g_object_unref (parent_folder);
- }
+ /* First sort by type. First the special folders, then the archives */
+ cmp = get_cmp_pos (type) - get_cmp_pos (type2);
+ if (cmp != 0)
+ goto finish;
- /* if they are not local folders */
- if (cmp1 == cmp2) {
- cmp1 = get_cmp_subfolder_type_pos (tny_folder_get_folder_type (TNY_FOLDER (folder1)));
- cmp2 = get_cmp_subfolder_type_pos (tny_folder_get_folder_type (TNY_FOLDER (folder2)));
- }
+ /* Now we sort using the account of each folder */
+ cmp = compare_accounts (TNY_FOLDER_STORE (folder1), TNY_FOLDER_STORE (folder2));
+ if (cmp != 0)
+ goto finish;
- if (cmp1 == cmp2)
- cmp = modest_text_utils_utf8_strcmp (name1, name2, TRUE);
- else
- cmp = (cmp1 - cmp2);
- }
+ /* Each group is preceeded by its account */
+ cmp = compare_accounts_first (TNY_FOLDER_STORE (folder1), TNY_FOLDER_STORE (folder2));
+ if (cmp != 0)
+ goto finish;
-finish:
+ /* Pure sort by name */
+ cmp = modest_text_utils_utf8_strcmp (name1, name2, TRUE);
+ finish:
if (folder1)
g_object_unref(G_OBJECT(folder1));
if (folder2)
if (gtk_tree_model_get_iter (model,&iter, path))
gtk_tree_model_get (model, &iter,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &folder,
+ INSTANCE_COLUMN, &folder,
-1);
return folder;
}
/* Get the target folder */
gtk_tree_model_get_iter (dest_model, &dest_iter, dest_row);
gtk_tree_model_get (dest_model, &dest_iter,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN,
+ INSTANCE_COLUMN,
&folder, -1);
if (!folder || !TNY_IS_FOLDER(folder)) {
/* Get data */
gtk_tree_model_get_iter (dest_model, &dest_iter, dest_row);
gtk_tree_model_get (dest_model, &dest_iter,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN,
+ INSTANCE_COLUMN,
&dest_folder, -1);
gtk_tree_model_get_iter (source_model, &iter, helper->source_row);
gtk_tree_model_get (source_model, &iter,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN,
+ INSTANCE_COLUMN,
&folder, -1);
/* Create the info for the performer */
GtkTreeViewColumn * tree_column;
tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (self),
- TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN);
+ NAME_COLUMN);
gtk_tree_view_column_queue_resize (tree_column);
#else
gtk_widget_queue_draw (GTK_WIDGET (self));
TnyFolderType type = TNY_FOLDER_TYPE_UNKNOWN;
gtk_tree_model_get (model, iter,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN,
+ TYPE_COLUMN,
&type, -1);
gboolean result = FALSE;
gchar *name = NULL;
gtk_tree_model_get (model, iter,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &a_folder,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN, &name,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
+ INSTANCE_COLUMN, &a_folder,
+ NAME_COLUMN, &name,
+ TYPE_COLUMN, &type,
-1);
g_free (name);
priv->reexpand = TRUE;
gtk_tree_model_get (tree_model, iter,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_TYPE_COLUMN, &type,
- TNY_GTK_FOLDER_STORE_TREE_MODEL_INSTANCE_COLUMN, &instance,
+ TYPE_COLUMN, &type,
+ INSTANCE_COLUMN, &instance,
-1);
if (type == TNY_FOLDER_TYPE_INBOX && priv->folder_to_select == NULL) {
priv->folder_to_select = g_object_ref (instance);
GtkTreeViewColumn * tree_column;
tree_column = gtk_tree_view_get_column (GTK_TREE_VIEW (self),
- TNY_GTK_FOLDER_STORE_TREE_MODEL_NAME_COLUMN);
+ NAME_COLUMN);
gtk_tree_view_column_queue_resize (tree_column);
#else
gtk_widget_queue_draw (GTK_WIDGET (self));