2010-10-06 13:40:50 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "EditEntryWidget.h"
|
2012-04-14 09:43:41 -04:00
|
|
|
#include "ui_EditEntryWidgetAdvanced.h"
|
2010-10-06 13:40:50 -04:00
|
|
|
#include "ui_EditEntryWidgetMain.h"
|
|
|
|
#include "ui_EditEntryWidgetNotes.h"
|
2012-05-15 06:31:49 -04:00
|
|
|
#include "ui_EditWidget.h"
|
|
|
|
#include "ui_EditWidgetIcons.h"
|
2010-10-06 13:40:50 -04:00
|
|
|
|
2012-05-02 05:11:28 -04:00
|
|
|
#include <QtGui/QDesktopServices>
|
2010-10-06 13:40:50 -04:00
|
|
|
#include <QtGui/QStackedLayout>
|
2012-04-17 10:04:49 -04:00
|
|
|
#include <QtGui/QMessageBox>
|
2010-10-06 13:40:50 -04:00
|
|
|
|
|
|
|
#include "core/Entry.h"
|
2012-05-15 10:50:42 -04:00
|
|
|
#include "core/Metadata.h"
|
2012-05-02 05:11:28 -04:00
|
|
|
#include "core/Tools.h"
|
2012-05-15 09:30:00 -04:00
|
|
|
#include "gui/EditWidgetIcons.h"
|
2012-04-14 09:43:41 -04:00
|
|
|
#include "gui/EntryAttachmentsModel.h"
|
|
|
|
#include "gui/EntryAttributesModel.h"
|
2012-05-02 05:11:28 -04:00
|
|
|
#include "gui/FileDialog.h"
|
2010-10-06 13:40:50 -04:00
|
|
|
|
|
|
|
EditEntryWidget::EditEntryWidget(QWidget* parent)
|
2012-05-15 04:50:08 -04:00
|
|
|
: EditWidget(parent)
|
2010-10-06 13:40:50 -04:00
|
|
|
, m_entry(0)
|
|
|
|
, m_mainUi(new Ui::EditEntryWidgetMain())
|
|
|
|
, m_notesUi(new Ui::EditEntryWidgetNotes())
|
2012-04-14 09:43:41 -04:00
|
|
|
, m_advancedUi(new Ui::EditEntryWidgetAdvanced())
|
2012-05-15 09:30:00 -04:00
|
|
|
, m_mainWidget(new QWidget())
|
|
|
|
, m_notesWidget(new QWidget())
|
|
|
|
, m_advancedWidget(new QWidget())
|
|
|
|
, m_iconsWidget(new EditWidgetIcons())
|
2010-10-06 13:40:50 -04:00
|
|
|
{
|
2012-05-15 04:50:08 -04:00
|
|
|
QFont headerLabelFont = headlineLabel()->font();
|
2010-10-06 16:54:07 -04:00
|
|
|
headerLabelFont.setBold(true);
|
|
|
|
headerLabelFont.setPointSize(headerLabelFont.pointSize() + 2);
|
2012-05-15 04:50:08 -04:00
|
|
|
headlineLabel()->setFont(headerLabelFont);
|
2010-10-06 13:40:50 -04:00
|
|
|
|
|
|
|
m_mainUi->setupUi(m_mainWidget);
|
2012-05-15 04:50:08 -04:00
|
|
|
add(tr("Entry"), m_mainWidget);
|
2010-10-06 13:40:50 -04:00
|
|
|
|
|
|
|
m_notesUi->setupUi(m_notesWidget);
|
2012-05-15 04:50:08 -04:00
|
|
|
add(tr("Description"), m_notesWidget);
|
2010-10-06 13:40:50 -04:00
|
|
|
|
2012-04-14 09:43:41 -04:00
|
|
|
m_advancedUi->setupUi(m_advancedWidget);
|
2012-05-15 04:50:08 -04:00
|
|
|
add(tr("Advanced"), m_advancedWidget);
|
2012-04-14 09:43:41 -04:00
|
|
|
|
2012-05-15 04:50:08 -04:00
|
|
|
add(tr("Icon"), m_iconsWidget);
|
2012-05-09 04:46:22 -04:00
|
|
|
|
2012-04-28 13:11:15 -04:00
|
|
|
m_entryAttachments = new EntryAttachments(this);
|
2012-04-14 09:43:41 -04:00
|
|
|
m_attachmentsModel = new EntryAttachmentsModel(m_advancedWidget);
|
2012-04-28 13:11:15 -04:00
|
|
|
m_attachmentsModel->setEntryAttachments(m_entryAttachments);
|
2012-04-14 09:43:41 -04:00
|
|
|
m_advancedUi->attachmentsView->setModel(m_attachmentsModel);
|
2012-05-02 05:11:28 -04:00
|
|
|
connect(m_advancedUi->saveAttachmentButton, SIGNAL(clicked()), SLOT(saveCurrentAttachment()));
|
|
|
|
connect(m_advancedUi->addAttachmentButton, SIGNAL(clicked()), SLOT(insertAttachment()));
|
|
|
|
connect(m_advancedUi->removeAttachmentButton, SIGNAL(clicked()), SLOT(removeCurrentAttachment()));
|
2012-04-14 09:43:41 -04:00
|
|
|
|
2012-04-28 13:11:15 -04:00
|
|
|
m_entryAttributes = new EntryAttributes(this);
|
2012-04-14 09:43:41 -04:00
|
|
|
m_attributesModel = new EntryAttributesModel(m_advancedWidget);
|
2012-04-28 13:11:15 -04:00
|
|
|
m_attributesModel->setEntryAttributes(m_entryAttributes);
|
2012-04-14 09:43:41 -04:00
|
|
|
m_advancedUi->attributesView->setModel(m_attributesModel);
|
2012-04-28 13:11:15 -04:00
|
|
|
connect(m_advancedUi->addAttributeButton, SIGNAL(clicked()), SLOT(insertAttribute()));
|
|
|
|
connect(m_advancedUi->editAttributeButton, SIGNAL(clicked()), SLOT(editCurrentAttribute()));
|
|
|
|
connect(m_advancedUi->removeAttributeButton, SIGNAL(clicked()), SLOT(removeCurrentAttribute()));
|
|
|
|
connect(m_advancedUi->attributesView->selectionModel(),
|
|
|
|
SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
|
|
|
SLOT(updateCurrentAttribute()));
|
2012-04-14 09:43:41 -04:00
|
|
|
|
2012-01-07 10:18:21 -05:00
|
|
|
connect(m_mainUi->togglePasswordButton, SIGNAL(toggled(bool)), SLOT(togglePassword(bool)));
|
|
|
|
connect(m_mainUi->expireCheck, SIGNAL(toggled(bool)), m_mainUi->expireDatePicker, SLOT(setEnabled(bool)));
|
2012-04-17 10:04:49 -04:00
|
|
|
connect(m_mainUi->passwordEdit, SIGNAL(textEdited(QString)), SLOT(setPasswordCheckColors()));
|
|
|
|
connect(m_mainUi->passwordRepeatEdit, SIGNAL(textEdited(QString)), SLOT(setPasswordCheckColors()));
|
2012-01-07 10:18:21 -05:00
|
|
|
|
2012-05-15 04:50:08 -04:00
|
|
|
connect(this, SIGNAL(accepted()), SLOT(saveEntry()));
|
|
|
|
connect(this, SIGNAL(rejected()), SLOT(cancel()));
|
2010-10-06 13:40:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
EditEntryWidget::~EditEntryWidget()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-14 13:10:42 -04:00
|
|
|
const QColor EditEntryWidget::CorrectSoFarColor = QColor(255, 205, 15);
|
|
|
|
const QColor EditEntryWidget::ErrorColor = QColor(255, 125, 125);
|
2012-04-17 10:04:49 -04:00
|
|
|
|
2012-05-09 04:46:22 -04:00
|
|
|
void EditEntryWidget::loadEntry(Entry* entry, bool create, const QString& groupName,
|
2012-05-13 13:02:07 -04:00
|
|
|
Database* database)
|
2010-10-06 13:40:50 -04:00
|
|
|
{
|
|
|
|
m_entry = entry;
|
2012-05-13 13:02:07 -04:00
|
|
|
m_database = database;
|
2012-05-10 04:29:25 -04:00
|
|
|
m_create = create;
|
2010-10-06 13:40:50 -04:00
|
|
|
|
2011-12-27 10:04:59 -05:00
|
|
|
if (create) {
|
2012-05-15 04:50:08 -04:00
|
|
|
headlineLabel()->setText(groupName+" > "+tr("Add entry"));
|
2011-12-27 10:04:59 -05:00
|
|
|
}
|
|
|
|
else {
|
2012-05-15 04:50:08 -04:00
|
|
|
headlineLabel()->setText(groupName+" > "+tr("Edit entry"));
|
2011-12-27 10:04:59 -05:00
|
|
|
}
|
2010-10-06 16:54:07 -04:00
|
|
|
|
2010-10-06 13:40:50 -04:00
|
|
|
m_mainUi->titleEdit->setText(entry->title());
|
|
|
|
m_mainUi->usernameEdit->setText(entry->username());
|
|
|
|
m_mainUi->urlEdit->setText(entry->url());
|
2012-01-07 10:18:21 -05:00
|
|
|
m_mainUi->passwordEdit->setText(entry->password());
|
|
|
|
m_mainUi->passwordRepeatEdit->setText(entry->password());
|
2012-04-17 10:04:49 -04:00
|
|
|
setPasswordCheckColors();
|
2012-01-07 10:18:21 -05:00
|
|
|
m_mainUi->expireCheck->setChecked(entry->timeInfo().expires());
|
2012-04-18 09:29:04 -04:00
|
|
|
m_mainUi->expireDatePicker->setDateTime(entry->timeInfo().expiryTime().toLocalTime());
|
2012-01-07 10:18:21 -05:00
|
|
|
m_mainUi->togglePasswordButton->setChecked(true);
|
2010-10-06 13:40:50 -04:00
|
|
|
|
|
|
|
m_notesUi->notesEdit->setPlainText(entry->notes());
|
|
|
|
|
2012-04-14 13:38:45 -04:00
|
|
|
m_entryAttributes->copyCustomKeysFrom(entry->attributes());
|
2012-04-23 15:06:04 -04:00
|
|
|
*m_entryAttachments = *entry->attachments();
|
2012-04-14 09:43:41 -04:00
|
|
|
|
2012-05-15 04:50:08 -04:00
|
|
|
setCurrentRow(0);
|
2012-04-23 17:19:29 -04:00
|
|
|
|
2012-04-28 13:11:15 -04:00
|
|
|
if (m_attributesModel->rowCount() != 0) {
|
|
|
|
m_advancedUi->attributesView->setCurrentIndex(m_attributesModel->index(0, 0));
|
|
|
|
}
|
|
|
|
else {
|
2012-04-30 12:22:02 -04:00
|
|
|
m_advancedUi->attributesEdit->setPlainText("");
|
2012-04-28 13:11:15 -04:00
|
|
|
m_advancedUi->attributesEdit->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2012-05-15 09:30:00 -04:00
|
|
|
IconStruct iconStruct;
|
|
|
|
iconStruct.uuid = entry->iconUuid();
|
|
|
|
iconStruct.number = entry->iconNumber();
|
|
|
|
m_iconsWidget->load(entry->uuid(), database, iconStruct);
|
2012-05-09 04:46:22 -04:00
|
|
|
|
2012-04-23 17:19:29 -04:00
|
|
|
m_mainUi->titleEdit->setFocus();
|
2010-10-06 13:40:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::saveEntry()
|
|
|
|
{
|
2012-04-17 10:04:49 -04:00
|
|
|
if (!passwordsEqual()) {
|
|
|
|
QMessageBox::warning(this, tr("Error"), tr("Different passwords supplied."));
|
|
|
|
return;
|
|
|
|
}
|
2012-04-23 15:06:04 -04:00
|
|
|
|
2012-04-28 13:11:15 -04:00
|
|
|
if (m_advancedUi->attributesView->currentIndex().isValid()) {
|
|
|
|
QString key = m_attributesModel->keyByIndex(m_advancedUi->attributesView->currentIndex());
|
|
|
|
m_entryAttributes->set(key, m_advancedUi->attributesEdit->toPlainText(),
|
|
|
|
m_entryAttributes->isProtected(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
m_currentAttribute = QPersistentModelIndex();
|
|
|
|
|
2012-05-10 04:29:25 -04:00
|
|
|
if (!m_create) {
|
|
|
|
m_entry->beginUpdate();
|
|
|
|
}
|
2012-04-23 15:06:04 -04:00
|
|
|
|
2012-04-18 09:23:46 -04:00
|
|
|
m_entry->setTitle(m_mainUi->titleEdit->text());
|
|
|
|
m_entry->setUsername(m_mainUi->usernameEdit->text());
|
|
|
|
m_entry->setUrl(m_mainUi->urlEdit->text());
|
2012-01-07 10:18:21 -05:00
|
|
|
m_entry->setPassword(m_mainUi->passwordEdit->text());
|
2012-04-16 20:27:38 -04:00
|
|
|
m_entry->setExpires(m_mainUi->expireCheck->isChecked());
|
2012-04-18 09:29:04 -04:00
|
|
|
m_entry->setExpiryTime(m_mainUi->expireDatePicker->dateTime().toUTC());
|
2010-10-06 13:40:50 -04:00
|
|
|
|
|
|
|
m_entry->setNotes(m_notesUi->notesEdit->toPlainText());
|
|
|
|
|
2012-04-14 13:38:45 -04:00
|
|
|
m_entry->attributes()->copyCustomKeysFrom(m_entryAttributes);
|
2012-04-23 15:06:04 -04:00
|
|
|
*m_entry->attachments() = *m_entryAttachments;
|
2012-04-14 09:43:41 -04:00
|
|
|
|
2012-05-15 09:30:00 -04:00
|
|
|
IconStruct iconStruct = m_iconsWidget->save();
|
|
|
|
|
2012-05-15 10:50:42 -04:00
|
|
|
if (iconStruct.number < 0) {
|
|
|
|
m_entry->setIcon(Entry::DefaultIconNumber);
|
|
|
|
}
|
|
|
|
else if (iconStruct.uuid.isNull()) {
|
2012-05-15 09:30:00 -04:00
|
|
|
m_entry->setIcon(iconStruct.number);
|
2012-05-09 04:46:22 -04:00
|
|
|
}
|
|
|
|
else {
|
2012-05-15 09:30:00 -04:00
|
|
|
m_entry->setIcon(iconStruct.uuid);
|
2012-05-09 04:46:22 -04:00
|
|
|
}
|
|
|
|
|
2012-05-10 04:29:25 -04:00
|
|
|
if (!m_create) {
|
|
|
|
m_entry->endUpdate();
|
|
|
|
}
|
2012-04-23 15:06:04 -04:00
|
|
|
|
2011-12-27 09:49:06 -05:00
|
|
|
m_entry = 0;
|
2012-05-15 10:50:42 -04:00
|
|
|
m_database = 0;
|
2012-04-28 13:11:15 -04:00
|
|
|
m_entryAttributes->clear();
|
|
|
|
m_entryAttachments->clear();
|
|
|
|
|
2011-12-27 09:49:06 -05:00
|
|
|
Q_EMIT editFinished(true);
|
2010-10-06 13:40:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::cancel()
|
|
|
|
{
|
2012-05-15 10:50:42 -04:00
|
|
|
if (!m_entry->iconUuid().isNull() &&
|
|
|
|
!m_database->metadata()->containsCustomIcon(m_entry->iconUuid())) {
|
|
|
|
m_entry->setIcon(Entry::DefaultIconNumber);
|
|
|
|
}
|
|
|
|
|
2010-10-06 13:40:50 -04:00
|
|
|
m_entry = 0;
|
2012-05-15 10:50:42 -04:00
|
|
|
m_database = 0;
|
2012-04-28 13:11:15 -04:00
|
|
|
m_entryAttributes->clear();
|
|
|
|
m_entryAttachments->clear();
|
|
|
|
|
2011-12-27 09:49:06 -05:00
|
|
|
Q_EMIT editFinished(false);
|
2010-10-06 13:40:50 -04:00
|
|
|
}
|
2012-01-07 10:18:21 -05:00
|
|
|
|
|
|
|
void EditEntryWidget::togglePassword(bool checked)
|
|
|
|
{
|
|
|
|
m_mainUi->passwordEdit->setEchoMode(checked ? QLineEdit::Password : QLineEdit::Normal);
|
|
|
|
m_mainUi->passwordRepeatEdit->setEchoMode(checked ? QLineEdit::Password : QLineEdit::Normal);
|
|
|
|
}
|
2012-04-17 10:04:49 -04:00
|
|
|
|
|
|
|
bool EditEntryWidget::passwordsEqual()
|
|
|
|
{
|
|
|
|
return m_mainUi->passwordEdit->text() == m_mainUi->passwordRepeatEdit->text();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::setPasswordCheckColors()
|
|
|
|
{
|
|
|
|
if (passwordsEqual()) {
|
2012-05-14 14:24:00 -04:00
|
|
|
m_mainUi->passwordRepeatEdit->setStyleSheet("");
|
2012-04-17 10:04:49 -04:00
|
|
|
}
|
|
|
|
else {
|
2012-05-14 14:24:00 -04:00
|
|
|
QString stylesheet = "QLineEdit { background: %1; }";
|
|
|
|
|
2012-04-17 10:04:49 -04:00
|
|
|
if (m_mainUi->passwordEdit->text().startsWith(m_mainUi->passwordRepeatEdit->text())) {
|
2012-05-14 14:24:00 -04:00
|
|
|
stylesheet = stylesheet.arg(CorrectSoFarColor.name());
|
2012-04-17 10:04:49 -04:00
|
|
|
}
|
|
|
|
else {
|
2012-05-14 14:24:00 -04:00
|
|
|
stylesheet = stylesheet.arg(ErrorColor.name());
|
2012-04-17 10:04:49 -04:00
|
|
|
}
|
2012-05-14 14:24:00 -04:00
|
|
|
|
|
|
|
m_mainUi->passwordRepeatEdit->setStyleSheet(stylesheet);
|
2012-04-17 10:04:49 -04:00
|
|
|
}
|
|
|
|
}
|
2012-04-28 13:11:15 -04:00
|
|
|
|
|
|
|
void EditEntryWidget::insertAttribute()
|
|
|
|
{
|
|
|
|
QString name = tr("New attribute");
|
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
while (m_entryAttributes->keys().contains(name)) {
|
|
|
|
name = QString("%1 %2").arg(tr("New attribute")).arg(i);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_entryAttributes->set(name, "");
|
|
|
|
QModelIndex index = m_attributesModel->indexByKey(name);
|
|
|
|
|
|
|
|
m_advancedUi->attributesView->setCurrentIndex(index);
|
|
|
|
m_advancedUi->attributesView->edit(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::editCurrentAttribute()
|
|
|
|
{
|
|
|
|
QModelIndex index = m_advancedUi->attributesView->currentIndex();
|
|
|
|
|
|
|
|
if (index.isValid()) {
|
|
|
|
m_advancedUi->attributesView->edit(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::removeCurrentAttribute()
|
|
|
|
{
|
|
|
|
QModelIndex index = m_advancedUi->attributesView->currentIndex();
|
|
|
|
|
|
|
|
if (index.isValid()) {
|
|
|
|
m_entryAttributes->remove(m_attributesModel->keyByIndex(index));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::updateCurrentAttribute()
|
|
|
|
{
|
|
|
|
QModelIndex newIndex = m_advancedUi->attributesView->currentIndex();
|
|
|
|
|
|
|
|
if (m_currentAttribute != newIndex) {
|
|
|
|
if (m_currentAttribute.isValid()) {
|
|
|
|
QString key = m_attributesModel->keyByIndex(m_currentAttribute);
|
|
|
|
m_entryAttributes->set(key, m_advancedUi->attributesEdit->toPlainText(),
|
|
|
|
m_entryAttributes->isProtected(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newIndex.isValid()) {
|
|
|
|
QString key = m_attributesModel->keyByIndex(newIndex);
|
|
|
|
m_advancedUi->attributesEdit->setPlainText(m_entryAttributes->value(key));
|
|
|
|
m_advancedUi->attributesEdit->setEnabled(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_advancedUi->attributesEdit->setPlainText("");
|
|
|
|
m_advancedUi->attributesEdit->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_advancedUi->editAttributeButton->setEnabled(newIndex.isValid());
|
|
|
|
m_advancedUi->removeAttributeButton->setEnabled(newIndex.isValid());
|
|
|
|
m_currentAttribute = newIndex;
|
|
|
|
}
|
|
|
|
}
|
2012-05-02 05:11:28 -04:00
|
|
|
|
|
|
|
void EditEntryWidget::insertAttachment()
|
|
|
|
{
|
2012-05-11 06:39:06 -04:00
|
|
|
// TODO: save last used dir
|
2012-05-02 05:11:28 -04:00
|
|
|
QString filename = fileDialog()->getOpenFileName(this, tr("Select file"),
|
|
|
|
QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation));
|
|
|
|
if (filename.isEmpty() || !QFile::exists(filename)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFile file(filename);
|
|
|
|
if (!file.open(QIODevice::ReadOnly)) {
|
|
|
|
QMessageBox::warning(this, tr("Error"),
|
|
|
|
tr("Unable to open file:\n").append(file.errorString()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray data;
|
|
|
|
if (!Tools::readAllFromDevice(&file, data)) {
|
|
|
|
QMessageBox::warning(this, tr("Error"),
|
|
|
|
tr("Unable to open file:\n").append(file.errorString()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_entryAttachments->set(QFileInfo(filename).fileName(), data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::saveCurrentAttachment()
|
|
|
|
{
|
|
|
|
QModelIndex index = m_advancedUi->attachmentsView->currentIndex();
|
|
|
|
if (!index.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString filename = m_attachmentsModel->keyByIndex(index);
|
2012-05-11 06:39:06 -04:00
|
|
|
// TODO: save last used dir
|
2012-05-02 05:11:28 -04:00
|
|
|
QDir dir(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation));
|
|
|
|
QString savePath = fileDialog()->getSaveFileName(this, tr("Save attachment"),
|
|
|
|
dir.filePath(filename));
|
|
|
|
if (!savePath.isEmpty()) {
|
|
|
|
QByteArray attachmentData = m_entryAttachments->value(filename);
|
|
|
|
|
|
|
|
QFile file(savePath);
|
|
|
|
if (!file.open(QIODevice::WriteOnly)) {
|
|
|
|
QMessageBox::warning(this, tr("Error"),
|
|
|
|
tr("Unable to save the attachment:\n").append(file.errorString()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (file.write(attachmentData) != attachmentData.size()) {
|
|
|
|
QMessageBox::warning(this, tr("Error"),
|
|
|
|
tr("Unable to save the attachment:\n").append(file.errorString()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditEntryWidget::removeCurrentAttachment()
|
|
|
|
{
|
|
|
|
QModelIndex index = m_advancedUi->attachmentsView->currentIndex();
|
|
|
|
if (!index.isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString key = m_attachmentsModel->keyByIndex(index);
|
|
|
|
m_entryAttachments->remove(key);
|
|
|
|
}
|