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

Accounts map is no longer a static global instance.

parent 3a1aa267
......@@ -79,7 +79,8 @@ void Accounts::updateNewMessageCounter(const QVariant &acntModelVariant,
qDebug("%s()", __func__);
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR))) {
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
......@@ -94,7 +95,7 @@ void Accounts::updateNewMessageCounter(const QVariant &acntModelVariant,
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
return;
......@@ -121,11 +122,16 @@ void Accounts::getAccountData(const QString &userName)
{
qDebug("%s()", __func__);
if (!AccountListModel::globAccounts.contains(userName)) {
if (Q_UNLIKELY(GlobInstcs::acntMapPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
if (!GlobInstcs::acntMapPtr->contains(userName)) {
return;
}
const AcntData &acntData(AccountListModel::globAccounts[userName]);
const AcntData &acntData((*GlobInstcs::acntMapPtr)[userName]);
emit sendAccountData(acntData.accountName(), userName,
acntData.loginMethod(), acntData.password(), acntData.isTestAccount(),
......@@ -185,7 +191,8 @@ bool Accounts::updateAccount(const QVariant &acntModelVariant,
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
(GlobInstcs::fileDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return false;
}
......@@ -206,11 +213,11 @@ bool Accounts::updateAccount(const QVariant &acntModelVariant,
return false;
}
if (!AccountListModel::globAccounts.contains(userName)) {
if (!GlobInstcs::acntMapPtr->contains(userName)) {
return false;
}
AcntData &acntData(AccountListModel::globAccounts[userName]);
AcntData &acntData((*GlobInstcs::acntMapPtr)[userName]);
/* update account map */
acntData.setLoginMethod(loginMetod);
......@@ -259,7 +266,7 @@ bool Accounts::updateAccount(const QVariant &acntModelVariant,
acntData.setCertPath(certPath);
/* Model data have changed. */
emit AccountListModel::globAccounts.accountDataChanged(userName);
emit GlobInstcs::acntMapPtr->accountDataChanged(userName);
/* Delete isds session context */
emit removeIsdsCtx(userName);
......@@ -275,7 +282,8 @@ bool Accounts::removeAccount(const QVariant &acntModelVariant,
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::accountDbPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
(GlobInstcs::fileDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return false;
}
......@@ -299,14 +307,14 @@ bool Accounts::removeAccount(const QVariant &acntModelVariant,
}
}
if (!AccountListModel::globAccounts.contains(userName)) {
if (!GlobInstcs::acntMapPtr->contains(userName)) {
return false;
}
/* Delete file database */
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical("%s", "Cannot open file database.");
return false;
......@@ -319,7 +327,7 @@ bool Accounts::removeAccount(const QVariant &acntModelVariant,
/* Delete message database */
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
return false;
......@@ -355,7 +363,8 @@ void Accounts::loadModelCounters(AccountListModel *accountModel)
qDebug("%s()", __func__);
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR))) {
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
......@@ -376,7 +385,7 @@ void Accounts::loadModelCounters(AccountListModel *accountModel)
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qWarning("Cannot open message database for '%s'.",
userName.toUtf8().constData());
......
......@@ -72,17 +72,18 @@ void Files::deleteExpiredFilesFromDbs(int days)
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
(GlobInstcs::fileDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
QStringList msgIDList;
QStringList userNameList = AccountListModel::globAccounts.keys();
QStringList userNameList(GlobInstcs::acntMapPtr->keys());
foreach (const QString &userName, userNameList) {
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!"
<< userName;
......@@ -95,7 +96,7 @@ void Files::deleteExpiredFilesFromDbs(int days)
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "ERROR: Message database cannot open!";
return;
......@@ -125,14 +126,15 @@ QByteArray Files::getFileRawContentFromDb(const QString &userName, int fileId)
qDebug("%s()", __func__);
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
(GlobInstcs::fileDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return QByteArray();
}
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "Cannot open file database!";
......@@ -149,14 +151,15 @@ void Files::openAttachmentFromDb(const QString &userName, int fileId)
qDebug("%s()", __func__);
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
(GlobInstcs::fileDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "Cannot open file database!";
......@@ -238,7 +241,8 @@ void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
(GlobInstcs::fileDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
......@@ -253,7 +257,7 @@ void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "ERROR: Message database cannot open!";
return;
......@@ -265,7 +269,7 @@ void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!";
return;
......@@ -307,7 +311,8 @@ void Files::deleteFileDb(const QString &userName)
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
(GlobInstcs::fileDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
......@@ -323,7 +328,7 @@ void Files::deleteFileDb(const QString &userName)
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database open error!";
return;
......@@ -335,7 +340,7 @@ void Files::deleteFileDb(const QString &userName)
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "ERROR: Message database cannot open!";
return;
......@@ -351,18 +356,19 @@ void Files::vacuumFileDbs(void)
qDebug("%s()", __func__);
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
(GlobInstcs::fileDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
emit statusBarTextChanged(tr("Vacuum databases"), true);
QStringList userNameList = AccountListModel::globAccounts.keys();
QStringList userNameList(GlobInstcs::acntMapPtr->keys());
foreach (const QString &userName, userNameList) {
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!"
<< userName;
......@@ -380,14 +386,15 @@ bool Files::deleteAttachmentsFromDb(const QString &userName, qint64 msgId)
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
(GlobInstcs::fileDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return false;
}
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!" << userName;
return false;
......@@ -396,7 +403,7 @@ bool Files::deleteAttachmentsFromDb(const QString &userName, qint64 msgId)
if (fDb->deleteFilesFromDb(msgId)) {
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "ERROR: Message database cannot open!";
return false;
......@@ -476,14 +483,15 @@ bool Files::setAttachmentModel(FileListModel &attachModel,
qDebug("%s()", __func__);
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
(GlobInstcs::fileDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return false;
}
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "Cannot open file database!";
......@@ -549,7 +557,8 @@ void Files::saveAttachmentsToDiskDb(const QString &userName,
qDebug("%s()", __func__);
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
(GlobInstcs::fileDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
......@@ -569,7 +578,7 @@ void Files::saveAttachmentsToDiskDb(const QString &userName,
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "Cannot open file database!";
......
......@@ -37,4 +37,6 @@ class FileDbContainer *GlobInstcs::fileDbsPtr = Q_NULLPTR;
class ZfoDb *GlobInstcs::zfoDbPtr = Q_NULLPTR;
class RecordsManagementDb *GlobInstcs::recMgmtDbPtr = Q_NULLPTR;
class AccountsMap *GlobInstcs::acntMapPtr = Q_NULLPTR;
class ImageProvider *GlobInstcs::imgProvPtr = Q_NULLPTR;
......@@ -50,6 +50,9 @@ public:
static
class RecordsManagementDb *recMgmtDbPtr; /*!< Records management database. */
static
class AccountsMap *acntMapPtr; /*!< Account container. */
static
class ImageProvider *imgProvPtr; /*!< Image provider. */
......
......@@ -352,15 +352,7 @@ int main(int argc, char *argv[])
&locker, SLOT(processNewState(Qt::ApplicationState)));
app.installEventFilter(&locker);
/* Create and init account model. */
AccountListModel *accountModelPtr = new (std::nothrow) AccountListModel;
if (Q_NULLPTR == accountModelPtr) {
qCritical("Cannot create account model.");
return EXIT_FAILURE;
}
accountModelPtr->setObjectName("mainAccountModel");
/* get main handle of appliaction and QML */
/* Get main handle of the application and the QML engine. */
QQmlApplicationEngine engine;
QQmlContext *ctx = engine.rootContext();
......@@ -407,9 +399,6 @@ int main(int argc, char *argv[])
ctx->setContextProperty("zfo", &zfo);
ctx->setContextProperty("recordsManagement", &recordsManagement);
/* register and set models in QML */
ctx->setContextProperty(accountModelPtr->objectName(), accountModelPtr);
/* Localise description in tables. */
accntinfTbl.reloadLocalisedDescription();
userinfTbl.reloadLocalisedDescription();
......@@ -418,7 +407,7 @@ int main(int argc, char *argv[])
evntsTbl.reloadLocalisedDescription();
msgZfoTbl.reloadLocalisedDescription();
/* Init and open account database. */
/* Initialise and open account database. */
AccountDb accountDb("ACCOUNTS", false);
MsgDbContainer messageDbs("MESSAGES");
FileDbContainer fileDbs("FILES");
......@@ -437,6 +426,12 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
GlobInstcs::acntMapPtr = new (std::nothrow) AccountsMap;
if (GlobInstcs::acntMapPtr == Q_NULLPTR) {
qCritical("Cannot allocate account map.");
return EXIT_FAILURE;
}
GlobInstcs::imgProvPtr = new (std::nothrow) ImageProvider;
if (GlobInstcs::imgProvPtr == Q_NULLPTR) {
qCritical("Cannot create image provider.");
......@@ -444,6 +439,18 @@ int main(int argc, char *argv[])
}
}
/* Create and initialise account model. */
AccountListModel *accountModelPtr = new (std::nothrow) AccountListModel;
if (Q_NULLPTR == accountModelPtr) {
qCritical("Cannot create account model.");
return EXIT_FAILURE;
}
accountModelPtr->setObjectName("mainAccountModel");
accountModelPtr->setAccounts(GlobInstcs::acntMapPtr);
/* Register and set account model in QML. */
ctx->setContextProperty(accountModelPtr->objectName(), accountModelPtr);
engine.addImageProvider(IMAGE_PROVIDER_ID, GlobInstcs::imgProvPtr);
QString dirName(
......@@ -581,13 +588,14 @@ int main(int argc, char *argv[])
GlobalSettingsQmlWrapper::saveAllSettings(accountModelPtr);
}
delete accountModelPtr;
accountModelPtr = Q_NULLPTR;
delete accountModelPtr; accountModelPtr = Q_NULLPTR;
/* Destroy globally accessible objects. */
{
GlobInstcs::imgProvPtr = Q_NULLPTR; /* Is owned by engine. */
delete GlobInstcs::acntMapPtr; GlobInstcs::acntMapPtr = Q_NULLPTR;
delete GlobInstcs::recMgmtDbPtr; GlobInstcs::recMgmtDbPtr = Q_NULLPTR;
GlobInstcs::zfoDbPtr = Q_NULLPTR;
GlobInstcs::fileDbsPtr = Q_NULLPTR;
......
......@@ -77,7 +77,8 @@ void Messages::fillContactList(const QVariant &dbModelVariant,
qDebug("%s()", __func__);
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR))) {
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
......@@ -92,7 +93,7 @@ void Messages::fillContactList(const QVariant &dbModelVariant,
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
return;
......@@ -108,7 +109,8 @@ void Messages::fillMessageList(const QVariant &msgModelVariant,
qDebug("%s()", __func__);
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR))) {
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
......@@ -123,7 +125,7 @@ void Messages::fillMessageList(const QVariant &msgModelVariant,
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
return;
......@@ -141,7 +143,8 @@ QString Messages::getMessageDetail(const QString &userName,
qDebug("%s()", __func__);
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR))) {
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return QString();
}
......@@ -154,7 +157,7 @@ QString Messages::getMessageDetail(const QString &userName,
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
return QString();
......@@ -168,14 +171,15 @@ MsgEnvelope *Messages::getMsgEnvelopeDataAndSetRecipient(
qDebug("%s()", __func__);
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR))) {
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return Q_NULLPTR;
}
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
return Q_NULLPTR;
......@@ -218,14 +222,15 @@ void Messages::markMessageAsLocallyRead(const QVariant &msgModelVariant,
qDebug("%s()", __func__);
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR))) {
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
return;
......@@ -247,14 +252,15 @@ void Messages::markMessagesAsLocallyRead(const QVariant &msgModelVariant,
qDebug("%s()", __func__);
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR))) {
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
return;
......@@ -293,7 +299,8 @@ void Messages::deleteMessageFromDbs(const QVariant &acntModelVariant,
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
(GlobInstcs::fileDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
......@@ -311,13 +318,13 @@ void Messages::deleteMessageFromDbs(const QVariant &acntModelVariant,
return;
}
if (!AccountListModel::globAccounts.contains(userName)) {
if (!GlobInstcs::acntMapPtr->contains(userName)) {
return;
}
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
return;
......@@ -325,7 +332,7 @@ void Messages::deleteMessageFromDbs(const QVariant &acntModelVariant,
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical("Cannot open file database for %s.",
userName.toUtf8().constData());
......@@ -413,18 +420,19 @@ void Messages::deleteExpiredMessagesFromDbs(int days)
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
(GlobInstcs::fileDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
QList<qint64> msgIDList;
QStringList userNameList = AccountListModel::globAccounts.keys();
QStringList userNameList(GlobInstcs::acntMapPtr->keys());
foreach (const QString &userName, userNameList) {
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("Cannot open message database for %s.",
userName.toUtf8().constData());
......@@ -438,7 +446,7 @@ void Messages::deleteExpiredMessagesFromDbs(int days)
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical("Cannot open file database for %s.",
userName.toUtf8().constData());
......@@ -486,16 +494,17 @@ int Messages::getAllDbSize(void)
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
(GlobInstcs::fileDbsPtr == Q_NULLPTR) ||
(GlobInstcs::acntMapPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return -1;
}
QStringList userNameList(AccountListModel::globAccounts.keys());
QStringList userNameList(GlobInstcs::acntMapPtr->keys());
foreach (const QString &userName, userNameList) {
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("Cannot open message database for user name '%s'.",
userName.toUtf8().constData());
......@@ -505,7 +514,7 @@ int Messages::getAllDbSize(void)
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
(*GlobInstcs::acntMapPtr)[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical("Cannot open file database for user name '%s'.",
userName.toUtf8().constData());
......@@ -519,8 +528,13 @@ int Messages::getAllDbSize(void)
int Messages::estimateAllDbSize(void)
{
if (Q_UNLIKELY(GlobInstcs::acntMapPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return -1;
}
/* 1 MB free disk space is required for new database */
return 2 * AccountListModel::globAccounts.size() * 1000000;
return 2 * GlobInstcs::acntMapPtr->size() * 1000000;
}
bool Messages::relocateDatabases(const QString &newLocationDir,
......@@ -528,7 +542,8 @@ bool Messages::relocateDatabases(const QString &newLocationDir,
{
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {