Commit 55db3189 authored by Karel Slaný's avatar Karel Slaný

Global worker pool and settings objects are created inside main().

parent 9af1fa7d
......@@ -114,6 +114,7 @@ SOURCES += \
src/dialogues/widget_input_dialogue.cpp \
src/dialogues/widget_message_dialogue.cpp \
src/files.cpp \
src/global.cpp \
src/io/filesystem.cpp \
src/isds/isds_conversion.cpp \
src/locker.cpp \
......@@ -150,8 +151,6 @@ SOURCES += \
src/sqlite/message_db_container.cpp \
src/sqlite/message_db.cpp \
src/sqlite/zfo_db.cpp \
src/worker/emitter.cpp \
src/worker/pool.cpp \
src/worker/task.cpp \
src/worker/task_change_password.cpp \
src/worker/task_download_account_info.cpp \
......@@ -198,6 +197,7 @@ HEADERS += \
src/dialogues/widget_input_dialogue.h \
src/dialogues/widget_message_dialogue.h \
src/files.h \
src/global.h \
src/io/db_tables.h \
src/io/filesystem.h \
src/isds/isds_conversion.h \
......
......@@ -26,6 +26,7 @@
#include "src/accounts.h"
#include "src/dialogues/dialogues.h"
#include "src/global.h"
#include "src/models/accountmodel.h"
#include "src/net/isds_session.h"
#include "src/settings.h"
......@@ -67,6 +68,11 @@ void Accounts::updateNewMessageCounter(const QVariant &acntModelVariant,
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
AccountListModel *accountModel =
AccountListModel::fromVariant(acntModelVariant);
if (accountModel == Q_NULLPTR) {
......@@ -76,7 +82,7 @@ void Accounts::updateNewMessageCounter(const QVariant &acntModelVariant,
}
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
......@@ -161,6 +167,11 @@ bool Accounts::updateAccount(const QVariant &acntModelVariant,
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return false;
}
AccountListModel *accountModel =
AccountListModel::fromVariant(acntModelVariant);
if (accountModel == Q_NULLPTR) {
......@@ -194,12 +205,14 @@ bool Accounts::updateAccount(const QVariant &acntModelVariant,
/* Reopen database if storeToDisk changed. */
if (acntData.storeToDisk() != storeToDisk) {
MessageDb *mDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName, oldStoreToDisk);
GlobalInstances::setPtr->dbsLocation, userName,
oldStoreToDisk);
if (mDb != Q_NULLPTR) {
QString mDbFileName(mDb->fileName());
/* Reopen database. */
globMessageDbsPtr->deleteDb(mDb);
globMessageDbsPtr->accessMessageDb(globSet.dbsLocation,
globMessageDbsPtr->accessMessageDb(
GlobalInstances::setPtr->dbsLocation,
userName, storeToDisk);
if (oldStoreToDisk) {
/* Delete databases from storage. */
......@@ -207,12 +220,14 @@ bool Accounts::updateAccount(const QVariant &acntModelVariant,
}
}
FileDb *fDb = globFileDbsPtr->accessFileDb(
globSet.dbsLocation, userName, oldStoreToDisk);
GlobalInstances::setPtr->dbsLocation, userName,
oldStoreToDisk);
if (fDb != Q_NULLPTR) {
QString fDbFileName(fDb->fileName());
/* Reopen database. */
globFileDbsPtr->deleteDb(fDb);
globFileDbsPtr->accessFileDb(globSet.dbsLocation,
globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation,
userName, storeToDisk);
if (oldStoreToDisk) {
/* Delete databases from storage. */
......@@ -241,6 +256,11 @@ bool Accounts::removeAccount(const QVariant &acntModelVariant,
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return false;
}
AccountListModel *accountModel =
AccountListModel::fromVariant(acntModelVariant);
if (accountModel == Q_NULLPTR) {
......@@ -265,8 +285,9 @@ bool Accounts::removeAccount(const QVariant &acntModelVariant,
}
/* Delete file database */
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical("%s", "Cannot open file database.");
return false;
......@@ -278,7 +299,7 @@ bool Accounts::removeAccount(const QVariant &acntModelVariant,
/* Delete message database */
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
......@@ -314,6 +335,11 @@ void Accounts::loadModelCounters(AccountListModel *accountModel)
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
if (accountModel == Q_NULLPTR) {
Q_ASSERT(0);
qCritical("%s", "Cannot access account model.");
......@@ -329,7 +355,7 @@ void Accounts::loadModelCounters(AccountListModel *accountModel)
}
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qWarning("Cannot open message database for '%s'.",
......
......@@ -33,6 +33,7 @@
#include "src/crypto/crypto.h"
#include "src/dialogues/dialogues.h"
#include "src/files.h"
#include "src/global.h"
#include "src/io/filesystem.h"
#include "src/models/accountmodel.h"
#include "src/net/xml_layer.h"
......@@ -69,11 +70,16 @@ void Files::deleteExpiredFilesFromDbs(int days)
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
QStringList msgIDList;
QStringList userNameList = AccountListModel::globAccounts.keys();
foreach (const QString &userName, userNameList) {
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName,
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!"
......@@ -85,9 +91,8 @@ void Files::deleteExpiredFilesFromDbs(int days)
continue;
}
MessageDb *msgDb =
globMessageDbsPtr->accessMessageDb(globSet.dbsLocation,
userName,
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "ERROR: Message database cannot open!";
......@@ -117,8 +122,14 @@ QByteArray Files::getFileRawContentFromDb(const QString &userName, int fileId)
{
qDebug("%s()", __func__);
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return QByteArray();
}
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "Cannot open file database!";
......@@ -134,8 +145,14 @@ void Files::openAttachmentFromDb(const QString &userName, int fileId)
{
qDebug("%s()", __func__);
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "Cannot open file database!";
......@@ -216,6 +233,11 @@ void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
if (userName.isEmpty() || msgId <= 0) {
return;
}
......@@ -224,8 +246,9 @@ void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
QString subject;
QStringList fileList;
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "ERROR: Message database cannot open!";
return;
......@@ -235,8 +258,9 @@ void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
return;
}
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!";
return;
......@@ -276,6 +300,11 @@ void Files::deleteFileDb(const QString &userName)
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
int msgResponse = Dialogues::message(Dialogues::QUESTION,
tr("Delete files: %1").arg(userName),
tr("Do you want to clean up the file database of account '%1'?").arg(userName),
......@@ -285,8 +314,9 @@ void Files::deleteFileDb(const QString &userName)
return;
}
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database open error!";
return;
......@@ -296,8 +326,8 @@ void Files::deleteFileDb(const QString &userName)
return;
}
MessageDb *msgDb =
globMessageDbsPtr->accessMessageDb(globSet.dbsLocation, userName,
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "ERROR: Message database cannot open!";
......@@ -313,12 +343,17 @@ void Files::vacuumFileDbs(void)
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
emit statusBarTextChanged(tr("Vacuum databases"), true);
QStringList userNameList = AccountListModel::globAccounts.keys();
foreach (const QString &userName, userNameList) {
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName,
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!"
......@@ -335,17 +370,22 @@ bool Files::deleteAttachmentsFromDb(const QString &userName, qint64 msgId)
{
qDebug("%s()", __func__);
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return false;
}
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!" << userName;
return false;
}
if (fDb->deleteFilesFromDb(msgId)) {
MessageDb *msgDb =
globMessageDbsPtr->accessMessageDb(globSet.dbsLocation,
userName,
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "ERROR: Message database cannot open!";
......@@ -425,8 +465,14 @@ bool Files::setAttachmentModel(FileListModel &attachModel,
{
qDebug("%s()", __func__);
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return false;
}
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "Cannot open file database!";
......@@ -491,6 +537,11 @@ void Files::saveAttachmentsToDiskDb(const QString &userName,
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
/* User name must be supplied. */
if (userName.isEmpty()) {
Q_ASSERT(0);
......@@ -504,8 +555,9 @@ void Files::saveAttachmentsToDiskDb(const QString &userName,
return;
}
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "Cannot open file database!";
......
......@@ -23,6 +23,7 @@
#include <QEvent>
#include "src/global.h"
#include "src/locker.h"
#include "src/settings.h"
......@@ -95,8 +96,13 @@ void Locker::processNewState(Qt::ApplicationState state)
void Locker::inactivityTimeOut(void)
{
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
/* Inactivity timer timed out and PIN value is set and recovered. */
if (!globSet._pinVal.isEmpty()) {
if (!GlobalInstances::setPtr->_pinVal.isEmpty()) {
emit lockApp();
}
}
......
......@@ -38,6 +38,7 @@
#include "src/dialogues/qml_input_dialogue.h"
#include "src/dialogues/dialogues.h"
#include "src/files.h"
#include "src/global.h"
#include "src/io/filesystem.h"
#include "src/locker.h"
#include "src/log/log.h"
......@@ -66,6 +67,7 @@
#include "src/sqlite/file_db_container.h"
#include "src/sqlite/message_db_container.h"
#include "src/sqlite/zfo_db.h"
#include "src/worker/emitter.h"
#include "src/worker/pool.h"
#include "src/zfo.h"
......@@ -254,6 +256,34 @@ int main(int argc, char *argv[])
/* Process command-line arguments. */
parser.process(app);
/* Create globally accessible objects. */
{
GlobalInstances::msgProcEmitterPtr =
new (std::nothrow) MessageProcessingEmitter;
if (GlobalInstances::msgProcEmitterPtr == Q_NULLPTR) {
qCritical("Cannot create status message emitter.");
return EXIT_FAILURE;
}
/*
* Only one worker thread currently.
* TODO -- To be able to run multiple threads in the pool
* a locking mechanism over isds context structures must
* be implemented. Also, per-context queueing
* ought to be implemented to avoid unnecessary waiting.
*/
GlobalInstances::workPoolPtr = new (std::nothrow) WorkerPool(1);
if (GlobalInstances::workPoolPtr == Q_NULLPTR) {
qCritical("Cannot create worker pool.");
return EXIT_FAILURE;
}
GlobalInstances::setPtr = new (std::nothrow) Settings;
if (GlobalInstances::setPtr == Q_NULLPTR) {
qCritical("cannot create settings.");
return EXIT_FAILURE;
}
}
QStringList cmdLineFileNames;
#if defined(Q_OS_ANDROID)
cmdLineFileNames = IntentNotification::getIntentArguments();
......@@ -265,20 +295,21 @@ int main(int argc, char *argv[])
{
QSettings settings(Settings::settingsPath(),
QSettings::IniFormat);
globSet.loadFromSettings(settings);
GlobalInstances::setPtr->loadFromSettings(settings);
}
/* set font family and font size from settings */
QFont font;
font.setFamily(DEFAULT_FONT_FAMILY);
font.setPointSize(globSet.fontSize);
font.setPointSize(GlobalInstances::setPtr->fontSize);
app.setFont(font);
/* load datovka localization and qtbase localization */
QTranslator datovkaTrans;
QTranslator qtbaseTrans;
QString lang(Localisation::shortLangName(globSet.language));
Localisation::setProgramLocale(globSet.language);
QString lang(
Localisation::shortLangName(GlobalInstances::setPtr->language));
Localisation::setProgramLocale(GlobalInstances::setPtr->language);
if (!datovkaTrans.load("datovka_" + lang, ":/locale/")) {
qDebug() << "Could not load datovka localisation file...";
}
......@@ -289,7 +320,7 @@ int main(int argc, char *argv[])
app.installTranslator(&qtbaseTrans);
/* Start worker threads. */
globWorkPool.start();
GlobalInstances::workPoolPtr->start();
logInfoNL("%s", "Worker pool started.");
/* Init and use these class - we need register it to QML */
......@@ -446,9 +477,10 @@ int main(int argc, char *argv[])
/*
* Open ZFO database, the second parameter means: true = zfo db will
* store in disk, false = only in memory
* store on disk, false = only in memory
*/
if (!globZfoDbPtr->openDb(ZFO_DB_NAME, (globSet.zfoDbSizeMBs > 0))) {
if (!globZfoDbPtr->openDb(
ZFO_DB_NAME, (GlobalInstances::setPtr->zfoDbSizeMBs > 0))) {
qDebug() << "ERROR: zfo db not found!";
}
......@@ -458,10 +490,11 @@ int main(int argc, char *argv[])
/* OpenSSL support test */
if (QSslSocket::supportsSsl()) {
/* set last update text to status bar */
if (!globSet.lastUpdateStr().isEmpty() && globSet.pinCode.isEmpty()) {
if (!GlobalInstances::setPtr->lastUpdateStr().isEmpty() &&
GlobalInstances::setPtr->pinCode.isEmpty()) {
emit isds.statusBarTextChanged(
QObject::tr("Last synchronisation: %1").
arg(globSet.lastUpdateStr()), false, true);
arg(GlobalInstances::setPtr->lastUpdateStr()), false, true);
}
} else {
Dialogues::errorMessage(Dialogues::WARNING,
......@@ -472,18 +505,21 @@ int main(int argc, char *argv[])
}
/* Deletion of messages from db is disabled when equal to 0. */
if (globSet.msgLifeTimeInDays > 0) {
messages.deleteExpiredMessagesFromDbs(globSet.msgLifeTimeInDays);
if (GlobalInstances::setPtr->msgLifeTimeInDays > 0) {
messages.deleteExpiredMessagesFromDbs(
GlobalInstances::setPtr->msgLifeTimeInDays);
}
/* Deletion of files from db is disabled when equal to 0. */
if (globSet.fileLifeTimeInDays > 0) {
files.deleteExpiredFilesFromDbs(globSet.fileLifeTimeInDays);
if (GlobalInstances::setPtr->fileLifeTimeInDays > 0) {
files.deleteExpiredFilesFromDbs(
GlobalInstances::setPtr->fileLifeTimeInDays);
}
/* Inactivity locking is disabled when equal to 0. */
if (globSet.pinInactTimeoutInSecs > 0) {
locker.setInactivityInterval(globSet.pinInactTimeoutInSecs);
if (GlobalInstances::setPtr->pinInactTimeoutInSecs > 0) {
locker.setInactivityInterval(
GlobalInstances::setPtr->pinInactTimeoutInSecs);
}
/* Load counters. */
......@@ -493,7 +529,7 @@ int main(int argc, char *argv[])
* Show PIN screen if needed. Encoded PIN is checked because it hasn't
* been decoded yet.
*/
if (!globSet.pinCode.isEmpty()) {
if (!GlobalInstances::setPtr->pinCode.isEmpty()) {
emit locker.lockApp();
}
......@@ -518,8 +554,8 @@ int main(int argc, char *argv[])
/* Wait until all threads finished. */
logInfoNL("%s", "Waiting for pending worker threads.");
globWorkPool.wait();
globWorkPool.stop();
GlobalInstances::workPoolPtr->wait();
GlobalInstances::workPoolPtr->stop();
logInfoNL("%s", "All worker threads finished");
/* Close all OTP connections if exist */
......@@ -529,7 +565,8 @@ int main(int argc, char *argv[])
* Store the configuration only when PIN has been recovered or is not
* used.
*/
if (!globSet._pinVal.isEmpty() || !globSet.pinConfigured()) {
if (!GlobalInstances::setPtr->_pinVal.isEmpty() ||
!GlobalInstances::setPtr->pinConfigured()) {
/*
* The PIN was set/recovered or
* incomplete data to check/recover the PIN were supplied.
......@@ -540,5 +577,13 @@ int main(int argc, char *argv[])
delete accountModelPtr;
accountModelPtr = Q_NULLPTR;
/* Destroy globally accessible objects. */
{
delete GlobalInstances::setPtr; GlobalInstances::setPtr = Q_NULLPTR;
delete GlobalInstances::workPoolPtr; GlobalInstances::workPoolPtr = Q_NULLPTR;
delete GlobalInstances::msgProcEmitterPtr; GlobalInstances::msgProcEmitterPtr = Q_NULLPTR;
}
return ret;
}
......@@ -28,6 +28,7 @@
#include <QStorageInfo>
#include "src/dialogues/dialogues.h"
#include "src/global.h"
#include "src/messages.h"
#include "src/models/accountmodel.h"
#include "src/models/databoxmodel.h"
......@@ -75,6 +76,11 @@ void Messages::fillContactList(const QVariant &dbModelVariant,
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
DataboxListModel *databoxModel =
DataboxListModel::fromVariant(dbModelVariant);
if (databoxModel == Q_NULLPTR) {
......@@ -84,7 +90,7 @@ void Messages::fillContactList(const QVariant &dbModelVariant,
}
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
......@@ -100,6 +106,11 @@ void Messages::fillMessageList(const QVariant &msgModelVariant,
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
MessageListModel *messageModel =
MessageListModel::fromVariant(msgModelVariant);
if (messageModel == Q_NULLPTR) {
......@@ -109,7 +120,7 @@ void Messages::fillMessageList(const QVariant &msgModelVariant,
}
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
......@@ -127,6 +138,11 @@ QString Messages::getMessageDetail(const QString &userName,
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return QString();
}
bool ok = false;
qint64 msgId = msgIdStr.toLongLong(&ok);
if (!ok || (msgId < 0)) {
......@@ -134,7 +150,7 @@ QString Messages::getMessageDetail(const QString &userName,
}
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
......@@ -148,8 +164,13 @@ MsgEnvelope *Messages::getMsgEnvelopeDataAndSetRecipient(
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return Q_NULLPTR;
}
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
......@@ -192,8 +213,13 @@ void Messages::markMessageAsLocallyRead(const QVariant &msgModelVariant,
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
......@@ -215,8 +241,13 @@ void Messages::markMessagesAsLocallyRead(const QVariant &msgModelVariant,
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
......@@ -254,6 +285,11 @@ void Messages::deleteMessageFromDbs(const QVariant &acntModelVariant,
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
if (userName.isEmpty()) {
return;
}
......@@ -272,15 +308,16 @@ void Messages::deleteMessageFromDbs(const QVariant &acntModelVariant,
}
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
return;
}
FileDb *fDb = globFileDbsPtr->accessFileDb(globSet.dbsLocation,
userName, AccountListModel::globAccounts[userName].storeToDisk());
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical("Cannot open file database for %s.",
userName.toUtf8().constData());
......@@ -366,12 +403,17 @@ void Messages::deleteExpiredMessagesFromDbs(int days)
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
QList<qint64> msgIDList;
QStringList userNameList = AccountListModel::globAccounts.keys();
foreach (const QString &userName, userNameList) {
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
globSet.dbsLocation, userName,
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("Cannot open message database for %s.",
......@@ -385,7 +427,7 @@ void Messages::deleteExpiredMessagesFromDbs(int days)
}
FileDb *fDb = globFileDbsPtr->accessFileDb(
globSet.dbsLocation, userName,
GlobalInstances::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical("Cannot open file database for %s.",
......@@ -432,10 +474,15 @@ int Messages::getAllDbSize(void)
{
int size = 0;
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR