forked from qt-creator/qt-creator
SSH: Support password input for private keys in non-GUI applications.
Change-Id: Ibd5e47409e92edb6909053d7f17e67b6fa72e642 Reviewed-on: http://codereview.qt.nokia.com/2384 Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
This commit is contained in:
@@ -31,23 +31,34 @@
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
#include "sshkeypasswordretriever_p.h"
|
#include "sshkeypasswordretriever_p.h"
|
||||||
|
|
||||||
#include <QtCore/QCoreApplication>
|
|
||||||
#include <QtCore/QString>
|
#include <QtCore/QString>
|
||||||
|
#include <QtGui/QApplication>
|
||||||
#include <QtGui/QInputDialog>
|
#include <QtGui/QInputDialog>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
std::string SshKeyPasswordRetriever::get_passphrase(const std::string &, const std::string &,
|
std::string SshKeyPasswordRetriever::get_passphrase(const std::string &, const std::string &,
|
||||||
UI_Result &result) const
|
UI_Result &result) const
|
||||||
{
|
{
|
||||||
bool ok;
|
const bool hasGui = dynamic_cast<QApplication *>(QApplication::instance());
|
||||||
const QString &password = QInputDialog::getText(0,
|
if (hasGui) {
|
||||||
QCoreApplication::translate("Utils::Ssh", "Password Required"),
|
bool ok;
|
||||||
QCoreApplication::translate("Utils::Ssh", "Please enter the password for your private key."),
|
const QString &password = QInputDialog::getText(0,
|
||||||
QLineEdit::Password, QString(), &ok);
|
QCoreApplication::translate("Utils::Ssh", "Password Required"),
|
||||||
result = ok ? OK : CANCEL_ACTION;
|
QCoreApplication::translate("Utils::Ssh", "Please enter the password for your private key."),
|
||||||
return std::string(password.toLocal8Bit().data());
|
QLineEdit::Password, QString(), &ok);
|
||||||
|
result = ok ? OK : CANCEL_ACTION;
|
||||||
|
return std::string(password.toLocal8Bit().data());
|
||||||
|
} else {
|
||||||
|
result = OK;
|
||||||
|
std::string password;
|
||||||
|
std::cout << "Please enter the password for your private key (set echo off beforehand!): " << std::flush;
|
||||||
|
std::cin >> password;
|
||||||
|
return password;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
Reference in New Issue
Block a user