From 67884d60b3647559a4367715350b6e579b248874 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 17 Feb 2019 07:30:40 -0800 Subject: [PATCH 1/3] Qt: Re-enable Load button to browse for file. --- Qt/QtMain.cpp | 29 ++++++++++++++++++++++++++--- UI/MainScreen.cpp | 13 +------------ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index 178f3f82c434..f7a0daf63a1e 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -6,13 +6,15 @@ // Currently supports: Android, Linux, Windows, Mac OSX #include -#include -#include #include #include +#include +#include +#include #include #include #include +#include #include "ext/glslang/glslang/Public/ShaderLang.h" @@ -39,6 +41,7 @@ MainUI *emugl = NULL; static int refreshRate = 60000; +static int browseFileEvent = -1; #ifdef SDL extern void mixaudio(void *userdata, Uint8 *stream, int len) { @@ -94,6 +97,8 @@ bool System_GetPropertyBool(SystemProperty prop) { switch (prop) { case SYSPROP_HAS_BACK_BUTTON: return true; + case SYSPROP_HAS_FILE_BROWSER: + return true; case SYSPROP_APP_GOLD: #ifdef GOLD return true; @@ -108,6 +113,8 @@ bool System_GetPropertyBool(SystemProperty prop) { void System_SendMessage(const char *command, const char *parameter) { if (!strcmp(command, "finish")) { qApp->exit(0); + } else if (!strcmp(command, "browse_file")) { + QCoreApplication::postEvent(emugl, new QEvent((QEvent::Type)browseFileEvent)); } } @@ -190,6 +197,9 @@ static int mainInternal(QApplication &a) { QScopedPointer audio(new MainAudio()); audio->run(); #endif + + browseFileEvent = QEvent::registerEventType(); + int retval = a.exec(); delete emugl; return retval; @@ -387,8 +397,21 @@ bool MainUI::event(QEvent *e) case QEvent::KeyRelease: NativeKey(KeyInput(DEVICE_ID_KEYBOARD, KeyMapRawQttoNative.find(((QKeyEvent*)e)->key())->second, KEY_UP)); break; + default: - return QWidget::event(e); + if (e->type() == browseFileEvent) { + QString fileName = QFileDialog::getOpenFileName(NULL, "Load ROM", g_Config.currentDirectory.c_str(), "PSP ROMs (*.iso *.cso *.pbp *.elf *.zip *.ppdmp)"); + if (QFile::exists(fileName)) { + QDir newPath; + g_Config.currentDirectory = newPath.filePath(fileName).toStdString(); + g_Config.Save(); + + NativeMessageReceived("boot", fileName.toStdString().c_str()); + } + break; + } else { + return QWidget::event(e); + } } e->accept(); return true; diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 904bcfac7f8b..7d90d6763fcf 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -915,8 +915,7 @@ void MainScreen::CreateViews() { TextView *ver = rightColumnItems->Add(new TextView(versionString, new LinearLayoutParams(Margins(70, -6, 0, 0)))); ver->SetSmall(true); ver->SetClip(false); -// Temporarily disabled the load button for Qt. See #11721 -#if defined(_WIN32) // || defined(USING_QT_UI) +#if defined(_WIN32) || defined(USING_QT_UI) rightColumnItems->Add(new Choice(mm->T("Load","Load...")))->OnClick.Handle(this, &MainScreen::OnLoadFile); #endif rightColumnItems->Add(new Choice(mm->T("Game Settings", "Settings")))->OnClick.Handle(this, &MainScreen::OnGameSettings); @@ -1028,16 +1027,6 @@ bool MainScreen::UseVerticalLayout() const { } UI::EventReturn MainScreen::OnLoadFile(UI::EventParams &e) { -#if defined(USING_QT_UI) - QString fileName = QFileDialog::getOpenFileName(NULL, "Load ROM", g_Config.currentDirectory.c_str(), "PSP ROMs (*.iso *.cso *.pbp *.elf *.zip *.ppdmp)"); - if (QFile::exists(fileName)) { - QDir newPath; - g_Config.currentDirectory = newPath.filePath(fileName).toStdString(); - g_Config.Save(); - screenManager()->switchScreen(new EmuScreen(fileName.toStdString())); - } -#endif - if (System_GetPropertyBool(SYSPROP_HAS_FILE_BROWSER)) { System_SendMessage("browse_file", ""); } From 8b40f1a8143d01563234f01ffdee50a4d34abd0c Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 17 Feb 2019 07:48:32 -0800 Subject: [PATCH 2/3] Qt: Correct Browse... handling for multithreaded. --- Qt/QtMain.cpp | 11 +++++++++++ UI/MainScreen.cpp | 43 ++++++++++++++++++++++--------------------- UI/MainScreen.h | 3 ++- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index f7a0daf63a1e..73b6f540ada9 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -31,6 +31,7 @@ #endif #include "QtMain.h" #include "gfx_es2/gpu_features.h" +#include "i18n/i18n.h" #include "math/math_util.h" #include "thread/threadutil.h" #include "util/text/utf8.h" @@ -42,6 +43,7 @@ MainUI *emugl = NULL; static int refreshRate = 60000; static int browseFileEvent = -1; +static int browseFolderEvent = -1; #ifdef SDL extern void mixaudio(void *userdata, Uint8 *stream, int len) { @@ -115,6 +117,8 @@ void System_SendMessage(const char *command, const char *parameter) { qApp->exit(0); } else if (!strcmp(command, "browse_file")) { QCoreApplication::postEvent(emugl, new QEvent((QEvent::Type)browseFileEvent)); + } else if (!strcmp(command, "browse_folder")) { + QCoreApplication::postEvent(emugl, new QEvent((QEvent::Type)browseFolderEvent)); } } @@ -199,6 +203,7 @@ static int mainInternal(QApplication &a) { #endif browseFileEvent = QEvent::registerEventType(); + browseFolderEvent = QEvent::registerEventType(); int retval = a.exec(); delete emugl; @@ -409,6 +414,12 @@ bool MainUI::event(QEvent *e) NativeMessageReceived("boot", fileName.toStdString().c_str()); } break; + } else if (e->type() == browseFolderEvent) { + I18NCategory *mm = GetI18NCategory("MainMenu"); + QString fileName = QFileDialog::getExistingDirectory(nullptr, mm->T("Choose folder"), g_Config.currentDirectory.c_str()); + if (QDir(fileName).exists()) { + NativeMessageReceived("browse_folderSelect", fileName.toStdString().c_str()); + } } else { return QWidget::event(e); } diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 7d90d6763fcf..1fe8038cb85d 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -67,12 +67,6 @@ #include "android/android-ndk-profiler/prof.h" #endif -#ifdef USING_QT_UI -#include -#include -#include -#endif - #include bool MainScreen::showHomebrewTab = false; @@ -447,12 +441,18 @@ GameBrowser::GameBrowser(std::string path, bool allowBrowsing, bool *gridStyle, Refresh(); } -void GameBrowser::FocusGame(std::string gamePath) { +void GameBrowser::FocusGame(const std::string &gamePath) { focusGamePath_ = gamePath; Refresh(); focusGamePath_.clear(); } +void GameBrowser::SetPath(const std::string &path) { + path_.SetPath(path); + g_Config.currentDirectory = path_.GetPath(); + Refresh(); +} + UI::EventReturn GameBrowser::LayoutChange(UI::EventParams &e) { *gridStyle_ = e.a == 0 ? true : false; Refresh(); @@ -466,14 +466,9 @@ UI::EventReturn GameBrowser::LastClick(UI::EventParams &e) { UI::EventReturn GameBrowser::HomeClick(UI::EventParams &e) { #ifdef __ANDROID__ - path_.SetPath(g_Config.memStickDirectory); + SetPath(g_Config.memStickDirectory); #elif defined(USING_QT_UI) - I18NCategory *mm = GetI18NCategory("MainMenu"); - QString fileName = QFileDialog::getExistingDirectory(NULL, "Browse for Folder", g_Config.currentDirectory.c_str()); - if (QDir(fileName).exists()) - path_.SetPath(fileName.toStdString()); - else - return UI::EVENT_DONE; + System_SendMessage("browse_folder", ""); #elif defined(_WIN32) #if PPSSPP_PLATFORM(UWP) // TODO UWP @@ -482,14 +477,12 @@ UI::EventReturn GameBrowser::HomeClick(UI::EventParams &e) { std::string folder = W32Util::BrowseForFolder(MainWindow::GetHWND(), mm->T("Choose folder")); if (!folder.size()) return UI::EVENT_DONE; - path_.SetPath(folder); + SetPath(folder); #endif #else - path_.SetPath(getenv("HOME")); + SetPath(getenv("HOME")); #endif - g_Config.currentDirectory = path_.GetPath(); - Refresh(); return UI::EVENT_DONE; } @@ -742,7 +735,7 @@ UI::EventReturn GameBrowser::GameButtonHighlight(UI::EventParams &e) { } UI::EventReturn GameBrowser::NavigateClick(UI::EventParams &e) { - DirButton *button = static_cast(e.v); + DirButton *button = static_cast(e.v); std::string text = button->GetPath(); if (button->PathAbsolute()) { path_.SetPath(text); @@ -1004,8 +997,16 @@ void MainScreen::sendMessage(const char *message, const char *value) { // Always call the base class method first to handle the most common messages. UIScreenWithBackground::sendMessage(message, value); - if (!strcmp(message, "boot") && screenManager()->topScreen() == this) { - screenManager()->switchScreen(new EmuScreen(value)); + if (screenManager()->topScreen() == this) { + if (!strcmp(message, "boot")) { + screenManager()->switchScreen(new EmuScreen(value)); + } + if (!strcmp(message, "browse_folderSelect")) { + int tab = tabHolder_->GetCurrentTab(); + if (tab >= 0 && tab < (int)gameBrowsers_.size()) { + gameBrowsers_[tab]->SetPath(value); + } + } } if (!strcmp(message, "permission_granted") && !strcmp(value, "storage")) { RecreateViews(); diff --git a/UI/MainScreen.h b/UI/MainScreen.h index d4957e1d7aed..93d21a2984ce 100644 --- a/UI/MainScreen.h +++ b/UI/MainScreen.h @@ -34,7 +34,8 @@ class GameBrowser : public UI::LinearLayout { UI::Choice *HomebrewStoreButton() { return homebrewStoreButton_; } - void FocusGame(std::string gamePath); + void FocusGame(const std::string &gamePath); + void SetPath(const std::string &path); protected: virtual bool DisplayTopBar(); From d19e59dde7d8731d24c2b29184ca2f509e5df206 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 17 Feb 2019 08:03:10 -0800 Subject: [PATCH 3/3] Windows: Browse for folder like Qt. Better to separate out the platform specific stuff. --- UI/MainScreen.cpp | 25 ++++++++++--------------- Windows/main.cpp | 9 ++++++++- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 1fe8038cb85d..8f1fb0044de5 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -58,8 +58,8 @@ #include "Core/HLE/sceUmd.h" #ifdef _WIN32 -#include "Windows/W32Util/ShellUtil.h" -#include "Windows/MainWindow.h" +// Unfortunate, for undef DrawText... +#include "Common/CommonWindows.h" #endif #ifdef ANDROID_NDK_PROFILER @@ -467,18 +467,13 @@ UI::EventReturn GameBrowser::LastClick(UI::EventParams &e) { UI::EventReturn GameBrowser::HomeClick(UI::EventParams &e) { #ifdef __ANDROID__ SetPath(g_Config.memStickDirectory); -#elif defined(USING_QT_UI) - System_SendMessage("browse_folder", ""); -#elif defined(_WIN32) -#if PPSSPP_PLATFORM(UWP) +#elif defined(USING_QT_UI) || defined(USING_WIN_UI) + if (System_GetPropertyBool(SYSPROP_HAS_FILE_BROWSER)) { + System_SendMessage("browse_folder", ""); + } +#elif PPSSPP_PLATFORM(UWP) // TODO UWP -#else - I18NCategory *mm = GetI18NCategory("MainMenu"); - std::string folder = W32Util::BrowseForFolder(MainWindow::GetHWND(), mm->T("Choose folder")); - if (!folder.size()) - return UI::EVENT_DONE; - SetPath(folder); -#endif + SetPath(g_Config.memStickDirectory); #else SetPath(getenv("HOME")); #endif @@ -526,7 +521,7 @@ void GameBrowser::Refresh() { if (allowBrowsing_) { topBar->Add(new Spacer(2.0f)); topBar->Add(new TextView(path_.GetFriendlyPath().c_str(), ALIGN_VCENTER | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, 64.0f, 1.0f))); -#if defined(_WIN32) || defined(USING_QT_UI) +#if defined(USING_WIN_UI) || defined(USING_QT_UI) topBar->Add(new Choice(mm->T("Browse", "Browse..."), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::HomeClick); #else topBar->Add(new Choice(mm->T("Home"), new LayoutParams(WRAP_CONTENT, 64.0f)))->OnClick.Handle(this, &GameBrowser::HomeClick); @@ -908,7 +903,7 @@ void MainScreen::CreateViews() { TextView *ver = rightColumnItems->Add(new TextView(versionString, new LinearLayoutParams(Margins(70, -6, 0, 0)))); ver->SetSmall(true); ver->SetClip(false); -#if defined(_WIN32) || defined(USING_QT_UI) +#if defined(USING_WIN_UI) || defined(USING_QT_UI) rightColumnItems->Add(new Choice(mm->T("Load","Load...")))->OnClick.Handle(this, &MainScreen::OnLoadFile); #endif rightColumnItems->Add(new Choice(mm->T("Game Settings", "Settings")))->OnClick.Handle(this, &MainScreen::OnGameSettings); diff --git a/Windows/main.cpp b/Windows/main.cpp index c3d3dfed7211..5ed2a7331d31 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -27,10 +27,11 @@ #include #include +#include "base/NativeApp.h" #include "base/display.h" #include "file/vfs.h" #include "file/zip_read.h" -#include "base/NativeApp.h" +#include "i18n/i18n.h" #include "profiler/profiler.h" #include "thread/threadutil.h" #include "util/text/utf8.h" @@ -58,6 +59,7 @@ #include "Windows/GEDebugger/GEDebugger.h" #include "Windows/W32Util/DialogManager.h" +#include "Windows/W32Util/ShellUtil.h" #include "Windows/Debugger/CtrlDisAsmView.h" #include "Windows/Debugger/CtrlMemView.h" @@ -274,6 +276,11 @@ void System_SendMessage(const char *command, const char *parameter) { } } else if (!strcmp(command, "browse_file")) { MainWindow::BrowseAndBoot(""); + } else if (!strcmp(command, "browse_folder")) { + I18NCategory *mm = GetI18NCategory("MainMenu"); + std::string folder = W32Util::BrowseForFolder(MainWindow::GetHWND(), mm->T("Choose folder")); + if (folder.size()) + NativeMessageReceived("browse_folderSelect", folder.c_str()); } else if (!strcmp(command, "bgImage_browse")) { MainWindow::BrowseBackground(); } else if (!strcmp(command, "toggle_fullscreen")) {