Port away from KStandardDirs

This commit is contained in:
Sebastian Kügler 2013-10-05 04:22:00 +02:00
parent 60b3b801ce
commit b0b984ac62

View File

@ -22,19 +22,19 @@
#include <QApplication> #include <QApplication>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QDir> #include <QDir>
#include <QDirIterator>
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QScriptValueIterator> #include <QScriptValueIterator>
#include <QStandardPaths> #include <QStandardPaths>
#include <QDebug> #include <QDebug>
#include <KGlobal> #include <kglobal.h>
#include <KLocalizedString> #include <klocalizedstring.h>
#include <KMimeTypeTrader> #include <kmimetypetrader.h>
#include <KServiceTypeTrader> #include <kservicetypetrader.h>
#include <KShell> #include <kshell.h>
#include <KStandardDirs> #include <kcomponentdata.h>
#include <KComponentData>
// KIO // KIO
//#include <kemailsettings.h> // no camelcase include //#include <kemailsettings.h> // no camelcase include
@ -513,25 +513,29 @@ QScriptValue ScriptEngine::userDataPath(QScriptContext *context, QScriptEngine *
return QDir::homePath(); return QDir::homePath();
} }
if (context->argumentCount() > 1) { QStandardPaths::StandardLocation location = QStandardPaths::GenericDataLocation;
const QString filename = context->argument(1).toString();
return KStandardDirs::locateLocal(type.toLatin1(), filename);
}
QStringList locations;
if (type.compare("desktop", Qt::CaseInsensitive) == 0) { if (type.compare("desktop", Qt::CaseInsensitive) == 0) {
locations = QStandardPaths::standardLocations(QStandardPaths::DesktopLocation); location = QStandardPaths::DesktopLocation;
} else if (type.compare("documents", Qt::CaseInsensitive) == 0) { } else if (type.compare("documents", Qt::CaseInsensitive) == 0) {
locations = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation); location = QStandardPaths::DocumentsLocation;
} else if (type.compare("music", Qt::CaseInsensitive) == 0) { } else if (type.compare("music", Qt::CaseInsensitive) == 0) {
locations = QStandardPaths::standardLocations(QStandardPaths::MusicLocation); location = QStandardPaths::MusicLocation;
} else if (type.compare("video", Qt::CaseInsensitive) == 0) { } else if (type.compare("video", Qt::CaseInsensitive) == 0) {
locations = QStandardPaths::standardLocations(QStandardPaths::MoviesLocation); location = QStandardPaths::MoviesLocation;
} else if (type.compare("downloads", Qt::CaseInsensitive) == 0) { } else if (type.compare("downloads", Qt::CaseInsensitive) == 0) {
locations = QStandardPaths::standardLocations(QStandardPaths::DownloadLocation); location = QStandardPaths::DownloadLocation;
} else if (type.compare("pictures", Qt::CaseInsensitive) == 0) { } else if (type.compare("pictures", Qt::CaseInsensitive) == 0) {
locations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); location = QStandardPaths::PicturesLocation;
} else if (type.compare("config", Qt::CaseInsensitive) == 0) {
location = QStandardPaths::ConfigLocation;
} }
if (context->argumentCount() > 1) {
QString loc = QStandardPaths::writableLocation(location);
loc.append(QDir::separator());
loc.append(context->argument(1).toString());
return loc;
}
const QStringList &locations = QStandardPaths::standardLocations(location);
return locations.count() ? locations.first() : QString(); return locations.count() ? locations.first() : QString();
} }
@ -683,7 +687,15 @@ void ScriptEngine::exception(const QScriptValue &value)
QStringList ScriptEngine::pendingUpdateScripts(Plasma::Corona *corona) QStringList ScriptEngine::pendingUpdateScripts(Plasma::Corona *corona)
{ {
const QString appName = corona->package().metadata().pluginName(); const QString appName = corona->package().metadata().pluginName();
QStringList scripts = KGlobal::dirs()->findAllResources("data", appName + "/updates/*.js"); QStringList scripts;
const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, appName + QStringLiteral("/kpartplugins"), QStandardPaths::LocateDirectory);
Q_FOREACH(const QString& dir, dirs) {
QDirIterator it(dir, QStringList() << QStringLiteral("*.js"));
while (it.hasNext()) {
scripts.append(it.next());
}
}
QStringList scriptPaths; QStringList scriptPaths;
if (scripts.isEmpty()) { if (scripts.isEmpty()) {