forked from qt-creator/qt-creator
Utils: Split FilePath off fileutils.h
This now rather central class deserves a suitably named file(pair). The rarer used declarations including otherwise not needed includes are still in fileutils.h. Change-Id: Ib18d72f16322c03f76023fdefcd5f6da35311b8b Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "utils_global.h"
|
||||
|
||||
#include "filepath.h"
|
||||
#include "hostosinfo.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
@@ -40,33 +41,17 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace Utils {
|
||||
class Environment;
|
||||
class FilePath;
|
||||
} // Utils
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QDataStream;
|
||||
class QDateTime;
|
||||
class QDir;
|
||||
class QFile;
|
||||
class QFileInfo;
|
||||
class QTemporaryFile;
|
||||
class QTextStream;
|
||||
class QWidget;
|
||||
|
||||
QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug dbg, const Utils::FilePath &c);
|
||||
|
||||
// for withNtfsPermissions
|
||||
#ifdef Q_OS_WIN
|
||||
extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
|
||||
#endif
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
// tst_fileutils becomes a friend of Utils::FilePath for testing private method
|
||||
class tst_fileutils;
|
||||
|
||||
namespace Utils {
|
||||
|
||||
class DeviceFileHooks
|
||||
@@ -99,151 +84,6 @@ public:
|
||||
std::function<Environment(const FilePath &)> environment;
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT FilePath
|
||||
{
|
||||
public:
|
||||
FilePath();
|
||||
|
||||
static FilePath fromString(const QString &filepath);
|
||||
static FilePath fromFileInfo(const QFileInfo &info);
|
||||
static FilePath fromStringWithExtension(const QString &filepath, const QString &defaultExtension);
|
||||
static FilePath fromUserInput(const QString &filepath);
|
||||
static FilePath fromUtf8(const char *filepath, int filepathSize = -1);
|
||||
static FilePath fromVariant(const QVariant &variant);
|
||||
|
||||
QString toString() const;
|
||||
FilePath onDevice(const FilePath &deviceTemplate) const;
|
||||
FilePath withNewPath(const QString &newPath) const;
|
||||
|
||||
QFileInfo toFileInfo() const;
|
||||
QVariant toVariant() const;
|
||||
QDir toDir() const;
|
||||
|
||||
QString toUserOutput() const;
|
||||
QString shortNativePath() const;
|
||||
|
||||
QString fileName() const;
|
||||
QString fileNameWithPathComponents(int pathComponents) const;
|
||||
|
||||
QString baseName() const;
|
||||
QString completeBaseName() const;
|
||||
QString suffix() const;
|
||||
QString completeSuffix() const;
|
||||
|
||||
QString scheme() const { return m_scheme; }
|
||||
void setScheme(const QString &scheme);
|
||||
|
||||
QString host() const { return m_host; }
|
||||
void setHost(const QString &host);
|
||||
|
||||
QString path() const { return m_data; }
|
||||
void setPath(const QString &path) { m_data = path; }
|
||||
|
||||
bool needsDevice() const;
|
||||
bool exists() const;
|
||||
|
||||
bool isWritablePath() const { return isWritableDir(); } // Remove.
|
||||
bool isWritableDir() const;
|
||||
bool isWritableFile() const;
|
||||
bool ensureWritableDir() const;
|
||||
bool ensureExistingFile() const;
|
||||
bool isExecutableFile() const;
|
||||
bool isReadableFile() const;
|
||||
bool isReadableDir() const;
|
||||
bool isRelativePath() const;
|
||||
bool isAbsolutePath() const { return !isRelativePath(); }
|
||||
bool isFile() const;
|
||||
bool isDir() const;
|
||||
|
||||
bool createDir() const;
|
||||
QList<FilePath> dirEntries(const QStringList &nameFilters,
|
||||
QDir::Filters filters,
|
||||
QDir::SortFlags sort = QDir::NoSort) const;
|
||||
QList<FilePath> dirEntries(QDir::Filters filters) const;
|
||||
QByteArray fileContents(qint64 maxSize = -1, qint64 offset = 0) const;
|
||||
bool writeFileContents(const QByteArray &data) const;
|
||||
|
||||
FilePath parentDir() const;
|
||||
FilePath absolutePath() const;
|
||||
FilePath absoluteFilePath() const;
|
||||
FilePath absoluteFilePath(const FilePath &tail) const;
|
||||
FilePath absoluteFromRelativePath(const FilePath &anchor) const;
|
||||
|
||||
bool operator==(const FilePath &other) const;
|
||||
bool operator!=(const FilePath &other) const;
|
||||
bool operator<(const FilePath &other) const;
|
||||
bool operator<=(const FilePath &other) const;
|
||||
bool operator>(const FilePath &other) const;
|
||||
bool operator>=(const FilePath &other) const;
|
||||
FilePath operator+(const QString &s) const;
|
||||
|
||||
bool isChildOf(const FilePath &s) const;
|
||||
bool isChildOf(const QDir &dir) const;
|
||||
bool startsWith(const QString &s) const;
|
||||
bool endsWith(const QString &s) const;
|
||||
|
||||
bool isNewerThan(const QDateTime &timeStamp) const;
|
||||
QDateTime lastModified() const;
|
||||
QFile::Permissions permissions() const;
|
||||
OsType osType() const;
|
||||
bool removeFile() const;
|
||||
bool removeRecursively(QString *error = nullptr) const;
|
||||
bool copyFile(const FilePath &target) const;
|
||||
bool renameFile(const FilePath &target) const;
|
||||
|
||||
Qt::CaseSensitivity caseSensitivity() const;
|
||||
|
||||
FilePath relativeChildPath(const FilePath &parent) const;
|
||||
FilePath relativePath(const FilePath &anchor) const;
|
||||
FilePath pathAppended(const QString &str) const;
|
||||
FilePath stringAppended(const QString &str) const;
|
||||
FilePath resolvePath(const QString &fileName) const;
|
||||
FilePath cleanPath() const;
|
||||
|
||||
FilePath canonicalPath() const;
|
||||
FilePath symLinkTarget() const;
|
||||
FilePath resolveSymlinks() const;
|
||||
FilePath withExecutableSuffix() const;
|
||||
|
||||
FilePath operator/(const QString &str) const;
|
||||
|
||||
void clear();
|
||||
bool isEmpty() const;
|
||||
|
||||
uint hash(uint seed) const;
|
||||
|
||||
// NOTE: Most FilePath operations on FilePath created from URL currently
|
||||
// do not work. Among the working are .toVariant() and .toUrl().
|
||||
static FilePath fromUrl(const QUrl &url);
|
||||
QUrl toUrl() const;
|
||||
|
||||
static void setDeviceFileHooks(const DeviceFileHooks &hooks);
|
||||
|
||||
FilePath searchOnDevice(const QList<FilePath> &dirs) const;
|
||||
Environment deviceEnvironment() const;
|
||||
|
||||
static QString formatFilePaths(const QList<FilePath> &files, const QString &separator);
|
||||
static void removeDuplicates(QList<FilePath> &files);
|
||||
static void sort(QList<FilePath> &files);
|
||||
|
||||
static QList<FilePath> filterEntriesHelper(const FilePath &base,
|
||||
const QStringList &entries,
|
||||
const QStringList &nameFilters,
|
||||
QDir::Filters filters,
|
||||
QDir::SortFlags sort);
|
||||
private:
|
||||
friend class ::tst_fileutils;
|
||||
static QString calcRelativePath(const QString &absolutePath, const QString &absoluteAnchorPath);
|
||||
|
||||
QString m_scheme;
|
||||
QString m_host;
|
||||
QString m_data;
|
||||
};
|
||||
|
||||
QTCREATOR_UTILS_EXPORT QTextStream &operator<<(QTextStream &s, const FilePath &fn);
|
||||
|
||||
using FilePaths = QList<FilePath>;
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT FileUtils {
|
||||
public:
|
||||
#ifdef QT_GUI_LIB
|
||||
@@ -286,6 +126,8 @@ public:
|
||||
static QByteArray fileId(const FilePath &fileName);
|
||||
static FilePath homePath();
|
||||
static bool renameFile(const FilePath &srcFilePath, const FilePath &tgtFilePath);
|
||||
|
||||
static void setDeviceFileHooks(const DeviceFileHooks &hooks);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@@ -431,6 +273,8 @@ private:
|
||||
bool m_autoRemove = true;
|
||||
};
|
||||
|
||||
QTCREATOR_UTILS_EXPORT QTextStream &operator<<(QTextStream &s, const FilePath &fn);
|
||||
|
||||
inline uint qHash(const Utils::FilePath &a, uint seed = 0) { return a.hash(seed); }
|
||||
|
||||
} // namespace Utils
|
||||
@@ -444,4 +288,3 @@ template<> struct QTCREATOR_UTILS_EXPORT hash<Utils::FilePath>
|
||||
};
|
||||
} // namespace std
|
||||
|
||||
Q_DECLARE_METATYPE(Utils::FilePath)
|
||||
|
||||
Reference in New Issue
Block a user