diff --git a/client/ui/models/api/apiServicesModel.cpp b/client/ui/models/api/apiServicesModel.cpp index de66715bb..53edcf412 100644 --- a/client/ui/models/api/apiServicesModel.cpp +++ b/client/ui/models/api/apiServicesModel.cpp @@ -37,8 +37,6 @@ namespace constexpr char isAvailable[] = "is_available"; - constexpr char supportInfo[] = "support_info"; - constexpr char subscriptionPlans[] = "subscription_plans"; constexpr char benefits[] = "benefits"; } @@ -176,8 +174,8 @@ QVariant ApiServicesModel::data(const QModelIndex &index, int role) const case SubscriptionPlansRole: { return apiServiceData.subscriptionPlans; } - case BenefitPanelRowsRole: { - return buildBenefitPanelRows(apiServiceData); + case BenefitRowsRole: { + return buildBenefitRows(apiServiceData); } } @@ -306,7 +304,7 @@ QHash ApiServicesModel::roleNames() const roles[EndDateRole] = "endDate"; roles[OrderRole] = "order"; roles[SubscriptionPlansRole] = "subscriptionPlans"; - roles[BenefitPanelRowsRole] = "benefitRows"; + roles[BenefitRowsRole] = "benefitRows"; return roles; } @@ -333,9 +331,9 @@ ApiServicesModel::ApiServicesData ApiServicesModel::getApiServicesData(const QJs serviceData.serviceInfo.features = serviceDescription.value(configKey::features).toString(); serviceData.subscriptionPlans = jsonObjectArrayToVariantList(serviceDescription.value(configKey::subscriptionPlans).toArray()); - serviceData.benefitsConfig = serviceDescription.value(configKey::benefits).toArray(); + serviceData.benefits = serviceDescription.value(configKey::benefits).toArray(); - serviceData.supportInfo = data.value(configKey::supportInfo).toObject(); + serviceData.supportInfo = data.value(apiDefs::key::supportInfo).toObject(); serviceData.type = serviceType; serviceData.protocol = serviceProtocol; @@ -381,8 +379,8 @@ QString ApiServicesModel::benefitInjectValue(const QString &injectKey, const Ser return formatPriceForBenefit(info.price); } - if (injectKey == QLatin1String("support_telegram")) { - const QString handle = supportInfo.value(QStringLiteral("telegram")).toString().trimmed(); + if (injectKey == apiDefs::key::telegram) { + const QString handle = supportInfo.value(apiDefs::key::telegram).toString().trimmed(); if (handle.isEmpty()) { return QStringLiteral("—"); } @@ -394,10 +392,10 @@ QString ApiServicesModel::benefitInjectValue(const QString &injectKey, const Ser return QString(); } -QVariantList ApiServicesModel::buildBenefitPanelRows(const ApiServicesData &service) const +QVariantList ApiServicesModel::buildBenefitRows(const ApiServicesData &service) const { QVariantList out; - for (const QJsonValue &v : service.benefitsConfig) { + for (const QJsonValue &v : service.benefits) { if (!v.isObject()) { continue; } @@ -420,8 +418,8 @@ QVariantList ApiServicesModel::buildBenefitPanelRows(const ApiServicesData &serv m.insert(QStringLiteral("icon"), iconUrlFromGatewayBenefitIcon(iconKey)); m.insert(QStringLiteral("title"), title); m.insert(QStringLiteral("body"), body); - if (o.value(QStringLiteral("body_accent")).toBool()) { - m.insert(QStringLiteral("body_accent"), true); + if (o.value(QStringLiteral("accent")).toBool()) { + m.insert(QStringLiteral("accent"), true); } out.append(m); } diff --git a/client/ui/models/api/apiServicesModel.h b/client/ui/models/api/apiServicesModel.h index 2ac221203..d1f57c0ec 100644 --- a/client/ui/models/api/apiServicesModel.h +++ b/client/ui/models/api/apiServicesModel.h @@ -24,7 +24,7 @@ public: EndDateRole, OrderRole, SubscriptionPlansRole, - BenefitPanelRowsRole + BenefitRowsRole }; explicit ApiServicesModel(QObject *parent = nullptr); @@ -92,12 +92,12 @@ private: QJsonArray availableCountries; QVariantList subscriptionPlans; - QJsonArray benefitsConfig; + QJsonArray benefits; }; ApiServicesData getApiServicesData(const QJsonObject &data); - QVariantList buildBenefitPanelRows(const ApiServicesData &service) const; + QVariantList buildBenefitRows(const ApiServicesData &service) const; QString benefitInjectValue(const QString &injectKey, const ServiceInfo &info, const QJsonObject &supportInfo) const; QString formatPriceForBenefit(const QString &rawPrice) const; diff --git a/client/ui/qml/Components/BenefitRow.qml b/client/ui/qml/Components/BenefitRow.qml index db18254af..07b547f12 100644 --- a/client/ui/qml/Components/BenefitRow.qml +++ b/client/ui/qml/Components/BenefitRow.qml @@ -11,7 +11,7 @@ RowLayout { property string iconSource: "" property string titleText: "" property string bodyText: "" - property bool bodyAccent: false + property bool accent: false spacing: 12 @@ -44,14 +44,14 @@ RowLayout { id: bodyLabel width: parent.width text: root.bodyText - color: root.bodyAccent ? AmneziaStyle.color.goldenApricot : AmneziaStyle.color.mutedGray + color: root.accent ? AmneziaStyle.color.goldenApricot : AmneziaStyle.color.mutedGray font.pixelSize: 14 wrapMode: Text.Wrap } MouseArea { anchors.fill: bodyLabel - visible: root.bodyAccent && root.bodyText.length > 0 + visible: root.accent && root.bodyText.length > 0 cursorShape: Qt.PointingHandCursor onClicked: { var t = root.bodyText.trim() diff --git a/client/ui/qml/Components/BenefitsPanel.qml b/client/ui/qml/Components/BenefitsPanel.qml index 8d5244c83..86ed1fd52 100644 --- a/client/ui/qml/Components/BenefitsPanel.qml +++ b/client/ui/qml/Components/BenefitsPanel.qml @@ -33,7 +33,7 @@ Rectangle { iconSource: root.benefitItems[index].icon titleText: root.benefitItems[index].title bodyText: root.benefitItems[index].body - bodyAccent: !!root.benefitItems[index].body_accent + accent: !!root.benefitItems[index].accent } } } diff --git a/client/ui/qml/Pages2/PageSetupWizardApiPremiumInfo.qml b/client/ui/qml/Pages2/PageSetupWizardApiPremiumInfo.qml index cb634fca1..15f22fb79 100644 --- a/client/ui/qml/Pages2/PageSetupWizardApiPremiumInfo.qml +++ b/client/ui/qml/Pages2/PageSetupWizardApiPremiumInfo.qml @@ -13,31 +13,28 @@ import "../Components" PageType { id: root - // ApiServicesModel selection is amnezia-premium (set in PageSetupWizardApiServicesList before navigation). - property var subscriptionPlans: [] property var benefitRows: [] - property int selectedGatewayPlanIndex: 0 + property int selectedPlanIndex: 0 property string premiumFeaturesHtml: "" property string premiumHeaderName: "" property string premiumHeaderDescription: "" - readonly property var currentGatewayPlan: subscriptionPlans[selectedGatewayPlanIndex] + readonly property var currentPlan: subscriptionPlans[selectedPlanIndex] function syncFromModel() { root.subscriptionPlans = ApiServicesModel.getSelectedServiceData("subscriptionPlans") root.benefitRows = ApiServicesModel.getSelectedServiceData("benefitRows") - root.selectedGatewayPlanIndex = 0 + root.selectedPlanIndex = 0 for (var i = 0; i < root.subscriptionPlans.length; ++i) { if (root.subscriptionPlans[i].recommended) { - root.selectedGatewayPlanIndex = i + root.selectedPlanIndex = i break } } - root.premiumFeaturesHtml = String(ApiServicesModel.getSelectedServiceData("features")).replace("%1", - LanguageModel.getCurrentSiteUrl("free")).replace("/free", "") + root.premiumFeaturesHtml = String(ApiServicesModel.getSelectedServiceData("features")).replace("%1", LanguageModel.getCurrentSiteUrl("free")).replace("/free", "") root.premiumHeaderName = String(ApiServicesModel.getSelectedServiceData("name")) root.premiumHeaderDescription = String(ApiServicesModel.getSelectedServiceData("serviceDescription")) } @@ -118,14 +115,14 @@ PageType { Layout.rightMargin: 16 Layout.bottomMargin: index === root.subscriptionPlans.length - 1 ? 24 : 12 - selected: root.selectedGatewayPlanIndex === index + selected: root.selectedPlanIndex === index primaryLeft: String(plan.primary_left) primaryRight: String(plan.primary_right) subtitle: String(plan.subtitle) showRecommendedBadge: !!plan.recommended recommendedText: qsTr("Recommended") - onSelectRequested: root.selectedGatewayPlanIndex = index + onSelectRequested: root.selectedPlanIndex = index } } @@ -258,7 +255,7 @@ PageType { anchors.bottomMargin: 16 + SettingsController.safeAreaBottomMargin text: { - var plan = root.currentGatewayPlan + var plan = root.currentPlan if (!plan) { return qsTr("Continue") } @@ -266,7 +263,7 @@ PageType { } clickedFunc: function() { - var plan = root.currentGatewayPlan + var plan = root.currentPlan if (!plan) { return }