aboutsummaryrefslogtreecommitdiff
path: root/accounts.cpp
diff options
context:
space:
mode:
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)};
+}