summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/citra_qt/CMakeLists.txt2
-rw-r--r--src/citra_qt/game_list.cpp154
-rw-r--r--src/citra_qt/game_list.h48
-rw-r--r--src/citra_qt/game_list_p.h130
-rw-r--r--src/citra_qt/main.cpp20
-rw-r--r--src/citra_qt/main.h4
6 files changed, 356 insertions, 2 deletions
diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt
index a82e8a85b..51a574629 100644
--- a/src/citra_qt/CMakeLists.txt
+++ b/src/citra_qt/CMakeLists.txt
@@ -17,6 +17,7 @@ set(SRCS
17 debugger/profiler.cpp 17 debugger/profiler.cpp
18 debugger/ramview.cpp 18 debugger/ramview.cpp
19 debugger/registers.cpp 19 debugger/registers.cpp
20 game_list.cpp
20 util/spinbox.cpp 21 util/spinbox.cpp
21 util/util.cpp 22 util/util.cpp
22 bootmanager.cpp 23 bootmanager.cpp
@@ -42,6 +43,7 @@ set(HEADERS
42 debugger/profiler.h 43 debugger/profiler.h
43 debugger/ramview.h 44 debugger/ramview.h
44 debugger/registers.h 45 debugger/registers.h
46 game_list.h
45 util/spinbox.h 47 util/spinbox.h
46 util/util.h 48 util/util.h
47 bootmanager.h 49 bootmanager.h
diff --git a/src/citra_qt/game_list.cpp b/src/citra_qt/game_list.cpp
new file mode 100644
index 000000000..f90e05374
--- /dev/null
+++ b/src/citra_qt/game_list.cpp
@@ -0,0 +1,154 @@
1// Copyright 2015 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <QHeaderView>
6#include <QThreadPool>
7#include <QVBoxLayout>
8
9#include "game_list.h"
10#include "game_list_p.h"
11
12#include "core/loader/loader.h"
13
14#include "common/common_paths.h"
15#include "common/logging/log.h"
16#include "common/string_util.h"
17
18GameList::GameList(QWidget* parent)
19{
20 QVBoxLayout* layout = new QVBoxLayout;
21
22 tree_view = new QTreeView;
23 item_model = new QStandardItemModel(tree_view);
24 tree_view->setModel(item_model);
25
26 tree_view->setAlternatingRowColors(true);
27 tree_view->setSelectionMode(QHeaderView::SingleSelection);
28 tree_view->setSelectionBehavior(QHeaderView::SelectRows);
29 tree_view->setVerticalScrollMode(QHeaderView::ScrollPerPixel);
30 tree_view->setHorizontalScrollMode(QHeaderView::ScrollPerPixel);
31 tree_view->setSortingEnabled(true);
32 tree_view->setEditTriggers(QHeaderView::NoEditTriggers);
33 tree_view->setUniformRowHeights(true);
34
35 item_model->insertColumns(0, COLUMN_COUNT);
36 item_model->setHeaderData(COLUMN_FILE_TYPE, Qt::Horizontal, "File type");
37 item_model->setHeaderData(COLUMN_NAME, Qt::Horizontal, "Name");
38 item_model->setHeaderData(COLUMN_SIZE, Qt::Horizontal, "Size");
39
40 connect(tree_view, SIGNAL(activated(const QModelIndex&)), this, SLOT(ValidateEntry(const QModelIndex&)));
41
42 // We must register all custom types with the Qt Automoc system so that we are able to use it with
43 // signals/slots. In this case, QList falls under the umbrells of custom types.
44 qRegisterMetaType<QList<QStandardItem*>>("QList<QStandardItem*>");
45
46 layout->addWidget(tree_view);
47 setLayout(layout);
48}
49
50GameList::~GameList()
51{
52 emit ShouldCancelWorker();
53}
54
55void GameList::AddEntry(QList<QStandardItem*> entry_items)
56{
57 item_model->invisibleRootItem()->appendRow(entry_items);
58}
59
60void GameList::ValidateEntry(const QModelIndex& item)
61{
62 // We don't care about the individual QStandardItem that was selected, but its row.
63 int row = item_model->itemFromIndex(item)->row();
64 QStandardItem* child_file = item_model->invisibleRootItem()->child(row, COLUMN_NAME);
65 QString file_path = child_file->data(GameListItemPath::FullPathRole).toString();
66
67 if (file_path.isEmpty())
68 return;
69 std::string std_file_path = file_path.toStdString();
70 if (!FileUtil::Exists(std_file_path) || FileUtil::IsDirectory(std_file_path))
71 return;
72 emit GameChosen(file_path);
73}
74
75void GameList::DonePopulating()
76{
77 tree_view->setEnabled(true);
78}
79
80void GameList::PopulateAsync(const QString& dir_path, bool deep_scan)
81{
82 if (!FileUtil::Exists(dir_path.toStdString()) || !FileUtil::IsDirectory(dir_path.toStdString())) {
83 LOG_ERROR(Frontend, "Could not find game list folder at %s", dir_path.toLatin1().data());
84 return;
85 }
86
87 tree_view->setEnabled(false);
88 // Delete any rows that might already exist if we're repopulating
89 item_model->removeRows(0, item_model->rowCount());
90
91 emit ShouldCancelWorker();
92 GameListWorker* worker = new GameListWorker(dir_path, deep_scan);
93
94 connect(worker, SIGNAL(EntryReady(QList<QStandardItem*>)), this, SLOT(AddEntry(QList<QStandardItem*>)), Qt::QueuedConnection);
95 connect(worker, SIGNAL(Finished()), this, SLOT(DonePopulating()), Qt::QueuedConnection);
96 // Use DirectConnection here because worker->Cancel() is thread-safe and we want it to cancel without delay.
97 connect(this, SIGNAL(ShouldCancelWorker()), worker, SLOT(Cancel()), Qt::DirectConnection);
98
99 QThreadPool::globalInstance()->start(worker);
100 current_worker = std::move(worker);
101}
102
103void GameListWorker::AddFstEntriesToGameList(const std::string& dir_path, bool deep_scan)
104{
105 const auto callback = [&](const std::string& directory,
106 const std::string& virtual_name) -> int {
107
108 std::string physical_name = directory + DIR_SEP + virtual_name;
109
110 if (stop_processing)
111 return -1; // A negative return value breaks the callback loop.
112
113 if (deep_scan && FileUtil::IsDirectory(physical_name)) {
114 AddFstEntriesToGameList(physical_name, true);
115 } else {
116 std::string filename_filename, filename_extension;
117 Common::SplitPath(physical_name, nullptr, &filename_filename, &filename_extension);
118
119 Loader::FileType guessed_filetype = Loader::GuessFromExtension(filename_extension);
120 if (guessed_filetype == Loader::FileType::Unknown)
121 return 0;
122 Loader::FileType filetype = Loader::IdentifyFile(physical_name);
123 if (filetype == Loader::FileType::Unknown) {
124 LOG_WARNING(Frontend, "File %s is of indeterminate type and is possibly corrupted.", physical_name.c_str());
125 return 0;
126 }
127 if (guessed_filetype != filetype) {
128 LOG_WARNING(Frontend, "Filetype and extension of file %s do not match.", physical_name.c_str());
129 }
130
131 emit EntryReady({
132 new GameListItem(QString::fromStdString(Loader::GetFileTypeString(filetype))),
133 new GameListItemPath(QString::fromStdString(physical_name)),
134 new GameListItemSize(FileUtil::GetSize(physical_name)),
135 });
136 }
137
138 return 0; // We don't care about the found entries
139 };
140 FileUtil::ScanDirectoryTreeAndCallback(dir_path, callback);
141}
142
143void GameListWorker::run()
144{
145 stop_processing = false;
146 AddFstEntriesToGameList(dir_path.toStdString(), deep_scan);
147 emit Finished();
148}
149
150void GameListWorker::Cancel()
151{
152 disconnect(this, 0, 0, 0);
153 stop_processing = true;
154}
diff --git a/src/citra_qt/game_list.h b/src/citra_qt/game_list.h
new file mode 100644
index 000000000..ab09edce3
--- /dev/null
+++ b/src/citra_qt/game_list.h
@@ -0,0 +1,48 @@
1// Copyright 2015 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <QModelIndex>
8#include <QStandardItem>
9#include <QStandardItemModel>
10#include <QString>
11#include <QTreeView>
12#include <QWidget>
13
14class GameListWorker;
15
16
17class GameList : public QWidget {
18 Q_OBJECT
19
20public:
21 enum {
22 COLUMN_FILE_TYPE,
23 COLUMN_NAME,
24 COLUMN_SIZE,
25 COLUMN_COUNT, // Number of columns
26 };
27
28 GameList(QWidget* parent = nullptr);
29 ~GameList() override;
30
31 void PopulateAsync(const QString& dir_path, bool deep_scan);
32
33public slots:
34 void AddEntry(QList<QStandardItem*> entry_items);
35
36private slots:
37 void ValidateEntry(const QModelIndex& item);
38 void DonePopulating();
39
40signals:
41 void GameChosen(QString game_path);
42 void ShouldCancelWorker();
43
44private:
45 QTreeView* tree_view = nullptr;
46 QStandardItemModel* item_model = nullptr;
47 GameListWorker* current_worker = nullptr;
48};
diff --git a/src/citra_qt/game_list_p.h b/src/citra_qt/game_list_p.h
new file mode 100644
index 000000000..820012bce
--- /dev/null
+++ b/src/citra_qt/game_list_p.h
@@ -0,0 +1,130 @@
1// Copyright 2015 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <atomic>
8
9#include <QRunnable>
10#include <QStandardItem>
11#include <QString>
12
13#include "citra_qt/util/util.h"
14#include "common/string_util.h"
15
16
17class GameListItem : public QStandardItem {
18
19public:
20 GameListItem(): QStandardItem() {}
21 GameListItem(const QString& string): QStandardItem(string) {}
22 virtual ~GameListItem() override {}
23};
24
25
26/**
27 * A specialization of GameListItem for path values.
28 * This class ensures that for every full path value it holds, a correct string representation
29 * of just the filename (with no extension) will be displayed to the user.
30 */
31class GameListItemPath : public GameListItem {
32
33public:
34 static const int FullPathRole = Qt::UserRole + 1;
35
36 GameListItemPath(): GameListItem() {}
37 GameListItemPath(const QString& game_path): GameListItem()
38 {
39 setData(game_path, FullPathRole);
40 }
41
42 void setData(const QVariant& value, int role) override
43 {
44 // By specializing setData for FullPathRole, we can ensure that the two string
45 // representations of the data are always accurate and in the correct format.
46 if (role == FullPathRole) {
47 std::string filename;
48 Common::SplitPath(value.toString().toStdString(), nullptr, &filename, nullptr);
49 GameListItem::setData(QString::fromStdString(filename), Qt::DisplayRole);
50 GameListItem::setData(value, FullPathRole);
51 } else {
52 GameListItem::setData(value, role);
53 }
54 }
55};
56
57
58/**
59 * A specialization of GameListItem for size values.
60 * This class ensures that for every numerical size value it holds (in bytes), a correct
61 * human-readable string representation will be displayed to the user.
62 */
63class GameListItemSize : public GameListItem {
64
65public:
66 static const int SizeRole = Qt::UserRole + 1;
67
68 GameListItemSize(): GameListItem() {}
69 GameListItemSize(const qulonglong size_bytes): GameListItem()
70 {
71 setData(size_bytes, SizeRole);
72 }
73
74 void setData(const QVariant& value, int role) override
75 {
76 // By specializing setData for SizeRole, we can ensure that the numerical and string
77 // representations of the data are always accurate and in the correct format.
78 if (role == SizeRole) {
79 qulonglong size_bytes = value.toULongLong();
80 GameListItem::setData(ReadableByteSize(size_bytes), Qt::DisplayRole);
81 GameListItem::setData(value, SizeRole);
82 } else {
83 GameListItem::setData(value, role);
84 }
85 }
86
87 /**
88 * This operator is, in practice, only used by the TreeView sorting systems.
89 * Override it so that it will correctly sort by numerical value instead of by string representation.
90 */
91 bool operator<(const QStandardItem& other) const override
92 {
93 return data(SizeRole).toULongLong() < other.data(SizeRole).toULongLong();
94 }
95};
96
97
98/**
99 * Asynchronous worker object for populating the game list.
100 * Communicates with other threads through Qt's signal/slot system.
101 */
102class GameListWorker : public QObject, public QRunnable {
103 Q_OBJECT
104
105public:
106 GameListWorker(QString dir_path, bool deep_scan):
107 QObject(), QRunnable(), dir_path(dir_path), deep_scan(deep_scan) {}
108
109public slots:
110 /// Starts the processing of directory tree information.
111 void run() override;
112 /// Tells the worker that it should no longer continue processing. Thread-safe.
113 void Cancel();
114
115signals:
116 /**
117 * The `EntryReady` signal is emitted once an entry has been prepared and is ready
118 * to be added to the game list.
119 * @param entry_items a list with `QStandardItem`s that make up the columns of the new entry.
120 */
121 void EntryReady(QList<QStandardItem*> entry_items);
122 void Finished();
123
124private:
125 QString dir_path;
126 bool deep_scan;
127 std::atomic_bool stop_processing;
128
129 void AddFstEntriesToGameList(const std::string& dir_path, bool deep_scan);
130};
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp
index 58de28c1d..ff2d60996 100644
--- a/src/citra_qt/main.cpp
+++ b/src/citra_qt/main.cpp
@@ -12,6 +12,7 @@
12 12
13#include "citra_qt/bootmanager.h" 13#include "citra_qt/bootmanager.h"
14#include "citra_qt/config.h" 14#include "citra_qt/config.h"
15#include "citra_qt/game_list.h"
15#include "citra_qt/hotkeys.h" 16#include "citra_qt/hotkeys.h"
16#include "citra_qt/main.h" 17#include "citra_qt/main.h"
17 18
@@ -59,6 +60,9 @@ GMainWindow::GMainWindow() : emu_thread(nullptr)
59 render_window = new GRenderWindow(this, emu_thread.get()); 60 render_window = new GRenderWindow(this, emu_thread.get());
60 render_window->hide(); 61 render_window->hide();
61 62
63 game_list = new GameList();
64 ui.horizontalLayout->addWidget(game_list);
65
62 profilerWidget = new ProfilerWidget(this); 66 profilerWidget = new ProfilerWidget(this);
63 addDockWidget(Qt::BottomDockWidgetArea, profilerWidget); 67 addDockWidget(Qt::BottomDockWidgetArea, profilerWidget);
64 profilerWidget->hide(); 68 profilerWidget->hide();
@@ -160,6 +164,7 @@ GMainWindow::GMainWindow() : emu_thread(nullptr)
160 UpdateRecentFiles(); 164 UpdateRecentFiles();
161 165
162 // Setup connections 166 // Setup connections
167 connect(game_list, SIGNAL(GameChosen(QString)), this, SLOT(OnGameListLoadFile(QString)));
163 connect(ui.action_Load_File, SIGNAL(triggered()), this, SLOT(OnMenuLoadFile())); 168 connect(ui.action_Load_File, SIGNAL(triggered()), this, SLOT(OnMenuLoadFile()));
164 connect(ui.action_Load_Symbol_Map, SIGNAL(triggered()), this, SLOT(OnMenuLoadSymbolMap())); 169 connect(ui.action_Load_Symbol_Map, SIGNAL(triggered()), this, SLOT(OnMenuLoadSymbolMap()));
165 connect(ui.action_Start, SIGNAL(triggered()), this, SLOT(OnStartGame())); 170 connect(ui.action_Start, SIGNAL(triggered()), this, SLOT(OnStartGame()));
@@ -193,6 +198,8 @@ GMainWindow::GMainWindow() : emu_thread(nullptr)
193 198
194 show(); 199 show();
195 200
201 game_list->PopulateAsync(settings.value("gameListRootDir").toString(), settings.value("gameListDeepScan").toBool());
202
196 QStringList args = QApplication::arguments(); 203 QStringList args = QApplication::arguments();
197 if (args.length() >= 2) { 204 if (args.length() >= 2) {
198 BootGame(args[1].toStdString()); 205 BootGame(args[1].toStdString());
@@ -264,6 +271,9 @@ void GMainWindow::BootGame(const std::string& filename) {
264 // Update the GUI 271 // Update the GUI
265 registersWidget->OnDebugModeEntered(); 272 registersWidget->OnDebugModeEntered();
266 callstackWidget->OnDebugModeEntered(); 273 callstackWidget->OnDebugModeEntered();
274 if (ui.action_Single_Window_Mode->isChecked()) {
275 game_list->hide();
276 }
267 render_window->show(); 277 render_window->show();
268 278
269 emulation_running = true; 279 emulation_running = true;
@@ -295,6 +305,7 @@ void GMainWindow::ShutdownGame() {
295 ui.action_Pause->setEnabled(false); 305 ui.action_Pause->setEnabled(false);
296 ui.action_Stop->setEnabled(false); 306 ui.action_Stop->setEnabled(false);
297 render_window->hide(); 307 render_window->hide();
308 game_list->show();
298 309
299 emulation_running = false; 310 emulation_running = false;
300} 311}
@@ -340,12 +351,16 @@ void GMainWindow::UpdateRecentFiles() {
340 } 351 }
341} 352}
342 353
354void GMainWindow::OnGameListLoadFile(QString game_path) {
355 BootGame(game_path.toLatin1().data());
356}
357
343void GMainWindow::OnMenuLoadFile() { 358void GMainWindow::OnMenuLoadFile() {
344 QSettings settings; 359 QSettings settings;
345 QString rom_path = settings.value("romsPath", QString()).toString(); 360 QString rom_path = settings.value("romsPath", QString()).toString();
346 361
347 QString filename = QFileDialog::getOpenFileName(this, tr("Load File"), rom_path, tr("3DS executable (*.3ds *.3dsx *.elf *.axf *.cci *.cxi)")); 362 QString filename = QFileDialog::getOpenFileName(this, tr("Load File"), rom_path, tr("3DS executable (*.3ds *.3dsx *.elf *.axf *.cci *.cxi)"));
348 if (filename.size()) { 363 if (!filename.isEmpty()) {
349 settings.setValue("romsPath", QFileInfo(filename).path()); 364 settings.setValue("romsPath", QFileInfo(filename).path());
350 StoreRecentFile(filename); 365 StoreRecentFile(filename);
351 366
@@ -358,7 +373,7 @@ void GMainWindow::OnMenuLoadSymbolMap() {
358 QString symbol_path = settings.value("symbolsPath", QString()).toString(); 373 QString symbol_path = settings.value("symbolsPath", QString()).toString();
359 374
360 QString filename = QFileDialog::getOpenFileName(this, tr("Load Symbol Map"), symbol_path, tr("Symbol map (*)")); 375 QString filename = QFileDialog::getOpenFileName(this, tr("Load Symbol Map"), symbol_path, tr("Symbol map (*)"));
361 if (filename.size()) { 376 if (!filename.isEmpty()) {
362 settings.setValue("symbolsPath", QFileInfo(filename).path()); 377 settings.setValue("symbolsPath", QFileInfo(filename).path());
363 378
364 LoadSymbolMap(filename.toLatin1().data()); 379 LoadSymbolMap(filename.toLatin1().data());
@@ -440,6 +455,7 @@ void GMainWindow::ToggleWindowMode() {
440 if (emulation_running) { 455 if (emulation_running) {
441 render_window->setVisible(true); 456 render_window->setVisible(true);
442 render_window->RestoreGeometry(); 457 render_window->RestoreGeometry();
458 game_list->show();
443 } 459 }
444 } 460 }
445} 461}
diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h
index e99501cab..48a1032bd 100644
--- a/src/citra_qt/main.h
+++ b/src/citra_qt/main.h
@@ -10,6 +10,7 @@
10 10
11#include "ui_main.h" 11#include "ui_main.h"
12 12
13class GameList;
13class GImageInfo; 14class GImageInfo;
14class GRenderWindow; 15class GRenderWindow;
15class EmuThread; 16class EmuThread;
@@ -87,6 +88,8 @@ private slots:
87 void OnStartGame(); 88 void OnStartGame();
88 void OnPauseGame(); 89 void OnPauseGame();
89 void OnStopGame(); 90 void OnStopGame();
91 /// Called whenever a user selects a game in the game list widget.
92 void OnGameListLoadFile(QString game_path);
90 void OnMenuLoadFile(); 93 void OnMenuLoadFile();
91 void OnMenuLoadSymbolMap(); 94 void OnMenuLoadSymbolMap();
92 void OnMenuRecentFile(); 95 void OnMenuRecentFile();
@@ -101,6 +104,7 @@ private:
101 Ui::MainWindow ui; 104 Ui::MainWindow ui;
102 105
103 GRenderWindow* render_window; 106 GRenderWindow* render_window;
107 GameList* game_list;
104 108
105 // Whether emulation is currently running in Citra. 109 // Whether emulation is currently running in Citra.
106 bool emulation_running = false; 110 bool emulation_running = false;