| 18 | |
| 19 | |
| 20 | void Model::fromJson(json_t* rootJ) { |
| 21 | assert(plugin); |
| 22 | |
| 23 | json_t* nameJ = json_object_get(rootJ, "name"); |
| 24 | if (nameJ) |
| 25 | name = json_string_value(nameJ); |
| 26 | if (name == "") |
| 27 | throw Exception("Module %s/%s has no name", plugin->slug.c_str(), slug.c_str()); |
| 28 | |
| 29 | json_t* descriptionJ = json_object_get(rootJ, "description"); |
| 30 | if (descriptionJ) |
| 31 | description = json_string_value(descriptionJ); |
| 32 | |
| 33 | // Tags |
| 34 | tagIds.clear(); |
| 35 | json_t* tagsJ = json_object_get(rootJ, "tags"); |
| 36 | if (tagsJ) { |
| 37 | size_t i; |
| 38 | json_t* tagJ; |
| 39 | json_array_foreach(tagsJ, i, tagJ) { |
| 40 | std::string tag = json_string_value(tagJ); |
| 41 | int tagId = tag::findId(tag); |
| 42 | if (tagId < 0) { |
| 43 | // WARN("Module %s/%s has invalid tag \"%s\"", plugin->slug.c_str(), slug.c_str(), tag.c_str()); |
| 44 | continue; |
| 45 | } |
| 46 | |
| 47 | // Omit duplicates |
| 48 | auto it = std::find(tagIds.begin(), tagIds.end(), tagId); |
| 49 | if (it != tagIds.end()) { |
| 50 | // WARN("Module %s/%s has duplicate tag \"%s\"", plugin->slug.c_str(), slug.c_str(), tag.c_str()); |
| 51 | continue; |
| 52 | } |
| 53 | |
| 54 | tagIds.push_back(tagId); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | // manualUrl |
| 59 | json_t* manualUrlJ = json_object_get(rootJ, "manualUrl"); |
| 60 | if (manualUrlJ) |
| 61 | manualUrl = json_string_value(manualUrlJ); |
| 62 | |
| 63 | // modularGridUrl |
| 64 | json_t* modularGridUrlJ = json_object_get(rootJ, "modularGridUrl"); |
| 65 | if (modularGridUrlJ) |
| 66 | modularGridUrl = json_string_value(modularGridUrlJ); |
| 67 | |
| 68 | // hidden |
| 69 | json_t* hiddenJ = json_object_get(rootJ, "hidden"); |
| 70 | // "disabled" was a deprecated alias in Rack <2 |
| 71 | if (!hiddenJ) |
| 72 | hiddenJ = json_object_get(rootJ, "disabled"); |
| 73 | // "deprecated" was a deprecated alias in Rack <2.2.4 |
| 74 | if (!hiddenJ) |
| 75 | hiddenJ = json_object_get(rootJ, "deprecated"); |
| 76 | if (hiddenJ) { |
| 77 | // Don't un-hide Model if already hidden by C++ |