From b7690ba919a8dc767f4683ff631f3b8b2ba1f143 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 16 Nov 2017 02:20:59 +0100 Subject: [PATCH] Ref T195, improved core UI * removed start/stop * added restart * use DBus UI component * show info about audio --- src/swiftcore/main.cpp | 1 - src/swiftcore/swiftcore.cpp | 133 ++++++++-------------- src/swiftcore/swiftcore.h | 43 ++++---- src/swiftcore/swiftcore.ui | 214 +++++++++++++++++++++++------------- 4 files changed, 207 insertions(+), 184 deletions(-) diff --git a/src/swiftcore/main.cpp b/src/swiftcore/main.cpp index 8105e88e0..74a395c9e 100644 --- a/src/swiftcore/main.cpp +++ b/src/swiftcore/main.cpp @@ -33,7 +33,6 @@ int main(int argc, char *argv[]) a.addWindowStateOption(); a.addDBusAddressOption(); a.addVatlibOptions(); - a.addParserOption({{"r", "start"}, QCoreApplication::translate("main", "Start the server.")}); a.addParserOption({{"c", "coreaudio"}, QCoreApplication::translate("main", "Audio in core.")}); if (!a.parseAndSynchronizeSetup()) { return EXIT_FAILURE; } diff --git a/src/swiftcore/swiftcore.cpp b/src/swiftcore/swiftcore.cpp index 4af7eaa77..83a701554 100644 --- a/src/swiftcore/swiftcore.cpp +++ b/src/swiftcore/swiftcore.cpp @@ -8,13 +8,14 @@ */ #include "swiftcore.h" -#include "blackcore/corefacade.h" #include "blackgui/components/commandinput.h" #include "blackgui/components/coreinfoareacomponent.h" #include "blackgui/components/coresettingsdialog.h" #include "blackgui/components/logcomponent.h" #include "blackgui/guiapplication.h" #include "blackgui/stylesheetutility.h" +#include "blackcore/context/contextaudio.h" +#include "blackcore/corefacade.h" #include "blackmisc/dbusserver.h" #include "blackmisc/icons.h" #include "blackmisc/loghandler.h" @@ -41,6 +42,7 @@ CSwiftCore::CSwiftCore(QWidget *parent) : CIdentifiable(this), ui(new Ui::CSwiftCore) { + Q_ASSERT(sGui); ui->setupUi(this); sGui->initMainApplicationWindow(this); const QString name(sGui->getApplicationNameAndVersion()); @@ -51,19 +53,26 @@ CSwiftCore::CSwiftCore(QWidget *parent) : m_mwaOverlayFrame = nullptr; m_mwaStatusBar = nullptr; - initLogDisplay(); - initSlots(); - initStyleSheet(); - initDBusMode(); - initMenus(); + connect(ui->pb_Restart, &QPushButton::clicked, this, &CSwiftCore::restart); + connect(sGui, &CGuiApplication::styleSheetsChanged, this, &CSwiftCore::onStyleSheetsChanged); + + this->initLogDisplay(); + this->initStyleSheet(); + this->initMenus(); + this->initAudio(); + + // log + CStatusMessage m = CStatusMessage(this).info("Cmd: " + CGuiApplication::arguments().join(" ")); + this->appendLogMessage(m); // command line ui->lep_CommandLineInput->setIdentifier(this->identifier()); connect(ui->lep_CommandLineInput, &CCommandInput::commandEntered, sGui->getCoreFacade(), &CCoreFacade::parseCommandLine); - - if (sGui->isParserOptionSet("start")) { startCore(sGui->getCmdDBusAddressValue()); } } +CSwiftCore::~CSwiftCore() +{ } + void CSwiftCore::initStyleSheet() { const QString s = sGui->getStyleSheetUtility().styles( @@ -76,56 +85,12 @@ void CSwiftCore::initStyleSheet() this->setStyleSheet(s); } -void CSwiftCore::initDBusMode() -{ - const QString dBusAddress(sGui->getCmdDBusAddressValue()); - if (dBusAddress.startsWith(CDBusServer::sessionBusAddress())) - { - ui->rb_SessionBus->setChecked(true); - } - else if (dBusAddress.startsWith(CDBusServer::systemBusAddress())) - { - ui->rb_SystemBus->setChecked(true); - } - else - { - ui->rb_P2PBus->setChecked(true); - ui->le_P2PAddress->setText(dBusAddress); - } -} - -CSwiftCore::~CSwiftCore() -{ } - -void CSwiftCore::ps_startCorePressed() -{ - startCore(getDBusAddress()); -} - -void CSwiftCore::ps_stopCorePressed() -{ - stopCore(); -} - -void CSwiftCore::ps_appendLogMessage(const CStatusMessage &message) +void CSwiftCore::appendLogMessage(const CStatusMessage &message) { ui->comp_InfoArea->getLogComponent()->appendStatusMessageToList(message); } -void CSwiftCore::ps_p2pModeToggled(bool checked) -{ - if (checked) - { - ui->le_P2PAddress->setEnabled(true); - } - else - { - ui->le_P2PAddress->setText(QString()); - ui->le_P2PAddress->setEnabled(false); - } -} - -void CSwiftCore::ps_showSettingsDialog() +void CSwiftCore::showSettingsDialog() { if (!m_settingsDialog) { @@ -134,19 +99,11 @@ void CSwiftCore::ps_showSettingsDialog() m_settingsDialog->show(); } -void CSwiftCore::ps_onStyleSheetsChanged() +void CSwiftCore::onStyleSheetsChanged() { this->initStyleSheet(); } -void CSwiftCore::initSlots() -{ - connect(ui->pb_StartCore, &QPushButton::clicked, this, &CSwiftCore::ps_startCorePressed); - connect(ui->pb_StopCore, &QPushButton::clicked, this, &CSwiftCore::ps_stopCorePressed); - connect(ui->rb_P2PBus, &QRadioButton::toggled, this, &CSwiftCore::ps_p2pModeToggled); - connect(sGui, &CGuiApplication::styleSheetsChanged, this, &CSwiftCore::ps_onStyleSheetsChanged); -} - void CSwiftCore::initLogDisplay() { m_mwaLogComponent->showDetails(false); @@ -155,7 +112,7 @@ void CSwiftCore::initLogDisplay() auto logHandler = CLogHandler::instance()->handlerForPattern( CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityInfo) ); - logHandler->subscribe(this, &CSwiftCore::ps_appendLogMessage); + logHandler->subscribe(this, &CSwiftCore::appendLogMessage); ui->comp_InfoArea->getLogComponent()->showFilterDialog(); // add a filter dialog } @@ -164,36 +121,40 @@ void CSwiftCore::initMenus() sGui->addMenuFile(*ui->menu_File); sGui->addMenuWindow(*ui->menu_Window); sGui->addMenuHelp(*ui->menu_Help); - connect(ui->menu_SettingsDialog, &QAction::triggered, this, &CSwiftCore::ps_showSettingsDialog); + connect(ui->menu_SettingsDialog, &QAction::triggered, this, &CSwiftCore::showSettingsDialog); } -void CSwiftCore::startCore(const QString &dBusAdress) +void CSwiftCore::initAudio() { - if (dBusAdress.isEmpty()) { return; } - Q_ASSERT_X(sGui, Q_FUNC_INFO, "Missing sGui"); - Q_ASSERT_X(sGui->getCoreFacade(), Q_FUNC_INFO, "Missing facade"); - - ui->pb_StartCore->setEnabled(false); - ui->pb_StopCore->setEnabled(true); - ui->gb_DBusMode->setDisabled(true); - sGui->processEventsToRefreshGui(); + if (!sGui->getIContextAudio()) { return; } + ui->lbl_AudioRunsWhere->setText(sGui->getIContextAudio()->audioRunsWhereInfo()); + if (sGui->getIContextAudio()->isUsingImplementingObject()) + { + ui->rb_AudioOnCore->setChecked(true); + } + else + { + ui->rb_AudioOnGui->setChecked(true); + } } -void CSwiftCore::stopCore() +void CSwiftCore::restart() { - ui->pb_StartCore->setEnabled(true); - ui->pb_StopCore->setEnabled(false); - ui->gb_DBusMode->setDisabled(false); - sGui->processEventsToRefreshGui(); - sGui->exit(); + ui->pb_Restart->setEnabled(false); + const QStringList args = this->getRestartCmdArgs(); + sGui->restartApplication(args, { "--coreaudio" }); } -QString CSwiftCore::getDBusAddress() const +QString CSwiftCore::getAudioCmdFromRadioButtons() const { - if (ui->rb_SessionBus->isChecked()) { return CDBusServer::sessionBusAddress(); } - if (ui->rb_SystemBus->isChecked()) { return CDBusServer::systemBusAddress(); } - if (ui->rb_P2PBus->isChecked()) { return CDBusServer::normalizeAddress(ui->le_P2PAddress->text()); } - - Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong DBus address"); + if (ui->rb_AudioOnCore->isChecked()) { return "--coreaudio"; } return ""; } + +QStringList CSwiftCore::getRestartCmdArgs() const +{ + const QString coreAudio = this->getAudioCmdFromRadioButtons(); + QStringList cmds = ui->comp_DBusSelector->getDBusCmdLineArgs(); + if (!coreAudio.isEmpty()) { cmds.append(coreAudio); } + return cmds; +} diff --git a/src/swiftcore/swiftcore.h b/src/swiftcore/swiftcore.h index 5e5358111..384cca903 100644 --- a/src/swiftcore/swiftcore.h +++ b/src/swiftcore/swiftcore.h @@ -1,3 +1,4 @@ + /* Copyright (C) 2015 * swift project Community / Contributors * @@ -12,6 +13,7 @@ #ifndef SWIFTCORE_H #define SWIFTCORE_H +#include "blackcore/coremodeenums.h" #include "blackgui/mainwindowaccess.h" #include "blackgui/systemtraywindow.h" #include "blackmisc/identifiable.h" @@ -43,34 +45,35 @@ public: //! Destructor virtual ~CSwiftCore(); -private slots: - //! \name PushButton slots - //! @{ - void ps_startCorePressed(); - void ps_stopCorePressed(); - void ps_appendLogMessage(const BlackMisc::CStatusMessage &message); - void ps_p2pModeToggled(bool checked); - //! @} - - //! Show the settings dialog - void ps_showSettingsDialog(); - - //! Style sheet has changed - virtual void ps_onStyleSheetsChanged(); - private: //! \name Init //! @{ - void initSlots(); void initLogDisplay(); void initStyleSheet(); - void initDBusMode(); void initMenus(); + void initAudio(); //! @} - void startCore(const QString &dBusAdress); - void stopCore(); - QString getDBusAddress() const; + //! Add a message to log UI + void appendLogMessage(const BlackMisc::CStatusMessage &message); + + //! Toggled P2P mode + void p2pModeToggled(bool checked); + + //! Show the settings dialog + void showSettingsDialog(); + + //! Style sheet has changed + virtual void onStyleSheetsChanged(); + + //! Restart with new arguments + void restart(); + + //! Core mode from radio buttons + QString getAudioCmdFromRadioButtons() const; + + //! Restart CMD args + QStringList getRestartCmdArgs() const; QScopedPointer m_settingsDialog; QScopedPointer ui; diff --git a/src/swiftcore/swiftcore.ui b/src/swiftcore/swiftcore.ui index 82ba3cd86..d4af13cca 100644 --- a/src/swiftcore/swiftcore.ui +++ b/src/swiftcore/swiftcore.ui @@ -6,55 +6,29 @@ 0 0 - 460 - 382 + 450 + 550 + + + 450 + 550 + + - swiftcore + swiftcore UI - - - - Controls - - - - - - /** Main window **/ -QTextEdit { - background-color: DimGray; -} - - - Start - - - - - - - false - - - /** Main window **/ -QTextEdit { - background-color: DimGray; -} - - - Stop - - - false - - - - - + + 4 + + + 4 + + + @@ -81,54 +55,134 @@ QTextEdit { - - - - DBus Mode + + + + + 0 + 0 + - - - + + + 0 + 200 + + + + + + + + Audio + + + + 9 + + + 4 + + + 9 + + + 4 + + + - Session + <Audio is where> + + + true + + + + + + + on core side + + + + + + + on GUI side true - - + + + + + + + Control + + + + 9 + + + 4 + + + 9 + + + 4 + + + + + /** Main window **/ +QTextEdit { + background-color: DimGray; +} + - P2P - - - - - - - System - - - - - - - false - - - P2P address + restart - - - - - + + + + DBus Mode + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + @@ -137,7 +191,7 @@ QTextEdit { 0 0 - 460 + 450 21 @@ -179,6 +233,12 @@ QTextEdit { + + BlackGui::Components::CDBusServerAddressSelector + QFrame +
blackgui/components/dbusserveraddressselector.h
+ 1 +
BlackGui::CSystemTrayWindow QMainWindow