s60deployconfigurationwidget.cpp 19.3 KB
Newer Older
1 2 3 4
/**************************************************************************
**
** This file is part of Qt Creator
**
con's avatar
con committed
5
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 7 8
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
con's avatar
con committed
9
** No Commercial Usage
10
**
con's avatar
con committed
11 12 13 14
** 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.
15 16 17 18 19 20 21 22 23 24
**
** 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.
**
con's avatar
con committed
25 26 27 28 29 30
** 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.
31 32 33 34 35 36 37 38
**
**************************************************************************/

#include "s60deployconfigurationwidget.h"
#include "s60deployconfiguration.h"
#include "s60devicerunconfiguration.h"

#include "s60runconfigbluetoothstarter.h"
39 40 41 42 43
#include <symbianutils/bluetoothlistener_gui.h>

#include <symbianutils/launcher.h>
#include <symbianutils/bluetoothlistener.h>
#include <symbianutils/symbiandevicemanager.h>
44

45 46
#include "trkruncontrol.h"

47
#include <utils/detailswidget.h>
48
#include <utils/ipaddresslineedit.h>
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#include <utils/qtcassert.h>
#include <utils/pathchooser.h>

#include <QtCore/QDir>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QComboBox>
#include <QtGui/QVBoxLayout>
#include <QtGui/QHBoxLayout>
#include <QtGui/QFormLayout>
#include <QtGui/QToolButton>
#include <QtGui/QStyle>
#include <QtGui/QApplication>
#include <QtGui/QSpacerItem>
#include <QtGui/QMessageBox>
#include <QtGui/QCheckBox>
65 66 67
#include <QtGui/QGroupBox>
#include <QtGui/QRadioButton>
#include <QtGui/QValidator>
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

Q_DECLARE_METATYPE(SymbianUtils::SymbianDevice)

namespace Qt4ProjectManager {
namespace Internal {

const char STARTING_DRIVE_LETTER = 'C';
const char LAST_DRIVE_LETTER = 'Z';

S60DeployConfigurationWidget::S60DeployConfigurationWidget(QWidget *parent)
    : ProjectExplorer::DeployConfigurationWidget(parent),
      m_detailsWidget(new Utils::DetailsWidget),
      m_serialPortsCombo(new QComboBox),
      m_sisFileLabel(new QLabel),
      m_deviceInfoButton(new QToolButton),
      m_deviceInfoDescriptionLabel(new QLabel(tr("Device:"))),
      m_deviceInfoLabel(new QLabel),
      m_installationDriveCombo(new QComboBox()),
86 87
      m_silentInstallCheckBox(new QCheckBox(tr("Silent installation"))),
      m_serialRadioButton(new QRadioButton(tr("Serial:"))),
88
      m_wlanRadioButton(new QRadioButton(tr("WLAN:"))),
89 90 91
      m_ipAddress(new Utils::IpAddressLineEdit),
      m_trkRadioButton(new QRadioButton(tr("TRK"))),
      m_codaRadioButton(new QRadioButton(tr("CODA")))
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
{
}

S60DeployConfigurationWidget::~S60DeployConfigurationWidget()
{
}

void S60DeployConfigurationWidget::init(ProjectExplorer::DeployConfiguration *dc)
{
    m_deployConfiguration = qobject_cast<S60DeployConfiguration *>(dc);

    m_detailsWidget->setState(Utils::DetailsWidget::NoSummary);

    QVBoxLayout *mainBoxLayout = new QVBoxLayout();
    mainBoxLayout->setMargin(0);
    setLayout(mainBoxLayout);
    mainBoxLayout->addWidget(m_detailsWidget);
    QWidget *detailsContainer = new QWidget;
    m_detailsWidget->setWidget(detailsContainer);

    QVBoxLayout *detailsBoxLayout = new QVBoxLayout();
    detailsBoxLayout->setMargin(0);
    detailsContainer->setLayout(detailsBoxLayout);

    QFormLayout *formLayout = new QFormLayout();
    formLayout->setMargin(0);
    detailsBoxLayout->addLayout(formLayout);
    formLayout->addRow(tr("Installation file:"), m_sisFileLabel);

    // Installation Drive control
    updateInstallationDrives();

    QHBoxLayout *installationBoxLayout = new QHBoxLayout();
    m_installationDriveCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents);
    connect(m_installationDriveCombo, SIGNAL(activated(int)), this, SLOT(setInstallationDrive(int)));
    QHBoxLayout *installationDriveHBoxLayout = new QHBoxLayout;
    installationDriveHBoxLayout->addWidget(m_installationDriveCombo);
    installationBoxLayout->addLayout(installationDriveHBoxLayout);

