mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-22 11:37:56 -04:00
Save As remember previous save path
Document folder is default.
This commit is contained in:
parent
6ff4dff484
commit
3988067dde
@ -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;
|
||||
}
|
||||
|
@ -93,6 +93,8 @@ public:
|
||||
void saveWindowState();
|
||||
void restoreWindowState();
|
||||
void saveCurrentTabIndex();
|
||||
void savePrevSaveDir(const QString& prevSaveDir);
|
||||
QString getPrevSaveDir() const;
|
||||
|
||||
public slots:
|
||||
void newTab();
|
||||
|
@ -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);
|
||||
|
@ -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 */}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user