|
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 "driveentry.h" |
|
21 #include "settingsview.h" |
|
22 #include "filebrowsersettings.h" |
|
23 #include "FB.hrh" |
|
24 |
|
25 #include <QModelIndex> |
|
26 #include <QFileIconProvider> |
|
27 |
|
28 /** |
|
29 Constructs a file browser custom system model with the given \a engineWrapper and \a parent. |
|
30 */ |
|
31 FbDriveModel::FbDriveModel(EngineWrapper *engineWrapper, QObject *parent) : |
|
32 QAbstractListModel(parent), |
|
33 mEngineWrapper(engineWrapper), |
|
34 mFileIconProvider(0) |
|
35 { |
|
36 mFileIconProvider = new QFileIconProvider(); |
|
37 } |
|
38 |
|
39 /** |
|
40 Destroys this file browser custom system model. |
|
41 */ |
|
42 FbDriveModel::~FbDriveModel() |
|
43 { |
|
44 if (mFileIconProvider) { |
|
45 delete mFileIconProvider; |
|
46 } |
|
47 } |
|
48 |
|
49 /** |
|
50 \reimp |
|
51 */ |
|
52 int FbDriveModel::rowCount(const QModelIndex &parent) const |
|
53 { |
|
54 Q_UNUSED(parent); |
|
55 return mEngineWrapper->itemCount(); |
|
56 } |
|
57 |
|
58 /** |
|
59 \reimp |
|
60 */ |
|
61 QVariant FbDriveModel::data(const QModelIndex &index, int role) const |
|
62 { |
|
63 if (!index.isValid() || index.model() != this) |
|
64 return QVariant(); |
|
65 |
|
66 switch (role) { |
|
67 case Qt::EditRole: |
|
68 case Qt::DisplayRole: { |
|
69 QStringList listItem; |
|
70 DriveEntry driveEntry(mEngineWrapper->getDriveEntry(index)); |
|
71 if (mEngineWrapper->settings().fileViewMode() == EFileViewModeSimple) |
|
72 { |
|
73 const QString SimpleDriveEntry("%1: <%2>"); |
|
74 listItem /*<< driveEntry.IconId() */ |
|
75 << SimpleDriveEntry.arg(driveEntry.driveLetter()) |
|
76 .arg(driveEntry.mediaTypeString()); |
|
77 } else if (mEngineWrapper->settings().fileViewMode() == EFileViewModeExtended) { |
|
78 const QString SimpleDriveEntry("%1: <%2>"); |
|
79 const QString ExtendedDriveEntry("%1/%2 kB"); |
|
80 listItem /*<< driveEntry.IconId()*/ |
|
81 << SimpleDriveEntry.arg(driveEntry.driveLetter()) |
|
82 .arg(driveEntry.mediaTypeString()) |
|
83 << ExtendedDriveEntry.arg(QString::number(driveEntry.volumeInfoFree()/1024)) |
|
84 .arg(QString::number(driveEntry.volumeInfoSize()/1024)); |
|
85 |
|
86 } |
|
87 return listItem; |
|
88 } |
|
89 case Qt::DecorationRole: { |
|
90 if (mEngineWrapper) { |
|
91 QIcon icon; |
|
92 //TODO Drive ico has to be provided, for some reason it is not visible |
|
93 icon = mFileIconProvider->icon(QFileIconProvider::Drive); |
|
94 return QVariant(icon); |
|
95 } |
|
96 } |
|
97 } |
|
98 return QVariant(); |
|
99 } |
|
100 |
|
101 /** |
|
102 \reimp |
|
103 */ |
|
104 QVariant FbDriveModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
105 { |
|
106 Q_UNUSED(section); |
|
107 Q_UNUSED(orientation); |
|
108 Q_UNUSED(role); |
|
109 |
|
110 // TODO, implement or remove |
|
111 return QVariant(); |
|
112 } |
|
113 |
|
114 |
|
115 DriveEntry FbDriveModel::driveEntry(const QModelIndex &index) const |
|
116 { |
|
117 return mEngineWrapper->getDriveEntry(index); |
|
118 } |
|
119 |
|
120 QString FbDriveModel::driveLetter(const QModelIndex &index) const |
|
121 { |
|
122 QString diskLetter; |
|
123 if (index.row() >= 0 && index.row() < mEngineWrapper->itemCount()) { |
|
124 DriveEntry driveEntry(mEngineWrapper->getDriveEntry(index)); |
|
125 diskLetter = driveEntry.driveLetter(); |
|
126 } |
|
127 return diskLetter; |
|
128 } |
|
129 |
|
130 QString FbDriveModel::mediaTypeString(const QModelIndex &index) const |
|
131 { |
|
132 QString mediaTypeString; |
|
133 if (index.row() >= 0 && index.row() < mEngineWrapper->itemCount()) { |
|
134 DriveEntry driveEntry(mEngineWrapper->getDriveEntry(index)); |
|
135 mediaTypeString = driveEntry.mediaTypeString(); |
|
136 } |
|
137 return mediaTypeString; |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |