2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2011-10-17 09:57:07 +02:00
|
|
|
* Copyright (C) 2010-2011 David Rosca
|
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-02 23:25:27 +01:00
|
|
|
#include "speeddial.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
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-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-03-27 21:59:40 +02:00
|
|
|
setOverrideCursor(Qt::WaitCursor);
|
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-09-11 19:15:06 +02:00
|
|
|
PLUGINSDIR = DATADIR + "plugins/";
|
|
|
|
TRANSLATIONSDIR = DATADIR + "locale/";
|
|
|
|
THEMESDIR = DATADIR + "themes/";
|
|
|
|
|
2011-09-17 11:39:25 +02:00
|
|
|
setWindowIcon(QupZilla::qupzillaIcon());
|
2011-03-02 16:57:41 +01:00
|
|
|
bool noAddons = false;
|
|
|
|
QUrl startUrl("");
|
|
|
|
QString message;
|
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:
|
|
|
|
message = "ACTION:NewTab";
|
|
|
|
break;
|
|
|
|
case CommandLineOptions::NewWindow:
|
|
|
|
message = "ACTION:NewWindow";
|
|
|
|
break;
|
|
|
|
case CommandLineOptions::ShowDownloadManager:
|
|
|
|
message = "ACTION:ShowDownloadManager";
|
|
|
|
break;
|
|
|
|
case CommandLineOptions::OpenUrl:
|
|
|
|
startUrl = pair.text;
|
|
|
|
message = "URL:" + startUrl.toString();
|
2011-04-03 21:50:44 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isRunning()) {
|
|
|
|
sendMessage(message);
|
|
|
|
m_isExited = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(this, SIGNAL(messageReceived(QString)), this, SLOT(receiveAppMessage(QString)));
|
|
|
|
|
|
|
|
setQuitOnLastWindowClosed(true);
|
|
|
|
setApplicationName("QupZilla");
|
|
|
|
setApplicationVersion(QupZilla::VERSION);
|
|
|
|
setOrganizationDomain("qupzilla");
|
|
|
|
|
|
|
|
QString homePath = QDir::homePath();
|
2011-11-06 17:01:23 +01:00
|
|
|
homePath += "/.qupzilla/";
|
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-11-06 17:01:23 +01:00
|
|
|
QSettings settings(homePath + "profiles/profiles.ini", QSettings::IniFormat);
|
|
|
|
if (settings.value("Profiles/startProfile", "default").toString().contains("/")) {
|
|
|
|
m_activeProfil = homePath + "profiles/default/";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_activeProfil = homePath + "profiles/" + settings.value("Profiles/startProfile", "default").toString() + "/";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_activeProfil = homePath + "profiles/" + startProfile + "/";
|
|
|
|
}
|
2011-04-03 21:50:44 +02:00
|
|
|
|
2011-10-18 14:30:17 +02:00
|
|
|
ProfileUpdater u(m_activeProfil, DATADIR);
|
|
|
|
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-11-06 17:01:23 +01:00
|
|
|
if (settings2.value("Web-Browser-Settings/CheckUpdates", true).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
|
|
|
|
|
|
|
QTimer::singleShot(2000, this, SLOT(restoreCursor()));
|
2011-11-06 17:01:23 +01:00
|
|
|
QTimer::singleShot(10 * 1000, this, SLOT(setupJumpList()));
|
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-09-13 18:21:34 +02:00
|
|
|
QString activeTheme = settings.value("activeTheme",
|
|
|
|
#ifdef Q_WS_X11
|
|
|
|
"linux"
|
|
|
|
#else
|
|
|
|
"windows"
|
|
|
|
#endif
|
2011-11-06 17:01:23 +01:00
|
|
|
).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
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
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-05-10 21:25:31 +02:00
|
|
|
QUrl userStyleSheet = settings.value("userStyleSheet", QUrl()).toUrl();
|
2011-10-29 18:37:28 +02:00
|
|
|
m_defaultZoom = settings.value("DefaultZoom", 100).toInt();
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.endGroup();
|
|
|
|
|
|
|
|
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-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-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-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-03-02 16:57:41 +01:00
|
|
|
return m_mainWindows.at(i);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainApplication::sendMessages(MainApplication::MessageType mes, bool state)
|
|
|
|
{
|
|
|
|
emit message(mes, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainApplication::receiveAppMessage(QString message)
|
|
|
|
{
|
|
|
|
if (message.startsWith("URL:")) {
|
|
|
|
QString url(message.remove("URL:"));
|
|
|
|
addNewTab(WebView::guessUrlFromString(url));
|
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") {
|
2011-05-18 22:58:49 +02:00
|
|
|
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-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QupZilla* actWin = getWindow();
|
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;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainApplication::makeNewWindow(bool tryRestore, const QUrl &startUrl)
|
|
|
|
{
|
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-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")) {
|
|
|
|
QFile(DATADIR + "data/default/profiles/default/browsedata.db").copy(m_activeProfil + "browsedata.db");
|
|
|
|
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-11-06 17:01:23 +01:00
|
|
|
app->load(DATADIR + "locale/" + 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++) {
|
|
|
|
stream << m_mainWindows.at(i)->tabWidget()->saveState();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_mainWindows.at(i)->isFullScreen()) {
|
2011-04-22 07:45:15 +02:00
|
|
|
stream << QByteArray();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-04-22 07:45:15 +02:00
|
|
|
stream << m_mainWindows.at(i)->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-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-11-06 17:01:23 +01:00
|
|
|
if (settings.value("isCrashed", false).toBool() && afterStart != 2) {
|
2011-03-02 16:57:41 +01:00
|
|
|
QMessageBox::StandardButton button = QMessageBox::warning(window, tr("Last session crashed"),
|
2011-11-06 17:01:23 +01:00
|
|
|
tr("<b>QupZilla crashed :-(</b><br/>Oops, last session of QupZilla ends with its crash. We are very sorry. Would you try to restore saved state?"),
|
|
|
|
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-18 14:30:17 +02:00
|
|
|
QString homePath = QDir::homePath() + "/.qupzilla/";
|
2011-10-07 17:33:51 +02:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (QDir(homePath).exists() && QFile(homePath + "profiles/profiles.ini").exists()) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
std::cout << "Creating new profile directory" << std::endl;
|
|
|
|
|
|
|
|
QDir dir = QDir::home();
|
|
|
|
dir.mkdir(".qupzilla");
|
|
|
|
dir.cd(".qupzilla");
|
|
|
|
|
|
|
|
dir.mkdir("profiles");
|
|
|
|
dir.cd("profiles");
|
|
|
|
|
|
|
|
//.qupzilla/profiles
|
2011-10-07 17:33:51 +02:00
|
|
|
QFile(homePath + "profiles/profiles.ini").remove();
|
|
|
|
QFile(DATADIR + "data/default/profiles/profiles.ini").copy(homePath + "profiles/profiles.ini");
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
dir.mkdir("default");
|
|
|
|
dir.cd("default");
|
|
|
|
|
|
|
|
//.qupzilla/profiles/default
|
2011-10-07 17:33:51 +02:00
|
|
|
QFile(homePath + "profiles/default/browsedata.db").remove();
|
|
|
|
QFile(DATADIR + "data/default/profiles/default/browsedata.db").copy(homePath + "profiles/default/browsedata.db");
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
return dir.isReadable();
|
|
|
|
}
|