bool BlackBerryCheckDevModeStep::init()
{
    if (!BlackBerryAbstractDeployStep::init())
        return false;

    QString deployCmd = target()->activeBuildConfiguration()->environment().searchInPath(QLatin1String(Constants::QNX_BLACKBERRY_DEPLOY_CMD));
    if (deployCmd.isEmpty()) {
        raiseError(tr("Could not find command '%1' in the build environment")
                       .arg(QLatin1String(Constants::QNX_BLACKBERRY_DEPLOY_CMD)));
        return false;
    }

    BlackBerryDeviceConfiguration::ConstPtr device = BlackBerryDeviceConfiguration::device(target()->kit());
    QString deviceHost = device ? device->sshParameters().host : QString();
    if (deviceHost.isEmpty()) {
        raiseError(tr("No hostname specified for device"));
        return false;
    }

    QStringList args;
    args << QLatin1String("-listDeviceInfo");
    args << deviceHost;
    if (!device->sshParameters().password.isEmpty()) {
        args << QLatin1String("-password");
        args << device->sshParameters().password;
    }

    addCommand(deployCmd, args);

    return true;
}
QString BlackBerryCreatePackageStep::debugToken() const
{
    BlackBerryDeviceConfiguration::ConstPtr device = BlackBerryDeviceConfiguration::device(target()->kit());
    if (!device)
        return QString();

    return device->debugToken();
}
QString BlackBerryRunConfiguration::deviceName() const
{
    BlackBerryDeviceConfiguration::ConstPtr device
            = BlackBerryDeviceConfiguration::device(target()->kit());
    if (!device)
        return QString();

    return device->displayName();
}
Debugger::DebuggerStartParameters BlackBerryRunControlFactory::startParameters(
    const BlackBerryRunConfiguration *runConfig)
{
    Debugger::DebuggerStartParameters params;
    ProjectExplorer::Target *target = runConfig->target();
    ProjectExplorer::Profile *profile = target->profile();

    params.startMode = Debugger::AttachToRemoteServer;
    params.debuggerCommand = Debugger::DebuggerProfileInformation::debuggerCommand(profile).toString();
    params.sysRoot = ProjectExplorer::SysRootProfileInformation::sysRoot(profile).toString();

    if (ProjectExplorer::ToolChain *tc = ProjectExplorer::ToolChainProfileInformation::toolChain(profile)) {
        params.toolChainAbi = tc->targetAbi();
        params.remoteArchitecture = ProjectExplorer::Abi::toString(tc->targetAbi().architecture());
    }

    params.executable = runConfig->localExecutableFilePath();
    params.remoteChannel = runConfig->deployConfiguration()->deviceHost() + QLatin1String(":8000");
    params.displayName = runConfig->displayName();
    params.remoteSetupNeeded = true;

    if (runConfig->debuggerAspect()->useQmlDebugger()) {
        BlackBerryDeviceConfiguration::ConstPtr device = BlackBerryDeviceConfiguration::device(runConfig->target()->profile());
        if (device) {
            params.qmlServerAddress = device->sshParameters().host;
            params.qmlServerPort = runConfig->debuggerAspect()->qmlDebugServerPort();
            params.languages |= Debugger::QmlLanguage;
        }
    }
    if (runConfig->debuggerAspect()->useCppDebugger())
        params.languages |= Debugger::CppLanguage;

    if (const ProjectExplorer::Project *project = runConfig->target()->project()) {
        params.projectSourceDirectory = project->projectDirectory();
        if (const ProjectExplorer::BuildConfiguration *buildConfig = runConfig->target()->activeBuildConfiguration()) {
            params.projectBuildDirectory = buildConfig->buildDirectory();
        }
        params.projectSourceFiles = project->files(ProjectExplorer::Project::ExcludeGeneratedFiles);
    }

    BlackBerryQtVersion *qtVersion =
        dynamic_cast<BlackBerryQtVersion *>(QtSupport::QtProfileInformation::qtVersion(profile));
    if (qtVersion)
        params.solibSearchPath = QnxUtils::searchPaths(qtVersion);

    return params;
}
ProjectExplorer::RunControl *BlackBerryRunControlFactory::create(ProjectExplorer::RunConfiguration *runConfiguration,
        ProjectExplorer::RunMode mode, QString *errorMessage)
{
    BlackBerryRunConfiguration *rc = qobject_cast<BlackBerryRunConfiguration *>(runConfiguration);
    if (!rc)
        return 0;

    BlackBerryDeployConfiguration *activeDeployConf = qobject_cast<BlackBerryDeployConfiguration *>(
                rc->target()->activeDeployConfiguration());
    if (!activeDeployConf) {
        if (errorMessage)
            *errorMessage = tr("No active deploy configuration");
        return 0;
    }

    BlackBerryDeviceConfiguration::ConstPtr device =
            BlackBerryDeviceConfiguration::device(rc->target()->kit());
    if (!BlackBerryDeviceConnectionManager::instance()->isConnected(device->id())) {
        if (errorMessage)
            *errorMessage = tr("Device not connected");
        return 0;
    }

    if (mode == ProjectExplorer::NormalRunMode) {
        BlackBerryRunControl *runControl = new BlackBerryRunControl(rc);
        m_activeRunControls[rc->key()] = runControl;
        return runControl;
    }

    Debugger::DebuggerRunControl * const runControl =
            Debugger::DebuggerPlugin::createDebugger(startParameters(rc), runConfiguration, errorMessage);
    if (!runControl)
        return 0;

    new BlackBerryDebugSupport(rc, runControl);
    m_activeRunControls[rc->key()] = runControl;
    return runControl;
}
QString BlackBerryCheckDevModeStep::password() const
{
    BlackBerryDeviceConfiguration::ConstPtr device = BlackBerryDeviceConfiguration::device(target()->kit());
    return device ? device->sshParameters().password : QString();
}