startremotedialog.cpp 5.4 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Tobias Hunger's avatar
Tobias Hunger committed
2
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
Tobias Hunger's avatar
Tobias Hunger committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
Tobias Hunger's avatar
Tobias Hunger committed
7
**
hjk's avatar
hjk committed
8 9 10 11
** 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
12 13 14
** 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.
Tobias Hunger's avatar
Tobias Hunger committed
15
**
16 17 18 19 20 21 22
** 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.
Tobias Hunger's avatar
Tobias Hunger committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
25 26 27

#include "startremotedialog.h"

28 29
#include "analyzerstartparameters.h"

30
#include <coreplugin/icore.h>
Tobias Hunger's avatar
Tobias Hunger committed
31 32
#include <projectexplorer/kitchooser.h>
#include <projectexplorer/kitinformation.h>
33
#include <projectexplorer/runnables.h>
34
#include <ssh/sshconnection.h>
Friedemann Kleint's avatar
Friedemann Kleint committed
35

36 37 38
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QLineEdit>
39
#include <QPushButton>
40

41 42 43
using namespace ProjectExplorer;
using namespace Utils;

44
namespace Analyzer {
45 46 47 48 49
namespace Internal {

class StartRemoteDialogPrivate
{
public:
50
    KitChooser *kitChooser;
51 52 53 54 55 56 57
    QLineEdit *executable;
    QLineEdit *arguments;
    QLineEdit *workingDirectory;
    QDialogButtonBox *buttonBox;
};

} // namespace Internal
58

hjk's avatar
hjk committed
59 60
StartRemoteDialog::StartRemoteDialog(QWidget *parent)
    : QDialog(parent)
61
    , d(new Internal::StartRemoteDialogPrivate)
62
{
63 64 65
    setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
    setWindowTitle(tr("Start Remote Analysis"));

66 67 68 69 70
    d->kitChooser = new KitChooser(this);
    d->kitChooser->setKitMatcher([](const Kit *kit) {
        const IDevice::ConstPtr device = DeviceKitInformation::device(kit);
        return kit->isValid() && device && !device->sshParameters().host.isEmpty();
    });
71 72 73
    d->executable = new QLineEdit(this);
    d->arguments = new QLineEdit(this);
    d->workingDirectory = new QLineEdit(this);
74 75 76 77 78

    d->buttonBox = new QDialogButtonBox(this);
    d->buttonBox->setOrientation(Qt::Horizontal);
    d->buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);

79
    QFormLayout *formLayout = new QFormLayout;
80
    formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
Tobias Hunger's avatar
Tobias Hunger committed
81
    formLayout->addRow(tr("Kit:"), d->kitChooser);
82 83 84
    formLayout->addRow(tr("Executable:"), d->executable);
    formLayout->addRow(tr("Arguments:"), d->arguments);
    formLayout->addRow(tr("Working directory:"), d->workingDirectory);
85 86

    QVBoxLayout *verticalLayout = new QVBoxLayout(this);
87
    verticalLayout->addLayout(formLayout);
88
    verticalLayout->addWidget(d->buttonBox);
89

hjk's avatar
hjk committed
90
    QSettings *settings = Core::ICore::settings();
91
    settings->beginGroup(QLatin1String("AnalyzerStartRemoteDialog"));
92
    d->kitChooser->populate();
93
    d->kitChooser->setCurrentKitId(Core::Id::fromSetting(settings->value(QLatin1String("profile"))));
94 95 96
    d->executable->setText(settings->value(QLatin1String("executable")).toString());
    d->workingDirectory->setText(settings->value(QLatin1String("workingDirectory")).toString());
    d->arguments->setText(settings->value(QLatin1String("arguments")).toString());
97 98
    settings->endGroup();

Montel Laurent's avatar
Montel Laurent committed
99 100 101 102 103 104
    connect(d->kitChooser, &KitChooser::activated, this, &StartRemoteDialog::validate);
    connect(d->executable, &QLineEdit::textChanged, this, &StartRemoteDialog::validate);
    connect(d->workingDirectory, &QLineEdit::textChanged, this, &StartRemoteDialog::validate);
    connect(d->arguments, &QLineEdit::textChanged, this, &StartRemoteDialog::validate);
    connect(d->buttonBox, &QDialogButtonBox::accepted, this, &StartRemoteDialog::accept);
    connect(d->buttonBox, &QDialogButtonBox::rejected, this, &StartRemoteDialog::reject);
105 106 107 108 109 110

    validate();
}

StartRemoteDialog::~StartRemoteDialog()
{
111
    delete d;
112 113 114 115
}

void StartRemoteDialog::accept()
{
hjk's avatar
hjk committed
116
    QSettings *settings = Core::ICore::settings();
117
    settings->beginGroup(QLatin1String("AnalyzerStartRemoteDialog"));
Tobias Hunger's avatar
Tobias Hunger committed
118
    settings->setValue(QLatin1String("profile"), d->kitChooser->currentKitId().toString());
119 120 121
    settings->setValue(QLatin1String("executable"), d->executable->text());
    settings->setValue(QLatin1String("workingDirectory"), d->workingDirectory->text());
    settings->setValue(QLatin1String("arguments"), d->arguments->text());
122 123 124 125 126 127 128
    settings->endGroup();

    QDialog::accept();
}

void StartRemoteDialog::validate()
{
129
    bool valid = !d->executable->text().isEmpty();
130
    d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(valid);
131 132
}

133
QSsh::SshConnectionParameters StartRemoteDialog::sshParams() const
134
{
Tobias Hunger's avatar
Tobias Hunger committed
135 136
    Kit *kit = d->kitChooser->currentKit();
    IDevice::ConstPtr device = DeviceKitInformation::device(kit);
137
    return device->sshParameters();
138 139
}

140
StandardRunnable StartRemoteDialog::runnable() const
141
{
142 143 144 145
    StandardRunnable r;
    r.executable = d->executable->text();
    r.commandLineArguments = d->arguments->text();
    r.workingDirectory = d->workingDirectory->text();
146
    return r;
147 148
}

hjk's avatar
hjk committed
149
} // namespace Analyzer