Added new fixes to changelog, week 31 post release - 3rd Aug.
[modest] / src / modest-local-folder-info.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #include <glib/gi18n.h>
31 #include <string.h> /* strcmp */
32 #include <modest-local-folder-info.h>
33 #include <stdio.h>
34
35 typedef struct {
36         TnyFolderType   type;
37         const gchar     *name;
38         const gchar     *display_name;
39 } ModestLocalFolder;
40
41 const ModestLocalFolder ModestLocalFolderMap[] = {
42         { TNY_FOLDER_TYPE_UNKNOWN,  "<unknown>",  N_("<Unknown>")},
43         { TNY_FOLDER_TYPE_NORMAL,   "<normal>",   N_("<Normal>")},
44         /* There is no special Inbox folder for local accounts */
45 /*      { TNY_FOLDER_TYPE_INBOX,    "inbox",      N_("mcen_me_folder_inbox")}, */
46         { TNY_FOLDER_TYPE_OUTBOX,   "outbox",     N_("mcen_me_folder_outbox")},
47         { TNY_FOLDER_TYPE_TRASH,    "trash",      N_("Trash")},
48         { TNY_FOLDER_TYPE_JUNK,     "junk",       N_("Junk")},
49         { TNY_FOLDER_TYPE_SENT,     "sent",       N_("mcen_me_folder_sent")},
50         { TNY_FOLDER_TYPE_ROOT,     "<root>",     N_("<root>")},
51         { TNY_FOLDER_TYPE_NOTES,    "notes",      N_("Notes")},
52         { TNY_FOLDER_TYPE_DRAFTS,   "drafts",     N_("mcen_me_folder_drafts")},
53 /* TODO: Do we want these? If so, they need a type ID: 
54  *      { TNY_FOLDER_TYPE_OUTBOX,   "contacts",   N_("Contacts")},
55         { TNY_FOLDER_TYPE_OUTBOX,   "calendar",   N_("Calendar")},
56 */
57         { TNY_FOLDER_TYPE_ARCHIVE,  "archive",    N_("mcen_me_folder_archive")}
58 };
59
60
61 TnyFolderType
62 modest_local_folder_info_get_type (const gchar *name)
63 {
64         int i;
65         g_return_val_if_fail (name, TNY_FOLDER_TYPE_UNKNOWN);
66
67         for (i = 0; i != G_N_ELEMENTS(ModestLocalFolderMap); ++i) {
68                 if (strcmp (ModestLocalFolderMap[i].name, name) == 0)
69                         return ModestLocalFolderMap[i].type;
70         }
71         return TNY_FOLDER_TYPE_UNKNOWN;
72 }
73
74
75 const gchar*
76 modest_local_folder_info_get_type_name (TnyFolderType type)
77 {
78         int i = 0;
79         g_return_val_if_fail (type >= TNY_FOLDER_TYPE_UNKNOWN &&
80                               type <  TNY_FOLDER_TYPE_NUM, NULL);
81         
82         for (i = 0; i != G_N_ELEMENTS(ModestLocalFolderMap); ++i) {
83                 if (ModestLocalFolderMap[i].type == type)
84                         return ModestLocalFolderMap[i].name;
85         }
86         return NULL;    
87 }
88
89 const gchar*
90 modest_local_folder_info_get_type_display_name (TnyFolderType type)
91 {
92         int i = 0;
93         g_return_val_if_fail (type >= TNY_FOLDER_TYPE_UNKNOWN &&
94                               type <  TNY_FOLDER_TYPE_NUM, NULL);
95         
96         /* Note that we call _() to get the localized name.
97          * This works because we used N_() on the static string when we initialized the array,
98          * to mark the string for translation.
99          */
100         for (i = 0; i != G_N_ELEMENTS(ModestLocalFolderMap); ++i) {
101                 if (ModestLocalFolderMap[i].type == type)
102                         return _(ModestLocalFolderMap[i].display_name);
103         }
104         return NULL;    
105 }
106
107
108 gchar *
109 modest_local_folder_info_get_maildir_path (const gchar* location_filepath)
110 {
111         return g_build_filename (location_filepath ? location_filepath : g_get_home_dir(),
112                                  MODEST_DIR,
113                                  MODEST_LOCAL_FOLDERS_MAILDIR, 
114                                  NULL);
115 }
116
117 gchar*
118 modest_per_account_local_outbox_folder_info_get_maildir_path (const gchar* account_name)
119 {
120         /* This directory should contain an "outbox" child directory: */
121         return g_build_filename (g_get_home_dir(),
122                                  MODEST_DIR,
123                                  MODEST_PER_ACCOUNT_LOCAL_OUTBOX_FOLDERS_MAILDIR, 
124                                  account_name,
125                                  NULL);
126 }
127
128 gchar*
129 modest_per_account_local_outbox_folder_info_get_maildir_path_to_outbox_folder (const gchar* account_name)
130 {
131         gchar *path_to_account_folder = 
132                 modest_per_account_local_outbox_folder_info_get_maildir_path(account_name);
133         if (!path_to_account_folder)
134                 return NULL;
135
136         gchar *path = g_build_filename (path_to_account_folder, "outbox", NULL);
137
138         g_free (path_to_account_folder);
139
140         return path;
141 }
142
143
144