File indexing completed on 2024-05-05 17:56:55

0001 /*
0002     SPDX-FileCopyrightText: 2003 Shie Erlich <erlich@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2003 Rafi Yanai <yanai@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 FILESYSTEMPROVIDER_H
0010 #define FILESYSTEMPROVIDER_H
0011 
0012 // QtCore
0013 #include <QObject>
0014 #include <QUrl>
0015 
0016 #include <KIO/Job>
0017 
0018 #include "filesystem.h"
0019 
0020 /**
0021  * @brief Provider for virtual file systems.
0022  *
0023  * This is a singleton.
0024  */
0025 class FileSystemProvider : public QObject
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     /**
0031      * Get a filesystem implementation for the filesystem target specified by URL. oldFilesystem is returned if
0032      * the filesystem did not change.
0033      *
0034      * The filesystem instances returned by this method are already connected with this handler and will
0035      * notify each other about filesystem changes.
0036      */
0037     FileSystem *getFilesystem(const QUrl &url, FileSystem *oldFilesystem = nullptr);
0038 
0039     /**
0040      * Start a copy job for copying, moving or linking files to a destination directory.
0041      * Operation may be implemented async depending on destination filesystem.
0042      */
0043     void startCopyFiles(const QList<QUrl> &urls,
0044                         const QUrl &destination,
0045                         KIO::CopyJob::CopyMode mode = KIO::CopyJob::Copy,
0046                         bool showProgressInfo = true,
0047                         JobMan::StartMode startMode = JobMan::Default);
0048 
0049     /**
0050      * Handle file dropping. Starts a copy job for copying, moving or linking files to a destination
0051      * directory after user choose the action in a context menu.
0052      *
0053      * Operation may implemented async depending on destination filesystem.
0054      */
0055     void startDropFiles(QDropEvent *event, const QUrl &destination);
0056 
0057     /**
0058      * Start a delete job for trashing or deleting files.
0059      *
0060      * Operation implemented async.
0061      */
0062     void startDeleteFiles(const QList<QUrl> &urls, bool moveToTrash = true);
0063 
0064     static FileSystemProvider &instance();
0065     static FileSystem::FS_TYPE getFilesystemType(const QUrl &url);
0066     /** Get ACL permissions for a file */
0067     static void getACL(FileItem *file, QString &acl, QString &defAcl);
0068 
0069 public slots:
0070     /**
0071      * Notify filesystems if they are affected by changes made by another filesystem.
0072      *
0073      * Only works if filesystem is connected to this provider.
0074      *
0075      * @param directory the directory that was changed (deleted, moved, content changed,...)
0076      * @param removed whether the directory was removed
0077      */
0078     void refreshFilesystems(const QUrl &directory, bool removed);
0079 
0080 private:
0081     FileSystem *getFilesystemInstance(const QUrl &directory);
0082     FileSystem *createFilesystem(const FileSystem::FS_TYPE type);
0083     FileSystemProvider();
0084 
0085     // filesystem instances for directory independent file operations, lazy initialized
0086     FileSystem *_defaultFileSystem;
0087     FileSystem *_virtFileSystem;
0088 
0089     QList<QPointer<FileSystem>> _fileSystems;
0090 
0091     static QString getACL(const QString &path, int type);
0092 };
0093 
0094 #endif