Save As remember previous save path

Document folder is default.
This commit is contained in:
ShaopengLin 2024-08-30 05:34:11 -04:00 committed by Kelson
parent 6ff4dff484
commit 3988067dde
4 changed files with 22 additions and 3 deletions

View File

@ -19,6 +19,8 @@
#include <QtPlatformHeaders\QWindowsWindowFunctions>
#endif
const QString DEFAULT_SAVE_DIR = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
////////////////////////////////////////////////////////////////////////////////
// KiwixApp
////////////////////////////////////////////////////////////////////////////////
@ -565,3 +567,15 @@ void KiwixApp::saveCurrentTabIndex()
{
return mp_session->setValue("currentTabIndex", getTabWidget()->currentIndex());
}
void KiwixApp::savePrevSaveDir(const QString &prevSaveDir)
{
mp_session->setValue("prevSaveDir", prevSaveDir);
}
QString KiwixApp::getPrevSaveDir() const
{
QString prevSaveDir = mp_session->value("prevSaveDir", DEFAULT_SAVE_DIR).toString();
QDir dir(prevSaveDir);
return dir.exists() ? prevSaveDir : DEFAULT_SAVE_DIR;
}

View File

@ -93,6 +93,8 @@ public:
void saveWindowState();
void restoreWindowState();
void saveCurrentTabIndex();
void savePrevSaveDir(const QString& prevSaveDir);
QString getPrevSaveDir() const;
public slots:
void newTab();

View File

@ -30,12 +30,13 @@ void KProfile::startDownload(QWebEngineDownloadRequest* download)
#else
QString defaultFileName = download->downloadFileName();
#endif
QString suggestedPath = app->getPrevSaveDir() + "/" + defaultFileName;
QString extension = defaultFileName.section('.', -1);
QString filter = extension != '.' ? "(*" + extension + ")" : "";
QString fileName = QFileDialog::getSaveFileName(
app->getMainWindow(), gt("save-file-as-window-title"),
defaultFileName, filter);
suggestedPath, filter);
if (fileName.isEmpty()) {
return;
@ -43,6 +44,7 @@ void KProfile::startDownload(QWebEngineDownloadRequest* download)
if (!fileName.endsWith(extension)) {
fileName.append(extension);
}
app->savePrevSaveDir(QFileInfo(fileName).absolutePath());
if (download->isSavePageDownload()) {
download->page()->printToPdf(fileName);

View File

@ -148,10 +148,11 @@ void WebView::saveViewContent()
auto mimeType = QByteArray::fromStdString(item.getMimetype());
mimeType = mimeType.split(';')[0];
QString suggestedFileName = item.getTitle().c_str();
if (mimeType == "text/html")
page()->save(QString());
page()->save(suggestedFileName + ".pdf");
else
page()->download(this->url());
page()->download(this->url(), suggestedFileName);
}
catch (...) { /* Blank */}
}