Commit 37af7495 authored by Karel Slaný's avatar Karel Slaný

Replaced global globRecordsManagementSet.

parent ca960ebe
......@@ -40,8 +40,6 @@ namespace RMNames {
const QLatin1String tokenCode("access_token_code");
}
RecordsManagementSettings globRecordsManagementSet;
RecordsManagementSettings::RecordsManagementSettings(void)
: m_url(),
m_token(),
......
......@@ -159,8 +159,3 @@ private:
QByteArray m_tokenIv; /*!< Initialisation vector data. */
QByteArray m_tokenCode; /*!< Encrypted token. */
};
/*!
* @brief Global instance of the structure.
*/
extern RecordsManagementSettings globRecordsManagementSet;
......@@ -29,6 +29,7 @@ class MessageProcessingEmitter *GlobInstcs::msgProcEmitterPtr = Q_NULLPTR;
class WorkerPool *GlobInstcs::workPoolPtr = Q_NULLPTR;
class Settings *GlobInstcs::setPtr = Q_NULLPTR;
class RecordsManagementSettings *GlobInstcs::recMgmtSetPtr = Q_NULLPTR;
class AccountDb *GlobInstcs::accountDbPtr = Q_NULLPTR;
class MsgDbContainer *GlobInstcs::messageDbsPtr = Q_NULLPTR;
......
......@@ -36,6 +36,8 @@ public:
static
class Settings *setPtr; /*!< Settings. */
static
class RecordsManagementSettings *recMgmtSetPtr; /*!< Records management settings. */
static
class AccountDb *accountDbPtr; /*!< Account database. */
......
......@@ -34,6 +34,7 @@
#include "src/accounts.h"
#include "src/datovka_shared/io/records_management_db.h"
#include "src/datovka_shared/localisation/localisation.h"
#include "src/datovka_shared/settings/records_management.h"
#include "src/dialogues/qml_dialogue_helper.h"
#include "src/dialogues/qml_input_dialogue.h"
#include "src/dialogues/dialogues.h"
......@@ -279,7 +280,14 @@ int main(int argc, char *argv[])
GlobInstcs::setPtr = new (std::nothrow) Settings;
if (GlobInstcs::setPtr == Q_NULLPTR) {
qCritical("cannot create settings.");
qCritical("Cannot create settings.");
return EXIT_FAILURE;
}
GlobInstcs::recMgmtSetPtr =
new (std::nothrow) RecordsManagementSettings;
if (GlobInstcs::recMgmtSetPtr == Q_NULLPTR) {
qCritical("Cannot create records management settings.");
return EXIT_FAILURE;
}
}
......@@ -583,6 +591,7 @@ int main(int argc, char *argv[])
GlobInstcs::messageDbsPtr = Q_NULLPTR;
GlobInstcs::accountDbPtr = Q_NULLPTR;
delete GlobInstcs::recMgmtSetPtr; GlobInstcs::recMgmtSetPtr = Q_NULLPTR;
delete GlobInstcs::setPtr; GlobInstcs::setPtr = Q_NULLPTR;
delete GlobInstcs::workPoolPtr; GlobInstcs::workPoolPtr = Q_NULLPTR;
......
......@@ -144,10 +144,15 @@ bool RecordsManagement::callServiceInfo(const QString &urlStr,
void RecordsManagement::callUploadHierarchy(
const QVariant &hirerachyModelVariant)
{
if (Q_UNLIKELY(GlobInstcs::recMgmtSetPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
QByteArray response;
if (globRecordsManagementSet.url().isEmpty() ||
globRecordsManagementSet.token().isEmpty()) {
if (GlobInstcs::recMgmtSetPtr->url().isEmpty() ||
GlobInstcs::recMgmtSetPtr->token().isEmpty()) {
return;
}
......@@ -164,8 +169,8 @@ void RecordsManagement::callUploadHierarchy(
/* Clear model. */
hierarchyModel->setHierarchy(UploadHierarchyResp());
m_rmc.setConnection(globRecordsManagementSet.url(),
globRecordsManagementSet.token());
m_rmc.setConnection(GlobInstcs::recMgmtSetPtr->url(),
GlobInstcs::recMgmtSetPtr->token());
if (m_rmc.communicate(RecordsManagementConnection::SRVC_UPLOAD_HIERARCHY,
QByteArray(), response)) {
......@@ -251,7 +256,12 @@ void RecordsManagement::getStoredMsgInfoFromRecordsManagement(
bool RecordsManagement::isValidRecordsManagement(void)
{
return globRecordsManagementSet.isValid();
if (GlobInstcs::recMgmtSetPtr != Q_NULLPTR) {
return GlobInstcs::recMgmtSetPtr->isValid();
} else {
Q_ASSERT(0);
return false;
}
}
void RecordsManagement::loadStoredServiceInfo(void)
......@@ -365,13 +375,18 @@ bool RecordsManagement::uploadFile(qint64 dmId, const QString &msgFileName,
{
QByteArray response;
if (Q_UNLIKELY(GlobInstcs::recMgmtSetPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return false;
}
if (msgFileName.isEmpty() || msgData.isEmpty()) {
Q_ASSERT(0);
return false;
}
if (globRecordsManagementSet.url().isEmpty() ||
globRecordsManagementSet.token().isEmpty()) {
if (GlobInstcs::recMgmtSetPtr->url().isEmpty() ||
GlobInstcs::recMgmtSetPtr->token().isEmpty()) {
return false;
}
......@@ -383,8 +398,8 @@ bool RecordsManagement::uploadFile(qint64 dmId, const QString &msgFileName,
emit statusBarTextChanged(tr("Upload message"), true, true);
m_rmc.setConnection(globRecordsManagementSet.url(),
globRecordsManagementSet.token());
m_rmc.setConnection(GlobInstcs::recMgmtSetPtr->url(),
GlobInstcs::recMgmtSetPtr->token());
if (m_rmc.communicate(RecordsManagementConnection::SRVC_UPLOAD_FILE,
ufReq.toJson(), response)) {
......
......@@ -28,6 +28,7 @@
#include "src/datovka_shared/localisation/localisation.h"
#include "src/datovka_shared/settings/records_management.h"
#include "src/global.h"
#include "src/io/filesystem.h"
#include "src/log/log.h"
#include "src/settings.h"
......@@ -129,7 +130,9 @@ void Settings::saveToSettings(QSettings &settings) const
PinSettings::saveToSettings(settings);
/* Records management settings. */
globRecordsManagementSet.saveToSettings(_pinVal, settings);
if (GlobInstcs::recMgmtSetPtr != Q_NULLPTR) {
GlobInstcs::recMgmtSetPtr->saveToSettings(_pinVal, settings);
}
}
void Settings::loadFromSettings(const QSettings &settings)
......@@ -196,7 +199,9 @@ void Settings::loadFromSettings(const QSettings &settings)
}
/* Records management settings. */
globRecordsManagementSet.loadFromSettings(settings);
if (GlobInstcs::recMgmtSetPtr != Q_NULLPTR) {
GlobInstcs::recMgmtSetPtr->loadFromSettings(settings);
}
}
QString Settings::settingsPath(void)
......
......@@ -226,22 +226,42 @@ void GlobalSettingsQmlWrapper::updatePinSettings(const QString &pinValue)
QString GlobalSettingsQmlWrapper::rmUrl(void) const
{
return globRecordsManagementSet.url();
if (GlobInstcs::recMgmtSetPtr != Q_NULLPTR) {
return GlobInstcs::recMgmtSetPtr->url();
} else {
Q_ASSERT(0);
return QString();
}
}
void GlobalSettingsQmlWrapper::setRmUrl(const QString &rmUrl)
{
globRecordsManagementSet.setUrl(rmUrl);
if (Q_UNLIKELY(GlobInstcs::recMgmtSetPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
GlobInstcs::recMgmtSetPtr->setUrl(rmUrl);
}
QString GlobalSettingsQmlWrapper::rmToken(void) const
{
return globRecordsManagementSet.token();
if (GlobInstcs::recMgmtSetPtr != Q_NULLPTR) {
return GlobInstcs::recMgmtSetPtr->token();
} else {
Q_ASSERT(0);
return QString();
}
}
void GlobalSettingsQmlWrapper::setRmToken(const QString &rmToken)
{
globRecordsManagementSet.setToken(rmToken);
if (Q_UNLIKELY(GlobInstcs::recMgmtSetPtr == Q_NULLPTR)) {
Q_ASSERT(0);
return;
}
GlobInstcs::recMgmtSetPtr->setToken(rmToken);
}
void GlobalSettingsQmlWrapper::verifyPin(const QString &pinValue)
......@@ -261,8 +281,10 @@ void GlobalSettingsQmlWrapper::verifyPin(const QString &pinValue)
/* Decrypt all keys in account model. */
AccountListModel::decryptAllPwds(GlobInstcs::setPtr->_pinVal);
/* Decrypt records management token in global settings */
globRecordsManagementSet.decryptToken(
GlobInstcs::setPtr->_pinVal);
if (GlobInstcs::recMgmtSetPtr != Q_NULLPTR) {
GlobInstcs::recMgmtSetPtr->decryptToken(
GlobInstcs::setPtr->_pinVal);
}
}
emit sendPinReply(verResult);
......
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