Ref T297, network settings (dynamic offset times)

This commit is contained in:
Klaus Basan
2018-07-31 16:12:00 +02:00
parent abafbc335a
commit ce004be6ac
6 changed files with 133 additions and 3 deletions

View File

@@ -41,5 +41,6 @@
#include "blackmisc/network/user.h"
#include "blackmisc/network/userlist.h"
#include "blackmisc/network/voicecapabilities.h"
#include "blackmisc/network/settings/networksettings.h"
#endif // guard

View File

@@ -42,6 +42,7 @@ namespace BlackMisc
CUser::registerMetadata();
CUserList::registerMetadata();
CVoiceCapabilities::registerMetadata();
Settings::CNetworkSettings::registerMetadata();
}
} // ns
} // ns

View File

@@ -0,0 +1,53 @@
/* Copyright (C) 2018
* 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 "networksettings.h"
#include <QtGlobal>
#include <QStringBuilder>
#include "blackmisc/stringutils.h"
namespace BlackMisc
{
namespace Network
{
namespace Settings
{
QString CNetworkSettings::convertToQString(bool i18n) const
{
Q_UNUSED(i18n);
return QStringLiteral("dyn.offset: ") % boolToYesNo(this->isUsingDynamicOffsetTimes());
}
CVariant CNetworkSettings::propertyByIndex(const CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexDynamicOffsetTime: return CVariant::fromValue(m_dynamicOffsetTimes);
default: break;
}
return CValueObject::propertyByIndex(index);
}
void CNetworkSettings::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
{
if (index.isMyself()) { (*this) = variant.to<CNetworkSettings>(); return; }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexDynamicOffsetTime: this->setDynamicOffsetTimes(variant.toBool()); break;
default: break;
}
CValueObject::setPropertyByIndex(index, variant);
}
} // ns
} // ns
} // ns

View File

@@ -0,0 +1,73 @@
/* Copyright (C) 2018
* 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 BLACKMISC_NETWORK_SETTINGS_NETWORKSETTINGS_H
#define BLACKMISC_NETWORK_SETTINGS_NETWORKSETTINGS_H
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/metaclass.h"
#include "blackmisc/propertyindex.h"
#include "blackmisc/valueobject.h"
#include "blackmisc/variant.h"
#include <QJsonObject>
#include <QMetaType>
#include <QString>
namespace BlackMisc
{
namespace Network
{
namespace Settings
{
//! Network settings
class BLACKMISC_EXPORT CNetworkSettings : public CValueObject<CNetworkSettings>
{
public:
//! Properties by index
enum ColumnIndex
{
IndexDynamicOffsetTime = CPropertyIndex::GlobalIndexCNetworkSettings,
};
//! Constructor
CNetworkSettings() {}
//! Dynamic offset values?
bool isUsingDynamicOffsetTimes() const { return m_dynamicOffsetTimes; }
//! Dynamic offset values?
void setDynamicOffsetTimes(bool dynamic) { m_dynamicOffsetTimes = dynamic; }
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
CVariant propertyByIndex(const CPropertyIndex &index) const;
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
void setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant);
private:
bool m_dynamicOffsetTimes = false;
BLACK_METACLASS(
CNetworkSettings,
BLACK_METAMEMBER(dynamicOffsetTimes)
);
};
} // ns
} // ns
} // ns
Q_DECLARE_METATYPE(BlackMisc::Network::Settings::CNetworkSettings)
#endif // guard