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