aboutsummaryrefslogtreecommitdiff
path: root/accounts_model.h
blob: 5541f7ec826c233491743c2eb9403760a4c59ce3 (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
#pragma once

#include <QAbstractListModel>
#include <deltachat.h>

#include "eventemitter.h"
#include "context.h"

class AccountsModel : public QAbstractListModel {
    Q_OBJECT
    Q_PROPERTY(size_t accountCount READ accountCount NOTIFY accountCountChanged)
    Q_PROPERTY(uint32_t selectedAccount READ selectedAccount WRITE setSelectedAccount NOTIFY selectedAccountChanged)

public:
    enum AccountRoles {
        NumberRole = Qt::UserRole + 1
    };
    explicit AccountsModel(QObject *parent = nullptr);
    ~AccountsModel();

    int rowCount(const QModelIndex & parent = QModelIndex()) const;

    QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;

    size_t accountCount() const;

    uint32_t selectedAccount();
    void setSelectedAccount(uint32_t selectedAccount);

    Q_INVOKABLE uint32_t addAccount();
    Q_INVOKABLE void removeAccount(uint32_t accountId);
    Q_INVOKABLE uint32_t importAccount(const QString &filename);
    Q_INVOKABLE Context *getSelectedAccount();

    Q_INVOKABLE void startIo();
    Q_INVOKABLE void stopIo();
    Q_INVOKABLE void maybeNetwork();

    Q_INVOKABLE DcAccountsEventEmitter *getEventEmitter();

signals:
    void accountCountChanged();
    void selectedAccountChanged();

protected:
    QHash<int, QByteArray> roleNames() const;

private:
    dc_accounts_t *m_accounts{nullptr};
    uint32_t m_selectedAccount{0};
};