2011-03-03 18:29:20 +01:00
/* ============================================================
* QupZilla - WebKit based browser
2011-12-15 18:34:48 +01:00
* Copyright ( C ) 2010 - 2011 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"
2011-03-02 16:57:41 +01:00
# include "historymodel.h"
# include "networkmanager.h"
# include "rssmanager.h"
# include "updater.h"
# include "autosaver.h"
# include "pluginproxy.h"
# include "bookmarksmodel.h"
# include "downloadmanager.h"
# include "autofillmodel.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"
2011-10-07 17:33:51 +02:00
# include "globalfunctions.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"
2011-03-02 16:57:41 +01:00
2011-12-28 13:16:04 +01:00
# ifdef Q_WS_WIN
# define DEFAULT_CHECK_UPDATES true
# define DEFAULT_THEME_NAME "windows"
# else
# define DEFAULT_CHECK_UPDATES false
# define DEFAULT_THEME_NAME "linux"
# endif
2011-12-28 14:55:54 +01:00
# if defined(PORTABLE_BUILD) && !defined(NO_SYSTEM_DATAPATH)
# define NO_SYSTEM_DATAPATH
# endif
2011-11-06 17:01:23 +01:00
MainApplication : : MainApplication ( const QList < CommandLineOptions : : ActionPair > & cmdActions , int & argc , char * * argv )
2011-03-02 17:25:05 +01:00
: QtSingleApplication ( " QupZillaWebBrowser " , 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_updater ( 0 )
, m_plugins ( 0 )
, m_bookmarksModel ( 0 )
, m_downloadManager ( 0 )
, m_autofill ( 0 )
, m_networkCache ( new QNetworkDiskCache )
, m_desktopNotifications ( 0 )
2011-10-28 17:52:42 +02:00
, m_iconProvider ( new IconProvider ( this ) )
2011-10-21 23:26:34 +02:00
, m_searchEnginesManager ( 0 )
2011-12-17 14:30:54 +01:00
, m_dbWriter ( new DatabaseWriter ( ) )
2011-10-02 17:39:59 +02:00
, m_isClosing ( false )
, m_isStateChanged ( false )
, m_isExited ( false )
, m_isRestoring ( false )
2011-10-24 17:46:45 +02:00
, m_databaseConnected ( false )
2011-03-02 16:57:41 +01:00
{
2011-10-04 18:05:26 +02:00
# if defined(Q_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
# ifdef PORTABLE_BUILD
PROFILEDIR = DATADIR + " profiles/ " ;
# else
PROFILEDIR = QDir : : homePath ( ) + " /.qupzilla/ " ;
# endif
2011-09-11 19:15:06 +02:00
PLUGINSDIR = DATADIR + " plugins/ " ;
TRANSLATIONSDIR = DATADIR + " locale/ " ;
THEMESDIR = DATADIR + " themes/ " ;
2011-12-28 14:55:54 +01:00
setOverrideCursor ( Qt : : WaitCursor ) ;
2011-09-17 11:39:25 +02:00
setWindowIcon ( QupZilla : : qupzillaIcon ( ) ) ;
2011-03-02 16:57:41 +01:00
bool noAddons = false ;
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 ) {
2011-11-06 17:01:23 +01:00
foreach ( CommandLineOptions : : ActionPair pair , cmdActions ) {
2011-05-18 22:58:49 +02:00
switch ( pair . action ) {
2011-04-03 21:50:44 +02:00
case CommandLineOptions : : StartWithoutAddons :
noAddons = true ;
break ;
case CommandLineOptions : : StartWithProfile :
2011-05-18 22:58:49 +02:00
startProfile = pair . text ;
break ;
case CommandLineOptions : : NewTab :
2011-12-26 20:23:54 +01:00
messages . append ( " ACTION:NewTab " ) ;
2011-12-30 16:54:37 +01:00
m_postLaunchActions . append ( OpenNewTab ) ;
2011-05-18 22:58:49 +02:00
break ;
case CommandLineOptions : : NewWindow :
2011-12-26 20:23:54 +01:00
messages . append ( " ACTION:NewWindow " ) ;
2011-05-18 22:58:49 +02:00
break ;
case CommandLineOptions : : ShowDownloadManager :
2011-12-26 20:23:54 +01:00
messages . append ( " ACTION:ShowDownloadManager " ) ;
2011-12-30 16:54:37 +01:00
m_postLaunchActions . append ( OpenDownloadManager ) ;
2011-12-26 20:23:54 +01:00
break ;
case CommandLineOptions : : StartPrivateBrowsing :
messages . append ( " ACTION:StartPrivateBrowsing " ) ;
2011-12-30 16:54:37 +01:00
m_postLaunchActions . append ( PrivateBrowsing ) ;
2011-05-18 22:58:49 +02:00
break ;
case CommandLineOptions : : OpenUrl :
startUrl = pair . text ;
2011-12-26 20:23:54 +01:00
messages . append ( " URL: " + startUrl . toString ( ) ) ;
2011-04-03 21:50:44 +02:00
break ;
default :
break ;
}
2011-03-02 16:57:41 +01:00
}
}
2011-12-27 12:27:39 +01:00
if ( messages . isEmpty ( ) ) {
messages . append ( " " ) ;
}
2011-03-02 16:57:41 +01:00
if ( isRunning ( ) ) {
2011-12-27 19:10:53 +01:00
foreach ( QString message , messages ) {
2011-12-26 20:23:54 +01:00
sendMessage ( message ) ;
}
2011-03-02 16:57:41 +01:00
m_isExited = true ;
return ;
}
connect ( this , SIGNAL ( messageReceived ( QString ) ) , this , SLOT ( receiveAppMessage ( QString ) ) ) ;
setQuitOnLastWindowClosed ( true ) ;
setApplicationName ( " QupZilla " ) ;
setApplicationVersion ( QupZilla : : VERSION ) ;
setOrganizationDomain ( " qupzilla " ) ;
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 ) ;
2011-11-06 17:01:23 +01:00
if ( settings . value ( " Profiles/startProfile " , " default " ) . toString ( ) . contains ( " / " ) ) {
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
2011-11-06 17:01:23 +01:00
QSettings settings2 ( m_activeProfil + " settings.ini " , QSettings : : IniFormat ) ;
2011-03-02 16:57:41 +01:00
settings2 . beginGroup ( " SessionRestore " ) ;
2011-11-06 17:01:23 +01:00
if ( settings2 . value ( " isRunning " , false ) . toBool ( ) ) {
2011-03-02 16:57:41 +01:00
settings2 . setValue ( " isCrashed " , true ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
settings2 . setValue ( " isRunning " , true ) ;
settings2 . endGroup ( ) ;
QSettings : : setPath ( QSettings : : IniFormat , QSettings : : UserScope , m_activeProfil ) ;
translateApp ( ) ;
2011-07-31 13:33:44 +02:00
QWebHistoryInterface : : setDefaultInterface ( new WebHistoryInterface ( this ) ) ;
2011-03-02 16:57:41 +01:00
2011-11-03 18:51:46 +01:00
QupZilla * qupzilla = new QupZilla ( QupZilla : : FirstAppWindow , startUrl ) ;
2011-03-02 16:57:41 +01:00
m_mainWindows . append ( qupzilla ) ;
2011-11-06 17:01:23 +01:00
connect ( qupzilla , SIGNAL ( message ( MainApplication : : MessageType , bool ) ) , this , SLOT ( sendMessages ( MainApplication : : MessageType , bool ) ) ) ;
2011-03-02 16:57:41 +01:00
qupzilla - > show ( ) ;
AutoSaver * saver = new AutoSaver ( ) ;
connect ( saver , SIGNAL ( saveApp ( ) ) , this , SLOT ( saveStateSlot ( ) ) ) ;
2011-10-02 17:39:59 +02:00
2011-12-28 13:16:04 +01:00
if ( settings2 . value ( " Web-Browser-Settings/CheckUpdates " , DEFAULT_CHECK_UPDATES ) . toBool ( ) ) {
2011-10-02 17:39:59 +02:00
m_updater = new Updater ( qupzilla ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
if ( noAddons ) {
2011-07-31 13:33:44 +02:00
settings2 . setValue ( " Plugin-Settings/AllowedPlugins " , QStringList ( ) ) ;
settings2 . setValue ( " Plugin-Settings/EnablePlugins " , false ) ;
2011-03-02 16:57:41 +01:00
}
2011-10-12 22:28:41 +02:00
networkManager ( ) - > loadCertificates ( ) ;
2011-03-02 16:57:41 +01:00
plugins ( ) - > loadPlugins ( ) ;
loadSettings ( ) ;
2011-03-29 19:55:21 +02:00
2011-12-30 16:54:37 +01:00
QTimer : : singleShot ( 0 , this , SLOT ( postLaunch ( ) ) ) ;
2011-03-29 19:55:21 +02:00
QTimer : : singleShot ( 2000 , this , SLOT ( restoreCursor ( ) ) ) ;
2011-12-30 16:54:37 +01:00
# ifdef Q_WS_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 ( PrivateBrowsing ) ) {
togglePrivateBrowsingMode ( true ) ;
}
if ( m_postLaunchActions . contains ( OpenDownloadManager ) ) {
downManager ( ) - > show ( ) ;
}
if ( m_postLaunchActions . contains ( OpenNewTab ) ) {
getWindow ( ) - > tabWidget ( ) - > addView ( ) ;
}
2011-03-02 16:57:41 +01:00
}
void MainApplication : : loadSettings ( )
{
2011-11-06 17:01:23 +01:00
QSettings settings ( m_activeProfil + " settings.ini " , QSettings : : IniFormat ) ;
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 ( ) ;
# ifdef Q_WS_X11
if ( QFile ( m_activeThemePath + " linux.css " ) . exists ( ) ) {
cssFile . setFileName ( m_activeThemePath + " linux.css " ) ;
cssFile . open ( QFile : : ReadOnly ) ;
css . append ( cssFile . readAll ( ) ) ;
cssFile . close ( ) ;
}
# endif
2011-12-14 22:30:05 +01:00
# if defined(Q_WS_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
QString relativePath = QDir : : current ( ) . relativeFilePath ( m_activeThemePath ) ;
css . replace ( QRegExp ( " url \\ s* \\ ( \\ s*([^ \\ *: \\ );]+) \\ s* \\ ) " , Qt : : CaseSensitive , QRegExp : : RegExp2 ) ,
QString ( " url(%1 \\ 1) " ) . arg ( relativePath + " / " ) ) ;
setStyleSheet ( css ) ;
2011-03-02 16:57:41 +01:00
webSettings ( ) ;
//Web browsing settings
settings . beginGroup ( " Web-Browser-Settings " ) ;
2011-11-06 17:01:23 +01:00
bool allowFlash = settings . value ( " allowFlash " , true ) . toBool ( ) ;
bool allowJavaScript = settings . value ( " allowJavaScript " , true ) . toBool ( ) ;
bool allowJavaScriptOpenWindow = settings . value ( " allowJavaScriptOpenWindow " , false ) . toBool ( ) ;
bool allowJava = settings . value ( " allowJava " , true ) . toBool ( ) ;
bool allowPersistentStorage = settings . value ( " allowPersistentStorage " , true ) . toBool ( ) ;
bool allowImages = settings . value ( " autoLoadImages " , true ) . toBool ( ) ;
2011-03-02 16:57:41 +01:00
bool dnsPrefetch = settings . value ( " DNS-Prefetch " , false ) . toBool ( ) ;
bool jsClipboard = settings . value ( " JavaScriptCanAccessClipboard " , true ) . toBool ( ) ;
bool linkInFocuschain = settings . value ( " IncludeLinkInFocusChain " , false ) . toBool ( ) ;
bool zoomTextOnly = settings . value ( " zoomTextOnly " , false ) . toBool ( ) ;
bool printElBg = settings . value ( " PrintElementBackground " , true ) . toBool ( ) ;
2011-11-13 20:36:10 +01:00
bool xssAuditing = settings . value ( " XSSAuditing " , false ) . toBool ( ) ;
2011-11-06 17:01:23 +01:00
int maxCachedPages = settings . value ( " maximumCachedPages " , 3 ) . toInt ( ) ;
2011-03-02 16:57:41 +01:00
int scrollingLines = settings . value ( " wheelScrollLines " , wheelScrollLines ( ) ) . toInt ( ) ;
2011-12-07 13:54:06 +01:00
QUrl userStyleSheet = QUrl : : fromLocalFile ( settings . value ( " userStyleSheet " , " " ) . toString ( ) ) ;
2011-10-29 18:37:28 +02:00
m_defaultZoom = settings . value ( " DefaultZoom " , 100 ) . toInt ( ) ;
2011-12-11 19:37:16 +01:00
WebPage : : UserAgent = settings . value ( " UserAgent " , " " ) . toString ( ) ;
2011-03-02 16:57:41 +01:00
settings . endGroup ( ) ;
2011-12-11 19:37:16 +01:00
2011-03-02 16:57:41 +01:00
m_websettings - > setAttribute ( QWebSettings : : DeveloperExtrasEnabled , true ) ;
m_websettings - > setAttribute ( QWebSettings : : PluginsEnabled , allowFlash ) ;
m_websettings - > setAttribute ( QWebSettings : : JavascriptEnabled , allowJavaScript ) ;
m_websettings - > setAttribute ( QWebSettings : : JavascriptCanOpenWindows , allowJavaScriptOpenWindow ) ;
m_websettings - > setAttribute ( QWebSettings : : JavaEnabled , allowJava ) ;
m_websettings - > setAttribute ( QWebSettings : : AutoLoadImages , allowImages ) ;
m_websettings - > setAttribute ( QWebSettings : : DnsPrefetchEnabled , dnsPrefetch ) ;
m_websettings - > setAttribute ( QWebSettings : : JavascriptCanAccessClipboard , jsClipboard ) ;
m_websettings - > setAttribute ( QWebSettings : : LinksIncludedInFocusChain , linkInFocuschain ) ;
m_websettings - > setAttribute ( QWebSettings : : ZoomTextOnly , zoomTextOnly ) ;
m_websettings - > setAttribute ( QWebSettings : : PrintElementBackgrounds , printElBg ) ;
2011-11-13 20:36:10 +01:00
m_websettings - > setAttribute ( QWebSettings : : XSSAuditingEnabled , xssAuditing ) ;
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
2011-11-05 22:02:23 +01:00
# if (QTWEBKIT_VERSION >= QTWEBKIT_VERSION_CHECK(2, 2, 0))
m_websettings - > setAttribute ( QWebSettings : : HyperlinkAuditingEnabled , true ) ;
m_websettings - > setAttribute ( QWebSettings : : JavascriptCanCloseWindows , true ) ;
# endif
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 ( ) ) ;
2011-12-11 19:37:16 +01:00
settings . endGroup ( ) ;
2011-03-17 15:35:51 +01:00
2011-05-10 21:25:31 +02:00
m_websettings - > setUserStyleSheetUrl ( userStyleSheet ) ;
2011-03-17 20:46:53 +01:00
m_websettings - > setDefaultTextEncoding ( " System " ) ;
2011-11-06 17:01:23 +01:00
m_websettings - > setWebGraphic ( QWebSettings : : DefaultFrameIconGraphic , IconProvider : : fromTheme ( " text-plain " ) . pixmap ( 16 , 16 ) ) ;
2011-12-10 13:15:07 +01:00
// Allows to load files from qrc: scheme in qupzilla: pages
2011-12-02 23:25:27 +01:00
QWebSecurityOrigin : : addLocalScheme ( " qupzilla " ) ;
2011-03-17 20:46:53 +01:00
2011-11-06 17:01:23 +01:00
if ( allowPersistentStorage ) {
m_websettings - > enablePersistentStorage ( m_activeProfil ) ;
}
2011-03-02 16:57:41 +01:00
m_websettings - > setMaximumPagesInCache ( maxCachedPages ) ;
setWheelScrollLines ( scrollingLines ) ;
2011-05-25 14:26:36 +02:00
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
}
2011-03-02 16:57:41 +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 ( )
{
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
}
2011-12-09 21:56:01 +01:00
return m_mainWindows . at ( i ) . data ( ) ;
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 ;
2011-07-30 17:57:14 +02:00
sendMessages ( 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 ;
}
2011-12-30 16:54:37 +01:00
void MainApplication : : togglePrivateBrowsingMode ( bool state )
{
webSettings ( ) - > setAttribute ( QWebSettings : : PrivateBrowsingEnabled , state ) ;
history ( ) - > setSaving ( ! state ) ;
cookieJar ( ) - > turnPrivateJar ( state ) ;
emit message ( MainApplication : : CheckPrivateBrowsing , state ) ;
}
2011-03-02 16:57:41 +01:00
void MainApplication : : sendMessages ( MainApplication : : MessageType mes , bool state )
{
emit message ( mes , state ) ;
}
void MainApplication : : receiveAppMessage ( QString message )
{
2011-12-27 12:27:39 +01:00
QWidget * actWin = getWindow ( ) ;
2011-03-02 16:57:41 +01:00
if ( message . startsWith ( " URL: " ) ) {
QString url ( message . remove ( " URL: " ) ) ;
addNewTab ( WebView : : guessUrlFromString ( url ) ) ;
2011-12-27 12:27:39 +01:00
actWin = getWindow ( ) ;
2011-11-06 17:01:23 +01:00
}
else if ( message . startsWith ( " ACTION: " ) ) {
2011-05-18 22:58:49 +02:00
QString text = message . mid ( 7 ) ;
2011-11-06 17:01:23 +01:00
if ( text = = " NewTab " ) {
2011-05-18 22:58:49 +02:00
addNewTab ( ) ;
2011-12-27 12:27:39 +01:00
actWin = getWindow ( ) ;
2011-11-06 17:01:23 +01:00
}
else if ( text = = " NewWindow " ) {
2011-12-27 12:27:39 +01:00
actWin = makeNewWindow ( false ) ;
2011-11-06 17:01:23 +01:00
}
else if ( text = = " 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
}
2011-12-26 20:23:54 +01:00
else if ( text = = " StartPrivateBrowsing " ) {
sendMessages ( StartPrivateBrowsing , true ) ;
2011-12-27 12:27:39 +01:00
actWin = getWindow ( ) ;
2011-12-26 20:23:54 +01:00
}
2011-03-02 16:57:41 +01:00
}
2011-03-31 16:01:59 +02:00
if ( ! actWin & & ! isClosing ( ) ) { // It can only occur if download manager window was still open
2011-03-02 16:57:41 +01:00
makeNewWindow ( true ) ;
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 ( ) ;
}
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
}
2011-03-02 16:57:41 +01:00
getWindow ( ) - > tabWidget ( ) - > addView ( url ) ;
}
2011-12-27 12:27:39 +01:00
QupZilla * MainApplication : : makeNewWindow ( bool tryRestore , const QUrl & startUrl )
2011-03-02 16:57:41 +01:00
{
2011-11-03 18:51:46 +01:00
QupZilla : : StartBehaviour behaviour ;
2011-11-06 17:01:23 +01:00
if ( tryRestore ) {
2011-11-03 18:51:46 +01:00
behaviour = QupZilla : : OtherRestoredWindow ;
2011-11-06 17:01:23 +01:00
}
else {
2011-11-03 18:51:46 +01:00
behaviour = QupZilla : : NewWindow ;
2011-11-06 17:01:23 +01:00
}
2011-11-03 18:51:46 +01:00
QupZilla * newWindow = new QupZilla ( behaviour , startUrl ) ;
2011-11-06 17:01:23 +01:00
connect ( newWindow , SIGNAL ( message ( MainApplication : : MessageType , bool ) ) , this , SLOT ( sendMessages ( MainApplication : : MessageType , bool ) ) ) ;
2011-03-02 16:57:41 +01:00
m_mainWindows . append ( newWindow ) ;
2011-03-05 13:16:13 +01:00
newWindow - > show ( ) ;
2011-12-27 12:27:39 +01:00
return newWindow ;
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! " ) ;
}
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 ( )
{
QLocale locale ;
2011-11-06 17:01:23 +01:00
QSettings settings ( m_activeProfil + " settings.ini " , QSettings : : IniFormat ) ;
2011-10-18 17:39:51 +02:00
settings . beginGroup ( " Language " ) ;
2011-11-06 17:01:23 +01:00
QString file = settings . value ( " language " , locale . name ( ) + " .qm " ) . toString ( ) ;
2011-03-02 16:57:41 +01:00
QString shortLoc = file . left ( 2 ) ;
2011-11-06 17:01:23 +01:00
if ( file = = " " | | ! QFile : : exists ( TRANSLATIONSDIR + file ) ) {
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
QTranslator * app = new QTranslator ( ) ;
2011-12-27 15:26:32 +01:00
app - > load ( TRANSLATIONSDIR + file ) ;
2011-03-02 16:57:41 +01:00
QTranslator * sys = new QTranslator ( ) ;
2011-11-06 17:01:23 +01:00
if ( QFile : : exists ( TRANSLATIONSDIR + " qt_ " + shortLoc + " .qm " ) ) {
2011-09-11 19:15:06 +02:00
sys - > load ( TRANSLATIONSDIR + " qt_ " + shortLoc + " .qm " ) ;
2011-11-06 17:01:23 +01:00
}
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 ;
}
m_isClosing = true ;
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
2011-11-06 17:01:23 +01:00
QSettings settings ( m_activeProfil + " settings.ini " , QSettings : : IniFormat ) ;
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 . setValue ( " isCrashed " , false ) ;
settings . endGroup ( ) ;
2011-10-18 17:39:51 +02:00
bool deleteCookies = settings . value ( " Web-Browser-Settings/deleteCookiesOnClose " , false ) . toBool ( ) ;
bool deleteHistory = settings . value ( " Web-Browser-Settings/deleteHistoryOnClose " , false ) . toBool ( ) ;
2011-03-02 16:57:41 +01:00
2011-11-06 17:01:23 +01:00
if ( deleteCookies ) {
QFile : : remove ( m_activeProfil + " cookies.dat " ) ;
}
if ( deleteHistory ) {
2011-04-26 10:03:17 +02:00
m_historymodel - > clearHistory ( ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
2011-10-21 23:26:34 +02:00
m_searchEnginesManager - > saveSettings ( ) ;
2011-03-02 16:57:41 +01:00
cookieJar ( ) - > saveCookies ( ) ;
2011-10-12 22:28:41 +02:00
m_networkmanager - > saveCertificates ( ) ;
2011-03-02 16:57:41 +01:00
m_plugins - > c2f_saveSettings ( ) ;
2011-12-02 23:25:27 +01:00
m_plugins - > speedDial ( ) - > saveSettings ( ) ;
2011-03-27 21:59:40 +02:00
AdBlockManager : : instance ( ) - > save ( ) ;
2011-09-11 19:15:06 +02:00
QFile : : remove ( getActiveProfilPath ( ) + " WebpageIcons.db " ) ;
2011-12-04 20:09:44 +01:00
m_iconProvider - > saveIconsToDatabase ( ) ;
2011-03-02 16:57:41 +01:00
2011-07-30 17:57:14 +02:00
// qDebug() << "Quitting application...";
2011-03-02 16:57:41 +01:00
quit ( ) ;
}
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
}
PluginProxy * MainApplication : : plugins ( )
{
2011-11-06 17:01:23 +01:00
if ( ! m_plugins ) {
2011-03-02 16:57:41 +01:00
m_plugins = new PluginProxy ( ) ;
2011-11-06 17:01:23 +01:00
}
2011-03-02 16:57:41 +01:00
return m_plugins ;
}
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 ;
}
HistoryModel * MainApplication : : history ( )
{
2011-11-06 17:01:23 +01:00
if ( ! m_historymodel ) {
2011-03-02 16:57:41 +01:00
m_historymodel = new HistoryModel ( getWindow ( ) ) ;
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 ) {
2011-03-02 16:57:41 +01:00
m_networkmanager = new NetworkManager ( getWindow ( ) ) ;
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 ;
}
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 ;
}
AutoFillModel * MainApplication : : autoFill ( )
{
2011-11-06 17:01:23 +01:00
if ( ! m_autofill ) {
2011-03-02 16:57:41 +01:00
m_autofill = new AutoFillModel ( 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 ;
}
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 ;
}
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
m_mainWindows . removeOne ( window ) ;
}
2011-03-05 13:43:37 +01:00
//Version of session.dat file
2011-03-02 16:57:41 +01:00
static const int sessionVersion = 0x0002 ;
bool MainApplication : : saveStateSlot ( )
{
2011-11-06 17:01:23 +01:00
if ( m_websettings - > testAttribute ( QWebSettings : : PrivateBrowsingEnabled ) | | m_isRestoring ) {
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
QSettings settings ( m_activeProfil + " settings.ini " , QSettings : : IniFormat ) ;
2011-03-02 16:57:41 +01:00
settings . beginGroup ( " SessionRestore " ) ;
2011-11-06 17:01:23 +01:00
settings . setValue ( " restoreSession " , false ) ;
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 ) ;
stream < < sessionVersion ;
stream < < m_mainWindows . count ( ) ;
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 ( ) ;
2011-11-06 17:01:23 +01:00
settings . setValue ( " restoreSession " , true ) ;
2011-03-02 16:57:41 +01:00
settings . endGroup ( ) ;
QupZilla * qupzilla_ = getWindow ( ) ;
2011-11-06 17:01:23 +01:00
if ( qupzilla_ ) {
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
2011-03-02 16:57:41 +01:00
return true ;
}
2011-03-17 17:03:04 +01:00
bool MainApplication : : restoreStateSlot ( QupZilla * window )
2011-03-02 16:57:41 +01:00
{
2011-12-30 16:54:37 +01:00
if ( m_postLaunchActions . contains ( PrivateBrowsing ) ) {
return false ;
}
2011-04-07 18:00:26 +02:00
m_isRestoring = true ;
2011-11-06 17:01:23 +01:00
QSettings settings ( m_activeProfil + " settings.ini " , QSettings : : IniFormat ) ;
2011-04-07 18:00:26 +02:00
int afterStart = settings . value ( " Web-URL-Settings/afterLaunch " , 1 ) . toInt ( ) ;
2011-03-02 16:57:41 +01:00
settings . beginGroup ( " SessionRestore " ) ;
2011-11-06 17:01:23 +01:00
if ( ! settings . value ( " restoreSession " , false ) . toBool ( ) ) {
2011-04-07 18:00:26 +02:00
m_isRestoring = false ;
2011-03-02 16:57:41 +01:00
return false ;
2011-04-07 18:00:26 +02:00
}
2011-12-10 22:53:01 +01:00
if ( settings . value ( " isCrashed " , false ) . toBool ( ) & & afterStart ! = 3 ) {
2011-03-02 16:57:41 +01:00
QMessageBox : : StandardButton button = QMessageBox : : warning ( window , tr ( " Last session crashed " ) ,
2011-12-16 19:38:29 +01:00
tr ( " <b>QupZilla crashed :-(</b><br/>Oops, the last session of QupZilla was interrupted unexpectedly. We apologize for this. Would you like to try restoring the last saved state? " ) ,
2011-11-06 17:01:23 +01:00
QMessageBox : : Yes | QMessageBox : : No , QMessageBox : : Yes ) ;
2011-04-07 18:00:26 +02:00
if ( button ! = QMessageBox : : Yes ) {
m_isRestoring = false ;
2011-03-02 16:57:41 +01:00
return false ;
2011-04-07 18:00:26 +02:00
}
2011-03-02 16:57:41 +01:00
}
2011-11-06 17:01:23 +01:00
if ( ! QFile : : exists ( m_activeProfil + " session.dat " ) ) {
2011-04-07 18:00:26 +02:00
m_isRestoring = false ;
2011-03-02 16:57:41 +01:00
return false ;
2011-04-07 18:00:26 +02:00
}
2011-03-02 16:57:41 +01:00
2011-11-06 17:01:23 +01:00
settings . setValue ( " isCrashed " , false ) ;
QFile file ( m_activeProfil + " session.dat " ) ;
2011-03-02 16:57:41 +01:00
file . open ( QIODevice : : ReadOnly ) ;
QDataStream stream ( & file ) ;
QByteArray tabState ;
QByteArray qMainWindowState ;
int version ;
int windowCount ;
stream > > version ;
2011-04-07 18:00:26 +02:00
if ( version ! = sessionVersion ) {
m_isRestoring = false ;
2011-03-02 16:57:41 +01:00
return false ;
2011-04-07 18:00:26 +02:00
}
2011-03-02 16:57:41 +01:00
stream > > windowCount ;
stream > > tabState ;
stream > > qMainWindowState ;
window - > tabWidget ( ) - > restoreState ( tabState ) ;
window - > restoreState ( qMainWindowState ) ;
if ( windowCount > 1 ) {
2011-04-07 18:00:26 +02:00
for ( int i = 1 ; i < windowCount ; i + + ) {
2011-03-02 16:57:41 +01:00
stream > > tabState ;
stream > > qMainWindowState ;
2011-11-03 18:51:46 +01:00
QupZilla * window = new QupZilla ( QupZilla : : OtherRestoredWindow ) ;
2011-03-02 16:57:41 +01:00
m_mainWindows . append ( window ) ;
2011-11-06 17:01:23 +01:00
connect ( window , SIGNAL ( message ( MainApplication : : MessageType , bool ) ) , this , SLOT ( sendMessages ( MainApplication : : MessageType , bool ) ) ) ;
2011-03-02 16:57:41 +01:00
QEventLoop eLoop ;
connect ( window , SIGNAL ( startingCompleted ( ) ) , & eLoop , SLOT ( quit ( ) ) ) ;
eLoop . exec ( ) ;
window - > tabWidget ( ) - > restoreState ( tabState ) ;
window - > restoreState ( qMainWindowState ) ;
2011-04-07 18:00:26 +02:00
// window->tabWidget()->closeTab(0);
2011-03-02 16:57:41 +01:00
window - > show ( ) ;
}
}
2011-04-07 18:00:26 +02:00
file . close ( ) ;
2011-03-02 16:57:41 +01:00
2011-04-07 18:00:26 +02:00
m_isRestoring = false ;
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
|
. qupzilla /
|
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
std : : cout < < " Creating new profile directory " < < std : : endl ;
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 " ) ;
//.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 " ) ;
//.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 ) ;
2011-03-02 16:57:41 +01:00
return dir . isReadable ( ) ;
}