diff --git a/src/SaveHistoryTask.h b/src/SaveHistoryTask.h --- a/src/SaveHistoryTask.h +++ b/src/SaveHistoryTask.h @@ -68,6 +68,8 @@ }; QHash _jobSession; + + static QString _saveDialogRecentURL; }; } diff --git a/src/SaveHistoryTask.cpp b/src/SaveHistoryTask.cpp --- 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,17 +50,29 @@ // 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 { QStringLiteral("text/plain"), QStringLiteral("text/html") }; 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 @@ 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