| 500 | } |
| 501 | |
| 502 | bool QvConfigHandler::p_CHUpdateSubscription(const GroupId &id, const QByteArray &data) |
| 503 | { |
| 504 | CheckValidId(id, false); |
| 505 | // |
| 506 | // ====================================================================================== Begin reading subscription |
| 507 | std::shared_ptr<SubscriptionDecoder> decoder; |
| 508 | |
| 509 | { |
| 510 | const auto type = groups[id].subscriptionOption.type; |
| 511 | for (const auto &plugin : PluginHost->UsablePlugins()) |
| 512 | { |
| 513 | const auto pluginInfo = PluginHost->GetPlugin(plugin); |
| 514 | if (pluginInfo->hasComponent(COMPONENT_SUBSCRIPTION_ADAPTER)) |
| 515 | { |
| 516 | const auto adapterInterface = pluginInfo->pluginInterface->GetSubscriptionAdapter(); |
| 517 | for (const auto &[t, _] : adapterInterface->SupportedSubscriptionTypes()) |
| 518 | { |
| 519 | if (t == type) |
| 520 | decoder = adapterInterface->GetSubscriptionDecoder(t); |
| 521 | } |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | if (decoder == nullptr) |
| 526 | { |
| 527 | QvMessageBoxWarn(nullptr, tr("Cannot Update Subscription"), |
| 528 | tr("Unknown subscription type: %1").arg(type) + NEWLINE + tr("A subscription plugin is missing?")); |
| 529 | return false; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | const auto groupName = groups[id].displayName; |
| 534 | const auto result = decoder->DecodeData(data); |
| 535 | QList<std::pair<QString, CONFIGROOT>> _newConnections; |
| 536 | |
| 537 | for (const auto &[name, json] : result.connections) |
| 538 | { |
| 539 | _newConnections.append({ name, CONFIGROOT(json) }); |
| 540 | } |
| 541 | for (const auto &link : result.links) |
| 542 | { |
| 543 | // Assign a group name, to pass the name check. |
| 544 | QString _alias; |
| 545 | QString errMessage; |
| 546 | QString __groupName = groupName; |
| 547 | const auto connectionConfigMap = ConvertConfigFromString(link.trimmed(), &_alias, &errMessage, &__groupName); |
| 548 | if (!errMessage.isEmpty()) |
| 549 | LOG("Error: ", errMessage); |
| 550 | _newConnections << connectionConfigMap; |
| 551 | } |
| 552 | |
| 553 | if (_newConnections.count() < 5) |
| 554 | { |
| 555 | LOG("Found a subscription with less than 5 connections."); |
| 556 | if (QvMessageBoxAsk( |
| 557 | nullptr, tr("Update Subscription"), |
| 558 | tr("%n entrie(s) have been found from the subscription source, do you want to continue?", "", _newConnections.count())) != Yes) |
| 559 | return false; |
nothing calls this directly
no test coverage detected