From 95a5a51e55bd36a8d23c8a95ea7b7ca560110041 Mon Sep 17 00:00:00 2001 From: spycrab Date: Fri, 23 Mar 2018 01:18:53 +0100 Subject: [PATCH] Qt: Implement missing "File" menu items --- Source/Core/DolphinQt2/MainWindow.cpp | 27 ++++++++++++++++++++++++-- Source/Core/DolphinQt2/MainWindow.h | 5 +++++ Source/Core/DolphinQt2/MenuBar.cpp | 28 +++++++++++++++++++++++++++ Source/Core/DolphinQt2/MenuBar.h | 7 +++++++ 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/Source/Core/DolphinQt2/MainWindow.cpp b/Source/Core/DolphinQt2/MainWindow.cpp index 1afa2bafdd..46060db385 100644 --- a/Source/Core/DolphinQt2/MainWindow.cpp +++ b/Source/Core/DolphinQt2/MainWindow.cpp @@ -28,6 +28,7 @@ #include "Core/Config/NetplaySettings.h" #include "Core/ConfigManager.h" #include "Core/Core.h" +#include "Core/HW/DVD/DVDInterface.h" #include "Core/HW/GCKeyboard.h" #include "Core/HW/GCPad.h" #include "Core/HW/ProcessorInterface.h" @@ -231,6 +232,10 @@ void MainWindow::ConnectMenuBar() // File connect(m_menu_bar, &MenuBar::Open, this, &MainWindow::Open); connect(m_menu_bar, &MenuBar::Exit, this, &MainWindow::close); + connect(m_menu_bar, &MenuBar::EjectDisc, this, &MainWindow::EjectDisc); + connect(m_menu_bar, &MenuBar::ChangeDisc, this, &MainWindow::ChangeDisc); + connect(m_menu_bar, &MenuBar::BootDVDBackup, this, + [this](const QString& drive) { StartGame(drive); }); // Emulation connect(m_menu_bar, &MenuBar::Pause, this, &MainWindow::Pause); @@ -406,12 +411,30 @@ void MainWindow::ConnectStack() tabifyDockWidget(m_log_widget, m_breakpoint_widget); } -void MainWindow::Open() +QString MainWindow::PromptFileName() { - QString file = QFileDialog::getOpenFileName( + return QFileDialog::getOpenFileName( this, tr("Select a File"), QDir::currentPath(), tr("All GC/Wii files (*.elf *.dol *.gcm *.iso *.tgc *.wbfs *.ciso *.gcz *.wad);;" "All Files (*)")); +} + +void MainWindow::ChangeDisc() +{ + QString file = PromptFileName(); + + if (!file.isEmpty()) + Core::RunAsCPUThread([&file] { DVDInterface::ChangeDisc(file.toStdString()); }); +} + +void MainWindow::EjectDisc() +{ + Core::RunAsCPUThread(DVDInterface::EjectDisc); +} + +void MainWindow::Open() +{ + QString file = PromptFileName(); if (!file.isEmpty()) StartGame(file); } diff --git a/Source/Core/DolphinQt2/MainWindow.h b/Source/Core/DolphinQt2/MainWindow.h index e324185385..4a72538050 100644 --- a/Source/Core/DolphinQt2/MainWindow.h +++ b/Source/Core/DolphinQt2/MainWindow.h @@ -128,6 +128,11 @@ private: void OnExportRecording(); void ShowTASInput(); + void ChangeDisc(); + void EjectDisc(); + + QString PromptFileName(); + void EnableScreenSaver(bool enable); void OnStopComplete(); diff --git a/Source/Core/DolphinQt2/MenuBar.cpp b/Source/Core/DolphinQt2/MenuBar.cpp index 8b29277a41..c9f6641a70 100644 --- a/Source/Core/DolphinQt2/MenuBar.cpp +++ b/Source/Core/DolphinQt2/MenuBar.cpp @@ -19,6 +19,7 @@ #include "Common/FileUtil.h" #include "Common/StringUtil.h" +#include "Common/CDUtils.h" #include "Core/Boot/Boot.h" #include "Core/CommonTitles.h" #include "Core/ConfigManager.h" @@ -74,6 +75,10 @@ void MenuBar::OnEmulationStateChanged(Core::State state) bool running = state != Core::State::Uninitialized; bool playing = running && state != Core::State::Paused; + // File + m_eject_disc->setEnabled(running); + m_change_disc->setEnabled(running); + // Emulation m_play_action->setEnabled(!playing); m_play_action->setVisible(!playing); @@ -122,11 +127,34 @@ void MenuBar::OnDebugModeToggled(bool enabled) removeAction(m_symbols->menuAction()); } +void MenuBar::AddDVDBackupMenu(QMenu* file_menu) +{ + m_backup_menu = file_menu->addMenu(tr("Boot from DVD Backup")); + + const std::vector drives = cdio_get_devices(); + // Windows Limitation of 24 character drives + for (size_t i = 0; i < drives.size() && i < 24; i++) + { + auto drive = QString::fromStdString(drives[i]); + AddAction(m_backup_menu, drive, this, [this, drive] { emit BootDVDBackup(drive); }); + } +} + void MenuBar::AddFileMenu() { QMenu* file_menu = addMenu(tr("&File")); m_open_action = AddAction(file_menu, tr("&Open..."), this, &MenuBar::Open, QKeySequence(QStringLiteral("Ctrl+O"))); + + file_menu->addSeparator(); + + m_change_disc = AddAction(file_menu, tr("Change &Disc..."), this, &MenuBar::ChangeDisc); + m_eject_disc = AddAction(file_menu, tr("&Eject Disc"), this, &MenuBar::EjectDisc); + + AddDVDBackupMenu(file_menu); + + file_menu->addSeparator(); + m_exit_action = AddAction(file_menu, tr("E&xit"), this, &MenuBar::Exit, QKeySequence(QStringLiteral("Alt+F4"))); } diff --git a/Source/Core/DolphinQt2/MenuBar.h b/Source/Core/DolphinQt2/MenuBar.h index 2c5b164d05..be848b87fa 100644 --- a/Source/Core/DolphinQt2/MenuBar.h +++ b/Source/Core/DolphinQt2/MenuBar.h @@ -40,6 +40,9 @@ signals: // File void Open(); void Exit(); + void ChangeDisc(); + void BootDVDBackup(const QString& backup); + void EjectDisc(); // Emulation void Play(); @@ -102,6 +105,7 @@ private: void OnEmulationStateChanged(Core::State state); void AddFileMenu(); + void AddDVDBackupMenu(QMenu* file_menu); void AddEmulationMenu(); void AddStateLoadMenu(QMenu* emu_menu); @@ -148,6 +152,9 @@ private: // File QAction* m_open_action; QAction* m_exit_action; + QAction* m_change_disc; + QAction* m_eject_disc; + QMenu* m_backup_menu; // Tools QAction* m_wad_install_action;