File indexing completed on 2024-05-12 04:57:52

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2010-2018 David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #ifndef BROWSERWINDOW_H
0019 #define BROWSERWINDOW_H
0020 
0021 #include <QMainWindow>
0022 #include <QPointer>
0023 #include <QUrl>
0024 
0025 #include "webtab.h"
0026 #include "qzcommon.h"
0027 
0028 class QLabel;
0029 class QVBoxLayout;
0030 class QSplitter;
0031 class QWebEngineFrame;
0032 class QTimer;
0033 
0034 class Menu;
0035 class MainMenu;
0036 class TabWidget;
0037 class TabbedWebView;
0038 class LineEdit;
0039 class HistoryMenu;
0040 class BookmarksMenu;
0041 class BookmarksToolbar;
0042 class AutoFill;
0043 class MainApplication;
0044 class WebView;
0045 class WebPage;
0046 class SideBar;
0047 class SideBarManager;
0048 class ProgressBar;
0049 class StatusBar;
0050 class NavigationBar;
0051 class NavigationContainer;
0052 class ClickableLabel;
0053 class LocationBar;
0054 class TabModel;
0055 class TabMruModel;
0056 
0057 class FALKON_EXPORT BrowserWindow : public QMainWindow
0058 {
0059     Q_OBJECT
0060 
0061 public:
0062     struct SavedWindow {
0063         QByteArray windowState;
0064         QByteArray windowGeometry;
0065         QHash<QString, QVariant> windowUiState;
0066         int virtualDesktop = -1;
0067         int currentTab = -1;
0068         QVector<WebTab::SavedTab> tabs;
0069 
0070         SavedWindow();
0071         SavedWindow(BrowserWindow *window);
0072 
0073         bool isValid() const;
0074         void clear();
0075 
0076         friend FALKON_EXPORT QDataStream &operator<<(QDataStream &stream, const SavedWindow &window);
0077         friend FALKON_EXPORT QDataStream &operator>>(QDataStream &stream, SavedWindow &window);
0078     };
0079 
0080     explicit BrowserWindow(Qz::BrowserWindowType type, const QUrl &url = QUrl());
0081     ~BrowserWindow() override;
0082 
0083     void setStartTab(WebTab* tab);
0084     void setStartPage(WebPage* page);
0085 
0086     void restoreWindow(const SavedWindow &window);
0087 
0088     bool fullScreenNavigationVisible() const;
0089     void showNavigationWithFullScreen();
0090     void hideNavigationWithFullScreen();
0091 
0092     void currentTabChanged();
0093     void updateLoadingActions();
0094 
0095     void addBookmark(const QUrl &url, const QString &title);
0096     void addDeleteOnCloseWidget(QWidget* widget);
0097 
0098     void createToolbarsMenu(QMenu* menu);
0099     void createSidebarsMenu(QMenu* menu);
0100     void createEncodingMenu(QMenu* menu);
0101 
0102     void removeActions(const QList<QAction*> &actions);
0103 
0104     SideBar* addSideBar();
0105     void saveSideBarSettings();
0106 
0107     int tabCount() const;
0108     TabbedWebView* weView() const;
0109     TabbedWebView* weView(int index) const;
0110 
0111     Qz::BrowserWindowType windowType() const;
0112     LocationBar* locationBar() const;
0113     TabWidget* tabWidget() const;
0114     BookmarksToolbar* bookmarksToolbar() const;
0115     StatusBar* statusBar() const;
0116     NavigationBar* navigationBar() const;
0117     SideBarManager* sideBarManager() const;
0118     QLabel* ipLabel() const;
0119     QMenu* superMenu() const;
0120 
0121     QUrl homepageUrl() const;
0122 
0123     QAction* action(const QString &name) const;
0124 
0125     TabModel *tabModel() const;
0126     TabMruModel *tabMruModel() const;
0127 
0128 Q_SIGNALS:
0129     void startingCompleted();
0130     void aboutToClose();
0131 
0132 public Q_SLOTS:
0133     void addTab();
0134 
0135     void goHome();
0136     void goHomeInNewTab();
0137     void goBack();
0138     void goForward();
0139 
0140     void reload();
0141     void reloadBypassCache();
0142 
0143     void setWindowTitle(const QString &t);
0144 
0145     void showWebInspector();
0146     void toggleWebInspector();
0147     void showHistoryManager();
0148 
0149     void toggleShowMenubar();
0150     void toggleShowStatusBar();
0151     void toggleShowBookmarksToolbar();
0152     void toggleShowNavigationToolbar();
0153     void toggleTabsOnTop(bool enable);
0154 
0155     void toggleFullScreen();
0156     void requestHtmlFullScreen(TabbedWebView *view, bool enable);
0157 
0158     void loadActionUrl(QObject* obj = nullptr);
0159     void loadActionUrlInNewTab(QObject* obj = nullptr);
0160 
0161     void bookmarkPage();
0162     void bookmarkAllTabs();
0163     void loadAddress(const QUrl &url);
0164     void showSource(WebView *view = nullptr);
0165 
0166 private Q_SLOTS:
0167     void openLocation();
0168     void openFile();
0169     void closeWindow();
0170     void closeTab();
0171     void loadSettings();
0172     void postLaunch();
0173 
0174     void webSearch();
0175     void searchOnPage();
0176     void changeEncoding();
0177     void printPage();
0178 
0179     void saveSettings();
0180     void hideNavigationSlot();
0181 
0182 private:
0183     bool event(QEvent* event) override;
0184     void resizeEvent(QResizeEvent* event) override;
0185     void keyPressEvent(QKeyEvent* event) override;
0186     void keyReleaseEvent(QKeyEvent* event) override;
0187     void closeEvent(QCloseEvent* event) override;
0188 
0189     void setupUi();
0190     void setupMenu();
0191     void updateStartupFocus();
0192 
0193     QAction *createEncodingAction(const QString &codecName, const QString &activeCodecName, QMenu *menu);
0194     void createEncodingSubMenu(const QString &name, QStringList &codecNames, QMenu *menu);
0195 
0196     QHash<QString, QVariant> saveUiState();
0197     void restoreUiState(const QHash<QString, QVariant> &state);
0198 
0199     QUrl m_startUrl;
0200     QUrl m_homepage;
0201     Qz::BrowserWindowType m_windowType;
0202     WebTab* m_startTab;
0203     WebPage* m_startPage;
0204 
0205     QVBoxLayout* m_mainLayout;
0206     QSplitter* m_mainSplitter;
0207 
0208     TabWidget* m_tabWidget;
0209     QPointer<SideBar> m_sideBar;
0210     SideBarManager* m_sideBarManager;
0211     StatusBar* m_statusBar;
0212 
0213     NavigationContainer* m_navigationContainer;
0214     NavigationBar* m_navigationToolbar;
0215     BookmarksToolbar* m_bookmarksToolbar;
0216 
0217     ProgressBar* m_progressBar;
0218     QLabel* m_ipLabel;
0219 
0220     QMenu* m_superMenu;
0221     MainMenu* m_mainMenu;
0222 
0223     TabModel *m_tabModel = nullptr;
0224     TabMruModel *m_tabMruModel = nullptr;
0225 
0226     int m_sideBarWidth;
0227     int m_webViewWidth;
0228 
0229     // Shortcuts
0230     bool m_useTabNumberShortcuts;
0231     bool m_useSpeedDialNumberShortcuts;
0232     bool m_useSingleKeyShortcuts;
0233 
0234     // Remember visibility of menubar and statusbar after entering Fullscreen
0235     bool m_menuBarVisible;
0236     bool m_statusBarVisible;
0237     QPointer<TabbedWebView> m_htmlFullScreenView;
0238     QTimer* m_hideNavigationTimer;
0239 
0240     QList<QPointer<QWidget> > m_deleteOnCloseWidgets;
0241 
0242 #ifdef QZ_WS_X11
0243 private:
0244     int getCurrentVirtualDesktop() const;
0245     void moveToVirtualDesktop(int desktopId);
0246 #endif
0247 };
0248 
0249 #endif // BROWSERWINDOW_H