X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-tny-local-folders-account.c;h=2efb49951cfaf86fd252e4fcdf0cd71c8d7ec92c;hp=eecb30c1fd51c33788c103a04d6cbbb79f2f6e52;hb=26a294f695ecdce260e36a11434ddcf2c7f43b9c;hpb=40e92875620a12ce1d34126c9a9c6bce97b21e6c diff --git a/src/modest-tny-local-folders-account.c b/src/modest-tny-local-folders-account.c index eecb30c..2efb499 100644 --- a/src/modest-tny-local-folders-account.c +++ b/src/modest-tny-local-folders-account.c @@ -28,18 +28,18 @@ */ +#include +#include #include #include - +#include #include #include #include +#include #include #include -#include -#include - G_DEFINE_TYPE (ModestTnyLocalFoldersAccount, modest_tny_local_folders_account, TNY_TYPE_CAMEL_STORE_ACCOUNT); @@ -54,6 +54,15 @@ struct _ModestTnyLocalFoldersAccountPrivate GSList *list_extra_folders; }; +static void get_folders (TnyFolderStore *self, + TnyList *list, + TnyFolderStoreQuery *query, + GError **err); + +static TnyFolder* create_folder (TnyFolderStore *self, + const gchar *name, + GError **err); + static void modest_tny_local_folders_account_dispose (GObject *object) { @@ -96,12 +105,6 @@ modest_tny_local_folders_account_finalize (GObject *object) } static void -get_folders (TnyFolderStore *self, TnyList *list, TnyFolderStoreQuery *query, GError **err); - -static void -get_folders_async (TnyFolderStore *self, TnyList *list, TnyGetFoldersCallback callback, TnyFolderStoreQuery *query, TnyStatusCallback status_callback, gpointer user_data); - -static void modest_tny_local_folders_account_class_init (ModestTnyLocalFoldersAccountClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -113,7 +116,7 @@ modest_tny_local_folders_account_class_init (ModestTnyLocalFoldersAccountClass * /* Override virtual functions from the parent class: */ TNY_CAMEL_STORE_ACCOUNT_CLASS(klass)->get_folders_func = get_folders; - TNY_CAMEL_STORE_ACCOUNT_CLASS(klass)->get_folders_async_func = get_folders_async; + TNY_CAMEL_STORE_ACCOUNT_CLASS(klass)->create_folder_func = create_folder; } static void @@ -145,6 +148,55 @@ modest_tny_local_folders_account_add_extra_folder (ModestTnyLocalFoldersAccount g_object_ref (folder); } +static gboolean +modest_tny_local_folders_account_query_passes (TnyFolderStoreQuery *query, TnyFolder *folder) +{ + gboolean retval = FALSE; + + if (query && (tny_list_get_length (tny_folder_store_query_get_items (query)) > 0)) + { + TnyList *items = tny_folder_store_query_get_items (query); + TnyIterator *iterator; + iterator = tny_list_create_iterator (items); + + while (!tny_iterator_is_done (iterator)) + { + TnyFolderStoreQueryItem *item = (TnyFolderStoreQueryItem*) tny_iterator_get_current (iterator); + if (item) { + TnyFolderStoreQueryOption options = tny_folder_store_query_item_get_options (item); + regex_t *regex = tny_folder_store_query_item_get_regex (item); + + if ((options & TNY_FOLDER_STORE_QUERY_OPTION_SUBSCRIBED) && + tny_folder_is_subscribed (folder)) + retval = TRUE; + + if ((options & TNY_FOLDER_STORE_QUERY_OPTION_UNSUBSCRIBED) && + !(tny_folder_is_subscribed (folder))) + retval = TRUE; + + if (regex && options & TNY_FOLDER_STORE_QUERY_OPTION_MATCH_ON_NAME) + if (regexec (regex, tny_folder_get_name (folder), 0, NULL, 0) == 0) + retval = TRUE; + + if (regex && options & TNY_FOLDER_STORE_QUERY_OPTION_MATCH_ON_ID) + if (regexec (regex, tny_folder_get_id (folder), 0, NULL, 0) == 0) + retval = TRUE; + + g_object_unref (G_OBJECT (item)); + } + + tny_iterator_next (iterator); + } + + g_object_unref (G_OBJECT (iterator)); + g_object_unref (G_OBJECT (items)); + } else + retval = TRUE; + + return retval; +} + + static void get_folders (TnyFolderStore *self, TnyList *list, TnyFolderStoreQuery *query, GError **err) { @@ -156,33 +208,24 @@ get_folders (TnyFolderStore *self, TnyList *list, TnyFolderStoreQuery *query, GE MODEST_TNY_LOCAL_FOLDERS_ACCOUNT_GET_CLASS (self)); parent_class->get_folders_func (self, list, query, err); - /* Add our extra folders: */ + /* Add our extra folders only if it passes the query */ GSList *iter = priv->list_extra_folders; - while (iter) - { + while (iter) { TnyFolder *folder = TNY_FOLDER (iter->data); - if (folder) - tny_list_append (list, G_OBJECT (folder)); + + if (folder && modest_tny_local_folders_account_query_passes (query, folder)) + tny_list_prepend (list, G_OBJECT (folder)); iter = g_slist_next (iter); } } -static void -get_folders_async (TnyFolderStore *self, TnyList *list, TnyGetFoldersCallback callback, TnyFolderStoreQuery *query, TnyStatusCallback status_callback, gpointer user_data) -{ - /* Call the base class implementation: */ - TnyCamelStoreAccountClass *parent_class = g_type_class_peek_parent ( - MODEST_TNY_LOCAL_FOLDERS_ACCOUNT_GET_CLASS (self)); - parent_class->get_folders_async_func (self, list, callback, query, status_callback, user_data); -} - static void add_account_folders_to_merged_folder (TnyAccount *account, TnyMergeFolder* merge_folder) { const gchar* account_id = tny_account_get_id (account); const gboolean is_actual_local_folders_account = account_id && - (strcmp (account_id, MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID) == 0); + (strcmp (account_id, MODEST_LOCAL_FOLDERS_ACCOUNT_ID) == 0); TnyList *list_outbox_folders = tny_simple_list_new (); tny_folder_store_get_folders (TNY_FOLDER_STORE (account), @@ -199,7 +242,7 @@ add_account_folders_to_merged_folder (TnyAccount *account, TnyMergeFolder* merge * because these are just left-over from earlier Modest versions * that put the outbox there: */ if (is_actual_local_folders_account) { - const TnyFolderType type = modest_tny_folder_get_local_folder_type (folder); + const TnyFolderType type = modest_tny_folder_get_local_or_mmc_folder_type (folder); if (type == TNY_FOLDER_TYPE_OUTBOX) { add = FALSE; } @@ -224,7 +267,10 @@ void modest_tny_local_folders_account_add_merged_outbox_folders (ModestTnyLocalF /* All per-account outbox folders are merged into one folders * so that they appear as one outbox to the user: */ - TnyMergeFolder *merged_outbox = TNY_MERGE_FOLDER (tny_merge_folder_new()); + TnyMergeFolder *merged_outbox = TNY_MERGE_FOLDER (tny_merge_folder_new(_("mcen_me_folder_outbox"))); + + /* Set type to outbox (NB#61580) */ + tny_merge_folder_set_folder_type (merged_outbox, TNY_FOLDER_TYPE_OUTBOX); GSList *iter = accounts; while (iter) @@ -245,9 +291,59 @@ void modest_tny_local_folders_account_add_merged_outbox_folders (ModestTnyLocalF } /* Add the merged outbox folder to the virtual local-folders store: */ + /* printf ("Debug: %s: adding merged outbox.\n", __FUNCTION__); */ modest_tny_local_folders_account_add_extra_folder (self, TNY_FOLDER(merged_outbox)); g_object_unref (merged_outbox); merged_outbox = NULL; } +gboolean +modest_tny_local_folders_account_extra_folder_exists (ModestTnyLocalFoldersAccount *self, + const gchar *name) +{ + ModestTnyLocalFoldersAccountPrivate *priv; + GSList *iter; + gboolean found; + gchar *down_name; + + /* Check that we're not trying to create/rename any folder + with the same name that our extra folders */ + priv = TNY_LOCAL_FOLDERS_ACCOUNT_GET_PRIVATE (self); + iter = priv->list_extra_folders; + found = FALSE; + down_name = g_utf8_strdown (name, strlen (name)); + while (iter && !found) { + TnyFolder *folder = TNY_FOLDER (iter->data); + const gchar *type_name; + + type_name = modest_local_folder_info_get_type_name (tny_folder_get_folder_type (folder)); + if (!strcmp (type_name, down_name)) + found = TRUE; + else + iter = g_slist_next (iter); + } + g_free (down_name); + + return found; +} + +static TnyFolder* +create_folder (TnyFolderStore *self, + const gchar *name, + GError **err) +{ + TnyCamelStoreAccountClass *parent_class; + + parent_class = g_type_class_peek_parent (MODEST_TNY_LOCAL_FOLDERS_ACCOUNT_GET_CLASS (self)); + + /* If the folder name is been used by our extra folders */ + if (modest_tny_local_folders_account_extra_folder_exists (MODEST_TNY_LOCAL_FOLDERS_ACCOUNT (self), name)) { + g_set_error (err, TNY_FOLDER_STORE_ERROR, + TNY_FOLDER_STORE_ERROR_CREATE_FOLDER, + "Folder name already in use"); + return NULL; + } + /* Call the base class implementation: */ + return parent_class->create_folder_func (self, name, err); +}