File indexing completed on 2024-05-05 17:56:55
0001 /* 0002 SPDX-FileCopyrightText: 2000 Shie Erlich <krusader@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2000 Rafi Yanai <krusader@users.sourceforge.net> 0004 SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #ifndef DEFAULTFILESYSTEM_H 0010 #define DEFAULTFILESYSTEM_H 0011 0012 #include "filesystem.h" 0013 0014 #include <QFileSystemWatcher> 0015 0016 #include <KCoreAddons/KDirWatch> 0017 0018 /** 0019 * @brief Default filesystem implementation supporting all KIO protocols 0020 * 0021 * This filesystem implementation allows file operations and listing for all supported KIO protocols 0022 * (local and remote/network). 0023 * 0024 * Refreshing local directories is optimized for performance. 0025 * 0026 * NOTE: For detecting local file changes a filesystem watcher is used. It cannot be used for 0027 * refreshing the view after own file operations are performed because the detection is to slow 0028 * (~500ms delay between operation finished and watcher emits signals). 0029 * 0030 */ 0031 class DefaultFileSystem : public FileSystem 0032 { 0033 Q_OBJECT 0034 public: 0035 DefaultFileSystem(); 0036 0037 void copyFiles(const QList<QUrl> &urls, 0038 const QUrl &destination, 0039 KIO::CopyJob::CopyMode mode = KIO::CopyJob::Copy, 0040 bool showProgressInfo = true, 0041 JobMan::StartMode startMode = JobMan::Default) override; 0042 void dropFiles(const QUrl &destination, QDropEvent *event) override; 0043 0044 void addFiles(const QList<QUrl> &fileUrls, KIO::CopyJob::CopyMode mode, const QString &dir = "") override; 0045 void mkDir(const QString &name) override; 0046 void rename(const QString &fileName, const QString &newName) override; 0047 /// Return URL for file name - even if file does not exist. 0048 QUrl getUrl(const QString &name) const override; 0049 bool canMoveToTrash(const QStringList &) const override 0050 { 0051 return isLocal(); 0052 } 0053 0054 QString mountPoint() const override 0055 { 0056 return _mountPoint; 0057 } 0058 bool hasAutoUpdate() const override 0059 { 0060 return !_watcher.isNull(); 0061 } 0062 void updateFilesystemInfo() override; 0063 0064 protected: 0065 bool refreshInternal(const QUrl &origin, bool onlyScan) override; 0066 /** 0067 * Get the file list from the .hidden file. 0068 * 0069 * @param dir the directory containing the .hidden file 0070 * @return a list containing all files that must be hidden or an empty set 0071 * if the file cannot be read. 0072 */ 0073 QSet<QString> filesInDotHidden(const QString &dir); 0074 0075 protected slots: 0076 /// Handle result after dir listing job is finished 0077 void slotListResult(KJob *job); 0078 /// Fill directory file list with new files from the dir lister 0079 void slotAddFiles(KIO::Job *job, const KIO::UDSEntryList &entries); 0080 /// URL redirection signal from dir lister 0081 void slotRedirection(KIO::Job *job, const QUrl &url); 0082 // React to filesystem changes nofified by watcher 0083 // NOTE: the path parameter can be the directory itself or files in this directory 0084 void slotWatcherCreated(const QString &path); 0085 void slotWatcherDirty(const QString &path); 0086 void slotWatcherDeleted(const QString &path); 0087 0088 private: 0089 bool refreshLocal(const QUrl &directory, bool onlyScan); // NOTE: this is very fast 0090 FileItem *createLocalFileItem(const QString &name); 0091 /// Returns the current path with symbolic links resolved 0092 QString realPath(); 0093 static QUrl resolveRelativePath(const QUrl &url); 0094 0095 QPointer<KDirWatch> _watcher; // dir watcher used to detect changes in the current dir 0096 bool _listError; // for async operation, return list job result 0097 QString _mountPoint; // the mount point of the current dir 0098 }; 0099 0100 #endif