* fix for NB#74144 (modest thinks foo/drafts is Drafts)
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Wed, 24 Oct 2007 12:01:50 +0000 (12:01 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Wed, 24 Oct 2007 12:01:50 +0000 (12:01 +0000)
  - made the check more precise, ie. compare the full path, not just the name
  - cleaned up the code and its callers

pmo-trunk-r3569

src/maemo/modest-msg-view-window.c
src/modest-tny-folder.c
src/modest-tny-folder.h
src/widgets/modest-mail-header-view.c

index 4d1cf23..6e27bfd 100644 (file)
@@ -1838,15 +1838,8 @@ modest_msg_view_window_get_folder_type (ModestMsgViewWindow *window)
                TnyFolder *folder;
 
                folder = tny_msg_get_folder (msg);
-               
                if (folder) {
                        folder_type = tny_folder_get_folder_type (folder);
-                       
-                       if (folder_type == TNY_FOLDER_TYPE_NORMAL || folder_type == TNY_FOLDER_TYPE_UNKNOWN) {
-                               const gchar *fname = tny_folder_get_name (folder);
-                               folder_type = modest_tny_folder_guess_folder_type_from_name (fname);
-                       }
-
                        g_object_unref (folder);
                }
                g_object_unref (msg);
index cea0d09..12b5022 100644 (file)
 #include <modest-runtime.h>
 #include <modest-tny-account-store.h>
 
-TnyFolderType
-modest_tny_folder_guess_folder_type_from_name (const gchar* name)
-{
-       gint  type;
-       gchar *folder;
-       gchar *dc_outbox = NULL;
-       gchar *dc_sent = NULL;
-       gchar *dc_drafts = NULL;
 
-       g_return_val_if_fail (name, TNY_FOLDER_TYPE_UNKNOWN);
-       
-       type = TNY_FOLDER_TYPE_UNKNOWN;
-       folder = g_utf8_strdown (name, strlen(name));
-       dc_outbox = g_utf8_strdown (_("mcen_me_folder_outbox"), -1);
-       dc_sent = g_utf8_strdown (_("mcen_me_folder_sent"), -1);
-       dc_drafts = g_utf8_strdown (_("mcen_me_folder_drafts"), -1);
-
-//     if (strcmp (folder, "inbox") == 0 ||
-//         strcmp (folder, _("inbox")) == 0 ||
-//         strcmp (folder, _("mcen_me_folder_inbox")) == 0)
-//             type = TNY_FOLDER_TYPE_INBOX;
-       if (strcmp (folder, dc_outbox) == 0)
-               type = TNY_FOLDER_TYPE_OUTBOX;
-//     else if (g_str_has_prefix(folder, "junk") ||
-//              g_str_has_prefix(folder, _("junk")))
-//             type = TNY_FOLDER_TYPE_JUNK;
-//     else if (g_str_has_prefix(folder, "trash") ||
-//              g_str_has_prefix(folder, _("trash")))
-//             type = TNY_FOLDER_TYPE_TRASH;
-       else if (strcmp (folder, dc_sent) == 0)
-               type = TNY_FOLDER_TYPE_SENT;
-       else if (strcmp (folder, dc_drafts) == 0)
-               type = TNY_FOLDER_TYPE_DRAFTS;
-//     else if (g_str_has_prefix(folder, "notes") ||
-//              g_str_has_prefix(folder, _("notes")))
-//             type = TNY_FOLDER_TYPE_NOTES;
-//     else if (g_str_has_prefix(folder, "contacts") ||
-//              g_str_has_prefix(folder, _("contacts")))
-//             type = TNY_FOLDER_TYPE_CONTACTS;
-//     else if (g_str_has_prefix(folder, "calendar") ||
-//              g_str_has_prefix(folder, _("calendar")))
-//             type = TNY_FOLDER_TYPE_CALENDAR;
+/* make sure you use the *full* name, because foo/drafts is not the same as drafts */
+static TnyFolderType
+modest_tny_folder_guess_folder_type_from_name (const gchar* full_name)
+{
+       g_return_val_if_fail (full_name, TNY_FOLDER_TYPE_UNKNOWN);
        
-       g_free (folder);
-       g_free (dc_outbox);
-       g_free (dc_sent);
-       g_free (dc_drafts);
-       return type;
+       if (strcmp (full_name, modest_local_folder_info_get_type_name(TNY_FOLDER_TYPE_OUTBOX)) == 0)
+               return TNY_FOLDER_TYPE_OUTBOX;
+       else if (strcmp (full_name, modest_local_folder_info_get_type_name(TNY_FOLDER_TYPE_DRAFTS)) == 0)
+               return TNY_FOLDER_TYPE_DRAFTS;
+       return
+               TNY_FOLDER_TYPE_UNKNOWN;
 }
 
 
@@ -104,8 +69,8 @@ modest_tny_folder_guess_folder_type (const TnyFolder *folder)
                type = tny_folder_get_folder_type (TNY_FOLDER (folder));
        
        if (type == TNY_FOLDER_TYPE_UNKNOWN) {
-               const gchar *folder_name;
-               folder_name = tny_folder_get_name (TNY_FOLDER (folder));
+               const gchar *folder_name =
+                       tny_camel_folder_get_full_name (TNY_CAMEL_FOLDER (folder));
                type =  modest_tny_folder_guess_folder_type_from_name (folder_name);
        }
 
index 03c12b6..0ae722c 100644 (file)
@@ -69,19 +69,6 @@ typedef enum {
  */
 TnyFolderType  modest_tny_folder_guess_folder_type   (const TnyFolder *folder);
 
-/**
- * modest_tny_folder_guess_type_from_name:
- * @folder_name: a folder name
- * 
- * determine the type of the folder. first, we see if tinymail
- * can give a specific type. if it cannot, we try to guess the
- * type, based on the name of the folder
- *
- * Note: this is a Class function, there does not require a tnyfolder instance
- *  
- * Returns: the folder type, or TNY_FOLDER_TYPE_UNKNOWN
- */
-TnyFolderType  modest_tny_folder_guess_folder_type_from_name   (const gchar *folder_name);
 
 
 /**
index 3875202..58bad84 100644 (file)
@@ -207,12 +207,7 @@ modest_mail_header_view_update_is_outgoing (TnyHeaderView *self)
        folder = tny_header_get_folder (priv->header);
 
        if (folder) {
-               TnyFolderType folder_type;
-               folder_type = tny_folder_get_folder_type (folder);
-               if (folder_type == TNY_FOLDER_TYPE_NORMAL || folder_type == TNY_FOLDER_TYPE_UNKNOWN) {
-                       const gchar *fname = tny_folder_get_name (folder);
-                       folder_type = modest_tny_folder_guess_folder_type_from_name (fname);
-               }
+               TnyFolderType folder_type = tny_folder_get_folder_type (folder);
 
                switch (folder_type) {
                case TNY_FOLDER_TYPE_DRAFTS: