Commit df37e1db authored by Boudewijn Rempt's avatar Boudewijn Rempt

Move KoResourcePaths to KoPlugin

parent e544ef88
......@@ -4,6 +4,7 @@ set(kritaplugin_LIB_SRCS
KoJsonTrader.cpp
KisMimeDatabase.cpp
KritaPluginDebug.cpp
KoResourcePaths.cpp
)
# help plugin trader find installed plugins when run from uninstalled tests
......
......@@ -25,11 +25,9 @@
#include <QDir>
#include <QFileInfo>
#include <QDebug>
#include <QApplication>
#include <QCoreApplication>
#include <QMutex>
#include "kis_debug.h"
#include "WidgetUtilsDebug.h"
;
Q_GLOBAL_STATIC(KoResourcePaths, s_instance);
static QString cleanup(const QString &path)
......@@ -89,16 +87,11 @@ QString getInstallationPrefix() {
#ifdef Q_OS_OSX
QString appPath = qApp->applicationDirPath();
debugWidgetUtils << "1" << appPath;
appPath.chop(QString("MacOS/").length());
debugWidgetUtils << "2" << appPath;
bool makeInstall = QDir(appPath + "/../../../share/kritaplugins").exists();
bool inBundle = QDir(appPath + "/Resources/kritaplugins").exists();
debugWidgetUtils << "3. After make install" << makeInstall;
debugWidgetUtils << "4. In Bundle" << inBundle;
QString bundlePath;
if (inBundle) {
......@@ -112,7 +105,6 @@ QString getInstallationPrefix() {
qFatal("Cannot calculate the bundle path from the app path");
}
debugWidgetUtils << ">>>>>>>>>>>" << bundlePath;
return bundlePath;
#else
#ifdef Q_OS_QWIN
......@@ -152,12 +144,10 @@ public:
r += relatives[type];
}
relativesMutex.unlock();
debugWidgetUtils << "\trelatives" << r;
absolutesMutex.lock();
if (absolutes.contains(type)) {
a += absolutes[type];
}
debugWidgetUtils << "\tabsolutes" << a;
absolutesMutex.unlock();
return r + a;
......@@ -275,7 +265,6 @@ void KoResourcePaths::addResourceTypeInternal(const QString &type, const QString
}
d->relativesMutex.unlock();
debugWidgetUtils << "addResourceType: type" << type << "basetype" << basetype << "relativename" << relativename << "priority" << priority << d->relatives[type];
}
void KoResourcePaths::addResourceDirInternal(const QString &type, const QString &absdir, bool priority)
......@@ -299,19 +288,16 @@ void KoResourcePaths::addResourceDirInternal(const QString &type, const QString
}
d->absolutesMutex.unlock();
debugWidgetUtils << "addResourceDir: type" << type << "absdir" << absdir << "priority" << priority << d->absolutes[type];
}
QString KoResourcePaths::findResourceInternal(const QString &type, const QString &fileName)
{
QStringList aliases = d->aliases(type);
debugWidgetUtils << "aliases" << aliases << getApplicationRoot();
QString resource = QStandardPaths::locate(QStandardPaths::AppDataLocation, fileName, QStandardPaths::LocateFile);
if (resource.isEmpty()) {
Q_FOREACH (const QString &alias, aliases) {
resource = QStandardPaths::locate(d->mapTypeToQStandardPaths(type), alias + '/' + fileName, QStandardPaths::LocateFile);
debugWidgetUtils << "\t1" << resource;
if (QFile::exists(resource)) {
continue;
}
......@@ -321,8 +307,6 @@ QString KoResourcePaths::findResourceInternal(const QString &type, const QString
QString approot = getApplicationRoot();
Q_FOREACH (const QString &alias, aliases) {
resource = approot + "/share/" + alias + '/' + fileName;
debugWidgetUtils << "\t1" << resource;
if (QFile::exists(resource)) {
continue;
}
......@@ -332,14 +316,12 @@ QString KoResourcePaths::findResourceInternal(const QString &type, const QString
QString approot = getApplicationRoot();
Q_FOREACH (const QString &alias, aliases) {
resource = approot + "/share/krita/" + alias + '/' + fileName;
debugWidgetUtils << "\t1" << resource;
if (QFile::exists(resource)) {
continue;
}
}
}
debugWidgetUtils << "findResource: type" << type << "filename" << fileName << "resource" << resource;
Q_ASSERT(!resource.isEmpty());
return resource;
}
......@@ -347,7 +329,6 @@ QString KoResourcePaths::findResourceInternal(const QString &type, const QString
QStringList KoResourcePaths::findDirsInternal(const QString &type)
{
QStringList aliases = d->aliases(type);
debugWidgetUtils << type << aliases << d->mapTypeToQStandardPaths(type);
QStringList dirs;
QStringList standardDirs =
......@@ -360,11 +341,9 @@ QStringList KoResourcePaths::findDirsInternal(const QString &type)
appendResources(&dirs, aliasDirs, true);
#ifdef Q_OS_OSX
debugWidgetUtils << "MAC:" << getApplicationRoot();
QStringList bundlePaths;
bundlePaths << getApplicationRoot() + "/share/krita/" + alias;
bundlePaths << getApplicationRoot() + "/../share/krita/" + alias;
debugWidgetUtils << "bundlePaths" << bundlePaths;
appendResources(&dirs, bundlePaths, true);
Q_ASSERT(!dirs.isEmpty());
#endif
......@@ -375,21 +354,18 @@ QStringList KoResourcePaths::findDirsInternal(const QString &type)
appendResources(&dirs, fallbackPaths, true);
}
debugWidgetUtils << "findDirs: type" << type << "resource" << dirs;
return dirs;
}
QStringList filesInDir(const QString &startdir, const QString & filter, bool recursive)
{
debugWidgetUtils << "filesInDir: startdir" << startdir << "filter" << filter << "recursive" << recursive;
QStringList result;
// First the entries in this path
QStringList nameFilters;
nameFilters << filter;
const QStringList fileNames = QDir(startdir).entryList(nameFilters, QDir::Files | QDir::CaseSensitive, QDir::Name);
debugWidgetUtils << "\tFound:" << fileNames.size() << ":" << fileNames;
Q_FOREACH (const QString &fileName, fileNames) {
QString file = startdir + '/' + fileName;
result << file;
......@@ -399,7 +375,6 @@ QStringList filesInDir(const QString &startdir, const QString & filter, bool rec
if (recursive) {
const QStringList entries = QDir(startdir).entryList(QDir::Dirs | QDir::NoDotAndDotDot);
Q_FOREACH (const QString &subdir, entries) {
debugWidgetUtils << "\tGoing to look in subdir" << subdir << "of" << startdir;
result << filesInDir(startdir + '/' + subdir, filter, recursive);
}
}
......@@ -410,13 +385,8 @@ QStringList KoResourcePaths::findAllResourcesInternal(const QString &type,
const QString &_filter,
SearchOptions options) const
{
debugWidgetUtils << "=====================================================";
debugWidgetUtils << type << _filter << QStandardPaths::standardLocations(d->mapTypeToQStandardPaths(type));
bool recursive = options & KoResourcePaths::Recursive;
debugWidgetUtils << "findAllResources: type" << type << "filter" << _filter << "recursive" << recursive;
QStringList aliases = d->aliases(type);
QString filter = _filter;
......@@ -424,7 +394,6 @@ QStringList KoResourcePaths::findAllResourcesInternal(const QString &type,
if (filter.indexOf('*') > 0) {
aliases << filter.split('*').first();
filter = '*' + filter.split('*')[1];
debugWidgetUtils << "Split up alias" << aliases << "filter" << filter;
}
QStringList resources;
......@@ -435,10 +404,7 @@ QStringList KoResourcePaths::findAllResourcesInternal(const QString &type,
appendResources(&resources, standardResources, true);
}
debugWidgetUtils << "\tresources from qstandardpaths:" << resources.size();
Q_FOREACH (const QString &alias, aliases) {
debugWidgetUtils << "\t\talias:" << alias;
QStringList dirs;
QFileInfo dirInfo(alias);
......@@ -457,8 +423,6 @@ QStringList KoResourcePaths::findAllResourcesInternal(const QString &type,
}
}
debugWidgetUtils << "\tresources also from aliases:" << resources.size();
// if the original filter is "input/*", we only want share/input/* and share/krita/input/* here, but not
// share/*. therefore, use _filter here instead of filter which was split into alias and "*".
QFileInfo fi(_filter);
......@@ -468,9 +432,6 @@ QStringList KoResourcePaths::findAllResourcesInternal(const QString &type,
prefixResources << filesInDir(getInstallationPrefix() + "share/krita/" + fi.path(), fi.fileName(), false);
appendResources(&resources, prefixResources, true);
debugWidgetUtils << "\tresources from installation:" << resources.size();
debugWidgetUtils << "=====================================================";
return resources;
}
......@@ -492,8 +453,6 @@ QStringList KoResourcePaths::resourceDirsInternal(const QString &type)
appendResources(&resourceDirs, aliasDirs, true);
}
debugWidgetUtils << "resourceDirs: type" << type << resourceDirs;
return resourceDirs;
}
......@@ -519,8 +478,6 @@ QString KoResourcePaths::saveLocationInternal(const QString &type, const QString
if (!d.exists() && create) {
d.mkpath(path);
}
debugWidgetUtils << "saveLocation: type" << type << "suffix" << suffix << "create" << create << "path" << path;
return path;
}
......@@ -537,7 +494,6 @@ QString KoResourcePaths::locateInternal(const QString &type, const QString &file
locations << QStandardPaths::locate(d->mapTypeToQStandardPaths(type),
(alias.endsWith('/') ? alias : alias + '/') + filename, QStandardPaths::LocateFile);
}
debugWidgetUtils << "locate: type" << type << "filename" << filename << "locations" << locations;
if (locations.size() > 0) {
return locations.first();
}
......@@ -549,7 +505,6 @@ QString KoResourcePaths::locateInternal(const QString &type, const QString &file
QString KoResourcePaths::locateLocalInternal(const QString &type, const QString &filename, bool createDir)
{
QString path = saveLocationInternal(type, "", createDir);
debugWidgetUtils << "locateLocal: type" << type << "filename" << filename << "CreateDir" << createDir << "path" << path;
return path + '/' + filename;
}
......
......@@ -22,7 +22,7 @@
#include <QString>
#include <QStringList>
#include <kritawidgetutils_export.h>
#include <kritaplugin_export.h>
/**
......@@ -39,8 +39,7 @@
* checks. In the future these should be converted to qloggingcategory to enable
* convenient enable/disable functionality.
*/
class KRITAWIDGETUTILS_EXPORT KoResourcePaths
class KRITAPLUGIN_EXPORT KoResourcePaths
{
public:
......
......@@ -21,7 +21,6 @@ set(kritawidgetutils_LIB_SRCS
KoUpdaterPrivate_p.cpp
KoProperties.cpp
KoFileDialog.cpp
KoResourcePaths.cpp
kis_num_parser.cpp
kis_spin_box_unit_manager.cpp
......
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