Changeset 1737

Show
Ignore:
Timestamp:
03/16/07 15:11:45
Author:
pvanhoof
Message:

APIs added

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r1736 r1737  
    44        GPL 
    55 
    6 2007-03.16  Sergio Villar Senin  <svillar@igalia.com> 
     62007-03-16  Philip Van Hoof  <pvanhoof@gnome.org> 
     7 
     8        * Design by contract assertions 
     9        * tny_account_store_find_account API added 
     10        * tny_folder_find_msg API added 
     11 
     12        * This was a major API change 
     13 
     142007-03-16  Sergio Villar Senin  <svillar@igalia.com> 
    715 
    816        * libtinymailui/tny-msg-view.c: fixed a typo in a function name 
  • trunk/libtinymail-camel/tny-camel-folder.c

    r1730 r1737  
    13561356} 
    13571357 
     1358 
     1359 
     1360 
     1361static TnyMsg* 
     1362tny_camel_folder_find_msg (TnyFolder *self, const gchar *url_string, GError **err) 
     1363{ 
     1364        return TNY_CAMEL_FOLDER_GET_CLASS (self)->find_msg_func (self, url_string, err); 
     1365} 
     1366 
     1367static TnyMsg* 
     1368tny_camel_folder_find_msg_default (TnyFolder *self, const gchar *url_string, GError **err) 
     1369{ 
     1370        TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (self); 
     1371        TnyMsg *retval = NULL; 
     1372        TnyHeader *hdr; 
     1373        CamelMessageInfo *info; 
     1374        const gchar *uid; 
     1375 
     1376        if (!_tny_session_check_operation (TNY_FOLDER_PRIV_GET_SESSION(priv), err,  
     1377                        TNY_FOLDER_ERROR, TNY_FOLDER_ERROR_GET_MSG)) 
     1378                return; 
     1379 
     1380        if (!priv->receive_strat) { 
     1381                _tny_session_stop_operation (TNY_FOLDER_PRIV_GET_SESSION (priv)); 
     1382                return NULL; 
     1383        } 
     1384 
     1385        g_static_rec_mutex_lock (priv->folder_lock); 
     1386 
     1387        if (!priv->folder || !priv->loaded || !CAMEL_IS_FOLDER (priv->folder)) 
     1388                if (!load_folder_no_lock (priv)) 
     1389                { 
     1390                        g_static_rec_mutex_unlock (priv->folder_lock); 
     1391                        _tny_session_stop_operation (TNY_FOLDER_PRIV_GET_SESSION (priv)); 
     1392                        return NULL; 
     1393                } 
     1394 
     1395        uid = strrchr (url_string, '/'); 
     1396        if (uid && uid[0] != '/' && strlen (uid) > 1) 
     1397        { 
     1398                uid++; 
     1399                info = camel_message_info_new_uid (NULL, uid); 
     1400                hdr = _tny_camel_header_new (); 
     1401                _tny_camel_header_set_as_memory (TNY_CAMEL_HEADER (hdr), info); 
     1402                retval = tny_msg_receive_strategy_perform_get_msg (priv->receive_strat, self, hdr, err); 
     1403                g_object_unref (G_OBJECT (hdr)); 
     1404        } else { 
     1405                g_set_error (err, TNY_FOLDER_ERROR,  
     1406                                TNY_FOLDER_ERROR_GET_MSG, 
     1407                                "This url string is malformated"); 
     1408                retval = NULL; 
     1409        } 
     1410 
     1411        g_static_rec_mutex_unlock (priv->folder_lock); 
     1412 
     1413        _tny_session_stop_operation (TNY_FOLDER_PRIV_GET_SESSION (priv)); 
     1414 
     1415        return retval; 
     1416} 
    13581417 
    13591418static const gchar* 
     
    30863145        klass->get_headers_func = tny_camel_folder_get_headers; 
    30873146        klass->get_msg_func = tny_camel_folder_get_msg; 
     3147        klass->find_msg_func = tny_camel_folder_find_msg; 
    30883148        klass->get_msg_async_func = tny_camel_folder_get_msg_async; 
    30893149        klass->get_id_func = tny_camel_folder_get_id; 
     
    31263186        klass->remove_observer_func = tny_camel_folder_store_remove_observer; 
    31273187 
    3128  
    31293188        return; 
    31303189} 
     
    31453204        class->get_headers_func = tny_camel_folder_get_headers_default; 
    31463205        class->get_msg_func = tny_camel_folder_get_msg_default; 
     3206        class->find_msg_func = tny_camel_folder_find_msg_default; 
    31473207        class->get_msg_async_func = tny_camel_folder_get_msg_async_default; 
    31483208        class->get_id_func = tny_camel_folder_get_id_default; 
  • trunk/libtinymail-camel/tny-camel-folder.h

    r1719 r1737  
    6262        void (*set_msg_receive_strategy_func) (TnyFolder *self, TnyMsgReceiveStrategy *st); 
    6363        TnyMsg* (*get_msg_func) (TnyFolder *self, TnyHeader *header, GError **err); 
     64        TnyMsg* (*find_msg_func) (TnyFolder *self, const gchar *url_string, GError **err); 
    6465        void (*get_msg_async_func) (TnyFolder *self, TnyHeader *header, TnyGetMsgCallback callback, gpointer user_data); 
    6566        void (*get_headers_func) (TnyFolder *self, TnyList *headers, gboolean refresh, GError **err); 
  • trunk/libtinymail-camel/tny-camel-store-account.c

    r1723 r1737  
    889889} 
    890890 
     891static TnyFolder* 
     892tny_camel_store_account_find_folder (TnyStoreAccount *self, const gchar *url_string, GError **err) 
     893{ 
     894        return TNY_CAMEL_STORE_ACCOUNT_GET_CLASS (self)->find_folder_func (self, url_string, err); 
     895} 
     896 
     897static TnyFolder* 
     898tny_camel_store_account_find_folder_default (TnyStoreAccount *self, const gchar *url_string, GError **err) 
     899{ 
     900        TnyFolder *retval = NULL; 
     901        TnyCamelAccountPriv *apriv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self); 
     902        TnyCamelStoreAccountPriv *priv = TNY_CAMEL_STORE_ACCOUNT_GET_PRIVATE (self);     
     903        CamelException ex = CAMEL_EXCEPTION_INITIALISER;     
     904        CamelFolderInfo *iter; guint32 flags; CamelStore *store; 
     905 
     906        g_assert (CAMEL_IS_SESSION (apriv->session)); 
     907 
     908        if (!_tny_session_check_operation (apriv->session, err,  
     909                        TNY_FOLDER_STORE_ERROR, TNY_FOLDER_STORE_ERROR_GET_FOLDERS)) 
     910                return; 
     911 
     912        if (apriv->service == NULL || !CAMEL_IS_SERVICE (apriv->service)) 
     913        { 
     914                g_set_error (err, TNY_FOLDER_STORE_ERROR,  
     915                                TNY_FOLDER_STORE_ERROR_GET_FOLDERS, 
     916                                "Account not ready for this operation (%s)", 
     917                                camel_exception_get_description (apriv->ex)); 
     918                _tny_session_stop_operation (apriv->session); 
     919                return; 
     920        } 
     921 
     922        store = CAMEL_STORE (apriv->service); 
     923 
     924        if (camel_exception_is_set (&ex)) 
     925        { 
     926                g_set_error (err, TNY_FOLDER_STORE_ERROR,  
     927                        TNY_FOLDER_STORE_ERROR_GET_FOLDERS, 
     928                        camel_exception_get_description (&ex)); 
     929                camel_exception_clear (&ex); 
     930 
     931                if (store && CAMEL_IS_OBJECT (store)) 
     932                        camel_object_unref (CAMEL_OBJECT (store)); 
     933                _tny_session_stop_operation (apriv->session); 
     934                return; 
     935        } 
     936 
     937        g_assert (CAMEL_IS_STORE (store)); 
     938 
     939        flags = CAMEL_STORE_FOLDER_INFO_FAST | CAMEL_STORE_FOLDER_INFO_NO_VIRTUAL; 
     940 
     941        if (!camel_session_is_online ((CamelSession*) apriv->session)) 
     942                flags |= CAMEL_STORE_FOLDER_INFO_SUBSCRIBED; 
     943 
     944        iter = camel_store_get_folder_info (store, url_string, flags, &ex); 
     945 
     946        if (camel_exception_is_set (&ex)) 
     947        { 
     948                g_set_error (err, TNY_FOLDER_STORE_ERROR,  
     949                        TNY_FOLDER_STORE_ERROR_GET_FOLDERS, 
     950                        camel_exception_get_description (&ex)); 
     951                camel_exception_clear (&ex); 
     952 
     953                if (CAMEL_IS_OBJECT (store)) 
     954                { 
     955                        if (iter && CAMEL_IS_STORE (store)) 
     956                                camel_store_free_folder_info (store, iter); 
     957                        camel_object_unref (CAMEL_OBJECT (store)); 
     958                } 
     959                _tny_session_stop_operation (apriv->session); 
     960                return; 
     961        } 
     962 
     963        if (iter) 
     964        { 
     965                gboolean was_new = FALSE; 
     966 
     967                TnyCamelFolder *folder = (TnyCamelFolder *) tny_camel_store_account_factor_folder ( 
     968                        TNY_CAMEL_STORE_ACCOUNT (self),  
     969                        iter->full_name, &was_new); 
     970 
     971                if (was_new && folder != NULL) 
     972                        _tny_camel_folder_set_folder_info (TNY_FOLDER_STORE (self), folder, iter); 
     973 
     974                retval = (TnyFolder *) folder; 
     975        } 
     976 
     977        _tny_session_stop_operation (apriv->session); 
     978 
     979        return retval; 
     980} 
    891981 
    892982static void 
     
    9121002        klass->subscribe_func = tny_camel_store_account_subscribe; 
    9131003        klass->unsubscribe_func = tny_camel_store_account_unsubscribe; 
     1004        klass->find_folder_func = tny_camel_store_account_find_folder; 
    9141005 
    9151006        return; 
     
    9361027        class->add_observer_func = tny_camel_store_account_add_observer_default; 
    9371028        class->remove_observer_func = tny_camel_store_account_remove_observer_default; 
     1029        class->find_folder_func = tny_camel_store_account_find_folder_default; 
    9381030 
    9391031        /* Protected default implementation */ 
  • trunk/libtinymail-camel/tny-camel-store-account.h

    r1694 r1737  
    5757        void (*remove_observer_func) (TnyFolderStore *self, TnyFolderStoreObserver *observer); 
    5858 
     59        TnyFolder * (*find_folder_func) (TnyStoreAccount *self, const gchar *url_string, GError **err); 
     60 
    5961        /* protected virtual methods*/ 
    6062        TnyFolder * (*factor_folder_func) (TnyCamelStoreAccount *self, const gchar *full_name, gboolean *was_new); 
  • trunk/libtinymail/tny-account-store.c

    r1726 r1737  
    3939/** 
    4040 * tny_account_store_find_account: 
    41  * @self: a #TnyAccountTransport object 
     41 * @self: a #TnyAccountStore object 
    4242 * @url_string: the url-string of the account to find 
    4343 * 
     
    4848 * Implementors: when implementing a platform-specific library, you must 
    4949 * implement this method. Let it return the account that corresponds to 
    50  * @url_string or NULL. Also see tny_account_matches_url_string at #TnyAccount. 
     50 * @url_string or let it return NULL. Also see  
     51 * tny_account_matches_url_string at #TnyAccount. 
    5152 * 
    5253 * This method can be used to resolve url-strings to #TnyAccount instances. 
     
    8182/** 
    8283 * tny_account_store_alert: 
    83  * @self: a #TnyAccountTransport object 
     84 * @self: a #TnyAccountStore object 
    8485 * @type: the message type (severity) 
    8586 * @prompt: the prompt 
     
    150151/** 
    151152 * tny_account_store_get_device: 
    152  * @self: a #TnyAccountTransport object 
     153 * @self: a #TnyAccountStore object 
    153154 * 
    154155 * This method returns a #TnyDevice instance. You must unreference the return 
     
    184185/** 
    185186 * tny_account_store_get_cache_dir: 
    186  * @self: a #TnyAccountTransport object 
     187 * @self: a #TnyAccountStore object 
    187188 *  
    188189 * Get the local path that will be used for storing the disk cache 
     
    222223/** 
    223224 * tny_account_store_get_accounts: 
    224  * @self: a #TnyAccountTransport object 
     225 * @self: a #TnyAccountStore object 
    225226 * @list: a #TnyList instance that will be filled with #TnyAccount instances 
    226227 * @types: a #TnyGetAccountsRequestType that describes which account types are needed 
     
    339340/** 
    340341 * tny_account_store_add_transport_account: 
    341  * @self: a #TnyAccountTransport object 
     342 * @self: a #TnyAccountStore object 
    342343 * @account: the account to add 
    343344 *  
  • trunk/libtinymail/tny-folder.c

    r1735 r1737  
    795795 * @err: a #GError object or NULL 
    796796 *  
    797  * Get a message in @self identified by @header. You must unreference the 
    798  * return value after use. 
     797 * Get a message in @self identified by @header. If not NULL, you must  
     798 * unreference the return value after use. 
    799799 *  
    800800 * Example: 
     
    834834 
    835835 
     836 
     837/** 
     838 * tny_folder_find_msg: 
     839 * @self: a #TnyFolder object 
     840 * @url_string: the url string 
     841 * @err: a #GError object or NULL 
     842 *  
     843 * Get a message in @self identified by @url_string. If not NULL, you must  
     844 * unreference the return value after use. 
     845 *  
     846 * Example: 
     847 * <informalexample><programlisting> 
     848 * TnyMsgView *message_view = tny_platform_factory_new_msg_view (platfact); 
     849 * TnyFolder *folder = ... 
     850 * TnyMsg *message = tny_folder_get_msg (folder, "imap://account/INBOX/100", NULL); 
     851 * tny_msg_view_set_msg (message_view, message); 
     852 * g_object_unref (G_OBJECT (message)); 
     853 * </programlisting></informalexample> 
     854 * 
     855 * Return value: The message instance or NULL on failure 
     856 * 
     857 **/ 
     858TnyMsg* 
     859tny_folder_find_msg (TnyFolder *self, const gchar *url_string, GError **err) 
     860{ 
     861        TnyMsg *retval; 
     862 
     863#ifdef DBC /* require */ 
     864        g_assert (TNY_IS_FOLDER (self)); 
     865        g_assert (url_string); 
     866        g_assert (strlen (url_string) > 0); 
     867        g_assert (strstr (url_string, "://") != NULL); 
     868        g_assert (TNY_FOLDER_GET_IFACE (self)->find_msg_func != NULL); 
     869#endif 
     870 
     871        retval = TNY_FOLDER_GET_IFACE (self)->find_msg_func (self, url_string, err); 
     872 
     873#ifdef DBC /* ensure */ 
     874        if (retval) 
     875                g_assert (TNY_IS_MSG (retval)); 
     876#endif 
     877 
     878        return retval; 
     879} 
    836880 
    837881 
  • trunk/libtinymail/tny-folder.h

    r1719 r1737  
    9393        void (*set_msg_receive_strategy_func) (TnyFolder *self, TnyMsgReceiveStrategy *st); 
    9494        TnyMsg* (*get_msg_func) (TnyFolder *self, TnyHeader *header, GError **err); 
     95        TnyMsg* (*find_msg_func) (TnyFolder *self, const gchar *url_string, GError **err); 
    9596        void (*get_msg_async_func) (TnyFolder *self, TnyHeader *header, TnyGetMsgCallback callback, gpointer user_data); 
    9697        void (*get_headers_func) (TnyFolder *self, TnyList *headers, gboolean refresh, GError **err); 
     
    128129void tny_folder_sync (TnyFolder *self, gboolean expunge, GError **err); 
    129130TnyMsg* tny_folder_get_msg (TnyFolder *self, TnyHeader *header, GError **err); 
     131TnyMsg* tny_folder_find_msg (TnyFolder *self, const gchar *url_string, GError **err); 
    130132void tny_folder_get_msg_async (TnyFolder *self, TnyHeader *header, TnyGetMsgCallback callback, gpointer user_data); 
    131133void tny_folder_get_headers (TnyFolder *self, TnyList *headers, gboolean refresh, GError **err); 
  • trunk/libtinymail/tny-list.c

    r1732 r1737  
    134134#endif 
    135135 
    136         TNY_LIST_GET_IFACE (self)->append_func (self, item); 
     136        TNY_LIST_GET_IFACE (self)->append_func (self, item);  
    137137 
    138138#ifdef DBC /* ensure */ 
  • trunk/libtinymail/tny-store-account.c

    r1732 r1737  
    2020#include <config.h> 
    2121 
     22#ifdef DBC 
     23#include <string.h> 
     24#endif 
     25 
    2226#include <tny-store-account.h> 
    2327#include <tny-folder-store.h> 
     
    2529 
    2630guint tny_store_account_signals [TNY_STORE_ACCOUNT_LAST_SIGNAL]; 
     31 
     32/** 
     33 * tny_store_account_find_folder: 
     34 * @self: a #TnyStoreAccount object 
     35 * @url_string: the url-string of the folder to find 
     36 * 
     37 * Try to find the folder in @self that corresponds to @url_string. If this  
     38 * method does not return NULL, the returned value is the found folder and 
     39 * must be unreferenced after use. 
     40 * 
     41 * Implementors: when implementing a #TnyStoreAccount, you must implement 
     42 * this method. Let it return the folder that corresponds to @url_string or  
     43 * let it return NULL. 
     44 * 
     45 * This method can be used to resolve url-strings to #TnyAccount instances. 
     46 * 
     47 * Return value: the found account or NULL. 
     48 **/ 
     49TnyFolder*  
     50tny_store_account_find_folder (TnyStoreAccount *self, const gchar *url_string, GError **err) 
     51{ 
     52        TnyFolder *retval; 
     53 
     54#ifdef DBC /* require */ 
     55        g_assert (TNY_IS_STORE_ACCOUNT (self)); 
     56        g_assert (url_string); 
     57        g_assert (strlen (url_string) > 0); 
     58        g_assert (strstr (url_string, "://")); 
     59        g_assert (TNY_STORE_ACCOUNT_GET_IFACE (self)->find_folder_func != NULL); 
     60#endif 
     61 
     62        retval = TNY_STORE_ACCOUNT_GET_IFACE (self)->find_folder_func (self, url_string, err); 
     63 
     64#ifdef DBC /* ensure */ 
     65        if (retval) 
     66                g_assert (TNY_IS_FOLDER (retval)); 
     67#endif 
     68 
     69        return retval; 
     70} 
    2771 
    2872/** 
  • trunk/libtinymail/tny-store-account.h

    r1202 r1737  
    5959        void (*subscribe_func) (TnyStoreAccount *self, TnyFolder *folder); 
    6060        void (*unsubscribe_func) (TnyStoreAccount *self, TnyFolder *folder); 
     61        TnyFolder * (*find_folder_func) (TnyStoreAccount *self, const gchar *url_string, GError **err); 
    6162}; 
    6263 
     
    6566void tny_store_account_subscribe (TnyStoreAccount *self, TnyFolder *folder); 
    6667void tny_store_account_unsubscribe (TnyStoreAccount *self, TnyFolder *folder); 
     68TnyFolder* tny_store_account_find_folder (TnyStoreAccount *self, const gchar *url_string, GError **err); 
    6769 
    6870