Added IMetaDataPlugin base class for parsing plugin name, description,

etc... from json metadata file.
print
Josef Rokos 9 years ago
parent 3a072742ac
commit 7755432484

@ -11,6 +11,14 @@ Accommodation::Accommodation()
{
}
void Accommodation::initServiceUi()
{
m_ui = new AccommodationForm();
AccommodationService *service = new AccommodationService();
m_service = service;
}
/*
QString Accommodation::pluginName()
{
return "Ubytovani";
@ -18,14 +26,11 @@ QString Accommodation::pluginName()
void Accommodation::init(const QJsonObject &metaData)
{
qDebug() << "init accomodation" << metaData;
m_ui = new AccommodationForm();
AccommodationService *service = new AccommodationService();
m_service = service;
}
QString Accommodation::pluginId()
{
return "ACCOMMODATION";
}
*/

@ -6,7 +6,7 @@
#include <QObject>
#include <QtPlugin>
class ACCOMMODATIONSHARED_EXPORT Accommodation : public QObject, IPlugin
class ACCOMMODATIONSHARED_EXPORT Accommodation : public QObject, IMetaDataPlugin
{
Q_OBJECT
@ -16,9 +16,12 @@ class ACCOMMODATIONSHARED_EXPORT Accommodation : public QObject, IPlugin
public:
Accommodation();
QString pluginName() Q_DECL_OVERRIDE;
void init(const QJsonObject &metaData) Q_DECL_OVERRIDE;
QString pluginId() Q_DECL_OVERRIDE;
// QString pluginName() Q_DECL_OVERRIDE;
// void init(const QJsonObject &metaData) Q_DECL_OVERRIDE;
// QString pluginId() Q_DECL_OVERRIDE;
protected:
void initServiceUi() Q_DECL_OVERRIDE;
};

@ -2,7 +2,7 @@
"id" : "ACCOMMODATION",
"name" : {
"default" : "Accommodation",
"CZ" : "Ubytování"
"CZ" : "Kemp"
},
"descriptoin" : {
"default" : "",

@ -3,5 +3,6 @@
#include "context.h"
#include "iplugin.h"
#include "imetadataplugin.h"
#endif // CORE_H

@ -13,14 +13,16 @@ DEFINES += CORE_LIBRARY
SOURCES += \
data/user.cpp \
context.cpp
context.cpp \
imetadataplugin.cpp
HEADERS += core.h\
core_global.h \
iplugin.h \
service.h \
data/user.h \
context.h
context.h \
imetadataplugin.h
unix {
target.path = /usr/lib

@ -0,0 +1,67 @@
#include "imetadataplugin.h"
#include <QJsonValue>
#include <QLocale>
#include <QDebug>
IMetaDataPlugin::IMetaDataPlugin()
{
}
IMetaDataPlugin::~IMetaDataPlugin()
{
}
QString IMetaDataPlugin::pluginName()
{
return m_name;
}
QString IMetaDataPlugin::pluginId()
{
return m_id;
}
QString IMetaDataPlugin::pluginDescription()
{
return m_description;
}
void IMetaDataPlugin::init(const QJsonObject &metaData)
{
parseMetaData(metaData);
initServiceUi();
}
void IMetaDataPlugin::parseMetaData(const QJsonObject &metaData)
{
qDebug() << metaData;
QJsonValue data = metaData["MetaData"];
if (!data.isObject()) {
return;
}
m_name = parseLocaleText(data.toObject()["name"].toObject());
m_description = parseLocaleText(data.toObject()["description"].toObject());
m_id = data.toObject()["id"].toString();
}
QString IMetaDataPlugin::parseLocaleText(const QJsonObject &object)
{
QString locale = QLocale::system().name();
QString ret;
foreach (QString key, object.keys()) {
if (locale.contains(key, Qt::CaseInsensitive)) {
ret = object[key].toString();
break;
}
}
if (ret.isEmpty()) {
ret = object["default"].toString();
}
return ret;
}

@ -0,0 +1,34 @@
#ifndef IMETADATAPLUGIN_H
#define IMETADATAPLUGIN_H
#include <QString>
#include "core_global.h"
#include "iplugin.h"
class CORESHARED_EXPORT IMetaDataPlugin : public IPlugin
{
public:
IMetaDataPlugin();
~IMetaDataPlugin();
// IPlugin interface
public:
virtual QString pluginName();
virtual QString pluginId();
virtual QString pluginDescription();
virtual void init(const QJsonObject &metaData);
protected:
virtual void initServiceUi() = 0;
virtual void parseMetaData(const QJsonObject &metaData);
private:
QString m_name;
QString m_id;
QString m_description;
QString parseLocaleText(const QJsonObject &object);
};
#endif // IMETADATAPLUGIN_H

@ -19,6 +19,7 @@ public:
virtual ~IPlugin() { }
virtual QString pluginName() = 0;
virtual QString pluginId() = 0;
virtual QString pluginDescription() = 0;
virtual void init(const QJsonObject &metaData) = 0;
virtual QWidget *ui() {
return m_ui;

Loading…
Cancel
Save