diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-04-16 17:07:36 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-04-16 17:07:36 +0200 |
commit | d796821f8304306dbe088701724243b39e8eb358 (patch) | |
tree | 836c85aa421db5c495e2b36f6a02cea924b6d919 /src/main.cpp | |
parent | Branch of Qt5.11 features (diff) | |
download | smolbote-d796821f8304306dbe088701724243b39e8eb358.tar.xz |
Multiple subwindows interface
Subwindows are similar to tab groups.
- Rewrote Browser and MainWindow, so they should be somewhat cleaner now
- Moved AboutDialog to lib/about
What's broken:
- loading bar
- search box
- address bar bookmark suggestions
- plugins
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 83 |
1 files changed, 27 insertions, 56 deletions
diff --git a/src/main.cpp b/src/main.cpp index 75691f9..9fd009b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,47 +6,24 @@ * SPDX-License-Identifier: GPL-3.0 */ -#include "browser.h" #include "commandline.h" #include "mainwindow/mainwindow.h" #include "version.h" -#include <iomanip> -#include <iostream> -#include "configuration/configuration.h" -// startup time measuring -#ifdef QT_DEBUG -#include <QElapsedTimer> -#endif +#include "webengine/webprofile.h" +#include "browser.h" +#include <configuration/configuration.h> +#include <memory> int main(int argc, char **argv) { - // Create application object - Browser instance(argc, argv); - instance.setApplicationVersion(SMOLBOTE_VERSION); - -#ifdef QT_DEBUG - QElapsedTimer timer; - timer.start(); -#endif + Browser app(argc, argv); CommandLine parser; - parser.parseCommandLine(instance); - -#ifdef QT_DEBUG - qDebug("config=%s", qUtf8Printable(parser.value(parser.configOption))); - qDebug("profile=%s", qUtf8Printable(parser.value(parser.profileOption))); - qDebug("socket=%s", qUtf8Printable(parser.value(parser.socketOption))); - -#endif + parser.parseCommandLine(app); + // create and load configuration std::shared_ptr<Configuration> config = std::make_shared<Configuration>(); - - // load user configuration - if(!parser.value(parser.configOption).isEmpty()) { - qDebug("Reading configuration [%s]: %s", - qUtf8Printable(parser.value(parser.configOption)), - config->read(parser.value(parser.configOption)) ? "ok" : "failed"); - } + config->read(parser.value(parser.configOption)); // parse command-line overrides // we assume the users knows what they're doing, so we only pass the unknown options to program_options @@ -59,43 +36,37 @@ int main(int argc, char **argv) const char *_argv[_argc]; // program_options requires 0 to be the program name, otherwise it seems to fail - _argv[0] = qUtf8Printable(instance.arguments().at(0)); + _argv[0] = qUtf8Printable(app.arguments().at(0)); for(int i = 1; i < _argc; ++i) { _argv[i] = qUtf8Printable(QString("--%1=%2").arg(parser.unknownOptions[i - 1].names().at(0), parser.value(parser.unknownOptions[i - 1]))); } - qDebug("Parsing command-line overrides: %s", config->parse(_argc, _argv) ? "ok" : "failed"); + config->parse(_argc, _argv); } - // check for other instances - bool isSingleInstance = instance.bindLocalSocket(parser.value(parser.socketOption)); - if(isSingleInstance) { - qDebug("Bound to local socket %s", qUtf8Printable(instance.serverName())); - instance.setConfiguration(config); - } + app.setConfiguration(config); + + // set up socket + bool isSingleInstance = app.bindLocalSocket(parser.value(parser.socketOption)); +#ifdef QT_DEBUG + qDebug("bindLocalSocket(%s) = %s", qUtf8Printable(parser.value(parser.socketOption)), isSingleInstance ? "true" : "false"); +#endif - // create session - { - QString profile; + // if we are the only instance, set up the browser + if(isSingleInstance) { if(parser.isSet(parser.profileOption)) - profile = parser.value(parser.profileOption); + app.setup(parser.value(parser.profileOption)); else - profile = QString::fromStdString(config->value<std::string>("browser.profile").value()); + app.setup(QString::fromStdString(config->value<std::string>("profile.default").value())); - instance.sendMessage(profile, parser.isSet(parser.newWindowOption), parser.positionalArguments()); + QObject::connect(&app, &Browser::messageAvailable, &app, &Browser::createSession); } - if(!isSingleInstance) { - return 0; - } - -#ifdef QT_DEBUG - qDebug("Startup complete in %lldms", timer.elapsed()); -#endif + app.sendMessage(parser.value(parser.profileOption), parser.isSet(parser.newWindowOption), parser.positionalArguments()); - // Normally we'd use - //return instance.exec(); - // but, Call to "exec" is ambiguous - return static_cast<QApplication *>(&instance)->exec(); + if(isSingleInstance) + return app.exec(); + else + return 0; } |