File indexing completed on 2024-05-12 04:19:48
0001 /* 0002 Gwenview: an image viewer 0003 Copyright 2007 Aurélien Gâteau <agateau@kde.org> 0004 0005 This program is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU General Public License 0007 as published by the Free Software Foundation; either version 2 0008 of the License, or (at your option) any later version. 0009 0010 This program is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU General Public License for more details. 0014 0015 You should have received a copy of the GNU General Public License 0016 along with this program; if not, write to the Free Software 0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0018 0019 */ 0020 #ifndef SORTEDDIRMODEL_H 0021 #define SORTEDDIRMODEL_H 0022 0023 #include <config-gwenview.h> 0024 0025 // Qt 0026 #include <QPointer> 0027 0028 // KF 0029 #include <KDirSortFilterProxyModel> 0030 0031 // Local 0032 #include <lib/gwenviewlib_export.h> 0033 #include <lib/mimetypeutils.h> 0034 0035 class KDirLister; 0036 class KFileItem; 0037 class QUrl; 0038 0039 namespace Gwenview 0040 { 0041 class AbstractSemanticInfoBackEnd; 0042 struct SortedDirModelPrivate; 0043 0044 #ifndef GWENVIEW_SEMANTICINFO_BACKEND_NONE 0045 struct SemanticInfo; 0046 #endif 0047 0048 class SortedDirModel; 0049 class GWENVIEWLIB_EXPORT AbstractSortedDirModelFilter : public QObject 0050 { 0051 public: 0052 AbstractSortedDirModelFilter(SortedDirModel *model); 0053 ~AbstractSortedDirModelFilter() override; 0054 SortedDirModel *model() const 0055 { 0056 return mModel; 0057 } 0058 0059 virtual bool needsSemanticInfo() const = 0; 0060 /** 0061 * Returns true if index should be accepted. 0062 * Warning: index is a source index of SortedDirModel 0063 */ 0064 virtual bool acceptsIndex(const QModelIndex &index) const = 0; 0065 0066 private: 0067 QPointer<SortedDirModel> mModel; 0068 }; 0069 0070 /** 0071 * This model makes it possible to show all images in a folder. 0072 * It can filter images based on name and metadata. 0073 */ 0074 class GWENVIEWLIB_EXPORT SortedDirModel : public KDirSortFilterProxyModel 0075 { 0076 Q_OBJECT 0077 public: 0078 explicit SortedDirModel(QObject *parent = nullptr); 0079 ~SortedDirModel() override; 0080 KDirLister *dirLister() const; 0081 /** 0082 * Redefines the dir lister, useful for debugging 0083 */ 0084 void setDirLister(KDirLister *); 0085 KFileItem itemForIndex(const QModelIndex &index) const; 0086 QUrl urlForIndex(const QModelIndex &index) const; 0087 KFileItem itemForSourceIndex(const QModelIndex &sourceIndex) const; 0088 QModelIndex indexForItem(const KFileItem &item) const; 0089 QModelIndex indexForUrl(const QUrl &url) const; 0090 0091 void setKindFilter(MimeTypeUtils::Kinds); 0092 MimeTypeUtils::Kinds kindFilter() const; 0093 0094 void adjustKindFilter(MimeTypeUtils::Kinds, bool set); 0095 0096 /** 0097 * A list of file extensions we should skip 0098 */ 0099 void setBlackListedExtensions(const QStringList &list); 0100 0101 void addFilter(AbstractSortedDirModelFilter *); 0102 0103 void removeFilter(AbstractSortedDirModelFilter *); 0104 0105 void reload(); 0106 0107 AbstractSemanticInfoBackEnd *semanticInfoBackEnd() const; 0108 0109 #ifndef GWENVIEW_SEMANTICINFO_BACKEND_NONE 0110 SemanticInfo semanticInfoForSourceIndex(const QModelIndex &sourceIndex) const; 0111 #endif 0112 0113 bool hasDocuments() const; 0114 0115 public Q_SLOTS: 0116 void applyFilters(); 0117 0118 protected: 0119 bool filterAcceptsRow(int row, const QModelIndex &parent) const override; 0120 bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; 0121 0122 private Q_SLOTS: 0123 void doApplyFilters(); 0124 0125 private: 0126 friend struct SortedDirModelPrivate; 0127 SortedDirModelPrivate *const d; 0128 }; 0129 0130 } // namespace 0131 0132 #endif /* SORTEDDIRMODEL_H */