1 /*****************************************************************************
2  * Copyright (C) 2003 Shie Erlich <erlich@users.sourceforge.net>             *
3  * Copyright (C) 2003 Rafi Yanai <yanai@users.sourceforge.net>               *
4  * Copyright (C) 2004-2019 Krusader Krew [https://krusader.org]              *
5  *                                                                           *
6  * This file is part of Krusader [https://krusader.org].                     *
7  *                                                                           *
8  * Krusader is free software: you can redistribute it and/or modify          *
9  * it under the terms of the GNU General Public License as published by      *
10  * the Free Software Foundation, either version 2 of the License, or         *
11  * (at your option) any later version.                                       *
12  *                                                                           *
13  * Krusader is distributed in the hope that it will be useful,               *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
16  * GNU General Public License for more details.                              *
17  *                                                                           *
18  * You should have received a copy of the GNU General Public License         *
19  * along with Krusader.  If not, see [http://www.gnu.org/licenses/].         *
20  *****************************************************************************/
21 
22 #ifndef FILESYSTEMPROVIDER_H
23 #define FILESYSTEMPROVIDER_H
24 
25 // QtCore
26 #include <QObject>
27 #include <QUrl>
28 
29 #include <KIO/Job>
30 
31 #include "filesystem.h"
32 
33 /**
34  * @brief Provider for virtual file systems.
35  *
36  * This is a singleton.
37  */
38 class FileSystemProvider : public QObject {
39     Q_OBJECT
40 
41 public:
42     /**
43      * Get a filesystem implementation for the filesystem target specified by URL. oldFilesystem is returned if
44      * the filesystem did not change.
45      *
46      * The filesystem instances returned by this method are already connected with this handler and will
47      * notify each other about filesystem changes.
48      */
49     FileSystem *getFilesystem(const QUrl &url, FileSystem *oldFilesystem = 0);
50 
51     /**
52      * Start a copy job for copying, moving or linking files to a destination directory.
53      * Operation may be implemented async depending on destination filesystem.
54      */
55     void startCopyFiles(const QList<QUrl> &urls, const QUrl &destination,
56                         KIO::CopyJob::CopyMode mode = KIO::CopyJob::Copy,
57                         bool showProgressInfo = true,
58                         JobMan::StartMode startMode = JobMan::Default);
59 
60     /**
61      * Handle file dropping. Starts a copy job for copying, moving or linking files to a destination
62      * directory after user choose the action in a context menu.
63      *
64      * Operation may implemented async depending on destination filesystem.
65      */
66     void startDropFiles(QDropEvent *event, const QUrl &destination);
67 
68     /**
69      * Start a delete job for trashing or deleting files.
70      *
71      * Operation implemented async.
72      */
73     void startDeleteFiles(const QList<QUrl> &urls, bool moveToTrash = true);
74 
75     static FileSystemProvider &instance();
76     static FileSystem::FS_TYPE getFilesystemType(const QUrl &url);
77     /** Get ACL permissions for a file */
78     static void getACL(FileItem *file, QString &acl, QString &defAcl);
79 
80 public slots:
81     /**
82      * Notify filesystems if they are affected by changes made by another filesystem.
83      *
84      * Only works if filesystem is connected to this provider.
85      *
86      * @param directory the directory that was changed (deleted, moved, content changed,...)
87      */
88     void refreshFilesystems(const QUrl &directory, bool removed);
89 
90 private:
91     FileSystem *getFilesystemInstance(const QUrl &directory);
92     FileSystem *createFilesystem(const FileSystem::FS_TYPE type);
93     FileSystemProvider();
94 
95     // filesystem instances for directory independent file operations, lazy initialized
96     FileSystem *_defaultFileSystem;
97     FileSystem *_virtFileSystem;
98 
99     QList<QPointer<FileSystem>> _fileSystems;
100 
101     static QString getACL(const QString & path, int type);
102 };
103 
104 #endif
105 
106