OSDN Git Service

684860023d1329115509636a02964cf16c6226c5
[qt-creator-jp/qt-creator-jp.git] / src / plugins / qt4projectmanager / qt-maemo / maemopublishedprojectmodel.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 #include "maemopublishedprojectmodel.h"
42
43 #include <QtCore/QFileInfo>
44
45 namespace Qt4ProjectManager {
46 namespace Internal {
47 namespace {
48 const int IncludeColumn = 2;
49 } // anonymous namespace
50
51 MaemoPublishedProjectModel::MaemoPublishedProjectModel(QObject *parent)
52     : QFileSystemModel(parent)
53 {
54     setFilter(filter() | QDir::Hidden | QDir::System);
55 }
56
57 void MaemoPublishedProjectModel::initFilesToExclude()
58 {
59     initFilesToExclude(rootPath());
60 }
61
62 void MaemoPublishedProjectModel::initFilesToExclude(const QString &filePath)
63 {
64     QFileInfo fi(filePath);
65     if (fi.isDir()) {
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);
70     } else {
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);
78         }
79     }
80 }
81
82 int MaemoPublishedProjectModel::columnCount(const QModelIndex &parent) const
83 {
84     Q_UNUSED(parent);
85     return IncludeColumn + 1;
86 }
87
88 int MaemoPublishedProjectModel::rowCount(const QModelIndex &parent) const
89 {
90     if (isDir(parent) && m_filesToExclude.contains(filePath(parent)))
91         return 0;
92     return QFileSystemModel::rowCount(parent);
93 }
94
95 QVariant MaemoPublishedProjectModel::headerData(int section,
96     Qt::Orientation orientation, int role) const
97 {
98     if (orientation != Qt::Horizontal || section != IncludeColumn)
99         return QFileSystemModel::headerData(section, orientation, role);
100     return tr("Include in package");
101 }
102
103 Qt::ItemFlags MaemoPublishedProjectModel::flags(const QModelIndex &index) const
104 {
105     if (index.column() != IncludeColumn)
106         return QFileSystemModel::flags(index);
107     return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
108 }
109
110 QVariant MaemoPublishedProjectModel::data(const QModelIndex &index,
111     int role) const
112 {
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;
120     else
121         return QVariant();
122 }
123
124 bool MaemoPublishedProjectModel::setData(const QModelIndex &index,
125     const QVariant &value, int role)
126 {
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));
132         } else {
133             m_filesToExclude.insert(filePath(index));
134         }
135         if (isDir(index))
136             emit layoutChanged();
137         return true;
138     }
139     return false;
140 }
141
142
143 } // namespace Internal
144 } // namespace Qt4ProjectManager