From 74e912ccd3fbbb3aecb4eacfa7ca6efa07ef87ca Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Thu, 4 Jul 2013 13:41:51 +0200 Subject: [PATCH] Remember the dir when opening/saving attachments. --- src/gui/entry/EditEntryWidget.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index 7bf4c62ed..a80267790 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -26,6 +26,7 @@ #include #include +#include "core/Config.h" #include "core/Database.h" #include "core/Entry.h" #include "core/Metadata.h" @@ -605,9 +606,11 @@ void EditEntryWidget::insertAttachment() { Q_ASSERT(!m_history); - // TODO: save last used dir - QString filename = fileDialog()->getOpenFileName(this, tr("Select file"), - QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)); + QString defaultDir = config()->get("LastAttachmentDir").toString(); + if (defaultDir.isEmpty() || !QDir(defaultDir).exists()) { + defaultDir = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation); + } + QString filename = fileDialog()->getOpenFileName(this, tr("Select file"), defaultDir); if (filename.isEmpty() || !QFile::exists(filename)) { return; } @@ -637,8 +640,11 @@ void EditEntryWidget::saveCurrentAttachment() } QString filename = m_attachmentsModel->keyByIndex(index); - // TODO: save last used dir - QDir dir(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)); + QString defaultDirName = config()->get("LastAttachmentDir").toString(); + if (defaultDirName.isEmpty() || !QDir(defaultDirName).exists()) { + defaultDirName = QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation); + } + QDir dir(defaultDirName); QString savePath = fileDialog()->getSaveFileName(this, tr("Save attachment"), dir.filePath(filename)); if (!savePath.isEmpty()) {