1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

Added new command line options (new tab, new window, show download

manager) + fixed overall behaviour
This commit is contained in:
nowrep 2011-05-18 22:58:49 +02:00
parent d3f997a121
commit cc2b20b54b
5 changed files with 130 additions and 54 deletions

View File

@ -30,21 +30,26 @@ void CommandLineOptions::showHelp()
{
using namespace std;
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"
" -p or -profile=PROFILE start with specified profile \n"
" -np or -no-plugins start without plugins \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"
;
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";
cout << help << " > " << QupZilla::WWWADDRESS.toAscii().data() << endl;
}
@ -56,41 +61,74 @@ void CommandLineOptions::parseActions()
// Skip first argument (it should be program itself)
for (int i = 1; i < m_argc; i++) {
QString arg(m_argv[i]);
if (arg == "-h" || arg == "-help") {
if (arg == "-h" || arg == "--help") {
showHelp();
found = true;
ActionPair pair;
pair.action = ExitAction;
m_actions.append(pair);
break;
}
if (arg == "-a" || arg == "-authors") {
if (arg == "-a" || arg == "--authors") {
cout << "QupZilla authors: " << endl;
cout << " nowrep <nowrep@gmail.com>" << endl;
found = true;
ActionPair pair;
pair.action = ExitAction;
m_actions.append(pair);
break;
}
if (arg == "-v" || arg == "-version") {
if (arg == "-v" || arg == "--version") {
cout << "QupZilla v" << QupZilla::VERSION.toAscii().data()
<< "(build " << QupZilla::BUILDTIME.toAscii().data() << ")"
<< endl;
found = true;
ActionPair pair;
pair.action = ExitAction;
m_actions.append(pair);
break;
}
if (arg.startsWith("-p=") || arg.startsWith("-profile=")) {
if (arg.startsWith("-p=") || arg.startsWith("--profile=")) {
arg.remove("-p=");
arg.remove("-profile=");
arg.remove("--profile=");
found = true;
cout << "starting with profile " << arg.toAscii().data() << endl;
QPair<int, QString> pair;
pair.first = StartWithProfile;
pair.second = arg;
ActionPair pair;
pair.action = StartWithProfile;
pair.text = arg;
m_actions.append(pair);
}
if (arg.startsWith("-np") || arg.startsWith("-no-plugins")) {
if (arg.startsWith("-np") || arg.startsWith("--no-plugins")) {
found = true;
QPair<int, QString> pair;
pair.first = StartWithoutAddons;
pair.second = "";
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 = "";
m_actions.append(pair);
}
if (arg.startsWith("-nw") || arg.startsWith("--new-window")) {
found = true;
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 = "";
m_actions.append(pair);
}
}
@ -99,15 +137,17 @@ void CommandLineOptions::parseActions()
if (m_argc > 1 && !url.isEmpty() && !url.startsWith("-")) {
found = true;
cout << "starting with url " << url.toAscii().data() << endl;
QPair<int, QString> pair;
pair.first = OpenUrl;
pair.second = url;
ActionPair pair;
pair.action = OpenUrl;
pair.text = url;
m_actions.append(pair);
}
if (m_argc > 1 && !found) {
cout << "bad arguments!" << endl;
cout << " Used bad arguments! Please see help below." << endl;
showHelp();
ActionPair pair;
pair.action = ExitAction;
m_actions.append(pair);
}
}

View File

@ -26,9 +26,15 @@ class CommandLineOptions : public QObject
{
Q_OBJECT
public:
enum Action {NoAction, OpenUrl, StartWithProfile, StartWithoutAddons};
enum Action {NoAction, OpenUrl, StartWithProfile, StartWithoutAddons, NewTab, NewWindow, ShowDownloadManager, ExitAction};
struct ActionPair {
Action action;
QString text;
};
explicit CommandLineOptions(int &argc, char **argv);
QList<QPair<int, QString> > getActions() { return m_actions; }
QList<ActionPair> getActions() { return m_actions; }
private:
void showHelp();
@ -36,7 +42,7 @@ private:
int m_argc;
char **m_argv;
QList<QPair<int, QString> > m_actions;
QList<ActionPair> m_actions;
};
#endif // COMMANDLINEOPTIONS_H

View File

@ -28,7 +28,6 @@
#include "rssmanager.h"
#include "updater.h"
#include "autosaver.h"
#include "commandlineoptions.h"
#include "pluginproxy.h"
#include "bookmarksmodel.h"
#include "downloadmanager.h"
@ -38,7 +37,7 @@
#include "iconprovider.h"
#include "qtwin.h"
MainApplication::MainApplication(int &argc, char **argv)
MainApplication::MainApplication(const QList<CommandLineOptions::ActionPair> &cmdActions, int &argc, char **argv)
: QtSingleApplication("QupZillaWebBrowser", argc, argv)
,m_bookmarksmanager(0)
,m_cookiemanager(0)
@ -73,24 +72,28 @@ MainApplication::MainApplication(int &argc, char **argv)
QString startProfile;
if (argc > 1) {
CommandLineOptions cmd(argc, argv);
QList<QPair<int, QString> > cmdActions = cmd.getActions();
for (int i = 0; i < cmdActions.count(); i++) {
QPair<int, QString> act = cmdActions.at(i);
switch (act.first) {
foreach (CommandLineOptions::ActionPair pair, cmdActions) {
switch (pair.action) {
case CommandLineOptions::StartWithoutAddons:
noAddons = true;
break;
case CommandLineOptions::OpenUrl:
startUrl = act.second;
message = "URL:"+startUrl.toString();
break;
case CommandLineOptions::StartWithProfile:
startProfile = act.second;
startProfile = pair.text;
break;
case CommandLineOptions::NewTab:
message = "ACTION:NewTab";
break;
case CommandLineOptions::NewWindow:
message = "ACTION:NewWindow";
break;
case CommandLineOptions::ShowDownloadManager:
message = "ACTION:ShowDownloadManager";
break;
case CommandLineOptions::OpenUrl:
startUrl = pair.text;
message = "URL:" + startUrl.toString();
break;
default:
m_isExited = true;
return;
break;
}
}
@ -252,6 +255,14 @@ void MainApplication::receiveAppMessage(QString message)
if (message.startsWith("URL:")) {
QString url(message.remove("URL:"));
addNewTab(WebView::guessUrlFromString(url));
} else if (message.startsWith("ACTION:")) {
QString text = message.mid(7);
if (text == "NewTab")
addNewTab();
else if (text == "NewWindow")
makeNewWindow(false);
else if (text == "ShowDownloadManager")
downManager()->show();
}
QupZilla* actWin = getWindow();
@ -265,7 +276,7 @@ void MainApplication::receiveAppMessage(QString message)
actWin->setFocus();
}
void MainApplication::addNewTab(QUrl url)
void MainApplication::addNewTab(const QUrl &url)
{
if (!getWindow())
return;

View File

@ -28,6 +28,7 @@
#include <iostream>
#include "qtsingleapplication.h"
#include "commandlineoptions.h"
class QupZilla;
class BookmarksManager;
@ -52,7 +53,7 @@ class MainApplication : public QtSingleApplication
public:
QString DATADIR;
explicit MainApplication(int &argc, char **argv);
explicit MainApplication(const QList<CommandLineOptions::ActionPair> &cmdActions, int &argc, char **argv);
enum MessageType{ SetAdBlockIconEnabled, CheckPrivateBrowsing , ReloadSettings };
@ -60,7 +61,7 @@ public:
void reloadSettings() { emit message(ReloadSettings, true); }
bool restoreStateSlot(QupZilla* window);
void makeNewWindow(bool tryRestore, const QUrl &startUrl=QUrl());
void addNewTab(QUrl url);
void addNewTab(const QUrl &url = QUrl());
void aboutToCloseWindow(QupZilla* window);
bool isChanged();

View File

@ -20,6 +20,7 @@
#include <QTextCodec>
#include <QtPlugin>
#include <iostream>
#include "commandlineoptions.h"
#include "mainapplication.h"
int main(int argc, char *argv[])
@ -32,9 +33,26 @@ int main(int argc, char *argv[])
QApplication::setGraphicsSystem("raster"); // Better overall performance on X11
#endif
MainApplication app(argc, argv);
QList<CommandLineOptions::ActionPair> cmdActions;
if (argc > 1) {
CommandLineOptions cmd(argc, argv);
cmdActions = cmd.getActions();
foreach (CommandLineOptions::ActionPair pair, cmdActions) {
switch (pair.action) {
case CommandLineOptions::ExitAction:
return 1;
break;
default:
break;
}
}
}
MainApplication app(cmdActions, argc, argv);
if (app.isExited()) {
std::cout << "QupZilla already running - activating existing window" << std::endl;
if (argc == 1)
std::cout << "QupZilla already running - activating existing window" << std::endl;
return 1;
}