1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of Qt Creator.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
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
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #include "maemodeployables.h"
44 #include "maemoprofilesupdatedialog.h"
46 #include <profileevaluator.h>
47 #include <projectexplorer/buildstep.h>
48 #include <qt4projectmanager/qt4projectmanagerconstants.h>
49 #include <qt4projectmanager/qt4buildconfiguration.h>
50 #include <qt4projectmanager/qt4project.h>
51 #include <qt4projectmanager/qt4target.h>
53 #include <QtCore/QTimer>
55 namespace Qt4ProjectManager {
58 MaemoDeployables::MaemoDeployables(const Qt4Target *target)
59 : m_target(target), m_updateTimer(new QTimer(this))
61 QTimer::singleShot(0, this, SLOT(init()));
62 m_updateTimer->setInterval(1500);
63 connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(createModels()));
66 MaemoDeployables::~MaemoDeployables() {}
68 void MaemoDeployables::init()
70 Qt4Project * const pro = m_target->qt4Project();
71 connect(pro, SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*,bool)),
72 m_updateTimer, SLOT(start()));
74 // TODO do we want to disable the view
79 void MaemoDeployables::createModels()
81 if (m_target->project()->activeTarget() != m_target)
83 const Qt4ProFileNode *const rootNode
84 = m_target->qt4Project()->rootProjectNode();
85 if (!rootNode) // Happens on project creation by wizard.
87 m_updateTimer->stop();
88 disconnect(m_target->qt4Project(),
89 SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*,bool)),
90 m_updateTimer, SLOT(start()));
92 qDeleteAll(m_listModels);
94 createModels(rootNode);
95 QList<MaemoDeployableListModel *> modelsWithoutTargetPath;
96 foreach (MaemoDeployableListModel *const model, m_listModels) {
97 if (!model->hasTargetPath()) {
98 if (model->proFileUpdateSetting() == MaemoDeployableListModel::AskToUpdateProFile)
99 modelsWithoutTargetPath << model;
103 if (!modelsWithoutTargetPath.isEmpty()) {
104 MaemoProFilesUpdateDialog dialog(modelsWithoutTargetPath);
106 const QList<MaemoProFilesUpdateDialog::UpdateSetting> &settings
107 = dialog.getUpdateSettings();
108 foreach (const MaemoProFilesUpdateDialog::UpdateSetting &setting, settings) {
109 const MaemoDeployableListModel::ProFileUpdateSetting updateSetting
111 ? MaemoDeployableListModel::UpdateProFile
112 : MaemoDeployableListModel::DontUpdateProFile;
113 m_updateSettings.insert(setting.first->proFilePath(),
115 setting.first->setProFileUpdateSetting(updateSetting);
120 connect(m_target->qt4Project(),
121 SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*,bool)),
122 m_updateTimer, SLOT(start()));
125 void MaemoDeployables::createModels(const Qt4ProFileNode *proFileNode)
127 switch (proFileNode->projectType()) {
128 case ApplicationTemplate:
129 case LibraryTemplate:
130 case ScriptTemplate: {
131 UpdateSettingsMap::ConstIterator it
132 = m_updateSettings.find(proFileNode->path());
133 const MaemoDeployableListModel::ProFileUpdateSetting updateSetting
134 = it != m_updateSettings.end()
135 ? it.value() : MaemoDeployableListModel::AskToUpdateProFile;
136 MaemoDeployableListModel *const newModel
137 = new MaemoDeployableListModel(proFileNode, updateSetting, this);
138 m_listModels << newModel;
141 case SubDirsTemplate: {
142 const QList<ProjectExplorer::ProjectNode *> &subProjects
143 = proFileNode->subProjectNodes();
144 foreach (const ProjectExplorer::ProjectNode *subProject, subProjects) {
145 const Qt4ProFileNode * const qt4SubProject
146 = qobject_cast<const Qt4ProFileNode *>(subProject);
147 if (qt4SubProject && !qt4SubProject->path()
148 .endsWith(QLatin1String(".pri")))
149 createModels(qt4SubProject);
157 void MaemoDeployables::setUnmodified()
159 foreach (MaemoDeployableListModel *model, m_listModels)
160 model->setUnModified();
163 bool MaemoDeployables::isModified() const
165 foreach (const MaemoDeployableListModel *model, m_listModels) {
166 if (model->isModified())
172 int MaemoDeployables::deployableCount() const
175 foreach (const MaemoDeployableListModel *model, m_listModels)
176 count += model->rowCount();
180 MaemoDeployable MaemoDeployables::deployableAt(int i) const
182 foreach (const MaemoDeployableListModel *model, m_listModels) {
184 if (i < model->rowCount())
185 return model->deployableAt(i);
186 i -= model->rowCount();
189 Q_ASSERT(!"Invalid deployable number");
190 return MaemoDeployable(QString(), QString());
193 QString MaemoDeployables::remoteExecutableFilePath(const QString &localExecutableFilePath) const
195 foreach (const MaemoDeployableListModel *model, m_listModels) {
196 if (model->localExecutableFilePath() == localExecutableFilePath)
197 return model->remoteExecutableFilePath();
202 int MaemoDeployables::rowCount(const QModelIndex &parent) const
204 return parent.isValid() ? 0 : modelCount();
207 QVariant MaemoDeployables::data(const QModelIndex &index, int role) const
209 if (!index.isValid() || index.row() < 0 || index.row() >= modelCount()
210 || index.column() != 0)
212 const MaemoDeployableListModel *const model = m_listModels.at(index.row());
213 if (role == Qt::ForegroundRole && !model->hasTargetPath()) {
215 brush.setColor(Qt::red);
218 if (role == Qt::DisplayRole)
219 return QFileInfo(model->proFilePath()).fileName();
223 } // namespace Qt4ProjectManager
224 } // namespace Internal