2011-03-03 18:29:20 +01:00
/* ============================================================
* QupZilla - WebKit based browser
2013-01-24 17:47:50 +01:00
* Copyright ( C ) 2010 - 2013 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"
# include "qupzilla.h"
# include "tabwidget.h"
# include "bookmarkstoolbar.h"
# include "cookiemanager.h"
# include "cookiejar.h"
2011-07-29 15:39:43 +02:00
# include "browsinglibrary.h"
2012-04-30 16:33:14 +02:00
# include "history.h"
2011-03-02 16:57:41 +01:00
# include "networkmanager.h"
# include "rssmanager.h"
# include "updater.h"
# include "autosaver.h"
# include "pluginproxy.h"
# include "bookmarksmodel.h"
# include "downloadmanager.h"
2013-01-24 17:47:50 +01:00
# include "autofill.h"
2011-03-27 21:59:40 +02:00
# include "adblockmanager.h"
2011-04-24 22:40:35 +02:00
# include "desktopnotificationsfactory.h"
2011-04-25 20:56:45 +02:00
# include "iconprovider.h"
2011-05-01 22:07:57 +02:00
# include "qtwin.h"
2011-07-31 13:33:44 +02:00
# include "mainapplication.h"
# include "webhistoryinterface.h"
2013-01-22 19:04:22 +01:00
# include "qztools.h"
2011-10-18 14:30:17 +02:00
# include "profileupdater.h"
2011-10-21 23:26:34 +02:00
# include "searchenginesmanager.h"
2011-12-08 19:12:43 +01:00
# include "databasewriter.h"
2011-12-09 21:56:01 +01:00
# include "speeddial.h"
2011-12-11 19:37:16 +01:00
# include "webpage.h"
2012-01-11 21:58:25 +01:00
# include "settings.h"
2012-08-10 21:16:43 +02:00
# include "qzsettings.h"
2012-03-23 17:29:12 +01:00
# include "clearprivatedata.h"
2012-03-24 22:08:17 +01:00
# include "commandlineoptions.h"
2012-08-16 23:15:31 +02:00
# include "useragentmanager.h"
2012-08-21 20:28:38 +02:00
# include "restoremanager.h"
2012-09-03 13:24:29 +02:00
# include "proxystyle.h"
2013-02-24 10:57:58 +01:00
# include "qzregexp.h"
2013-01-29 20:34:14 +01:00
# include "checkboxdialog.h"
2012-12-01 11:16:49 +01:00
# include "registerqappassociation.h"
2013-01-19 17:28:12 +01:00
# include "html5permissions/html5permissionsmanager.h"
2013-02-05 20:43:53 +01:00
# ifdef USE_HUNSPELL
2013-02-05 15:41:10 +01:00
# include "qtwebkit/spellcheck/speller.h"
2013-02-05 20:43:53 +01:00
# endif
2011-03-02 16:57:41 +01:00
2012-09-03 22:48:52 +02:00
# ifdef Q_OS_MAC
2013-02-07 14:01:01 +01:00
# include "macmenureceiver.h"
2012-02-29 18:33:50 +01:00
# include <QFileOpenEvent>
2013-03-16 14:57:08 +01:00
# include <QMenu>
2012-02-29 18:33:50 +01:00
# endif
# include <QNetworkDiskCache>
# include <QDesktopServices>
2012-06-26 11:49:39 +02:00
# include <QTranslator>
2012-02-29 18:33:50 +01:00
# include <QSettings>
2012-06-26 11:49:39 +02:00
# include <QProcess>
# include <QDebug>
2012-02-29 18:33:50 +01:00
# include <QTimer>
2012-06-26 11:49:39 +02:00
# include <QDir>
2012-02-29 18:33:50 +01:00
2011-12-28 14:55:54 +01:00
# if defined(PORTABLE_BUILD) && !defined(NO_SYSTEM_DATAPATH)
# define NO_SYSTEM_DATAPATH
# endif
2013-01-30 12:18:07 +01:00
# if QT_VERSION < 0x050000
# include "qwebkitversion.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 )
2011-10-02 17:39:59 +02:00
, m_cookiemanager ( 0 )
, m_browsingLibrary ( 0 )
, m_historymodel ( 0 )
, m_websettings ( 0 )
, m_networkmanager ( 0 )
, m_cookiejar ( 0 )
, m_rssmanager ( 0 )
, m_bookmarksModel ( 0 )
, m_downloadManager ( 0 )
, m_autofill ( 0 )
2012-06-15 17:43:19 +02:00
, m_networkCache ( 0 )
2011-10-02 17:39:59 +02:00
, m_desktopNotifications ( 0 )
2011-10-21 23:26:34 +02:00
, m_searchEnginesManager ( 0 )
2012-08-21 20:28:38 +02:00
, m_restoreManager ( 0 )
2012-09-03 13:24:29 +02:00
, m_proxyStyle ( 0 )
2013-01-19 17:28:12 +01:00
, m_html5permissions ( 0 )
2013-02-05 20:43:53 +01:00
# ifdef USE_HUNSPELL
2013-02-05 15:41:10 +01:00
, m_speller ( 0 )
2013-02-05 20:43:53 +01:00
# endif
2012-03-14 14:04:20 +01:00
, m_dbWriter ( new DatabaseWriter ( this ) )
2012-08-16 23:15:31 +02:00
, m_uaManager ( new UserAgentManager )
2012-06-26 11:49:39 +02:00
, m_isPrivateSession ( false )
2011-10-02 17:39:59 +02:00
, m_isClosing ( false )
, m_isStateChanged ( false )
, m_isRestoring ( false )
2012-03-14 14:04:20 +01:00
, m_startingAfterCrash ( false )
2011-10-24 17:46:45 +02:00
, m_databaseConnected ( false )
2013-01-29 20:34:14 +01:00
# ifdef Q_OS_WIN
2012-12-01 07:50:31 +01:00
, m_registerQAppAssociation ( 0 )
2013-01-29 20:34:14 +01:00
# endif
2013-02-07 14:01:01 +01:00
# ifdef Q_OS_MAC
, m_macMenuReceiver ( 0 )
2013-03-16 14:57:08 +01:00
, m_macDockMenu ( 0 )
2013-02-07 14:01:01 +01:00
# endif
2011-03-02 16:57:41 +01:00
{
2012-12-22 12:47:45 +01:00
# if defined(QZ_WS_X11) && !defined(NO_SYSTEM_DATAPATH)
2011-10-18 14:30:17 +02:00
DATADIR = USE_DATADIR ;
2011-03-02 16:57:41 +01:00
# else
2011-10-13 18:19:43 +02:00
DATADIR = qApp - > applicationDirPath ( ) + " / " ;
2011-03-02 16:57:41 +01:00
# endif
2011-12-28 14:55:54 +01:00
2012-09-03 22:48:52 +02:00
# ifdef Q_OS_MAC
2012-09-04 12:42:45 +02:00
DATADIR . append ( QLatin1String ( " ../Resources/ " ) ) ;
2012-01-12 20:32:09 +01:00
# endif
2011-12-28 14:55:54 +01:00
# ifdef PORTABLE_BUILD
PROFILEDIR = DATADIR + " profiles/ " ;
# else
2013-02-21 11:05:00 +01:00
bool confPathExists = QDir ( QDir : : homePath ( ) + " /.config/qupzilla " ) . exists ( ) ;
bool homePathExists = QDir ( QDir : : homePath ( ) + " /.qupzilla " ) . exists ( ) ;
if ( homePathExists & & ! confPathExists ) {
PROFILEDIR = QDir : : homePath ( ) + " /.qupzilla/ " ;
}
else {
PROFILEDIR = QDir : : homePath ( ) + " /.config/qupzilla/ " ;
}
2011-12-28 14:55:54 +01:00
# endif
2011-09-11 19:15:06 +02:00
TRANSLATIONSDIR = DATADIR + " locale/ " ;
THEMESDIR = DATADIR + " themes/ " ;
2012-01-27 17:25:51 +01:00
setWindowIcon ( QIcon ( " :icons/exeicons/qupzilla-window.png " ) ) ;
2011-03-02 16:57:41 +01:00
bool noAddons = false ;
2012-09-01 15:59:27 +02:00
bool newInstance = false ;
2012-03-13 15:10:18 +01:00
QUrl startUrl ;
2011-12-26 20:23:54 +01:00
QStringList messages ;
2011-04-03 21:50:44 +02:00
QString startProfile ;
2011-05-10 21:25:31 +02:00
2011-03-02 16:57:41 +01:00
if ( argc > 1 ) {
2012-03-24 22:08:17 +01:00
CommandLineOptions cmd ( argc ) ;
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 ;
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 ;
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 :
2012-06-26 11:49:39 +02:00
m_isPrivateSession = 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
}
}
2012-06-26 11:49:39 +02:00
// Don't start single application in private browsing
if ( ! m_isPrivateSession ) {
2012-09-01 15:59:27 +02:00
QString appId = " QupZillaWebBrowser " ;
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 {
appId . append ( startProfile ) ;
}
}
setAppId ( appId ) ;
2012-06-26 11:49:39 +02:00
}
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 ( ) ) {
2013-03-06 09:05:41 +01:00
foreach ( const QString & message , messages ) {
2011-12-26 20:23:54 +01:00
sendMessage ( message ) ;
}
2012-03-14 14:04:20 +01:00
m_isClosing = true ;
2011-03-02 16:57:41 +01:00
return ;
}
2012-09-03 22:48:52 +02:00
# ifdef Q_OS_MAC
2012-01-06 15:03:48 +01:00
setQuitOnLastWindowClosed ( false ) ;
# else
2011-03-02 16:57:41 +01:00
setQuitOnLastWindowClosed ( true ) ;
2012-01-06 15:03:48 +01:00
# endif
2011-03-02 16:57:41 +01:00
setApplicationName ( " QupZilla " ) ;
setApplicationVersion ( QupZilla : : VERSION ) ;
setOrganizationDomain ( " qupzilla " ) ;
2012-01-06 15:03:48 +01:00
QDesktopServices : : setUrlHandler ( " http " , this , " addNewTab " ) ;
2013-01-28 10:52:55 +01:00
QDesktopServices : : setUrlHandler ( " ftp " , this , " addNewTab " ) ;
2011-03-02 16:57:41 +01:00
2011-04-07 18:00:26 +02:00
checkSettingsDir ( ) ;
2011-03-02 16:57:41 +01:00
QSettings : : setDefaultFormat ( QSettings : : IniFormat ) ;
2011-04-03 21:50:44 +02:00
if ( startProfile . isEmpty ( ) ) {
2011-12-28 14:55:54 +01:00
QSettings settings ( PROFILEDIR + " profiles/profiles.ini " , QSettings : : IniFormat ) ;
2012-09-04 12:42:45 +02:00
if ( settings . value ( " Profiles/startProfile " , " default " ) . toString ( ) . contains ( QLatin1Char ( ' / ' ) ) ) {
2011-12-28 14:55:54 +01:00
m_activeProfil = PROFILEDIR + " profiles/default/ " ;
2011-11-06 17:01:23 +01:00
}
else {
2011-12-28 14:55:54 +01:00
m_activeProfil = PROFILEDIR + " profiles/ " + settings . value ( " Profiles/startProfile " , " default " ) . toString ( ) + " / " ;
2011-11-06 17:01:23 +01:00
}
}
else {
2011-12-28 14:55:54 +01:00
m_activeProfil = PROFILEDIR + " profiles/ " + startProfile + " / " ;
2011-11-06 17:01:23 +01:00
}
2011-04-03 21:50:44 +02:00
2011-12-27 15:26:32 +01:00
ProfileUpdater u ( m_activeProfil ) ;
2011-10-18 14:30:17 +02:00
u . checkProfile ( ) ;
2011-10-23 14:44:18 +02:00
connectDatabase ( ) ;
2011-10-18 14:30:17 +02:00
2012-01-11 21:58:25 +01:00
Settings : : createSettings ( m_activeProfil + " settings.ini " ) ;
2011-03-02 16:57:41 +01:00
translateApp ( ) ;
2012-01-21 23:19:38 +01:00
QupZilla * qupzilla = new QupZilla ( Qz : : BW_FirstAppWindow , startUrl ) ;
2013-03-23 17:37:58 +01:00
m_mainWindows . prepend ( qupzilla ) ;
2011-03-02 16:57:41 +01:00
2013-03-06 09:05:41 +01:00
connect ( qupzilla , SIGNAL ( message ( Qz : : AppMessageType , bool ) ) , this , SLOT ( sendMessages ( Qz : : AppMessageType , bool ) ) ) ;
2012-03-13 15:10:18 +01:00
connect ( qupzilla , SIGNAL ( startingCompleted ( ) ) , this , SLOT ( restoreCursor ( ) ) ) ;
2011-10-02 17:39:59 +02:00
2011-03-02 16:57:41 +01:00
loadSettings ( ) ;
2012-03-13 15:10:18 +01:00
2012-04-04 21:12:52 +02:00
m_plugins = new PluginProxy ;
2012-03-13 15:10:18 +01:00
if ( ! noAddons ) {
2012-04-04 21:12:52 +02:00
m_plugins - > loadPlugins ( ) ;
2012-03-13 15:10:18 +01:00
}
2011-03-29 19:55:21 +02:00
2012-06-26 11:49:39 +02:00
if ( ! m_isPrivateSession ) {
Settings settings ;
m_startingAfterCrash = settings . value ( " SessionRestore/isRunning " , false ) . toBool ( ) ;
bool checkUpdates = settings . value ( " Web-Browser-Settings/CheckUpdates " , DEFAULT_CHECK_UPDATES ) . toBool ( ) ;
2012-08-21 20:28:38 +02:00
int afterLaunch = settings . value ( " Web-URL-Settings/afterLaunch " , 1 ) . toInt ( ) ;
2012-06-26 11:49:39 +02:00
settings . setValue ( " SessionRestore/isRunning " , true ) ;
if ( checkUpdates ) {
new Updater ( qupzilla ) ;
}
2012-08-21 20:28:38 +02:00
if ( m_startingAfterCrash | | afterLaunch = = 3 ) {
m_restoreManager = new RestoreManager ( m_activeProfil + " session.dat " ) ;
2012-12-25 16:56:23 +01:00
if ( ! m_restoreManager - > isValid ( ) ) {
destroyRestoreManager ( ) ;
}
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 ( ) ) ) ;
2012-09-03 22:48:52 +02:00
# ifdef Q_OS_WIN
2011-11-06 17:01:23 +01:00
QTimer : : singleShot ( 10 * 1000 , this , SLOT ( setupJumpList ( ) ) ) ;
2011-12-30 16:54:37 +01:00
# endif
}
void MainApplication : : postLaunch ( )
{
if ( m_postLaunchActions . contains ( OpenDownloadManager ) ) {
downManager ( ) - > show ( ) ;
}
if ( m_postLaunchActions . contains ( OpenNewTab ) ) {
2013-01-25 23:49:46 +01:00
getWindow ( ) - > tabWidget ( ) - > addView ( QUrl ( ) , Qz : : NT_SelectedNewEmptyTab ) ;
2011-12-30 16:54:37 +01:00
}
2012-03-13 15:10:18 +01:00
AutoSaver * saver = new AutoSaver ( ) ;
connect ( saver , SIGNAL ( saveApp ( ) ) , this , SLOT ( saveStateSlot ( ) ) ) ;
QSettings : : setPath ( QSettings : : IniFormat , QSettings : : UserScope , m_activeProfil ) ;
QWebHistoryInterface : : setDefaultInterface ( new WebHistoryInterface ( this ) ) ;
connect ( this , SIGNAL ( messageReceived ( QString ) ) , this , SLOT ( receiveAppMessage ( QString ) ) ) ;
connect ( this , SIGNAL ( aboutToQuit ( ) ) , this , SLOT ( saveSettings ( ) ) ) ;
2013-03-16 15:44:06 +01:00
# ifndef PORTABLE_BUILD
Settings settings ;
bool alwaysCheckDefaultBrowser = settings . value ( " Web-Browser-Settings/CheckDefaultBrowser " , DEFAULT_CHECK_DEFAULTBROWSER ) . toBool ( ) ;
if ( alwaysCheckDefaultBrowser ) {
alwaysCheckDefaultBrowser = checkDefaultWebBrowser ( ) ;
settings . setValue ( " Web-Browser-Settings/CheckDefaultBrowser " , alwaysCheckDefaultBrowser ) ;
}
# endif
2011-03-02 16:57:41 +01:00
}
void MainApplication : : loadSettings ( )
{
2012-01-11 21:58:25 +01:00
Settings settings ;
2011-09-11 19:15:06 +02:00
settings . beginGroup ( " Themes " ) ;
2011-12-28 13:16:04 +01:00
QString activeTheme = settings . value ( " activeTheme " , DEFAULT_THEME_NAME ) . toString ( ) ;
2011-09-11 19:15:06 +02:00
settings . endGroup ( ) ;
m_activeThemePath = THEMESDIR + activeTheme + " / " ;
QFile cssFile ( m_activeThemePath + " main.css " ) ;
cssFile . open ( QFile : : ReadOnly ) ;
QString css = cssFile . readAll ( ) ;
cssFile . close ( ) ;
2012-12-22 12:47:45 +01:00
# ifdef QZ_WS_X11
2011-09-11 19:15:06 +02:00
if ( QFile ( m_activeThemePath + " linux.css " ) . exists ( ) ) {
cssFile . setFileName ( m_activeThemePath + " linux.css " ) ;
cssFile . open ( QFile : : ReadOnly ) ;
css . append ( cssFile . readAll ( ) ) ;
cssFile . close ( ) ;
}
# endif
2012-09-03 22:48:52 +02:00
# ifdef Q_OS_MAC
2012-01-06 14:17:46 +01:00
if ( QFile ( m_activeThemePath + " mac.css " ) . exists ( ) ) {
cssFile . setFileName ( m_activeThemePath + " mac.css " ) ;
cssFile . open ( QFile : : ReadOnly ) ;
css . append ( cssFile . readAll ( ) ) ;
cssFile . close ( ) ;
}
# endif
2012-09-03 22:48:52 +02:00
# if defined(Q_OS_WIN) || defined(Q_OS_OS2)
2011-09-11 19:15:06 +02:00
if ( QFile ( m_activeThemePath + " windows.css " ) . exists ( ) ) {
cssFile . setFileName ( m_activeThemePath + " windows.css " ) ;
cssFile . open ( QFile : : ReadOnly ) ;
css . append ( cssFile . readAll ( ) ) ;
cssFile . close ( ) ;
}
# endif
2012-08-09 04:00:09 +02:00
//RTL Support
//loading 'rtl.css' when layout is right to left!
2012-08-13 15:41:08 +02:00
if ( isRightToLeft ( ) & & QFile ( m_activeThemePath + " rtl.css " ) . exists ( ) ) {
2012-08-09 04:00:09 +02:00
cssFile . setFileName ( m_activeThemePath + " rtl.css " ) ;
cssFile . open ( QFile : : ReadOnly ) ;
css . append ( cssFile . readAll ( ) ) ;
cssFile . close ( ) ;
}
2011-09-11 19:15:06 +02:00
QString relativePath = QDir : : current ( ) . relativeFilePath ( m_activeThemePath ) ;
2013-02-24 10:57:58 +01:00
css . replace ( QzRegExp ( " url \\ s* \\ ( \\ s*([^ \\ *: \\ );]+) \\ s* \\ ) " , Qt : : CaseSensitive ) ,
2011-09-11 19:15:06 +02:00
QString ( " url(%1 \\ 1) " ) . arg ( relativePath + " / " ) ) ;
setStyleSheet ( css ) ;
2011-03-02 16:57:41 +01:00
webSettings ( ) ;
2012-03-30 12:02:49 +02:00
2011-03-02 16:57:41 +01:00
//Web browsing settings
settings . beginGroup ( " Web-Browser-Settings " ) ;
2012-06-26 11:49:39 +02:00
if ( ! m_isPrivateSession ) {
m_websettings - > enablePersistentStorage ( m_activeProfil ) ;
m_websettings - > setAttribute ( QWebSettings : : LocalStorageEnabled , settings . value ( " HTML5StorageEnabled " , true ) . toBool ( ) ) ;
}
2012-12-20 22:57:58 +01:00
2011-03-02 16:57:41 +01:00
m_websettings - > setAttribute ( QWebSettings : : DeveloperExtrasEnabled , true ) ;
2012-03-30 12:02:49 +02:00
m_websettings - > setAttribute ( QWebSettings : : PluginsEnabled , settings . value ( " allowFlash " , true ) . toBool ( ) ) ;
m_websettings - > setAttribute ( QWebSettings : : JavascriptEnabled , settings . value ( " allowJavaScript " , true ) . toBool ( ) ) ;
m_websettings - > setAttribute ( QWebSettings : : JavascriptCanOpenWindows , settings . value ( " allowJavaScriptOpenWindow " , false ) . toBool ( ) ) ;
m_websettings - > setAttribute ( QWebSettings : : JavaEnabled , settings . value ( " allowJava " , true ) . toBool ( ) ) ;
m_websettings - > setAttribute ( QWebSettings : : DnsPrefetchEnabled , settings . value ( " DNS-Prefetch " , false ) . toBool ( ) ) ;
2012-12-28 01:17:01 +01:00
m_websettings - > setAttribute ( QWebSettings : : JavascriptCanAccessClipboard , settings . value ( " allowJavaScriptAccessClipboard " , true ) . toBool ( ) ) ;
2012-03-30 12:02:49 +02:00
m_websettings - > setAttribute ( QWebSettings : : LinksIncludedInFocusChain , settings . value ( " IncludeLinkInFocusChain " , false ) . toBool ( ) ) ;
m_websettings - > setAttribute ( QWebSettings : : ZoomTextOnly , settings . value ( " zoomTextOnly " , false ) . toBool ( ) ) ;
m_websettings - > setAttribute ( QWebSettings : : PrintElementBackgrounds , settings . value ( " PrintElementBackground " , true ) . toBool ( ) ) ;
m_websettings - > setAttribute ( QWebSettings : : XSSAuditingEnabled , settings . value ( " XSSAuditing " , false ) . toBool ( ) ) ;
m_websettings - > setMaximumPagesInCache ( settings . value ( " maximumCachedPages " , 3 ) . toInt ( ) ) ;
m_websettings - > setDefaultTextEncoding ( settings . value ( " DefaultEncoding " , m_websettings - > defaultTextEncoding ( ) ) . toString ( ) ) ;
2013-01-20 12:10:28 +01:00
# if QTWEBKIT_FROM_2_3
2012-12-22 13:52:46 +01:00
m_websettings - > setAttribute ( QWebSettings : : CaretBrowsingEnabled , settings . value ( " CaretBrowsing " , false ) . toBool ( ) ) ;
2012-12-21 16:38:44 +01:00
m_websettings - > setAttribute ( QWebSettings : : ScrollAnimatorEnabled , settings . value ( " AnimateScrolling " , true ) . toBool ( ) ) ;
# endif
2011-10-13 17:38:51 +02:00
# ifdef USE_WEBGL
2011-11-05 22:02:23 +01:00
m_websettings - > setAttribute ( QWebSettings : : WebGLEnabled , true ) ;
2011-10-13 17:38:51 +02:00
m_websettings - > setAttribute ( QWebSettings : : AcceleratedCompositingEnabled , true ) ;
# endif
2011-03-02 16:57:41 +01:00
2013-01-20 12:10:28 +01:00
# if QTWEBKIT_FROM_2_2
2011-11-05 22:02:23 +01:00
m_websettings - > setAttribute ( QWebSettings : : HyperlinkAuditingEnabled , true ) ;
2012-12-28 01:17:01 +01:00
m_websettings - > setAttribute ( QWebSettings : : JavascriptCanCloseWindows , settings . value ( " allowJavaScriptCloseWindow " , false ) . toBool ( ) ) ;
2011-11-05 22:02:23 +01:00
# endif
2012-03-30 12:02:49 +02:00
setWheelScrollLines ( settings . value ( " wheelScrollLines " , wheelScrollLines ( ) ) . toInt ( ) ) ;
2013-01-31 11:53:48 +01:00
m_websettings - > setUserStyleSheetUrl ( userStyleSheet ( settings . value ( " userStyleSheet " , QString ( ) ) . toString ( ) ) ) ;
2012-03-30 12:02:49 +02:00
settings . endGroup ( ) ;
2011-12-11 19:37:16 +01:00
settings . beginGroup ( " Browser-Fonts " ) ;
2011-03-17 15:35:51 +01:00
m_websettings - > setFontFamily ( QWebSettings : : StandardFont , settings . value ( " StandardFont " , m_websettings - > fontFamily ( QWebSettings : : StandardFont ) ) . toString ( ) ) ;
m_websettings - > setFontFamily ( QWebSettings : : CursiveFont , settings . value ( " CursiveFont " , m_websettings - > fontFamily ( QWebSettings : : CursiveFont ) ) . toString ( ) ) ;
m_websettings - > setFontFamily ( QWebSettings : : FantasyFont , settings . value ( " FantasyFont " , m_websettings - > fontFamily ( QWebSettings : : FantasyFont ) ) . toString ( ) ) ;
m_websettings - > setFontFamily ( QWebSettings : : FixedFont , settings . value ( " FixedFont " , m_websettings - > fontFamily ( QWebSettings : : FixedFont ) ) . toString ( ) ) ;
m_websettings - > setFontFamily ( QWebSettings : : SansSerifFont , settings . value ( " SansSerifFont " , m_websettings - > fontFamily ( QWebSettings : : SansSerifFont ) ) . toString ( ) ) ;
m_websettings - > setFontFamily ( QWebSettings : : SerifFont , settings . value ( " SerifFont " , m_websettings - > fontFamily ( QWebSettings : : SerifFont ) ) . toString ( ) ) ;
2011-11-06 17:01:23 +01:00
m_websettings - > setFontSize ( QWebSettings : : DefaultFontSize , settings . value ( " DefaultFontSize " , m_websettings - > fontSize ( QWebSettings : : DefaultFontSize ) ) . toInt ( ) ) ;
m_websettings - > setFontSize ( QWebSettings : : DefaultFixedFontSize , settings . value ( " FixedFontSize " , m_websettings - > fontSize ( QWebSettings : : DefaultFixedFontSize ) ) . toInt ( ) ) ;
2012-01-23 19:28:47 +01:00
m_websettings - > setFontSize ( QWebSettings : : MinimumFontSize , settings . value ( " MinimumFontSize " , m_websettings - > fontSize ( QWebSettings : : MinimumFontSize ) ) . toInt ( ) ) ;
m_websettings - > setFontSize ( QWebSettings : : MinimumLogicalFontSize , settings . value ( " MinimumLogicalFontSize " , m_websettings - > fontSize ( QWebSettings : : MinimumLogicalFontSize ) ) . toInt ( ) ) ;
2011-12-11 19:37:16 +01:00
settings . endGroup ( ) ;
2011-03-17 15:35:51 +01:00
2012-04-22 20:51:28 +02:00
m_websettings - > setWebGraphic ( QWebSettings : : DefaultFrameIconGraphic , qIconProvider - > emptyWebIcon ( ) . pixmap ( 16 , 16 ) ) ;
2012-01-22 16:28:11 +01:00
m_websettings - > setWebGraphic ( QWebSettings : : MissingImageGraphic , QPixmap ( ) ) ;
2011-12-10 13:15:07 +01:00
2012-06-26 11:49:39 +02:00
if ( m_isPrivateSession ) {
m_websettings - > setAttribute ( QWebSettings : : PrivateBrowsingEnabled , true ) ;
history ( ) - > setSaving ( false ) ;
}
2011-11-06 17:01:23 +01:00
if ( m_downloadManager ) {
2011-05-25 14:26:36 +02:00
m_downloadManager - > loadSettings ( ) ;
2011-11-06 17:01:23 +01:00
}
2012-01-24 19:58:20 +01:00
2012-08-10 21:16:43 +02:00
qzSettings - > loadSettings ( ) ;
2012-08-16 23:15:31 +02:00
m_uaManager - > loadSettings ( ) ;
2011-03-02 16:57:41 +01:00
}
2012-01-12 21:32:27 +01:00
void MainApplication : : reloadSettings ( )
{
loadSettings ( ) ;
2012-01-21 23:19:38 +01:00
emit message ( Qz : : AM_ReloadSettings , true ) ;
2012-01-12 21:32:27 +01:00
}
2011-10-22 22:29:33 +02:00
void MainApplication : : restoreCursor ( )
{
2011-11-06 17:01:23 +01:00
QApplication : : restoreOverrideCursor ( ) ;
2011-10-22 22:29:33 +02:00
}
2011-05-06 20:05:49 +02:00
void MainApplication : : setupJumpList ( )
{
QtWin : : setupJumpList ( ) ;
}
2011-03-02 16:57:41 +01:00
QupZilla * MainApplication : : getWindow ( )
{
2012-08-23 15:52:07 +02:00
QupZilla * activeW = qobject_cast < QupZilla * > ( activeWindow ( ) ) ;
if ( activeW ) {
return activeW ;
}
2011-11-06 17:01:23 +01:00
for ( int i = 0 ; i < m_mainWindows . count ( ) ; i + + ) {
if ( ! m_mainWindows . at ( i ) ) {
2011-03-02 16:57:41 +01:00
continue ;
2011-11-06 17:01:23 +01:00
}
2012-08-23 15:52:07 +02:00
2011-12-09 21:56:01 +01:00
return m_mainWindows . at ( i ) . data ( ) ;
2011-03-02 16:57:41 +01:00
}
2012-08-23 15:52:07 +02:00
2011-03-02 16:57:41 +01:00
return 0 ;
}
2011-07-28 12:12:00 +02:00
void MainApplication : : setStateChanged ( )
2011-03-02 16:57:41 +01:00
{
2011-07-28 12:12:00 +02:00
m_isStateChanged = true ;
2012-01-21 23:19:38 +01:00
sendMessages ( Qz : : AM_HistoryStateChanged , true ) ;
2011-07-28 12:12:00 +02:00
}
bool MainApplication : : isStateChanged ( )
{
if ( m_isStateChanged ) {
m_isStateChanged = false ;
2011-03-02 16:57:41 +01:00
return true ;
}
return false ;
}
2012-04-01 16:36:38 +02:00
QList < QupZilla * > MainApplication : : mainWindows ( )
{
QList < QupZilla * > list ;
for ( int i = 0 ; i < m_mainWindows . count ( ) ; i + + ) {
if ( ! m_mainWindows . at ( i ) ) {
continue ;
}
list . append ( m_mainWindows . at ( i ) . data ( ) ) ;
}
return list ;
}
2013-02-05 20:43:53 +01:00
bool MainApplication : : isClosing ( ) const
{
return m_isClosing ;
}
2013-02-11 16:45:10 +01:00
bool MainApplication : : isRestoring ( ) const
{
return m_isRestoring ;
}
2013-02-05 20:43:53 +01:00
bool MainApplication : : isPrivateSession ( ) const
{
return m_isPrivateSession ;
}
bool MainApplication : : isStartingAfterCrash ( ) const
2013-02-05 15:41:10 +01:00
{
2013-02-05 20:43:53 +01:00
return m_startingAfterCrash ;
}
int MainApplication : : windowCount ( ) const
{
return m_mainWindows . count ( ) ;
}
QString MainApplication : : currentLanguageFile ( ) const
{
return m_activeLanguage ;
}
QString MainApplication : : currentLanguage ( ) const
{
QString lang = m_activeLanguage ;
if ( lang . isEmpty ( ) ) {
return " en_US " ;
}
return lang . left ( lang . length ( ) - 3 ) ;
}
QString MainApplication : : currentProfilePath ( ) const
{
return m_activeProfil ;
2013-02-05 15:41:10 +01:00
}
2012-01-21 23:19:38 +01:00
void MainApplication : : sendMessages ( Qz : : AppMessageType mes , bool state )
2011-03-02 16:57:41 +01:00
{
emit message ( mes , state ) ;
}
void MainApplication : : receiveAppMessage ( QString message )
{
2011-12-27 12:27:39 +01:00
QWidget * actWin = getWindow ( ) ;
2012-04-03 20:41:07 +02:00
QUrl actUrl ;
2012-09-04 12:42:45 +02:00
if ( message . startsWith ( QLatin1String ( " URL: " ) ) ) {
2013-02-19 11:56:47 +01:00
const QUrl & url = QUrl : : fromUserInput ( message . mid ( 4 ) ) ;
2012-03-16 23:28:23 +01:00
addNewTab ( url ) ;
2011-12-27 12:27:39 +01:00
actWin = getWindow ( ) ;
2011-11-06 17:01:23 +01:00
}
2012-09-04 12:42:45 +02:00
else if ( message . startsWith ( QLatin1String ( " ACTION: " ) ) ) {
2013-02-19 11:56:47 +01:00
const QString & text = message . mid ( 7 ) ;
2012-09-04 12:42:45 +02:00
if ( text = = QLatin1String ( " NewTab " ) ) {
2011-05-18 22:58:49 +02:00
addNewTab ( ) ;
2011-11-06 17:01:23 +01:00
}
2012-09-04 12:42:45 +02:00
else if ( text = = QLatin1String ( " NewWindow " ) ) {
2012-01-21 23:19:38 +01:00
actWin = makeNewWindow ( Qz : : BW_NewWindow ) ;
2011-11-06 17:01:23 +01:00
}
2012-09-04 12:42:45 +02:00
else if ( text = = QLatin1String ( " ShowDownloadManager " ) ) {
2011-05-18 22:58:49 +02:00
downManager ( ) - > show ( ) ;
2011-12-27 12:27:39 +01:00
actWin = downManager ( ) ;
2011-11-06 17:01:23 +01:00
}
2012-09-04 12:42:45 +02:00
else if ( text . startsWith ( QLatin1String ( " OpenUrlInCurrentTab " ) ) ) {
2012-07-10 00:36:05 +02:00
actUrl = QUrl : : fromUserInput ( text . mid ( 19 ) ) ;
}
2012-09-04 12:42:45 +02:00
else if ( text . startsWith ( QLatin1String ( " OpenUrlInNewWindow " ) ) ) {
2012-07-10 00:36:05 +02:00
makeNewWindow ( Qz : : BW_NewWindow , QUrl : : fromUserInput ( text . mid ( 18 ) ) ) ;
return ;
2011-12-26 20:23:54 +01:00
}
2011-03-02 16:57:41 +01:00
}
2013-02-19 11:56:47 +01:00
if ( ! actWin ) {
if ( ! isClosing ( ) ) {
// It can only occur if download manager window was still opened
makeNewWindow ( Qz : : BW_NewWindow , actUrl ) ;
}
2011-03-02 16:57:41 +01:00
return ;
}
2011-12-27 12:27:39 +01:00
2012-04-03 20:41:07 +02:00
QupZilla * qz = qobject_cast < QupZilla * > ( actWin ) ;
2011-03-02 16:57:41 +01:00
actWin - > setWindowState ( actWin - > windowState ( ) & ~ Qt : : WindowMinimized ) ;
actWin - > raise ( ) ;
actWin - > activateWindow ( ) ;
actWin - > setFocus ( ) ;
2012-04-03 20:41:07 +02:00
if ( qz & & ! actUrl . isEmpty ( ) ) {
qz - > loadAddress ( actUrl ) ;
}
2011-03-02 16:57:41 +01:00
}
2011-05-18 22:58:49 +02:00
void MainApplication : : addNewTab ( const QUrl & url )
2011-03-02 16:57:41 +01:00
{
2011-11-06 17:01:23 +01:00
if ( ! getWindow ( ) ) {
2011-03-02 16:57:41 +01:00
return ;
2011-11-06 17:01:23 +01:00
}
2013-01-25 23:49:46 +01:00
getWindow ( ) - > tabWidget ( ) - > addView ( url , url . isEmpty ( ) ? Qz : : NT_SelectedNewEmptyTab : Qz : : NT_SelectedTabAtTheEnd ) ;
2011-03-02 16:57:41 +01:00
}
2012-01-21 23:19:38 +01:00
QupZilla * MainApplication : : makeNewWindow ( Qz : : BrowserWindow type , const QUrl & startUrl )
2011-03-02 16:57:41 +01:00
{
2013-02-07 14:01:01 +01:00
if ( m_mainWindows . count ( ) = = 0 & & type ! = Qz : : BW_MacFirstWindow ) {
2012-01-21 23:19:38 +01:00
type = Qz : : BW_FirstAppWindow ;
2012-01-18 18:36:10 +01:00
}
2012-01-21 23:19:38 +01:00
QupZilla * newWindow = new QupZilla ( type , startUrl ) ;
2013-03-23 17:37:58 +01:00
m_mainWindows . prepend ( newWindow ) ;
2011-12-27 12:27:39 +01:00
return newWindow ;
2011-03-02 16:57:41 +01:00
}
2012-09-03 22:48:52 +02:00
# ifdef Q_OS_MAC
2013-03-16 14:57:08 +01:00
extern void qt_mac_set_dock_menu ( QMenu * menu ) ;
QMenu * MainApplication : : macDockMenu ( )
{
if ( ! m_macDockMenu ) {
m_macDockMenu = new QMenu ( 0 ) ;
qt_mac_set_dock_menu ( m_macDockMenu ) ;
}
return m_macDockMenu ;
}
2013-02-07 14:01:01 +01:00
MacMenuReceiver * MainApplication : : macMenuReceiver ( )
{
if ( ! m_macMenuReceiver ) {
m_macMenuReceiver = new MacMenuReceiver ( this ) ;
}
return m_macMenuReceiver ;
}
2012-01-12 20:10:51 +01:00
bool MainApplication : : event ( QEvent * e )
{
switch ( e - > type ( ) ) {
case QEvent : : FileOpen : {
2012-01-25 10:52:00 +01:00
QString fileName = static_cast < QFileOpenEvent * > ( e ) - > file ( ) ;
2012-01-12 20:10:51 +01:00
addNewTab ( QUrl : : fromLocalFile ( fileName ) ) ;
return true ;
}
break ;
default :
break ;
}
return QtSingleApplication : : event ( e ) ;
}
# endif
2011-03-02 16:57:41 +01:00
void MainApplication : : connectDatabase ( )
{
2011-11-06 17:01:23 +01:00
if ( m_databaseConnected ) {
2011-10-24 17:46:45 +02:00
return ;
2011-11-06 17:01:23 +01:00
}
2011-10-24 17:46:45 +02:00
2011-03-02 16:57:41 +01:00
QSqlDatabase db = QSqlDatabase : : addDatabase ( " QSQLITE " ) ;
2011-10-24 17:46:45 +02:00
db . setDatabaseName ( m_activeProfil + " browsedata.db " ) ;
if ( ! QFile : : exists ( m_activeProfil + " browsedata.db " ) ) {
2011-12-27 15:26:32 +01:00
QFile ( " :data/browsedata.db " ) . copy ( m_activeProfil + " browsedata.db " ) ;
QFile ( m_activeProfil + " browsedata.db " ) . setPermissions ( QFile : : ReadUser | QFile : : WriteUser ) ;
2011-10-24 17:46:45 +02:00
db . setDatabaseName ( m_activeProfil + " browsedata.db " ) ;
2011-03-02 16:57:41 +01:00
qWarning ( " Cannot find SQLite database file! Copying and using the defaults! " ) ;
}
2012-06-26 11:49:39 +02:00
if ( m_isPrivateSession ) {
db . setConnectOptions ( " QSQLITE_OPEN_READONLY " ) ;
}
2011-11-06 17:01:23 +01:00
if ( ! db . open ( ) ) {
2011-03-02 16:57:41 +01:00
qWarning ( " Cannot open SQLite database! Continuing without database.... " ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
2011-10-24 17:46:45 +02:00
m_databaseConnected = true ;
2011-03-02 16:57:41 +01:00
}
void MainApplication : : translateApp ( )
{
2012-01-11 21:58:25 +01:00
Settings settings ;
2013-02-05 20:43:53 +01:00
QString file = settings . value ( " Language/language " , QLocale : : system ( ) . name ( ) ) . toString ( ) ;
if ( ! file . isEmpty ( ) & & ! file . endsWith ( QLatin1String ( " .qm " ) ) ) {
file . append ( " .qm " ) ;
}
2011-03-02 16:57:41 +01:00
2012-04-01 16:36:38 +02:00
QTranslator * app = new QTranslator ( this ) ;
2012-04-04 18:48:54 +02:00
app - > load ( file , TRANSLATIONSDIR ) ;
2011-03-02 16:57:41 +01:00
2012-04-04 18:48:54 +02:00
QTranslator * sys = new QTranslator ( this ) ;
sys - > load ( " qt_ " + file , TRANSLATIONSDIR ) ;
2011-03-02 16:57:41 +01:00
m_activeLanguage = file ;
installTranslator ( app ) ;
installTranslator ( sys ) ;
}
void MainApplication : : quitApplication ( )
{
if ( m_downloadManager & & ! m_downloadManager - > canClose ( ) ) {
m_downloadManager - > show ( ) ;
return ;
}
2012-01-04 14:09:27 +01:00
2011-03-02 16:57:41 +01:00
m_isClosing = true ;
2012-01-15 17:50:09 +01:00
m_networkmanager - > disconnectObjects ( ) ;
2012-01-12 20:10:51 +01:00
2011-11-06 17:01:23 +01:00
if ( m_mainWindows . count ( ) > 0 ) {
2011-03-02 16:57:41 +01:00
saveStateSlot ( ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
2012-01-12 20:10:51 +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
//
2012-01-12 20:32:09 +01:00
// * this can occur on Mac OS (see #157)
2012-01-12 20:10:51 +01:00
quit ( ) ;
}
void MainApplication : : saveSettings ( )
{
2012-06-26 11:49:39 +02:00
if ( m_isPrivateSession ) {
return ;
}
2012-01-12 20:10:51 +01:00
m_isClosing = true ;
2012-01-15 17:50:09 +01:00
m_networkmanager - > disconnectObjects ( ) ;
2012-01-12 20:10:51 +01:00
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 " ) ;
bool deleteHistory = settings . value ( " deleteHistoryOnClose " , false ) . toBool ( ) ;
bool deleteHtml5Storage = settings . value ( " deleteHTML5StorageOnClose " , false ) . toBool ( ) ;
settings . endGroup ( ) ;
2011-03-02 16:57:41 +01:00
2011-11-06 17:01:23 +01:00
if ( deleteHistory ) {
2011-04-26 10:03:17 +02:00
m_historymodel - > 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
}
2011-03-02 16:57:41 +01:00
2011-10-21 23:26:34 +02:00
m_searchEnginesManager - > saveSettings ( ) ;
2011-10-12 22:28:41 +02:00
m_networkmanager - > saveCertificates ( ) ;
2012-07-08 14:03:50 +02:00
m_plugins - > shutdown ( ) ;
2012-04-22 20:51:28 +02:00
qIconProvider - > saveIconsToDatabase ( ) ;
2012-11-27 19:14:03 +01:00
clearTempPath ( ) ;
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 ( ) ;
2012-04-04 18:48:54 +02:00
QFile : : remove ( currentProfilePath ( ) + " WebpageIcons.db " ) ;
2012-01-11 21:58:25 +01:00
Settings : : syncSettings ( ) ;
2011-03-02 16:57:41 +01:00
}
2011-07-29 15:39:43 +02:00
BrowsingLibrary * MainApplication : : browsingLibrary ( )
2011-03-02 16:57:41 +01:00
{
2011-11-06 17:01:23 +01:00
if ( ! m_browsingLibrary ) {
2011-07-29 15:39:43 +02:00
m_browsingLibrary = new BrowsingLibrary ( getWindow ( ) ) ;
2011-11-06 17:01:23 +01:00
}
2011-07-29 15:39:43 +02:00
return m_browsingLibrary ;
2011-03-02 16:57:41 +01:00
}
CookieManager * MainApplication : : cookieManager ( )
{
2011-11-06 17:01:23 +01:00
if ( ! m_cookiemanager ) {
2011-03-02 16:57:41 +01:00
m_cookiemanager = new CookieManager ( ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
return m_cookiemanager ;
}
2012-04-30 16:33:14 +02:00
History * MainApplication : : history ( )
2011-03-02 16:57:41 +01:00
{
2011-11-06 17:01:23 +01:00
if ( ! m_historymodel ) {
2012-04-30 16:33:14 +02:00
m_historymodel = new History ( this ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
return m_historymodel ;
}
QWebSettings * MainApplication : : webSettings ( )
{
2011-11-06 17:01:23 +01:00
if ( ! m_websettings ) {
2011-03-02 16:57:41 +01:00
m_websettings = QWebSettings : : globalSettings ( ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
return m_websettings ;
}
NetworkManager * MainApplication : : networkManager ( )
{
2011-11-06 17:01:23 +01:00
if ( ! m_networkmanager ) {
2013-02-25 23:25:11 +01:00
m_networkmanager = new NetworkManager ( this ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
return m_networkmanager ;
}
CookieJar * MainApplication : : cookieJar ( )
{
if ( ! m_cookiejar ) {
m_cookiejar = new CookieJar ( getWindow ( ) ) ;
m_cookiejar - > restoreCookies ( ) ;
}
return m_cookiejar ;
}
RSSManager * MainApplication : : rssManager ( )
{
2011-11-06 17:01:23 +01:00
if ( ! m_rssmanager ) {
2011-03-02 16:57:41 +01:00
m_rssmanager = new RSSManager ( getWindow ( ) ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
return m_rssmanager ;
}
2012-04-04 21:12:52 +02:00
PluginProxy * MainApplication : : plugins ( )
{
return m_plugins ;
}
2011-04-15 20:45:22 +02:00
BookmarksModel * MainApplication : : bookmarksModel ( )
2011-03-02 16:57:41 +01:00
{
2011-11-06 17:01:23 +01:00
if ( ! m_bookmarksModel ) {
2011-04-15 20:45:22 +02:00
m_bookmarksModel = new BookmarksModel ( this ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
return m_bookmarksModel ;
}
DownloadManager * MainApplication : : downManager ( )
{
2011-11-06 17:01:23 +01:00
if ( ! m_downloadManager ) {
2011-03-02 16:57:41 +01:00
m_downloadManager = new DownloadManager ( ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
return m_downloadManager ;
}
2013-01-24 17:47:50 +01:00
AutoFill * MainApplication : : autoFill ( )
2011-03-02 16:57:41 +01:00
{
2011-11-06 17:01:23 +01:00
if ( ! m_autofill ) {
2013-01-24 17:47:50 +01:00
m_autofill = new AutoFill ( getWindow ( ) ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
return m_autofill ;
}
2011-10-21 23:26:34 +02:00
SearchEnginesManager * MainApplication : : searchEnginesManager ( )
{
2011-11-06 17:01:23 +01:00
if ( ! m_searchEnginesManager ) {
2011-10-21 23:26:34 +02:00
m_searchEnginesManager = new SearchEnginesManager ( ) ;
2011-11-06 17:01:23 +01:00
}
2011-10-21 23:26:34 +02:00
return m_searchEnginesManager ;
}
2012-06-15 17:43:19 +02:00
QNetworkDiskCache * MainApplication : : networkCache ( )
{
if ( ! m_networkCache ) {
2013-02-10 14:50:18 +01:00
Settings settings ;
const QString & basePath = settings . value ( " Web-Browser-Settings/CachePath " ,
QString ( " %1networkcache/ " ) . arg ( m_activeProfil ) ) . toString ( ) ;
2013-02-26 11:58:38 +01:00
const QString & cachePath = QString ( " %1/%2-Qt%3/ " ) . arg ( basePath , qWebKitVersion ( ) , qVersion ( ) ) ;
2012-06-15 17:43:19 +02:00
m_networkCache = new QNetworkDiskCache ( this ) ;
2013-02-10 14:50:18 +01:00
m_networkCache - > setCacheDirectory ( cachePath ) ;
2012-06-15 17:43:19 +02:00
}
return m_networkCache ;
}
2011-04-24 22:40:35 +02:00
DesktopNotificationsFactory * MainApplication : : desktopNotifications ( )
{
2011-11-06 17:01:23 +01:00
if ( ! m_desktopNotifications ) {
2011-04-24 22:40:35 +02:00
m_desktopNotifications = new DesktopNotificationsFactory ( this ) ;
2011-11-06 17:01:23 +01:00
}
2011-04-24 22:40:35 +02:00
return m_desktopNotifications ;
}
2013-01-21 22:11:31 +01:00
HTML5PermissionsManager * MainApplication : : html5permissions ( )
2013-01-19 17:28:12 +01:00
{
if ( ! m_html5permissions ) {
m_html5permissions = new HTML5PermissionsManager ( this ) ;
}
return m_html5permissions ;
}
2013-02-05 20:43:53 +01:00
# ifdef USE_HUNSPELL
2013-02-05 15:41:10 +01:00
Speller * MainApplication : : speller ( )
{
if ( ! m_speller ) {
2013-02-05 20:43:53 +01:00
m_speller = new Speller ( this ) ;
2013-02-05 15:41:10 +01:00
}
return m_speller ;
}
2013-02-05 20:43:53 +01:00
# endif
2013-02-05 15:41:10 +01:00
2012-06-26 11:49:39 +02:00
void MainApplication : : startPrivateBrowsing ( )
{
QStringList args ;
2013-03-06 09:05:41 +01:00
foreach ( const QString & arg , arguments ( ) ) {
2013-03-23 13:02:00 +01:00
if ( arg . startsWith ( QLatin1Char ( ' - ' ) ) & &
arg ! = QLatin1String ( " --private-browsing " ) & &
arg ! = QLatin1String ( " -pb " ) ) {
2012-06-26 11:49:39 +02:00
args . append ( arg ) ;
}
}
2012-09-04 12:42:45 +02:00
args . append ( QLatin1String ( " --private-browsing " ) ) ;
2012-06-26 11:49:39 +02:00
if ( ! QProcess : : startDetached ( applicationFilePath ( ) , args ) ) {
qWarning ( ) < < " MainApplication: Cannot start new browser process for private browsing! " < < applicationFilePath ( ) < < args ;
}
}
2012-07-04 17:53:49 +02:00
void MainApplication : : reloadUserStyleSheet ( )
{
Settings settings ;
settings . beginGroup ( " Web-Browser-Settings " ) ;
2013-01-31 11:53:48 +01:00
m_websettings - > setUserStyleSheetUrl ( userStyleSheet ( settings . value ( " userStyleSheet " , QString ( ) ) . toString ( ) ) ) ;
2012-07-04 17:53:49 +02:00
settings . endGroup ( ) ;
}
2012-12-01 07:50:31 +01:00
bool MainApplication : : checkDefaultWebBrowser ( )
{
2013-01-29 20:34:14 +01:00
# ifdef Q_OS_WIN
2012-12-01 07:50:31 +01:00
bool showAgain = true ;
if ( ! associationManager ( ) - > isDefaultForAllCapabilities ( ) ) {
2013-03-16 15:44:06 +01:00
CheckBoxDialog dialog ( QDialogButtonBox : : Yes | QDialogButtonBox : : 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 " ) ) ;
dialog . setIcon ( qIconProvider - > standardIcon ( QStyle : : SP_MessageBoxWarning ) ) ;
2012-12-01 07:50:31 +01:00
2013-01-29 20:34:14 +01:00
if ( dialog . exec ( ) = = QDialog : : Accepted ) {
2012-12-01 07:50:31 +01:00
associationManager ( ) - > registerAllAssociation ( ) ;
}
2013-01-29 20:34:14 +01:00
showAgain = dialog . isChecked ( ) ;
2012-12-01 07:50:31 +01:00
}
return showAgain ;
2013-01-29 20:34:14 +01:00
# else
return false ;
# endif
2012-12-01 07:50:31 +01:00
}
2013-01-29 20:34:14 +01:00
# ifdef Q_OS_WIN
2012-12-01 07:50:31 +01:00
RegisterQAppAssociation * MainApplication : : associationManager ( )
{
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 ) ;
2013-01-29 17:33:56 +01:00
m_registerQAppAssociation - > addCapability ( " ftp " , " QupZilla.FTP " , " URL:File Transfer Protocol " , appIconPath , RegisterQAppAssociation : : UrlAssociation ) ;
2012-12-01 07:50:31 +01:00
}
return m_registerQAppAssociation ;
}
2013-01-29 20:34:14 +01:00
# endif
2012-12-01 07:50:31 +01:00
2013-01-31 11:53:48 +01:00
QUrl MainApplication : : userStyleSheet ( const QString & filePath ) const
2012-06-26 11:49:39 +02:00
{
2013-02-22 11:59:52 +01:00
QString userStyle ;
2013-02-24 13:07:14 +01:00
# ifndef QZ_WS_X11
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 ;
# ifdef Q_OS_MAC
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
2013-02-22 11:59:52 +01:00
userStyle + = QString ( " ::selection {background: %1; color: %2;} " ) . arg ( highlightColor , highlightedTextColor ) ;
# endif
userStyle + = AdBlockManager : : instance ( ) - > elementHidingRules ( ) + " { display:none !important;} " ;
2012-06-26 11:49:39 +02:00
QFile file ( filePath ) ;
if ( ! filePath . isEmpty ( ) & & file . open ( QFile : : ReadOnly ) ) {
2012-07-08 21:17:10 +02:00
QString fileData = QString : : fromUtf8 ( file . readAll ( ) ) ;
2012-09-04 12:42:45 +02:00
fileData . remove ( QLatin1Char ( ' \n ' ) ) ;
2012-07-04 17:53:49 +02:00
userStyle . append ( fileData ) ;
2012-06-26 11:49:39 +02:00
file . close ( ) ;
}
2012-12-20 14:45:35 +01:00
const QString & encodedStyle = userStyle . toLatin1 ( ) . toBase64 ( ) ;
2012-07-04 17:53:49 +02:00
const QString & dataString = QString ( " data:text/css;charset=utf-8;base64,%1 " ) . arg ( encodedStyle ) ;
2012-06-26 11:49:39 +02:00
return QUrl ( dataString ) ;
}
2011-03-17 17:03:04 +01:00
void MainApplication : : aboutToCloseWindow ( QupZilla * window )
2011-03-02 16:57:41 +01:00
{
2011-11-06 17:01:23 +01:00
if ( ! window ) {
2011-03-02 16:57:41 +01:00
return ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
2012-01-18 18:36:10 +01:00
if ( m_mainWindows . count ( ) = = 1 ) {
if ( m_browsingLibrary ) {
m_browsingLibrary - > close ( ) ;
}
if ( m_cookiemanager ) {
m_cookiemanager - > close ( ) ;
}
}
2011-03-02 16:57:41 +01:00
m_mainWindows . removeOne ( window ) ;
}
bool MainApplication : : saveStateSlot ( )
{
2012-08-21 20:28:38 +02:00
if ( m_isPrivateSession | | m_isRestoring | | m_mainWindows . count ( ) = = 0 | | m_restoreManager ) {
2011-03-02 16:57:41 +01:00
return false ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
2011-11-06 17:01:23 +01:00
QFile file ( m_activeProfil + " session.dat " ) ;
2011-03-02 16:57:41 +01:00
file . open ( QIODevice : : WriteOnly ) ;
QDataStream stream ( & file ) ;
2012-12-20 15:22:14 +01:00
stream < < Qz : : sessionVersion ;
2011-03-02 16:57:41 +01:00
stream < < m_mainWindows . count ( ) ;
2012-01-10 19:10:16 +01:00
2011-03-02 16:57:41 +01:00
for ( int i = 0 ; i < m_mainWindows . count ( ) ; i + + ) {
2011-12-09 21:56:01 +01:00
QupZilla * qz = m_mainWindows . at ( i ) . data ( ) ;
if ( ! qz ) {
continue ;
}
stream < < qz - > tabWidget ( ) - > saveState ( ) ;
if ( qz - > isFullScreen ( ) ) {
2011-04-22 07:45:15 +02:00
stream < < QByteArray ( ) ;
2011-11-06 17:01:23 +01:00
}
else {
2011-12-09 21:56:01 +01:00
stream < < qz - > saveState ( ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
}
file . close ( ) ;
QupZilla * qupzilla_ = getWindow ( ) ;
2012-01-18 18:36:10 +01:00
if ( qupzilla_ & & m_mainWindows . count ( ) = = 1 ) {
2011-03-29 19:55:21 +02:00
qupzilla_ - > tabWidget ( ) - > savePinnedTabs ( ) ;
2011-11-06 17:01:23 +01:00
}
2011-04-04 20:04:29 +02:00
2012-03-05 14:32:24 +01:00
// Saving cookies
m_cookiejar - > saveCookies ( ) ;
2011-03-02 16:57:41 +01:00
return true ;
}
2012-08-24 19:24:48 +02:00
bool MainApplication : : restoreStateSlot ( QupZilla * window , RestoreData recoveryData )
2011-03-02 16:57:41 +01:00
{
2012-08-24 19:24:48 +02:00
if ( m_isPrivateSession | | recoveryData . isEmpty ( ) ) {
2011-12-30 16:54:37 +01:00
return false ;
}
2011-04-07 18:00:26 +02:00
m_isRestoring = true ;
2012-03-14 14:04:20 +01:00
2012-08-24 19:24:48 +02:00
window - > tabWidget ( ) - > closeRecoveryTab ( ) ;
2011-03-02 16:57:41 +01:00
2012-08-24 19:24:48 +02: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
2012-08-22 13:45:03 +02:00
2012-08-24 19:24:48 +02:00
QupZilla * newWin = makeNewWindow ( Qz : : BW_OtherRestoredWindow ) ;
2013-02-26 12:56:11 +01:00
newWin - > restoreWindowState ( recoveryData . first ( ) ) ;
recoveryData . remove ( 0 ) ;
2012-08-24 19:24:48 +02:00
}
else {
2013-01-25 23:36:50 +01:00
// QTabWidget::count() - count of tabs is not updated after closing
// recovery tab ...
int tabCount = window - > tabWidget ( ) - > count ( ) ;
2013-02-26 12:56:11 +01:00
RestoreManager : : WindowData data = recoveryData . first ( ) ;
2013-01-25 23:36:50 +01:00
data . currentTab + = tabCount ;
2013-02-26 12:56:11 +01:00
recoveryData . remove ( 0 ) ;
2013-01-25 23:36:50 +01:00
window - > restoreWindowState ( data ) ;
2012-08-22 13:45:03 +02:00
}
2011-03-02 16:57:41 +01:00
2013-03-06 09:05:41 +01:00
foreach ( const RestoreManager : : WindowData & data , recoveryData ) {
2012-08-24 19:24:48 +02:00
QupZilla * window = makeNewWindow ( Qz : : BW_OtherRestoredWindow ) ;
window - > restoreWindowState ( data ) ;
2011-03-02 16:57:41 +01:00
}
2012-08-21 20:28:38 +02:00
destroyRestoreManager ( ) ;
2011-04-07 18:00:26 +02:00
m_isRestoring = false ;
2012-08-21 20:28:38 +02:00
2011-03-02 16:57:41 +01:00
return true ;
}
2011-04-07 18:00:26 +02:00
bool MainApplication : : checkSettingsDir ( )
2011-03-02 16:57:41 +01:00
{
/*
$ HOMEDIR
|
2013-02-21 11:05:00 +01:00
. config / qupzilla /
2011-03-02 16:57:41 +01:00
|
profiles / - - - - - - - - - - -
| |
default / profiles . ini
2011-10-18 14:30:17 +02:00
|
browsedata . db
2011-03-02 16:57:41 +01:00
*/
2011-10-07 17:33:51 +02:00
2011-12-28 14:55:54 +01:00
if ( QDir ( PROFILEDIR ) . exists ( ) & & QFile ( PROFILEDIR + " profiles/profiles.ini " ) . exists ( ) ) {
2011-11-06 17:01:23 +01:00
return true ;
}
2011-03-02 16:57:41 +01:00
2012-03-12 18:22:01 +01:00
std : : cout < < " QupZilla: Creating new profile directory " < < std : : endl ;
2011-03-02 16:57:41 +01:00
2011-12-28 14:55:54 +01:00
QDir dir ( PROFILEDIR ) ;
if ( ! dir . exists ( ) ) {
dir . mkpath ( PROFILEDIR ) ;
}
2011-03-02 16:57:41 +01:00
dir . mkdir ( " profiles " ) ;
dir . cd ( " profiles " ) ;
2013-02-21 11:05:00 +01:00
//.config/qupzilla/profiles
2011-12-28 14:55:54 +01:00
QFile ( PROFILEDIR + " profiles/profiles.ini " ) . remove ( ) ;
QFile ( " :data/profiles.ini " ) . copy ( PROFILEDIR + " profiles/profiles.ini " ) ;
QFile ( PROFILEDIR + " profiles/profiles.ini " ) . setPermissions ( QFile : : ReadUser | QFile : : WriteUser ) ;
2011-03-02 16:57:41 +01:00
dir . mkdir ( " default " ) ;
dir . cd ( " default " ) ;
2013-02-21 11:05:00 +01:00
//.config/qupzilla/profiles/default
2011-12-28 14:55:54 +01:00
QFile ( PROFILEDIR + " profiles/default/browsedata.db " ) . remove ( ) ;
QFile ( " :data/browsedata.db " ) . copy ( PROFILEDIR + " profiles/default/browsedata.db " ) ;
QFile ( PROFILEDIR + " profiles/default/browsedata.db " ) . setPermissions ( QFile : : ReadUser | QFile : : WriteUser ) ;
2012-04-05 14:26:44 +02:00
QFile versionFile ( PROFILEDIR + " profiles/default/version " ) ;
versionFile . open ( QFile : : WriteOnly ) ;
versionFile . write ( QupZilla : : VERSION . toUtf8 ( ) ) ;
versionFile . close ( ) ;
2011-03-02 16:57:41 +01:00
return dir . isReadable ( ) ;
}
2012-08-16 23:15:31 +02:00
2012-08-21 20:28:38 +02:00
void MainApplication : : destroyRestoreManager ( )
{
delete m_restoreManager ;
m_restoreManager = 0 ;
}
2013-03-03 20:18:34 +01:00
ProxyStyle * MainApplication : : proxyStyle ( ) const
{
return m_proxyStyle ;
}
2012-09-03 13:24:29 +02:00
void MainApplication : : setProxyStyle ( ProxyStyle * style )
{
m_proxyStyle = style ;
QApplication : : setStyle ( style ) ;
}
QString MainApplication : : currentStyle ( ) const
{
return m_proxyStyle - > baseStyle ( ) - > objectName ( ) ;
}
2012-11-27 19:14:03 +01:00
void MainApplication : : clearTempPath ( )
{
QString path = PROFILEDIR + " tmp/ " ;
QDir dir ( path ) ;
2012-11-28 11:27:30 +01:00
if ( dir . exists ( ) ) {
2013-01-22 19:04:22 +01:00
QzTools : : removeDir ( path ) ;
2012-11-28 11:27:30 +01:00
}
2012-11-27 19:14:03 +01:00
}
QString MainApplication : : tempPath ( ) const
{
QString path = PROFILEDIR + " tmp/ " ;
QDir dir ( path ) ;
2012-11-28 11:27:30 +01:00
if ( ! dir . exists ( ) ) {
2013-02-22 10:06:05 +01:00
# ifdef QZ_WS_X11
// Symlink it to standard temporary path /tmp
2013-03-21 23:44:01 +01:00
QDir ( ) . mkpath ( QDir : : tempPath ( ) + " /qupzilla/tmp " ) ;
QFile : : remove ( PROFILEDIR + " tmp " ) ;
QFile : : link ( QDir : : tempPath ( ) + " /qupzilla/tmp/ " , PROFILEDIR + " tmp " ) ;
2013-02-22 10:06:05 +01:00
# else
2012-11-27 19:14:03 +01:00
dir . mkdir ( path ) ;
2013-02-22 10:06:05 +01:00
# endif
2012-11-28 11:27:30 +01:00
}
2012-11-27 19:14:03 +01:00
return path ;
}
2012-08-16 23:15:31 +02:00
MainApplication : : ~ MainApplication ( )
{
delete m_uaManager ;
2013-03-16 14:57:08 +01:00
# ifdef Q_OS_MAC
delete m_macDockMenu ;
# endif
2012-08-16 23:15:31 +02:00
}