Changeset 2513

Show
Ignore:
Timestamp:
07/27/07 15:32:09
Author:
pvanhoof
Message:

Knowing why connecting failed

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/pvanhoof/sessionwork/ChangeLog

    r2510 r2513  
    44        * The poke status calls are now on the same queue as the other 
    55        operations 
     6        * Rewritten the TnySessionCamel infrastructure that connects accounts 
     7        and sets them up 
     8        * Added support for detecting folder changes to 
     9        TnyGtkFolderStoreTreeModel 
     10        * API change on tny_camel_account_set_online. The last argument is now 
     11        a callback rather than a GError. In the callback you can know about 
     12        when the account got connected and if not, why it failed 
     13 
     14        * This was a major API change in TnyAccount 
    615 
    7162007-07-27  Philip Van Hoof  <pvanhoof@gnome.org> 
  • devel/pvanhoof/sessionwork/libtinymail-camel/tny-camel-account.c

    r2509 r2513  
    11601160} 
    11611161 
    1162 /** 
    1163  * tny_camel_account_set_online: 
    1164  * @self: a #TnyCamelAccount object 
    1165  * @online: whether or not the account is online 
    1166  * @err: a #GError instance or NULL 
    1167  * 
    1168  * Set the connectivity status of an account. 
    1169  * Setting this to FALSE means that the account will not attempt to use the network,  
    1170  * and will use only the cache. 
    1171  * Setting this to TRUE means that the account may use the network to provide up-to-date  
    1172  * information. 
    1173  * 
    1174  **/ 
    1175 void  
    1176 tny_camel_account_set_online (TnyCamelAccount *self, gboolean online, GError **err) 
    1177 
    1178         TNY_CAMEL_ACCOUNT_GET_CLASS (self)->set_online_func (self, online, err); 
    1179 
     1162/* The is the protected version that will actually set it online. This should 
     1163 * always happen in a thread. In fact, it will always happen in the operations 
     1164 * queue of @self (else it's a bug). */ 
    11801165 
    11811166void  
     
    13221307 
    13231308 
    1324 typedef struct { 
    1325         TnyCamelAccount *self; 
    1326         gboolean online; 
    1327         GError **err; 
    1328         GMainLoop *loop; 
    1329 } SetOnlineInfo; 
    1330  
    1331 static gpointer 
    1332 set_online_thread (gpointer data) 
    1333 
    1334         SetOnlineInfo *info = (SetOnlineInfo *) data; 
    1335  
    1336         _tny_camel_account_set_online (info->self, info->online, info->err); 
    1337  
    1338         if (g_main_loop_is_running (info->loop)) 
    1339                 g_main_loop_quit (info->loop); 
    1340  
    1341         g_thread_exit (NULL); 
    1342         return NULL; 
    1343 
    1344  
     1309 
     1310 
     1311 
     1312/** 
     1313 * tny_camel_account_set_online: 
     1314 * @self: a #TnyCamelAccount object 
     1315 * @online: whether or not the account is online 
     1316 * @callback: a callback when the account went online 
     1317 * 
     1318 * Set the connectivity status of an account. Setting this to FALSE means that  
     1319 * the account will not attempt to use the network, and will use only the cache. 
     1320 * Setting this to TRUE means that the account may use the network to  
     1321 * provide up-to-date information. 
     1322 * 
     1323 * The @callback will be invoke as soon as the account is actually online. It's 
     1324 * guaranteed that the @callback will happen in the mainloop, if available. 
     1325 * 
     1326 **/ 
    13451327void  
    1346 tny_camel_account_set_online_default (TnyCamelAccount *self, gboolean online, GError **err) 
    1347 
    1348         if (g_main_depth () != 0) 
    1349         { 
    1350                 /* We are being called from the mainnloop */ 
    1351                 SetOnlineInfo *info = g_slice_new (SetOnlineInfo); 
    1352                 GThread *thread = NULL; 
    1353  
    1354                 info->self = TNY_CAMEL_ACCOUNT (g_object_ref (self)); 
    1355                 info->online = online; 
    1356                 info->err = err; 
    1357                 info->loop = g_main_loop_new (NULL, FALSE); 
    1358  
    1359                 thread = g_thread_create (set_online_thread, info, TRUE, NULL); 
    1360  
    1361                 g_main_loop_run (info->loop); 
    1362  
    1363                 g_main_loop_unref (info->loop); 
    1364                 g_object_unref (info->self); 
    1365                 g_slice_free (SetOnlineInfo, info); 
    1366  
    1367         } else 
    1368                 _tny_camel_account_set_online (self, online, err); 
     1328tny_camel_account_set_online (TnyCamelAccount *self, gboolean online, TnyCamelSetOnlineCallback callback) 
     1329
     1330        TNY_CAMEL_ACCOUNT_GET_CLASS (self)->set_online_func (self, online, callback); 
     1331
     1332 
     1333typedef struct 
     1334
     1335        TnyCamelAccount *account; 
     1336        GError *err; 
     1337        TnyCamelSetOnlineCallback callback; 
     1338} OnSetOnlineInfo; 
     1339 
     1340gboolean  
     1341on_set_online_done_idle_func (gpointer data) 
     1342
     1343        OnSetOnlineInfo *info = (OnSetOnlineInfo *) data; 
     1344 
     1345        if (info->callback) 
     1346                info->callback (info->account, info->err); 
     1347 
     1348        return FALSE; 
     1349
     1350 
     1351static void  
     1352on_set_online_done_destroy_func (gpointer data) 
     1353
     1354        OnSetOnlineInfo *info = (OnSetOnlineInfo *) data; 
     1355 
     1356        /* We copied it, so we must also free it */ 
     1357        if (info->err) 
     1358                g_error_free (info->err); 
     1359 
     1360        /* Thread reference */ 
     1361        g_object_unref (info->account); 
     1362        g_slice_free (OnSetOnlineInfo, data); 
     1363 
     1364        return; 
     1365
     1366 
     1367static void  
     1368on_set_online_done (TnySessionCamel *self, TnyCamelAccount *account, GError *err, gpointer user_data) 
     1369
     1370        OnSetOnlineInfo *info = g_slice_new (OnSetOnlineInfo); 
     1371 
     1372        /* Thread reference */ 
     1373        info->account = TNY_CAMEL_ACCOUNT (g_object_ref (account)); 
     1374 
     1375        /* We must copy the err because this context will destroy it! */ 
     1376        if (err) 
     1377                info->err = g_error_copy (err);  
     1378        else 
     1379                info->err = NULL; 
     1380 
     1381        info->callback = (TnyCamelSetOnlineCallback) user_data; 
     1382 
     1383        g_idle_add_full (G_PRIORITY_HIGH, on_set_online_done_idle_func,  
     1384                info, on_set_online_done_destroy_func); 
     1385 
     1386        return; 
     1387
     1388 
     1389void  
     1390tny_camel_account_set_online_default (TnyCamelAccount *self, gboolean online, TnyCamelSetOnlineCallback callback) 
     1391
     1392 
     1393        /* In case we  are a store account, this means that we need to throw the  
     1394         * request to go online to the account's queue. */ 
     1395 
     1396        if (TNY_IS_CAMEL_STORE_ACCOUNT (self)) 
     1397        { 
     1398                TnyCamelAccountPriv *priv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self); 
     1399                TnySessionCamel *session = priv->session; 
     1400 
     1401                _tny_camel_store_account_queue_going_online ( 
     1402                        TNY_CAMEL_STORE_ACCOUNT (self), session, online,  
     1403                        on_set_online_done, (gpointer ) callback); 
     1404        } 
     1405 
     1406 
     1407        /* Else, if it's a transport account, we don't have any transport  
     1408         * account implementations that actually need to go online at this  
     1409         * moment yet. At the moment of transferring the first message, the 
     1410         * current implementations will automatically connect themselves. */ 
     1411 
     1412        if (TNY_IS_CAMEL_TRANSPORT_ACCOUNT (self)) 
     1413        { 
     1414                g_signal_emit (self,  
     1415                        tny_camel_account_signals [TNY_CAMEL_ACCOUNT_SET_ONLINE_HAPPENED], 0, online); 
     1416                return; 
     1417        } 
    13691418} 
    13701419 
  • devel/pvanhoof/sessionwork/libtinymail-camel/tny-camel-account.h

    r2352 r2513  
    4848extern guint tny_camel_account_signals [TNY_CAMEL_ACCOUNT_LAST_SIGNAL]; 
    4949 
     50typedef void (*TnyCamelSetOnlineCallback) (TnyCamelAccount *account, GError *err); 
     51 
    5052 
    5153struct _TnyCamelAccount 
     
    8991 
    9092        void (*add_option_func) (TnyCamelAccount *self, const gchar *option); 
    91         void (*set_online_func) (TnyCamelAccount *self, gboolean online, GError **err); 
     93        void (*set_online_func) (TnyCamelAccount *self, gboolean online, TnyCamelSetOnlineCallback callback); 
    9294 
    9395        /* Abstract methods */ 
     
    103105void tny_camel_account_add_option (TnyCamelAccount *self, const gchar *option); 
    104106void tny_camel_account_set_session (TnyCamelAccount *self, TnySessionCamel *session); 
    105 void tny_camel_account_set_online (TnyCamelAccount *self, gboolean online, GError **err); 
     107void tny_camel_account_set_online (TnyCamelAccount *self, gboolean online, TnyCamelSetOnlineCallback callback); 
    106108 
    107109 
  • devel/pvanhoof/sessionwork/libtinymail-camel/tny-camel-store-account-priv.h

    r2509 r2513  
    4444 
    4545void _tny_camel_store_account_emit_conchg_signal (TnyCamelStoreAccount *self); 
    46 void _tny_camel_store_account_queue_going_online (TnyCamelStoreAccount *self, TnySessionCamel *session, gboolean online, go_online_error_func err_func); 
     46void _tny_camel_store_account_queue_going_online (TnyCamelStoreAccount *self, TnySessionCamel *session, gboolean online, go_online_callback_func err_func, gpointer user_data); 
    4747 
    4848#endif 
  • devel/pvanhoof/sessionwork/libtinymail-camel/tny-camel-store-account.c

    r2509 r2513  
    411411                        } 
    412412                } else { 
    413  
    414413                        tny_camel_store_account_do_emit (TNY_CAMEL_STORE_ACCOUNT (self)); 
    415  
    416                         /* tny_camel_account_set_online (self, apriv->connected); */ 
    417414                } 
    418415 
     
    15311528        TnyCamelStoreAccount *self; 
    15321529        gboolean online; 
    1533         go_online_error_func err_func; 
     1530        go_online_callback_func done_func; 
     1531        gpointer user_data; 
    15341532} GoingOnlineInfo; 
    15351533 
     
    15461544         * must wait. */ 
    15471545 
    1548         /* The info->err_func points to on_account_connect_failed in the  
    1549          * TnySessionCamel implementation. Go take a look! */ 
     1546        /* The info->done_func points to on_account_connect_done in the  
     1547         * TnySessionCamel implementation. Or to the set_online_done handler. 
     1548         * Go take a look! */ 
    15501549 
    15511550        apriv->is_connecting = TRUE; 
     
    15591558 
    15601559        if (err) { 
    1561                 info->err_func (info->session, TNY_CAMEL_ACCOUNT (info->self), err); 
     1560                info->done_func (info->session, TNY_CAMEL_ACCOUNT (info->self), err, info->user_data); 
    15621561                g_error_free (err); 
    15631562        } else { 
     
    15701569 
    15711570                if (err) { 
    1572                         info->err_func (info->session,  
    1573                                 TNY_CAMEL_ACCOUNT (info->self), err); 
     1571                        info->done_func (info->session,  
     1572                                TNY_CAMEL_ACCOUNT (info->self), err, info->user_data); 
    15741573                        g_error_free (err); 
    1575                 } 
     1574                } else 
     1575                        info->done_func (info->session,  
     1576                                TNY_CAMEL_ACCOUNT (info->self), NULL, info->user_data); 
     1577 
    15761578        } 
    15771579 
     
    15931595 
    15941596void 
    1595 _tny_camel_store_account_queue_going_online (TnyCamelStoreAccount *self, TnySessionCamel *session, gboolean online, go_online_error_func err_func
     1597_tny_camel_store_account_queue_going_online (TnyCamelStoreAccount *self, TnySessionCamel *session, gboolean online, go_online_callback_func done_func, gpointer user_data
    15961598{ 
    15971599        GoingOnlineInfo *info = NULL; 
     
    16051607        info->session = session; 
    16061608        info->self = self; 
    1607         info->err_func = err_func; 
     1609        info->done_func = done_func; 
    16081610        info->online = online; 
     1611        info->user_data = user_data; 
    16091612 
    16101613        /* thread reference */ 
  • devel/pvanhoof/sessionwork/libtinymail-camel/tny-session-camel-priv.h

    r2509 r2513  
    2424}; 
    2525 
    26 typedef void (*go_online_error_func) (TnySessionCamel *self, TnyCamelAccount *account, GError *err); 
     26typedef void (*go_online_callback_func) (TnySessionCamel *self, TnyCamelAccount *account, GError *err, gpointer user_data); 
    2727void _tny_session_camel_register_account (TnySessionCamel *self, TnyCamelAccount *account); 
    2828void _tny_session_camel_activate_account (TnySessionCamel *self, TnyCamelAccount *account); 
  • devel/pvanhoof/sessionwork/libtinymail-camel/tny-session-camel.c

    r2509 r2513  
    412412 
    413413static void 
    414 on_account_connect_failed (TnySessionCamel *self, TnyCamelAccount *account, GError *err) 
    415 
    416         tny_lockable_lock (self->priv->ui_lock); 
    417         tny_session_camel_do_an_error (self, TNY_ACCOUNT (account), TNY_ALERT_TYPE_ERROR, FALSE, err); 
    418         tny_lockable_unlock (self->priv->ui_lock); 
     414on_account_connect_done (TnySessionCamel *self, TnyCamelAccount *account, GError *err, gpointer user_data) 
     415
     416        /* This one happens when a account is finished with connecting. On  
     417         * failure, err is not NULL */ 
     418 
     419        if (err) 
     420        { 
     421                tny_lockable_lock (self->priv->ui_lock); 
     422                tny_session_camel_do_an_error (self, TNY_ACCOUNT (account), TNY_ALERT_TYPE_ERROR, FALSE, err); 
     423                tny_lockable_unlock (self->priv->ui_lock); 
     424        } 
    419425 
    420426        return; 
     
    437443                _tny_camel_store_account_queue_going_online ( 
    438444                        TNY_CAMEL_STORE_ACCOUNT (account), self, online,  
    439                         on_account_connect_failed); 
     445                        on_account_connect_done, NULL); 
    440446        } 
    441447