Skip to content

Commit 0c421a8

Browse files
committed
#3342 versiondialog: handle writing of encrypted notes
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
1 parent f3f6a51 commit 0c421a8

File tree

5 files changed

+30
-32
lines changed

5 files changed

+30
-32
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
## 25.8.4
44

5-
- Allow decrypting of the note text in the version dialog if the note was decrypted
5+
- Now the version dialog can show decrypted note content if the note was decrypted
66
in the note edit panel (for [#3342](https://github.com/pbek/QOwnNotes/issues/3342))
7+
- The note text will also be restored correctly, depending on if it was encrypted or not
78
- In addition, when doing git versioning with libgit2 support also the diff will be decrypted
89
- When viewing note version with enabled libgit2 support, now a message box will be shown
910
that there are no versions if there are none (for [#3296](https://github.com/pbek/QOwnNotes/issues/3296))

src/dialogs/versiondialog.cpp

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,14 @@ VersionDialog::VersionDialog(const QJSValue &versions, QWidget *parent)
4848
QString itemName;
4949
QString diffHtml;
5050
ui->versionListWidget->clear();
51-
diffList = new QStringList();
52-
dataList = new QStringList();
53-
auto currentNote = MainWindow::instance()->getCurrentNote();
51+
_diffList = new QStringList();
52+
_dataList = new QStringList();
53+
const auto currentNote = MainWindow::instance()->getCurrentNote();
5454
bool canDecryptNoteText = currentNote.canDecryptNoteText();
5555

56-
qDebug() << __func__
57-
<< " - 'currentNote.canDecryptNoteText()': " << currentNote.canDecryptNoteText();
58-
59-
// if (currentNote.canDecryptNoteText()) {
60-
// const QSignalBlocker blocker(ui->encryptedNoteTextEdit);
61-
// Q_UNUSED(blocker)
62-
//
63-
// ui->noteTextEdit->hide();
64-
// const auto text = currentNote.fetchDecryptedNoteText();
65-
6656
// Init the iterator for the versions
6757
QJSValueIterator versionsIterator(versions);
6858

69-
// This seems to report a hasNext even if there aren't any items
70-
if (!versionsIterator.hasNext()) {
71-
return;
72-
}
73-
7459
// Iterate over the versions
7560
while (versionsIterator.hasNext()) {
7661
versionsIterator.next();
@@ -93,19 +78,21 @@ VersionDialog::VersionDialog(const QJSValue &versions, QWidget *parent)
9378
diffHtml.replace(QLatin1String("\n"), QLatin1String("<br />"));
9479

9580
ui->versionListWidget->addItem(itemName);
96-
diffList->append(diffHtml);
81+
_diffList->append(diffHtml);
9782
QString noteText = versionsIterator.value().property(QStringLiteral("data")).toString();
9883

9984
// Decrypt the note text if possible
10085
if (canDecryptNoteText) {
10186
noteText = currentNote.getDecryptedNoteText(Note::parseEncryptedNoteText(noteText));
10287
}
10388

104-
dataList->append(noteText);
89+
_dataList->append(noteText);
10590
}
10691

107-
ui->versionListWidget->setCurrentRow(0);
108-
ui->diffBrowser->setHtml(diffList->at(0));
92+
if (!_diffList->isEmpty()) {
93+
ui->versionListWidget->setCurrentRow(0);
94+
ui->diffBrowser->setHtml(_diffList->at(0));
95+
}
10996
}
11097

11198
void VersionDialog::setupMainSplitter() {
@@ -131,16 +118,16 @@ void VersionDialog::storeSettings() {
131118
VersionDialog::~VersionDialog() { delete ui; }
132119

133120
void VersionDialog::on_versionListWidget_currentRowChanged(int currentRow) {
134-
ui->diffBrowser->setHtml(diffList->value(currentRow));
135-
ui->noteTextEdit->setPlainText(dataList->value(currentRow));
121+
ui->diffBrowser->setHtml(_diffList->value(currentRow));
122+
ui->noteTextEdit->setPlainText(_dataList->value(currentRow));
136123
}
137124

138125
void VersionDialog::dialogButtonClicked(QAbstractButton *button) {
139126
int actionRole = button->property("ActionRole").toInt();
140127

141128
if (actionRole == Restore) {
142129
MainWindow::instance()->setCurrentNoteText(
143-
dataList->value(ui->versionListWidget->currentRow()));
130+
_dataList->value(ui->versionListWidget->currentRow()));
144131
}
145132

146133
this->close();

src/dialogs/versiondialog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class VersionDialog : public MasterDialog {
3333

3434
Ui::VersionDialog *ui;
3535
QSplitter *versionSplitter;
36-
QStringList *diffList;
37-
QStringList *dataList;
36+
QStringList *_diffList;
37+
QStringList *_dataList;
3838
void setupMainSplitter();
3939
};
4040

src/mainwindow.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4599,10 +4599,20 @@ void MainWindow::startNavigationParser() {
45994599
* @brief MainWindow::setCurrentNoteText
46004600
* @param text
46014601
*/
4602-
void MainWindow::setCurrentNoteText(QString text) {
4602+
void MainWindow::setCurrentNoteText(const QString &text) {
4603+
bool canDecryptNoteText = currentNote.canDecryptNoteText();
46034604
allowNoteEditing();
4604-
currentNote.setNoteText(std::move(text));
4605-
setNoteTextFromNote(&currentNote, false);
4605+
4606+
// If the note can be decrypted, we need to show the encrypted note text edit and set the text
4607+
// there
4608+
if (canDecryptNoteText) {
4609+
ui->encryptedNoteTextEdit->setText(text);
4610+
ui->encryptedNoteTextEdit->show();
4611+
ui->noteTextEdit->hide();
4612+
} else {
4613+
currentNote.setNoteText(std::move(text));
4614+
setNoteTextFromNote(&currentNote, false);
4615+
}
46064616
}
46074617

46084618
/**

src/mainwindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class MainWindow : public QMainWindow {
122122

123123
void reloadOpenAiControls();
124124

125-
void setCurrentNoteText(QString text);
125+
void setCurrentNoteText(const QString &text);
126126

127127
void setCurrentNote(Note note, bool updateNoteText = true, bool updateSelectedNote = true,
128128
bool addPreviousNoteToHistory = true);

0 commit comments

Comments
 (0)