diff options
Diffstat (limited to 'src/citra_qt/game_list_p.h')
| -rw-r--r-- | src/citra_qt/game_list_p.h | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/src/citra_qt/game_list_p.h b/src/citra_qt/game_list_p.h index 353b2d1e2..bcb3fccbd 100644 --- a/src/citra_qt/game_list_p.h +++ b/src/citra_qt/game_list_p.h | |||
| @@ -12,8 +12,8 @@ | |||
| 12 | #include <QString> | 12 | #include <QString> |
| 13 | 13 | ||
| 14 | #include "citra_qt/util/util.h" | 14 | #include "citra_qt/util/util.h" |
| 15 | #include "common/string_util.h" | ||
| 16 | #include "common/color.h" | 15 | #include "common/color.h" |
| 16 | #include "common/string_util.h" | ||
| 17 | 17 | ||
| 18 | #include "core/loader/smdh.h" | 18 | #include "core/loader/smdh.h" |
| 19 | 19 | ||
| @@ -51,19 +51,22 @@ static QPixmap GetDefaultIcon(bool large) { | |||
| 51 | * @param language title language | 51 | * @param language title language |
| 52 | * @return QString short title | 52 | * @return QString short title |
| 53 | */ | 53 | */ |
| 54 | static QString GetQStringShortTitleFromSMDH(const Loader::SMDH& smdh, Loader::SMDH::TitleLanguage language) { | 54 | static QString GetQStringShortTitleFromSMDH(const Loader::SMDH& smdh, |
| 55 | Loader::SMDH::TitleLanguage language) { | ||
| 55 | return QString::fromUtf16(smdh.GetShortTitle(language).data()); | 56 | return QString::fromUtf16(smdh.GetShortTitle(language).data()); |
| 56 | } | 57 | } |
| 57 | 58 | ||
| 58 | class GameListItem : public QStandardItem { | 59 | class GameListItem : public QStandardItem { |
| 59 | 60 | ||
| 60 | public: | 61 | public: |
| 61 | GameListItem(): QStandardItem() {} | 62 | GameListItem() : QStandardItem() { |
| 62 | GameListItem(const QString& string): QStandardItem(string) {} | 63 | } |
| 63 | virtual ~GameListItem() override {} | 64 | GameListItem(const QString& string) : QStandardItem(string) { |
| 65 | } | ||
| 66 | virtual ~GameListItem() override { | ||
| 67 | } | ||
| 64 | }; | 68 | }; |
| 65 | 69 | ||
| 66 | |||
| 67 | /** | 70 | /** |
| 68 | * A specialization of GameListItem for path values. | 71 | * A specialization of GameListItem for path values. |
| 69 | * This class ensures that for every full path value it holds, a correct string representation | 72 | * This class ensures that for every full path value it holds, a correct string representation |
| @@ -76,9 +79,9 @@ public: | |||
| 76 | static const int FullPathRole = Qt::UserRole + 1; | 79 | static const int FullPathRole = Qt::UserRole + 1; |
| 77 | static const int TitleRole = Qt::UserRole + 2; | 80 | static const int TitleRole = Qt::UserRole + 2; |
| 78 | 81 | ||
| 79 | GameListItemPath(): GameListItem() {} | 82 | GameListItemPath() : GameListItem() { |
| 80 | GameListItemPath(const QString& game_path, const std::vector<u8>& smdh_data): GameListItem() | 83 | } |
| 81 | { | 84 | GameListItemPath(const QString& game_path, const std::vector<u8>& smdh_data) : GameListItem() { |
| 82 | setData(game_path, FullPathRole); | 85 | setData(game_path, FullPathRole); |
| 83 | 86 | ||
| 84 | if (!Loader::IsValidSMDH(smdh_data)) { | 87 | if (!Loader::IsValidSMDH(smdh_data)) { |
| @@ -94,13 +97,15 @@ public: | |||
| 94 | setData(GetQPixmapFromSMDH(smdh, true), Qt::DecorationRole); | 97 | setData(GetQPixmapFromSMDH(smdh, true), Qt::DecorationRole); |
| 95 | 98 | ||
| 96 | // Get title form SMDH | 99 | // Get title form SMDH |
| 97 | setData(GetQStringShortTitleFromSMDH(smdh, Loader::SMDH::TitleLanguage::English), TitleRole); | 100 | setData(GetQStringShortTitleFromSMDH(smdh, Loader::SMDH::TitleLanguage::English), |
| 101 | TitleRole); | ||
| 98 | } | 102 | } |
| 99 | 103 | ||
| 100 | QVariant data(int role) const override { | 104 | QVariant data(int role) const override { |
| 101 | if (role == Qt::DisplayRole) { | 105 | if (role == Qt::DisplayRole) { |
| 102 | std::string filename; | 106 | std::string filename; |
| 103 | Common::SplitPath(data(FullPathRole).toString().toStdString(), nullptr, &filename, nullptr); | 107 | Common::SplitPath(data(FullPathRole).toString().toStdString(), nullptr, &filename, |
| 108 | nullptr); | ||
| 104 | QString title = data(TitleRole).toString(); | 109 | QString title = data(TitleRole).toString(); |
| 105 | return QString::fromStdString(filename) + (title.isEmpty() ? "" : "\n " + title); | 110 | return QString::fromStdString(filename) + (title.isEmpty() ? "" : "\n " + title); |
| 106 | } else { | 111 | } else { |
| @@ -109,7 +114,6 @@ public: | |||
| 109 | } | 114 | } |
| 110 | }; | 115 | }; |
| 111 | 116 | ||
| 112 | |||
| 113 | /** | 117 | /** |
| 114 | * A specialization of GameListItem for size values. | 118 | * A specialization of GameListItem for size values. |
| 115 | * This class ensures that for every numerical size value it holds (in bytes), a correct | 119 | * This class ensures that for every numerical size value it holds (in bytes), a correct |
| @@ -120,14 +124,13 @@ class GameListItemSize : public GameListItem { | |||
| 120 | public: | 124 | public: |
| 121 | static const int SizeRole = Qt::UserRole + 1; | 125 | static const int SizeRole = Qt::UserRole + 1; |
| 122 | 126 | ||
| 123 | GameListItemSize(): GameListItem() {} | 127 | GameListItemSize() : GameListItem() { |
| 124 | GameListItemSize(const qulonglong size_bytes): GameListItem() | 128 | } |
| 125 | { | 129 | GameListItemSize(const qulonglong size_bytes) : GameListItem() { |
| 126 | setData(size_bytes, SizeRole); | 130 | setData(size_bytes, SizeRole); |
| 127 | } | 131 | } |
| 128 | 132 | ||
| 129 | void setData(const QVariant& value, int role) override | 133 | void setData(const QVariant& value, int role) override { |
| 130 | { | ||
| 131 | // By specializing setData for SizeRole, we can ensure that the numerical and string | 134 | // By specializing setData for SizeRole, we can ensure that the numerical and string |
| 132 | // representations of the data are always accurate and in the correct format. | 135 | // representations of the data are always accurate and in the correct format. |
| 133 | if (role == SizeRole) { | 136 | if (role == SizeRole) { |
| @@ -141,15 +144,14 @@ public: | |||
| 141 | 144 | ||
| 142 | /** | 145 | /** |
| 143 | * This operator is, in practice, only used by the TreeView sorting systems. | 146 | * This operator is, in practice, only used by the TreeView sorting systems. |
| 144 | * Override it so that it will correctly sort by numerical value instead of by string representation. | 147 | * Override it so that it will correctly sort by numerical value instead of by string |
| 148 | * representation. | ||
| 145 | */ | 149 | */ |
| 146 | bool operator<(const QStandardItem& other) const override | 150 | bool operator<(const QStandardItem& other) const override { |
| 147 | { | ||
| 148 | return data(SizeRole).toULongLong() < other.data(SizeRole).toULongLong(); | 151 | return data(SizeRole).toULongLong() < other.data(SizeRole).toULongLong(); |
| 149 | } | 152 | } |
| 150 | }; | 153 | }; |
| 151 | 154 | ||
| 152 | |||
| 153 | /** | 155 | /** |
| 154 | * Asynchronous worker object for populating the game list. | 156 | * Asynchronous worker object for populating the game list. |
| 155 | * Communicates with other threads through Qt's signal/slot system. | 157 | * Communicates with other threads through Qt's signal/slot system. |
| @@ -158,8 +160,9 @@ class GameListWorker : public QObject, public QRunnable { | |||
| 158 | Q_OBJECT | 160 | Q_OBJECT |
| 159 | 161 | ||
| 160 | public: | 162 | public: |
| 161 | GameListWorker(QString dir_path, bool deep_scan): | 163 | GameListWorker(QString dir_path, bool deep_scan) |
| 162 | QObject(), QRunnable(), dir_path(dir_path), deep_scan(deep_scan) {} | 164 | : QObject(), QRunnable(), dir_path(dir_path), deep_scan(deep_scan) { |
| 165 | } | ||
| 163 | 166 | ||
| 164 | public slots: | 167 | public slots: |
| 165 | /// Starts the processing of directory tree information. | 168 | /// Starts the processing of directory tree information. |