| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | // Copyright 2015 Dolphin Emulator Project
 | 
					
						
							|  |  |  | // Licensed under GPLv2+
 | 
					
						
							|  |  |  | // Refer to the license.txt file included.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QDir>
 | 
					
						
							|  |  |  | #include <QFileDialog>
 | 
					
						
							|  |  |  | #include <QIcon>
 | 
					
						
							|  |  |  | #include <QMessageBox>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Core/BootManager.h"
 | 
					
						
							| 
									
										
										
										
											2016-07-13 01:11:29 +00:00
										 |  |  | #include "Core/ConfigManager.h"
 | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | #include "Core/Core.h"
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | #include "Core/HW/ProcessorInterface.h"
 | 
					
						
							| 
									
										
										
										
											2016-02-15 12:56:40 +11:00
										 |  |  | #include "Core/Movie.h"
 | 
					
						
							|  |  |  | #include "Core/State.h"
 | 
					
						
							| 
									
										
										
										
											2016-05-09 06:34:07 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-11 22:59:44 +11:00
										 |  |  | #include "DolphinQt2/AboutDialog.h"
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | #include "DolphinQt2/Config/PathDialog.h"
 | 
					
						
							|  |  |  | #include "DolphinQt2/Config/SettingsWindow.h"
 | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | #include "DolphinQt2/Host.h"
 | 
					
						
							|  |  |  | #include "DolphinQt2/MainWindow.h"
 | 
					
						
							|  |  |  | #include "DolphinQt2/Resources.h"
 | 
					
						
							| 
									
										
										
										
											2015-12-20 15:36:39 -08:00
										 |  |  | #include "DolphinQt2/Settings.h"
 | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | MainWindow::MainWindow() : QMainWindow(nullptr) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   setWindowTitle(tr("Dolphin")); | 
					
						
							|  |  |  |   setWindowIcon(QIcon(Resources::GetMisc(Resources::LOGO_SMALL))); | 
					
						
							|  |  |  |   setUnifiedTitleAndToolBarOnMac(true); | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   CreateComponents(); | 
					
						
							| 
									
										
										
										
											2016-02-09 20:42:06 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   ConnectGameList(); | 
					
						
							|  |  |  |   ConnectPathsDialog(); | 
					
						
							|  |  |  |   ConnectToolBar(); | 
					
						
							|  |  |  |   ConnectRenderWidget(); | 
					
						
							|  |  |  |   ConnectStack(); | 
					
						
							|  |  |  |   ConnectMenuBar(); | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-14 17:04:16 -08:00
										 |  |  | MainWindow::~MainWindow() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   m_render_widget->deleteLater(); | 
					
						
							| 
									
										
										
										
											2016-02-14 17:04:16 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-09 20:42:06 -08:00
										 |  |  | void MainWindow::CreateComponents() | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   m_menu_bar = new MenuBar(this); | 
					
						
							|  |  |  |   m_tool_bar = new ToolBar(this); | 
					
						
							|  |  |  |   m_game_list = new GameList(this); | 
					
						
							|  |  |  |   m_render_widget = new RenderWidget; | 
					
						
							|  |  |  |   m_stack = new QStackedWidget(this); | 
					
						
							|  |  |  |   m_paths_dialog = new PathDialog(this); | 
					
						
							|  |  |  |   m_settings_window = new SettingsWindow(this); | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-09 20:42:06 -08:00
										 |  |  | void MainWindow::ConnectMenuBar() | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   setMenuBar(m_menu_bar); | 
					
						
							|  |  |  |   // File
 | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::Open, this, &MainWindow::Open); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::Exit, this, &MainWindow::close); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Emulation
 | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::Pause, this, &MainWindow::Pause); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::Play, this, &MainWindow::Play); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::Stop, this, &MainWindow::Stop); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::Reset, this, &MainWindow::Reset); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::Fullscreen, this, &MainWindow::FullScreen); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::FrameAdvance, this, &MainWindow::FrameAdvance); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::Screenshot, this, &MainWindow::ScreenShot); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::StateLoad, this, &MainWindow::StateLoad); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::StateSave, this, &MainWindow::StateSave); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::StateLoadSlot, this, &MainWindow::StateLoadSlot); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::StateSaveSlot, this, &MainWindow::StateSaveSlot); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::StateLoadSlotAt, this, &MainWindow::StateLoadSlotAt); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::StateSaveSlotAt, this, &MainWindow::StateSaveSlotAt); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::StateLoadUndo, this, &MainWindow::StateLoadUndo); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::StateSaveUndo, this, &MainWindow::StateSaveUndo); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::StateSaveOldest, this, &MainWindow::StateSaveOldest); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::SetStateSlot, this, &MainWindow::SetStateSlot); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // View
 | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::ShowTable, m_game_list, &GameList::SetTableView); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::ShowList, m_game_list, &GameList::SetListView); | 
					
						
							|  |  |  |   connect(m_menu_bar, &MenuBar::ShowAboutDialog, this, &MainWindow::ShowAboutDialog); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   connect(this, &MainWindow::EmulationStarted, m_menu_bar, &MenuBar::EmulationStarted); | 
					
						
							|  |  |  |   connect(this, &MainWindow::EmulationPaused, m_menu_bar, &MenuBar::EmulationPaused); | 
					
						
							|  |  |  |   connect(this, &MainWindow::EmulationStopped, m_menu_bar, &MenuBar::EmulationStopped); | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-09 20:42:06 -08:00
										 |  |  | void MainWindow::ConnectToolBar() | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   addToolBar(m_tool_bar); | 
					
						
							|  |  |  |   connect(m_tool_bar, &ToolBar::OpenPressed, this, &MainWindow::Open); | 
					
						
							|  |  |  |   connect(m_tool_bar, &ToolBar::PlayPressed, this, &MainWindow::Play); | 
					
						
							|  |  |  |   connect(m_tool_bar, &ToolBar::PausePressed, this, &MainWindow::Pause); | 
					
						
							|  |  |  |   connect(m_tool_bar, &ToolBar::StopPressed, this, &MainWindow::Stop); | 
					
						
							|  |  |  |   connect(m_tool_bar, &ToolBar::FullScreenPressed, this, &MainWindow::FullScreen); | 
					
						
							|  |  |  |   connect(m_tool_bar, &ToolBar::ScreenShotPressed, this, &MainWindow::ScreenShot); | 
					
						
							|  |  |  |   connect(m_tool_bar, &ToolBar::PathsPressed, this, &MainWindow::ShowPathsDialog); | 
					
						
							|  |  |  |   connect(m_tool_bar, &ToolBar::SettingsPressed, this, &MainWindow::ShowSettingsWindow); | 
					
						
							| 
									
										
										
										
											2015-12-03 20:41:17 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   connect(this, &MainWindow::EmulationStarted, m_tool_bar, &ToolBar::EmulationStarted); | 
					
						
							|  |  |  |   connect(this, &MainWindow::EmulationPaused, m_tool_bar, &ToolBar::EmulationPaused); | 
					
						
							|  |  |  |   connect(this, &MainWindow::EmulationStopped, m_tool_bar, &ToolBar::EmulationStopped); | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-09 20:42:06 -08:00
										 |  |  | void MainWindow::ConnectGameList() | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   connect(m_game_list, &GameList::GameSelected, this, &MainWindow::Play); | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-09 20:42:06 -08:00
										 |  |  | void MainWindow::ConnectRenderWidget() | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   m_rendering_to_main = false; | 
					
						
							|  |  |  |   m_render_widget->hide(); | 
					
						
							|  |  |  |   connect(m_render_widget, &RenderWidget::EscapePressed, this, &MainWindow::Stop); | 
					
						
							|  |  |  |   connect(m_render_widget, &RenderWidget::Closed, this, &MainWindow::ForceStop); | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-09 20:42:06 -08:00
										 |  |  | void MainWindow::ConnectStack() | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   m_stack->setMinimumSize(800, 600); | 
					
						
							|  |  |  |   m_stack->addWidget(m_game_list); | 
					
						
							|  |  |  |   setCentralWidget(m_stack); | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-09 20:42:06 -08:00
										 |  |  | void MainWindow::ConnectPathsDialog() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   connect(m_paths_dialog, &PathDialog::PathAdded, m_game_list, &GameList::DirectoryAdded); | 
					
						
							|  |  |  |   connect(m_paths_dialog, &PathDialog::PathRemoved, m_game_list, &GameList::DirectoryRemoved); | 
					
						
							| 
									
										
										
										
											2016-02-09 20:42:06 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | void MainWindow::Open() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   QString file = QFileDialog::getOpenFileName( | 
					
						
							|  |  |  |       this, tr("Select a File"), QDir::currentPath(), | 
					
						
							| 
									
										
										
										
											2016-12-17 14:48:49 +01:00
										 |  |  |       tr("All GC/Wii files (*.elf *.dol *.gcm *.iso *.tgc *.wbfs *.ciso *.gcz *.wad);;" | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |          "All Files (*)")); | 
					
						
							|  |  |  |   if (!file.isEmpty()) | 
					
						
							|  |  |  |     StartGame(file); | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::Play() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // If we're in a paused game, start it up again.
 | 
					
						
							|  |  |  |   // Otherwise, play the selected game, if there is one.
 | 
					
						
							|  |  |  |   // Otherwise, play the default game.
 | 
					
						
							|  |  |  |   // Otherwise, play the last played game, if there is one.
 | 
					
						
							|  |  |  |   // Otherwise, prompt for a new game.
 | 
					
						
							| 
									
										
										
										
											2017-02-05 07:39:58 -05:00
										 |  |  |   if (Core::GetState() == Core::State::Paused) | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   { | 
					
						
							| 
									
										
										
										
											2017-02-05 07:39:58 -05:00
										 |  |  |     Core::SetState(Core::State::Running); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |     emit EmulationStarted(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     QString selection = m_game_list->GetSelectedGame(); | 
					
						
							|  |  |  |     if (selection.length() > 0) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       StartGame(selection); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       QString default_path = Settings().GetDefaultGame(); | 
					
						
							|  |  |  |       if (!default_path.isEmpty() && QFile::exists(default_path)) | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         StartGame(default_path); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         QString last_path = Settings().GetLastGame(); | 
					
						
							|  |  |  |         if (!last_path.isEmpty() && QFile::exists(last_path)) | 
					
						
							|  |  |  |           StartGame(last_path); | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           Open(); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::Pause() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-02-05 07:39:58 -05:00
										 |  |  |   Core::SetState(Core::State::Paused); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   emit EmulationPaused(); | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool MainWindow::Stop() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   bool stop = true; | 
					
						
							|  |  |  |   if (Settings().GetConfirmStop()) | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     // We could pause the game here and resume it if they say no.
 | 
					
						
							|  |  |  |     QMessageBox::StandardButton confirm; | 
					
						
							|  |  |  |     confirm = QMessageBox::question(m_render_widget, tr("Confirm"), tr("Stop emulation?")); | 
					
						
							|  |  |  |     stop = (confirm == QMessageBox::Yes); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   if (stop) | 
					
						
							| 
									
										
										
										
											2016-07-06 19:00:33 -05:00
										 |  |  |   { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |     ForceStop(); | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-06 19:00:33 -05:00
										 |  |  | #ifdef Q_OS_WIN
 | 
					
						
							|  |  |  |     // Allow windows to idle or turn off display again
 | 
					
						
							|  |  |  |     SetThreadExecutionState(ES_CONTINUOUS); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   return stop; | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::ForceStop() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   BootManager::Stop(); | 
					
						
							|  |  |  |   HideRenderWidget(); | 
					
						
							|  |  |  |   emit EmulationStopped(); | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-15 12:56:40 +11:00
										 |  |  | void MainWindow::Reset() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   if (Movie::IsRecordingInput()) | 
					
						
							| 
									
										
										
										
											2016-08-04 12:54:45 -04:00
										 |  |  |     Movie::SetReset(true); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   ProcessorInterface::ResetButton_Tap(); | 
					
						
							| 
									
										
										
										
											2016-02-15 12:56:40 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::FrameAdvance() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   Movie::DoFrameStep(); | 
					
						
							|  |  |  |   EmulationPaused(); | 
					
						
							| 
									
										
										
										
											2016-02-15 12:56:40 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | void MainWindow::FullScreen() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // If the render widget is fullscreen we want to reset it to whatever is in
 | 
					
						
							|  |  |  |   // settings. If it's set to be fullscreen then it just remakes the window,
 | 
					
						
							|  |  |  |   // which probably isn't ideal.
 | 
					
						
							|  |  |  |   bool was_fullscreen = m_render_widget->isFullScreen(); | 
					
						
							|  |  |  |   HideRenderWidget(); | 
					
						
							|  |  |  |   if (was_fullscreen) | 
					
						
							|  |  |  |     ShowRenderWidget(); | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     m_render_widget->showFullScreen(); | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::ScreenShot() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   Core::SaveScreenShot(); | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-21 19:46:03 -08:00
										 |  |  | void MainWindow::StartGame(const QString& path) | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // If we're running, only start a new game once we've stopped the last.
 | 
					
						
							| 
									
										
										
										
											2017-02-05 07:39:58 -05:00
										 |  |  |   if (Core::GetState() != Core::State::Uninitialized) | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   { | 
					
						
							|  |  |  |     if (!Stop()) | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   // Boot up, show an error if it fails to load the game.
 | 
					
						
							|  |  |  |   if (!BootManager::BootCore(path.toStdString())) | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     QMessageBox::critical(this, tr("Error"), tr("Failed to init core"), QMessageBox::Ok); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   Settings().SetLastGame(path); | 
					
						
							|  |  |  |   ShowRenderWidget(); | 
					
						
							|  |  |  |   emit EmulationStarted(); | 
					
						
							| 
									
										
										
										
											2016-07-06 19:00:33 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef Q_OS_WIN
 | 
					
						
							|  |  |  |   // Prevents Windows from sleeping, turning off the display, or idling
 | 
					
						
							|  |  |  |   EXECUTION_STATE shouldScreenSave = | 
					
						
							|  |  |  |       SConfig::GetInstance().bDisableScreenSaver ? ES_DISPLAY_REQUIRED : 0; | 
					
						
							|  |  |  |   SetThreadExecutionState(ES_CONTINUOUS | shouldScreenSave | ES_SYSTEM_REQUIRED); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::ShowRenderWidget() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   Settings settings; | 
					
						
							|  |  |  |   if (settings.GetRenderToMain()) | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     // If we're rendering to main, add it to the stack and update our title when necessary.
 | 
					
						
							|  |  |  |     m_rendering_to_main = true; | 
					
						
							|  |  |  |     m_stack->setCurrentIndex(m_stack->addWidget(m_render_widget)); | 
					
						
							|  |  |  |     connect(Host::GetInstance(), &Host::RequestTitle, this, &MainWindow::setWindowTitle); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     // Otherwise, just show it.
 | 
					
						
							|  |  |  |     m_rendering_to_main = false; | 
					
						
							|  |  |  |     if (settings.GetFullScreen()) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       m_render_widget->showFullScreen(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       m_render_widget->setFixedSize(settings.GetRenderWindowSize()); | 
					
						
							|  |  |  |       m_render_widget->showNormal(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::HideRenderWidget() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   if (m_rendering_to_main) | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     // Remove the widget from the stack and reparent it to nullptr, so that it can draw
 | 
					
						
							|  |  |  |     // itself in a new window if it wants. Disconnect the title updates.
 | 
					
						
							|  |  |  |     m_stack->removeWidget(m_render_widget); | 
					
						
							|  |  |  |     m_render_widget->setParent(nullptr); | 
					
						
							|  |  |  |     m_rendering_to_main = false; | 
					
						
							|  |  |  |     disconnect(Host::GetInstance(), &Host::RequestTitle, this, &MainWindow::setWindowTitle); | 
					
						
							|  |  |  |     setWindowTitle(tr("Dolphin")); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   m_render_widget->hide(); | 
					
						
							| 
									
										
										
										
											2015-11-27 00:33:07 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-02-09 20:42:06 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::ShowPathsDialog() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   m_paths_dialog->show(); | 
					
						
							|  |  |  |   m_paths_dialog->raise(); | 
					
						
							|  |  |  |   m_paths_dialog->activateWindow(); | 
					
						
							| 
									
										
										
										
											2016-02-09 20:42:06 -08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-02-11 22:59:44 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-09 06:34:07 -07:00
										 |  |  | void MainWindow::ShowSettingsWindow() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   m_settings_window->show(); | 
					
						
							|  |  |  |   m_settings_window->raise(); | 
					
						
							|  |  |  |   m_settings_window->activateWindow(); | 
					
						
							| 
									
										
										
										
											2016-05-09 06:34:07 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-11 22:59:44 +11:00
										 |  |  | void MainWindow::ShowAboutDialog() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   AboutDialog* about = new AboutDialog(this); | 
					
						
							|  |  |  |   about->show(); | 
					
						
							| 
									
										
										
										
											2016-02-11 22:59:44 +11:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-02-15 12:56:40 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::StateLoad() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   QString path = QFileDialog::getOpenFileName(this, tr("Select a File"), QDir::currentPath(), | 
					
						
							|  |  |  |                                               tr("All Save States (*.sav *.s##);; All Files (*)")); | 
					
						
							|  |  |  |   State::LoadAs(path.toStdString()); | 
					
						
							| 
									
										
										
										
											2016-02-15 12:56:40 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::StateSave() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   QString path = QFileDialog::getSaveFileName(this, tr("Select a File"), QDir::currentPath(), | 
					
						
							|  |  |  |                                               tr("All Save States (*.sav *.s##);; All Files (*)")); | 
					
						
							|  |  |  |   State::SaveAs(path.toStdString()); | 
					
						
							| 
									
										
										
										
											2016-02-15 12:56:40 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::StateLoadSlot() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   State::Load(m_state_slot); | 
					
						
							| 
									
										
										
										
											2016-02-15 12:56:40 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::StateSaveSlot() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   State::Save(m_state_slot, true); | 
					
						
							|  |  |  |   m_menu_bar->UpdateStateSlotMenu(); | 
					
						
							| 
									
										
										
										
											2016-02-15 12:56:40 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::StateLoadSlotAt(int slot) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   State::Load(slot); | 
					
						
							| 
									
										
										
										
											2016-02-15 12:56:40 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::StateSaveSlotAt(int slot) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   State::Save(slot, true); | 
					
						
							|  |  |  |   m_menu_bar->UpdateStateSlotMenu(); | 
					
						
							| 
									
										
										
										
											2016-02-15 12:56:40 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::StateLoadUndo() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   State::UndoLoadState(); | 
					
						
							| 
									
										
										
										
											2016-02-15 12:56:40 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::StateSaveUndo() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   State::UndoSaveState(); | 
					
						
							| 
									
										
										
										
											2016-02-15 12:56:40 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::StateSaveOldest() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   State::SaveFirstSaved(); | 
					
						
							| 
									
										
										
										
											2016-02-15 12:56:40 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MainWindow::SetStateSlot(int slot) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   Settings().SetStateSlot(slot); | 
					
						
							|  |  |  |   m_state_slot = slot; | 
					
						
							| 
									
										
										
										
											2016-02-15 12:56:40 +11:00
										 |  |  | } |