2011-03-03 18:29:20 +01:00
/* ============================================================
* QupZilla - WebKit based browser
2014-01-11 16:11:42 +01:00
* Copyright ( C ) 2010 - 2014 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-02-19 22:07:21 +01:00
# include "browserwindow.h"
2011-03-02 16:57:41 +01:00
# 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"
2014-02-05 15:26:51 +01:00
# include "bookmarks.h"
2011-03-02 16:57:41 +01:00
# 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-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
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
2014-03-07 18:03:42 +01:00
2012-02-29 18:33:50 +01:00
# include <QNetworkDiskCache>
# include <QDesktopServices>
2014-03-07 18:03:42 +01:00
# include <QSqlDatabase>
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
2013-01-30 12:18:07 +01:00
# if QT_VERSION < 0x050000
# include "qwebkitversion.h"
2014-02-11 09:40:47 +01:00
# else
# include <QStandardPaths>
2013-01-30 12:18:07 +01:00
# 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-06 16:12:36 +01:00
, m_autoSaver ( 0 )
2011-10-02 17:39:59 +02:00
, m_cookiemanager ( 0 )
, m_browsingLibrary ( 0 )
2014-03-06 16:12:36 +01:00
, m_history ( 0 )
2011-10-02 17:39:59 +02:00
, m_websettings ( 0 )
, m_networkmanager ( 0 )
, m_cookiejar ( 0 )
, m_rssmanager ( 0 )
2014-02-01 19:21:49 +01:00
, m_plugins ( 0 )
2014-02-05 15:26:51 +01:00
, m_bookmarks ( 0 )
2011-10-02 17:39:59 +02:00
, 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 )
2014-03-06 16:12:36 +01:00
, m_uaManager ( new UserAgentManager ( this ) )
2012-06-26 11:49:39 +02:00
, m_isPrivateSession ( false )
2014-01-23 13:02:07 +01:00
, m_isPortable ( false )
2011-10-02 17:39:59 +02:00
, m_isClosing ( 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 )
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
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
{
2014-02-13 14:53:20 +01:00
setApplicationName ( " QupZilla " ) ;
2014-02-19 22:07:21 +01:00
setApplicationVersion ( Qz : : VERSION ) ;
2014-02-13 14:53:20 +01:00
setOrganizationDomain ( " qupzilla " ) ;
2014-03-03 14:47:47 +01:00
# if defined(Q_OS_UNIX) && !defined(NO_SYSTEM_DATAPATH)
2014-03-03 15:06:22 +01:00
DATADIR = USE_DATADIR " / " ;
2011-03-02 16:57:41 +01:00
# else
2013-12-27 15:09:42 +01: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
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 ;
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 :
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
}
}
2014-01-23 13:02:07 +01:00
if ( isPortable ( ) ) {
std : : cout < < " QupZilla: Running in Portable Mode. " < < std : : endl ;
PROFILEDIR = DATADIR + " profiles/ " ;
}
else {
2014-02-11 09:40:47 +01:00
# if defined(Q_OS_WIN) || defined(Q_OS_OS2)
2014-02-13 14:53:20 +01:00
// Use %LOCALAPPDATA%/qupzilla as PROFILEDIR on Windows
2014-02-12 17:11:05 +01:00
# if QT_VERSION < 0x050000
2014-02-11 09:40:47 +01:00
QString dataLocation = QDesktopServices : : storageLocation ( QDesktopServices : : DataLocation ) ;
# else
QString dataLocation = QStandardPaths : : writableLocation ( QStandardPaths : : DataLocation ) ;
# endif
if ( dataLocation . isEmpty ( ) ) {
dataLocation = QDir : : homePath ( ) + QLatin1String ( " /.config/qupzilla/ " ) ;
}
2014-01-23 13:02:07 +01:00
2014-02-11 09:40:47 +01:00
QDir confPath = QDir ( dataLocation ) ;
2014-02-13 19:24:12 +01:00
QDir homePath = QDir ( QDir : : homePath ( ) + QLatin1String ( " /.qupzilla/ " ) ) ;
if ( ! homePath . exists ( ) ) {
homePath = QDir : : homePath ( ) + QLatin1String ( " /.config/qupzilla/ " ) ;
}
2014-02-11 09:40:47 +01:00
# else // Unix
QDir confPath = QDir ( QDir : : homePath ( ) + QLatin1String ( " /.config/qupzilla/ " ) ) ;
QDir homePath = QDir ( QDir : : homePath ( ) + QLatin1String ( " /.qupzilla/ " ) ) ;
2014-02-13 19:24:12 +01:00
# endif
2014-02-11 09:40:47 +01:00
if ( homePath . exists ( ) & & ! confPath . exists ( ) ) {
PROFILEDIR = homePath . absolutePath ( ) + QLatin1Char ( ' / ' ) ;
qWarning ( ) < < " WARNING: Using deprecated configuration path " < < homePath . absolutePath ( ) ;
qWarning ( ) < < " WARNING: This path may not be supported in future versions! " ;
qWarning ( ) < < " WARNING: Please move your configuration into " < < confPath . absolutePath ( ) ;
2014-01-23 13:02:07 +01:00
}
else {
2014-02-11 09:40:47 +01:00
PROFILEDIR = confPath . absolutePath ( ) + QLatin1Char ( ' / ' ) ;
2014-01-23 13:02:07 +01:00
}
}
2014-02-11 09:40:47 +01:00
// Make sure the path exists
QDir dir ;
dir . mkpath ( PROFILEDIR ) ;
2014-01-23 13:02:07 +01:00
TRANSLATIONSDIR = DATADIR + " locale/ " ;
THEMESDIR = DATADIR + " themes/ " ;
2012-06-26 11:49:39 +02:00
// Don't start single application in private browsing
if ( ! m_isPrivateSession ) {
2014-01-23 13:02:07 +01:00
QString appId = isPortable ( ) ? " QupZillaWebBrowserPortable " : " QupZillaWebBrowser " ;
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 {
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
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 {
2013-12-27 15:09:42 +01:00
m_activeProfil = PROFILEDIR + " profiles/ " + settings . value ( " Profiles/startProfile " , " default " ) . toString ( ) + " / " ;
2011-11-06 17:01:23 +01:00
}
}
else {
2013-12-27 15:09:42 +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 " ) ;
2014-03-06 16:12:36 +01:00
m_autoSaver = new AutoSaver ( this ) ;
connect ( m_autoSaver , SIGNAL ( save ( ) ) , this , SLOT ( saveStateSlot ( ) ) ) ;
2011-03-02 16:57:41 +01:00
translateApp ( ) ;
2014-02-19 22:07:21 +01:00
BrowserWindow * qupzilla = new BrowserWindow ( Qz : : BW_FirstAppWindow , startUrl ) ;
2013-03-23 17:37:58 +01:00
m_mainWindows . prepend ( qupzilla ) ;
2011-03-02 16:57:41 +01:00
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 ( ) ;
2014-02-11 15:44:47 +01:00
int afterLaunch = settings . value ( " Web-URL-Settings/afterLaunch " , 3 ) . toInt ( ) ;
2012-06-26 11:49:39 +02:00
settings . setValue ( " SessionRestore/isRunning " , true ) ;
2014-02-02 16:21:06 +01:00
# ifndef DISABLE_UPDATES_CHECK
2014-02-22 15:23:46 +01:00
bool checkUpdates = settings . value ( " Web-Browser-Settings/CheckUpdates " , DEFAULT_CHECK_UPDATES ) . toBool ( ) ;
2012-06-26 11:49:39 +02:00
if ( checkUpdates ) {
new Updater ( qupzilla ) ;
}
2014-02-02 16:21:06 +01:00
# endif
2013-12-06 21:26:07 +01:00
backupSavedSessions ( ) ;
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
2014-01-22 17:34:25 +01:00
if ( m_postLaunchActions . contains ( ToggleFullScreen ) ) {
getWindow ( ) - > toggleFullScreen ( ) ;
}
2012-03-13 15:10:18 +01:00
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
2014-01-23 13:02:07 +01:00
if ( ! isPortable ( ) ) {
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 ) ;
}
2013-03-16 15:44:06 +01:00
}
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 ( ) ;
2013-06-07 12:59:22 +02:00
loadTheme ( activeTheme ) ;
2011-09-11 19:15:06 +02:00
2013-06-07 12:59:22 +02:00
// Create global QWebSettings object
2011-03-02 16:57:41 +01:00
webSettings ( ) ;
2012-03-30 12:02:49 +02:00
2013-06-07 12:59:22 +02:00
// Web browsing settings
2011-03-02 16:57:41 +01:00
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-04-23 13:31:29 +02:00
m_websettings - > setAttribute ( QWebSettings : : SpatialNavigationEnabled , settings . value ( " SpatialNavigation " , false ) . toBool ( ) ) ;
2012-03-30 12:02:49 +02:00
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
2014-03-07 18:03:42 +01:00
m_websettings - > setWebGraphic ( QWebSettings : : DefaultFrameIconGraphic , IconProvider : : 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
}
2014-03-09 12:49:45 +01:00
void MainApplication : : doReloadSettings ( )
2012-01-12 21:32:27 +01:00
{
2014-03-09 12:49:45 +01:00
loadSettings ( ) ;
emit reloadSettings ( ) ;
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 ( ) ;
}
2014-02-19 22:07:21 +01:00
BrowserWindow * MainApplication : : getWindow ( )
2011-03-02 16:57:41 +01:00
{
2014-02-19 22:07:21 +01:00
BrowserWindow * activeW = qobject_cast < BrowserWindow * > ( activeWindow ( ) ) ;
2012-08-23 15:52:07 +02:00
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
{
2014-03-06 16:12:36 +01:00
m_autoSaver - > changeOcurred ( ) ;
2011-07-28 12:12:00 +02:00
}
2014-02-19 22:07:21 +01:00
QList < BrowserWindow * > MainApplication : : mainWindows ( )
2012-04-01 16:36:38 +02:00
{
2014-02-19 22:07:21 +01:00
QList < BrowserWindow * > list ;
2012-04-01 16:36:38 +02:00
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 ;
}
2014-01-23 13:02:07 +01:00
bool MainApplication : : isPortable ( ) const
{
# ifdef PORTABLE_BUILD
return true ;
# else
return m_isPortable ;
# endif
}
2013-02-05 20:43:53 +01:00
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
}
2011-03-02 16:57:41 +01:00
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-12-30 13:43:48 +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-12-30 13:43:48 +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
}
2014-01-22 17:34:25 +01:00
else if ( text = = QLatin1String ( " ToggleFullScreen " ) & & actWin ) {
2014-02-19 22:07:21 +01:00
BrowserWindow * qz = static_cast < BrowserWindow * > ( actWin ) ;
2014-01-22 17:34:25 +01:00
qz - > toggleFullScreen ( ) ;
}
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
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
2014-02-19 22:07:21 +01:00
BrowserWindow * qz = qobject_cast < BrowserWindow * > ( actWin ) ;
2014-01-22 17:34:25 +01:00
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
}
2014-02-19 22:07:21 +01:00
BrowserWindow * MainApplication : : makeNewWindow ( Qz : : BrowserWindowType 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
}
2014-02-19 22:07:21 +01:00
BrowserWindow * newWindow = new BrowserWindow ( 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
}
2013-06-07 12:59:22 +02:00
void MainApplication : : loadTheme ( const QString & name )
{
// Themes are loaded from the following directories:
// 1. Directory "themes" in user profile
// 2. Directory "themes" in root profile directory
// 3. System data path
// > /usr/share/qupzilla/themes on Linux
// > $EXECUTABLE_DIR/themes on Windows
QStringList themePaths ;
themePaths < < m_activeProfil + " themes/ "
< < PROFILEDIR + " themes/ "
< < THEMESDIR ;
foreach ( const QString & path , themePaths ) {
2013-12-30 13:43:48 +01:00
const QString theme = path + name + " / " ;
2013-06-07 12:59:22 +02:00
if ( QFile : : exists ( theme + " main.css " ) ) {
m_activeThemePath = theme ;
break ;
}
}
if ( m_activeThemePath . isEmpty ( ) ) {
qWarning ( " Cannot load theme '%s'! " , qPrintable ( name ) ) ;
2013-12-27 15:09:42 +01:00
m_activeThemePath = THEMESDIR + DEFAULT_THEME_NAME + " / " ;
2013-06-07 12:59:22 +02:00
}
QFile cssFile ( m_activeThemePath + " main.css " ) ;
cssFile . open ( QFile : : ReadOnly ) ;
QString css = cssFile . readAll ( ) ;
cssFile . close ( ) ;
2013-12-27 15:09:31 +01:00
/*
* # id [ style = QtStyle ] ( QtStyle = QMacStyle , QWindowsVistaStyle , QGtkStyle , . . . )
* should be enough instead of loading special stylesheets
*/
2014-03-03 14:47:47 +01:00
# ifdef Q_OS_UNIX
2013-06-07 12:59:22 +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
# ifdef Q_OS_MAC
if ( QFile ( m_activeThemePath + " mac.css " ) . exists ( ) ) {
cssFile . setFileName ( m_activeThemePath + " mac.css " ) ;
cssFile . open ( QFile : : ReadOnly ) ;
css . append ( cssFile . readAll ( ) ) ;
cssFile . close ( ) ;
}
# endif
# if defined(Q_OS_WIN) || defined(Q_OS_OS2)
if ( QFile ( m_activeThemePath + " windows.css " ) . exists ( ) ) {
cssFile . setFileName ( m_activeThemePath + " windows.css " ) ;
cssFile . open ( QFile : : ReadOnly ) ;
css . append ( cssFile . readAll ( ) ) ;
cssFile . close ( ) ;
}
# endif
// RTL Support
// Loading 'rtl.css' when layout is right to left!
if ( isRightToLeft ( ) & & QFile ( m_activeThemePath + " rtl.css " ) . exists ( ) ) {
cssFile . setFileName ( m_activeThemePath + " rtl.css " ) ;
cssFile . open ( QFile : : ReadOnly ) ;
css . append ( cssFile . readAll ( ) ) ;
cssFile . close ( ) ;
}
QString relativePath = QDir : : current ( ) . relativeFilePath ( m_activeThemePath ) ;
css . replace ( QzRegExp ( " url \\ s* \\ ( \\ s*([^ \\ *: \\ );]+) \\ s* \\ ) " , Qt : : CaseSensitive ) ,
QString ( " url(%1 \\ 1) " ) . arg ( relativePath + " / " ) ) ;
setStyleSheet ( css ) ;
}
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
2014-01-17 21:39:02 +01:00
// If "xx_yy" translation doesn't exists, try to use "xx*" translation
// It can only happen when Language is chosen from system locale
if ( ! file . isEmpty ( ) & & ! QFile ( TRANSLATIONSDIR + QLatin1String ( " / " ) + file ) . exists ( ) ) {
QDir translationsDir ( TRANSLATIONSDIR ) ;
QString lang = file . left ( 2 ) + QLatin1String ( " *.qm " ) ;
const QStringList translations = translationsDir . entryList ( QStringList ( lang ) ) ;
// If no translation can be found, default English will be used
file = translations . isEmpty ( ) ? QString ( ) : translations . first ( ) ;
}
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 ) ;
}
2013-12-06 21:26:07 +01:00
void MainApplication : : backupSavedSessions ( )
{
// session.dat - current
// session.dat.old - first backup
// session.dat.old1 - second backup
const QString sessionFile = m_activeProfil + " session.dat " ;
if ( ! QFile : : exists ( sessionFile ) ) {
return ;
}
if ( QFile : : exists ( sessionFile + " .old " ) ) {
QFile : : remove ( sessionFile + " .old1 " ) ;
QFile : : copy ( sessionFile + " .old " , sessionFile + " .old1 " ) ;
}
QFile : : remove ( sessionFile + " .old " ) ;
QFile : : copy ( sessionFile , sessionFile + " .old " ) ;
}
2011-03-02 16:57:41 +01:00
void MainApplication : : quitApplication ( )
{
if ( m_downloadManager & & ! m_downloadManager - > canClose ( ) ) {
m_downloadManager - > show ( ) ;
return ;
}
2012-01-04 14:09:27 +01:00
2011-11-06 17:01:23 +01:00
if ( m_mainWindows . count ( ) > 0 ) {
2014-03-06 16:12:36 +01:00
m_autoSaver - > saveIfNecessary ( ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
2014-03-06 16:12:36 +01:00
m_isClosing = true ;
m_networkmanager - > disconnectObjects ( ) ;
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
2013-04-16 10:00:18 +02:00
if ( ! m_isPrivateSession ) {
removeLockFile ( ) ;
}
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 ) {
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
}
2011-03-02 16:57:41 +01:00
2011-10-21 23:26:34 +02:00
m_searchEnginesManager - > saveSettings ( ) ;
2014-02-13 20:46:15 +01:00
m_networkmanager - > saveSettings ( ) ;
2012-07-08 14:03:50 +02:00
m_plugins - > shutdown ( ) ;
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 ( ) ;
2014-03-07 18:24:13 +01:00
IconProvider : : instance ( ) - > saveIconsToDatabase ( ) ;
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
{
2014-03-06 16:12:36 +01:00
if ( ! m_history ) {
m_history = new History ( this ) ;
2011-11-06 17:01:23 +01:00
}
2014-03-06 16:12:36 +01:00
return m_history ;
2011-03-02 16:57:41 +01:00
}
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 ) {
2014-03-06 16:12:36 +01:00
m_cookiejar = new CookieJar ( m_isPrivateSession ? QString ( ) : m_activeProfil , this ) ;
2011-03-02 16:57:41 +01:00
}
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 ;
}
2014-02-05 15:26:51 +01:00
Bookmarks * MainApplication : : bookmarks ( )
2011-03-02 16:57:41 +01:00
{
2014-02-05 15:26:51 +01:00
if ( ! m_bookmarks ) {
2014-03-06 16:12:36 +01:00
m_bookmarks = new Bookmarks ( m_activeProfil , this ) ;
2011-11-06 17:01:23 +01:00
}
2014-02-05 15:26:51 +01:00
return m_bookmarks ;
2011-03-02 16:57:41 +01:00
}
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-05-14 17:25:55 +02:00
m_autofill = new AutoFill ( this ) ;
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 ;
2013-12-30 13:43:48 +01:00
const QString basePath = settings . value ( " Web-Browser-Settings/CachePath " ,
QString ( " %1networkcache/ " ) . arg ( m_activeProfil ) ) . toString ( ) ;
2013-02-10 14:50:18 +01:00
2013-12-30 13:43:48 +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 ;
}
2014-03-07 18:03:42 +01:00
MainApplication * MainApplication : : instance ( )
{
return static_cast < MainApplication * > ( QCoreApplication : : instance ( ) ) ;
}
2013-02-05 15:41:10 +01:00
2014-02-22 15:20:54 +01:00
void MainApplication : : startPrivateBrowsing ( const QUrl & startUrl )
2012-06-26 11:49:39 +02:00
{
2014-02-22 15:20:54 +01:00
const QUrl url = ! startUrl . isEmpty ( ) ? startUrl : qobject_cast < QAction * > ( sender ( ) ) - > data ( ) . toUrl ( ) ;
2014-02-22 14:57:22 +01:00
2012-06-26 11:49:39 +02:00
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
2014-02-22 14:57:22 +01:00
if ( ! url . isEmpty ( ) ) {
args < < url . toEncoded ( ) ;
}
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 ( )
{
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
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 " ) ) ;
2014-03-07 22:54:50 +01:00
dialog . setIcon ( IconProvider : : 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
}
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
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 ;
2014-03-03 14:47:47 +01:00
# ifndef Q_OS_UNIX
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
2013-05-02 21:01:17 +02:00
userStyle + = AdBlockManager : : instance ( ) - > elementHidingRules ( ) ;
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 ( ) ;
}
2013-12-30 13:43:48 +01:00
const QString encodedStyle = userStyle . toLatin1 ( ) . toBase64 ( ) ;
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 ) ;
}
2014-02-19 22:07:21 +01:00
void MainApplication : : aboutToCloseWindow ( BrowserWindow * 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
2014-03-06 16:18:58 +01:00
QByteArray data ;
QDataStream stream ( & data , QIODevice : : WriteOnly ) ;
2011-03-02 16:57:41 +01:00
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 + + ) {
2014-02-19 22:07:21 +01:00
BrowserWindow * qz = m_mainWindows . at ( i ) . data ( ) ;
2011-12-09 21:56:01 +01:00
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
}
2014-02-19 22:07:21 +01:00
BrowserWindow * 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
2014-03-06 16:18:58 +01:00
QFile file ( m_activeProfil + QLatin1String ( " session.dat " ) ) ;
file . open ( QIODevice : : WriteOnly ) ;
file . write ( data ) ;
file . close ( ) ;
2011-03-02 16:57:41 +01:00
return true ;
}
2014-02-19 22:07:21 +01:00
bool MainApplication : : restoreStateSlot ( BrowserWindow * 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
2014-02-19 22:07:21 +01:00
BrowserWindow * 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 ...
2013-11-26 14:14:36 +01:00
// update: it seems with ComboTabBar QTabWidget::count() is updated,
// we add pinnedTabCounts to currentTab!
int tabCount = window - > tabWidget ( ) - > pinnedTabsCount ( ) ;
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 ) {
2014-02-19 22:07:21 +01:00
BrowserWindow * window = makeNewWindow ( Qz : : BW_OtherRestoredWindow ) ;
2012-08-24 19:24:48 +02:00
window - > restoreWindowState ( data ) ;
2014-02-25 19:36:13 +01:00
// for correct geometry calculation in BrowserWindow::setupUi()
2013-08-03 22:17:15 +02:00
mApp - > processEvents ( ) ;
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
|
2014-02-09 18:55:11 +01:00
profiles / - - - - - - - - - - - - - - - - - - - - -
| |
default / - - - - - - - - - - - - - profiles . ini
| |
browsedata . db bookmarks . json
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 ) ;
2014-02-09 18:55:11 +01:00
QFile ( " :data/bookmarks.json " ) . copy ( PROFILEDIR + " profiles/default/bookmarks.json " ) ;
QFile ( PROFILEDIR + " profiles/default/bookmarks.json " ) . setPermissions ( QFile : : ReadUser | QFile : : WriteUser ) ;
2012-04-05 14:26:44 +02:00
QFile versionFile ( PROFILEDIR + " profiles/default/version " ) ;
versionFile . open ( QFile : : WriteOnly ) ;
2014-02-19 22:07:21 +01:00
versionFile . write ( Qz : : VERSION . toUtf8 ( ) ) ;
2012-04-05 14:26:44 +02:00
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 ( ) ) {
2014-03-03 14:47:47 +01:00
# ifdef Q_OS_UNIX
2013-02-22 10:06:05 +01:00
// 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 ( )
{
2013-03-16 14:57:08 +01:00
# ifdef Q_OS_MAC
delete m_macDockMenu ;
# endif
2012-08-16 23:15:31 +02:00
}