diff --git a/gui/passwordgeneratordialog.cpp b/gui/passwordgeneratordialog.cpp index a8f21c0..61587e3 100644 --- a/gui/passwordgeneratordialog.cpp +++ b/gui/passwordgeneratordialog.cpp @@ -50,7 +50,6 @@ PasswordGeneratorDialog::PasswordGeneratorDialog(QWidget *parent) #endif 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->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->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(); } @@ -130,7 +135,7 @@ void PasswordGeneratorDialog::generateNewPassword() default_random_engine rng(m_random()); uniform_int_distribution dist(0, m_charset.size() - 1); const auto getRandomCharacter = [this, &dist, &rng]() { return m_charset[dist(rng)]; }; - string res(length, 0); + string res(static_cast(length), 0); generate_n(res.begin(), length, getRandomCharacter); m_ui->passwordLineEdit->setText(QString::fromLatin1(res.data(), length)); } catch (const CryptoException &ex) { @@ -157,12 +162,14 @@ void PasswordGeneratorDialog::handlePasswordChanged() m_ui->copyPasswordCommandLinkButton->setEnabled(m_ui->passwordLineEdit->text().count() > 0); } +#ifndef QT_NO_CLIPBOARD /*! * \brief Copies the current password to the clipboard. */ void PasswordGeneratorDialog::copyPassword() { - QClipboard *cb = QApplication::clipboard(); - cb->setText(m_ui->passwordLineEdit->text()); + QApplication::clipboard()->setText(m_ui->passwordLineEdit->text()); } +#endif + } // namespace QtGui diff --git a/gui/passwordgeneratordialog.h b/gui/passwordgeneratordialog.h index 14e552c..580b64c 100644 --- a/gui/passwordgeneratordialog.h +++ b/gui/passwordgeneratordialog.h @@ -25,7 +25,9 @@ private Q_SLOTS: void generateNewPassword(); void handleCheckedCategoriesChanged(); void handlePasswordChanged(); +#ifndef QT_NO_CLIPBOARD void copyPassword(); +#endif private: std::unique_ptr m_ui;