2011-03-03 18:29:20 +01:00
/* ============================================================
2017-01-20 09:58:13 +01:00
* QupZilla - Qt web browser
* Copyright ( C ) 2010 - 2017 David Rosca < nowrep @ gmail . com >
2011-03-03 18:29:20 +01:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
2011-03-02 16:57:41 +01:00
# include "mainapplication.h"
2014-03-10 00:47:07 +01:00
# include "history.h"
# include "qztools.h"
# include "updater.h"
# include "autofill.h"
# include "settings.h"
# include "qzregexp.h"
# include "autosaver.h"
2014-03-09 21:51:42 +01:00
# include "datapaths.h"
2011-03-02 16:57:41 +01:00
# include "tabwidget.h"
# include "cookiejar.h"
2014-03-10 00:47:07 +01:00
# include "bookmarks.h"
# include "qzsettings.h"
# include "proxystyle.h"
2011-03-02 16:57:41 +01:00
# include "pluginproxy.h"
2011-04-25 20:56:45 +02:00
# include "iconprovider.h"
2014-03-10 00:47:07 +01:00
# include "browserwindow.h"
# include "checkboxdialog.h"
2015-09-29 11:45:39 +02:00
# include "networkmanager.h"
2014-03-09 21:51:42 +01:00
# include "profilemanager.h"
2014-03-10 00:47:07 +01:00
# include "adblockmanager.h"
# include "restoremanager.h"
# include "browsinglibrary.h"
# include "downloadmanager.h"
2012-03-23 17:29:12 +01:00
# include "clearprivatedata.h"
2012-08-16 23:15:31 +02:00
# include "useragentmanager.h"
2014-03-10 00:47:07 +01:00
# include "commandlineoptions.h"
# include "searchenginesmanager.h"
# include "desktopnotificationsfactory.h"
2013-01-19 17:28:12 +01:00
# include "html5permissions/html5permissionsmanager.h"
2015-05-27 19:16:19 +02:00
# include "scripts.h"
2017-04-07 10:02:27 +02:00
# include "sessionmanager.h"
2013-02-05 20:43:53 +01:00
2015-01-27 12:15:00 +01:00
# include <QWebEngineSettings>
2012-02-29 18:33:50 +01:00
# include <QDesktopServices>
2014-05-04 20:21:41 +02:00
# include <QFontDatabase>
2014-03-07 18:03:42 +01:00
# include <QSqlDatabase>
2014-03-27 11:51:31 +01:00
# include <QLibraryInfo>
2014-10-05 16:12:29 +02:00
# include <QMessageBox>
2012-06-26 11:49:39 +02:00
# include <QTranslator>
2014-03-16 11:21:24 +01:00
# include <QThreadPool>
2012-02-29 18:33:50 +01:00
# include <QSettings>
2012-06-26 11:49:39 +02:00
# include <QProcess>
2012-02-29 18:33:50 +01:00
# include <QTimer>
2012-06-26 11:49:39 +02:00
# include <QDir>
2014-02-11 09:40:47 +01:00
# include <QStandardPaths>
2015-05-27 18:48:45 +02:00
# include <QWebEngineProfile>
2015-05-24 19:22:32 +02:00
# include <QWebEngineDownloadItem>
2015-05-27 18:48:45 +02:00
# include <QWebEngineScriptCollection>
2013-01-30 12:18:07 +01:00
2017-01-20 11:14:50 +01:00
# ifdef Q_OS_WIN
# include <QtWin>
# include <QWinJumpList>
# include <QWinJumpListCategory>
# endif
2015-09-09 23:37:28 +02:00
# include <iostream>
2014-03-19 12:14:01 +01:00
# if defined(Q_OS_WIN) && !defined(Q_OS_OS2)
# include "registerqappassociation.h"
# endif
2012-03-24 22:08:17 +01:00
MainApplication : : MainApplication ( int & argc , char * * argv )
2012-06-26 11:49:39 +02:00
: QtSingleApplication ( argc , argv )
2014-03-10 00:47:07 +01:00
, m_isPrivate ( false )
, m_isPortable ( false )
, m_isClosing ( false )
, m_isRestoring ( false )
, m_isStartingAfterCrash ( false )
2014-03-06 16:12:36 +01:00
, m_history ( 0 )
2014-02-05 15:26:51 +01:00
, m_bookmarks ( 0 )
2014-03-10 00:47:07 +01:00
, m_autoFill ( 0 )
, m_cookieJar ( 0 )
, m_plugins ( 0 )
, m_browsingLibrary ( 0 )
, m_networkManager ( 0 )
2012-08-21 20:28:38 +02:00
, m_restoreManager ( 0 )
2017-04-07 10:02:27 +02:00
, m_sessionManager ( 0 )
2014-03-10 00:47:07 +01:00
, m_downloadManager ( 0 )
, m_userAgentManager ( 0 )
, m_searchEnginesManager ( 0 )
, m_html5PermissionsManager ( 0 )
, m_desktopNotifications ( 0 )
2015-05-24 17:29:41 +02:00
, m_webProfile ( 0 )
2014-03-10 00:47:07 +01:00
, m_autoSaver ( 0 )
2014-01-01 23:15:50 +01:00
# if defined(Q_OS_WIN) && !defined(Q_OS_OS2)
2012-12-01 07:50:31 +01:00
, m_registerQAppAssociation ( 0 )
2013-01-29 20:34:14 +01:00
# endif
2011-03-02 16:57:41 +01:00
{
2016-12-31 14:32:48 +01:00
setAttribute ( Qt : : AA_UseHighDpiPixmaps ) ;
2015-11-12 16:38:39 +01:00
setAttribute ( Qt : : AA_DontCreateNativeWidgetSiblings ) ;
2014-11-14 09:28:42 +01:00
2014-03-10 00:47:07 +01:00
setApplicationName ( QLatin1String ( " QupZilla " ) ) ;
setOrganizationDomain ( QLatin1String ( " qupzilla " ) ) ;
2014-04-16 09:17:57 +02:00
setWindowIcon ( QIcon : : fromTheme ( QSL ( " qupzilla " ) , QIcon ( QSL ( " :icons/exeicons/qupzilla-window.png " ) ) ) ) ;
2017-06-06 17:56:49 +02:00
setDesktopFileName ( QSL ( " org.qupzilla.QupZilla " ) ) ;
2014-03-09 21:51:42 +01:00
2015-09-09 23:37:28 +02:00
# ifdef GIT_REVISION
setApplicationVersion ( QSL ( " %1 (%2) " ) . arg ( Qz : : VERSION , GIT_REVISION ) ) ;
# else
setApplicationVersion ( Qz : : VERSION ) ;
# endif
2014-04-07 09:30:42 +02:00
// Set fallback icon theme (eg. on Windows/Mac)
if ( QIcon : : fromTheme ( QSL ( " view-refresh " ) ) . isNull ( ) ) {
2016-12-31 14:32:48 +01:00
QIcon : : setThemeSearchPaths ( QStringList ( ) < < QL1S ( " :/breeze-fallback " ) ) ;
QIcon : : setThemeName ( QSL ( " breeze-fallback " ) ) ;
2014-04-07 09:30:42 +02:00
}
2014-10-05 16:12:29 +02:00
// QSQLITE database plugin is required
if ( ! QSqlDatabase : : isDriverAvailable ( QSL ( " QSQLITE " ) ) ) {
2014-12-24 21:08:38 +01:00
QMessageBox : : critical ( 0 , QSL ( " Error " ) , QSL ( " Qt SQLite database plugin is not available. Please install it and restart the application. " ) ) ;
2014-10-05 16:12:29 +02:00
m_isClosing = true ;
return ;
}
2014-05-04 20:21:41 +02:00
# ifdef Q_OS_WIN
// Set default app font (needed for N'ko)
int fontId = QFontDatabase : : addApplicationFont ( QSL ( " font.ttf " ) ) ;
if ( fontId ! = - 1 ) {
const QStringList families = QFontDatabase : : applicationFontFamilies ( fontId ) ;
if ( ! families . empty ( ) )
2015-10-23 11:55:14 +02:00
setFont ( QFont ( families . at ( 0 ) ) ) ;
2014-05-04 20:21:41 +02:00
}
# endif
2012-03-13 15:10:18 +01:00
QUrl startUrl ;
2011-04-03 21:50:44 +02:00
QString startProfile ;
2014-03-10 00:47:07 +01:00
QStringList messages ;
bool noAddons = false ;
bool newInstance = false ;
2011-05-10 21:25:31 +02:00
2011-03-02 16:57:41 +01:00
if ( argc > 1 ) {
2015-09-09 23:37:28 +02:00
CommandLineOptions cmd ;
2013-03-06 09:05:41 +01:00
foreach ( const CommandLineOptions : : ActionPair & pair , cmd . getActions ( ) ) {
2011-05-18 22:58:49 +02:00
switch ( pair . action ) {
2012-01-21 23:19:38 +01:00
case Qz : : CL_StartWithoutAddons :
2011-04-03 21:50:44 +02:00
noAddons = true ;
break ;
2012-01-21 23:19:38 +01:00
case Qz : : CL_StartWithProfile :
2011-05-18 22:58:49 +02:00
startProfile = pair . text ;
break ;
2014-01-23 13:02:07 +01:00
case Qz : : CL_StartPortable :
m_isPortable = true ;
break ;
2012-01-21 23:19:38 +01:00
case Qz : : CL_NewTab :
2012-09-04 12:42:45 +02:00
messages . append ( QLatin1String ( " ACTION:NewTab " ) ) ;
2011-12-30 16:54:37 +01:00
m_postLaunchActions . append ( OpenNewTab ) ;
2011-05-18 22:58:49 +02:00
break ;
2012-01-21 23:19:38 +01:00
case Qz : : CL_NewWindow :
2012-09-04 12:42:45 +02:00
messages . append ( QLatin1String ( " ACTION:NewWindow " ) ) ;
2011-05-18 22:58:49 +02:00
break ;
2014-01-22 17:34:25 +01:00
case Qz : : CL_ToggleFullScreen :
messages . append ( QLatin1String ( " ACTION:ToggleFullScreen " ) ) ;
m_postLaunchActions . append ( ToggleFullScreen ) ;
break ;
2012-01-21 23:19:38 +01:00
case Qz : : CL_ShowDownloadManager :
2012-09-04 12:42:45 +02:00
messages . append ( QLatin1String ( " ACTION:ShowDownloadManager " ) ) ;
2011-12-30 16:54:37 +01:00
m_postLaunchActions . append ( OpenDownloadManager ) ;
2011-12-26 20:23:54 +01:00
break ;
2012-01-21 23:19:38 +01:00
case Qz : : CL_StartPrivateBrowsing :
2014-03-10 00:47:07 +01:00
m_isPrivate = true ;
2011-05-18 22:58:49 +02:00
break ;
2012-09-01 15:59:27 +02:00
case Qz : : CL_StartNewInstance :
newInstance = true ;
break ;
2012-04-03 20:41:07 +02:00
case Qz : : CL_OpenUrlInCurrentTab :
startUrl = QUrl : : fromUserInput ( pair . text ) ;
messages . append ( " ACTION:OpenUrlInCurrentTab " + pair . text ) ;
2012-07-10 00:36:05 +02:00
break ;
case Qz : : CL_OpenUrlInNewWindow :
startUrl = QUrl : : fromUserInput ( pair . text ) ;
messages . append ( " ACTION:OpenUrlInNewWindow " + pair . text ) ;
2012-04-03 20:41:07 +02:00
break ;
2012-01-21 23:19:38 +01:00
case Qz : : CL_OpenUrl :
2012-03-24 22:08:17 +01:00
startUrl = QUrl : : fromUserInput ( pair . text ) ;
2012-03-16 23:28:23 +01:00
messages . append ( " URL: " + pair . text ) ;
2011-04-03 21:50:44 +02:00
break ;
2012-03-24 22:08:17 +01:00
case Qz : : CL_ExitAction :
m_isClosing = true ;
return ;
2011-04-03 21:50:44 +02:00
default :
break ;
}
2011-03-02 16:57:41 +01:00
}
}
2014-01-23 13:02:07 +01:00
if ( isPortable ( ) ) {
std : : cout < < " QupZilla: Running in Portable Mode. " < < std : : endl ;
2014-03-09 21:51:42 +01:00
DataPaths : : setPortableVersion ( ) ;
2014-01-23 13:02:07 +01:00
}
2012-06-26 11:49:39 +02:00
// Don't start single application in private browsing
2014-03-10 00:47:07 +01:00
if ( ! isPrivate ( ) ) {
QString appId = QLatin1String ( " QupZillaWebBrowser " ) ;
if ( isPortable ( ) ) {
appId . append ( QLatin1String ( " Portable " ) ) ;
}
2012-09-01 15:59:27 +02:00
if ( newInstance ) {
2012-09-04 12:42:45 +02:00
if ( startProfile . isEmpty ( ) | | startProfile = = QLatin1String ( " default " ) ) {
2012-09-01 15:59:27 +02:00
std : : cout < < " New instance cannot be started with default profile! " < < std : : endl ;
}
else {
2015-10-04 19:54:59 +02:00
// Generate unique appId so it is possible to start more separate instances
// of the same profile. It is dangerous to run more instances of the same profile,
// but if the user wants it, we should allow it.
appId . append ( startProfile + QString : : number ( QDateTime : : currentMSecsSinceEpoch ( ) ) ) ;
2012-09-01 15:59:27 +02:00
}
}
setAppId ( appId ) ;
2012-06-26 11:49:39 +02:00
}
2014-03-10 00:47:07 +01:00
// If there is nothing to tell other instance, we need to at least wake it
2011-12-27 12:27:39 +01:00
if ( messages . isEmpty ( ) ) {
2012-09-04 12:42:45 +02:00
messages . append ( QLatin1String ( " " ) ) ;
2011-12-27 12:27:39 +01:00
}
2011-03-02 16:57:41 +01:00
if ( isRunning ( ) ) {
2014-03-10 00:47:07 +01:00
m_isClosing = true ;
2013-03-06 09:05:41 +01:00
foreach ( const QString & message , messages ) {
2011-12-26 20:23:54 +01:00
sendMessage ( message ) ;
}
2011-03-02 16:57:41 +01:00
return ;
}
2017-02-10 19:00:58 +01:00
# ifdef Q_OS_MACOS
2012-01-06 15:03:48 +01:00
setQuitOnLastWindowClosed ( false ) ;
2017-03-20 01:58:55 +01:00
// disable tabbing issue#2261
extern void disableWindowTabbing ( ) ;
disableWindowTabbing ( ) ;
2012-01-06 15:03:48 +01:00
# else
2011-03-02 16:57:41 +01:00
setQuitOnLastWindowClosed ( true ) ;
2012-01-06 15:03:48 +01:00
# endif
2015-10-05 22:03:53 +02:00
QSettings : : setDefaultFormat ( QSettings : : IniFormat ) ;
2017-01-27 20:59:10 +01:00
QDesktopServices : : setUrlHandler ( QSL ( " http " ) , this , " addNewTab " ) ;
QDesktopServices : : setUrlHandler ( QSL ( " https " ) , this , " addNewTab " ) ;
QDesktopServices : : setUrlHandler ( QSL ( " ftp " ) , this , " addNewTab " ) ;
2015-10-05 22:03:53 +02:00
ProfileManager profileManager ;
profileManager . initConfigDir ( ) ;
profileManager . initCurrentProfile ( startProfile ) ;
Settings : : createSettings ( DataPaths : : currentProfilePath ( ) + QLatin1String ( " /settings.ini " ) ) ;
2015-05-24 19:22:32 +02:00
m_webProfile = isPrivate ( ) ? new QWebEngineProfile ( this ) : QWebEngineProfile : : defaultProfile ( ) ;
connect ( m_webProfile , & QWebEngineProfile : : downloadRequested , this , & MainApplication : : downloadRequested ) ;
2015-10-05 17:20:53 +02:00
m_networkManager = new NetworkManager ( this ) ;
2015-08-28 19:25:45 +02:00
// Setup QWebChannel userscript
QWebEngineScript script ;
script . setName ( QSL ( " _qupzilla_webchannel " ) ) ;
script . setInjectionPoint ( QWebEngineScript : : DocumentCreation ) ;
2016-12-26 16:45:25 +01:00
script . setWorldId ( QWebEngineScript : : MainWorld ) ;
2015-08-28 19:25:45 +02:00
script . setRunsOnSubFrames ( true ) ;
script . setSourceCode ( Scripts : : setupWebChannel ( ) ) ;
m_webProfile - > scripts ( ) - > insert ( script ) ;
2017-04-07 10:02:27 +02:00
if ( ! isPrivate ( ) ) {
m_sessionManager = new SessionManager ( this ) ;
m_autoSaver = new AutoSaver ( this ) ;
connect ( m_autoSaver , SIGNAL ( save ( ) ) , m_sessionManager , SLOT ( autoSaveLastSession ( ) ) ) ;
Settings settings ;
m_isStartingAfterCrash = settings . value ( " SessionRestore/isRunning " , false ) . toBool ( ) ;
settings . setValue ( " SessionRestore/isRunning " , true ) ;
// we have to ask about startup session before creating main window
if ( ! m_isStartingAfterCrash & & afterLaunch ( ) = = SelectSession )
m_restoreManager = new RestoreManager ( sessionManager ( ) - > askSessionFromUser ( ) ) ;
}
2014-03-06 16:12:36 +01:00
2011-03-02 16:57:41 +01:00
translateApp ( ) ;
loadSettings ( ) ;
2012-03-13 15:10:18 +01:00
2012-04-04 21:12:52 +02:00
m_plugins = new PluginProxy ;
2015-08-31 18:56:52 +02:00
m_autoFill = new AutoFill ( this ) ;
2012-04-04 21:12:52 +02:00
2015-05-24 20:41:49 +02:00
if ( ! noAddons )
2012-04-04 21:12:52 +02:00
m_plugins - > loadPlugins ( ) ;
2015-05-24 20:41:49 +02:00
2014-09-25 17:37:20 +02:00
BrowserWindow * window = createWindow ( Qz : : BW_FirstAppWindow , startUrl ) ;
connect ( window , SIGNAL ( startingCompleted ( ) ) , this , SLOT ( restoreOverrideCursor ( ) ) ) ;
2014-12-02 19:35:17 +01:00
connect ( this , SIGNAL ( focusChanged ( QWidget * , QWidget * ) ) , this , SLOT ( onFocusChanged ( ) ) ) ;
2014-09-25 17:37:20 +02:00
2014-03-10 00:47:07 +01:00
if ( ! isPrivate ( ) ) {
2016-04-05 10:18:49 +02:00
# ifndef DISABLE_CHECK_UPDATES
2017-04-07 10:02:27 +02:00
Settings settings ;
2016-04-05 10:18:49 +02:00
bool checkUpdates = settings . value ( " Web-Browser-Settings/CheckUpdates " , true ) . toBool ( ) ;
2014-02-22 15:23:46 +01:00
2012-06-26 11:49:39 +02:00
if ( checkUpdates ) {
2014-03-10 00:47:07 +01:00
new Updater ( window ) ;
2012-06-26 11:49:39 +02:00
}
2014-02-02 16:21:06 +01:00
# endif
2013-12-06 21:26:07 +01:00
2017-04-07 10:02:27 +02:00
sessionManager ( ) - > backupSavedSessions ( ) ;
2013-12-06 21:26:07 +01:00
2015-09-28 14:51:38 +02:00
if ( m_isStartingAfterCrash | | afterLaunch ( ) = = RestoreSession ) {
2017-04-07 10:02:27 +02:00
m_restoreManager = new RestoreManager ( sessionManager ( ) - > lastActiveSessionPath ( ) ) ;
2012-12-25 16:56:23 +01:00
if ( ! m_restoreManager - > isValid ( ) ) {
destroyRestoreManager ( ) ;
2015-10-05 23:39:59 +02:00
} else {
// Pinned tabs are saved into session.dat, so remove the old saved pinned tabs
QFile : : remove ( DataPaths : : currentProfilePath ( ) + QL1S ( " /pinnedtabs.dat " ) ) ;
2012-12-25 16:56:23 +01:00
}
2012-08-21 20:28:38 +02:00
}
2012-03-14 14:04:20 +01:00
}
2011-12-30 16:54:37 +01:00
QTimer : : singleShot ( 0 , this , SLOT ( postLaunch ( ) ) ) ;
}
2014-03-09 21:51:42 +01:00
MainApplication : : ~ MainApplication ( )
{
2014-03-16 11:21:24 +01:00
IconProvider : : instance ( ) - > saveIconsToDatabase ( ) ;
// Wait for all QtConcurrent jobs to finish
QThreadPool : : globalInstance ( ) - > waitForDone ( ) ;
2014-03-09 21:51:42 +01:00
// Delete all classes that are saving data in destructor
delete m_bookmarks ;
2014-03-10 09:38:16 +01:00
delete m_cookieJar ;
2014-09-29 18:23:42 +02:00
delete m_plugins ;
Settings : : syncSettings ( ) ;
2014-03-09 21:51:42 +01:00
}
2014-03-10 00:47:07 +01:00
bool MainApplication : : isClosing ( ) const
2011-12-30 16:54:37 +01:00
{
2014-03-10 00:47:07 +01:00
return m_isClosing ;
2011-03-02 16:57:41 +01:00
}
2014-03-10 00:47:07 +01:00
bool MainApplication : : isRestoring ( ) const
2011-03-02 16:57:41 +01:00
{
2014-03-10 00:47:07 +01:00
return m_isRestoring ;
}
2012-12-21 16:38:44 +01:00
2014-03-10 00:47:07 +01:00
bool MainApplication : : isPrivate ( ) const
{
return m_isPrivate ;
}
2011-03-02 16:57:41 +01:00
2014-03-10 00:47:07 +01:00
bool MainApplication : : isPortable ( ) const
{
# ifdef PORTABLE_BUILD
return true ;
# else
return m_isPortable ;
2011-11-05 22:02:23 +01:00
# endif
2011-03-02 16:57:41 +01:00
}
2014-03-10 00:47:07 +01:00
bool MainApplication : : isStartingAfterCrash ( ) const
2012-01-12 21:32:27 +01:00
{
2014-03-10 00:47:07 +01:00
return m_isStartingAfterCrash ;
2012-01-12 21:32:27 +01:00
}
2014-03-10 00:47:07 +01:00
int MainApplication : : windowCount ( ) const
2011-10-22 22:29:33 +02:00
{
2014-03-10 00:47:07 +01:00
return m_windows . count ( ) ;
2011-10-22 22:29:33 +02:00
}
2014-03-10 00:47:07 +01:00
QList < BrowserWindow * > MainApplication : : windows ( ) const
2011-05-06 20:05:49 +02:00
{
2014-03-10 00:47:07 +01:00
return m_windows ;
2011-05-06 20:05:49 +02:00
}
2014-03-10 00:47:07 +01:00
BrowserWindow * MainApplication : : getWindow ( ) const
2011-03-02 16:57:41 +01:00
{
2014-12-02 19:35:17 +01:00
if ( m_lastActiveWindow ) {
2015-10-13 04:42:13 +02:00
return m_lastActiveWindow . data ( ) ;
2012-08-23 15:52:07 +02:00
}
2015-10-23 11:55:14 +02:00
return m_windows . isEmpty ( ) ? 0 : m_windows . at ( 0 ) ;
2014-03-10 00:47:07 +01:00
}
2012-08-23 15:52:07 +02:00
2014-03-10 00:47:07 +01:00
BrowserWindow * MainApplication : : createWindow ( Qz : : BrowserWindowType type , const QUrl & startUrl )
{
if ( windowCount ( ) = = 0 & & type ! = Qz : : BW_MacFirstWindow ) {
type = Qz : : BW_FirstAppWindow ;
2011-03-02 16:57:41 +01:00
}
2012-08-23 15:52:07 +02:00
2014-03-10 00:47:07 +01:00
BrowserWindow * window = new BrowserWindow ( type , startUrl ) ;
connect ( window , SIGNAL ( destroyed ( QObject * ) ) , this , SLOT ( windowDestroyed ( QObject * ) ) ) ;
2011-03-02 16:57:41 +01:00
2014-03-10 00:47:07 +01:00
m_windows . prepend ( window ) ;
return window ;
2011-07-28 12:12:00 +02:00
}
2015-09-28 14:51:38 +02:00
MainApplication : : AfterLaunch MainApplication : : afterLaunch ( ) const
{
return static_cast < AfterLaunch > ( Settings ( ) . value ( QSL ( " Web-URL-Settings/afterLaunch " ) , RestoreSession ) . toInt ( ) ) ;
}
2017-03-26 11:27:04 +02:00
void MainApplication : : openSession ( BrowserWindow * window , RestoreData & restoreData )
2012-04-01 16:36:38 +02:00
{
2014-03-25 16:55:00 +01:00
setOverrideCursor ( Qt : : BusyCursor ) ;
2014-03-10 00:47:07 +01:00
2017-03-26 11:27:04 +02:00
if ( ! window )
window = createWindow ( Qz : : BW_OtherRestoredWindow ) ;
2014-04-08 15:47:48 +02:00
window - > setUpdatesEnabled ( false ) ;
2017-03-26 11:27:04 +02:00
if ( m_isRestoring )
window - > tabWidget ( ) - > closeRecoveryTab ( ) ;
2014-03-10 00:47:07 +01:00
if ( window - > tabWidget ( ) - > normalTabsCount ( ) > 1 ) {
// This can only happen when recovering crashed session!
//
// Don't restore tabs in current window as user already opened
// some new tabs.
// Instead create new one and restore pinned tabs there
BrowserWindow * newWin = createWindow ( Qz : : BW_OtherRestoredWindow ) ;
2014-04-08 15:47:48 +02:00
newWin - > setUpdatesEnabled ( false ) ;
2015-10-23 11:55:14 +02:00
newWin - > restoreWindowState ( restoreData . at ( 0 ) ) ;
2014-04-08 15:47:48 +02:00
newWin - > setUpdatesEnabled ( true ) ;
2014-03-10 00:47:07 +01:00
restoreData . remove ( 0 ) ;
}
else {
// QTabWidget::count() - count of tabs is not updated after closing
// recovery tab ...
// update: it seems with ComboTabBar QTabWidget::count() is updated,
// we add pinnedTabCounts to currentTab!
int tabCount = window - > tabWidget ( ) - > pinnedTabsCount ( ) ;
2015-10-23 11:55:14 +02:00
RestoreManager : : WindowData data = restoreData . at ( 0 ) ;
2014-03-10 00:47:07 +01:00
data . currentTab + = tabCount ;
restoreData . remove ( 0 ) ;
window - > restoreWindowState ( data ) ;
2012-04-01 16:36:38 +02:00
}
2014-04-08 15:47:48 +02:00
window - > setUpdatesEnabled ( true ) ;
2014-04-01 16:34:08 +02:00
processEvents ( ) ;
2014-03-10 00:47:07 +01:00
foreach ( const RestoreManager : : WindowData & data , restoreData ) {
BrowserWindow * window = createWindow ( Qz : : BW_OtherRestoredWindow ) ;
2014-04-08 15:47:48 +02:00
window - > setUpdatesEnabled ( false ) ;
2014-03-10 00:47:07 +01:00
window - > restoreWindowState ( data ) ;
2014-04-08 15:47:48 +02:00
window - > setUpdatesEnabled ( true ) ;
2014-04-01 16:34:08 +02:00
processEvents ( ) ;
2014-03-10 00:47:07 +01:00
}
2012-04-01 16:36:38 +02:00
2014-03-25 16:55:00 +01:00
restoreOverrideCursor ( ) ;
2017-03-26 11:27:04 +02:00
}
bool MainApplication : : restoreSession ( BrowserWindow * window , RestoreData restoreData )
{
if ( m_isPrivate | | restoreData . isEmpty ( ) ) {
return false ;
}
m_isRestoring = true ;
openSession ( window , restoreData ) ;
destroyRestoreManager ( ) ;
2014-03-10 00:47:07 +01:00
m_isRestoring = false ;
return true ;
2013-02-05 20:43:53 +01:00
}
2014-03-10 00:47:07 +01:00
void MainApplication : : destroyRestoreManager ( )
2013-02-11 16:45:10 +01:00
{
2014-03-10 00:47:07 +01:00
delete m_restoreManager ;
m_restoreManager = 0 ;
2013-02-11 16:45:10 +01:00
}
2014-03-10 00:47:07 +01:00
void MainApplication : : reloadSettings ( )
2013-02-05 20:43:53 +01:00
{
2014-03-10 00:47:07 +01:00
loadSettings ( ) ;
emit settingsReloaded ( ) ;
2013-02-05 20:43:53 +01:00
}
2014-03-10 00:47:07 +01:00
QString MainApplication : : styleName ( ) const
2013-02-05 20:43:53 +01:00
{
2017-01-31 21:37:12 +01:00
return m_proxyStyle ? m_proxyStyle - > name ( ) : QString ( ) ;
}
void MainApplication : : setProxyStyle ( ProxyStyle * style )
{
m_proxyStyle = style ;
setStyle ( style ) ;
2013-02-05 20:43:53 +01:00
}
QString MainApplication : : currentLanguageFile ( ) const
{
2014-03-10 00:47:07 +01:00
return m_languageFile ;
2013-02-05 20:43:53 +01:00
}
QString MainApplication : : currentLanguage ( ) const
{
2014-03-10 00:47:07 +01:00
QString lang = m_languageFile ;
2013-02-05 20:43:53 +01:00
if ( lang . isEmpty ( ) ) {
return " en_US " ;
}
return lang . left ( lang . length ( ) - 3 ) ;
}
2014-03-10 00:47:07 +01:00
History * MainApplication : : history ( )
2011-03-02 16:57:41 +01:00
{
2014-03-10 00:47:07 +01:00
if ( ! m_history ) {
m_history = new History ( this ) ;
}
return m_history ;
}
2012-04-03 20:41:07 +02:00
2014-03-10 00:47:07 +01:00
Bookmarks * MainApplication : : bookmarks ( )
{
if ( ! m_bookmarks ) {
m_bookmarks = new Bookmarks ( this ) ;
2011-11-06 17:01:23 +01:00
}
2014-03-10 00:47:07 +01:00
return m_bookmarks ;
}
AutoFill * MainApplication : : autoFill ( )
{
return m_autoFill ;
}
2011-03-02 16:57:41 +01:00
2014-03-10 00:47:07 +01:00
CookieJar * MainApplication : : cookieJar ( )
{
if ( ! m_cookieJar ) {
m_cookieJar = new CookieJar ( this ) ;
2011-03-02 16:57:41 +01:00
}
2014-03-10 00:47:07 +01:00
return m_cookieJar ;
}
2011-12-27 12:27:39 +01:00
2014-03-10 00:47:07 +01:00
PluginProxy * MainApplication : : plugins ( )
{
return m_plugins ;
}
2012-04-03 20:41:07 +02:00
2014-03-10 00:47:07 +01:00
BrowsingLibrary * MainApplication : : browsingLibrary ( )
2011-03-02 16:57:41 +01:00
{
2014-03-10 00:47:07 +01:00
if ( ! m_browsingLibrary ) {
m_browsingLibrary = new BrowsingLibrary ( getWindow ( ) ) ;
2011-11-06 17:01:23 +01:00
}
2014-03-10 00:47:07 +01:00
return m_browsingLibrary ;
}
2013-01-25 23:49:46 +01:00
2015-09-29 11:45:39 +02:00
NetworkManager * MainApplication : : networkManager ( )
2014-03-10 00:47:07 +01:00
{
return m_networkManager ;
}
2011-12-27 12:27:39 +01:00
2014-03-10 00:47:07 +01:00
RestoreManager * MainApplication : : restoreManager ( )
{
return m_restoreManager ;
2011-03-02 16:57:41 +01:00
}
2017-04-07 10:02:27 +02:00
SessionManager * MainApplication : : sessionManager ( )
{
return m_sessionManager ;
}
2014-03-10 00:47:07 +01:00
DownloadManager * MainApplication : : downloadManager ( )
{
if ( ! m_downloadManager ) {
m_downloadManager = new DownloadManager ( ) ;
}
return m_downloadManager ;
}
2013-03-16 14:57:08 +01:00
2014-03-10 00:47:07 +01:00
UserAgentManager * MainApplication : : userAgentManager ( )
2013-03-16 14:57:08 +01:00
{
2014-03-10 00:47:07 +01:00
if ( ! m_userAgentManager ) {
m_userAgentManager = new UserAgentManager ( this ) ;
2013-03-16 14:57:08 +01:00
}
2014-03-10 00:47:07 +01:00
return m_userAgentManager ;
2013-03-16 14:57:08 +01:00
}
2014-03-10 00:47:07 +01:00
SearchEnginesManager * MainApplication : : searchEnginesManager ( )
2013-02-07 14:01:01 +01:00
{
2014-03-10 00:47:07 +01:00
if ( ! m_searchEnginesManager ) {
m_searchEnginesManager = new SearchEnginesManager ( this ) ;
2013-02-07 14:01:01 +01:00
}
2014-03-10 00:47:07 +01:00
return m_searchEnginesManager ;
2013-02-07 14:01:01 +01:00
}
2014-03-10 00:47:07 +01:00
HTML5PermissionsManager * MainApplication : : html5PermissionsManager ( )
2012-01-12 20:10:51 +01:00
{
2014-03-10 00:47:07 +01:00
if ( ! m_html5PermissionsManager ) {
m_html5PermissionsManager = new HTML5PermissionsManager ( this ) ;
2012-01-12 20:10:51 +01:00
}
2014-03-10 00:47:07 +01:00
return m_html5PermissionsManager ;
}
2012-01-12 20:10:51 +01:00
2014-03-10 00:47:07 +01:00
DesktopNotificationsFactory * MainApplication : : desktopNotifications ( )
{
if ( ! m_desktopNotifications ) {
m_desktopNotifications = new DesktopNotificationsFactory ( this ) ;
2012-01-12 20:10:51 +01:00
}
2014-03-10 00:47:07 +01:00
return m_desktopNotifications ;
}
2012-01-12 20:10:51 +01:00
2015-05-24 19:22:32 +02:00
QWebEngineProfile * MainApplication : : webProfile ( ) const
2015-05-24 17:29:41 +02:00
{
return m_webProfile ;
}
2014-03-10 00:47:07 +01:00
// static
MainApplication * MainApplication : : instance ( )
{
return static_cast < MainApplication * > ( QCoreApplication : : instance ( ) ) ;
2012-01-12 20:10:51 +01:00
}
2014-03-10 00:47:07 +01:00
void MainApplication : : addNewTab ( const QUrl & url )
2013-06-07 12:59:22 +02:00
{
2014-03-10 00:47:07 +01:00
BrowserWindow * window = getWindow ( ) ;
2013-06-07 12:59:22 +02:00
2014-03-10 00:47:07 +01:00
if ( window ) {
window - > tabWidget ( ) - > addView ( url , url . isEmpty ( ) ? Qz : : NT_SelectedNewEmptyTab : Qz : : NT_SelectedTabAtTheEnd ) ;
2013-06-07 12:59:22 +02:00
}
2014-03-10 00:47:07 +01:00
}
2013-06-07 12:59:22 +02:00
2014-03-10 00:47:07 +01:00
void MainApplication : : startPrivateBrowsing ( const QUrl & startUrl )
{
QUrl url = startUrl ;
if ( QAction * act = qobject_cast < QAction * > ( sender ( ) ) ) {
url = act - > data ( ) . toUrl ( ) ;
2013-06-07 12:59:22 +02:00
}
2014-03-10 00:47:07 +01:00
QStringList args ;
2016-01-25 13:51:23 +01:00
args . append ( QSL ( " --private-browsing " ) ) ;
args . append ( QSL ( " --profile= " ) + ProfileManager : : currentProfile ( ) ) ;
2013-06-07 12:59:22 +02:00
2014-03-10 00:47:07 +01:00
if ( ! url . isEmpty ( ) ) {
args < < url . toEncoded ( ) ;
2013-06-07 12:59:22 +02:00
}
2014-03-10 00:47:07 +01:00
if ( ! QProcess : : startDetached ( applicationFilePath ( ) , args ) ) {
qWarning ( ) < < " MainApplication: Cannot start new browser process for private browsing! " < < applicationFilePath ( ) < < args ;
2013-06-07 12:59:22 +02:00
}
2014-03-10 00:47:07 +01:00
}
2013-06-07 12:59:22 +02:00
2014-03-10 00:47:07 +01:00
void MainApplication : : reloadUserStyleSheet ( )
{
2015-05-27 18:48:45 +02:00
const QString userCssFile = Settings ( ) . value ( " Web-Browser-Settings/userStyleSheet " , QString ( ) ) . toString ( ) ;
setUserStyleSheet ( userCssFile ) ;
2014-03-10 00:47:07 +01:00
}
2013-06-07 12:59:22 +02:00
2014-03-10 00:47:07 +01:00
void MainApplication : : restoreOverrideCursor ( )
{
QApplication : : restoreOverrideCursor ( ) ;
2013-06-07 12:59:22 +02:00
}
2016-02-26 10:43:34 +01:00
void MainApplication : : changeOccurred ( )
2011-03-02 16:57:41 +01:00
{
2017-04-07 10:02:27 +02:00
if ( m_autoSaver )
m_autoSaver - > changeOccurred ( ) ;
2014-03-10 00:47:07 +01:00
}
2013-02-05 20:43:53 +01:00
2014-03-10 00:47:07 +01:00
void MainApplication : : quitApplication ( )
{
if ( m_downloadManager & & ! m_downloadManager - > canClose ( ) ) {
m_downloadManager - > show ( ) ;
return ;
2013-02-05 20:43:53 +01:00
}
2011-03-02 16:57:41 +01:00
2017-04-07 10:02:27 +02:00
if ( m_sessionManager & & m_windows . count ( ) > 0 ) {
m_sessionManager - > autoSaveLastSession ( ) ;
2014-01-17 21:39:02 +01:00
}
2014-03-10 00:47:07 +01:00
m_isClosing = true ;
2011-03-02 16:57:41 +01:00
2014-03-10 00:47:07 +01:00
// Saving settings in saveSettings() slot called from quit() so
// everything gets saved also when quitting application in other
// way than clicking Quit action in File menu or closing last window
// eg. on Mac (#157)
2011-03-02 16:57:41 +01:00
2014-03-10 00:47:07 +01:00
if ( ! isPrivate ( ) ) {
removeLockFile ( ) ;
}
2011-03-02 16:57:41 +01:00
2014-03-10 00:47:07 +01:00
quit ( ) ;
2011-03-02 16:57:41 +01:00
}
2014-03-10 00:47:07 +01:00
void MainApplication : : postLaunch ( )
2013-12-06 21:26:07 +01:00
{
2014-03-10 00:47:07 +01:00
if ( m_postLaunchActions . contains ( OpenDownloadManager ) ) {
downloadManager ( ) - > show ( ) ;
}
2013-12-06 21:26:07 +01:00
2014-03-10 00:47:07 +01:00
if ( m_postLaunchActions . contains ( OpenNewTab ) ) {
getWindow ( ) - > tabWidget ( ) - > addView ( QUrl ( ) , Qz : : NT_SelectedNewEmptyTab ) ;
2013-12-06 21:26:07 +01:00
}
2014-03-10 00:47:07 +01:00
if ( m_postLaunchActions . contains ( ToggleFullScreen ) ) {
getWindow ( ) - > toggleFullScreen ( ) ;
2013-12-06 21:26:07 +01:00
}
2014-03-10 00:47:07 +01:00
QSettings : : setPath ( QSettings : : IniFormat , QSettings : : UserScope , DataPaths : : currentProfilePath ( ) ) ;
connect ( this , SIGNAL ( messageReceived ( QString ) ) , this , SLOT ( messageReceived ( QString ) ) ) ;
connect ( this , SIGNAL ( aboutToQuit ( ) ) , this , SLOT ( saveSettings ( ) ) ) ;
2017-01-20 11:14:50 +01:00
createJumpList ( ) ;
2017-03-18 17:19:57 +01:00
initPulseSupport ( ) ;
2015-10-15 09:44:03 +02:00
2016-12-24 11:32:48 +01:00
QTimer : : singleShot ( 5000 , this , & MainApplication : : runDeferredPostLaunchActions ) ;
2013-12-06 21:26:07 +01:00
}
2017-04-07 10:02:27 +02:00
QByteArray MainApplication : : saveState ( ) const
2011-03-02 16:57:41 +01:00
{
2014-03-10 00:47:07 +01:00
QByteArray data ;
QDataStream stream ( & data , QIODevice : : WriteOnly ) ;
2011-03-02 16:57:41 +01:00
2014-03-10 00:47:07 +01:00
stream < < Qz : : sessionVersion ;
stream < < m_windows . count ( ) ;
2014-03-06 16:12:36 +01:00
2014-03-10 00:47:07 +01:00
foreach ( BrowserWindow * w , m_windows ) {
stream < < w - > tabWidget ( ) - > saveState ( ) ;
if ( w - > isFullScreen ( ) ) {
stream < < QByteArray ( ) ;
}
else {
stream < < w - > saveState ( ) ;
}
}
2012-01-12 20:10:51 +01:00
2017-04-07 10:02:27 +02:00
return data ;
2017-03-26 11:27:04 +02:00
}
2012-01-12 20:10:51 +01:00
void MainApplication : : saveSettings ( )
{
2014-03-10 00:47:07 +01:00
if ( isPrivate ( ) ) {
2012-06-26 11:49:39 +02:00
return ;
}
2012-01-12 20:10:51 +01:00
m_isClosing = true ;
2012-01-11 21:58:25 +01:00
Settings settings ;
2011-03-02 16:57:41 +01:00
settings . beginGroup ( " SessionRestore " ) ;
2011-11-06 17:01:23 +01:00
settings . setValue ( " isRunning " , false ) ;
2011-03-02 16:57:41 +01:00
settings . endGroup ( ) ;
2012-01-26 18:23:35 +01:00
settings . beginGroup ( " Web-Browser-Settings " ) ;
2017-01-27 13:37:56 +01:00
bool deleteCache = settings . value ( " deleteCacheOnClose " , false ) . toBool ( ) ;
2012-01-26 18:23:35 +01:00
bool deleteHistory = settings . value ( " deleteHistoryOnClose " , false ) . toBool ( ) ;
bool deleteHtml5Storage = settings . value ( " deleteHTML5StorageOnClose " , false ) . toBool ( ) ;
settings . endGroup ( ) ;
2011-03-02 16:57:41 +01:00
2017-01-22 20:43:41 +01:00
settings . beginGroup ( " Cookie-Settings " ) ;
bool deleteCookies = settings . value ( " deleteCookiesOnClose " , false ) . toBool ( ) ;
settings . endGroup ( ) ;
2011-11-06 17:01:23 +01:00
if ( deleteHistory ) {
2014-03-06 16:12:36 +01:00
m_history - > clearHistory ( ) ;
2011-11-06 17:01:23 +01:00
}
2012-01-26 18:23:35 +01:00
if ( deleteHtml5Storage ) {
2012-03-23 17:29:12 +01:00
ClearPrivateData : : clearLocalStorage ( ) ;
2012-01-26 18:23:35 +01:00
}
2017-01-22 20:43:41 +01:00
if ( deleteCookies ) {
m_cookieJar - > deleteAllCookies ( ) ;
}
2017-01-27 13:37:56 +01:00
if ( deleteCache ) {
QzTools : : removeDir ( mApp - > webProfile ( ) - > cachePath ( ) ) ;
}
2011-03-02 16:57:41 +01:00
2011-10-21 23:26:34 +02:00
m_searchEnginesManager - > saveSettings ( ) ;
2012-07-08 14:03:50 +02:00
m_plugins - > shutdown ( ) ;
2017-01-26 12:34:55 +01:00
m_networkManager - > shutdown ( ) ;
2014-03-09 21:51:42 +01:00
DataPaths : : clearTempData ( ) ;
2011-03-02 16:57:41 +01:00
2013-02-09 15:44:17 +01:00
qzSettings - > saveSettings ( ) ;
2012-01-12 20:10:51 +01:00
AdBlockManager : : instance ( ) - > save ( ) ;
2014-03-09 22:17:13 +01:00
QFile : : remove ( DataPaths : : currentProfilePath ( ) + QLatin1String ( " /WebpageIcons.db " ) ) ;
2017-04-07 10:02:27 +02:00
sessionManager ( ) - > saveSettings ( ) ;
2011-03-02 16:57:41 +01:00
}
2014-05-01 14:08:06 +02:00
void MainApplication : : messageReceived ( const QString & message )
2011-03-02 16:57:41 +01:00
{
2014-03-10 00:47:07 +01:00
QWidget * actWin = getWindow ( ) ;
QUrl actUrl ;
2011-03-02 16:57:41 +01:00
2014-03-10 00:47:07 +01:00
if ( message . startsWith ( QLatin1String ( " URL: " ) ) ) {
const QUrl url = QUrl : : fromUserInput ( message . mid ( 4 ) ) ;
addNewTab ( url ) ;
actWin = getWindow ( ) ;
2011-11-06 17:01:23 +01:00
}
2014-03-10 00:47:07 +01:00
else if ( message . startsWith ( QLatin1String ( " ACTION: " ) ) ) {
const QString text = message . mid ( 7 ) ;
if ( text = = QLatin1String ( " NewTab " ) ) {
addNewTab ( ) ;
}
else if ( text = = QLatin1String ( " NewWindow " ) ) {
actWin = createWindow ( Qz : : BW_NewWindow ) ;
}
else if ( text = = QLatin1String ( " ShowDownloadManager " ) ) {
downloadManager ( ) - > show ( ) ;
actWin = downloadManager ( ) ;
}
else if ( text = = QLatin1String ( " ToggleFullScreen " ) & & actWin ) {
BrowserWindow * qz = static_cast < BrowserWindow * > ( actWin ) ;
qz - > toggleFullScreen ( ) ;
}
else if ( text . startsWith ( QLatin1String ( " OpenUrlInCurrentTab " ) ) ) {
actUrl = QUrl : : fromUserInput ( text . mid ( 19 ) ) ;
}
else if ( text . startsWith ( QLatin1String ( " OpenUrlInNewWindow " ) ) ) {
createWindow ( Qz : : BW_NewWindow , QUrl : : fromUserInput ( text . mid ( 18 ) ) ) ;
return ;
}
2011-11-06 17:01:23 +01:00
}
2014-05-01 14:08:06 +02:00
else {
// User attempted to start another instance, let's open a new window
actWin = createWindow ( Qz : : BW_NewWindow ) ;
}
2011-03-02 16:57:41 +01:00
2014-03-10 00:47:07 +01:00
if ( ! actWin ) {
if ( ! isClosing ( ) ) {
// It can only occur if download manager window was still opened
createWindow ( Qz : : BW_NewWindow , actUrl ) ;
}
return ;
2011-03-02 16:57:41 +01:00
}
2014-03-10 00:47:07 +01:00
actWin - > setWindowState ( actWin - > windowState ( ) & ~ Qt : : WindowMinimized ) ;
actWin - > raise ( ) ;
actWin - > activateWindow ( ) ;
actWin - > setFocus ( ) ;
BrowserWindow * win = qobject_cast < BrowserWindow * > ( actWin ) ;
if ( win & & ! actUrl . isEmpty ( ) ) {
win - > loadAddress ( actUrl ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
}
2014-03-10 19:41:44 +01:00
void MainApplication : : windowDestroyed ( QObject * window )
2012-04-04 21:12:52 +02:00
{
2014-03-10 16:55:11 +01:00
// qobject_cast doesn't work because QObject::destroyed is emitted from destructor
Q_ASSERT ( static_cast < BrowserWindow * > ( window ) ) ;
Q_ASSERT ( m_windows . contains ( static_cast < BrowserWindow * > ( window ) ) ) ;
2014-03-10 00:47:07 +01:00
2014-03-10 16:55:11 +01:00
m_windows . removeOne ( static_cast < BrowserWindow * > ( window ) ) ;
2012-04-04 21:12:52 +02:00
}
2014-12-02 19:35:17 +01:00
void MainApplication : : onFocusChanged ( )
{
BrowserWindow * activeBrowserWindow = qobject_cast < BrowserWindow * > ( activeWindow ( ) ) ;
if ( activeBrowserWindow ) {
m_lastActiveWindow = activeBrowserWindow ;
2017-03-20 09:07:33 +01:00
emit activeWindowChanged ( m_lastActiveWindow ) ;
2014-12-02 19:35:17 +01:00
}
}
2016-12-24 11:32:48 +01:00
void MainApplication : : runDeferredPostLaunchActions ( )
{
checkDefaultWebBrowser ( ) ;
checkOptimizeDatabase ( ) ;
}
2015-05-24 19:22:32 +02:00
void MainApplication : : downloadRequested ( QWebEngineDownloadItem * download )
{
downloadManager ( ) - > download ( download ) ;
}
2014-03-10 00:47:07 +01:00
void MainApplication : : loadSettings ( )
2011-03-02 16:57:41 +01:00
{
2014-03-10 00:47:07 +01:00
Settings settings ;
settings . beginGroup ( " Themes " ) ;
QString activeTheme = settings . value ( " activeTheme " , DEFAULT_THEME_NAME ) . toString ( ) ;
settings . endGroup ( ) ;
loadTheme ( activeTheme ) ;
2015-10-01 18:02:36 +02:00
QWebEngineSettings * webSettings = QWebEngineSettings : : defaultSettings ( ) ;
2014-03-10 00:47:07 +01:00
// Web browsing settings
settings . beginGroup ( " Web-Browser-Settings " ) ;
2015-01-27 12:15:00 +01:00
webSettings - > setAttribute ( QWebEngineSettings : : LocalStorageEnabled , settings . value ( " HTML5StorageEnabled " , true ) . toBool ( ) ) ;
2015-10-05 17:29:09 +02:00
webSettings - > setAttribute ( QWebEngineSettings : : PluginsEnabled , settings . value ( " allowPlugins " , true ) . toBool ( ) ) ;
2015-01-27 12:15:00 +01:00
webSettings - > setAttribute ( QWebEngineSettings : : JavascriptEnabled , settings . value ( " allowJavaScript " , true ) . toBool ( ) ) ;
webSettings - > setAttribute ( QWebEngineSettings : : JavascriptCanOpenWindows , settings . value ( " allowJavaScriptOpenWindow " , false ) . toBool ( ) ) ;
webSettings - > setAttribute ( QWebEngineSettings : : JavascriptCanAccessClipboard , settings . value ( " allowJavaScriptAccessClipboard " , true ) . toBool ( ) ) ;
webSettings - > setAttribute ( QWebEngineSettings : : LinksIncludedInFocusChain , settings . value ( " IncludeLinkInFocusChain " , false ) . toBool ( ) ) ;
webSettings - > setAttribute ( QWebEngineSettings : : XSSAuditingEnabled , settings . value ( " XSSAuditing " , false ) . toBool ( ) ) ;
2017-02-06 19:52:39 +01:00
webSettings - > setAttribute ( QWebEngineSettings : : PrintElementBackgrounds , settings . value ( " PrintElementBackground " , true ) . toBool ( ) ) ;
2015-01-27 12:15:00 +01:00
webSettings - > setAttribute ( QWebEngineSettings : : SpatialNavigationEnabled , settings . value ( " SpatialNavigation " , false ) . toBool ( ) ) ;
webSettings - > setAttribute ( QWebEngineSettings : : ScrollAnimatorEnabled , settings . value ( " AnimateScrolling " , true ) . toBool ( ) ) ;
webSettings - > setAttribute ( QWebEngineSettings : : HyperlinkAuditingEnabled , false ) ;
2015-10-05 17:39:52 +02:00
webSettings - > setAttribute ( QWebEngineSettings : : FullScreenSupportEnabled , true ) ;
2016-12-27 14:25:08 +01:00
webSettings - > setAttribute ( QWebEngineSettings : : LocalContentCanAccessRemoteUrls , true ) ;
2017-07-19 13:06:25 +02:00
webSettings - > setAttribute ( QWebEngineSettings : : FocusOnNavigationEnabled , false ) ;
2014-03-10 00:47:07 +01:00
2015-01-27 12:15:00 +01:00
webSettings - > setDefaultTextEncoding ( settings . value ( " DefaultEncoding " , webSettings - > defaultTextEncoding ( ) ) . toString ( ) ) ;
2014-03-10 00:47:07 +01:00
setWheelScrollLines ( settings . value ( " wheelScrollLines " , wheelScrollLines ( ) ) . toInt ( ) ) ;
2015-01-27 12:15:00 +01:00
2014-09-25 17:37:20 +02:00
const QString userCss = settings . value ( " userStyleSheet " , QString ( ) ) . toString ( ) ;
2014-03-10 00:47:07 +01:00
settings . endGroup ( ) ;
2015-05-27 18:48:45 +02:00
setUserStyleSheet ( userCss ) ;
2014-09-25 17:37:20 +02:00
2014-03-10 00:47:07 +01:00
settings . beginGroup ( " Browser-Fonts " ) ;
2015-01-27 12:15:00 +01:00
webSettings - > setFontFamily ( QWebEngineSettings : : StandardFont , settings . value ( " StandardFont " , webSettings - > fontFamily ( QWebEngineSettings : : StandardFont ) ) . toString ( ) ) ;
webSettings - > setFontFamily ( QWebEngineSettings : : CursiveFont , settings . value ( " CursiveFont " , webSettings - > fontFamily ( QWebEngineSettings : : CursiveFont ) ) . toString ( ) ) ;
webSettings - > setFontFamily ( QWebEngineSettings : : FantasyFont , settings . value ( " FantasyFont " , webSettings - > fontFamily ( QWebEngineSettings : : FantasyFont ) ) . toString ( ) ) ;
webSettings - > setFontFamily ( QWebEngineSettings : : FixedFont , settings . value ( " FixedFont " , webSettings - > fontFamily ( QWebEngineSettings : : FixedFont ) ) . toString ( ) ) ;
webSettings - > setFontFamily ( QWebEngineSettings : : SansSerifFont , settings . value ( " SansSerifFont " , webSettings - > fontFamily ( QWebEngineSettings : : SansSerifFont ) ) . toString ( ) ) ;
webSettings - > setFontFamily ( QWebEngineSettings : : SerifFont , settings . value ( " SerifFont " , webSettings - > fontFamily ( QWebEngineSettings : : SerifFont ) ) . toString ( ) ) ;
webSettings - > setFontSize ( QWebEngineSettings : : DefaultFontSize , settings . value ( " DefaultFontSize " , 15 ) . toInt ( ) ) ;
webSettings - > setFontSize ( QWebEngineSettings : : DefaultFixedFontSize , settings . value ( " FixedFontSize " , 14 ) . toInt ( ) ) ;
webSettings - > setFontSize ( QWebEngineSettings : : MinimumFontSize , settings . value ( " MinimumFontSize " , 3 ) . toInt ( ) ) ;
webSettings - > setFontSize ( QWebEngineSettings : : MinimumLogicalFontSize , settings . value ( " MinimumLogicalFontSize " , 5 ) . toInt ( ) ) ;
2014-03-10 00:47:07 +01:00
settings . endGroup ( ) ;
2015-05-22 21:46:55 +02:00
QWebEngineProfile * profile = QWebEngineProfile : : defaultProfile ( ) ;
profile - > setPersistentCookiesPolicy ( QWebEngineProfile : : AllowPersistentCookies ) ;
profile - > setPersistentStoragePath ( DataPaths : : currentProfilePath ( ) ) ;
2015-09-28 20:39:10 +02:00
QString defaultPath = DataPaths : : path ( DataPaths : : Cache ) ;
if ( ! defaultPath . startsWith ( DataPaths : : currentProfilePath ( ) ) )
2015-09-29 10:55:24 +02:00
defaultPath . append ( QLatin1Char ( ' / ' ) + ProfileManager : : currentProfile ( ) ) ;
2015-09-28 20:39:10 +02:00
const QString & cachePath = settings . value ( " Web-Browser-Settings/CachePath " , defaultPath ) . toString ( ) ;
2015-05-22 21:46:55 +02:00
profile - > setCachePath ( cachePath ) ;
2015-09-29 10:55:24 +02:00
const bool allowCache = settings . value ( QSL ( " Web-Browser-Settings/AllowLocalCache " ) , true ) . toBool ( ) ;
profile - > setHttpCacheType ( allowCache ? QWebEngineProfile : : DiskHttpCache : QWebEngineProfile : : MemoryHttpCache ) ;
2017-01-22 09:22:22 +01:00
const int cacheSize = settings . value ( QSL ( " Web-Browser-Settings/LocalCacheSize " ) , 50 ) . toInt ( ) * 1000 * 1000 ;
profile - > setHttpCacheMaximumSize ( cacheSize ) ;
2016-10-25 23:36:39 +02:00
settings . beginGroup ( QSL ( " SpellCheck " ) ) ;
profile - > setSpellCheckEnabled ( settings . value ( QSL ( " Enabled " ) , false ) . toBool ( ) ) ;
2017-01-27 22:46:30 +01:00
profile - > setSpellCheckLanguages ( settings . value ( QSL ( " Languages " ) ) . toStringList ( ) ) ;
2016-10-25 23:36:39 +02:00
settings . endGroup ( ) ;
2014-03-10 00:47:07 +01:00
if ( isPrivate ( ) ) {
2015-01-27 12:15:00 +01:00
webSettings - > setAttribute ( QWebEngineSettings : : LocalStorageEnabled , false ) ;
2014-03-10 00:47:07 +01:00
history ( ) - > setSaving ( false ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
2014-03-10 00:47:07 +01:00
if ( m_downloadManager ) {
m_downloadManager - > loadSettings ( ) ;
2011-11-06 17:01:23 +01:00
}
2014-03-10 00:47:07 +01:00
qzSettings - > loadSettings ( ) ;
2015-10-05 22:21:14 +02:00
networkManager ( ) - > loadSettings ( ) ;
2014-03-10 00:47:07 +01:00
userAgentManager ( ) - > loadSettings ( ) ;
2011-03-02 16:57:41 +01:00
}
2014-03-10 00:47:07 +01:00
void MainApplication : : loadTheme ( const QString & name )
2011-03-02 16:57:41 +01:00
{
2014-03-10 00:47:07 +01:00
QString activeThemePath ;
const QStringList themePaths = DataPaths : : allPaths ( DataPaths : : Themes ) ;
foreach ( const QString & path , themePaths ) {
const QString theme = QString ( " %1/%2 " ) . arg ( path , name ) ;
if ( QFile : : exists ( theme + QLatin1String ( " /main.css " ) ) ) {
activeThemePath = theme ;
break ;
}
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
2014-03-10 00:47:07 +01:00
if ( activeThemePath . isEmpty ( ) ) {
qWarning ( ) < < " Cannot load theme " < < name ;
activeThemePath = QString ( " %1/%2 " ) . arg ( DataPaths : : path ( DataPaths : : Themes ) , DEFAULT_THEME_NAME ) ;
2011-11-06 17:01:23 +01:00
}
2011-10-21 23:26:34 +02:00
2014-03-10 00:47:07 +01:00
QString qss = QzTools : : readAllFileContents ( activeThemePath + QLatin1String ( " /main.css " ) ) ;
2014-03-09 21:51:42 +01:00
2017-02-10 19:00:58 +01:00
# if defined(Q_OS_MACOS)
2014-03-10 00:47:07 +01:00
qss . append ( QzTools : : readAllFileContents ( activeThemePath + QLatin1String ( " /mac.css " ) ) ) ;
2014-04-20 12:28:33 +02:00
# elif defined(Q_OS_UNIX)
qss . append ( QzTools : : readAllFileContents ( activeThemePath + QLatin1String ( " /linux.css " ) ) ) ;
2014-03-10 00:47:07 +01:00
# elif defined(Q_OS_WIN) || defined(Q_OS_OS2)
qss . append ( QzTools : : readAllFileContents ( activeThemePath + QLatin1String ( " /windows.css " ) ) ) ;
# endif
2012-06-15 17:43:19 +02:00
2014-03-10 00:47:07 +01:00
if ( isRightToLeft ( ) ) {
qss . append ( QzTools : : readAllFileContents ( activeThemePath + QLatin1String ( " /rtl.css " ) ) ) ;
2011-11-06 17:01:23 +01:00
}
2014-03-10 00:47:07 +01:00
QString relativePath = QDir : : current ( ) . relativeFilePath ( activeThemePath ) ;
2014-04-19 11:23:25 +02:00
qss . replace ( QzRegExp ( QSL ( " url \\ s* \\ ( \\ s*([^ \\ *: \\ );]+) \\ s* \\ ) " ) , Qt : : CaseSensitive ) , QString ( " url(%1/ \\ 1) " ) . arg ( relativePath ) ) ;
2014-03-10 00:47:07 +01:00
setStyleSheet ( qss ) ;
2011-04-24 22:40:35 +02:00
}
2014-03-10 00:47:07 +01:00
void MainApplication : : translateApp ( )
2013-01-19 17:28:12 +01:00
{
2014-09-25 17:37:20 +02:00
QString file = Settings ( ) . value ( QSL ( " Language/language " ) , QLocale : : system ( ) . name ( ) ) . toString ( ) ;
2014-03-10 00:47:07 +01:00
2014-12-27 12:32:16 +01:00
// It can only be "C" locale, for which we will use default English language
if ( file . size ( ) < 2 )
file . clear ( ) ;
if ( ! file . isEmpty ( ) & & ! file . endsWith ( QL1S ( " .qm " ) ) )
2014-03-27 11:51:31 +01:00
file . append ( QL1S ( " .qm " ) ) ;
2013-01-19 17:28:12 +01:00
2014-03-27 11:51:31 +01:00
// Either we load default language (with empty file), or we attempt to load xx.qm (xx_yy.qm)
Q_ASSERT ( file . isEmpty ( ) | | file . size ( ) > = 5 ) ;
2014-03-10 19:41:44 +01:00
QString translationPath = DataPaths : : path ( DataPaths : : Translations ) ;
2013-02-05 15:41:10 +01:00
2014-03-10 00:47:07 +01:00
if ( ! file . isEmpty ( ) ) {
const QStringList translationsPaths = DataPaths : : allPaths ( DataPaths : : Translations ) ;
2014-02-22 14:57:22 +01:00
2014-03-10 00:47:07 +01:00
foreach ( const QString & path , translationsPaths ) {
// If "xx_yy" translation doesn't exists, try to use "xx*" translation
2014-03-27 11:51:31 +01:00
// It can only happen when language is chosen from system locale
2014-03-10 00:47:07 +01:00
2014-03-10 19:41:44 +01:00
if ( ! QFile ( QString ( " %1/%2 " ) . arg ( path , file ) ) . exists ( ) ) {
2014-03-10 00:47:07 +01:00
QDir dir ( path ) ;
2014-03-27 11:51:31 +01:00
QString lang = file . left ( 2 ) + QL1S ( " *.qm " ) ;
2014-03-10 00:47:07 +01:00
const QStringList translations = dir . entryList ( QStringList ( lang ) ) ;
// If no translation can be found, default English will be used
2015-10-23 11:55:14 +02:00
file = translations . isEmpty ( ) ? QString ( ) : translations . at ( 0 ) ;
2014-03-10 00:47:07 +01:00
}
2014-03-10 19:41:44 +01:00
if ( ! file . isEmpty ( ) & & QFile ( QString ( " %1/%2 " ) . arg ( path , file ) ) . exists ( ) ) {
translationPath = path ;
2014-03-10 00:47:07 +01:00
break ;
}
2012-06-26 11:49:39 +02:00
}
}
2014-03-27 11:51:31 +01:00
// Load application translation
2014-03-10 00:47:07 +01:00
QTranslator * app = new QTranslator ( this ) ;
2014-03-10 19:41:44 +01:00
app - > load ( file , translationPath ) ;
2012-06-26 11:49:39 +02:00
2014-03-27 11:51:31 +01:00
// Load Qt translation (first try to load from Qt path)
2014-03-10 00:47:07 +01:00
QTranslator * sys = new QTranslator ( this ) ;
2014-03-27 11:51:31 +01:00
sys - > load ( QL1S ( " qt_ " ) + file , QLibraryInfo : : location ( QLibraryInfo : : TranslationsPath ) ) ;
// If there is no translation in Qt path for specified language, try to load it from our path
if ( sys - > isEmpty ( ) ) {
sys - > load ( QL1S ( " qt_ " ) + file , translationPath ) ;
}
2014-02-22 14:57:22 +01:00
2014-03-10 00:47:07 +01:00
m_languageFile = file ;
installTranslator ( app ) ;
installTranslator ( sys ) ;
2012-06-26 11:49:39 +02:00
}
2014-03-10 00:47:07 +01:00
void MainApplication : : checkDefaultWebBrowser ( )
2012-12-01 07:50:31 +01:00
{
2014-03-10 00:47:07 +01:00
if ( isPortable ( ) ) {
return ;
}
2014-01-01 23:15:50 +01:00
# if defined(Q_OS_WIN) && !defined(Q_OS_OS2)
2014-03-10 00:47:07 +01:00
Settings settings ;
bool checkNow = settings . value ( " Web-Browser-Settings/CheckDefaultBrowser " , DEFAULT_CHECK_DEFAULTBROWSER ) . toBool ( ) ;
if ( ! checkNow ) {
return ;
}
bool checkAgain = true ;
2012-12-01 07:50:31 +01:00
if ( ! associationManager ( ) - > isDefaultForAllCapabilities ( ) ) {
2017-04-05 10:27:03 +02:00
CheckBoxDialog dialog ( QMessageBox : : Yes | QMessageBox : : No , getWindow ( ) ) ;
2013-01-29 20:34:14 +01:00
dialog . setText ( tr ( " QupZilla is not currently your default browser. Would you like to make it your default browser? " ) ) ;
dialog . setCheckBoxText ( tr ( " Always perform this check when starting QupZilla. " ) ) ;
2013-03-16 15:44:06 +01:00
dialog . setDefaultCheckState ( Qt : : Checked ) ;
2013-01-29 20:34:14 +01:00
dialog . setWindowTitle ( tr ( " Default Browser " ) ) ;
2017-04-05 10:27:03 +02:00
dialog . setIcon ( QMessageBox : : Warning ) ;
2012-12-01 07:50:31 +01:00
2017-04-05 10:27:03 +02:00
if ( dialog . exec ( ) = = QMessageBox : : Yes ) {
2012-12-01 07:50:31 +01:00
associationManager ( ) - > registerAllAssociation ( ) ;
}
2013-01-29 20:34:14 +01:00
2014-03-10 00:47:07 +01:00
checkAgain = dialog . isChecked ( ) ;
2012-12-01 07:50:31 +01:00
}
2014-03-10 00:47:07 +01:00
settings . setValue ( " Web-Browser-Settings/CheckDefaultBrowser " , checkAgain ) ;
2013-01-29 20:34:14 +01:00
# endif
2012-12-01 07:50:31 +01:00
}
2016-12-24 11:32:48 +01:00
void MainApplication : : checkOptimizeDatabase ( )
{
Settings settings ;
settings . beginGroup ( QSL ( " Browser " ) ) ;
const int numberOfRuns = settings . value ( QSL ( " RunsWithoutOptimizeDb " ) , 0 ) . toInt ( ) ;
settings . setValue ( QSL ( " RunsWithoutOptimizeDb " ) , numberOfRuns + 1 ) ;
if ( numberOfRuns > 20 ) {
std : : cout < < " Optimizing database... " < < std : : endl ;
IconProvider : : instance ( ) - > clearOldIconsInDatabase ( ) ;
settings . setValue ( QSL ( " RunsWithoutOptimizeDb " ) , 0 ) ;
}
settings . endGroup ( ) ;
}
2015-05-27 18:48:45 +02:00
void MainApplication : : setUserStyleSheet ( const QString & filePath )
2012-06-26 11:49:39 +02:00
{
2014-03-10 00:47:07 +01:00
QString userCss ;
2013-02-22 11:59:52 +01:00
2017-02-10 19:00:58 +01:00
# if !defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
2013-02-22 11:59:52 +01:00
// Don't grey out selection on losing focus (to prevent graying out found text)
2013-02-24 13:07:14 +01:00
QString highlightColor ;
QString highlightedTextColor ;
2017-02-10 19:00:58 +01:00
# ifdef Q_OS_MACOS
2013-02-24 13:07:14 +01:00
highlightColor = QLatin1String ( " #b6d6fc " ) ;
highlightedTextColor = QLatin1String ( " #000 " ) ;
# else
2013-02-22 11:59:52 +01:00
QPalette pal = style ( ) - > standardPalette ( ) ;
2013-02-24 13:07:14 +01:00
highlightColor = pal . color ( QPalette : : Highlight ) . name ( ) ;
highlightedTextColor = pal . color ( QPalette : : HighlightedText ) . name ( ) ;
# endif
2014-03-10 00:47:07 +01:00
userCss + = QString ( " ::selection {background: %1; color: %2;} " ) . arg ( highlightColor , highlightedTextColor ) ;
2013-02-22 11:59:52 +01:00
# endif
2014-03-10 00:47:07 +01:00
userCss + = QzTools : : readAllFileContents ( filePath ) . remove ( QLatin1Char ( ' \n ' ) ) ;
2012-06-26 11:49:39 +02:00
2015-05-27 18:48:45 +02:00
const QString name = QStringLiteral ( " _qupzilla_userstylesheet " ) ;
2015-06-24 10:46:57 +02:00
QWebEngineScript oldScript = m_webProfile - > scripts ( ) - > findScript ( name ) ;
2015-05-27 18:48:45 +02:00
if ( ! oldScript . isNull ( ) ) {
2015-06-24 10:46:57 +02:00
m_webProfile - > scripts ( ) - > remove ( oldScript ) ;
2015-05-27 18:48:45 +02:00
}
2012-06-26 11:49:39 +02:00
2016-05-27 11:03:40 +02:00
if ( userCss . isEmpty ( ) )
return ;
2015-05-27 18:48:45 +02:00
QWebEngineScript script ;
script . setName ( name ) ;
script . setInjectionPoint ( QWebEngineScript : : DocumentReady ) ;
2016-05-10 10:47:35 +02:00
script . setWorldId ( WebPage : : SafeJsWorld ) ;
2015-05-27 18:48:45 +02:00
script . setRunsOnSubFrames ( true ) ;
2015-05-27 19:16:19 +02:00
script . setSourceCode ( Scripts : : setCss ( userCss ) ) ;
2015-06-24 10:46:57 +02:00
m_webProfile - > scripts ( ) - > insert ( script ) ;
2012-06-26 11:49:39 +02:00
}
2017-01-20 11:14:50 +01:00
void MainApplication : : createJumpList ( )
{
# ifdef Q_OS_WIN
QWinJumpList * jumpList = new QWinJumpList ( this ) ;
jumpList - > clear ( ) ;
// Frequent
QWinJumpListCategory * frequent = jumpList - > frequent ( ) ;
frequent - > setVisible ( true ) ;
const QVector < HistoryEntry > mostList = m_history - > mostVisited ( 7 ) ;
for ( const HistoryEntry & entry : mostList ) {
frequent - > addLink ( IconProvider : : iconForUrl ( entry . url ) , entry . title , applicationFilePath ( ) , QStringList { entry . url . toEncoded ( ) } ) ;
}
// Tasks
QWinJumpListCategory * tasks = jumpList - > tasks ( ) ;
tasks - > setVisible ( true ) ;
tasks - > addLink ( IconProvider : : newTabIcon ( ) , tr ( " Open new tab " ) , applicationFilePath ( ) , { QSL ( " --new-tab " ) } ) ;
tasks - > addLink ( IconProvider : : newWindowIcon ( ) , tr ( " Open new window " ) , applicationFilePath ( ) , { QSL ( " --new-window " ) } ) ;
tasks - > addLink ( IconProvider : : privateBrowsingIcon ( ) , tr ( " Open new private window " ) , applicationFilePath ( ) , { QSL ( " --private-browsing " ) } ) ;
# endif
}
2017-03-18 17:19:57 +01:00
void MainApplication : : initPulseSupport ( )
{
qputenv ( " PULSE_PROP_OVERRIDE_application.name " , " QupZilla " ) ;
qputenv ( " PULSE_PROP_OVERRIDE_application.icon_name " , " qupzilla " ) ;
qputenv ( " PULSE_PROP_OVERRIDE_media.icon_name " , " qupzilla " ) ;
}
2014-03-10 00:47:07 +01:00
# if defined(Q_OS_WIN) && !defined(Q_OS_OS2)
RegisterQAppAssociation * MainApplication : : associationManager ( )
2011-03-02 16:57:41 +01:00
{
2014-03-10 00:47:07 +01:00
if ( ! m_registerQAppAssociation ) {
QString desc = tr ( " QupZilla is a new, fast and secure open-source WWW browser. QupZilla is licensed under GPL version 3 or (at your option) any later version. It is based on WebKit core and Qt Framework. " ) ;
QString fileIconPath = QApplication : : applicationFilePath ( ) + " ,1 " ;
QString appIconPath = QApplication : : applicationFilePath ( ) + " ,0 " ;
m_registerQAppAssociation = new RegisterQAppAssociation ( " QupZilla " , QApplication : : applicationFilePath ( ) , appIconPath , desc , this ) ;
m_registerQAppAssociation - > addCapability ( " .html " , " QupZilla.HTML " , " HTML File " , fileIconPath , RegisterQAppAssociation : : FileAssociation ) ;
m_registerQAppAssociation - > addCapability ( " .htm " , " QupZilla.HTM " , " HTM File " , fileIconPath , RegisterQAppAssociation : : FileAssociation ) ;
m_registerQAppAssociation - > addCapability ( " http " , " QupZilla.HTTP " , " URL:HyperText Transfer Protocol " , appIconPath , RegisterQAppAssociation : : UrlAssociation ) ;
m_registerQAppAssociation - > addCapability ( " https " , " QupZilla.HTTPS " , " URL:HyperText Transfer Protocol with Privacy " , appIconPath , RegisterQAppAssociation : : UrlAssociation ) ;
2011-11-06 17:01:23 +01:00
}
2014-03-10 00:47:07 +01:00
return m_registerQAppAssociation ;
2011-03-02 16:57:41 +01:00
}
2014-03-10 00:47:07 +01:00
# endif
2011-03-02 16:57:41 +01:00
2017-02-10 19:00:58 +01:00
# ifdef Q_OS_MACOS
2014-03-10 00:47:07 +01:00
# include <QFileOpenEvent>
2013-03-03 20:18:34 +01:00
2014-03-10 00:47:07 +01:00
bool MainApplication : : event ( QEvent * e )
2012-09-03 13:24:29 +02:00
{
2014-03-10 00:47:07 +01:00
switch ( e - > type ( ) ) {
2016-09-04 15:42:51 +02:00
case QEvent : : FileOpen : {
QFileOpenEvent * ev = static_cast < QFileOpenEvent * > ( e ) ;
if ( ! ev - > url ( ) . isEmpty ( ) ) {
addNewTab ( ev - > url ( ) ) ;
} else if ( ! ev - > file ( ) . isEmpty ( ) ) {
addNewTab ( QUrl : : fromLocalFile ( ev - > file ( ) ) ) ;
} else {
return false ;
}
2014-03-10 00:47:07 +01:00
return true ;
2016-09-04 15:42:51 +02:00
}
2014-11-08 10:21:01 +01:00
case QEvent : : ApplicationActivate :
2016-03-21 11:09:44 +01:00
if ( ! activeWindow ( ) & & m_windows . isEmpty ( ) )
2014-11-08 10:21:01 +01:00
createWindow ( Qz : : BW_NewWindow ) ;
break ;
2012-09-03 13:24:29 +02:00
2014-03-10 00:47:07 +01:00
default :
break ;
}
2012-09-03 13:24:29 +02:00
2014-03-10 00:47:07 +01:00
return QtSingleApplication : : event ( e ) ;
2012-09-03 13:24:29 +02:00
}
2014-03-10 00:47:07 +01:00
# endif