Added the option to sort instances by total playtime (#5701)

Signed-off-by: Anceph <yucehasan31@gmail.com>
This commit is contained in:
Anceph 2026-06-24 00:23:31 +03:00
parent f654ce8212
commit a607373ced
3 changed files with 26 additions and 1 deletions

View file

@ -62,6 +62,12 @@ bool InstanceProxyModel::subSortLessThan(const QModelIndex& left, const QModelIn
QString sortMode = APPLICATION->settings()->get("InstSortMode").toString(); QString sortMode = APPLICATION->settings()->get("InstSortMode").toString();
if (sortMode == "LastLaunch") { if (sortMode == "LastLaunch") {
return pdataLeft->lastLaunch() > pdataRight->lastLaunch(); return pdataLeft->lastLaunch() > pdataRight->lastLaunch();
} else if (sortMode == "Playtime") {
if (pdataLeft->totalTimePlayed() == pdataRight->totalTimePlayed()) {
// fallback to name sorting if playtime is equal
return m_naturalSort.compare(pdataLeft->name(), pdataRight->name()) < 0;
}
return pdataLeft->totalTimePlayed() > pdataRight->totalTimePlayed();
} else { } else {
return m_naturalSort.compare(pdataLeft->name(), pdataRight->name()) < 0; return m_naturalSort.compare(pdataLeft->name(), pdataRight->name()) < 0;
} }

View file

@ -62,7 +62,9 @@ enum InstSortMode {
// Sort alphabetically by name. // Sort alphabetically by name.
Sort_Name, Sort_Name,
// Sort by which instance was launched most recently. // Sort by which instance was launched most recently.
Sort_LastLaunch Sort_LastLaunch,
// Sort by which instance has the most playtime.
Sort_Playtime,
}; };
LauncherPage::LauncherPage(QWidget* parent) : QWidget(parent), ui(new Ui::LauncherPage) LauncherPage::LauncherPage(QWidget* parent) : QWidget(parent), ui(new Ui::LauncherPage)
@ -71,6 +73,7 @@ LauncherPage::LauncherPage(QWidget* parent) : QWidget(parent), ui(new Ui::Launch
ui->sortingModeGroup->setId(ui->sortByNameBtn, Sort_Name); ui->sortingModeGroup->setId(ui->sortByNameBtn, Sort_Name);
ui->sortingModeGroup->setId(ui->sortLastLaunchedBtn, Sort_LastLaunch); ui->sortingModeGroup->setId(ui->sortLastLaunchedBtn, Sort_LastLaunch);
ui->sortingModeGroup->setId(ui->sortByPlaytimeBtn, Sort_Playtime);
loadSettings(); loadSettings();
@ -227,6 +230,9 @@ void LauncherPage::applySettings()
case Sort_LastLaunch: case Sort_LastLaunch:
s->set("InstSortMode", "LastLaunch"); s->set("InstSortMode", "LastLaunch");
break; break;
case Sort_Playtime:
s->set("InstSortMode", "Playtime");
break;
case Sort_Name: case Sort_Name:
default: default:
s->set("InstSortMode", "Name"); s->set("InstSortMode", "Name");
@ -282,6 +288,8 @@ void LauncherPage::loadSettings()
QString sortMode = s->get("InstSortMode").toString(); QString sortMode = s->get("InstSortMode").toString();
if (sortMode == "LastLaunch") { if (sortMode == "LastLaunch") {
ui->sortLastLaunchedBtn->setChecked(true); ui->sortLastLaunchedBtn->setChecked(true);
} else if (sortMode == "Playtime"){
ui->sortByPlaytimeBtn->setChecked(true);
} else { } else {
ui->sortByNameBtn->setChecked(true); ui->sortByNameBtn->setChecked(true);
} }

View file

@ -83,6 +83,16 @@
</attribute> </attribute>
</widget> </widget>
</item> </item>
<item>
<widget class="QRadioButton" name="sortByPlaytimeBtn">
<property name="text">
<string>By &amp;playtime</string>
</property>
<attribute name="buttonGroup">
<string notr="true">sortingModeGroup</string>
</attribute>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
@ -675,6 +685,7 @@
<tabstop>scrollArea</tabstop> <tabstop>scrollArea</tabstop>
<tabstop>sortByNameBtn</tabstop> <tabstop>sortByNameBtn</tabstop>
<tabstop>sortLastLaunchedBtn</tabstop> <tabstop>sortLastLaunchedBtn</tabstop>
<tabstop>sortByPlaytimeBtn</tabstop>
<tabstop>askToRenameDirBtn</tabstop> <tabstop>askToRenameDirBtn</tabstop>
<tabstop>alwaysRenameDirBtn</tabstop> <tabstop>alwaysRenameDirBtn</tabstop>
<tabstop>neverRenameDirBtn</tabstop> <tabstop>neverRenameDirBtn</tabstop>