diff --git a/src/utils/applicationstate.cpp b/src/utils/applicationstate.cpp index f02cd9892..5a752064f 100644 --- a/src/utils/applicationstate.cpp +++ b/src/utils/applicationstate.cpp @@ -1,37 +1,38 @@ /* utils/applicationstate.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2022 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "applicationstate.h" #include #include #include #include QString ApplicationState::lastUsedExportDirectory() { QString ret; const KConfigGroup stateConfig{KSharedConfig::openStateConfig(), "Export"}; ret = stateConfig.readEntry("LastDirectory"); if (ret.isEmpty()) { // try the normal config for backward compatibility const KConfigGroup config{KSharedConfig::openConfig(), "ExportDialog"}; ret = config.readEntry("LastDirectory"); } return ret.isEmpty() ? QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) : ret; } void ApplicationState::setLastUsedExportDirectory(const QString &path) { + const QFileInfo fi{path}; KConfigGroup stateConfig{KSharedConfig::openStateConfig(), "Export"}; - stateConfig.writeEntry("LastDirectory", QFileInfo{path}.absolutePath()); + stateConfig.writeEntry("LastDirectory", fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath()); } diff --git a/src/utils/applicationstate.h b/src/utils/applicationstate.h index c518c62e2..d5d62a605 100644 --- a/src/utils/applicationstate.h +++ b/src/utils/applicationstate.h @@ -1,21 +1,29 @@ /* utils/applicationstate.h This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2022 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once class QString; namespace ApplicationState { +/** + * Reads the last used export directory from the application state config file. + */ QString lastUsedExportDirectory(); +/** + * Writes the last used export directory to the application state config file. + * If \p path references a file, then the file name is stripped. The path is + * written as absolute path. + */ void setLastUsedExportDirectory(const QString &path); };