debuggeroptionspage.cpp 12.3 KB
Newer Older
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
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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.
**
** GNU Lesser General Public License Usage
** 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
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

#include "debuggeroptionspage.h"

#include "debuggeritemmanager.h"
#include "debuggeritemmodel.h"

#include <projectexplorer/projectexplorerconstants.h>

#include <utils/detailswidget.h>
#include <utils/pathchooser.h>
#include <utils/qtcassert.h>
David Schulz's avatar
David Schulz committed
40
#include <utils/winutils.h>
41

42
#include <QFileInfo>
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <QFormLayout>
#include <QHeaderView>
#include <QLabel>
#include <QLineEdit>
#include <QObject>
#include <QPushButton>
#include <QTreeView>
#include <QWidget>

using namespace Utils;

namespace Debugger {
namespace Internal {

static const char debuggingToolsWikiLinkC[] = "http://qt-project.org/wiki/Qt_Creator_Windows_Debugging";

// -----------------------------------------------------------------------
// DebuggerItemConfigWidget
// -----------------------------------------------------------------------

63
64
DebuggerItemConfigWidget::DebuggerItemConfigWidget(DebuggerItemModel *model) :
    m_model(model)
65
{
66
67
    QTC_CHECK(model);

68
69
70
71
72
    m_displayNameLineEdit = new QLineEdit(this);

    m_binaryChooser = new PathChooser(this);
    m_binaryChooser->setExpectedKind(PathChooser::ExistingCommand);
    m_binaryChooser->setMinimumWidth(400);
73
    m_binaryChooser->setHistoryCompleter(QLatin1String("DebuggerPaths"));
74
    connect(m_binaryChooser, SIGNAL(changed(QString)), this, SLOT(commandWasChanged()));
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

    m_cdbLabel = new QLabel(this);
    m_cdbLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
    m_cdbLabel->setOpenExternalLinks(true);

    m_abis = new QLineEdit(this);
    m_abis->setEnabled(false);

    QFormLayout *formLayout = new QFormLayout(this);
    formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
    formLayout->addRow(new QLabel(tr("Name:")), m_displayNameLineEdit);
//    formLayout->addRow(new QLabel(tr("Type:")), m_engineTypeComboBox);
    formLayout->addRow(m_cdbLabel);
    formLayout->addRow(new QLabel(tr("Path:")), m_binaryChooser);
    formLayout->addRow(new QLabel(tr("ABIs:")), m_abis);
}

92
DebuggerItem DebuggerItemConfigWidget::item() const
93
94
95
96
97
98
99
100
{
    DebuggerItem item(m_id);
    if (m_id.isNull())
        return item;

    item.setDisplayName(m_displayNameLineEdit->text());
    item.setCommand(m_binaryChooser->fileName());
    item.setAutoDetected(m_autodetected);
101
102
103
104
105
106
107
108
    QList<ProjectExplorer::Abi> abiList;
    foreach (const QString &a, m_abis->text().split(QRegExp(QLatin1String("[^A-Za-z0-9-_]+")))) {
        ProjectExplorer::Abi abi(a);
        if (a.isNull())
            continue;
        abiList << a;
    }
    item.setAbis(abiList);
109
    item.setEngineType(m_engineType);
110
111
112
    return item;
}

113
114
115

void DebuggerItemConfigWidget::store() const
{
116
117
118
    DebuggerItem i = item();
    if (i.isValid())
        m_model->updateDebugger(i);
119
120
121
122
123
124
125
}

void DebuggerItemConfigWidget::setAbis(const QStringList &abiNames)
{
    m_abis->setText(abiNames.join(QLatin1String(", ")));
}

126
void DebuggerItemConfigWidget::setItem(const DebuggerItem &item)
127
{
128
129
130
131
132
    store(); // store away the (changed) settings for future use

    m_autodetected = item.isAutoDetected();
    m_id = item.id();

133
134
    m_displayNameLineEdit->setEnabled(!item.isAutoDetected());
    m_displayNameLineEdit->setText(item.displayName());
135

136
137
    m_binaryChooser->setEnabled(!item.isAutoDetected());
    m_binaryChooser->setFileName(item.command());
138
139
140

    QString text;
    QString versionCommand;
141
    if (item.engineType() == CdbEngineType) {
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#ifdef Q_OS_WIN
        const bool is64bit = winIs64BitSystem();
#else
        const bool is64bit = false;
#endif
        const QString versionString = is64bit ? tr("64-bit version") : tr("32-bit version");
        //: Label text for path configuration. %2 is "x-bit version".
        text = tr("<html><body><p>Specify the path to the "
                  "<a href=\"%1\">Windows Console Debugger executable</a>"
                  " (%2) here.</p>""</body></html>").
                arg(QLatin1String(debuggingToolsWikiLinkC), versionString);
        versionCommand = QLatin1String("-version");
    } else {
        versionCommand = QLatin1String("--version");
    }

    m_cdbLabel->setText(text);
    m_cdbLabel->setVisible(!text.isEmpty());
    m_binaryChooser->setCommandVersionArguments(QStringList(versionCommand));

162
    setAbis(item.abiNames());
163
    m_engineType = item.engineType();
164
165
}

166
void DebuggerItemConfigWidget::apply()
167
{
168
169
    DebuggerItem current = m_model->currentDebugger();
    if (!current.isValid())
170
        return; // Nothing was selected here.
171

172
173
174
175
176
177
178
179
180
181
182
    store();
    setItem(item());
}

void DebuggerItemConfigWidget::commandWasChanged()
{
    // Use DebuggerItemManager as a cache:
    const DebuggerItem *existing
            = DebuggerItemManager::findByCommand(m_binaryChooser->fileName());
    if (existing) {
        setAbis(existing->abiNames());
183
        m_engineType = existing->engineType();
184
185
186
187
188
189
    } else {
        QFileInfo fi = QFileInfo(m_binaryChooser->path());
        if (fi.isExecutable()) {
            DebuggerItem tmp = item();
            tmp.reinitializeFromFile();
            setAbis(tmp.abiNames());
190
            m_engineType = tmp.engineType();
191
192
        }
    }
193
    m_model->updateDebugger(item());
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
}

// --------------------------------------------------------------------------
// DebuggerOptionsPage
// --------------------------------------------------------------------------

DebuggerOptionsPage::DebuggerOptionsPage()
{
    m_model = 0;
    m_debuggerView = 0;
    m_container = 0;
    m_addButton = 0;
    m_cloneButton = 0;
    m_delButton = 0;

    setId(ProjectExplorer::Constants::DEBUGGER_SETTINGS_PAGE_ID);
    setDisplayName(tr("Debuggers"));
    setCategory(ProjectExplorer::Constants::PROJECTEXPLORER_SETTINGS_CATEGORY);
    setDisplayCategory(QCoreApplication::translate("ProjectExplorer",
        ProjectExplorer::Constants::PROJECTEXPLORER_SETTINGS_TR_CATEGORY));
    setCategoryIcon(QLatin1String(ProjectExplorer::Constants::PROJECTEXPLORER_SETTINGS_CATEGORY_ICON));
}

QWidget *DebuggerOptionsPage::createPage(QWidget *parent)
{
    m_configWidget = new QWidget(parent);

    m_addButton = new QPushButton(tr("Add"), m_configWidget);
    m_cloneButton = new QPushButton(tr("Clone"), m_configWidget);
    m_delButton = new QPushButton(tr("Remove"), m_configWidget);

    m_container = new DetailsWidget(m_configWidget);
    m_container->setState(DetailsWidget::NoSummary);
    m_container->setVisible(false);

229
    m_model = new DebuggerItemModel(parent);
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268

    m_debuggerView = new QTreeView(m_configWidget);
    m_debuggerView->setModel(m_model);
    m_debuggerView->setUniformRowHeights(true);
    m_debuggerView->setSelectionMode(QAbstractItemView::SingleSelection);
    m_debuggerView->setSelectionBehavior(QAbstractItemView::SelectRows);
    m_debuggerView->expandAll();

    QHeaderView *header = m_debuggerView->header();
    header->setStretchLastSection(false);
    header->setResizeMode(0, QHeaderView::ResizeToContents);
    header->setResizeMode(1, QHeaderView::ResizeToContents);
    header->setResizeMode(2, QHeaderView::Stretch);

    QVBoxLayout *buttonLayout = new QVBoxLayout();
    buttonLayout->setSpacing(6);
    buttonLayout->setContentsMargins(0, 0, 0, 0);
    buttonLayout->addWidget(m_addButton);
    buttonLayout->addWidget(m_cloneButton);
    buttonLayout->addWidget(m_delButton);
    buttonLayout->addItem(new QSpacerItem(10, 40, QSizePolicy::Minimum, QSizePolicy::Expanding));

    QVBoxLayout *verticalLayout = new QVBoxLayout();
    verticalLayout->addWidget(m_debuggerView);
    verticalLayout->addWidget(m_container);

    QHBoxLayout *horizontalLayout = new QHBoxLayout(m_configWidget);
    horizontalLayout->addLayout(verticalLayout);
    horizontalLayout->addLayout(buttonLayout);

    connect(m_debuggerView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
            this, SLOT(debuggerSelectionChanged()));

    connect(m_addButton, SIGNAL(clicked()), this, SLOT(addDebugger()), Qt::QueuedConnection);
    connect(m_cloneButton, SIGNAL(clicked()), this, SLOT(cloneDebugger()), Qt::QueuedConnection);
    connect(m_delButton, SIGNAL(clicked()), this, SLOT(removeDebugger()), Qt::QueuedConnection);

    m_searchKeywords = tr("Debuggers");

269
    m_itemConfigWidget = new DebuggerItemConfigWidget(m_model);
270
271
272
273
274
275
276
277
278
    m_container->setWidget(m_itemConfigWidget);

    updateState();

    return m_configWidget;
}

void DebuggerOptionsPage::apply()
{
279
280
    m_itemConfigWidget->apply();
    m_model->apply();
281
282
283
284
}

void DebuggerOptionsPage::cloneDebugger()
{
285
286
287
288
    DebuggerItem item = m_model->currentDebugger();
    if (!item.isValid())
        return;

289
    DebuggerItem newItem;
290
291
    newItem.createId();
    newItem.setAutoDetected(false);
292
293
294
295
    newItem.setCommand(item.command());
    newItem.setEngineType(item.engineType());
    newItem.setAbis(item.abis());
    newItem.setDisplayName(DebuggerItemManager::uniqueDisplayName(tr("Clone of %1").arg(item.displayName())));
296
    newItem.setAutoDetected(false);
297
    m_model->addDebugger(newItem);
298
299
300
301
302
303
    m_debuggerView->setCurrentIndex(m_model->lastIndex());
}

void DebuggerOptionsPage::addDebugger()
{
    DebuggerItem item;
304
305
    item.createId();
    item.setAutoDetected(false);
306
307
308
    item.setEngineType(NoEngineType);
    item.setDisplayName(DebuggerItemManager::uniqueDisplayName(tr("New Debugger")));
    item.setAutoDetected(false);
309
    m_model->addDebugger(item);
310
311
312
313
314
    m_debuggerView->setCurrentIndex(m_model->lastIndex());
}

void DebuggerOptionsPage::removeDebugger()
{
315
316
    QVariant id = m_model->currentDebuggerId();
    m_model->removeDebugger(id);
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
    m_debuggerView->setCurrentIndex(m_model->lastIndex());
}

void DebuggerOptionsPage::finish()
{
    // Deleted by settingsdialog.
    m_configWidget = 0;

    // Children of m_configWidget.
    m_container = 0;
    m_debuggerView = 0;
    m_addButton = 0;
    m_cloneButton = 0;
    m_delButton = 0;
}

bool DebuggerOptionsPage::matches(const QString &s) const
{
    return m_searchKeywords.contains(s, Qt::CaseInsensitive);
}

void DebuggerOptionsPage::debuggerSelectionChanged()
{
    QTC_ASSERT(m_container, return);

    QModelIndex mi = m_debuggerView->currentIndex();
    mi = mi.sibling(mi.row(), 0);
    m_model->setCurrentIndex(mi);

346
347
348
349
    DebuggerItem item = m_model->currentDebugger();

    m_itemConfigWidget->setItem(item);
    m_container->setVisible(item.isValid());
350
351
352
353
354
355
356
    updateState();
}

void DebuggerOptionsPage::debuggerModelChanged()
{
    QTC_ASSERT(m_container, return);

357
358
359
360
361
362
363
    QVariant id = m_model->currentDebuggerId();
    const DebuggerItem *item = DebuggerItemManager::findById(id);
    if (!item)
        return;

    m_itemConfigWidget->setItem(*item);
    m_container->setVisible(m_model->currentDebuggerId().isValid());
364
365
366
367
368
369
370
371
372
    m_debuggerView->setCurrentIndex(m_model->currentIndex());
    updateState();
}

void DebuggerOptionsPage::updateState()
{
    if (!m_cloneButton)
        return;

373
374
    DebuggerItem item = m_model->currentDebugger();

Tobias Hunger's avatar
Tobias Hunger committed
375
376
    bool canCopy = item.isValid() && item.canClone();
    bool canDelete = m_model->currentIndex().parent().isValid() && !item.isAutoDetected();
377

378
379
380
381
382
383
    m_cloneButton->setEnabled(canCopy);
    m_delButton->setEnabled(canDelete);
}

} // namespace Internal
} // namespace Debugger