From bd49ad358c8c1cb5868cec01211f7f78f485adf9 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 24 Mar 2020 20:56:47 +0100 Subject: [PATCH] Qt: move open_dir to qt_utils --- rpcs3/rpcs3qt/game_list_frame.cpp | 32 ++++--------------------------- rpcs3/rpcs3qt/qt_utils.cpp | 32 +++++++++++++++++++++++++++++++ rpcs3/rpcs3qt/qt_utils.h | 6 ++++++ 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/rpcs3/rpcs3qt/game_list_frame.cpp b/rpcs3/rpcs3qt/game_list_frame.cpp index d3d00d9c9c..da8c8e71ba 100644 --- a/rpcs3/rpcs3qt/game_list_frame.cpp +++ b/rpcs3/rpcs3qt/game_list_frame.cpp @@ -780,30 +780,6 @@ void game_list_frame::SaveSettings() m_gui_settings->SetValue(gui::gl_state, m_game_list->horizontalHeader()->saveState()); } -static void open_dir(const std::string& spath) -{ - fs::create_dir(spath); - const QString path = qstr(spath); - - if (fs::is_file(spath)) - { - // open directory and select file - // https://stackoverflow.com/questions/3490336/how-to-reveal-in-finder-or-show-in-explorer-with-qt -#ifdef _WIN32 - QProcess::startDetached("explorer.exe", { "/select,", QDir::toNativeSeparators(path) }); -#elif defined(__APPLE__) - QProcess::execute("/usr/bin/osascript", { "-e", "tell application \"Finder\" to reveal POSIX file \"" + path + "\"" }); - QProcess::execute("/usr/bin/osascript", { "-e", "tell application \"Finder\" to activate" }); -#else - // open parent directory - QDesktopServices::openUrl(QUrl("file:///" + qstr(fs::get_parent_dir(spath)))); -#endif - return; - } - - QDesktopServices::openUrl(QUrl("file:///" + path)); -} - void game_list_frame::doubleClickedSlot(QTableWidgetItem *item) { if (!item) @@ -983,12 +959,12 @@ void game_list_frame::ShowContextMenu(const QPoint &pos) const std::string new_config_path = Emulator::GetCustomConfigPath(current_game.serial); if (fs::is_file(new_config_path)) - open_dir(new_config_path); + gui::utils::open_dir(new_config_path); const std::string old_config_path = Emulator::GetCustomConfigPath(current_game.serial, true); if (fs::is_file(old_config_path)) - open_dir(old_config_path); + gui::utils::open_dir(old_config_path); }); } if (fs::is_dir(data_base_dir)) @@ -996,7 +972,7 @@ void game_list_frame::ShowContextMenu(const QPoint &pos) QAction* open_data_dir = menu.addAction(tr("&Open Data Folder")); connect(open_data_dir, &QAction::triggered, [=, this]() { - open_dir(data_base_dir); + gui::utils::open_dir(data_base_dir); }); } menu.addSeparator(); @@ -1106,7 +1082,7 @@ void game_list_frame::ShowContextMenu(const QPoint &pos) }); connect(open_game_folder, &QAction::triggered, [=, this]() { - open_dir(current_game.path); + gui::utils::open_dir(current_game.path); }); connect(check_compat, &QAction::triggered, [=, this] { diff --git a/rpcs3/rpcs3qt/qt_utils.cpp b/rpcs3/rpcs3qt/qt_utils.cpp index f8ada24aba..e368a4dd02 100644 --- a/rpcs3/rpcs3qt/qt_utils.cpp +++ b/rpcs3/rpcs3qt/qt_utils.cpp @@ -1,9 +1,12 @@ #include "qt_utils.h" #include #include +#include #include #include +#include #include +#include #include "Emu/System.h" @@ -276,5 +279,34 @@ namespace gui // if nothing was found reset the icon to default return QApplication::windowIcon(); } + + void open_dir(const std::string& spath) + { + fs::create_dir(spath); + const QString path = qstr(spath); + + if (fs::is_file(spath)) + { + // open directory and select file + // https://stackoverflow.com/questions/3490336/how-to-reveal-in-finder-or-show-in-explorer-with-qt +#ifdef _WIN32 + QProcess::startDetached("explorer.exe", { "/select,", QDir::toNativeSeparators(path) }); +#elif defined(__APPLE__) + QProcess::execute("/usr/bin/osascript", { "-e", "tell application \"Finder\" to reveal POSIX file \"" + path + "\"" }); + QProcess::execute("/usr/bin/osascript", { "-e", "tell application \"Finder\" to activate" }); +#else + // open parent directory + QDesktopServices::openUrl(QUrl("file:///" + qstr(fs::get_parent_dir(spath)))); +#endif + return; + } + + QDesktopServices::openUrl(QUrl("file:///" + path)); + } + + void open_dir(const QString& path) + { + open_dir(sstr(path)); + } } // utils } // gui diff --git a/rpcs3/rpcs3qt/qt_utils.h b/rpcs3/rpcs3qt/qt_utils.h index e71fd9ec3a..bb45bfd329 100644 --- a/rpcs3/rpcs3qt/qt_utils.h +++ b/rpcs3/rpcs3qt/qt_utils.h @@ -56,5 +56,11 @@ namespace gui // Loads the app icon from path and embeds it centered into an empty square icon QIcon get_app_icon_from_path(const std::string& path, const std::string& title_id); + + // Open a path in the explorer and mark the file + void open_dir(const std::string& spath); + + // Open a path in the explorer and mark the file + void open_dir(const QString& path); } // utils } // gui