OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qt-maemo / maemodeployables.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of Qt Creator.
8 **
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
14 ** this package.
15 **
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.
23 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "maemodeployables.h"
43
44 #include "maemoprofilesupdatedialog.h"
45
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>
52
53 #include <QtCore/QTimer>
54
55 namespace Qt4ProjectManager {
56 namespace Internal {
57
58 MaemoDeployables::MaemoDeployables(const Qt4Target *target)
59     : m_target(target), m_updateTimer(new QTimer(this))
60 {
61     QTimer::singleShot(0, this, SLOT(init()));
62     m_updateTimer->setInterval(1500);
63     connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(createModels()));
64 }
65
66 MaemoDeployables::~MaemoDeployables() {}
67
68 void MaemoDeployables::init()
69 {
70     Qt4Project * const pro = m_target->qt4Project();
71     connect(pro, SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*,bool)),
72             m_updateTimer, SLOT(start()));
73
74     // TODO do we want to disable the view
75
76     createModels();
77 }
78
79 void MaemoDeployables::createModels()
80 {
81     if (m_target->project()->activeTarget() != m_target)
82         return;
83     const Qt4ProFileNode *const rootNode
84         = m_target->qt4Project()->rootProjectNode();
85     if (!rootNode) // Happens on project creation by wizard.
86         return;
87     m_updateTimer->stop();
88     disconnect(m_target->qt4Project(),
89         SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*,bool)),
90         m_updateTimer, SLOT(start()));
91     beginResetModel();
92     qDeleteAll(m_listModels);
93     m_listModels.clear();
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;
100         }
101     }
102
103     if (!modelsWithoutTargetPath.isEmpty()) {
104         MaemoProFilesUpdateDialog dialog(modelsWithoutTargetPath);
105         dialog.exec();
106         const QList<MaemoProFilesUpdateDialog::UpdateSetting> &settings
107             = dialog.getUpdateSettings();
108         foreach (const MaemoProFilesUpdateDialog::UpdateSetting &setting, settings) {
109             const MaemoDeployableListModel::ProFileUpdateSetting updateSetting
110                 = setting.second
111                     ? MaemoDeployableListModel::UpdateProFile
112                     : MaemoDeployableListModel::DontUpdateProFile;
113             m_updateSettings.insert(setting.first->proFilePath(),
114                 updateSetting);
115             setting.first->setProFileUpdateSetting(updateSetting);
116         }
117     }
118
119     endResetModel();
120     connect(m_target->qt4Project(),
121             SIGNAL(proFileUpdated(Qt4ProjectManager::Internal::Qt4ProFileNode*,bool)),
122             m_updateTimer, SLOT(start()));
123 }
124
125 void MaemoDeployables::createModels(const Qt4ProFileNode *proFileNode)
126 {
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;
139         break;
140     }
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);
150         }
151     }
152     default:
153         break;
154     }
155 }
156
157 void MaemoDeployables::setUnmodified()
158 {
159     foreach (MaemoDeployableListModel *model, m_listModels)
160         model->setUnModified();
161 }
162
163 bool MaemoDeployables::isModified() const
164 {
165     foreach (const MaemoDeployableListModel *model, m_listModels) {
166         if (model->isModified())
167             return true;
168     }
169     return false;
170 }
171
172 int MaemoDeployables::deployableCount() const
173 {
174     int count = 0;
175     foreach (const MaemoDeployableListModel *model, m_listModels)
176         count += model->rowCount();
177     return count;
178 }
179
180 MaemoDeployable MaemoDeployables::deployableAt(int i) const
181 {
182     foreach (const MaemoDeployableListModel *model, m_listModels) {
183         Q_ASSERT(i >= 0);
184         if (i < model->rowCount())
185             return model->deployableAt(i);
186         i -= model->rowCount();
187     }
188
189     Q_ASSERT(!"Invalid deployable number");
190     return MaemoDeployable(QString(), QString());
191 }
192
193 QString MaemoDeployables::remoteExecutableFilePath(const QString &localExecutableFilePath) const
194 {
195     foreach (const MaemoDeployableListModel *model, m_listModels) {
196         if (model->localExecutableFilePath() == localExecutableFilePath)
197             return model->remoteExecutableFilePath();
198     }
199     return QString();
200 }
201
202 int MaemoDeployables::rowCount(const QModelIndex &parent) const
203 {
204     return parent.isValid() ? 0 : modelCount();
205 }
206
207 QVariant MaemoDeployables::data(const QModelIndex &index, int role) const
208 {
209     if (!index.isValid() || index.row() < 0 || index.row() >= modelCount()
210             || index.column() != 0)
211         return QVariant();
212     const MaemoDeployableListModel *const model = m_listModels.at(index.row());
213     if (role == Qt::ForegroundRole && !model->hasTargetPath()) {
214         QBrush brush;
215         brush.setColor(Qt::red);
216         return brush;
217     }
218     if (role == Qt::DisplayRole)
219         return QFileInfo(model->proFilePath()).fileName();
220     return QVariant();
221 }
222
223 } // namespace Qt4ProjectManager
224 } // namespace Internal