genericlinuxdeviceconfigurationwizardpages.cpp 6.33 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** 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, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29

30
#include "genericlinuxdeviceconfigurationwizardpages.h"
31 32
#include "ui_genericlinuxdeviceconfigurationwizardsetuppage.h"

33
#include <projectexplorer/devicesupport/idevice.h>
34 35 36 37 38 39 40 41 42 43

namespace RemoteLinux {
namespace Internal {

class GenericLinuxDeviceConfigurationWizardSetupPagePrivate
{
public:
    Ui::GenericLinuxDeviceConfigurationWizardSetupPage ui;
};

44 45 46 47 48 49
class GenericLinuxDeviceConfigurationWizardFinalPagePrivate
{
public:
    QLabel infoLabel;
};

50 51
} // namespace Internal

52
using namespace QSsh;
53 54 55
using namespace Utils;

GenericLinuxDeviceConfigurationWizardSetupPage::GenericLinuxDeviceConfigurationWizardSetupPage(QWidget *parent) :
56
    QWizardPage(parent), d(new Internal::GenericLinuxDeviceConfigurationWizardSetupPagePrivate)
57
{
58
    d->ui.setupUi(this);
59
    setTitle(tr("Connection"));
60
    setSubTitle(QLatin1String(" ")); // For Qt bug (background color)
61
    d->ui.privateKeyPathChooser->setExpectedKind(PathChooser::File);
62
    d->ui.privateKeyPathChooser->setPromptDialogTitle(tr("Choose a Private Key File"));
63 64 65 66 67
    connect(d->ui.nameLineEdit, SIGNAL(textChanged(QString)), SIGNAL(completeChanged()));
    connect(d->ui.hostNameLineEdit, SIGNAL(textChanged(QString)), SIGNAL(completeChanged()));
    connect(d->ui.userNameLineEdit, SIGNAL(textChanged(QString)), SIGNAL(completeChanged()));
    connect(d->ui.privateKeyPathChooser, SIGNAL(validChanged()), SIGNAL(completeChanged()));
    connect(d->ui.passwordButton, SIGNAL(toggled(bool)), SLOT(handleAuthTypeChanged()));
68 69 70 71
}

GenericLinuxDeviceConfigurationWizardSetupPage::~GenericLinuxDeviceConfigurationWizardSetupPage()
{
72
    delete d;
73 74 75 76
}

void GenericLinuxDeviceConfigurationWizardSetupPage::initializePage()
{
77
    d->ui.nameLineEdit->setText(defaultConfigurationName());
78 79 80 81
    d->ui.hostNameLineEdit->setText(defaultHostName());
    d->ui.userNameLineEdit->setText(defaultUserName());
    d->ui.passwordButton->setChecked(true);
    d->ui.passwordLineEdit->setText(defaultPassWord());
82
    d->ui.privateKeyPathChooser->setPath(ProjectExplorer::IDevice::defaultPrivateKeyFilePath());
83 84 85 86 87 88
    handleAuthTypeChanged();
}

bool GenericLinuxDeviceConfigurationWizardSetupPage::isComplete() const
{
    return !configurationName().isEmpty() && !hostName().isEmpty() && !userName().isEmpty()
89
            && (authenticationType() != SshConnectionParameters::AuthenticationTypePublicKey
90
                || d->ui.privateKeyPathChooser->isValid());
91 92 93 94
}

QString GenericLinuxDeviceConfigurationWizardSetupPage::configurationName() const
{
95
    return d->ui.nameLineEdit->text().trimmed();
96 97 98 99
}

QString GenericLinuxDeviceConfigurationWizardSetupPage::hostName() const
{
100
    return d->ui.hostNameLineEdit->text().trimmed();
101 102 103 104
}

QString GenericLinuxDeviceConfigurationWizardSetupPage::userName() const
{
105
    return d->ui.userNameLineEdit->text().trimmed();
106 107 108 109
}

SshConnectionParameters::AuthenticationType GenericLinuxDeviceConfigurationWizardSetupPage::authenticationType() const
{
110
    return d->ui.passwordButton->isChecked()
111 112
        ? SshConnectionParameters::AuthenticationTypeTryAllPasswordBasedMethods
        : SshConnectionParameters::AuthenticationTypePublicKey;
113 114 115 116
}

QString GenericLinuxDeviceConfigurationWizardSetupPage::password() const
{
117
    return d->ui.passwordLineEdit->text();
118 119 120 121
}

QString GenericLinuxDeviceConfigurationWizardSetupPage::privateKeyFilePath() const
{
122
    return d->ui.privateKeyPathChooser->path();
123 124
}

125 126
QString GenericLinuxDeviceConfigurationWizardSetupPage::defaultConfigurationName() const
{
127
    return tr("Generic Linux Device");
128 129
}

130 131 132 133 134 135 136 137 138 139
QString GenericLinuxDeviceConfigurationWizardSetupPage::defaultHostName() const
{
    return QString();
}

QString GenericLinuxDeviceConfigurationWizardSetupPage::defaultUserName() const
{
    return QString();
}

140 141 142 143 144
QString GenericLinuxDeviceConfigurationWizardSetupPage::defaultPassWord() const
{
    return QString();
}

145 146
void GenericLinuxDeviceConfigurationWizardSetupPage::handleAuthTypeChanged()
{
147 148
    d->ui.passwordLineEdit->setEnabled(authenticationType() != SshConnectionParameters::AuthenticationTypePublicKey);
    d->ui.privateKeyPathChooser->setEnabled(!d->ui.passwordLineEdit->isEnabled());
149 150 151
    emit completeChanged();
}

152 153

GenericLinuxDeviceConfigurationWizardFinalPage::GenericLinuxDeviceConfigurationWizardFinalPage(QWidget *parent)
154
    : QWizardPage(parent), d(new Internal::GenericLinuxDeviceConfigurationWizardFinalPagePrivate)
155
{
156
    setTitle(tr("Summary"));
157
    setSubTitle(QLatin1String(" ")); // For Qt bug (background color)
158
    d->infoLabel.setWordWrap(true);
159
    QVBoxLayout * const layout = new QVBoxLayout(this);
160
    layout->addWidget(&d->infoLabel);
161 162 163 164
}

GenericLinuxDeviceConfigurationWizardFinalPage::~GenericLinuxDeviceConfigurationWizardFinalPage()
{
165
    delete d;
166 167 168 169
}

void GenericLinuxDeviceConfigurationWizardFinalPage::initializePage()
{
170
    d->infoLabel.setText(infoText());
171 172 173 174 175 176 177 178
}

QString GenericLinuxDeviceConfigurationWizardFinalPage::infoText() const
{
    return tr("The new device configuration will now be created.\n"
        "In addition, device connectivity will be tested.");
}

179
} // namespace RemoteLinux