* all:
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Wed, 17 Jan 2007 00:21:17 +0000 (00:21 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Wed, 17 Jan 2007 00:21:17 +0000 (00:21 +0000)
- create the local folders at startup if the do not yet exist

pmo-trunk-r653

src/modest-init.c
src/modest-main.c
src/modest-tny-folder.c
src/modest-tny-folder.h

index de67233..d9e530e 100644 (file)
@@ -33,7 +33,9 @@
 #include <modest-tny-platform-factory.h>
 #include <modest-widget-memory.h>
 #include <modest-widget-memory-priv.h>
+#include <modest-tny-folder.h>
 #include <modest-init.h>
+#include <glib/gstdio.h>
 
 typedef struct {
        ModestHeaderViewColumn col;
@@ -41,6 +43,7 @@ typedef struct {
 } FolderCols;
 
 
+
 #if MODEST_PLATFORM_ID==1   /*gtk*/
 static const FolderCols INBOX_COLUMNS[] = {
        {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 20},
@@ -72,6 +75,13 @@ static const FolderCols OUTBOX_COLUMNS = {
 };
 #endif /*MODEST_PLATFORM*/
 
+static const ModestLocalFolderType LOCAL_FOLDERS[] = {
+       MODEST_LOCAL_FOLDER_TYPE_OUTBOX,
+       MODEST_LOCAL_FOLDER_TYPE_DRAFTS,
+       MODEST_LOCAL_FOLDER_TYPE_SENT,
+       MODEST_LOCAL_FOLDER_TYPE_ARCHIVE        
+};
+
 
 static ModestTnyPlatformFactory*
 get_platform_factory (void)
@@ -176,5 +186,37 @@ modest_init_header_columns (gboolean overwrite)
 gboolean
 modest_init_local_folders  (void)
 {
+       int i;
+       gchar *path;
+       static const gchar* maildirs[] = {
+               "cur", "new", "tmp"
+       };
+       
+       path = g_build_filename (g_get_home_dir(), ".modest", NULL);
+
+       if (g_access (path, W_OK) != 0) {
+               g_printerr ("modest: cannot write into %s\n", path);
+               g_free (path);
+               return FALSE;
+       }
+
+       for (i = 0; i != G_N_ELEMENTS(LOCAL_FOLDERS); ++i) {
+               int j;
+               for (j = 0; j != G_N_ELEMENTS(maildirs); ++j) {
+                       gchar *dir;
+                       dir = g_build_filename (path, "local_folders",
+                                               modest_tny_folder_get_local_folder_type_name(LOCAL_FOLDERS[i]),
+                                               maildirs[j],
+                                               NULL);
+                       if (g_mkdir_with_parents (dir, 0755) < 0) {
+                               g_printerr ("modest: failed to create %s\n", dir);
+                               g_free (dir);
+                               return FALSE;
+                       }
+                       g_free(dir);
+               }
+       }
+       
+       g_free (path);
        return TRUE;
 }
index 0a08943..8d58594 100644 (file)
 #endif /* MODEST_PLATFORM==2 */
 
 /* return values */
-#define MODEST_ERR_NONE    0
-#define MODEST_ERR_OPTIONS 1
-#define MODEST_ERR_CONF    2
-#define MODEST_ERR_UI      3
-#define MODEST_ERR_HILDON  4
-#define MODEST_ERR_RUN     5
-#define MODEST_ERR_SEND    6
+enum {
+       MODEST_ERR_NONE    = 0,
+       MODEST_ERR_OPTIONS, 
+       MODEST_ERR_CONF,    
+       MODEST_ERR_UI,      
+       MODEST_ERR_HILDON,  
+       MODEST_ERR_RUN,     
+       MODEST_ERR_SEND,    
+       MODEST_ERR_INIT,
+};
 
 static gboolean hildon_init (); /* NOP if HILDON is not defined */
 static int start_ui (const gchar* mailto, const gchar *cc,
@@ -136,6 +139,12 @@ main (int argc, char *argv[])
                retval = MODEST_ERR_CONF;
                goto cleanup;
        }
+
+       if (!modest_init_local_folders ()) {
+               g_printerr ("modest: failed to initialize local folders, exiting\n");
+               retval = MODEST_ERR_INIT;
+               goto cleanup;
+       }
        
        /* Get the account store */
        account_store = tny_platform_factory_new_account_store (fact);
index 8ef6a4c..9f6f290 100644 (file)
 #include <string.h>
 #include <modest-tny-folder.h>
 
+
+typedef struct {
+       ModestLocalFolderType   type;
+       const gchar             *name;
+       const gchar             *display_name;
+} ModestLocalFolder;
+
+const ModestLocalFolder ModestLocalFolderMap[] = {
+       { MODEST_LOCAL_FOLDER_TYPE_JUNK,    "junk",    N_("junk")},
+       { MODEST_LOCAL_FOLDER_TYPE_TRASH,   "trash",   N_("trash")},
+       { MODEST_LOCAL_FOLDER_TYPE_DRAFTS,  "drafts",  N_("drafts")},
+       { MODEST_LOCAL_FOLDER_TYPE_SENT,    "sent",    N_("sent")},
+       { MODEST_LOCAL_FOLDER_TYPE_OUTBOX,  "outbox",  N_("outbox")},
+       { MODEST_LOCAL_FOLDER_TYPE_ARCHIVE, "archive", N_("archive")}
+};
+
+
+ModestLocalFolderType
+modest_tny_folder_get_local_folder_type (const gchar *name)
+{
+       int i;
+
+       g_return_val_if_fail (name, MODEST_LOCAL_FOLDER_TYPE_UNKNOWN);
+
+       for (i = 0; i != G_N_ELEMENTS(ModestLocalFolderMap); ++i) {
+               if (strcmp (ModestLocalFolderMap[i].name, name) == 0)
+                       return ModestLocalFolderMap[i].type;
+       }
+       return MODEST_LOCAL_FOLDER_TYPE_UNKNOWN;
+}
+
+const gchar*
+modest_tny_folder_get_local_folder_type_name (ModestLocalFolderType type)
+{
+       int i = 0;
+       g_return_val_if_fail (type > MODEST_LOCAL_FOLDER_TYPE_UNKNOWN &&
+                             type < MODEST_LOCAL_FOLDER_TYPE_NUM, NULL);
+       
+       for (i = 0; i != G_N_ELEMENTS(ModestLocalFolderMap); ++i) {
+               if (ModestLocalFolderMap[i].type == type)
+                       return ModestLocalFolderMap[i].name;
+       }
+       return NULL;    
+}
+
+
+const gchar*
+modest_tny_folder_get_local_folder_type_display_name (ModestLocalFolderType type)
+{
+       int i = 0;
+       g_return_val_if_fail (type > MODEST_LOCAL_FOLDER_TYPE_UNKNOWN &&
+                             type < MODEST_LOCAL_FOLDER_TYPE_NUM, NULL);
+       
+       for (i = 0; i != G_N_ELEMENTS(ModestLocalFolderMap); ++i) {
+               if (ModestLocalFolderMap[i].type == type)
+                       return ModestLocalFolderMap[i].display_name;
+       }
+       return NULL;    
+}
+
+
+
+
 TnyFolderType
 modest_tny_folder_guess_folder_type_from_name (const gchar* name)
 {
index 0010015..0ace9ac 100644 (file)
@@ -43,6 +43,18 @@ typedef enum {
        MODEST_FOLDER_RULES_FOLDER_DELETABLE 
 } ModestTnyFolderRules;
 
+typedef enum {
+       MODEST_LOCAL_FOLDER_TYPE_UNKNOWN,
+       
+       MODEST_LOCAL_FOLDER_TYPE_DRAFTS,
+       MODEST_LOCAL_FOLDER_TYPE_SENT,
+       MODEST_LOCAL_FOLDER_TYPE_OUTBOX,
+       MODEST_LOCAL_FOLDER_TYPE_ARCHIVE,
+       MODEST_LOCAL_FOLDER_TYPE_JUNK,
+       MODEST_LOCAL_FOLDER_TYPE_TRASH,
+       
+       MODEST_LOCAL_FOLDER_TYPE_NUM    
+} ModestLocalFolderType;
 
 
 /**
@@ -85,6 +97,13 @@ TnyFolderType  modest_tny_folder_guess_folder_type_from_name   (const gchar *fol
 ModestTnyFolderRules  modest_tny_folder_get_rules   (const TnyFolder *folder);
 
 
+/* some class-function (ie. don't require TnyFolder* */
+ModestLocalFolderType modest_tny_folder_get_local_folder_type (const gchar *name);
+const gchar* modest_tny_folder_get_local_folder_type_name (ModestLocalFolderType type);
+const gchar* modest_tny_folder_get_local_folder_type_display_name (ModestLocalFolderType type);
+
+
+
 G_END_DECLS
 
 #endif /* __MODEST_TNY_FOLDER_H__*/