Changeset 2513
- Timestamp:
- 07/27/07 15:32:09
- Files:
-
- devel/pvanhoof/sessionwork/ChangeLog (modified) (1 diff)
- devel/pvanhoof/sessionwork/libtinymail-camel/tny-camel-account.c (modified) (2 diffs)
- devel/pvanhoof/sessionwork/libtinymail-camel/tny-camel-account.h (modified) (3 diffs)
- devel/pvanhoof/sessionwork/libtinymail-camel/tny-camel-store-account-priv.h (modified) (1 diff)
- devel/pvanhoof/sessionwork/libtinymail-camel/tny-camel-store-account.c (modified) (7 diffs)
- devel/pvanhoof/sessionwork/libtinymail-camel/tny-session-camel-priv.h (modified) (1 diff)
- devel/pvanhoof/sessionwork/libtinymail-camel/tny-session-camel.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
devel/pvanhoof/sessionwork/ChangeLog
r2510 r2513 4 4 * The poke status calls are now on the same queue as the other 5 5 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 6 15 7 16 2007-07-27 Philip Van Hoof <pvanhoof@gnome.org> devel/pvanhoof/sessionwork/libtinymail-camel/tny-camel-account.c
r2509 r2513 1160 1160 } 1161 1161 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). */ 1180 1165 1181 1166 void … … 1322 1307 1323 1308 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 **/ 1345 1327 void 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); 1328 tny_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 1333 typedef struct 1334 { 1335 TnyCamelAccount *account; 1336 GError *err; 1337 TnyCamelSetOnlineCallback callback; 1338 } OnSetOnlineInfo; 1339 1340 gboolean 1341 on_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 1351 static void 1352 on_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 1367 static void 1368 on_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 1389 void 1390 tny_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 } 1369 1418 } 1370 1419 devel/pvanhoof/sessionwork/libtinymail-camel/tny-camel-account.h
r2352 r2513 48 48 extern guint tny_camel_account_signals [TNY_CAMEL_ACCOUNT_LAST_SIGNAL]; 49 49 50 typedef void (*TnyCamelSetOnlineCallback) (TnyCamelAccount *account, GError *err); 51 50 52 51 53 struct _TnyCamelAccount … … 89 91 90 92 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); 92 94 93 95 /* Abstract methods */ … … 103 105 void tny_camel_account_add_option (TnyCamelAccount *self, const gchar *option); 104 106 void tny_camel_account_set_session (TnyCamelAccount *self, TnySessionCamel *session); 105 void tny_camel_account_set_online (TnyCamelAccount *self, gboolean online, GError **err);107 void tny_camel_account_set_online (TnyCamelAccount *self, gboolean online, TnyCamelSetOnlineCallback callback); 106 108 107 109 devel/pvanhoof/sessionwork/libtinymail-camel/tny-camel-store-account-priv.h
r2509 r2513 44 44 45 45 void _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);46 void _tny_camel_store_account_queue_going_online (TnyCamelStoreAccount *self, TnySessionCamel *session, gboolean online, go_online_callback_func err_func, gpointer user_data); 47 47 48 48 #endif devel/pvanhoof/sessionwork/libtinymail-camel/tny-camel-store-account.c
r2509 r2513 411 411 } 412 412 } else { 413 414 413 tny_camel_store_account_do_emit (TNY_CAMEL_STORE_ACCOUNT (self)); 415 416 /* tny_camel_account_set_online (self, apriv->connected); */417 414 } 418 415 … … 1531 1528 TnyCamelStoreAccount *self; 1532 1529 gboolean online; 1533 go_online_error_func err_func; 1530 go_online_callback_func done_func; 1531 gpointer user_data; 1534 1532 } GoingOnlineInfo; 1535 1533 … … 1546 1544 * must wait. */ 1547 1545 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! */ 1550 1549 1551 1550 apriv->is_connecting = TRUE; … … 1559 1558 1560 1559 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); 1562 1561 g_error_free (err); 1563 1562 } else { … … 1570 1569 1571 1570 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); 1574 1573 g_error_free (err); 1575 } 1574 } else 1575 info->done_func (info->session, 1576 TNY_CAMEL_ACCOUNT (info->self), NULL, info->user_data); 1577 1576 1578 } 1577 1579 … … 1593 1595 1594 1596 void 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) 1596 1598 { 1597 1599 GoingOnlineInfo *info = NULL; … … 1605 1607 info->session = session; 1606 1608 info->self = self; 1607 info-> err_func = err_func;1609 info->done_func = done_func; 1608 1610 info->online = online; 1611 info->user_data = user_data; 1609 1612 1610 1613 /* thread reference */ devel/pvanhoof/sessionwork/libtinymail-camel/tny-session-camel-priv.h
r2509 r2513 24 24 }; 25 25 26 typedef void (*go_online_ error_func) (TnySessionCamel *self, TnyCamelAccount *account, GError *err);26 typedef void (*go_online_callback_func) (TnySessionCamel *self, TnyCamelAccount *account, GError *err, gpointer user_data); 27 27 void _tny_session_camel_register_account (TnySessionCamel *self, TnyCamelAccount *account); 28 28 void _tny_session_camel_activate_account (TnySessionCamel *self, TnyCamelAccount *account); devel/pvanhoof/sessionwork/libtinymail-camel/tny-session-camel.c
r2509 r2513 412 412 413 413 static 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); 414 on_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 } 419 425 420 426 return; … … 437 443 _tny_camel_store_account_queue_going_online ( 438 444 TNY_CAMEL_STORE_ACCOUNT (account), self, online, 439 on_account_connect_ failed);445 on_account_connect_done, NULL); 440 446 } 441 447
