refs #883, class for storing the launcher state

* removed DBus setting (causing crash as it was shared among launcher/pilot client, so using cache)
* also remember UI values
This commit is contained in:
Klaus Basan
2017-02-17 20:00:59 +01:00
committed by Mathew Sutcliffe
parent 92100c85f7
commit d918ee4cfd
8 changed files with 184 additions and 21 deletions

View File

@@ -21,16 +21,6 @@ namespace BlackCore
{
namespace Application
{
//! DBus server address
struct TDBusServerAddress : public BlackMisc::TSettingTrait<QString>
{
//! \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<BlackMisc::Input::CActionHotkeyList>
{
@@ -101,7 +91,6 @@ namespace BlackCore
//! \copydoc BlackCore::TSettingTrait::defaultValue
static bool defaultValue() { return true; }
};
} // ns
} // ns

View File

@@ -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

View File

@@ -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<Application::TDBusServerAddress> m_dbusServerAddress { this };
BlackMisc::CData<Data::TLauncherSetup> 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

View File

@@ -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<ColumnIndex>();
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<CLauncherSetup>(); return; }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
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

View File

@@ -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<CLauncherSetup>
{
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<CoreMode>(m_coreMode); }
//! Core mode
void setCoreMode(CoreMode mode) { m_coreMode = static_cast<int>(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<int>(Standalone); //!< core
BLACK_METACLASS(
CLauncherSetup,
BLACK_METAMEMBER(dBusAddress),
BLACK_METAMEMBER(windowFrameless),
BLACK_METAMEMBER(coreMode)
);
};
//! Trait for global setup data
struct TLauncherSetup : public BlackMisc::TDataTrait<CLauncherSetup>
{
//! 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

View File

@@ -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

View File

@@ -18,7 +18,6 @@ namespace BlackCore
{
//! Register all relevant metadata in BlackCore
BLACKCORE_EXPORT void registerMetadata();
} // ns
#endif // guard

View File

@@ -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
};