File indexing completed on 2024-04-21 04:57:57

0001 /*
0002     SPDX-FileCopyrightText: 2000-2011 Dawit Alemayehu <adawit@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-only
0005 */
0006 
0007 #ifndef DIR_FILTER_PLUGIN_H
0008 #define DIR_FILTER_PLUGIN_H
0009 
0010 #include <QSet>
0011 #include <QPointer>
0012 #include <QStringList>
0013 #include <QWidget>
0014 #include <QMenu>
0015 #include <QUrl>
0016 
0017 #include <konq_kpart_plugin.h>
0018 #include <KParts/ListingFilterExtension>
0019 #include <KParts/ListingNotificationExtension>
0020 
0021 class QPushButton;
0022 class KFileItemList;
0023 class KLineEdit;
0024 namespace KParts
0025 {
0026 class ReadOnlyPart;
0027 }
0028 
0029 class FilterBar : public QWidget
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034     explicit FilterBar(QWidget *parent = nullptr);
0035     ~FilterBar() override;
0036     void selectAll();
0037 
0038     QMenu *typeFilterMenu();
0039     void setTypeFilterMenu(QMenu *);
0040 
0041     bool typeFilterMenuEnabled() const;
0042     void setEnableTypeFilterMenu(bool);
0043 
0044     void setNameFilter(const QString &);
0045 
0046 public Q_SLOTS:
0047     void clear();
0048 
0049 Q_SIGNALS:
0050     void filterChanged(const QString &nameFilter);
0051     void closeRequest();
0052 
0053 protected:
0054     void showEvent(QShowEvent *event) override;
0055     void keyReleaseEvent(QKeyEvent *event) override;
0056 
0057 private:
0058     KLineEdit *m_filterInput;
0059     QPushButton *m_typeFilterButton;
0060 };
0061 
0062 class SessionManager
0063 {
0064 public:
0065     struct Filters {
0066         QStringList typeFilters;
0067         QString nameFilter;
0068     };
0069 
0070     SessionManager();
0071     ~SessionManager();
0072     Filters restore(const QUrl &url);
0073     void save(const QUrl &url, const Filters &filters);
0074 
0075     bool showCount;
0076     bool useMultipleFilters;
0077 
0078 protected:
0079     void loadSettings();
0080     void saveSettings();
0081 
0082 private:
0083     bool m_bSettingsLoaded;
0084     QMap<QString, Filters> m_filters;
0085 };
0086 
0087 class DirFilterPlugin : public KonqParts::Plugin
0088 {
0089     Q_OBJECT
0090 
0091 public:
0092 
0093     DirFilterPlugin(QObject *parent, const QVariantList &);
0094     ~DirFilterPlugin() override;
0095 
0096 private Q_SLOTS:
0097     void slotReset();
0098     void slotOpenURL();
0099     void slotOpenURLCompleted();
0100     void slotShowPopup();
0101     void slotShowCount();
0102     void slotShowFilterBar();
0103     void slotMultipleFilters();
0104     void slotItemSelected(QAction *);
0105     void slotNameFilterChanged(const QString &);
0106     void slotCloseRequest();
0107     void slotListingEvent(KParts::ListingNotificationExtension::NotificationEventType, const KFileItemList &);
0108 
0109 private:
0110     void setFilterBar();
0111 
0112     struct MimeInfo {
0113         MimeInfo() : action(nullptr), useAsFilter(false) {}
0114 
0115         QAction *action;
0116         bool useAsFilter;
0117 
0118         QString iconName;
0119         QString mimeComment;
0120 
0121         QSet<QString> filenames;
0122     };
0123     typedef QMap<QString, MimeInfo> MimeInfoMap;
0124 
0125     FilterBar *m_filterBar;
0126     QWidget *m_focusWidget;
0127     QPointer<KParts::ReadOnlyPart> m_part;
0128     QPointer<KParts::ListingFilterExtension> m_listingExt;
0129     MimeInfoMap m_pMimeInfo;
0130 };
0131 
0132 #endif
0133