From bf4a89e82e3db42a723dd38418f3bbbbc44e3769 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 14 Jun 2025 13:12:19 +1000 Subject: [PATCH] Qt: Use GameList::FormatTimespan() No point duplicating the logic since the core can handle plural translations now. --- src/core/game_list.cpp | 6 ++++-- src/duckstation-qt/gamelistwidget.cpp | 15 +-------------- src/duckstation-qt/gamelistwidget.h | 2 -- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/core/game_list.cpp b/src/core/game_list.cpp index 3a16aa422..5791f352f 100644 --- a/src/core/game_list.cpp +++ b/src/core/game_list.cpp @@ -1602,9 +1602,11 @@ TinyString GameList::FormatTimespan(std::time_t timespan, bool long_format) else { if (hours > 0) - ret.assign(TRANSLATE_PLURAL_STR("GameList", "%n hours", "", hours)); + ret.assign(TRANSLATE_PLURAL_SSTR("GameList", "%n hours", "", hours)); + else if (minutes > 0) + ret.assign(TRANSLATE_PLURAL_SSTR("GameList", "%n minutes", "", minutes)); else - ret.assign(TRANSLATE_PLURAL_STR("GameList", "%n minutes", "", minutes)); + ret.assign(TRANSLATE_PLURAL_SSTR("GameList", "%n seconds", "", seconds)); } return ret; diff --git a/src/duckstation-qt/gamelistwidget.cpp b/src/duckstation-qt/gamelistwidget.cpp index fffce0b30..f066d8b21 100644 --- a/src/duckstation-qt/gamelistwidget.cpp +++ b/src/duckstation-qt/gamelistwidget.cpp @@ -350,19 +350,6 @@ void GameListModel::invalidateCoverForPath(const std::string& path) emit dataChanged(mi, mi, {Qt::DecorationRole}); } -QString GameListModel::formatTimespan(time_t timespan) -{ - // avoid an extra string conversion - const u32 hours = static_cast(timespan / 3600); - const u32 minutes = static_cast((timespan % 3600) / 60); - if (hours > 0) - return qApp->translate("GameList", "%n hours", "", hours); - else if (minutes > 0) - return qApp->translate("GameList", "%n minutes", "", minutes); - else - return qApp->translate("GameList", "%n seconds", "", static_cast((timespan % 3600) % 60)); -} - const QPixmap& GameListModel::getIconPixmapForEntry(const GameList::Entry* ge) const { // We only do this for discs/disc sets for now. @@ -571,7 +558,7 @@ QVariant GameListModel::data(const QModelIndex& index, int role, const GameList: if (ge->total_played_time == 0) return {}; else - return formatTimespan(ge->total_played_time); + return QtUtils::StringViewToQString(GameList::FormatTimespan(ge->total_played_time, true)); } case Column_LastPlayed: diff --git a/src/duckstation-qt/gamelistwidget.h b/src/duckstation-qt/gamelistwidget.h index 6f40871f8..ec5262985 100644 --- a/src/duckstation-qt/gamelistwidget.h +++ b/src/duckstation-qt/gamelistwidget.h @@ -125,8 +125,6 @@ private: const QPixmap& getFlagPixmapForEntry(const GameList::Entry* ge) const; static void fixIconPixmapSize(QPixmap& pm); - static QString formatTimespan(time_t timespan); - std::optional m_taken_entries; float m_cover_scale = 0.0f;