kitinformationconfigwidget.cpp 11.9 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Tobias Hunger's avatar
Tobias Hunger committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
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
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.
Tobias Hunger's avatar
Tobias Hunger committed
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
Tobias Hunger's avatar
Tobias Hunger committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
Tobias Hunger's avatar
Tobias Hunger committed
29

Tobias Hunger's avatar
Tobias Hunger committed
30
#include "kitinformationconfigwidget.h"
Tobias Hunger's avatar
Tobias Hunger committed
31
32
33
34
35

#include "devicesupport/devicemanager.h"
#include "devicesupport/devicemanagermodel.h"
#include "devicesupport/idevicefactory.h"
#include "projectexplorerconstants.h"
Tobias Hunger's avatar
Tobias Hunger committed
36
37
#include "kit.h"
#include "kitinformation.h"
Tobias Hunger's avatar
Tobias Hunger committed
38
39
40
41
42
43
#include "toolchain.h"
#include "toolchainmanager.h"

#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/pathchooser.h>
Friedemann Kleint's avatar
Friedemann Kleint committed
44
#include <utils/fancylineedit.h>
Tobias Hunger's avatar
Tobias Hunger committed
45
46
47
48

#include <QComboBox>
#include <QPushButton>

hjk's avatar
hjk committed
49
50
using namespace Core;

