File indexing completed on 2024-05-12 04:57:53
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 MAINAPPLICATION_H 0019 #define MAINAPPLICATION_H 0020 0021 #define mApp MainApplication::instance() 0022 0023 #include <QList> 0024 #include <QPointer> 0025 0026 #include "qtsingleapplication/qtsingleapplication.h" 0027 #include "restoremanager.h" 0028 #include "qzcommon.h" 0029 0030 class QMenu; 0031 class QWebEngineProfile; 0032 class QWebEngineSettings; 0033 class QNetworkAccessManager; 0034 class QWebEngineDownloadRequest; 0035 0036 class History; 0037 class AutoFill; 0038 class MainMenu; 0039 class Bookmarks; 0040 class CookieJar; 0041 class AutoSaver; 0042 class PluginProxy; 0043 class BrowserWindow; 0044 class NetworkManager; 0045 class BrowsingLibrary; 0046 class DownloadManager; 0047 class UserAgentManager; 0048 class SearchEnginesManager; 0049 class HTML5PermissionsManager; 0050 class RegisterQAppAssociation; 0051 class DesktopNotificationsFactory; 0052 class ProxyStyle; 0053 class SessionManager; 0054 class ClosedWindowsManager; 0055 class ProtocolHandlerManager; 0056 0057 class FALKON_EXPORT MainApplication : public QtSingleApplication 0058 { 0059 Q_OBJECT 0060 0061 public: 0062 enum AfterLaunch { 0063 OpenBlankPage = 0, 0064 OpenHomePage = 1, 0065 OpenSpeedDial = 2, 0066 RestoreSession = 3, 0067 SelectSession = 4 0068 }; 0069 0070 explicit MainApplication(int &argc, char** argv); 0071 ~MainApplication(); 0072 0073 bool isClosing() const; 0074 bool isPrivate() const; 0075 bool isPortable() const; 0076 bool isStartingAfterCrash() const; 0077 0078 int windowCount() const; 0079 QList<BrowserWindow*> windows() const; 0080 0081 BrowserWindow* getWindow() const; 0082 BrowserWindow* createWindow(Qz::BrowserWindowType type, const QUrl &startUrl = QUrl()); 0083 0084 AfterLaunch afterLaunch() const; 0085 0086 void openSession(BrowserWindow* window, RestoreData &restoreData); 0087 bool restoreSession(BrowserWindow* window, RestoreData restoreData); 0088 void destroyRestoreManager(); 0089 void reloadSettings(); 0090 0091 // Name of current Qt style 0092 QString styleName() const; 0093 void setProxyStyle(ProxyStyle *style); 0094 0095 QByteArray wmClass() const; 0096 0097 History* history(); 0098 Bookmarks* bookmarks(); 0099 0100 AutoFill* autoFill(); 0101 CookieJar* cookieJar(); 0102 PluginProxy* plugins(); 0103 BrowsingLibrary* browsingLibrary(); 0104 0105 NetworkManager* networkManager(); 0106 RestoreManager* restoreManager(); 0107 SessionManager* sessionManager(); 0108 DownloadManager* downloadManager(); 0109 UserAgentManager* userAgentManager(); 0110 SearchEnginesManager* searchEnginesManager(); 0111 ClosedWindowsManager* closedWindowsManager(); 0112 ProtocolHandlerManager *protocolHandlerManager(); 0113 HTML5PermissionsManager* html5PermissionsManager(); 0114 DesktopNotificationsFactory* desktopNotifications(); 0115 QWebEngineProfile* webProfile() const; 0116 QWebEngineSettings *webSettings() const; 0117 0118 QByteArray saveState() const; 0119 0120 static MainApplication* instance(); 0121 0122 static bool isTestModeEnabled(); 0123 static void setTestModeEnabled(bool enabled); 0124 0125 public Q_SLOTS: 0126 void addNewTab(const QUrl &url = QUrl()); 0127 void startPrivateBrowsing(const QUrl &startUrl = QUrl()); 0128 0129 void reloadUserStyleSheet(); 0130 void restoreOverrideCursor(); 0131 0132 void changeOccurred(); 0133 void quitApplication(); 0134 0135 Q_SIGNALS: 0136 void settingsReloaded(); 0137 void activeWindowChanged(BrowserWindow* window); 0138 0139 private Q_SLOTS: 0140 void postLaunch(); 0141 0142 void saveSettings(); 0143 0144 void messageReceived(const QString &message); 0145 void windowDestroyed(QObject* window); 0146 void onFocusChanged(); 0147 void runDeferredPostLaunchActions(); 0148 0149 void downloadRequested(QWebEngineDownloadRequest *download); 0150 0151 private: 0152 enum PostLaunchAction { 0153 OpenDownloadManager, 0154 OpenNewTab, 0155 ToggleFullScreen 0156 }; 0157 0158 void loadSettings(); 0159 void loadTheme(const QString &name); 0160 0161 void setupUserScripts(); 0162 void setUserStyleSheet(const QString &filePath); 0163 0164 void checkDefaultWebBrowser(); 0165 void checkOptimizeDatabase(); 0166 0167 void registerAllowedSchemes(); 0168 0169 bool m_isPrivate; 0170 bool m_isPortable; 0171 bool m_isClosing; 0172 bool m_isStartingAfterCrash; 0173 0174 History* m_history; 0175 Bookmarks* m_bookmarks; 0176 0177 AutoFill* m_autoFill; 0178 CookieJar* m_cookieJar; 0179 PluginProxy* m_plugins; 0180 BrowsingLibrary* m_browsingLibrary; 0181 0182 NetworkManager* m_networkManager; 0183 RestoreManager* m_restoreManager; 0184 SessionManager* m_sessionManager; 0185 DownloadManager* m_downloadManager; 0186 UserAgentManager* m_userAgentManager; 0187 SearchEnginesManager* m_searchEnginesManager; 0188 ClosedWindowsManager* m_closedWindowsManager; 0189 ProtocolHandlerManager *m_protocolHandlerManager; 0190 HTML5PermissionsManager* m_html5PermissionsManager; 0191 DesktopNotificationsFactory* m_desktopNotifications; 0192 QWebEngineProfile* m_webProfile; 0193 0194 AutoSaver* m_autoSaver; 0195 ProxyStyle *m_proxyStyle = nullptr; 0196 0197 QByteArray m_wmClass; 0198 0199 QList<BrowserWindow*> m_windows; 0200 QPointer<BrowserWindow> m_lastActiveWindow; 0201 0202 QList<PostLaunchAction> m_postLaunchActions; 0203 0204 void createJumpList(); 0205 void initPulseSupport(); 0206 0207 #if defined(Q_OS_WIN) && !defined(Q_OS_OS2) 0208 public: 0209 RegisterQAppAssociation* associationManager(); 0210 0211 private: 0212 RegisterQAppAssociation* m_registerQAppAssociation; 0213 #endif 0214 0215 #ifdef Q_OS_MACOS 0216 public: 0217 bool event(QEvent* e); 0218 #endif 0219 }; 0220 0221 #endif // MAINAPPLICATION_H