maemorunconfiguration.cpp 7.85 KB
Newer Older
ck's avatar
ck 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).
ck's avatar
ck committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
**
** 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.
**
**************************************************************************/
29

ck's avatar
ck committed
30
31
#include "maemorunconfiguration.h"

32
#include "maemodeployables.h"
33
#include "maemodeploystep.h"
ck's avatar
ck committed
34
#include "maemoglobal.h"
35
#include "maemorunconfigurationwidget.h"
ck's avatar
ck committed
36
#include "maemotoolchain.h"
37
#include "qemuruntimemanager.h"
dt's avatar
dt committed
38
#include "qtoutputformatter.h"
ck's avatar
ck committed
39
40
41

#include <coreplugin/icore.h>
#include <coreplugin/messagemanager.h>
42
43

#include <projectexplorer/projectexplorer.h>
44
#include <projectexplorer/session.h>
45

46
#include <qt4projectmanager/qt4buildconfiguration.h>
47
#include <qt4projectmanager/qt4project.h>
48

ck's avatar
ck committed
49
50
#include <utils/qtcassert.h>

ck's avatar
ck committed
51
#include <QtCore/QStringBuilder>
ck's avatar
ck committed
52

53
namespace Qt4ProjectManager {
54
namespace Internal {
ck's avatar
ck committed
55

56
using namespace ProjectExplorer;
ck's avatar
ck committed
57

Tobias Hunger's avatar
Tobias Hunger committed
58
MaemoRunConfiguration::MaemoRunConfiguration(Qt4Target *parent,
ck's avatar
ck committed
59
        const QString &proFilePath)
Tobias Hunger's avatar
Tobias Hunger committed
60
    : RunConfiguration(parent, QLatin1String(MAEMO_RC_ID))
ck's avatar
ck committed
61
    , m_proFilePath(proFilePath)
62
{
ck's avatar
ck committed
63
    init();
64
65
}

Tobias Hunger's avatar
Tobias Hunger committed
66
MaemoRunConfiguration::MaemoRunConfiguration(Qt4Target *parent,
kh1's avatar
kh1 committed
67
        MaemoRunConfiguration *source)
Tobias Hunger's avatar
Tobias Hunger committed
68
    : RunConfiguration(parent, source)
69
70
71
72
73
    , m_proFilePath(source->m_proFilePath)
    , m_gdbPath(source->m_gdbPath)
    , m_devConfig(source->m_devConfig)
    , m_arguments(source->m_arguments)
{
ck's avatar
ck committed
74
    init();
75
76
}

ck's avatar
ck committed
77
void MaemoRunConfiguration::init()
ck's avatar
ck committed
78
{
79
    setDisplayName(QFileInfo(m_proFilePath).completeBaseName());
ck's avatar
ck committed
80

81
    updateDeviceConfigurations();
kh1's avatar
kh1 committed
82
83
    connect(&MaemoDeviceConfigurations::instance(), SIGNAL(updated()), this,
        SLOT(updateDeviceConfigurations()));
ck's avatar
ck committed
84

kh1's avatar
kh1 committed
85
86
87
    connect(qt4Target()->qt4Project(),
        SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*)),
        this, SLOT(proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFileNode*)));
ck's avatar
ck committed
88
89
90
91
92
93
}

MaemoRunConfiguration::~MaemoRunConfiguration()
{
}

Tobias Hunger's avatar
Tobias Hunger committed
94
Qt4Target *MaemoRunConfiguration::qt4Target() const
ck's avatar
ck committed
95
{
Tobias Hunger's avatar
Tobias Hunger committed
96
97
98
99
100
101
    return static_cast<Qt4Target *>(target());
}

Qt4BuildConfiguration *MaemoRunConfiguration::activeQt4BuildConfiguration() const
{
    return static_cast<Qt4BuildConfiguration *>(activeBuildConfiguration());
ck's avatar
ck committed
102
103
}

104
bool MaemoRunConfiguration::isEnabled(ProjectExplorer::BuildConfiguration *config) const
ck's avatar
ck committed
105
{
106
    Qt4BuildConfiguration *qt4bc = qobject_cast<Qt4BuildConfiguration*>(config);
107
108
    QTC_ASSERT(qt4bc, return false);
    ToolChain::ToolChainType type = qt4bc->toolChainType();
ck's avatar
ck committed
109
110
111
    return type == ToolChain::GCC_MAEMO;
}

112
QWidget *MaemoRunConfiguration::createConfigurationWidget()
ck's avatar
ck committed
113
114
115
116
{
    return new MaemoRunConfigurationWidget(this);
}

dt's avatar
dt committed
117
118
119
120
121
ProjectExplorer::OutputFormatter *MaemoRunConfiguration::createConfigurationWidget() const
{
    return new QtOutputFormatter(qt4Target()->qt4Project());
}

122
123
124
void MaemoRunConfiguration::proFileUpdate(Qt4ProjectManager::Internal::Qt4ProFileNode *pro)
{
    if (m_proFilePath == pro->path())
dt's avatar
dt committed
125
        emit targetInformationChanged();
126
127
}

128
QVariantMap MaemoRunConfiguration::toMap() const
ck's avatar
ck committed
129
{
130
131
132
    QVariantMap map(RunConfiguration::toMap());
    map.insert(DeviceIdKey, m_devConfig.internalId);
    map.insert(ArgumentsKey, m_arguments);
133
    const QDir dir = QDir(target()->project()->projectDirectory());
134
135
    map.insert(ProFileKey, dir.relativeFilePath(m_proFilePath));
    return map;
ck's avatar
ck committed
136
137
}

