aboutsummaryrefslogtreecommitdiff
path: root/qml
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 /qml
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 'qml')
-rw-r--r--qml/AccountsPage.qml33
-rw-r--r--qml/main.qml14
2 files changed, 35 insertions, 12 deletions
diff --git a/qml/AccountsPage.qml b/qml/AccountsPage.qml
index c9368d2..3278031 100644
--- a/qml/AccountsPage.qml
+++ b/qml/AccountsPage.qml
@@ -12,7 +12,10 @@ Kirigami.Page {
mainAction: Kirigami.Action {
iconName: "list-add-user"
text: "Add account"
- onTriggered: accountsModel.addAccount()
+ onTriggered: {
+ let accountId = dcAccounts.addAccount()
+ accountsModel.insert(accountsModel.count, { number: accountId })
+ }
}
contextualActions: [
@@ -31,7 +34,7 @@ Kirigami.Page {
if (url.startsWith("file://")) {
var filename = url.substring(7)
console.log("Importing " + filename)
- var accountId = accountsModel.importAccount (filename)
+ var accountId = dcAccounts.importAccount(filename)
if (accountId == 0) {
console.log("Import failed")
} else {
@@ -41,6 +44,23 @@ Kirigami.Page {
}
}
+ ListModel {
+ id: accountsModel
+ }
+
+ function updateAccounts() {
+ let accountsList = dcAccounts.getAll()
+
+ accountsModel.clear()
+ for (let i = 0; i < accountsList.length; i++) {
+ accountsModel.insert(i, { number: accountsList[i] })
+ }
+ }
+
+ Component.onCompleted: {
+ updateAccounts()
+ }
+
ListView {
id: accountsListView
anchors.fill: parent
@@ -63,8 +83,8 @@ Kirigami.Page {
while (pageStack.depth > 1) {
pageStack.pop()
}
- accountsModel.selectedAccount = model.number
- let context = accountsModel.getSelectedAccount()
+ dcAccounts.selectAccount(model.number)
+ let context = dcAccounts.getSelectedAccount()
if (context.isConfigured()) {
pageStack.push("qrc:/qml/ChatlistPage.qml", {context: context})
} else {
@@ -76,7 +96,10 @@ Kirigami.Page {
Button {
width: 100
text: "Delete"
- onClicked: accountsModel.removeAccount(model.number)
+ onClicked: {
+ dcAccounts.removeAccount(model.number)
+ accountsModel.remove(model.index)
+ }
}
}
}
diff --git a/qml/main.qml b/qml/main.qml
index cb116b3..546d553 100644
--- a/qml/main.qml
+++ b/qml/main.qml
@@ -19,9 +19,9 @@ Kirigami.ApplicationWindow {
text: "Start IO"
onCheckedChanged: {
if (checked) {
- accountsModel.startIo()
+ dcAccounts.startIo()
} else {
- accountsModel.stopIo()
+ dcAccouts.stopIo()
}
}
}
@@ -30,7 +30,7 @@ Kirigami.ApplicationWindow {
Kirigami.Action {
text: "Maybe network"
iconName: "view-refresh"
- onTriggered: accountsModel.maybeNetwork()
+ onTriggered: dcAccounts.maybeNetwork()
}
]
}
@@ -39,18 +39,18 @@ Kirigami.ApplicationWindow {
id: contextDrawer
}
- AccountsModel {
- id: accountsModel
+ DcAccounts {
+ id: dcAccounts
}
Component.onCompleted: {
console.log('starting')
- eventEmitter = accountsModel.getEventEmitter()
+ eventEmitter = dcAccounts.getEventEmitter()
eventEmitter.start();
}
onClosing: {
// Cancel all tasks that may block the termination of event loop.
- accountsModel.stopIo()
+ dcAccounts.stopIo()
}
}