aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-09-26 14:07:07 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2017-09-26 14:07:07 +0200
commit7b995a088607ce75925c161f86cdef54d36b33d4 (patch)
tree1565fec0b0a0a5516960ec8a38a77455c5547ad7
parentSome fixes based on clazy (diff)
downloadsmolbote-7b995a088607ce75925c161f86cdef54d36b33d4.tar.xz
Passing full arguments to running instance
-rw-r--r--src/main.cpp103
1 files changed, 64 insertions, 39 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 86b39db..87def7a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -37,12 +37,8 @@ void printPoiToml(std::ostream &output)
}
}
-int main(int argc, char *argv[])
+const QHash<QString, QVariant> parseCommandLine(QApplication &app)
{
- // Create application object
- Browser app(argc, argv);
-
- // parse command line options
QCommandLineParser parser;
parser.setApplicationDescription("yet another Qt browser");
parser.addHelpOption();
@@ -57,8 +53,8 @@ int main(int argc, char *argv[])
QCommandLineOption profileOption(QStringList() << "p" << "profile", "Use this profile.", "PROFILE");
parser.addOption(profileOption);
- QCommandLineOption nopluginsOption(QStringList() << "n" << "no-plugins", "Don't load plugins");
- parser.addOption(nopluginsOption);
+ //QCommandLineOption nopluginsOption(QStringList() << "n" << "no-plugins", "Don't load plugins");
+ //parser.addOption(nopluginsOption);
QCommandLineOption newInstanceOption(QStringList() << "new-instance", "Skip instance check at startup");
parser.addOption(newInstanceOption);
@@ -73,47 +69,76 @@ int main(int argc, char *argv[])
parser.process(app);
- // Check for another instance
- // unless specified not to
- if(!parser.isSet(newInstanceOption)) {
- app.bindLocalSocket();
- if(app.isRunning()) {
- qDebug("Another instance is running, returning...");
- QHash<QString, QVariant> params;
- if(parser.isSet(profileOption)) {
- params.insert("profile", parser.value(profileOption));
- }
- params.insert("urls", QVariant(parser.positionalArguments()));
- app.sendMessage(params);
- return 0;
- }
+ QHash<QString, QVariant> options;
+ if(parser.isSet(configOption)) {
+ options.insert("config", parser.value(configOption));
}
-
if(parser.isSet(defaultConfigOption)) {
- printPoiToml(std::cout);
- return 0;
+ options.insert("print-defaults", true);
+ }
+ if(parser.isSet(profileOption)) {
+ options.insert("profile", parser.value(profileOption));
+ }
+ if(parser.isSet(newInstanceOption)) {
+ options.insert("new-instance", true);
}
+ if(parser.isSet(newWindowOption)) {
+ options.insert("in-new-window", true);
+ }
+ if(parser.isSet(newTabOption)) {
+ options.insert("in-new-tab", true);
+ }
+ options.insert("urls", parser.positionalArguments());
+
+ return options;
+}
+
+int main(int argc, char *argv[])
+{
+ // Create application object
+ Browser app(argc, argv);
+
+ // program init
+ {
+ // parse command line options
+ const QHash<QString, QVariant> options = parseCommandLine(app);
+
+ // Check for another instance unless specified not to
+ if(!options.contains("new-instance")) {
+ app.bindLocalSocket();
+ if(app.isRunning()) {
+ qDebug("Another instance is running, returning...");
+ app.sendMessage(options);
+ return 0;
+ }
+ }
- app.setWindowIcon(QIcon(QLatin1String(":/icon.svg")));
- // This lets the web view automatically scale on high-dpi displays.
- app.setAttribute(Qt::AA_EnableHighDpiScaling);
+ if(options.contains("print-defaults")) {
+ printPoiToml(std::cout);
+ return 0;
+ }
- // Set configuration
- app.loadSettings(parser.value(configOption));
+ app.setWindowIcon(QIcon(QLatin1String(":/icon.svg")));
+ // This lets the web view automatically scale on high-dpi displays.
+ app.setAttribute(Qt::AA_EnableHighDpiScaling);
- // Load profiles
- app.loadProfiles();
+ // Set configuration
+ app.loadSettings(options.value("config", "").toString());
- // Load plugins
-// if(!parser.isSet(nopluginsOption)) {
-// app.loadPlugins();
-// }
+ // Load profiles
+ app.loadProfiles();
- MainWindow *w = new MainWindow(parser.positionalArguments());
- if(parser.isSet(profileOption)) {
- w->setProfile(app.profile(parser.value(profileOption)));
+ // Load plugins
+ // if(!parser.isSet(nopluginsOption)) {
+ // app.loadPlugins();
+ // }
+
+ MainWindow *w = new MainWindow(options.value("urls").toStringList());
+ if(options.contains("profile")) {
+ w->setProfile(app.profile(options.value("profile").toString()));
+ }
+ app.addWindow(w);
}
- app.addWindow(w);
return app.exec();
}