AusweisApp2/src/file_provider/FileProvider.cpp

55 lines
1.0 KiB
C++
Raw Normal View History

2017-12-20 14:54:05 +01:00
/*!
2018-03-28 15:10:51 +02:00
* \copyright Copyright (c) 2017-2018 Governikus GmbH & Co. KG, Germany
2017-12-20 14:54:05 +01:00
*/
#include "FileProvider.h"
#include "SingletonHelper.h"
#include <QLoggingCategory>
2018-03-28 15:10:51 +02:00
#include <QMutexLocker>
2017-12-20 14:54:05 +01:00
using namespace governikus;
Q_DECLARE_LOGGING_CATEGORY(fileprovider)
defineSingleton(FileProvider)
FileProvider::FileProvider()
: mUpdatableFiles()
2018-03-28 15:10:51 +02:00
, mGetFileMutex()
2017-12-20 14:54:05 +01:00
{
}
FileProvider& FileProvider::getInstance()
{
return *Instance;
}
const QSharedPointer<UpdatableFile> FileProvider::getFile(const QString& pSection, const QString& pName, const QString& pDefaultPath)
{
2018-03-28 15:10:51 +02:00
const QMutexLocker locker(&mGetFileMutex);
2017-12-20 14:54:05 +01:00
const QString key = pSection + QLatin1Char('/') + pName;
const QSharedPointer<UpdatableFile> existingF = mUpdatableFiles.value(key, QSharedPointer<UpdatableFile>());
if (existingF.isNull())
{
const QSharedPointer<UpdatableFile> newF(new UpdatableFile(pSection, pName, pDefaultPath));
if (!pName.isEmpty())
{
mUpdatableFiles.insert(key, newF);
}
return newF;
}
else
{
existingF->setDefaultPath(pDefaultPath);
return existingF;
}
}