File indexing completed on 2024-04-14 05:43:37
0001 /* 0002 * Copyright 2016 Boudhayan Gupta <bgupta@kde.org> 0003 * 0004 * Redistribution and use in source and binary forms, with or without 0005 * modification, are permitted provided that the following conditions 0006 * are met: 0007 * 0008 * 1. Redistributions of source code must retain the above copyright 0009 * notice, this list of conditions and the following disclaimer. 0010 * 2. Redistributions in binary form must reproduce the above copyright 0011 * notice, this list of conditions and the following disclaimer in the 0012 * documentation and/or other materials provided with the distribution. 0013 * 3. Neither the name of KDE e.V. (or its successor approved by the 0014 * membership of KDE e.V.) nor the names of its contributors may be used 0015 * to endorse or promote products derived from this software without 0016 * specific prior written permission. 0017 * 0018 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 0019 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0020 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 0021 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 0022 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 0023 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0024 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0025 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0026 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 0027 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0028 */ 0029 0030 #ifndef STASHFS_H 0031 #define STASHFS_H 0032 0033 #include <QDebug> 0034 #include <QHash> 0035 #include <QObject> 0036 #include <QPointer> 0037 #include <QString> 0038 0039 class StashFileSystem : public QObject 0040 { 0041 Q_OBJECT 0042 0043 public: 0044 enum NodeType { 0045 DirectoryNode, 0046 SymlinkNode, 0047 FileNode, 0048 InvalidNode, 0049 }; 0050 0051 struct StashNodeData; 0052 0053 typedef QHash<QString, StashNodeData> StashNode; 0054 0055 struct StashNodeData { 0056 StashNodeData(NodeType ntype) 0057 : type(ntype) 0058 , children(nullptr) 0059 { 0060 } 0061 ~StashNodeData() 0062 { 0063 } 0064 0065 NodeType type; 0066 QString source; 0067 StashFileSystem::StashNode *children; 0068 }; 0069 0070 explicit StashFileSystem(QObject *parent = nullptr); 0071 virtual ~StashFileSystem(); 0072 0073 QStringList findNodesFromPath(const QString &path); 0074 0075 bool delEntry(const QString &path); 0076 bool addFile(const QString &src, const QString &dest); 0077 bool addFolder(const QString &dest); 0078 bool addSymlink(const QString &src, const QString &dest); 0079 bool copyFile(const QString &src, const QString &dest); 0080 void deleteAllItems(); 0081 0082 // Finds the node object for the given path in the SFS 0083 StashNodeData findNode(const QString &path); 0084 StashNodeData findNode(const QStringList &path); 0085 0086 StashNodeData getRoot(); 0087 void findPathFromSource(const QString &path, const QString &dir, QStringList &fileList, StashNode *node); 0088 0089 // For debug purposes 0090 void displayNode(StashNode *node); 0091 void displayRoot(); 0092 0093 private: 0094 bool addNode(const QString &location, const StashNodeData &data); 0095 void deleteChildren(StashNodeData nodeData); 0096 QStringList splitPath(const QString &path); 0097 StashNodeData root; 0098 }; 0099 0100 #endif