D18352: Remember last output save directory

Kurt Hindenburg noreply at phabricator.kde.org
Wed Apr 10 04:39:03 BST 2019


hindenburg added a comment.


  Well I decided to try again.  This seems much cleaner and doesn't add any extra dependents.   It works locally and with sftp URLs.  On a side note, I don't think the foreach() loop actually works, so there should be real issue w/ reading/writing the config file every time.
  
    diff --git a/src/SaveHistoryTask.cpp b/src/SaveHistoryTask.cpp
    index a202914d..54156313 100644
    --- a/src/SaveHistoryTask.cpp
    +++ b/src/SaveHistoryTask.cpp
    @@ -26,6 +26,9 @@
     
     #include <KMessageBox>
     #include <KLocalizedString>
    +#include <KSharedConfig>
    +#include <KConfig>
    +#include <KConfigGroup>
     
     #include "SessionManager.h"
     #include "Emulation.h"
    @@ -45,9 +48,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 +57,15 @@ void SaveHistoryTask::execute()
         };
         dialog->setMimeTypeFilters(mimeTypes);
     
    +    KSharedConfigPtr konsoleConfig = KSharedConfig::openConfig();
    +    auto group = konsoleConfig->group("SaveHistory Settings");
    +    const auto list = group.readPathEntry("Recent URLs", QStringList());
    +    if (list.isEmpty()) {
    +        dialog->setDirectory(QDir::homePath());
    +    } else {
    +        dialog->setDirectoryUrl(QUrl(list.at(0)));
    +    }
    +
         // 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 +86,9 @@ void SaveHistoryTask::execute()
                 continue;
             }
     
    +        // Save selected URL for next time
    +        group.writePathEntry("Recent URLs", url.adjusted(QUrl::RemoveFilename|QUrl::StripTrailingSlash).toString());
    +
             KIO::TransferJob* job = KIO::put(url,
                                              -1,   // no special permissions
                                              // overwrite existing files

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/20190410/36e7d335/attachment-0001.html>


More information about the konsole-devel mailing list