D18352: Remember last output save directory

Kurt Hindenburg noreply at phabricator.kde.org
Sat Apr 13 23:20:53 BST 2019


hindenburg added a comment.


  Can you try this?
  
    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 <KMessageBox>
     #include <KLocalizedString>
    +#include <KSharedConfig>
    +#include <KConfig>
    +#include <KConfigGroup>
     
     #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<KJob *, SaveJob> _jobSession;
    +
    +    static QString _saveDialogRecentURL;
     };
     
     }

REPOSITORY
  R319 Konsole

REVISION DETAIL
  https://phabricator.kde.org/D18352

To: guotao, #konsole
Cc: hindenburg, ngraham, mglb, konsole-devel, gennad, thsurrel, maximilianocuria
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/konsole-devel/attachments/20190413/ea57b84b/attachment-0001.html>


More information about the konsole-devel mailing list