aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/baremetal/debugservers/uvsc/uvtargetdriverviewer.cpp
blob: d33e35bb64fddb0158829d61c0114573e04f1f4c (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright (C) 2020 Denis Shienkov <denis.shienkov@gmail.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

#include "uvproject.h" // for targetUVisionPath()
#include "uvtargetdrivermodel.h"
#include "uvtargetdriverviewer.h"

#include <QDialogButtonBox>
#include <QFormLayout>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QMessageBox>
#include <QPlainTextEdit>
#include <QPushButton>
#include <QVBoxLayout>

namespace BareMetal {
namespace Internal {
namespace Uv {

// DriverSelectorToolPanel

DriverSelectorToolPanel::DriverSelectorToolPanel(QWidget *parent)
    : FadingPanel(parent)
{
    const auto layout = new QHBoxLayout;
    layout->setContentsMargins(0, 0, 0, 0);
    const auto button = new QPushButton(tr("Manage..."));
    layout->addWidget(button);
    setLayout(layout);
    connect(button, &QPushButton::clicked, this, &DriverSelectorToolPanel::clicked);
}

void DriverSelectorToolPanel::fadeTo(qreal value)
{
    Q_UNUSED(value)
}

void DriverSelectorToolPanel::setOpacity(qreal value)
{
    Q_UNUSED(value)
}

// DriverSelectorDetailsPanel

DriverSelectorDetailsPanel::DriverSelectorDetailsPanel(DriverSelection &selection, QWidget *parent)
    : QWidget(parent), m_selection(selection)
{
    const auto layout = new QFormLayout;
    m_dllEdit = new QLineEdit;;
    m_dllEdit->setReadOnly(true);
    m_dllEdit->setToolTip(tr("Debugger driver library."));
    layout->addRow(tr("Driver library:"), m_dllEdit);
    m_cpuDllView = new DriverSelectionCpuDllView(m_selection);
    layout->addRow(tr("CPU library:"), m_cpuDllView);
    setLayout(layout);

    refresh();

    connect(m_cpuDllView, &DriverSelectionCpuDllView::dllChanged, this, [this](int index) {
        if (index >= 0)
            m_selection.cpuDllIndex = index;
        emit selectionChanged();
    });
}

void DriverSelectorDetailsPanel::refresh()
{
    m_dllEdit->setText((m_selection.dll));
    m_cpuDllView->refresh();
    m_cpuDllView->setCpuDll(m_selection.cpuDllIndex);
}

// DriverSelector

DriverSelector::DriverSelector(const QStringList &supportedDrivers, QWidget *parent)
    : DetailsWidget(parent)
{
    const auto toolPanel = new DriverSelectorToolPanel;
    toolPanel->setEnabled(!supportedDrivers.isEmpty());
    setToolWidget(toolPanel);
    const auto detailsPanel = new DriverSelectorDetailsPanel(m_selection);
    setWidget(detailsPanel);

    connect(toolPanel, &DriverSelectorToolPanel::clicked, this, [=]() {
        DriverSelectionDialog dialog(m_toolsIniFile, supportedDrivers, this);
        const int result = dialog.exec();
        if (result != QDialog::Accepted)
            return;
        DriverSelection selection;
        selection = dialog.selection();
        setSelection(selection);
    });

    connect(detailsPanel, &DriverSelectorDetailsPanel::selectionChanged,
            this, &DriverSelector::selectionChanged);
}

void DriverSelector::setToolsIniFile(const Utils::FilePath &toolsIniFile)
{
    m_toolsIniFile = toolsIniFile;
    setEnabled(m_toolsIniFile.exists());
}

Utils::FilePath DriverSelector::toolsIniFile() const
{
    return m_toolsIniFile;
}

void DriverSelector::setSelection(const DriverSelection &selection)
{
    m_selection = selection;
    const auto summary = m_selection.name.isEmpty()
            ? tr("Target driver not selected.") : m_selection.name;
    setSummaryText(summary);
    setExpandable(!m_selection.name.isEmpty());

    if (const auto detailsPanel = qobject_cast<DriverSelectorDetailsPanel *>(widget()))
        detailsPanel->refresh();

    emit selectionChanged();
}

DriverSelection DriverSelector::selection() const
{
    return m_selection;
}

// DriverSelectionDialog

DriverSelectionDialog::DriverSelectionDialog(const Utils::FilePath &toolsIniFile,
                                             const QStringList &supportedDrivers,
                                             QWidget *parent)
    : QDialog(parent), m_model(new DriverSelectionModel(this)),
      m_view(new DriverSelectionView(this))
{
    setWindowTitle(tr("Available Target Drivers"));

    const auto layout = new QVBoxLayout;
    layout->setContentsMargins(0, 0, 0, 0);
    layout->addWidget(m_view);
    const auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
    layout->addWidget(buttonBox);
    setLayout(layout);

    connect(buttonBox, &QDialogButtonBox::accepted, this, &DriverSelectionDialog::accept);
    connect(buttonBox, &QDialogButtonBox::rejected, this, &DriverSelectionDialog::reject);

    connect(m_view, &DriverSelectionView::driverSelected, this,
            [this](const DriverSelection &selection) {
        m_selection = selection;
    });

    m_model->fillDrivers(toolsIniFile, supportedDrivers);
    m_view->setModel(m_model);
}

void DriverSelectionDialog::setSelection(const DriverSelection &selection)
{
    m_selection = selection;
}

DriverSelection DriverSelectionDialog::selection() const
{
    return m_selection;
}

} // namespace Uv
} // namespace Internal
} // namespace BareMetal