diff --git a/libguh/plugin/deviceplugin.cpp b/libguh/plugin/deviceplugin.cpp index e9b6847d..f6e5caaf 100644 --- a/libguh/plugin/deviceplugin.cpp +++ b/libguh/plugin/deviceplugin.cpp @@ -125,7 +125,13 @@ DevicePlugin::~DevicePlugin() /*! Returns the name of this DevicePlugin. */ QString DevicePlugin::pluginName() const { - return translateValue(m_metaData.value("idName").toString(), m_metaData.value("name").toString()); + return m_metaData.value("name").toString(); +} + +/*! Returns the displayName of this DevicePlugin, to be shown to the user, translated. */ +QString DevicePlugin::pluginDisplayName() const +{ + return translateValue(m_metaData.value("name").toString(), m_metaData.value("displayName").toString()); } /*! Returns the id of this DevicePlugin. @@ -141,7 +147,8 @@ QList DevicePlugin::supportedVendors() const { QList vendors; foreach (const QJsonValue &vendorJson, m_metaData.value("vendors").toArray()) { - Vendor vendor(vendorJson.toObject().value("id").toString(), translateValue(m_metaData.value("idName").toString(), vendorJson.toObject().value("name").toString())); + Vendor vendor(vendorJson.toObject().value("id").toString(), vendorJson.toObject().value("name").toString()); + vendor.setDisplayName(translateValue(m_metaData.value("name").toString(), vendorJson.toObject().value("displayName").toString())); vendors.append(vendor); } return vendors; @@ -302,7 +309,7 @@ QPair > DevicePlugin::parseParamTypes(const QJsonArray &a // Check fields int index = 0; - QStringList missingFields = verifyFields(QStringList() << "id" << "name" << "idName" << "type", pt); + QStringList missingFields = verifyFields(QStringList() << "id" << "name" << "displayName" << "type", pt); if (!missingFields.isEmpty()) { qCWarning(dcDeviceManager) << pluginName() << "Error parsing ParamType: missing fields" << missingFields.join(", ") << endl << pt; return QPair >(false, QList()); @@ -317,7 +324,8 @@ QPair > DevicePlugin::parseParamTypes(const QJsonArray &a return QPair >(false, QList()); } - ParamType paramType(ParamTypeId(pt.value("id").toString()), translateValue(m_metaData.value("idName").toString(), pt.value("name").toString()), t, pt.value("defaultValue").toVariant()); + ParamType paramType(ParamTypeId(pt.value("id").toString()), pt.value("name").toString(), t, pt.value("defaultValue").toVariant()); + paramType.setDisplayName(translateValue(m_metaData.value("name").toString(), pt.value("displayName").toString())); paramType.setIndex(index); // Set allowed values @@ -518,7 +526,7 @@ void DevicePlugin::loadMetaData() VendorId vendorId = vendorObject.value("id").toString(); foreach (const QJsonValue &deviceClassJson, vendorJson.toObject().value("deviceClasses").toArray()) { QJsonObject deviceClassObject = deviceClassJson.toObject(); - QStringList missingFields = verifyFields(QStringList() << "id" << "name" << "displyName" << "createMethods" << "paramTypes", deviceClassObject); + QStringList missingFields = verifyFields(QStringList() << "id" << "name" << "displayName" << "createMethods" << "paramTypes", deviceClassObject); if (!missingFields.isEmpty()) { qCWarning(dcDeviceManager) << "Skipping DeviceClass because of missing" << missingFields.join(", ") << deviceClassObject; broken = true; @@ -526,7 +534,7 @@ void DevicePlugin::loadMetaData() } DeviceClass deviceClass(pluginId(), vendorId, deviceClassObject.value("id").toString()); - deviceClass.setName(m_metaData.value("name").toString()); + deviceClass.setName(deviceClassObject.value("name").toString()); deviceClass.setDisplayName(translateValue(m_metaData.value("name").toString(), deviceClassObject.value("displayName").toString())); DeviceClass::CreateMethods createMethods; foreach (const QJsonValue &createMethodValue, deviceClassObject.value("createMethods").toArray()) { @@ -569,7 +577,7 @@ void DevicePlugin::loadMetaData() "in deviceClass " << deviceClass.name() << ". Falling back to SetupMethodJustAdd."; deviceClass.setSetupMethod(DeviceClass::SetupMethodJustAdd); } - deviceClass.setPairingInfo(translateValue(m_metaData.value("idName").toString(), deviceClassObject.value("pairingInfo").toString())); + deviceClass.setPairingInfo(translateValue(m_metaData.value("name").toString(), deviceClassObject.value("pairingInfo").toString())); QPair > paramTypesVerification = parseParamTypes(deviceClassObject.value("paramTypes").toArray()); if (!paramTypesVerification.first) { broken = true; @@ -664,7 +672,8 @@ void DevicePlugin::loadMetaData() eventType.setName(m_metaData.value("name").toString()); eventType.setDisplayName(translateValue(m_metaData.value("name").toString(), st.value("displayNameEvent").toString())); - ParamType paramType(ParamTypeId(stateType.id().toString()), translateValue(m_metaData.value("idName").toString(), st.value("name").toString()), stateType.type()); + ParamType paramType(ParamTypeId(stateType.id().toString()), st.value("name").toString(), stateType.type()); + paramType.setDisplayName(translateValue(m_metaData.value("name").toString(), st.value("displayName").toString())); paramType.setAllowedValues(stateType.possibleValues()); paramType.setDefaultValue(stateType.defaultValue()); paramType.setMinValue(stateType.minValue()); @@ -692,7 +701,7 @@ void DevicePlugin::loadMetaData() QJsonObject at = actionTypesJson.toObject(); QStringList missingFields = verifyFields(QStringList() << "id" << "name" << "displayName", at); if (!missingFields.isEmpty()) { - qCWarning(dcDeviceManager) << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in actionTypes"; + qCWarning(dcDeviceManager) << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in actionTypes" << at; broken = true; break; } @@ -719,7 +728,7 @@ void DevicePlugin::loadMetaData() QJsonObject et = eventTypesJson.toObject(); QStringList missingFields = verifyFields(QStringList() << "id" << "name" << "displayName", et); if (!missingFields.isEmpty()) { - qCWarning(dcDeviceManager) << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in eventTypes"; + qCWarning(dcDeviceManager) << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in eventTypes:" << et; broken = true; break; } diff --git a/libguh/plugin/deviceplugin.h b/libguh/plugin/deviceplugin.h index 89d27407..a6633f4f 100644 --- a/libguh/plugin/deviceplugin.h +++ b/libguh/plugin/deviceplugin.h @@ -58,8 +58,9 @@ public: virtual void init() {} - QString pluginName() const; PluginId pluginId() const; + QString pluginName() const; + QString pluginDisplayName() const; QList supportedVendors() const; QList supportedDevices() const; diff --git a/libguh/types/paramtype.cpp b/libguh/types/paramtype.cpp index 9fe92b46..f832ea61 100644 --- a/libguh/types/paramtype.cpp +++ b/libguh/types/paramtype.cpp @@ -66,6 +66,18 @@ void ParamType::setName(const QString &name) m_name = name; } +/*! Returns the displayName of this ParamType, to be shown to the user, translated. */ +QString ParamType::displayName() const +{ + return m_displayName; +} + +/*! Sets the displayName of this ParamType, to be shown to the user, translated. */ +void ParamType::setDisplayName(const QString &displayName) +{ + m_displayName = displayName; +} + /*! Returns the index of this \l{ParamType}. The index of an \l{ParamType} indicates the order in the corresponding Type. */ int ParamType::index() const { diff --git a/libguh/types/paramtype.h b/libguh/types/paramtype.h index 11d77603..e86f133c 100644 --- a/libguh/types/paramtype.h +++ b/libguh/types/paramtype.h @@ -41,6 +41,9 @@ public: QString name() const; void setName(const QString &name); + QString displayName() const; + void setDisplayName(const QString &displayName); + int index() const; void setIndex(const int &index); @@ -76,6 +79,7 @@ public: private: ParamTypeId m_id; QString m_name; + QString m_displayName; int m_index; QVariant::Type m_type; QVariant m_defaultValue; diff --git a/libguh/types/vendor.cpp b/libguh/types/vendor.cpp index 0f36298c..9c05624c 100644 --- a/libguh/types/vendor.cpp +++ b/libguh/types/vendor.cpp @@ -62,3 +62,15 @@ void Vendor::setName(const QString &name) { m_name = name; } + +/*! Returns the name of this Vendor, to be shown to the user, translated. */ +QString Vendor::displayName() const +{ + return m_displayName; +} + +/*! Sets the name of this Vendor, to be shown to the user, translated. */ +void Vendor::setDisplayName(const QString &displayName) +{ + m_displayName = displayName; +} diff --git a/libguh/types/vendor.h b/libguh/types/vendor.h index dd94b271..1e339649 100644 --- a/libguh/types/vendor.h +++ b/libguh/types/vendor.h @@ -40,9 +40,13 @@ public: QString name() const; void setName(const QString &name); + QString displayName() const; + void setDisplayName(const QString &displayName); + private: VendorId m_id; QString m_name; + QString m_displayName; }; #endif // VENDOR_H diff --git a/plugins/mock/devicepluginmock.json b/plugins/mock/devicepluginmock.json index 412b59d0..8e054b19 100644 --- a/plugins/mock/devicepluginmock.json +++ b/plugins/mock/devicepluginmock.json @@ -1,6 +1,6 @@ { - "displayName": "Mock Devices", "name": "MockDevice", + "displayName": "Mock Devices", "id": "727a4a9a-c187-446f-aadf-f1b2220607d1", "paramTypes": [ { @@ -8,7 +8,6 @@ "name": "configParamInt", "displayName": "configParamInt", "type": "int", - "index": 0, "defaultValue": 42, "minValue": 1, "maxValue": 50 @@ -18,15 +17,14 @@ "name": "configParamBool", "displayName": "configParamBool", "type": "bool", - "index": 1, "defaultValue": true } ], "vendors": [ { - "displayName": "guh", - "name": "guh", "id": "2062d64d-3232-433c-88bc-0d33c0ba2ba6", + "name": "guh", + "displayName": "guh", "deviceClasses": [ { "id": "753f0d32-0468-4d08-82ed-1964aab03298", @@ -48,7 +46,6 @@ "name": "resultCount", "displayName": "resultCount", "type": "int", - "index": 0, "defaultValue": 2, "allowedValues": [1, 2] } @@ -58,7 +55,6 @@ "id": "d4f06047-125e-4479-9810-b54c189917f5", "name": "httpport", "displayName": "http port", - "index": 0, "type": "int" }, { @@ -66,7 +62,6 @@ "name": "async", "displayName": "async", "type": "bool", - "index": 1, "defaultValue": false, "readOnly": true }, @@ -74,7 +69,6 @@ "id": "ae8f8901-f2c1-42a5-8111-6d2fc8e4c1e4", "name": "broken", "displayName": "broken", - "index": 2, "type": "bool", "defaultValue": false } @@ -85,7 +79,6 @@ "name": "int", "displayName": "Dummy int state", "displayNameEvent": "Dummy int state changed", - "index": 0, "defaultValue": 10, "graphRelevant": true, "type": "int" @@ -95,7 +88,6 @@ "name": "boolValue", "displayName": "Dummy bool state", "displayNameEvent": "Dummy bool state changed", - "index": 1, "defaultValue": false, "type": "bool", "cached": false @@ -104,21 +96,20 @@ "eventTypes": [ { "id": "45bf3752-0fc6-46b9-89fd-ffd878b5b22b", - "index": 0, + "name": "mockEvent1", "displayName": "Mock Event 1", "graphRelevant": true }, { "id": "863d5920-b1cf-4eb9-88bd-8f7b8583b1cf", + "name": "mockEvent2", "displayName": "Mock Event 2", - "index": 1, "paramTypes": [ { "id": "0550e16d-60b9-4ba5-83f4-4d3cee656121", "name": "mockParamInt", "displayName": "mockParamInt", "type": "int", - "index": 0, "defaultValue": 10 } ] @@ -129,20 +120,17 @@ "id": "dea0f4e1-65e3-4981-8eaa-2701c53a9185", "displayName": "Mock Action 1 (with params)", "name": "withParams", - "index": 0, "paramTypes": [ { "id": "a2d3a256-a551-4712-a65b-ecd5a436a1cb", "name": "mockActionParam1", "displayName": "mockActionParam1", - "index": 0, "type": "int" }, { "id": "304a4899-18be-4e3b-94f4-d03be52f3233", "name": "mockActionParam2", "displayName": "mockActionParam2", - "index": 1, "type": "bool" } ] @@ -150,25 +138,21 @@ { "id": "defd3ed6-1a0d-400b-8879-a0202cf39935", "name": "withoutParams", - "index": 1, "displayName": "Mock Action 2 (without params)" }, { "id": "fbae06d3-7666-483e-a39e-ec50fe89054e", "name": "mockAsync", - "index": 2, "displayName": "Mock Action 3 (async)" }, { "id": "df3cf33d-26d5-4577-9132-9823bd33fad0", "name": "mockFailing", - "index": 3, "displayName": "Mock Action 4 (broken)" }, { "id": "bfe89a1d-3497-4121-8318-e77c37537219", "name": "mockAsyncFailing", - "index": 4, "displayName": "Mock Action 5 (async, broken)" } ] @@ -192,7 +176,6 @@ "id": "d4f06047-125e-4479-9810-b54c189917f5", "name": "httpport", "displayName": "http port", - "index": 0, "type": "int" }, { @@ -200,7 +183,6 @@ "name": "async", "displayName": "async", "type": "bool", - "index": 1, "defaultValue": false, "readOnly": true }, @@ -208,7 +190,6 @@ "id": "ae8f8901-f2c1-42a5-8111-6d2fc8e4c1e4", "name": "broken", "displayName": "broken", - "index": 2, "type": "bool", "defaultValue": false } @@ -219,7 +200,6 @@ "name": "int", "displayName": "Dummy int state", "displayNameEvent": "Dummy int state changed", - "index": 0, "defaultValue": 10, "graphRelevant": true, "type": "int" @@ -229,7 +209,6 @@ "name": "boolValue", "displayName": "Dummy bool state", "displayNameEvent": "Dummy bool state changed", - "index": 1, "defaultValue": false, "type": "bool", "cached": false @@ -239,21 +218,18 @@ { "id": "45bf3752-0fc6-46b9-89fd-ffd878b5b22b", "name": "event1", - "index": 0, "displayName": "Mock Event 1" }, { "id": "863d5920-b1cf-4eb9-88bd-8f7b8583b1cf", "name": "event2", "displayName": "Mock Event 2", - "index": 1, "paramTypes": [ { "id": "0550e16d-60b9-4ba5-83f4-4d3cee656121", "name": "mockParamInt", "displayName": "mockParamInt", "type": "int", - "index": 0, "defaultValue": 10 } ] @@ -262,44 +238,41 @@ "actionTypes": [ { "id": "dea0f4e1-65e3-4981-8eaa-2701c53a9185", - "displayName": "Mock Action 1 (with params)", "name": "withParams", - "index": 0, + "displayName": "Mock Action 1 (with params)", "paramTypes": [ { "id": "a2d3a256-a551-4712-a65b-ecd5a436a1cb", "name": "mockActionParam1", "displayName": "mockActionParam1", - "index": 0, "type": "int" }, { "id": "304a4899-18be-4e3b-94f4-d03be52f3233", "name": "mockActionParam2", "displayName": "mockActionParam2", - "index": 1, "type": "bool" } ] }, { "id": "defd3ed6-1a0d-400b-8879-a0202cf39935", - "index": 1, + "name": "mockActionNoParms", "displayName": "Mock Action 2 (without params)" }, { "id": "fbae06d3-7666-483e-a39e-ec50fe89054e", - "index": 2, + "name": "mockActionAsync", "displayName": "Mock Action 3 (async)" }, { "id": "df3cf33d-26d5-4577-9132-9823bd33fad0", - "index": 3, + "name": "mockActionBroken", "displayName": "Mock Action 4 (broken)" }, { "id": "bfe89a1d-3497-4121-8318-e77c37537219", - "index": 4, + "name": "mockActionAsyncBroken", "displayName": "Mock Action 5 (async, broken)" } ] @@ -325,7 +298,6 @@ "name": "resultCount", "displayName": "resultCount", "type": "int", - "index": 0, "defaultValue": 2, "allowedValues": [1, 2] } @@ -337,7 +309,6 @@ "displayName": "color", "displayNameEvent": "color changed", "displayNameAction": "Set color", - "index": 0, "type": "QColor", "defaultValue": "#000000", "ruleRelevant": false, @@ -351,7 +322,6 @@ "displayNameEvent": "percentage changed", "displayNameAction": "Set percentage", "type": "int", - "index": 1, "unit": "Percentage", "defaultValue": 0, "ruleRelevant": false, @@ -366,7 +336,6 @@ "displayNameEvent": "allowed values changed", "displayNameAction": "Set allowed values", "type": "QString", - "index": 2, "defaultValue": "String value 1", "possibleValues": [ "String value 1", @@ -383,7 +352,6 @@ "displayNameEvent": "double value changed", "displayNameAction": "Set double value", "type": "double", - "index": 3, "defaultValue": 0.0, "minValue": -100.0, "maxValue": 100.0, @@ -395,7 +363,6 @@ "displayName": "bool value", "displayNameEvent": "bool value changed", "displayNameAction": "Set bool value", - "index": 4, "type": "bool", "defaultValue": false, "writable": true @@ -405,7 +372,6 @@ { "id": "54646e7c-bc54-4895-81a2-590d72d120f9", "name": "timeout", - "index": 0, "displayName": "Timeout action" } ] @@ -430,7 +396,6 @@ "name": "resultCount", "displayName": "resultCount", "type": "int", - "index": 0, "defaultValue": 2, "allowedValues": [1, 2] } @@ -441,7 +406,6 @@ "name": "pin", "displayName": "pin", "type": "QString", - "index": 0, "inputType": "TextLine", "defaultValue": "243681", "readOnly": true @@ -454,7 +418,6 @@ "displayName": "color", "displayNameEvent": "color changed", "displayNameAction": "Set color", - "index": 0, "type": "QColor", "defaultValue": "#000000", "ruleRelevant": false, @@ -468,7 +431,6 @@ "displayNameEvent": "percentage changed", "displayNameAction": "Set percentage", "type": "int", - "index": 1, "unit": "Percentage", "defaultValue": 0, "ruleRelevant": false, @@ -483,7 +445,6 @@ "displayNameEvent": "allowed values changed", "displayNameAction": "Set allowed values", "type": "QString", - "index": 2, "defaultValue": "String value 1", "possibleValues": [ "String value 1", @@ -500,7 +461,6 @@ "displayNameEvent": "double value changed", "displayNameAction": "Set double value", "type": "double", - "index": 3, "defaultValue": 0.0, "minValue": -100.0, "maxValue": 100.0, @@ -512,7 +472,6 @@ "displayName": "bool value", "displayNameEvent": "bool value changed", "displayNameAction": "Set bool value", - "index": 4, "type": "bool", "defaultValue": false, "writable": true @@ -522,7 +481,6 @@ { "id": "54646e7c-bc54-4895-81a2-590d72d120f9", "name": "timeout", - "index": 0, "displayName": "Timeout action" } ] @@ -547,7 +505,6 @@ "displayName": "bool value", "displayNameEvent": "bool value changed", "displayNameAction": "Set bool value", - "index": 0, "type": "bool", "defaultValue": false, "writable": true @@ -569,7 +526,6 @@ "name": "parentUuid", "displayName": "parent uuid", "type": "QUuid", - "index": 0, "readOnly": true } ], @@ -580,7 +536,6 @@ "displayName": "bool value", "displayNameEvent": "bool value changed", "displayNameAction": "Set bool value", - "index": 0, "type": "bool", "defaultValue": false, "writable": true @@ -602,7 +557,6 @@ "name": "textLine", "displayName": "Text line", "type": "QString", - "index": 0, "inputType": "TextLine", "defaultValue": "This is a text line" }, @@ -611,7 +565,6 @@ "name": "textArea", "displayName": "Text area", "type": "QString", - "index": 1, "inputType": "TextArea", "defaultValue": "This is a text area" }, @@ -620,7 +573,6 @@ "name": "password", "displayName": "Password text", "type": "QString", - "index": 2, "inputType": "Password", "defaultValue": "secret" }, @@ -629,7 +581,6 @@ "name": "search", "displayName": "Search text", "type": "QString", - "index": 3, "inputType": "Search", "defaultValue": "Search text..." }, @@ -638,7 +589,6 @@ "name": "mail", "displayName": "Mail address", "type": "QString", - "index": 4, "inputType": "Mail", "defaultValue": "name@example.com" }, @@ -647,7 +597,6 @@ "name": "ip4", "displayName": "IPv4 address", "type": "QString", - "index": 5, "inputType": "IPv4Address", "defaultValue": "127.0.0.1" }, @@ -656,7 +605,6 @@ "name": "ip6", "displayName": "IPv6 address", "type": "QString", - "index": 6, "inputType": "IPv6Address", "defaultValue": "::1" }, @@ -665,7 +613,6 @@ "name": "url", "displayName": "URL", "type": "QString", - "index": 7, "inputType": "Url", "defaultValue": "http://guh.guru" }, @@ -674,7 +621,6 @@ "name": "mac", "displayName": "Mac address", "type": "QString", - "index": 8, "inputType": "MacAddress", "defaultValue": "11:22:33:aa:bb:cc" }