From 67c7c2827ffb28524eec4e20911ce1e820aa46b5 Mon Sep 17 00:00:00 2001 From: Janusz Sobczak Date: Thu, 20 May 2010 14:37:31 +0200 Subject: [PATCH] Modified Reset menu action behaviour. Enable 'Reset secret notes' menu action only if user has not supplied correct password. 'Undo reset' menu action has been removed. Signed-off-by: Janusz Sobczak --- src/mainwindow.cpp | 37 +++++++++++-------------------------- src/mainwindow.h | 6 ++---- src/mainwindow.ui | 1 - 3 files changed, 13 insertions(+), 31 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 835bde2..9d8a7c9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -37,10 +37,11 @@ MainWindow::MainWindow(QWidget *parent) : hasReadFile(false) { ui->setupUi(this); + + resetAction = ui->menuOptions->addAction(tr("Reset secret notes")); + connect(resetAction, SIGNAL(triggered()), this, SLOT(on_actionReset_secret_notes_triggered())); + enableTextEdit(false); - undoResetAction = ui->menuOptions->addAction(tr("Undo reset")); - connect(undoResetAction, SIGNAL(triggered()),this, SLOT(undoReset())); - enableUndoReset(false); undoEditAction = ui->menuOptions->addAction(tr("Undo edit")); connect(undoEditAction,SIGNAL(triggered()), this, SLOT(undoEdit())); @@ -64,7 +65,6 @@ MainWindow::MainWindow(QWidget *parent) : MainWindow::~MainWindow() { plaintext.fill(0); - undoText.fill(0); delete ui; if (password) memset(password,0,passLength); @@ -287,14 +287,8 @@ void MainWindow::on_actionReset_secret_notes_triggered() if (password) memset(password, 0, passLength); delete[] password; - password = NULL; - if (plaintext.length() > 0) { - undoText.fill(0); - undoText = plaintext; - } + password = NULL; - if (undoText.length() > 0) - enableUndoReset(true); ui->textEdit->clear(); enableTextEdit(true); askNewPassword(); @@ -338,23 +332,9 @@ void MainWindow::enableTextEdit(bool ena) if (!ena) { ui->textEdit->setPlainText(tr("Secret Notes disabled")); } + enableResetAction(!ena); } -void MainWindow::enableUndoReset(bool ena) -{ - undoResetAction->setVisible(ena); -} - -void MainWindow::undoReset() -{ - plaintext.fill(0); - plaintext = undoText; - undoText.fill(0); - undoText = ""; - ui->textEdit->setPlainText(plaintext); - enableUndoReset(false); - enableTextEdit(true); -} void MainWindow::undoEdit() { @@ -365,3 +345,8 @@ void MainWindow::on_textEdit_undoAvailable(bool b) { undoEditAction->setVisible(b); } + +void MainWindow::enableResetAction(bool b) +{ + resetAction->setVisible(b); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index f3cb59b..9abe266 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -48,10 +48,9 @@ private: void setPassword(const QString& text); void askNewPassword(); QString plaintext; - QString undoText; void enableTextEdit(bool); - void enableUndoReset(bool); - QAction *undoResetAction; + void enableResetAction(bool); + QAction *resetAction; QAction *undoEditAction; QString filePath; @@ -59,7 +58,6 @@ private slots: void on_actionReset_secret_notes_triggered(); void on_actionChange_password_triggered(); void on_textEdit_undoAvailable(bool b); - void undoReset(); void undoEdit(); void readFile(); }; diff --git a/src/mainwindow.ui b/src/mainwindow.ui index f93e6c0..6a6d8cf 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -44,7 +44,6 @@ Options - -- 1.7.9.5