1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56: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

@ -33,18 +33,23 @@ void CommandLineOptions::showHelp()
const char* help = " Usage: qupzilla [options] URL \n" const char* help = " Usage: qupzilla [options] URL \n"
"\n" "\n"
" QupZilla options:\n" " QupZilla options:\n"
" -h or -help print this message \n" " -h or --help print this message \n"
" -a or -authors print QupZilla authors \n" " -a or --authors print QupZilla authors \n"
" -v or -version print QupZilla version \n" " -v or --version print QupZilla version \n"
" -p or -profile=PROFILE start with specified profile \n" "\n"
" -np or -no-plugins start without plugins \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" "\n"
" QupZilla is a new, fast and secure web browser\n" " QupZilla is a new, fast and secure web browser\n"
" based on WebKit core (http://webkit.org) and\n" " based on WebKit core (http://webkit.org) and\n"
" written in Qt Framework (http://qt.nokia.com) \n\n" " written in Qt Framework (http://qt.nokia.com) \n\n"
" For more informations please visit wiki at \n" " For more informations please visit wiki at \n"
" https://github.com/nowrep/QupZilla/wiki \n" " https://github.com/nowrep/QupZilla/wiki \n";
;
cout << help << " > " << QupZilla::WWWADDRESS.toAscii().data() << endl; cout << help << " > " << QupZilla::WWWADDRESS.toAscii().data() << endl;
} }
@ -56,41 +61,74 @@ void CommandLineOptions::parseActions()
// Skip first argument (it should be program itself) // Skip first argument (it should be program itself)
for (int i = 1; i < m_argc; i++) { for (int i = 1; i < m_argc; i++) {
QString arg(m_argv[i]); QString arg(m_argv[i]);
if (arg == "-h" || arg == "-help") { if (arg == "-h" || arg == "--help") {
showHelp(); showHelp();
found = true; found = true;
ActionPair pair;
pair.action = ExitAction;
m_actions.append(pair);
break; break;
} }
if (arg == "-a" || arg == "-authors") { if (arg == "-a" || arg == "--authors") {
cout << "QupZilla authors: " << endl; cout << "QupZilla authors: " << endl;
cout << " nowrep <nowrep@gmail.com>" << endl; cout << " nowrep <nowrep@gmail.com>" << endl;
found = true; found = true;
ActionPair pair;
pair.action = ExitAction;
m_actions.append(pair);
break; break;
} }
if (arg == "-v" || arg == "-version") { if (arg == "-v" || arg == "--version") {
cout << "QupZilla v" << QupZilla::VERSION.toAscii().data() cout << "QupZilla v" << QupZilla::VERSION.toAscii().data()
<< "(build " << QupZilla::BUILDTIME.toAscii().data() << ")" << "(build " << QupZilla::BUILDTIME.toAscii().data() << ")"
<< endl; << endl;
found = true; found = true;
ActionPair pair;
pair.action = ExitAction;
m_actions.append(pair);
break; break;
} }
if (arg.startsWith("-p=") || arg.startsWith("-profile=")) { if (arg.startsWith("-p=") || arg.startsWith("--profile=")) {
arg.remove("-p="); arg.remove("-p=");
arg.remove("-profile="); arg.remove("--profile=");
found = true; found = true;
cout << "starting with profile " << arg.toAscii().data() << endl; cout << "starting with profile " << arg.toAscii().data() << endl;
QPair<int, QString> pair; ActionPair pair;
pair.first = StartWithProfile; pair.action = StartWithProfile;
pair.second = arg; pair.text = arg;
m_actions.append(pair); m_actions.append(pair);
} }
if (arg.startsWith("-np") || arg.startsWith("-no-plugins")) { if (arg.startsWith("-np") || arg.startsWith("--no-plugins")) {
found = true; found = true;
QPair<int, QString> pair; ActionPair pair;
pair.first = StartWithoutAddons; pair.action = StartWithoutAddons;
pair.second = ""; 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); m_actions.append(pair);
} }
} }
@ -99,15 +137,17 @@ void CommandLineOptions::parseActions()
if (m_argc > 1 && !url.isEmpty() && !url.startsWith("-")) { if (m_argc > 1 && !url.isEmpty() && !url.startsWith("-")) {
found = true; found = true;
cout << "starting with url " << url.toAscii().data() << endl; cout << "starting with url " << url.toAscii().data() << endl;
QPair<int, QString> pair; ActionPair pair;
pair.first = OpenUrl; pair.action = OpenUrl;
pair.second = url; pair.text = url;
m_actions.append(pair); m_actions.append(pair);
} }
if (m_argc > 1 && !found) { if (m_argc > 1 && !found) {
cout << "bad arguments!" << endl; cout << " Used bad arguments! Please see help below." << endl;
showHelp(); showHelp();
ActionPair pair;
pair.action = ExitAction;
m_actions.append(pair);
} }
} }

View File

@ -26,9 +26,15 @@ class CommandLineOptions : public QObject
{ {
Q_OBJECT Q_OBJECT
public: 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); explicit CommandLineOptions(int &argc, char **argv);
QList<QPair<int, QString> > getActions() { return m_actions; } QList<ActionPair> getActions() { return m_actions; }
private: private:
void showHelp(); void showHelp();
@ -36,7 +42,7 @@ private:
int m_argc; int m_argc;
char **m_argv; char **m_argv;
QList<QPair<int, QString> > m_actions; QList<ActionPair> m_actions;
}; };
#endif // COMMANDLINEOPTIONS_H #endif // COMMANDLINEOPTIONS_H

View File

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

View File

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

View File

@ -20,6 +20,7 @@
#include <QTextCodec> #include <QTextCodec>
#include <QtPlugin> #include <QtPlugin>
#include <iostream> #include <iostream>
#include "commandlineoptions.h"
#include "mainapplication.h" #include "mainapplication.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -32,8 +33,25 @@ int main(int argc, char *argv[])
QApplication::setGraphicsSystem("raster"); // Better overall performance on X11 QApplication::setGraphicsSystem("raster"); // Better overall performance on X11
#endif #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()) { if (app.isExited()) {
if (argc == 1)
std::cout << "QupZilla already running - activating existing window" << std::endl; std::cout << "QupZilla already running - activating existing window" << std::endl;
return 1; return 1;
} }