|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "fbfilemodel.h" |
|
19 #include "enginewrapper.h" |
|
20 #include "fbfileentry.h" |
|
21 #include "filebrowsersettings.h" |
|
22 #include "FB.hrh" |
|
23 |
|
24 #include <QModelIndex> |
|
25 #include <QFileIconProvider> |
|
26 |
|
27 /** |
|
28 Constructs a file browser custom system model with the given \a engineWrapper and \a parent. |
|
29 */ |
|
30 FbFileModel::FbFileModel(EngineWrapper *engineWrapper, QObject *parent) : |
|
31 QAbstractListModel(parent), |
|
32 mEngineWrapper(engineWrapper), |
|
33 mFileIconProvider(0) |
|
34 { |
|
35 mFileIconProvider = new QFileIconProvider(); |
|
36 } |
|
37 |
|
38 /** |
|
39 Destroys this file browser custom system model. |
|
40 */ |
|
41 FbFileModel::~FbFileModel() |
|
42 { |
|
43 if (mFileIconProvider) { |
|
44 delete mFileIconProvider; |
|
45 } |
|
46 } |
|
47 |
|
48 /** |
|
49 \reimp |
|
50 */ |
|
51 int FbFileModel::rowCount(const QModelIndex &parent) const |
|
52 { |
|
53 Q_UNUSED(parent); |
|
54 return mEngineWrapper->itemCount(); |
|
55 } |
|
56 |
|
57 /** |
|
58 \reimp |
|
59 */ |
|
60 QVariant FbFileModel::data(const QModelIndex &index, int role) const |
|
61 { |
|
62 if (!index.isValid() || index.model() != this) |
|
63 return QVariant(); |
|
64 |
|
65 switch (role) { |
|
66 case Qt::EditRole: |
|
67 case Qt::DisplayRole: { |
|
68 QStringList listItem; |
|
69 FbFileEntry fileEntry(mEngineWrapper->getFileEntry(index)); |
|
70 if (mEngineWrapper->settings().fileViewMode() == EFileViewModeSimple) |
|
71 { |
|
72 listItem /*<< fileEntry.IconId()*/ |
|
73 << fileEntry.name(); |
|
74 } else if (mEngineWrapper->settings().fileViewMode() == EFileViewModeExtended) { |
|
75 QString extraData; |
|
76 extraData.append(fileEntry.modifiedString()); |
|
77 if (fileEntry.isDir() && fileEntry.dirEntries() >= 0) { |
|
78 extraData.append(" - "); |
|
79 extraData.append(fileEntry.dirEntriesString()); |
|
80 } else if (!fileEntry.isDir()) { |
|
81 extraData.append(" - "); |
|
82 extraData.append(fileEntry.sizeString()); |
|
83 } |
|
84 listItem /*<< fileEntry.IconId()*/ |
|
85 << fileEntry.name() << extraData << fileEntry.attributesString(); |
|
86 } |
|
87 return listItem; |
|
88 } |
|
89 case Qt::DecorationRole: { |
|
90 if (mEngineWrapper) { |
|
91 QIcon icon; |
|
92 FbFileEntry fileEntry(mEngineWrapper->getFileEntry(index)); |
|
93 if (fileEntry.isDir()) { |
|
94 icon = mFileIconProvider->icon(QFileIconProvider::Folder); |
|
95 } else { |
|
96 icon = mFileIconProvider->icon(QFileIconProvider::File); |
|
97 } |
|
98 // } |
|
99 return QVariant(icon); |
|
100 } |
|
101 } |
|
102 } |
|
103 |
|
104 return QVariant(); |
|
105 } |
|
106 |
|
107 /** |
|
108 * Move down to directory selected by index \a index |
|
109 */ |
|
110 void FbFileModel::moveDownToDirectory(const QModelIndex &index) |
|
111 { |
|
112 beginResetModel(); |
|
113 mEngineWrapper->moveDownToDirectory(index); |
|
114 endResetModel(); |
|
115 } |
|
116 |
|
117 /** |
|
118 * Move to directory one level up |
|
119 */ |
|
120 void FbFileModel::moveUpOneLevel() |
|
121 { |
|
122 beginResetModel(); |
|
123 mEngineWrapper->moveUpOneLevel(); |
|
124 endResetModel(); |
|
125 } |
|
126 |
|
127 /** |
|
128 \reimp |
|
129 */ |
|
130 QVariant FbFileModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
131 { |
|
132 Q_UNUSED(section) |
|
133 Q_UNUSED(orientation) |
|
134 Q_UNUSED(role) |
|
135 |
|
136 // TODO, implement or remove |
|
137 return QVariant(); |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |