diff --git a/src/libs/ssh/sshkeycreationdialog.cpp b/src/libs/ssh/sshkeycreationdialog.cpp index 7ffa2c9b4b5..139b3bab72c 100644 --- a/src/libs/ssh/sshkeycreationdialog.cpp +++ b/src/libs/ssh/sshkeycreationdialog.cpp @@ -69,6 +69,9 @@ void SshKeyCreationDialog::keyTypeChanged() void SshKeyCreationDialog::generateKeys() { + if (userForbidsOverwriting()) + return; + const SshKeyGenerator::KeyType keyType = m_ui->rsa->isChecked() ? SshKeyGenerator::Rsa : SshKeyGenerator::Dsa; @@ -130,6 +133,16 @@ void SshKeyCreationDialog::saveKeys() accept(); } +bool SshKeyCreationDialog::userForbidsOverwriting() +{ + if (!QFileInfo(privateKeyFilePath()).exists() && !QFileInfo(publicKeyFilePath()).exists()) + return false; + const QMessageBox::StandardButton reply = QMessageBox::question(this, tr("File Exists"), + tr("There already is a file of that name. Do you want to overwrite it?"), + QMessageBox::Yes | QMessageBox::No, QMessageBox::No); + return reply != QMessageBox::Yes; +} + QString SshKeyCreationDialog::privateKeyFilePath() const { return m_ui->privateKeyFileValueLabel->text(); diff --git a/src/libs/ssh/sshkeycreationdialog.h b/src/libs/ssh/sshkeycreationdialog.h index 23afd761592..0c31af63d5a 100644 --- a/src/libs/ssh/sshkeycreationdialog.h +++ b/src/libs/ssh/sshkeycreationdialog.h @@ -57,6 +57,7 @@ private slots: private: void setPrivateKeyFile(const QString &filePath); void saveKeys(); + bool userForbidsOverwriting(); private: SshKeyGenerator *m_keyGenerator;