1
/* Copyright 2013 Yorba Foundation
3
* This software is licensed under the GNU Lesser General Public License
4
* (version 2.1 or later). See the COPYING file in this distribution.
7
namespace Geary.ImapEngine {
9
private int init_count = 0;
10
private Gee.HashMap<GenericAccount, AccountSynchronizer>? account_synchronizers = null;
12
internal void init() {
13
if (init_count++ != 0)
16
account_synchronizers = new Gee.HashMap<GenericAccount, AccountSynchronizer>();
18
// create a FullAccountSync object for each Account as it comes and goes
19
Engine.instance.account_available.connect(on_account_available);
20
Engine.instance.account_unavailable.connect(on_account_unavailable);
23
private GenericAccount? get_imap_account(AccountInformation account_info) {
25
return Engine.instance.get_account_instance(account_info) as GenericAccount;
27
debug("Unable to get account instance %s: %s", account_info.email, err.message);
33
private void on_account_available(AccountInformation account_info) {
34
GenericAccount? imap_account = get_imap_account(account_info);
35
if (imap_account == null)
38
assert(!account_synchronizers.has_key(imap_account));
39
account_synchronizers.set(imap_account, new AccountSynchronizer(imap_account));
42
private void on_account_unavailable(AccountInformation account_info) {
43
GenericAccount? imap_account = get_imap_account(account_info);
44
if (imap_account == null)
47
AccountSynchronizer? account_synchronizer = account_synchronizers.get(imap_account);
48
assert(account_synchronizer != null);
50
account_synchronizer.stop_async.begin(on_synchronizer_stopped);
53
private void on_synchronizer_stopped(Object? source, AsyncResult result) {
54
AccountSynchronizer account_synchronizer = (AccountSynchronizer) source;
55
account_synchronizer.stop_async.end(result);
57
bool removed = account_synchronizers.unset(account_synchronizer.account);