1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 17:52:10 +02:00

MainApplication: Add support for starting in test mode

This commit is contained in:
David Rosca 2018-01-27 09:02:45 +01:00
parent c2a730e9f4
commit 0af95e3b1f
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
3 changed files with 31 additions and 4 deletions

View File

@ -1,6 +1,6 @@
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2014-2017 David Rosca <nowrep@gmail.com>
* Copyright (C) 2014-2018 David Rosca <nowrep@gmail.com>
*
* 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
@ -18,6 +18,7 @@
#include "datapaths.h"
#include "qztools.h"
#include "../config.h"
#include "mainapplication.h"
#include <QApplication>
#include <QDir>
@ -92,7 +93,12 @@ void DataPaths::init()
initAssetsIn(location);
}
m_paths[Config].append(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
if (MainApplication::isTestModeEnabled()) {
m_paths[Config].append(QDir::tempPath() + QL1S("/QupZilla-test"));
} else {
m_paths[Config].append(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
}
m_paths[Profiles].append(m_paths[Config].at(0) + QLatin1String("/profiles"));
// We also allow to load data from Config path
initAssetsIn(m_paths[Config].at(0));

View File

@ -78,6 +78,8 @@
#include "registerqappassociation.h"
#endif
static bool s_testMode = false;
MainApplication::MainApplication(int &argc, char** argv)
: QtSingleApplication(argc, argv)
, m_isPrivate(false)
@ -217,6 +219,10 @@ MainApplication::MainApplication(int &argc, char** argv)
appId.append(QLatin1String("Portable"));
}
if (isTestModeEnabled()) {
appId.append(QSL("TestMode"));
}
if (newInstance) {
if (startProfile.isEmpty() || startProfile == QLatin1String("default")) {
std::cout << "New instance cannot be started with default profile!" << std::endl;
@ -272,7 +278,7 @@ MainApplication::MainApplication(int &argc, char** argv)
setupUserScripts();
if (!isPrivate()) {
if (!isPrivate() && !isTestModeEnabled()) {
m_sessionManager = new SessionManager(this);
m_autoSaver = new AutoSaver(this);
connect(m_autoSaver, SIGNAL(save()), m_sessionManager, SLOT(autoSaveLastSession()));
@ -313,7 +319,7 @@ MainApplication::MainApplication(int &argc, char** argv)
connect(this, SIGNAL(focusChanged(QWidget*,QWidget*)), this, SLOT(onFocusChanged()));
if (!isPrivate()) {
if (!isPrivate() && !isTestModeEnabled()) {
#ifndef DISABLE_CHECK_UPDATES
Settings settings;
bool checkUpdates = settings.value("Web-Browser-Settings/CheckUpdates", true).toBool();
@ -619,6 +625,18 @@ MainApplication* MainApplication::instance()
return static_cast<MainApplication*>(QCoreApplication::instance());
}
// static
bool MainApplication::isTestModeEnabled()
{
return s_testMode;
}
// static
void MainApplication::setTestModeEnabled(bool enabled)
{
s_testMode = enabled;
}
void MainApplication::addNewTab(const QUrl &url)
{
BrowserWindow* window = getWindow();

View File

@ -118,6 +118,9 @@ public:
static MainApplication* instance();
static bool isTestModeEnabled();
static void setTestModeEnabled(bool enabled);
public slots:
void addNewTab(const QUrl &url = QUrl());
void startPrivateBrowsing(const QUrl &startUrl = QUrl());