diff --git a/src/lib/app/commandlineoptions.cpp b/src/lib/app/commandlineoptions.cpp index 061b8cf3b..66f0417cc 100644 --- a/src/lib/app/commandlineoptions.cpp +++ b/src/lib/app/commandlineoptions.cpp @@ -45,6 +45,7 @@ void CommandLineOptions::showHelp() "\n" " -p=PROFILE or --profile=PROFILE start with specified profile \n" " -ne or --no-extensions start without extensions\n" + " -po or --portable start in portable mode\n" "\n" " Options to control running QupZilla:\n" " -nt or --new-tab open new tab\n" @@ -157,6 +158,12 @@ void CommandLineOptions::parseActions() 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"))) { ActionPair pair; pair.action = Qz::CL_ToggleFullScreen; diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index d4f705c23..3bd90f6ad 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -73,10 +73,6 @@ #include #include -#if defined(PORTABLE_BUILD) && !defined(NO_SYSTEM_DATAPATH) -#define NO_SYSTEM_DATAPATH -#endif - #if QT_VERSION < 0x050000 #include "qwebkitversion.h" #endif @@ -105,6 +101,7 @@ MainApplication::MainApplication(int &argc, char** argv) , m_dbWriter(new DatabaseWriter(this)) , m_uaManager(new UserAgentManager) , m_isPrivateSession(false) + , m_isPortable(false) , m_isClosing(false) , m_isStateChanged(false) , m_isRestoring(false) @@ -128,23 +125,6 @@ MainApplication::MainApplication(int &argc, char** argv) DATADIR.append(QLatin1String("../Resources/")); #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")); bool noAddons = false; bool newInstance = false; @@ -163,6 +143,9 @@ MainApplication::MainApplication(int &argc, char** argv) case Qz::CL_StartWithProfile: startProfile = pair.text; break; + case Qz::CL_StartPortable: + m_isPortable = true; + break; case Qz::CL_NewTab: messages.append(QLatin1String("ACTION:NewTab")); 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 if (!m_isPrivateSession) { -#ifndef PORTABLE_BUILD - QString appId = "QupZillaWebBrowser"; -#else - QString appId = "QupZillaWebBrowserPortable"; -#endif + QString appId = isPortable() ? "QupZillaWebBrowserPortable" : "QupZillaWebBrowser"; if (newInstance) { 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(aboutToQuit()), this, SLOT(saveSettings())); -#ifndef PORTABLE_BUILD - Settings settings; - bool alwaysCheckDefaultBrowser = settings.value("Web-Browser-Settings/CheckDefaultBrowser", DEFAULT_CHECK_DEFAULTBROWSER).toBool(); - if (alwaysCheckDefaultBrowser) { - alwaysCheckDefaultBrowser = checkDefaultWebBrowser(); - settings.setValue("Web-Browser-Settings/CheckDefaultBrowser", alwaysCheckDefaultBrowser); + if (!isPortable()) { + Settings settings; + bool alwaysCheckDefaultBrowser = settings.value("Web-Browser-Settings/CheckDefaultBrowser", DEFAULT_CHECK_DEFAULTBROWSER).toBool(); + if (alwaysCheckDefaultBrowser) { + alwaysCheckDefaultBrowser = checkDefaultWebBrowser(); + settings.setValue("Web-Browser-Settings/CheckDefaultBrowser", alwaysCheckDefaultBrowser); + } } -#endif } void MainApplication::loadSettings() @@ -510,6 +508,15 @@ bool MainApplication::isPrivateSession() const return m_isPrivateSession; } +bool MainApplication::isPortable() const +{ +#ifdef PORTABLE_BUILD + return true; +#else + return m_isPortable; +#endif +} + bool MainApplication::isStartingAfterCrash() const { return m_startingAfterCrash; diff --git a/src/lib/app/mainapplication.h b/src/lib/app/mainapplication.h index c9d9ced8b..5ea284c2d 100644 --- a/src/lib/app/mainapplication.h +++ b/src/lib/app/mainapplication.h @@ -85,6 +85,7 @@ public: bool isClosing() const; bool isRestoring() const; bool isPrivateSession() const; + bool isPortable() const; bool isStartingAfterCrash() const; int windowCount() const; QString currentLanguageFile() const; @@ -197,6 +198,7 @@ private: QString m_activeThemePath; bool m_isPrivateSession; + bool m_isPortable; bool m_isClosing; bool m_isStateChanged; bool m_isRestoring; diff --git a/src/lib/app/qz_namespace.h b/src/lib/app/qz_namespace.h index 21a4b47c9..76e98f94d 100644 --- a/src/lib/app/qz_namespace.h +++ b/src/lib/app/qz_namespace.h @@ -71,6 +71,7 @@ enum CommandLineAction { CL_ToggleFullScreen, CL_StartPrivateBrowsing, CL_StartNewInstance, + CL_StartPortable, CL_ExitAction }; @@ -128,12 +129,6 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Qz::NewTabPositionFlags) #define DEFAULT_DOWNLOAD_USE_NATIVE_DIALOG true #endif -#ifdef PORTABLE_BUILD -#define DEFAULT_ENABLE_PLUGINS false -#else -#define DEFAULT_ENABLE_PLUGINS true -#endif - #define QTWEBKIT_FROM_2_2 \ (QT_VERSION >= 0x050000 || (QTWEBKIT_VERSION >= QTWEBKIT_VERSION_CHECK(2, 2, 0))) diff --git a/src/lib/network/schemehandlers/qupzillaschemehandler.cpp b/src/lib/network/schemehandlers/qupzillaschemehandler.cpp index ebf567d06..873e90019 100644 --- a/src/lib/network/schemehandlers/qupzillaschemehandler.cpp +++ b/src/lib/network/schemehandlers/qupzillaschemehandler.cpp @@ -422,11 +422,7 @@ QString QupZillaSchemeReply::configPage() QString KDEIntegration = tr("Disabled"); #endif -#ifdef PORTABLE_BUILD - QString portableBuild = tr("Enabled"); -#else - QString portableBuild = tr("Disabled"); -#endif + QString portableBuild = mApp->isPortable() ? tr("Enabled") : tr("Disabled"); cPage.replace(QLatin1String("%BUILD-CONFIG-TEXT%"), QString("
%1
%2
").arg(tr("Debug build"), debugBuild) + diff --git a/src/lib/plugins/plugins.cpp b/src/lib/plugins/plugins.cpp index 0e9399fa7..80afe3fe7 100644 --- a/src/lib/plugins/plugins.cpp +++ b/src/lib/plugins/plugins.cpp @@ -83,7 +83,7 @@ void Plugins::loadSettings() { Settings 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(); settings.endGroup(); @@ -165,11 +165,14 @@ void Plugins::loadAvailablePlugins() m_pluginsLoaded = true; QStringList dirs; - dirs << mApp->DATADIR + "plugins/" - // Portable build: Load only plugins from DATADIR/plugins/ directory. - // Loaded plugins are saved with relative path, instead of absolute for - // normal build. -#ifndef PORTABLE_BUILD + dirs << mApp->DATADIR + "plugins/"; + + // Portable build: Load only plugins from DATADIR/plugins/ directory. + // Loaded plugins are saved with relative path, instead of absolute for + // normal build. + + if (!mApp->isPortable()) { + dirs #if defined(QZ_WS_X11) && !defined(NO_SYSTEM_DATAPATH) #ifdef USE_LIBPATH << USE_LIBPATH "qupzilla/" @@ -177,9 +180,8 @@ void Plugins::loadAvailablePlugins() << "/usr/lib/qupzilla/" #endif #endif - << mApp->PROFILEDIR + "plugins/" -#endif - ; + << mApp->PROFILEDIR + "plugins/"; + } foreach (const QString &dir, dirs) { QDir pluginsDir = QDir(dir); diff --git a/src/lib/preferences/pluginsmanager.cpp b/src/lib/preferences/pluginsmanager.cpp index 012b3c275..b1d62e010 100644 --- a/src/lib/preferences/pluginsmanager.cpp +++ b/src/lib/preferences/pluginsmanager.cpp @@ -40,7 +40,7 @@ PluginsManager::PluginsManager(QWidget* parent) //Application Extensions Settings settings; settings.beginGroup("Plugin-Settings"); - bool appPluginsEnabled = settings.value("EnablePlugins", DEFAULT_ENABLE_PLUGINS).toBool(); + bool appPluginsEnabled = settings.value("EnablePlugins", !mApp->isPortable()).toBool(); settings.endGroup(); ui->allowAppPlugins->setChecked(appPluginsEnabled); @@ -115,11 +115,12 @@ void PluginsManager::save() if (item->checkState() == Qt::Checked) { const Plugins::Plugin plugin = item->data(Qt::UserRole + 10).value(); -#ifndef PORTABLE_BUILD - allowedPlugins.append(plugin.fullPath); -#else - allowedPlugins.append(mApp->DATADIR + "plugins/" + plugin.fileName); -#endif + if (!mApp->isPortable()) { + allowedPlugins.append(plugin.fullPath); + } + else { + allowedPlugins.append(mApp->DATADIR + "plugins/" + plugin.fileName); + } } }