Commit 2cdcb60a authored by kh1's avatar kh1
Browse files

Initial ssh key generation dialog implementation.

--[ Details ]---------[ remember extra blank line after subject ]---|
parent 77715321
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of Qt Creator.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "maemosshconfigdialog.h"
#include "maemosshthread.h"
#include <coreplugin/icore.h>
#include <ne7ssh.h>
#include <QtCore/QDir>
using namespace Qt4ProjectManager::Internal;
MaemoSshConfigDialog::MaemoSshConfigDialog(QWidget *parent)
: QDialog(parent)
, m_keyDeployer(0)
{
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.deployButton, SIGNAL(clicked()), this, SLOT(deployKey()));
connect(m_ui.generateButton, SIGNAL(clicked()), this, SLOT(generateSshKey()));
}
MaemoSshConfigDialog::~MaemoSshConfigDialog()
{
}
void MaemoSshConfigDialog::generateSshKey()
{
if (!m_ui.keyFileLineEdit->isValid()) {
ne7ssh ssh;
ssh.generateKeyPair("rsa", "test", "id_rsa", "id_rsa.pub");
} else {
m_ui.infoLabel->setText("An public key has been created already.");
}
}
void MaemoSshConfigDialog::deployKey()
{
if (m_keyDeployer)
return;
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<SshDeploySpec>()
// << 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()));
}
} 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);
}
}
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of Qt Creator.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef MAEMOSSHCONFIGDIALOG_H
#define MAEMOSSHCONFIGDIALOG_H
#include "ui_maemosshconfigdialog.h"
#include <QtGui/QDialog>
namespace Qt4ProjectManager {
namespace Internal {
class MaemoSshDeployer;
class MaemoSshConfigDialog : public QDialog
{
Q_OBJECT
public:
MaemoSshConfigDialog(QWidget *parent = 0);
~MaemoSshConfigDialog();
private slots:
void generateSshKey();
void deployKey();
void handleDeployThreadFinished();
void stopDeploying();
private:
Ui::MaemoSshConfigDialog m_ui;
MaemoSshDeployer *m_keyDeployer;
};
} // Qt4ProjectManager
} // Internal
#endif // MAEMOSSHCONFIGDIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MaemoSshConfigDialog</class>
<widget class="QDialog" name="MaemoSshConfigDialog">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>387</width>
<height>128</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>SSH Key Configuration</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="useKeyFromPath">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Use key from location:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="keyLabel">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Private key file:</string>
</property>
</widget>
</item>
<item>
<widget class="Utils::PathChooser" name="keyFileLineEdit" native="true">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="infoLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="generateButton">
<property name="text">
<string>Generate SSH Key</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="deployButton">
<property name="text">
<string>Deploy Public Key</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="closeButton">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Utils::PathChooser</class>
<extends>QWidget</extends>
<header location="global">utils/pathchooser.h</header>
<container>1</container>
<slots>
<signal>editingFinished()</signal>
<signal>browsingFinished()</signal>
</slots>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>closeButton</tabstop>
<tabstop>deployButton</tabstop>
<tabstop>generateButton</tabstop>
<tabstop>useKeyFromPath</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>closeButton</sender>
<signal>clicked()</signal>
<receiver>MaemoSshConfigDialog</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>351</x>
<y>96</y>
</hint>
<hint type="destinationlabel">
<x>381</x>
<y>107</y>
</hint>
</hints>
</connection>
<connection>
<sender>useKeyFromPath</sender>
<signal>toggled(bool)</signal>
<receiver>keyLabel</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>83</x>
<y>17</y>
</hint>
<hint type="destinationlabel">
<x>73</x>
<y>42</y>
</hint>
</hints>
</connection>
<connection>
<sender>useKeyFromPath</sender>
<signal>toggled(bool)</signal>
<receiver>keyFileLineEdit</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>193</x>
<y>17</y>
</hint>
<hint type="destinationlabel">
<x>246</x>
<y>42</y>
</hint>
</hints>
</connection>
</connections>
</ui>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment