1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

Make afterLaunch settings enum

This commit is contained in:
David Rosca 2015-09-28 14:51:38 +02:00
parent f28da4407f
commit 7adc31337b
4 changed files with 24 additions and 17 deletions

View File

@ -162,22 +162,20 @@ void BrowserWindow::postLaunch()
{ {
loadSettings(); loadSettings();
Settings settings;
int afterLaunch = settings.value("Web-URL-Settings/afterLaunch", 3).toInt();
bool addTab = true; bool addTab = true;
QUrl startUrl; QUrl startUrl;
switch (afterLaunch) { switch (mApp->afterLaunch()) {
case 0: case MainApplication::OpenBlankPage:
startUrl = QUrl(); startUrl = QUrl();
break; break;
case 2: case MainApplication::OpenSpeedDial:
startUrl = QUrl("qupzilla:speeddial"); startUrl = QUrl("qupzilla:speeddial");
break; break;
case 1: case MainApplication::OpenHomePage:
case 3: case MainApplication::RestoreSession:
startUrl = m_homepage; startUrl = m_homepage;
break; break;
@ -192,7 +190,7 @@ void BrowserWindow::postLaunch()
startUrl.clear(); startUrl.clear();
m_tabWidget->addView(QUrl("qupzilla:restore"), Qz::NT_CleanSelectedTabAtTheEnd); m_tabWidget->addView(QUrl("qupzilla:restore"), Qz::NT_CleanSelectedTabAtTheEnd);
} }
else if (afterLaunch == 3 && mApp->restoreManager()) { else if (mApp->afterLaunch() == MainApplication::RestoreSession && mApp->restoreManager()) {
addTab = !mApp->restoreSession(this, mApp->restoreManager()->restoreData()); addTab = !mApp->restoreSession(this, mApp->restoreManager()->restoreData());
} }
else { else {
@ -1336,10 +1334,9 @@ void BrowserWindow::closeEvent(QCloseEvent* event)
} }
Settings settings; Settings settings;
int afterLaunch = settings.value("Web-URL-Settings/afterLaunch", 3).toInt();
bool askOnClose = settings.value("Browser-Tabs-Settings/AskOnClosing", true).toBool(); bool askOnClose = settings.value("Browser-Tabs-Settings/AskOnClosing", true).toBool();
if (afterLaunch == 3 && mApp->windowCount() == 1) { if (mApp->afterLaunch() == MainApplication::RestoreSession && mApp->windowCount() == 1) {
askOnClose = false; askOnClose = false;
} }

View File

@ -287,7 +287,6 @@ MainApplication::MainApplication(int &argc, char** argv)
if (!isPrivate()) { if (!isPrivate()) {
Settings settings; Settings settings;
m_isStartingAfterCrash = settings.value("SessionRestore/isRunning", false).toBool(); m_isStartingAfterCrash = settings.value("SessionRestore/isRunning", false).toBool();
int afterLaunch = settings.value("Web-URL-Settings/afterLaunch", 3).toInt();
settings.setValue("SessionRestore/isRunning", true); settings.setValue("SessionRestore/isRunning", true);
#ifndef DISABLE_UPDATES_CHECK #ifndef DISABLE_UPDATES_CHECK
@ -300,7 +299,7 @@ MainApplication::MainApplication(int &argc, char** argv)
backupSavedSessions(); backupSavedSessions();
if (m_isStartingAfterCrash || afterLaunch == 3) { if (m_isStartingAfterCrash || afterLaunch() == RestoreSession) {
m_restoreManager = new RestoreManager(); m_restoreManager = new RestoreManager();
if (!m_restoreManager->isValid()) { if (!m_restoreManager->isValid()) {
destroyRestoreManager(); destroyRestoreManager();
@ -390,6 +389,11 @@ BrowserWindow* MainApplication::createWindow(Qz::BrowserWindowType type, const Q
return window; return window;
} }
MainApplication::AfterLaunch MainApplication::afterLaunch() const
{
return static_cast<AfterLaunch>(Settings().value(QSL("Web-URL-Settings/afterLaunch"), RestoreSession).toInt());
}
bool MainApplication::restoreSession(BrowserWindow* window, RestoreData restoreData) bool MainApplication::restoreSession(BrowserWindow* window, RestoreData restoreData)
{ {
if (m_isPrivate || restoreData.isEmpty()) { if (m_isPrivate || restoreData.isEmpty()) {
@ -717,9 +721,7 @@ void MainApplication::saveSession()
} }
} }
int afterLaunch = Settings().value("Web-URL-Settings/afterLaunch", 3).toInt(); if (afterLaunch() != RestoreSession) {
if (afterLaunch != 3) {
// Pinned tabs are saved only for last window into pinnedtabs.dat // Pinned tabs are saved only for last window into pinnedtabs.dat
BrowserWindow* qupzilla_ = getWindow(); BrowserWindow* qupzilla_ = getWindow();
if (qupzilla_ && m_windows.count() == 1) { if (qupzilla_ && m_windows.count() == 1) {

View File

@ -53,6 +53,13 @@ class QUPZILLA_EXPORT MainApplication : public QtSingleApplication
Q_OBJECT Q_OBJECT
public: public:
enum AfterLaunch {
OpenBlankPage = 0,
OpenHomePage = 1,
OpenSpeedDial = 2,
RestoreSession = 3
};
explicit MainApplication(int &argc, char** argv); explicit MainApplication(int &argc, char** argv);
~MainApplication(); ~MainApplication();
@ -68,6 +75,8 @@ public:
BrowserWindow* getWindow() const; BrowserWindow* getWindow() const;
BrowserWindow* createWindow(Qz::BrowserWindowType type, const QUrl &startUrl = QUrl()); BrowserWindow* createWindow(Qz::BrowserWindowType type, const QUrl &startUrl = QUrl());
AfterLaunch afterLaunch() const;
bool restoreSession(BrowserWindow* window, RestoreData restoreData); bool restoreSession(BrowserWindow* window, RestoreData restoreData);
void destroyRestoreManager(); void destroyRestoreManager();
void reloadSettings(); void reloadSettings();

View File

@ -146,9 +146,8 @@ Preferences::Preferences(BrowserWindow* window)
m_newTabUrl = settings.value("newTabUrl", QUrl(QSL("qupzilla:speeddial"))).toUrl(); m_newTabUrl = settings.value("newTabUrl", QUrl(QSL("qupzilla:speeddial"))).toUrl();
ui->homepage->setText(m_homepage.toEncoded()); ui->homepage->setText(m_homepage.toEncoded());
ui->newTabUrl->setText(m_newTabUrl.toEncoded()); ui->newTabUrl->setText(m_newTabUrl.toEncoded());
int afterLaunch = settings.value("afterLaunch", 3).toInt();
settings.endGroup(); settings.endGroup();
ui->afterLaunch->setCurrentIndex(afterLaunch); ui->afterLaunch->setCurrentIndex(mApp->afterLaunch());
ui->checkUpdates->setChecked(settings.value("Web-Browser-Settings/CheckUpdates", DEFAULT_CHECK_UPDATES).toBool()); ui->checkUpdates->setChecked(settings.value("Web-Browser-Settings/CheckUpdates", DEFAULT_CHECK_UPDATES).toBool());
ui->dontLoadTabsUntilSelected->setChecked(settings.value("Web-Browser-Settings/LoadTabsOnActivation", true).toBool()); ui->dontLoadTabsUntilSelected->setChecked(settings.value("Web-Browser-Settings/LoadTabsOnActivation", true).toBool());