From 769ab81027393569a2dda80d1744a3ed392a5b2b Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Sun, 14 Feb 2021 10:53:21 -0500 Subject: [PATCH] Setup QFileDialog side urls for various windows. --- src/drivers/Qt/ConsoleWindow.cpp | 149 +++++++++++++++++++++++++++---- src/drivers/Qt/config.cpp | 32 +++---- 2 files changed, 147 insertions(+), 34 deletions(-) diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 5403b07a..c84a42f1 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -1019,7 +1019,10 @@ void consoleWin_t::openROMFile(void) QString filename; std::string last; char dir[512]; + char *romDir; QFileDialog dialog(this, tr("Open ROM File") ); + QList urls; + QDir d; const QStringList filters( { "All Useable files (*.nes *.NES *.nsf *.NSF *.fds *.FDS *.unf *.UNF *.unif *.UNIF *.zip *.ZIP)", @@ -1030,6 +1033,23 @@ void consoleWin_t::openROMFile(void) "Any files (*)" }); + urls << QUrl::fromLocalFile( QDir::rootPath() ); + urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first()); + urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).first()); + urls << QUrl::fromLocalFile( QDir( FCEUI_GetBaseDirectory() ).absolutePath() ); + + romDir = getenv("FCEUX_ROM_PATH"); + + if ( romDir != NULL ) + { + d.setPath(romDir); + + if ( d.exists() ) + { + urls << QUrl::fromLocalFile( d.absolutePath() ); + } + } + dialog.setFileMode(QFileDialog::ExistingFile); dialog.setNameFilters( filters ); @@ -1048,6 +1068,7 @@ void consoleWin_t::openROMFile(void) g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal); dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal); + dialog.setSidebarUrls(urls); dialog.show(); ret = dialog.exec(); @@ -1063,10 +1084,10 @@ void consoleWin_t::openROMFile(void) } } - if ( filename.isNull() ) - { - return; - } + if ( filename.isNull() ) + { + return; + } qDebug() << "selected file path : " << filename.toUtf8(); g_config->setOption ("SDL.LastOpenFile", filename.toStdString().c_str() ); @@ -1092,8 +1113,27 @@ void consoleWin_t::loadNSF(void) QString filename; std::string last; char dir[512]; + char *romDir; QFileDialog dialog(this, tr("Load NSF File") ); + QList urls; + QDir d; + urls << QUrl::fromLocalFile( QDir::rootPath() ); + urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first()); + urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).first()); + urls << QUrl::fromLocalFile( QDir( FCEUI_GetBaseDirectory() ).absolutePath() ); + + romDir = getenv("FCEUX_ROM_PATH"); + + if ( romDir != NULL ) + { + d.setPath(romDir); + + if ( d.exists() ) + { + urls << QUrl::fromLocalFile( d.absolutePath() ); + } + } dialog.setFileMode(QFileDialog::ExistingFile); dialog.setNameFilter(tr("NSF Sound Files (*.nsf *.NSF) ;; Zip Files (*.zip *.ZIP) ;; All files (*)")); @@ -1112,6 +1152,7 @@ void consoleWin_t::loadNSF(void) g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal); dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal); + dialog.setSidebarUrls(urls); dialog.show(); ret = dialog.exec(); @@ -1146,7 +1187,36 @@ void consoleWin_t::loadStateFrom(void) QString filename; std::string last; char dir[512]; + const char *base; QFileDialog dialog(this, tr("Load State From File") ); + QList urls; + QDir d; + + base = FCEUI_GetBaseDirectory(); + + urls << QUrl::fromLocalFile( QDir::rootPath() ); + urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first()); + urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).first()); + + if ( base ) + { + urls << QUrl::fromLocalFile( QDir( base ).absolutePath() ); + + d.setPath( QString(base) + "/fcs"); + + if ( d.exists() ) + { + urls << QUrl::fromLocalFile( d.absolutePath() ); + } + + d.setPath( QString(base) + "/sav"); + + if ( d.exists() ) + { + urls << QUrl::fromLocalFile( d.absolutePath() ); + } + } + dialog.setFileMode(QFileDialog::ExistingFile); @@ -1166,6 +1236,7 @@ void consoleWin_t::loadStateFrom(void) g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal); dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal); + dialog.setSidebarUrls(urls); dialog.show(); ret = dialog.exec(); @@ -1200,7 +1271,35 @@ void consoleWin_t::saveStateAs(void) QString filename; std::string last; char dir[512]; + const char *base; QFileDialog dialog(this, tr("Save State To File") ); + QList urls; + QDir d; + + base = FCEUI_GetBaseDirectory(); + + urls << QUrl::fromLocalFile( QDir::rootPath() ); + urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first()); + urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).first()); + + if ( base ) + { + urls << QUrl::fromLocalFile( QDir( base ).absolutePath() ); + + d.setPath( QString(base) + "/fcs"); + + if ( d.exists() ) + { + urls << QUrl::fromLocalFile( d.absolutePath() ); + } + + d.setPath( QString(base) + "/sav"); + + if ( d.exists() ) + { + urls << QUrl::fromLocalFile( d.absolutePath() ); + } + } dialog.setFileMode(QFileDialog::AnyFile); @@ -1213,6 +1312,13 @@ void consoleWin_t::saveStateAs(void) g_config->getOption ("SDL.LastSaveStateAs", &last ); + if ( last.size() == 0 ) + { + if ( base ) + { + last = std::string(base) + "/sav"; + } + } getDirFromFile( last.c_str(), dir ); dialog.setDirectory( tr(dir) ); @@ -1221,6 +1327,7 @@ void consoleWin_t::saveStateAs(void) g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal); dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal); + dialog.setSidebarUrls(urls); dialog.show(); ret = dialog.exec(); @@ -1237,9 +1344,9 @@ void consoleWin_t::saveStateAs(void) } if ( filename.isNull() ) - { - return; - } + { + return; + } qDebug() << "selected file path : " << filename.toUtf8(); g_config->setOption ("SDL.LastSaveStateAs", filename.toStdString().c_str() ); @@ -1644,6 +1751,11 @@ void consoleWin_t::loadGameGenieROM(void) std::string last; char dir[512]; QFileDialog dialog(this, tr("Open Game Genie ROM") ); + QList urls; + + urls << QUrl::fromLocalFile( QDir::rootPath() ); + urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first()); + urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).first()); dialog.setFileMode(QFileDialog::ExistingFile); @@ -1663,6 +1775,7 @@ void consoleWin_t::loadGameGenieROM(void) g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal); dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal); + dialog.setSidebarUrls(urls); dialog.show(); ret = dialog.exec(); @@ -1678,10 +1791,10 @@ void consoleWin_t::loadGameGenieROM(void) } } - if ( filename.isNull() ) - { - return; - } + if ( filename.isNull() ) + { + return; + } qDebug() << "selected file path : " << filename.toUtf8(); g_config->setOption ("SDL.LastOpenFile", filename.toStdString().c_str() ); @@ -1727,6 +1840,11 @@ void consoleWin_t::fdsLoadBiosFile(void) std::string last; char dir[512]; QFileDialog dialog(this, tr("Load FDS BIOS (disksys.rom)") ); + QList urls; + + urls << QUrl::fromLocalFile( QDir::rootPath() ); + urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first()); + urls << QUrl::fromLocalFile(QStandardPaths::standardLocations(QStandardPaths::DownloadLocation).first()); dialog.setFileMode(QFileDialog::ExistingFile); @@ -1746,6 +1864,7 @@ void consoleWin_t::fdsLoadBiosFile(void) g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal); dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal); + dialog.setSidebarUrls(urls); dialog.show(); ret = dialog.exec(); @@ -1761,10 +1880,10 @@ void consoleWin_t::fdsLoadBiosFile(void) } } - if ( filename.isNull() ) - { - return; - } + if ( filename.isNull() ) + { + return; + } qDebug() << "selected file path : " << filename.toUtf8(); // copy BIOS file to proper place (~/.fceux/disksys.rom) diff --git a/src/drivers/Qt/config.cpp b/src/drivers/Qt/config.cpp index 96dc9de5..c951f256 100644 --- a/src/drivers/Qt/config.cpp +++ b/src/drivers/Qt/config.cpp @@ -195,7 +195,7 @@ GetBaseDirectory(std::string &dir) Config * InitConfig() { - std::string dir, prefix; + std::string dir, prefix, savPath, movPath; Config *config; GetBaseDirectory(dir); @@ -337,24 +337,18 @@ InitConfig() config->addOption("loadstate", "SDL.AutoLoadState", INVALID_STATE); config->addOption("savestate", "SDL.AutoSaveState", INVALID_STATE); - //TODO implement this - config->addOption("periodicsaves", "SDL.PeriodicSaves", 0); + //TODO implement this + config->addOption("periodicsaves", "SDL.PeriodicSaves", 0); + + savPath = dir + "/sav"; + movPath = dir + "/movies"; - char* home_dir = getenv("HOME"); - if ( home_dir == NULL ) - { - home_dir = getenv("HOMEPATH"); - } - if ( home_dir == NULL ) - { - home_dir = ""; - } // prefixed with _ because they are internal (not cli options) - config->addOption("_lastopenfile", "SDL.LastOpenFile", home_dir); - config->addOption("_laststatefrom", "SDL.LastLoadStateFrom", home_dir); - config->addOption("_lastopennsf", "SDL.LastOpenNSF", home_dir); - config->addOption("_lastsavestateas", "SDL.LastSaveStateAs", home_dir); - config->addOption("_lastopenmovie", "SDL.LastOpenMovie", home_dir); + config->addOption("_lastopenfile", "SDL.LastOpenFile", dir); + config->addOption("_laststatefrom", "SDL.LastLoadStateFrom", savPath ); + config->addOption("_lastopennsf", "SDL.LastOpenNSF", dir); + config->addOption("_lastsavestateas", "SDL.LastSaveStateAs", savPath ); + config->addOption("_lastopenmovie", "SDL.LastOpenMovie", movPath); config->addOption("_lastloadlua", "SDL.LastLoadLua", ""); config->addOption("_useNativeFileDialog", "SDL.UseNativeFileDialog", false); @@ -378,8 +372,8 @@ InitConfig() // enable new PPU core config->addOption("newppu", "SDL.NewPPU", 0); - // quit when a+b+select+start is pressed - config->addOption("4buttonexit", "SDL.ABStartSelectExit", 0); + // quit when a+b+select+start is pressed + config->addOption("4buttonexit", "SDL.ABStartSelectExit", 0); // GamePad 0 - 3 for(unsigned int i = 0; i < GAMEPAD_NUM_DEVICES; i++)