1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "maemodeploystepwidget.h"
34 #include "ui_maemodeploystepwidget.h"
36 #include "maemodeploystep.h"
37 #include "maemodeployablelistmodel.h"
38 #include "maemodeployables.h"
39 #include "maemodeviceconfigurations.h"
40 #include "maemosettingspages.h"
41 #include "maemoglobal.h"
42 #include "maemomanager.h"
43 #include "maemopertargetdeviceconfigurationlistmodel.h"
44 #include "maemorunconfiguration.h"
45 #include "qt4maemotarget.h"
47 #include <coreplugin/icore.h>
48 #include <projectexplorer/buildconfiguration.h>
49 #include <projectexplorer/target.h>
50 #include <utils/qtcassert.h>
52 #include <QtGui/QFileDialog>
53 #include <QtGui/QMessageBox>
54 #include <QtGui/QPixmap>
56 namespace Qt4ProjectManager {
59 MaemoDeployStepWidget::MaemoDeployStepWidget(MaemoDeployStep *step) :
60 ProjectExplorer::BuildStepConfigWidget(),
61 ui(new Ui::MaemoDeployStepWidget),
65 ui->modelComboBox->setModel(m_step->deployables().data());
66 connect(m_step->deployables().data(), SIGNAL(modelAboutToBeReset()),
67 SLOT(handleModelListToBeReset()));
69 // Queued connection because of race condition with combo box's reaction
71 connect(m_step->deployables().data(), SIGNAL(modelReset()),
72 SLOT(handleModelListReset()), Qt::QueuedConnection);
74 connect(ui->modelComboBox, SIGNAL(currentIndexChanged(int)),
76 connect(ui->addDesktopFileButton, SIGNAL(clicked()),
77 SLOT(addDesktopFile()));
78 connect(ui->addIconButton, SIGNAL(clicked()), SLOT(addIcon()));
79 handleModelListReset();
83 MaemoDeployStepWidget::~MaemoDeployStepWidget()
88 void MaemoDeployStepWidget::init()
90 ui->deviceConfigComboBox->setModel(m_step->maemotarget()->deviceConfigurationsModel());
91 connect(m_step, SIGNAL(deviceConfigChanged()), SLOT(handleDeviceUpdate()));
93 connect(ui->deviceConfigComboBox, SIGNAL(activated(int)), this,
94 SLOT(setCurrentDeviceConfig(int)));
95 ui->deployToSysrootCheckBox->setChecked(m_step->isDeployToSysrootEnabled());
96 connect(ui->deployToSysrootCheckBox, SIGNAL(toggled(bool)), this,
97 SLOT(setDeployToSysroot(bool)));
98 connect(ui->manageDevConfsLabel, SIGNAL(linkActivated(QString)),
99 SLOT(showDeviceConfigurations()));
102 void MaemoDeployStepWidget::handleDeviceUpdate()
104 const MaemoDeviceConfig::ConstPtr &devConf = m_step->deviceConfig();
105 const MaemoDeviceConfig::Id internalId
106 = MaemoDeviceConfigurations::instance()->internalId(devConf);
107 const int newIndex = m_step->maemotarget()->deviceConfigurationsModel()
108 ->indexForInternalId(internalId);
109 ui->deviceConfigComboBox->setCurrentIndex(newIndex);
110 emit updateSummary();
113 QString MaemoDeployStepWidget::summaryText() const
115 return tr("<b>Deploy to device</b>: %1")
116 .arg(MaemoGlobal::deviceConfigurationName(m_step->deviceConfig()));
119 QString MaemoDeployStepWidget::displayName() const
124 void MaemoDeployStepWidget::setCurrentDeviceConfig(int index)
126 disconnect(m_step, SIGNAL(deviceConfigChanged()), this,
127 SLOT(handleDeviceUpdate()));
128 m_step->setDeviceConfig(index);
129 connect(m_step, SIGNAL(deviceConfigChanged()), SLOT(handleDeviceUpdate()));
133 void MaemoDeployStepWidget::setDeployToSysroot(bool doDeploy)
135 m_step->setDeployToSysrootEnabled(doDeploy);
138 void MaemoDeployStepWidget::handleModelListToBeReset()
140 ui->tableView->reset(); // Otherwise we'll crash if the user is currently editing.
141 ui->tableView->setModel(0);
142 ui->addDesktopFileButton->setEnabled(false);
143 ui->addIconButton->setEnabled(false);
146 void MaemoDeployStepWidget::handleModelListReset()
148 QTC_ASSERT(m_step->deployables()->modelCount() == ui->modelComboBox->count(), return);
149 if (m_step->deployables()->modelCount() > 0) {
150 if (ui->modelComboBox->currentIndex() == -1)
151 ui->modelComboBox->setCurrentIndex(0);
153 setModel(ui->modelComboBox->currentIndex());
157 void MaemoDeployStepWidget::setModel(int row)
159 bool canAddDesktopFile = false;
160 bool canAddIconFile = false;
162 MaemoDeployableListModel *const model
163 = m_step->deployables()->modelAt(row);
164 ui->tableView->setModel(model);
165 ui->tableView->resizeRowsToContents();
166 canAddDesktopFile = model->canAddDesktopFile();
167 canAddIconFile = model->canAddIcon();
169 ui->addDesktopFileButton->setEnabled(canAddDesktopFile);
170 ui->addIconButton->setEnabled(canAddIconFile);
173 void MaemoDeployStepWidget::addDesktopFile()
175 const int modelRow = ui->modelComboBox->currentIndex();
178 MaemoDeployableListModel *const model
179 = m_step->deployables()->modelAt(modelRow);
181 if (!model->addDesktopFile(error)) {
182 QMessageBox::warning(this, tr("Could not create desktop file"),
183 tr("Error creating desktop file: %1").arg(error));
185 ui->addDesktopFileButton->setEnabled(model->canAddDesktopFile());
186 ui->tableView->resizeRowsToContents();
189 void MaemoDeployStepWidget::addIcon()
191 const int modelRow = ui->modelComboBox->currentIndex();
195 MaemoDeployableListModel *const model
196 = m_step->deployables()->modelAt(modelRow);
197 const QString origFilePath = QFileDialog::getOpenFileName(this,
198 tr("Choose Icon (will be scaled to 64x64 pixels, if necessary)"),
199 model->projectDir(), QLatin1String("(*.png)"));
200 if (origFilePath.isEmpty())
202 QPixmap pixmap(origFilePath);
203 if (pixmap.isNull()) {
204 QMessageBox::critical(this, tr("Invalid Icon"),
205 tr("Unable to read image"));
208 const QSize iconSize(64, 64);
209 if (pixmap.size() != iconSize)
210 pixmap = pixmap.scaled(iconSize);
211 const QString newFileName = model->projectName() + QLatin1Char('.')
212 + QFileInfo(origFilePath).suffix();
213 const QString newFilePath = model->projectDir() + QLatin1Char('/')
215 if (!pixmap.save(newFilePath)) {
216 QMessageBox::critical(this, tr("Failed to Save Icon"),
217 tr("Could not save icon to '%1'.").arg(newFilePath));
222 if (!model->addIcon(newFileName, error)) {
223 QMessageBox::critical(this, tr("Could Not Add Icon"),
224 tr("Error adding icon: %1").arg(error));
226 ui->addIconButton->setEnabled(model->canAddIcon());
227 ui->tableView->resizeRowsToContents();
230 void MaemoDeployStepWidget::showDeviceConfigurations()
232 MaemoDeviceConfigurationsSettingsPage *page
233 = MaemoManager::instance().deviceConfigurationsSettingsPage();
234 Core::ICore::instance()->showOptionsDialog(page->category(), page->id());
237 } // namespace Internal
238 } // namespace Qt4ProjectManager