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 * Copyright (C) 2015 Piotr Wójcik <chocimier@tlen.pl>
5 * Copyright (C) 2016 - 2017 Jan Bajer aka bajasoft <jbajer@gmail.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 **************************************************************************/
21 
22 #ifndef OTTER_WINDOW_H
23 #define OTTER_WINDOW_H
24 
25 #include "ToolBarWidget.h"
26 #include "WebWidget.h"
27 #include "../core/SessionsManager.h"
28 
29 #include <QtCore/QDateTime>
30 #include <QtCore/QUrl>
31 #include <QtGui/QIcon>
32 
33 namespace Otter
34 {
35 
36 class ContentsWidget;
37 
38 class WindowToolBarWidget final : public ToolBarWidget
39 {
40 public:
41 	explicit WindowToolBarWidget(int identifier, Window *parent);
42 
43 protected:
44 	void paintEvent(QPaintEvent *event) override;
45 };
46 
47 class Window final : public QWidget, public ActionExecutor
48 {
49 	Q_OBJECT
50 
51 public:
52 	explicit Window(const QVariantMap &parameters, ContentsWidget *widget, MainWindow *mainWindow);
53 
54 	void clear();
55 	void setOption(int identifier, const QVariant &value);
56 	void setSession(const SessionWindow &session, bool deferLoading = false);
57 	Window* clone(bool cloneHistory, MainWindow *mainWindow) const;
58 	MainWindow* getMainWindow() const;
59 	WindowToolBarWidget* getAddressBar() const;
60 	ContentsWidget* getContentsWidget();
61 	WebWidget* getWebWidget();
62 	QString getTitle() const;
63 	QLatin1String getType() const;
64 	QVariant getOption(int identifier) const;
65 	QUrl getUrl() const;
66 	QIcon getIcon() const;
67 	QPixmap createThumbnail() const;
68 	QDateTime getLastActivity() const;
69 	ActionsManager::ActionDefinition::State getActionState(int identifier, const QVariantMap &parameters = {}) const override;
70 	WindowHistoryInformation getHistory() const;
71 	SessionWindow getSession() const;
72 	WindowState getWindowState() const;
73 	QSize sizeHint() const override;
74 	WebWidget::LoadingState getLoadingState() const;
75 	WebWidget::ContentStates getContentState() const;
76 	quint64 getIdentifier() const;
77 	int getZoom() const;
78 	bool canClone() const;
79 	bool canZoom() const;
80 	bool isAboutToClose() const override;
81 	bool isActive() const;
82 	bool isPinned() const;
83 	bool isPrivate() const;
84 
85 public slots:
86 	void triggerAction(int identifier, const QVariantMap &parameters = {}, ActionsManager::TriggerType trigger = ActionsManager::UnknownTrigger) override;
87 	void requestClose();
88 	void search(const QString &query, const QString &searchEngine);
89 	void markAsActive(bool updateLastActivity = true);
90 	void setUrl(const QUrl &url, bool isTyped = true);
91 	void setZoom(int zoom);
92 	void setPinned(bool isPinned);
93 
94 protected:
95 	void timerEvent(QTimerEvent *event) override;
96 	void hideEvent(QHideEvent *event) override;
97 	void focusInEvent(QFocusEvent *event) override;
98 	void updateFocus();
99 	void setContentsWidget(ContentsWidget *widget);
100 	bool event(QEvent *event) override;
101 
102 protected slots:
103 	void handleIconChanged(const QIcon &icon);
104 	void handleSearchRequest(const QString &query, const QString &searchEngine, SessionsManager::OpenHints hints = SessionsManager::DefaultOpen);
105 	void handleGeometryChangeRequest(const QRect &geometry);
106 	void handleToolBarStateChanged(int identifier, const ToolBarState &state);
107 
108 private:
109 	MainWindow *m_mainWindow;
110 	WindowToolBarWidget *m_addressBarWidget;
111 	QPointer<ContentsWidget> m_contentsWidget;
112 	QDateTime m_lastActivity;
113 	SessionWindow m_session;
114 	QVariantMap m_parameters;
115 	quint64 m_identifier;
116 	int m_suspendTimer;
117 	bool m_isAboutToClose;
118 	bool m_isPinned;
119 
120 	static quint64 m_identifierCounter;
121 
122 signals:
123 	void activated();
124 	void aboutToClose();
125 	void aboutToNavigate();
126 	void needsAttention();
127 	void requestedSearch(const QString &query, const QString &searchEngine, SessionsManager::OpenHints hints = SessionsManager::DefaultOpen);
128 	void requestedNewWindow(ContentsWidget *widget, SessionsManager::OpenHints hints, const QVariantMap &parameters);
129 	void requestedCloseWindow(Window *window);
130 	void statusMessageChanged(const QString &message);
131 	void titleChanged(const QString &title);
132 	void urlChanged(const QUrl &url, bool force);
133 	void iconChanged(const QIcon &icon);
134 	void requestBlocked(const NetworkManager::ResourceInformation &request);
135 	void actionsStateChanged();
136 	void arbitraryActionsStateChanged(const QVector<int> &identifiers);
137 	void categorizedActionsStateChanged(const QVector<int> &categories);
138 	void contentStateChanged(WebWidget::ContentStates state);
139 	void loadingStateChanged(WebWidget::LoadingState state);
140 	void pageInformationChanged(WebWidget::PageInformation, const QVariant &value);
141 	void optionChanged(int identifier, const QVariant &value);
142 	void zoomChanged(int zoom);
143 	void canZoomChanged(bool isAllowed);
144 	void isPinnedChanged(bool isPinned);
145 };
146 
147 }
148 
149 #endif
150