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
/**************************************************************************
**
** Copyright (C) 2011 - 2013 Research In Motion
**
** Contact: Research In Motion (blackberry-qt@qnx.com)
** Contact: KDAB (info@kdab.com)
**
** 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 "bardescriptoreditorwidget.h"
#include "ui_bardescriptoreditorwidget.h"
#include "qnxconstants.h"
#include "bardescriptoreditor.h"
#include "bardescriptorpermissionsmodel.h"
#include "blackberrydeviceconfiguration.h"
#include "blackberrydebugtokenreader.h"
#include <projectexplorer/devicesupport/devicemanager.h>
#include <qtsupport/qtversionmanager.h>
#include <texteditor/plaintexteditor.h>
#include <utils/qtcassert.h>
#include <QInputDialog>
#include <QMessageBox>
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
#include <QStandardItemModel>
#include <QStringListModel>
using namespace Qnx;
using namespace Qnx::Internal;
namespace {
void setTextBlocked(QLineEdit *lineEdit, const QString &value)
{
bool blocked = lineEdit->blockSignals(true);
lineEdit->setText(value);
lineEdit->blockSignals(blocked);
}
void setComboBoxDataBlocked(QComboBox *comboBox, const QString &data)
{
int index = comboBox->findData(data);
QTC_CHECK(index > -1);
bool blocked = comboBox->blockSignals(true);
comboBox->setCurrentIndex(index);
comboBox->blockSignals(blocked);
}
void setPathBlocked(Utils::PathChooser *pathChooser, const QString &path)
{
bool blocked = pathChooser->blockSignals(true);
pathChooser->setPath(path);
pathChooser->blockSignals(blocked);
}
void setCheckBoxBlocked(QCheckBox *checkBox, bool check)
{
bool blocked = checkBox->blockSignals(true);
checkBox->setChecked(check);
checkBox->blockSignals(blocked);
}
// Recommended maximum size for icons according to
// http://developer.blackberry.com/native/documentation/bb10/com.qnx.doc.native_sdk.devguide/com.qnx.doc.native_sdk.devguide/topic/r_barfile_dtd_ref_image.html
static int AppIconMaxWidth = 114;
static int AppIconMaxHeight = 114;
// Recommended maximum size for splashscreens according to
// http://developer.blackberry.com/native/documentation/bb10/com.qnx.doc.native_sdk.devguide/com.qnx.doc.native_sdk.devguide/topic/r_barfile_dtd_ref_splashscreens.html
static int SplashScreenMaxWidth = 1280;
static int SplashScreenMaxHeight = 1280;
}
BarDescriptorEditorWidget::BarDescriptorEditorWidget(QWidget *parent)
: QStackedWidget(parent)
, m_editor(0)
, m_dirty(false)
, m_ui(new Ui::BarDescriptorEditorWidget)
{
m_ui->setupUi(this);
setCurrentIndex(0);
initGeneralPage();
initApplicationPage();
initAssetsPage();
initSourcePage();
}
BarDescriptorEditorWidget::~BarDescriptorEditorWidget()
{
delete m_ui;
}
void BarDescriptorEditorWidget::initGeneralPage()
{
m_ui->setFromDebugToken->setVisible(BlackBerryDebugTokenReader::isSupported());
QRegExp versionNumberRegExp(QLatin1String("(\\d{1,3}\\.)?(\\d{1,3}\\.)?(\\d{1,3})"));
QRegExpValidator *versionNumberValidator = new QRegExpValidator(versionNumberRegExp, this);
m_ui->packageVersion->setValidator(versionNumberValidator);
connect(m_ui->packageId, SIGNAL(textChanged(QString)), this, SLOT(setDirty()));
connect(m_ui->packageVersion, SIGNAL(textChanged(QString)), this, SLOT(setDirty()));
connect(m_ui->packageBuildId, SIGNAL(textChanged(QString)), this, SLOT(setDirty()));
connect(m_ui->author, SIGNAL(textChanged(QString)), this, SLOT(setDirty()));
connect(m_ui->authorId, SIGNAL(textChanged(QString)), this, SLOT(setDirty()));
connect(m_ui->setFromDebugToken, SIGNAL(clicked()), this, SLOT(setAuthorFromDebugToken()));
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
171
172
173
174
175
176
177
178
179
}
void BarDescriptorEditorWidget::clearGeneralPage()
{
setTextBlocked(m_ui->packageId, QString());
setTextBlocked(m_ui->packageVersion, QString());
setTextBlocked(m_ui->packageBuildId, QString());
setTextBlocked(m_ui->author, QString());
setTextBlocked(m_ui->authorId, QString());
}
void BarDescriptorEditorWidget::initApplicationPage()
{
// General
m_ui->orientation->addItem(tr("Default"), QLatin1String(""));
m_ui->orientation->addItem(tr("Auto-orient"), QLatin1String("auto-orient"));
m_ui->orientation->addItem(tr("Landscape"), QLatin1String("landscape"));
m_ui->orientation->addItem(tr("Portrait"), QLatin1String("portrait"));
m_ui->chrome->addItem(tr("Standard"), QLatin1String("standard"));
m_ui->chrome->addItem(tr("None"), QLatin1String("none"));
connect(m_ui->orientation, SIGNAL(currentIndexChanged(int)), this, SLOT(setDirty()));
connect(m_ui->chrome, SIGNAL(currentIndexChanged(int)), this, SLOT(setDirty()));
connect(m_ui->transparentMainWindow, SIGNAL(toggled(bool)), this, SLOT(setDirty()));
connect(m_ui->applicationArguments, SIGNAL(textChanged(QString)), this, SLOT(setDirty()));
//Permissions
m_permissionsModel = new BarDescriptorPermissionsModel(this);
m_ui->permissionsView->setModel(m_permissionsModel);
connect(m_ui->selectAllPermissions, SIGNAL(clicked()), m_permissionsModel, SLOT(checkAll()));
connect(m_ui->deselectAllPermissions, SIGNAL(clicked()), m_permissionsModel, SLOT(uncheckAll()));
connect(m_permissionsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(setDirty()));
// Environment
m_ui->environmentWidget->setBaseEnvironmentText(tr("Device Environment"));
connect(m_ui->environmentWidget, SIGNAL(userChangesChanged()), this, SLOT(setDirty()));
// Entry-Point Text and Images
m_ui->iconFilePath->setExpectedKind(Utils::PathChooser::File);
m_ui->iconFilePath->setPromptDialogFilter(tr("Images (*.jpg *.png)"));
m_ui->iconWarningLabel->setVisible(false);
m_ui->iconWarningPixmap->setVisible(false);
m_ui->splashScreenWarningLabel->setVisible(false);
m_ui->splashScreenWarningPixmap->setVisible(false);
connect(m_ui->applicationName, SIGNAL(textChanged(QString)), this, SLOT(setDirty()));
connect(m_ui->applicationDescription, SIGNAL(textChanged()), this, SLOT(setDirty()));
connect(m_ui->iconFilePath, SIGNAL(changed(QString)), this, SLOT(setDirty()));
connect(m_ui->iconFilePath, SIGNAL(changed(QString)), this, SLOT(addImageAsAsset(QString)));
connect(m_ui->iconFilePath, SIGNAL(changed(QString)), this, SLOT(setApplicationIconPreview(QString)));
connect(m_ui->iconFilePath, SIGNAL(changed(QString)), this, SLOT(validateIconSize(QString)));
193
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
connect(m_ui->iconClearButton, SIGNAL(clicked()), m_ui->iconFilePath->lineEdit(), SLOT(clear()));
m_splashScreenModel = new QStringListModel(this);
m_ui->splashScreensView->setModel(m_splashScreenModel);
connect(m_ui->addSplashScreen, SIGNAL(clicked()), this, SLOT(browseForSplashScreen()));
connect(m_ui->removeSplashScreen, SIGNAL(clicked()), this, SLOT(removeSelectedSplashScreen()));
connect(m_splashScreenModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(setDirty()));
connect(m_ui->splashScreensView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(handleSplashScreenSelectionChanged(QItemSelection, QItemSelection)));
}
void BarDescriptorEditorWidget::clearApplicationPage()
{
// General
setComboBoxDataBlocked(m_ui->orientation, QLatin1String(""));
setComboBoxDataBlocked(m_ui->chrome, QLatin1String("none"));
setCheckBoxBlocked(m_ui->transparentMainWindow, false);
setTextBlocked(m_ui->applicationArguments, QString());
// Permissions
disconnect(m_permissionsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(setDirty()));
m_permissionsModel->uncheckAll();
connect(m_permissionsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(setDirty()));
// Environment
disconnect(m_ui->environmentWidget, SIGNAL(userChangesChanged()), this, SLOT(setDirty()));
m_ui->environmentWidget->setUserChanges(QList<Utils::EnvironmentItem>());
connect(m_ui->environmentWidget, SIGNAL(userChangesChanged()), this, SLOT(setDirty()));
// Entry-Point Text and Images
setPathBlocked(m_ui->iconFilePath, QString());
setApplicationIconPreview(QString());
disconnect(m_splashScreenModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(setDirty()));
m_splashScreenModel->setStringList(QStringList());
connect(m_splashScreenModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(setDirty()));
setImagePreview(m_ui->splashScreenPreviewLabel, QString());
}
void BarDescriptorEditorWidget::initAssetsPage()
{
QStringList headerLabels;
headerLabels << tr("Path") << tr("Destination") << tr("Entry-Point");
m_assetsModel = new QStandardItemModel(this);
m_assetsModel->setHorizontalHeaderLabels(headerLabels);
m_ui->assets->setModel(m_assetsModel);
connect(m_ui->addAsset, SIGNAL(clicked()), this, SLOT(addNewAsset()));
connect(m_ui->removeAsset, SIGNAL(clicked()), this, SLOT(removeSelectedAsset()));
connect(m_assetsModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updateEntryCheckState(QStandardItem*)));
connectAssetsModel();
}
void BarDescriptorEditorWidget::clearAssetsPage()
{
// We can't just block signals, as the view depends on them
disconnectAssetsModel();
m_assetsModel->removeRows(0, m_assetsModel->rowCount());
connectAssetsModel();
}
void BarDescriptorEditorWidget::initSourcePage()
{
m_ui->xmlSourceView->configure(QLatin1String(Constants::QNX_BAR_DESCRIPTOR_MIME_TYPE));
connect(m_ui->xmlSourceView, SIGNAL(textChanged()), this, SLOT(setDirty()));
}
void BarDescriptorEditorWidget::clearSourcePage()
{
disconnect(m_ui->xmlSourceView, SIGNAL(textChanged()), this, SLOT(setDirty()));
m_ui->xmlSourceView->clear();
connect(m_ui->xmlSourceView, SIGNAL(textChanged()), this, SLOT(setDirty()));
void BarDescriptorEditorWidget::disconnectAssetsModel()
{
disconnect(m_assetsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(setDirty()));
disconnect(m_assetsModel, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(setDirty()));
disconnect(m_assetsModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(setDirty()));
}
void BarDescriptorEditorWidget::connectAssetsModel()
{
connect(m_assetsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(setDirty()));
connect(m_assetsModel, SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(setDirty()));
connect(m_assetsModel, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(setDirty()));
}
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
Core::IEditor *BarDescriptorEditorWidget::editor() const
{
if (!m_editor) {
m_editor = const_cast<BarDescriptorEditorWidget *>(this)->createEditor();
connect(this, SIGNAL(changed()), m_editor, SIGNAL(changed()));
}
return m_editor;
}
QString BarDescriptorEditorWidget::packageId() const
{
return m_ui->packageId->text();
}
void BarDescriptorEditorWidget::setPackageId(const QString &packageId)
{
setTextBlocked(m_ui->packageId, packageId);
}
QString BarDescriptorEditorWidget::packageVersion() const
{
QString version = m_ui->packageVersion->text();
int pos = 0;
if (m_ui->packageVersion->validator()->validate(version, pos) == QValidator::Intermediate) {
if (version.endsWith(QLatin1Char('.')))
version = version.left(version.size() - 1);
}
return version;
}
void BarDescriptorEditorWidget::setPackageVersion(const QString &packageVersion)
{
setTextBlocked(m_ui->packageVersion, packageVersion);
}
QString BarDescriptorEditorWidget::packageBuildId() const
{
return m_ui->packageBuildId->text();
}
void BarDescriptorEditorWidget::setPackageBuildId(const QString &packageBuildId)
{
setTextBlocked(m_ui->packageBuildId, packageBuildId);
}
QString BarDescriptorEditorWidget::author() const
{
return m_ui->author->text();
}
void BarDescriptorEditorWidget::setAuthor(const QString &author)
{
setTextBlocked(m_ui->author, author);
}
QString BarDescriptorEditorWidget::authorId() const
{
return m_ui->authorId->text();
}
void BarDescriptorEditorWidget::setAuthorId(const QString &authorId)
{
setTextBlocked(m_ui->authorId, authorId);
}
QString BarDescriptorEditorWidget::orientation() const
{
return m_ui->orientation->itemData(m_ui->orientation->currentIndex()).toString();
}
void BarDescriptorEditorWidget::setOrientation(const QString &orientation)
{
setComboBoxDataBlocked(m_ui->orientation, orientation);
}
QString BarDescriptorEditorWidget::chrome() const
{
return m_ui->chrome->itemData(m_ui->chrome->currentIndex()).toString();
}
void BarDescriptorEditorWidget::setChrome(const QString &chrome)
{
setComboBoxDataBlocked(m_ui->chrome, chrome);
}
bool BarDescriptorEditorWidget::transparent() const
{
return m_ui->transparentMainWindow->isChecked();
}
void BarDescriptorEditorWidget::setTransparent(bool transparent)
{
setCheckBoxBlocked(m_ui->transparentMainWindow, transparent);
}
void BarDescriptorEditorWidget::appendApplicationArgument(const QString &argument)
{
QString completeArguments = m_ui->applicationArguments->text();
if (!completeArguments.isEmpty())
completeArguments.append(QLatin1Char(' '));
completeArguments.append(argument);
setTextBlocked(m_ui->applicationArguments, completeArguments);
}
QStringList BarDescriptorEditorWidget::applicationArguments() const
{
// TODO: Should probably handle "argument with spaces within quotes"
return m_ui->applicationArguments->text().split(QLatin1Char(' '));
}
QStringList BarDescriptorEditorWidget::checkedPermissions() const
{
return m_permissionsModel->checkedIdentifiers();
}
void BarDescriptorEditorWidget::checkPermission(const QString &identifier)
{
disconnect(m_permissionsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(setDirty()));
m_permissionsModel->checkPermission(identifier);
connect(m_permissionsModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(setDirty()));
}
QList<Utils::EnvironmentItem> BarDescriptorEditorWidget::environment() const
{
return m_ui->environmentWidget->userChanges();
}
void BarDescriptorEditorWidget::appendEnvironmentItem(const Utils::EnvironmentItem &envItem)
{
disconnect(m_ui->environmentWidget, SIGNAL(userChangesChanged()), this, SLOT(setDirty()));
QList<Utils::EnvironmentItem> items = m_ui->environmentWidget->userChanges();
items.append(envItem);
m_ui->environmentWidget->setUserChanges(items);
connect(m_ui->environmentWidget, SIGNAL(userChangesChanged()), this, SLOT(setDirty()));
}
QString BarDescriptorEditorWidget::applicationName() const
{
return m_ui->applicationName->text();
}
void BarDescriptorEditorWidget::setApplicationName(const QString &applicationName)
{
setTextBlocked(m_ui->applicationName, applicationName);
}
QString BarDescriptorEditorWidget::applicationDescription() const
{
return m_ui->applicationDescription->toPlainText();
}
void BarDescriptorEditorWidget::setApplicationDescription(const QString &applicationDescription)
{
bool blocked = m_ui->applicationDescription->blockSignals(true);
m_ui->applicationDescription->setPlainText(applicationDescription);
m_ui->applicationDescription->blockSignals(blocked);
}
QString BarDescriptorEditorWidget::applicationIconFileName() const
{
return QFileInfo(m_ui->iconFilePath->path()).fileName();
}
void BarDescriptorEditorWidget::setApplicationIcon(const QString &iconPath)
{
// During file loading, the assets might not have been read yet
QMetaObject::invokeMethod(this, "setApplicationIconDelayed", Qt::QueuedConnection, Q_ARG(QString, iconPath));
}
QStringList BarDescriptorEditorWidget::splashScreens() const
{
QStringList result;
foreach (const QString &splashScreen, m_splashScreenModel->stringList())
result << QFileInfo(splashScreen).fileName();
return result;
}
void BarDescriptorEditorWidget::appendSplashScreen(const QString &splashScreenPath)
{
// During file loading, the assets might not have been read yet
QMetaObject::invokeMethod(this, "appendSplashScreenDelayed", Qt::QueuedConnection, Q_ARG(QString, splashScreenPath));
}
void BarDescriptorEditorWidget::setApplicationIconDelayed(const QString &iconPath)
{
const QString fullIconPath = localAssetPathFromDestination(iconPath);
setPathBlocked(m_ui->iconFilePath, fullIconPath);
setApplicationIconPreview(fullIconPath);
validateIconSize(fullIconPath);
}
void BarDescriptorEditorWidget::setImagePreview(QLabel *previewLabel, const QString &path)
{
if (path.isEmpty()) {
previewLabel->clear();
return;
}
QPixmap originalPixmap(path);
if (originalPixmap.isNull()) {
previewLabel->clear();
return;
}
QSize size = previewLabel->minimumSize();
QPixmap scaledPixmap = originalPixmap.scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
if (scaledPixmap.isNull()) {
previewLabel->clear();
return;
}
previewLabel->setPixmap(scaledPixmap);
}
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
void BarDescriptorEditorWidget::validateImage(const QString &path, QLabel *warningMessage, QLabel *warningPixmap, const QSize &maximumSize)
{
ImageValidationResult result = Valid;
QSize actualSize;
if (!path.isEmpty()) {
QImage img(path);
if (img.isNull()) {
result = CouldNotLoad;
} else {
actualSize = img.size();
if (actualSize.width() > maximumSize.width() || actualSize.height() > maximumSize.height())
result = IncorrectSize;
}
}
switch (result) {
case CouldNotLoad:
warningMessage->setText(tr("<font color=\"red\">Could not open '%1' for reading.</font>").arg(path));
warningMessage->setVisible(true);
warningPixmap->setVisible(true);
break;
case IncorrectSize: {
warningMessage->setText(tr("<font color=\"red\">The selected image is too big (%1x%2). The maximum size is %3x%4 pixels.</font>")
.arg(actualSize.width()).arg(actualSize.height())
.arg(maximumSize.width()).arg(maximumSize.height()));
warningMessage->setVisible(true);
warningPixmap->setVisible(true);
break;
}
case Valid:
default:
warningMessage->setVisible(false);
warningPixmap->setVisible(false);
break;
}
}
void BarDescriptorEditorWidget::setApplicationIconPreview(const QString &path)
{
setImagePreview(m_ui->iconPreviewLabel, path);
}
void BarDescriptorEditorWidget::validateIconSize(const QString &path)
{
validateImage(path, m_ui->iconWarningLabel, m_ui->iconWarningPixmap, QSize(AppIconMaxWidth, AppIconMaxHeight));
}
void BarDescriptorEditorWidget::appendSplashScreenDelayed(const QString &splashScreenPath)
{
const QString fullSplashScreenPath = localAssetPathFromDestination(splashScreenPath);
disconnect(m_splashScreenModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(setDirty()));
int rowCount = m_splashScreenModel->rowCount();
m_splashScreenModel->insertRow(rowCount);
m_splashScreenModel->setData(m_splashScreenModel->index(rowCount), fullSplashScreenPath);
connect(m_splashScreenModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(setDirty()));
}
void BarDescriptorEditorWidget::browseForSplashScreen()
{
const QString fileName = QFileDialog::getOpenFileName(this, tr("Select Splash Screen"), QString(), tr("Images (*.jpg *.png)"));
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
if (fileName.isEmpty())
return;
if (m_splashScreenModel->stringList().contains(fileName))
return;
int rowCount = m_splashScreenModel->rowCount();
m_splashScreenModel->insertRow(rowCount);
m_splashScreenModel->setData(m_splashScreenModel->index(rowCount), fileName);
addImageAsAsset(fileName);
}
void BarDescriptorEditorWidget::removeSelectedSplashScreen()
{
QModelIndexList selectedIndexes = m_ui->splashScreensView->selectionModel()->selectedRows();
if (selectedIndexes.isEmpty())
return;
foreach (const QModelIndex &index, selectedIndexes) {
QString path = m_splashScreenModel->data(index, Qt::DisplayRole).toString();
QList<QStandardItem*> assetItems = m_assetsModel->findItems(path);
foreach (QStandardItem *assetItem, assetItems) {
QList<QStandardItem*> assetRow = m_assetsModel->takeRow(assetItem->row());
while (!assetRow.isEmpty())
delete assetRow.takeLast();
}
m_splashScreenModel->removeRow(index.row());
}
}
void BarDescriptorEditorWidget::handleSplashScreenSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{
Q_UNUSED(deselected);
const bool emptySelection = selected.indexes().isEmpty();
m_ui->removeSplashScreen->setEnabled(!emptySelection);
if (!emptySelection) {
QString path = m_splashScreenModel->data(selected.indexes().at(0), Qt::DisplayRole).toString();
setImagePreview(m_ui->splashScreenPreviewLabel, path);
validateSplashScreenSize(path);
} else {
setImagePreview(m_ui->splashScreenPreviewLabel, QString());
m_ui->splashScreenWarningLabel->setVisible(false);
m_ui->splashScreenWarningPixmap->setVisible(false);
void BarDescriptorEditorWidget::validateSplashScreenSize(const QString &path)
{
validateImage(path, m_ui->splashScreenWarningLabel, m_ui->splashScreenWarningPixmap, QSize(SplashScreenMaxWidth, SplashScreenMaxHeight));
}
void BarDescriptorEditorWidget::addAsset(const BarDescriptorAsset &asset)
{
disconnectAssetsModel();
addAssetInternal(asset);
connectAssetsModel();
}
void BarDescriptorEditorWidget::addAssetInternal(const BarDescriptorAsset &asset)
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
{
const QString path = asset.source;
const QString dest = asset.destination;
QTC_ASSERT(!path.isEmpty(), return);
QTC_ASSERT(!dest.isEmpty(), return);
if (hasAsset(asset))
return;
QList<QStandardItem *> items;
items << new QStandardItem(path);
items << new QStandardItem(dest);
QStandardItem *entryItem = new QStandardItem();
entryItem->setCheckable(true);
entryItem->setCheckState(asset.entry ? Qt::Checked : Qt::Unchecked);
items << entryItem;
m_assetsModel->appendRow(items);
}
bool BarDescriptorEditorWidget::hasAsset(const BarDescriptorAsset &asset)
{
// TODO: Move this to a specific BarDescriptorAssetModel
for (int i = 0; i < m_assetsModel->rowCount(); ++i) {
QStandardItem *sourceItem = m_assetsModel->item(i, 0);
QStandardItem *destItem = m_assetsModel->item(i, 1);
if (sourceItem->text() == asset.source && destItem->text() == asset.destination)
return true;
}
return false;
}
QString BarDescriptorEditorWidget::localAssetPathFromDestination(const QString &destination)
{
for (int i = 0; i < m_assetsModel->rowCount(); ++i) {
QStandardItem *destItem = m_assetsModel->item(i, 1);
if (destItem->text() == destination)
return m_assetsModel->item(i, 0)->text();
}
return QString();
}
QList<BarDescriptorAsset> BarDescriptorEditorWidget::assets() const
{
QList<BarDescriptorAsset> result;
for (int i = 0; i < m_assetsModel->rowCount(); ++i) {
BarDescriptorAsset asset;
asset.source = m_assetsModel->item(i, 0)->text();
asset.destination = m_assetsModel->item(i, 1)->text();
asset.entry = m_assetsModel->item(i, 2)->checkState() == Qt::Checked;
result << asset;
}
return result;
}
QString BarDescriptorEditorWidget::xmlSource() const
{
return m_ui->xmlSourceView->toPlainText();
}
void BarDescriptorEditorWidget::setXmlSource(const QString &xmlSource)
{
disconnect(m_ui->xmlSourceView, SIGNAL(textChanged()), this, SLOT(setDirty()));
m_ui->xmlSourceView->setPlainText(xmlSource);
connect(m_ui->xmlSourceView, SIGNAL(textChanged()), this, SLOT(setDirty()));
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
}
bool BarDescriptorEditorWidget::isDirty() const
{
return m_dirty;
}
void BarDescriptorEditorWidget::clear()
{
clearGeneralPage();
clearApplicationPage();
clearAssetsPage();
clearSourcePage();
}
void BarDescriptorEditorWidget::setDirty(bool dirty)
{
m_dirty = dirty;
emit changed();
}
BarDescriptorEditor *BarDescriptorEditorWidget::createEditor()
{
return new BarDescriptorEditor(this);
}
void BarDescriptorEditorWidget::addNewAsset()
{
const QString fileName = QFileDialog::getOpenFileName(this, tr("Select File to Add"));
if (fileName.isEmpty())
return;
QFileInfo fi(fileName);
BarDescriptorAsset asset;
asset.source = fileName;
asset.destination = fi.fileName();
asset.entry = false; // TODO
addAssetInternal(asset);
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
}
void BarDescriptorEditorWidget::removeSelectedAsset()
{
QModelIndexList selectedIndexes = m_ui->assets->selectionModel()->selectedRows();
if (selectedIndexes.isEmpty())
return;
foreach (const QModelIndex &index, selectedIndexes)
m_assetsModel->removeRow(index.row());
}
void BarDescriptorEditorWidget::updateEntryCheckState(QStandardItem *item)
{
if (item->column() != 2 || item->checkState() == Qt::Unchecked)
return;
disconnect(m_assetsModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updateEntryCheckState(QStandardItem*)));
for (int i = 0; i < m_assetsModel->rowCount(); ++i) {
QStandardItem *other = m_assetsModel->item(i, 2);
if (other == item)
continue;
// Only one asset can be the entry point
other->setCheckState(Qt::Unchecked);
}
connect(m_assetsModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updateEntryCheckState(QStandardItem*)));
}
void BarDescriptorEditorWidget::addImageAsAsset(const QString &path)
{
if (path.isEmpty())
return;
BarDescriptorAsset asset;
asset.source = path;
asset.destination = QFileInfo(path).fileName();
asset.entry = false;
addAssetInternal(asset);
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
void BarDescriptorEditorWidget::setAuthorFromDebugToken()
{
// To select debug token, make it fancier once the debug token management is done in
// Qt Creator
QStringList debugTokens;
ProjectExplorer::DeviceManager *deviceManager = ProjectExplorer::DeviceManager::instance();
for (int i = 0; i < deviceManager->deviceCount(); ++i) {
ProjectExplorer::IDevice::ConstPtr device = deviceManager->deviceAt(i);
if (device->type() == Core::Id(Constants::QNX_BB_OS_TYPE)) {
BlackBerryDeviceConfiguration::ConstPtr bbDevice = device.dynamicCast<const BlackBerryDeviceConfiguration>();
QTC_ASSERT(bbDevice, continue);
debugTokens << bbDevice->debugToken();
}
}
debugTokens.removeDuplicates();
bool ok;
QString debugToken = QInputDialog::getItem(this, tr("Select Debug Token"), tr("Debug token:"), debugTokens, 0, false, &ok);
if (!ok || debugToken.isEmpty())
return;
BlackBerryDebugTokenReader debugTokenReader(debugToken);
if (!debugTokenReader.isValid()) {
QMessageBox::warning(this, tr("Error Reading Debug Token"), tr("There was a problem reading debug token"));
return;
}
m_ui->author->setText(debugTokenReader.author());
m_ui->authorId->setText(debugTokenReader.authorId());
}