    // Non-silent installs are a fallback if one wants to override missing dependencies.
    m_silentInstallCheckBox->setChecked(m_deployConfiguration->silentInstall());
    m_silentInstallCheckBox->setToolTip(tr("Silent installation is an installation mode "
                                           "that does not require user's intervention. "
                                           "In case it fails the non silent installation is launched."));
    connect(m_silentInstallCheckBox, SIGNAL(stateChanged(int)), this, SLOT(silentInstallChanged(int)));
    installationBoxLayout->addWidget(m_silentInstallCheckBox);
    installationBoxLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored));
    formLayout->addRow(tr("Installation drive:"), installationBoxLayout);

    updateSerialDevices();
    connect(SymbianUtils::SymbianDeviceManager::instance(), SIGNAL(updated()),
            this, SLOT(updateSerialDevices()));
144

145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
    //Debug Client
    QHBoxLayout *debugClientHBoxLayout = new QHBoxLayout;

    QVBoxLayout *debugClientVBoxLayout = new QVBoxLayout;
    debugClientVBoxLayout->addWidget(m_trkRadioButton);
    debugClientVBoxLayout->addWidget(m_codaRadioButton);

    debugClientVBoxLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::Expanding));

    debugClientHBoxLayout->addLayout(debugClientVBoxLayout);

    debugClientHBoxLayout->addWidget(createCommunicationChannel());
    debugClientHBoxLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored));

    QGroupBox *debugClientGroupBox = new QGroupBox(tr("Debug Client"));
    debugClientGroupBox->setLayout(debugClientHBoxLayout);

    bool usingTrk = m_deployConfiguration->communicationChannel() == S60DeployConfiguration::CommunicationTrkSerialConnection;
    m_trkRadioButton->setChecked(usingTrk);
    m_codaRadioButton->setChecked(!usingTrk);

    bool usingTcp = m_deployConfiguration->communicationChannel() == S60DeployConfiguration::CommunicationCodaTcpConnection;
    m_serialRadioButton->setChecked(!usingTcp);
    m_wlanRadioButton->setChecked(usingTcp);

    connect(m_trkRadioButton, SIGNAL(clicked()), this, SLOT(updateDebugClient()));
    connect(m_codaRadioButton, SIGNAL(clicked()), this, SLOT(updateDebugClient()));

    updateDebugClient();

    formLayout->addRow(debugClientGroupBox);
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193

    // Device Info with button. Widgets are enabled in above call to updateSerialDevices()
    QHBoxLayout *infoHBoxLayout = new QHBoxLayout;
    m_deviceInfoLabel->setWordWrap(true);
    m_deviceInfoLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
    infoHBoxLayout->addWidget(m_deviceInfoLabel);
    infoHBoxLayout->addWidget(m_deviceInfoButton);
    m_deviceInfoButton->setIcon(qApp->style()->standardIcon(QStyle::SP_MessageBoxInformation));
    m_deviceInfoButton->setToolTip(tr("Queries the device for information"));
    connect(m_deviceInfoButton, SIGNAL(clicked()), this, SLOT(updateDeviceInfo()));
    formLayout->addRow(m_deviceInfoDescriptionLabel, infoHBoxLayout);
    updateTargetInformation();
    connect(m_deployConfiguration, SIGNAL(targetInformationChanged()),
            this, SLOT(updateTargetInformation()));
}

