From fd61a8ce03698d13f0a4af5fe2133e49c9ddb53d Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 17 Jan 2007 09:10:35 +0000 Subject: [PATCH] * all: - implement local folders; still needs some work though pmo-trunk-r655 --- src/modest-init.c | 15 +++------ src/modest-init.h | 2 +- src/modest-local-folder-info.c | 7 +++++ src/modest-local-folder-info.h | 15 ++++++++- src/modest-tny-account-store.c | 54 +++++++++++++++++++++++++++++++- src/modest-tny-account-store.h | 1 - src/modest-tny-folder.c | 62 ------------------------------------- src/modest-tny-folder.h | 22 ------------- src/modest-tny-platform-factory.h | 1 + 9 files changed, 81 insertions(+), 98 deletions(-) diff --git a/src/modest-init.c b/src/modest-init.c index d17f137..908142a 100644 --- a/src/modest-init.c +++ b/src/modest-init.c @@ -186,36 +186,31 @@ gboolean modest_init_local_folders (void) { int i; - gchar *path; + gchar *maildir_path; static const gchar* maildirs[] = { "cur", "new", "tmp" }; - path = g_build_filename (g_get_home_dir(), ".modest", NULL); - - if (g_access (path, W_OK) != 0) { - g_printerr ("modest: cannot write into %s\n", path); - g_free (path); - return FALSE; - } + maildir_path = modest_local_folder_info_get_maildir_path (); for (i = 0; i != G_N_ELEMENTS(LOCAL_FOLDERS); ++i) { int j; for (j = 0; j != G_N_ELEMENTS(maildirs); ++j) { gchar *dir; - dir = g_build_filename (path, "local_folders", + dir = g_build_filename (maildir_path, modest_local_folder_info_get_type_name(LOCAL_FOLDERS[i]), maildirs[j], NULL); if (g_mkdir_with_parents (dir, 0755) < 0) { g_printerr ("modest: failed to create %s\n", dir); g_free (dir); + g_free (maildir_path); return FALSE; } g_free(dir); } } - g_free (path); + g_free (maildir_path); return TRUE; } diff --git a/src/modest-init.h b/src/modest-init.h index 690d64b..74355e8 100644 --- a/src/modest-init.h +++ b/src/modest-init.h @@ -36,7 +36,6 @@ /* * functions to initialize various parts of the modest system */ - G_BEGIN_DECLS /** @@ -61,6 +60,7 @@ gboolean modest_init_header_columns (gboolean overwrite); */ gboolean modest_init_local_folders (void); + G_END_DECLS #endif /*__MODEST_INIT_H__*/ diff --git a/src/modest-local-folder-info.c b/src/modest-local-folder-info.c index dfdfd6c..1c89200 100644 --- a/src/modest-local-folder-info.c +++ b/src/modest-local-folder-info.c @@ -90,3 +90,10 @@ modest_local_folder_info_get_type_display_name (ModestLocalFolderType type) } +gchar * +modest_local_folder_info_get_maildir_path (void) +{ + return g_build_filename (g_get_home_dir(), ".modest", + "local_folders", NULL); +} + diff --git a/src/modest-local-folder-info.h b/src/modest-local-folder-info.h index 4b5ea10..8e2937d 100644 --- a/src/modest-local-folder-info.h +++ b/src/modest-local-folder-info.h @@ -72,7 +72,7 @@ ModestLocalFolderType modest_local_folder_info_get_type (const gchar *name); const gchar* modest_local_folder_info_get_type_name (ModestLocalFolderType type); /** - * modest_local_folder_get_type_display_name + * modest_local_folder_info_get_type_display_name * @type: the type of the local folder * * get the localized display name for some local folder @@ -84,6 +84,19 @@ const gchar* modest_local_folder_info_get_type_name (ModestLocalFolderType type) const gchar* modest_local_folder_info_get_type_display_name (ModestLocalFolderType type); +/** + * modest_local_folder_info_get_maildir_path + * @type: the type of the local folder + * + * get the path to the Maildir where the local folders are stored + * + * Returns: the local_folders Maildir path as a newly allocated + * string, which must be freed by the caller. + * + */ +gchar *modest_local_folder_info_get_maildir_path (void); + + G_END_DECLS #endif /* __MODEST_LOCAL_FOLDER_INFO_H__ */ diff --git a/src/modest-tny-account-store.c b/src/modest-tny-account-store.c index 7455bc5..71d6688 100644 --- a/src/modest-tny-account-store.c +++ b/src/modest-tny-account-store.c @@ -41,6 +41,7 @@ #include #include #include +#include #include "modest-account-mgr.h" #include "modest-tny-account-store.h" #include "modest-tny-platform-factory.h" @@ -71,7 +72,9 @@ enum { typedef struct _ModestTnyAccountStorePrivate ModestTnyAccountStorePrivate; struct _ModestTnyAccountStorePrivate { + gchar *cache_dir; + GHashTable *password_hash; TnyDevice *device; TnyPlatformFactory *platform_fact; @@ -159,6 +162,7 @@ modest_tny_account_store_instance_init (ModestTnyAccountStore *obj) MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(obj); priv->cache_dir = NULL; + priv->platform_fact = NULL; priv->tny_session_camel = NULL; priv->device = NULL; @@ -505,6 +509,44 @@ modest_tny_account_store_add_transport_account (TnyAccountStore *self, } +/* create a pseudo-account for our local folders */ +static TnyAccount* +get_local_folder_account (ModestTnyAccountStore *self) +{ + TnyStoreAccount *tny_account; + CamelURL *url; + gchar *maildir, *url_string; + ModestTnyAccountStorePrivate *priv; + + priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self); + + tny_account = tny_camel_store_account_new (); + if (!tny_account) { + g_printerr ("modest: cannot create account for local folders"); + return NULL; + } + + maildir = modest_local_folder_info_get_maildir_path (); + + url = camel_url_new ("maildir:", NULL); + camel_url_set_path (url, maildir); + + url_string = camel_url_to_string (url, 0); + tny_account_set_url_string (TNY_ACCOUNT(tny_account), url_string); + + tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account), + priv->tny_session_camel); + + tny_account_set_name (TNY_ACCOUNT(tny_account), _("Local folders")); + + camel_url_free (url); + g_free (maildir); + g_free (url_string); + + return TNY_ACCOUNT(tny_account); +} + + static TnyAccount* get_tny_account_from_account (ModestTnyAccountStore *self, ModestAccountData *account_data, TnyGetAccountsRequestType type) @@ -548,6 +590,7 @@ modest_tny_account_store_get_accounts (TnyAccountStore *iface, TnyList *list, ModestTnyAccountStorePrivate *priv; GSList *accounts, *cursor; ModestAccountMgr *account_mgr; + TnyAccount *local_folder_account; g_return_if_fail (iface); g_return_if_fail (TNY_IS_LIST(list)); @@ -577,6 +620,14 @@ modest_tny_account_store_get_accounts (TnyAccountStore *iface, TnyList *list, modest_account_mgr_free_account_data (account_mgr, account_data); } g_slist_free (accounts); + + /* also, add the local folder pseudo-account */ + local_folder_account = get_local_folder_account (MODEST_TNY_ACCOUNT_STORE(self)); + if (!local_folder_account) + g_printerr ("modest: failed to add local folders account\n"); + else + tny_list_prepend (list, G_OBJECT(local_folder_account)); + tny_session_camel_set_account_store (priv->tny_session_camel, iface); } @@ -652,11 +703,12 @@ void modest_tny_account_store_set_get_pass_func (ModestTnyAccountStore *self, ModestTnyGetPassFunc func) { - g_warning (__FUNCTION__); + g_message (__FUNCTION__); return; /* not implemented, we use signals */ } + TnySessionCamel* tny_account_store_get_session (TnyAccountStore *self) { diff --git a/src/modest-tny-account-store.h b/src/modest-tny-account-store.h index d1f674a..81ffa97 100644 --- a/src/modest-tny-account-store.h +++ b/src/modest-tny-account-store.h @@ -91,7 +91,6 @@ GType modest_tny_account_store_get_type (void) G_GNUC_CONST; */ ModestTnyAccountStore* modest_tny_account_store_new (ModestAccountMgr *account_mgr); - /** * tny_account_store_get_session * @self: a TnyAccountStore instance diff --git a/src/modest-tny-folder.c b/src/modest-tny-folder.c index 9f6f290..b527cd0 100644 --- a/src/modest-tny-folder.c +++ b/src/modest-tny-folder.c @@ -33,68 +33,6 @@ #include -typedef struct { - ModestLocalFolderType type; - const gchar *name; - const gchar *display_name; -} ModestLocalFolder; - -const ModestLocalFolder ModestLocalFolderMap[] = { - { MODEST_LOCAL_FOLDER_TYPE_JUNK, "junk", N_("junk")}, - { MODEST_LOCAL_FOLDER_TYPE_TRASH, "trash", N_("trash")}, - { MODEST_LOCAL_FOLDER_TYPE_DRAFTS, "drafts", N_("drafts")}, - { MODEST_LOCAL_FOLDER_TYPE_SENT, "sent", N_("sent")}, - { MODEST_LOCAL_FOLDER_TYPE_OUTBOX, "outbox", N_("outbox")}, - { MODEST_LOCAL_FOLDER_TYPE_ARCHIVE, "archive", N_("archive")} -}; - - -ModestLocalFolderType -modest_tny_folder_get_local_folder_type (const gchar *name) -{ - int i; - - g_return_val_if_fail (name, MODEST_LOCAL_FOLDER_TYPE_UNKNOWN); - - for (i = 0; i != G_N_ELEMENTS(ModestLocalFolderMap); ++i) { - if (strcmp (ModestLocalFolderMap[i].name, name) == 0) - return ModestLocalFolderMap[i].type; - } - return MODEST_LOCAL_FOLDER_TYPE_UNKNOWN; -} - -const gchar* -modest_tny_folder_get_local_folder_type_name (ModestLocalFolderType type) -{ - int i = 0; - g_return_val_if_fail (type > MODEST_LOCAL_FOLDER_TYPE_UNKNOWN && - type < MODEST_LOCAL_FOLDER_TYPE_NUM, NULL); - - for (i = 0; i != G_N_ELEMENTS(ModestLocalFolderMap); ++i) { - if (ModestLocalFolderMap[i].type == type) - return ModestLocalFolderMap[i].name; - } - return NULL; -} - - -const gchar* -modest_tny_folder_get_local_folder_type_display_name (ModestLocalFolderType type) -{ - int i = 0; - g_return_val_if_fail (type > MODEST_LOCAL_FOLDER_TYPE_UNKNOWN && - type < MODEST_LOCAL_FOLDER_TYPE_NUM, NULL); - - for (i = 0; i != G_N_ELEMENTS(ModestLocalFolderMap); ++i) { - if (ModestLocalFolderMap[i].type == type) - return ModestLocalFolderMap[i].display_name; - } - return NULL; -} - - - - TnyFolderType modest_tny_folder_guess_folder_type_from_name (const gchar* name) { diff --git a/src/modest-tny-folder.h b/src/modest-tny-folder.h index 0ace9ac..51a04db 100644 --- a/src/modest-tny-folder.h +++ b/src/modest-tny-folder.h @@ -43,20 +43,6 @@ typedef enum { MODEST_FOLDER_RULES_FOLDER_DELETABLE } ModestTnyFolderRules; -typedef enum { - MODEST_LOCAL_FOLDER_TYPE_UNKNOWN, - - MODEST_LOCAL_FOLDER_TYPE_DRAFTS, - MODEST_LOCAL_FOLDER_TYPE_SENT, - MODEST_LOCAL_FOLDER_TYPE_OUTBOX, - MODEST_LOCAL_FOLDER_TYPE_ARCHIVE, - MODEST_LOCAL_FOLDER_TYPE_JUNK, - MODEST_LOCAL_FOLDER_TYPE_TRASH, - - MODEST_LOCAL_FOLDER_TYPE_NUM -} ModestLocalFolderType; - - /** * modest_tny_folder_guess_type: * @folder: a valid tnymail folder @@ -96,14 +82,6 @@ TnyFolderType modest_tny_folder_guess_folder_type_from_name (const gchar *fol */ ModestTnyFolderRules modest_tny_folder_get_rules (const TnyFolder *folder); - -/* some class-function (ie. don't require TnyFolder* */ -ModestLocalFolderType modest_tny_folder_get_local_folder_type (const gchar *name); -const gchar* modest_tny_folder_get_local_folder_type_name (ModestLocalFolderType type); -const gchar* modest_tny_folder_get_local_folder_type_display_name (ModestLocalFolderType type); - - - G_END_DECLS #endif /* __MODEST_TNY_FOLDER_H__*/ diff --git a/src/modest-tny-platform-factory.h b/src/modest-tny-platform-factory.h index fdd92ea..a9fa02b 100644 --- a/src/modest-tny-platform-factory.h +++ b/src/modest-tny-platform-factory.h @@ -110,6 +110,7 @@ ModestConf* modest_tny_platform_factory_get_conf_instance (ModestTnyPlatform **/ ModestMailOperationQueue* modest_tny_platform_factory_get_mail_operation_queue_instance (ModestTnyPlatformFactory *fact); + G_END_DECLS #endif /* __MODEST_TNY_PLATFORM_FACTORY_H__ */ -- 1.7.9.5