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>
40 #include <modest-account-mgr.h>
41 #include <modest-account-mgr-helpers.h>
44 ModestHeaderViewColumn col;
48 static const FolderCols INBOX_COLUMNS_DETAILS[] = {
49 {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
50 {MODEST_HEADER_VIEW_COLUMN_ATTACH, 40},
51 {MODEST_HEADER_VIEW_COLUMN_FROM, 80},
52 {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 80},
53 {MODEST_HEADER_VIEW_COLUMN_RECEIVED_DATE, 60},
54 {MODEST_HEADER_VIEW_COLUMN_SIZE, 50}
56 static const FolderCols INBOX_COLUMNS_TWOLINES[] = {
57 {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
58 {MODEST_HEADER_VIEW_COLUMN_ATTACH, 40},
59 {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_IN, 200}
62 static const FolderCols OUTBOX_COLUMNS_DETAILS[] = {
63 {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
64 {MODEST_HEADER_VIEW_COLUMN_ATTACH, 40},
65 {MODEST_HEADER_VIEW_COLUMN_TO, 80},
66 {MODEST_HEADER_VIEW_COLUMN_SUBJECT, 80},
67 {MODEST_HEADER_VIEW_COLUMN_SENT_DATE, 80},
68 {MODEST_HEADER_VIEW_COLUMN_SIZE, 50}
70 static const FolderCols OUTBOX_COLUMNS_TWOLINES[] = {
71 {MODEST_HEADER_VIEW_COLUMN_MSGTYPE, 40},
72 {MODEST_HEADER_VIEW_COLUMN_ATTACH, 40},
73 {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT,200},
76 static const TnyFolderType LOCAL_FOLDERS[] = {
77 TNY_FOLDER_TYPE_OUTBOX,
78 TNY_FOLDER_TYPE_DRAFTS,
80 TNY_FOLDER_TYPE_ARCHIVE
83 static ModestTnyPlatformFactory*
84 get_platform_factory (void)
86 TnyPlatformFactory *fact =
87 modest_tny_platform_factory_get_instance ();
90 g_printerr ("modest: cannot get platform factory instance\n");
94 return MODEST_TNY_PLATFORM_FACTORY(fact);
99 get_modest_conf (void)
101 ModestTnyPlatformFactory *fact =
102 get_platform_factory ();
104 modest_tny_platform_factory_get_conf_instance (fact);
106 g_printerr ("modest: cannot get modest conf instance\n");
113 static ModestAccountMgr*
114 get_account_mgr (void)
116 ModestTnyPlatformFactory *fact =
117 get_platform_factory ();
118 ModestAccountMgr *acc_mgr =
119 modest_tny_platform_factory_get_account_mgr_instance (fact);
121 g_printerr ("modest: cannot get modest account mgr instance\n");
128 /* NOTE: the exact details of this format are important, as they
129 * are also used in modest-widget-memory. FIXME: make a shared function
130 * for this with widget-memory
133 save_header_settings (ModestConf *conf, TnyFolderType type,
134 ModestHeaderViewStyle style, const FolderCols* cols,
135 guint col_num, gboolean overwrite)
141 g_return_val_if_fail (cols, FALSE);
143 key = _modest_widget_memory_get_keyname_with_double_type ("header-view",
145 MODEST_WIDGET_MEMORY_PARAM_COLUMN_WIDTH);
146 /* if we're not in overwrite mode, only write stuff it
147 * there was nothing before */
148 if (!overwrite && modest_conf_key_exists(conf, key, NULL)) {
153 /* the format is necessarily the same as the one in modest-widget-memory */
154 str = g_string_new (NULL);
155 for (i = 0; i != col_num; ++i)
156 g_string_append_printf (str, "%d:%d ",
157 cols[i].col, cols[i].width);
159 modest_conf_set_string (conf, key, str->str, NULL);
161 g_string_free (str, TRUE);
166 /* we set the the defaults here for all folder types */
168 modest_init_header_columns (gboolean overwrite)
173 conf = get_modest_conf ();
175 g_printerr ("modest: cannot get modest conf\n");
179 for (folder_type = TNY_FOLDER_TYPE_UNKNOWN;
180 folder_type <= TNY_FOLDER_TYPE_CALENDAR; ++folder_type) {
182 switch (folder_type) {
183 case TNY_FOLDER_TYPE_OUTBOX:
184 case TNY_FOLDER_TYPE_SENT:
185 case TNY_FOLDER_TYPE_DRAFTS:
186 save_header_settings (conf, folder_type,
187 MODEST_HEADER_VIEW_STYLE_DETAILS,
188 OUTBOX_COLUMNS_DETAILS,
189 G_N_ELEMENTS(OUTBOX_COLUMNS_DETAILS),
191 save_header_settings (conf, folder_type,
192 MODEST_HEADER_VIEW_STYLE_TWOLINES,
193 OUTBOX_COLUMNS_TWOLINES,
194 G_N_ELEMENTS(OUTBOX_COLUMNS_TWOLINES),
199 save_header_settings (conf, folder_type,
200 MODEST_HEADER_VIEW_STYLE_DETAILS,
201 INBOX_COLUMNS_DETAILS,
202 G_N_ELEMENTS(INBOX_COLUMNS_DETAILS),
204 save_header_settings (conf, folder_type,
205 MODEST_HEADER_VIEW_STYLE_TWOLINES,
206 INBOX_COLUMNS_TWOLINES,
207 G_N_ELEMENTS(INBOX_COLUMNS_TWOLINES),
215 modest_init_local_folders (void)
219 static const gchar* maildirs[] = {
223 maildir_path = modest_local_folder_info_get_maildir_path ();
225 for (i = 0; i != G_N_ELEMENTS(LOCAL_FOLDERS); ++i) {
227 for (j = 0; j != G_N_ELEMENTS(maildirs); ++j) {
229 dir = g_build_filename (maildir_path,
230 modest_local_folder_info_get_type_name(LOCAL_FOLDERS[i]),
233 if (g_mkdir_with_parents (dir, 0755) < 0) {
234 g_printerr ("modest: failed to create %s\n", dir);
236 g_free (maildir_path);
243 g_free (maildir_path);
250 free_element (gpointer data, gpointer user_data)
257 modest_init_default_account_maybe (void)
259 ModestAccountMgr *acc_mgr;
261 GSList *all_accounts = NULL;
262 gchar *default_account;
263 gboolean retval = TRUE;
265 acc_mgr = get_account_mgr ();
267 g_printerr ("modest: cannot get modest account mgr\n");
271 all_accounts = modest_account_mgr_account_names (acc_mgr, NULL);
272 if (all_accounts) { /* if there are any accounts, there should be a default one */
274 modest_account_mgr_get_default_account (acc_mgr);
275 if (!default_account) {
276 gchar *first_account;
277 g_printerr ("modest: no default account defined\n");
278 first_account = (gchar*)all_accounts->data;
279 if ((retval = modest_account_mgr_set_default_account (acc_mgr, first_account)))
280 g_printerr ("modest: set '%s' as the default account\n",
283 g_printerr ("modest: failed to set '%s' as the default account\n",
285 g_free (default_account);
287 g_slist_foreach (all_accounts, free_element, NULL);
288 g_slist_free (all_accounts);