Add new WeatherData plugin structure

refs #556
This commit is contained in:
Roland Winklmeier
2016-01-13 20:42:12 +01:00
parent ca06933c0d
commit 79210cb14e
8 changed files with 407 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
/* Copyright (C) 2016
* 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 "weatherdataplugininfo.h"
using namespace BlackMisc;
namespace BlackMisc
{
namespace Weather
{
CWeatherDataPluginInfo::CWeatherDataPluginInfo(const QString &identifier, const QString &name, const QString &description, bool valid) :
m_identifier(identifier), m_name(name), m_description(description), m_valid(valid)
{ }
void CWeatherDataPluginInfo::convertFromJson(const QJsonObject &json)
{
if (json.contains("IID")) // comes from the plugin
{
// json data is already validated by CPluginManagerWeatherData
CValueObject::convertFromJson(json["MetaData"].toObject());
m_valid = true;
}
else
{
CValueObject::convertFromJson(json);
}
}
QString CWeatherDataPluginInfo::convertToQString(bool i18n) const
{
Q_UNUSED(i18n);
return QString("%1 (%2)").arg(m_name, m_identifier);
}
} // ns
} // ns

View File

@@ -0,0 +1,72 @@
/* Copyright (C) 2016
* 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_WEATHER_WEATHERDATAPLUGININFO_H
#define BLACKMISC_WEATHER_WEATHERDATAPLUGININFO_H
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/valueobject.h"
namespace BlackMisc
{
namespace Weather
{
//! Describing a weather data plugin
class BLACKMISC_EXPORT CWeatherDataPluginInfo : public BlackMisc::CValueObject<CWeatherDataPluginInfo>
{
public:
//! Default constructor
CWeatherDataPluginInfo() = default;
//! Constructor (used with unit tests)
CWeatherDataPluginInfo(const QString &identifier, const QString &name,
const QString &description, bool valid);
//! \copydoc BlackMisc::CValueObject::convertFromJson
void convertFromJson(const QJsonObject &json);
//! Check if the provided plugin metadata is valid.
//! Weather data plugin has to meet the following requirements:
//! * implements org.swift-project.blackcore.weatherdata;
//! * provides plugin name;
bool isValid() const { return m_valid; }
//! Identifier
const QString &getIdentifier() const { return m_identifier; }
//! Name
const QString &getName() const { return m_name; }
//! Description
const QString &getDescription() const { return m_description; }
//! \copydoc CValueObject::convertToQString
QString convertToQString(bool i18n = false) const;
private:
BLACK_ENABLE_TUPLE_CONVERSION(CWeatherDataPluginInfo)
QString m_identifier;
QString m_name;
QString m_description;
bool m_valid { false };
};
} // ns
} // ns
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Weather::CWeatherDataPluginInfo, (
attr(o.m_identifier, flags <CaseInsensitiveComparison> ()),
attr(o.m_name, flags < DisabledForComparison | DisabledForHashing > ()),
attr(o.m_description, flags < DisabledForComparison | DisabledForHashing > ()),
attr(o.m_valid, flags < DisabledForComparison | DisabledForHashing > ())
))
Q_DECLARE_METATYPE(BlackMisc::Weather::CWeatherDataPluginInfo)
#endif // guard

View File

@@ -0,0 +1,25 @@
/* Copyright (C) 2016
* 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 "weatherdataplugininfolist.h"
namespace BlackMisc
{
namespace Weather
{
CWeatherDataPluginInfoList::CWeatherDataPluginInfoList() { }
QStringList CWeatherDataPluginInfoList::toStringList(bool i18n) const
{
return this->transform([i18n](const CWeatherDataPluginInfo & info) { return info.toQString(i18n); });
}
} // namespace
} // namespace

View File

@@ -0,0 +1,50 @@
/* Copyright (C) 2016
* 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_WEATHER_WEATHERDATAPLUGININFOLIST_H
#define BLACKMISC_WEATHER_WEATHERDATAPLUGININFOLIST_H
#include "weatherdataplugininfo.h"
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/sequence.h"
#include "blackmisc/collection.h"
#include <QStringList>
namespace BlackMisc
{
namespace Weather
{
//! Value object encapsulating a list of CWeatherDataPluginInfo objects.
class BLACKMISC_EXPORT CWeatherDataPluginInfoList :
public BlackMisc::CSequence<CWeatherDataPluginInfo>,
public BlackMisc::Mixin::MetaType<CWeatherDataPluginInfoList>
{
public:
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CWeatherDataPluginInfoList)
//! Default constructor
CWeatherDataPluginInfoList();
//! Construct from a base class object.
CWeatherDataPluginInfoList(const CSequence<CWeatherDataPluginInfo> &other);
//! String list with meaningful representations
QStringList toStringList(bool i18n = false) const;
};
} // ns
} // ns
Q_DECLARE_METATYPE(BlackMisc::Weather::CWeatherDataPluginInfoList)
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Weather::CWeatherDataPluginInfo>)
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Weather::CWeatherDataPluginInfo>)
#endif // guard