1 /*
2     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
3 
4     SPDX-FileCopyrightText: 2010 Eike Hein <hein@kde.org>
5 */
6 
7 #ifndef URLCATCHER_H
8 #define URLCATCHER_H
9 
10 #include <QSortFilterProxyModel>
11 #include <QStandardItem>
12 
13 #include "chatwindow.h"
14 
15 
16 class QTreeView;
17 class QLineEdit;
18 class QMenu;
19 class KToolBar;
20 
21 
22 class UrlDateItem : public QStandardItem
23 {
24     public:
25         explicit UrlDateItem(const QDateTime& dateTime);
26         ~UrlDateItem() override;
27 
28         QVariant data(int role) const override;
29 
30   private:
31         Q_DISABLE_COPY(UrlDateItem)
32 };
33 
34 
35 class UrlSortFilterProxyModel : public QSortFilterProxyModel
36 {
37     Q_OBJECT
38 
39     public:
40         explicit UrlSortFilterProxyModel(QObject* parent = nullptr);
41         ~UrlSortFilterProxyModel() override;
42 
43         Qt::ItemFlags flags(const QModelIndex& index) const override;
44 
45     protected:
46         bool lessThan(const QModelIndex& left, const QModelIndex& right) const override;
47 
48     private:
49         Q_DISABLE_COPY(UrlSortFilterProxyModel)
50 };
51 
52 
53 class UrlCatcher : public ChatWindow
54 {
55     Q_OBJECT
56 
57     public:
58         explicit UrlCatcher(QWidget* parent);
59         ~UrlCatcher() override;
60 
61 
62     protected:
63         void childAdjustFocus() override;
64         bool event(QEvent* event) override;
65 
66 
67     private Q_SLOTS:
68         void updateItemActionStates();
69         void updateListActionStates();
70         void openContextMenu(const QPoint& p);
71         void openUrl(const QModelIndex& index);
72         void openSelectedUrls();
73         void saveSelectedUrls();
74         void bookmarkSelectedUrls();
75         void copySelectedUrls();
76         void deleteSelectedUrls();
77         void saveUrlModel();
78         void clearUrlModel();
79 
80         void updateFilter();
81         void startFilterTimer(const QString &filter);
82 
83     private:
84         void setupActions();
85         void setupUrlTree();
86 
87     private:
88         KToolBar* m_toolBar;
89         QMenu* m_contextMenu;
90 
91         QList<QAction*> m_itemActions;
92         QList<QAction*> m_listActions;
93 
94         QTreeView* m_urlTree;
95         QLineEdit* m_searchLine;
96         QTimer* m_filterTimer;
97 
98         Q_DISABLE_COPY(UrlCatcher)
99 };
100 
101 #endif
102