diff --git a/src/blackcore/application/applicationsettings.h b/src/blackcore/application/applicationsettings.h index e1394661d..50dea1157 100644 --- a/src/blackcore/application/applicationsettings.h +++ b/src/blackcore/application/applicationsettings.h @@ -21,16 +21,6 @@ namespace BlackCore { namespace Application { - //! DBus server address - struct TDBusServerAddress : public BlackMisc::TSettingTrait - { - //! \copydoc BlackMisc::TSettingTrait::key - static const char *key() { return "network/dbusserver"; } - - //! \copydoc BlackMisc::TSettingTrait::defaultValue - static const QString &defaultValue() { static const QString dv("session"); return dv; } - }; - //! User configured hotkeys struct TActionHotkeys : public BlackMisc::TSettingTrait { @@ -101,7 +91,6 @@ namespace BlackCore //! \copydoc BlackCore::TSettingTrait::defaultValue static bool defaultValue() { return true; } }; - } // ns } // ns diff --git a/src/blackcore/corefacade.cpp b/src/blackcore/corefacade.cpp index 7927043eb..29388bfa2 100644 --- a/src/blackcore/corefacade.cpp +++ b/src/blackcore/corefacade.cpp @@ -17,6 +17,7 @@ #include "blackcore/context/contextownaircraftimpl.h" #include "blackcore/context/contextsimulator.h" #include "blackcore/context/contextsimulatorimpl.h" +#include "blackcore/data/launchersetup.h" #include "blackcore/corefacade.h" #include "blackcore/corefacadeconfig.h" #include "blackcore/registermetadata.h" @@ -42,6 +43,7 @@ using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::Simulation; +using namespace BlackCore::Data; using namespace BlackCore::Context; namespace BlackCore @@ -64,11 +66,12 @@ namespace BlackCore if (config.hasDBusAddress()) { dbusAddress = config.getDBusAddress(); - m_dbusServerAddress.set(dbusAddress); + m_launcherSetup.setProperty(CLauncherSetup::IndexDBusAddress, dbusAddress); } else { - dbusAddress = m_dbusServerAddress.getThreadLocal(); + CLauncherSetup setup = m_launcherSetup.get(); + dbusAddress = setup.getDBusAddress(); } // DBus diff --git a/src/blackcore/corefacade.h b/src/blackcore/corefacade.h index a8edf25a2..24c454cbf 100644 --- a/src/blackcore/corefacade.h +++ b/src/blackcore/corefacade.h @@ -13,7 +13,7 @@ #define BLACKCORE_COREFACADE_H #include "blackcore/blackcoreexport.h" -#include "blackcore/application/applicationsettings.h" +#include "blackcore/data/launchersetup.h" #include "blackcore/vatsim/vatsimsettings.h" #include "blackmisc/identifier.h" #include "blackmisc/settingscache.h" @@ -165,12 +165,12 @@ namespace BlackCore private: bool m_initalized = false; //!< flag if already initialized bool m_shuttingDown = false; //!< flag if shutting down - BlackMisc::CSetting m_dbusServerAddress { this }; + BlackMisc::CData m_launcherSetup { this }; // DBus BlackMisc::CDBusServer *m_dbusServer = nullptr; - QDBusConnection m_dbusConnection = QDBusConnection("default"); bool m_initDBusConnection = false; + QDBusConnection m_dbusConnection { "default" }; // contexts: // There is a reason why we do not use smart pointers here. When the context is deleted diff --git a/src/blackcore/data/launchersetup.cpp b/src/blackcore/data/launchersetup.cpp new file mode 100644 index 000000000..31d88642a --- /dev/null +++ b/src/blackcore/data/launchersetup.cpp @@ -0,0 +1,63 @@ +/* Copyright (C) 2017 + * 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 "launchersetup.h" +#include "blackmisc/stringutils.h" + +using namespace BlackMisc; + +namespace BlackCore +{ + namespace Data + { + QString CLauncherSetup::convertToQString(bool i18n) const + { + Q_UNUSED(i18n); + return QString("DBus: %1 frameless: %2 mode: %3").arg(m_dBusAddress, boolToYesNo(m_windowFrameless)).arg(m_coreMode); + } + + CVariant CLauncherSetup::propertyByIndex(const BlackMisc::CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexDBusAddress: + return CVariant::fromValue(this->m_dBusAddress); + case IndexFramelessWindow: + return CVariant::fromValue(this->m_windowFrameless); + case IndexCoreMode: + return CVariant::fromValue(this->m_coreMode); + default: + return CValueObject::propertyByIndex(index); + } + } + + void CLauncherSetup::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) + { + if (index.isMyself()) { (*this) = variant.to(); return; } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexDBusAddress: + this->setDBusAddress(variant.toQString()); + break; + case IndexFramelessWindow: + this->m_windowFrameless = variant.toBool(); + break; + case IndexCoreMode: + this->m_coreMode = variant.toInt(); + break; + default: + CValueObject::setPropertyByIndex(index, variant); + break; + } + } + } // ns +} // ns diff --git a/src/blackcore/data/launchersetup.h b/src/blackcore/data/launchersetup.h new file mode 100644 index 000000000..09fa4ba9e --- /dev/null +++ b/src/blackcore/data/launchersetup.h @@ -0,0 +1,105 @@ +/* Copyright (C) 2017 + * 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 BLACKCORE_DATA_LAUNCHERSETUP +#define BLACKCORE_DATA_LAUNCHERSETUP + +#include "blackcore/blackcoreexport.h" +#include "blackmisc/propertyindex.h" +#include "blackmisc/datacache.h" +#include "blackmisc/valueobject.h" +#include "blackmisc/variant.h" + +namespace BlackCore +{ + namespace Data + { + //! Launcher setup + class BLACKCORE_EXPORT CLauncherSetup : public BlackMisc::CValueObject + { + public: + //! Properties by index + enum ColumnIndex + { + IndexDBusAddress = BlackMisc::CPropertyIndex::GlobalIndexCLauncherSetup, + IndexFramelessWindow, + IndexCoreMode + }; + + //! Core mode + enum CoreMode + { + Standalone, + CoreWithAudioOnGui, + CoreWithAudioOnCore, + }; + + //! Default constructor + CLauncherSetup() {} + + //! Destructor. + ~CLauncherSetup() {} + + //! DBus address + const QString &getDBusAddress() const { return m_dBusAddress; } + + //! DBus address + void setDBusAddress(const QString &dBusAddress) { m_dBusAddress = dBusAddress.trimmed(); } + + //! Core mode + CoreMode getCoreMode() const { return static_cast(m_coreMode); } + + //! Core mode + void setCoreMode(CoreMode mode) { m_coreMode = static_cast(mode); } + + //! Frameless window? + bool useFramelessWindow() const { return m_windowFrameless; } + + //! Frameless window? + void setFramelessWindow(bool frameless) { m_windowFrameless = frameless; } + + //! \copydoc BlackMisc::Mixin::String::toQString + QString convertToQString(bool i18n = false) const; + + //! \copydoc BlackMisc::Mixin::Index::propertyByIndex + BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; + + //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex + void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant); + + private: + QString m_dBusAddress { "session" }; //!< DBus address + bool m_windowFrameless = false; //!< frameless window + int m_coreMode = static_cast(Standalone); //!< core + + BLACK_METACLASS( + CLauncherSetup, + BLACK_METAMEMBER(dBusAddress), + BLACK_METAMEMBER(windowFrameless), + BLACK_METAMEMBER(coreMode) + ); + }; + + //! Trait for global setup data + struct TLauncherSetup : public BlackMisc::TDataTrait + { + //! Key in data cache + static const char *key() { return "swiftlaunchersetup"; } + + //! First load is synchronous + static constexpr bool isPinned() { return true; } + }; + } // ns +} // ns + +Q_DECLARE_METATYPE(BlackCore::Data::CLauncherSetup) + +#endif // guard diff --git a/src/blackcore/registermetadata.cpp b/src/blackcore/registermetadata.cpp index 1976a8729..e3e5c7926 100644 --- a/src/blackcore/registermetadata.cpp +++ b/src/blackcore/registermetadata.cpp @@ -9,11 +9,12 @@ #include "blackcore/registermetadata.h" #include "blackcore/context/contextapplication.h" -#include "blackcore/db/databasereader.h" -#include "blackcore/vatsim/vatsimsettings.h" +#include "blackcore/data/launchersetup.h" #include "blackcore/data/globalsetup.h" #include "blackcore/data/updateinfo.h" #include "blackcore/data/vatsimsetup.h" +#include "blackcore/db/databasereader.h" +#include "blackcore/vatsim/vatsimsettings.h" #include "blackcore/network.h" #include "blackcore/voicechannel.h" #include "blackcore/webreaderflags.h" @@ -38,11 +39,10 @@ namespace BlackCore BlackCore::Db::CDatabaseReaderConfig::registerMetadata(); BlackCore::Db::CDatabaseReaderConfigList::registerMetadata(); - BlackCore::Data::CGlobalSetup::registerMetadata(); BlackCore::Data::CUpdateInfo::registerMetadata(); BlackCore::Data::CVatsimSetup::registerMetadata(); - + BlackCore::Data::CLauncherSetup::registerMetadata(); BlackCore::Vatsim::CReaderSettings::registerMetadata(); } } // namespace diff --git a/src/blackcore/registermetadata.h b/src/blackcore/registermetadata.h index 2cbdc539f..682d4fe63 100644 --- a/src/blackcore/registermetadata.h +++ b/src/blackcore/registermetadata.h @@ -18,7 +18,6 @@ namespace BlackCore { //! Register all relevant metadata in BlackCore BLACKCORE_EXPORT void registerMetadata(); - } // ns #endif // guard diff --git a/src/blackmisc/propertyindex.h b/src/blackmisc/propertyindex.h index 8d94a889c..823c5ad2f 100644 --- a/src/blackmisc/propertyindex.h +++ b/src/blackmisc/propertyindex.h @@ -138,6 +138,7 @@ namespace BlackMisc GlobalIndexCGlobalSetup = 12000, GlobalIndexCUpdateInfo = 12100, GlobalIndexCVatsimSetup = 12200, + GlobalIndexCLauncherSetup = 12300, GlobalIndexCGuiStateDbOwnModelsComponent = 14000, GlobalIndexCGuiStateDbOwnModelSetComponent = 14100, GlobalIndexCDockWidgetSettings = 14200, @@ -149,6 +150,9 @@ namespace BlackMisc GlobalIndexCAtcStationsSettings = 14800, GlobalIndexCInterpolatioRenderingSetup = 16000, GlobalIndexCInterpolationHints = 16100, + GlobalIndexSwiftPilotClient = 17000, + GlobalIndexSwiftCore = 17100, + GlobalIndexSwiftLauncher = 17200, GlobalIndexLineNumber = 20000, //!< pseudo index for line numbers };