Commit 4a5f2102 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Make singleton of KisResourceLocator

parent 521c2751
......@@ -32,7 +32,7 @@ class KRITARESOURCES_EXPORT KisResourceLoaderRegistry : public QObject, public K
public:
~KisResourceLoaderRegistry() override;
static KisResourceLoaderRegistry* instance();
static KisResourceLoaderRegistry *instance();
private:
......
......@@ -19,6 +19,7 @@
#include "KisResourceLocator.h"
#include <QApplication>
#include <QDebug>
#include <QList>
#include <QDir>
......@@ -60,11 +61,21 @@ public:
QStringList errorMessages;
};
KisResourceLocator::KisResourceLocator()
: d(new Private())
KisResourceLocator::KisResourceLocator(QObject *parent)
: QObject(parent)
, d(new Private())
{
}
KisResourceLocator *KisResourceLocator::instance()
{
KisResourceLocator *locator = qApp->findChild<KisResourceLocator *>(QString());
if (!locator) {
locator = new KisResourceLocator(qApp);
}
return locator;
}
KisResourceLocator::~KisResourceLocator()
{
}
......
......@@ -20,6 +20,7 @@
#ifndef KISRESOURCELOCATOR_H
#define KISRESOURCELOCATOR_H
#include <QObject>
#include <QScopedPointer>
#include <QStringList>
#include <QString>
......@@ -31,14 +32,16 @@
* The KisResourceLocator class is used to find resources of
* a certain type.
*/
class KRITARESOURCES_EXPORT KisResourceLocator
class KRITARESOURCES_EXPORT KisResourceLocator : public QObject
{
Q_OBJECT
public:
static const QString resourceLocationKey;
static const QStringList resourceTypeFolders;
KisResourceLocator();
static KisResourceLocator *instance();
~KisResourceLocator();
enum class LocatorError {
......@@ -61,6 +64,10 @@ public:
private:
KisResourceLocator(QObject *parent);
KisResourceLocator(const KisResourceLocator&);
KisResourceLocator operator=(const KisResourceLocator&);
enum class InitalizationStatus {
Unknown, // We don't know whether Krita has run on this system for this resource location yet
Initialized, // Everything is ready to start synchronizing the database
......
......@@ -27,9 +27,10 @@
#include <kconfiggroup.h>
#include <ksharedconfig.h>
#include <KisResourceLocator.h>
#include <KritaVersionWrapper.h>
#include <KisResourceLocator.h>
#ifndef FILES_DATA_DIR
#error "FILES_DATA_DIR not set. A directory with the data used for testing installing resources"
#endif
......@@ -40,6 +41,7 @@
void TestResourceLocator::initTestCase()
{
m_locator = KisResourceLocator::instance();
m_srcLocation = QString(FILES_DATA_DIR);
QVERIFY2(QDir(m_srcLocation).exists(), m_srcLocation.toUtf8());
m_dstLocation = QString(FILES_DEST_DIR);
......@@ -50,8 +52,8 @@ void TestResourceLocator::initTestCase()
void TestResourceLocator::testLocatorInitalization()
{
KisResourceLocator::LocatorError r = m_locator.initialize(m_srcLocation);
if (!m_locator.errorMessages().isEmpty()) qDebug() << m_locator.errorMessages();
KisResourceLocator::LocatorError r = m_locator->initialize(m_srcLocation);
if (!m_locator->errorMessages().isEmpty()) qDebug() << m_locator->errorMessages();
QVERIFY(r == KisResourceLocator::LocatorError::Ok);
QVERIFY(QDir(m_dstLocation).exists());
Q_FOREACH(const QString &folder, KisResourceLocator::resourceTypeFolders) {
......@@ -71,7 +73,7 @@ void TestResourceLocator::testLocatorInitalization()
void TestResourceLocator::testLocatorSynchronization()
{
QVERIFY(m_locator.synchronizeDb());
QVERIFY(m_locator->synchronizeDb());
}
void TestResourceLocator::cleanupTestCase()
......
......@@ -22,7 +22,8 @@
#include <QObject>
#include <KisResourceLocator.h>
class KisResourceLocator;
class TestResourceLocator : public QObject
{
......@@ -39,7 +40,7 @@ private:
QString m_srcLocation;
QString m_dstLocation;
KisResourceLocator m_locator;
KisResourceLocator *m_locator;
};
......
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