qt4target.cpp 19.9 KB
Newer Older
Tobias Hunger's avatar
Tobias Hunger committed
1
2
3
4
/**************************************************************************
**
** This file is part of Qt Creator
**
hjk's avatar
hjk committed
5
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
Tobias Hunger's avatar
Tobias Hunger committed
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
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#include "qt4target.h"

#include "makestep.h"
#include "profilereader.h"
#include "qmakestep.h"
Tobias Hunger's avatar
Tobias Hunger committed
35
#include "qt4deployconfiguration.h"
Tobias Hunger's avatar
Tobias Hunger committed
36
37
#include "qt4project.h"
#include "qt4runconfiguration.h"
38
#include "qt4projectmanagerconstants.h"
39
#include "qt-maemo/maemodeploystep.h"
40
#include "qt-maemo/maemopackagecreationstep.h"
Tobias Hunger's avatar
Tobias Hunger committed
41
#include "qt-maemo/maemorunconfiguration.h"
42
#include "qt-s60/s60deployconfiguration.h"
Tobias Hunger's avatar
Tobias Hunger committed
43
44
#include "qt-s60/s60devicerunconfiguration.h"
#include "qt-s60/s60emulatorrunconfiguration.h"
45
#include "qt-s60/s60createpackagestep.h"
46
#include "qt-s60/s60deploystep.h"
Tobias Hunger's avatar
Tobias Hunger committed
47

Tobias Hunger's avatar
Tobias Hunger committed
48
#include <projectexplorer/buildsteplist.h>
49
#include <projectexplorer/customexecutablerunconfiguration.h>
50
#include <projectexplorer/toolchaintype.h>
Tobias Hunger's avatar
Tobias Hunger committed
51
#include <projectexplorer/projectexplorerconstants.h>
con's avatar
con committed
52
53
#include <coreplugin/coreconstants.h>
#include <symbianutils/symbiandevicemanager.h>
Tobias Hunger's avatar
Tobias Hunger committed
54
55

#include <QtGui/QApplication>
con's avatar
con committed
56
57
#include <QtGui/QPixmap>
#include <QtGui/QPainter>
Tobias Hunger's avatar
Tobias Hunger committed
58
59
60
61
62
63
64
65

using namespace ProjectExplorer;
using namespace Qt4ProjectManager;
using namespace Qt4ProjectManager::Internal;

namespace {

QString displayNameForId(const QString &id) {
Tobias Hunger's avatar
Tobias Hunger committed
66
    if (id == QLatin1String(Qt4ProjectManager::Constants::DESKTOP_TARGET_ID))
Tobias Hunger's avatar
Tobias Hunger committed
67
        return QApplication::translate("Qt4ProjectManager::Internal::Qt4Target", "Desktop", "Qt4 Desktop target display name");
Tobias Hunger's avatar
Tobias Hunger committed
68
    if (id == QLatin1String(Qt4ProjectManager::Constants::S60_EMULATOR_TARGET_ID))
69
        return QApplication::translate("Qt4ProjectManager::Internal::Qt4Target", "Symbian Emulator", "Qt4 Symbian Emulator target display name");
Tobias Hunger's avatar
Tobias Hunger committed
70
    if (id == QLatin1String(Qt4ProjectManager::Constants::S60_DEVICE_TARGET_ID))
71
        return QApplication::translate("Qt4ProjectManager::Internal::Qt4Target", "Symbian Device", "Qt4 Symbian Device target display name");
Tobias Hunger's avatar
Tobias Hunger committed
72
    if (id == QLatin1String(Qt4ProjectManager::Constants::MAEMO_DEVICE_TARGET_ID))
Tobias Hunger's avatar
Tobias Hunger committed
73
        return QApplication::translate("Qt4ProjectManager::Internal::Qt4Target", "Maemo", "Qt4 Maemo target display name");
Tobias Hunger's avatar
Tobias Hunger committed
74
    if (id == QLatin1String(Qt4ProjectManager::Constants::QT_SIMULATOR_TARGET_ID))
75
        return QApplication::translate("Qt4ProjectManager::Internal::Qt4Target", "Qt Simulator", "Qt4 Simulator target display name");
Tobias Hunger's avatar
Tobias Hunger committed
76
77
78
79
    return QString();
}

QIcon iconForId(const QString &id) {
Tobias Hunger's avatar
Tobias Hunger committed
80
    if (id == QLatin1String(Qt4ProjectManager::Constants::DESKTOP_TARGET_ID))
Tobias Hunger's avatar
Tobias Hunger committed
81
        return QIcon(qApp->style()->standardIcon(QStyle::SP_ComputerIcon));
Tobias Hunger's avatar
Tobias Hunger committed
82
    if (id == QLatin1String(Qt4ProjectManager::Constants::S60_EMULATOR_TARGET_ID))
83
        return QIcon(QLatin1String(":/projectexplorer/images/SymbianEmulator.png"));
Tobias Hunger's avatar
Tobias Hunger committed
84
    if (id == QLatin1String(Qt4ProjectManager::Constants::S60_DEVICE_TARGET_ID))
85
        return QIcon(QLatin1String(":/projectexplorer/images/SymbianDevice.png"));
Tobias Hunger's avatar
Tobias Hunger committed
86
    if (id == QLatin1String(Qt4ProjectManager::Constants::MAEMO_DEVICE_TARGET_ID))
87
        return QIcon(QLatin1String(":/projectexplorer/images/MaemoDevice.png"));
Tobias Hunger's avatar
Tobias Hunger committed
88
    if (id == QLatin1String(Qt4ProjectManager::Constants::QT_SIMULATOR_TARGET_ID))
89
        return QIcon(QLatin1String(":/projectexplorer/images/SymbianEmulator.png"));
Tobias Hunger's avatar
Tobias Hunger committed
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
    return QIcon();
}

} // namespace

// -------------------------------------------------------------------------
// Qt4TargetFactory
// -------------------------------------------------------------------------

Qt4TargetFactory::Qt4TargetFactory(QObject *parent) :
    ITargetFactory(parent)
{
    connect(QtVersionManager::instance(), SIGNAL(qtVersionsChanged(QList<int>)),
            this, SIGNAL(availableCreationIdsChanged()));
}

Qt4TargetFactory::~Qt4TargetFactory()
{
}

QStringList Qt4TargetFactory::availableCreationIds(ProjectExplorer::Project *parent) const
{
    if (!qobject_cast<Qt4Project *>(parent))
        return QStringList();

115
116
117
118
119
120
121
122
123
    QSet<QString> ids;
    ids << QLatin1String("Qt4ProjectManager.Target.DesktopTarget")
        << QLatin1String("Qt4ProjectManager.Target.S60EmulatorTarget")
        << QLatin1String("Qt4ProjectManager.Target.S60DeviceTarget")
        << QLatin1String("Qt4ProjectManager.Target.MaemoDeviceTarget")
        << QLatin1String("Qt4ProjectManager.Target.QtSimulatorTarget");


    return parent->possibleTargetIds().intersect(ids).toList();
Tobias Hunger's avatar
Tobias Hunger committed
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
}

QString Qt4TargetFactory::displayNameForId(const QString &id) const
{
    return ::displayNameForId(id);
}

bool Qt4TargetFactory::canCreate(ProjectExplorer::Project *parent, const QString &id) const
{
    if (!qobject_cast<Qt4Project *>(parent))
        return false;

    return parent->canAddTarget(id);
}

Qt4Target *Qt4TargetFactory::create(ProjectExplorer::Project *parent, const QString &id)
140
{
141
142
143
144
    QList<QtVersion *> knownVersions = QtVersionManager::instance()->versionsForTargetId(id);
    if (knownVersions.count() > 1)
        knownVersions = knownVersions.mid(0, 1);
    return create(parent, id, knownVersions);
145
146
147
}

Qt4Target *Qt4TargetFactory::create(ProjectExplorer::Project *parent, const QString &id, QList<QtVersion *> versions)
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
{
    QList<BuildConfigurationInfo> infos;
    foreach (QtVersion *version, versions) {
        bool buildAll = false;
        if (version && version->isValid() && (version->defaultBuildConfig() & QtVersion::BuildAll))
            buildAll = true;

        if (buildAll) {
            infos.append(BuildConfigurationInfo(version, QtVersion::BuildAll | QtVersion::DebugBuild));
            infos.append(BuildConfigurationInfo(version, QtVersion::BuildAll));
        } else {
            infos.append(BuildConfigurationInfo(version, QtVersion::DebugBuild));
            infos.append(BuildConfigurationInfo(version, QtVersion::QmakeBuildConfig(0)));
        }
    }

    return create(parent, id, infos);
}

Qt4Target *Qt4TargetFactory::create(ProjectExplorer::Project *parent, const QString &id, QList<BuildConfigurationInfo> infos)
Tobias Hunger's avatar
Tobias Hunger committed
168
169
170
171
{
    if (!canCreate(parent, id))
        return 0;

172
173
    Qt4Project *qt4project = static_cast<Qt4Project *>(parent);
    Qt4Target *t = new Qt4Target(qt4project, id);
Tobias Hunger's avatar
Tobias Hunger committed
174

175
176
    QList<QtVersion *> knownVersions(QtVersionManager::instance()->versionsForTargetId(id));
    if (knownVersions.isEmpty())
Tobias Hunger's avatar
Tobias Hunger committed
177
178
        return t;

179
180
181
182
183
184
185
186
187
188
    // count Qt versions:
    int qtVersionCount = 0;
    {
        QSet<QtVersion *> differentVersions;
        foreach (const BuildConfigurationInfo &info, infos) {
            if (knownVersions.contains(info.version))
                differentVersions.insert(info.version);
        }
        qtVersionCount = differentVersions.count();
    }
189

190
191
192
    // Create Buildconfigurations:
    foreach (const BuildConfigurationInfo &info, infos) {
        if (!info.version || !knownVersions.contains(info.version))
193
194
            continue;

195
        QString displayName;
196

197
        if (qtVersionCount > 1)
198
199
            displayName = info.version->displayName() + QChar(' ');
        displayName.append((info.buildConfig & QtVersion::DebugBuild) ? tr("Debug") : tr("Release"));
200

201
        // Skip release builds for the symbian emulator.
202
203
        if (id == QLatin1String(Constants::S60_EMULATOR_TARGET_ID) &&
            !(info.buildConfig & QtVersion::DebugBuild))
204
205
206
            continue;

        t->addQt4BuildConfiguration(displayName, info.version, info.buildConfig, info.additionalArguments, info.directory);
Tobias Hunger's avatar
Tobias Hunger committed
207
208
    }

Tobias Hunger's avatar
Tobias Hunger committed
209
210
    t->addDeployConfiguration(t->deployConfigurationFactory()->create(t, ProjectExplorer::Constants::DEFAULT_DEPLOYCONFIGURATION_ID));

211
    // create RunConfigurations:
212
213
214
215
    QStringList pathes = qt4project->applicationProFilePathes();
    foreach (const QString &path, pathes)
        t->addRunConfigurationForPath(path);

216
217
218
    if (t->runConfigurations().isEmpty())
        t->addRunConfiguration(new CustomExecutableRunConfiguration(t));

Tobias Hunger's avatar
Tobias Hunger committed
219
220
221
222
223
224
225
226
227
228
229
230
231
    return t;
}

bool Qt4TargetFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
{
    return canCreate(parent, ProjectExplorer::idFromMap(map));
}

Qt4Target *Qt4TargetFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
{
    if (!canRestore(parent, map))
        return 0;

232
    Qt4Project *qt4project(static_cast<Qt4Project *>(parent));
Tobias Hunger's avatar
Tobias Hunger committed
233
234
235
236
237
238
239
240
241
242
243
244
245
    Qt4Target *t(new Qt4Target(qt4project, QLatin1String("transient ID")));
    if (t->fromMap(map))
        return t;
    delete t;
    return 0;
}

// -------------------------------------------------------------------------
// Qt4Target
// -------------------------------------------------------------------------

Qt4Target::Qt4Target(Qt4Project *parent, const QString &id) :
    ProjectExplorer::Target(parent, id),
con's avatar
con committed
246
247
    m_connectedPixmap(QLatin1String(":/projectexplorer/images/ConnectionOn.png")),
    m_disconnectedPixmap(QLatin1String(":/projectexplorer/images/ConnectionOff.png")),
Tobias Hunger's avatar
Tobias Hunger committed
248
249
    m_buildConfigurationFactory(new Qt4BuildConfigurationFactory(this)),
    m_deployConfigurationFactory(new Qt4DeployConfigurationFactory(this))
Tobias Hunger's avatar
Tobias Hunger committed
250
251
252
{
    connect(project(), SIGNAL(supportedTargetIdsChanged()),
            this, SLOT(updateQtVersion()));
dt's avatar
dt committed
253

Tobias Hunger's avatar
Tobias Hunger committed
254
    connect(this, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
dt's avatar
dt committed
255
            this, SLOT(emitProFileEvaluateNeeded()));
Tobias Hunger's avatar
Tobias Hunger committed
256
257
    connect(this, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
            this, SIGNAL(environmentChanged()));
258
259
    connect(this, SIGNAL(addedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
            this, SLOT(onAddedBuildConfiguration(ProjectExplorer::BuildConfiguration*)));
260
261
    connect(this, SIGNAL(addedDeployConfiguration(ProjectExplorer::DeployConfiguration*)),
            this, SLOT(onAddedDeployConfiguration(ProjectExplorer::DeployConfiguration*)));
con's avatar
con committed
262
263
    connect(this, SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
            this, SLOT(updateToolTipAndIcon()));
Tobias Hunger's avatar
Tobias Hunger committed
264

265
    setDefaultDisplayName(displayNameForId(id));
266
    setIcon(iconForId(id));
Tobias Hunger's avatar
Tobias Hunger committed
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
}

Qt4Target::~Qt4Target()
{
}

Qt4BuildConfiguration *Qt4Target::activeBuildConfiguration() const
{
    return static_cast<Qt4BuildConfiguration *>(Target::activeBuildConfiguration());
}

Qt4Project *Qt4Target::qt4Project() const
{
    return static_cast<Qt4Project *>(project());
}

Qt4BuildConfiguration *Qt4Target::addQt4BuildConfiguration(QString displayName, QtVersion *qtversion,
                                                           QtVersion::QmakeBuildConfigs qmakeBuildConfiguration,
285
                                                           QString additionalArguments,
286
                                                           QString directory)
Tobias Hunger's avatar
Tobias Hunger committed
287
288
289
290
291
292
{
    Q_ASSERT(qtversion);
    bool debug = qmakeBuildConfiguration & QtVersion::DebugBuild;

    // Add the buildconfiguration
    Qt4BuildConfiguration *bc = new Qt4BuildConfiguration(this);
293
    bc->setDefaultDisplayName(displayName);
Tobias Hunger's avatar
Tobias Hunger committed
294

Tobias Hunger's avatar
Tobias Hunger committed
295
296
297
298
299
300
301
302
303
304
    BuildStepList *buildSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_BUILD);
    BuildStepList *cleanSteps = bc->stepList(ProjectExplorer::Constants::BUILDSTEPS_CLEAN);
    Q_ASSERT(buildSteps);
    Q_ASSERT(cleanSteps);

    QMakeStep *qmakeStep = new QMakeStep(buildSteps);
    buildSteps->insertStep(0, qmakeStep);

    MakeStep *makeStep = new MakeStep(buildSteps);
    buildSteps->insertStep(1, makeStep);
305

Tobias Hunger's avatar
Tobias Hunger committed
306
    MakeStep* cleanStep = new MakeStep(cleanSteps);
Tobias Hunger's avatar
Tobias Hunger committed
307
    cleanStep->setClean(true);
308
    cleanStep->setUserArguments("clean");
Tobias Hunger's avatar
Tobias Hunger committed
309
    cleanSteps->insertStep(0, cleanStep);
Tobias Hunger's avatar
Tobias Hunger committed
310
311
312
313
314
    if (!additionalArguments.isEmpty())
        qmakeStep->setUserArguments(additionalArguments);

    // set some options for qmake and make
    if (qmakeBuildConfiguration & QtVersion::BuildAll) // debug_and_release => explicit targets
315
        makeStep->setUserArguments(debug ? "debug" : "release");
Tobias Hunger's avatar
Tobias Hunger committed
316
317
318
319
320

    bc->setQMakeBuildConfiguration(qmakeBuildConfiguration);

    // Finally set the qt version & ToolChain
    bc->setQtVersion(qtversion);
321
    ProjectExplorer::ToolChainType defaultTc = preferredToolChainType(filterToolChainTypes(bc->qtVersion()->possibleToolChainTypes()));
Tobias Hunger's avatar
Tobias Hunger committed
322
    bc->setToolChainType(defaultTc);
323
324
    if (!directory.isEmpty())
        bc->setShadowBuildAndDirectory(directory != project()->projectDirectory(), directory);
Tobias Hunger's avatar
Tobias Hunger committed
325
326
327
328
329
330
331
332
333
334
    addBuildConfiguration(bc);

    return bc;
}

Qt4BuildConfigurationFactory *Qt4Target::buildConfigurationFactory() const
{
    return m_buildConfigurationFactory;
}

Tobias Hunger's avatar
Tobias Hunger committed
335
336
337
338
339
ProjectExplorer::DeployConfigurationFactory *Qt4Target::deployConfigurationFactory() const
{
    return m_deployConfigurationFactory;
}

Tobias Hunger's avatar
Tobias Hunger committed
340
341
void Qt4Target::addRunConfigurationForPath(const QString &proFilePath)
{
342
343
    if (id() == QLatin1String(Constants::DESKTOP_TARGET_ID) ||
        id() == QLatin1String(Constants::QT_SIMULATOR_TARGET_ID))
Tobias Hunger's avatar
Tobias Hunger committed
344
        addRunConfiguration(new Qt4RunConfiguration(this, proFilePath));
345
    else if (id() == QLatin1String(Constants::S60_EMULATOR_TARGET_ID))
Tobias Hunger's avatar
Tobias Hunger committed
346
        addRunConfiguration(new S60EmulatorRunConfiguration(this, proFilePath));
347
    else if (id() == QLatin1String(Constants::S60_DEVICE_TARGET_ID))
Tobias Hunger's avatar
Tobias Hunger committed
348
        addRunConfiguration(new S60DeviceRunConfiguration(this, proFilePath));
349
    else if (id() == QLatin1String(Constants::MAEMO_DEVICE_TARGET_ID))
Tobias Hunger's avatar
Tobias Hunger committed
350
351
352
        addRunConfiguration(new MaemoRunConfiguration(this, proFilePath));
}

353
QList<ProjectExplorer::ToolChainType> Qt4Target::filterToolChainTypes(const QList<ProjectExplorer::ToolChainType> &candidates) const
Tobias Hunger's avatar
Tobias Hunger committed
354
{
355
    QList<ProjectExplorer::ToolChainType> tmp(candidates);
356
    if (id() == QLatin1String(Constants::S60_EMULATOR_TARGET_ID)) {
357
358
        if (tmp.contains(ProjectExplorer::ToolChain_WINSCW))
            return QList<ProjectExplorer::ToolChainType>() << ProjectExplorer::ToolChain_WINSCW;
Tobias Hunger's avatar
Tobias Hunger committed
359
        else
360
            return QList<ProjectExplorer::ToolChainType>();
361
    } else if (id() == QLatin1String(Constants::S60_DEVICE_TARGET_ID)) {
362
        tmp.removeAll(ProjectExplorer::ToolChain_WINSCW);
Tobias Hunger's avatar
Tobias Hunger committed
363
364
365
366
367
        return tmp;
    }
    return tmp;
}

368
ProjectExplorer::ToolChainType Qt4Target::preferredToolChainType(const QList<ProjectExplorer::ToolChainType> &candidates) const
Tobias Hunger's avatar
Tobias Hunger committed
369
{
370
    ProjectExplorer::ToolChainType preferredType = ProjectExplorer::ToolChain_INVALID;
371
    if (id() == QLatin1String(Constants::S60_EMULATOR_TARGET_ID) &&
372
373
        candidates.contains(ProjectExplorer::ToolChain_WINSCW))
        preferredType = ProjectExplorer::ToolChain_WINSCW;
Tobias Hunger's avatar
Tobias Hunger committed
374
375
376
377
378
    if (!candidates.isEmpty())
        preferredType = candidates.at(0);
    return preferredType;
}

379
380
381
382
383
384
385
386
387
388
QString Qt4Target::defaultBuildDirectory() const
{
    if (id() == QLatin1String(Constants::S60_DEVICE_TARGET_ID)
        || id() == QLatin1String(Constants::S60_EMULATOR_TARGET_ID)
#if defined(Q_OS_WIN)
        || id() == QLatin1String(Constants::MAEMO_DEVICE_TARGET_ID)
#endif
        )
        return project()->projectDirectory();

389
390
391
392
393
    return defaultShadowBuildDirectory(qt4Project()->defaultTopLevelBuildDirectory(), id());
}

QString Qt4Target::defaultShadowBuildDirectory(const QString &projectLocation, const QString &id)
{
394
    QString shortName = QLatin1String("unknown");
395
    if (id == QLatin1String(Constants::DESKTOP_TARGET_ID))
396
        shortName = QLatin1String("desktop");
397
    else if (id == QLatin1String(Constants::S60_EMULATOR_TARGET_ID))
398
        shortName = QLatin1String("symbian_emulator");
399
    else if (id == QLatin1String(Constants::S60_DEVICE_TARGET_ID))
400
        shortName = QLatin1String("symbian");
401
    else if (id == QLatin1String(Constants::MAEMO_DEVICE_TARGET_ID))
402
        shortName = QLatin1String("maemo");
403
    else if (id == QLatin1String(Constants::QT_SIMULATOR_TARGET_ID))
404
        shortName = QLatin1String("simulator");
405

dt's avatar
dt committed
406
407
408
409
    // currently we can't have the build directory to be deeper then the source directory
    // since that is broken in qmake
    // Once qmake is fixed we can change that to have a top directory and
    // subdirectories per build. (Replacing "QChar('-')" with "QChar('/') )
410
    return projectLocation + QChar('-') + shortName;
411
412
}

Tobias Hunger's avatar
Tobias Hunger committed
413
414
bool Qt4Target::fromMap(const QVariantMap &map)
{
415
    bool success = Target::fromMap(map);
416
    setIcon(iconForId(id()));
417
    setDefaultDisplayName(displayNameForId(id()));
418
    return success;
Tobias Hunger's avatar
Tobias Hunger committed
419
420
421
422
423
424
425
}

void Qt4Target::updateQtVersion()
{
    setEnabled(project()->supportedTargetIds().contains(id()));
}

426
427
428
429
430
431
432
void Qt4Target::onAddedBuildConfiguration(ProjectExplorer::BuildConfiguration *bc)
{
    Q_ASSERT(bc);
    Qt4BuildConfiguration *qt4bc = qobject_cast<Qt4BuildConfiguration *>(bc);
    Q_ASSERT(qt4bc);
    connect(qt4bc, SIGNAL(buildDirectoryInitialized()),
            this, SIGNAL(buildDirectoryInitialized()));
dt's avatar
dt committed
433
434
    connect(qt4bc, SIGNAL(proFileEvaluateNeeded(Qt4ProjectManager::Internal::Qt4BuildConfiguration *)),
            this, SLOT(onProFileEvaluateNeeded(Qt4ProjectManager::Internal::Qt4BuildConfiguration *)));
435
436
}

437
438
439
440
441
442
443
444
445
446
void Qt4Target::onAddedDeployConfiguration(ProjectExplorer::DeployConfiguration *dc)
{
    Q_ASSERT(dc);
    S60DeployConfiguration *deployConf(qobject_cast<S60DeployConfiguration *>(dc));
    if (!deployConf)
        return;
    connect(deployConf, SIGNAL(serialPortNameChanged()),
            this, SLOT(slotUpdateDeviceInformation()));
}

con's avatar
con committed
447
void Qt4Target::slotUpdateDeviceInformation()
Tobias Hunger's avatar
Tobias Hunger committed
448
{
449
450
    S60DeployConfiguration *dc(qobject_cast<S60DeployConfiguration *>(sender()));
    if (dc && dc == activeDeployConfiguration()) {
con's avatar
con committed
451
452
        updateToolTipAndIcon();
    }
Tobias Hunger's avatar
Tobias Hunger committed
453
454
}

dt's avatar
dt committed
455
void Qt4Target::onProFileEvaluateNeeded(Qt4ProjectManager::Internal::Qt4BuildConfiguration *bc)
456
457
{
    if (bc && bc == activeBuildConfiguration())
dt's avatar
dt committed
458
459
460
461
462
463
        emit proFileEvaluateNeeded(this);
}

void Qt4Target::emitProFileEvaluateNeeded()
{
    emit proFileEvaluateNeeded(this);
464
465
}

con's avatar
con committed
466
void Qt4Target::updateToolTipAndIcon()
Tobias Hunger's avatar
Tobias Hunger committed
467
{
468
    static const int TARGET_OVERLAY_ORIGINAL_SIZE = 32;
469
    if (const S60DeployConfiguration *s60DeployConf = qobject_cast<S60DeployConfiguration *>(activeDeployConfiguration()))  {
470
        const SymbianUtils::SymbianDeviceManager *sdm = SymbianUtils::SymbianDeviceManager::instance();
471
        const int deviceIndex = sdm->findByPortName(s60DeployConf->serialPortName());
472
        QPixmap overlay;
473
        if (deviceIndex == -1) {
con's avatar
con committed
474
            setToolTip(tr("<b>Device:</b> Not connected"));
475
            overlay = m_disconnectedPixmap;
476
477
478
479
480
481
482
        } else {
            // device connected
            const SymbianUtils::SymbianDevice device = sdm->devices().at(deviceIndex);
            const QString tooltip = device.additionalInformation().isEmpty() ?
                                    tr("<b>Device:</b> %1").arg(device.friendlyName()) :
                                    tr("<b>Device:</b> %1, %2").arg(device.friendlyName(), device.additionalInformation());
            setToolTip(tooltip);
483
            overlay = m_connectedPixmap;
con's avatar
con committed
484
        }
485
486
487
488
489
490
491
492
493
494
495
496
497
        double factor = Core::Constants::TARGET_ICON_SIZE / (double)TARGET_OVERLAY_ORIGINAL_SIZE;
        QSize overlaySize(overlay.size().width()*factor, overlay.size().height()*factor);
        QPixmap pixmap(Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE);
        pixmap.fill(Qt::transparent);
        QPainter painter(&pixmap);
        painter.drawPixmap(Core::Constants::TARGET_ICON_SIZE - overlaySize.width(),
                           Core::Constants::TARGET_ICON_SIZE - overlaySize.height(),
                           overlay.scaled(overlaySize));

        setOverlayIcon(QIcon(pixmap));
    } else {
        setToolTip(QString());
        setOverlayIcon(QIcon());
con's avatar
con committed
498
    }
Tobias Hunger's avatar
Tobias Hunger committed
499
}