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

[Portable] Portable mode can now be enabled with commandline option

It is not needed to rebuild for Portable mode.
However, it is still possible to enforce portable mode with
PORTABLE_BUILD build option.
This commit is contained in:
nowrep 2014-01-23 13:02:07 +01:00
parent a1f9b784d7
commit 29b6b93dd4
7 changed files with 69 additions and 59 deletions

View File

@ -45,6 +45,7 @@ void CommandLineOptions::showHelp()
"\n" "\n"
" -p=PROFILE or --profile=PROFILE start with specified profile \n" " -p=PROFILE or --profile=PROFILE start with specified profile \n"
" -ne or --no-extensions start without extensions\n" " -ne or --no-extensions start without extensions\n"
" -po or --portable start in portable mode\n"
"\n" "\n"
" Options to control running QupZilla:\n" " Options to control running QupZilla:\n"
" -nt or --new-tab open new tab\n" " -nt or --new-tab open new tab\n"
@ -157,6 +158,12 @@ void CommandLineOptions::parseActions()
m_actions.append(pair); m_actions.append(pair);
} }
if (arg.startsWith(QLatin1String("-po")) || arg.startsWith(QLatin1String("--portable"))) {
ActionPair pair;
pair.action = Qz::CL_StartPortable;
m_actions.append(pair);
}
if (arg.startsWith(QLatin1String("-fs")) || arg.startsWith(QLatin1String("--fullscreen"))) { if (arg.startsWith(QLatin1String("-fs")) || arg.startsWith(QLatin1String("--fullscreen"))) {
ActionPair pair; ActionPair pair;
pair.action = Qz::CL_ToggleFullScreen; pair.action = Qz::CL_ToggleFullScreen;

View File

@ -73,10 +73,6 @@
#include <QTimer> #include <QTimer>
#include <QDir> #include <QDir>
#if defined(PORTABLE_BUILD) && !defined(NO_SYSTEM_DATAPATH)
#define NO_SYSTEM_DATAPATH
#endif
#if QT_VERSION < 0x050000 #if QT_VERSION < 0x050000
#include "qwebkitversion.h" #include "qwebkitversion.h"
#endif #endif
@ -105,6 +101,7 @@ MainApplication::MainApplication(int &argc, char** argv)
, m_dbWriter(new DatabaseWriter(this)) , m_dbWriter(new DatabaseWriter(this))
, m_uaManager(new UserAgentManager) , m_uaManager(new UserAgentManager)
, m_isPrivateSession(false) , m_isPrivateSession(false)
, m_isPortable(false)
, m_isClosing(false) , m_isClosing(false)
, m_isStateChanged(false) , m_isStateChanged(false)
, m_isRestoring(false) , m_isRestoring(false)
@ -128,23 +125,6 @@ MainApplication::MainApplication(int &argc, char** argv)
DATADIR.append(QLatin1String("../Resources/")); DATADIR.append(QLatin1String("../Resources/"));
#endif #endif
#ifdef PORTABLE_BUILD
PROFILEDIR = DATADIR + "profiles/";
#else
bool confPathExists = QDir(QDir::homePath() + "/.config/qupzilla").exists();
bool homePathExists = QDir(QDir::homePath() + "/.qupzilla").exists();
if (homePathExists && !confPathExists) {
PROFILEDIR = QDir::homePath() + "/.qupzilla/";
}
else {
PROFILEDIR = QDir::homePath() + "/.config/qupzilla/";
}
#endif
TRANSLATIONSDIR = DATADIR + "locale/";
THEMESDIR = DATADIR + "themes/";
setWindowIcon(QIcon(":icons/exeicons/qupzilla-window.png")); setWindowIcon(QIcon(":icons/exeicons/qupzilla-window.png"));
bool noAddons = false; bool noAddons = false;
bool newInstance = false; bool newInstance = false;
@ -163,6 +143,9 @@ MainApplication::MainApplication(int &argc, char** argv)
case Qz::CL_StartWithProfile: case Qz::CL_StartWithProfile:
startProfile = pair.text; startProfile = pair.text;
break; break;
case Qz::CL_StartPortable:
m_isPortable = true;
break;
case Qz::CL_NewTab: case Qz::CL_NewTab:
messages.append(QLatin1String("ACTION:NewTab")); messages.append(QLatin1String("ACTION:NewTab"));
m_postLaunchActions.append(OpenNewTab); m_postLaunchActions.append(OpenNewTab);
@ -205,13 +188,28 @@ MainApplication::MainApplication(int &argc, char** argv)
} }
} }
if (isPortable()) {
std::cout << "QupZilla: Running in Portable Mode." << std::endl;
PROFILEDIR = DATADIR + "profiles/";
}
else {
bool confPathExists = QDir(QDir::homePath() + "/.config/qupzilla").exists();
bool homePathExists = QDir(QDir::homePath() + "/.qupzilla").exists();
if (homePathExists && !confPathExists) {
PROFILEDIR = QDir::homePath() + "/.qupzilla/";
}
else {
PROFILEDIR = QDir::homePath() + "/.config/qupzilla/";
}
}
TRANSLATIONSDIR = DATADIR + "locale/";
THEMESDIR = DATADIR + "themes/";
// Don't start single application in private browsing // Don't start single application in private browsing
if (!m_isPrivateSession) { if (!m_isPrivateSession) {
#ifndef PORTABLE_BUILD QString appId = isPortable() ? "QupZillaWebBrowserPortable" : "QupZillaWebBrowser";
QString appId = "QupZillaWebBrowser";
#else
QString appId = "QupZillaWebBrowserPortable";
#endif
if (newInstance) { if (newInstance) {
if (startProfile.isEmpty() || startProfile == QLatin1String("default")) { if (startProfile.isEmpty() || startProfile == QLatin1String("default")) {
@ -337,14 +335,14 @@ void MainApplication::postLaunch()
connect(this, SIGNAL(messageReceived(QString)), this, SLOT(receiveAppMessage(QString))); connect(this, SIGNAL(messageReceived(QString)), this, SLOT(receiveAppMessage(QString)));
connect(this, SIGNAL(aboutToQuit()), this, SLOT(saveSettings())); connect(this, SIGNAL(aboutToQuit()), this, SLOT(saveSettings()));
#ifndef PORTABLE_BUILD if (!isPortable()) {
Settings settings; Settings settings;
bool alwaysCheckDefaultBrowser = settings.value("Web-Browser-Settings/CheckDefaultBrowser", DEFAULT_CHECK_DEFAULTBROWSER).toBool(); bool alwaysCheckDefaultBrowser = settings.value("Web-Browser-Settings/CheckDefaultBrowser", DEFAULT_CHECK_DEFAULTBROWSER).toBool();
if (alwaysCheckDefaultBrowser) { if (alwaysCheckDefaultBrowser) {
alwaysCheckDefaultBrowser = checkDefaultWebBrowser(); alwaysCheckDefaultBrowser = checkDefaultWebBrowser();
settings.setValue("Web-Browser-Settings/CheckDefaultBrowser", alwaysCheckDefaultBrowser); settings.setValue("Web-Browser-Settings/CheckDefaultBrowser", alwaysCheckDefaultBrowser);
}
} }
#endif
} }
void MainApplication::loadSettings() void MainApplication::loadSettings()
@ -510,6 +508,15 @@ bool MainApplication::isPrivateSession() const
return m_isPrivateSession; return m_isPrivateSession;
} }
bool MainApplication::isPortable() const
{
#ifdef PORTABLE_BUILD
return true;
#else
return m_isPortable;
#endif
}
bool MainApplication::isStartingAfterCrash() const bool MainApplication::isStartingAfterCrash() const
{ {
return m_startingAfterCrash; return m_startingAfterCrash;

View File

@ -85,6 +85,7 @@ public:
bool isClosing() const; bool isClosing() const;
bool isRestoring() const; bool isRestoring() const;
bool isPrivateSession() const; bool isPrivateSession() const;
bool isPortable() const;
bool isStartingAfterCrash() const; bool isStartingAfterCrash() const;
int windowCount() const; int windowCount() const;
QString currentLanguageFile() const; QString currentLanguageFile() const;
@ -197,6 +198,7 @@ private:
QString m_activeThemePath; QString m_activeThemePath;
bool m_isPrivateSession; bool m_isPrivateSession;
bool m_isPortable;
bool m_isClosing; bool m_isClosing;
bool m_isStateChanged; bool m_isStateChanged;
bool m_isRestoring; bool m_isRestoring;

View File

@ -71,6 +71,7 @@ enum CommandLineAction {
CL_ToggleFullScreen, CL_ToggleFullScreen,
CL_StartPrivateBrowsing, CL_StartPrivateBrowsing,
CL_StartNewInstance, CL_StartNewInstance,
CL_StartPortable,
CL_ExitAction CL_ExitAction
}; };
@ -128,12 +129,6 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Qz::NewTabPositionFlags)
#define DEFAULT_DOWNLOAD_USE_NATIVE_DIALOG true #define DEFAULT_DOWNLOAD_USE_NATIVE_DIALOG true
#endif #endif
#ifdef PORTABLE_BUILD
#define DEFAULT_ENABLE_PLUGINS false
#else
#define DEFAULT_ENABLE_PLUGINS true
#endif
#define QTWEBKIT_FROM_2_2 \ #define QTWEBKIT_FROM_2_2 \
(QT_VERSION >= 0x050000 || (QTWEBKIT_VERSION >= QTWEBKIT_VERSION_CHECK(2, 2, 0))) (QT_VERSION >= 0x050000 || (QTWEBKIT_VERSION >= QTWEBKIT_VERSION_CHECK(2, 2, 0)))

View File

@ -422,11 +422,7 @@ QString QupZillaSchemeReply::configPage()
QString KDEIntegration = tr("Disabled"); QString KDEIntegration = tr("Disabled");
#endif #endif
#ifdef PORTABLE_BUILD QString portableBuild = mApp->isPortable() ? tr("<b>Enabled</b>") : tr("Disabled");
QString portableBuild = tr("<b>Enabled</b>");
#else
QString portableBuild = tr("Disabled");
#endif
cPage.replace(QLatin1String("%BUILD-CONFIG-TEXT%"), cPage.replace(QLatin1String("%BUILD-CONFIG-TEXT%"),
QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Debug build"), debugBuild) + QString("<dt>%1</dt><dd>%2<dd>").arg(tr("Debug build"), debugBuild) +

View File

@ -83,7 +83,7 @@ void Plugins::loadSettings()
{ {
Settings settings; Settings settings;
settings.beginGroup("Plugin-Settings"); settings.beginGroup("Plugin-Settings");
m_pluginsEnabled = settings.value("EnablePlugins", DEFAULT_ENABLE_PLUGINS).toBool(); m_pluginsEnabled = settings.value("EnablePlugins", !mApp->isPortable()).toBool();
m_allowedPlugins = settings.value("AllowedPlugins", QStringList()).toStringList(); m_allowedPlugins = settings.value("AllowedPlugins", QStringList()).toStringList();
settings.endGroup(); settings.endGroup();
@ -165,11 +165,14 @@ void Plugins::loadAvailablePlugins()
m_pluginsLoaded = true; m_pluginsLoaded = true;
QStringList dirs; QStringList dirs;
dirs << mApp->DATADIR + "plugins/" dirs << mApp->DATADIR + "plugins/";
// Portable build: Load only plugins from DATADIR/plugins/ directory.
// Loaded plugins are saved with relative path, instead of absolute for // Portable build: Load only plugins from DATADIR/plugins/ directory.
// normal build. // Loaded plugins are saved with relative path, instead of absolute for
#ifndef PORTABLE_BUILD // normal build.
if (!mApp->isPortable()) {
dirs
#if defined(QZ_WS_X11) && !defined(NO_SYSTEM_DATAPATH) #if defined(QZ_WS_X11) && !defined(NO_SYSTEM_DATAPATH)
#ifdef USE_LIBPATH #ifdef USE_LIBPATH
<< USE_LIBPATH "qupzilla/" << USE_LIBPATH "qupzilla/"
@ -177,9 +180,8 @@ void Plugins::loadAvailablePlugins()
<< "/usr/lib/qupzilla/" << "/usr/lib/qupzilla/"
#endif #endif
#endif #endif
<< mApp->PROFILEDIR + "plugins/" << mApp->PROFILEDIR + "plugins/";
#endif }
;
foreach (const QString &dir, dirs) { foreach (const QString &dir, dirs) {
QDir pluginsDir = QDir(dir); QDir pluginsDir = QDir(dir);

View File

@ -40,7 +40,7 @@ PluginsManager::PluginsManager(QWidget* parent)
//Application Extensions //Application Extensions
Settings settings; Settings settings;
settings.beginGroup("Plugin-Settings"); settings.beginGroup("Plugin-Settings");
bool appPluginsEnabled = settings.value("EnablePlugins", DEFAULT_ENABLE_PLUGINS).toBool(); bool appPluginsEnabled = settings.value("EnablePlugins", !mApp->isPortable()).toBool();
settings.endGroup(); settings.endGroup();
ui->allowAppPlugins->setChecked(appPluginsEnabled); ui->allowAppPlugins->setChecked(appPluginsEnabled);
@ -115,11 +115,12 @@ void PluginsManager::save()
if (item->checkState() == Qt::Checked) { if (item->checkState() == Qt::Checked) {
const Plugins::Plugin plugin = item->data(Qt::UserRole + 10).value<Plugins::Plugin>(); const Plugins::Plugin plugin = item->data(Qt::UserRole + 10).value<Plugins::Plugin>();
#ifndef PORTABLE_BUILD if (!mApp->isPortable()) {
allowedPlugins.append(plugin.fullPath); allowedPlugins.append(plugin.fullPath);
#else }
allowedPlugins.append(mApp->DATADIR + "plugins/" + plugin.fileName); else {
#endif allowedPlugins.append(mApp->DATADIR + "plugins/" + plugin.fileName);
}
} }
} }