Set better the default max height for hildon2 dialogs
[modest] / src / widgets / modest-folder-view.c
index 0da3a04..2a956e2 100644 (file)
@@ -189,6 +189,7 @@ static void         on_display_name_changed (ModestAccountMgr *self,
 static void         update_style (ModestFolderView *self);
 static void         on_notify_style (GObject *obj, GParamSpec *spec, gpointer userdata);
 static gint         get_cmp_pos (TnyFolderType t, TnyFolder *folder_store);
+static gboolean     inbox_is_special (TnyFolderStore *folder_store);
 
 static gboolean     get_inner_models        (ModestFolderView *self,
                                             GtkTreeModel **filter_model,
@@ -499,7 +500,7 @@ convert_parent_folders_to_dots (gchar **item_name)
 }
 
 static void
-format_compact_style (gchar **item_name, 
+format_compact_style (gchar **item_name,
                      GObject *instance,
                      gboolean bold,
                      gboolean multiaccount,
@@ -603,15 +604,11 @@ text_cell_data  (GtkTreeViewColumn *column,
                        }
                }
 
-               if (type == TNY_FOLDER_TYPE_INBOX) {
-                       g_free (fname);
-                       fname = g_strdup (_("mcen_me_folder_inbox"));
-               }
-
-               /* note: we cannot reliably get the counts from the tree model, we need
-                * to use explicit calls on tny_folder for some reason.
-                */
-               /* Select the number to show: the unread or unsent messages. in case of outbox/drafts, show all */
+               /* note: we cannot reliably get the counts from the
+                * tree model, we need to use explicit calls on
+                * tny_folder for some reason. Select the number to
+                * show: the unread or unsent messages. in case of
+                * outbox/drafts, show all */
                if ((type == TNY_FOLDER_TYPE_DRAFTS) ||
                    (type == TNY_FOLDER_TYPE_OUTBOX) ||
                    (type == TNY_FOLDER_TYPE_MERGE)) { /* _OUTBOX actually returns _MERGE... */
@@ -884,6 +881,13 @@ get_folder_icons (TnyFolderType type, GObject *instance)
                type = modest_tny_folder_guess_folder_type (TNY_FOLDER (instance));
        }
 
+       /* It's not enough with check the folder type. We need to
+          ensure that we're not giving a special folder icon to a
+          normal folder with the same name than a special folder */
+       if (TNY_IS_FOLDER (instance) &&
+           get_cmp_pos (type, TNY_FOLDER (instance)) ==  4)
+               type = TNY_FOLDER_TYPE_NORMAL;
+
        /* Remote folders should not be treated as special folders */
        if (TNY_IS_FOLDER_STORE (instance) &&
            !TNY_IS_ACCOUNT (instance) &&
@@ -1059,6 +1063,12 @@ add_columns (GtkWidget *treeview)
 
        /* Set icon and text render function */
        renderer = gtk_cell_renderer_pixbuf_new();
+#ifdef MODEST_TOOLKIT_HILDON2
+       g_object_set (renderer,
+                     "xpad", MODEST_MARGIN_DEFAULT,
+                     "ypad", MODEST_MARGIN_DEFAULT,
+                     NULL);
+#endif
        gtk_tree_view_column_pack_start (column, renderer, FALSE);
        gtk_tree_view_column_set_cell_data_func(column, renderer,
                                                icon_cell_data, treeview, NULL);
@@ -1067,6 +1077,7 @@ add_columns (GtkWidget *treeview)
        g_object_set (renderer, 
 #ifdef MODEST_TOOLKIT_HILDON2
                      "ellipsize", PANGO_ELLIPSIZE_MIDDLE,
+                     "ypad", MODEST_MARGIN_DEFAULT,
 #else
                      "ellipsize", PANGO_ELLIPSIZE_END,
 #endif
@@ -1077,8 +1088,14 @@ add_columns (GtkWidget *treeview)
 
        priv->messages_renderer = gtk_cell_renderer_text_new ();
        g_object_set (priv->messages_renderer, 
+#ifdef MODEST_TOOLKIT_HILDON2
+                     "yalign", 0.0,
+                     "ypad", MODEST_MARGIN_DEFAULT,
+                     "xpad", MODEST_MARGIN_DOUBLE,
+#else
                      "scale", PANGO_SCALE_X_SMALL,
                      "scale-set", TRUE,
+#endif
                      "alignment", PANGO_ALIGN_RIGHT,
                      "align-set", TRUE,
                      "xalign", 1.0,
@@ -1751,7 +1768,9 @@ filter_row (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
        /* If this is a move to dialog, hide Sent, Outbox and Drafts
        folder as no message can be move there according to UI specs */
        if (!priv->show_non_move) {
-               switch (type) {
+               if (TNY_IS_FOLDER (instance) && 
+                   modest_tny_folder_is_local_folder (TNY_FOLDER (instance))) {
+                       switch (type) {
                        case TNY_FOLDER_TYPE_OUTBOX:
                        case TNY_FOLDER_TYPE_SENT:
                        case TNY_FOLDER_TYPE_DRAFTS:
@@ -1762,7 +1781,7 @@ filter_row (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
                                type = modest_tny_folder_guess_folder_type(TNY_FOLDER(instance));
                                if (type == TNY_FOLDER_TYPE_INVALID)
                                        g_warning ("%s: BUG: TNY_FOLDER_TYPE_INVALID", __FUNCTION__);
-
+                               
                                if (type == TNY_FOLDER_TYPE_OUTBOX ||
                                    type == TNY_FOLDER_TYPE_SENT
                                    || type == TNY_FOLDER_TYPE_DRAFTS)
@@ -1770,6 +1789,7 @@ filter_row (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
                                break;
                        default:
                                break;
+                       }
                }
        }
 
@@ -2101,13 +2121,39 @@ get_cmp_rows_type_pos (GObject *folder)
        }
 }
 
+static gboolean
+inbox_is_special (TnyFolderStore *folder_store)
+{
+       gboolean is_special = TRUE;
+
+       if (TNY_IS_FOLDER (folder_store)) {
+               const gchar *id;
+               gchar *downcase;
+               gchar *last_bar;
+               gchar *last_inbox_bar;
+
+               id = tny_folder_get_id (TNY_FOLDER (folder_store));
+               downcase = g_utf8_strdown (id, -1);
+               last_bar = g_strrstr (downcase, "/");
+               if (last_bar) {
+                       last_inbox_bar = g_strrstr  (downcase, "inbox/");
+                       if ((last_inbox_bar == NULL) || (last_inbox_bar + 5 != last_bar))
+                               is_special = FALSE;
+               } else {
+                       is_special = FALSE;
+               }
+               g_free (downcase);
+       }
+       return is_special;
+}
+
 static gint
 get_cmp_pos (TnyFolderType t, TnyFolder *folder_store)
 {
        TnyAccount *account;
        gboolean is_special;
        /* Inbox, Outbox, Drafts, Sent, User */
-       /* 0, 1, 2, 3, 4 */
+       /* 0, 1, 2, 3, 4 */
 
        if (!TNY_IS_FOLDER (folder_store))
                return 4;
@@ -2116,12 +2162,18 @@ get_cmp_pos (TnyFolderType t, TnyFolder *folder_store)
        {
                account = tny_folder_get_account (folder_store);
                is_special = (get_cmp_rows_type_pos (G_OBJECT (account)) == 0);
+
+               /* In inbox case we need to know if the inbox is really the top
+                * inbox of the account, or if it's a submailbox inbox. To do
+                * this we'll apply an heuristic rule: Find last "/" and check
+                * if it's preceeded by another Inbox */
+               is_special = is_special && !inbox_is_special (TNY_FOLDER_STORE (folder_store));
                g_object_unref (account);
                return is_special?0:4;
        }
        break;
        case TNY_FOLDER_TYPE_OUTBOX:
-               return 2;
+               return (TNY_IS_MERGE_FOLDER (folder_store))?2:4;
                break;
        case TNY_FOLDER_TYPE_DRAFTS:
        {
@@ -2158,21 +2210,31 @@ compare_account_names (TnyAccount *a1, TnyAccount *a2)
 static gint
 compare_accounts (TnyFolderStore *s1, TnyFolderStore *s2)
 {
-       TnyAccount *a1, *a2;
+       TnyAccount *a1 = NULL, *a2 = NULL;
        gint cmp;
 
        if (TNY_IS_ACCOUNT (s1)) {
                a1 = TNY_ACCOUNT (g_object_ref (s1));
-       } else {
+       } else if (!TNY_IS_MERGE_FOLDER (s1)) {
                a1 = tny_folder_get_account (TNY_FOLDER (s1));
        }
 
        if (TNY_IS_ACCOUNT (s2)) {
                a2 = TNY_ACCOUNT (g_object_ref (s2));
-       } else {
+       } else  if (!TNY_IS_MERGE_FOLDER (s2)) {
                a2 = tny_folder_get_account (TNY_FOLDER (s2));
        }
 
+       if (!a1 || !a2) {
+               if (!a1 && !a2)
+                       cmp = 0;
+               else if (!a1)
+                       cmp = 1;
+               else
+                       cmp = -1;
+               goto finish;
+       }
+
        if (a1 == a2) {
                cmp = 0;
                goto finish;
@@ -2185,8 +2247,10 @@ compare_accounts (TnyFolderStore *s1, TnyFolderStore *s2)
        cmp = compare_account_names (a1, a2);
 
 finish:
-       g_object_unref (a1);
-       g_object_unref (a2);
+       if (a1)
+               g_object_unref (a1);
+       if (a2)
+               g_object_unref (a2);
 
        return cmp;
 }
@@ -2244,14 +2308,17 @@ cmp_rows (GtkTreeModel *tree_model, GtkTreeIter *iter1, GtkTreeIter *iter2,
                goto finish;
 
        /* 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 (TNY_IS_FOLDER_STORE (folder1) && 
+           TNY_IS_FOLDER_STORE (folder2)) {
+               cmp = compare_accounts (TNY_FOLDER_STORE (folder1), TNY_FOLDER_STORE (folder2));
+               if (cmp != 0)
+                       goto finish;
 
-       /* Each group is preceeded by its account */
-       cmp = compare_accounts_first (TNY_FOLDER_STORE (folder1), TNY_FOLDER_STORE (folder2));
-       if (cmp != 0)
-               goto finish;
+               /* Each group is preceeded by its account */
+               cmp = compare_accounts_first (TNY_FOLDER_STORE (folder1), TNY_FOLDER_STORE (folder2));
+               if (cmp != 0)
+                       goto finish;
+       }
 
        /* Pure sort by name */
        cmp = modest_text_utils_utf8_strcmp (name1, name2, TRUE);
@@ -3489,18 +3556,39 @@ update_style (ModestFolderView *self)
 {
        ModestFolderViewPrivate *priv;
        GdkColor style_color;
+       PangoAttrList *attr_list;
+       GtkStyle *style;
+       PangoAttribute *attr;
 
        g_return_if_fail (MODEST_IS_FOLDER_VIEW (self));
        priv = MODEST_FOLDER_VIEW_GET_PRIVATE (self);
 
+       /* Set color */
+
+       attr_list = pango_attr_list_new ();
        if (!gtk_style_lookup_color (GTK_WIDGET (self)->style, "SecondaryTextColor", &style_color)) {
                gdk_color_parse ("grey", &style_color);
        }
+       attr = pango_attr_foreground_new (style_color.red, style_color.green, style_color.blue);
+       pango_attr_list_insert (attr_list, attr);
+       
+       /* set font */
+       style = gtk_rc_get_style_by_paths (gtk_widget_get_settings
+                                          (GTK_WIDGET(self)),
+                                          "SmallSystemFont", NULL,
+                                          G_TYPE_NONE);
+       if (style) {
+               attr = pango_attr_font_desc_new (pango_font_description_copy
+                                                (style->font_desc));
+               pango_attr_list_insert (attr_list, attr);
 
-       g_object_set (G_OBJECT (priv->messages_renderer),
-                     "foreground-gdk", &style_color,
-                     "foreground-set", TRUE,
-                     NULL);
+               g_object_set (G_OBJECT (priv->messages_renderer),
+                             "foreground-gdk", &style_color,
+                             "foreground-set", TRUE,
+                             "attributes", attr_list,
+                             NULL);
+               pango_attr_list_unref (attr_list);
+       }
 }
 
 static void 
@@ -3547,3 +3635,36 @@ modest_folder_view_unset_filter (ModestFolderView *self,
                gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (filter_model));  
        }
 }
+
+gboolean
+modest_folder_view_any_folder_fulfils_rules (ModestFolderView *self,
+                                            ModestTnyFolderRules rules)
+{
+       GtkTreeModel *filter_model;
+       GtkTreeIter iter;
+       gboolean fulfil = FALSE;
+
+       if (!get_inner_models (self, &filter_model, NULL, NULL))
+               return FALSE;
+
+       if (!gtk_tree_model_get_iter_first (filter_model, &iter))
+               return FALSE;
+
+       do {
+               TnyFolderStore *folder;
+
+               gtk_tree_model_get (filter_model, &iter, INSTANCE_COLUMN, &folder, -1);
+               if (folder) {
+                       if (TNY_IS_FOLDER (folder)) {
+                               ModestTnyFolderRules folder_rules = modest_tny_folder_get_rules (TNY_FOLDER (folder));
+                               /* Folder rules are negative: non_writable, non_deletable... */
+                               if (!(folder_rules & rules))
+                                       fulfil = TRUE;
+                       }
+                       g_object_unref (folder);
+               }
+
+       } while (gtk_tree_model_iter_next (filter_model, &iter) && !fulfil);
+
+       return fulfil;
+}