Quick GUI: Clear previous/wrong password

This commit is contained in:
Martchus 2018-09-10 19:54:49 +02:00
parent b12b7a7b24
commit 1d3f81ab70
2 changed files with 15 additions and 2 deletions

View File

@ -72,6 +72,9 @@ void Controller::setFilePath(const QString &filePath)
m_fileName = QString::fromLocal8Bit(IoUtilities::fileName(m_file.path()).data());
emit filePathChanged(m_filePath = filePath);
// clear password so we don't use the password from the previous file
m_password.clear();
// handle recent files
const auto index = m_recentFiles.indexOf(m_filePath);
if (!index) {
@ -121,6 +124,8 @@ void Controller::load(const QString &filePath)
if (m_file.isEncryptionUsed() && m_password.isEmpty()) {
emit passwordRequired(m_filePath);
} else {
// clear password since the password which has been provided likely wasn't correct
clearPassword();
emit fileError(tr("A crypto error occured when opening the file: ") + QString::fromLocal8Bit(e.what()));
}
} catch (const runtime_error &e) {
@ -156,6 +161,7 @@ void Controller::close()
{
try {
m_file.close();
m_password.clear();
resetFileStatus();
} catch (...) {
emitIoError(tr("closing"));
@ -293,9 +299,9 @@ bool Controller::copyToClipboard(const QString &text) const
void Controller::resetFileStatus()
{
setFileOpen(false);
m_entryModel.reset();
m_fieldModel.reset();
setFileOpen(false);
}
void Controller::updateWindowTitle()

View File

@ -18,7 +18,7 @@ class Controller : public QObject {
Q_OBJECT
Q_PROPERTY(QString filePath READ filePath WRITE setFilePath NOTIFY filePathChanged)
Q_PROPERTY(QString fileName READ fileName NOTIFY filePathChanged)
Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
Q_PROPERTY(QString password READ password WRITE setPassword RESET clearPassword NOTIFY passwordChanged)
Q_PROPERTY(QString windowTitle READ windowTitle NOTIFY windowTitleChanged)
Q_PROPERTY(bool fileOpen READ isFileOpen NOTIFY fileOpenChanged)
Q_PROPERTY(bool passwordSet READ isPasswordSet NOTIFY passwordChanged)
@ -41,6 +41,7 @@ public:
void setFilePath(const QString &filePath);
const QString &password() const;
void setPassword(const QString &password);
Q_INVOKABLE void clearPassword();
const QString &windowTitle() const;
bool isFileOpen() const;
bool isPasswordSet() const;
@ -130,6 +131,12 @@ inline const QString &Controller::password() const
return m_password;
}
inline void Controller::clearPassword()
{
m_password.clear();
emit passwordChanged(QString());
}
inline const QString &Controller::windowTitle() const
{
return m_windowTitle;