diff --git a/src/kiwixapp.cpp b/src/kiwixapp.cpp index d764a20..e2e7510 100644 --- a/src/kiwixapp.cpp +++ b/src/kiwixapp.cpp @@ -19,6 +19,8 @@ #include #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; +} diff --git a/src/kiwixapp.h b/src/kiwixapp.h index 8c74229..aa5738d 100644 --- a/src/kiwixapp.h +++ b/src/kiwixapp.h @@ -93,6 +93,8 @@ public: void saveWindowState(); void restoreWindowState(); void saveCurrentTabIndex(); + void savePrevSaveDir(const QString& prevSaveDir); + QString getPrevSaveDir() const; public slots: void newTab(); diff --git a/src/kprofile.cpp b/src/kprofile.cpp index a293a63..d1297c2 100644 --- a/src/kprofile.cpp +++ b/src/kprofile.cpp @@ -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); diff --git a/src/webview.cpp b/src/webview.cpp index 6734690..8cee5c6 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -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 */} }