void Dialog::okClicked() { long pidNumber; if ((0 < (pidNumber = verifyPidFile())) && !verifyFields()) { createConfigFile(); sendSignal((pid_t) pidNumber); } }
/*! Return a list of \l{DeviceClass}{DeviceClasses} describing all the devices supported by this plugin. */ QList<DeviceClass> DevicePlugin::supportedDevices() const { QList<DeviceClass> deviceClasses; foreach (const QJsonValue &vendorJson, m_metaData.value("vendors").toArray()) { bool broken = false; VendorId vendorId = vendorJson.toObject().value("id").toString(); foreach (const QJsonValue &deviceClassJson, vendorJson.toObject().value("deviceClasses").toArray()) { QJsonObject jo = deviceClassJson.toObject(); DeviceClass deviceClass(pluginId(), vendorId, jo.value("deviceClassId").toString()); deviceClass.setName(jo.value("name").toString()); DeviceClass::CreateMethods createMethods; foreach (const QJsonValue &createMethodValue, jo.value("createMethods").toArray()) { if (createMethodValue.toString() == "discovery") { createMethods |= DeviceClass::CreateMethodDiscovery; } else if (createMethodValue.toString() == "auto") { createMethods |= DeviceClass::CreateMethodAuto; } else { createMethods |= DeviceClass::CreateMethodUser; } } deviceClass.setCreateMethods(createMethods); deviceClass.setDiscoveryParamTypes(parseParamTypes(jo.value("discoveryParamTypes").toArray())); QString setupMethod = jo.value("setupMethod").toString(); if (setupMethod == "pushButton") { deviceClass.setSetupMethod(DeviceClass::SetupMethodPushButton); } else if (setupMethod == "displayPin") { deviceClass.setSetupMethod(DeviceClass::SetupMethodDisplayPin); } else if (setupMethod == "enterPin") { deviceClass.setSetupMethod(DeviceClass::SetupMethodEnterPin); } else { deviceClass.setSetupMethod(DeviceClass::SetupMethodJustAdd); } deviceClass.setPairingInfo(jo.value("pairingInfo").toString()); deviceClass.setParamTypes(parseParamTypes(jo.value("paramTypes").toArray())); QList<ActionType> actionTypes; QList<StateType> stateTypes; foreach (const QJsonValue &stateTypesJson, jo.value("stateTypes").toArray()) { QJsonObject st = stateTypesJson.toObject(); QStringList missingFields = verifyFields(QStringList() << "type" << "id" << "name", st); if (!missingFields.isEmpty()) { qCWarning(dcDeviceManager) << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in stateTypes"; broken = true; break; } QVariant::Type t = QVariant::nameToType(st.value("type").toString().toLatin1().data()); StateType stateType(st.value("id").toString()); stateType.setName(st.value("name").toString()); stateType.setType(t); stateType.setUnit(unitStringToUnit(st.value("unit").toString())); stateType.setDefaultValue(st.value("defaultValue").toVariant()); stateTypes.append(stateType); // create ActionType if this StateType is writable if (st.contains("writable")) { ActionType actionType(st.value("id").toString()); actionType.setName("set " + st.value("name").toString()); // Note: fields already checked in StateType ParamType paramType(st.value("name").toString(), t, st.value("defaultValue").toVariant()); if (st.value("writable").toObject().contains("allowedValues")) { QVariantList allowedValues; foreach (const QJsonValue &allowedTypesJson, st.value("writable").toObject().value("allowedValues").toArray()) { allowedValues.append(allowedTypesJson.toVariant()); } paramType.setAllowedValues(allowedValues); } paramType.setInputType(inputTypeStringToInputType(st.value("writable").toObject().value("inputType").toString())); paramType.setUnit(unitStringToUnit(st.value("unit").toString())); paramType.setLimits(st.value("writable").toObject().value("minValue").toVariant(), st.value("writable").toObject().value("maxValue").toVariant()); actionType.setParamTypes(QList<ParamType>() << paramType); actionTypes.append(actionType); } } deviceClass.setStateTypes(stateTypes); foreach (const QJsonValue &actionTypesJson, jo.value("actionTypes").toArray()) { QJsonObject at = actionTypesJson.toObject(); QStringList missingFields = verifyFields(QStringList() << "id" << "name", at); if (!missingFields.isEmpty()) { qCWarning(dcDeviceManager) << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in actionTypes"; broken = true; break; } ActionType actionType(at.value("id").toString()); actionType.setName(at.value("name").toString()); actionType.setParamTypes(parseParamTypes(at.value("paramTypes").toArray())); actionTypes.append(actionType); } deviceClass.setActionTypes(actionTypes); QList<EventType> eventTypes; foreach (const QJsonValue &eventTypesJson, jo.value("eventTypes").toArray()) { QJsonObject et = eventTypesJson.toObject(); QStringList missingFields = verifyFields(QStringList() << "id" << "name", et); if (!missingFields.isEmpty()) { qCWarning(dcDeviceManager) << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in eventTypes"; broken = true; break; } EventType eventType(et.value("id").toString()); eventType.setName(et.value("name").toString()); eventType.setParamTypes(parseParamTypes(et.value("paramTypes").toArray())); eventTypes.append(eventType); } deviceClass.setEventTypes(eventTypes); if (!broken) { deviceClasses.append(deviceClass); } }
void SliderGenerator::slotCreate() { if (verifyFields()) { saveConfig(); openDB::BackendConnector::Iterator slider_it = getSliderParameter(); openDB::Table& _slider = slider_it.result().resultTable(); if (_slider.storage().records() > 0) { // lettura dei vari template std::string main_template, slide_template, label_template, radio_template, checkedradio_template, css_template; openDB::readTemplate(main_template, editMainTemplate->text().toStdString()); openDB::readTemplate(slide_template, editSlideTemplate->text().toStdString()); openDB::readTemplate(label_template, editLabelTemplate->text().toStdString()); openDB::readTemplate(radio_template, editRadioTemplate->text().toStdString()); openDB::readTemplate(checkedradio_template, editRadioCheckedTemplate->text().toStdString()); openDB::readTemplate(css_template, editCSSControlTemplate->text().toStdString()); std::string slides_list, // conterra' il codice html completo di tutte le slide label_list, // conterra' il codice html di tutte le label radio_list, // conterra' il codice html di tutti i radio-button css_list; // conterra' il codice css di tutti i controlli per lo slider unsigned index = 1; // contatore/indice usato per identificare univocamente slide, label, radio-button e // controlli css openDB::BackendConnector::Iterator slides_it = getSlidersSlides(); openDB::Table& slides = slides_it.result().resultTable(); openDB::Storage::Iterator s_it = slides.storage().begin(), s_end = slides.storage().end(); for (; s_it != s_end; s_it++, index++) { std::string slide_tmp = slide_template, label_tmp = label_template, radio_tmp = (s_it == slides.storage().begin() ? checkedradio_template : radio_template), css_tmp = css_template; stringMap par; (*s_it).current(par); par.insert({{slideIndexParName, std::to_string(index)}}); // aggiunta del parametro indice par.insert({{slideOffsetParName, std::to_string((index - 1) * 100)}}); // aggiunta del parametro offset // risoluzione dei parametri openDB::prepare(slide_tmp, par); openDB::prepare(label_tmp, par); openDB::prepare(radio_tmp, par); openDB::prepare(css_tmp, par); // aggiunta alla lista slides_list += slide_tmp; label_list += label_tmp; radio_list += radio_tmp; css_list += css_tmp; } // eliminazione del result per le slide non piu' necessari parentWindow->backendConnector().deleteTransaction(slides_it); /* per ottenere il codice finale dello slider sono necessari due passaggi di preparazione: * 1) sostituire ai parametri slidesTemplateParName, labelTemplateParName, ecc.. i rispettivi valori; * 2) essendo i valori dei parametri di cui sopra anch'essi parametrici si procede a sostituire i parametri coi * valori memorizzati nel database; */ // passo di preparazione 1 stringMap htmlCSS_par = { {slidesTemplateParName, slides_list}, {labelTemplateParName, label_list}, {radioTemplateParName, radio_list}, {cssTemplateParName, css_list} }; openDB::prepare(main_template, htmlCSS_par); // passo di preparazione 2 stringMap slider_par; (*_slider.storage().begin()).current(slider_par); openDB::prepare(main_template, slider_par); // scrittura su file dello slider std::fstream stream(editOutFile->text().toStdString().c_str(), std::ios::out); stream << main_template << std::endl; stream.close(); } // eliminazione del result per lo slider parentWindow->backendConnector().deleteTransaction(slider_it); } }
/*! Return a list of \l{DeviceClass}{DeviceClasses} describing all the devices supported by this plugin. If a DeviceClass has an invalid parameter it will be ignored. */ QList<DeviceClass> DevicePlugin::supportedDevices() const { QList<DeviceClass> deviceClasses; foreach (const QJsonValue &vendorJson, m_metaData.value("vendors").toArray()) { bool broken = false; VendorId vendorId = vendorJson.toObject().value("id").toString(); foreach (const QJsonValue &deviceClassJson, vendorJson.toObject().value("deviceClasses").toArray()) { QJsonObject jo = deviceClassJson.toObject(); DeviceClass deviceClass(pluginId(), vendorId, jo.value("deviceClassId").toString()); deviceClass.setName(jo.value("name").toString()); DeviceClass::CreateMethods createMethods; foreach (const QJsonValue &createMethodValue, jo.value("createMethods").toArray()) { if (createMethodValue.toString() == "discovery") { createMethods |= DeviceClass::CreateMethodDiscovery; } else if (createMethodValue.toString() == "auto") { createMethods |= DeviceClass::CreateMethodAuto; } else if (createMethodValue.toString() == "user") { createMethods |= DeviceClass::CreateMethodUser; } else { qCWarning(dcDeviceManager) << "Unknown createMehtod" << createMethodValue.toString() << "in deviceClass " << deviceClass.name() << ". Falling back to CreateMethodUser."; createMethods |= DeviceClass::CreateMethodUser; } } deviceClass.setCreateMethods(createMethods); deviceClass.setDeviceIcon(loadAndVerifyDeviceIcon(jo.value("deviceIcon").toString())); deviceClass.setDiscoveryParamTypes(parseParamTypes(jo.value("discoveryParamTypes").toArray())); QString setupMethod = jo.value("setupMethod").toString(); if (setupMethod == "pushButton") { deviceClass.setSetupMethod(DeviceClass::SetupMethodPushButton); } else if (setupMethod == "displayPin") { deviceClass.setSetupMethod(DeviceClass::SetupMethodDisplayPin); } else if (setupMethod == "enterPin") { deviceClass.setSetupMethod(DeviceClass::SetupMethodEnterPin); } else if (setupMethod == "justAdd") { qCWarning(dcDeviceManager) << "Unknown setupMehtod" << setupMethod << "in deviceClass " << deviceClass.name() << ". Falling back to SetupMethodJustAdd."; deviceClass.setSetupMethod(DeviceClass::SetupMethodJustAdd); } deviceClass.setPairingInfo(jo.value("pairingInfo").toString()); deviceClass.setParamTypes(parseParamTypes(jo.value("paramTypes").toArray())); QList<DeviceClass::BasicTag> basicTags; foreach (const QJsonValue &basicTagJson, jo.value("basicTags").toArray()) { basicTags.append(loadAndVerifyBasicTag(basicTagJson.toString())); } deviceClass.setBasicTags(basicTags); QList<ActionType> actionTypes; QList<StateType> stateTypes; foreach (const QJsonValue &stateTypesJson, jo.value("stateTypes").toArray()) { QJsonObject st = stateTypesJson.toObject(); QStringList missingFields = verifyFields(QStringList() << "type" << "id" << "name", st); if (!missingFields.isEmpty()) { qCWarning(dcDeviceManager) << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in stateTypes"; broken = true; break; } QVariant::Type t = QVariant::nameToType(st.value("type").toString().toLatin1().data()); StateType stateType(st.value("id").toString()); stateType.setName(st.value("name").toString()); stateType.setType(t); stateType.setUnit(loadAndVerifyUnit(st.value("unit").toString())); stateType.setDefaultValue(st.value("defaultValue").toVariant()); if (st.contains("minValue")) stateType.setMinValue(st.value("minValue").toVariant()); if (st.contains("maxValue")) stateType.setMaxValue(st.value("maxValue").toVariant()); if (st.contains("possibleValues")) { QVariantList possibleValues; foreach (const QJsonValue &possibleValueJson, st.value("possibleValues").toArray()) { possibleValues.append(possibleValueJson.toVariant()); } stateType.setPossibleValues(possibleValues); // inform the plugin developer about the error in the plugin json file Q_ASSERT_X(stateType.possibleValues().contains(stateType.defaultValue()), QString("\"%1\" plugin").arg(pluginName()).toLatin1().data(), QString("The given default value \"%1\" is not in the possible values of the stateType \"%2\".") .arg(stateType.defaultValue().toString()).arg(stateType.name()).toLatin1().data()); } stateTypes.append(stateType); // create ActionType if this StateType is writable if (st.contains("writable") && st.value("writable").toBool()) { // Note: fields already checked in StateType ActionType actionType(ActionTypeId(stateType.id().toString())); actionType.setName("set " + stateType.name()); ParamType paramType(stateType.name(), t, stateType.defaultValue()); paramType.setAllowedValues(stateType.possibleValues()); paramType.setUnit(stateType.unit()); paramType.setLimits(stateType.minValue(), stateType.maxValue()); actionType.setParamTypes(QList<ParamType>() << paramType); actionTypes.append(actionType); } } deviceClass.setStateTypes(stateTypes); foreach (const QJsonValue &actionTypesJson, jo.value("actionTypes").toArray()) { QJsonObject at = actionTypesJson.toObject(); QStringList missingFields = verifyFields(QStringList() << "id" << "name", at); if (!missingFields.isEmpty()) { qCWarning(dcDeviceManager) << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in actionTypes"; broken = true; break; } ActionType actionType(at.value("id").toString()); actionType.setName(at.value("name").toString()); actionType.setParamTypes(parseParamTypes(at.value("paramTypes").toArray())); actionTypes.append(actionType); } deviceClass.setActionTypes(actionTypes); QList<EventType> eventTypes; foreach (const QJsonValue &eventTypesJson, jo.value("eventTypes").toArray()) { QJsonObject et = eventTypesJson.toObject(); QStringList missingFields = verifyFields(QStringList() << "id" << "name", et); if (!missingFields.isEmpty()) { qCWarning(dcDeviceManager) << "Skipping device class" << deviceClass.name() << "because of missing" << missingFields.join(", ") << "in eventTypes"; broken = true; break; } EventType eventType(et.value("id").toString()); eventType.setName(et.value("name").toString()); eventType.setParamTypes(parseParamTypes(et.value("paramTypes").toArray())); eventTypes.append(eventType); } deviceClass.setEventTypes(eventTypes); if (!broken) deviceClasses.append(deviceClass); } }