|
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 "fbdrivemodel.h" |
|
19 #include "enginewrapper.h" |
|
20 #include "fbdriveentry.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 FbDriveModel::FbDriveModel(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 FbDriveModel::~FbDriveModel() |
|
42 { |
|
43 if (mFileIconProvider) { |
|
44 delete mFileIconProvider; |
|
45 } |
|
46 } |
|
47 |
|
48 /** |
|
49 \reimp |
|
50 */ |
|
51 int FbDriveModel::rowCount(const QModelIndex &parent) const |
|
52 { |
|
53 Q_UNUSED(parent); |
|
54 return mEngineWrapper->itemCount(); |
|
55 } |
|
56 |
|
57 /** |
|
58 \reimp |
|
59 */ |
|
60 QVariant FbDriveModel::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 FbDriveEntry driveEntry(mEngineWrapper->getDriveEntry(index)); |
|
70 if (mEngineWrapper->settings().fileViewMode() == EFileViewModeSimple) |
|
71 { |
|
72 const QString SimpleDriveEntry("%1: <%2>"); |
|
73 listItem /*<< driveEntry.IconId() */ |
|
74 << SimpleDriveEntry.arg(driveEntry.driveLetter()) |
|
75 .arg(driveEntry.mediaTypeString()); |
|
76 } else if (mEngineWrapper->settings().fileViewMode() == EFileViewModeExtended) { |
|
77 const QString SimpleDriveEntry("%1: <%2>"); |
|
78 const QString ExtendedDriveEntry("%1/%2 kB"); |
|
79 listItem /*<< driveEntry.IconId()*/ |
|
80 << SimpleDriveEntry.arg(driveEntry.driveLetter()) |
|
81 .arg(driveEntry.mediaTypeString()) |
|
82 << ExtendedDriveEntry.arg(QString::number(driveEntry.volumeInfoFree()/1024)) |
|
83 .arg(QString::number(driveEntry.volumeInfoSize()/1024)); |
|
84 |
|
85 } |
|
86 return listItem; |
|
87 } |
|
88 case Qt::DecorationRole: { |
|
89 if (mEngineWrapper) { |
|
90 QIcon icon; |
|
91 //TODO Drive ico has to be provided, for some reason it is not visible |
|
92 icon = mFileIconProvider->icon(QFileIconProvider::Drive); |
|
93 return QVariant(icon); |
|
94 } |
|
95 } |
|
96 } |
|
97 return QVariant(); |
|
98 } |
|
99 |
|
100 /** |
|
101 \reimp |
|
102 */ |
|
103 QVariant FbDriveModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
104 { |
|
105 Q_UNUSED(section); |
|
106 Q_UNUSED(orientation); |
|
107 Q_UNUSED(role); |
|
108 |
|
109 // TODO, implement or remove |
|
110 return QVariant(); |
|
111 } |
|
112 |
|
113 |
|
114 FbDriveEntry FbDriveModel::driveEntry(const QModelIndex &index) const |
|
115 { |
|
116 return mEngineWrapper->getDriveEntry(index); |
|
117 } |
|
118 |
|
119 QString FbDriveModel::driveLetter(const QModelIndex &index) const |
|
120 { |
|
121 QString diskLetter; |
|
122 if (index.row() >= 0 && index.row() < mEngineWrapper->itemCount()) { |
|
123 FbDriveEntry driveEntry(mEngineWrapper->getDriveEntry(index)); |
|
124 diskLetter = driveEntry.driveLetter(); |
|
125 } |
|
126 return diskLetter; |
|
127 } |
|
128 |
|
129 QString FbDriveModel::mediaTypeString(const QModelIndex &index) const |
|
130 { |
|
131 QString mediaTypeString; |
|
132 if (index.row() >= 0 && index.row() < mEngineWrapper->itemCount()) { |
|
133 FbDriveEntry driveEntry(mEngineWrapper->getDriveEntry(index)); |
|
134 mediaTypeString = driveEntry.mediaTypeString(); |
|
135 } |
|
136 return mediaTypeString; |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |