1 /*
2    SPDX-FileCopyrightText: 2016-2021 Laurent Montel <montel@kde.org>
3 
4    SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include <QPoint>
10 #include <QString>
11 #include <QUrl>
12 namespace Akregator
13 {
14 class ArticleViewerWebEngine;
15 class URLHandlerWebEngine
16 {
17 public:
~URLHandlerWebEngine()18     virtual ~URLHandlerWebEngine()
19     {
20     }
21 
22     /**
23      * Called when LMB-clicking on a link in the reader. Should start
24      * processing equivalent to "opening" the link.
25      *
26      * @return true if the click was handled by this URLHandlerWebEngine,
27      *         false otherwise.
28      */
29     virtual bool handleClick(const QUrl &url, ArticleViewerWebEngine *w) const = 0;
30 
31     /**
32      * Called when RMB-clicking on a link in the reader. Should show
33      * a context menu at the specified point with the specified
34      * widget as parent.
35      *
36      * @return true if the right-click was handled by this
37      * URLHandlerWebEngine, false otherwise.
38      */
39     virtual bool handleContextMenuRequest(const QUrl &url, const QPoint &p, ArticleViewerWebEngine *w) const = 0;
40 
41     /**
42      * Called when hovering over a link.
43      *
44      * @return a string to be shown in the status bar while hoverin
45      * over this link.
46      */
47     virtual QString statusBarMessage(const QUrl &url, ArticleViewerWebEngine *w) const = 0;
48 };
49 
50 class AkregatorConfigHandler : public URLHandlerWebEngine
51 {
52 public:
AkregatorConfigHandler()53     AkregatorConfigHandler()
54         : URLHandlerWebEngine()
55     {
56     }
57 
~AkregatorConfigHandler()58     ~AkregatorConfigHandler() override
59     {
60     }
61 
62     Q_REQUIRED_RESULT bool handleClick(const QUrl &, ArticleViewerWebEngine *) const override;
63     Q_REQUIRED_RESULT bool handleContextMenuRequest(const QUrl &, const QPoint &, ArticleViewerWebEngine *) const override;
64     Q_REQUIRED_RESULT QString statusBarMessage(const QUrl &, ArticleViewerWebEngine *) const override;
65 };
66 
67 class MailToURLHandlerWebEngine : public URLHandlerWebEngine
68 {
69 public:
MailToURLHandlerWebEngine()70     MailToURLHandlerWebEngine()
71         : URLHandlerWebEngine()
72     {
73     }
74 
~MailToURLHandlerWebEngine()75     ~MailToURLHandlerWebEngine() override
76     {
77     }
78 
79     Q_REQUIRED_RESULT bool handleClick(const QUrl &, ArticleViewerWebEngine *) const override;
80     Q_REQUIRED_RESULT bool handleContextMenuRequest(const QUrl &, const QPoint &, ArticleViewerWebEngine *) const override;
81     Q_REQUIRED_RESULT QString statusBarMessage(const QUrl &, ArticleViewerWebEngine *) const override;
82 };
83 
84 class ActionURLHandlerWebEngine : public URLHandlerWebEngine
85 {
86 public:
ActionURLHandlerWebEngine()87     ActionURLHandlerWebEngine()
88         : URLHandlerWebEngine()
89     {
90     }
91 
~ActionURLHandlerWebEngine()92     ~ActionURLHandlerWebEngine() override
93     {
94     }
95 
96     Q_REQUIRED_RESULT bool handleClick(const QUrl &, ArticleViewerWebEngine *) const override;
97     Q_REQUIRED_RESULT bool handleContextMenuRequest(const QUrl &, const QPoint &, ArticleViewerWebEngine *) const override;
98     Q_REQUIRED_RESULT QString statusBarMessage(const QUrl &, ArticleViewerWebEngine *) const override;
99 };
100 }
101 
102