diff options
author | Jesper K. Pedersen <jesper.pedersen@kdab.com> | 2013-05-16 19:28:51 +0200 |
---|---|---|
committer | Jesper K. Pedersen <jesper.pedersen@kdab.com> | 2013-05-21 12:06:59 +0200 |
commit | 02723d30c87e72f68d863c015f16a3432d52a996 (patch) | |
tree | ba51e4932b07bb4282225ad667bbb1d4a685f8e8 | |
parent | 13ad623fdff541d028a74705ddf0a94f47092a56 (diff) |
implement a QDir prototype so it can be used from scripts
Change-Id: I990cbc42383c668345e65561e2eec3a135b16f60
Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com>
-rw-r--r-- | objects/enums.cpp | 115 | ||||
-rw-r--r-- | objects/enums.h | 48 | ||||
-rw-r--r-- | scripting.pro | 10 | ||||
-rw-r--r-- | tests/qdir/qdir.qs | 107 | ||||
-rw-r--r-- | tests/qdir/testcase/a | 1 | ||||
-rw-r--r-- | tests/qdir/testcase/b | 1 | ||||
-rw-r--r-- | tests/qdir/testcase/c | 1 | ||||
-rw-r--r-- | tests/qdir/testcase/x/abc.txt | 1 | ||||
-rw-r--r-- | tests/qdir/testcase/x/data | 1 | ||||
-rw-r--r-- | tests/qdir/testcase/x/def.txt | 1 | ||||
-rw-r--r-- | tests/qdir/testcase/x/hij.data | 1 | ||||
-rw-r--r-- | tests/qdir/testcase/x/klm.data | 1 | ||||
-rw-r--r-- | tests/qdir/testcase/y/foo | 1 | ||||
-rw-r--r-- | wrappers/enumwappers.cpp | 4 | ||||
-rw-r--r-- | wrappers/qdirprototype.cpp | 281 | ||||
-rw-r--r-- | wrappers/qdirprototype.h | 156 | ||||
-rw-r--r-- | wrappers/scriptwrappers.cpp | 2 |
17 files changed, 728 insertions, 4 deletions
diff --git a/objects/enums.cpp b/objects/enums.cpp new file mode 100644 index 0000000..17a3ac0 --- /dev/null +++ b/objects/enums.cpp @@ -0,0 +1,115 @@ +/************************************************************************** +** +** Copyright (C) 2013 Kläralvdalens Datakonsult AB, a KDAB Group company. +** Contact: Kläralvdalens Datakonsult AB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "enums.h" + +QDir::Filters Enums::convertFilters(int filters) +{ + QDir::Filters result; + if ( filters & Dirs ) + result |= QDir::Dirs; + + if ( filters & Files ) + result |= QDir::Files; + + if ( filters & Drives ) + result |= QDir::Drives; + + if ( filters & NoSymLinks ) + result |= QDir::NoSymLinks; + + if ( filters & Readable ) + result |= QDir::Readable; + + if ( filters & Writable ) + result |= QDir::Writable; + + if ( filters & Executable ) + result |= QDir::Executable; + + if ( filters & Modified ) + result |= QDir::Modified; + + if ( filters & Hidden ) + result |= QDir::Hidden; + + if ( filters & System ) + result |= QDir::System; + + if ( filters & AllDirs ) + result |= QDir::AllDirs; + + if ( filters & CaseSensitive ) + result |= QDir::CaseSensitive; + + if ( filters & NoDotAndDotDot ) + result |= QDir::NoDotAndDotDot; + + if ( filters & NoDot ) + result |= QDir::NoDot; + + if ( filters & NoDotDot ) + result |= QDir::NoDotDot; + + return result; +} + +QDir::SortFlags Enums::convertSortFlag(int sort) +{ + QDir::SortFlags result; + if ( sort & Name ) + result |= QDir::Name; + + if ( sort & Time ) + result |= QDir::Time; + + if ( sort & Size ) + result |= QDir::Size; + + if ( sort & DirsFirst ) + result |= QDir::DirsFirst; + + if ( sort & Reversed ) + result |= QDir::Reversed; + + if ( sort & IgnoreCase ) + result |= QDir::IgnoreCase; + + if ( sort & DirsLast ) + result |= QDir::DirsLast; + + if ( sort & LocaleAware ) + result |= QDir::LocaleAware; + + if ( sort & Type ) + result |= QDir::Type; + + return result; + +} diff --git a/objects/enums.h b/objects/enums.h index c6c19fa..431ada6 100644 --- a/objects/enums.h +++ b/objects/enums.h @@ -32,6 +32,7 @@ #include <QObject> #include <QMetaType> +#include <QDir> /** This class exports enums needed on the scripting side @@ -50,8 +51,53 @@ public: EndOfDoc = 5 }; Q_ENUMS(PositionOperation) + + enum Filter { + Dirs = QDir::Dirs, + Files = QDir::Files, + Drives = QDir::Drives, + NoSymLinks = QDir::NoSymLinks, + AllEntries = QDir::AllEntries, + TypeMask = QDir::TypeMask, + Readable = QDir::Readable, + Writable = QDir::Writable, + Executable = QDir::Executable, + PermissionMask = QDir::PermissionMask, + Modified = QDir::Modified, + Hidden = QDir::Hidden, + System = QDir::System, + AccessMask = QDir::AccessMask, + AllDirs = QDir::AllDirs, + CaseSensitive = QDir::CaseSensitive, + NoDotAndDotDot = QDir::NoDotAndDotDot, + NoDot = QDir::NoDot, + NoDotDot = QDir::NoDotDot, + NoFilter = QDir::NoFilter, + }; + Q_ENUMS(Filter) + + enum SortFlag { + Name = QDir::Name, + Time = QDir::Time, + Size = QDir::Size, + Unsorted = QDir::Unsorted, + SortByMask = QDir::SortByMask, + + DirsFirst = QDir::DirsFirst, + Reversed = QDir::Reversed, + IgnoreCase = QDir::IgnoreCase, + DirsLast = QDir::DirsLast, + LocaleAware = QDir::LocaleAware, + Type = QDir::Type, + NoSort = QDir::NoSort + }; + Q_ENUMS(SortFlag) + + static QDir::Filters convertFilters(int filters); + static QDir::SortFlags convertSortFlag(int sort); }; Q_DECLARE_METATYPE(Enums::PositionOperation) - +Q_DECLARE_METATYPE(Enums::Filter) +Q_DECLARE_METATYPE(Enums::SortFlag) #endif // ENUMS_H diff --git a/scripting.pro b/scripting.pro index ac779b4..964f012 100644 --- a/scripting.pro +++ b/scripting.pro @@ -25,7 +25,9 @@ SOURCES += scriptingplugin.cpp \ utils/position.cpp \ utils/utils.cpp \ objects/cppclass.cpp \ - wrappers/qfileinfoprototype.cpp + wrappers/qfileinfoprototype.cpp \ + wrappers/qdirprototype.cpp \ + objects/enums.cpp HEADERS += scriptingplugin.h \ scripting_global.h \ @@ -50,7 +52,8 @@ HEADERS += scriptingplugin.h \ utils/position.h \ utils/utils.h \ objects/cppclass.h \ - wrappers/qfileinfoprototype.h + wrappers/qfileinfoprototype.h \ + wrappers/qdirprototype.h # Qt Creator linking @@ -85,7 +88,8 @@ OTHER_FILES += \ tests/class/class.qs \ tests/class/test.h \ tests/qfileinfo/qfileinfo.qs \ - tests/qfileinfo/test.cpp + tests/qfileinfo/test.cpp \ + tests/qdir/qdir.qs diff --git a/tests/qdir/qdir.qs b/tests/qdir/qdir.qs new file mode 100644 index 0000000..f26de18 --- /dev/null +++ b/tests/qdir/qdir.qs @@ -0,0 +1,107 @@ +include("../test.js") +testBasic() +testDirOp() +testFilter() +testCd() +testStaticFunctions() + +function testBasic() { + var usrbin = new QDir("/usr/bin") + compare(usrbin.path,"/usr/bin") + compare(usrbin.absolutePath,"/usr/bin") + compare(usrbin.dirName,"bin") + + var scriptDir = new QDir(utils.currentScripRoot) + compare(scriptDir.count, 4) + compare(scriptDir.at(0), ".") + compare(scriptDir.at(1), "..") + compare(scriptDir.at(2), "qdir.qs") + compare(scriptDir.at(3), "testcase") + + compare(usrbin.isReadable, true) + compare(usrbin.exists(), true) + + var bogus = new QDir("/bogus") + compare(bogus.exists(), false) + + var root = new QDir("/") + compare(usrbin.isRoot, false) + compare(root.isRoot, true) + + var relative = new QDir("foo") + compare(relative.isRelative, true) + compare(usrbin.isRelative, false) +} + +function testDirOp() { + var scriptDir = new QDir(utils.currentScripRoot) + + compare(scriptDir.exists("NEWDIR"),false) + var ok = scriptDir.mkdir("NEWDIR") + assert(ok) + + compare(scriptDir.exists("NEWDIR"),true) + + ok = scriptDir.rename("NEWDIR", "NEWDIR2") + assert(ok) + + compare(scriptDir.exists("NEWDIR"),false) + compare(scriptDir.exists("NEWDIR2"),true) + + ok = scriptDir.rmdir("NEWDIR2") + assert(ok) + + compare(scriptDir.exists("NEWDIR2"),false) +} + +function testFilter() { + var testcase = new QDir(utils.currentScripRoot + "/testcase" ) + var files = testcase.entryList() + compare(files.length, 5) + + var files = testcase.entryList([], Filter.Files, SortFlag.Name ) + compareArrays(files,["a","b","c"]) + + files = testcase.entryList([], Filter.Dirs, SortFlag.Name ) + compareArrays(files,[".","..","x","y"]) + + files = testcase.entryList([], Filter.Dirs | Filter.NoDotAndDotDot, SortFlag.Name ) + compareArrays(files,["x","y"]) + + files = testcase.entryList([], Filter.Files | Filter.NoDotAndDotDot, SortFlag.Size) + compareArrays(files, ["c","b","a"]) + + files = testcase.entryList([], Filter.Files | Filter.NoDotAndDotDot, SortFlag.Size | SortFlag.Reversed) + compareArrays(files, ["a","b","c"]) + + testcase = new QDir(utils.currentScripRoot + "/testcase/x" ) + files = testcase.entryList(["*.txt"], Filter.NoFilter, SortFlag.Name ) + compareArrays(files,["abc.txt","def.txt"]) + + files = testcase.entryList(["*.txt", "*.data"], Filter.NoFilter, SortFlag.Name ) + compareArrays(files,["abc.txt","def.txt","hij.data","klm.data"]) +} + + +function testCd() { + var dir = new QDir(utils.currentScripRoot ) + var filesHere = dir.entryList() + + dir = dir.cd("testcase") + var files = dir.entryList([], Filter.Files, SortFlag.Name ) + compareArrays(files,["a","b","c"]) + + dir = dir.cdUp() + compareArrays(filesHere, dir.entryList()) +} + +function testStaticFunctions() { + var str = QDir().toNativeSeparators("/usr/bin"); + compare(str, "/usr/bin") + + QDir().setCurrent(utils.currentScripRoot) + compare(QDir().currentPath(), utils.currentScripRoot); + assert(QDir().current().exists("qdir.qs")); + + compare(QDir().cleanPath("//usr/./../tmp/./bah"),"/tmp/bah") +} diff --git a/tests/qdir/testcase/a b/tests/qdir/testcase/a new file mode 100644 index 0000000..587be6b --- /dev/null +++ b/tests/qdir/testcase/a @@ -0,0 +1 @@ +x diff --git a/tests/qdir/testcase/b b/tests/qdir/testcase/b new file mode 100644 index 0000000..ccc9bd6 --- /dev/null +++ b/tests/qdir/testcase/b @@ -0,0 +1 @@ +xx diff --git a/tests/qdir/testcase/c b/tests/qdir/testcase/c new file mode 100644 index 0000000..d6459e0 --- /dev/null +++ b/tests/qdir/testcase/c @@ -0,0 +1 @@ +xxx diff --git a/tests/qdir/testcase/x/abc.txt b/tests/qdir/testcase/x/abc.txt new file mode 100644 index 0000000..587be6b --- /dev/null +++ b/tests/qdir/testcase/x/abc.txt @@ -0,0 +1 @@ +x diff --git a/tests/qdir/testcase/x/data b/tests/qdir/testcase/x/data new file mode 100644 index 0000000..587be6b --- /dev/null +++ b/tests/qdir/testcase/x/data @@ -0,0 +1 @@ +x diff --git a/tests/qdir/testcase/x/def.txt b/tests/qdir/testcase/x/def.txt new file mode 100644 index 0000000..587be6b --- /dev/null +++ b/tests/qdir/testcase/x/def.txt @@ -0,0 +1 @@ +x diff --git a/tests/qdir/testcase/x/hij.data b/tests/qdir/testcase/x/hij.data new file mode 100644 index 0000000..587be6b --- /dev/null +++ b/tests/qdir/testcase/x/hij.data @@ -0,0 +1 @@ +x diff --git a/tests/qdir/testcase/x/klm.data b/tests/qdir/testcase/x/klm.data new file mode 100644 index 0000000..587be6b --- /dev/null +++ b/tests/qdir/testcase/x/klm.data @@ -0,0 +1 @@ +x diff --git a/tests/qdir/testcase/y/foo b/tests/qdir/testcase/y/foo new file mode 100644 index 0000000..587be6b --- /dev/null +++ b/tests/qdir/testcase/y/foo @@ -0,0 +1 @@ +x diff --git a/wrappers/enumwappers.cpp b/wrappers/enumwappers.cpp index 3950211..4cf79b8 100644 --- a/wrappers/enumwappers.cpp +++ b/wrappers/enumwappers.cpp @@ -53,10 +53,14 @@ static QScriptValue toScriptValue##ENUM(QScriptEngine *engine, const CLASS::ENUM } createEnumStatics(Enums,PositionOperation) +createEnumStatics(Enums,Filter) +createEnumStatics(Enums,SortFlag) void registerEnums(QScriptEngine* engine ) { registerEnum(engine, Enums, PositionOperation); + registerEnum(engine, Enums, Filter); + registerEnum(engine, Enums, SortFlag); } } // namespace Internal diff --git a/wrappers/qdirprototype.cpp b/wrappers/qdirprototype.cpp new file mode 100644 index 0000000..6604d83 --- /dev/null +++ b/wrappers/qdirprototype.cpp @@ -0,0 +1,281 @@ +/************************************************************************** +** +** Copyright (C) 2013 Kläralvdalens Datakonsult AB, a KDAB Group company. +** Contact: Kläralvdalens Datakonsult AB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#include "qdirprototype.h" +#include <QScriptValue> +#include <qscriptcontext.h> +#include <QScriptEngine> + +namespace Scripting { +namespace Internal { + +QScriptValue QDirPrototype::construct(QScriptContext *context, QScriptEngine *engine) +{ + if ( context->argumentCount() == 1 ) + return engine->toScriptValue( QDir(context->argument(0).toString())); + else + return engine->toScriptValue( QDir() ); +} + +#define DIR qscriptvalue_cast<QDir>(thisObject()) + +//XXX void setPath(const QString &path); + +QString QDirPrototype::path() const +{ + return DIR.path(); +} + +QString QDirPrototype::absolutePath() const +{ + return DIR.absolutePath(); +} + +QString QDirPrototype::canonicalPath() const +{ + return DIR.canonicalPath(); +} + +void QDirPrototype::addResourceSearchPath(const QString &path) +{ + DIR.addResourceSearchPath(path); +} + +void QDirPrototype::setSearchPaths(const QString &prefix, const QStringList &searchPaths) +{ + DIR.setSearchPaths(prefix,searchPaths); +} + +void QDirPrototype::addSearchPath(const QString &prefix, const QString &path) +{ + DIR.addSearchPath(prefix,path); +} + +QStringList QDirPrototype::searchPaths(const QString &prefix) +{ + return DIR.searchPaths(prefix); +} + +QString QDirPrototype::dirName() const +{ + return DIR.dirName(); +} + +QString QDirPrototype::filePath(const QString &fileName) const +{ + return DIR.filePath(fileName); +} + +QString QDirPrototype::absoluteFilePath(const QString &fileName) const +{ + return DIR.absoluteFilePath(fileName); +} + +QString QDirPrototype::relativeFilePath(const QString &fileName) const +{ + return DIR.relativeFilePath(fileName); +} + +QString QDirPrototype::toNativeSeparators(const QString &pathName) +{ + return DIR.toNativeSeparators(pathName); +} + +QString QDirPrototype::fromNativeSeparators(const QString &pathName) +{ + return DIR.fromNativeSeparators(pathName); +} + +QDir QDirPrototype::cd(const QString &dirName) +{ + QDir d = DIR; + d.cd(dirName); + return d; +} + +QDir QDirPrototype::cdUp() +{ + QDir d = DIR; + d.cdUp(); + return d; +} + +//XXX QStringList nameFilters() const; +//XXX void setNameFilters(const QStringList &nameFilters); + +//XXX Filters filter() const; +//XXX void setFilter(Filters filter); +//XXX SortFlags sorting() const; +//XXX void setSorting(SortFlags sort); + +uint QDirPrototype::count() const +{ + return DIR.count(); +} + +QString QDirPrototype::at(int i) const +{ + return DIR[i]; +} + + +QStringList QDirPrototype::entryList(const QStringList &nameFilters, int filters, int sort) const +{ + return DIR.entryList(nameFilters, Enums::convertFilters(filters), Enums::convertSortFlag(sort)); +} + +//XXX QFileInfoList entryInfoList(Filters filters = NoFilter, SortFlags sort = NoSort) const; +//XXX QFileInfoList entryInfoList(const QStringList &nameFilters, Filters filters = NoFilter, +//XXX SortFlags sort = NoSort) const; + +bool QDirPrototype::mkdir(const QString &dirName) const +{ + return DIR.mkdir(dirName); +} + +bool QDirPrototype::rmdir(const QString &dirName) const +{ + return DIR.rmdir(dirName); +} + +bool QDirPrototype::mkpath(const QString &dirPath) const +{ + return DIR.mkpath(dirPath); +} + +bool QDirPrototype::rmpath(const QString &dirPath) const +{ + return DIR.rmpath(dirPath); +} + + +bool QDirPrototype::isReadable() const +{ + return DIR.isReadable(); +} + +bool QDirPrototype::exists() const +{ + return DIR.exists(); +} + +bool QDirPrototype::isRoot() const +{ + return DIR.isRoot(); +} + +bool QDirPrototype::isRelativePath(const QString &path) +{ + return DIR.isRelativePath(path); +} + +bool QDirPrototype::isRelative() const +{ + return DIR.isRelative(); +} + +bool QDirPrototype::isAbsolute() const +{ + return DIR.isAbsolute(); +} + +//XXX bool makeAbsolute(); + +bool QDirPrototype::remove(const QString &fileName) +{ + return DIR.remove(fileName); +} + +bool QDirPrototype::rename(const QString &oldName, const QString &newName) +{ + return DIR.rename(oldName, newName); +} + +bool QDirPrototype::exists(const QString &name) const +{ + return DIR.exists(name); +} + + +QFileInfoList QDirPrototype::drives() +{ + return DIR.drives(); +} + +QChar QDirPrototype::separator() +{ + return DIR.separator(); +} + +bool QDirPrototype::setCurrent(const QString &path) +{ + return DIR.setCurrent(path); +} + +QString QDirPrototype::currentPath() +{ + return DIR.currentPath(); +} + +QString QDirPrototype::homePath() +{ + return DIR.homePath(); +} + +QString QDirPrototype::rootPath() +{ + return DIR.rootPath(); +} + +QString QDirPrototype::tempPath() +{ + return DIR.tempPath(); +} + +#ifndef QT_NO_REGEXP +bool QDirPrototype::match(const QStringList &filters, const QString &fileName) +{ + return DIR.match(filters, fileName); +} + +bool QDirPrototype::match(const QString &filter, const QString &fileName) +{ + return DIR.match(filter,fileName); +} +#endif + +QString QDirPrototype::cleanPath(const QString &path) +{ + return DIR.cleanPath(path); +} + +//XXX void refresh() const; +} // namespace Internal +} // namespace Scripting + diff --git a/wrappers/qdirprototype.h b/wrappers/qdirprototype.h new file mode 100644 index 0000000..1fb3162 --- /dev/null +++ b/wrappers/qdirprototype.h @@ -0,0 +1,156 @@ +/************************************************************************** +** +** Copyright (C) 2013 Kläralvdalens Datakonsult AB, a KDAB Group company. +** Contact: Kläralvdalens Datakonsult AB (info@kdab.com) +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef SCRIPTING_INTERNAL_QDIRPROTOTYPE_H +#define SCRIPTING_INTERNAL_QDIRPROTOTYPE_H + +#include <QObject> +#include <QDir> +#include <QMetaType> +#include <QScriptable> +#include "objects/enums.h" + +namespace Scripting { +namespace Internal { + +/** + * @brief Wrapper for QDir, which makes it available in scripts + */ +class QDirPrototype : public QObject, public QScriptable +{ + // Methods comments out using //XXX are methods from QDir, which are not wrapped + // The reason is that they make no sense, as this wrapper wraps a QDir, not a QDir*, + // so the QDir is copied, and therefore read only. + + Q_OBJECT + Q_PROPERTY(QString path READ path) + Q_PROPERTY(QString absolutePath READ absolutePath) + Q_PROPERTY(QString canonicalPath READ canonicalPath) + Q_PROPERTY(QString dirName READ dirName) + Q_PROPERTY(uint count READ count) + Q_PROPERTY(bool isReadable READ isReadable) + // Q_PROPERTY(bool exists READ exists) - not wrapped as that would shadow exists(fileName) + Q_PROPERTY(bool isRoot READ isRoot) + Q_PROPERTY(bool isRelative READ isRelative) + Q_PROPERTY(bool isAbsolute READ isAbsolute) + +public: + static QScriptValue construct(QScriptContext* context, QScriptEngine* engine); + +public slots: + //XXX void setPath(const QString &path); + QString path() const; + QString absolutePath() const; + QString canonicalPath() const; + + void addResourceSearchPath(const QString &path); + + void setSearchPaths(const QString &prefix, const QStringList &searchPaths); + void addSearchPath(const QString &prefix, const QString &path); + QStringList searchPaths(const QString &prefix); + + QString dirName() const; + QString filePath(const QString &fileName) const; + QString absoluteFilePath(const QString &fileName) const; + QString relativeFilePath(const QString &fileName) const; + + QString toNativeSeparators(const QString &pathName); + QString fromNativeSeparators(const QString &pathName); + + // The signature of these are changed to return a QDir + QDir cd(const QString &dirName); + QDir cdUp(); + + //XXX QStringList nameFilters() const; + //XXX void setNameFilters(const QStringList &nameFilters); + //XXX Filters filter() const; + //XXX void setFilter(Filters filter); + //XXX SortFlags sorting() const; + //XXX void setSorting(SortFlags sort); + + uint count() const; + QString at(int i) const; // Was operator[] + + + QStringList entryList(const QStringList &nameFilters = QStringList(), int filters = Enums::NoFilter, + int sort = QDir::NoSort) const; + + //XXX QFileInfoList entryInfoList(Filters filters = NoFilter, SortFlags sort = NoSort) const; + //XXX QFileInfoList entryInfoList(const QStringList &nameFilters, Filters filters = NoFilter, + //XXX SortFlags sort = NoSort) const; + + bool mkdir(const QString &dirName) const; + bool rmdir(const QString &dirName) const; + bool mkpath(const QString &dirPath) const; + bool rmpath(const QString &dirPath) const; + + bool isReadable() const; + bool exists() const; + bool isRoot() const; + + bool isRelativePath(const QString &path); + bool isAbsolutePath(const QString &path) { return !isRelativePath(path); } + bool isRelative() const; + bool isAbsolute() const; + //XXX bool makeAbsolute(); + + bool remove(const QString &fileName); + bool rename(const QString &oldName, const QString &newName); + bool exists(const QString &name) const; + + QFileInfoList drives(); + + QChar separator(); + + bool setCurrent(const QString &path); + inline QDir current() { return QDir(currentPath()); } + QString currentPath(); + + QDir home() { return QDir(homePath()); } + QString homePath(); + QDir root() { return QDir(rootPath()); } + QString rootPath(); + QDir temp() { return QDir(tempPath()); } + QString tempPath(); + +#ifndef QT_NO_REGEXP + bool match(const QStringList &filters, const QString &fileName); + bool match(const QString &filter, const QString &fileName); +#endif + + QString cleanPath(const QString &path); + //XXX void refresh() const; +}; + +} // namespace Internal +} // namespace Scripting + +#endif // SCRIPTING_INTERNAL_QDIRPROTOTYPE_H + +Q_DECLARE_METATYPE(QDir) diff --git a/wrappers/scriptwrappers.cpp b/wrappers/scriptwrappers.cpp index de8e709..f14abc0 100644 --- a/wrappers/scriptwrappers.cpp +++ b/wrappers/scriptwrappers.cpp @@ -32,6 +32,7 @@ #include "utils/position.h" #include <QFileInfo> #include "qfileinfoprototype.h" +#include "qdirprototype.h" namespace Scripting { namespace Internal { @@ -90,6 +91,7 @@ void registerWrappers(QScriptEngine* engine ) qScriptRegisterMetaType(engine, scriptValueFromQRect, QRectFromScriptValue ); registerProtoType(QFileInfo, QFileInfoPrototype); + registerProtoType(QDir,QDirPrototype); } } // namespace Internal |