diff --git a/containments/desktop/package/contents/ui/ConfigFilter.qml b/containments/desktop/package/contents/ui/ConfigFilter.qml index 00c27b8d4..497fc7426 100644 --- a/containments/desktop/package/contents/ui/ConfigFilter.qml +++ b/containments/desktop/package/contents/ui/ConfigFilter.qml @@ -1,159 +1,166 @@ /*************************************************************************** * Copyright (C) 2014 by Eike Hein * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ import QtQuick 2.0 import QtQuick.Controls 1.0 import QtQuick.Layouts 1.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.private.desktopcontainment.folder 0.1 as Folder Item { id: configIcons width: childrenRect.width height: childrenRect.height property alias cfg_filterMode: filterMode.currentIndex property alias cfg_filterPattern: filterPattern.text property alias cfg_filterMimeTypes: mimeTypesModel.checkedTypes - Folder.FilterableMimeTypesModel { - id: mimeTypesModel + PlasmaCore.SortFilterModel { + id: filderedMimeTypesModel - filter: mimeFilter.text + sourceModel: Folder.MimeTypesModel { + id: mimeTypesModel + } + + // SortFilterModel doesn't have a case-sensitivity option + // but filterRegExp always causes case-insensitive sorting. + filterRegExp: mimeFilter.text + filterRole: "display" } ColumnLayout { width: parent.width height: parent.height ComboBox { id: filterMode Layout.fillWidth: true model: [i18n("Show All Files"), i18n("Show Files Matching"), i18n("Hide Files Matching")] } Label { Layout.fillWidth: true text: i18n("File name pattern:") } TextField { id: filterPattern Layout.fillWidth: true enabled: (filterMode.currentIndex > 0) } Label { Layout.fillWidth: true text: i18n("File types:") } TextField { id: mimeFilter Layout.fillWidth: true enabled: (filterMode.currentIndex > 0) placeholderText: i18n("Search file type...") } RowLayout { Layout.fillWidth: true Layout.fillHeight: true ScrollView { Layout.fillWidth: true Layout.fillHeight: true frameVisible: true enabled: (filterMode.currentIndex > 0) ListView { - model: mimeTypesModel + model: filderedMimeTypesModel delegate: RowLayout { CheckBox { Layout.maximumWidth: 18 // FIXME HACK: Use actual radio button width. checked: model.checked onCheckedChanged: model.checked = checked } PlasmaCore.IconItem { anchors.verticalCenter: parent.verticalCenter width: units.iconSizes.small height: units.iconSizes.small Layout.maximumWidth: width Layout.maximumHeight: height source: model.decoration } Label { Layout.fillWidth: true text: model.display } } } } ColumnLayout { Layout.alignment: Qt.AlignTop Button { Layout.fillWidth: true enabled: (filterMode.currentIndex > 0) text: i18n("Select All") onClicked: { mimeTypesModel.checkAll(); } } Button { Layout.fillWidth: true enabled: (filterMode.currentIndex > 0) text: i18n("Deselect All") onClicked: { mimeTypesModel.checkedTypes = ""; } } } } } } diff --git a/containments/desktop/plugins/folder/folderplugin.cpp b/containments/desktop/plugins/folder/folderplugin.cpp index 9b21e0feb..5bc7e1e58 100644 --- a/containments/desktop/plugins/folder/folderplugin.cpp +++ b/containments/desktop/plugins/folder/folderplugin.cpp @@ -1,56 +1,56 @@ /*************************************************************************** * Copyright (C) 2014 by Eike Hein * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "folderplugin.h" #include "directorypicker.h" #include "foldermodel.h" #include "itemviewadapter.h" #include "labelgenerator.h" #include "menuhelper.h" #include "mimetypesmodel.h" #include "placesmodel.h" #include "positioner.h" #include "previewpluginsmodel.h" #include "rubberband.h" #include "subdialog.h" #include "viewpropertiesmenu.h" #include "wheelinterceptor.h" #include "shortcut.h" #include void FolderPlugin::registerTypes(const char *uri) { Q_ASSERT(uri == QLatin1String("org.kde.private.desktopcontainment.folder")); qmlRegisterType(uri, 0, 1, "DirectoryPicker"); qmlRegisterType(uri, 0, 1, "FolderModel"); qmlRegisterType(uri, 0, 1, "ItemViewAdapter"); qmlRegisterType(uri, 0, 1, "LabelGenerator"); qmlRegisterType(uri, 0, 1, "MenuHelper"); - qmlRegisterType(uri, 0, 1, "FilterableMimeTypesModel"); + qmlRegisterType(uri, 0, 1, "MimeTypesModel"); qmlRegisterType(uri, 0, 1, "PlacesModel"); qmlRegisterType(uri, 0, 1, "Positioner"); qmlRegisterType(uri, 0, 1, "PreviewPluginsModel"); qmlRegisterType(uri, 0, 1, "RubberBand"); qmlRegisterType(uri, 0, 1, "SubDialog"); qmlRegisterType(uri, 0, 1, "ViewPropertiesMenu"); qmlRegisterType(uri, 0, 1, "WheelInterceptor"); qmlRegisterType(uri, 0, 1, "ShortCut"); } diff --git a/containments/desktop/plugins/folder/mimetypesmodel.cpp b/containments/desktop/plugins/folder/mimetypesmodel.cpp index 71d8821d1..4e841fc26 100644 --- a/containments/desktop/plugins/folder/mimetypesmodel.cpp +++ b/containments/desktop/plugins/folder/mimetypesmodel.cpp @@ -1,194 +1,149 @@ /*************************************************************************** * Copyright (C) 2014 by Eike Hein * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "mimetypesmodel.h" #include static bool lessThan(const QMimeType &a, const QMimeType &b) { return QString::localeAwareCompare(a.name(), b.name()) < 0; } MimeTypesModel::MimeTypesModel(QObject *parent) : QAbstractListModel(parent) { QMimeDatabase db; m_mimeTypesList = db.allMimeTypes(); qStableSort(m_mimeTypesList.begin(), m_mimeTypesList.end(), lessThan); checkedRows = QVector(m_mimeTypesList.size(), false); } MimeTypesModel::~MimeTypesModel() { } QHash MimeTypesModel::roleNames() const { return { { Qt::DisplayRole, "display" }, { Qt::DecorationRole, "decoration" }, { Qt::CheckStateRole, "checked" } }; } QVariant MimeTypesModel::data(const QModelIndex &index, int role) const { if (index.row() < 0 || index.row() >= m_mimeTypesList.size()) { return QVariant(); } switch (role) { case Qt::DisplayRole: return m_mimeTypesList.at(index.row()).name(); case Qt::DecorationRole: { QString icon = m_mimeTypesList.at(index.row()).iconName(); if (icon.isEmpty()) { icon = m_mimeTypesList.at(index.row()).genericIconName(); } return icon; } case Qt::CheckStateRole: return checkedRows.at(index.row()) ? Qt::Checked : Qt::Unchecked; } return QVariant(); } bool MimeTypesModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (index.row() < 0 || index.row() >= m_mimeTypesList.size()) { return false; } if (role == Qt::CheckStateRole) { const bool newChecked = value.toBool(); if (checkedRows.at(index.row()) != newChecked) { checkedRows[index.row()] = newChecked; emit dataChanged(index, index, {role}); emit checkedTypesChanged(); return true; } } return false; } void MimeTypesModel::checkAll() { checkedRows = QVector(m_mimeTypesList.size(), true); emit dataChanged(index(0, 0), index(m_mimeTypesList.size() - 1, 0)); emit checkedTypesChanged(); } int MimeTypesModel::indexOfType(const QString &name) const { for (int i = 0; i < m_mimeTypesList.size(); i++) { if (m_mimeTypesList.at(i).name() == name) { return i; } } return -1; } QStringList MimeTypesModel::checkedTypes() const { QStringList list; for (int i =0; i < checkedRows.size(); ++i) { if (checkedRows.at(i)) { list.append(m_mimeTypesList.at(i).name()); } } if (!list.isEmpty()) { return list; } return QStringList(QLatin1String("")); } void MimeTypesModel::setCheckedTypes(const QStringList &list) { checkedRows = QVector(m_mimeTypesList.size(), false); foreach (const QString &name, list) { const int row = indexOfType(name); if (row != -1) { checkedRows[row] = true; } } emit dataChanged(index(0, 0), index(m_mimeTypesList.size() - 1, 0)); emit checkedTypesChanged(); } - -FilterableMimeTypesModel::FilterableMimeTypesModel(QObject *parent) : QSortFilterProxyModel(parent), - m_sourceModel(new MimeTypesModel(this)) -{ - setSourceModel(m_sourceModel); - setDynamicSortFilter(true); - - connect(m_sourceModel, &MimeTypesModel::checkedTypesChanged, this, &FilterableMimeTypesModel::checkedTypesChanged); -} - -FilterableMimeTypesModel::~FilterableMimeTypesModel() -{ -} - -void FilterableMimeTypesModel::checkAll() -{ - m_sourceModel->checkAll(); -} - -QStringList FilterableMimeTypesModel::checkedTypes() const -{ - return m_sourceModel->checkedTypes(); -} - -void FilterableMimeTypesModel::setCheckedTypes(const QStringList &list) -{ - m_sourceModel->setCheckedTypes(list); -} - -QString FilterableMimeTypesModel::filter() const -{ - return m_filter; -} - -void FilterableMimeTypesModel::setFilter(const QString &filter) -{ - if (m_filter != filter) { - m_filter = filter; - - setFilterFixedString(m_filter); - - emit filterChanged(); - } -} - diff --git a/containments/desktop/plugins/folder/mimetypesmodel.h b/containments/desktop/plugins/folder/mimetypesmodel.h index 531106251..6d0d66f50 100644 --- a/containments/desktop/plugins/folder/mimetypesmodel.h +++ b/containments/desktop/plugins/folder/mimetypesmodel.h @@ -1,88 +1,60 @@ /*************************************************************************** * Copyright (C) 2014 by Eike Hein * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #ifndef MIMETYPESMODEL_H #define MIMETYPESMODEL_H #include #include #include class QStringList; class MimeTypesModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(QStringList checkedTypes READ checkedTypes WRITE setCheckedTypes NOTIFY checkedTypesChanged) public: MimeTypesModel(QObject *parent = 0); ~MimeTypesModel(); QHash roleNames() const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; bool setData(const QModelIndex &index, const QVariant &value, int role) Q_DECL_OVERRIDE; Q_INVOKABLE void checkAll(); int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE { Q_UNUSED(parent) return m_mimeTypesList.size(); } QStringList checkedTypes() const; void setCheckedTypes(const QStringList &list); Q_SIGNALS: void checkedTypesChanged() const; private: int indexOfType(const QString &name) const; QList m_mimeTypesList; QVector checkedRows; }; -class FilterableMimeTypesModel : public QSortFilterProxyModel -{ - Q_OBJECT - - Q_PROPERTY(QStringList checkedTypes READ checkedTypes WRITE setCheckedTypes NOTIFY checkedTypesChanged) - Q_PROPERTY(QString filter READ filter WRITE setFilter NOTIFY filterChanged) - - public: - FilterableMimeTypesModel(QObject *parent = 0); - ~FilterableMimeTypesModel(); - - Q_INVOKABLE void checkAll(); - - QStringList checkedTypes() const; - void setCheckedTypes(const QStringList &list); - - QString filter() const; - void setFilter(const QString &filter); - - Q_SIGNALS: - void checkedTypesChanged() const; - void filterChanged() const; - - private: - MimeTypesModel *m_sourceModel; - QString m_filter; -}; - #endif