Commit 3a1aa267 authored by Karel Slaný's avatar Karel Slaný

Moved global image provider pointer into GlobInstcs.

parent 37af7495
......@@ -36,3 +36,5 @@ class MsgDbContainer *GlobInstcs::messageDbsPtr = Q_NULLPTR;
class FileDbContainer *GlobInstcs::fileDbsPtr = Q_NULLPTR;
class ZfoDb *GlobInstcs::zfoDbPtr = Q_NULLPTR;
class RecordsManagementDb *GlobInstcs::recMgmtDbPtr = Q_NULLPTR;
class ImageProvider *GlobInstcs::imgProvPtr = Q_NULLPTR;
......@@ -50,6 +50,9 @@ public:
static
class RecordsManagementDb *recMgmtDbPtr; /*!< Records management database. */
static
class ImageProvider *imgProvPtr; /*!< Image provider. */
private:
/*!
* @brief Private constructor.
......
......@@ -364,13 +364,6 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine;
QQmlContext *ctx = engine.rootContext();
globImgProvPtr = new (std::nothrow) ImageProvider;
if (Q_NULLPTR == globImgProvPtr) {
qCritical("Cannot create image provider.");
return EXIT_FAILURE;
}
engine.addImageProvider(IMAGE_PROVIDER_ID, globImgProvPtr);
/* Register application pages to QML */
registerQmlTypes(uri, QML_PAGE_LOC, qmlPages);
registerQmlTypes(uri, QML_COMPONENT_LOC, qmlComponents);
......@@ -443,8 +436,16 @@ int main(int argc, char *argv[])
"Cannot allocate records management db.");
return EXIT_FAILURE;
}
GlobInstcs::imgProvPtr = new (std::nothrow) ImageProvider;
if (GlobInstcs::imgProvPtr == Q_NULLPTR) {
qCritical("Cannot create image provider.");
return EXIT_FAILURE;
}
}
engine.addImageProvider(IMAGE_PROVIDER_ID, GlobInstcs::imgProvPtr);
QString dirName(
existingWritableLocation(QStandardPaths::AppDataLocation));
if (dirName.isEmpty()) {
......@@ -585,6 +586,8 @@ int main(int argc, char *argv[])
/* Destroy globally accessible objects. */
{
GlobInstcs::imgProvPtr = Q_NULLPTR; /* Is owned by engine. */
delete GlobInstcs::recMgmtDbPtr; GlobInstcs::recMgmtDbPtr = Q_NULLPTR;
GlobInstcs::zfoDbPtr = Q_NULLPTR;
GlobInstcs::fileDbsPtr = Q_NULLPTR;
......
......@@ -85,5 +85,3 @@ bool ImageProvider::setSvg(const QString &id, const QByteArray &svgData)
}
return true;
}
ImageProvider *globImgProvPtr = Q_NULLPTR;
......@@ -73,8 +73,3 @@ public:
private:
QMap<QString, QByteArray> m_svgImgs; /*!< Map of images in SVG format. */
};
/*!
* @brief Globally accessible image provider.
*/
extern ImageProvider *globImgProvPtr;
......@@ -126,9 +126,9 @@ bool RecordsManagement::callServiceInfo(const QString &urlStr,
ServiceInfoResp siRes(
ServiceInfoResp::fromJson(response, &ok));
if (ok && siRes.isValid()) {
if (globImgProvPtr != Q_NULLPTR) {
globImgProvPtr->setSvg(RM_SVG_LOGO_ID,
siRes.logoSvg());
if (GlobInstcs::imgProvPtr != Q_NULLPTR) {
GlobInstcs::imgProvPtr->setSvg(
RM_SVG_LOGO_ID, siRes.logoSvg());
}
emit serviceInfo(siRes.name(), siRes.tokenName());
emit statusBarTextChanged(tr("Done"), false, true);
......@@ -276,8 +276,8 @@ void RecordsManagement::loadStoredServiceInfo(void)
return;
}
if (globImgProvPtr != Q_NULLPTR) {
globImgProvPtr->setSvg(RM_SVG_LOGO_ID, entry.logoSvg);
if (GlobInstcs::imgProvPtr != Q_NULLPTR) {
GlobInstcs::imgProvPtr->setSvg(RM_SVG_LOGO_ID, entry.logoSvg);
}
emit serviceInfo(entry.name, entry.tokenName);
}
......@@ -345,8 +345,8 @@ bool RecordsManagement::updateServiceInfo(const QString &newUrlStr,
entry.url = cUrlStr;
entry.name = srName;
entry.tokenName = srToken;
entry.logoSvg = (globImgProvPtr != Q_NULLPTR) ?
globImgProvPtr->svg(RM_SVG_LOGO_ID) : QByteArray();
entry.logoSvg = (GlobInstcs::imgProvPtr != Q_NULLPTR) ?
GlobInstcs::imgProvPtr->svg(RM_SVG_LOGO_ID) : QByteArray();
GlobInstcs::recMgmtDbPtr->updateServiceInfo(entry);
if (oldUrlStr != cUrlStr) {
return GlobInstcs::recMgmtDbPtr->deleteAllStoredMsg();
......
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