File indexing completed on 2024-04-14 03:53:35

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org>
0004     SPDX-FileCopyrightText: 2007 Pino Toscano <pino@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef OPENWITHDIALOG_P_H
0010 #define OPENWITHDIALOG_P_H
0011 
0012 #include <QAbstractItemModel>
0013 #include <QSortFilterProxyModel>
0014 #include <QTreeView>
0015 
0016 #include <memory>
0017 
0018 class KApplicationModelPrivate;
0019 
0020 /**
0021  * @internal
0022  */
0023 class KApplicationModel : public QAbstractItemModel
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     explicit KApplicationModel(QObject *parent = nullptr);
0029     ~KApplicationModel() override;
0030     bool canFetchMore(const QModelIndex &parent) const override;
0031     int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0032     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0033     void fetchMore(const QModelIndex &parent) override;
0034     //        Qt::ItemFlags flags(const QModelIndex &index) const override;
0035     bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
0036     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0037     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0038     QModelIndex parent(const QModelIndex &index) const override;
0039     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0040 
0041     QString entryPathFor(const QModelIndex &index) const;
0042     QString execFor(const QModelIndex &index) const;
0043     bool isDirectory(const QModelIndex &index) const;
0044     void fetchAll(const QModelIndex &parent);
0045 
0046 private:
0047     friend class KApplicationModelPrivate;
0048     std::unique_ptr<KApplicationModelPrivate> const d;
0049 
0050     Q_DISABLE_COPY(KApplicationModel)
0051 };
0052 
0053 /**
0054  * @internal
0055  */
0056 class QTreeViewProxyFilter : public QSortFilterProxyModel
0057 {
0058     Q_OBJECT
0059 
0060 public:
0061     explicit QTreeViewProxyFilter(QObject *parent = nullptr);
0062     bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
0063 };
0064 
0065 class KApplicationViewPrivate;
0066 
0067 /**
0068  * @internal
0069  */
0070 class KApplicationView : public QTreeView
0071 {
0072     Q_OBJECT
0073 
0074 public:
0075     explicit KApplicationView(QWidget *parent = nullptr);
0076     ~KApplicationView() override;
0077 
0078     void setModels(KApplicationModel *model, QSortFilterProxyModel *proxyModel);
0079     QSortFilterProxyModel *proxyModel();
0080 
0081     bool isDirSel() const;
0082 
0083 Q_SIGNALS:
0084     void selected(const QString &_name, const QString &_exec);
0085     void highlighted(const QString &_name, const QString &_exec);
0086 
0087 protected Q_SLOTS:
0088     void currentChanged(const QModelIndex &current, const QModelIndex &previous) override;
0089 
0090 private Q_SLOTS:
0091     void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
0092 
0093 private:
0094     friend class KApplicationViewPrivate;
0095     std::unique_ptr<KApplicationViewPrivate> const d;
0096 
0097     Q_DISABLE_COPY(KApplicationView)
0098 };
0099 
0100 #endif