Files
qt-creator/src/plugins/qt4projectmanager/qt-maemo/maemorunconfigurationwidget.cpp

293 lines
12 KiB
C++
Raw Normal View History

/****************************************************************************
**
2010-03-05 11:25:49 +01:00
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Creator.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** 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.
**
** 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, 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.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "maemorunconfigurationwidget.h"
#include "deviceenvreader.h"
#include "maemodeviceconfiglistmodel.h"
#include "maemomanager.h"
#include "maemoremotemountsmodel.h"
#include "maemorunconfiguration.h"
#include "maemosettingspage.h"
#include <coreplugin/icore.h>
#include <projectexplorer/environmenteditmodel.h>
#include <QtGui/QComboBox>
#include <QtGui/QFileDialog>
#include <QtGui/QFormLayout>
#include <QtGui/QGroupBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QTableView>
#include <QtGui/QToolButton>
namespace Qt4ProjectManager {
namespace Internal {
MaemoRunConfigurationWidget::MaemoRunConfigurationWidget(
MaemoRunConfiguration *runConfiguration, QWidget *parent)
: QWidget(parent),
m_runConfiguration(runConfiguration),
m_deviceEnvReader(new DeviceEnvReader(this, runConfiguration))
{
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
QFormLayout *formLayout = new QFormLayout;
mainLayout->addLayout(formLayout);
formLayout->setFormAlignment(Qt::AlignLeft | Qt::AlignVCenter);
m_configNameLineEdit = new QLineEdit(m_runConfiguration->displayName());
formLayout->addRow(tr("Run configuration name:"), m_configNameLineEdit);
QWidget *devConfWidget = new QWidget;
QHBoxLayout *devConfLayout = new QHBoxLayout(devConfWidget);
m_devConfBox = new QComboBox;
m_devConfBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
m_devConfBox->setModel(runConfiguration->deviceConfigModel());
devConfLayout->setMargin(0);
devConfLayout->addWidget(m_devConfBox);
QLabel *addDevConfLabel= new QLabel(tr("<a href=\"%1\">Manage device configurations</a>")
.arg(QLatin1String("deviceconfig")));
addDevConfLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
devConfLayout->addWidget(addDevConfLabel);
QLabel *debuggerConfLabel = new QLabel(tr("<a href=\"%1\">Set Debugger</a>")
.arg(QLatin1String("debugger")));
debuggerConfLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
devConfLayout->addWidget(debuggerConfLabel);
formLayout->addRow(new QLabel(tr("Device configuration:")), devConfWidget);
m_executableLabel = new QLabel(m_runConfiguration->localExecutableFilePath());
formLayout->addRow(tr("Executable:"), m_executableLabel);
m_argsLineEdit = new QLineEdit(m_runConfiguration->arguments().join(" "));
formLayout->addRow(tr("Arguments:"), m_argsLineEdit);
mainLayout->addSpacing(20);
QGroupBox *mountViewBox = new QGroupBox;
#ifndef Q_OS_WIN
mainLayout->addWidget(mountViewBox);
#endif
mountViewBox->setTitle(tr("Local Directories to mount from device"));
QVBoxLayout *mountViewLayout = new QVBoxLayout(mountViewBox);
QHBoxLayout *hostAddressLayout = new QHBoxLayout;
mountViewLayout->addLayout(hostAddressLayout);
QLabel *hostNameLabel
= new QLabel(tr("This host's address from the device:"));
m_hostAddressLineEdit = new QLineEdit;
m_hostAddressLineEdit->setText(m_runConfiguration->localHostAddressFromDevice());
connect(m_hostAddressLineEdit, SIGNAL(editingFinished()), this,
SLOT(handleHostAddressChanged()));
hostAddressLayout->addWidget(hostNameLabel);
hostAddressLayout->addWidget(m_hostAddressLineEdit);
hostAddressLayout->addStretch(1);
QHBoxLayout *tableLayout = new QHBoxLayout;
mountViewLayout->addLayout(tableLayout);
m_mountView = new QTableView;
m_mountView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
m_mountView->setSelectionBehavior(QTableView::SelectRows);
m_mountView->setModel(m_runConfiguration->remoteMounts());
tableLayout->addWidget(m_mountView);
QVBoxLayout *mountViewButtonsLayout = new QVBoxLayout;
tableLayout->addLayout(mountViewButtonsLayout);
QToolButton *addMountButton = new QToolButton;
QIcon plusIcon;
plusIcon.addFile(QLatin1String(":/core/images/plus.png"));
addMountButton->setIcon(plusIcon);
mountViewButtonsLayout->addWidget(addMountButton);
m_removeMountButton = new QToolButton;
QIcon minusIcon;
minusIcon.addFile(QLatin1String(":/core/images/minus.png"));
m_removeMountButton->setIcon(minusIcon);
mountViewButtonsLayout->addWidget(m_removeMountButton);
mountViewButtonsLayout->addStretch(1);
QWidget *baseEnvironmentWidget = new QWidget;
QHBoxLayout *baseEnvironmentLayout = new QHBoxLayout(baseEnvironmentWidget);
baseEnvironmentLayout->setMargin(0);
QLabel *label = new QLabel(tr("Base environment for this runconfiguration:"), this);
baseEnvironmentLayout->addWidget(label);
QComboBox *m_baseEnvironmentComboBox = new QComboBox(this);
m_baseEnvironmentComboBox->addItems(QStringList() << tr("Clean Environment")
<< tr("System Environment"));
m_baseEnvironmentComboBox->setEnabled(false);
m_baseEnvironmentComboBox->setCurrentIndex(1); // TODO: see next
//m_baseEnvironmentComboBox->setCurrentIndex(rc->baseEnvironmentBase());
//connect(m_baseEnvironmentComboBox, SIGNAL(currentIndexChanged(int)),
// this, SLOT(baseEnvironmentSelected(int)));
baseEnvironmentLayout->addWidget(m_baseEnvironmentComboBox);
m_fetchEnv = new QPushButton(tr("Fetch Device Environment"));
connect(m_fetchEnv, SIGNAL(pressed()), this, SLOT(fetchEnvironment()));
baseEnvironmentLayout->addStretch(10);
baseEnvironmentLayout->addWidget(m_fetchEnv);
m_environmentWidget = new ProjectExplorer::EnvironmentWidget(this, baseEnvironmentWidget);
m_environmentWidget->setBaseEnvironment(m_deviceEnvReader->deviceEnvironment());
m_environmentWidget->setBaseEnvironmentText(tr("System Environment")); // TODO: see next
//m_environmentWidget->setBaseEnvironmentText(rc->baseEnvironmentText());
// m_environmentWidget->setUserChanges(rc->userEnvironmentChanges());
mainLayout->addWidget(m_environmentWidget);
handleCurrentDeviceConfigChanged();
enableOrDisableRemoveButton();
connect(m_configNameLineEdit, SIGNAL(textEdited(QString)), this,
SLOT(configNameEdited(QString)));
connect(m_argsLineEdit, SIGNAL(textEdited(QString)), this,
SLOT(argumentsEdited(QString)));
connect(m_devConfBox, SIGNAL(activated(int)), this,
SLOT(setCurrentDeviceConfig(int)));
connect(runConfiguration->deviceConfigModel(), SIGNAL(currentChanged()),
this, SLOT(handleCurrentDeviceConfigChanged()));
connect(m_runConfiguration, SIGNAL(targetInformationChanged()), this,
SLOT(updateTargetInformation()));
connect(addDevConfLabel, SIGNAL(linkActivated(QString)), this,
SLOT(showSettingsDialog(QString)));
connect(debuggerConfLabel, SIGNAL(linkActivated(QString)), this,
SLOT(showSettingsDialog(QString)));
connect(addMountButton, SIGNAL(clicked()), this, SLOT(addMount()));
connect(m_removeMountButton, SIGNAL(clicked()), this, SLOT(removeMount()));
connect(m_mountView, SIGNAL(doubleClicked(QModelIndex)), this,
SLOT(changeLocalMountDir(QModelIndex)));
connect(m_mountView->selectionModel(),
SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this,
SLOT(enableOrDisableRemoveButton()));
connect(m_deviceEnvReader, SIGNAL(finished()), this,
SLOT(fetchEnvironmentFinished()));
}
void MaemoRunConfigurationWidget::configNameEdited(const QString &text)
{
m_runConfiguration->setDisplayName(text);
}
void MaemoRunConfigurationWidget::argumentsEdited(const QString &text)
{
m_runConfiguration->setArguments(text.split(' ', QString::SkipEmptyParts));
}
void MaemoRunConfigurationWidget::updateTargetInformation()
{
m_executableLabel->setText(m_runConfiguration->localExecutableFilePath());
}
void MaemoRunConfigurationWidget::showSettingsDialog(const QString &link)
{
if (link == QLatin1String("deviceconfig")) {
MaemoSettingsPage *page = MaemoManager::instance().settingsPage();
Core::ICore::instance()->showOptionsDialog(page->category(), page->id());
} else if (link == QLatin1String("debugger")) {
Core::ICore::instance()->showOptionsDialog(QLatin1String("O.Debugger"),
QLatin1String("M.Gdb"));
}
}
void MaemoRunConfigurationWidget::handleCurrentDeviceConfigChanged()
{
m_devConfBox->setCurrentIndex(m_runConfiguration->deviceConfigModel()
->currentIndex());
}
void MaemoRunConfigurationWidget::setCurrentDeviceConfig(int index)
{
m_runConfiguration->deviceConfigModel()->setCurrentIndex(index);
}
void MaemoRunConfigurationWidget::enableOrDisableRemoveButton()
{
const QModelIndexList selectedRows
= m_mountView->selectionModel()->selectedRows();
m_removeMountButton->setEnabled(!selectedRows.isEmpty());
}
void MaemoRunConfigurationWidget::addMount()
{
const QString localDir = QFileDialog::getExistingDirectory(this,
tr("Choose directory to mount"));
if (!localDir.isEmpty()) {
MaemoRemoteMountsModel * const mountsModel
= m_runConfiguration->remoteMounts();
mountsModel->addMountSpecification(localDir);
m_mountView->edit(mountsModel->index(mountsModel->mountSpecificationCount() - 1,
mountsModel->RemoteMountPointRow));
}
}
void MaemoRunConfigurationWidget::removeMount()
{
const QModelIndexList selectedRows
= m_mountView->selectionModel()->selectedRows();
if (!selectedRows.isEmpty()) {
m_runConfiguration->remoteMounts()
->removeMountSpecificationAt(selectedRows.first().row());
}
}
void MaemoRunConfigurationWidget::changeLocalMountDir(const QModelIndex &index)
{
if (index.column() == MaemoRemoteMountsModel::LocalDirRow) {
MaemoRemoteMountsModel * const mountsModel
= m_runConfiguration->remoteMounts();
const QString oldDir
= mountsModel->mountSpecificationAt(index.row()).localDir;
const QString localDir = QFileDialog::getExistingDirectory(this,
tr("Choose directory to mount"), oldDir);
if (!localDir.isEmpty())
mountsModel->setLocalDir(index.row(), localDir);
}
}
void MaemoRunConfigurationWidget::handleHostAddressChanged()
{
m_runConfiguration->setLocalHostAddressFromDevice(m_hostAddressLineEdit->text());
}
void MaemoRunConfigurationWidget::fetchEnvironment()
{
m_deviceEnvReader->start();
m_fetchEnv->setEnabled(false);
}
void MaemoRunConfigurationWidget::fetchEnvironmentFinished()
{
m_fetchEnv->setEnabled(true);
m_environmentWidget->setBaseEnvironment(m_deviceEnvReader->deviceEnvironment());
}
} // namespace Internal
} // namespace Qt4ProjectManager