blackberrydeployconfiguration.cpp 8.36 KB
Newer Older
Tobias Nätterlund's avatar
Tobias Nätterlund committed
1 2
/**************************************************************************
**
3
** Copyright (C) 2012, 2013 BlackBerry Limited. All rights reserved.
Tobias Nätterlund's avatar
Tobias Nätterlund committed
4
**
5
** Contact: BlackBerry (qt@blackberry.com)
Tobias Nätterlund's avatar
Tobias Nätterlund committed
6 7
** Contact: KDAB (info@kdab.com)
**
hjk's avatar
hjk committed
8
** This file is part of Qt Creator.
Tobias Nätterlund's avatar
Tobias Nätterlund committed
9
**
hjk's avatar
hjk committed
10 11 12 13 14 15 16
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
Tobias Nätterlund's avatar
Tobias Nätterlund committed
17
**
hjk's avatar
hjk committed
18 19 20 21 22 23 24 25 26 27
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
Tobias Nätterlund's avatar
Tobias Nätterlund committed
28 29
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
30
****************************************************************************/
Tobias Nätterlund's avatar
Tobias Nätterlund committed
31 32 33 34 35 36 37

#include "blackberrydeployconfiguration.h"

#include "qnxconstants.h"
#include "blackberrydeployconfigurationwidget.h"
#include "blackberrydeployinformation.h"

Tobias Hunger's avatar
Tobias Hunger committed
38
#include <projectexplorer/kitinformation.h>
Tobias Nätterlund's avatar
Tobias Nätterlund committed
39
#include <projectexplorer/target.h>
40
#include <projectexplorer/projectexplorer.h>
41 42 43
#include <qt4projectmanager/qmakenodes.h>
#include <qt4projectmanager/qmakeproject.h>
#include <qt4projectmanager/qmakebuildconfiguration.h>
44
#include <qtsupport/qtkitinformation.h>
45
#include <coreplugin/icore.h>
Tobias Nätterlund's avatar
Tobias Nätterlund committed
46
#include <ssh/sshconnection.h>
47
#include <utils/checkablemessagebox.h>
Tobias Nätterlund's avatar
Tobias Nätterlund committed
48

49 50
#include <QMessageBox>

Tobias Nätterlund's avatar
Tobias Nätterlund committed
51 52 53 54
using namespace Qnx;
using namespace Qnx::Internal;

namespace {
55
const char DEPLOYMENT_INFO_KEY[]     = "Qnx.BlackBerry.DeployInformation";
56
const char BAR_DESC_SETUP[]          = "Qnx.BlackBerry.DeployInformation.BarDescriptorSetup";
Tobias Nätterlund's avatar
Tobias Nätterlund committed
57 58 59 60 61 62 63 64 65 66 67 68 69
}

BlackBerryDeployConfiguration::BlackBerryDeployConfiguration(ProjectExplorer::Target *parent)
    : ProjectExplorer::DeployConfiguration(parent, Core::Id(Constants::QNX_BB_DEPLOYCONFIGURATION_ID))
{
    ctor();
}

BlackBerryDeployConfiguration::BlackBerryDeployConfiguration(ProjectExplorer::Target *parent,
                                               BlackBerryDeployConfiguration *source)
    : ProjectExplorer::DeployConfiguration(parent, source)
{
    ctor();
70
    cloneSteps(source);
Tobias Nätterlund's avatar
Tobias Nätterlund committed
71 72 73 74
}

void BlackBerryDeployConfiguration::ctor()
{
75
    m_deployInformation = new BlackBerryDeployInformation(target());
76
    m_appBarDesciptorSetup = false;
Tobias Nätterlund's avatar
Tobias Nätterlund committed
77

78 79
    connect(target()->project(), SIGNAL(proFilesEvaluated()), this, SLOT(setupBarDescriptor()), Qt::UniqueConnection);

Tobias Nätterlund's avatar
Tobias Nätterlund committed
80 81 82
    setDefaultDisplayName(tr("Deploy to BlackBerry Device"));
}

