Commit d88c86ec authored by Karel Slaný's avatar Karel Slaný

Removed globAccountsModelPtr from db_wrapper.cpp.

parent f8378983
......@@ -93,7 +93,7 @@ Component {
anchors.fill: parent
onClicked: {
statusBarText.text = ""
isds.syncAllAccounts()
isds.syncAllAccounts(accountListModel)
}
}
}
......@@ -240,7 +240,7 @@ Component {
MouseArea {
anchors.fill: parent
onClicked: {
isds.syncOneAccount(rUserName)
isds.syncOneAccount(accountListModel, rUserName)
}
}
}
......
......@@ -203,9 +203,9 @@ Component {
if (downloadStart) {
downloadStart = false
if (msgType == MessageType.TYPE_RECEIVED) {
isds.syncSingleAccountReceived(messageModel, userName)
isds.syncSingleAccountReceived(accountListModel, messageModel, userName)
} else if (msgType == MessageType.TYPE_SENT) {
isds.syncSingleAccountSent(messageModel, userName)
isds.syncSingleAccountSent(accountListModel, messageModel, userName)
}
messages.fillMessageList(messageModel, userName, msgType)
}
......
......@@ -22,6 +22,7 @@
*/
#include "src/settings.h"
#include "src/models/accountmodel.h"
#include "src/net/db_wrapper.h"
#include "src/sqlite/account_db.h"
......@@ -81,22 +82,12 @@ bool DbWrapper::insertMessageListToDb(const QString &userName,
msgDb->commitTransaction();
if (messageType == MessageDb::TYPE_RECEIVED) {
globAccountsModelPtr->updateCounters(userName,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_RECEIVED),
msgDb->getMessageCount(MessageDb::TYPE_RECEIVED),
-1, -1);
if (newMsgs > 0) {
txt = tr("%1: new messages: %2")
.arg(userName).arg(QString::number(newMsgs));
} else {
txt = tr("%1: No new messages.").arg(userName);
}
} else {
globAccountsModelPtr->updateCounters(userName,
-1, -1,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_SENT),
msgDb->getMessageCount(MessageDb::TYPE_SENT));
}
return true;
......
......@@ -26,7 +26,6 @@
#include <QObject>
#include "src/models/accountmodel.h"
#include "src/sqlite/message_db_container.h"
#include "src/sqlite/file_db_container.h"
......
......@@ -38,28 +38,29 @@ IsdsWrapper::~IsdsWrapper(void)
{
}
void IsdsWrapper::syncAllAccounts(void)
void IsdsWrapper::syncAllAccounts(const QVariant &acntModelVariant)
{
qDebug("%s()", __func__);
QList<QString> userNameList = AccountListModel::globAccounts.keys();
foreach (const QString userName, userNameList) {
syncOneAccount(userName);
syncOneAccount(acntModelVariant, userName);
}
}
void IsdsWrapper::syncOneAccount(const QString &userName)
void IsdsWrapper::syncOneAccount(const QVariant &acntModelVariant,
const QString &userName)
{
qDebug("%s()", __func__);
if (syncSingleAccountSent(QVariant(), userName)) {
if (syncSingleAccountSent(acntModelVariant, QVariant(), userName)) {
/* Download received only when sent successfully downloaded. */
syncSingleAccountReceived(QVariant(), userName);
syncSingleAccountReceived(acntModelVariant, QVariant(), userName);
}
}
bool IsdsWrapper::syncSingleAccountReceived(const QVariant &msgModelVariant,
const QString &userName)
bool IsdsWrapper::syncSingleAccountReceived(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName)
{
if (userName.isEmpty()) {
Dialogues::errorMessage(Dialogues::CRITICAL,
......@@ -108,11 +109,27 @@ bool IsdsWrapper::syncSingleAccountReceived(const QVariant &msgModelVariant,
}
}
AccountListModel *accountModel =
AccountListModel::fromVariant(acntModelVariant);
if (accountModel == Q_NULLPTR) {
qWarning("%s", "Cannot access account model.");
} else {
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb != Q_NULLPTR) {
accountModel->updateCounters(userName,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_RECEIVED),
msgDb->getMessageCount(MessageDb::TYPE_RECEIVED),
-1, -1);
}
}
return true;
}
bool IsdsWrapper::syncSingleAccountSent(const QVariant &msgModelVariant,
const QString &userName)
bool IsdsWrapper::syncSingleAccountSent(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName)
{
if (userName.isEmpty()) {
Dialogues::errorMessage(Dialogues::CRITICAL,
......@@ -157,6 +174,22 @@ bool IsdsWrapper::syncSingleAccountSent(const QVariant &msgModelVariant,
}
}
AccountListModel *accountModel =
AccountListModel::fromVariant(acntModelVariant);
if (accountModel == Q_NULLPTR) {
qWarning("%s", "Cannot access account model.");
} else {
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb != Q_NULLPTR) {
accountModel->updateCounters(userName,
-1, -1,
msgDb->getCntOfNewMsgs(MessageDb::TYPE_SENT),
msgDb->getMessageCount(MessageDb::TYPE_SENT));
}
}
return true;
}
......
......@@ -44,41 +44,51 @@ public:
/*!
* @brief Download message list of all accounts.
*
* @param[in,out] acntModelVariant QVariant holding account model
* to be altered.
*/
Q_INVOKABLE
void syncAllAccounts(void);
void syncAllAccounts(const QVariant &acntModelVariant);
/*!
* @brief Download message list of one account.
*
* @param[in] userName Account username string.
* @param[in,out] acntModelVariant QVariant holding account model
* to be altered.
* @param[in] userName Account username string.
*/
Q_INVOKABLE
void syncOneAccount(const QString &userName);
void syncOneAccount(const QVariant &acntModelVariant,
const QString &userName);
/*!
* @brief Download received message list.
*
* @param[in,out] acntModelVariant QVariant holding account model
* to be altered.
* @param[in,out] msgModelVariant QVariant holding message model
* to be altered.
* @param[in] userName Account username string.
* @return True on success.
*/
Q_INVOKABLE
bool syncSingleAccountReceived(const QVariant &msgModelVariant,
const QString &userName);
bool syncSingleAccountReceived(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName);
/*!
* @brief Download list of sent messages.
*
* @param[in,out] acntModelVariant QVariant holding account model
* to be altered.
* @param[in,out] msgModelVariant QVariant holding message model
* to be altered.
* @param[in] userName Account username string.
* @return True on success.
*/
Q_INVOKABLE
bool syncSingleAccountSent(const QVariant &msgModelVariant,
const QString &userName);
bool syncSingleAccountSent(const QVariant &acntModelVariant,
const QVariant &msgModelVariant, const QString &userName);
/*!
* @brief Download account info.
......
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