2010-05-20 15:47:42 +02:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-05-20 15:47:42 +02:00
|
|
|
**
|
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** No Commercial Usage
|
2010-05-20 15:47:42 +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-05-20 15:47:42 +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-05-20 15:47:42 +02:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
#include "maemoqemumanager.h"
|
2010-05-20 15:47:42 +02:00
|
|
|
|
2010-11-26 17:53:13 +01:00
|
|
|
#include "maemoglobal.h"
|
2010-12-03 18:02:41 +01:00
|
|
|
#include "maemomanager.h"
|
2010-11-30 15:31:15 +01:00
|
|
|
#include "maemoqemuruntimeparser.h"
|
2010-12-03 18:02:41 +01:00
|
|
|
#include "maemosettingspages.h"
|
2010-05-20 15:47:42 +02:00
|
|
|
#include "maemorunconfiguration.h"
|
|
|
|
|
#include "qtversionmanager.h"
|
|
|
|
|
#include "qt4project.h"
|
|
|
|
|
#include "qt4projectmanagerconstants.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2010-11-02 16:53:56 +01:00
|
|
|
#include <coreplugin/uniqueidmanager.h>
|
2010-05-20 15:47:42 +02:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
2010-06-25 12:56:16 +02:00
|
|
|
#include <coreplugin/icontext.h>
|
2010-05-20 15:47:42 +02:00
|
|
|
#include <coreplugin/modemanager.h>
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
|
2010-09-07 17:43:27 +02:00
|
|
|
#include <QtCore/QDebug>
|
2010-05-20 15:47:42 +02:00
|
|
|
#include <QtCore/QDir>
|
|
|
|
|
#include <QtCore/QList>
|
|
|
|
|
#include <QtCore/QSet>
|
2010-05-21 09:12:35 +02:00
|
|
|
#include <QtCore/QStringBuilder>
|
2010-05-20 15:47:42 +02:00
|
|
|
|
2010-05-27 13:28:07 +02:00
|
|
|
#include <QtGui/QAction>
|
2010-09-07 17:43:27 +02:00
|
|
|
#include <QtGui/QDesktopServices>
|
|
|
|
|
#include <QtGui/QMessageBox>
|
|
|
|
|
|
2010-10-11 14:35:45 +02:00
|
|
|
#include <limits.h>
|
|
|
|
|
|
2010-05-20 15:47:42 +02:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
using namespace Qt4ProjectManager;
|
|
|
|
|
using namespace Qt4ProjectManager::Internal;
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
MaemoQemuManager *MaemoQemuManager::m_instance = 0;
|
2010-05-20 15:47:42 +02:00
|
|
|
|
|
|
|
|
const QSize iconSize = QSize(24, 20);
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
MaemoQemuManager::MaemoQemuManager(QObject *parent)
|
2010-05-20 15:47:42 +02:00
|
|
|
: QObject(parent)
|
|
|
|
|
, m_qemuAction(0)
|
|
|
|
|
, m_qemuProcess(new QProcess(this))
|
2010-10-11 14:35:45 +02:00
|
|
|
, m_runningQtId(INT_MIN)
|
2010-05-20 15:47:42 +02:00
|
|
|
, m_userTerminated(false)
|
|
|
|
|
{
|
|
|
|
|
m_qemuStarterIcon.addFile(":/qt-maemo/images/qemu-run.png", iconSize);
|
|
|
|
|
m_qemuStarterIcon.addFile(":/qt-maemo/images/qemu-stop.png", iconSize,
|
|
|
|
|
QIcon::Normal, QIcon::On);
|
|
|
|
|
|
|
|
|
|
m_qemuAction = new QAction("Maemo Emulator", this);
|
|
|
|
|
m_qemuAction->setEnabled(false);
|
|
|
|
|
m_qemuAction->setVisible(false);
|
|
|
|
|
m_qemuAction->setIcon(m_qemuStarterIcon.pixmap(iconSize));
|
|
|
|
|
m_qemuAction->setToolTip(tr("Start Maemo Emulator"));
|
|
|
|
|
connect(m_qemuAction, SIGNAL(triggered()), this, SLOT(startRuntime()));
|
|
|
|
|
|
|
|
|
|
Core::ICore *core = Core::ICore::instance();
|
|
|
|
|
Core::ActionManager *actionManager = core->actionManager();
|
|
|
|
|
Core::Command *qemuCommand = actionManager->registerAction(m_qemuAction,
|
2010-06-28 14:30:03 +02:00
|
|
|
"MaemoEmulator", Core::Context(Core::Constants::C_GLOBAL));
|
2010-05-20 15:47:42 +02:00
|
|
|
qemuCommand->setAttribute(Core::Command::CA_UpdateText);
|
|
|
|
|
qemuCommand->setAttribute(Core::Command::CA_UpdateIcon);
|
|
|
|
|
|
|
|
|
|
Core::ModeManager *modeManager = core->modeManager();
|
2011-01-12 14:21:12 +01:00
|
|
|
modeManager->addAction(qemuCommand->action(), 1);
|
2010-05-20 15:47:42 +02:00
|
|
|
|
|
|
|
|
// listen to qt version changes to update the start button
|
|
|
|
|
connect(QtVersionManager::instance(), SIGNAL(qtVersionsChanged(QList<int>)),
|
|
|
|
|
this, SLOT(qtVersionsChanged(QList<int>)));
|
|
|
|
|
|
|
|
|
|
// listen to project add, remove and startup changes to udate start button
|
|
|
|
|
SessionManager *session = ProjectExplorerPlugin::instance()->session();
|
|
|
|
|
connect(session, SIGNAL(projectAdded(ProjectExplorer::Project*)), this,
|
|
|
|
|
SLOT(projectAdded(ProjectExplorer::Project*)));
|
|
|
|
|
connect(session, SIGNAL(projectRemoved(ProjectExplorer::Project*)), this,
|
|
|
|
|
SLOT(projectRemoved(ProjectExplorer::Project*)));
|
|
|
|
|
connect(session, SIGNAL(startupProjectChanged(ProjectExplorer::Project*)),
|
|
|
|
|
this, SLOT(projectChanged(ProjectExplorer::Project*)));
|
|
|
|
|
|
|
|
|
|
connect(m_qemuProcess, SIGNAL(error(QProcess::ProcessError)), this,
|
|
|
|
|
SLOT(qemuProcessError(QProcess::ProcessError)));
|
|
|
|
|
connect(m_qemuProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this,
|
|
|
|
|
SLOT(qemuProcessFinished()));
|
2010-07-22 12:10:44 +02:00
|
|
|
connect(m_qemuProcess, SIGNAL(readyReadStandardOutput()), this,
|
|
|
|
|
SLOT(qemuOutput()));
|
|
|
|
|
connect(m_qemuProcess, SIGNAL(readyReadStandardError()), this,
|
|
|
|
|
SLOT(qemuOutput()));
|
2010-05-20 15:47:42 +02:00
|
|
|
connect(this, SIGNAL(qemuProcessStatus(QemuStatus, QString)),
|
|
|
|
|
this, SLOT(qemuStatusChanged(QemuStatus, QString)));
|
2010-08-18 16:33:11 +02:00
|
|
|
|
|
|
|
|
m_runtimeRootWatcher = new QFileSystemWatcher(this);
|
|
|
|
|
connect(m_runtimeRootWatcher, SIGNAL(directoryChanged(QString)), this,
|
|
|
|
|
SLOT(runtimeRootChanged(QString)));
|
|
|
|
|
m_runtimeFolderWatcher = new QFileSystemWatcher(this);
|
|
|
|
|
connect(m_runtimeFolderWatcher, SIGNAL(directoryChanged(QString)), this,
|
|
|
|
|
SLOT(runtimeFolderChanged(QString)));
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
MaemoQemuManager::~MaemoQemuManager()
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
terminateRuntime();
|
2010-05-25 13:43:16 +02:00
|
|
|
m_instance = 0;
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
MaemoQemuManager &MaemoQemuManager::instance(QObject *parent)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
2010-05-25 13:43:16 +02:00
|
|
|
if (m_instance == 0)
|
2010-07-28 09:36:30 +02:00
|
|
|
m_instance = new MaemoQemuManager(parent);
|
2010-05-20 15:47:42 +02:00
|
|
|
return *m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-30 14:14:55 +01:00
|
|
|
bool MaemoQemuManager::runtimeForQtVersion(int uniqueId, MaemoQemuRuntime *rt) const
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
2010-11-30 14:14:55 +01:00
|
|
|
*rt = m_runtimes.value(uniqueId, MaemoQemuRuntime());
|
2010-08-18 16:33:11 +02:00
|
|
|
return rt->isValid();
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::qtVersionsChanged(const QList<int> &uniqueIds)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
QtVersionManager *manager = QtVersionManager::instance();
|
|
|
|
|
foreach (int uniqueId, uniqueIds) {
|
|
|
|
|
if (manager->isValidId(uniqueId)) {
|
2010-08-18 16:33:11 +02:00
|
|
|
QtVersion *version = manager->version(uniqueId);
|
|
|
|
|
if (version->supportsTargetId(Constants::MAEMO_DEVICE_TARGET_ID)) {
|
2010-11-30 15:31:15 +01:00
|
|
|
MaemoQemuRuntime runtime
|
|
|
|
|
= MaemoQemuRuntimeParser::parseRuntime(version);
|
2010-11-30 13:45:15 +01:00
|
|
|
if (runtime.isValid()) {
|
2010-08-18 16:33:11 +02:00
|
|
|
m_runtimes.insert(uniqueId, runtime);
|
|
|
|
|
if (!m_runtimeRootWatcher->directories().contains(runtime.m_watchPath))
|
|
|
|
|
m_runtimeRootWatcher->addPath(runtime.m_watchPath);
|
|
|
|
|
} else {
|
|
|
|
|
m_runtimes.remove(uniqueId);
|
|
|
|
|
}
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// this qt version has been removed from the settings
|
|
|
|
|
m_runtimes.remove(uniqueId);
|
|
|
|
|
if (uniqueId == m_runningQtId) {
|
|
|
|
|
terminateRuntime();
|
|
|
|
|
emit qemuProcessStatus(QemuUserReason, tr("Qemu has been shut "
|
|
|
|
|
"down, because you removed the corresponding Qt version."));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// make visible only if we have a runtime and a maemo target
|
|
|
|
|
m_qemuAction->setVisible(!m_runtimes.isEmpty() && sessionHasMaemoTarget());
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::projectAdded(ProjectExplorer::Project *project)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
// handle all target related changes, add, remove, etc...
|
|
|
|
|
connect(project, SIGNAL(addedTarget(ProjectExplorer::Target*)), this,
|
|
|
|
|
SLOT(targetAdded(ProjectExplorer::Target*)));
|
|
|
|
|
connect(project, SIGNAL(removedTarget(ProjectExplorer::Target*)), this,
|
|
|
|
|
SLOT(targetRemoved(ProjectExplorer::Target*)));
|
|
|
|
|
connect(project, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
|
|
|
|
|
this, SLOT(targetChanged(ProjectExplorer::Target*)));
|
|
|
|
|
|
|
|
|
|
foreach (Target *target, project->targets())
|
|
|
|
|
targetAdded(target);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::projectRemoved(ProjectExplorer::Project *project)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
disconnect(project, SIGNAL(addedTarget(ProjectExplorer::Target*)), this,
|
|
|
|
|
SLOT(targetAdded(ProjectExplorer::Target*)));
|
|
|
|
|
disconnect(project, SIGNAL(removedTarget(ProjectExplorer::Target*)), this,
|
|
|
|
|
SLOT(targetRemoved(ProjectExplorer::Target*)));
|
|
|
|
|
disconnect(project, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)),
|
|
|
|
|
this, SLOT(targetChanged(ProjectExplorer::Target*)));
|
|
|
|
|
|
|
|
|
|
foreach (Target *target, project->targets())
|
|
|
|
|
targetRemoved(target);
|
|
|
|
|
m_qemuAction->setVisible(!m_runtimes.isEmpty() && sessionHasMaemoTarget());
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::projectChanged(ProjectExplorer::Project *project)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
2010-07-16 17:09:05 +02:00
|
|
|
if (project) {
|
2010-06-21 13:25:34 +02:00
|
|
|
toggleStarterButton(project->activeTarget());
|
2010-07-16 17:09:05 +02:00
|
|
|
deviceConfigurationChanged(project->activeTarget());
|
|
|
|
|
}
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool targetIsMaemo(const QString &id)
|
|
|
|
|
{
|
2010-11-26 17:53:13 +01:00
|
|
|
return id == QLatin1String(Qt4ProjectManager::Constants::MAEMO_DEVICE_TARGET_ID);
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::targetAdded(ProjectExplorer::Target *target)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
if (!target || !targetIsMaemo(target->id()))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// handle all run configuration changes, add, remove, etc...
|
|
|
|
|
connect(target, SIGNAL(addedRunConfiguration(ProjectExplorer::RunConfiguration*)),
|
|
|
|
|
this, SLOT(runConfigurationAdded(ProjectExplorer::RunConfiguration*)));
|
|
|
|
|
connect(target, SIGNAL(removedRunConfiguration(ProjectExplorer::RunConfiguration*)),
|
|
|
|
|
this, SLOT(runConfigurationRemoved(ProjectExplorer::RunConfiguration*)));
|
|
|
|
|
connect(target, SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
|
|
|
|
|
this, SLOT(runConfigurationChanged(ProjectExplorer::RunConfiguration*)));
|
|
|
|
|
|
|
|
|
|
// handle all build configuration changes, add, remove, etc...
|
|
|
|
|
connect(target, SIGNAL(removedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
|
|
|
|
|
this, SLOT(buildConfigurationAdded(ProjectExplorer::BuildConfiguration*)));
|
|
|
|
|
connect(target, SIGNAL(removedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
|
|
|
|
|
this, SLOT(buildConfigurationRemoved(ProjectExplorer::BuildConfiguration*)));
|
|
|
|
|
connect(target, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
|
|
|
|
|
this, SLOT(buildConfigurationChanged(ProjectExplorer::BuildConfiguration*)));
|
|
|
|
|
|
|
|
|
|
// handle the qt version changes the build configuration uses
|
|
|
|
|
connect(target, SIGNAL(environmentChanged()), this, SLOT(environmentChanged()));
|
|
|
|
|
|
2010-06-21 13:25:34 +02:00
|
|
|
foreach (RunConfiguration *rc, target->runConfigurations())
|
|
|
|
|
toggleDeviceConnections(qobject_cast<MaemoRunConfiguration*> (rc), true);
|
2010-10-06 12:33:02 +02:00
|
|
|
toggleStarterButton(target);
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::targetRemoved(ProjectExplorer::Target *target)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
if (!target || !targetIsMaemo(target->id()))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
disconnect(target, SIGNAL(addedRunConfiguration(ProjectExplorer::RunConfiguration*)),
|
|
|
|
|
this, SLOT(runConfigurationAdded(ProjectExplorer::RunConfiguration*)));
|
|
|
|
|
disconnect(target, SIGNAL(removedRunConfiguration(ProjectExplorer::RunConfiguration*)),
|
|
|
|
|
this, SLOT(runConfigurationRemoved(ProjectExplorer::RunConfiguration*)));
|
|
|
|
|
disconnect(target, SIGNAL(activeRunConfigurationChanged(ProjectExplorer::RunConfiguration*)),
|
|
|
|
|
this, SLOT(runConfigurationChanged(ProjectExplorer::RunConfiguration*)));
|
|
|
|
|
|
|
|
|
|
disconnect(target, SIGNAL(removedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
|
|
|
|
|
this, SLOT(buildConfigurationAdded(ProjectExplorer::BuildConfiguration*)));
|
|
|
|
|
disconnect(target, SIGNAL(removedBuildConfiguration(ProjectExplorer::BuildConfiguration*)),
|
|
|
|
|
this, SLOT(buildConfigurationRemoved(ProjectExplorer::BuildConfiguration*)));
|
|
|
|
|
disconnect(target, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)),
|
|
|
|
|
this, SLOT(buildConfigurationChanged(ProjectExplorer::BuildConfiguration*)));
|
|
|
|
|
|
|
|
|
|
disconnect(target, SIGNAL(environmentChanged()), this, SLOT(environmentChanged()));
|
|
|
|
|
|
2010-06-21 13:25:34 +02:00
|
|
|
foreach (RunConfiguration *rc, target->runConfigurations())
|
|
|
|
|
toggleDeviceConnections(qobject_cast<MaemoRunConfiguration*> (rc), false);
|
2010-05-20 15:47:42 +02:00
|
|
|
m_qemuAction->setVisible(!m_runtimes.isEmpty() && sessionHasMaemoTarget());
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::targetChanged(ProjectExplorer::Target *target)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
2010-07-16 17:09:05 +02:00
|
|
|
if (target) {
|
2010-06-21 13:25:34 +02:00
|
|
|
toggleStarterButton(target);
|
2010-07-16 17:09:05 +02:00
|
|
|
deviceConfigurationChanged(target);
|
|
|
|
|
}
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::runConfigurationAdded(ProjectExplorer::RunConfiguration *rc)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
if (!rc || !targetIsMaemo(rc->target()->id()))
|
|
|
|
|
return;
|
2010-06-21 13:25:34 +02:00
|
|
|
toggleDeviceConnections(qobject_cast<MaemoRunConfiguration*> (rc), true);
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::runConfigurationRemoved(ProjectExplorer::RunConfiguration *rc)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
if (!rc || rc->target()->id() != QLatin1String(Constants::MAEMO_DEVICE_TARGET_ID))
|
|
|
|
|
return;
|
2010-06-21 13:25:34 +02:00
|
|
|
toggleDeviceConnections(qobject_cast<MaemoRunConfiguration*> (rc), false);
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::runConfigurationChanged(ProjectExplorer::RunConfiguration *rc)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
if (rc)
|
2010-07-22 12:10:44 +02:00
|
|
|
m_qemuAction->setEnabled(targetUsesMatchingRuntimeConfig(rc->target()));
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::buildConfigurationAdded(ProjectExplorer::BuildConfiguration *bc)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
if (!bc || !targetIsMaemo(bc->target()->id()))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
connect(bc, SIGNAL(environmentChanged()), this, SLOT(environmentChanged()));
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::buildConfigurationRemoved(ProjectExplorer::BuildConfiguration *bc)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
if (!bc || !targetIsMaemo(bc->target()->id()))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
disconnect(bc, SIGNAL(environmentChanged()), this, SLOT(environmentChanged()));
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::buildConfigurationChanged(ProjectExplorer::BuildConfiguration *bc)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
if (bc)
|
2010-06-21 13:25:34 +02:00
|
|
|
toggleStarterButton(bc->target());
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::environmentChanged()
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
// likely to happen when the qt version changes the build config is using
|
|
|
|
|
if (ProjectExplorerPlugin *explorer = ProjectExplorerPlugin::instance()) {
|
|
|
|
|
if (Project *project = explorer->session()->startupProject())
|
2010-06-21 13:25:34 +02:00
|
|
|
toggleStarterButton(project->activeTarget());
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::deviceConfigurationChanged(ProjectExplorer::Target *target)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
2010-07-22 12:10:44 +02:00
|
|
|
m_qemuAction->setEnabled(targetUsesMatchingRuntimeConfig(target));
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::startRuntime()
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
m_userTerminated = false;
|
|
|
|
|
Project *p = ProjectExplorerPlugin::instance()->session()->startupProject();
|
|
|
|
|
if (!p)
|
|
|
|
|
return;
|
2010-07-22 12:10:44 +02:00
|
|
|
QtVersion *version;
|
|
|
|
|
if (!targetUsesMatchingRuntimeConfig(p->activeTarget(), &version)) {
|
|
|
|
|
qWarning("Strange: Qemu button was enabled, but target does not match.");
|
2010-05-20 15:47:42 +02:00
|
|
|
return;
|
2010-07-22 12:10:44 +02:00
|
|
|
}
|
2010-05-20 15:47:42 +02:00
|
|
|
|
2010-07-22 12:10:44 +02:00
|
|
|
m_runningQtId = version->uniqueId();
|
2010-11-30 14:14:55 +01:00
|
|
|
const MaemoQemuRuntime rt = m_runtimes.value(version->uniqueId());
|
2010-12-03 09:15:36 +01:00
|
|
|
m_qemuProcess->setProcessEnvironment(rt.environment());
|
2010-07-22 12:10:44 +02:00
|
|
|
m_qemuProcess->setWorkingDirectory(rt.m_root);
|
2010-11-30 16:42:30 +01:00
|
|
|
m_qemuProcess->start(rt.m_bin % QLatin1Char(' ') % rt.m_args);
|
2010-07-22 12:10:44 +02:00
|
|
|
if (!m_qemuProcess->waitForStarted())
|
|
|
|
|
return;
|
2010-06-17 15:57:08 +02:00
|
|
|
|
2010-07-22 12:10:44 +02:00
|
|
|
emit qemuProcessStatus(QemuStarting);
|
|
|
|
|
connect(m_qemuAction, SIGNAL(triggered()), this, SLOT(terminateRuntime()));
|
|
|
|
|
disconnect(m_qemuAction, SIGNAL(triggered()), this, SLOT(startRuntime()));
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::terminateRuntime()
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
m_userTerminated = true;
|
|
|
|
|
|
|
|
|
|
if (m_qemuProcess->state() != QProcess::NotRunning) {
|
|
|
|
|
m_qemuProcess->terminate();
|
|
|
|
|
m_qemuProcess->kill();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connect(m_qemuAction, SIGNAL(triggered()), this, SLOT(startRuntime()));
|
|
|
|
|
disconnect(m_qemuAction, SIGNAL(triggered()), this, SLOT(terminateRuntime()));
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::qemuProcessFinished()
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
2010-10-11 14:35:45 +02:00
|
|
|
m_runningQtId = INT_MIN;
|
2010-05-20 15:47:42 +02:00
|
|
|
QemuStatus status = QemuFinished;
|
2010-07-22 12:10:44 +02:00
|
|
|
QString error;
|
2010-05-20 15:47:42 +02:00
|
|
|
|
|
|
|
|
if (!m_userTerminated) {
|
2010-07-22 12:10:44 +02:00
|
|
|
if (m_qemuProcess->exitStatus() == QProcess::CrashExit) {
|
|
|
|
|
status = QemuCrashed;
|
|
|
|
|
error = m_qemuProcess->errorString();
|
|
|
|
|
} else if (m_qemuProcess->exitCode() != 0) {
|
|
|
|
|
error = tr("Qemu finished with error: Exit code was %1.")
|
|
|
|
|
.arg(m_qemuProcess->exitCode());
|
|
|
|
|
}
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_userTerminated = false;
|
2010-07-22 12:10:44 +02:00
|
|
|
emit qemuProcessStatus(status, error);
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::qemuProcessError(QProcess::ProcessError error)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
if (error == QProcess::FailedToStart)
|
|
|
|
|
emit qemuProcessStatus(QemuFailedToStart, m_qemuProcess->errorString());
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::qemuStatusChanged(QemuStatus status, const QString &error)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
bool running = false;
|
|
|
|
|
switch (status) {
|
|
|
|
|
case QemuStarting:
|
|
|
|
|
running = true;
|
|
|
|
|
break;
|
|
|
|
|
case QemuFailedToStart:
|
2010-12-03 18:02:41 +01:00
|
|
|
QMessageBox::warning(0, tr("Qemu error"),
|
|
|
|
|
tr("Qemu failed to start: %1"));
|
2010-05-20 15:47:42 +02:00
|
|
|
break;
|
2010-12-03 18:02:41 +01:00
|
|
|
case QemuCrashed:
|
|
|
|
|
MaemoManager::instance().qemuSettingsPage()->showQemuCrashDialog();
|
2010-05-20 15:47:42 +02:00
|
|
|
break;
|
|
|
|
|
case QemuFinished:
|
|
|
|
|
case QemuUserReason:
|
2010-12-03 18:02:41 +01:00
|
|
|
if (!error.isEmpty())
|
|
|
|
|
QMessageBox::warning(0, tr("Qemu error"), error);
|
2010-05-20 15:47:42 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Q_ASSERT(!"Missing handling of Qemu status");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateStarterIcon(running);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::qemuOutput()
|
2010-07-22 12:10:44 +02:00
|
|
|
{
|
|
|
|
|
qDebug("%s", m_qemuProcess->readAllStandardOutput().data());
|
|
|
|
|
qDebug("%s", m_qemuProcess->readAllStandardError().data());
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-18 16:33:11 +02:00
|
|
|
void MaemoQemuManager::runtimeRootChanged(const QString &directory)
|
|
|
|
|
{
|
|
|
|
|
QList<int> uniqueIds;
|
2010-11-30 14:14:55 +01:00
|
|
|
QMap<int, MaemoQemuRuntime>::const_iterator it;
|
2010-08-18 16:33:11 +02:00
|
|
|
for (it = m_runtimes.constBegin(); it != m_runtimes.constEnd(); ++it) {
|
|
|
|
|
if (QDir(it.value().m_watchPath) == QDir(directory))
|
|
|
|
|
uniqueIds.append(it.key());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (int uniqueId, uniqueIds) {
|
2010-11-30 14:14:55 +01:00
|
|
|
MaemoQemuRuntime runtime = m_runtimes.value(uniqueId, MaemoQemuRuntime());
|
2010-08-18 16:33:11 +02:00
|
|
|
if (runtime.isValid()) {
|
|
|
|
|
if (QFile::exists(runtime.m_root)) {
|
|
|
|
|
// nothing changed, so we can remove it
|
|
|
|
|
uniqueIds.removeAll(uniqueId);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (QFile::exists(runtime.m_root)) {
|
|
|
|
|
if (!QFile::exists(runtime.m_root + QLatin1String("/information"))) {
|
|
|
|
|
// install might be still in progress
|
|
|
|
|
uniqueIds.removeAll(uniqueId);
|
|
|
|
|
m_runtimeFolderWatcher->addPath(runtime.m_root);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
notify(uniqueIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaemoQemuManager::runtimeFolderChanged(const QString &directory)
|
|
|
|
|
{
|
|
|
|
|
if (QFile::exists(directory + QLatin1String("/information"))) {
|
|
|
|
|
QList<int> uniqueIds;
|
2010-11-30 14:14:55 +01:00
|
|
|
QMap<int, MaemoQemuRuntime>::const_iterator it;
|
2010-08-18 16:33:11 +02:00
|
|
|
for (it = m_runtimes.constBegin(); it != m_runtimes.constEnd(); ++it) {
|
|
|
|
|
if (QDir(it.value().m_root) == QDir(directory))
|
|
|
|
|
uniqueIds.append(it.key());
|
|
|
|
|
}
|
|
|
|
|
notify(uniqueIds);
|
|
|
|
|
m_runtimeFolderWatcher->removePath(directory);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-20 15:47:42 +02:00
|
|
|
// -- private
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::updateStarterIcon(bool running)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
QIcon::State state;
|
|
|
|
|
QString toolTip;
|
|
|
|
|
if (running) {
|
|
|
|
|
state = QIcon::On;
|
|
|
|
|
toolTip = tr("Stop Maemo Emulator");
|
|
|
|
|
} else {
|
|
|
|
|
state = QIcon::Off;
|
|
|
|
|
toolTip = tr("Start Maemo Emulator");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_qemuAction->setToolTip(toolTip);
|
|
|
|
|
m_qemuAction->setIcon(m_qemuStarterIcon.pixmap(iconSize, QIcon::Normal,
|
|
|
|
|
state));
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::toggleStarterButton(Target *target)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
int uniqueId = -1;
|
|
|
|
|
if (target) {
|
|
|
|
|
if (Qt4Target *qt4Target = qobject_cast<Qt4Target*>(target)) {
|
|
|
|
|
if (Qt4BuildConfiguration *bc = qt4Target->activeBuildConfiguration()) {
|
|
|
|
|
if (QtVersion *version = bc->qtVersion())
|
|
|
|
|
uniqueId = version->uniqueId();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-11 14:35:45 +02:00
|
|
|
if (uniqueId >= 0 && (m_runtimes.isEmpty() || !m_runtimes.contains(uniqueId)))
|
2010-10-06 12:33:02 +02:00
|
|
|
qtVersionsChanged(QList<int>() << uniqueId);
|
|
|
|
|
|
2010-05-20 15:47:42 +02:00
|
|
|
bool isRunning = m_qemuProcess->state() != QProcess::NotRunning;
|
|
|
|
|
if (m_runningQtId == uniqueId)
|
|
|
|
|
isRunning = false;
|
|
|
|
|
|
2010-11-30 14:14:55 +01:00
|
|
|
m_qemuAction->setEnabled(m_runtimes.value(uniqueId, MaemoQemuRuntime()).isValid()
|
2010-07-22 12:10:44 +02:00
|
|
|
&& targetUsesMatchingRuntimeConfig(target) && !isRunning);
|
2010-10-06 12:33:02 +02:00
|
|
|
m_qemuAction->setVisible(!m_runtimes.isEmpty() && sessionHasMaemoTarget());
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
bool MaemoQemuManager::sessionHasMaemoTarget() const
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
bool result = false;
|
|
|
|
|
ProjectExplorerPlugin *explorer = ProjectExplorerPlugin::instance();
|
|
|
|
|
const QList<Project*> &projects = explorer->session()->projects();
|
|
|
|
|
foreach (const Project *p, projects)
|
|
|
|
|
result |= p->target(QLatin1String(Constants::MAEMO_DEVICE_TARGET_ID)) != 0;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
bool MaemoQemuManager::targetUsesMatchingRuntimeConfig(Target *target,
|
2010-07-22 12:10:44 +02:00
|
|
|
QtVersion **qtVersion)
|
2010-05-20 15:47:42 +02:00
|
|
|
{
|
|
|
|
|
if (!target)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
MaemoRunConfiguration *mrc =
|
|
|
|
|
qobject_cast<MaemoRunConfiguration *> (target->activeRunConfiguration());
|
2010-07-21 17:00:40 +02:00
|
|
|
if (!mrc)
|
|
|
|
|
return false;
|
|
|
|
|
Qt4BuildConfiguration *bc
|
|
|
|
|
= qobject_cast<Qt4BuildConfiguration *>(target->activeBuildConfiguration());
|
|
|
|
|
if (!bc)
|
|
|
|
|
return false;
|
|
|
|
|
QtVersion *version = bc->qtVersion();
|
2010-11-30 14:14:55 +01:00
|
|
|
if (!version || !m_runtimes.value(version->uniqueId(), MaemoQemuRuntime()).isValid())
|
2010-07-21 17:00:40 +02:00
|
|
|
return false;
|
|
|
|
|
|
2010-07-22 12:10:44 +02:00
|
|
|
if (qtVersion)
|
|
|
|
|
*qtVersion = version;
|
2010-07-21 17:00:40 +02:00
|
|
|
const MaemoDeviceConfig &config = mrc->deviceConfig();
|
|
|
|
|
return config.isValid() && config.type == MaemoDeviceConfig::Simulator;
|
2010-05-20 15:47:42 +02:00
|
|
|
}
|
|
|
|
|
|
2010-08-18 16:33:11 +02:00
|
|
|
void MaemoQemuManager::notify(const QList<int> uniqueIds)
|
|
|
|
|
{
|
|
|
|
|
qtVersionsChanged(uniqueIds);
|
|
|
|
|
environmentChanged(); // to toggle the start button
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 09:36:30 +02:00
|
|
|
void MaemoQemuManager::toggleDeviceConnections(MaemoRunConfiguration *mrc,
|
2010-06-21 13:25:34 +02:00
|
|
|
bool _connect)
|
|
|
|
|
{
|
|
|
|
|
if (!mrc)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (_connect) { // handle device configuration changes
|
|
|
|
|
connect(mrc, SIGNAL(deviceConfigurationChanged(ProjectExplorer::Target*)),
|
|
|
|
|
this, SLOT(deviceConfigurationChanged(ProjectExplorer::Target*)));
|
|
|
|
|
} else {
|
|
|
|
|
disconnect(mrc, SIGNAL(deviceConfigurationChanged(ProjectExplorer::Target*)),
|
|
|
|
|
this, SLOT(deviceConfigurationChanged(ProjectExplorer::Target*)));
|
|
|
|
|
}
|
|
|
|
|
}
|