138
bool MaemoRunConfiguration::fromMap(const QVariantMap &map)
ck's avatar
ck committed
139
{
140
141
142
    if (!RunConfiguration::fromMap(map))
        return false;

ck's avatar
ck committed
143
    setDeviceConfig(MaemoDeviceConfigurations::instance().
144
145
        find(map.value(DeviceIdKey, 0).toInt()));
    m_arguments = map.value(ArgumentsKey).toStringList();
146
    const QDir dir = QDir(target()->project()->projectDirectory());
147
    m_proFilePath = dir.filePath(map.value(ProFileKey).toString());
148

149
    return true;
ck's avatar
ck committed
150
151
}

152
void MaemoRunConfiguration::setDeviceConfig(const MaemoDeviceConfig &devConf)
153
{
ck's avatar
ck committed
154
    m_devConfig = devConf;
155
    emit deviceConfigurationChanged(target());
156
157
}

158
MaemoDeviceConfig MaemoRunConfiguration::deviceConfig() const
159
{
ck's avatar
ck committed
160
    return m_devConfig;
ck's avatar
ck committed
161
162
163
164
}

const MaemoToolChain *MaemoRunConfiguration::toolchain() const
{
Tobias Hunger's avatar
Tobias Hunger committed
165
    Qt4BuildConfiguration *qt4bc(activeQt4BuildConfiguration());
166
    QTC_ASSERT(qt4bc, return 0);
kh1's avatar
kh1 committed
167
    MaemoToolChain *tc = dynamic_cast<MaemoToolChain *>(qt4bc->toolChain());
ck's avatar
ck committed
168
169
170
171
172
173
    QTC_ASSERT(tc != 0, return 0);
    return tc;
}

const QString MaemoRunConfiguration::gdbCmd() const
{
174
    if (const MaemoToolChain *tc = toolchain())
175
176
        return QDir::toNativeSeparators(tc->targetRoot() + QLatin1String("/bin/gdb"));
    return QString();
ck's avatar
ck committed
177
178
}

179
180
MaemoDeployStep *MaemoRunConfiguration::deployStep() const
{
ck's avatar
ck committed
181
182
    MaemoDeployStep * const step
        = MaemoGlobal::buildStep<MaemoDeployStep>(activeQt4BuildConfiguration());
183
184
    Q_ASSERT_X(step, Q_FUNC_INFO,
        "Impossible: Maemo build configuration without deploy step.");
ck's avatar
ck committed
185
    return step;
186
187
}

ck's avatar
ck committed
188
189
QString MaemoRunConfiguration::maddeRoot() const
{
190
    if (const MaemoToolChain *tc = toolchain())
kh1's avatar
kh1 committed
191
        return tc->maddeRoot();
192
    return QString();
ck's avatar
ck committed
193
194
195
196
}

const QString MaemoRunConfiguration::sysRoot() const
{
197
    if (const MaemoToolChain *tc = toolchain())
ck's avatar
ck committed
198
        return tc->sysrootRoot();
199
    return QString();
ck's avatar
ck committed
200
201
}

202
203
204
205
206
207
208
const QString MaemoRunConfiguration::targetRoot() const
{
    if (const MaemoToolChain *tc = toolchain())
        return tc->targetRoot();
    return QString();
}

209
210
const QStringList MaemoRunConfiguration::arguments() const
{
ck's avatar
ck committed
211
    return m_arguments;
212
213
}

ck's avatar
ck committed
214
215
const QString MaemoRunConfiguration::dumperLib() const
{
Tobias Hunger's avatar
Tobias Hunger committed
216
    Qt4BuildConfiguration *qt4bc(activeQt4BuildConfiguration());
217
    return qt4bc->qtVersion()->debuggingHelperLibrary();
ck's avatar
ck committed
218
219
}

220
QString MaemoRunConfiguration::localExecutableFilePath() const
ck's avatar
ck committed
221
{
222
223
    TargetInformation ti = qt4Target()->qt4Project()->rootProjectNode()
        ->targetInformation(m_proFilePath);
dt's avatar
dt committed
224
225
226
    if (!ti.valid)
        return QString();

227
    return QDir::cleanPath(ti.workingDir + QLatin1Char('/') + ti.target);
ck's avatar
ck committed
228
229
}

230
231
232
233
234
235
QString MaemoRunConfiguration::remoteExecutableFilePath() const
{
    return deployStep()->deployables()
        ->remoteExecutableFilePath(localExecutableFilePath());
}

236
QString MaemoRunConfiguration::runtimeGdbServerPort() const
ck's avatar
ck committed
237
{
238
239
240
241
242
243
244
    if (Qt4BuildConfiguration *qt4bc = activeQt4BuildConfiguration()) {
        Runtime rt;
        const int id = qt4bc->qtVersion()->uniqueId();
        if (QemuRuntimeManager::instance().runtimeForQtVersion(id, &rt))
            return rt.m_gdbServerPort;
    }
    return QLatin1String("13219");
ck's avatar
ck committed
245
246
247
248
}

void MaemoRunConfiguration::setArguments(const QStringList &args)
{
ck's avatar
ck committed
249
    m_arguments = args;
ck's avatar
ck committed
250
251
}

ck's avatar
ck committed
252
253
void MaemoRunConfiguration::updateDeviceConfigurations()
{
254
255
256
257
258
259
260
261
262
    const MaemoDeviceConfigurations &configManager
        = MaemoDeviceConfigurations::instance();
    if (!m_devConfig.isValid()) {
        const QList<MaemoDeviceConfig> &configList = configManager.devConfigs();
        if (!configList.isEmpty())
            m_devConfig = configList.first();
    } else {
        m_devConfig = configManager.find(m_devConfig.internalId);
    }
263
    emit deviceConfigurationsUpdated(target());
ck's avatar
ck committed
264
265
}

266
} // namespace Internal
267
} // namespace Qt4ProjectManager