diff --git a/src/lib/network/schemehandlers/fileschemehandler.cpp b/src/lib/network/schemehandlers/fileschemehandler.cpp index bd30e3a05..64f248f26 100644 --- a/src/lib/network/schemehandlers/fileschemehandler.cpp +++ b/src/lib/network/schemehandlers/fileschemehandler.cpp @@ -92,9 +92,9 @@ void FileSchemeHandler::handleUrl(const QUrl &url) } else if (status == 2) { // Save - const QString &savePath = QFileDialog::getSaveFileName(mApp->getWindow(), + const QString &savePath = QzTools::getSaveFileName("FileSchemeHandler-Save", mApp->getWindow(), QObject::tr("Save file as..."), - QDir::homePath() + "/" + QzTools::getFileNameFromUrl(url)); + QDir::homePath() + QDir::separator() + QzTools::getFileNameFromUrl(url)); if (!savePath.isEmpty()) { file.copy(savePath); diff --git a/src/lib/other/pagescreen.cpp b/src/lib/other/pagescreen.cpp index 000aba4d2..10050c073 100644 --- a/src/lib/other/pagescreen.cpp +++ b/src/lib/other/pagescreen.cpp @@ -95,7 +95,7 @@ void PageScreen::changeLocation() { const QString &suggestedPath = QString("%1/%2.%3").arg(QDir::homePath(), QzTools::filterCharsFromFilename(m_pageTitle), m_formats[ui->formats->currentIndex()].toLower()); - const QString &path = QFileDialog::getOpenFileName(this, tr("Choose location..."), suggestedPath); + const QString &path = QzTools::getOpenFileName("PageScreen-ChangeLocation", this, tr("Choose location..."), suggestedPath); if (!path.isEmpty()) { ui->location->setText(path); diff --git a/src/lib/preferences/autofillmanager.cpp b/src/lib/preferences/autofillmanager.cpp index 6239322da..5d5c69a28 100644 --- a/src/lib/preferences/autofillmanager.cpp +++ b/src/lib/preferences/autofillmanager.cpp @@ -22,6 +22,7 @@ #include "passwordbackends/passwordbackend.h" #include "mainapplication.h" #include "settings.h" +#include "qztools.h" #include #include @@ -274,7 +275,7 @@ void AutoFillManager::showExceptions() void AutoFillManager::importPasswords() { - m_fileName = QFileDialog::getOpenFileName(this, tr("Choose file..."), QDir::homePath() + "/passwords.xml", "*.xml"); + m_fileName = QzTools::getOpenFileName("AutoFill-ImportPasswords", this, tr("Choose file..."), QDir::homePath() + "/passwords.xml", "*.xml"); if (m_fileName.isEmpty()) { return; @@ -285,7 +286,7 @@ void AutoFillManager::importPasswords() void AutoFillManager::exportPasswords() { - m_fileName = QFileDialog::getSaveFileName(this, tr("Choose file..."), QDir::homePath() + "/passwords.xml", "*.xml"); + m_fileName = QzTools::getSaveFileName("AutoFill-ExportPasswords", this, tr("Choose file..."), QDir::homePath() + "/passwords.xml", "*.xml"); if (m_fileName.isEmpty()) { return; diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index 595fa92c9..307b19cd0 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -581,7 +581,7 @@ void Preferences::chooseDownPath() void Preferences::chooseUserStyleClicked() { - QString file = QFileDialog::getOpenFileName(this, tr("Choose stylesheet location..."), QDir::homePath(), "*.css"); + QString file = QzTools::getOpenFileName("Preferences-UserStyle", this, tr("Choose stylesheet location..."), QDir::homePath(), "*.css"); if (file.isEmpty()) { return; } diff --git a/src/lib/tools/qztools.cpp b/src/lib/tools/qztools.cpp index 41195e165..85f2c9a60 100644 --- a/src/lib/tools/qztools.cpp +++ b/src/lib/tools/qztools.cpp @@ -530,6 +530,7 @@ QString QzTools::getExistingDirectory(const QString &name, QWidget* parent, cons { Settings settings; settings.beginGroup("FileDialogPaths"); + QString lastDir = settings.value(name, dir).toString(); QString path = QFileDialog::getExistingDirectory(parent, caption, lastDir, options); @@ -538,6 +539,7 @@ QString QzTools::getExistingDirectory(const QString &name, QWidget* parent, cons settings.setValue(name, QFileInfo(path).absolutePath()); } + settings.endGroup(); return path; } @@ -545,7 +547,16 @@ QString QzTools::getOpenFileName(const QString &name, QWidget* parent, const QSt { Settings settings; settings.beginGroup("FileDialogPaths"); - QString lastDir = settings.value(name, dir).toString(); + + QString lastDir = settings.value(name, QString()).toString(); + QString fileName = QFileInfo(dir).isFile() ? QFileInfo(dir).fileName() : QString(); + + if (lastDir.isEmpty()) { + lastDir = dir; + } + else { + lastDir.append(QDir::separator() + fileName); + } QString path = QFileDialog::getOpenFileName(parent, caption, lastDir, filter, selectedFilter, options); @@ -553,6 +564,7 @@ QString QzTools::getOpenFileName(const QString &name, QWidget* parent, const QSt settings.setValue(name, QFileInfo(path).absolutePath()); } + settings.endGroup(); return path; } @@ -560,7 +572,16 @@ QStringList QzTools::getOpenFileNames(const QString &name, QWidget* parent, cons { Settings settings; settings.beginGroup("FileDialogPaths"); - QString lastDir = settings.value(name, dir).toString(); + + QString lastDir = settings.value(name, QString()).toString(); + QString fileName = QFileInfo(dir).isFile() ? QFileInfo(dir).fileName() : QString(); + + if (lastDir.isEmpty()) { + lastDir = dir; + } + else { + lastDir.append(QDir::separator() + fileName); + } QStringList paths = QFileDialog::getOpenFileNames(parent, caption, lastDir, filter, selectedFilter, options); @@ -568,6 +589,7 @@ QStringList QzTools::getOpenFileNames(const QString &name, QWidget* parent, cons settings.setValue(name, QFileInfo(paths.first()).absolutePath()); } + settings.endGroup(); return paths; } @@ -575,7 +597,16 @@ QString QzTools::getSaveFileName(const QString &name, QWidget* parent, const QSt { Settings settings; settings.beginGroup("FileDialogPaths"); - QString lastDir = settings.value(name, dir).toString(); + + QString lastDir = settings.value(name, QString()).toString(); + QString fileName = QFileInfo(dir).isFile() ? QFileInfo(dir).fileName() : QString(); + + if (lastDir.isEmpty()) { + lastDir = dir; + } + else { + lastDir.append(QDir::separator() + fileName); + } QString path = QFileDialog::getSaveFileName(parent, caption, lastDir, filter, selectedFilter, options); @@ -583,6 +614,7 @@ QString QzTools::getSaveFileName(const QString &name, QWidget* parent, const QSt settings.setValue(name, QFileInfo(path).absolutePath()); } + settings.endGroup(); return path; } diff --git a/src/lib/webview/siteinfo.cpp b/src/lib/webview/siteinfo.cpp index d3e9d3a25..f37df722a 100644 --- a/src/lib/webview/siteinfo.cpp +++ b/src/lib/webview/siteinfo.cpp @@ -236,7 +236,7 @@ void SiteInfo::downloadImage() QString imageFileName = QzTools::getFileNameFromUrl(QUrl(item->text(1))); - QString filePath = QFileDialog::getSaveFileName(this, tr("Save image..."), QDir::homePath() + "/" + imageFileName); + QString filePath = QzTools::getSaveFileName("SiteInfo-DownloadImage", this, tr("Save image..."), QDir::homePath() + QDir::separator() + imageFileName); if (filePath.isEmpty()) { return; }