From 30e6831bf859a8166b67132b51ca49a32ccd0bd5 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 11 Nov 2015 20:25:21 +0100 Subject: [PATCH] refs #507, launcher (new GUI) --- src/swiftlauncher/introwindow.cpp | 113 ----- src/swiftlauncher/introwindow.h | 51 -- src/swiftlauncher/introwindow.ui | 357 -------------- src/swiftlauncher/main.cpp | 81 ++- src/swiftlauncher/swiftlauncher.cpp | 342 +++++++++++++ src/swiftlauncher/swiftlauncher.h | 140 ++++++ src/swiftlauncher/swiftlauncher.pro | 3 +- src/swiftlauncher/swiftlauncher.qrc | 21 + src/swiftlauncher/swiftlauncher.ui | 734 ++++++++++++++++++++++++++++ 9 files changed, 1303 insertions(+), 539 deletions(-) delete mode 100644 src/swiftlauncher/introwindow.cpp delete mode 100644 src/swiftlauncher/introwindow.h delete mode 100644 src/swiftlauncher/introwindow.ui create mode 100644 src/swiftlauncher/swiftlauncher.cpp create mode 100644 src/swiftlauncher/swiftlauncher.h create mode 100644 src/swiftlauncher/swiftlauncher.qrc create mode 100644 src/swiftlauncher/swiftlauncher.ui diff --git a/src/swiftlauncher/introwindow.cpp b/src/swiftlauncher/introwindow.cpp deleted file mode 100644 index a7fe8b784..000000000 --- a/src/swiftlauncher/introwindow.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* Copyright (C) 2014 - * swift project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "introwindow.h" -#include "ui_introwindow.h" -#include "blackcore/dbus_server.h" -#include "blackcore/settingscache.h" -#include "blackmisc/network/networkutils.h" -#include "blackmisc/project.h" -#include -#include -#include -#include -#include - -using namespace BlackMisc; -using namespace BlackMisc::Network; -using namespace BlackCore; -using namespace BlackGui; - -/* - * Constructor - */ -CIntroWindow::CIntroWindow(QWidget *parent) : - QDialog(parent, (Qt::WindowStaysOnTopHint)), - // (Qt::Tool | Qt::WindowStaysOnTopHint)), - ui(new Ui::CIntroWindow) -{ - ui->setupUi(this); - this->setWindowTitle(CProject::versionStringDevBetaInfo()); - this->layout()->setSizeConstraint(QLayout::SetFixedSize); - this->ui->cb_DBusServer->addItem(CDBusServer::sessionDBusServer()); - this->ui->cb_DBusServer->addItem(CDBusServer::systemDBusServer()); - this->ui->cb_DBusServer->addItems(CNetworkUtils::getKnownIpAddresses()); - this->ui->cb_DBusServer->setCurrentIndex(0); -} - -/* - * Destructor - */ -CIntroWindow::~CIntroWindow() { } - -/* - * Window mode - */ -BlackGui::CEnableForFramelessWindow::WindowMode CIntroWindow::getWindowMode() const -{ - if (this->ui->rb_WindowFrameless->isChecked()) - return CEnableForFramelessWindow::WindowFrameless; - else - return CEnableForFramelessWindow::WindowTool; -} - -/* - * Core mode - */ -GuiModes::CoreMode CIntroWindow::getCoreMode() const -{ - if (this->ui->rb_CoreExternalVoiceLocal->isChecked()) - { - return GuiModes::CoreExternalAudioLocal; - } - else if (this->ui->rb_CoreInGuiProcess->isChecked()) - { - return GuiModes::CoreInGuiProcess; - } - else - { - return GuiModes::CoreExternal; - } -} - -/* - * DBus server address - */ -QString CIntroWindow::getDBusAddress() const -{ - return this->ui->cb_DBusServer->currentText(); -} - -/* - * Button clicked - */ -void CIntroWindow::buttonClicked() const -{ - QObject *sender = QObject::sender(); - if (sender == this->ui->pb_ModelDb) - { - QDesktopServices::openUrl(QUrl("http://vatrep.vatsim-germany.org/page/index.php", QUrl::TolerantMode)); - } - else if (sender == this->ui->pb_WebSite) - { - QDesktopServices::openUrl(QUrl("https://dev.vatsim-germany.org/", QUrl::TolerantMode)); - } - else if (sender == this->ui->pb_SettingsDir) - { - QString path(QDir::toNativeSeparators(CSettingsCache::persistentStore())); - QDesktopServices::openUrl(QUrl("file:///" + path)); - } - else if (sender == this->ui->pb_CoreStart) - { - //! \todo make fully OS independent - QString sfx = QFileInfo(QCoreApplication::applicationFilePath()).suffix(); - QString core = QDir(QApplication::applicationDirPath()).filePath("swiftcore." + sfx); - QProcess::startDetached(core); - } -} diff --git a/src/swiftlauncher/introwindow.h b/src/swiftlauncher/introwindow.h deleted file mode 100644 index 48d3fd0f3..000000000 --- a/src/swiftlauncher/introwindow.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Copyright (C) 2013 - * swift project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef STDGUI_INTROWINDOW_H -#define STDGUI_INTROWINDOW_H - -#include "swiftguistandard/guimodeenums.h" -#include "blackgui/enableforframelesswindow.h" -#include -#include - -namespace Ui { class CIntroWindow; } - -//! Intro screen -class CIntroWindow : public QDialog -{ - Q_OBJECT - -public: - //! Constructor - explicit CIntroWindow(QWidget *parent = nullptr); - - //! Destructor - ~CIntroWindow(); - - //! Selected window mode - BlackGui::CEnableForFramelessWindow::WindowMode getWindowMode() const; - - //! Get core mode - GuiModes::CoreMode getCoreMode() const; - - //! select DBus address/mode - QString getDBusAddress() const; - -private slots: - //! Button has been clicked - void buttonClicked() const; - -private: - QScopedPointer ui; -}; - -#endif // guard diff --git a/src/swiftlauncher/introwindow.ui b/src/swiftlauncher/introwindow.ui deleted file mode 100644 index 86cdd5386..000000000 --- a/src/swiftlauncher/introwindow.ui +++ /dev/null @@ -1,357 +0,0 @@ - - - CIntroWindow - - - - 0 - 0 - 250 - 300 - - - - swift intro screen - - - - :/blackgui/icons/aircraftdeparture.png:/blackgui/icons/aircraftdeparture.png - - - QWidget { - font-family: arial-rounded; - font: bold 10px; - color: yellow; /** font **/ - background-color: black; -} - -QPushButton { - background-color: rgba(255, 255, 0, 175); - color: black; - border-style: solid; - border-width:1px; - border-radius: 5px; - border-color: green; - margin: 3px; - padding: 3px; -} - -QRadioButton { - background-color: transparent; -} - -QGroupBox { - border: 2px solid yellow; - border-radius: 5px; - margin-top: 2ex; /* leave space at the top for the title */ -} - -QComboBox { - background-color: black; - border: 1px solid yellow; -} - - QGroupBox::title { - subcontrol-origin: margin; - subcontrol-position: top left; /* position at the top center */ - padding: 0 0px; - margin: 0px; - background-color: black; - } - -#lbl_Icon { - max-height: 128; - max-width: 128; -} - - - false - - - true - - - - - - 9 - - - 9 - - - 0 - - - 9 - - - 9 - - - - - Window - - - - - - Normal - - - true - - - - - - - Frameless - - - - - - - - - - Core - - - - - - Included in GUI -process - - - - - - - External (DBus) - - - true - - - - - - - External, -voice included - - - - - - - start core - - - - - - - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - 3 - - - 2 - - - 2 - - - 0 - - - 2 - - - - - Model DB - - - - - - - Web site - - - - - - - settings dir. - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - - DBus server - - - - - - - true - - - QComboBox::InsertAtTop - - - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - bb_OkCancel - accepted() - CIntroWindow - accept() - - - 240 - 290 - - - 157 - 274 - - - - - bb_OkCancel - rejected() - CIntroWindow - reject() - - - 240 - 290 - - - 286 - 274 - - - - - pb_ModelDb - clicked() - CIntroWindow - buttonClicked() - - - 217 - 34 - - - 319 - 37 - - - - - pb_WebSite - clicked() - CIntroWindow - buttonClicked() - - - 238 - 75 - - - 322 - 73 - - - - - pb_SettingsDir - clicked() - CIntroWindow - buttonClicked() - - - 197 - 97 - - - 86 - 250 - - - - - pb_CoreStart - clicked() - CIntroWindow - buttonClicked() - - - 90 - 194 - - - 0 - 218 - - - - - - buttonClicked() - - diff --git a/src/swiftlauncher/main.cpp b/src/swiftlauncher/main.cpp index c6c0bf888..f60f78609 100644 --- a/src/swiftlauncher/main.cpp +++ b/src/swiftlauncher/main.cpp @@ -8,7 +8,7 @@ */ #include "swiftguistandard/guimodeenums.h" -#include "introwindow.h" +#include "swiftlauncher.h" #include "blackcore/blackcorefreefunctions.h" #include "blackgui/guiutility.h" #include "blackmisc/blackmiscfreefunctions.h" @@ -27,28 +27,75 @@ using namespace BlackGui; using namespace BlackMisc; using namespace BlackCore; +enum CommandLineParseResult +{ + CommandLineOk, + CommandLineError, + CommandLineVersionRequested, + CommandLineHelpRequested +}; + +CommandLineParseResult parseCommandLine(QCommandLineParser &parser, bool &installer, QString &errorMessage) +{ + parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions); + parser.addOption({{"i", "installer"}, QCoreApplication::translate("main", "Installer setup.")}); + + QCommandLineOption helpOption = parser.addHelpOption(); + QCommandLineOption versionOption = parser.addVersionOption(); + + if (!parser.parse(QCoreApplication::arguments())) + { + errorMessage = parser.errorText(); + return CommandLineError; + } + + // help/version + if (parser.isSet(helpOption)) { return CommandLineHelpRequested; } + if (parser.isSet(versionOption)) { return CommandLineVersionRequested; } + + installer = parser.isSet("installer"); + return CommandLineOk; +} + int main(int argc, char *argv[]) { QApplication a(argc, argv); - CGuiUtility::initSwiftGuiApplication(a, "swiftgui", CIcons::swift24()); + const QString appName("swift launcher"); + a.setApplicationVersion(CProject::version()); + a.setApplicationName(appName); + CGuiUtility::initSwiftGuiApplication(a, appName, CIcons::swift24()); + + // Process the actual command line arguments given by the user + QCommandLineParser parser; + parser.setApplicationDescription(appName); + QString errorMessage; + bool installer = false; + switch (parseCommandLine(parser, installer, errorMessage)) + { + case CommandLineOk: + break; + case CommandLineError: + CGuiUtility::commandLineErrorMessage(errorMessage, parser); + return 1; + case CommandLineVersionRequested: + CGuiUtility::commandLineVersionRequested(); + return 0; + case CommandLineHelpRequested: + CGuiUtility::commandLineHelpRequested(parser); + return 0; + } // Dialog to decide external or internal core - CIntroWindow intro; - intro.setWindowIcon(CIcons::swift24()); - if (intro.exec() == QDialog::Rejected) { return 0; } + CSwiftLauncher launcher; + launcher.setWindowIcon(CIcons::swift24()); + if (launcher.exec() == QDialog::Rejected) { return 0; } + launcher.close(); - GuiModes::CoreMode coreMode = intro.getCoreMode(); - CEnableForFramelessWindow::WindowMode windowMode = intro.getWindowMode(); - QString dBusAddress(intro.getDBusAddress()); - intro.close(); - - QString args(" --core %1 --dbus %2 --window %3"); - QString exe = QDir::currentPath() + "/swiftguistd.exe" + - args.arg(GuiModes::coreModeToString(coreMode)).arg(dBusAddress).arg(CEnableForFramelessWindow::windowModeToString(windowMode)); - QProcess *process = new QProcess(QCoreApplication::instance()); - Q_ASSERT_X(process, Q_FUNC_INFO, "Cannot start process"); - Q_UNUSED(process); - process->startDetached(exe); + QString exe(launcher.getExecutable()); + QStringList exeArgs(launcher.getExecutableArgs()); + Q_ASSERT_X(!exe.isEmpty(), Q_FUNC_INFO, "Missing executable"); + CLogMessage(QCoreApplication::instance()).debug() << launcher.getCmdLine(); + QProcess::startDetached(exe, exeArgs); return 0; } diff --git a/src/swiftlauncher/swiftlauncher.cpp b/src/swiftlauncher/swiftlauncher.cpp new file mode 100644 index 000000000..bd2723a87 --- /dev/null +++ b/src/swiftlauncher/swiftlauncher.cpp @@ -0,0 +1,342 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "swiftlauncher.h" +#include "ui_swiftlauncher.h" +#include "blackgui/stylesheetutility.h" +#include "blackcore/dbus_server.h" +#include "blackcore/data/download.h" +#include "blackmisc/network/networkutils.h" +#include "blackmisc/icons.h" +#include "blackmisc/project.h" +#include "blackmisc/logmessage.h" +#include "blackmisc/loghandler.h" +#include +#include +#include +#include +#include +#include +#include + +using namespace BlackGui; +using namespace BlackCore; +using namespace BlackCore::Data; +using namespace BlackMisc; +using namespace BlackMisc::Network; + +CSwiftLauncher::CSwiftLauncher(QWidget *parent) : + QDialog(parent, CEnableForFramelessWindow::modeToWindowFlags(CEnableForFramelessWindow::WindowNormal)), + CEnableForFramelessWindow(CEnableForFramelessWindow::WindowFrameless, true, "framelessMainWindow", this), + ui(new Ui::CSwiftLauncher) +{ + ui->setupUi(this); + this->setWindowTitle(QCoreApplication::instance()->applicationName() + " " + CProject::versionStringDevBetaInfo()); + this->init(); + connect(ui->pb_CheckForUpdates, &QPushButton::pressed, this, &CSwiftLauncher::ps_loadSetup); + connect(ui->tb_SwiftCore, &QPushButton::pressed, this, &CSwiftLauncher::ps_startButtonPressed); + connect(ui->tb_SwiftData, &QPushButton::pressed, this, &CSwiftLauncher::ps_startButtonPressed); + connect(ui->tb_SwiftGui, &QPushButton::pressed, this, &CSwiftLauncher::ps_startButtonPressed); + connect(ui->tb_Database, &QPushButton::pressed, this, &CSwiftLauncher::ps_startButtonPressed); + connect(ui->tb_BackToMain, &QToolButton::pressed, this, &CSwiftLauncher::ps_showMainPage); + + new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_L), this, SLOT(ps_showLogPage())); + this->ui->le_DBusServerPort->setValidator(new QIntValidator(0, 65535, this)); + QTimer::singleShot(5000, this, &CSwiftLauncher::ps_loadedSetup); //deferred init of setup +} + +CSwiftLauncher::~CSwiftLauncher() +{ } + +QString CSwiftLauncher::getCmdLine() const +{ + return toCmdLine(this->m_executable, this->m_executableArgs); +} + +CEnableForFramelessWindow::WindowMode CSwiftLauncher::getWindowMode() const +{ + if (ui->rb_WindowFrameless->isChecked()) { return CEnableForFramelessWindow::WindowFrameless; } + return CEnableForFramelessWindow::WindowNormal; +} + +GuiModes::CoreMode CSwiftLauncher::getCoreMode() const +{ + if (ui->rb_SwiftStandalone->isChecked()) { return GuiModes::CoreInGuiProcess; } + if (ui->rb_SwiftCoreAudio->isChecked()) { return GuiModes::CoreExternalCoreAudio; } + if (ui->rb_SwiftCoreGuiAudio->isChecked()) { return GuiModes::CoreExternalAudioGui; } + + Q_ASSERT_X(false, Q_FUNC_INFO, "wrong mode"); + return GuiModes::CoreInGuiProcess; +} + +QString CSwiftLauncher::getDBusAddress() const +{ + if (this->ui->rb_DBusSession->isChecked()) { return CDBusServer::sessionDBusServer(); } + if (this->ui->rb_DBusSystem->isChecked()) { return CDBusServer::systemDBusServer(); } + return CDBusServer::fixAddressToDBusAddress( + this->ui->cb_DBusServerAddress->currentText() + ":" + + this->ui->le_DBusServerPort->text()); +} + +void CSwiftLauncher::mouseMoveEvent(QMouseEvent *event) +{ + if (!handleMouseMoveEvent(event)) { QDialog::mouseMoveEvent(event); } +} + +void CSwiftLauncher::mousePressEvent(QMouseEvent *event) +{ + if (!handleMousePressEvent(event)) { QDialog::mousePressEvent(event); } +} + +void CSwiftLauncher::init() +{ + this->ui->lbl_NewVersionUrl->setTextFormat(Qt::RichText); + this->ui->lbl_NewVersionUrl->setTextInteractionFlags(Qt::TextBrowserInteraction); + this->ui->lbl_NewVersionUrl->setOpenExternalLinks(true); + + this->ui->wi_NewVersionAvailable->setVisible(false); + this->ui->wi_NoNewVersion->setVisible(true); + + this->initStyleSheet(); + this->initLogDisplay(); + this->initDBusGui(); + this->initVersion(); +} + +void CSwiftLauncher::initStyleSheet() +{ + const QString s = CStyleSheetUtility::instance().styles( + { + CStyleSheetUtility::fileNameFonts(), + CStyleSheetUtility::fileNameStandardWidget(), + CStyleSheetUtility::fileNameSwiftLauncher() + } + ); + this->setStyleSheet(s); +} + +void CSwiftLauncher::displayLatestNews() +{ + CUrlList newsUrls(this->m_setup.get().swiftLatestNewsUrls()); + QUrl newUrl(newsUrls.getNextUrl()); + + Q_UNUSED(newUrl); + /** Qt bug + QWebEngineView *view = new QWebEngineView(this->ui->pg_LatestNews); + if (view->url() != newUrl) + { + view->load(newUrl)); + } + view->show(); + **/ + +} + +void CSwiftLauncher::initDBusGui() +{ + this->ui->cb_DBusServerAddress->addItem("127.0.0.1"); + this->ui->cb_DBusServerAddress->addItems(CNetworkUtils::getKnownIpAddresses()); + this->ui->cb_DBusServerAddress->setCurrentIndex(0); + + connect(ui->cb_DBusServerAddress, &QComboBox::currentTextChanged, this, &CSwiftLauncher::ps_dbusServerAddressSelectionChanged); + connect(ui->rb_DBusP2P, &QRadioButton::clicked, this, &CSwiftLauncher::ps_dbusServerModeSelected); + connect(ui->rb_DBusSession, &QRadioButton::clicked, this, &CSwiftLauncher::ps_dbusServerModeSelected); + connect(ui->rb_DBusSystem, &QRadioButton::clicked, this, &CSwiftLauncher::ps_dbusServerModeSelected); +} + +void CSwiftLauncher::initVersion() +{ + this->ui->le_CurrentVersion->setText(CProject::versionStringDevBetaInfo()); +} + +void CSwiftLauncher::initLogDisplay() +{ + CLogHandler::instance()->install(true); + CLogHandler::instance()->enableConsoleOutput(false); // default disable + auto logHandler = CLogHandler::instance()->handlerForPattern( + CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityInfo) + ); + logHandler->subscribe(this, &CSwiftLauncher::ps_appendLogMessage); +} + +void CSwiftLauncher::startSwiftCore() +{ + QStringList args( + { + "--start", + "--dbus", this->getDBusAddress() + }); + + if (this->ui->rb_SwiftCoreAudio->isChecked()) + { + args.append("--coreaudio"); + } + + // I set this for debug purpose only + this->m_executableArgs = args; + this->m_executable = CProject::swiftCoreExecutableName(); + CLogMessage(this).debug() << this->getCmdLine(); + + // start + QProcess::startDetached(this->m_executable, this->m_executableArgs); +} + +void CSwiftLauncher::setSwiftDataExecutable() +{ + m_executable = CProject::swiftDataExecutableName(); + m_executableArgs.clear(); +} + +bool CSwiftLauncher::setSwiftGuiExecutable() +{ + QString msg; + if (this->isStandaloneGuiSelected() || this->canConnectDBusServer(msg)) + { + + m_executable = CProject::swiftGuiExecutableName(); + QStringList args + { + "--core", GuiModes::coreModeToString(getCoreMode()), + "--window", CEnableForFramelessWindow::windowModeToString(getWindowMode()) + }; + if (!this->isStandaloneGuiSelected()) + { + args.append("--dbus"); + args.append(getDBusAddress()); // already converted + } + m_executableArgs = args; + return true; + } + else + { + m_executable = CProject::swiftGuiExecutableName(); + m_executableArgs.clear(); + static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation() })); + CStatusMessage m(cats, CStatusMessage::SeverityError, + "DBus server for " + getDBusAddress() + " can not be connected: " + msg); + this->ps_showStatusMessage(m); + return false; + } +} + +bool CSwiftLauncher::canConnectDBusServer(QString &msg) const +{ + if (this->isStandaloneGuiSelected()) { return true; } // do not mind here + return CDBusServer::isDBusAvailable(getDBusAddress(), msg); +} + +bool CSwiftLauncher::isStandaloneGuiSelected() const +{ + return this->ui->rb_SwiftStandalone->isChecked(); +} + +QString CSwiftLauncher::toCmdLine(const QString &exe, const QStringList &exeArgs) +{ + if (exeArgs.isEmpty()) { return exe; } + QString cmd(exe); + for (const QString &a : exeArgs) + { + cmd = cmd.append(" ").append(a); + } + return cmd; +} + +void CSwiftLauncher::ps_loadSetup() +{ + CSetupReader::instance().requestReload(); +} + +void CSwiftLauncher::ps_loadedSetup() +{ + CDownload download(this->m_download.get()); + QString latestVersion(download.getLatestVersion()) ; // need to get this from somewhere + CUrlList downloadUrls(download.getDownloadUrls()); + bool newVersionAvailable = CProject::isNewerVersion(latestVersion) && !downloadUrls.isEmpty(); + this->ui->wi_NewVersionAvailable->setVisible(newVersionAvailable); + this->ui->wi_NoNewVersion->setVisible(!newVersionAvailable); + this->ui->le_LatestVersion->setText(latestVersion); + + if (!downloadUrls.isEmpty()) + { + CUrl downloadUrl(downloadUrls.getNextUrl()); + QString urlStr(downloadUrl.toQString()); + QString hl("%2 %3"); + this->ui->lbl_NewVersionUrl->setText(hl.arg(urlStr).arg(urlStr).arg(latestVersion)); + } + + this->displayLatestNews(); +} + +void CSwiftLauncher::ps_startButtonPressed() +{ + QObject *sender = QObject::sender(); + if (sender == this->ui->tb_SwiftGui) + { + if (this->setSwiftGuiExecutable()) + { + this->accept(); + } + } + else if (sender == this->ui->tb_SwiftData) + { + this->setSwiftDataExecutable(); + this->accept(); + } + else if (sender == this->ui->tb_SwiftCore) + { + if (this->isStandaloneGuiSelected()) { this->ui->rb_SwiftCoreGuiAudio->setChecked(true); } + this->startSwiftCore(); + } + else if (sender == this->ui->tb_Database) + { + CUrl homePage(this->m_setup.get().dbHomePageUrl()); + QDesktopServices::openUrl(homePage); + } +} + +void CSwiftLauncher::ps_dbusServerAddressSelectionChanged(const QString ¤tText) +{ + Q_UNUSED(currentText); + if (this->isStandaloneGuiSelected()) + { + this->ui->rb_SwiftCoreGuiAudio->setChecked(true); + } + this->ui->rb_DBusP2P->setChecked(true); +} + +void CSwiftLauncher::ps_dbusServerModeSelected(bool selected) +{ + if (!selected) { return; } + if (!this->isStandaloneGuiSelected()) { return; } + this->ui->rb_SwiftCoreGuiAudio->setChecked(true); +} + +void CSwiftLauncher::ps_showStatusMessage(const CStatusMessage &msg) +{ + this->ui->fr_SwiftLauncherMain->showMessage(msg, 5000); +} + +void CSwiftLauncher::ps_appendLogMessage(const CStatusMessage &message) +{ + ui->fr_SwiftLauncherLog->appendStatusMessageToList(message); + if (message.getSeverity() == CStatusMessage::SeverityError) + { + this->ps_showStatusMessage(message); + } +} + +void CSwiftLauncher::ps_showMainPage() +{ + this->ui->sw_SwiftLauncher->setCurrentWidget(this->ui->pg_SwiftLauncherMain); +} + +void CSwiftLauncher::ps_showLogPage() +{ + this->ui->sw_SwiftLauncher->setCurrentWidget(this->ui->pg_SwiftLauncherLog); +} diff --git a/src/swiftlauncher/swiftlauncher.h b/src/swiftlauncher/swiftlauncher.h new file mode 100644 index 000000000..a7000e3c3 --- /dev/null +++ b/src/swiftlauncher/swiftlauncher.h @@ -0,0 +1,140 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef SWIFTLAUNCHER_H +#define SWIFTLAUNCHER_H + +#include +#include +#include "blackcore/setupreader.h" +#include "blackgui/enableforframelesswindow.h" +#include "blackgui/overlaymessagesframe.h" +#include "swiftguistandard/guimodeenums.h" + +namespace Ui { class CSwiftLauncher; } + +/*! + * swift launcher tool + * \note Besides the fact the launcher makes it easy to start our applications it also pre-fetches some + * cache files, hence reducing load times in the subsequent applications. Therefor starting via the launcher + * is preferable, but not mandatory. + */ +class CSwiftLauncher : + public QDialog, + public BlackGui::CEnableForFramelessWindow +{ + Q_OBJECT + +public: + //! Constructor + explicit CSwiftLauncher(QWidget *parent = nullptr); + + //! Destructor + ~CSwiftLauncher(); + + //! Executable + const QString &getExecutable() const { return m_executable; } + + //! Arguments + const QStringList &getExecutableArgs() const { return m_executableArgs; } + + //! Current command line + QString getCmdLine() const; + +protected: + //! \copydoc QDialog::mousePressEvent + virtual void mousePressEvent(QMouseEvent *event) override; + + //! \copydoc QDialog::mouseMoveEvent + void mouseMoveEvent(QMouseEvent *event); + +private: + QScopedPointer ui; + BlackCore::CData m_setup { this, &CSwiftLauncher::ps_loadedSetup }; //!< setup cache + BlackCore::CData m_download { this, &CSwiftLauncher::ps_loadedSetup }; + QString m_executable; + QStringList m_executableArgs; + + //! Get core mode + GuiModes::CoreMode getCoreMode() const; + + //! select DBus address/mode + QString getDBusAddress() const; + + //! Selected window mode + BlackGui::CEnableForFramelessWindow::WindowMode getWindowMode() const; + + //! Init + void init(); + + //! style sheets + void initStyleSheet(); + + //! combobox for DBus + void initDBusGui(); + + //! Version string + void initVersion(); + + //! Log display + void initLogDisplay(); + + //! latest news + void displayLatestNews(); + + //! Start the core + void startSwiftCore(); + + //! Set executable for swift data + void setSwiftDataExecutable(); + + //! Set executable for swift GUI + bool setSwiftGuiExecutable(); + + //! Can DBus server be connected + bool canConnectDBusServer(QString &msg) const; + + //! Standalone GUI selected + bool isStandaloneGuiSelected() const; + + //! Command line + static QString toCmdLine(const QString &exe, const QStringList &exeArgs); + +private slots: + //! Load latest version + void ps_loadSetup(); + + //! Loaded latest version + void ps_loadedSetup(); + + //! Start button pressed + void ps_startButtonPressed(); + + //! Changed selection + void ps_dbusServerAddressSelectionChanged(const QString ¤tText); + + //! DBus server mode selected + void ps_dbusServerModeSelected(bool selected); + + //! Display status message as overlay + void ps_showStatusMessage(const BlackMisc::CStatusMessage &msg); + + //! Append status message + void ps_appendLogMessage(const BlackMisc::CStatusMessage &message); + + //! Show set main page + void ps_showMainPage(); + + //! Show the log page + void ps_showLogPage(); +}; + +#endif // guard diff --git a/src/swiftlauncher/swiftlauncher.pro b/src/swiftlauncher/swiftlauncher.pro index 3062893da..ac477a4e8 100644 --- a/src/swiftlauncher/swiftlauncher.pro +++ b/src/swiftlauncher/swiftlauncher.pro @@ -1,6 +1,6 @@ load(common_pre) -QT += core dbus gui svg network xml multimedia +QT += core dbus gui svg network xml multimedia webenginewidgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets @@ -29,6 +29,7 @@ DEPENDPATH += . $$SourceRoot/src/blackmisc \ INCLUDEPATH += . $$SourceRoot/src OTHER_FILES += *.qss *.ico *.rc +RESOURCES += swiftlauncher.qrc RC_FILE = swift.rc DISTFILES += swift.rc diff --git a/src/swiftlauncher/swiftlauncher.qrc b/src/swiftlauncher/swiftlauncher.qrc new file mode 100644 index 000000000..515ac078c --- /dev/null +++ b/src/swiftlauncher/swiftlauncher.qrc @@ -0,0 +1,21 @@ + + + icons/swift256Launcher.png + icons/swift256Launcher.xcf + icons/swiftFrameless.png + icons/swiftNormal.png + icons/swiftFrameless100x162.png + icons/swiftFrameless125x203.png + icons/swiftFrameless200x325.png + icons/swiftNormal100x165.png + icons/swiftNormal125x206.png + icons/swiftNormal200x329.png + icons/swiftHeader325x65.png + icons/swiftGUIandCore130x100.png + icons/swiftGUIandCore215x165.png + icons/swiftCore110x100.png + icons/swiftGUIandCore115x85.png + icons/swiftNormal61x100.png + icons/swiftNormal115x189.png + + diff --git a/src/swiftlauncher/swiftlauncher.ui b/src/swiftlauncher/swiftlauncher.ui new file mode 100644 index 000000000..3c16f4ac4 --- /dev/null +++ b/src/swiftlauncher/swiftlauncher.ui @@ -0,0 +1,734 @@ + + + CSwiftLauncher + + + + 0 + 0 + 365 + 625 + + + + swift launcher + + + + 4 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 25 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + 6 + + + + + 0 + 0 + 355 + 306 + + + + Latest news + + + + + + + 0 + 0 + 355 + 306 + + + + Window type + + + + + + Frameless + + + + + + + Normal window + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + :/launcher/icons/swiftFrameless125x203.png + + + + + + + + + + :/launcher/icons/swiftNormal125x206.png + + + + + + + + + 0 + 0 + 355 + 306 + + + + Core mode + + + + 4 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + DBus + + + + 4 + + + 4 + + + 4 + + + 0 + + + 4 + + + + + DBus session server + + + true + + + + + + + DBus system server + + + + + + + DBus peer to peer server (P2P) + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 20 + + + 0 + + + 20 + + + 0 + + + + + + 0 + 0 + + + + true + + + + + + + Address: + + + Qt::LinksAccessibleByMouse + + + + + + + Port: + + + + + + + + 80 + 16777215 + + + + 45000 + + + 5 + + + + + + + + + + + + + GUI and core + + + bg_CoreMode + + + + + + + + + + :/launcher/icons/swiftGUIandCore115x85.png + + + + + + + GUI and core + + + bg_CoreMode + + + + + + + + + + :/launcher/icons/swiftGUIandCore115x85.png + + + + + + + standalone + + + true + + + bg_CoreMode + + + + + + + Audio on GUI side + + + + + + + + + + :/launcher/icons/swiftNormal61x100.png + + + + + + + Audio on core side + + + + + + + + + 0 + 0 + 355 + 306 + + + + Check for updates + + + + + + + + + You are running the latest version! + + + + + + + + + + + + + A new version is available here: + + + + + + + http://www.foobar.com + + + + + + + + + + true + + + + + + + Latest version: + + + + + + + This version: + + + + + + + check for updates + + + + + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + 0 + 0 + 355 + 306 + + + + Credits and License + + + + + + true + + + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Credits will go here</p></body></html> + + + + + + + + + + + + 0 + 0 + + + + + 0 + 140 + + + + 0 + + + + + 0 + 0 + 355 + 113 + + + + Start application + + + + + + mapping tool + + + + + + + goto swift DB + + + + + + + start swift core + + + swift core + + + + :/own/icons/own/swift/swiftNova64.png:/own/icons/own/swift/swiftNova64.png + + + + 64 + 64 + + + + + + + + start swift GUI + + + swift GUI + + + + :/own/icons/own/swift/swift64.png:/own/icons/own/swift/swift64.png + + + + 64 + 64 + + + + + + + + open browser for swift database + + + goto swift database + + + + :/own/icons/own/swift/swift64Database.png:/own/icons/own/swift/swift64Database.png + + + + 64 + 64 + + + + + + + + start swift data (the mapping tool) + + + mapping tool + + + + :/own/icons/own/swift/swift64Database.png:/own/icons/own/swift/swift64Database.png + + + + 64 + 64 + + + + + + + + GUI + + + + + + + core + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 25 + 20 + + + + + + + + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + back to main + + + + :/diagona/icons/diagona/icons/arrow-180.png:/diagona/icons/diagona/icons/arrow-180.png + + + Ctrl+M + + + + + + + + + + + + BlackGui::COverlayMessagesFrame + QFrame +
blackgui/overlaymessagesframe.h
+ 1 +
+ + BlackGui::Components::CLogComponent + QFrame +
blackgui/components/logcomponent.h
+ 1 +
+
+ + + + + + + + +