X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-tny-local-folders-account.c;h=3410305464cfb19200620dfca1c07f9e3a446fb0;hp=ab3a2124c7599582f0071aa4710a39ba5ea294d1;hb=4d39841513a3a7f7aa9d38ab97cb9fcc9171e80b;hpb=9e5500bca1d9adc7b6e8d97c605a57780ce525b8 diff --git a/src/modest-tny-local-folders-account.c b/src/modest-tny-local-folders-account.c index ab3a212..3410305 100644 --- a/src/modest-tny-local-folders-account.c +++ b/src/modest-tny-local-folders-account.c @@ -39,6 +39,7 @@ #include #include #include +#include G_DEFINE_TYPE (ModestTnyLocalFoldersAccount, modest_tny_local_folders_account, @@ -56,16 +57,31 @@ struct _ModestTnyLocalFoldersAccountPrivate static void get_folders (TnyFolderStore *self, TnyList *list, - TnyFolderStoreQuery *query, + TnyFolderStoreQuery *query, + gboolean refresh, GError **err); static TnyFolder* create_folder (TnyFolderStore *self, const gchar *name, GError **err); +enum { + OUTBOX_DELETED_SIGNAL, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = {0}; + static void modest_tny_local_folders_account_finalize (GObject *object) { + ModestTnyLocalFoldersAccountPrivate *priv; + + priv = TNY_LOCAL_FOLDERS_ACCOUNT_GET_PRIVATE (object); + if (priv->outbox_folder) { + g_object_unref (priv->outbox_folder); + priv->outbox_folder = NULL; + } G_OBJECT_CLASS (modest_tny_local_folders_account_parent_class)->finalize (object); } @@ -73,14 +89,27 @@ static void modest_tny_local_folders_account_class_init (ModestTnyLocalFoldersAccountClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - + g_type_class_add_private (klass, sizeof (ModestTnyLocalFoldersAccountPrivate)); - + object_class->finalize = modest_tny_local_folders_account_finalize; - + + /* Signals */ + + /* Note that this signal is removed before unsetting my own + reference to outbox, this means that by the time of this + call, modest_tny_local_folders_account_get_merged_outbox is + still valid. The reason is that the listeners of the signal + might want to do something with the outbox instance */ + signals[OUTBOX_DELETED_SIGNAL] = g_signal_new + ("outbox-deleted", MODEST_TYPE_TNY_LOCAL_FOLDERS_ACCOUNT, + G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET + (ModestTnyLocalFoldersAccountClass, outbox_deleted), NULL, + NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + /* Override virtual functions from the parent class: */ - TNY_CAMEL_STORE_ACCOUNT_CLASS(klass)->get_folders_func = get_folders; - TNY_CAMEL_STORE_ACCOUNT_CLASS(klass)->create_folder_func = create_folder; + TNY_CAMEL_STORE_ACCOUNT_CLASS(klass)->get_folders = get_folders; + TNY_CAMEL_STORE_ACCOUNT_CLASS(klass)->create_folder = create_folder; } static void @@ -113,7 +142,7 @@ modest_tny_local_folders_account_query_passes (TnyFolderStoreQuery *query, TnyFo TnyFolderStoreQueryItem *item = (TnyFolderStoreQueryItem*) tny_iterator_get_current (iterator); if (item) { TnyFolderStoreQueryOption options = tny_folder_store_query_item_get_options (item); - regex_t *regex = (regex_t *) tny_folder_store_query_item_get_regex (item); + const regex_t *regex = tny_folder_store_query_item_get_regex (item); if ((options & TNY_FOLDER_STORE_QUERY_OPTION_SUBSCRIBED) && tny_folder_is_subscribed (folder)) @@ -146,14 +175,18 @@ modest_tny_local_folders_account_query_passes (TnyFolderStoreQuery *query, TnyFo } static void -get_folders (TnyFolderStore *self, TnyList *list, TnyFolderStoreQuery *query, GError **err) +get_folders (TnyFolderStore *self, + TnyList *list, + TnyFolderStoreQuery *query, + gboolean refresh, + GError **err) { TnyCamelStoreAccountClass *parent_class; ModestTnyLocalFoldersAccountPrivate *priv; /* Call the base class implementation: */ parent_class = g_type_class_peek_parent (MODEST_TNY_LOCAL_FOLDERS_ACCOUNT_GET_CLASS (self)); - parent_class->get_folders_func (self, list, query, err); + parent_class->get_folders (self, list, query, refresh, err); /* Add our extra folder only if it passes the query */ priv = TNY_LOCAL_FOLDERS_ACCOUNT_GET_PRIVATE (self); @@ -174,14 +207,14 @@ create_folder (TnyFolderStore *self, /* If the folder name is been used by our extra folders */ if (modest_tny_local_folders_account_folder_name_in_use (MODEST_TNY_LOCAL_FOLDERS_ACCOUNT (self), name)) { - g_set_error (err, TNY_FOLDER_STORE_ERROR, - TNY_FOLDER_STORE_ERROR_CREATE_FOLDER, + g_set_error (err, TNY_ERROR_DOMAIN, + TNY_SERVICE_ERROR_FOLDER_CREATE, "Folder name already in use"); return NULL; } /* Call the base class implementation: */ - return parent_class->create_folder_func (self, name, err); + return parent_class->create_folder (self, name, err); } /*****************************/ @@ -231,18 +264,16 @@ modest_tny_local_folders_account_add_folder_to_outbox (ModestTnyLocalFoldersAcco g_return_if_fail (MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (self)); g_return_if_fail (TNY_IS_FOLDER (per_account_outbox)); - /* We can not test it yet, because there is no API to set the - type of a folder */ -/* g_return_if_fail (tny_folder_get_folder_type (per_account_outbox) == TNY_FOLDER_TYPE_OUTBOX); */ - priv = TNY_LOCAL_FOLDERS_ACCOUNT_GET_PRIVATE (self); /* Create on-demand */ if (!priv->outbox_folder) { - priv->outbox_folder = TNY_MERGE_FOLDER (tny_merge_folder_new (_("mcen_me_folder_outbox"))); - + priv->outbox_folder = (TnyMergeFolder *) + tny_merge_folder_new_with_ui_locker (_("mcen_me_folder_outbox"), + tny_gtk_lockable_new ()); /* Set type to outbox */ - tny_merge_folder_set_folder_type (priv->outbox_folder, TNY_FOLDER_TYPE_OUTBOX); + tny_merge_folder_set_folder_type (priv->outbox_folder, + TNY_FOLDER_TYPE_OUTBOX); } /* Add outbox to the global OUTBOX folder */ @@ -268,8 +299,25 @@ modest_tny_local_folders_account_remove_folder_from_outbox (ModestTnyLocalFolder merged_folders = tny_simple_list_new (); tny_merge_folder_get_folders (priv->outbox_folder, merged_folders); if (tny_list_get_length (merged_folders) == 0) { + /* Emit signal */ + g_signal_emit ((GObject *)self, signals[OUTBOX_DELETED_SIGNAL], 0); + + /* Unref my own reference */ g_object_unref (priv->outbox_folder); priv->outbox_folder = NULL; } g_object_unref (merged_folders); } + +TnyFolder * +modest_tny_local_folders_account_get_merged_outbox (ModestTnyLocalFoldersAccount *self) +{ + ModestTnyLocalFoldersAccountPrivate *priv; + g_return_val_if_fail (MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (self), NULL); + + priv = TNY_LOCAL_FOLDERS_ACCOUNT_GET_PRIVATE (self); + if (priv->outbox_folder) + return g_object_ref (priv->outbox_folder); + else + return NULL; +}