2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2012-01-01 15:29:55 +01:00
|
|
|
* Copyright (C) 2010-2012 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "mainapplication.h"
|
|
|
|
#include "qupzilla.h"
|
|
|
|
#include "tabwidget.h"
|
|
|
|
#include "bookmarkstoolbar.h"
|
|
|
|
#include "cookiemanager.h"
|
|
|
|
#include "cookiejar.h"
|
2011-07-29 15:39:43 +02:00
|
|
|
#include "browsinglibrary.h"
|
2012-04-30 16:33:14 +02:00
|
|
|
#include "history.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "networkmanager.h"
|
|
|
|
#include "rssmanager.h"
|
|
|
|
#include "updater.h"
|
|
|
|
#include "autosaver.h"
|
|
|
|
#include "pluginproxy.h"
|
|
|
|
#include "bookmarksmodel.h"
|
|
|
|
#include "downloadmanager.h"
|
|
|
|
#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"
|
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"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#ifdef Q_WS_MAC
|
|
|
|
#include <QFileOpenEvent>
|
|
|
|
#endif
|
|
|
|
#include <QWebSecurityOrigin>
|
|
|
|
#include <QNetworkDiskCache>
|
|
|
|
#include <QDesktopServices>
|
2012-06-26 11:49:39 +02:00
|
|
|
#include <QTranslator>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QSettings>
|
2012-06-26 11:49:39 +02:00
|
|
|
#include <QProcess>
|
|
|
|
#include <QDebug>
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QTimer>
|
2012-06-26 11:49:39 +02:00
|
|
|
#include <QDir>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2011-12-28 14:55:54 +01:00
|
|
|
#if defined(PORTABLE_BUILD) && !defined(NO_SYSTEM_DATAPATH)
|
|
|
|
#define NO_SYSTEM_DATAPATH
|
|
|
|
#endif
|
|
|
|
|
2012-03-24 22:08:17 +01:00
|
|
|
MainApplication::MainApplication(int &argc, char** argv)
|
2012-06-26 11:49:39 +02:00
|
|
|
: QtSingleApplication(argc, argv)
|
2011-10-02 17:39:59 +02:00
|
|
|
, m_cookiemanager(0)
|
|
|
|
, m_browsingLibrary(0)
|
|
|
|
, m_historymodel(0)
|
|
|
|
, m_websettings(0)
|
|
|
|
, m_networkmanager(0)
|
|
|
|
, m_cookiejar(0)
|
|
|
|
, m_rssmanager(0)
|
|
|
|
, m_bookmarksModel(0)
|
|
|
|
, m_downloadManager(0)
|
|
|
|
, m_autofill(0)
|
2012-06-15 17:43:19 +02:00
|
|
|
, m_networkCache(0)
|
2011-10-02 17:39:59 +02:00
|
|
|
, m_desktopNotifications(0)
|
2011-10-21 23:26:34 +02:00
|
|
|
, m_searchEnginesManager(0)
|
2012-03-14 14:04:20 +01:00
|
|
|
, m_dbWriter(new DatabaseWriter(this))
|
2012-06-26 11:49:39 +02:00
|
|
|
, m_isPrivateSession(false)
|
2011-10-02 17:39:59 +02:00
|
|
|
, m_isClosing(false)
|
|
|
|
, m_isStateChanged(false)
|
|
|
|
, m_isRestoring(false)
|
2012-03-14 14:04:20 +01:00
|
|
|
, m_startingAfterCrash(false)
|
2011-10-24 17:46:45 +02:00
|
|
|
, m_databaseConnected(false)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-12 20:32:09 +01: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
|
|
|
|
2012-01-12 20:32:09 +01:00
|
|
|
#ifdef Q_WS_MAC
|
2012-01-27 17:25:51 +01:00
|
|
|
DATADIR.append("../Resources/");
|
2012-01-12 20:32:09 +01:00
|
|
|
#endif
|
|
|
|
|
2011-12-28 14:55:54 +01:00
|
|
|
#ifdef PORTABLE_BUILD
|
|
|
|
PROFILEDIR = DATADIR + "profiles/";
|
|
|
|
#else
|
|
|
|
PROFILEDIR = QDir::homePath() + "/.qupzilla/";
|
|
|
|
#endif
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
TRANSLATIONSDIR = DATADIR + "locale/";
|
|
|
|
THEMESDIR = DATADIR + "themes/";
|
|
|
|
|
2011-12-28 14:55:54 +01:00
|
|
|
setOverrideCursor(Qt::WaitCursor);
|
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-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);
|
|
|
|
|
|
|
|
foreach(const CommandLineOptions::ActionPair & pair, cmd.getActions()) {
|
2011-05-18 22:58:49 +02:00
|
|
|
switch (pair.action) {
|
2012-01-21 23:19:38 +01:00
|
|
|
case Qz::CL_StartWithoutAddons:
|
2011-04-03 21:50:44 +02:00
|
|
|
noAddons = true;
|
|
|
|
break;
|
2012-01-21 23:19:38 +01:00
|
|
|
case Qz::CL_StartWithProfile:
|
2011-05-18 22:58:49 +02:00
|
|
|
startProfile = pair.text;
|
|
|
|
break;
|
2012-01-21 23:19:38 +01:00
|
|
|
case Qz::CL_NewTab:
|
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;
|
2012-01-21 23:19:38 +01:00
|
|
|
case Qz::CL_NewWindow:
|
2011-12-26 20:23:54 +01:00
|
|
|
messages.append("ACTION:NewWindow");
|
2011-05-18 22:58:49 +02:00
|
|
|
break;
|
2012-01-21 23:19:38 +01:00
|
|
|
case Qz::CL_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;
|
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-04-03 20:41:07 +02:00
|
|
|
case Qz::CL_OpenUrlInCurrentTab:
|
|
|
|
startUrl = QUrl::fromUserInput(pair.text);
|
|
|
|
messages.append("ACTION:OpenUrlInCurrentTab" + pair.text);
|
2012-07-10 00:36:05 +02:00
|
|
|
break;
|
|
|
|
case Qz::CL_OpenUrlInNewWindow:
|
|
|
|
startUrl = QUrl::fromUserInput(pair.text);
|
|
|
|
messages.append("ACTION:OpenUrlInNewWindow" + pair.text);
|
2012-04-03 20:41:07 +02:00
|
|
|
break;
|
2012-01-21 23:19:38 +01:00
|
|
|
case Qz::CL_OpenUrl:
|
2012-03-24 22:08:17 +01:00
|
|
|
startUrl = QUrl::fromUserInput(pair.text);
|
2012-03-16 23:28:23 +01:00
|
|
|
messages.append("URL:" + pair.text);
|
2011-04-03 21:50:44 +02:00
|
|
|
break;
|
2012-03-24 22:08:17 +01:00
|
|
|
case Qz::CL_ExitAction:
|
|
|
|
m_isClosing = true;
|
|
|
|
return;
|
2011-04-03 21:50:44 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-26 11:49:39 +02:00
|
|
|
// Don't start single application in private browsing
|
|
|
|
if (!m_isPrivateSession) {
|
|
|
|
setAppId("QupZillaWebBrowser");
|
|
|
|
}
|
|
|
|
|
2011-12-27 12:27:39 +01:00
|
|
|
if (messages.isEmpty()) {
|
|
|
|
messages.append(" ");
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
if (isRunning()) {
|
2012-01-24 19:12:31 +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-01-06 15:03:48 +01:00
|
|
|
#ifdef Q_WS_MAC
|
|
|
|
setQuitOnLastWindowClosed(false);
|
|
|
|
#else
|
2011-03-02 16:57:41 +01:00
|
|
|
setQuitOnLastWindowClosed(true);
|
2012-01-06 15:03:48 +01:00
|
|
|
#endif
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
setApplicationName("QupZilla");
|
|
|
|
setApplicationVersion(QupZilla::VERSION);
|
|
|
|
setOrganizationDomain("qupzilla");
|
2012-01-06 15:03:48 +01:00
|
|
|
QDesktopServices::setUrlHandler("http", this, "addNewTab");
|
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-07-01 18:50:18 +02: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
|
|
|
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings::createSettings(m_activeProfil + "settings.ini");
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
translateApp();
|
|
|
|
|
2012-01-21 23:19:38 +01:00
|
|
|
QupZilla* qupzilla = new QupZilla(Qz::BW_FirstAppWindow, startUrl);
|
2011-03-02 16:57:41 +01:00
|
|
|
qupzilla->show();
|
2012-03-13 15:10:18 +01:00
|
|
|
m_mainWindows.append(qupzilla);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-03-13 15:10:18 +01:00
|
|
|
connect(qupzilla, SIGNAL(message(Qz::AppMessageType, bool)), this, SLOT(sendMessages(Qz::AppMessageType, bool)));
|
|
|
|
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
|
|
|
networkManager()->loadCertificates();
|
|
|
|
|
2012-04-04 21:12:52 +02:00
|
|
|
m_plugins = new PluginProxy;
|
|
|
|
|
2012-03-13 15:10:18 +01:00
|
|
|
if (!noAddons) {
|
2012-04-04 21:12:52 +02:00
|
|
|
m_plugins->loadPlugins();
|
2012-03-13 15:10:18 +01:00
|
|
|
}
|
2011-03-29 19:55:21 +02:00
|
|
|
|
2012-06-26 11:49:39 +02:00
|
|
|
if (!m_isPrivateSession) {
|
|
|
|
Settings settings;
|
|
|
|
m_startingAfterCrash = settings.value("SessionRestore/isRunning", false).toBool();
|
|
|
|
bool checkUpdates = settings.value("Web-Browser-Settings/CheckUpdates", DEFAULT_CHECK_UPDATES).toBool();
|
|
|
|
settings.setValue("SessionRestore/isRunning", true);
|
|
|
|
|
|
|
|
if (checkUpdates) {
|
|
|
|
new Updater(qupzilla);
|
|
|
|
}
|
2012-03-14 14:04:20 +01:00
|
|
|
}
|
|
|
|
|
2011-12-30 16:54:37 +01:00
|
|
|
QTimer::singleShot(0, this, SLOT(postLaunch()));
|
|
|
|
#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(OpenDownloadManager)) {
|
|
|
|
downManager()->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_postLaunchActions.contains(OpenNewTab)) {
|
2012-01-26 20:19:56 +01:00
|
|
|
getWindow()->tabWidget()->addView(QUrl(), Qz::NT_SelectedTabAtTheEnd);
|
2011-12-30 16:54:37 +01:00
|
|
|
}
|
2012-03-13 15:10:18 +01:00
|
|
|
|
|
|
|
AutoSaver* saver = new AutoSaver();
|
|
|
|
connect(saver, SIGNAL(saveApp()), this, SLOT(saveStateSlot()));
|
|
|
|
|
|
|
|
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, m_activeProfil);
|
|
|
|
QWebHistoryInterface::setDefaultInterface(new WebHistoryInterface(this));
|
|
|
|
|
|
|
|
connect(this, SIGNAL(messageReceived(QString)), this, SLOT(receiveAppMessage(QString)));
|
|
|
|
connect(this, SIGNAL(aboutToQuit()), this, SLOT(saveSettings()));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainApplication::loadSettings()
|
|
|
|
{
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings settings;
|
2011-09-11 19:15:06 +02:00
|
|
|
settings.beginGroup("Themes");
|
2011-12-28 13:16:04 +01:00
|
|
|
QString activeTheme = settings.value("activeTheme", DEFAULT_THEME_NAME).toString();
|
2011-09-11 19:15:06 +02:00
|
|
|
settings.endGroup();
|
|
|
|
m_activeThemePath = THEMESDIR + activeTheme + "/";
|
|
|
|
QFile cssFile(m_activeThemePath + "main.css");
|
|
|
|
cssFile.open(QFile::ReadOnly);
|
|
|
|
QString css = cssFile.readAll();
|
|
|
|
cssFile.close();
|
|
|
|
#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
|
2012-01-06 14:17:46 +01:00
|
|
|
#ifdef Q_WS_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
|
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();
|
2012-03-30 12:02:49 +02:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
//Web browsing settings
|
|
|
|
settings.beginGroup("Web-Browser-Settings");
|
2012-06-26 11:49:39 +02:00
|
|
|
|
|
|
|
if (!m_isPrivateSession) {
|
|
|
|
m_websettings->enablePersistentStorage(m_activeProfil);
|
|
|
|
m_websettings->setAttribute(QWebSettings::LocalStorageEnabled, settings.value("HTML5StorageEnabled", true).toBool());
|
|
|
|
}
|
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());
|
|
|
|
m_websettings->setAttribute(QWebSettings::JavascriptCanAccessClipboard, settings.value("JavaScriptCanAccessClipboard", true).toBool());
|
|
|
|
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());
|
|
|
|
|
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
|
|
|
|
|
2012-03-30 12:02:49 +02:00
|
|
|
setWheelScrollLines(settings.value("wheelScrollLines", wheelScrollLines()).toInt());
|
2012-06-25 16:07:25 +02:00
|
|
|
m_websettings->setUserStyleSheetUrl(userStyleSheet(settings.value("userStyleSheet", "").toString()));
|
2012-03-30 12:02:49 +02:00
|
|
|
WebPage::setUserAgent(settings.value("UserAgent", "").toString());
|
|
|
|
settings.endGroup();
|
|
|
|
|
2011-12-11 19:37:16 +01:00
|
|
|
settings.beginGroup("Browser-Fonts");
|
2011-03-17 15:35:51 +01:00
|
|
|
m_websettings->setFontFamily(QWebSettings::StandardFont, settings.value("StandardFont", m_websettings->fontFamily(QWebSettings::StandardFont)).toString());
|
|
|
|
m_websettings->setFontFamily(QWebSettings::CursiveFont, settings.value("CursiveFont", m_websettings->fontFamily(QWebSettings::CursiveFont)).toString());
|
|
|
|
m_websettings->setFontFamily(QWebSettings::FantasyFont, settings.value("FantasyFont", m_websettings->fontFamily(QWebSettings::FantasyFont)).toString());
|
|
|
|
m_websettings->setFontFamily(QWebSettings::FixedFont, settings.value("FixedFont", m_websettings->fontFamily(QWebSettings::FixedFont)).toString());
|
|
|
|
m_websettings->setFontFamily(QWebSettings::SansSerifFont, settings.value("SansSerifFont", m_websettings->fontFamily(QWebSettings::SansSerifFont)).toString());
|
|
|
|
m_websettings->setFontFamily(QWebSettings::SerifFont, settings.value("SerifFont", m_websettings->fontFamily(QWebSettings::SerifFont)).toString());
|
2011-11-06 17:01:23 +01:00
|
|
|
m_websettings->setFontSize(QWebSettings::DefaultFontSize, settings.value("DefaultFontSize", m_websettings->fontSize(QWebSettings::DefaultFontSize)).toInt());
|
|
|
|
m_websettings->setFontSize(QWebSettings::DefaultFixedFontSize, settings.value("FixedFontSize", m_websettings->fontSize(QWebSettings::DefaultFixedFontSize)).toInt());
|
2012-01-23 19:28:47 +01:00
|
|
|
m_websettings->setFontSize(QWebSettings::MinimumFontSize, settings.value("MinimumFontSize", m_websettings->fontSize(QWebSettings::MinimumFontSize)).toInt());
|
|
|
|
m_websettings->setFontSize(QWebSettings::MinimumLogicalFontSize, settings.value("MinimumLogicalFontSize", m_websettings->fontSize(QWebSettings::MinimumLogicalFontSize)).toInt());
|
2011-12-11 19:37:16 +01:00
|
|
|
settings.endGroup();
|
2011-03-17 15:35:51 +01:00
|
|
|
|
2012-04-22 20:51:28 +02:00
|
|
|
m_websettings->setWebGraphic(QWebSettings::DefaultFrameIconGraphic, qIconProvider->emptyWebIcon().pixmap(16, 16));
|
2012-01-22 16:28:11 +01:00
|
|
|
m_websettings->setWebGraphic(QWebSettings::MissingImageGraphic, QPixmap());
|
2011-12-10 13:15:07 +01:00
|
|
|
|
|
|
|
// 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
|
|
|
|
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();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-12 21:32:27 +01:00
|
|
|
void MainApplication::reloadSettings()
|
|
|
|
{
|
|
|
|
loadSettings();
|
2012-01-21 23:19:38 +01:00
|
|
|
emit message(Qz::AM_ReloadSettings, true);
|
2012-01-12 21:32:27 +01:00
|
|
|
}
|
|
|
|
|
2011-10-22 22:29:33 +02:00
|
|
|
void MainApplication::restoreCursor()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
QApplication::restoreOverrideCursor();
|
2011-10-22 22:29:33 +02:00
|
|
|
}
|
|
|
|
|
2011-05-06 20:05:49 +02:00
|
|
|
void MainApplication::setupJumpList()
|
|
|
|
{
|
|
|
|
QtWin::setupJumpList();
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QupZilla* MainApplication::getWindow()
|
|
|
|
{
|
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;
|
2012-01-21 23:19:38 +01:00
|
|
|
sendMessages(Qz::AM_HistoryStateChanged, true);
|
2011-07-28 12:12:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool MainApplication::isStateChanged()
|
|
|
|
{
|
|
|
|
if (m_isStateChanged) {
|
|
|
|
m_isStateChanged = false;
|
2011-03-02 16:57:41 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-01 16:36:38 +02:00
|
|
|
QList<QupZilla*> MainApplication::mainWindows()
|
|
|
|
{
|
|
|
|
QList<QupZilla*> list;
|
|
|
|
|
|
|
|
for (int i = 0; i < m_mainWindows.count(); i++) {
|
|
|
|
if (!m_mainWindows.at(i)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
list.append(m_mainWindows.at(i).data());
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2012-01-21 23:19:38 +01:00
|
|
|
void MainApplication::sendMessages(Qz::AppMessageType mes, bool state)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
emit message(mes, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainApplication::receiveAppMessage(QString message)
|
|
|
|
{
|
2011-12-27 12:27:39 +01:00
|
|
|
QWidget* actWin = getWindow();
|
2012-04-03 20:41:07 +02:00
|
|
|
QUrl actUrl;
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
if (message.startsWith("URL:")) {
|
2012-03-24 22:08:17 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
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-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else if (text == "NewWindow") {
|
2012-01-21 23:19:38 +01:00
|
|
|
actWin = makeNewWindow(Qz::BW_NewWindow);
|
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
|
|
|
}
|
2012-04-03 20:41:07 +02:00
|
|
|
else if (text.startsWith("OpenUrlInCurrentTab")) {
|
2012-07-10 00:36:05 +02:00
|
|
|
actUrl = QUrl::fromUserInput(text.mid(19));
|
|
|
|
}
|
|
|
|
else if (text.startsWith("OpenUrlInNewWindow")) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-03-31 16:01:59 +02:00
|
|
|
if (!actWin && !isClosing()) { // It can only occur if download manager window was still open
|
2012-04-03 20:41:07 +02:00
|
|
|
makeNewWindow(Qz::BW_NewWindow, actUrl);
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
|
|
|
}
|
2011-12-27 12:27:39 +01:00
|
|
|
|
2012-04-03 20:41:07 +02:00
|
|
|
QupZilla* qz = qobject_cast<QupZilla*>(actWin);
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized);
|
|
|
|
actWin->raise();
|
|
|
|
actWin->activateWindow();
|
|
|
|
actWin->setFocus();
|
2012-04-03 20:41:07 +02:00
|
|
|
|
|
|
|
if (qz && !actUrl.isEmpty()) {
|
|
|
|
qz->loadAddress(actUrl);
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-05-18 22:58:49 +02:00
|
|
|
void MainApplication::addNewTab(const QUrl &url)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!getWindow()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-01-26 20:19:56 +01:00
|
|
|
getWindow()->tabWidget()->addView(url, Qz::NT_SelectedTabAtTheEnd);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 23:19:38 +01:00
|
|
|
QupZilla* MainApplication::makeNewWindow(Qz::BrowserWindow type, const QUrl &startUrl)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-18 18:36:10 +01:00
|
|
|
if (m_mainWindows.count() == 0) {
|
2012-01-21 23:19:38 +01:00
|
|
|
type = Qz::BW_FirstAppWindow;
|
2012-01-18 18:36:10 +01:00
|
|
|
}
|
|
|
|
|
2012-01-21 23:19:38 +01:00
|
|
|
QupZilla* newWindow = new QupZilla(type, startUrl);
|
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
|
|
|
}
|
|
|
|
|
2012-01-12 20:10:51 +01:00
|
|
|
#ifdef Q_WS_MAC
|
|
|
|
bool MainApplication::event(QEvent* e)
|
|
|
|
{
|
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::FileOpen: {
|
2012-01-25 10:52:00 +01:00
|
|
|
QString fileName = static_cast<QFileOpenEvent*>(e)->file();
|
2012-01-12 20:10:51 +01:00
|
|
|
addNewTab(QUrl::fromLocalFile(fileName));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QtSingleApplication::event(e);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void MainApplication::connectDatabase()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_databaseConnected) {
|
2011-10-24 17:46:45 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-24 17:46:45 +02:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
|
2011-10-24 17:46:45 +02:00
|
|
|
db.setDatabaseName(m_activeProfil + "browsedata.db");
|
|
|
|
if (!QFile::exists(m_activeProfil + "browsedata.db")) {
|
2011-12-27 15:26:32 +01:00
|
|
|
QFile(":data/browsedata.db").copy(m_activeProfil + "browsedata.db");
|
|
|
|
QFile(m_activeProfil + "browsedata.db").setPermissions(QFile::ReadUser | QFile::WriteUser);
|
|
|
|
|
2011-10-24 17:46:45 +02:00
|
|
|
db.setDatabaseName(m_activeProfil + "browsedata.db");
|
2011-03-02 16:57:41 +01:00
|
|
|
qWarning("Cannot find SQLite database file! Copying and using the defaults!");
|
|
|
|
}
|
2012-06-26 11:49:39 +02:00
|
|
|
|
|
|
|
if (m_isPrivateSession) {
|
|
|
|
db.setConnectOptions("QSQLITE_OPEN_READONLY");
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!db.open()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
qWarning("Cannot open SQLite database! Continuing without database....");
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-10-24 17:46:45 +02:00
|
|
|
m_databaseConnected = true;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainApplication::translateApp()
|
|
|
|
{
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings settings;
|
2012-04-04 18:48:54 +02:00
|
|
|
const QString &file = settings.value("Language/language", QLocale::system().name()).toString();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-04-01 16:36:38 +02:00
|
|
|
QTranslator* app = new QTranslator(this);
|
2012-04-04 18:48:54 +02:00
|
|
|
app->load(file, TRANSLATIONSDIR);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-04-04 18:48:54 +02:00
|
|
|
QTranslator* sys = new QTranslator(this);
|
|
|
|
sys->load("qt_" + file, TRANSLATIONSDIR);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
m_activeLanguage = file;
|
|
|
|
|
|
|
|
installTranslator(app);
|
|
|
|
installTranslator(sys);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainApplication::quitApplication()
|
|
|
|
{
|
|
|
|
if (m_downloadManager && !m_downloadManager->canClose()) {
|
|
|
|
m_downloadManager->show();
|
|
|
|
return;
|
|
|
|
}
|
2012-01-04 14:09:27 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
m_isClosing = true;
|
2012-01-15 17:50:09 +01:00
|
|
|
m_networkmanager->disconnectObjects();
|
2012-01-12 20:10:51 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_mainWindows.count() > 0) {
|
2011-03-02 16:57:41 +01:00
|
|
|
saveStateSlot();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-12 20:10:51 +01:00
|
|
|
// Saving settings in saveSettings() slot called from quit() so
|
|
|
|
// everything gets saved also when quitting application in other
|
|
|
|
// way than clicking Quit action in File menu or closing last window
|
|
|
|
//
|
2012-01-12 20:32:09 +01:00
|
|
|
// * this can occur on Mac OS (see #157)
|
2012-01-12 20:10:51 +01:00
|
|
|
|
|
|
|
quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainApplication::saveSettings()
|
|
|
|
{
|
2012-06-26 11:49:39 +02:00
|
|
|
if (m_isPrivateSession) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-12 20:10:51 +01:00
|
|
|
m_isClosing = true;
|
2012-01-15 17:50:09 +01:00
|
|
|
m_networkmanager->disconnectObjects();
|
2012-01-12 20:10:51 +01:00
|
|
|
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings settings;
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.beginGroup("SessionRestore");
|
2011-11-06 17:01:23 +01:00
|
|
|
settings.setValue("isRunning", false);
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.endGroup();
|
|
|
|
|
2012-01-26 18:23:35 +01:00
|
|
|
settings.beginGroup("Web-Browser-Settings");
|
|
|
|
bool deleteCookies = settings.value("deleteCookiesOnClose", false).toBool();
|
|
|
|
bool deleteHistory = settings.value("deleteHistoryOnClose", false).toBool();
|
|
|
|
bool deleteHtml5Storage = settings.value("deleteHTML5StorageOnClose", false).toBool();
|
|
|
|
settings.endGroup();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-12 20:10:51 +01:00
|
|
|
if (deleteCookies) {
|
|
|
|
m_cookiejar->clearCookies();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
if (deleteHistory) {
|
2011-04-26 10:03:17 +02:00
|
|
|
m_historymodel->clearHistory();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-01-26 18:23:35 +01:00
|
|
|
if (deleteHtml5Storage) {
|
2012-03-23 17:29:12 +01:00
|
|
|
ClearPrivateData::clearLocalStorage();
|
2012-01-26 18:23:35 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-10-21 23:26:34 +02:00
|
|
|
m_searchEnginesManager->saveSettings();
|
2011-10-12 22:28:41 +02:00
|
|
|
m_networkmanager->saveCertificates();
|
2012-07-08 14:03:50 +02:00
|
|
|
m_plugins->shutdown();
|
2012-04-22 20:51:28 +02:00
|
|
|
qIconProvider->saveIconsToDatabase();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-12 20:10:51 +01:00
|
|
|
AdBlockManager::instance()->save();
|
2012-04-04 18:48:54 +02:00
|
|
|
QFile::remove(currentProfilePath() + "WebpageIcons.db");
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings::syncSettings();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-07-29 15:39:43 +02:00
|
|
|
BrowsingLibrary* MainApplication::browsingLibrary()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!m_browsingLibrary) {
|
2011-07-29 15:39:43 +02:00
|
|
|
m_browsingLibrary = new BrowsingLibrary(getWindow());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-07-29 15:39:43 +02:00
|
|
|
return m_browsingLibrary;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CookieManager* MainApplication::cookieManager()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!m_cookiemanager) {
|
2011-03-02 16:57:41 +01:00
|
|
|
m_cookiemanager = new CookieManager();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
return m_cookiemanager;
|
|
|
|
}
|
|
|
|
|
2012-04-30 16:33:14 +02:00
|
|
|
History* MainApplication::history()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!m_historymodel) {
|
2012-04-30 16:33:14 +02:00
|
|
|
m_historymodel = new History(this);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
return m_historymodel;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWebSettings* MainApplication::webSettings()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!m_websettings) {
|
2011-03-02 16:57:41 +01:00
|
|
|
m_websettings = QWebSettings::globalSettings();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
return m_websettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
NetworkManager* MainApplication::networkManager()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!m_networkmanager) {
|
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;
|
|
|
|
}
|
|
|
|
|
2012-04-04 21:12:52 +02:00
|
|
|
PluginProxy* MainApplication::plugins()
|
|
|
|
{
|
|
|
|
return m_plugins;
|
|
|
|
}
|
|
|
|
|
2011-04-15 20:45:22 +02:00
|
|
|
BookmarksModel* MainApplication::bookmarksModel()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!m_bookmarksModel) {
|
2011-04-15 20:45:22 +02:00
|
|
|
m_bookmarksModel = new BookmarksModel(this);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
return m_bookmarksModel;
|
|
|
|
}
|
|
|
|
|
|
|
|
DownloadManager* MainApplication::downManager()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!m_downloadManager) {
|
2011-03-02 16:57:41 +01:00
|
|
|
m_downloadManager = new DownloadManager();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
return m_downloadManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-06-15 17:43:19 +02:00
|
|
|
QNetworkDiskCache* MainApplication::networkCache()
|
|
|
|
{
|
|
|
|
if (!m_networkCache) {
|
|
|
|
m_networkCache = new QNetworkDiskCache(this);
|
|
|
|
m_networkCache->setCacheDirectory(m_activeProfil + "/networkcache");
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-06-26 11:49:39 +02:00
|
|
|
void MainApplication::startPrivateBrowsing()
|
|
|
|
{
|
|
|
|
QStringList args;
|
|
|
|
foreach(const QString & arg, arguments()) {
|
2012-07-01 18:50:18 +02:00
|
|
|
if (arg.startsWith('-')) {
|
2012-06-26 11:49:39 +02:00
|
|
|
args.append(arg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
args.append("--private-browsing");
|
|
|
|
|
|
|
|
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");
|
|
|
|
m_websettings->setUserStyleSheetUrl(userStyleSheet(settings.value("userStyleSheet", "").toString()));
|
|
|
|
settings.endGroup();
|
|
|
|
}
|
|
|
|
|
2012-06-26 11:49:39 +02:00
|
|
|
QUrl MainApplication::userStyleSheet(const QString &filePath) const
|
|
|
|
{
|
2012-07-04 17:53:49 +02:00
|
|
|
QString userStyle = AdBlockManager::instance()->elementHidingRules() + "{ display:none !important;}";
|
2012-06-26 11:49:39 +02:00
|
|
|
|
|
|
|
QFile file(filePath);
|
|
|
|
if (!filePath.isEmpty() && file.open(QFile::ReadOnly)) {
|
2012-07-08 21:17:10 +02:00
|
|
|
QString fileData = QString::fromUtf8(file.readAll());
|
2012-07-04 17:53:49 +02:00
|
|
|
fileData.remove('\n');
|
|
|
|
userStyle.append(fileData);
|
2012-06-26 11:49:39 +02:00
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
2012-07-04 17:53:49 +02:00
|
|
|
const QString &encodedStyle = userStyle.toAscii().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);
|
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void MainApplication::aboutToCloseWindow(QupZilla* window)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!window) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-18 18:36:10 +01:00
|
|
|
if (m_mainWindows.count() == 1) {
|
|
|
|
if (m_browsingLibrary) {
|
|
|
|
m_browsingLibrary->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_cookiemanager) {
|
|
|
|
m_cookiemanager->close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
m_mainWindows.removeOne(window);
|
|
|
|
}
|
|
|
|
|
2011-03-05 13:43:37 +01:00
|
|
|
//Version of session.dat file
|
2012-03-11 18:24:19 +01:00
|
|
|
static const int sessionVersion = 0x0003;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
bool MainApplication::saveStateSlot()
|
|
|
|
{
|
2012-06-26 11:49:39 +02:00
|
|
|
if (m_isPrivateSession || m_isRestoring || m_mainWindows.count() == 0) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return false;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
QFile file(m_activeProfil + "session.dat");
|
2011-03-02 16:57:41 +01:00
|
|
|
file.open(QIODevice::WriteOnly);
|
|
|
|
QDataStream stream(&file);
|
|
|
|
|
|
|
|
stream << sessionVersion;
|
|
|
|
stream << m_mainWindows.count();
|
2012-01-10 19:10:16 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
for (int i = 0; i < m_mainWindows.count(); i++) {
|
2011-12-09 21:56:01 +01:00
|
|
|
QupZilla* qz = m_mainWindows.at(i).data();
|
|
|
|
if (!qz) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
stream << qz->tabWidget()->saveState();
|
|
|
|
if (qz->isFullScreen()) {
|
2011-04-22 07:45:15 +02:00
|
|
|
stream << QByteArray();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-12-09 21:56:01 +01:00
|
|
|
stream << qz->saveState();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
QupZilla* qupzilla_ = getWindow();
|
2012-01-18 18:36:10 +01:00
|
|
|
if (qupzilla_ && m_mainWindows.count() == 1) {
|
2011-03-29 19:55:21 +02:00
|
|
|
qupzilla_->tabWidget()->savePinnedTabs();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-04 20:04:29 +02:00
|
|
|
|
2012-03-05 14:32:24 +01:00
|
|
|
// Saving cookies
|
|
|
|
m_cookiejar->saveCookies();
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
bool MainApplication::restoreStateSlot(QupZilla* window)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-06-26 11:49:39 +02:00
|
|
|
if (m_isPrivateSession) {
|
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
|
|
|
|
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
|
|
|
QFile file(m_activeProfil + "session.dat");
|
2011-03-02 16:57:41 +01:00
|
|
|
file.open(QIODevice::ReadOnly);
|
|
|
|
QDataStream stream(&file);
|
|
|
|
|
|
|
|
QByteArray tabState;
|
2012-03-13 17:51:37 +01:00
|
|
|
QByteArray windowState;
|
2011-03-02 16:57:41 +01:00
|
|
|
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;
|
2012-03-13 17:51:37 +01:00
|
|
|
stream >> windowState;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-03-13 17:51:37 +01:00
|
|
|
window->restoreWindowState(windowState, tabState);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
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;
|
2012-03-13 17:51:37 +01:00
|
|
|
stream >> windowState;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-01-21 23:19:38 +01:00
|
|
|
QupZilla* window = new QupZilla(Qz::BW_OtherRestoredWindow);
|
2011-03-02 16:57:41 +01:00
|
|
|
m_mainWindows.append(window);
|
|
|
|
|
2012-03-13 17:51:37 +01:00
|
|
|
window->restoreWindowState(windowState, tabState);
|
|
|
|
|
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
|
|
|
|
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");
|
|
|
|
|
|
|
|
//.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);
|
2012-04-05 14:26:44 +02:00
|
|
|
QFile versionFile(PROFILEDIR + "profiles/default/version");
|
|
|
|
versionFile.open(QFile::WriteOnly);
|
|
|
|
versionFile.write(QupZilla::VERSION.toUtf8());
|
|
|
|
versionFile.close();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
return dir.isReadable();
|
|
|
|
}
|