Quick GUI: Clear previous/wrong password
This commit is contained in:
parent
b12b7a7b24
commit
1d3f81ab70
|
@ -72,6 +72,9 @@ void Controller::setFilePath(const QString &filePath)
|
||||||
m_fileName = QString::fromLocal8Bit(IoUtilities::fileName(m_file.path()).data());
|
m_fileName = QString::fromLocal8Bit(IoUtilities::fileName(m_file.path()).data());
|
||||||
emit filePathChanged(m_filePath = filePath);
|
emit filePathChanged(m_filePath = filePath);
|
||||||
|
|
||||||
|
// clear password so we don't use the password from the previous file
|
||||||
|
m_password.clear();
|
||||||
|
|
||||||
// handle recent files
|
// handle recent files
|
||||||
const auto index = m_recentFiles.indexOf(m_filePath);
|
const auto index = m_recentFiles.indexOf(m_filePath);
|
||||||
if (!index) {
|
if (!index) {
|
||||||
|
@ -121,6 +124,8 @@ void Controller::load(const QString &filePath)
|
||||||
if (m_file.isEncryptionUsed() && m_password.isEmpty()) {
|
if (m_file.isEncryptionUsed() && m_password.isEmpty()) {
|
||||||
emit passwordRequired(m_filePath);
|
emit passwordRequired(m_filePath);
|
||||||
} else {
|
} 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()));
|
emit fileError(tr("A crypto error occured when opening the file: ") + QString::fromLocal8Bit(e.what()));
|
||||||
}
|
}
|
||||||
} catch (const runtime_error &e) {
|
} catch (const runtime_error &e) {
|
||||||
|
@ -156,6 +161,7 @@ void Controller::close()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
m_file.close();
|
m_file.close();
|
||||||
|
m_password.clear();
|
||||||
resetFileStatus();
|
resetFileStatus();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
emitIoError(tr("closing"));
|
emitIoError(tr("closing"));
|
||||||
|
@ -293,9 +299,9 @@ bool Controller::copyToClipboard(const QString &text) const
|
||||||
|
|
||||||
void Controller::resetFileStatus()
|
void Controller::resetFileStatus()
|
||||||
{
|
{
|
||||||
setFileOpen(false);
|
|
||||||
m_entryModel.reset();
|
m_entryModel.reset();
|
||||||
m_fieldModel.reset();
|
m_fieldModel.reset();
|
||||||
|
setFileOpen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::updateWindowTitle()
|
void Controller::updateWindowTitle()
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Controller : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString filePath READ filePath WRITE setFilePath NOTIFY filePathChanged)
|
Q_PROPERTY(QString filePath READ filePath WRITE setFilePath NOTIFY filePathChanged)
|
||||||
Q_PROPERTY(QString fileName READ fileName 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(QString windowTitle READ windowTitle NOTIFY windowTitleChanged)
|
||||||
Q_PROPERTY(bool fileOpen READ isFileOpen NOTIFY fileOpenChanged)
|
Q_PROPERTY(bool fileOpen READ isFileOpen NOTIFY fileOpenChanged)
|
||||||
Q_PROPERTY(bool passwordSet READ isPasswordSet NOTIFY passwordChanged)
|
Q_PROPERTY(bool passwordSet READ isPasswordSet NOTIFY passwordChanged)
|
||||||
|
@ -41,6 +41,7 @@ public:
|
||||||
void setFilePath(const QString &filePath);
|
void setFilePath(const QString &filePath);
|
||||||
const QString &password() const;
|
const QString &password() const;
|
||||||
void setPassword(const QString &password);
|
void setPassword(const QString &password);
|
||||||
|
Q_INVOKABLE void clearPassword();
|
||||||
const QString &windowTitle() const;
|
const QString &windowTitle() const;
|
||||||
bool isFileOpen() const;
|
bool isFileOpen() const;
|
||||||
bool isPasswordSet() const;
|
bool isPasswordSet() const;
|
||||||
|
@ -130,6 +131,12 @@ inline const QString &Controller::password() const
|
||||||
return m_password;
|
return m_password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void Controller::clearPassword()
|
||||||
|
{
|
||||||
|
m_password.clear();
|
||||||
|
emit passwordChanged(QString());
|
||||||
|
}
|
||||||
|
|
||||||
inline const QString &Controller::windowTitle() const
|
inline const QString &Controller::windowTitle() const
|
||||||
{
|
{
|
||||||
return m_windowTitle;
|
return m_windowTitle;
|
||||||
|
|
Loading…
Reference in New Issue