2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
2017-08-25 17:11:29 +02:00
|
|
|
* Falkon - Qt web browser
|
2016-04-23 09:46:49 +02:00
|
|
|
* Copyright (C) 2010-2016 David Rosca <nowrep@gmail.com>
|
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 "commandlineoptions.h"
|
|
|
|
|
2013-12-18 17:51:38 +01:00
|
|
|
#include <QFileInfo>
|
2015-09-09 23:37:28 +02:00
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QCommandLineParser>
|
2012-03-24 22:08:17 +01:00
|
|
|
|
2015-09-09 23:37:28 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
CommandLineOptions::CommandLineOptions()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
parseActions();
|
|
|
|
}
|
|
|
|
|
2012-01-21 23:19:38 +01:00
|
|
|
CommandLineOptions::ActionPairList CommandLineOptions::getActions()
|
|
|
|
{
|
|
|
|
return m_actions;
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void CommandLineOptions::parseActions()
|
|
|
|
{
|
2015-09-09 23:37:28 +02:00
|
|
|
// Options
|
|
|
|
QCommandLineOption authorsOption(QStringList({QSL("a"), QSL("authors")}));
|
|
|
|
authorsOption.setDescription(QSL("Displays author information."));
|
|
|
|
|
|
|
|
QCommandLineOption profileOption(QStringList({QSL("p"), QSL("profile")}));
|
|
|
|
profileOption.setValueName(QSL("profileName"));
|
|
|
|
profileOption.setDescription(QSL("Starts with specified profile."));
|
|
|
|
|
2016-07-25 10:24:49 +02:00
|
|
|
QCommandLineOption noExtensionsOption(QStringList({QSL("e"), QSL("no-extensions")}));
|
2015-09-09 23:37:28 +02:00
|
|
|
noExtensionsOption.setDescription(QSL("Starts without extensions."));
|
|
|
|
|
2016-07-25 10:24:49 +02:00
|
|
|
QCommandLineOption privateBrowsingOption(QStringList({QSL("i"), QSL("private-browsing")}));
|
2015-09-09 23:37:28 +02:00
|
|
|
privateBrowsingOption.setDescription(QSL("Starts private browsing."));
|
|
|
|
|
2016-07-25 10:24:49 +02:00
|
|
|
QCommandLineOption portableOption(QStringList({QSL("o"), QSL("portable")}));
|
2015-09-09 23:37:28 +02:00
|
|
|
portableOption.setDescription(QSL("Starts in portable mode."));
|
|
|
|
|
2016-07-25 10:24:49 +02:00
|
|
|
QCommandLineOption noRemoteOption(QStringList({QSL("r"), QSL("no-remote")}));
|
2015-09-09 23:37:28 +02:00
|
|
|
noRemoteOption.setDescription(QSL("Starts new browser instance."));
|
|
|
|
|
2016-07-25 10:24:49 +02:00
|
|
|
QCommandLineOption newTabOption(QStringList({QSL("t"), QSL("new-tab")}));
|
2015-09-09 23:37:28 +02:00
|
|
|
newTabOption.setDescription(QSL("Opens new tab."));
|
|
|
|
|
2016-07-25 10:24:49 +02:00
|
|
|
QCommandLineOption newWindowOption(QStringList({QSL("w"), QSL("new-window")}));
|
2015-09-09 23:37:28 +02:00
|
|
|
newWindowOption.setDescription(QSL("Opens new window."));
|
|
|
|
|
2016-07-25 10:24:49 +02:00
|
|
|
QCommandLineOption downloadManagerOption(QStringList({QSL("d"), QSL("download-manager")}));
|
2015-09-09 23:37:28 +02:00
|
|
|
downloadManagerOption.setDescription(QSL("Opens download manager."));
|
|
|
|
|
2016-07-25 10:24:49 +02:00
|
|
|
QCommandLineOption currentTabOption(QStringList({QSL("c"), QSL("current-tab")}));
|
2015-09-09 23:37:28 +02:00
|
|
|
currentTabOption.setValueName(QSL("URL"));
|
|
|
|
currentTabOption.setDescription(QSL("Opens URL in current tab."));
|
|
|
|
|
2016-07-25 10:24:49 +02:00
|
|
|
QCommandLineOption openWindowOption(QStringList({QSL("u"), QSL("open-window")}));
|
2015-09-09 23:37:28 +02:00
|
|
|
openWindowOption.setValueName(QSL("URL"));
|
|
|
|
openWindowOption.setDescription(QSL("Opens URL in new window."));
|
|
|
|
|
2016-07-25 10:24:49 +02:00
|
|
|
QCommandLineOption fullscreenOption(QStringList({QSL("f"), QSL("fullscreen")}));
|
2015-09-09 23:37:28 +02:00
|
|
|
fullscreenOption.setDescription(QSL("Toggles fullscreen."));
|
|
|
|
|
|
|
|
// Parser
|
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.setApplicationDescription(QSL("QtWebEngine based browser"));
|
2016-04-23 09:46:49 +02:00
|
|
|
QCommandLineOption helpOption = parser.addHelpOption();
|
|
|
|
QCommandLineOption versionOption = parser.addVersionOption();
|
2015-09-09 23:37:28 +02:00
|
|
|
parser.addOption(authorsOption);
|
|
|
|
parser.addOption(profileOption);
|
|
|
|
parser.addOption(noExtensionsOption);
|
|
|
|
parser.addOption(privateBrowsingOption);
|
|
|
|
parser.addOption(portableOption);
|
|
|
|
parser.addOption(noRemoteOption);
|
|
|
|
parser.addOption(newTabOption);
|
|
|
|
parser.addOption(newWindowOption);
|
|
|
|
parser.addOption(downloadManagerOption);
|
|
|
|
parser.addOption(currentTabOption);
|
|
|
|
parser.addOption(openWindowOption);
|
|
|
|
parser.addOption(fullscreenOption);
|
|
|
|
parser.addPositionalArgument(QSL("URL"), QSL("URLs to open"), QSL("[URL...]"));
|
2016-04-23 09:46:49 +02:00
|
|
|
|
|
|
|
// parse() and not process() so we can pass arbitrary options to Chromium
|
|
|
|
parser.parse(QCoreApplication::arguments());
|
|
|
|
|
|
|
|
if (parser.isSet(helpOption)) {
|
|
|
|
parser.showHelp();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser.isSet(versionOption)) {
|
|
|
|
parser.showVersion();
|
|
|
|
}
|
2015-09-09 23:37:28 +02:00
|
|
|
|
|
|
|
if (parser.isSet(authorsOption)) {
|
|
|
|
std::cout << "David Rosca <nowrep@gmail.com>" << std::endl;
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2015-09-09 23:37:28 +02:00
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_ExitAction;
|
|
|
|
m_actions.append(pair);
|
2012-03-24 22:08:17 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-09 23:37:28 +02:00
|
|
|
if (parser.isSet(profileOption)) {
|
|
|
|
const QString profileName = parser.value(profileOption);
|
2017-08-25 17:11:29 +02:00
|
|
|
std::cout << "Falkon: Starting with profile '" << profileName.toUtf8().data() << "'" << std::endl;
|
2015-09-09 23:37:28 +02:00
|
|
|
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_StartWithProfile;
|
|
|
|
pair.text = profileName;
|
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser.isSet(noExtensionsOption)) {
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_StartWithoutAddons;
|
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser.isSet(privateBrowsingOption)) {
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_StartPrivateBrowsing;
|
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser.isSet(portableOption)) {
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_StartPortable;
|
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser.isSet(noRemoteOption)) {
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_StartNewInstance;
|
|
|
|
m_actions.append(pair);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2015-09-09 23:37:28 +02:00
|
|
|
if (parser.isSet(newTabOption)) {
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_NewTab;
|
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser.isSet(newWindowOption)) {
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_NewWindow;
|
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser.isSet(downloadManagerOption)) {
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_ShowDownloadManager;
|
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser.isSet(currentTabOption)) {
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_OpenUrlInCurrentTab;
|
|
|
|
pair.text = parser.value(currentTabOption);
|
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser.isSet(openWindowOption)) {
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_OpenUrlInNewWindow;
|
|
|
|
pair.text = parser.value(openWindowOption);
|
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser.isSet(fullscreenOption)) {
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_ToggleFullScreen;
|
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parser.positionalArguments().isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QString url = parser.positionalArguments().last();
|
2013-12-18 17:51:38 +01:00
|
|
|
QFileInfo fileInfo(url);
|
|
|
|
|
|
|
|
if (fileInfo.exists()) {
|
|
|
|
url = fileInfo.absoluteFilePath();
|
|
|
|
}
|
2012-03-24 22:08:17 +01:00
|
|
|
|
2015-09-09 23:37:28 +02:00
|
|
|
if (!url.isEmpty() && !url.startsWith(QLatin1Char('-'))) {
|
2011-05-18 22:58:49 +02:00
|
|
|
ActionPair pair;
|
2012-01-21 23:19:38 +01:00
|
|
|
pair.action = Qz::CL_OpenUrl;
|
2011-05-18 22:58:49 +02:00
|
|
|
pair.text = url;
|
2011-04-03 21:50:44 +02:00
|
|
|
m_actions.append(pair);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|