Defining a function as virtual in FileAccess is intended to allow testing sub classes to be written more easily. This way the test can use a moc class that emulates the needed conditions with no actual file being present. This would otherwise be a technical and logistical nightmare. */
| 36 | actual file being present. This would otherwise be a technical and logistical nightmare. |
| 37 | */ |
| 38 | class FileAccess |
| 39 | { |
| 40 | public: |
| 41 | FileAccess(); |
| 42 | |
| 43 | FileAccess(const FileAccess&); |
| 44 | FileAccess(FileAccess&&) noexcept; |
| 45 | FileAccess& operator=(const FileAccess&); |
| 46 | FileAccess& operator=(FileAccess&&) noexcept; |
| 47 | virtual ~FileAccess(); |
| 48 | explicit FileAccess(const QString& name, bool bWantToWrite = false); // name: local file or dirname or url (when supported) |
| 49 | |
| 50 | explicit FileAccess(const QUrl& name, bool bWantToWrite = false); // name: local file or dirname or url (when supported) |
| 51 | void setFile(const QString& name, bool bWantToWrite = false); |
| 52 | void setFile(const QUrl& url, bool bWantToWrite = false); |
| 53 | void setFile(FileAccess* pParent, const QFileInfo& fi); |
| 54 | |
| 55 | virtual void loadData(); |
| 56 | |
| 57 | [[nodiscard]] bool isNormal() const; |
| 58 | [[nodiscard]] bool isValid() const; |
| 59 | [[nodiscard]] bool isBrokenLink() const { return m_bBrokenLink; } |
| 60 | [[nodiscard]] virtual bool isFile() const; |
| 61 | [[nodiscard]] virtual bool isDir() const; |
| 62 | [[nodiscard]] virtual bool isSymLink() const; |
| 63 | [[nodiscard]] virtual bool exists() const; |
| 64 | [[nodiscard]] virtual qint64 size() const; // Size as returned by stat(). |
| 65 | [[nodiscard]] virtual qint64 sizeForReading(); // If the size can't be determined by stat() then the file is copied to a local temp file. |
| 66 | [[nodiscard]] virtual bool isReadable() const; |
| 67 | [[nodiscard]] virtual bool isWritable() const; |
| 68 | [[nodiscard]] virtual bool isExecutable() const; |
| 69 | [[nodiscard]] virtual bool isHidden() const; |
| 70 | [[nodiscard]] const QString& readLink() const; |
| 71 | |
| 72 | [[nodiscard]] const QDateTime& lastModified() const; |
| 73 | |
| 74 | [[nodiscard]] const QString& displayName() const { return mDisplayName.isEmpty() ? fileName() : mDisplayName; } |
| 75 | [[nodiscard]] const QString& fileName(bool needTmp = false) const; // Just the name-part of the path, without parent directories |
| 76 | [[nodiscard]] QString fileRelPath() const; // The path relative to base comparison directory |
| 77 | [[nodiscard]] QString prettyAbsPath() const; |
| 78 | [[nodiscard]] const QUrl& url() const; |
| 79 | void setUrl(const QUrl& inUrl) { m_url = inUrl; } |
| 80 | |
| 81 | //Workaround for QUrl::toDisplayString/QUrl::toString behavior that does not fit KDiff3's expectations |
| 82 | [[nodiscard]] QString absoluteFilePath() const; |
| 83 | [[nodiscard]] static QString prettyAbsPath(const QUrl& url) |
| 84 | { |
| 85 | if(!isLocal(url)) return url.toDisplayString(); |
| 86 | |
| 87 | //work around for bad path in windows drop event urls. (Qt 5.15.2 affected) |
| 88 | const QString path = url.toLocalFile(); |
| 89 | if(!path.isEmpty() && !path.startsWith('/')) |
| 90 | return path; |
| 91 | |
| 92 | return QFileInfo(url.path()).absoluteFilePath(); |
| 93 | } |
| 94 | |
| 95 | //Workaround for QUrl::isLocalFile behavior that does not fit KDiff3's expectations. |