2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 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"
|
2014-02-19 22:07:21 +01:00
|
|
|
#include "browserwindow.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-03-24 22:08:17 +01:00
|
|
|
#include <QCoreApplication>
|
2013-12-18 17:51:38 +01:00
|
|
|
#include <QFileInfo>
|
2012-03-24 22:08:17 +01:00
|
|
|
|
|
|
|
CommandLineOptions::CommandLineOptions(int &argc)
|
2012-01-21 20:27:45 +01:00
|
|
|
: m_argc(argc)
|
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::showHelp()
|
|
|
|
{
|
|
|
|
using namespace std;
|
|
|
|
|
2011-05-18 22:58:49 +02:00
|
|
|
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"
|
2014-01-23 13:02:07 +01:00
|
|
|
" -po or --portable start in portable mode\n"
|
2012-03-25 14:21:45 +02:00
|
|
|
"\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"
|
2014-01-22 17:34:25 +01:00
|
|
|
" -fs or --fullscreen toggle fullscreen\n"
|
|
|
|
" -nr or --no-remote open new browser instance\n"
|
2012-04-03 20:41:07 +02:00
|
|
|
" -ct=URL or --current-tab=URL open URL in current tab\n"
|
2012-07-10 00:36:05 +02:00
|
|
|
" -ow=URL or --open-window=URL open URL in new window\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"
|
2014-01-22 17:11:17 +01:00
|
|
|
" written in Qt Framework (http://qt-project.org/) \n\n"
|
2012-03-25 14:21:45 +02:00
|
|
|
" For more information please visit wiki at \n"
|
2012-04-17 14:00:32 +02:00
|
|
|
" https://github.com/QupZilla/qupzilla/wiki \n";
|
2011-05-18 22:58:49 +02:00
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
cout << help << " > " << Qz::WWWADDRESS.toUtf8().data() << endl;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandLineOptions::parseActions()
|
|
|
|
{
|
|
|
|
using namespace std;
|
|
|
|
|
2013-12-30 13:43:48 +01:00
|
|
|
const QStringList arguments = QCoreApplication::arguments();
|
2012-03-24 22:08:17 +01:00
|
|
|
if (arguments.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-10 21:25:31 +02:00
|
|
|
// Skip first argument (it should be program itself)
|
2012-03-24 22:08:17 +01:00
|
|
|
for (int i = 1; i < arguments.count(); ++i) {
|
|
|
|
QString arg = arguments.at(i);
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (arg == QLatin1String("-h") || arg == QLatin1String("--help")) {
|
2011-03-02 16:57:41 +01:00
|
|
|
showHelp();
|
2011-05-18 22:58:49 +02:00
|
|
|
ActionPair pair;
|
2012-01-21 23:19:38 +01:00
|
|
|
pair.action = Qz::CL_ExitAction;
|
2011-05-18 22:58:49 +02:00
|
|
|
m_actions.append(pair);
|
2011-03-02 16:57:41 +01:00
|
|
|
break;
|
|
|
|
}
|
2011-12-26 20:23:54 +01:00
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (arg == QLatin1String("-a") || arg == QLatin1String("--authors")) {
|
2011-03-02 16:57:41 +01:00
|
|
|
cout << "QupZilla authors: " << endl;
|
2013-03-04 13:23:04 +01:00
|
|
|
cout << " David Rosca <nowrep@gmail.com>" << endl;
|
2011-05-18 22:58:49 +02:00
|
|
|
ActionPair pair;
|
2012-01-21 23:19:38 +01:00
|
|
|
pair.action = Qz::CL_ExitAction;
|
2011-05-18 22:58:49 +02:00
|
|
|
m_actions.append(pair);
|
2011-03-02 16:57:41 +01:00
|
|
|
break;
|
|
|
|
}
|
2011-12-26 20:23:54 +01:00
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (arg == QLatin1String("-v") || arg == QLatin1String("--version")) {
|
2014-02-19 22:07:21 +01:00
|
|
|
cout << "QupZilla v" << Qz::VERSION.toUtf8().data()
|
2012-03-25 14:21:45 +02:00
|
|
|
#ifdef GIT_REVISION
|
2011-12-18 15:42:28 +01:00
|
|
|
<< " rev " << GIT_REVISION << " "
|
2012-03-25 14:21:45 +02:00
|
|
|
#endif
|
2014-02-19 22:07:21 +01:00
|
|
|
<< "(build " << Qz::BUILDTIME.toUtf8().data() << ")"
|
2011-03-02 16:57:41 +01:00
|
|
|
<< endl;
|
2011-05-18 22:58:49 +02:00
|
|
|
ActionPair pair;
|
2012-01-21 23:19:38 +01:00
|
|
|
pair.action = Qz::CL_ExitAction;
|
2011-05-18 22:58:49 +02:00
|
|
|
m_actions.append(pair);
|
2011-03-02 16:57:41 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (arg.startsWith(QLatin1String("-p=")) || arg.startsWith(QLatin1String("--profile="))) {
|
|
|
|
int index = arg.indexOf(QLatin1Char('='));
|
2012-07-10 00:36:05 +02:00
|
|
|
if (index != -1) {
|
2012-07-10 11:56:24 +02:00
|
|
|
const QString profileName = arg.mid(index + 1);
|
|
|
|
cout << "QupZilla: Starting with profile '" << profileName.toUtf8().data() << "'" << endl;
|
2012-07-10 00:36:05 +02:00
|
|
|
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_StartWithProfile;
|
2012-07-10 11:56:24 +02:00
|
|
|
pair.text = profileName;
|
2012-07-10 00:36:05 +02:00
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
2011-05-18 22:58:49 +02:00
|
|
|
}
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (arg.startsWith(QLatin1String("-ne")) || arg.startsWith(QLatin1String("--no-extensions"))) {
|
2011-05-18 22:58:49 +02:00
|
|
|
ActionPair pair;
|
2012-01-21 23:19:38 +01:00
|
|
|
pair.action = Qz::CL_StartWithoutAddons;
|
2011-05-18 22:58:49 +02:00
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (arg.startsWith(QLatin1String("-nt")) || arg.startsWith(QLatin1String("--new-tab"))) {
|
2011-05-18 22:58:49 +02:00
|
|
|
ActionPair pair;
|
2012-01-21 23:19:38 +01:00
|
|
|
pair.action = Qz::CL_NewTab;
|
2011-04-03 21:50:44 +02:00
|
|
|
m_actions.append(pair);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (arg.startsWith(QLatin1String("-nw")) || arg.startsWith(QLatin1String("--new-window"))) {
|
2011-05-18 22:58:49 +02:00
|
|
|
ActionPair pair;
|
2012-01-21 23:19:38 +01:00
|
|
|
pair.action = Qz::CL_NewWindow;
|
2011-05-18 22:58:49 +02:00
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (arg.startsWith(QLatin1String("-dm")) || arg.startsWith(QLatin1String("--download-manager"))) {
|
2011-05-18 22:58:49 +02:00
|
|
|
ActionPair pair;
|
2012-01-21 23:19:38 +01:00
|
|
|
pair.action = Qz::CL_ShowDownloadManager;
|
2011-04-03 21:50:44 +02:00
|
|
|
m_actions.append(pair);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-12-26 20:23:54 +01:00
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (arg.startsWith(QLatin1String("-pb")) || arg.startsWith(QLatin1String("--private-browsing"))) {
|
2011-12-26 20:23:54 +01:00
|
|
|
ActionPair pair;
|
2012-01-21 23:19:38 +01:00
|
|
|
pair.action = Qz::CL_StartPrivateBrowsing;
|
2012-09-01 15:59:27 +02:00
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (arg.startsWith(QLatin1String("-nr")) || arg.startsWith(QLatin1String("--no-remote"))) {
|
2012-09-01 15:59:27 +02:00
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_StartNewInstance;
|
2011-12-26 20:23:54 +01:00
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
2012-04-03 20:41:07 +02:00
|
|
|
|
2014-01-23 13:02:07 +01:00
|
|
|
if (arg.startsWith(QLatin1String("-po")) || arg.startsWith(QLatin1String("--portable"))) {
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_StartPortable;
|
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
2014-01-22 17:34:25 +01:00
|
|
|
if (arg.startsWith(QLatin1String("-fs")) || arg.startsWith(QLatin1String("--fullscreen"))) {
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_ToggleFullScreen;
|
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (arg.startsWith(QLatin1String("-ct")) || arg.startsWith(QLatin1String("--current-tab"))) {
|
|
|
|
int index = arg.indexOf(QLatin1Char('='));
|
2012-07-10 00:36:05 +02:00
|
|
|
if (index != -1) {
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_OpenUrlInCurrentTab;
|
|
|
|
pair.text = arg.mid(index + 1);
|
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (arg.startsWith(QLatin1String("-ow")) || arg.startsWith(QLatin1String("--open-window"))) {
|
|
|
|
int index = arg.indexOf(QLatin1Char('='));
|
2012-07-10 00:36:05 +02:00
|
|
|
if (index != -1) {
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = Qz::CL_OpenUrlInNewWindow;
|
|
|
|
pair.text = arg.mid(index + 1);
|
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
2012-04-03 20:41:07 +02:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:51:38 +01:00
|
|
|
QString url = arguments.last();
|
|
|
|
QFileInfo fileInfo(url);
|
|
|
|
|
|
|
|
if (fileInfo.exists()) {
|
|
|
|
url = fileInfo.absoluteFilePath();
|
|
|
|
}
|
2012-03-24 22:08:17 +01:00
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (m_argc > 1 && !url.isEmpty() && !url.startsWith(QLatin1Char('-')) &&
|
|
|
|
(url.contains(QLatin1Char('.')) || url.contains(QLatin1Char('/'))
|
|
|
|
|| url.contains(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
|
|
|
}
|
|
|
|
}
|