X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fmodest-init.c;h=a9568d5b04708289d3ada2e2943fe150637164dd;hb=da78260d1ea50e18f9a307b2deb1a0adec2fc2c8;hp=9a5f0ba943de1993b297ccde419192b37e74b952;hpb=c537f8f378839e858fd033107c02d384251f3f57;p=modest diff --git a/src/modest-init.c b/src/modest-init.c index 9a5f0ba..a9568d5 100644 --- a/src/modest-init.c +++ b/src/modest-init.c @@ -37,6 +37,8 @@ #include #include #include +#include +#include typedef struct { ModestHeaderViewColumn col; @@ -71,14 +73,13 @@ static const FolderCols OUTBOX_COLUMNS_TWOLINES[] = { {MODEST_HEADER_VIEW_COLUMN_COMPACT_HEADER_OUT,200}, }; -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 const TnyFolderType LOCAL_FOLDERS[] = { + TNY_FOLDER_TYPE_OUTBOX, + TNY_FOLDER_TYPE_DRAFTS, + TNY_FOLDER_TYPE_SENT, + TNY_FOLDER_TYPE_ARCHIVE }; - static ModestTnyPlatformFactory* get_platform_factory (void) { @@ -109,6 +110,21 @@ get_modest_conf (void) } +static ModestAccountMgr* +get_account_mgr (void) +{ + ModestTnyPlatformFactory *fact = + get_platform_factory (); + ModestAccountMgr *acc_mgr = + modest_tny_platform_factory_get_account_mgr_instance (fact); + if (!acc_mgr) { + g_printerr ("modest: cannot get modest account mgr instance\n"); + return NULL; + } + return acc_mgr; +} + + /* NOTE: the exact details of this format are important, as they * are also used in modest-widget-memory. FIXME: make a shared function * for this with widget-memory @@ -227,3 +243,49 @@ modest_init_local_folders (void) g_free (maildir_path); return TRUE; } + + + +static void +free_element (gpointer data, gpointer user_data) +{ + g_free (data); +} + + +gboolean +modest_init_default_account_maybe (void) +{ + ModestAccountMgr *acc_mgr; + + GSList *all_accounts = NULL; + gchar *default_account; + gboolean retval = TRUE; + + acc_mgr = get_account_mgr (); + if (!acc_mgr) { + g_printerr ("modest: cannot get modest account mgr\n"); + return FALSE; + } + + all_accounts = modest_account_mgr_account_names (acc_mgr, NULL); + if (all_accounts) { /* if there are any accounts, there should be a default one */ + default_account = + modest_account_mgr_get_default_account (acc_mgr); + if (!default_account) { + gchar *first_account; + g_printerr ("modest: no default account defined\n"); + first_account = (gchar*)all_accounts->data; + if ((retval = modest_account_mgr_set_default_account (acc_mgr, first_account))) + g_printerr ("modest: set '%s' as the default account\n", + first_account); + else + g_printerr ("modest: failed to set '%s' as the default account\n", + first_account); + g_free (default_account); + } + g_slist_foreach (all_accounts, free_element, NULL); + g_slist_free (all_accounts); + } + return retval; +}