diff --git a/src/core/EntryAttachments.cpp b/src/core/EntryAttachments.cpp index c611f4413..8957398cf 100644 --- a/src/core/EntryAttachments.cpp +++ b/src/core/EntryAttachments.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -235,8 +236,10 @@ bool EntryAttachments::openAttachment(const QString& key, QString* errorMessage) const bool saveOk = tmpFile.open() && tmpFile.setPermissions(QFile::ReadOwner | QFile::WriteOwner) && tmpFile.write(attachmentData) == attachmentData.size() && tmpFile.flush(); - if (!saveOk && errorMessage) { - *errorMessage = QString("%1 - %2").arg(key, tmpFile.errorString()); + if (!saveOk) { + if (errorMessage) { + *errorMessage = QString("%1 - %2").arg(key, tmpFile.errorString()); + } return false; } @@ -249,15 +252,35 @@ bool EntryAttachments::openAttachment(const QString& key, QString* errorMessage) watcher->start(tmpFile.fileName(), 5); connect(watcher.data(), &FileWatcher::fileChanged, this, &EntryAttachments::attachmentFileModified); m_attachmentFileWatchers.insert(tmpFile.fileName(), watcher); + } else if (auto path = m_openedAttachments.value(key); m_attachmentFileWatchers.contains(path)) { + // If we are already watching an open attachment file, overwrite it with the information from the entry + auto watcher = m_attachmentFileWatchers.value(path); + watcher->stop(); + + QFile file(path); + auto finally = qScopeGuard([&file, &watcher, &path] { + file.close(); + watcher->start(path, 5); + }); + + const auto attachmentData = value(key); + const bool saveOk = file.open(QIODevice::WriteOnly) && file.setPermissions(QFile::ReadOwner | QFile::WriteOwner) + && file.write(attachmentData) == attachmentData.size() && file.flush(); + + if (!saveOk) { + if (errorMessage) { + *errorMessage = QString("%1 - %2").arg(key, file.errorString()); + } + return false; + } } const bool openOk = QDesktopServices::openUrl(QUrl::fromLocalFile(m_openedAttachments.value(key))); if (!openOk && errorMessage) { *errorMessage = tr("Cannot open file \"%1\"").arg(key); - return false; } - return true; + return openOk; } void EntryAttachments::attachmentFileModified(const QString& path) diff --git a/src/gui/entry/NewEntryAttachmentsDialog.cpp b/src/gui/entry/NewEntryAttachmentsDialog.cpp index b8da3b791..7adbff332 100644 --- a/src/gui/entry/NewEntryAttachmentsDialog.cpp +++ b/src/gui/entry/NewEntryAttachmentsDialog.cpp @@ -33,9 +33,7 @@ NewEntryAttachmentsDialog::NewEntryAttachmentsDialog(QPointer setWindowTitle(tr("New entry attachment")); - m_ui->dialogButtons->clear(); - m_ui->dialogButtons->addButton(QDialogButtonBox::Ok); - m_ui->dialogButtons->addButton(QDialogButtonBox::Cancel); + m_ui->dialogButtons->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(m_ui->dialogButtons, SIGNAL(accepted()), this, SLOT(saveAttachment())); connect(m_ui->dialogButtons, SIGNAL(rejected()), this, SLOT(reject())); @@ -67,7 +65,7 @@ void NewEntryAttachmentsDialog::saveAttachment() auto text = m_ui->attachmentTextEdit->toPlainText().toUtf8(); QString error; - if (validateFileName(fileName, error)) { + if (!validateFileName(fileName, error)) { QMessageBox::warning(this, tr("Save attachment"), error); return; } diff --git a/src/gui/styles/dark/darkstyle.qss b/src/gui/styles/dark/darkstyle.qss index 2b0cfebc0..8da2d1a40 100644 --- a/src/gui/styles/dark/darkstyle.qss +++ b/src/gui/styles/dark/darkstyle.qss @@ -1,14 +1,12 @@ DatabaseWidget:!active, DatabaseWidget #groupView:!active, DatabaseWidget #tagView:!active, -EntryPreviewWidget QLineEdit:!active, EntryPreviewWidget QTextEdit:!active, -EntryPreviewWidget TagsEdit:!active, QStatusBar:!active { +EntryPreviewWidget *:!active[blendIn="true"], QStatusBar:!active { background-color: #404042; } DatabaseWidget:disabled, DatabaseWidget #groupView:disabled, DatabaseWidget #tagView:disabled, -EntryPreviewWidget QLineEdit:disabled, EntryPreviewWidget QTextEdit:disabled, -EntryPreviewWidget TagsEdit:disabled, QStatusBar:disabled { +EntryPreviewWidget *:disabled[blendIn="true"], QStatusBar:disabled { background-color: #424242; } diff --git a/src/gui/styles/light/lightstyle.qss b/src/gui/styles/light/lightstyle.qss index a2b6d7769..0eaf7ca88 100644 --- a/src/gui/styles/light/lightstyle.qss +++ b/src/gui/styles/light/lightstyle.qss @@ -1,14 +1,12 @@ DatabaseWidget:!active, DatabaseWidget #groupView:!active, DatabaseWidget #tagView:!active, -EntryPreviewWidget QLineEdit:!active, EntryPreviewWidget QTextEdit:!active, -EntryPreviewWidget TagsEdit:!active, QStatusBar:!active { +EntryPreviewWidget *:!active[blendIn="true"], QStatusBar:!active { background-color: #FCFCFC; } DatabaseWidget:disabled, DatabaseWidget #groupView:disabled, DatabaseWidget #tagView:disabled, -EntryPreviewWidget QLineEdit:disabled, EntryPreviewWidget QTextEdit:disabled, -EntryPreviewWidget TagsEdit:disabled, QStatusBar:disabled { +EntryPreviewWidget *:disabled[blendIn="true"], QStatusBar:disabled { background-color: #EDEDED; }