mirror of
https://github.com/MultiMC/MultiMC5.git
synced 2025-02-11 00:40:17 +00:00
WIP fix sorting and stuff
This commit is contained in:
parent
2660bb2385
commit
7d68ae8ece
@ -159,16 +159,27 @@ void ListModel::fetchMore(const QModelIndex& parent)
|
||||
void ListModel::performPaginatedSearch()
|
||||
{
|
||||
NetJob *netJob = new NetJob("CurseForge::Search", APPLICATION->network());
|
||||
QString textSortOrder;
|
||||
switch (currentSortOrder) {
|
||||
case SortOrder::Ascending: {
|
||||
textSortOrder = "asc";
|
||||
break;
|
||||
}
|
||||
case SortOrder::Descending: {
|
||||
textSortOrder = "desc";
|
||||
break;
|
||||
}
|
||||
}
|
||||
auto searchUrl = QString(
|
||||
"https://api.curseforge.com/v1/mods/search?"
|
||||
"categoryId=0&"
|
||||
"gameId=432&"
|
||||
"classId=4471&"
|
||||
"index=%1&"
|
||||
"pageSize=25&"
|
||||
"searchFilter=%2&"
|
||||
"sectionId=4471&"
|
||||
"sort=%3"
|
||||
).arg(nextSearchOffset).arg(currentSearchTerm).arg(currentSort);
|
||||
"sortField=%3&"
|
||||
"sortOrder=%4"
|
||||
).arg(nextSearchOffset).arg(currentSearchTerm).arg(currentSort + 1).arg(textSortOrder);
|
||||
auto download = Net::Download::makeByteArray(QUrl(searchUrl), &response);
|
||||
download->setExtraHeader("x-api-key", APPLICATION->curseAPIKey());
|
||||
netJob->addNetAction(download);
|
||||
@ -178,13 +189,14 @@ void ListModel::performPaginatedSearch()
|
||||
QObject::connect(netJob, &NetJob::failed, this, &ListModel::searchRequestFailed);
|
||||
}
|
||||
|
||||
void ListModel::searchWithTerm(const QString& term, int sort)
|
||||
void ListModel::searchWithTerm(const QString& term, int sort, SortOrder sortOrder)
|
||||
{
|
||||
if(currentSearchTerm == term && currentSearchTerm.isNull() == term.isNull() && currentSort == sort) {
|
||||
return;
|
||||
}
|
||||
currentSearchTerm = term;
|
||||
currentSort = sort;
|
||||
currentSortOrder = sortOrder;
|
||||
if(jobPtr) {
|
||||
jobPtr->abort();
|
||||
searchState = ResetRequested;
|
||||
|
@ -23,6 +23,11 @@ namespace CurseForge {
|
||||
typedef QMap<QString, QIcon> LogoMap;
|
||||
typedef std::function<void(QString)> LogoCallback;
|
||||
|
||||
enum SortOrder {
|
||||
Ascending,
|
||||
Descending
|
||||
};
|
||||
|
||||
class ListModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -39,7 +44,7 @@ public:
|
||||
void fetchMore(const QModelIndex & parent) override;
|
||||
|
||||
void getLogo(const QString &logo, const QString &logoUrl, LogoCallback callback);
|
||||
void searchWithTerm(const QString & term, const int sort);
|
||||
void searchWithTerm(const QString & term, const int sort, SortOrder sortOrder);
|
||||
|
||||
private slots:
|
||||
void performPaginatedSearch();
|
||||
@ -62,6 +67,7 @@ private:
|
||||
|
||||
QString currentSearchTerm;
|
||||
int currentSort = 0;
|
||||
SortOrder currentSortOrder = SortOrder::Ascending;
|
||||
int nextSearchOffset = 0;
|
||||
enum SearchState {
|
||||
None,
|
||||
|
@ -23,12 +23,12 @@ CFPage::CFPage(NewInstanceDialog* dialog, QWidget *parent)
|
||||
ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300);
|
||||
|
||||
// index is used to set the sorting with the curseforge api
|
||||
ui->sortByBox->addItem(tr("Sort by featured"));
|
||||
ui->sortByBox->addItem(tr("Sort by popularity"));
|
||||
ui->sortByBox->addItem(tr("Sort by last updated"));
|
||||
ui->sortByBox->addItem(tr("Sort by name"));
|
||||
ui->sortByBox->addItem(tr("Sort by author"));
|
||||
ui->sortByBox->addItem(tr("Sort by total downloads"));
|
||||
ui->sortByBox->addItem(tr("Sort by featured"), CurseForge::SortOrder::Descending);
|
||||
ui->sortByBox->addItem(tr("Sort by popularity"), CurseForge::SortOrder::Descending);
|
||||
ui->sortByBox->addItem(tr("Sort by last updated"), CurseForge::SortOrder::Descending);
|
||||
ui->sortByBox->addItem(tr("Sort by name"), CurseForge::SortOrder::Ascending);
|
||||
ui->sortByBox->addItem(tr("Sort by author"), CurseForge::SortOrder::Ascending);
|
||||
ui->sortByBox->addItem(tr("Sort by total downloads"), CurseForge::SortOrder::Descending);
|
||||
|
||||
connect(ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
|
||||
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &CFPage::onSelectionChanged);
|
||||
@ -66,7 +66,7 @@ void CFPage::openedImpl()
|
||||
|
||||
void CFPage::triggerSearch()
|
||||
{
|
||||
listModel->searchWithTerm(ui->searchEdit->text(), ui->sortByBox->currentIndex());
|
||||
listModel->searchWithTerm(ui->searchEdit->text(), ui->sortByBox->currentIndex(), (CurseForge::SortOrder) ui->sortByBox->currentData().toInt());
|
||||
}
|
||||
|
||||
void CFPage::refreshRightPane() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user