aboutsummaryrefslogtreecommitdiff
path: root/application/pages/modplatform/technic
diff options
context:
space:
mode:
authorphit <2097483+phit@users.noreply.github.com>2021-06-19 16:19:39 +0200
committerphit <2097483+phit@users.noreply.github.com>2021-06-20 01:03:17 +0200
commitf7c144c3932a18e1cd96e1ad7505e53ea706a47d (patch)
tree41db6a9b877d269b941c07ba738dba5bf92051e6 /application/pages/modplatform/technic
parent5f8d07c0092b6cc44f81104a3d7f9e7e49d9df5d (diff)
downloadPrismLauncher-f7c144c3932a18e1cd96e1ad7505e53ea706a47d.tar.gz
PrismLauncher-f7c144c3932a18e1cd96e1ad7505e53ea706a47d.tar.bz2
PrismLauncher-f7c144c3932a18e1cd96e1ad7505e53ea706a47d.zip
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.
Diffstat (limited to 'application/pages/modplatform/technic')
-rw-r--r--application/pages/modplatform/technic/TechnicModel.cpp17
-rw-r--r--application/pages/modplatform/technic/TechnicPage.cpp103
-rw-r--r--application/pages/modplatform/technic/TechnicPage.ui6
3 files changed, 69 insertions, 57 deletions
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<QByteArray> response = std::make_shared<QByteArray>();
+ 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<QByteArray> response = std::make_shared<QByteArray>();
- 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 @@
<number>0</number>
</property>
<item>
- <widget class="QLineEdit" name="searchEdit"/>
+ <widget class="QLineEdit" name="searchEdit">
+ <property name="placeholderText">
+ <string>Search and filter ...</string>
+ </property>
+ </widget>
</item>
<item>
<widget class="QPushButton" name="searchButton">