From 61ed2c88a4e205eb5eef2df6cdb13c7ddd6e2943 Mon Sep 17 00:00:00 2001 From: Kurt Hindenburg Date: Sun, 21 Apr 2019 15:12:13 -0400 Subject: [PATCH] Remember last 'Save Output As' directory This will save current session's last 'Save Output As' directory as well as saving it so next Konsole startup will remember it. Original code by Tao Guo with additions by myself. BUG: 403103 FIXED-IN: 19.08.0 Differential Revision: https://phabricator.kde.org/D18352 --- src/SaveHistoryTask.cpp | 27 ++++++++++++++++++++++++--- src/SaveHistoryTask.h | 2 ++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/SaveHistoryTask.cpp b/src/SaveHistoryTask.cpp index a202914d..16ab661c 100644 --- a/src/SaveHistoryTask.cpp +++ b/src/SaveHistoryTask.cpp @@ -26,12 +26,17 @@ #include #include +#include +#include +#include #include "SessionManager.h" #include "Emulation.h" namespace Konsole { +QString SaveHistoryTask::_saveDialogRecentURL; + SaveHistoryTask::SaveHistoryTask(QObject* parent) : SessionTask(parent) { @@ -45,9 +50,7 @@ void SaveHistoryTask::execute() // three then providing a URL for each one will be tedious // TODO - show a warning ( preferably passive ) if saving the history output fails - QFileDialog* dialog = new QFileDialog(QApplication::activeWindow(), - QString(), - QDir::homePath()); + QFileDialog* dialog = new QFileDialog(QApplication::activeWindow()); dialog->setAcceptMode(QFileDialog::AcceptSave); QStringList mimeTypes { @@ -56,6 +59,20 @@ void SaveHistoryTask::execute() }; dialog->setMimeTypeFilters(mimeTypes); + KSharedConfigPtr konsoleConfig = KSharedConfig::openConfig(); + auto group = konsoleConfig->group("SaveHistory Settings"); + + if (_saveDialogRecentURL.isEmpty()) { + const auto list = group.readPathEntry("Recent URLs", QStringList()); + if (list.isEmpty()) { + dialog->setDirectory(QDir::homePath()); + } else { + dialog->setDirectoryUrl(QUrl(list.at(0))); + } + } else { + dialog->setDirectoryUrl(QUrl(_saveDialogRecentURL)); + } + // iterate over each session in the task and display a dialog to allow the user to choose where // to save that session's history. // then start a KIO job to transfer the data from the history to the chosen URL @@ -76,6 +93,10 @@ void SaveHistoryTask::execute() continue; } + // Save selected URL for next time + _saveDialogRecentURL = url.adjusted(QUrl::RemoveFilename|QUrl::StripTrailingSlash).toString(); + group.writePathEntry("Recent URLs", _saveDialogRecentURL); + KIO::TransferJob* job = KIO::put(url, -1, // no special permissions // overwrite existing files diff --git a/src/SaveHistoryTask.h b/src/SaveHistoryTask.h index c90c7e9e..65504d6f 100644 --- a/src/SaveHistoryTask.h +++ b/src/SaveHistoryTask.h @@ -68,6 +68,8 @@ private: }; QHash _jobSession; + + static QString _saveDialogRecentURL; }; }