diff --git a/src/swiftlauncher/swiftlauncher.cpp b/src/swiftlauncher/swiftlauncher.cpp index 2f2e50bb4..809addb11 100644 --- a/src/swiftlauncher/swiftlauncher.cpp +++ b/src/swiftlauncher/swiftlauncher.cpp @@ -12,6 +12,7 @@ #include "blackconfig/buildconfig.h" #include "blackgui/guiapplication.h" #include "blackgui/stylesheetutility.h" +#include "blackcore/context/contextapplicationproxy.h" #include "blackcore/setupreader.h" #include "blackmisc/dbusserver.h" #include "blackmisc/network/networkutils.h" @@ -29,6 +30,8 @@ using namespace BlackConfig; using namespace BlackGui; using namespace BlackCore; +using namespace BlackCore::Application; +using namespace BlackCore::Context; using namespace BlackCore::Data; using namespace BlackMisc; using namespace BlackMisc::Network; @@ -36,6 +39,7 @@ using namespace BlackMisc::Network; CSwiftLauncher::CSwiftLauncher(QWidget *parent) : QDialog(parent, CEnableForFramelessWindow::modeToWindowFlags(CEnableForFramelessWindow::WindowNormal)), CEnableForFramelessWindow(CEnableForFramelessWindow::WindowFrameless, true, "framelessMainWindow", this), + CIdentifiable(this), ui(new Ui::CSwiftLauncher) { ui->setupUi(this); @@ -60,16 +64,14 @@ CSwiftLauncher::CSwiftLauncher(QWidget *parent) : ui->le_DBusServerPort->setValidator(new QIntValidator(0, 65535, this)); // default from settings - const QString dbus(m_dbusServerAddress.getThreadLocal()); - this->setDefault(dbus); + this->setDefaults(); // periodically check - connect(&m_checkTimer, &QTimer::timeout, this, &CSwiftLauncher::ps_checkRunningApplications); - m_checkTimer.setInterval(5000); + connect(&m_checkTimer, &QTimer::timeout, this, &CSwiftLauncher::ps_checkRunningApplicationsAndCore); + m_checkTimer.setInterval(2500); m_checkTimer.start(); } - CSwiftLauncher::~CSwiftLauncher() { } @@ -87,8 +89,8 @@ CEnableForFramelessWindow::WindowMode CSwiftLauncher::getWindowMode() const CoreModes::CoreMode CSwiftLauncher::getCoreMode() const { if (ui->rb_SwiftStandalone->isChecked()) { return CoreModes::CoreInGuiProcess; } - if (ui->rb_SwiftCoreAudio->isChecked()) { return CoreModes::CoreExternalCoreAudio; } - if (ui->rb_SwiftCoreGuiAudio->isChecked()) { return CoreModes::CoreExternalAudioGui; } + if (ui->rb_SwiftCoreAudioOnCore->isChecked()) { return CoreModes::CoreExternalCoreAudio; } + if (ui->rb_SwiftCoreAudioOnGui->isChecked()) { return CoreModes::CoreExternalAudioGui; } Q_ASSERT_X(false, Q_FUNC_INFO, "wrong mode"); return CoreModes::CoreInGuiProcess; @@ -199,6 +201,12 @@ void CSwiftLauncher::initDBusGui() 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); + + // normally no system Bus on Windows + if (CBuildConfig::isRunningOnWindowsNtPlatform() && CBuildConfig::isShippedVersion()) + { + ui->rb_DBusSystem->setEnabled(false); + } } void CSwiftLauncher::initVersion() @@ -218,15 +226,16 @@ void CSwiftLauncher::initLogDisplay() void CSwiftLauncher::startSwiftCore() { + this->saveSetup(); const QString dBus(this->getDBusAddress()); - m_dbusServerAddress.setAndSave(dBus); + QStringList args( { "--start", "--dbus", dBus }); - if (ui->rb_SwiftCoreAudio->isChecked()) + if (ui->rb_SwiftCoreAudioOnCore->isChecked()) { args.append("--coreaudio"); } @@ -252,44 +261,43 @@ void CSwiftLauncher::setSwiftDataExecutable() bool CSwiftLauncher::setSwiftGuiExecutable() { - QString msg; - if (this->isStandaloneGuiSelected() || this->canConnectDBusServer(msg)) + m_executable.clear(); + if (CBuildConfig::isRunningOnUnixPlatform()) { m_executable += "./"; } + m_executable += CBuildConfig::swiftGuiExecutableName(); + QStringList args { - m_executable.clear(); - if (CBuildConfig::isRunningOnUnixPlatform()) { m_executable += "./"; } - m_executable += CBuildConfig::swiftGuiExecutableName(); - QStringList args - { - "--core", CoreModes::coreModeToString(getCoreMode()), - "--window", CEnableForFramelessWindow::windowModeToString(getWindowMode()) - }; - if (!this->isStandaloneGuiSelected()) - { - const QString dBus(this->getDBusAddress()); - m_dbusServerAddress.setAndSave(dBus); + "--core", CoreModes::coreModeToString(getCoreMode()), + "--window", CEnableForFramelessWindow::windowModeToString(getWindowMode()) + }; - args.append("--dbus"); - args.append(dBus); // already converted - } - m_executableArgs = args; - return true; - } - else + this->saveSetup(); + if (!this->isStandaloneGuiSelected()) { - m_executable = CBuildConfig::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; + const QString dBus(this->getDBusAddress()); + this->saveSetup(); + args.append("--dbus"); + args.append(dBus); // already converted + + QString msg; + if (!CSwiftLauncher::canConnectSwiftOnDBusServer(dBus, msg)) + { + static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation() })); + const CStatusMessage m(cats, CStatusMessage::SeverityError, + "DBus server for '" + this->getDBusAddress() + "' can not be connected.\n\n" + + "Likely the core is not running or is not reachable.\n\n" + + "Details: " + msg); + this->ps_showStatusMessage(m); + return false; + } } + m_executableArgs = args; + return true; } -bool CSwiftLauncher::canConnectDBusServer(QString &msg) const +bool CSwiftLauncher::canConnectSwiftOnDBusServer(const QString &dBusAddress, QString &msg) const { if (this->isStandaloneGuiSelected()) { return true; } // do not mind here - return CDBusServer::isDBusAvailable(getDBusAddress(), msg); + return CContextApplicationProxy::isContextResponsive(dBusAddress, msg); } bool CSwiftLauncher::isStandaloneGuiSelected() const @@ -297,14 +305,15 @@ bool CSwiftLauncher::isStandaloneGuiSelected() const return ui->rb_SwiftStandalone->isChecked(); } -void CSwiftLauncher::setDefault(const QString &value) +void CSwiftLauncher::setDefaults() { - QString v(value.toLower().trimmed()); - if (v.isEmpty() || v.startsWith("session")) + const CLauncherSetup setup(m_setup.get()); + const QString dbus(setup.getDBusAddress().toLower().trimmed()); + if (dbus.isEmpty() || dbus.startsWith("session")) { ui->rb_DBusSession->setChecked(true); } - else if (v.startsWith("sys")) + else if (dbus.startsWith("sys")) { ui->rb_DBusSystem->setChecked(true); } @@ -312,6 +321,40 @@ void CSwiftLauncher::setDefault(const QString &value) { ui->rb_DBusP2P->setChecked(true); } + if (setup.useFramelessWindow()) + { + ui->rb_WindowFrameless->setChecked(true); + } + else + { + ui->rb_WindowNormal->setChecked(true); + } + switch (setup.getCoreMode()) + { + case CLauncherSetup::Standalone: ui->rb_SwiftStandalone->setChecked(true); break; + case CLauncherSetup::CoreWithAudioOnCore: ui->rb_SwiftCoreAudioOnCore->setChecked(true); break; + case CLauncherSetup::CoreWithAudioOnGui: ui->rb_SwiftCoreAudioOnGui->setChecked(true); break; + default: + break; + } +} + +void CSwiftLauncher::saveSetup() +{ + CLauncherSetup setup = m_setup.get(); + const QString dBus(this->getDBusAddress()); + if (!dBus.isEmpty()) { setup.setDBusAddress(dBus); } + setup.setFramelessWindow(ui->rb_WindowFrameless->isChecked()); + setup.setCoreMode(CLauncherSetup::Standalone); + if (ui->rb_SwiftCoreAudioOnCore->isChecked()) + { + setup.setCoreMode(CLauncherSetup::CoreWithAudioOnCore); + } + else if (ui->rb_SwiftCoreAudioOnGui->isChecked()) + { + setup.setCoreMode(CLauncherSetup::CoreWithAudioOnGui); + } + m_setup.set(setup); } QString CSwiftLauncher::toCmdLine(const QString &exe, const QStringList &exeArgs) @@ -393,7 +436,7 @@ void CSwiftLauncher::ps_startButtonPressed() } else if (sender == ui->tb_SwiftCore) { - if (this->isStandaloneGuiSelected()) { ui->rb_SwiftCoreGuiAudio->setChecked(true); } + if (this->isStandaloneGuiSelected()) { ui->rb_SwiftCoreAudioOnGui->setChecked(true); } ui->tb_SwiftCore->setEnabled(false); m_startCoreWaitCycles = 2; this->startSwiftCore(); @@ -410,7 +453,7 @@ void CSwiftLauncher::ps_dbusServerAddressSelectionChanged(const QString ¤t Q_UNUSED(currentText); if (this->isStandaloneGuiSelected()) { - ui->rb_SwiftCoreGuiAudio->setChecked(true); + ui->rb_SwiftCoreAudioOnGui->setChecked(true); } ui->rb_DBusP2P->setChecked(true); } @@ -419,7 +462,7 @@ void CSwiftLauncher::ps_dbusServerModeSelected(bool selected) { if (!selected) { return; } if (!this->isStandaloneGuiSelected()) { return; } - ui->rb_SwiftCoreGuiAudio->setChecked(true); + ui->rb_SwiftCoreAudioOnGui->setChecked(true); } void CSwiftLauncher::ps_showStatusMessage(const CStatusMessage &msg) @@ -463,26 +506,19 @@ void CSwiftLauncher::ps_showLogPage() ui->sw_SwiftLauncher->setCurrentWidget(ui->pg_SwiftLauncherLog); } -void CSwiftLauncher::ps_checkRunningApplications() +void CSwiftLauncher::ps_checkRunningApplicationsAndCore() { - const CApplicationInfoList runningApps = sGui->getRunningApplications(); + // wait some time before buttons are enabled (allows startup) if (m_startCoreWaitCycles > 0) { m_startCoreWaitCycles--; } - else { ui->tb_SwiftCore->setEnabled(true); } if (m_startMappingToolWaitCycles > 0) { m_startMappingToolWaitCycles--; } - else { ui->tb_SwiftMappingTool->setEnabled(true); } + if (m_startGuiWaitCycles > 0) { m_startGuiWaitCycles--; } - for (const CApplicationInfo &info : runningApps) - { - switch (info.application()) - { - case CApplicationInfo::PilotClientCore : - ui->tb_SwiftCore->setEnabled(false); - break; - case CApplicationInfo::MappingTool : - ui->tb_SwiftMappingTool->setEnabled(false); - break; - default: - break; - } - } + const CApplicationInfoList runningApps = sGui->getRunningApplications(); + const bool foundLocalCore = runningApps.containsApplication(CApplicationInfo::PilotClientCore); + const bool foundLocalMappingTool = runningApps.containsApplication(CApplicationInfo::MappingTool); + const bool foundLocalPilotClientGui = runningApps.containsApplication(CApplicationInfo::PilotClientGui); + + ui->tb_SwiftCore->setEnabled(!foundLocalCore && m_startCoreWaitCycles < 1); + ui->tb_SwiftMappingTool->setEnabled(!foundLocalMappingTool && m_startMappingToolWaitCycles < 1); + ui->tb_SwiftGui->setEnabled(!foundLocalPilotClientGui && m_startGuiWaitCycles < 1); } diff --git a/src/swiftlauncher/swiftlauncher.h b/src/swiftlauncher/swiftlauncher.h index bb0c8df28..9a6b20400 100644 --- a/src/swiftlauncher/swiftlauncher.h +++ b/src/swiftlauncher/swiftlauncher.h @@ -17,8 +17,9 @@ #include "blackgui/mainwindowaccess.h" #include "blackcore/data/globalsetup.h" #include "blackcore/data/updateinfo.h" +#include "blackcore/data/launchersetup.h" #include "blackcore/coremodeenums.h" -#include "blackcore/application/applicationsettings.h" +#include "blackmisc/identifiable.h" #include #include #include @@ -35,7 +36,8 @@ namespace Ui { class CSwiftLauncher; } class CSwiftLauncher : public QDialog, public BlackGui::CEnableForFramelessWindow, - public BlackGui::IMainWindowAccess + public BlackGui::IMainWindowAccess, + public BlackMisc::CIdentifiable { Q_OBJECT Q_INTERFACES(BlackGui::IMainWindowAccess) @@ -56,7 +58,7 @@ public: //! Destructor virtual ~CSwiftLauncher(); - //! Executable + //! Executable (to be started) const QString &getExecutable() const { return m_executable; } //! Arguments @@ -72,19 +74,16 @@ protected: //! \copydoc QDialog::mouseMoveEvent void mouseMoveEvent(QMouseEvent *event) override; -private slots: - //! Display latest news - void ps_displayLatestNews(QNetworkReply *reply); - private: - QScopedPointer ui; + QScopedPointer ui; BlackMisc::CData m_updateInfo { this, &CSwiftLauncher::ps_changedUpdateInfoCache }; //!< version cache - BlackMisc::CSetting m_dbusServerAddress { this }; //!< DBus address + BlackMisc::CData m_setup { this }; //! setup, ie last user selection QString m_executable; QStringList m_executableArgs; QTimer m_checkTimer { this }; int m_startCoreWaitCycles = 0; int m_startMappingToolWaitCycles = 0; + int m_startGuiWaitCycles = 0; bool m_updateInfoLoaded = false; //! Get core mode @@ -128,13 +127,16 @@ private: bool setSwiftGuiExecutable(); //! Can DBus server be connected - bool canConnectDBusServer(QString &msg) const; + bool canConnectSwiftOnDBusServer(const QString &dbusAddress, QString &msg) const; //! Standalone GUI selected bool isStandaloneGuiSelected() const; //! Set default - void setDefault(const QString &value); + void setDefaults(); + + //! Save state + void saveSetup(); //! Command line static QString toCmdLine(const QString &exe, const QStringList &exeArgs); @@ -146,6 +148,9 @@ private slots: //! Loaded latest version void ps_loadedUpdateInfo(bool success); + //! Display latest news + void ps_displayLatestNews(QNetworkReply *reply); + //! Cache values have been changed void ps_changedUpdateInfoCache(); @@ -177,7 +182,7 @@ private slots: void ps_showLogPage(); //! Check if applicationas are already running - void ps_checkRunningApplications(); + void ps_checkRunningApplicationsAndCore(); }; #endif // guard diff --git a/src/swiftlauncher/swiftlauncher.ui b/src/swiftlauncher/swiftlauncher.ui index d27df74f3..20ca518aa 100644 --- a/src/swiftlauncher/swiftlauncher.ui +++ b/src/swiftlauncher/swiftlauncher.ui @@ -212,7 +212,7 @@ 4 - + GUI and core @@ -222,7 +222,7 @@ - + GUI and core @@ -440,6 +440,18 @@ Check for &updates + + 3 + + + 3 + + + 3 + + + 3 + @@ -447,16 +459,16 @@ - 2 + 4 - 2 + 4 - 2 + 4 - 2 + 4 @@ -588,16 +600,7 @@ - border: 0px; - - - QFrame::NoFrame - - - QFrame::Plain - - - 0 + border: 0px; padding: 2px; true @@ -607,8 +610,8 @@ 0 0 - 368 - 185 + 376 + 189 @@ -642,7 +645,6 @@ QFrame::Raised - comp_InfoBar