1 /**************************************************************************
2 * Otter Browser: Web browser controlled by the user, not vice-versa.
3 * Copyright (C) 2013 - 2018 Michal Dutkiewicz aka Emdek <michal@emdek.pl>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 **************************************************************************/
19 
20 #ifndef OTTER_CONTENTSWIDGET_H
21 #define OTTER_CONTENTSWIDGET_H
22 
23 #include "WebWidget.h"
24 
25 #include <QtCore/QPointer>
26 
27 namespace Otter
28 {
29 
30 class ContentsDialog;
31 class Window;
32 
33 class ContentsWidget : public QWidget, public ActionExecutor
34 {
35 	Q_OBJECT
36 
37 public:
38 	explicit ContentsWidget(const QVariantMap &parameters, Window *window, QWidget *parent);
39 
40 	virtual void setParent(Window *window);
41 	virtual ContentsWidget* clone(bool cloneHistory = true) const;
42 	virtual WebWidget* getWebWidget() const;
43 	Window* getWindow() const;
44 	virtual QString parseQuery(const QString &query) const;
45 	virtual QString getTitle() const = 0;
46 	virtual QString getDescription() const;
47 	virtual QString getVersion() const;
48 	virtual QString getStatusMessage() const;
49 	virtual QLatin1String getType() const = 0;
50 	virtual QVariant getOption(int identifier) const;
51 	virtual QUrl getUrl() const = 0;
52 	virtual QIcon getIcon() const = 0;
53 	virtual QPixmap createThumbnail();
54 	ActionsManager::ActionDefinition::State getActionState(int identifier, const QVariantMap &parameters = {}) const override;
55 	virtual WindowHistoryInformation getHistory() const;
56 	virtual WebWidget::ContentStates getContentState() const;
57 	virtual WebWidget::LoadingState getLoadingState() const;
58 	int getSidebar() const;
59 	virtual int getZoom() const;
60 	virtual bool canClone() const;
61 	virtual bool canZoom() const;
62 	virtual bool isPrivate() const;
63 	bool isSidebarPanel() const;
64 
65 public slots:
66 	virtual void triggerAction(int identifier, const QVariantMap &parameters = {}, ActionsManager::TriggerType trigger = ActionsManager::UnknownTrigger) override;
67 	virtual void print(QPrinter *printer);
68 	void showDialog(ContentsDialog *dialog, bool lockEventLoop = true);
69 	virtual void setOption(int identifier, const QVariant &value);
70 	virtual void setHistory(const WindowHistoryInformation &history);
71 	virtual void setZoom(int zoom);
72 	virtual void setUrl(const QUrl &url, bool isTyped = true);
73 
74 protected:
75 	void timerEvent(QTimerEvent *event) override;
76 	void changeEvent(QEvent *event) override;
77 	void showEvent(QShowEvent *event) override;
78 	void resizeEvent(QResizeEvent *event) override;
79 	void mousePressEvent(QMouseEvent *event) override;
80 	void mouseReleaseEvent(QMouseEvent *event) override;
81 
82 protected slots:
83 	void handleAboutToClose();
84 	void handleDialogFinished();
85 
86 private:
87 	Window *m_window;
88 	QWidget *m_layer;
89 	QVector<QPointer<ContentsDialog> > m_dialogs;
90 	int m_layerTimer;
91 	int m_sidebar;
92 
93 signals:
94 	void aboutToNavigate();
95 	void needsAttention();
96 	void requestedNewWindow(ContentsWidget *widget, SessionsManager::OpenHints hints, const QVariantMap &parameters);
97 	void requestedSearch(const QString &query, const QString &search, SessionsManager::OpenHints hints);
98 	void requestedGeometryChange(const QRect &geometry);
99 	void webWidgetChanged();
100 	void statusMessageChanged(const QString &message);
101 	void titleChanged(const QString &title);
102 	void urlChanged(const QUrl &url);
103 	void iconChanged(const QIcon &icon);
104 	void requestBlocked(const NetworkManager::ResourceInformation &request);
105 	void arbitraryActionsStateChanged(const QVector<int> &identifiers);
106 	void categorizedActionsStateChanged(const QVector<int> &categories);
107 	void contentStateChanged(WebWidget::ContentStates state);
108 	void loadingStateChanged(WebWidget::LoadingState state);
109 	void pageInformationChanged(WebWidget::PageInformation, const QVariant &value);
110 	void optionChanged(int identifier, const QVariant &value);
111 	void zoomChanged(int zoom);
112 	void canZoomChanged(bool isAllowed);
113 };
114 
115 }
116 
117 #endif
118