Commit 74c788d2 authored by Karel Slaný's avatar Karel Slaný

Removed globAccountsModelPtr, explicitly passing accountModel between QML pages.

parent d40a41a3
......@@ -28,6 +28,7 @@ import QtQuick.Layouts 1.2
import QtQuick.Dialogs 1.2
import QtGraphicalEffects 1.0
import cz.nic.mobileDatovka.messages 1.0
import cz.nic.mobileDatovka.models 1.0
/*
* Roles are defined in AccountListModel::roleNames() and are accessed directly
......@@ -56,6 +57,21 @@ Component {
syncAllButton.enabled = false
}
}
/*
* The account list model is created by C++ code because the accounts
* need to be set up and saved from within the main function.
* But, the account model is explicitly passed to other QML pages just
* to maintain consistency with other models and to emphasise the fact
* that the pages need to access the model.
*/
//AccountListModel {
// id: mainAccountModel
//
// Component.onCompleted: {
// }
//}
Rectangle {
id: datovkaHeader
anchors.top: parent.top
......@@ -93,9 +109,9 @@ Component {
anchors.fill: parent
onClicked: {
statusBarText.text = ""
if (isds.syncAllAccounts(accountListModel)) {
if (isds.syncAllAccounts(mainAccountModel)) {
settings.setLastUpdateToNow()
settings.saveAllSettings(accountListModel)
settings.saveAllSettings(mainAccountModel)
}
}
}
......@@ -110,7 +126,8 @@ Component {
onClicked: {
pageView.push(pageMenuDatovkaSettings, {
"pageView": pageView,
"statusBar": statusBar
"statusBar": statusBar,
"accountModel": mainAccountModel
}, StackView.Immediate)
}
}
......@@ -131,7 +148,8 @@ Component {
"pageView": pageView,
"statusBar": statusBar,
"acntName": "",
"userName": ""
"userName": "",
"accountModel": mainAccountModel
}, StackView.Immediate)
}
}
......@@ -146,7 +164,7 @@ Component {
visible: true
width: parent.width
interactive: true
model: accountListModel
model: mainAccountModel
onCountChanged: {
if (accountList.count == 0) {
accountList.visible = false
......@@ -228,7 +246,8 @@ Component {
"pageView": pageView,
"statusBar": statusBar,
"acntName": rAcntName,
"userName": rUserName
"userName": rUserName,
"accountModel": mainAccountModel
}, StackView.Immediate)
}
}
......@@ -243,9 +262,9 @@ Component {
MouseArea {
anchors.fill: parent
onClicked: {
if (isds.syncOneAccount(accountListModel, rUserName)) {
if (isds.syncOneAccount(mainAccountModel, rUserName)) {
settings.setLastUpdateToNow()
settings.saveAllSettings(accountListModel)
settings.saveAllSettings(mainAccountModel)
}
}
}
......@@ -319,7 +338,8 @@ Component {
"statusBar": statusBar,
"acntName": rAcntName,
"userName": rUserName,
"msgType": MessageType.TYPE_RECEIVED
"msgType": MessageType.TYPE_RECEIVED,
"accountModel": mainAccountModel
}, StackView.Immediate)
}
}
......@@ -387,7 +407,8 @@ Component {
"statusBar": statusBar,
"acntName": rAcntName,
"userName": rUserName,
"msgType": MessageType.TYPE_SENT
"msgType": MessageType.TYPE_SENT,
"accountModel": mainAccountModel
}, StackView.Immediate)
}
}
......
......@@ -39,6 +39,7 @@ Component {
property var statusBar
property string acntName
property string userName
property var accountModel: null
property int myWidht: mainLayout.width - 2 * defaultMargin
......@@ -151,7 +152,8 @@ Component {
"pageView": pageView,
"statusBar": statusBar,
"acntName": acntName,
"userName": userName
"userName": userName,
"accountModel": accountModel
}, StackView.Immediate)
} else if (index == 1) {
pageView.replace(pageAccountDetail, {
......@@ -164,11 +166,11 @@ Component {
files.deleteFileDb(userName)
} else if (index == 3) {
if (isds.changePassword(userName, acntName)) {
settings.saveAllSettings(accountListModel)
settings.saveAllSettings(accountModel)
}
} else if (index == 4) {
if (accounts.removeAccount(accountListModel, userName, true)) {
settings.saveAllSettings(accountListModel)
if (accounts.removeAccount(accountModel, userName, true)) {
settings.saveAllSettings(accountModel)
pageView.pop(StackView.Immediate)
}
} else {
......
......@@ -30,13 +30,14 @@ import QtGraphicalEffects 1.0
import cz.nic.mobileDatovka 1.0
Component {
id: menuDatovkamainSettings
id: menuDatovkaSettings
Item {
id: mainLayout
/* These properties must be set by caller. */
property var pageView
property var statusBar
property var accountModel: null
property int myWidht: mainLayout.width - 2 * defaultMargin
......@@ -153,27 +154,32 @@ Component {
"pageView": pageView,
"statusBar": statusBar,
"acntName": "",
"userName": ""
"userName": "",
"accountModel": accountModel
}, StackView.Immediate)
} else if (index == 2) {
pageView.replace(pageSettingsGeneral, {
"pageView": pageView,
"statusBar": statusBar
"statusBar": statusBar,
"accountModel": accountModel
}, StackView.Immediate)
} else if (index == 3) {
pageView.replace(pageSettingsSync, {
"pageView": pageView,
"statusBar": statusBar
"statusBar": statusBar,
"accountModel": accountModel
}, StackView.Immediate)
} else if (index == 4) {
pageView.replace(pageSettingsStorage, {
"pageView": pageView,
"statusBar": statusBar
"statusBar": statusBar,
"accountModel": accountModel
}, StackView.Immediate)
} else if (index == 5) {
pageView.replace(pageSettingsPin, {
"pageView": pageView,
"statusBar": statusBar
"statusBar": statusBar,
"accountModel": accountModel
}, StackView.Immediate)
} else if (index == 6) {
pageView.replace(pageMessageSearch, {
......
......@@ -44,6 +44,7 @@ Component {
property int msgType
property string msgId
property bool canDeleteMsg
property var accountModel: null
property var messageModel: null
property int myWidht: mainLayout.width - 2 * defaultMargin
......@@ -167,7 +168,7 @@ Component {
} else if (index == 2) {
messages.markMessageAsLocallyRead(messageModel, userName, msgId, false)
} else if (index == 3) {
messages.deleteMessageFromDbs(accountListModel, messageModel, userName, msgId)
messages.deleteMessageFromDbs(accountModel, messageModel, userName, msgId)
}
pageView.pop(StackView.Immediate)
}
......
......@@ -45,6 +45,7 @@ Component {
property string acntName
property string userName
property int msgType
property var accountModel: null
Component.onCompleted: {
messages.fillMessageList(messageModel, userName, msgType)
......@@ -89,7 +90,7 @@ Component {
MouseArea {
anchors.fill: parent
onClicked: {
accounts.updateNewMessageCounter(accountListModel, userName)
accounts.updateNewMessageCounter(accountModel, userName)
statusBar.visible = false
pageView.pop(StackView.Immediate)
}
......@@ -194,6 +195,7 @@ Component {
"msgType": msgType,
"msgId": msgId,
"canDeleteMsg": canDelete,
"accountModel": accountModel,
"messageModel": messageModel
}, StackView.Immediate)
}
......@@ -203,12 +205,12 @@ Component {
if (downloadStart) {
downloadStart = false
if (msgType == MessageType.TYPE_RECEIVED) {
if (isds.syncSingleAccountReceived(accountListModel, messageModel, userName)) {
if (isds.syncSingleAccountReceived(accountModel, messageModel, userName)) {
settings.setLastUpdateToNow()
settings.saveAllSettings(accountListModel)
settings.saveAllSettings(accountModel)
}
} else if (msgType == MessageType.TYPE_SENT) {
isds.syncSingleAccountSent(accountListModel, messageModel, userName)
isds.syncSingleAccountSent(accountModel, messageModel, userName)
}
messages.fillMessageList(messageModel, userName, msgType)
}
......
......@@ -30,11 +30,14 @@ Component {
id: settingsAccount
Item {
id: mainLayout
/* These properties must be set by caller. */
property var pageView
property var statusBar
property string acntName
property string userName
property var accountModel: null
property bool isNewAccount: (userName == "")
property string sLoginMethod: "pwd"
Component.onCompleted: {
......@@ -312,29 +315,29 @@ Component {
/* TODO - Must be replaced via better solution in the future. */
onSaveAccountResponse: {
if (isNewAccount) {
if (accounts.createAccount(accountListModel, sLoginMethod,
if (accounts.createAccount(accountModel, sLoginMethod,
accountNameTextField.text.toString(),
userNameTextField.text.toString(),
passwordTextField.text.toString(),
testAccount.checked, rememberPassword.checked,
useLS.checked, certPathLabelId.text.toString())) {
if (isds.getAccountInfo(userNameTextField.text.toString(), true)) {
settings.saveAllSettings(accountListModel)
settings.saveAllSettings(accountModel)
pageView.pop(StackView.Immediate)
} else {
if (accounts.removeAccount(accountListModel, userNameTextField.text.toString(), false)) {
settings.saveAllSettings(accountListModel)
if (accounts.removeAccount(accountModel, userNameTextField.text.toString(), false)) {
settings.saveAllSettings(accountModel)
}
}
}
} else {
if (accounts.updateAccount(accountListModel, sLoginMethod,
if (accounts.updateAccount(accountModel, sLoginMethod,
accountNameTextField.text.toString(),
userNameTextField.text.toString(),
passwordTextField.text.toString(),
testAccount.checked, rememberPassword.checked,
useLS.checked, certPathLabelId.text.toString())) {
settings.saveAllSettings(accountListModel)
settings.saveAllSettings(accountModel)
}
pageView.pop(StackView.Immediate)
}
......
......@@ -29,9 +29,12 @@ Component {
id: settingsGeneral
Item {
id: mainLayout
/* These properties must be set by caller. */
property var pageView
property var statusBar
property var accountModel: null
property string sectionName: "general"
property string sLang: "cs"
Component.onCompleted: {
......@@ -171,7 +174,7 @@ Component {
onSaveSettingsGeneralResponse: {
settings.updateSettingsGeneral(sLang,
fontSizeSpinBox.val().toString())
settings.saveAllSettings(accountListModel)
settings.saveAllSettings(accountModel)
pageView.pop(StackView.Immediate)
}
}
......
......@@ -33,6 +33,7 @@ Component {
/* These properties must be set by caller. */
property var pageView
property var statusBar
property var accountModel: null
Component.onCompleted: {
currentPIN = settings.pinValue()
......@@ -176,7 +177,7 @@ Component {
} else {
errLineText.visible = false
settings.updatePinSettings(pinConfirmField1.text.toString())
settings.saveAllSettings(accountListModel)
settings.saveAllSettings(accountModel)
pageView.pop(StackView.Immediate)
}
/* change current pin code */
......@@ -198,7 +199,7 @@ Component {
} else {
errLineText.visible = false
settings.updatePinSettings(pinConfirmField1.text.toString())
settings.saveAllSettings(accountListModel)
settings.saveAllSettings(accountModel)
pageView.pop(StackView.Immediate)
}
} else {
......@@ -212,7 +213,7 @@ Component {
if (pinValueField.text == currentPIN) {
errLineText.visible = false
settings.updatePinSettings("")
settings.saveAllSettings(accountListModel)
settings.saveAllSettings(accountModel)
settings.setInactivityInterval(0)
locker.setInactivityInterval(0)
pageView.pop(StackView.Immediate)
......
......@@ -29,9 +29,12 @@ Component {
id: settingsStorage
Item {
id: mainLayout
/* These properties must be set by caller. */
property var pageView
property var statusBar
property var accountModel: null
property string sectionName: "storage"
Component.onCompleted: {
settings.loadSettings(sectionName)
......@@ -231,7 +234,7 @@ Component {
messageLifeSpinBox.val().toString(),
attachLifeSpinBox.val().toString(),
dbPathText.text.toString())
settings.saveAllSettings(accountListModel)
settings.saveAllSettings(accountModel)
pageView.pop(StackView.Immediate)
}
}
......
......@@ -29,9 +29,12 @@ Component {
id: settingsSync
Item {
id: mainLayout
/* These properties must be set by caller. */
property var pageView
property var statusBar
property var accountModel: null
property string sectionName: "sync"
Component.onCompleted: {
settings.loadSettings(sectionName)
......@@ -127,7 +130,7 @@ Component {
settings.updateSettingsSync(
idownloadOnlyNewMsgs.checked,
idownloadCompleteMsgs.checked)
settings.saveAllSettings(accountListModel)
settings.saveAllSettings(accountModel)
pageView.pop(StackView.Immediate)
}
}
......
......@@ -258,12 +258,12 @@ int main(int argc, char *argv[])
app.installEventFilter(&locker);
/* Create and init account model. */
globAccountsModelPtr = new (std::nothrow) AccountListModel;
if (Q_NULLPTR == globAccountsModelPtr) {
AccountListModel *accountModelPtr = new (std::nothrow) AccountListModel;
if (Q_NULLPTR == accountModelPtr) {
qCritical("Cannot create account model.");
return EXIT_FAILURE;
}
globAccountsModelPtr->setObjectName("accountListModel");
accountModelPtr->setObjectName("mainAccountModel");
/* get main handle of appliaction and QML */
QQmlApplicationEngine engine;
......@@ -302,8 +302,7 @@ int main(int argc, char *argv[])
ctx->setContextProperty("dlgEmitter", QmlDlgHelper::dlgEmitter);
/* register and set models in QML */
ctx->setContextProperty(globAccountsModelPtr->objectName(),
globAccountsModelPtr);
ctx->setContextProperty(accountModelPtr->objectName(), accountModelPtr);
/* Localise description in tables. */
accntinfTbl.reloadLocalisedDescription();
......@@ -334,7 +333,7 @@ int main(int argc, char *argv[])
{
QSettings settings(Settings::settingsPath(),
QSettings::IniFormat);
globAccountsModelPtr->loadAccountsFromSettings(settings);
accountModelPtr->loadAccountsFromSettings(settings);
/*
* No need to load counters here as some messages are likely
* to be deleted.
......@@ -376,7 +375,7 @@ int main(int argc, char *argv[])
}
/* Load counters. */
Accounts::loadModelCounters(globAccountsModelPtr);
Accounts::loadModelCounters(accountModelPtr);
/*
* Show PIN screen if needed. Encoded PIN is checked because it hasn't
......@@ -418,11 +417,11 @@ int main(int argc, char *argv[])
* The PIN was set/recovered or
* incomplete data to check/recover the PIN were supplied.
*/
GlobalSettingsQmlWrapper::saveAllSettings(globAccountsModelPtr);
GlobalSettingsQmlWrapper::saveAllSettings(accountModelPtr);
}
delete globAccountsModelPtr;
globAccountsModelPtr = Q_NULLPTR;
delete accountModelPtr;
accountModelPtr = Q_NULLPTR;
return ret;
}
......@@ -521,8 +521,6 @@ void AccountsMap::loadAccountsFromSettings(const QSettings &settings)
}
}
AccountListModel *globAccountsModelPtr = Q_NULLPTR;
AccountsMap AccountListModel::globAccounts;
void AccountListModel::declareQML(void)
......
......@@ -21,8 +21,8 @@
* the two.
*/
#ifndef ACCOUNTMODEL_H
#define ACCOUNTMODEL_H
#ifndef _ACCOUNTMODEL_H_
#define _ACCOUNTMODEL_H_
#include <QAbstractListModel>
#include <QSettings>
......@@ -320,12 +320,4 @@ private:
Q_DECLARE_METATYPE(AccountListModel)
Q_DECLARE_METATYPE(AccountListModel::Roles)
/*
* The model cannot be a static global instance because of the dependencies on
* other static objects (static initialisation order fiasco).
*
* Therefore it must me allocated somewhere in the program.
*/
extern AccountListModel *globAccountsModelPtr;
#endif // ACCOUNTMODEL_H
#endif /* _ACCOUNTMODEL_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment