| 1 |
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 |
|
| 5 |
#ifndef DCAPFILE_H |
| 6 |
#define DCAPFILE_H |
| 7 |
|
| 8 |
#include <dtkcore_global.h> |
| 9 |
|
| 10 |
#include <DObject> |
| 11 |
#include <QDir> |
| 12 |
#include <QFile> |
| 13 |
|
| 14 |
DCORE_BEGIN_NAMESPACE |
| 15 |
|
| 16 |
class DCapFilePrivate; |
| 17 |
class DCapFile : public QFile, public DObject |
| 18 |
{ |
| 19 |
Q_OBJECT |
| 20 |
D_DECLARE_PRIVATE(DCapFile) |
| 21 |
Q_DISABLE_COPY(DCapFile) |
| 22 |
|
| 23 |
public: |
| 24 |
explicit DCapFile(QObject *parent = nullptr); |
| 25 |
DCapFile(const QString &name, QObject *parent = nullptr); |
| 26 |
|
| 27 |
~DCapFile() override; |
| 28 |
|
| 29 |
void setFileName(const QString &name); |
| 30 |
|
| 31 |
bool exists() const; |
| 32 |
static bool exists(const QString &fileName); |
| 33 |
|
| 34 |
#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) |
| 35 |
D_DECL_DEPRECATED_X("Use QFile::symLinkTarget() instead") |
| 36 |
QString readLink() const; |
| 37 |
#endif |
| 38 |
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) |
| 39 |
QString symLinkTarget() const; |
| 40 |
#endif |
| 41 |
bool remove(); |
| 42 |
static bool remove(const QString &fileName); |
| 43 |
|
| 44 |
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) |
| 45 |
bool moveToTrash(); |
| 46 |
static bool moveToTrash(const QString &fileName, QString *pathInTrash = nullptr); |
| 47 |
#endif |
| 48 |
|
| 49 |
bool rename(const QString &newName); |
| 50 |
static bool rename(const QString &oldName, const QString &newName); |
| 51 |
|
| 52 |
bool link(const QString &newName); |
| 53 |
static bool link(const QString &oldname, const QString &newName); |
| 54 |
|
| 55 |
bool copy(const QString &newName); |
| 56 |
static bool copy(const QString &fileName, const QString &newName); |
| 57 |
|
| 58 |
bool open(OpenMode flags) override; |
| 59 |
|
| 60 |
bool resize(qint64 sz) override; |
| 61 |
static bool resize(const QString &filename, qint64 sz); |
| 62 |
|
| 63 |
private: |
| 64 |
bool open(FILE *f, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle); |
| 65 |
bool open(int fd, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle); |
| 66 |
}; |
| 67 |
|
| 68 |
class DCapDirPrivate; |
| 69 |
class DCapDir : public QDir |
| 70 |
{ |
| 71 |
public: |
| 72 |
DCapDir(const DCapDir &); |
| 73 |
DCapDir(const QString &path = QString()); |
| 74 |
DCapDir(const QString &path, const QString &nameFilter, |
| 75 |
SortFlags sort = SortFlags(Name | IgnoreCase), Filters filter = AllEntries); |
| 76 |
~DCapDir(); |
| 77 |
|
| 78 |
void setPath(const QString &path); |
| 79 |
|
| 80 |
bool cd(const QString &dirName); |
| 81 |
|
| 82 |
QStringList entryList(Filters filters = NoFilter, SortFlags sort = NoSort) const; |
| 83 |
QStringList entryList(const QStringList &nameFilters, Filters filters = NoFilter, |
| 84 |
SortFlags sort = NoSort) const; |
| 85 |
|
| 86 |
QFileInfoList entryInfoList(Filters filters = NoFilter, SortFlags sort = NoSort) const; |
| 87 |
QFileInfoList entryInfoList(const QStringList &nameFilters, Filters filters = NoFilter, |
| 88 |
SortFlags sort = NoSort) const; |
| 89 |
|
| 90 |
bool mkdir(const QString &dirName) const; |
| 91 |
bool rmdir(const QString &dirName) const; |
| 92 |
bool mkpath(const QString &dirPath) const; |
| 93 |
bool rmpath(const QString &dirPath) const; |
| 94 |
bool exists() const; |
| 95 |
bool remove(const QString &fileName); |
| 96 |
bool rename(const QString &oldName, const QString &newName); |
| 97 |
bool exists(const QString &name) const; |
| 98 |
|
| 99 |
private: |
| 100 |
QSharedDataPointer<DCapDirPrivate> dd_ptr; |
| 101 |
}; |
| 102 |
|
| 103 |
DCORE_END_NAMESPACE |
| 104 |
Q_DECLARE_SHARED(DTK_CORE_NAMESPACE::DCapDir) |
| 105 |
#endif // DCAPFILE_H |