Qt: enum class drop_type

This commit is contained in:
Megamouse 2020-04-22 20:08:07 +02:00
parent 18e0b83ac9
commit 193837298b
2 changed files with 22 additions and 6 deletions

View file

@ -2148,9 +2148,9 @@ Check data for valid file types and cache their paths if necessary
@param savePaths = flag for path caching @param savePaths = flag for path caching
@returns validity of file type @returns validity of file type
*/ */
int main_window::IsValidFile(const QMimeData& md, QStringList* drop_paths) main_window::drop_type main_window::IsValidFile(const QMimeData& md, QStringList* drop_paths)
{ {
int drop_type = drop_type::drop_error; auto drop_type = drop_type::drop_error;
const QList<QUrl> list = md.urls(); // get list of all the dropped file urls const QList<QUrl> list = md.urls(); // get list of all the dropped file urls
@ -2229,8 +2229,11 @@ void main_window::dropEvent(QDropEvent* event)
switch (IsValidFile(*event->mimeData(), &drop_paths)) // get valid file paths and drop type switch (IsValidFile(*event->mimeData(), &drop_paths)) // get valid file paths and drop type
{ {
case drop_type::drop_error: case drop_type::drop_error:
{
break; break;
}
case drop_type::drop_pkg: // install the packages case drop_type::drop_pkg: // install the packages
{
if (drop_paths.count() > 1) if (drop_paths.count() > 1)
{ {
pkg_install_dialog dlg(drop_paths, this); pkg_install_dialog dlg(drop_paths, this);
@ -2249,10 +2252,14 @@ void main_window::dropEvent(QDropEvent* event)
InstallPackages(drop_paths, true); InstallPackages(drop_paths, true);
} }
break; break;
}
case drop_type::drop_pup: // install the firmware case drop_type::drop_pup: // install the firmware
{
InstallPup(drop_paths.first()); InstallPup(drop_paths.first());
break; break;
}
case drop_type::drop_rap: // import rap files to exdata dir case drop_type::drop_rap: // import rap files to exdata dir
{
for (const auto& rap : drop_paths) for (const auto& rap : drop_paths)
{ {
const std::string rapname = sstr(QFileInfo(rap).fileName()); const std::string rapname = sstr(QFileInfo(rap).fileName());
@ -2270,14 +2277,18 @@ void main_window::dropEvent(QDropEvent* event)
// Refresh game list since we probably unlocked some games now. // Refresh game list since we probably unlocked some games now.
m_game_list_frame->Refresh(true); m_game_list_frame->Refresh(true);
break; break;
}
case drop_type::drop_dir: // import valid games to gamelist (games.yaml) case drop_type::drop_dir: // import valid games to gamelist (games.yaml)
{
for (const auto& path : drop_paths) for (const auto& path : drop_paths)
{ {
AddGamesFromDir(path); AddGamesFromDir(path);
} }
m_game_list_frame->Refresh(true); m_game_list_frame->Refresh(true);
break; break;
}
case drop_type::drop_game: // import valid games to gamelist (games.yaml) case drop_type::drop_game: // import valid games to gamelist (games.yaml)
{
if (const auto error = Emu.BootGame(sstr(drop_paths.first()), "", true); error != game_boot_result::no_errors) if (const auto error = Emu.BootGame(sstr(drop_paths.first()), "", true); error != game_boot_result::no_errors)
{ {
gui_log.error("Boot failed: reason: %s, path: %s", error, sstr(drop_paths.first())); gui_log.error("Boot failed: reason: %s, path: %s", error, sstr(drop_paths.first()));
@ -2289,18 +2300,23 @@ void main_window::dropEvent(QDropEvent* event)
m_game_list_frame->Refresh(true); m_game_list_frame->Refresh(true);
} }
break; break;
}
case drop_type::drop_rrc: // replay a rsx capture file case drop_type::drop_rrc: // replay a rsx capture file
{
BootRsxCapture(sstr(drop_paths.first())); BootRsxCapture(sstr(drop_paths.first()));
break; break;
}
default: default:
{
gui_log.warning("Invalid dropType in gamelist dropEvent"); gui_log.warning("Invalid dropType in gamelist dropEvent");
break; break;
} }
}
} }
void main_window::dragEnterEvent(QDragEnterEvent* event) void main_window::dragEnterEvent(QDragEnterEvent* event)
{ {
if (IsValidFile(*event->mimeData())) if (IsValidFile(*event->mimeData()) != drop_type::drop_error)
{ {
event->accept(); event->accept();
} }
@ -2308,7 +2324,7 @@ void main_window::dragEnterEvent(QDragEnterEvent* event)
void main_window::dragMoveEvent(QDragMoveEvent* event) void main_window::dragMoveEvent(QDragMoveEvent* event)
{ {
if (IsValidFile(*event->mimeData())) if (IsValidFile(*event->mimeData()) != drop_type::drop_error)
{ {
event->accept(); event->accept();
} }

View file

@ -62,7 +62,7 @@ class main_window : public QMainWindow
QStringList m_vulkan_adapters; QStringList m_vulkan_adapters;
#endif #endif
enum drop_type enum class drop_type
{ {
drop_error, drop_error,
drop_pkg, drop_pkg,
@ -137,7 +137,7 @@ private:
void InstallPup(QString filePath = ""); void InstallPup(QString filePath = "");
void HandlePupInstallation(QString file_path = ""); void HandlePupInstallation(QString file_path = "");
int IsValidFile(const QMimeData& md, QStringList* drop_paths = nullptr); drop_type IsValidFile(const QMimeData& md, QStringList* drop_paths = nullptr);
void AddGamesFromDir(const QString& path); void AddGamesFromDir(const QString& path);
QAction* CreateRecentAction(const q_string_pair& entry, const uint& sc_idx); QAction* CreateRecentAction(const q_string_pair& entry, const uint& sc_idx);