diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.cpp index 7f531367874..903f8a7aa2e 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.cpp @@ -38,6 +38,7 @@ #include "maemoconfigtestdialog.h" #include "maemodeviceconfigurations.h" +#include "maemosshconfigdialog.h" #include "maemosshthread.h" #include @@ -118,7 +119,6 @@ MaemoSettingsWidget::MaemoSettingsWidget(QWidget *parent) m_nameValidator(new NameValidator(m_devConfs)), m_timeoutValidator(new TimeoutValidator), m_keyDeployer(0) - { initGui(); } @@ -160,6 +160,7 @@ void MaemoSettingsWidget::initGui() m_ui->nameLineEdit->setValidator(m_nameValidator); m_ui->timeoutLineEdit->setValidator(m_timeoutValidator); m_ui->keyFileLineEdit->setExpectedKind(Utils::PathChooser::File); + foreach (const MaemoDeviceConfig &devConf, m_devConfs) m_ui->configurationComboBox->addItem(devConf.name); connect(m_ui->configurationComboBox, SIGNAL(currentIndexChanged(int)), @@ -350,27 +351,49 @@ void MaemoSettingsWidget::testConfig() dialog->open(); } +void MaemoSettingsWidget::showGenerateSshKeyDialog() +{ + MaemoSshConfigDialog dialog(this); + connect(&dialog, SIGNAL(publicKeyGenerated(QString)), this, + SLOT(setPublicKey(QString))); + connect(&dialog, SIGNAL(privateKeyGenerated(QString)), this, + SLOT(setPrivateKey(QString))); + dialog.exec(); +} + +void MaemoSettingsWidget::setPublicKey(const QString &path) +{ + m_publicKey = path; +} + +void MaemoSettingsWidget::setPrivateKey(const QString &path) +{ + m_ui->keyFileLineEdit->setPath(path); + keyFileEditingFinished(); +} + void MaemoSettingsWidget::deployKey() { if (m_keyDeployer) return; - const QString &dir = QFileInfo(currentConfig().keyFile).path(); - const QString &keyFile = QFileDialog::getOpenFileName(this, - tr("Choose public key file"), dir, - tr("Public Key Files(*.pub);;All Files (*)")); - if (keyFile.isEmpty()) + if (!QFileInfo(m_publicKey).exists()) { + const QString &dir = QFileInfo(currentConfig().keyFile).path(); + m_publicKey = QFileDialog::getOpenFileName(this, + tr("Choose public key file"), dir, + tr("Public Key Files(*.pub);;All Files (*)")); + } + + if (m_publicKey.isEmpty()) return; m_ui->deployKeyButton->disconnect(); - SshDeploySpec deploySpec(keyFile, homeDirOnDevice(currentConfig().uname) + SshDeploySpec deploySpec(m_publicKey, homeDirOnDevice(currentConfig().uname) + QLatin1String("/.ssh/authorized_keys"), true); m_keyDeployer = new MaemoSshDeployer(currentConfig(), QList() << deploySpec); - connect(m_keyDeployer, SIGNAL(finished()), - this, SLOT(handleDeployThreadFinished())); + connect(m_keyDeployer, SIGNAL(finished()), this, SLOT(handleDeployThreadFinished())); m_ui->deployKeyButton->setText(tr("Stop deploying")); - connect(m_ui->deployKeyButton, SIGNAL(clicked()), - this, SLOT(stopDeploying())); + connect(m_ui->deployKeyButton, SIGNAL(clicked()), this, SLOT(stopDeploying())); m_keyDeployer->start(); } @@ -410,11 +433,13 @@ void MaemoSettingsWidget::currentConfigChanged(int index) if (index == -1) { m_ui->removeConfigButton->setEnabled(false); m_ui->testConfigButton->setEnabled(false); + m_ui->generateKeyButton->setEnabled(false); clearDetails(); m_ui->detailsWidget->setEnabled(false); } else { m_ui->removeConfigButton->setEnabled(true); m_ui->testConfigButton->setEnabled(true); + m_ui->generateKeyButton->setEnabled(true); m_ui->configurationComboBox->setCurrentIndex(index); display(currentConfig()); } diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.h b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.h index 0b2844c8e2b..af56ed9b387 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.h @@ -82,6 +82,10 @@ private slots: // For configuration testing. void testConfig(); + void showGenerateSshKeyDialog(); + void setPublicKey(const QString &path); + void setPrivateKey(const QString &path); + // For key deploying. void deployKey(); void handleDeployThreadFinished(); @@ -104,6 +108,7 @@ private: NameValidator * const m_nameValidator; TimeoutValidator * const m_timeoutValidator; MaemoSshDeployer *m_keyDeployer; + QString m_publicKey; }; } // namespace Internal diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.ui b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.ui index 3c07b9023cf..a2f2a1427c7 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.ui +++ b/src/plugins/qt4projectmanager/qt-maemo/maemosettingswidget.ui @@ -6,39 +6,262 @@ 0 0 - 550 - 350 + 484 + 307 Maemo Device Configurations - - - - - - - Configuration: - - + + + + + + + + + Configuration: + + + + + + + + 0 + 0 + + + + false + + + + - - - - - 0 - 0 - + + + + QFrame::StyledPanel - - false + + QFrame::Raised + + + + + false + + + + 0 + 0 + + + + + + + Name + + + + + + + + + + Device type: + + + + + + + + 0 + + + + + Remote Device + + + + + + + Local Simulator + + + + + + + + + + Authentication type: + + + + + + + + 0 + + + + + Password + + + + + + + Key + + + + + + + + + + Host Name: + + + + + + + IP or host name of the device + + + + + + + Ports: + + + + + + + + + + 0 + 0 + + + + SSH: + + + + + + + 0 + + + 65535 + + + 22 + + + + + + + + 0 + 0 + + + + Gdb server: + + + + + + + 65535 + + + 10000 + + + + + + + + + Connection Timeout: + + + + + + + Timeout value in milliseconds + + + + + + + User Name: + + + + + + + + + + Password: + + + + + + + QLineEdit::Password + + + + + + + Private key file: + + + + + + + + + + - + @@ -67,13 +290,23 @@ + + + + false + + + Generate SSH Key ... + + + false - Deploy Key ... + Deploy public Key ... @@ -92,226 +325,6 @@ - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - false - - - - 0 - 0 - - - - - - - Name - - - - - - - - - - Device type: - - - - - - - - 0 - - - - - Remote device - - - - - - - Local simulator - - - - - - - - - - Authentication type: - - - - - - - - 0 - - - - - Password - - - - - - - Key - - - - - - - - - - Host name: - - - - - - - IP or host name of the device - - - - - - - Ports: - - - - - - - - - SSH: - - - - - - - 0 - - - 65535 - - - 22 - - - - - - - Gdb server: - - - - - - - 65535 - - - 10000 - - - - - - - - - Connection timeout: - - - - - - - Timeout value in milliseconds - - - - - - - User name: - - - - - - - - - - Password: - - - - - - - QLineEdit::Password - - - - - - - Private key file: - - - - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -335,8 +348,8 @@ deviceTypeChanged() - 273 - 108 + 231 + 99 511 @@ -351,8 +364,8 @@ hostNameEditingFinished() - 402 - 163 + 335 + 148 424 @@ -367,8 +380,8 @@ timeoutEditingFinished() - 402 - 225 + 335 + 202 425 @@ -383,8 +396,8 @@ userNameEditingFinished() - 402 - 255 + 335 + 228 422 @@ -399,8 +412,8 @@ passwordEditingFinished() - 402 - 285 + 335 + 254 423 @@ -415,8 +428,8 @@ deviceTypeChanged() - 402 - 108 + 335 + 99 426 @@ -447,8 +460,8 @@ deleteConfig() - 523 - 69 + 473 + 61 513 @@ -463,8 +476,8 @@ authenticationTypeChanged() - 273 - 133 + 231 + 122 513 @@ -479,8 +492,8 @@ keyFileEditingFinished() - 402 - 305 + 335 + 273 257 @@ -495,8 +508,8 @@ keyFileEditingFinished() - 402 - 305 + 335 + 273 257 @@ -511,8 +524,8 @@ testConfig() - 523 - 102 + 473 + 90 428 @@ -527,8 +540,8 @@ deployKey() - 523 - 135 + 473 + 148 510 @@ -543,8 +556,8 @@ authenticationTypeChanged() - 402 - 133 + 335 + 122 525 @@ -568,6 +581,22 @@ + + generateKeyButton + clicked() + MaemoSettingsWidget + showGenerateSshKeyDialog() + + + 403 + 107 + + + 358 + -11 + + + configNameEditingFinished() @@ -586,5 +615,6 @@ deployKey() gdbServerPortEditingFinished() currentConfigChanged(int) + showGenerateSshKeyDialog() diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosshconfigdialog.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemosshconfigdialog.cpp index f0f09675d8c..f1fce1e23ab 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemosshconfigdialog.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemosshconfigdialog.cpp @@ -33,96 +33,105 @@ ****************************************************************************/ #include "maemosshconfigdialog.h" -#include "maemosshthread.h" -#include +#include "maemodeviceconfigurations.h" +#include "ne7sshobject.h" + #include #include +#include + +#include +#include +#include + using namespace Qt4ProjectManager::Internal; MaemoSshConfigDialog::MaemoSshConfigDialog(QWidget *parent) : QDialog(parent) - , m_keyDeployer(0) + , home(QDesktopServices::storageLocation(QDesktopServices::HomeLocation)) { m_ui.setupUi(this); - const QLatin1String root("MaemoSsh/"); - QSettings *settings = Core::ICore::instance()->settings(); - m_ui.useKeyFromPath->setChecked(settings->value(root + QLatin1String("userKey"), - false).toBool()); - m_ui.keyFileLineEdit->setExpectedKind(Utils::PathChooser::File); - m_ui.keyFileLineEdit->setPath(settings->value(root + QLatin1String("keyPath"), - QDir::toNativeSeparators(QDir::homePath() + QLatin1String("/.ssh/id_rsa.pub"))) - .toString()); + connect(m_ui.rsa, SIGNAL(toggled(bool)), this, SLOT(slotToggled())); + connect(m_ui.dsa, SIGNAL(toggled(bool)), this, SLOT(slotToggled())); - connect(m_ui.deployButton, SIGNAL(clicked()), this, SLOT(deployKey())); connect(m_ui.generateButton, SIGNAL(clicked()), this, SLOT(generateSshKey())); + connect(m_ui.savePublicKey, SIGNAL(clicked()), this, SLOT(savePublicKey())); + connect(m_ui.savePrivateKey, SIGNAL(clicked()), this, SLOT(savePrivateKey())); } MaemoSshConfigDialog::~MaemoSshConfigDialog() { } +void MaemoSshConfigDialog::slotToggled() +{ + m_ui.comboBox->setCurrentIndex(0); + m_ui.comboBox->setEnabled(m_ui.rsa->isChecked()); +} + void MaemoSshConfigDialog::generateSshKey() { - if (!m_ui.keyFileLineEdit->isValid()) { - ne7ssh ssh; - ssh.generateKeyPair("rsa", "test", "id_rsa", "id_rsa.pub"); + algorithm = m_ui.rsa->isChecked() ? "rsa" : "dsa"; + tmpKey = QDir::tempPath().append(QLatin1Char('/') + algorithm).toUtf8(); + QByteArray userId = QString(home.mid(home.lastIndexOf(QLatin1Char('/')) + 1) + + QLatin1Char('@') + QHostInfo::localHostName()).toUtf8(); + + QFile::remove(tmpKey); + QFile::remove(tmpKey + ".pub"); + + QApplication::setOverrideCursor(Qt::BusyCursor); + + QSharedPointer ssh = Ne7SshObject::instance()->get(); + if (ssh->generateKeyPair(algorithm, userId, tmpKey, tmpKey + ".pub", + m_ui.comboBox->currentText().toUShort())) { + QFile file(tmpKey + ".pub"); + if (file.open(QIODevice::ReadOnly)) + m_ui.plainTextEdit->setPlainText(file.readAll()); + m_ui.savePublicKey->setEnabled(true); + m_ui.savePrivateKey->setEnabled(true); } else { - m_ui.infoLabel->setText("An public key has been created already."); + m_ui.plainTextEdit->setPlainText(tr("Could not create SSH key pair.")); } + + QApplication::restoreOverrideCursor(); } -void MaemoSshConfigDialog::deployKey() +void MaemoSshConfigDialog::savePublicKey() { - if (m_keyDeployer) - return; + checkSshDir(); + copyFile(QFileDialog::getSaveFileName(this, tr("Choose folder to save " + "public key file"), home + QString::fromLatin1("/.ssh/id_%1.pub") + .arg(algorithm.constData())), true); +} - if (m_ui.keyFileLineEdit->validatePath(m_ui.keyFileLineEdit->path())) { - m_ui.deployButton->disconnect(); - //SshDeploySpec deploySpec(keyFile, homeDirOnDevice(currentConfig().uname) - // + QLatin1String("/.ssh/authorized_keys"), true); - //m_keyDeployer = new MaemoSshDeployer(currentConfig(), QList() - // << deploySpec); - //connect(m_keyDeployer, SIGNAL(finished()), this, - // SLOT(handleDeployThreadFinished())); - if (m_keyDeployer) { - m_keyDeployer->start(); - m_ui.deployButton->setText(tr("Stop deploying")); - connect(m_ui.deployButton, SIGNAL(clicked()), this, SLOT(stopDeploying())); +void MaemoSshConfigDialog::savePrivateKey() +{ + checkSshDir(); + copyFile(QFileDialog::getSaveFileName(this, tr("Choose folder to save " + "private key file"), home + QString::fromLatin1("/.ssh/id_%1") + .arg(algorithm.constData())), false); +} + +void MaemoSshConfigDialog::checkSshDir() +{ + QDir dir(home + QString::fromLatin1("/.ssh")); + if (!dir.exists()) + dir.mkpath(home + QString::fromLatin1("/.ssh")); +} + +void MaemoSshConfigDialog::copyFile(const QString &file, bool pubKey) +{ + if (!file.isEmpty()) { + if (!QFile::exists(file) || QFile::remove(file)) { + QFile(tmpKey + (pubKey ? ".pub" : "")).copy(file); + if (pubKey) + emit publicKeyGenerated(file); + else + emit privateKeyGenerated(file); } - } else { - m_ui.infoLabel->setText("The public key path is invalid."); - } -} - -void MaemoSshConfigDialog::handleDeployThreadFinished() -{ - if (!m_keyDeployer) - return; - - if (m_keyDeployer->hasError()) { - m_ui.infoLabel->setText(tr("Key deployment failed: %1") - .arg(m_keyDeployer->error())); - } else { - m_ui.infoLabel->setText(tr("Key was successfully deployed.")); - } - stopDeploying(); -} - -void MaemoSshConfigDialog::stopDeploying() -{ - if (m_keyDeployer) { - m_ui.deployButton->disconnect(); - const bool buttonWasEnabled = m_ui.deployButton->isEnabled(); - m_keyDeployer->disconnect(); - m_keyDeployer->stop(); - delete m_keyDeployer; - m_keyDeployer = 0; - m_ui.deployButton->setText(tr("Deploy Public Key")); - connect(m_ui.deployButton, SIGNAL(clicked()), this, SLOT(deployKey())); - m_ui.deployButton->setEnabled(buttonWasEnabled); } } diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosshconfigdialog.h b/src/plugins/qt4projectmanager/qt-maemo/maemosshconfigdialog.h index aa8284a7a5b..6a246618e83 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemosshconfigdialog.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemosshconfigdialog.h @@ -42,8 +42,6 @@ namespace Qt4ProjectManager { namespace Internal { -class MaemoSshDeployer; - class MaemoSshConfigDialog : public QDialog { Q_OBJECT @@ -51,15 +49,25 @@ public: MaemoSshConfigDialog(QWidget *parent = 0); ~MaemoSshConfigDialog(); +signals: + void publicKeyGenerated(const QString &path); + void privateKeyGenerated(const QString &path); + private slots: + void slotToggled(); void generateSshKey(); - void deployKey(); - void handleDeployThreadFinished(); - void stopDeploying(); + void savePublicKey(); + void savePrivateKey(); private: + void checkSshDir(); + void copyFile(const QString &file, bool pubKey); + +private: + QString home; + QByteArray tmpKey; + QByteArray algorithm; Ui::MaemoSshConfigDialog m_ui; - MaemoSshDeployer *m_keyDeployer; }; } // Qt4ProjectManager diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosshconfigdialog.ui b/src/plugins/qt4projectmanager/qt-maemo/maemosshconfigdialog.ui index 8f80c258c6b..85d5152e24c 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemosshconfigdialog.ui +++ b/src/plugins/qt4projectmanager/qt-maemo/maemosshconfigdialog.ui @@ -9,117 +9,218 @@ 0 0 - 387 - 128 + 500 + 275 - + 0 0 + + + 500 + 275 + + SSH Key Configuration - + - - - - 0 - 0 - - - - Use key from location: + + + Options + + + + + + 0 + 0 + + + + Key size: + + + + + + + + 1024 + + + + + 2048 + + + + + 4096 + + + + + + + + Qt::Horizontal + + + + 328 + 20 + + + + + + + + Key algorithm: + + + + + + + + + + 0 + 0 + + + + RSA + + + true + + + + + + + + 0 + 0 + + + + DSA + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + - + + + Key + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + + + false + + + + + + Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + + Generate SSH Key + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Save public Key... + + + + + + + false + + + Save private Key... + + + + + + + + + + - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - false - - - - 0 - 0 - - - - Private key file: - - - - - - - false - - - - - - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 20 - 0 - - - - - - - - - - - - - - - Qt::Horizontal - - - - - - - - - Generate SSH Key - - - - - Qt::Horizontal @@ -131,13 +232,6 @@ - - - - Deploy Public Key - - - @@ -149,23 +243,8 @@ - - - Utils::PathChooser - QWidget -
utils/pathchooser.h
- 1 - - editingFinished() - browsingFinished() - -
-
closeButton - deployButton - generateButton - useKeyFromPath @@ -185,37 +264,5 @@
- - useKeyFromPath - toggled(bool) - keyLabel - setEnabled(bool) - - - 83 - 17 - - - 73 - 42 - - - - - useKeyFromPath - toggled(bool) - keyFileLineEdit - setEnabled(bool) - - - 193 - 17 - - - 246 - 42 - - - diff --git a/src/plugins/qt4projectmanager/qt-maemo/qt-maemo.pri b/src/plugins/qt4projectmanager/qt-maemo/qt-maemo.pri index 0ccdaa8414a..83ce4a5e378 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/qt-maemo.pri +++ b/src/plugins/qt4projectmanager/qt-maemo/qt-maemo.pri @@ -13,6 +13,7 @@ HEADERS += \ $$PWD/maemorunfactories.h \ $$PWD/maemosettingspage.h \ $$PWD/maemosettingswidget.h \ + $$PWD/maemosshconfigdialog.h \ $$PWD/maemosshconnection.h \ $$PWD/maemosshthread.h \ $$PWD/maemotoolchain.h \ @@ -31,6 +32,7 @@ SOURCES += \ $$PWD/maemorunfactories.cpp \ $$PWD/maemosettingspage.cpp \ $$PWD/maemosettingswidget.cpp \ + $$PWD/maemosshconfigdialog.cpp \ $$PWD/maemosshconnection.cpp \ $$PWD/maemosshthread.cpp \ $$PWD/maemotoolchain.cpp \ @@ -41,6 +43,7 @@ SOURCES += \ FORMS += \ $$PWD/maemoconfigtestdialog.ui \ - $$PWD/maemosettingswidget.ui + $$PWD/maemosettingswidget.ui \ + $$PWD/maemosshconfigdialog.ui RESOURCES += $$PWD/qt-maemo.qrc