genericlinuxdeviceconfigurationwizardpages.cpp 6.42 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->setHistoryCompleter(QLatin1String("Ssh.KeyFile.History"));
63
    d->ui.privateKeyPathChooser->setPromptDialogTitle(tr("Choose a Private Key File"));
64
65
66
67
68
    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()));
69
70
71
72
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

153
154

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

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

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

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

180
} // namespace RemoteLinux