aboutsummaryrefslogtreecommitdiff
path: root/accounts.cpp
blob: f1486b52ade7b66ea093400d1de4aa5c4350ccfc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <QFile>

#include "accounts.h"

DcAccounts::DcAccounts(QObject *parent)
  : QObject(parent)
{
    m_accounts = dc_accounts_new("Qt", "./deltachat-data");
}

DcAccounts::~DcAccounts()
{
    dc_accounts_unref(m_accounts);
}

uint32_t
DcAccounts::addAccount()
{
    return dc_accounts_add_account(m_accounts);
}

uint32_t
DcAccounts::importAccount(QString tarfile)
{
    QByteArray utf8Text = tarfile.toUtf8();
    return dc_accounts_import_account(m_accounts, utf8Text.constData());
}

uint32_t
DcAccounts::migrateAccount(QString dbfile)
{
    QByteArray utf8Text = dbfile.toUtf8();
    return dc_accounts_migrate_account(m_accounts, utf8Text.constData());
}

bool
DcAccounts::removeAccount(uint32_t accountId)
{
    return dc_accounts_remove_account(m_accounts, accountId);
}

QVariantList
DcAccounts::getAll()
{
    QVariantList result;
    dc_array_t *accountIdArray = dc_accounts_get_all(m_accounts);
    for (size_t i = 0; i < dc_array_get_cnt(accountIdArray); i++) {
        result << dc_array_get_id(accountIdArray, i);
    }
    dc_array_unref(accountIdArray);
    return result;
}

Context *
DcAccounts::getAccount(uint32_t accountId)
{
    dc_context_t *context = dc_accounts_get_account(m_accounts, accountId);

    return new Context(this, context);
}

Context *
DcAccounts::getSelectedAccount()
{
    dc_context_t *context = dc_accounts_get_selected_account(m_accounts);

    return new Context(this, context);
}

bool
DcAccounts::selectAccount(uint32_t accountId) {
    return dc_accounts_select_account(m_accounts, accountId);
}

void
DcAccounts::startIo()
{
    dc_accounts_start_io(m_accounts);
}

void
DcAccounts::stopIo()
{
    dc_accounts_stop_io(m_accounts);
}

void
DcAccounts::maybeNetwork()
{
    dc_accounts_maybe_network(m_accounts);
}

DcAccountsEventEmitter *
DcAccounts::getEventEmitter()
{
    return new DcAccountsEventEmitter{dc_accounts_get_event_emitter(m_accounts)};
}