QWidget *S60DeployConfigurationWidget::createCommunicationChannel()
{
194 195
    m_serialPortsCombo->setSizeAdjustPolicy(QComboBox::AdjustToContents);
    connect(m_serialPortsCombo, SIGNAL(activated(int)), this, SLOT(setSerialPort(int)));
196 197 198 199 200
    connect(m_serialRadioButton, SIGNAL(clicked()), this, SLOT(updateCommunicationChannel()));
    connect(m_wlanRadioButton, SIGNAL(clicked()), this, SLOT(updateCommunicationChannel()));
    connect(m_ipAddress, SIGNAL(validAddressChanged(QString)), this, SLOT(updateWlanAddress(QString)));
    connect(m_ipAddress, SIGNAL(invalidAddressChanged()), this, SLOT(cleanWlanAddress()));

201
    QHBoxLayout *serialPortHBoxLayout = new QHBoxLayout;
202
    serialPortHBoxLayout->addWidget(new QLabel(tr("Serial port:")));
203 204 205 206 207 208 209 210 211 212 213 214
    serialPortHBoxLayout->addWidget(m_serialPortsCombo);
    serialPortHBoxLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored));

#ifndef Q_OS_WIN
    // Update device list: on Linux only.
    QToolButton *updateSerialDevicesButton(new QToolButton);
    updateSerialDevicesButton->setIcon(qApp->style()->standardIcon(QStyle::SP_BrowserReload));
    connect(updateSerialDevicesButton, SIGNAL(clicked()),
            SymbianUtils::SymbianDeviceManager::instance(), SLOT(update()));
    serialPortHBoxLayout->addWidget(updateSerialDevicesButton);
#endif

215
    QGroupBox *communicationChannelGroupBox = new QGroupBox(tr("Communication Channel"));
216 217 218
    QGridLayout *communicationChannelGridLayout = new QGridLayout;
    communicationChannelGridLayout->addWidget(m_serialRadioButton, 0, 0);
    communicationChannelGridLayout->addWidget(m_wlanRadioButton, 1, 0);
219 220 221 222 223 224 225 226 227 228 229 230 231 232

    m_ipAddress->setMinimumWidth(30);
    m_ipAddress->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);

    if(!m_deployConfiguration->deviceAddress().isEmpty())
        m_ipAddress->setText(QString("%1:%2")
                         .arg(m_deployConfiguration->deviceAddress())
                         .arg(m_deployConfiguration->devicePort()));

    QHBoxLayout *wlanChannelLayout = new QHBoxLayout();
    wlanChannelLayout->addWidget(new QLabel(tr("Address:")));
    wlanChannelLayout->addWidget(m_ipAddress);
    wlanChannelLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored));

233 234
    communicationChannelGridLayout->addLayout(serialPortHBoxLayout, 0, 1);
    communicationChannelGridLayout->addLayout(wlanChannelLayout, 1, 1);
235

236
    communicationChannelGroupBox->setLayout(communicationChannelGridLayout);
237
    return communicationChannelGroupBox;
238 239 240 241 242 243
}

void S60DeployConfigurationWidget::updateInstallationDrives()
{
    m_installationDriveCombo->clear();
    for (int i = STARTING_DRIVE_LETTER; i <= LAST_DRIVE_LETTER; ++i) {
244
        m_installationDriveCombo->addItem(QString("%1:").arg(static_cast<char>(i)), qVariantFromValue(i));
245
    }
246
    int index = QChar::toUpper(static_cast<ushort>(m_deployConfiguration->installationDrive())) - STARTING_DRIVE_LETTER;
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282

    Q_ASSERT(index >= 0 && index <= LAST_DRIVE_LETTER-STARTING_DRIVE_LETTER);

    m_installationDriveCombo->setCurrentIndex(index);
}

void S60DeployConfigurationWidget::silentInstallChanged(int state)
{
    m_deployConfiguration->setSilentInstall(state == Qt::Checked);
}

void S60DeployConfigurationWidget::updateSerialDevices()
{
    m_serialPortsCombo->clear();
    clearDeviceInfo();
    const QString previouPortName = m_deployConfiguration->serialPortName();
    const QList<SymbianUtils::SymbianDevice> devices = SymbianUtils::SymbianDeviceManager::instance()->devices();
    int newIndex = -1;
    for (int i = 0; i < devices.size(); ++i) {
        const SymbianUtils::SymbianDevice &device = devices.at(i);
        m_serialPortsCombo->addItem(device.friendlyName(), qVariantFromValue(device));
        if (device.portName() == previouPortName)
            newIndex = i;
    }
    // Set new index: prefer to keep old or set to 0, if available.
    if (newIndex == -1 && !devices.empty())
        newIndex = 0;
    m_serialPortsCombo->setCurrentIndex(newIndex);
    if (newIndex == -1) {
        m_deviceInfoButton->setEnabled(false);
        m_deployConfiguration->setSerialPortName(QString());
    } else {
        m_deviceInfoButton->setEnabled(true);
        const QString newPortName = device(newIndex).portName();
        m_deployConfiguration->setSerialPortName(newPortName);
    }
283
    if (m_deployConfiguration->communicationChannel() != S60DeployConfiguration::CommunicationTrkSerialConnection)
284
        m_deviceInfoButton->setEnabled(false);
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
}

