1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 17:42:10 +01:00
falkonOfficial/src/lib/app/commandlineoptions.cpp

172 lines
6.1 KiB
C++
Raw Normal View History

2011-03-03 18:29:20 +01:00
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 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"
#include "qupzilla.h"
#include <QCoreApplication>
CommandLineOptions::CommandLineOptions(int &argc)
: m_argc(argc)
2011-03-02 16:57:41 +01:00
{
parseActions();
}
CommandLineOptions::ActionPairList CommandLineOptions::getActions()
{
return m_actions;
}
2011-03-02 16:57:41 +01:00
void CommandLineOptions::showHelp()
{
using namespace std;
const char* help = " Usage: qupzilla [options] URL \n"
2012-03-25 14:21:45 +02:00
"\n"
" QupZilla options:\n"
" -h or --help print this message \n"
" -a or --authors print QupZilla authors \n"
" -v or --version print QupZilla version \n"
"\n"
" -p=PROFILE or --profile=PROFILE start with specified profile \n"
" -ne or --no-extensions start without extensions\n"
"\n"
" Options to control running QupZilla:\n"
" -nt or --new-tab open new tab\n"
" -nw or --new-window open new window\n"
" -pb or --private-browsing start private browsing\n"
" -dm or --download-manager show download manager\n"
" -ct=URL or --current-tab=URL open URL in current tab\n"
2012-03-25 14:21:45 +02:00
"\n"
" QupZilla is a new, fast and secure web browser\n"
" based on WebKit core (http://webkit.org) and\n"
" written in Qt Framework (http://qt.nokia.com) \n\n"
" For more information please visit wiki at \n"
" https://github.com/QupZilla/qupzilla/wiki \n";
cout << help << " > " << QupZilla::WWWADDRESS.toUtf8().data() << endl;
2011-03-02 16:57:41 +01:00
}
void CommandLineOptions::parseActions()
{
using namespace std;
const QStringList &arguments = QCoreApplication::arguments();
if (arguments.isEmpty()) {
return;
}
// Skip first argument (it should be program itself)
for (int i = 1; i < arguments.count(); ++i) {
QString arg = arguments.at(i);
if (arg == "-h" || arg == "--help") {
2011-03-02 16:57:41 +01:00
showHelp();
ActionPair pair;
pair.action = Qz::CL_ExitAction;
m_actions.append(pair);
2011-03-02 16:57:41 +01:00
break;
}
if (arg == "-a" || arg == "--authors") {
2011-03-02 16:57:41 +01:00
cout << "QupZilla authors: " << endl;
cout << " nowrep <nowrep@gmail.com>" << endl;
ActionPair pair;
pair.action = Qz::CL_ExitAction;
m_actions.append(pair);
2011-03-02 16:57:41 +01:00
break;
}
if (arg == "-v" || arg == "--version") {
cout << "QupZilla v" << QupZilla::VERSION.toUtf8().data()
2012-03-25 14:21:45 +02:00
#ifdef GIT_REVISION
<< " rev " << GIT_REVISION << " "
2012-03-25 14:21:45 +02:00
#endif
<< "(build " << QupZilla::BUILDTIME.toUtf8().data() << ")"
2011-03-02 16:57:41 +01:00
<< endl;
ActionPair pair;
pair.action = Qz::CL_ExitAction;
m_actions.append(pair);
2011-03-02 16:57:41 +01:00
break;
}
if (arg.startsWith("-p=") || arg.startsWith("--profile=")) {
2011-03-02 16:57:41 +01:00
arg.remove("-p=");
arg.remove("--profile=");
cout << "QupZilla: Starting with profile " << arg.toUtf8().data() << endl;
ActionPair pair;
pair.action = Qz::CL_StartWithProfile;
pair.text = arg;
m_actions.append(pair);
}
if (arg.startsWith("-ne") || arg.startsWith("--no-extensions")) {
ActionPair pair;
pair.action = Qz::CL_StartWithoutAddons;
pair.text = "";
m_actions.append(pair);
}
if (arg.startsWith("-nt") || arg.startsWith("--new-tab")) {
ActionPair pair;
pair.action = Qz::CL_NewTab;
pair.text = "";
m_actions.append(pair);
2011-03-02 16:57:41 +01:00
}
if (arg.startsWith("-nw") || arg.startsWith("--new-window")) {
ActionPair pair;
pair.action = Qz::CL_NewWindow;
pair.text = "";
m_actions.append(pair);
}
if (arg.startsWith("-dm") || arg.startsWith("--download-manager")) {
ActionPair pair;
pair.action = Qz::CL_ShowDownloadManager;
pair.text = "";
m_actions.append(pair);
2011-03-02 16:57:41 +01:00
}
if (arg.startsWith("-pb") || arg.startsWith("--private-browsing")) {
ActionPair pair;
pair.action = Qz::CL_StartPrivateBrowsing;
pair.text = "";
m_actions.append(pair);
}
if (arg.startsWith("-ct") || arg.startsWith("--current-tab")) {
arg.remove("-ct=");
arg.remove("--current-tab=");
ActionPair pair;
pair.action = Qz::CL_OpenUrlInCurrentTab;
pair.text = arg;
m_actions.append(pair);
}
2011-03-02 16:57:41 +01:00
}
const QString &url = arguments.last();
if (m_argc > 1 && !url.isEmpty() && !url.startsWith("-") &&
(url.contains(".") || url.contains("/") || url.contains("\\"))) {
ActionPair pair;
pair.action = Qz::CL_OpenUrl;
pair.text = url;
m_actions.append(pair);
2011-03-02 16:57:41 +01:00
}
}