all repos — mgba @ 6cc889022666683f20f9614fd65392ab8e5af4c1

mGBA Game Boy Advance Emulator

Qt: Add MRU list
Jeffrey Pfau jeffrey@endrift.com
Mon, 22 Dec 2014 23:00:31 -0800
commit

6cc889022666683f20f9614fd65392ab8e5af4c1

parent

458df43d1890b3918e5e19f2b319d11a524eb0de

M CHANGESCHANGES

@@ -7,6 +7,7 @@ - Better audio resampling via FFmpeg

- Settings window - Bilinear resampling option - Add option to skip BIOS start screen + - List of recently opened games Bugfixes: - Qt: Fix issue with set frame sizes being the wrong height - Qt: Fix emulator crashing when full screen if a game is not running
M src/platform/qt/ConfigController.cppsrc/platform/qt/ConfigController.cpp

@@ -131,7 +131,7 @@ }

m_optionSet[optionName]->setValue(GBAConfigGetValue(&m_config, key)); } -QString ConfigController::getOption(const char* key) { +QString ConfigController::getOption(const char* key) const { return QString(GBAConfigGetValue(&m_config, key)); }

@@ -174,6 +174,35 @@ return;

} QString stringValue(value.toString()); setOption(key, stringValue.toLocal8Bit().constData()); +} + +QList<QString> ConfigController::getMRU() const { + QList<QString> mru; + for (int i = 0; i < MRU_LIST_SIZE; ++i) { + char mruName[7]; + snprintf(mruName, sizeof(mruName) - 1, "mru.%i", i); + mruName[sizeof(mruName) - 1] = '\0'; + QString item = getOption(mruName); + if (item.isNull()) { + continue; + } + mru.append(item); + } + return mru; +} + +void ConfigController::setMRU(const QList<QString>& mru) { + int i = 0; + for (const QString& item : mru) { + char mruName[7]; + snprintf(mruName, sizeof(mruName) - 1, "mru.%i", i); + mruName[sizeof(mruName) - 1] = '\0'; + setOption(mruName, item); + ++i; + if (i >= MRU_LIST_SIZE) { + break; + } + } } void ConfigController::write() {
M src/platform/qt/ConfigController.hsrc/platform/qt/ConfigController.h

@@ -57,6 +57,7 @@ Q_OBJECT

public: constexpr static const char* const PORT = "qt"; + static const int MRU_LIST_SIZE = 10; ConfigController(QObject* parent = nullptr); ~ConfigController();

@@ -67,7 +68,10 @@

ConfigOption* addOption(const char* key); void updateOption(const char* key); - QString getOption(const char* key); + QString getOption(const char* key) const; + + QList<QString> getMRU() const; + void setMRU(const QList<QString>& mru); public slots: void setOption(const char* key, bool value);
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -45,6 +45,7 @@ #endif

#ifdef USE_GDB_STUB , m_gdbController(nullptr) #endif + , m_mruMenu(nullptr) { setWindowTitle(PROJECT_NAME); setFocusPolicy(Qt::StrongFocus);

@@ -156,6 +157,9 @@

if (opts->width && opts->height) { m_screenWidget->setSizeHint(QSize(opts->width, opts->height)); } + + m_mruFiles = m_config->getMRU(); + updateMRU(); m_inputController.setConfiguration(m_config); }

@@ -313,6 +317,7 @@ emit startDrawing(m_controller->drawContext(), context);

foreach (QAction* action, m_gameActions) { action->setDisabled(false); } + appendMRU(context->fname); char title[13] = { '\0' }; GBAGetGameTitle(context->gba, title); setWindowTitle(tr(PROJECT_NAME " - %1").arg(title));

@@ -402,6 +407,8 @@ addAction(fileMenu->addAction(tr("Load &ROM..."), this, SLOT(selectROM()), QKeySequence::Open));

fileMenu->addAction(tr("Load &BIOS..."), this, SLOT(selectBIOS())); fileMenu->addAction(tr("Load &patch..."), this, SLOT(selectPatch())); + m_mruMenu = fileMenu->addMenu(tr("Recent")); + fileMenu->addSeparator(); QAction* loadState = new QAction(tr("&Load state"), fileMenu);

@@ -627,6 +634,36 @@ }

void Window::detachWidget(QWidget* widget) { m_screenWidget->layout()->removeWidget(widget); +} + +void Window::appendMRU(const QString& fname) { + int index = m_mruFiles.indexOf(fname); + if (index >= 0) { + m_mruFiles.removeAt(index); + } + m_mruFiles.prepend(fname); + while (m_mruFiles.size() > ConfigController::MRU_LIST_SIZE) { + m_mruFiles.removeLast(); + } + updateMRU(); +} + +void Window::updateMRU() { + if (!m_mruMenu) { + return; + } + m_mruMenu->clear(); + int i = 0; + for (const QString& file : m_mruFiles) { + QAction* item = new QAction(file, m_mruMenu); + item->setShortcut(QString("Ctrl+%1").arg(i)); + connect(item, &QAction::triggered, [this, file]() { m_controller->loadGame(file); }); + m_mruMenu->addAction(item); + ++i; + } + m_config->setMRU(m_mruFiles); + m_config->write(); + m_mruMenu->setEnabled(i > 0); } WindowBackground::WindowBackground(QWidget* parent)
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -104,6 +104,9 @@

void attachWidget(QWidget* widget); void detachWidget(QWidget* widget); + void appendMRU(const QString& fname); + void updateMRU(); + GameController* m_controller; Display* m_display; QList<QAction*> m_gameActions;

@@ -115,6 +118,8 @@ ConfigController* m_config;

InputController m_inputController; QList<QDateTime> m_frameList; QTimer m_fpsTimer; + QList<QString> m_mruFiles; + QMenu* m_mruMenu; #ifdef USE_FFMPEG VideoView* m_videoView;