Tobias Hunger's avatar
Tobias Hunger committed
51
52
53
54
55
56
57
namespace ProjectExplorer {
namespace Internal {

// --------------------------------------------------------------------------
// SysRootInformationConfigWidget:
// --------------------------------------------------------------------------

58
59
SysRootInformationConfigWidget::SysRootInformationConfigWidget(Kit *k, const KitInformation *ki) :
    KitConfigWidget(k, ki),
60
    m_ignoreChange(false)
Tobias Hunger's avatar
Tobias Hunger committed
61
62
63
{
    m_chooser = new Utils::PathChooser;
    m_chooser->setExpectedKind(Utils::PathChooser::ExistingDirectory);
64
    m_chooser->setHistoryCompleter(QLatin1String("PE.SysRoot.History"));
Tobias Hunger's avatar
Tobias Hunger committed
65
    m_chooser->setFileName(SysRootKitInformation::sysRoot(k));
Tobias Hunger's avatar
Tobias Hunger committed
66
    connect(m_chooser, SIGNAL(changed(QString)), this, SLOT(pathWasChanged()));
Tobias Hunger's avatar
Tobias Hunger committed
67
68
}

Tobias Hunger's avatar
Tobias Hunger committed
69
70
71
72
73
SysRootInformationConfigWidget::~SysRootInformationConfigWidget()
{
    delete m_chooser;
}

Tobias Hunger's avatar
Tobias Hunger committed
74
75
76
77
78
QString SysRootInformationConfigWidget::displayName() const
{
    return tr("Sysroot:");
}

hjk's avatar
hjk committed
79
80
81
QString SysRootInformationConfigWidget::toolTip() const
{
    return tr("The root directory of the system image to use.<br>"
Tobias Hunger's avatar
Tobias Hunger committed
82
              "Leave empty when building for the desktop.");
hjk's avatar
hjk committed
83
84
}

Tobias Hunger's avatar
Tobias Hunger committed
85
void SysRootInformationConfigWidget::refresh()
Tobias Hunger's avatar
Tobias Hunger committed
86
{
87
88
    if (!m_ignoreChange)
        m_chooser->setFileName(SysRootKitInformation::sysRoot(m_kit));
Tobias Hunger's avatar
Tobias Hunger committed
89
90
91
92
}

void SysRootInformationConfigWidget::makeReadOnly()
{
93
    m_chooser->setReadOnly(true);
Tobias Hunger's avatar
Tobias Hunger committed
94
95
}

hjk's avatar
hjk committed
96
97
98
99
100
QWidget *SysRootInformationConfigWidget::mainWidget() const
{
    return m_chooser->lineEdit();
}

Eike Ziller's avatar
Eike Ziller committed
101
102
103
104
105
QWidget *SysRootInformationConfigWidget::buttonWidget() const
{
    return m_chooser->buttonAtIndex(0);
}

Tobias Hunger's avatar
Tobias Hunger committed
106
107
void SysRootInformationConfigWidget::pathWasChanged()
{
108
    m_ignoreChange = true;
Tobias Hunger's avatar
Tobias Hunger committed
109
    SysRootKitInformation::setSysRoot(m_kit, m_chooser->fileName());
110
    m_ignoreChange = false;
Tobias Hunger's avatar
Tobias Hunger committed
111
112
}

Tobias Hunger's avatar
Tobias Hunger committed
113
114
115
116
// --------------------------------------------------------------------------
// ToolChainInformationConfigWidget:
// --------------------------------------------------------------------------

117
118
ToolChainInformationConfigWidget::ToolChainInformationConfigWidget(Kit *k, const KitInformation *ki) :
    KitConfigWidget(k, ki)
Tobias Hunger's avatar
Tobias Hunger committed
119
{
hjk's avatar
hjk committed
120
    m_comboBox = new QComboBox;
Tobias Hunger's avatar
Tobias Hunger committed
121
    m_comboBox->setEnabled(false);
122
    m_comboBox->setToolTip(toolTip());
Tobias Hunger's avatar
Tobias Hunger committed
123

hjk's avatar
hjk committed
124
    foreach (ToolChain *tc, ToolChainManager::toolChains())
Tobias Hunger's avatar
Tobias Hunger committed
125
126
127
128
        toolChainAdded(tc);

    updateComboBox();

Tobias Hunger's avatar
Tobias Hunger committed
129
130
    refresh();
    connect(m_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(currentToolChainChanged(int)));
Tobias Hunger's avatar
Tobias Hunger committed
131

132
    m_manageButton = new QPushButton(KitConfigWidget::msgManage());
Tobias Hunger's avatar
Tobias Hunger committed
133
134
135
    m_manageButton->setContentsMargins(0, 0, 0, 0);
    connect(m_manageButton, SIGNAL(clicked()), this, SLOT(manageToolChains()));

hjk's avatar
hjk committed
136
    QObject *tcm = ToolChainManager::instance();
Tobias Hunger's avatar
Tobias Hunger committed
137
138
139
140
141
142
143
144
    connect(tcm, SIGNAL(toolChainAdded(ProjectExplorer::ToolChain*)),
            this, SLOT(toolChainAdded(ProjectExplorer::ToolChain*)));
    connect(tcm, SIGNAL(toolChainRemoved(ProjectExplorer::ToolChain*)),
            this, SLOT(toolChainRemoved(ProjectExplorer::ToolChain*)));
    connect(tcm, SIGNAL(toolChainUpdated(ProjectExplorer::ToolChain*)),
            this, SLOT(toolChainUpdated(ProjectExplorer::ToolChain*)));
}

Tobias Hunger's avatar
Tobias Hunger committed
145
146
147
148
149
150
ToolChainInformationConfigWidget::~ToolChainInformationConfigWidget()
{
    delete m_comboBox;
    delete m_manageButton;
}

Tobias Hunger's avatar
Tobias Hunger committed
151
152
QString ToolChainInformationConfigWidget::displayName() const
{
153
    return tr("Compiler:");
Tobias Hunger's avatar
Tobias Hunger committed
154
155
}

hjk's avatar
hjk committed
156
157
158
159
160
161
162
QString ToolChainInformationConfigWidget::toolTip() const
{
    return tr("The compiler to use for building.<br>"
              "Make sure the compiler will produce binaries compatible with the target device, "
              "Qt version and other libraries used.");
}

Tobias Hunger's avatar
Tobias Hunger committed
163
void ToolChainInformationConfigWidget::refresh()
Tobias Hunger's avatar
Tobias Hunger committed
164
{
Tobias Hunger's avatar
Tobias Hunger committed
165
    m_comboBox->setCurrentIndex(indexOf(ToolChainKitInformation::toolChain(m_kit)));
Tobias Hunger's avatar
Tobias Hunger committed
166
167
168
169
170
171
172
}

void ToolChainInformationConfigWidget::makeReadOnly()
{
    m_comboBox->setEnabled(false);
}

hjk's avatar
hjk committed
173
174
175
176
177
QWidget *ToolChainInformationConfigWidget::mainWidget() const
{
    return m_comboBox;
}

Eike Ziller's avatar
Eike Ziller committed
178
179
180
181
182
QWidget *ToolChainInformationConfigWidget::buttonWidget() const
{
    return m_manageButton;
}

Tobias Hunger's avatar
Tobias Hunger committed
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
void ToolChainInformationConfigWidget::toolChainAdded(ProjectExplorer::ToolChain *tc)
{
    m_comboBox->addItem(tc->displayName(), tc->id());
    updateComboBox();
}

void ToolChainInformationConfigWidget::toolChainRemoved(ProjectExplorer::ToolChain *tc)
{
    const int pos = indexOf(tc);
    if (pos < 0)
        return;
    m_comboBox->removeItem(pos);
    updateComboBox();
}
void ToolChainInformationConfigWidget::toolChainUpdated(ProjectExplorer::ToolChain *tc)
{
    const int pos = indexOf(tc);
    if (pos < 0)
        return;
    m_comboBox->setItemText(pos, tc->displayName());
}

void ToolChainInformationConfigWidget::manageToolChains()
{
hjk's avatar
hjk committed
207
208
    Core::ICore::showOptionsDialog(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY,
                                   Constants::TOOLCHAIN_SETTINGS_PAGE_ID);
Tobias Hunger's avatar
Tobias Hunger committed
209
210
}

Tobias Hunger's avatar
Tobias Hunger committed
211
212
213
void ToolChainInformationConfigWidget::currentToolChainChanged(int idx)
{
    const QString id = m_comboBox->itemData(idx).toString();
hjk's avatar
hjk committed
214
    ToolChainKitInformation::setToolChain(m_kit, ToolChainManager::findToolChain(id));
Tobias Hunger's avatar
Tobias Hunger committed
215
216
}

Tobias Hunger's avatar
Tobias Hunger committed
217
218
219
220
221
222
223
224
void ToolChainInformationConfigWidget::updateComboBox()
{
    // remove unavailable tool chain:
    int pos = indexOf(0);
    if (pos >= 0)
        m_comboBox->removeItem(pos);

    if (m_comboBox->count() == 0) {
225
        m_comboBox->addItem(tr("<No compiler available>"), QString());
Tobias Hunger's avatar
Tobias Hunger committed
226
227
        m_comboBox->setEnabled(false);
    } else {
228
        m_comboBox->setEnabled(true);
Tobias Hunger's avatar
Tobias Hunger committed
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
    }
}

int ToolChainInformationConfigWidget::indexOf(const ToolChain *tc)
{
    const QString id = tc ? tc->id() : QString();
    for (int i = 0; i < m_comboBox->count(); ++i) {
        if (id == m_comboBox->itemData(i).toString())
            return i;
    }
    return -1;
}

// --------------------------------------------------------------------------
// DeviceTypeInformationConfigWidget:
// --------------------------------------------------------------------------

246
247
DeviceTypeInformationConfigWidget::DeviceTypeInformationConfigWidget(Kit *workingCopy, const KitInformation *ki) :
    KitConfigWidget(workingCopy, ki), m_comboBox(new QComboBox)
Tobias Hunger's avatar
Tobias Hunger committed
248
249
{
    QList<IDeviceFactory *> factories
250
            = ExtensionSystem::PluginManager::getObjects<IDeviceFactory>();
Tobias Hunger's avatar
Tobias Hunger committed
251
    foreach (IDeviceFactory *factory, factories) {
hjk's avatar
hjk committed
252
        foreach (Core::Id id, factory->availableCreationIds())
Tobias Hunger's avatar
Tobias Hunger committed
253
            m_comboBox->addItem(factory->displayNameForId(id), id.uniqueIdentifier());
Tobias Hunger's avatar
Tobias Hunger committed
254
255
    }

256
257
    m_comboBox->setToolTip(toolTip());

Tobias Hunger's avatar
Tobias Hunger committed
258
259
    refresh();
    connect(m_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(currentTypeChanged(int)));
Tobias Hunger's avatar
Tobias Hunger committed
260
261
}

Tobias Hunger's avatar
Tobias Hunger committed
262
263
264
265
266
DeviceTypeInformationConfigWidget::~DeviceTypeInformationConfigWidget()
{
    delete m_comboBox;
}

hjk's avatar
hjk committed
267
268
269
270
271
QWidget *DeviceTypeInformationConfigWidget::mainWidget() const
{
    return m_comboBox;
}

Tobias Hunger's avatar
Tobias Hunger committed
272
273
QString DeviceTypeInformationConfigWidget::displayName() const
{
274
    return tr("Device type:");
Tobias Hunger's avatar
Tobias Hunger committed
275
276
}

hjk's avatar
hjk committed
277
278
279
280
281
QString DeviceTypeInformationConfigWidget::toolTip() const
{
    return tr("The type of device to run applications on.");
}

Tobias Hunger's avatar
Tobias Hunger committed
282
void DeviceTypeInformationConfigWidget::refresh()
Tobias Hunger's avatar
Tobias Hunger committed
283
{
Tobias Hunger's avatar
Tobias Hunger committed
284
    Core::Id devType = DeviceTypeKitInformation::deviceTypeId(m_kit);
Tobias Hunger's avatar
Tobias Hunger committed
285
286
287
    if (!devType.isValid())
        m_comboBox->setCurrentIndex(-1);
    for (int i = 0; i < m_comboBox->count(); ++i) {
Tobias Hunger's avatar
Tobias Hunger committed
288
        if (m_comboBox->itemData(i).toInt() == devType.uniqueIdentifier()) {
Tobias Hunger's avatar
Tobias Hunger committed
289
290
291
292
293
294
            m_comboBox->setCurrentIndex(i);
            break;
        }
    }
}

Tobias Hunger's avatar
Tobias Hunger committed
295
void DeviceTypeInformationConfigWidget::makeReadOnly()
Tobias Hunger's avatar
Tobias Hunger committed
296
{
Tobias Hunger's avatar
Tobias Hunger committed
297
    m_comboBox->setEnabled(false);
Tobias Hunger's avatar
Tobias Hunger committed
298
299
}

Tobias Hunger's avatar
Tobias Hunger committed
300
void DeviceTypeInformationConfigWidget::currentTypeChanged(int idx)
Tobias Hunger's avatar
Tobias Hunger committed
301
{
Tobias Hunger's avatar
Tobias Hunger committed
302
303
    Core::Id type = idx < 0 ? Core::Id() : Core::Id::fromUniqueIdentifier(m_comboBox->itemData(idx).toInt());
    DeviceTypeKitInformation::setDeviceTypeId(m_kit, type);
Tobias Hunger's avatar
Tobias Hunger committed
304
305
306
307
308
309
}

// --------------------------------------------------------------------------
// DeviceInformationConfigWidget:
// --------------------------------------------------------------------------

310
311
DeviceInformationConfigWidget::DeviceInformationConfigWidget(Kit *workingCopy, const KitInformation *ki) :
    KitConfigWidget(workingCopy, ki),
hjk's avatar
hjk committed
312
    m_isReadOnly(false),
313
    m_ignoreChange(false),
hjk's avatar
hjk committed
314
    m_comboBox(new QComboBox),
Tobias Hunger's avatar
Tobias Hunger committed
315
316
317
318
    m_model(new DeviceManagerModel(DeviceManager::instance()))
{
    m_comboBox->setModel(m_model);

319
    m_manageButton = new QPushButton(KitConfigWidget::msgManage());
Tobias Hunger's avatar
Tobias Hunger committed
320

Tobias Hunger's avatar
Tobias Hunger committed
321
    refresh();
322
323
    m_comboBox->setToolTip(toolTip());

hjk's avatar
hjk committed
324
325
    connect(m_model, SIGNAL(modelAboutToBeReset()), SLOT(modelAboutToReset()));
    connect(m_model, SIGNAL(modelReset()), SLOT(modelReset()));
Tobias Hunger's avatar
Tobias Hunger committed
326
    connect(m_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(currentDeviceChanged()));
Tobias Hunger's avatar
Tobias Hunger committed
327
328
329
    connect(m_manageButton, SIGNAL(clicked()), this, SLOT(manageDevices()));
}

Tobias Hunger's avatar
Tobias Hunger committed
330
331
332
333
334
335
336
DeviceInformationConfigWidget::~DeviceInformationConfigWidget()
{
    delete m_comboBox;
    delete m_model;
    delete m_manageButton;
}

hjk's avatar
hjk committed
337
338
339
340
341
QWidget *DeviceInformationConfigWidget::mainWidget() const
{
    return m_comboBox;
}

Tobias Hunger's avatar
Tobias Hunger committed
342
343
344
345
346
QString DeviceInformationConfigWidget::displayName() const
{
    return tr("Device:");
}

hjk's avatar
hjk committed
347
348
349
350
351
QString DeviceInformationConfigWidget::toolTip() const
{
    return tr("The device to run the applications on.");
}

Tobias Hunger's avatar
Tobias Hunger committed
352
void DeviceInformationConfigWidget::refresh()
Tobias Hunger's avatar
Tobias Hunger committed
353
{
Tobias Hunger's avatar
Tobias Hunger committed
354
    m_model->setTypeFilter(DeviceTypeKitInformation::deviceTypeId(m_kit));
Tobias Hunger's avatar
Tobias Hunger committed
355
    m_comboBox->setCurrentIndex(m_model->indexOf(DeviceKitInformation::device(m_kit)));
Tobias Hunger's avatar
Tobias Hunger committed
356
357
358
359
360
361
362
}

void DeviceInformationConfigWidget::makeReadOnly()
{
    m_comboBox->setEnabled(false);
}

Eike Ziller's avatar
Eike Ziller committed
363
364
365
366
367
QWidget *DeviceInformationConfigWidget::buttonWidget() const
{
    return m_manageButton;
}

Tobias Hunger's avatar
Tobias Hunger committed
368
369
void DeviceInformationConfigWidget::manageDevices()
{
hjk's avatar
hjk committed
370
371
    ICore::showOptionsDialog(Constants::DEVICE_SETTINGS_CATEGORY,
                             Constants::DEVICE_SETTINGS_PAGE_ID);
Tobias Hunger's avatar
Tobias Hunger committed
372
373
}

374
375
376
void DeviceInformationConfigWidget::modelAboutToReset()
{
    m_selectedId = m_model->deviceId(m_comboBox->currentIndex());
377
    m_ignoreChange = true;
378
379
380
381
382
}

void DeviceInformationConfigWidget::modelReset()
{
    m_comboBox->setCurrentIndex(m_model->indexForId(m_selectedId));
383
    m_ignoreChange = false;
384
385
}

Tobias Hunger's avatar
Tobias Hunger committed
386
387
void DeviceInformationConfigWidget::currentDeviceChanged()
{
388
389
    if (m_ignoreChange)
        return;
Tobias Hunger's avatar
Tobias Hunger committed
390
391
392
    DeviceKitInformation::setDeviceId(m_kit, m_model->deviceId(m_comboBox->currentIndex()));
}

Tobias Hunger's avatar
Tobias Hunger committed
393
394
} // namespace Internal
} // namespace ProjectExplorer