2010-07-13 17:00:12 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** No Commercial Usage
|
2010-07-13 17:00:12 +02:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** This file contains pre-release code and may not be distributed.
|
|
|
|
|
** You may use this file in accordance with the terms and conditions
|
|
|
|
|
** contained in the Technology Preview License Agreement accompanying
|
|
|
|
|
** this package.
|
2010-07-13 17:00:12 +02:00
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-07-13 17:00:12 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "maemoglobal.h"
|
|
|
|
|
|
2010-11-30 15:31:15 +01:00
|
|
|
#include "maemoconstants.h"
|
2010-11-30 10:55:44 +01:00
|
|
|
#include "maemodeviceconfigurations.h"
|
|
|
|
|
|
2011-01-10 12:13:27 +01:00
|
|
|
#include <coreplugin/filemanager.h>
|
2010-11-30 10:55:44 +01:00
|
|
|
#include <coreplugin/ssh/sshconnection.h>
|
2011-01-04 14:14:12 +01:00
|
|
|
#include <qt4projectmanager/qtversionmanager.h>
|
2010-11-26 17:53:13 +01:00
|
|
|
#include <utils/environment.h>
|
|
|
|
|
|
2010-11-26 12:19:32 +01:00
|
|
|
#include <QtCore/QCoreApplication>
|
2010-11-26 17:53:13 +01:00
|
|
|
#include <QtGui/QDesktopServices>
|
2010-11-26 12:19:32 +01:00
|
|
|
#include <QtCore/QDir>
|
2010-11-26 17:53:13 +01:00
|
|
|
#include <QtCore/QProcess>
|
2010-07-13 17:16:23 +02:00
|
|
|
#include <QtCore/QString>
|
|
|
|
|
|
2010-11-26 12:19:32 +01:00
|
|
|
#define TR(text) QCoreApplication::translate("Qt4ProjectManager::Internal::MaemoGlobal", text)
|
|
|
|
|
|
2010-07-13 17:00:12 +02:00
|
|
|
namespace Qt4ProjectManager {
|
|
|
|
|
namespace Internal {
|
2010-11-30 15:31:15 +01:00
|
|
|
namespace {
|
|
|
|
|
static const QLatin1String binQmake("/bin/qmake" EXEC_SUFFIX);
|
|
|
|
|
}
|
2010-07-13 17:00:12 +02:00
|
|
|
|
|
|
|
|
QString MaemoGlobal::homeDirOnDevice(const QString &uname)
|
|
|
|
|
{
|
|
|
|
|
return uname == QLatin1String("root")
|
|
|
|
|
? QString::fromLatin1("/root")
|
|
|
|
|
: QLatin1String("/home/") + uname;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MaemoGlobal::remoteSudo()
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String("/usr/lib/mad-developer/devrootsh");
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-15 16:43:56 +02:00
|
|
|
QString MaemoGlobal::remoteCommandPrefix(const QString &commandFilePath)
|
|
|
|
|
{
|
2010-09-13 16:50:30 +02:00
|
|
|
return QString::fromLocal8Bit("%1 chmod a+x %2; %3; ")
|
|
|
|
|
.arg(remoteSudo(), commandFilePath, remoteSourceProfilesCommand());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MaemoGlobal::remoteSourceProfilesCommand()
|
|
|
|
|
{
|
|
|
|
|
const QList<QByteArray> profiles = QList<QByteArray>() << "/etc/profile"
|
|
|
|
|
<< "/home/user/.profile" << "~/.profile";
|
|
|
|
|
QByteArray remoteCall(":");
|
|
|
|
|
foreach (const QByteArray &profile, profiles)
|
|
|
|
|
remoteCall += "; test -f " + profile + " && source " + profile;
|
|
|
|
|
return QString::fromAscii(remoteCall);
|
2010-07-15 16:43:56 +02:00
|
|
|
}
|
|
|
|
|
|
2010-09-23 10:35:23 +02:00
|
|
|
QString MaemoGlobal::remoteEnvironment(const QList<Utils::EnvironmentItem> &list)
|
2010-07-29 14:42:04 +02:00
|
|
|
{
|
|
|
|
|
QString env;
|
|
|
|
|
QString placeHolder = QLatin1String("%1=%2 ");
|
2010-09-23 10:35:23 +02:00
|
|
|
foreach (const Utils::EnvironmentItem &item, list)
|
2010-07-29 14:42:04 +02:00
|
|
|
env.append(placeHolder.arg(item.name).arg(item.value));
|
|
|
|
|
return env.mid(0, env.size() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-30 10:55:44 +01:00
|
|
|
QString MaemoGlobal::failedToConnectToServerMessage(const Core::SshConnection::Ptr &connection,
|
|
|
|
|
const MaemoDeviceConfig &deviceConfig)
|
|
|
|
|
{
|
|
|
|
|
QString errorMsg = TR("Could not connect to host: %1")
|
|
|
|
|
.arg(connection->errorString());
|
|
|
|
|
|
|
|
|
|
if (deviceConfig.type == MaemoDeviceConfig::Simulator) {
|
|
|
|
|
if (connection->errorState() == Core::SshTimeoutError
|
|
|
|
|
|| connection->errorState() == Core::SshSocketError) {
|
|
|
|
|
errorMsg += TR("\nDid you start Qemu?");
|
|
|
|
|
}
|
|
|
|
|
} else if (connection->errorState() == Core::SshTimeoutError) {
|
|
|
|
|
errorMsg += TR("\nIs the device connected and set up for network access?");
|
|
|
|
|
}
|
|
|
|
|
return errorMsg;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-04 14:14:12 +01:00
|
|
|
QString MaemoGlobal::maddeRoot(const QtVersion *qtVersion)
|
2010-11-30 15:31:15 +01:00
|
|
|
{
|
2011-01-04 14:14:12 +01:00
|
|
|
QDir dir(targetRoot(qtVersion));
|
2010-11-30 15:31:15 +01:00
|
|
|
dir.cdUp(); dir.cdUp();
|
|
|
|
|
return dir.absolutePath();
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-04 14:14:12 +01:00
|
|
|
QString MaemoGlobal::targetRoot(const QtVersion *qtVersion)
|
2010-11-30 15:31:15 +01:00
|
|
|
{
|
2011-01-04 14:14:12 +01:00
|
|
|
return QDir::cleanPath(qtVersion->qmakeCommand()).remove(binQmake);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MaemoGlobal::targetName(const QtVersion *qtVersion)
|
|
|
|
|
{
|
|
|
|
|
return QDir(targetRoot(qtVersion)).dirName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MaemoGlobal::madAdminCommand(const QtVersion *qtVersion)
|
|
|
|
|
{
|
|
|
|
|
return maddeRoot(qtVersion) + QLatin1String("/bin/mad-admin");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString MaemoGlobal::madCommand(const QtVersion *qtVersion)
|
|
|
|
|
{
|
|
|
|
|
return maddeRoot(qtVersion) + QLatin1String("/bin/mad");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaemoGlobal::MaemoVersion MaemoGlobal::version(const QtVersion *qtVersion)
|
|
|
|
|
{
|
|
|
|
|
const QString &name = targetName(qtVersion);
|
|
|
|
|
if (name.startsWith(QLatin1String("fremantle")))
|
|
|
|
|
return Maemo5;
|
|
|
|
|
if (name.startsWith(QLatin1String("harmattan")))
|
|
|
|
|
return Maemo6;
|
|
|
|
|
qWarning("Unknown Maemo version!");
|
|
|
|
|
return static_cast<MaemoVersion>(-1);
|
2010-11-30 15:31:15 +01:00
|
|
|
}
|
|
|
|
|
|
2010-11-26 12:19:32 +01:00
|
|
|
bool MaemoGlobal::removeRecursively(const QString &filePath, QString &error)
|
|
|
|
|
{
|
|
|
|
|
QFileInfo fileInfo(filePath);
|
2010-11-26 14:41:04 +01:00
|
|
|
if (!fileInfo.exists())
|
|
|
|
|
return true;
|
2010-12-16 13:06:15 +01:00
|
|
|
QFile::setPermissions(filePath, fileInfo.permissions() | QFile::WriteUser);
|
2010-11-26 12:19:32 +01:00
|
|
|
if (fileInfo.isDir()) {
|
|
|
|
|
QDir dir(filePath);
|
|
|
|
|
QStringList fileNames = dir.entryList(QDir::Files | QDir::Hidden
|
|
|
|
|
| QDir::System | QDir::Dirs | QDir::NoDotAndDotDot);
|
|
|
|
|
foreach (const QString &fileName, fileNames) {
|
|
|
|
|
if (!removeRecursively(filePath + QLatin1Char('/') + fileName, error))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
dir.cdUp();
|
|
|
|
|
if (!dir.rmdir(fileInfo.fileName())) {
|
|
|
|
|
error = TR("Failed to remove directory '%1'.")
|
|
|
|
|
.arg(QDir::toNativeSeparators(filePath));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!QFile::remove(filePath)) {
|
|
|
|
|
error = TR("Failed to remove file '%1'.")
|
|
|
|
|
.arg(QDir::toNativeSeparators(filePath));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-04 14:14:12 +01:00
|
|
|
bool MaemoGlobal::callMad(QProcess &proc, const QStringList &args,
|
|
|
|
|
const QtVersion *qtVersion)
|
|
|
|
|
{
|
|
|
|
|
return callMaddeShellScript(proc, maddeRoot(qtVersion),
|
|
|
|
|
madCommand(qtVersion), args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MaemoGlobal::callMadAdmin(QProcess &proc, const QStringList &args,
|
|
|
|
|
const QtVersion *qtVersion)
|
|
|
|
|
{
|
|
|
|
|
return callMaddeShellScript(proc, maddeRoot(qtVersion),
|
|
|
|
|
madAdminCommand(qtVersion), args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MaemoGlobal::callMaddeShellScript(QProcess &proc, const QString &maddeRoot,
|
2010-11-26 17:53:13 +01:00
|
|
|
const QString &command, const QStringList &args)
|
|
|
|
|
{
|
2011-01-04 14:14:12 +01:00
|
|
|
if (!QFileInfo(command).exists())
|
|
|
|
|
return false;
|
2010-11-26 17:53:13 +01:00
|
|
|
QString actualCommand = command;
|
|
|
|
|
QStringList actualArgs = args;
|
|
|
|
|
#ifdef Q_OS_WIN
|
2010-11-29 18:35:07 +01:00
|
|
|
Utils::Environment env(proc.systemEnvironment());
|
2010-11-26 17:53:13 +01:00
|
|
|
env.prependOrSetPath(maddeRoot + QLatin1String("/bin"));
|
|
|
|
|
env.prependOrSet(QLatin1String("HOME"),
|
|
|
|
|
QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
|
|
|
|
|
proc.setEnvironment(env.toStringList());
|
|
|
|
|
actualArgs.prepend(command);
|
|
|
|
|
actualCommand = maddeRoot + QLatin1String("/bin/sh.exe");
|
|
|
|
|
#else
|
|
|
|
|
Q_UNUSED(maddeRoot);
|
|
|
|
|
#endif
|
|
|
|
|
proc.start(actualCommand, actualArgs);
|
2011-01-04 14:14:12 +01:00
|
|
|
return true;
|
2010-11-26 17:53:13 +01:00
|
|
|
}
|
|
|
|
|
|
2011-01-10 12:13:27 +01:00
|
|
|
MaemoGlobal::FileUpdate::FileUpdate(const QString &fileName)
|
|
|
|
|
: m_fileName(fileName)
|
|
|
|
|
{
|
|
|
|
|
Core::FileManager::instance()->expectFileChange(fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MaemoGlobal::FileUpdate::~FileUpdate()
|
|
|
|
|
{
|
|
|
|
|
Core::FileManager::instance()->unexpectFileChange(m_fileName);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-13 17:00:12 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Qt4ProjectManager
|