83 84
void BlackBerryDeployConfiguration::setupBarDescriptor()
{
85
    QmakeProjectManager::QmakeBuildConfiguration *bc = qobject_cast<QmakeProjectManager::QmakeBuildConfiguration *>(target()->activeBuildConfiguration());
86 87 88 89 90 91
    if (!bc || !target()->kit())
        return;

    Core::Id deviceType = ProjectExplorer::DeviceTypeKitInformation::deviceTypeId(target()->kit());
    QString projectName = target()->project()->displayName();

92
    QString targetName;
93 94
    QmakeProjectManager::Qt4Project *project =  static_cast<QmakeProjectManager::Qt4Project *>(target()->project());
    foreach (QmakeProjectManager::Qt4ProFileNode *node, project->applicationProFiles()) {
95 96 97 98 99 100 101
        QString target = node->targetInformation().target;
        if (!target.isEmpty()) {
            targetName = target;
            break;
        }
    }

102 103 104 105 106 107 108
    if (deviceType == Constants::QNX_BB_OS_TYPE) {
        const QLatin1String barDescriptorFileName("bar-descriptor.xml");
        Utils::FileName barDescriptorPath = Utils::FileName::fromString(target()->project()->projectDirectory()).appendPath(barDescriptorFileName);
        const QFile barDescriptorFile(barDescriptorPath.toString());
        if (barDescriptorFile.exists())
            return;

109 110 111 112 113 114 115 116 117 118 119 120
        if (m_appBarDesciptorSetup)
            return;

        QDialogButtonBox::StandardButton button = Utils::CheckableMessageBox::question(Core::ICore::mainWindow(),
                                             tr("Setup Application Descriptor File"),
                                             tr("You need to set up a bar descriptor file to enable "
                                                "packaging.\nDo you want Qt Creator to generate it for your project?"),
                                             tr("Don't ask again for this project"), &m_appBarDesciptorSetup);

        if (button == QDialogButtonBox::No)
            return;

121
        QString barDescriptorTemplate;
122 123
        QtSupport::QtVersionNumber qtVersion = QtSupport::QtKitInformation::qtVersion(target()->kit())->qtVersion();
        if (qtVersion >= QtSupport::QtVersionNumber(5, 0, 0))
124
            barDescriptorTemplate = Core::ICore::resourcePath()
125
                    + QLatin1String("/templates/wizards/bb-qt5-bardescriptor/bar-descriptor.xml");
126 127
        else
            barDescriptorTemplate = Core::ICore::resourcePath()
128
                    + QLatin1String("/templates/wizards/bb-bardescriptor/bar-descriptor.xml");
129

130
        Utils::FileReader reader;
131 132
        if (!reader.fetch(barDescriptorTemplate)) {
            QMessageBox::warning(Core::ICore::mainWindow(),
Leena Miettinen's avatar
Leena Miettinen committed
133 134
                                 tr("Cannot Set up Application Descriptor File"),
                                 tr("Reading the bar descriptor template failed."),
135 136 137 138 139
                                 QMessageBox::Ok);
            return;
        }

        QString content = QString::fromUtf8(reader.data());
140
        content.replace(QLatin1String("PROJECTNAME"), projectName);
141
        content.replace(QLatin1String("PROJECTPATH"), targetName);
142 143 144 145 146 147 148
        content.replace(QLatin1String("ID"), QLatin1String("com.example.") + projectName);

        if (Utils::FileName::fromString(target()->project()->projectDirectory())
                 .appendPath(QLatin1String("qml")).toFileInfo().exists())
            content.replace(QLatin1String("</qnx>"),
                            QLatin1String("    <asset path=\"%SRC_DIR%/qml\">qml</asset>\n</qnx>"));

149 150 151 152
        Utils::FileSaver writer(barDescriptorFile.fileName(), QIODevice::WriteOnly);
        writer.write(content.toUtf8());
        if (!writer.finalize()) {
            QMessageBox::warning(Core::ICore::mainWindow(),
Leena Miettinen's avatar
Leena Miettinen committed
153 154
                                 tr("Cannot Set up Application Descriptor File"),
                                 tr("Writing the bar descriptor file failed."),
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
                                 QMessageBox::Ok);
            return;
        }

        // Add the Bar Descriptor to the existing project
        if (target()->project()->rootProjectNode())
            addBarDescriptorToProject(barDescriptorPath.toString());
    }
}

void BlackBerryDeployConfiguration::addBarDescriptorToProject(const QString &barDesciptorPath)
{
    if (barDesciptorPath.isEmpty())
        return;

170 171
    ProjectExplorer::ProjectExplorerPlugin::instance()
            ->addExistingFiles(target()->project()->rootProjectNode(), QStringList() << barDesciptorPath);
172 173
}

Tobias Nätterlund's avatar
Tobias Nätterlund committed
174 175 176 177 178 179
BlackBerryDeployConfiguration::~BlackBerryDeployConfiguration()
{
}

BlackBerryDeployInformation *BlackBerryDeployConfiguration::deploymentInfo() const
{
180
    return m_deployInformation;
Tobias Nätterlund's avatar
Tobias Nätterlund committed
181 182
}

183
ProjectExplorer::NamedWidget *BlackBerryDeployConfiguration::createConfigWidget()
Tobias Nätterlund's avatar
Tobias Nätterlund committed
184
{
185
    return new BlackBerryDeployConfigurationWidget(this);
Tobias Nätterlund's avatar
Tobias Nätterlund committed
186 187
}

188 189 190 191
QVariantMap BlackBerryDeployConfiguration::toMap() const
{
    QVariantMap map(ProjectExplorer::DeployConfiguration::toMap());
    map.insert(QLatin1String(DEPLOYMENT_INFO_KEY), deploymentInfo()->toMap());
192
    map.insert(QLatin1String(BAR_DESC_SETUP), m_appBarDesciptorSetup);
193 194 195 196 197 198 199 200
    return map;
}

bool BlackBerryDeployConfiguration::fromMap(const QVariantMap &map)
{
    if (!ProjectExplorer::DeployConfiguration::fromMap(map))
        return false;

201
    m_appBarDesciptorSetup = map.value(QLatin1String(BAR_DESC_SETUP)).toBool();
202 203 204 205
    QVariantMap deployInfoMap = map.value(QLatin1String(DEPLOYMENT_INFO_KEY)).toMap();
    deploymentInfo()->fromMap(deployInfoMap);
    return true;
}