Qt: Let the getOpenFileName function class take an optional starting path

This commit is contained in:
Vicki Pfau 2023-07-16 01:44:07 -07:00
parent 4e55bc703c
commit c49050fe65
2 changed files with 21 additions and 9 deletions

View File

@ -169,10 +169,14 @@ void GBAApp::continueAll(const QList<Window*>& paused) {
}
}
QString GBAApp::getOpenFileName(QWidget* owner, const QString& title, const QString& filter) {
QString GBAApp::getOpenFileName(QWidget* owner, const QString& title, const QString& filter, const QString& path) {
QList<Window*> paused;
QString base(path);
if (base.isNull()) {
base = m_configController->getOption("lastDirectory");
}
pauseAll(&paused);
QString filename = QFileDialog::getOpenFileName(owner, title, m_configController->getOption("lastDirectory"), filter);
QString filename = QFileDialog::getOpenFileName(owner, title, base, filter);
continueAll(paused);
if (!filename.isEmpty()) {
m_configController->setOption("lastDirectory", QFileInfo(filename).dir().canonicalPath());
@ -180,10 +184,14 @@ QString GBAApp::getOpenFileName(QWidget* owner, const QString& title, const QStr
return filename;
}
QStringList GBAApp::getOpenFileNames(QWidget* owner, const QString& title, const QString& filter) {
QStringList GBAApp::getOpenFileNames(QWidget* owner, const QString& title, const QString& filter, const QString& path) {
QList<Window*> paused;
QString base(path);
if (base.isNull()) {
base = m_configController->getOption("lastDirectory");
}
pauseAll(&paused);
QStringList filenames = QFileDialog::getOpenFileNames(owner, title, m_configController->getOption("lastDirectory"), filter);
QStringList filenames = QFileDialog::getOpenFileNames(owner, title, base, filter);
continueAll(paused);
if (!filenames.isEmpty()) {
m_configController->setOption("lastDirectory", QFileInfo(filenames.at(0)).dir().canonicalPath());
@ -191,10 +199,14 @@ QStringList GBAApp::getOpenFileNames(QWidget* owner, const QString& title, const
return filenames;
}
QString GBAApp::getSaveFileName(QWidget* owner, const QString& title, const QString& filter) {
QString GBAApp::getSaveFileName(QWidget* owner, const QString& title, const QString& filter, const QString& path) {
QList<Window*> paused;
QString base(path);
if (base.isNull()) {
base = m_configController->getOption("lastDirectory");
}
pauseAll(&paused);
QString filename = QFileDialog::getSaveFileName(owner, title, m_configController->getOption("lastDirectory"), filter);
QString filename = QFileDialog::getSaveFileName(owner, title, base, filter);
continueAll(paused);
if (!filename.isEmpty()) {
m_configController->setOption("lastDirectory", QFileInfo(filename).dir().canonicalPath());

View File

@ -63,9 +63,9 @@ public:
QList<Window*> windows() { return m_windows; }
QString getOpenFileName(QWidget* owner, const QString& title, const QString& filter = {});
QStringList getOpenFileNames(QWidget* owner, const QString& title, const QString& filter = {});
QString getSaveFileName(QWidget* owner, const QString& title, const QString& filter = {});
QString getOpenFileName(QWidget* owner, const QString& title, const QString& filter = {}, const QString& path = {});
QStringList getOpenFileNames(QWidget* owner, const QString& title, const QString& filter = {}, const QString& path = {});
QString getSaveFileName(QWidget* owner, const QString& title, const QString& filter = {}, const QString& path = {});
QString getOpenDirectoryName(QWidget* owner, const QString& title, const QString& path = {});
const NoIntroDB* gameDB() const { return m_db; }