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: Videosortfilterproxymodel implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "videosortfilterproxymodel.h" |
|
19 #include "videosortfilterproxymodeldata.h" |
|
20 #include "videocollectioncommon.h" |
|
21 #include "videolistdatamodel.h" |
|
22 |
|
23 using namespace VideoCollectionCommon; |
|
24 |
|
25 int VideoSortFilterProxyModelData::mSortRole = -1; |
|
26 Qt::SortOrder VideoSortFilterProxyModelData::mSortOrder = Qt::AscendingOrder; |
|
27 bool VideoSortFilterProxyModelData::mSortAsync = false; |
|
28 bool VideoSortFilterProxyModelData::mDeleteItemsFails = false; |
|
29 bool VideoSortFilterProxyModelData::mRemoveAlbumsFails = false; |
|
30 int VideoSortFilterProxyModelData::mDoSortingCallCount = 0; |
|
31 bool VideoSortFilterProxyModelData::mOpenFails = false; |
|
32 QList<TMPXItemId> VideoSortFilterProxyModelData::mItemIds = QList<TMPXItemId>(); |
|
33 QModelIndex VideoSortFilterProxyModelData::mLastIndex = QModelIndex(); |
|
34 TMPXItemId VideoSortFilterProxyModelData::mLastItemId = TMPXItemId::InvalidId(); |
|
35 TMPXItemId VideoSortFilterProxyModelData::mOpenedItemId = TMPXItemId::InvalidId(); |
|
36 int VideoSortFilterProxyModelData::mDetailsReturnValue = 0; |
|
37 int VideoSortFilterProxyModelData::mAddItemsInAlbumReturnValue = 0; |
|
38 int VideoSortFilterProxyModelData::mRemoveItemsFromAlbumReturnValue = 0; |
|
39 TMPXItemId VideoSortFilterProxyModelData::mGenericFilterId = TMPXItemId::InvalidId(); |
|
40 bool VideoSortFilterProxyModelData::mGenericFilterValue = false; |
|
41 TMPXItemId VideoSortFilterProxyModelData::mNewAlbumId = TMPXItemId::InvalidId(); |
|
42 QString VideoSortFilterProxyModelData::mLastItemNameInRename = ""; |
|
43 int VideoSortFilterProxyModelData::mRenameItemReturnValue = 0; |
|
44 QString VideoSortFilterProxyModelData::mLastAddedAlbumName = ""; |
|
45 |
|
46 const TMPXItemId INVALID_ID = TMPXItemId::InvalidId(); |
|
47 |
|
48 VideoSortFilterProxyModel::VideoSortFilterProxyModel(VideoCollectionCommon::TModelType type, QObject *parent): |
|
49 QSortFilterProxyModel(parent), |
|
50 mModel(0), |
|
51 mCollectionClient(0), |
|
52 mType(type), |
|
53 mLevel(VideoCollectionCommon::ELevelInvalid), |
|
54 mIdleSortTimer(0), |
|
55 mWantedSortRole(VideoCollectionCommon::KeyDateTime) |
|
56 { |
|
57 // NOP |
|
58 } |
|
59 |
|
60 VideoSortFilterProxyModel::~VideoSortFilterProxyModel() |
|
61 { |
|
62 VideoSortFilterProxyModelData::reset(); |
|
63 } |
|
64 |
|
65 int VideoSortFilterProxyModel::initialize(VideoListDataModel *sourceModel) |
|
66 { |
|
67 setSourceModel(sourceModel); |
|
68 |
|
69 return 0; |
|
70 } |
|
71 |
|
72 bool VideoSortFilterProxyModel::connectSignals() |
|
73 { |
|
74 // not stubbed |
|
75 return true; |
|
76 } |
|
77 |
|
78 void VideoSortFilterProxyModel::disconnectSignals() |
|
79 { |
|
80 // not stubbed |
|
81 } |
|
82 |
|
83 int VideoSortFilterProxyModel::open(VideoCollectionCommon::TCollectionLevels level) |
|
84 { |
|
85 int err = 0; |
|
86 |
|
87 mLevel = level; |
|
88 if (VideoSortFilterProxyModelData::mOpenFails) |
|
89 { |
|
90 err = -1; |
|
91 } |
|
92 |
|
93 return err; |
|
94 } |
|
95 |
|
96 void VideoSortFilterProxyModel::doSorting(int sortingRole, |
|
97 Qt::SortOrder order, |
|
98 bool async) |
|
99 { |
|
100 VideoSortFilterProxyModelData::mDoSortingCallCount++; |
|
101 VideoSortFilterProxyModelData::mSortRole = sortingRole; |
|
102 VideoSortFilterProxyModelData::mSortOrder = order; |
|
103 VideoSortFilterProxyModelData::mSortAsync = async; |
|
104 setSortRole(sortingRole); |
|
105 sort(0, order); |
|
106 } |
|
107 |
|
108 void VideoSortFilterProxyModel::getSorting(int &sortingRole, |
|
109 Qt::SortOrder &order) |
|
110 { |
|
111 sortingRole = VideoSortFilterProxyModelData::mSortRole; |
|
112 order = VideoSortFilterProxyModelData::mSortOrder; |
|
113 } |
|
114 |
|
115 int VideoSortFilterProxyModel::deleteItems(const QModelIndexList &indexList) |
|
116 { |
|
117 |
|
118 int err = 0; |
|
119 if (VideoSortFilterProxyModelData::mDeleteItemsFails) |
|
120 { |
|
121 err = -1; |
|
122 } |
|
123 else |
|
124 { |
|
125 if (indexList.count() > 0) |
|
126 { |
|
127 VideoSortFilterProxyModelData::mLastIndex = indexList.at(0); |
|
128 } |
|
129 } |
|
130 |
|
131 return err; |
|
132 } |
|
133 |
|
134 int VideoSortFilterProxyModel::openItem(TMPXItemId mediaId) |
|
135 { |
|
136 VideoSortFilterProxyModelData::mLastItemId = mediaId; |
|
137 |
|
138 return 0; |
|
139 } |
|
140 |
|
141 int VideoSortFilterProxyModel::back() |
|
142 { |
|
143 // not stubbed |
|
144 return 0; |
|
145 } |
|
146 |
|
147 int VideoSortFilterProxyModel::fetchItemDetails(const QModelIndex &index) |
|
148 { |
|
149 VideoSortFilterProxyModelData::mLastIndex = index; |
|
150 |
|
151 return VideoSortFilterProxyModelData::mDetailsReturnValue; |
|
152 } |
|
153 |
|
154 void VideoSortFilterProxyModel::processSorting() |
|
155 { |
|
156 // not stubbed |
|
157 } |
|
158 |
|
159 void VideoSortFilterProxyModel::albumChangedSlot() |
|
160 { |
|
161 // not stubbed |
|
162 } |
|
163 |
|
164 bool VideoSortFilterProxyModel::lessThan(const QModelIndex &left, |
|
165 const QModelIndex &right) const |
|
166 { |
|
167 Q_UNUSED(left); |
|
168 Q_UNUSED(right); |
|
169 // not stubbed |
|
170 return true; |
|
171 } |
|
172 |
|
173 bool VideoSortFilterProxyModel::filterAcceptsRow (int source_row, |
|
174 const QModelIndex &source_parent) const |
|
175 { |
|
176 Q_UNUSED(source_row); |
|
177 Q_UNUSED(source_parent); |
|
178 // not stubbed |
|
179 return true; |
|
180 } |
|
181 |
|
182 const TMPXItemId& VideoSortFilterProxyModel::getMediaIdAtIndex( |
|
183 const QModelIndex &index) const |
|
184 { |
|
185 if (index.row() >= 0 && |
|
186 index.row() < VideoSortFilterProxyModelData::mItemIds.count()) |
|
187 { |
|
188 return VideoSortFilterProxyModelData::mItemIds[index.row()]; |
|
189 } |
|
190 return INVALID_ID; |
|
191 } |
|
192 |
|
193 QModelIndex VideoSortFilterProxyModel::indexOfId(const TMPXItemId &id) |
|
194 { |
|
195 //VideoListDataModel *sourceModel = qobject_cast<VideoListDataModel*>(sourceModel()); |
|
196 |
|
197 for(int i = 0; i < VideoSortFilterProxyModelData::mItemIds.count(); i++) |
|
198 { |
|
199 if(VideoSortFilterProxyModelData::mItemIds.at(i) == id) |
|
200 { |
|
201 //return sourceModel->index(i, 0); |
|
202 return index(i, 0); |
|
203 } |
|
204 } |
|
205 return QModelIndex(); |
|
206 } |
|
207 |
|
208 QString VideoSortFilterProxyModel::getMediaFilePathForId(const TMPXItemId &mediaId) |
|
209 { |
|
210 Q_UNUSED(mediaId); |
|
211 // not stubbed |
|
212 return QString(); |
|
213 } |
|
214 |
|
215 TModelType VideoSortFilterProxyModel::getType() |
|
216 { |
|
217 return mType; |
|
218 } |
|
219 |
|
220 TMPXItemId VideoSortFilterProxyModel::addNewAlbum(const QString &title) |
|
221 { |
|
222 VideoSortFilterProxyModelData::mLastAddedAlbumName = title; |
|
223 return VideoSortFilterProxyModelData::mNewAlbumId; |
|
224 } |
|
225 |
|
226 QString VideoSortFilterProxyModel::resolveAlbumName( |
|
227 const QString& albumName) const |
|
228 { |
|
229 QString name = albumName; |
|
230 return name; |
|
231 } |
|
232 |
|
233 int VideoSortFilterProxyModel::addItemsInAlbum(TMPXItemId &albumId, const QList<TMPXItemId> &mediaIds) |
|
234 { |
|
235 if(VideoSortFilterProxyModelData::mAddItemsInAlbumReturnValue >= 0) |
|
236 { |
|
237 VideoSortFilterProxyModelData::mLastItemId = albumId; |
|
238 VideoSortFilterProxyModelData::mItemIds.clear(); |
|
239 VideoSortFilterProxyModelData::mItemIds = mediaIds; |
|
240 } |
|
241 // not stubbed |
|
242 return VideoSortFilterProxyModelData::mAddItemsInAlbumReturnValue; |
|
243 } |
|
244 |
|
245 int VideoSortFilterProxyModel::removeAlbums(const QModelIndexList &indexList) |
|
246 { |
|
247 |
|
248 int err = 0; |
|
249 if (VideoSortFilterProxyModelData::mRemoveAlbumsFails) |
|
250 { |
|
251 err = -1; |
|
252 } |
|
253 else |
|
254 { |
|
255 if (indexList.count() > 0) |
|
256 { |
|
257 VideoSortFilterProxyModelData::mLastIndex = indexList.at(0); |
|
258 } |
|
259 } |
|
260 |
|
261 return err; |
|
262 } |
|
263 |
|
264 int VideoSortFilterProxyModel::removeItemsFromAlbum(class TMPXItemId &album, QList<class TMPXItemId> const &mediaIds) |
|
265 { |
|
266 if(VideoSortFilterProxyModelData::mRemoveItemsFromAlbumReturnValue >= 0) |
|
267 { |
|
268 VideoSortFilterProxyModelData::mLastItemId = album; |
|
269 VideoSortFilterProxyModelData::mItemIds.clear(); |
|
270 VideoSortFilterProxyModelData::mItemIds = mediaIds; |
|
271 } |
|
272 return VideoSortFilterProxyModelData::mRemoveItemsFromAlbumReturnValue; |
|
273 } |
|
274 |
|
275 void VideoSortFilterProxyModel::setAlbumInUse(const TMPXItemId &albumId) |
|
276 { |
|
277 VideoSortFilterProxyModelData::mLastItemId = albumId; |
|
278 } |
|
279 |
|
280 int VideoSortFilterProxyModel::renameItem(const TMPXItemId &itemId, const QString &newTitle) |
|
281 { |
|
282 if(VideoSortFilterProxyModelData::mRemoveItemsFromAlbumReturnValue >= 0) |
|
283 { |
|
284 VideoSortFilterProxyModelData::mLastItemId = itemId; |
|
285 VideoSortFilterProxyModelData::mLastItemNameInRename = newTitle; |
|
286 |
|
287 } |
|
288 return VideoSortFilterProxyModelData::mRenameItemReturnValue; |
|
289 } |
|
290 |
|
291 TMPXItemId VideoSortFilterProxyModel::getOpenItem() const |
|
292 { |
|
293 return VideoSortFilterProxyModelData::mOpenedItemId; |
|
294 } |
|
295 |
|
296 void VideoSortFilterProxyModel::setGenericIdFilter(const TMPXItemId &itemId, bool filterValue) |
|
297 { |
|
298 VideoSortFilterProxyModelData::mGenericFilterId = itemId; |
|
299 VideoSortFilterProxyModelData::mGenericFilterValue = filterValue; |
|
300 return; |
|
301 } |
|
302 |
|
303 // end of file |
|