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 ****************************************************************************/
41 #include "maemopublishedprojectmodel.h"
43 #include <QtCore/QFileInfo>
45 namespace Qt4ProjectManager {
48 const int IncludeColumn = 2;
49 } // anonymous namespace
51 MaemoPublishedProjectModel::MaemoPublishedProjectModel(QObject *parent)
52 : QFileSystemModel(parent)
54 setFilter(filter() | QDir::Hidden | QDir::System);
57 void MaemoPublishedProjectModel::initFilesToExclude()
59 initFilesToExclude(rootPath());
62 void MaemoPublishedProjectModel::initFilesToExclude(const QString &filePath)
64 QFileInfo fi(filePath);
66 const QStringList fileNames = QDir(filePath).entryList(QDir::Files
67 | QDir::Dirs | QDir::NoDotAndDotDot | QDir::System | QDir::Hidden);
68 foreach (const QString &fileName, fileNames)
69 initFilesToExclude(filePath + QLatin1Char('/') + fileName);
71 const QString &fileName = fi.fileName();
72 if (fi.isHidden() || fileName.endsWith(QLatin1String(".o"))
73 || fileName == QLatin1String("Makefile")
74 || fileName.contains(QLatin1String(".pro.user"))
75 || fileName.contains(QLatin1String(".so"))
76 || fileName.endsWith(QLatin1String(".a"))) {
77 m_filesToExclude.insert(filePath);
82 int MaemoPublishedProjectModel::columnCount(const QModelIndex &parent) const
85 return IncludeColumn + 1;
88 int MaemoPublishedProjectModel::rowCount(const QModelIndex &parent) const
90 if (isDir(parent) && m_filesToExclude.contains(filePath(parent)))
92 return QFileSystemModel::rowCount(parent);
95 QVariant MaemoPublishedProjectModel::headerData(int section,
96 Qt::Orientation orientation, int role) const
98 if (orientation != Qt::Horizontal || section != IncludeColumn)
99 return QFileSystemModel::headerData(section, orientation, role);
100 return tr("Include in package");
103 Qt::ItemFlags MaemoPublishedProjectModel::flags(const QModelIndex &index) const
105 if (index.column() != IncludeColumn)
106 return QFileSystemModel::flags(index);
107 return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
110 QVariant MaemoPublishedProjectModel::data(const QModelIndex &index,
113 if (index.column() != IncludeColumn)
114 return QFileSystemModel::data(index, role);
115 const bool include = !m_filesToExclude.contains(filePath(index));
116 if (role == Qt::DisplayRole)
117 return include ? tr("Include") : tr("Do not include");
118 else if (role == Qt::CheckStateRole)
119 return include ? Qt::Checked : Qt::Unchecked;
124 bool MaemoPublishedProjectModel::setData(const QModelIndex &index,
125 const QVariant &value, int role)
127 if (index.column() != IncludeColumn)
128 return QFileSystemModel::setData(index, value, role);
129 if (role == Qt::CheckStateRole) {
130 if (value == Qt::Checked) {
131 m_filesToExclude.remove(filePath(index));
133 m_filesToExclude.insert(filePath(index));
136 emit layoutChanged();
143 } // namespace Internal
144 } // namespace Qt4ProjectManager