~ubuntu-branches/ubuntu/saucy/geary/saucy-updates

« back to all changes in this revision

Viewing changes to src/engine/imap-engine/imap-engine.vala

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2013-03-14 13:48:23 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130314134823-gyk5av1g508zyj8a
Tags: 0.3.0~pr1-0ubuntu1
New upstream version (FFE lp: #1154316), supports multiple account as
well as full conversation views with inline replies

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2013 Yorba Foundation
 
2
 *
 
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.
 
5
 */
 
6
 
 
7
namespace Geary.ImapEngine {
 
8
 
 
9
private int init_count = 0;
 
10
private Gee.HashMap<GenericAccount, AccountSynchronizer>? account_synchronizers = null;
 
11
 
 
12
internal void init() {
 
13
    if (init_count++ != 0)
 
14
        return;
 
15
    
 
16
    account_synchronizers = new Gee.HashMap<GenericAccount, AccountSynchronizer>();
 
17
    
 
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);
 
21
}
 
22
 
 
23
private GenericAccount? get_imap_account(AccountInformation account_info) {
 
24
    try {
 
25
        return Engine.instance.get_account_instance(account_info) as GenericAccount;
 
26
    } catch (Error err) {
 
27
        debug("Unable to get account instance %s: %s", account_info.email, err.message);
 
28
    }
 
29
    
 
30
    return null;
 
31
}
 
32
 
 
33
private void on_account_available(AccountInformation account_info) {
 
34
    GenericAccount? imap_account = get_imap_account(account_info);
 
35
    if (imap_account == null)
 
36
        return;
 
37
    
 
38
    assert(!account_synchronizers.has_key(imap_account));
 
39
    account_synchronizers.set(imap_account, new AccountSynchronizer(imap_account));
 
40
}
 
41
 
 
42
private void on_account_unavailable(AccountInformation account_info) {
 
43
    GenericAccount? imap_account = get_imap_account(account_info);
 
44
    if (imap_account == null)
 
45
        return;
 
46
    
 
47
    AccountSynchronizer? account_synchronizer = account_synchronizers.get(imap_account);
 
48
    assert(account_synchronizer != null);
 
49
    
 
50
    account_synchronizer.stop_async.begin(on_synchronizer_stopped);
 
51
}
 
52
 
 
53
private void on_synchronizer_stopped(Object? source, AsyncResult result) {
 
54
    AccountSynchronizer account_synchronizer = (AccountSynchronizer) source;
 
55
    account_synchronizer.stop_async.end(result);
 
56
    
 
57
    bool removed = account_synchronizers.unset(account_synchronizer.account);
 
58
    assert(removed);
 
59
}
 
60
 
 
61
}
 
62