* This function opens a file chooser dialog and returns the filename the * user selected. * */
| 610 | * user selected. |
| 611 | * */ |
| 612 | static std::string GetFilename(const char *title, int mode, const char *filter) |
| 613 | { |
| 614 | int ret, useNativeFileDialogVal; |
| 615 | QFileDialog dialog(consoleWindow, title); |
| 616 | std::string initPath; |
| 617 | QList<QUrl> urls; |
| 618 | |
| 619 | //if (FCEUI_EmulationPaused () == 0) |
| 620 | // FCEUI_ToggleEmulationPause (); |
| 621 | std::string fname = ""; |
| 622 | |
| 623 | urls << QUrl::fromLocalFile(QDir::rootPath()); |
| 624 | urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first()); |
| 625 | urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::DesktopLocation).first()); |
| 626 | urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).first()); |
| 627 | urls << QUrl::fromLocalFile(QDir(FCEUI_GetBaseDirectory()).absolutePath()); |
| 628 | |
| 629 | initPath.assign(FCEUI_GetBaseDirectory()); |
| 630 | |
| 631 | switch (mode) |
| 632 | { |
| 633 | case 0: // Save State |
| 634 | dialog.setLabelText(QFileDialog::Accept, dialog.tr("Save")); |
| 635 | dialog.setFileMode(QFileDialog::AnyFile); |
| 636 | initPath += "/fcs"; |
| 637 | break; |
| 638 | default: |
| 639 | case 1: // Load State |
| 640 | dialog.setLabelText(QFileDialog::Accept, dialog.tr("Load")); |
| 641 | dialog.setFileMode(QFileDialog::ExistingFile); |
| 642 | initPath += "/fcs"; |
| 643 | break; |
| 644 | case 2: // Record Movie To |
| 645 | dialog.setLabelText(QFileDialog::Accept, dialog.tr("Record")); |
| 646 | dialog.setFileMode(QFileDialog::AnyFile); |
| 647 | initPath += "/movies"; |
| 648 | break; |
| 649 | case 3: // Load Lua Script |
| 650 | dialog.setLabelText(QFileDialog::Accept, dialog.tr("Load")); |
| 651 | dialog.setFileMode(QFileDialog::ExistingFile); |
| 652 | //initPath += "/fcs"; |
| 653 | break; |
| 654 | } |
| 655 | dialog.setFilter(QDir::AllEntries | QDir::AllDirs | QDir::Hidden); |
| 656 | dialog.setDirectory(dialog.tr(initPath.c_str())); |
| 657 | |
| 658 | // Check config option to use native file dialog or not |
| 659 | g_config->getOption("SDL.UseNativeFileDialog", &useNativeFileDialogVal); |
| 660 | |
| 661 | dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal); |
| 662 | dialog.setSidebarUrls(urls); |
| 663 | |
| 664 | ret = dialog.exec(); |
| 665 | |
| 666 | if (ret) |
| 667 | { |
| 668 | QStringList fileList; |
| 669 | fileList = dialog.selectedFiles(); |
no test coverage detected