1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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.
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.
31 #include <modest-defs.h>
32 #include <widgets/modest-header-view.h>
33 #include <widgets/modest-folder-view.h>
34 #include <modest-tny-platform-factory.h>
35 #include <modest-widget-memory.h>
36 #include <modest-widget-memory-priv.h>
37 #include <modest-local-folder-info.h>
38 #include <modest-init.h>
39 #include <glib/gstdio.h>
42 ModestHeaderViewColumn col;
47 #if MODEST_PLATFORM_ID==1 /*gtk*/
48 static const FolderCols INBOX_COLUMNS[] = {
49 {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 20},
50 {MODEST_HEADER_VIEW_COLUMN_ATTACH, 20},
51 {MODEST_HEADER_VIEW_COLUMN_FROM, 50},
52 {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 50},
53 {MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE, 50},
54 {MODEST_HEADER_VIEW_COLUMN_SIZE, 30},
57 static const FolderCols OUTBOX_COLUMNS[] = {
58 {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 20},
59 {MODEST_HEADER_VIEW_COLUMN_ATTACH, 20},
60 {MODEST_HEADER_VIEW_COLUMN_TO, 50},
61 {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 50},
62 {MODEST_HEADER_VIEW_COLUMN_SENT_DATE, 50},
63 {MODEST_HEADER_VIEW_COLUMN_SIZE, 30},
65 #elif MODEST_PLATFORM==2 /*maemo*/
66 static const FolderCols INBOX_COLUMNS = {
67 {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 20},
68 {MODEST_HEADER_VIEW_COLUMN_ATTACH, 20},
69 {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN,150},
71 static const FolderCols OUTBOX_COLUMNS = {
72 {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 20},
73 {MODEST_HEADER_VIEW_COLUMN_ATTACH, 20},
74 {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT,150},
76 #endif /*MODEST_PLATFORM*/
78 static const ModestLocalFolderType LOCAL_FOLDERS[] = {
79 MODEST_LOCAL_FOLDER_TYPE_OUTBOX,
80 MODEST_LOCAL_FOLDER_TYPE_DRAFTS,
81 MODEST_LOCAL_FOLDER_TYPE_SENT,
82 MODEST_LOCAL_FOLDER_TYPE_ARCHIVE
86 static ModestTnyPlatformFactory*
87 get_platform_factory (void)
89 TnyPlatformFactory *fact =
90 modest_tny_platform_factory_get_instance ();
93 g_printerr ("modest: cannot get platform factory instance\n");
97 return MODEST_TNY_PLATFORM_FACTORY(fact);
102 get_modest_conf (void)
104 ModestTnyPlatformFactory *fact =
105 get_platform_factory ();
107 modest_tny_platform_factory_get_conf_instance (fact);
109 g_printerr ("modest: cannot get modest conf instance\n");
116 /* NOTE: the exact details of this format are important, as they
117 * are also used in modest-widget-memory. FIXME: make a shared function
118 * for this with widget-memory
121 save_header_settings (ModestConf *conf, TnyFolderType type, const FolderCols* cols,
122 guint col_num, gboolean overwrite)
128 g_return_val_if_fail (cols, FALSE);
130 key = _modest_widget_memory_get_keyname_with_type ("header-view",
132 MODEST_WIDGET_MEMORY_PARAM_COLUMN_WIDTH);
133 /* if we're not in overwrite mode, only write stuff it
134 * there was nothing before */
135 if (!overwrite && modest_conf_key_exists(conf, key, NULL)) {
140 /* the format is necessarily the same as the one in modest-widget-memory */
141 str = g_string_new (NULL);
142 for (i = 0; i != col_num; ++i)
143 g_string_append_printf (str, "%d:%d ",
144 cols[i].col, cols[i].width);
146 modest_conf_set_string (conf, key, str->str, NULL);
148 g_string_free (str, TRUE);
153 /* we set the the defaults here for all folder types */
155 modest_init_header_columns (gboolean overwrite)
160 conf = get_modest_conf ();
162 g_printerr ("modest: cannot get modest conf\n");
166 for (folder_type = TNY_FOLDER_TYPE_UNKNOWN;
167 folder_type <= TNY_FOLDER_TYPE_CALENDAR; ++folder_type) {
169 switch (folder_type) {
170 case TNY_FOLDER_TYPE_OUTBOX:
171 case TNY_FOLDER_TYPE_SENT:
172 case TNY_FOLDER_TYPE_DRAFTS:
173 save_header_settings (conf, folder_type, OUTBOX_COLUMNS,
174 G_N_ELEMENTS(OUTBOX_COLUMNS),
178 save_header_settings (conf, folder_type, INBOX_COLUMNS,
179 G_N_ELEMENTS(INBOX_COLUMNS),
187 modest_init_local_folders (void)
191 static const gchar* maildirs[] = {
195 maildir_path = modest_local_folder_info_get_maildir_path ();
197 for (i = 0; i != G_N_ELEMENTS(LOCAL_FOLDERS); ++i) {
199 for (j = 0; j != G_N_ELEMENTS(maildirs); ++j) {
201 dir = g_build_filename (maildir_path,
202 modest_local_folder_info_get_type_name(LOCAL_FOLDERS[i]),
205 if (g_mkdir_with_parents (dir, 0755) < 0) {
206 g_printerr ("modest: failed to create %s\n", dir);
208 g_free (maildir_path);
215 g_free (maildir_path);