2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2011-12-15 18:34:48 +01:00
|
|
|
* Copyright (C) 2010-2011 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"
|
|
|
|
|
2011-12-12 21:14:43 +01:00
|
|
|
CommandLineOptions::CommandLineOptions(int &argc, char** argv)
|
|
|
|
: QObject(0)
|
2011-11-06 17:01:23 +01:00
|
|
|
, m_argc(argc)
|
|
|
|
, m_argv(argv)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
parseActions();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommandLineOptions::showHelp()
|
|
|
|
{
|
|
|
|
using namespace std;
|
|
|
|
|
2011-05-18 22:58:49 +02:00
|
|
|
const char* help = " Usage: qupzilla [options] URL \n"
|
|
|
|
"\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 or --profile=PROFILE start with specified profile \n"
|
|
|
|
" -np or --no-plugins start without plugins \n"
|
|
|
|
"\n"
|
|
|
|
" -nt or --new-tab open new tab\n"
|
|
|
|
" -nw or --new-window open new window\n"
|
|
|
|
" -dm or --download-manager show download manager\n"
|
|
|
|
"\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 informations please visit wiki at \n"
|
|
|
|
" https://github.com/nowrep/QupZilla/wiki \n";
|
|
|
|
|
2011-12-04 16:54:57 +01:00
|
|
|
cout << help << " > " << QupZilla::WWWADDRESS.toUtf8().data() << endl;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CommandLineOptions::parseActions()
|
|
|
|
{
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
bool found = false;
|
2011-05-10 21:25:31 +02:00
|
|
|
// Skip first argument (it should be program itself)
|
2011-03-02 16:57:41 +01:00
|
|
|
for (int i = 1; i < m_argc; i++) {
|
|
|
|
QString arg(m_argv[i]);
|
2011-05-18 22:58:49 +02:00
|
|
|
if (arg == "-h" || arg == "--help") {
|
2011-03-02 16:57:41 +01:00
|
|
|
showHelp();
|
|
|
|
found = true;
|
2011-05-18 22:58:49 +02:00
|
|
|
ActionPair pair;
|
|
|
|
pair.action = ExitAction;
|
|
|
|
m_actions.append(pair);
|
2011-03-02 16:57:41 +01:00
|
|
|
break;
|
|
|
|
}
|
2011-05-18 22:58:49 +02:00
|
|
|
if (arg == "-a" || arg == "--authors") {
|
2011-03-02 16:57:41 +01:00
|
|
|
cout << "QupZilla authors: " << endl;
|
|
|
|
cout << " nowrep <nowrep@gmail.com>" << endl;
|
|
|
|
found = true;
|
2011-05-18 22:58:49 +02:00
|
|
|
ActionPair pair;
|
|
|
|
pair.action = ExitAction;
|
|
|
|
m_actions.append(pair);
|
2011-03-02 16:57:41 +01:00
|
|
|
break;
|
|
|
|
}
|
2011-05-18 22:58:49 +02:00
|
|
|
if (arg == "-v" || arg == "--version") {
|
2011-12-04 16:54:57 +01:00
|
|
|
cout << "QupZilla v" << QupZilla::VERSION.toUtf8().data()
|
|
|
|
<< "(build " << QupZilla::BUILDTIME.toUtf8().data() << ")"
|
2011-03-02 16:57:41 +01:00
|
|
|
<< endl;
|
|
|
|
found = true;
|
2011-05-18 22:58:49 +02:00
|
|
|
ActionPair pair;
|
|
|
|
pair.action = ExitAction;
|
|
|
|
m_actions.append(pair);
|
2011-03-02 16:57:41 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-05-18 22:58:49 +02:00
|
|
|
if (arg.startsWith("-p=") || arg.startsWith("--profile=")) {
|
2011-03-02 16:57:41 +01:00
|
|
|
arg.remove("-p=");
|
2011-05-18 22:58:49 +02:00
|
|
|
arg.remove("--profile=");
|
2011-03-02 16:57:41 +01:00
|
|
|
found = true;
|
2011-12-04 16:54:57 +01:00
|
|
|
cout << "starting with profile " << arg.toUtf8().data() << endl;
|
2011-05-18 22:58:49 +02:00
|
|
|
ActionPair pair;
|
|
|
|
pair.action = StartWithProfile;
|
|
|
|
pair.text = arg;
|
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg.startsWith("-np") || arg.startsWith("--no-plugins")) {
|
|
|
|
found = true;
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = StartWithoutAddons;
|
|
|
|
pair.text = "";
|
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg.startsWith("-nt") || arg.startsWith("--new-tab")) {
|
|
|
|
found = true;
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = NewTab;
|
|
|
|
pair.text = "";
|
2011-04-03 21:50:44 +02:00
|
|
|
m_actions.append(pair);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-05-18 22:58:49 +02:00
|
|
|
if (arg.startsWith("-nw") || arg.startsWith("--new-window")) {
|
2011-03-02 16:57:41 +01:00
|
|
|
found = true;
|
2011-05-18 22:58:49 +02:00
|
|
|
ActionPair pair;
|
|
|
|
pair.action = NewWindow;
|
|
|
|
pair.text = "";
|
|
|
|
m_actions.append(pair);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg.startsWith("-dm") || arg.startsWith("--download-manager")) {
|
|
|
|
found = true;
|
|
|
|
ActionPair pair;
|
|
|
|
pair.action = ShowDownloadManager;
|
|
|
|
pair.text = "";
|
2011-04-03 21:50:44 +02:00
|
|
|
m_actions.append(pair);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
QString url(m_argv[m_argc - 1]);
|
2011-03-02 16:57:41 +01:00
|
|
|
if (m_argc > 1 && !url.isEmpty() && !url.startsWith("-")) {
|
|
|
|
found = true;
|
2011-12-04 16:54:57 +01:00
|
|
|
cout << "starting with url " << url.toUtf8().data() << endl;
|
2011-05-18 22:58:49 +02:00
|
|
|
ActionPair pair;
|
|
|
|
pair.action = OpenUrl;
|
|
|
|
pair.text = url;
|
2011-04-03 21:50:44 +02:00
|
|
|
m_actions.append(pair);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_argc > 1 && !found) {
|
2011-05-18 22:58:49 +02:00
|
|
|
cout << " Used bad arguments! Please see help below." << endl;
|
2011-03-02 16:57:41 +01:00
|
|
|
showHelp();
|
2011-05-18 22:58:49 +02:00
|
|
|
ActionPair pair;
|
|
|
|
pair.action = ExitAction;
|
|
|
|
m_actions.append(pair);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|