forked from linuxdeepin/util-dfm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: [io] remove redundant code
1. Remove factory classes 2. Remove `DLocal*` classes Log: refactor dfm-io Task: https://pms.uniontech.com/task-view-247375.html Change-Id: Ic52137fef0d8b8a23046ab846916aa986879f3ce
- Loading branch information
1 parent
f1af756
commit 5f08aa4
Showing
152 changed files
with
3,259 additions
and
11,527 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// SPDX-FileCopyrightText: 2020 - 2023 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#ifndef DENUMERATOR_H | ||
#define DENUMERATOR_H | ||
|
||
#include <dfm-io/dfmio_global.h> | ||
#include <dfm-io/error/error.h> | ||
|
||
#include <QUrl> | ||
#include <QSharedPointer> | ||
|
||
#include <functional> | ||
|
||
BEGIN_IO_NAMESPACE | ||
|
||
class DEnumeratorPrivate; | ||
class DFileInfo; | ||
|
||
class DEnumerator | ||
{ | ||
public: | ||
enum class DirFilter : int16_t { | ||
kNoFilter = -1, // no filter | ||
kDirs = 0x001, // List directories that match the filters. | ||
kFiles = 0x002, // List files. | ||
kDrives = 0x004, // List disk drives (ignored under Unix). | ||
kAllEntries = 0x001 | 0x002 | 0x004, // List directories, files, drives and symlinks (this does not list broken symlinks unless you specify System). | ||
kNoSymLinks = 0x008, // Do not list symbolic links (ignored by operating systems that don't support symbolic links). | ||
|
||
kReadable = 0x010, // List files for which the application has read access. The Readable value needs to be combined with Dirs or Files. | ||
kWritable = 0x020, // List files for which the application has write access. The Writable value needs to be combined with Dirs or Files. | ||
kExecutable = 0x040, // List files for which the application has execute access. The Executable value needs to be combined with Dirs or Files. | ||
kModified = 0x080, // Only list files that have been modified (ignored on Unix). | ||
|
||
kHidden = 0x100, // List hidden files (on Unix, files starting with a "."). | ||
kSystem = 0x200, // List system files (on Unix, FIFOs, sockets and device files are included; on Windows, .lnk files are included) | ||
kAllDirs = 0x400, // List all directories; i.e. don't apply the filters to directory names. | ||
kCaseSensitive = 0x800, // The filter should be case sensitive. | ||
|
||
kNoDot = 0x2000, // Do not list the special entry ".". | ||
kNoDotDot = 0x4000, // Do not list the special entry "..". | ||
kNoDotAndDotDot = 0x2000 | 0x4000, // Do not list the special entries "." and "..". | ||
}; | ||
Q_DECLARE_FLAGS(DirFilters, DirFilter) | ||
|
||
enum class IteratorFlag : uint8_t { | ||
kNoIteratorFlags = 0x00, // The default value, representing no flags. The iterator will return entries for the assigned path. | ||
kFollowSymlinks = 0x01, // When combined with Subdirectories, this flag enables iterating through all subdirectories of the assigned path, following all symbolic links. Symbolic link loops (e.g., "link" => "." or "link" => "..") are automatically detected and ignored. | ||
kSubdirectories = 0x02, // List entries inside all subdirectories as well. | ||
}; | ||
Q_DECLARE_FLAGS(IteratorFlags, IteratorFlag) | ||
|
||
enum class SortRoleCompareFlag : uint8_t { | ||
kSortRoleCompareDefault = 0, // The default value | ||
kSortRoleCompareFileName = 1, // compare by file path | ||
kSortRoleCompareFileSize = 2, // compare by file size | ||
kSortRoleCompareFileLastModified = 3, // compare by last modified time | ||
kSortRoleCompareFileLastRead = 4, // compare by last read time | ||
}; | ||
|
||
struct SortFileInfo | ||
{ | ||
QUrl url; | ||
bool isFile { false }; | ||
bool isDir { false }; | ||
bool isSymLink { false }; | ||
bool isHide { false }; | ||
bool isReadable { false }; | ||
bool isWriteable { false }; | ||
bool isExecutable { false }; | ||
}; | ||
|
||
public: | ||
explicit DEnumerator(const QUrl &uri); | ||
explicit DEnumerator(const QUrl &uri, const QStringList &nameFilters, DirFilters filters, IteratorFlags flags); | ||
~DEnumerator(); | ||
QUrl uri() const; | ||
|
||
void setNameFilters(const QStringList &filters); | ||
QStringList nameFilters() const; | ||
|
||
void setDirFilters(DirFilters filters); | ||
DirFilters dirFilters() const; | ||
|
||
void setIteratorFlags(IteratorFlags flags); | ||
IteratorFlags iteratorFlags() const; | ||
|
||
void setTimeout(ulong timeout); | ||
ulong timeout() const; | ||
|
||
void setSortRole(SortRoleCompareFlag role); | ||
SortRoleCompareFlag sortRole() const; | ||
|
||
void setSortOrder(Qt::SortOrder order); | ||
Qt::SortOrder sortOrder() const; | ||
|
||
void setSortMixed(bool mix); | ||
bool isSortMixed() const; | ||
|
||
public: | ||
bool cancel(); | ||
bool hasNext() const; | ||
QUrl next() const; | ||
QSharedPointer<DFileInfo> fileInfo() const; | ||
quint64 fileCount(); | ||
QList<QSharedPointer<DFileInfo>> fileInfoList(); | ||
QList<QSharedPointer<DEnumerator::SortFileInfo>> sortFileInfoList(); | ||
DFMIOError lastError() const; | ||
|
||
private: | ||
QScopedPointer<DEnumeratorPrivate> d; | ||
}; | ||
|
||
Q_DECLARE_OPERATORS_FOR_FLAGS(DEnumerator::DirFilters); | ||
Q_DECLARE_OPERATORS_FOR_FLAGS(DEnumerator::IteratorFlags); | ||
|
||
END_IO_NAMESPACE | ||
|
||
Q_DECLARE_METATYPE(DFMIO::DEnumerator::SortRoleCompareFlag) | ||
Q_DECLARE_METATYPE(QSharedPointer<DFMIO::DEnumerator::SortFileInfo>) | ||
Q_DECLARE_METATYPE(QList<QSharedPointer<DFMIO::DEnumerator::SortFileInfo>>) | ||
|
||
#endif // DENUMERATOR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
// SPDX-FileCopyrightText: 2020 - 2023 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#ifndef DFILE_H | ||
#define DFILE_H | ||
|
||
#include <dfm-io/dfmio_global.h> | ||
#include <dfm-io/error/error.h> | ||
|
||
#include <QUrl> | ||
#include <QSharedPointer> | ||
|
||
#include <functional> | ||
|
||
BEGIN_IO_NAMESPACE | ||
|
||
class DFileFuture; | ||
class DFilePrivate; | ||
|
||
class DFile | ||
{ | ||
public: | ||
enum class OpenFlag : uint16_t { | ||
kNotOpen = 0x0000, | ||
kReadOnly = 0x0001, | ||
kWriteOnly = 0x0002, // auto create | ||
kReadWrite = kReadOnly | kWriteOnly, // auto create | ||
kAppend = 0x0004, | ||
kTruncate = 0x0008, | ||
kText = 0x0010, | ||
kUnbuffered = 0x0020, | ||
kNewOnly = 0x0040, | ||
kExistingOnly = 0x0080, | ||
|
||
kCustomStart = 0x0100, | ||
}; | ||
Q_DECLARE_FLAGS(OpenFlags, OpenFlag) | ||
|
||
enum class CopyFlag : uint8_t { | ||
kNone = 0, // No flags set. | ||
kOverwrite = 1, // Overwrite any existing files. | ||
kBackup = 2, // Make a backup of any existing files. | ||
kNoFollowSymlinks = 3, // Don’t follow symlinks. | ||
kAllMetadata = 4, // Copy all file metadata instead of just default set used for copy. | ||
kNoFallbackForMove = 5, // Don’t use copy and delete fallback if native move not supported. | ||
kTargetDefaultPerms = 6, // Leaves target file with default perms, instead of setting the source file perms. | ||
|
||
kUserFlag = 0x10 | ||
}; | ||
|
||
enum class SeekType : uint8_t { | ||
kBegin = 0x00, | ||
kCurrent = 0x01, | ||
kEnd = 0x02 | ||
}; | ||
|
||
enum class Permission : uint16_t { | ||
kNoPermission = 0x0000, | ||
|
||
kExeOther = 0x0001, | ||
kWriteOther = 0x0002, | ||
kReadOther = 0x0004, | ||
|
||
kExeGroup = 0x0010, | ||
kWriteGroup = 0x0020, | ||
kReadGroup = 0x0040, | ||
|
||
kExeUser = 0x0100, | ||
kWriteUser = 0x0200, | ||
kReadUser = 0x0400, | ||
|
||
kExeOwner = 0x1000, | ||
kWriteOwner = 0x2000, | ||
kReadOwner = 0x4000, | ||
}; | ||
Q_DECLARE_FLAGS(Permissions, Permission) | ||
|
||
// callback, use function pointer | ||
using ReadCallbackFunc = void (*)(qint64, void *); | ||
using ReadQCallbackFunc = void (*)(QByteArray, void *); | ||
using ReadAllCallbackFunc = void (*)(QByteArray, void *); | ||
|
||
using WriteCallbackFunc = void (*)(qint64, void *); | ||
using WriteAllCallbackFunc = void (*)(qint64, void *); | ||
using WriteQCallbackFunc = void (*)(qint64, void *); | ||
|
||
public: | ||
explicit DFile(const QUrl &uri); | ||
explicit DFile(const QString &path); | ||
~DFile(); | ||
QUrl uri() const; | ||
bool isOpen() const; | ||
qint64 size() const; | ||
bool exists() const; | ||
qint64 pos() const; | ||
Permissions permissions() const; | ||
DFMIOError lastError() const; | ||
|
||
bool open(OpenFlags mode); | ||
bool close(); | ||
bool cancel(); | ||
bool seek(qint64 pos, SeekType type = SeekType::kBegin) const; | ||
bool flush(); | ||
bool setPermissions(Permissions permission); | ||
|
||
// read and write | ||
qint64 read(char *data, qint64 maxSize); | ||
QByteArray read(qint64 maxSize); | ||
QByteArray readAll(); | ||
qint64 write(const char *data, qint64 len); | ||
qint64 write(const char *data); | ||
qint64 write(const QByteArray &byteArray); | ||
|
||
// async callback | ||
void readAsync(char *data, qint64 maxSize, int ioPriority = 0, ReadCallbackFunc func = nullptr, void *userData = nullptr); | ||
void readQAsync(qint64 maxSize, int ioPriority = 0, ReadQCallbackFunc func = nullptr, void *userData = nullptr); | ||
void readAllAsync(int ioPriority = 0, ReadAllCallbackFunc func = nullptr, void *userData = nullptr); | ||
void writeAsync(const char *data, qint64 maxSize, int ioPriority = 0, WriteCallbackFunc func = nullptr, void *userData = nullptr); | ||
void writeAllAsync(const char *data, int ioPriority = 0, WriteAllCallbackFunc func = nullptr, void *userData = nullptr); | ||
void writeQAsync(const QByteArray &byteArray, int ioPriority = 0, WriteQCallbackFunc func = nullptr, void *userData = nullptr); | ||
|
||
// future callback | ||
[[nodiscard]] DFileFuture *openAsync(OpenFlags mode, int ioPriority, QObject *parent = nullptr); | ||
[[nodiscard]] DFileFuture *closeAsync(int ioPriority, QObject *parent = nullptr); | ||
[[nodiscard]] DFileFuture *readAsync(quint64 maxSize, int ioPriority, QObject *parent = nullptr); | ||
[[nodiscard]] DFileFuture *readAllAsync(int ioPriority, QObject *parent = nullptr); | ||
[[nodiscard]] DFileFuture *writeAsync(const QByteArray &data, qint64 len, int ioPriority, QObject *parent = nullptr); | ||
[[nodiscard]] DFileFuture *writeAsync(const QByteArray &data, int ioPriority, QObject *parent = nullptr); | ||
[[nodiscard]] DFileFuture *flushAsync(int ioPriority, QObject *parent = nullptr); | ||
[[nodiscard]] DFileFuture *sizeAsync(int ioPriority, QObject *parent = nullptr); | ||
[[nodiscard]] DFileFuture *existsAsync(int ioPriority, QObject *parent = nullptr); | ||
[[nodiscard]] DFileFuture *permissionsAsync(int ioPriority, QObject *parent = nullptr); | ||
[[nodiscard]] DFileFuture *setPermissionsAsync(Permissions permission, int ioPriority, QObject *parent = nullptr); | ||
|
||
private: | ||
QScopedPointer<DFilePrivate> d; | ||
}; | ||
|
||
Q_DECLARE_OPERATORS_FOR_FLAGS(DFile::OpenFlags); | ||
Q_DECLARE_OPERATORS_FOR_FLAGS(DFile::Permissions); | ||
|
||
END_IO_NAMESPACE | ||
|
||
#endif // DFILE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.