Improve archive folder detection
[modest] / src / widgets / modest-folder-view.c
index 810976f..d952c08 100644 (file)
@@ -424,6 +424,42 @@ on_get_mmc_account_name (TnyStoreAccount* account, gpointer user_data)
 }
 
 static void
+convert_parent_folders_to_dots (gchar **item_name)
+{
+       gint n_parents = 0;
+       gchar *c;
+       gchar *last_separator;
+
+       if (item_name == NULL)
+               return;
+
+       for (c = *item_name; *c != '\0'; c++) {
+               if (g_str_has_prefix (c, MODEST_FOLDER_PATH_SEPARATOR)) {
+                       n_parents++;
+               }
+       }
+
+       last_separator = g_strrstr (*item_name, MODEST_FOLDER_PATH_SEPARATOR);
+       if (last_separator != NULL) {
+               last_separator = last_separator + strlen (MODEST_FOLDER_PATH_SEPARATOR);
+       }
+
+       if (n_parents > 0) {
+               GString *buffer;
+               gint i;
+
+               buffer = g_string_new ("");
+               for (i = 0; i < n_parents; i++) {
+                       buffer = g_string_append (buffer, MODEST_FOLDER_DOT);
+               }
+               buffer = g_string_append (buffer, last_separator);
+               g_free (*item_name);
+               *item_name = g_string_free (buffer, FALSE);
+       }
+
+}
+
+static void
 format_compact_style (gchar **item_name, 
                      GObject *instance,
                      gboolean bold,
@@ -452,6 +488,9 @@ format_compact_style (gchar **item_name,
                if (account == NULL)
                        return;
 
+               /* convert parent folders to dots */
+               convert_parent_folders_to_dots  (item_name);
+
                folder_name = tny_folder_get_name (folder);
                if (g_str_has_suffix (*item_name, folder_name)) {
                        gchar *offset = g_strrstr (*item_name, folder_name);
@@ -460,8 +499,7 @@ format_compact_style (gchar **item_name,
                }
 
                buffer = g_string_new ("");
-               buffer = g_string_append (buffer, tny_account_get_name (account));
-               buffer = g_string_append (buffer, MODEST_FOLDER_PATH_SEPARATOR);
+
                buffer = g_string_append (buffer, *item_name);
                if (concat_folder_name) {
                        if (bold) buffer = g_string_append (buffer, "<span weight='bold'>");
@@ -783,19 +821,19 @@ get_folder_icons (TnyFolderType type, GObject *instance)
        static GdkPixbuf *inbox_pixbuf = NULL, *outbox_pixbuf = NULL,
                *junk_pixbuf = NULL, *sent_pixbuf = NULL,
                *trash_pixbuf = NULL, *draft_pixbuf = NULL,
-               *normal_pixbuf = NULL, *anorm_pixbuf = NULL,
+               *normal_pixbuf = NULL, *anorm_pixbuf = NULL, *mmc_pixbuf = NULL,
                *ammc_pixbuf = NULL, *avirt_pixbuf = NULL;
 
        static GdkPixbuf *inbox_pixbuf_open = NULL, *outbox_pixbuf_open = NULL,
                *junk_pixbuf_open = NULL, *sent_pixbuf_open = NULL,
                *trash_pixbuf_open = NULL, *draft_pixbuf_open = NULL,
-               *normal_pixbuf_open = NULL, *anorm_pixbuf_open = NULL,
+               *normal_pixbuf_open = NULL, *anorm_pixbuf_open = NULL, *mmc_pixbuf_open = NULL,
                *ammc_pixbuf_open = NULL, *avirt_pixbuf_open = NULL;
 
        static GdkPixbuf *inbox_pixbuf_close = NULL, *outbox_pixbuf_close = NULL,
                *junk_pixbuf_close = NULL, *sent_pixbuf_close = NULL,
                *trash_pixbuf_close = NULL, *draft_pixbuf_close = NULL,
-               *normal_pixbuf_close = NULL, *anorm_pixbuf_close = NULL,
+               *normal_pixbuf_close = NULL, *anorm_pixbuf_close = NULL, *mmc_pixbuf_close = NULL,
                *ammc_pixbuf_close = NULL, *avirt_pixbuf_close = NULL;
 
        ThreePixbufs *retval = NULL;
@@ -812,14 +850,20 @@ get_folder_icons (TnyFolderType type, GObject *instance)
            !TNY_IS_ACCOUNT (instance) &&
            type != TNY_FOLDER_TYPE_INBOX &&
            modest_tny_folder_store_is_remote (TNY_FOLDER_STORE (instance))) {
+#ifdef MODEST_TOOLKIT_HILDON2
+               return get_composite_icons (MODEST_FOLDER_ICON_ACCOUNT,
+                                           &anorm_pixbuf,
+                                           &anorm_pixbuf_open,
+                                           &anorm_pixbuf_close);
+#else
                return get_composite_icons (MODEST_FOLDER_ICON_NORMAL,
                                            &normal_pixbuf,
                                            &normal_pixbuf_open,
                                            &normal_pixbuf_close);
+#endif
        }
 
        switch (type) {
-               const gchar *icon_code;
 
        case TNY_FOLDER_TYPE_INVALID:
                g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
@@ -886,18 +930,26 @@ get_folder_icons (TnyFolderType type, GObject *instance)
                                              &draft_pixbuf_open,
                                              &draft_pixbuf_close);
                break;
+       case TNY_FOLDER_TYPE_ARCHIVE:
+               retval = get_composite_icons (MODEST_FOLDER_ICON_MMC_FOLDER,
+                                             &mmc_pixbuf,
+                                             &mmc_pixbuf_open,
+                                             &mmc_pixbuf_close);
+               break;
        case TNY_FOLDER_TYPE_NORMAL:
        default:
                /* Memory card folders could have an special icon */
-               if (modest_tny_folder_is_memory_card_folder (TNY_FOLDER (instance)))
-                       icon_code = MODEST_FOLDER_ICON_MMC_FOLDER;
-               else
-                       icon_code = MODEST_FOLDER_ICON_NORMAL;
-
-               retval = get_composite_icons (icon_code,
-                                             &normal_pixbuf,
-                                             &normal_pixbuf_open,
-                                             &normal_pixbuf_close);
+               if (modest_tny_folder_is_memory_card_folder (TNY_FOLDER (instance))) {
+                       retval = get_composite_icons (MODEST_FOLDER_ICON_MMC_FOLDER,
+                                                     &mmc_pixbuf,
+                                                     &mmc_pixbuf_open,
+                                                     &mmc_pixbuf_close);
+               } else {
+                       retval = get_composite_icons (MODEST_FOLDER_ICON_NORMAL,
+                                                     &normal_pixbuf,
+                                                     &normal_pixbuf_open,
+                                                     &normal_pixbuf_close);
+               }
                break;
        }
 
@@ -1561,6 +1613,7 @@ filter_row (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
        guint i;
        gboolean found = FALSE;
        gboolean cleared = FALSE;
+       ModestTnyFolderRules rules = 0;
 
        g_return_val_if_fail (MODEST_IS_FOLDER_VIEW (data), FALSE);
        priv = MODEST_FOLDER_VIEW_GET_PRIVATE (data);
@@ -1716,6 +1769,34 @@ filter_row (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
                }
        }
 
+       if (retval && TNY_IS_FOLDER (instance)) {
+               rules = modest_tny_folder_get_rules (TNY_FOLDER (instance));
+       }
+
+       if (retval && (priv->filter & MODEST_FOLDER_VIEW_FILTER_DELETABLE)) {
+               if (TNY_IS_FOLDER (instance)) {
+                       retval = !(rules & MODEST_FOLDER_RULES_FOLDER_NON_DELETABLE);
+               } else if (TNY_IS_ACCOUNT (instance)) {
+                       retval = FALSE;
+               }
+       }
+
+       if (retval && (priv->filter & MODEST_FOLDER_VIEW_FILTER_RENAMEABLE)) {
+               if (TNY_IS_FOLDER (instance)) {
+                       retval = !(rules & MODEST_FOLDER_RULES_FOLDER_NON_RENAMEABLE);
+               } else if (TNY_IS_ACCOUNT (instance)) {
+                       retval = FALSE;
+               }
+       }
+
+       if (retval && (priv->filter & MODEST_FOLDER_VIEW_FILTER_MOVEABLE)) {
+               if (TNY_IS_FOLDER (instance)) {
+                       retval = !(rules & MODEST_FOLDER_RULES_FOLDER_NON_MOVEABLE);
+               } else if (TNY_IS_ACCOUNT (instance)) {
+                       retval = FALSE;
+               }
+       }
+
        /* Free */
        g_object_unref (instance);