Check for QT_NO_CLIPBOARD in PasswordGeneratorDialog
This commit is contained in:
parent
cb121fb75d
commit
36b8324f6b
|
@ -50,7 +50,6 @@ PasswordGeneratorDialog::PasswordGeneratorDialog(QWidget *parent)
|
||||||
#endif
|
#endif
|
||||||
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
|
setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
|
||||||
|
|
||||||
connect(m_ui->copyPasswordCommandLinkButton, &QCommandLinkButton::clicked, this, &PasswordGeneratorDialog::copyPassword);
|
|
||||||
connect(m_ui->generatePassowordCommandLinkButton, &QCommandLinkButton::clicked, this, &PasswordGeneratorDialog::generateNewPassword);
|
connect(m_ui->generatePassowordCommandLinkButton, &QCommandLinkButton::clicked, this, &PasswordGeneratorDialog::generateNewPassword);
|
||||||
connect(m_ui->useCapitalLettersCheckBox, &QCheckBox::stateChanged, this, &PasswordGeneratorDialog::handleCheckedCategoriesChanged);
|
connect(m_ui->useCapitalLettersCheckBox, &QCheckBox::stateChanged, this, &PasswordGeneratorDialog::handleCheckedCategoriesChanged);
|
||||||
connect(m_ui->useCapitalLettersCheckBox, &QCheckBox::stateChanged, this, &PasswordGeneratorDialog::handleCheckedCategoriesChanged);
|
connect(m_ui->useCapitalLettersCheckBox, &QCheckBox::stateChanged, this, &PasswordGeneratorDialog::handleCheckedCategoriesChanged);
|
||||||
|
@ -60,6 +59,12 @@ PasswordGeneratorDialog::PasswordGeneratorDialog(QWidget *parent)
|
||||||
connect(m_ui->passwordLineEdit, &QLineEdit::textChanged, this, &PasswordGeneratorDialog::handlePasswordChanged);
|
connect(m_ui->passwordLineEdit, &QLineEdit::textChanged, this, &PasswordGeneratorDialog::handlePasswordChanged);
|
||||||
connect(m_ui->closePushButton, &QPushButton::clicked, this, &PasswordGeneratorDialog::close);
|
connect(m_ui->closePushButton, &QPushButton::clicked, this, &PasswordGeneratorDialog::close);
|
||||||
|
|
||||||
|
#ifndef QT_NO_CLIPBOARD
|
||||||
|
connect(m_ui->copyPasswordCommandLinkButton, &QCommandLinkButton::clicked, this, &PasswordGeneratorDialog::copyPassword);
|
||||||
|
#else
|
||||||
|
m_ui->copyPasswordCommandLinkButton->setDisabled(true);
|
||||||
|
#endif
|
||||||
|
|
||||||
handlePasswordChanged();
|
handlePasswordChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +135,7 @@ void PasswordGeneratorDialog::generateNewPassword()
|
||||||
default_random_engine rng(m_random());
|
default_random_engine rng(m_random());
|
||||||
uniform_int_distribution<size_t> dist(0, m_charset.size() - 1);
|
uniform_int_distribution<size_t> dist(0, m_charset.size() - 1);
|
||||||
const auto getRandomCharacter = [this, &dist, &rng]() { return m_charset[dist(rng)]; };
|
const auto getRandomCharacter = [this, &dist, &rng]() { return m_charset[dist(rng)]; };
|
||||||
string res(length, 0);
|
string res(static_cast<size_t>(length), 0);
|
||||||
generate_n(res.begin(), length, getRandomCharacter);
|
generate_n(res.begin(), length, getRandomCharacter);
|
||||||
m_ui->passwordLineEdit->setText(QString::fromLatin1(res.data(), length));
|
m_ui->passwordLineEdit->setText(QString::fromLatin1(res.data(), length));
|
||||||
} catch (const CryptoException &ex) {
|
} catch (const CryptoException &ex) {
|
||||||
|
@ -157,12 +162,14 @@ void PasswordGeneratorDialog::handlePasswordChanged()
|
||||||
m_ui->copyPasswordCommandLinkButton->setEnabled(m_ui->passwordLineEdit->text().count() > 0);
|
m_ui->copyPasswordCommandLinkButton->setEnabled(m_ui->passwordLineEdit->text().count() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef QT_NO_CLIPBOARD
|
||||||
/*!
|
/*!
|
||||||
* \brief Copies the current password to the clipboard.
|
* \brief Copies the current password to the clipboard.
|
||||||
*/
|
*/
|
||||||
void PasswordGeneratorDialog::copyPassword()
|
void PasswordGeneratorDialog::copyPassword()
|
||||||
{
|
{
|
||||||
QClipboard *cb = QApplication::clipboard();
|
QApplication::clipboard()->setText(m_ui->passwordLineEdit->text());
|
||||||
cb->setText(m_ui->passwordLineEdit->text());
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace QtGui
|
} // namespace QtGui
|
||||||
|
|
|
@ -25,7 +25,9 @@ private Q_SLOTS:
|
||||||
void generateNewPassword();
|
void generateNewPassword();
|
||||||
void handleCheckedCategoriesChanged();
|
void handleCheckedCategoriesChanged();
|
||||||
void handlePasswordChanged();
|
void handlePasswordChanged();
|
||||||
|
#ifndef QT_NO_CLIPBOARD
|
||||||
void copyPassword();
|
void copyPassword();
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<Ui::PasswordGeneratorDialog> m_ui;
|
std::unique_ptr<Ui::PasswordGeneratorDialog> m_ui;
|
||||||
|
|
Loading…
Reference in New Issue