14#include <unordered_map>
23QString
qs(
const std::string& s)
25 return QString::fromStdString(s);
35 : QAbstractListModel(parent), themeManager_(themeManager)
38 {QStringLiteral(
"All"), QStringLiteral(
"Show all games in your library"), {}, 0},
39 {QStringLiteral(
"Favorites"),
40 QStringLiteral(
"Show games you've marked as favorites"),
43 {QStringLiteral(
"Recently Played"),
44 QStringLiteral(
"Show games sorted by last played date"),
47 {QStringLiteral(
"Installed"), QStringLiteral(
"Show only installed games"), {}, 0},
48 {QStringLiteral(
"Not Installed"),
49 QStringLiteral(
"Show games not currently installed"),
52 {QStringLiteral(
"Updates Available"),
53 QStringLiteral(
"Show games with updates ready to download"),
56 {QStringLiteral(
"Running"), QStringLiteral(
"Show currently running games"), {}, 0},
65 return static_cast<int>(rows_.size());
70 if (!index.isValid() || index.row() < 0 || index.row() >=
static_cast<int>(rows_.size()))
72 const Row& r = rows_[
static_cast<size_t>(index.row())];
76 return QString(
"%1 (%2)").arg(r.label).arg(r.count);
77 case Qt::DecorationRole:
93 static const char32_t kIcons[] = {
97 for (
size_t i = 0; i < rows_.size() && i < std::size(kIcons); ++i)
103 emit dataChanged(index(0), index(
static_cast<int>(rows_.size()) - 1), {Qt::DecorationRole});
108 int notInstalled,
int updatesAvailable,
int running)
110 const int newCounts[] = {all, favorites, recentlyPlayed, installed,
111 notInstalled, updatesAvailable, running};
112 for (
size_t i = 0; i < rows_.size() && i < std::size(newCounts); ++i)
114 if (rows_[i].count != newCounts[i])
116 rows_[i].count = newCounts[i];
117 emit dataChanged(index(
static_cast<int>(i)), index(
static_cast<int>(i)),
125 for (
size_t i = 0; i < rows_.size(); ++i)
127 if (rows_[i].label.contains(partial, Qt::CaseInsensitive))
128 return static_cast<int>(i);
138 : QAbstractListModel(parent), themeManager_(themeManager)
144 if (parent.isValid())
146 return static_cast<int>(entries_.size());
151 if (!index.isValid() || index.row() < 0 || index.row() >=
static_cast<int>(entries_.size()))
153 const SidebarEntry& e = entries_[
static_cast<size_t>(index.row())];
156 case Qt::DisplayRole:
158 case Qt::DecorationRole:
160 case Qt::ToolTipRole:
179 static const std::vector<Def> defs = {
181 QStringLiteral(
"Games from Steam library")},
183 QStringLiteral(
"Manually added local games")},
185 QStringLiteral(
"Games from GOG Galaxy")},
187 QStringLiteral(
"Games from Epic Games Store")},
189 QStringLiteral(
"Games configured via Lutris")},
191 QStringLiteral(
"Games from itch.io")},
193 QStringLiteral(
"Flatpak-packaged games")},
196 std::map<GameSource, int> sourceCounts;
197 for (
const Game* g : allGames)
200 sourceCounts[g->source]++;
209 allEntry.
display = QString(
"All (%1)").arg(allGames.size());
210 allEntry.
tooltip = QString(
"Show all %1 games").arg(allGames.size());
213 entries_.push_back(std::move(allEntry));
215 for (
const Def& d : defs)
217 auto it = sourceCounts.find(d.source);
218 if (it == sourceCounts.end() || it->second <= 0)
221 e.
display = QString(
"%1 (%2)").arg(d.label).arg(it->second);
222 e.
tooltip = QString(
"%1 (%2 games)").arg(d.tooltip).arg(it->second);
224 e.
intId =
static_cast<int>(d.source);
225 entries_.push_back(std::move(e));
233 for (
size_t i = 0; i < entries_.size(); ++i)
235 if (entries_[i].intId == value)
236 return static_cast<int>(i);
246 : QAbstractListModel(parent), themeManager_(themeManager)
252 if (parent.isValid())
254 return static_cast<int>(entries_.size());
259 if (!index.isValid() || index.row() < 0 || index.row() >=
static_cast<int>(entries_.size()))
261 const SidebarEntry& e = entries_[
static_cast<size_t>(index.row())];
264 case Qt::DisplayRole:
266 case Qt::DecorationRole:
268 case Qt::ToolTipRole:
280 std::map<std::string, int> runnerCounts;
284 for (
const Game* game : allGames)
290 game->runnerConfig.runnerType ==
"native" ||
291 game->runnerConfig.runnerVersion ==
"native";
298 std::string version = game->runnerConfig.runnerVersion;
300 version = game->runnerConfig.runnerType;
301 if (version.empty() && !game->runnerConfig.protonVersion.empty() &&
302 game->runnerConfig.protonVersion !=
"Native Linux")
303 version = game->runnerConfig.protonVersion;
304 if (!version.empty() && version !=
"native")
305 runnerCounts[version]++;
316 e.
display = QString(
"All (%1)").arg(totalCount);
317 e.
tooltip = QString(
"Show all %1 games").arg(totalCount);
320 entries_.push_back(std::move(e));
326 e.
display = QString(
"Native (%1)").arg(nativeCount);
327 e.
tooltip = QString(
"Native Linux games (%1)").arg(nativeCount);
329 e.
stringId = QStringLiteral(
"native");
330 entries_.push_back(std::move(e));
333 std::vector<std::pair<std::string, int>> proton, wine, other;
334 for (
const auto& [version, count] : runnerCounts)
336 QString lower = qs(version).toLower();
337 if (lower.contains(QStringLiteral(
"proton")) || lower.contains(QStringLiteral(
"umu")))
338 proton.push_back({version, count});
339 else if (lower.contains(QStringLiteral(
"wine")))
340 wine.push_back({version, count});
341 else if (version !=
"native")
342 other.push_back({version, count});
344 auto byName = [](
const auto& a,
const auto& b) {
return a.first < b.first; };
345 std::sort(proton.begin(), proton.end(), byName);
346 std::sort(wine.begin(), wine.end(), byName);
347 std::sort(other.begin(), other.end(), byName);
349 auto emitGroup = [&](
const std::vector<std::pair<std::string, int>>& group,
char32_t icon,
350 const QString& prefix)
352 for (
const auto& [version, count] : group)
355 e.
display = QString(
"%1 (%2)").arg(qs(version)).arg(count);
357 ? QString(
"%1 (%2 games)").arg(qs(version)).arg(count)
358 : QString(
"%1: %2 (%3 games)").arg(prefix, qs(version)).arg(count);
361 entries_.push_back(std::move(e));
364 emitGroup(proton,
FA::Atom, QStringLiteral(
"Proton"));
373 for (
size_t i = 0; i < entries_.size(); ++i)
375 if (entries_[i].stringId == version)
376 return static_cast<int>(i);
386 : QAbstractListModel(parent), themeManager_(themeManager)
392 if (parent.isValid())
394 return static_cast<int>(entries_.size());
399 if (!index.isValid() || index.row() < 0 || index.row() >=
static_cast<int>(entries_.size()))
401 const SidebarEntry& e = entries_[
static_cast<size_t>(index.row())];
404 case Qt::DisplayRole:
406 case Qt::DecorationRole:
408 case Qt::ToolTipRole:
419 const std::vector<const Game*>& allGames,
int totalGameCount)
423 std::unordered_map<std::string, int> counts;
424 for (
const Game* g : allGames)
428 for (
const auto& col : g->collections)
438 e.
display = QString(
"All (%1)").arg(totalGameCount);
439 e.
tooltip = QStringLiteral(
"Show all games without collection filter");
442 entries_.push_back(std::move(e));
445 for (
const std::string& name : collectionNames)
447 auto it = counts.find(name);
448 int count = it == counts.end() ? 0 : it->second;
450 e.
display = QString(
"%1 (%2)").arg(qs(name)).arg(count);
451 e.
tooltip = QString(
"Show %1 games in '%2' collection").arg(count).arg(qs(name));
454 entries_.push_back(std::move(e));
462 for (
size_t i = 0; i < entries_.size(); ++i)
464 if (entries_[i].stringId == name)
465 return static_cast<int>(i);
void setCounts(int all, int favorites, int recentlyPlayed, int installed, int notInstalled, int updatesAvailable, int running)
CategoryModel(ThemeManager *themeManager, QObject *parent=nullptr)
int rowCount(const QModelIndex &parent={}) const override
int rowContaining(const QString &partial) const
QVariant data(const QModelIndex &index, int role) const override
QVariant data(const QModelIndex &index, int role) const override
int rowCount(const QModelIndex &parent={}) const override
int rowForCollection(const QString &name) const
CollectionsModel(ThemeManager *themeManager, QObject *parent=nullptr)
void rebuild(const std::vector< std::string > &collectionNames, const std::vector< const Game * > &allGames, int totalGameCount)
Complete representation of a game in the library.
static QIcon icon(char32_t codepoint, int size, const QColor &color)
Render a FontAwesome glyph as a QIcon at the given size and color.
void rebuild(const std::vector< const Game * > &allGames)
int rowCount(const QModelIndex &parent={}) const override
int rowForVersion(const QString &version) const
QVariant data(const QModelIndex &index, int role) const override
RunnerFilterModel(ThemeManager *themeManager, QObject *parent=nullptr)
void rebuild(const std::vector< const Game * > &allGames)
int rowForSourceValue(int value) const
int rowCount(const QModelIndex &parent={}) const override
SourceFilterModel(ThemeManager *themeManager, QObject *parent=nullptr)
QVariant data(const QModelIndex &index, int role) const override
GameSource
Where the game was acquired from (store/service/local).
@ Steam
Steam store/platform.
@ Local
Manually added game (not from a store).
@ Itch
itch.io indie games
@ Lutris
Lutris community scripts.
@ GOG
GOG.com (DRM-free games).
@ Flatpak
Flatpak package.
@ Native
Native Linux executable (no compatibility layer).
constexpr char32_t ClockRotateLeft
constexpr char32_t HardDrive
constexpr char32_t FolderOpen
constexpr char32_t CompactDisc
constexpr char32_t CircleUp
constexpr char32_t CirclePlay
constexpr char32_t BoxOpen
constexpr char32_t Gamepad
constexpr char32_t WineGlass
constexpr char32_t LayerGroup
constexpr char32_t ItchIo
constexpr char32_t Bookmark
constexpr char32_t TableCellsLarge
constexpr char32_t Folder