SymbianUtils::SymbianDevice S60DeployConfigurationWidget::device(int i) const
{
    const QVariant data = m_serialPortsCombo->itemData(i);
    if (data.isValid() && qVariantCanConvert<SymbianUtils::SymbianDevice>(data))
        return qVariantValue<SymbianUtils::SymbianDevice>(data);
    return SymbianUtils::SymbianDevice();
}

SymbianUtils::SymbianDevice S60DeployConfigurationWidget::currentDevice() const
{
    return device(m_serialPortsCombo->currentIndex());
}

void S60DeployConfigurationWidget::updateTargetInformation()
{
    QString package;
303 304 305 306
    for (int i = 0; i < m_deployConfiguration->signedPackages().count(); ++i)
        package += m_deployConfiguration->signedPackages()[i] + QLatin1String("\n");
    if (!package.isEmpty())
        package.remove(package.length()-1, 1);
307 308 309 310 311
    m_sisFileLabel->setText(QDir::toNativeSeparators(package));
}

void S60DeployConfigurationWidget::setInstallationDrive(int index)
{
312
    m_deployConfiguration->setInstallationDrive(static_cast<char>(STARTING_DRIVE_LETTER + index));
313 314 315 316 317 318 319 320 321 322
}

void S60DeployConfigurationWidget::setSerialPort(int index)
{
    const SymbianUtils::SymbianDevice d = device(index);
    m_deployConfiguration->setSerialPortName(d.portName());
    m_deviceInfoButton->setEnabled(index >= 0);
    clearDeviceInfo();
}

323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
void S60DeployConfigurationWidget::updateDebugClient()
{
        if (!m_trkRadioButton->isChecked() && !m_codaRadioButton->isChecked())
            m_trkRadioButton->setChecked(true);

        if (m_trkRadioButton->isChecked()) {
            m_serialRadioButton->setEnabled(true);
            m_serialRadioButton->setChecked(true);
            m_wlanRadioButton->setEnabled(false);
            updateSerialDevices();
        } else if(m_codaRadioButton->isChecked()) {
            m_serialRadioButton->setEnabled(true);
            m_wlanRadioButton->setEnabled(true);
        }

        updateCommunicationChannel();
}

341 342
void S60DeployConfigurationWidget::updateCommunicationChannel()
{
343 344 345
    if (!m_serialRadioButton->isChecked() && !m_wlanRadioButton->isChecked())
        m_serialRadioButton->setChecked(true);

346 347 348
    if (m_serialRadioButton->isChecked()) {
        m_ipAddress->setDisabled(true);
        m_serialPortsCombo->setDisabled(false);
349 350 351 352
        if (m_trkRadioButton->isChecked())
            m_deployConfiguration->setCommunicationChannel(S60DeployConfiguration::CommunicationTrkSerialConnection);
        else
            m_deployConfiguration->setCommunicationChannel(S60DeployConfiguration::CommunicationCodaSerialConnection);
353
        updateSerialDevices();
354 355 356
    } else if(m_wlanRadioButton->isChecked()) {
        m_ipAddress->setDisabled(false);
        m_serialPortsCombo->setDisabled(true);
357
        m_deployConfiguration->setCommunicationChannel(S60DeployConfiguration::CommunicationCodaTcpConnection);
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
    }
}

void S60DeployConfigurationWidget::updateWlanAddress(const QString &address)
{
    QStringList addressList = address.split(QLatin1String(":"), QString::SkipEmptyParts);
    if (addressList.count() > 0) {
        m_deployConfiguration->setDeviceAddress(addressList.at(0));
        if (addressList.count() > 1)
            m_deployConfiguration->setDevicePort(addressList.at(1));
        else
            m_deployConfiguration->setDevicePort(QString());
    }
}

