diff --git a/Common/System/Request.cpp b/Common/System/Request.cpp index 0e4e53b97b..7ec0a872f2 100644 --- a/Common/System/Request.cpp +++ b/Common/System/Request.cpp @@ -8,6 +8,8 @@ const char *RequestTypeAsString(SystemRequestType type) { switch (type) { case SystemRequestType::INPUT_TEXT_MODAL: return "INPUT_TEXT_MODAL"; case SystemRequestType::BROWSE_FOR_IMAGE: return "BROWSE_FOR_IMAGE"; + case SystemRequestType::BROWSE_FOR_FILE: return "BROWSE_FOR_FILE"; + case SystemRequestType::BROWSE_FOR_FOLDER: return "BROWSE_FOR_FOLDER"; default: return "N/A"; } } diff --git a/Common/System/Request.h b/Common/System/Request.h index bd61104926..856fbb9e41 100644 --- a/Common/System/Request.h +++ b/Common/System/Request.h @@ -75,3 +75,7 @@ enum class BrowseFileType { inline void System_BrowseForFile(const std::string &title, BrowseFileType type, RequestCallback callback) { g_requestManager.MakeSystemRequest(SystemRequestType::BROWSE_FOR_FILE, callback, title, "", (int)type); } + +inline void System_BrowseForFolder(const std::string &title, RequestCallback callback) { + g_requestManager.MakeSystemRequest(SystemRequestType::BROWSE_FOR_FOLDER, callback, title, "", 0); +} diff --git a/Common/System/System.h b/Common/System/System.h index 1e1c04ea4a..1b05cf4960 100644 --- a/Common/System/System.h +++ b/Common/System/System.h @@ -55,6 +55,7 @@ enum class SystemRequestType { INPUT_TEXT_MODAL, BROWSE_FOR_IMAGE, BROWSE_FOR_FILE, + BROWSE_FOR_FOLDER, }; // Implementations are supposed to process the request, and post the response to the g_RequestManager (see Message.h). diff --git a/Qt/QtMain.cpp b/Qt/QtMain.cpp index e05ef5e3ad..966af70b77 100644 --- a/Qt/QtMain.cpp +++ b/Qt/QtMain.cpp @@ -307,10 +307,12 @@ bool MainUI::HandleCustomEvent(QEvent *e) { g_requestManager.PostSystemFailure(g_requestId); } } else if (e->type() == browseFolderEvent) { - auto mm = GetI18NCategory("MainMenu"); - QString fileName = QFileDialog::getExistingDirectory(nullptr, mm->T("Choose folder"), g_Config.currentDirectory.c_str()); + QString title = QString::fromStdString(g_param1); + QString fileName = QFileDialog::getExistingDirectory(nullptr, title, g_Config.currentDirectory.c_str()); if (QDir(fileName).exists()) { - NativeMessageReceived("browse_folderSelect", fileName.toStdString().c_str()); + g_requestManager.PostSystemSuccess(g_requestId, fileName.toStdString().c_str()); + } else { + g_requestManager.PostSystemFailure(g_requestId); } } else if (e->type() == inputBoxEvent) { QString title = QString::fromStdString(g_param1); @@ -348,6 +350,12 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string g_param3 = param3; QCoreApplication::postEvent(emugl, new QEvent((QEvent::Type)browseFileEvent)); return true; + case SystemRequestType::BROWSE_FOR_FOLDER: + g_requestId = requestId; + g_param1 = param1; + g_param2 = param2; + QCoreApplication::postEvent(emugl, new QEvent((QEvent::Type)browseFolderEvent)); + return true; default: return false; } diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index 9a19fe37f2..768b3c4f21 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -540,7 +540,11 @@ UI::EventReturn GameBrowser::LastClick(UI::EventParams &e) { } UI::EventReturn GameBrowser::BrowseClick(UI::EventParams &e) { - System_SendMessage("browse_folder", ""); + auto mm = GetI18NCategory("MainMenu"); + System_BrowseForFolder(mm->T("Choose folder"), [this](const std::string &value, int) { + std::string filename = value; + this->SetPath(Path(filename)); + }); return UI::EVENT_DONE; } @@ -1254,15 +1258,6 @@ void MainScreen::sendMessage(const char *message, const char *value) { if (!strcmp(message, "boot")) { LaunchFile(screenManager(), Path(std::string(value))); } - if (!strcmp(message, "browse_folderSelect")) { - std::string filename = value; - INFO_LOG(SYSTEM, "Got folder: '%s'", filename.c_str()); - int tab = tabHolder_->GetCurrentTab(); - // Don't allow browsing in the other tabs (I don't think it's possible to reach the option though) - if (tab == 1) { - gameBrowsers_[tab]->SetPath(Path(filename)); - } - } } if (!strcmp(message, "permission_granted") && !strcmp(value, "storage")) { RecreateViews(); diff --git a/UI/MemStickScreen.cpp b/UI/MemStickScreen.cpp index 5bf8c83d6f..9b3def0b61 100644 --- a/UI/MemStickScreen.cpp +++ b/UI/MemStickScreen.cpp @@ -445,32 +445,24 @@ UI::EventReturn MemStickScreen::UseStorageRoot(UI::EventParams ¶ms) { } UI::EventReturn MemStickScreen::Browse(UI::EventParams ¶ms) { - System_SendMessage("browse_folder", ""); - return UI::EVENT_DONE; -} + auto mm = GetI18NCategory("MainMenu"); + System_BrowseForFolder(mm->T("Choose folder"), [=](const std::string &value, int) { + std::string filename; + filename = value; + INFO_LOG(SYSTEM, "Got folder: '%s'", filename.c_str()); -void MemStickScreen::sendMessage(const char *message, const char *value) { - // Always call the base class method first to handle the most common messages. - UIDialogScreenWithBackground::sendMessage(message, value); + // Browse finished. Let's pop up the confirmation dialog. + Path pendingMemStickFolder = Path(filename); - if (screenManager()->topScreen() == this) { - if (!strcmp(message, "browse_folderSelect")) { - std::string filename; - filename = value; - INFO_LOG(SYSTEM, "Got folder: '%s'", filename.c_str()); - - // Browse finished. Let's pop up the confirmation dialog. - Path pendingMemStickFolder = Path(filename); - - if (pendingMemStickFolder == g_Config.memStickDirectory) { - auto iz = GetI18NCategory("MemStick"); - return; - } - - bool existingFiles = FolderSeemsToBeUsed(pendingMemStickFolder); - screenManager()->push(new ConfirmMemstickMoveScreen(pendingMemStickFolder, initialSetup_)); + if (pendingMemStickFolder == g_Config.memStickDirectory) { + auto iz = GetI18NCategory("MemStick"); + return; } - } + + bool existingFiles = FolderSeemsToBeUsed(pendingMemStickFolder); + screenManager()->push(new ConfirmMemstickMoveScreen(pendingMemStickFolder, initialSetup_)); + }); + return UI::EVENT_DONE; } void MemStickScreen::dialogFinished(const Screen *dialog, DialogResult result) { diff --git a/UI/MemStickScreen.h b/UI/MemStickScreen.h index 378f4f3ed0..3912e095bc 100644 --- a/UI/MemStickScreen.h +++ b/UI/MemStickScreen.h @@ -48,7 +48,6 @@ public: protected: void CreateViews() override; - void sendMessage(const char *message, const char *value) override; void dialogFinished(const Screen *dialog, DialogResult result) override; void update() override; void render() override {