From fe89c7a4ff760564f3cdbcd8e27c04eadd9f79d8 Mon Sep 17 00:00:00 2001 From: link2xt Date: Thu, 5 Nov 2020 22:03:37 +0300 Subject: Move accounts model from C++ to QML C++ models are not well documented and it is easier to manage the model in QML. Now all QObjects are thin wrappers around Delta Chat core structures. --- accounts.cpp | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 accounts.cpp (limited to 'accounts.cpp') diff --git a/accounts.cpp b/accounts.cpp new file mode 100644 index 0000000..f1486b5 --- /dev/null +++ b/accounts.cpp @@ -0,0 +1,97 @@ +#include + +#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)}; +} -- cgit v1.2.3-70-g09d2