1
/****************************************************************************
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of Qt Creator.
8
** Commercial License Usage
9
** Licensees holding valid commercial Qt licenses may use this file in
10
** accordance with the commercial license agreement provided with the
11
** Software or, alternatively, in accordance with the terms contained in
12
** a written agreement between you and Digia. For licensing terms and
13
** conditions see http://qt.digia.com/licensing. For further information
14
** use the contact form at http://qt.digia.com/contact-us.
16
** GNU Lesser General Public License Usage
17
** Alternatively, this file may be used under the terms of the GNU Lesser
18
** General Public License version 2.1 as published by the Free Software
19
** Foundation and appearing in the file LICENSE.LGPL included in the
20
** packaging of this file. Please review the following information to
21
** ensure the GNU Lesser General Public License version 2.1 requirements
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24
** In addition, as a special exception, Digia gives you certain additional
25
** rights. These rights are described in the Digia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28
****************************************************************************/
29
#include "maemoglobal.h"
31
#include "maemoconstants.h"
32
#include "maemoqemumanager.h"
34
#include <projectexplorer/devicesupport/idevice.h>
35
#include <projectexplorer/kitinformation.h>
36
#include <projectexplorer/target.h>
37
#include <qt4projectmanager/qt4projectmanagerconstants.h>
38
#include <qtsupport/baseqtversion.h>
39
#include <qtsupport/qtkitinformation.h>
40
#include <remotelinux/remotelinux_constants.h>
41
#include <utils/environment.h>
42
#include <utils/hostosinfo.h>
48
#include <QDesktopServices>
50
using namespace ProjectExplorer;
51
using namespace Qt4ProjectManager;
52
using namespace Qt4ProjectManager::Constants;
53
using namespace RemoteLinux;
54
using namespace Utils;
58
static const QString binQmake = QLatin1String("/bin/qmake" QTC_HOST_EXE_SUFFIX);
60
bool MaemoGlobal::hasMaemoDevice(const Kit *k)
62
IDevice::ConstPtr dev = DeviceKitInformation::device(k);
66
const Core::Id type = dev->type();
67
return type == Maemo5OsType || type == HarmattanOsType;
70
bool MaemoGlobal::supportsMaemoDevice(const Kit *k)
72
const Core::Id type = DeviceTypeKitInformation::deviceTypeId(k);
73
return type == Maemo5OsType || type == HarmattanOsType;
76
bool MaemoGlobal::isValidMaemo5QtVersion(const QString &qmakePath)
78
return isValidMaemoQtVersion(qmakePath, Core::Id(Maemo5OsType));
81
bool MaemoGlobal::isValidHarmattanQtVersion(const QString &qmakePath)
83
return isValidMaemoQtVersion(qmakePath, Core::Id(HarmattanOsType));
86
bool MaemoGlobal::isValidMaemoQtVersion(const QString &qmakePath, Core::Id deviceType)
88
if (MaemoGlobal::deviceType(qmakePath) != deviceType)
90
QProcess madAdminProc;
91
const QStringList arguments(QLatin1String("list"));
92
if (!callMadAdmin(madAdminProc, arguments, qmakePath, false))
94
if (!madAdminProc.waitForStarted() || !madAdminProc.waitForFinished())
97
madAdminProc.setReadChannel(QProcess::StandardOutput);
98
const QByteArray tgtName = targetName(qmakePath).toLatin1();
99
while (madAdminProc.canReadLine()) {
100
const QByteArray &line = madAdminProc.readLine();
101
if (line.contains(tgtName)
102
&& (line.contains("(installed)") || line.contains("(default)")))
109
QString MaemoGlobal::homeDirOnDevice(const QString &uname)
111
return uname == QLatin1String("root")
112
? QString::fromLatin1("/root")
113
: QLatin1String("/home/") + uname;
116
QString MaemoGlobal::devrootshPath()
118
return QLatin1String("/usr/lib/mad-developer/devrootsh");
121
int MaemoGlobal::applicationIconSize(const Target *target)
123
Core::Id deviceType = DeviceTypeKitInformation::deviceTypeId(target->kit());
124
return deviceType == HarmattanOsType ? 80 : 64;
127
QString MaemoGlobal::remoteSudo(Core::Id deviceType, const QString &uname)
129
if (uname == QLatin1String("root"))
131
if (deviceType == Maemo5OsType || deviceType == HarmattanOsType)
132
return devrootshPath();
133
return QString(); // Using sudo would open a can of worms.
136
QString MaemoGlobal::remoteSourceProfilesCommand()
138
const QList<QByteArray> profiles = QList<QByteArray>() << "/etc/profile"
139
<< "/home/user/.profile" << "~/.profile";
140
QByteArray remoteCall(":");
141
foreach (const QByteArray &profile, profiles)
142
remoteCall += "; test -f " + profile + " && source " + profile;
143
return QString::fromLatin1(remoteCall);
146
PortList MaemoGlobal::freePorts(const Kit *k)
148
IDevice::ConstPtr device = DeviceKitInformation::device(k);
149
QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitInformation::qtVersion(k);
151
if (!device || !qtVersion)
153
if (device->machineType() == IDevice::Emulator) {
155
const int id = qtVersion->uniqueId();
156
if (MaemoQemuManager::instance().runtimeForQtVersion(id, &rt))
157
return rt.m_freePorts;
159
return device->freePorts();
162
QString MaemoGlobal::maddeRoot(const QString &qmakePath)
164
QDir dir(targetRoot(qmakePath));
165
dir.cdUp(); dir.cdUp();
166
return dir.absolutePath();
169
FileName MaemoGlobal::maddeRoot(const Kit *k)
171
return SysRootKitInformation::sysRoot(k).parentDir().parentDir();
174
QString MaemoGlobal::targetRoot(const QString &qmakePath)
176
return QDir::cleanPath(qmakePath).remove(binQmake, HostOsInfo::fileNameCaseSensitivity());
179
QString MaemoGlobal::targetName(const QString &qmakePath)
181
return QDir(targetRoot(qmakePath)).dirName();
184
QString MaemoGlobal::madAdminCommand(const QString &qmakePath)
186
return maddeRoot(qmakePath) + QLatin1String("/bin/mad-admin");
189
QString MaemoGlobal::madCommand(const QString &qmakePath)
191
return maddeRoot(qmakePath) + QLatin1String("/bin/mad");
194
QString MaemoGlobal::madDeveloperUiName(Core::Id deviceType)
196
return deviceType == HarmattanOsType
197
? tr("SDK Connectivity") : tr("Mad Developer");
200
Core::Id MaemoGlobal::deviceType(const QString &qmakePath)
202
const QString &name = targetName(qmakePath);
203
if (name.startsWith(QLatin1String("fremantle")))
204
return Core::Id(Maemo5OsType);
205
if (name.startsWith(QLatin1String("harmattan")))
206
return Core::Id(HarmattanOsType);
207
return Core::Id(RemoteLinux::Constants::GenericLinuxOsType);
210
QString MaemoGlobal::architecture(const QString &qmakePath)
213
const QStringList args = QStringList() << QLatin1String("uname")
214
<< QLatin1String("-m");
215
if (!callMad(proc, args, qmakePath, true))
217
if (!proc.waitForFinished())
219
QString arch = QString::fromUtf8(proc.readAllStandardOutput());
220
arch.chop(1); // Newline
224
void MaemoGlobal::addMaddeEnvironment(Environment &env, const QString &qmakePath)
226
Environment maddeEnv;
227
if (HostOsInfo::isWindowsHost()) {
228
const QString root = maddeRoot(qmakePath);
229
env.prependOrSetPath(root + QLatin1String("/bin"));
230
env.prependOrSet(QLatin1String("HOME"),
231
QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
233
for (Environment::const_iterator it = maddeEnv.constBegin(); it != maddeEnv.constEnd(); ++it)
234
env.prependOrSet(it.key(), it.value());
237
void MaemoGlobal::transformMaddeCall(QString &command, QStringList &args, const QString &qmakePath)
239
if (HostOsInfo::isWindowsHost()) {
240
const QString root = maddeRoot(qmakePath);
241
args.prepend(command);
242
command = root + QLatin1String("/bin/sh.exe");
246
bool MaemoGlobal::callMad(QProcess &proc, const QStringList &args,
247
const QString &qmakePath, bool useTarget)
249
return callMaddeShellScript(proc, qmakePath, madCommand(qmakePath), args,
253
bool MaemoGlobal::callMadAdmin(QProcess &proc, const QStringList &args,
254
const QString &qmakePath, bool useTarget)
256
return callMaddeShellScript(proc, qmakePath, madAdminCommand(qmakePath),
260
bool MaemoGlobal::callMaddeShellScript(QProcess &proc,
261
const QString &qmakePath, const QString &command, const QStringList &args,
264
if (!QFileInfo(command).exists())
266
QString actualCommand = command;
267
QStringList actualArgs = targetArgs(qmakePath, useTarget) + args;
268
Environment env(proc.systemEnvironment());
269
addMaddeEnvironment(env, qmakePath);
270
proc.setEnvironment(env.toStringList());
271
transformMaddeCall(actualCommand, actualArgs, qmakePath);
272
proc.start(actualCommand, actualArgs);
276
QStringList MaemoGlobal::targetArgs(const QString &qmakePath, bool useTarget)
280
args << QLatin1String("-t") << targetName(qmakePath);
284
} // namespace Internal