* modest-main:
[modest] / src / modest-init.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 <config.h>
31 #include <widgets/modest-header-view.h>
32 #include <widgets/modest-folder-view.h>
33 #include <modest-tny-platform-factory.h>
34 #include <modest-widget-memory.h>
35 #include <modest-widget-memory-priv.h>
36 #include <modest-init.h>
37
38 typedef struct {
39         ModestHeaderViewColumn col;
40         guint                  width;
41 } FolderCols;
42
43
44 #if MODEST_PLATFORM_ID==1   /*gtk*/
45 static const FolderCols INBOX_COLUMNS[] = {
46         {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 20},
47         {MODEST_HEADER_VIEW_COLUMN_ATTACH,  20},
48         {MODEST_HEADER_VIEW_COLUMN_FROM,    50},
49         {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 50},
50         {MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE, 50},
51         {MODEST_HEADER_VIEW_COLUMN_SIZE, 30},
52 };
53
54 static const FolderCols OUTBOX_COLUMNS[] = {
55          {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 20},
56          {MODEST_HEADER_VIEW_COLUMN_ATTACH,  20},
57          {MODEST_HEADER_VIEW_COLUMN_TO,    50},
58          {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 50},
59          {MODEST_HEADER_VIEW_COLUMN_SENT_DATE, 50},
60          {MODEST_HEADER_VIEW_COLUMN_SIZE, 30},
61 };
62 #elif MODEST_PLATFORM==2  /*maemo*/
63 static const FolderCols INBOX_COLUMNS = {
64         {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 20},
65         {MODEST_HEADER_VIEW_COLUMN_ATTACH,  20},
66         {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN,150},
67 };
68 static const FolderCols OUTBOX_COLUMNS = {
69          {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 20},
70          {MODEST_HEADER_VIEW_COLUMN_ATTACH,  20},
71          {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT,150},
72 };
73 #endif /*MODEST_PLATFORM*/
74
75
76 static ModestTnyPlatformFactory*
77 get_platform_factory (void)
78 {
79         TnyPlatformFactory *fact =
80                 modest_tny_platform_factory_get_instance ();
81
82         if (!fact) {
83                 g_printerr ("modest: cannot get platform factory instance\n");
84                 return NULL;
85         }
86
87         return MODEST_TNY_PLATFORM_FACTORY(fact);
88 }
89
90
91 static ModestConf*
92 get_modest_conf (void)
93 {
94         ModestTnyPlatformFactory *fact =
95                 get_platform_factory ();
96         ModestConf *conf =
97                 modest_tny_platform_factory_get_conf_instance (fact);
98         if (!conf) {
99                 g_printerr ("modest: cannot get modest conf instance\n");
100                 return NULL;
101         }
102         return conf;
103 }
104
105
106 /* NOTE: the exact details of this format are important, as they
107  * are also used in modest-widget-memory. FIXME: make a shared function
108  * for this with widget-memory
109  */
110 static gboolean
111 save_header_settings (ModestConf *conf, TnyFolderType type, const FolderCols* cols,
112                      guint col_num, gboolean overwrite)
113 {
114         int i;
115         gchar *key;
116         GString *str;
117
118         g_return_val_if_fail (cols, FALSE);
119
120         key = _modest_widget_memory_get_keyname_with_type ("header-view",
121                                                            type,
122                                                            MODEST_WIDGET_MEMORY_PARAM_COLUMN_WIDTH);
123         /* if we're not in overwrite mode, only write stuff it
124          * there was nothing before */
125         if (!overwrite &&  modest_conf_key_exists(conf, key, NULL)) {
126                 g_free (key);
127                 return TRUE;
128         }
129
130         /* the format is necessarily the same as the one in modest-widget-memory */
131         str = g_string_new (NULL);
132         for (i = 0; i != col_num; ++i) 
133                 g_string_append_printf (str, "%d:%d ",
134                                         cols[i].col, cols[i].width); 
135
136         modest_conf_set_string (conf, key, str->str, NULL);
137         g_free (key);
138         g_string_free (str, TRUE);
139         
140         return TRUE;
141 }
142
143 /* we set the the defaults here for all folder types */
144 gboolean
145 modest_init_header_columns (gboolean overwrite)
146 {
147         ModestConf *conf;
148         int folder_type;
149
150         conf = get_modest_conf ();
151         if (!conf) {
152                 g_printerr ("modest: cannot get modest conf\n");
153                 return FALSE;
154         }
155         
156         for (folder_type = TNY_FOLDER_TYPE_UNKNOWN;
157              folder_type <= TNY_FOLDER_TYPE_CALENDAR; ++folder_type) {          
158                 
159                 switch (folder_type) {
160                 case TNY_FOLDER_TYPE_OUTBOX:
161                 case TNY_FOLDER_TYPE_SENT:
162                 case TNY_FOLDER_TYPE_DRAFTS:
163                         save_header_settings (conf, folder_type, OUTBOX_COLUMNS,
164                                               G_N_ELEMENTS(OUTBOX_COLUMNS),
165                                               overwrite);
166                         break;
167                 default:
168                         save_header_settings (conf, folder_type, INBOX_COLUMNS,
169                                               G_N_ELEMENTS(INBOX_COLUMNS),
170                                               overwrite);
171                 };
172         }
173         return TRUE;
174 }
175
176 gboolean
177 modest_init_local_folders  (void)
178 {
179         return TRUE;
180 }