aboutsummaryrefslogtreecommitdiff
path: root/accounts.cpp
diff options
context:
space:
mode:
authorlink2xt <link2xt@testrun.org>2020-11-05 22:03:37 +0300
committerlink2xt <link2xt@testrun.org>2020-11-05 23:08:08 +0300
commitfe89c7a4ff760564f3cdbcd8e27c04eadd9f79d8 (patch)
tree39d56b00509277afca8743adcf6051bd42121e99 /accounts.cpp
parentdaa31b783ad1dead6cbed79b428792702612aa31 (diff)
downloadkdeltachat-fe89c7a4ff760564f3cdbcd8e27c04eadd9f79d8.tar.gz
kdeltachat-fe89c7a4ff760564f3cdbcd8e27c04eadd9f79d8.zip
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.
Diffstat (limited to 'accounts.cpp')
-rw-r--r--accounts.cpp97
1 files changed, 97 insertions, 0 deletions
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 <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)};
+}