feature: added issued configs info parsing
This commit is contained in:
parent
eda24765e7
commit
c2b17c128d
6 changed files with 87 additions and 28 deletions
|
@ -26,6 +26,22 @@ namespace apiDefs
|
|||
constexpr QLatin1String stackType("stack_type");
|
||||
|
||||
constexpr QLatin1String vpnKey("vpn_key");
|
||||
|
||||
constexpr QLatin1String installationUuid("installation_uuid");
|
||||
constexpr QLatin1String workerLastUpdated("worker_last_updated");
|
||||
constexpr QLatin1String lastDownloaded("last_downloaded");
|
||||
constexpr QLatin1String sourceType("source_type");
|
||||
|
||||
constexpr QLatin1String serverCountryCode("server_country_code");
|
||||
constexpr QLatin1String serverCountryName("server_country_name");
|
||||
|
||||
constexpr QLatin1String osVersion("os_version");
|
||||
|
||||
constexpr QLatin1String availableCountries("available_countries");
|
||||
constexpr QLatin1String activeDeviceCount("active_device_count");
|
||||
constexpr QLatin1String maxDeviceCount("max_device_count");
|
||||
constexpr QLatin1String subscriptionEndDate("subscription_end_date");
|
||||
constexpr QLatin1String issuedConfigs("issued_configs");
|
||||
}
|
||||
|
||||
const int requestTimeoutMsecs = 12 * 1000; // 12 secs
|
||||
|
|
|
@ -68,4 +68,5 @@ bool ApiSettingsController::getAccountInfo()
|
|||
void ApiSettingsController::updateApiCountryModel()
|
||||
{
|
||||
m_apiCountryModel->updateModel(m_apiAccountInfoModel->getAvailableCountries(), "");
|
||||
m_apiCountryModel->updateIssuedConfigsInfo(m_apiAccountInfoModel->getIssuedConfigsInfo());
|
||||
}
|
||||
|
|
|
@ -8,14 +8,6 @@
|
|||
namespace
|
||||
{
|
||||
Logger logger("AccountInfoModel");
|
||||
|
||||
namespace configKey
|
||||
{
|
||||
constexpr char availableCountries[] = "available_countries";
|
||||
constexpr char activeDeviceCount[] = "active_device_count";
|
||||
constexpr char maxDeviceCount[] = "max_device_count";
|
||||
constexpr char subscriptionEndDate[] = "subscription_end_date";
|
||||
}
|
||||
}
|
||||
|
||||
ApiAccountInfoModel::ApiAccountInfoModel(QObject *parent) : QAbstractListModel(parent)
|
||||
|
@ -77,11 +69,12 @@ void ApiAccountInfoModel::updateModel(const QJsonObject &accountInfoObject, cons
|
|||
|
||||
AccountInfoData accountInfoData;
|
||||
|
||||
m_availableCountries = accountInfoObject.value(configKey::availableCountries).toArray();
|
||||
m_availableCountries = accountInfoObject.value(apiDefs::key::availableCountries).toArray();
|
||||
m_issuedConfigsInfo = accountInfoObject.value(apiDefs::key::issuedConfigs).toArray();
|
||||
|
||||
accountInfoData.activeDeviceCount = accountInfoObject.value(configKey::activeDeviceCount).toInt();
|
||||
accountInfoData.maxDeviceCount = accountInfoObject.value(configKey::maxDeviceCount).toInt();
|
||||
accountInfoData.subscriptionEndDate = accountInfoObject.value(configKey::subscriptionEndDate).toString();
|
||||
accountInfoData.activeDeviceCount = accountInfoObject.value(apiDefs::key::activeDeviceCount).toInt();
|
||||
accountInfoData.maxDeviceCount = accountInfoObject.value(apiDefs::key::maxDeviceCount).toInt();
|
||||
accountInfoData.subscriptionEndDate = accountInfoObject.value(apiDefs::key::subscriptionEndDate).toString();
|
||||
|
||||
accountInfoData.configType = apiUtils::getConfigType(serverConfig);
|
||||
|
||||
|
@ -108,6 +101,11 @@ QJsonArray ApiAccountInfoModel::getAvailableCountries()
|
|||
return m_availableCountries;
|
||||
}
|
||||
|
||||
QJsonArray ApiAccountInfoModel::getIssuedConfigsInfo()
|
||||
{
|
||||
return m_issuedConfigsInfo;
|
||||
}
|
||||
|
||||
QString ApiAccountInfoModel::getTelegramBotLink()
|
||||
{
|
||||
if (m_accountInfoData.configType == apiDefs::ConfigType::AmneziaFreeV3) {
|
||||
|
|
|
@ -31,6 +31,7 @@ public slots:
|
|||
QVariant data(const QString &roleString);
|
||||
|
||||
QJsonArray getAvailableCountries();
|
||||
QJsonArray getIssuedConfigsInfo();
|
||||
QString getTelegramBotLink();
|
||||
|
||||
protected:
|
||||
|
@ -48,6 +49,7 @@ private:
|
|||
|
||||
AccountInfoData m_accountInfoData;
|
||||
QJsonArray m_availableCountries;
|
||||
QJsonArray m_issuedConfigsInfo;
|
||||
};
|
||||
|
||||
#endif // APIACCOUNTINFOMODEL_H
|
||||
|
|
|
@ -2,17 +2,12 @@
|
|||
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "core/api/apiDefs.h"
|
||||
#include "logger.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
Logger logger("ApiCountryModel");
|
||||
|
||||
namespace configKey
|
||||
{
|
||||
constexpr char serverCountryCode[] = "server_country_code";
|
||||
constexpr char serverCountryName[] = "server_country_name";
|
||||
}
|
||||
}
|
||||
|
||||
ApiCountryModel::ApiCountryModel(QObject *parent) : QAbstractListModel(parent)
|
||||
|
@ -30,17 +25,19 @@ QVariant ApiCountryModel::data(const QModelIndex &index, int role) const
|
|||
if (!index.isValid() || index.row() < 0 || index.row() >= static_cast<int>(rowCount()))
|
||||
return QVariant();
|
||||
|
||||
QJsonObject countryInfo = m_countries.at(index.row()).toObject();
|
||||
CountryInfo countryInfo = m_countries.at(index.row());
|
||||
IssuedConfigInfo issuedConfigInfo = m_issuedConfigs.value(countryInfo.countryCode);
|
||||
bool isIssued = !issuedConfigInfo.lastDownloaded.isEmpty();
|
||||
|
||||
switch (role) {
|
||||
case CountryCodeRole: {
|
||||
return countryInfo.value(configKey::serverCountryCode).toString();
|
||||
return countryInfo.countryCode;
|
||||
}
|
||||
case CountryNameRole: {
|
||||
return countryInfo.value(configKey::serverCountryName).toString();
|
||||
return countryInfo.countryName;
|
||||
}
|
||||
case CountryImageCodeRole: {
|
||||
return countryInfo.value(configKey::serverCountryCode).toString().toUpper();
|
||||
return countryInfo.countryCode.toUpper();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,13 +48,39 @@ void ApiCountryModel::updateModel(const QJsonArray &countries, const QString &cu
|
|||
{
|
||||
beginResetModel();
|
||||
|
||||
m_countries = countries;
|
||||
for (int i = 0; i < m_countries.size(); i++) {
|
||||
if (m_countries.at(i).toObject().value(configKey::serverCountryCode).toString() == currentCountryCode) {
|
||||
m_countries.clear();
|
||||
for (int i = 0; i < countries.size(); i++) {
|
||||
CountryInfo countryInfo;
|
||||
QJsonObject countryObject = countries.at(i).toObject();
|
||||
|
||||
countryInfo.countryName = countryObject.value(apiDefs::key::serverCountryName).toString();
|
||||
countryInfo.countryCode = countryObject.value(apiDefs::key::serverCountryCode).toString();
|
||||
|
||||
if (countryInfo.countryCode == currentCountryCode) {
|
||||
m_currentIndex = i;
|
||||
emit currentIndexChanged(m_currentIndex);
|
||||
break;
|
||||
}
|
||||
m_countries.push_back(countryInfo);
|
||||
}
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void ApiCountryModel::updateIssuedConfigsInfo(const QJsonArray &issuedConfigs)
|
||||
{
|
||||
beginResetModel();
|
||||
|
||||
for (int i = 0; i < issuedConfigs.size(); i++) {
|
||||
IssuedConfigInfo issuedConfigInfo;
|
||||
QJsonObject issuedConfigObject = issuedConfigs.at(i).toObject();
|
||||
|
||||
issuedConfigInfo.installationUuid = issuedConfigObject.value(apiDefs::key::installationUuid).toString();
|
||||
issuedConfigInfo.workerLastUpdated = issuedConfigObject.value(apiDefs::key::workerLastUpdated).toString();
|
||||
issuedConfigInfo.lastDownloaded = issuedConfigObject.value(apiDefs::key::lastDownloaded).toString();
|
||||
issuedConfigInfo.sourceType = issuedConfigObject.value(apiDefs::key::sourceType).toString();
|
||||
issuedConfigInfo.osVersion = issuedConfigObject.value(apiDefs::key::osVersion).toString();
|
||||
|
||||
m_issuedConfigs.insert(issuedConfigObject.value(apiDefs::key::serverCountryCode).toString(), issuedConfigInfo);
|
||||
}
|
||||
|
||||
endResetModel();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define APICOUNTRYMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QHash>
|
||||
#include <QJsonArray>
|
||||
|
||||
class ApiCountryModel : public QAbstractListModel
|
||||
|
@ -12,7 +13,8 @@ public:
|
|||
enum Roles {
|
||||
CountryNameRole = Qt::UserRole + 1,
|
||||
CountryCodeRole,
|
||||
CountryImageCodeRole
|
||||
CountryImageCodeRole,
|
||||
IsIssuedRole
|
||||
};
|
||||
|
||||
explicit ApiCountryModel(QObject *parent = nullptr);
|
||||
|
@ -25,6 +27,7 @@ public:
|
|||
|
||||
public slots:
|
||||
void updateModel(const QJsonArray &countries, const QString ¤tCountryCode);
|
||||
void updateIssuedConfigsInfo(const QJsonArray &issuedConfigs);
|
||||
|
||||
int getCurrentIndex();
|
||||
void setCurrentIndex(const int i);
|
||||
|
@ -36,7 +39,23 @@ protected:
|
|||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
private:
|
||||
QJsonArray m_countries;
|
||||
struct IssuedConfigInfo
|
||||
{
|
||||
QString installationUuid;
|
||||
QString workerLastUpdated;
|
||||
QString lastDownloaded;
|
||||
QString sourceType;
|
||||
QString osVersion;
|
||||
};
|
||||
|
||||
struct CountryInfo
|
||||
{
|
||||
QString countryName;
|
||||
QString countryCode;
|
||||
};
|
||||
|
||||
QVector<CountryInfo> m_countries;
|
||||
QHash<QString, IssuedConfigInfo> m_issuedConfigs;
|
||||
int m_currentIndex;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue