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.
This commit is contained in:
phit
2021-06-19 16:19:39 +02:00
parent 5f8d07c009
commit f7c144c393
15 changed files with 205 additions and 115 deletions

View File

@ -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();

View File

@ -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"))
{
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 a valid url or solder key";
return;
}
QJsonParseError parse_error;
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
QJsonObject obj = doc.object();
if(parse_error.error != QJsonParseError::NoError)
QJsonValueRef solderUrl = obj["solder"];
if (solderUrl.isString())
{
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();
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

View File

@ -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">