2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-06-16 17:03:43 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2016-01-15 14:57:40 +01:00
|
|
|
|
2011-06-16 17:03:43 +02:00
|
|
|
#include "publickeydeploymentdialog.h"
|
|
|
|
|
|
2011-07-22 12:38:57 +02:00
|
|
|
#include "sshkeydeployer.h"
|
2011-06-16 17:03:43 +02:00
|
|
|
|
2011-11-29 15:49:37 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2012-05-18 10:49:35 +02:00
|
|
|
#include <ssh/sshconnection.h>
|
2020-05-13 11:33:31 +02:00
|
|
|
#include <utils/theme/theme.h>
|
2011-08-02 12:20:16 +02:00
|
|
|
|
2012-07-25 17:41:01 +02:00
|
|
|
using namespace ProjectExplorer;
|
2021-08-17 16:36:42 +02:00
|
|
|
using namespace Utils;
|
2012-07-25 17:41:01 +02:00
|
|
|
|
2011-06-16 17:03:43 +02:00
|
|
|
namespace RemoteLinux {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
class PublicKeyDeploymentDialogPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
2011-11-29 15:49:37 +01:00
|
|
|
SshKeyDeployer keyDeployer;
|
2011-06-16 17:03:43 +02:00
|
|
|
bool done;
|
|
|
|
|
};
|
|
|
|
|
} // namespace Internal;
|
|
|
|
|
|
|
|
|
|
using namespace Internal;
|
|
|
|
|
|
2019-01-09 10:59:42 +01:00
|
|
|
PublicKeyDeploymentDialog *PublicKeyDeploymentDialog::createDialog(
|
|
|
|
|
const IDevice::ConstPtr &deviceConfig, QWidget *parent)
|
2011-11-29 15:49:37 +01:00
|
|
|
{
|
2021-09-27 18:23:27 +02:00
|
|
|
const FilePath dir = deviceConfig->sshParameters().privateKeyFile.parentDir();
|
2021-08-17 16:36:42 +02:00
|
|
|
const FilePath publicKeyFileName = FileUtils::getOpenFilePath(nullptr,
|
2011-11-29 15:49:37 +01:00
|
|
|
tr("Choose Public Key File"), dir,
|
|
|
|
|
tr("Public Key Files (*.pub);;All Files (*)"));
|
|
|
|
|
if (publicKeyFileName.isEmpty())
|
2018-11-24 17:06:01 +01:00
|
|
|
return nullptr;
|
2021-08-17 16:36:42 +02:00
|
|
|
return new PublicKeyDeploymentDialog(deviceConfig, publicKeyFileName.toString(), parent);
|
2011-11-29 15:49:37 +01:00
|
|
|
}
|
|
|
|
|
|
2012-07-25 17:41:01 +02:00
|
|
|
PublicKeyDeploymentDialog::PublicKeyDeploymentDialog(const IDevice::ConstPtr &deviceConfig,
|
2011-11-29 15:49:37 +01:00
|
|
|
const QString &publicKeyFileName, QWidget *parent)
|
2011-09-15 09:10:10 +02:00
|
|
|
: QProgressDialog(parent), d(new PublicKeyDeploymentDialogPrivate)
|
2011-06-16 17:03:43 +02:00
|
|
|
{
|
|
|
|
|
setAutoReset(false);
|
|
|
|
|
setAutoClose(false);
|
|
|
|
|
setMinimumDuration(0);
|
|
|
|
|
setMaximum(1);
|
|
|
|
|
|
2011-09-15 09:10:10 +02:00
|
|
|
d->done = false;
|
2011-06-16 17:03:43 +02:00
|
|
|
setLabelText(tr("Deploying..."));
|
|
|
|
|
setValue(0);
|
2015-01-30 11:02:24 +01:00
|
|
|
connect(this, &PublicKeyDeploymentDialog::canceled,
|
|
|
|
|
this, &PublicKeyDeploymentDialog::handleCanceled);
|
|
|
|
|
connect(&d->keyDeployer, &SshKeyDeployer::error,
|
|
|
|
|
this, &PublicKeyDeploymentDialog::handleDeploymentError);
|
|
|
|
|
connect(&d->keyDeployer, &SshKeyDeployer::finishedSuccessfully,
|
|
|
|
|
this, &PublicKeyDeploymentDialog::handleDeploymentSuccess);
|
2011-11-29 15:49:37 +01:00
|
|
|
d->keyDeployer.deployPublicKey(deviceConfig->sshParameters(), publicKeyFileName);
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PublicKeyDeploymentDialog::~PublicKeyDeploymentDialog()
|
|
|
|
|
{
|
2011-09-15 09:10:10 +02:00
|
|
|
delete d;
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PublicKeyDeploymentDialog::handleDeploymentSuccess()
|
|
|
|
|
{
|
|
|
|
|
handleDeploymentFinished(QString());
|
|
|
|
|
setValue(1);
|
2011-09-15 09:10:10 +02:00
|
|
|
d->done = true;
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PublicKeyDeploymentDialog::handleDeploymentError(const QString &errorMsg)
|
|
|
|
|
{
|
|
|
|
|
handleDeploymentFinished(errorMsg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PublicKeyDeploymentDialog::handleDeploymentFinished(const QString &errorMsg)
|
|
|
|
|
{
|
|
|
|
|
QString buttonText;
|
2020-05-13 11:33:31 +02:00
|
|
|
QString textColor;
|
2011-06-16 17:03:43 +02:00
|
|
|
if (errorMsg.isEmpty()) {
|
|
|
|
|
buttonText = tr("Deployment finished successfully.");
|
2020-05-13 11:33:31 +02:00
|
|
|
textColor = Utils::creatorTheme()->color(Utils::Theme::TextColorNormal).name();
|
2011-06-16 17:03:43 +02:00
|
|
|
} else {
|
|
|
|
|
buttonText = errorMsg;
|
2020-05-13 11:33:31 +02:00
|
|
|
textColor = Utils::creatorTheme()->color(Utils::Theme::TextColorError).name();
|
2011-06-16 17:03:43 +02:00
|
|
|
}
|
2021-08-24 14:37:40 +02:00
|
|
|
setLabelText(QString::fromLatin1("<font color=\"%1\">%2</font>")
|
|
|
|
|
.arg(textColor)
|
|
|
|
|
.arg(buttonText.replace("\n", "<br/>")));
|
2011-06-16 17:03:43 +02:00
|
|
|
setCancelButtonText(tr("Close"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PublicKeyDeploymentDialog::handleCanceled()
|
|
|
|
|
{
|
2018-11-24 17:06:01 +01:00
|
|
|
disconnect(&d->keyDeployer, nullptr, this, nullptr);
|
2011-11-29 15:49:37 +01:00
|
|
|
d->keyDeployer.stopDeployment();
|
2011-09-15 09:10:10 +02:00
|
|
|
if (d->done)
|
2011-06-16 17:03:43 +02:00
|
|
|
accept();
|
|
|
|
|
else
|
|
|
|
|
reject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace RemoteLinux
|