File indexing completed on 2024-11-10 07:31:57

0001 /***************************************************************************
0002  *   Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net>                     *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  *                                                                         *
0009  *   This program is distributed in the hope that it will be useful,       *
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0012  *   GNU General Public License for more details.                          *
0013  *                                                                         *
0014  *   You should have received a copy of the GNU General Public License     *
0015  *   along with this program; if not, write to the                         *
0016  *   Free Software Foundation, Inc.,                                       *
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
0018  ***************************************************************************/
0019 
0020 #ifndef KGET_SORTFILTERPROXYMODEL_H
0021 #define KGET_SORTFILTERPROXYMODEL_H
0022 
0023 #include <QSortFilterProxyModel>
0024 
0025 class KGetSortFilterProxyModel : public QSortFilterProxyModel
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     explicit KGetSortFilterProxyModel(int sortColumn, QObject *parent = nullptr);
0031     ~KGetSortFilterProxyModel() override;
0032 
0033     enum DownloadFilterType { NoFilter, VideoFiles, AudioFiles, CompressedFiles, ImageFiles };
0034 
0035     enum FilterMode { Contain, DoesNotContain };
0036 
0037     void setFilterType(int filterType);
0038     void setFilterMode(int filterMode);
0039     void setFilterColumn(int column);
0040     bool showWebContent() const;
0041 
0042 public Q_SLOTS:
0043     void setShowWebContent(bool show);
0044     void setShowWebContent(int show);
0045 
0046 protected:
0047     bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
0048 
0049 private:
0050     /**
0051      * Returns true if text should be accepted by the filter
0052      */
0053     bool acceptText(const QString &text) const;
0054 
0055     /**
0056      * @param row to get the column from
0057      * @return string for the column that is being filtered
0058      */
0059     QString columnText(int row, const QModelIndex &sourceParent) const;
0060 
0061 private:
0062     int m_filterType;
0063     FilterMode m_filterMode;
0064     int m_column;
0065     bool m_showWebContent;
0066     QHash<int, QString> m_mimeTypes;
0067 };
0068 
0069 #endif // KGET_SORTFILTERPROXYMODEL_H