refs #883, launcher improvements

* check if core is running before starting pilot client DBus UI
* avoid starting pilot client when already running
* save UI state (cache)
* made lauchner BlackMisc::CIdentifiable
This commit is contained in:
Klaus Basan
2017-02-17 20:11:54 +01:00
committed by Mathew Sutcliffe
parent 5d81b23386
commit 3b3cdf4566
3 changed files with 138 additions and 95 deletions

View File

@@ -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 &current
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);
}

View File

@@ -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 <QDialog>
#include <QTimer>
#include <QScopedPointer>
@@ -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::CSwiftLauncher> ui;
QScopedPointer<Ui::CSwiftLauncher> ui;
BlackMisc::CData<BlackCore::Data::TUpdateInfo> m_updateInfo { this, &CSwiftLauncher::ps_changedUpdateInfoCache }; //!< version cache
BlackMisc::CSetting<BlackCore::Application::TDBusServerAddress> m_dbusServerAddress { this }; //!< DBus address
BlackMisc::CData<BlackCore::Data::TLauncherSetup> 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

View File

@@ -212,7 +212,7 @@
<number>4</number>
</property>
<item row="0" column="1" alignment="Qt::AlignHCenter">
<widget class="QRadioButton" name="rb_SwiftCoreGuiAudio">
<widget class="QRadioButton" name="rb_SwiftCoreAudioOnGui">
<property name="text">
<string>GUI and core</string>
</property>
@@ -222,7 +222,7 @@
</widget>
</item>
<item row="0" column="2" alignment="Qt::AlignHCenter">
<widget class="QRadioButton" name="rb_SwiftCoreAudio">
<widget class="QRadioButton" name="rb_SwiftCoreAudioOnCore">
<property name="text">
<string>GUI and core</string>
</property>
@@ -440,6 +440,18 @@
<string>Check for &amp;updates</string>
</attribute>
<layout class="QVBoxLayout" name="vl_Updates">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QGroupBox" name="gb_SoftwareUpdates">
<property name="title">
@@ -447,16 +459,16 @@
</property>
<layout class="QGridLayout" name="gl_Version">
<property name="leftMargin">
<number>2</number>
<number>4</number>
</property>
<property name="topMargin">
<number>2</number>
<number>4</number>
</property>
<property name="rightMargin">
<number>2</number>
<number>4</number>
</property>
<property name="bottomMargin">
<number>2</number>
<number>4</number>
</property>
<item row="3" column="1" colspan="3">
<widget class="QWidget" name="wi_NoNewVersion" native="true">
@@ -588,16 +600,7 @@
<item>
<widget class="QScrollArea" name="sa_DataUpdates">
<property name="styleSheet">
<string notr="true">border: 0px;</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
<string notr="true">border: 0px; padding: 2px;</string>
</property>
<property name="widgetResizable">
<bool>true</bool>
@@ -607,8 +610,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>368</width>
<height>185</height>
<width>376</width>
<height>189</height>
</rect>
</property>
<layout class="QVBoxLayout" name="vl_DataUpdatesScrollArea">
@@ -642,7 +645,6 @@
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<zorder>comp_InfoBar</zorder>
</widget>
</item>
</layout>