Skip to content

Commit

Permalink
Qt: fix opening folders by using util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse committed Dec 10, 2022
1 parent 8399516 commit d873c21
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
1 change: 1 addition & 0 deletions rpcs3/emucore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,7 @@
</ClCompile>
<ClCompile Include="Emu\Io\recording_config.cpp">
<Filter>Emu\Io</Filter>
</ClCompile>
<ClCompile Include="Emu\Cell\Modules\HLE_PATCHES.cpp">
<Filter>Emu\Cell\Modules</Filter>
</ClCompile>
Expand Down
38 changes: 34 additions & 4 deletions rpcs3/rpcs3qt/qt_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "stdafx.h"
#include "qt_utils.h"
#include <QApplication>
#include <QBitmap>
Expand All @@ -12,6 +13,8 @@
#include "Utilities/File.h"
#include <cmath>

LOG_CHANNEL(gui_log, "GUI");

inline std::string sstr(const QString& _in) { return _in.toStdString(); }
constexpr auto qstr = QString::fromStdString;

Expand Down Expand Up @@ -394,26 +397,53 @@ namespace gui

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) });
const QString cleaned_path = QDir::toNativeSeparators(path);
gui_log.notice("gui::utils::open_dir: About to open file path '%s' (original: '%s')", cleaned_path, spath);

if (!QProcess::startDetached("explorer.exe", {"/select,", cleaned_path}))
{
gui_log.error("gui::utils::open_dir: Failed to start explorer process");
}
#elif defined(__APPLE__)
gui_log.notice("gui::utils::open_dir: About to open file path '%s'", spath);

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::fromLocalFile(qstr(fs::get_parent_dir(spath))));
const QUrl url = QUrl::fromLocalFile(qstr(fs::get_parent_dir(spath)));
const std::string url_path = url.toString().toStdString();
gui_log.notice("gui::utils::open_dir: About to open parent dir url '%s' for path '%s'", url_path, spath);

if (!QDesktopServices::openUrl(url))
{
gui_log.error("gui::utils::open_dir: Failed to open parent dir url '%s' for path '%s'", url_path, spath);
}
#endif
return;
}

QDesktopServices::openUrl(QUrl::fromLocalFile(path));
if (!fs::is_dir && !fs::create_path(spath))
{
gui_log.error("gui::utils::open_dir: Failed to create path '%s' (%s)", spath, fs::g_tls_error);
return;
}

const QUrl url = QUrl::fromLocalFile(path);
const std::string url_path = url.toString().toStdString();
gui_log.notice("gui::utils::open_dir: About to open dir url '%s' for path '%s'", url_path, spath);

if (!QDesktopServices::openUrl(url))
{
gui_log.error("gui::utils::open_dir: Failed to open dir url '%s' for path '%s'", url_path, spath);
}
}

void open_dir(const QString& path)
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/rpcs3qt/save_manager_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void save_manager_dialog::Init()
}
const int idx_real = item->data(Qt::UserRole).toInt();
const QString path = qstr(m_dir + m_save_entries[idx_real].dirName + "/");
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
gui::utils::open_dir(path);
});
connect(slider_icon_size, &QAbstractSlider::valueChanged, this, &save_manager_dialog::SetIconSize);
connect(m_list->horizontalHeader(), &QHeaderView::sectionClicked, this, &save_manager_dialog::OnSort);
Expand Down Expand Up @@ -488,7 +488,7 @@ void save_manager_dialog::ShowContextMenu(const QPoint &pos)
}
const int idx_real = item->data(Qt::UserRole).toInt();
const QString path = qstr(m_dir + m_save_entries[idx_real].dirName + "/");
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
gui::utils::open_dir(path);
});

menu->exec(m_list->viewport()->mapToGlobal(pos));
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/rpcs3qt/trophy_manager_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ void trophy_manager_dialog::ShowTrophyTableContextMenu(const QPoint& pos)
connect(show_trophy_dir, &QAction::triggered, this, [this, db_ind]()
{
const QString path = qstr(m_trophies_db[db_ind]->path);
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
gui::utils::open_dir(path);
});

menu->addAction(show_trophy_dir);
Expand Down Expand Up @@ -802,7 +802,7 @@ void trophy_manager_dialog::ShowGameTableContextMenu(const QPoint& pos)
connect(show_trophy_dir, &QAction::triggered, this, [this, db_ind]()
{
const QString path = qstr(m_trophies_db[db_ind]->path);
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
gui::utils::open_dir(path);
});

menu->addAction(show_trophy_dir);
Expand Down
3 changes: 2 additions & 1 deletion rpcs3/rpcs3qt/user_manager_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "main_application.h"
#include "gui_settings.h"
#include "persistent_settings.h"
#include "qt_utils.h"

#include "Emu/System.h"
#include "Emu/system_utils.hpp"
Expand Down Expand Up @@ -426,7 +427,7 @@ void user_manager_dialog::ShowContextMenu(const QPoint &pos)
connect(show_dir_act, &QAction::triggered, this, [this, key]()
{
const QString path = qstr(m_user_list[key].GetUserDir());
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
gui::utils::open_dir(path);
});

connect(user_id_act, &QAction::triggered, this, [this] {OnSort(0); });
Expand Down

0 comments on commit d873c21

Please sign in to comment.