summaryrefslogtreecommitdiff
path: root/plugins/autotest/squishsettingspage.cpp
blob: 9325e928e659c6b2c73d218e4192ce3a83c2ed79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd
** All rights reserved.
** For any questions to The Qt Company, please use contact form at
** http://www.qt.io/contact-us
**
** This file is part of the Qt Creator Enterprise Auto Test Add-on.
**
** Licensees holding valid Qt Enterprise licenses may use this file in
** accordance with the Qt Enterprise License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company.
**
** If you have questions regarding the use of this file, please use
** contact form at http://www.qt.io/contact-us
**
****************************************************************************/

#include "autotestconstants.h"
#include "squishsettingspage.h"
#include "squishsettings.h"

#include <coreplugin/icore.h>
#include <utils/hostosinfo.h>

namespace Autotest {
namespace Internal {

SquishSettingsWidget::SquishSettingsWidget(QWidget *parent)
    : QWidget(parent)
{
    m_ui.setupUi(this);

    connect(m_ui.localCheckBox, &QCheckBox::toggled,
            this, &SquishSettingsWidget::onLocalToggled);
}

void SquishSettingsWidget::setSettings(const SquishSettings &settings)
{
    m_ui.squishPathChooser->setFileName(settings.squishPath);
    m_ui.licensePathChooser->setFileName(settings.licensePath);
    m_ui.localCheckBox->setChecked(settings.local);
    m_ui.serverHostLineEdit->setText(settings.serverHost);
    m_ui.serverPortSpinBox->setValue(settings.serverPort);
    m_ui.verboseCheckBox->setChecked(settings.verbose);
}

SquishSettings SquishSettingsWidget::settings() const
{
    SquishSettings result;
    result.squishPath = m_ui.squishPathChooser->fileName();
    result.licensePath = m_ui.licensePathChooser->fileName();
    result.local = m_ui.localCheckBox->checkState() == Qt::Checked;
    result.serverHost = m_ui.serverHostLineEdit->text();
    result.serverPort = m_ui.serverPortSpinBox->value();
    result.verbose = m_ui.verboseCheckBox->checkState() == Qt::Checked;
    return result;
}

void SquishSettingsWidget::onLocalToggled(bool checked)
{
    m_ui.serverHostLineEdit->setEnabled(!checked);
    m_ui.serverPortSpinBox->setEnabled(!checked);
}

SquishSettingsPage::SquishSettingsPage(const QSharedPointer<SquishSettings> &settings)
    : m_settings(settings), m_widget(0)
{
    setId("B.Squish");
    setDisplayName(tr("Squish"));
    setCategory(Constants::AUTOTEST_SETTINGS_CATEGORY);
}

QWidget *SquishSettingsPage::widget()
{
    if (!m_widget) {
        m_widget = new SquishSettingsWidget;
        m_widget->setSettings(*m_settings);
    }
    return m_widget;
}

void SquishSettingsPage::apply()
{
    if (!m_widget) // page was not shown at all
        return;
    const SquishSettings newSettings = m_widget->settings();
    if (newSettings != *m_settings) {
        *m_settings = newSettings;
        m_settings->toSettings(Core::ICore::settings());
    }
}

} // namespace Internal
} // namespace Autotest