1 /**************************************************************************
2 ** This file is part of LiteIDE
3 **
4 ** Copyright (c) 2011-2017 LiteIDE. All rights reserved.
5 **
6 ** This library is free software; you can redistribute it and/or
7 ** modify it under the terms of the GNU Lesser General Public
8 ** License as published by the Free Software Foundation; either
9 ** version 2.1 of the License, or (at your option) any later version.
10 **
11 ** This library is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 ** Lesser General Public License for more details.
15 **
16 ** In addition, as a special exception,  that plugins developed for LiteIDE,
17 ** are allowed to remain closed sourced and can be distributed under any license .
18 ** These rights are included in the file LGPL_EXCEPTION.txt in this package.
19 **
20 **************************************************************************/
21 // Module: multifoldermodel.h
22 // Creator: visualfc <visualfc@gmail.com>
23 
24 #ifndef MULTIFOLDERMODEL_H
25 #define MULTIFOLDERMODEL_H
26 
27 #include "multiindexmodel.h"
28 #include <QDir>
29 #include <QMap>
30 #include <QFileSystemModel>
31 
32 class MultiFolderModel : public MultiIndexModel
33 {
34     Q_OBJECT
35 public:
36     explicit MultiFolderModel(QObject* parent = 0);
37     virtual ~MultiFolderModel();
38 public:
39     QModelIndex addRootPath(const QString &path);
40     void removeRootPath(const QString &path);
41     void removeRoot(const QModelIndex &index);
42 
43     bool isRootPath(const QString &path) const;
44     bool isRootIndex(const QModelIndex &index) const;
45     void clearAll();
46     void reloadAll();
47 
48     QList<QModelIndex> rootIndexs() const;
49     QStringList rootPathList() const;
50 
51     QString filePath(const QModelIndex &index) const;
52     QString fileName(const QModelIndex &index) const;
53     QFileInfo fileInfo(const QModelIndex &index) const;
54     QString fileRootPath(const QModelIndex &index) const;
55 
56     bool isDir(const QModelIndex &index) const;
57     qint64 size(const QModelIndex &index) const;
58     QString type(const QModelIndex &index) const;
59     QDateTime lastModified(const QModelIndex &index) const;
60     QFile::Permissions permissions(const QModelIndex &index) const;
61 
62     bool remove(const QModelIndex &index);
63     bool rmdir(const QModelIndex &index);
64 
65     QList<QModelIndex> indexForPath(const QString &path) const;
66     QModelIndex indexForPath(QFileSystemModel* sourceModel,const QString &path) const;
67 signals:
68     void directoryLoaded(QFileSystemModel*,QString);
69 public:
70     void setFilter(QDir::Filters filters);
71     QDir::Filters filter() const;
72 
73     void setSorting(QDir::SortFlags sort);
74     QDir::SortFlags sorting() const;
75 
76     void setResolveSymlinks(bool enable);
77     bool resolveSymlinks() const;
78 
79     void setReadOnly(bool enable);
80     bool isReadOnly() const;
81 
82     void setNameFilterDisables(bool enable);
83     bool nameFilterDisables() const;
84 
85     void setNameFilters(const QStringList &filters);
86     QStringList nameFilters() const;
87 
88     void setShowDetails(bool b);
89     bool isShowDetails() const;
90 public:
91     virtual bool lessThan(const QAbstractItemModel *sourceModel, const QModelIndex &left, const QModelIndex &right) const;
92     virtual bool filterAcceptsRow(const QAbstractItemModel *sourceModel, int source_row, const QModelIndex &source_parent) const;
93     virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
94 protected slots:
95     void slotDirectoryLoaded(const QString &path);
96 protected:
97     QDir::SortFlags m_sorts;
98     QDir::Filters   m_filters;
99     bool            m_resolveSymlinks;
100     bool            m_isReadOnly;
101     bool            m_nameFilterDisables;
102     bool            m_isShowDetails;
103     QStringList     m_nameFilters;
104 };
105 
106 #endif // MULTIFOLDERMODEL_H
107