void S60DeployConfigurationWidget::cleanWlanAddress()
{
    if (!m_deployConfiguration->deviceAddress().isEmpty())
        m_deployConfiguration->setDeviceAddress(QString());

    if (!m_deployConfiguration->devicePort().isEmpty())
        m_deployConfiguration->setDevicePort(QString());
}

382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
void S60DeployConfigurationWidget::clearDeviceInfo()
{
    // Restore text & color
    m_deviceInfoLabel->clear();
    m_deviceInfoLabel->setStyleSheet(QString());
}

void S60DeployConfigurationWidget::setDeviceInfoLabel(const QString &message, bool isError)
{
    m_deviceInfoLabel->setStyleSheet(isError ?
                                         QString(QLatin1String("background-color: red;")) :
                                         QString());
    m_deviceInfoLabel->setText(message);
    m_deviceInfoLabel->adjustSize();
}

void S60DeployConfigurationWidget::slotLauncherStateChanged(int s)
{
    switch (s) {
    case trk::Launcher::WaitingForTrk: {
        // Entered trk wait state..open message box
403
        QMessageBox *mb = TrkRunControl::createTrkWaitingMessageBox(m_infoLauncher->trkServerName(), this);
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
        connect(m_infoLauncher, SIGNAL(stateChanged(int)), mb, SLOT(close()));
        connect(mb, SIGNAL(finished(int)), this, SLOT(slotWaitingForTrkClosed()));
        mb->open();
    }
        break;
    case trk::Launcher::DeviceDescriptionReceived: // All ok, done
        setDeviceInfoLabel(m_infoLauncher->deviceDescription());
        m_deviceInfoButton->setEnabled(true);
        m_infoLauncher->deleteLater();
        break;
    }
}

void S60DeployConfigurationWidget::slotWaitingForTrkClosed()
{
    if (m_infoLauncher && m_infoLauncher->state() == trk::Launcher::WaitingForTrk) {
        m_infoLauncher->deleteLater();
        clearDeviceInfo();
        m_deviceInfoButton->setEnabled(true);
    }
}

void S60DeployConfigurationWidget::updateDeviceInfo()
{
428
    //TODO: No CODA device info! Implement it when it is available
429
    if (m_deployConfiguration->communicationChannel() == S60DeployConfiguration::CommunicationTrkSerialConnection) {
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
        QTC_ASSERT(!m_infoLauncher, return)
                setDeviceInfoLabel(tr("Connecting..."));
        // Do a launcher run with the ping protocol. Prompt to connect and
        // go asynchronous afterwards to pop up launch trk box if a timeout occurs.
        QString message;
        const SymbianUtils::SymbianDevice commDev = currentDevice();
        m_infoLauncher = trk::Launcher::acquireFromDeviceManager(commDev.portName(), this, &message);
        if (!m_infoLauncher) {
            setDeviceInfoLabel(message, true);
            return;
        }
        connect(m_infoLauncher, SIGNAL(stateChanged(int)), this, SLOT(slotLauncherStateChanged(int)));

        m_infoLauncher->setSerialFrame(commDev.type() == SymbianUtils::SerialPortCommunication);
        m_infoLauncher->setTrkServerName(commDev.portName());

        // Prompt user
        const trk::PromptStartCommunicationResult src =
                S60RunConfigBluetoothStarter::startCommunication(m_infoLauncher->trkDevice(),
                                                                 this, &message);
        switch (src) {
        case trk::PromptStartCommunicationConnected:
            break;
        case trk::PromptStartCommunicationCanceled:
            clearDeviceInfo();
            m_infoLauncher->deleteLater();
            return;
        case trk::PromptStartCommunicationError:
            setDeviceInfoLabel(message, true);
            m_infoLauncher->deleteLater();
            return;
        };
        if (!m_infoLauncher->startServer(&message)) {
            setDeviceInfoLabel(message, true);
            m_infoLauncher->deleteLater();
            return;
        }
        // Wait for either timeout or results
        m_deviceInfoButton->setEnabled(false);
    } else
        setDeviceInfoLabel(tr("Currently there is no information about device for CODA connection type."), true);
471 472 473 474
}

} // namespace Internal
} // namespace Qt4ProjectManager