Commit 83e3a298 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Turn the list of resource folders into a const list

parent 8599359b
......@@ -19,18 +19,101 @@
#include "KisResourceLocator.h"
#include <QList>
#include <QDir>
#include <QFileInfo>
#include <QMessageBox>
#include <kconfig.h>
#include <kconfiggroup.h>
#include <ksharedconfig.h>
#include <klocalizedstring.h>
#include "KisResourceStorage.h"
const QString KisResourceLocator::resourceLocationKey {"ResourceDirectory"};
const QStringList KisResourceLocator::resourceTypeFolders = QStringList()
<< "tags"
<< "asl"
<< "bundles"
<< "brushes"
<< "gradients"
<< "paintoppresets"
<< "palettes"
<< "patterns"
<< "taskset"
<< "workspaces"
<< "input"
<< "pykrita"
<< "symbols"
<< "color-schemes"
<< "preset_icons"
<< "preset_icons/tool_icons"
<< "preset_icons/emblem_icons";
class KisResourceLocator::Private {
public:
QString resourceLocation;
QList<KisResourceStorageSP> storages;
QStringList errorMessages;
};
KisResourceLocator::KisResourceLocator()
: d(new Private())
{
}
KisResourceLocator::~KisResourceLocator()
{
}
KisResourceLocator::LocatorError KisResourceLocator::initialize()
{
KConfigGroup cfg(KSharedConfig::openConfig(), "");
d->resourceLocation = cfg.readEntry(resourceLocationKey, QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
QFileInfo fi(d->resourceLocation);
if (!fi.exists()) {
if (!QDir().mkpath(d->resourceLocation)) {
d->errorMessages << i18n("Could not create the resource location at %1.", d->resourceLocation);
return LocatorError::CannotCreateLocation;
}
}
if (!fi.isWritable()) {
d->errorMessages << i18n("The resource location at %1 is not writable.", d->resourceLocation);
return LocatorError::LocationReadOnly;
}
if (QDir(d->resourceLocation).isEmpty()) {
KisResourceLocator::LocatorError res = firstTimeInstallation();
if (res != LocatorError::Ok) {
return res;
}
}
return LocatorError::Ok;
}
KisResourceLocator::LocatorError KisResourceLocator::firstTimeInstallation()
{
Q_FOREACH(const QString &folder, resourceTypeFolders) {
QFileInfo fi(d->resourceLocation + "/" + folder + "/");
QDir dir;
if (!fi.exists()) {
if (!dir.mkpath(fi.canonicalFilePath())) {
d->errorMessages << i18n("Could not create the resource location at %1.", fi.canonicalPath());
return LocatorError::CannotCreateLocation;
}
}
if (!fi.isWritable()) {
d->errorMessages << i18n("The resource location at %1 is not writable.", fi.canonicalPath());
return LocatorError::LocationReadOnly;
}
}
return LocatorError::Ok;
}
......@@ -21,6 +21,8 @@
#define KISRESOURCELOCATOR_H
#include <QScopedPointer>
#include <QStringList>
#include <QString>
#include <kritaresources_export.h>
......@@ -32,9 +34,27 @@
class KRITARESOURCES_EXPORT KisResourceLocator
{
public:
static const QString resourceLocationKey;
static const QStringList resourceTypeFolders;
KisResourceLocator();
~KisResourceLocator();
enum class LocatorError {
Ok,
LocationReadOnly,
CannotCreateLocation
};
LocatorError initialize();
QString lastErrorMessage() const;
private:
LocatorError firstTimeInstallation();
class Private;
QScopedPointer<Private> d;
};
......
......@@ -58,6 +58,7 @@
#include <KoResourcePaths.h>
#include <KisResourceCacheDb.h>
#include <KisResourceLocator.h>
#include "KisProofingConfiguration.h"
#include "KoColorConversionTransformation.h"
......@@ -217,7 +218,7 @@ GeneralTab::GeneralTab(QWidget *_parent, const char *_name)
m_urlResourceFolder->setMode(KoFileDialog::OpenDirectory);
m_urlResourceFolder->setConfigurationName("resource_directory");
m_urlResourceFolder->setFileName(cfg.readEntry<QString>("ResourceDirectory", QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)));
m_urlResourceFolder->setFileName(cfg.readEntry<QString>(KisResourceLocator::resourceLocationKey, QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)));
}
void GeneralTab::setDefault()
......@@ -265,7 +266,7 @@ void GeneralTab::setDefault()
cursorColorBtutton->setColor(cursorColor);
m_urlCacheDbLocation->setFileName(cfg.readEntry<QString>(KisResourceCacheDb::dbLocationKey, QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)));
m_urlResourceFolder->setFileName(cfg.readEntry<QString>("ResourceDirectory", QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)));
m_urlResourceFolder->setFileName(cfg.readEntry<QString>(KisResourceLocator::resourceLocationKey, QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)));
}
CursorStyle GeneralTab::cursorStyle()
......@@ -1333,7 +1334,7 @@ bool KisDlgPreferences::editPreferences()
cfg.setFavoritePresets(dialog->m_general->favoritePresets());
cfg.writeEntry(KisResourceCacheDb::dbLocationKey, dialog->m_general->m_urlCacheDbLocation->fileName());
cfg.writeEntry("ResourceDirectory", dialog->m_general->m_urlResourceFolder->fileName());
cfg.writeEntry(KisResourceLocator::resourceLocationKey, dialog->m_general->m_urlResourceFolder->fileName());
// Color settings
cfg.setUseSystemMonitorProfile(dialog->m_colorSettings->m_page->chkUseSystemMonitorProfile->isChecked());
......
......@@ -51,7 +51,7 @@
#include <kis_color_manager.h>
KisConfig::KisConfig()
: m_cfg( KSharedConfig::openConfig()->group(""))
: m_cfg(KSharedConfig::openConfig()->group(""))
{
}
......
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