From f7c144c3932a18e1cd96e1ad7505e53ea706a47d Mon Sep 17 00:00:00 2001 From: phit <2097483+phit@users.noreply.github.com> Date: Sat, 19 Jun 2021 16:19:39 +0200 Subject: GH-3720 Fix UI inconsistencies with Modplatforms Fixes GH-3118 Fixes GH-3720 Fixes GH-3731 Icons and Ok button state will now switch consistently when moving between tabs. ATLaunchers packlist is now no longer redownloaded each time you open its Tab. All lists are striped now. And all search and filter fields now have a placeholder text. --- .../pages/modplatform/technic/TechnicModel.cpp | 17 +++- .../pages/modplatform/technic/TechnicPage.cpp | 103 ++++++++++----------- .../pages/modplatform/technic/TechnicPage.ui | 6 +- 3 files changed, 69 insertions(+), 57 deletions(-) (limited to 'application/pages/modplatform/technic') diff --git a/application/pages/modplatform/technic/TechnicModel.cpp b/application/pages/modplatform/technic/TechnicModel.cpp index bf256ab6..a240a94a 100644 --- a/application/pages/modplatform/technic/TechnicModel.cpp +++ b/application/pages/modplatform/technic/TechnicModel.cpp @@ -72,7 +72,7 @@ int Technic::ListModel::rowCount(const QModelIndex&) const void Technic::ListModel::searchWithTerm(const QString& term) { - if(currentSearchTerm == term) { + if(currentSearchTerm == term && currentSearchTerm.isNull() == term.isNull()) { return; } currentSearchTerm = term; @@ -93,9 +93,18 @@ void Technic::ListModel::searchWithTerm(const QString& term) void Technic::ListModel::performSearch() { NetJob *netJob = new NetJob("Technic::Search"); - auto searchUrl = QString( - "https://api.technicpack.net/search?build=multimc&q=%1" - ).arg(currentSearchTerm); + QString searchUrl = ""; + if (currentSearchTerm.isEmpty()) { + searchUrl = QString( + "https://api.technicpack.net/trending?build=multimc" + ).arg(currentSearchTerm); + } + else + { + searchUrl = QString( + "https://api.technicpack.net/search?build=multimc&q=%1" + ).arg(currentSearchTerm); + } netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response)); jobPtr = netJob; jobPtr->start(); diff --git a/application/pages/modplatform/technic/TechnicPage.cpp b/application/pages/modplatform/technic/TechnicPage.cpp index d246edf2..e836f767 100644 --- a/application/pages/modplatform/technic/TechnicPage.cpp +++ b/application/pages/modplatform/technic/TechnicPage.cpp @@ -60,7 +60,8 @@ bool TechnicPage::shouldDisplay() const void TechnicPage::openedImpl() { - dialog->setSuggestedPack(); + suggestCurrent(); + triggerSearch(); } void TechnicPage::triggerSearch() { @@ -95,8 +96,7 @@ void TechnicPage::suggestCurrent() return; } - QString editedLogoName; - editedLogoName = "technic_" + current.logoName.section(".", 0, 0); + QString editedLogoName = "technic_" + current.logoName.section(".", 0, 0); model->getLogo(current.logoName, current.logoUrl, [this, editedLogoName](QString logo) { dialog->setSuggestedIconFromFile(logo, editedLogoName); @@ -105,67 +105,66 @@ void TechnicPage::suggestCurrent() if (current.metadataLoaded) { metadataLoaded(); + return; } - else + + NetJob *netJob = new NetJob(QString("Technic::PackMeta(%1)").arg(current.name)); + std::shared_ptr response = std::make_shared(); + QString slug = current.slug; + netJob->addNetAction(Net::Download::makeByteArray(QString("https://api.technicpack.net/modpack/%1?build=multimc").arg(slug), response.get())); + QObject::connect(netJob, &NetJob::succeeded, this, [this, response, slug] { - NetJob *netJob = new NetJob(QString("Technic::PackMeta(%1)").arg(current.name)); - std::shared_ptr response = std::make_shared(); - QString slug = current.slug; - netJob->addNetAction(Net::Download::makeByteArray(QString("https://api.technicpack.net/modpack/%1?build=multimc").arg(slug), response.get())); - QObject::connect(netJob, &NetJob::succeeded, this, [this, response, slug] + if (current.slug != slug) { - if (current.slug != slug) - { - return; - } - QJsonParseError parse_error; - QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); - QJsonObject obj = doc.object(); - if(parse_error.error != QJsonParseError::NoError) - { - qWarning() << "Error while parsing JSON response from Technic at " << parse_error.offset << " reason: " << parse_error.errorString(); - qWarning() << *response; - return; - } - if (!obj.contains("url")) + return; + } + QJsonParseError parse_error; + QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); + QJsonObject obj = doc.object(); + if(parse_error.error != QJsonParseError::NoError) + { + qWarning() << "Error while parsing JSON response from Technic at " << parse_error.offset << " reason: " << parse_error.errorString(); + qWarning() << *response; + return; + } + if (!obj.contains("url")) + { + qWarning() << "Json doesn't contain an url key"; + return; + } + QJsonValueRef url = obj["url"]; + if (url.isString()) + { + current.url = url.toString(); + } + else + { + if (!obj.contains("solder")) { - qWarning() << "Json doesn't contain an url key"; + qWarning() << "Json doesn't contain a valid url or solder key"; return; } - QJsonValueRef url = obj["url"]; - if (url.isString()) + QJsonValueRef solderUrl = obj["solder"]; + if (solderUrl.isString()) { - current.url = url.toString(); + current.url = solderUrl.toString(); + current.isSolder = true; } else { - if (!obj.contains("solder")) - { - qWarning() << "Json doesn't contain a valid url or solder key"; - return; - } - QJsonValueRef solderUrl = obj["solder"]; - if (solderUrl.isString()) - { - current.url = solderUrl.toString(); - current.isSolder = true; - } - else - { - qWarning() << "Json doesn't contain a valid url or solder key"; - return; - } + qWarning() << "Json doesn't contain a valid url or solder key"; + return; } + } - current.minecraftVersion = Json::ensureString(obj, "minecraft", QString(), "__placeholder__"); - current.websiteUrl = Json::ensureString(obj, "platformUrl", QString(), "__placeholder__"); - current.author = Json::ensureString(obj, "user", QString(), "__placeholder__"); - current.description = Json::ensureString(obj, "description", QString(), "__placeholder__"); - current.metadataLoaded = true; - metadataLoaded(); - }); - netJob->start(); - } + current.minecraftVersion = Json::ensureString(obj, "minecraft", QString(), "__placeholder__"); + current.websiteUrl = Json::ensureString(obj, "platformUrl", QString(), "__placeholder__"); + current.author = Json::ensureString(obj, "user", QString(), "__placeholder__"); + current.description = Json::ensureString(obj, "description", QString(), "__placeholder__"); + current.metadataLoaded = true; + metadataLoaded(); + }); + netJob->start(); } // expects current.metadataLoaded to be true diff --git a/application/pages/modplatform/technic/TechnicPage.ui b/application/pages/modplatform/technic/TechnicPage.ui index 36ce2ecf..2ca45dd2 100644 --- a/application/pages/modplatform/technic/TechnicPage.ui +++ b/application/pages/modplatform/technic/TechnicPage.ui @@ -27,7 +27,11 @@ 0 - + + + Search and filter ... + + -- cgit