1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "maemodeploystepwidget.h"
35 #include "ui_maemodeploystepwidget.h"
37 #include "maemodeploystep.h"
38 #include "maemodeployablelistmodel.h"
39 #include "maemodeployables.h"
40 #include "maemodeviceconfigurations.h"
41 #include "maemosettingspages.h"
42 #include "maemoglobal.h"
43 #include "maemomanager.h"
44 #include "maemopertargetdeviceconfigurationlistmodel.h"
45 #include "maemorunconfiguration.h"
46 #include "qt4maemotarget.h"
48 #include <coreplugin/icore.h>
49 #include <projectexplorer/buildconfiguration.h>
50 #include <projectexplorer/target.h>
51 #include <utils/qtcassert.h>
53 #include <QtGui/QFileDialog>
54 #include <QtGui/QMessageBox>
55 #include <QtGui/QPixmap>
57 namespace Qt4ProjectManager {
60 MaemoDeployStepWidget::MaemoDeployStepWidget(MaemoDeployStep *step) :
61 ProjectExplorer::BuildStepConfigWidget(),
62 ui(new Ui::MaemoDeployStepWidget),
66 ui->modelComboBox->setModel(m_step->deployables().data());
67 connect(m_step->deployables().data(), SIGNAL(modelAboutToBeReset()),
68 SLOT(handleModelListToBeReset()));
70 // Queued connection because of race condition with combo box's reaction
72 connect(m_step->deployables().data(), SIGNAL(modelReset()),
73 SLOT(handleModelListReset()), Qt::QueuedConnection);
75 connect(ui->modelComboBox, SIGNAL(currentIndexChanged(int)),
77 connect(ui->addDesktopFileButton, SIGNAL(clicked()),
78 SLOT(addDesktopFile()));
79 connect(ui->addIconButton, SIGNAL(clicked()), SLOT(addIcon()));
80 handleModelListReset();
84 MaemoDeployStepWidget::~MaemoDeployStepWidget()
89 void MaemoDeployStepWidget::init()
91 ui->deviceConfigComboBox->setModel(m_step->maemotarget()->deviceConfigurationsModel());
92 connect(m_step, SIGNAL(deviceConfigChanged()), SLOT(handleDeviceUpdate()));
94 connect(ui->deviceConfigComboBox, SIGNAL(activated(int)), this,
95 SLOT(setCurrentDeviceConfig(int)));
96 ui->deployToSysrootCheckBox->setChecked(m_step->isDeployToSysrootEnabled());
97 connect(ui->deployToSysrootCheckBox, SIGNAL(toggled(bool)), this,
98 SLOT(setDeployToSysroot(bool)));
99 connect(ui->manageDevConfsLabel, SIGNAL(linkActivated(QString)),
100 SLOT(showDeviceConfigurations()));
103 void MaemoDeployStepWidget::handleDeviceUpdate()
105 const MaemoDeviceConfig::ConstPtr &devConf = m_step->deviceConfig();
106 const MaemoDeviceConfig::Id internalId
107 = MaemoDeviceConfigurations::instance()->internalId(devConf);
108 const int newIndex = m_step->maemotarget()->deviceConfigurationsModel()
109 ->indexForInternalId(internalId);
110 ui->deviceConfigComboBox->setCurrentIndex(newIndex);
111 emit updateSummary();
114 QString MaemoDeployStepWidget::summaryText() const
116 return tr("<b>Deploy to device</b>: %1")
117 .arg(MaemoGlobal::deviceConfigurationName(m_step->deviceConfig()));
120 QString MaemoDeployStepWidget::displayName() const
125 void MaemoDeployStepWidget::setCurrentDeviceConfig(int index)
127 disconnect(m_step, SIGNAL(deviceConfigChanged()), this,
128 SLOT(handleDeviceUpdate()));
129 m_step->setDeviceConfig(index);
130 connect(m_step, SIGNAL(deviceConfigChanged()), SLOT(handleDeviceUpdate()));
134 void MaemoDeployStepWidget::setDeployToSysroot(bool doDeploy)
136 m_step->setDeployToSysrootEnabled(doDeploy);
139 void MaemoDeployStepWidget::handleModelListToBeReset()
141 ui->tableView->reset(); // Otherwise we'll crash if the user is currently editing.
142 ui->tableView->setModel(0);
143 ui->addDesktopFileButton->setEnabled(false);
144 ui->addIconButton->setEnabled(false);
147 void MaemoDeployStepWidget::handleModelListReset()
149 QTC_ASSERT(m_step->deployables()->modelCount() == ui->modelComboBox->count(), return);
150 if (m_step->deployables()->modelCount() > 0) {
151 if (ui->modelComboBox->currentIndex() == -1)
152 ui->modelComboBox->setCurrentIndex(0);
154 setModel(ui->modelComboBox->currentIndex());
158 void MaemoDeployStepWidget::setModel(int row)
160 bool canAddDesktopFile = false;
161 bool canAddIconFile = false;
163 MaemoDeployableListModel *const model
164 = m_step->deployables()->modelAt(row);
165 ui->tableView->setModel(model);
166 ui->tableView->resizeRowsToContents();
167 canAddDesktopFile = model->canAddDesktopFile();
168 canAddIconFile = model->canAddIcon();
170 ui->addDesktopFileButton->setEnabled(canAddDesktopFile);
171 ui->addIconButton->setEnabled(canAddIconFile);
174 void MaemoDeployStepWidget::addDesktopFile()
176 const int modelRow = ui->modelComboBox->currentIndex();
179 MaemoDeployableListModel *const model
180 = m_step->deployables()->modelAt(modelRow);
182 if (!model->addDesktopFile(error)) {
183 QMessageBox::warning(this, tr("Could not create desktop file"),
184 tr("Error creating desktop file: %1").arg(error));
186 ui->addDesktopFileButton->setEnabled(model->canAddDesktopFile());
187 ui->tableView->resizeRowsToContents();
190 void MaemoDeployStepWidget::addIcon()
192 const int modelRow = ui->modelComboBox->currentIndex();
196 MaemoDeployableListModel *const model
197 = m_step->deployables()->modelAt(modelRow);
198 const QString origFilePath = QFileDialog::getOpenFileName(this,
199 tr("Choose Icon (will be scaled to 64x64 pixels, if necessary)"),
200 model->projectDir(), QLatin1String("(*.png)"));
201 if (origFilePath.isEmpty())
203 QPixmap pixmap(origFilePath);
204 if (pixmap.isNull()) {
205 QMessageBox::critical(this, tr("Invalid Icon"),
206 tr("Unable to read image"));
209 const QSize iconSize(64, 64);
210 if (pixmap.size() != iconSize)
211 pixmap = pixmap.scaled(iconSize);
212 const QString newFileName = model->projectName() + QLatin1Char('.')
213 + QFileInfo(origFilePath).suffix();
214 const QString newFilePath = model->projectDir() + QLatin1Char('/')
216 if (!pixmap.save(newFilePath)) {
217 QMessageBox::critical(this, tr("Failed to Save Icon"),
218 tr("Could not save icon to '%1'.").arg(newFilePath));
223 if (!model->addIcon(newFileName, error)) {
224 QMessageBox::critical(this, tr("Could Not Add Icon"),
225 tr("Error adding icon: %1").arg(error));
227 ui->addIconButton->setEnabled(model->canAddIcon());
228 ui->tableView->resizeRowsToContents();
231 void MaemoDeployStepWidget::showDeviceConfigurations()
233 MaemoDeviceConfigurationsSettingsPage *page
234 = MaemoManager::instance().deviceConfigurationsSettingsPage();
235 Core::ICore::instance()->showOptionsDialog(page->category(), page->id());
238 } // namespace Internal
239 } // namespace Qt4ProjectManager