File indexing completed on 2025-01-19 04:25:15

0001 /*
0002  * Replacement fot QT Bindings that were removed from QT5
0003  * Copyright (C) 2020  Pedro de Carvalho Gomes <pedro.gomes@ipsoft.com>
0004  *
0005  * This program is free software: you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation, either version 3 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This program is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017  */
0018 #ifndef COREDIR_H
0019 #define COREDIR_H
0020 
0021 #include "QtBinding.h"
0022 
0023 #include <QObject>
0024 #include <QDir>
0025 
0026 namespace QtBindings
0027 {
0028     namespace Core
0029     {
0030         class Dir : public QObject, public QDir, public QtBindings::Base<Dir>
0031         {
0032         Q_OBJECT
0033         public:
0034             Q_INVOKABLE Dir(const QDir &path);
0035             Q_INVOKABLE Dir(const Dir &path);
0036             Q_INVOKABLE Dir(const QString &path = QString());
0037             Q_INVOKABLE Dir(const QString &path, const QString &nameFilter, SortFlags sort = SortFlags(Name | IgnoreCase), Filters filter = AllEntries);
0038             Q_INVOKABLE static bool isAbsolutePath(const QString &path);
0039             Q_INVOKABLE static bool isRelativePath(const QString &path);
0040             Q_INVOKABLE static bool match(const QString &filter, const QString &fileName);
0041             Q_INVOKABLE static bool match(const QStringList &filters, const QString &fileName);
0042             Q_INVOKABLE static bool setCurrent(const QString &path);
0043             Q_INVOKABLE static QChar listSeparator();
0044             Q_INVOKABLE static QChar separator();
0045             Q_INVOKABLE static QDir current();
0046             Q_INVOKABLE static QDir home();
0047             Q_INVOKABLE static QDir root();
0048             Q_INVOKABLE static QDir temp();
0049             Q_INVOKABLE static QFileInfoList drives();
0050             Q_INVOKABLE static QString cleanPath(const QString &path);
0051             Q_INVOKABLE static QString currentPath();
0052             Q_INVOKABLE static QString fromNativeSeparators(const QString &pathName);
0053             Q_INVOKABLE static QString homePath();
0054             Q_INVOKABLE static QStringList nameFiltersFromString(const QString &nameFilter);
0055             Q_INVOKABLE static QStringList searchPaths(const QString &prefix);
0056             Q_INVOKABLE static QString rootPath();
0057             Q_INVOKABLE static QString tempPath();
0058             Q_INVOKABLE static QString toNativeSeparators(const QString &pathName);
0059             Q_INVOKABLE static void addSearchPath(const QString &prefix, const QString &path);
0060             Q_INVOKABLE static void setSearchPaths(const QString &prefix, const QStringList &searchPaths);
0061             Dir &operator=(const Dir &other);
0062         public slots:
0063             bool cd(const QString &dirName);
0064             bool cdUp();
0065             bool exists() const;
0066             bool exists(const QString &name) const;
0067             bool isAbsolute() const { return !isRelative(); }
0068             bool isEmpty(Filters filters = Filters(AllEntries | NoDotAndDotDot)) const;
0069             bool isReadable() const;
0070             bool isRelative() const;
0071             bool isRoot() const;
0072             bool makeAbsolute();
0073             bool mkdir(const QString &dirName) const;
0074             bool mkpath(const QString &dirPath) const;
0075             bool remove(const QString &fileName);
0076             bool removeRecursively();
0077             bool rename(const QString &oldName, const QString &newName);
0078             bool rmdir(const QString &dirName) const;
0079             bool rmpath(const QString &dirPath) const;
0080             Filters filter() const;
0081             QFileInfoList entryInfoList(const QStringList &nameFilters, Filters filters = NoFilter, SortFlags sort = NoSort) const;
0082             QFileInfoList entryInfoList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
0083             QString absoluteFilePath(const QString &fileName) const;
0084             QString absolutePath() const;
0085             QString canonicalPath() const;
0086             QString dirName() const;
0087             QString filePath(const QString &fileName) const;
0088             QStringList entryList(const QStringList &nameFilters, Filters filters = NoFilter, SortFlags sort = NoSort) const;
0089             QStringList entryList(Filters filters = NoFilter, SortFlags sort = NoSort) const;
0090             QStringList nameFilters() const;
0091             QString path() const;
0092             QString relativeFilePath(const QString &fileName) const;
0093             SortFlags sorting() const;
0094             uint count() const;
0095             void refresh() const;
0096             void setFilter(Filters filter);
0097             void setNameFilters(const QStringList &nameFilters);
0098             void setPath(const QString &path);
0099             void setSorting(SortFlags sort);
0100             void swap(QDir &other);
0101         };
0102     }
0103 }
0104 Q_DECLARE_METATYPE(QtBindings::Core::Dir)
0105 #endif //COREDIR_H