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

Moved global database pointers into GlobInstcs.

parent 22976f7e
......@@ -40,12 +40,22 @@ Accounts::Accounts(QObject *parent)
QString Accounts::boxId(const QString &userName)
{
return globAccountDbPtr->dbId(userName);
if (GlobInstcs::accountDbPtr != Q_NULLPTR) {
return GlobInstcs::accountDbPtr->dbId(userName);
} else {
Q_ASSERT(0);
return QString();
}
}
bool Accounts::boxEffectiveOVM(const QString &userName)
{
return globAccountDbPtr->boxEffectiveOVM(userName);
if (GlobInstcs::accountDbPtr != Q_NULLPTR) {
return GlobInstcs::accountDbPtr->boxEffectiveOVM(userName);
} else {
Q_ASSERT(0);
return false;
}
}
void Accounts::updateAccountCounters(const QVariant &acntModelVariant)
......@@ -68,7 +78,8 @@ void Accounts::updateNewMessageCounter(const QVariant &acntModelVariant,
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
......@@ -81,8 +92,8 @@ void Accounts::updateNewMessageCounter(const QVariant &acntModelVariant,
return;
}
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
GlobalInstances::setPtr->dbsLocation, userName,
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
......@@ -98,7 +109,12 @@ QString Accounts::fillAccountInfo(const QString &userName)
{
qDebug("%s()", __func__);
return globAccountDbPtr->getAccountDetail(userName);
if (GlobInstcs::accountDbPtr != Q_NULLPTR) {
return GlobInstcs::accountDbPtr->getAccountDetail(userName);
} else {
Q_ASSERT(0);
return QString();
}
}
void Accounts::getAccountData(const QString &userName)
......@@ -167,7 +183,9 @@ bool Accounts::updateAccount(const QVariant &acntModelVariant,
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return false;
}
......@@ -204,30 +222,28 @@ bool Accounts::updateAccount(const QVariant &acntModelVariant,
bool oldStoreToDisk = acntData.storeToDisk();
/* Reopen database if storeToDisk changed. */
if (acntData.storeToDisk() != storeToDisk) {
MessageDb *mDb = globMessageDbsPtr->accessMessageDb(
GlobalInstances::setPtr->dbsLocation, userName,
oldStoreToDisk);
MessageDb *mDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName, oldStoreToDisk);
if (mDb != Q_NULLPTR) {
QString mDbFileName(mDb->fileName());
/* Reopen database. */
globMessageDbsPtr->deleteDb(mDb);
globMessageDbsPtr->accessMessageDb(
GlobalInstances::setPtr->dbsLocation,
GlobInstcs::messageDbsPtr->deleteDb(mDb);
GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation,
userName, storeToDisk);
if (oldStoreToDisk) {
/* Delete databases from storage. */
QFile::remove(mDbFileName);
}
}
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
oldStoreToDisk);
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName, oldStoreToDisk);
if (fDb != Q_NULLPTR) {
QString fDbFileName(fDb->fileName());
/* Reopen database. */
globFileDbsPtr->deleteDb(fDb);
globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation,
GlobInstcs::fileDbsPtr->deleteDb(fDb);
GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation,
userName, storeToDisk);
if (oldStoreToDisk) {
/* Delete databases from storage. */
......@@ -256,7 +272,10 @@ bool Accounts::removeAccount(const QVariant &acntModelVariant,
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::accountDbPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return false;
}
......@@ -285,39 +304,39 @@ bool Accounts::removeAccount(const QVariant &acntModelVariant,
}
/* Delete file database */
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical("%s", "Cannot open file database.");
return false;
}
if (!globFileDbsPtr->deleteDb(fDb)) {
if (!GlobInstcs::fileDbsPtr->deleteDb(fDb)) {
qCritical("%s", "Could not delete file database.");
return false;
}
/* Delete message database */
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
GlobalInstances::setPtr->dbsLocation, userName,
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical("%s", "Cannot open message database.");
return false;
}
if (!globMessageDbsPtr->deleteDb(msgDb)) {
if (!GlobInstcs::messageDbsPtr->deleteDb(msgDb)) {
qCritical("%s", "Could not delete message database.");
return false;
}
/* Delete account info from account database */
if (!globAccountDbPtr->deleteAccountInfoFromDb(userName)) {
if (!GlobInstcs::accountDbPtr->deleteAccountInfoFromDb(userName)) {
qCritical("%s", "Could not delete account info.");
return false;
}
/* Delete user info from account database */
if (!globAccountDbPtr->deleteUserInfoFromDb(userName)) {
if (!GlobInstcs::accountDbPtr->deleteUserInfoFromDb(userName)) {
qCritical("%s", "Could not delete user info.");
return false;
}
......@@ -335,7 +354,8 @@ void Accounts::loadModelCounters(AccountListModel *accountModel)
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
......@@ -354,8 +374,8 @@ void Accounts::loadModelCounters(AccountListModel *accountModel)
continue;
}
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
GlobalInstances::setPtr->dbsLocation, userName,
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qWarning("Cannot open message database for '%s'.",
......
......@@ -287,5 +287,3 @@ QList<class SQLiteTbl *> RecordsManagementDb::listOfTables(void) const
tables.append(&strdFlsMsgsTbl);
return tables;
}
RecordsManagementDb *globRecordsManagementDbPtr = Q_NULLPTR;
......@@ -135,8 +135,3 @@ protected:
virtual
QList<class SQLiteTbl *> listOfTables(void) const Q_DECL_OVERRIDE;
};
/*!
* @brief Global records management database.
*/
extern RecordsManagementDb *globRecordsManagementDbPtr;
/*
* Copyright (C) 2014-2017 CZ.NIC
* Copyright (C) 2014-2018 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -70,7 +70,9 @@ void Files::deleteExpiredFilesFromDbs(int days)
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
......@@ -78,8 +80,8 @@ void Files::deleteExpiredFilesFromDbs(int days)
QStringList msgIDList;
QStringList userNameList = AccountListModel::globAccounts.keys();
foreach (const QString &userName, userNameList) {
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!"
......@@ -91,8 +93,8 @@ void Files::deleteExpiredFilesFromDbs(int days)
continue;
}
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
GlobalInstances::setPtr->dbsLocation, userName,
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "ERROR: Message database cannot open!";
......@@ -122,13 +124,14 @@ QByteArray Files::getFileRawContentFromDb(const QString &userName, int fileId)
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return QByteArray();
}
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
......@@ -145,13 +148,14 @@ void Files::openAttachmentFromDb(const QString &userName, int fileId)
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
......@@ -166,7 +170,6 @@ void Files::openAttachmentFromDb(const QString &userName, int fileId)
void Files::openAttachment(const QString &fileName, const QByteArray &base64Data)
{
Q_ASSERT(!fileName.isEmpty());
Q_ASSERT(!base64Data.isEmpty());
......@@ -233,7 +236,9 @@ void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
......@@ -246,8 +251,8 @@ void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
QString subject;
QStringList fileList;
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
GlobalInstances::setPtr->dbsLocation, userName,
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "ERROR: Message database cannot open!";
......@@ -258,8 +263,8 @@ void Files::sendAttachmentsWithEmail(const QString &userName, qint64 msgId)
return;
}
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!";
......@@ -300,7 +305,9 @@ void Files::deleteFileDb(const QString &userName)
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
......@@ -314,20 +321,20 @@ void Files::deleteFileDb(const QString &userName)
return;
}
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database open error!";
return;
}
if (!globFileDbsPtr->deleteDb(fDb)) {
if (!GlobInstcs::fileDbsPtr->deleteDb(fDb)) {
qCritical() << "ERROR: File database could not delete!";
return;
}
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
GlobalInstances::setPtr->dbsLocation, userName,
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "ERROR: Message database cannot open!";
......@@ -343,7 +350,8 @@ void Files::vacuumFileDbs(void)
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
......@@ -352,8 +360,8 @@ void Files::vacuumFileDbs(void)
QStringList userNameList = AccountListModel::globAccounts.keys();
foreach (const QString &userName, userNameList) {
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!"
......@@ -370,13 +378,15 @@ bool Files::deleteAttachmentsFromDb(const QString &userName, qint64 msgId)
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::messageDbsPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return false;
}
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
qCritical() << "ERROR: File database cannot open!" << userName;
......@@ -384,8 +394,8 @@ bool Files::deleteAttachmentsFromDb(const QString &userName, qint64 msgId)
}
if (fDb->deleteFilesFromDb(msgId)) {
MessageDb *msgDb = globMessageDbsPtr->accessMessageDb(
GlobalInstances::setPtr->dbsLocation, userName,
MessageDb *msgDb = GlobInstcs::messageDbsPtr->accessMessageDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (msgDb == Q_NULLPTR) {
qCritical() << "ERROR: Message database cannot open!";
......@@ -465,13 +475,14 @@ bool Files::setAttachmentModel(FileListModel &attachModel,
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return false;
}
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
......@@ -537,7 +548,8 @@ void Files::saveAttachmentsToDiskDb(const QString &userName,
{
qDebug("%s()", __func__);
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
if (Q_UNLIKELY((GlobInstcs::setPtr == Q_NULLPTR) ||
(GlobInstcs::fileDbsPtr == Q_NULLPTR))) {
Q_ASSERT(0);
return;
}
......@@ -555,8 +567,8 @@ void Files::saveAttachmentsToDiskDb(const QString &userName,
return;
}
FileDb *fDb = globFileDbsPtr->accessFileDb(
GlobalInstances::setPtr->dbsLocation, userName,
FileDb *fDb = GlobInstcs::fileDbsPtr->accessFileDb(
GlobInstcs::setPtr->dbsLocation, userName,
AccountListModel::globAccounts[userName].storeToDisk());
if (fDb == Q_NULLPTR) {
......
......@@ -25,7 +25,13 @@
#include "src/global.h"
class MessageProcessingEmitter *GlobalInstances::msgProcEmitterPtr = Q_NULLPTR;
class WorkerPool *GlobalInstances::workPoolPtr = Q_NULLPTR;
class MessageProcessingEmitter *GlobInstcs::msgProcEmitterPtr = Q_NULLPTR;
class WorkerPool *GlobInstcs::workPoolPtr = Q_NULLPTR;
class Settings *GlobalInstances::setPtr = Q_NULLPTR;
class Settings *GlobInstcs::setPtr = Q_NULLPTR;
class AccountDb *GlobInstcs::accountDbPtr = Q_NULLPTR;
class MsgDbContainer *GlobInstcs::messageDbsPtr = Q_NULLPTR;
class FileDbContainer *GlobInstcs::fileDbsPtr = Q_NULLPTR;
class ZfoDb *GlobInstcs::zfoDbPtr = Q_NULLPTR;
class RecordsManagementDb *GlobInstcs::recMgmtDbPtr = Q_NULLPTR;
......@@ -26,7 +26,7 @@
/*!
* @brief The class holds pointers to all globally accessible structures.
*/
class GlobalInstances {
class GlobInstcs {
public:
static
......@@ -37,9 +37,20 @@ public:
static
class Settings *setPtr; /*!< Settings. */
static
class AccountDb *accountDbPtr; /*!< Account database. */
static
class MsgDbContainer *messageDbsPtr; /*!< Message database container. */
static
class FileDbContainer *fileDbsPtr; /*!< File database container. */
static
class ZfoDb *zfoDbPtr; /*!< ZFO files database. */
static
class RecordsManagementDb *recMgmtDbPtr; /*!< Records management database. */
private:
/*!
* @brief Private constructor.
*/
GlobalInstances(void);
GlobInstcs(void);
};
/*
* Copyright (C) 2014-2017 CZ.NIC
* Copyright (C) 2014-2018 CZ.NIC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -96,13 +96,13 @@ void Locker::processNewState(Qt::ApplicationState state)
void Locker::inactivityTimeOut(void)
{
if (Q_UNLIKELY(GlobalInstances::setPtr == Q_NULLPTR)) {
if (Q_UNLIKELY(GlobInstcs::setPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
/* Inactivity timer timed out and PIN value is set and recovered. */
if (!GlobalInstances::setPtr->_pinVal.isEmpty()) {
if (!GlobInstcs::setPtr->_pinVal.isEmpty()) {
emit lockApp();
}
}
......
......@@ -258,9 +258,9 @@ int main(int argc, char *argv[])
/* Create globally accessible objects. */
{
GlobalInstances::msgProcEmitterPtr =
GlobInstcs::msgProcEmitterPtr =
new (std::nothrow) MessageProcessingEmitter;
if (GlobalInstances::msgProcEmitterPtr == Q_NULLPTR) {
if (GlobInstcs::msgProcEmitterPtr == Q_NULLPTR) {
qCritical("Cannot create status message emitter.");
return EXIT_FAILURE;
}
......@@ -271,14 +271,14 @@ int main(int argc, char *argv[])
* 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) {
GlobInstcs::workPoolPtr = new (std::nothrow) WorkerPool(1);
if (GlobInstcs::workPoolPtr == Q_NULLPTR) {
qCritical("Cannot create worker pool.");
return EXIT_FAILURE;
}
GlobalInstances::setPtr = new (std::nothrow) Settings;
if (GlobalInstances::setPtr == Q_NULLPTR) {
GlobInstcs::setPtr = new (std::nothrow) Settings;
if (GlobInstcs::setPtr == Q_NULLPTR) {
qCritical("cannot create settings.");
return EXIT_FAILURE;
}
......@@ -295,21 +295,21 @@ int main(int argc, char *argv[])
{
QSettings settings(Settings::settingsPath(),
QSettings::IniFormat);
GlobalInstances::setPtr->loadFromSettings(settings);
GlobInstcs::setPtr->loadFromSettings(settings);
}
/* set font family and font size from settings */
QFont font;
font.setFamily(DEFAULT_FONT_FAMILY);
font.setPointSize(GlobalInstances::setPtr->fontSize);
font.setPointSize(GlobInstcs::setPtr->fontSize);
app.setFont(font);
/* load datovka localization and qtbase localization */
QTranslator datovkaTrans;
QTranslator qtbaseTrans;
QString lang(
Localisation::shortLangName(GlobalInstances::setPtr->language));
Localisation::setProgramLocale(GlobalInstances::setPtr->language);
Localisation::shortLangName(GlobInstcs::setPtr->language));
Localisation::setProgramLocale(GlobInstcs::setPtr->language);
if (!datovkaTrans.load("datovka_" + lang, ":/locale/")) {
qDebug() << "Could not load datovka localisation file...";
}
......@@ -320,7 +320,7 @@ int main(int argc, char *argv[])
app.installTranslator(&qtbaseTrans);
/* Start worker threads. */
GlobalInstances::workPoolPtr->start();
GlobInstcs::workPoolPtr->start();
logInfoNL("%s", "Worker pool started.");
/* Init and use these class - we need register it to QML */
......@@ -417,9 +417,25 @@ int main(int argc, char *argv[])
evntsTbl.reloadLocalisedDescription();
msgZfoTbl.reloadLocalisedDescription();
/* init and open account database */
AccountDb globAccountDb("ACCOUNTS", false);
globAccountDbPtr = &globAccountDb;
/* Init and open account database. */
AccountDb accountDb("ACCOUNTS", false);
MsgDbContainer messageDbs("MESSAGES");
FileDbContainer fileDbs("FILES");
ZfoDb zfoDb("ZFOS", false);
{
GlobInstcs::accountDbPtr = &accountDb;
GlobInstcs::messageDbsPtr = &messageDbs;
GlobInstcs::fileDbsPtr = &fileDbs;
GlobInstcs::zfoDbPtr = &zfoDb;
GlobInstcs::recMgmtDbPtr = new (std::nothrow)
RecordsManagementDb("recordsManagementDb", false);
if (GlobInstcs::recMgmtDbPtr == Q_NULLPTR) {
logErrorNL("%s",
"Cannot allocate records management db.");
return EXIT_FAILURE;
}
}
QString dirName(
existingWritableLocation(QStandardPaths::AppDataLocation));
......@@ -431,33 +447,15 @@ int main(int argc, char *argv[])
}
QString dbPath(dirName + QDir::separator() + ACNT_DB_NAME);
if (!globAccountDbPtr->openDb(dbPath, SQLiteDb::CREATE_MISSING)) {
if (!GlobInstcs::accountDbPtr->openDb(dbPath,
SQLiteDb::CREATE_MISSING)) {
logErrorNL("%s", "Account database not found!");
return EXIT_FAILURE;
}
/* init message db container */
MsgDbContainer globMessageDb("MESSAGES");
globMessageDbsPtr = &globMessageDb;
/* init file db container */
FileDbContainer globFileDb("FILES");
globFileDbsPtr = &globFileDb;
/* init zfo db database */
ZfoDb globZfoDb("ZFOS", false);
globZfoDbPtr = &globZfoDb;
/* init and open records management database */
globRecordsManagementDbPtr = new (std::nothrow)
RecordsManagementDb("recordsManagementDb", false);
if (Q_NULLPTR == globRecordsManagementDbPtr) {
logErrorNL("%s", "Cannot allocate records management db.");
return EXIT_FAILURE;
}
/* Open records management database. */
QString rmDbPath(dirName + QDir::separator() + RECORDS_MANAGEMENT_DB_FILE);
if (!globRecordsManagementDbPtr->openDb(
if (!GlobInstcs::recMgmtDbPtr->openDb(
rmDbPath, SQLiteDb::CREATE_MISSING)) {
logErrorNL("Error opening records management db '%s'.",
rmDbPath.toUtf8().constData());
......@@ -479,8 +477,8 @@ int main(int argc, char *argv[])
* Open ZFO database, the second parameter means: true = zfo db will
* store on disk, false = only in memory
*/
if (!globZfoDbPtr->openDb(
ZFO_DB_NAME, (GlobalInstances::setPtr->zfoDbSizeMBs > 0))) {
if (!GlobInstcs::zfoDbPtr->openDb(
ZFO_DB_NAME, (GlobInstcs::setPtr->zfoDbSizeMBs > 0))) {
qDebug() << "ERROR: zfo db not found!";
}
......@@ -490,11 +488,11 @@ int main(int argc, char *argv[])
/* OpenSSL support test */
if (QSslSocket::supportsSsl()) {
/* set last update text to status bar */
if (!GlobalInstances::setPtr->lastUpdateStr().isEmpty() &&
GlobalInstances::setPtr->pinCode.isEmpty()) {
if (!GlobInstcs::setPtr->lastUpdateStr().isEmpty() &&
GlobInstcs::setPtr->pinCode.isEmpty()) {
emit isds.statusBarTextChanged(
QObject::tr("Last synchronisation: %1").
arg(GlobalInstances::setPtr->lastUpdateStr()), false, true);
arg(GlobInstcs::setPtr->lastUpdateStr()), false, true);
}
} else {
Dialogues::errorMessage(Dialogues::WARNING,
......@@ -505,21 +503,21 @@ int main(int argc, char *argv[])
}
/* Deletion of messages from db is disabled when equal to 0. */
if (GlobalInstances::setPtr->msgLifeTimeInDays > 0) {
if (GlobInstcs::setPtr->msgLifeTimeInDays > 0) {
messages.deleteExpiredMessagesFromDbs(
GlobalInstances::setPtr->msgLifeTimeInDays);
GlobInstcs::setPtr->msgLifeTimeInDays);
}
/* Deletion of files from db is disabled when equal to 0. */
if (GlobalInstances::setPtr->fileLifeTimeInDays > 0) {
if (GlobInstcs::setPtr->fileLifeTimeInDays > 0) {
files.deleteExpiredFilesFromDbs(
GlobalInstances::setPtr->fileLifeTimeInDays);
GlobInstcs::setPtr->fileLifeTimeInDays);
}
/* Inactivity locking is disabled when equal to 0. */
if (GlobalInstances::setPtr->pinInactTimeoutInSecs > 0) {
if (GlobInstcs::setPtr->pinInactTimeoutInSecs > 0) {
locker.setInactivityInterval(
GlobalInstances::setPtr->pinInactTimeoutInSecs);
GlobInstcs::setPtr->pinInactTimeoutInSecs);
}
/* Load counters. */
......@@ -529,7 +527,7 @@ int main(int argc, char *argv[])
* Show PIN screen if needed. Encoded PIN is checked because it hasn't
* been decoded yet.
*/
if (!GlobalInstances::setPtr->pinCode.isEmpty()) {
if (!GlobInstcs::setPtr->pinCode.isEmpty()) {
emit locker.lockApp();
}
......@@ -554,8 +552,8 @@ int main(int argc, char *argv[])
/* Wait until all threads finished. */
logInfoNL("%s", "Waiting for pending worker threads.");
GlobalInstances::workPoolPtr->wait();
GlobalInstances::workPoolPtr->stop();
GlobInstcs::workPoolPtr->wait();
GlobInstcs::workPoolPtr->stop();
logInfoNL("%s", "All worker threads finished");
/* Close all OTP connections if exist */
......@@ -565,8 +563,8 @@ int main(int argc, char *argv[])
* Store the configuration only when PIN has been recovered or is not
* used.
*/
if (!GlobalInstances::setPtr->_pinVal.isEmpty() ||
!GlobalInstances::setPtr->pinConfigured()) {
if (!GlobInstcs::setPtr->_pinVal.isEmpty() ||
!GlobInstcs::setPtr->pinConfigured()) {
/*
* The PIN was set/recovered or
* incomplete data to check/recover the PIN were supplied.
......@@ -579,10 +577,16 @@ int main(int argc, char *argv[])
/* Destroy globally accessible objects. */
{
delete GlobalInstances::setPtr; GlobalInstances::setPtr = Q_NULLPTR;
delete GlobInstcs::recMgmtDbPtr; GlobInstcs::recMgmtDbPtr = Q_NULLPTR;
GlobInstcs::zfoDbPtr = Q_NULLPTR;
GlobInstcs::fileDbsPtr = Q_NULLPTR;
GlobInstcs::messageDbsPtr = Q_NULLPTR;
GlobInstcs::accountDbPtr = Q_NULLPTR;