diff options
author | Fawzi Mohamed <fawzi.mohamed@digia.com> | 2014-02-14 01:02:30 +0100 |
---|---|---|
committer | Fawzi Mohamed <fawzi.mohamed@digia.com> | 2014-02-14 15:39:39 +0100 |
commit | 3a2157d4e9ff1f9fdd893b1dc43f5b27c068dbe3 (patch) | |
tree | 7d70dba1b6d2bf5ee69192eb9db661f566c75d89 /src/plugins/ios/iosrunconfiguration.cpp | |
parent | c4ab8909979f0acce65a89e0626942db76381822 (diff) | |
download | qt-creator-3a2157d4e9ff1f9fdd893b1dc43f5b27c068dbe3.tar.gz |
ios: improve run handling
disabling running when running is not possible with message explaining
it:
* device is not available (and tell user if another device is available)
* profile parsings
Change-Id: I8a2e8e4486555b09de2ac4ceab89997286c81454
Reviewed-by: Daniel Teske <daniel.teske@digia.com>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@digia.com>
Diffstat (limited to 'src/plugins/ios/iosrunconfiguration.cpp')
-rw-r--r-- | src/plugins/ios/iosrunconfiguration.cpp | 109 |
1 files changed, 108 insertions, 1 deletions
diff --git a/src/plugins/ios/iosrunconfiguration.cpp b/src/plugins/ios/iosrunconfiguration.cpp index f607d311c9..b097c490df 100644 --- a/src/plugins/ios/iosrunconfiguration.cpp +++ b/src/plugins/ios/iosrunconfiguration.cpp @@ -30,10 +30,12 @@ #include "iosrunconfiguration.h" #include "iosmanager.h" #include "iosdeploystep.h" +#include "ui_iosrunconfiguration.h" #include <projectexplorer/kitinformation.h> #include <projectexplorer/target.h> #include <projectexplorer/deployconfiguration.h> +#include <projectexplorer/devicesupport/devicemanager.h> #include <projectexplorer/buildstep.h> #include <projectexplorer/buildsteplist.h> #include <qmakeprojectmanager/qmakebuildconfiguration.h> @@ -41,7 +43,6 @@ #include <qmakeprojectmanager/qmakenodes.h> #include <qtsupport/qtoutputformatter.h> #include <qtsupport/qtkitinformation.h> -#include "ui_iosrunconfiguration.h" #include <QList> @@ -93,7 +94,43 @@ IosRunConfiguration::IosRunConfiguration(Target *parent, IosRunConfiguration *so void IosRunConfiguration::init() { + QmakeProject *project = static_cast<QmakeProject *>(target()->project()); + m_parseSuccess = project->validParse(m_profilePath); + m_parseInProgress = project->parseInProgress(m_profilePath); + m_lastIsEnabled = isEnabled(); + m_lastDisabledReason = disabledReason(); + connect(DeviceManager::instance(), SIGNAL(updated()), + SLOT(deviceChanges())); + connect(KitManager::instance(), SIGNAL(kitsChanged()), + SLOT(deviceChanges())); + connect(target()->project(), SIGNAL(proFileUpdated(QmakeProjectManager::QmakeProFileNode*,bool,bool)), + this, SLOT(proFileUpdated(QmakeProjectManager::QmakeProFileNode*,bool,bool))); +} + +void IosRunConfiguration::enabledCheck() +{ + bool newIsEnabled = isEnabled(); + QString newDisabledReason = disabledReason(); + if (newDisabledReason != m_lastDisabledReason || newIsEnabled != m_lastIsEnabled) { + m_lastDisabledReason = newDisabledReason; + m_lastIsEnabled = newIsEnabled; + emit enabledChanged(); + } +} + +void IosRunConfiguration::deviceChanges() { setDefaultDisplayName(defaultDisplayName()); + enabledCheck(); +} + +void IosRunConfiguration::proFileUpdated(QmakeProjectManager::QmakeProFileNode *pro, bool success, + bool parseInProgress) +{ + if (m_profilePath != pro->path()) + return; + m_parseSuccess = success; + m_parseInProgress = parseInProgress; + enabledCheck(); } QWidget *IosRunConfiguration::createConfigurationWidget() @@ -210,6 +247,76 @@ QVariantMap IosRunConfiguration::toMap() const return res; } +bool IosRunConfiguration::isEnabled() const +{ + if (m_parseInProgress || !m_parseSuccess) + return false; + Core::Id devType = ProjectExplorer::DeviceTypeKitInformation::deviceTypeId(target()->kit()); + if (devType != Constants::IOS_DEVICE_TYPE && devType != Constants::IOS_SIMULATOR_TYPE) + return false; + IDevice::ConstPtr dev = ProjectExplorer::DeviceKitInformation::device(target()->kit()); + if (dev.isNull() || dev->deviceState() != IDevice::DeviceReadyToUse) + return false; + return RunConfiguration::isEnabled(); +} + +QString IosRunConfiguration::disabledReason() const +{ + if (m_parseInProgress) + return tr("The .pro file '%1' is currently being parsed.") + .arg(QFileInfo(m_profilePath).fileName()); + if (!m_parseSuccess) + return static_cast<QmakeProject *>(target()->project()) + ->disabledReasonForRunConfiguration(m_profilePath); + Core::Id devType = ProjectExplorer::DeviceTypeKitInformation::deviceTypeId(target()->kit()); + if (devType != Constants::IOS_DEVICE_TYPE && devType != Constants::IOS_SIMULATOR_TYPE) + return tr("Kit has incorrect device type for running on iOS devices."); + IDevice::ConstPtr dev = ProjectExplorer::DeviceKitInformation::device(target()->kit()); + QString validDevName; + bool hasConncetedDev = false; + if (devType == Constants::IOS_DEVICE_TYPE) { + DeviceManager *dm = DeviceManager::instance(); + for (int idev = 0; idev < dm->deviceCount(); ++idev) { + IDevice::ConstPtr availDev = dm->deviceAt(idev); + if (!availDev.isNull() && availDev->type() == Constants::IOS_DEVICE_TYPE) { + if (availDev->deviceState() == IDevice::DeviceReadyToUse) { + validDevName += QLatin1String(" "); + validDevName += availDev->displayName(); + } else if (availDev->deviceState() == IDevice::DeviceConnected) { + hasConncetedDev = true; + } + } + } + } + + if (dev.isNull()) { + if (!validDevName.isEmpty()) + return tr("No device chosen. Select %1.").arg(validDevName); // should not happen + else if (hasConncetedDev) + return tr("No device chosen. Enable developer mode on a device."); // should not happen + else + return tr("No device available."); + } else { + switch (dev->deviceState()) { + case IDevice::DeviceReadyToUse: + break; + case IDevice::DeviceConnected: + return tr("To use this device you need to enable developer mode on it."); + case IDevice::DeviceDisconnected: + case IDevice::DeviceStateUnknown: + if (!validDevName.isEmpty()) + return tr("%1 is not connected. Select %2?") + .arg(dev->displayName(), validDevName); + else if (hasConncetedDev) + return tr("%1 is not connected. Enable developer mode on a device?") + .arg(dev->displayName()); + else + return tr("%1 is not connected.").arg(dev->displayName()); + } + } + return RunConfiguration::disabledReason(); +} + IosRunConfigurationWidget::IosRunConfigurationWidget(IosRunConfiguration *runConfiguration) : m_ui(new Ui::IosRunConfiguration), m_runConfiguration(runConfiguration) { |