mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
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:
committed by
Mathew Sutcliffe
parent
92100c85f7
commit
d918ee4cfd
63
src/blackcore/data/launchersetup.cpp
Normal file
63
src/blackcore/data/launchersetup.cpp
Normal 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
|
||||
105
src/blackcore/data/launchersetup.h
Normal file
105
src/blackcore/data/launchersetup.h
Normal 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
|
||||
Reference in New Issue
Block a user