Skip to content

Commit

Permalink
Remember previous download location
Browse files Browse the repository at this point in the history
The last downloaded file's location is remembered and the "Save File" dialog opens in the same directory.
  • Loading branch information
juuz0 committed Jun 13, 2024
1 parent 02c0cd5 commit 3b8927b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
23 changes: 17 additions & 6 deletions src/kiwixapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,32 @@ QString gt(const QString &key) {
return KiwixApp::instance()->getText(key);
}

QString KiwixApp::getZimImportDir() const
{
QString importDir = mp_session->value("zim-import-dir").toString();
if (importDir.isEmpty()) {
importDir = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
if (importDir.isEmpty()) { importDir = QDir::currentPath(); }
}
return importDir;
}

void KiwixApp::setZimImportDir(QString importDir)
{
mp_session->setValue("zim-import-dir", importDir);
}

void KiwixApp::openZimFile(const QString &zimfile)
{
QString _zimfile;
if (zimfile.isEmpty()) {
QString importDir = mp_session->value("zim-import-dir").toString();
if (importDir.isEmpty()) {
importDir = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
if (importDir.isEmpty()) { importDir = QDir::currentPath(); }
}
QString importDir = getZimImportDir();
_zimfile = QFileDialog::getOpenFileName(getMainWindow(), gt("open-zim"), importDir, "ZIM Files (*.zim);;Split ZIM Files (*.zimaa)");

if (_zimfile.isEmpty()) { return; }
_zimfile = QDir::toNativeSeparators(_zimfile);
QFileInfo fileInfo(_zimfile);
mp_session->setValue("zim-import-dir", fileInfo.absolutePath());
setZimImportDir(fileInfo.absolutePath());
}
QString zimId;
const auto &validZimFile = zimfile.isEmpty() ? _zimfile : zimfile;
Expand Down
2 changes: 2 additions & 0 deletions src/kiwixapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class KiwixApp : public QtSingleApplication
kiwix::Server* getLocalServer() { return &m_server; }
SettingsManager* getSettingsManager() { return &m_settingsManager; };
QString getText(const QString &key) { return m_translation.getText(key); };
QString getZimImportDir() const;
void setZimImportDir(QString);
void setMonitorDir(const QString &dir);
bool isCurrentArticleBookmarked();
QString parseStyleFromFile(QString filePath);
Expand Down
5 changes: 4 additions & 1 deletion src/kprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ void KProfile::openFile(WebEngineDownloadType* download)
void KProfile::saveFile(WebEngineDownloadType* download)
{
QString defaultFileName = download->url().fileName();
QString fileName = QFileDialog::getSaveFileName(KiwixApp::instance()->getMainWindow(), "Save File", defaultFileName);
QString fileName = QFileDialog::getSaveFileName(KiwixApp::instance()->getMainWindow(), "Save File",
QDir::cleanPath(KiwixApp::instance()->getZimImportDir() + QDir::separator() + defaultFileName));
if (fileName.isEmpty()) {
download->cancel();
return;
Expand All @@ -65,6 +66,8 @@ void KProfile::saveFile(WebEngineDownloadType* download)
fileName.append(extension);
}
setDownloadFilePath(download, fileName);
QFileInfo fileInfo(fileName);
KiwixApp::instance()->setZimImportDir(fileInfo.absolutePath());
download->accept();
}

Expand Down

0 comments on commit 3b8927b

Please sign in to comment.