34
|
1 |
/**
|
|
2 |
* Copyright (c) 2009 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: Stub model to be used when unit testing videocollectionsortfilterproxy
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDES
|
|
20 |
#include "videocollectionclient.h"
|
|
21 |
#include "videolistdatamodel.h"
|
|
22 |
|
|
23 |
bool VideoListDataModel::mInitFails = false;
|
|
24 |
bool VideoListDataModel::mRemoveRowsFails = false;
|
|
25 |
bool VideoListDataModel::mGetMediaIdAtIndexFails = false;
|
|
26 |
bool VideoListDataModel::mBelongsToAlbum = false;
|
|
27 |
bool VideoListDataModel::mReturnInvalid = false;
|
35
|
28 |
int VideoListDataModel::mRemoveFrAlbumReturn = -1;
|
34
|
29 |
int VideoListDataModel::mLastDeletedIndexRow = -1;
|
|
30 |
QString VideoListDataModel::mMediaFilePathReturnValue = "";
|
|
31 |
|
|
32 |
// ---------------------------------------------------------------------------
|
|
33 |
// VideoListDataModel
|
|
34 |
// ---------------------------------------------------------------------------
|
|
35 |
//
|
|
36 |
VideoListDataModel::VideoListDataModel(QObject *parent) :
|
|
37 |
QAbstractItemModel(parent),
|
|
38 |
mCollectionClient(0)
|
|
39 |
{
|
|
40 |
|
|
41 |
}
|
|
42 |
|
|
43 |
// ---------------------------------------------------------------------------
|
|
44 |
// ~VideoListDataModel
|
|
45 |
// ---------------------------------------------------------------------------
|
|
46 |
//
|
|
47 |
VideoListDataModel::~VideoListDataModel()
|
|
48 |
{
|
|
49 |
removeAll();
|
|
50 |
|
|
51 |
delete mCollectionClient;
|
|
52 |
}
|
|
53 |
|
|
54 |
// -----------------------------------------------------------------------------
|
|
55 |
// initialize
|
|
56 |
// -----------------------------------------------------------------------------
|
|
57 |
//
|
|
58 |
int VideoListDataModel::initialize()
|
|
59 |
{
|
|
60 |
if(mInitFails)
|
|
61 |
{
|
|
62 |
return -1;
|
|
63 |
}
|
|
64 |
return 0;
|
|
65 |
}
|
|
66 |
|
|
67 |
// ---------------------------------------------------------------------------
|
|
68 |
// mediaIdAtIndex
|
|
69 |
// ---------------------------------------------------------------------------
|
|
70 |
//
|
|
71 |
TMPXItemId VideoListDataModel::mediaIdAtIndex(int index) const
|
|
72 |
{
|
|
73 |
TMPXItemId id = TMPXItemId::InvalidId();
|
|
74 |
if( mGetMediaIdAtIndexFails || index < 0 || index >= mData.count())
|
|
75 |
{
|
|
76 |
return id;
|
|
77 |
}
|
|
78 |
|
|
79 |
id = mData.at(index)->mId;
|
|
80 |
|
|
81 |
return id;
|
|
82 |
}
|
|
83 |
|
|
84 |
// ---------------------------------------------------------------------------
|
|
85 |
// mediaFilePathForId
|
|
86 |
// ---------------------------------------------------------------------------
|
|
87 |
//
|
|
88 |
QString VideoListDataModel::mediaFilePathForId(int mediaId) const
|
|
89 |
{
|
|
90 |
Q_UNUSED(mediaId);
|
|
91 |
return mMediaFilePathReturnValue;
|
|
92 |
}
|
|
93 |
|
|
94 |
// ---------------------------------------------------------------------------
|
|
95 |
// removeRows
|
|
96 |
// ---------------------------------------------------------------------------
|
|
97 |
//
|
|
98 |
bool VideoListDataModel::removeRows(const QModelIndexList &indexList)
|
|
99 |
{
|
|
100 |
mLastDeletedIndexRow = -1;
|
|
101 |
if( mRemoveRowsFails )
|
|
102 |
return false;
|
|
103 |
else
|
|
104 |
{
|
|
105 |
if(indexList.count() > 0)
|
|
106 |
{
|
|
107 |
mLastDeletedIndexRow = indexList.at(indexList.count() - 1).row();
|
|
108 |
}
|
|
109 |
QModelIndexList sortable(indexList);
|
|
110 |
qSort(sortable);
|
|
111 |
QModelIndexList::const_iterator iter = sortable.constEnd();
|
|
112 |
QModelIndex index;
|
|
113 |
while(iter != sortable.constBegin())
|
|
114 |
{
|
|
115 |
iter--;
|
|
116 |
index = (*iter);
|
|
117 |
beginRemoveRows(QModelIndex(), index.row(), index.row());
|
|
118 |
|
|
119 |
delete mData.at(index.row());
|
|
120 |
mData.removeAt(index.row());
|
|
121 |
|
|
122 |
endRemoveRows();
|
|
123 |
}
|
|
124 |
|
|
125 |
return true;
|
|
126 |
}
|
|
127 |
}
|
|
128 |
|
|
129 |
// ---------------------------------------------------------------------------
|
|
130 |
// getCollectionClient
|
|
131 |
// ---------------------------------------------------------------------------
|
|
132 |
//
|
|
133 |
VideoCollectionClient* VideoListDataModel::getCollectionClient()
|
|
134 |
{
|
|
135 |
if(!this->mCollectionClient)
|
|
136 |
{
|
|
137 |
mCollectionClient = new VideoCollectionClient();
|
|
138 |
}
|
|
139 |
return mCollectionClient;
|
|
140 |
}
|
|
141 |
|
|
142 |
// ---------------------------------------------------------------------------
|
|
143 |
// rowCount
|
|
144 |
// ---------------------------------------------------------------------------
|
|
145 |
//
|
|
146 |
int VideoListDataModel::rowCount(const QModelIndex &parent) const
|
|
147 |
{
|
|
148 |
if (parent.isValid())
|
|
149 |
{
|
|
150 |
return 0;
|
|
151 |
}
|
|
152 |
return mData.count();
|
|
153 |
}
|
|
154 |
|
|
155 |
// ---------------------------------------------------------------------------
|
|
156 |
// itemData
|
|
157 |
// ---------------------------------------------------------------------------
|
|
158 |
//
|
|
159 |
QMap<int, QVariant> VideoListDataModel::itemData(const QModelIndex &index) const
|
|
160 |
{
|
|
161 |
Q_UNUSED(index);
|
|
162 |
QMap<int, QVariant> itemData;
|
|
163 |
|
|
164 |
return itemData;
|
|
165 |
}
|
|
166 |
|
|
167 |
// ---------------------------------------------------------------------------
|
|
168 |
// data
|
|
169 |
// ---------------------------------------------------------------------------
|
|
170 |
//
|
|
171 |
QVariant VideoListDataModel::data(const QModelIndex & index, int role) const
|
|
172 |
{
|
|
173 |
QVariant returnValue = QVariant();
|
|
174 |
if(!index.isValid())
|
|
175 |
{
|
|
176 |
return returnValue;
|
|
177 |
}
|
|
178 |
if(mReturnInvalid)
|
|
179 |
{
|
|
180 |
return returnValue;
|
|
181 |
}
|
|
182 |
int row = index.row();
|
36
|
183 |
if(role == VideoCollectionCommon::KeyTitle)
|
34
|
184 |
{
|
|
185 |
if(row >= 0 && row < mData.count())
|
|
186 |
{
|
|
187 |
returnValue = mData.at(row)->mName;
|
|
188 |
}
|
|
189 |
}
|
36
|
190 |
else if(role == VideoCollectionCommon::KeySizeValue ||
|
|
191 |
role == VideoCollectionCommon::KeyNumberOfItems)
|
34
|
192 |
{
|
|
193 |
if(row >= 0 && row < mData.count())
|
|
194 |
{
|
|
195 |
returnValue = mData.at(row)->mSize;
|
|
196 |
}
|
|
197 |
}
|
|
198 |
else if(role == VideoCollectionCommon::KeyDateTime)
|
|
199 |
{
|
|
200 |
if(row >= 0 && row < mData.count())
|
|
201 |
{
|
|
202 |
returnValue = mData.at(row)->mDate;
|
|
203 |
}
|
|
204 |
}
|
|
205 |
else if(role == VideoCollectionCommon::KeyStatus)
|
|
206 |
{
|
|
207 |
if(row >= 0 && row < mData.count())
|
|
208 |
{
|
|
209 |
returnValue = mData.at(row)->mStatus;
|
|
210 |
}
|
|
211 |
}
|
|
212 |
else if(role == INVALID_ROLE_FOR_SORTING)
|
|
213 |
{
|
|
214 |
if(row >= 0 && row < mData.count())
|
|
215 |
{
|
|
216 |
returnValue = mData.at(row)->mName;
|
|
217 |
}
|
|
218 |
}
|
|
219 |
return returnValue;
|
|
220 |
}
|
|
221 |
|
|
222 |
// ---------------------------------------------------------------------------
|
|
223 |
// columnCount
|
|
224 |
// ---------------------------------------------------------------------------
|
|
225 |
//
|
|
226 |
int VideoListDataModel::columnCount(const QModelIndex & parent) const
|
|
227 |
{
|
|
228 |
if (parent.isValid())
|
|
229 |
{
|
|
230 |
return 0;
|
|
231 |
}
|
|
232 |
else
|
|
233 |
{
|
|
234 |
return 1;
|
|
235 |
}
|
|
236 |
}
|
|
237 |
|
|
238 |
// ---------------------------------------------------------------------------
|
|
239 |
// index
|
|
240 |
// ---------------------------------------------------------------------------
|
|
241 |
//
|
|
242 |
QModelIndex VideoListDataModel::index(int row, int column, const QModelIndex & parent) const
|
|
243 |
{
|
|
244 |
Q_UNUSED(parent);
|
|
245 |
if(row >= 0 && row < mData.count())
|
|
246 |
{
|
|
247 |
return createIndex(row, column);
|
|
248 |
}
|
|
249 |
return QModelIndex();
|
|
250 |
}
|
|
251 |
|
|
252 |
// ---------------------------------------------------------------------------
|
|
253 |
// parent
|
|
254 |
// ---------------------------------------------------------------------------
|
|
255 |
//
|
|
256 |
QModelIndex VideoListDataModel::parent(const QModelIndex & index) const
|
|
257 |
{
|
|
258 |
Q_UNUSED(index);
|
|
259 |
return QModelIndex();
|
|
260 |
}
|
|
261 |
|
|
262 |
void VideoListDataModel::removeAll()
|
|
263 |
{
|
|
264 |
beginRemoveRows(QModelIndex(), 0,0);
|
|
265 |
QList<DummyData*>::iterator iter = mData.begin();
|
|
266 |
while(iter != mData.end())
|
|
267 |
{
|
|
268 |
delete *iter;
|
|
269 |
++iter;
|
|
270 |
}
|
|
271 |
mData.clear();
|
|
272 |
endRemoveRows();
|
|
273 |
}
|
|
274 |
|
|
275 |
|
|
276 |
// ---------------------------------------------------------------------------
|
|
277 |
// emitAlbumChanged
|
|
278 |
// ---------------------------------------------------------------------------
|
|
279 |
//
|
|
280 |
void VideoListDataModel::emitAlbumChanged()
|
|
281 |
{
|
|
282 |
emit albumChanged();
|
|
283 |
}
|
|
284 |
|
|
285 |
// ---------------------------------------------------------------------------
|
|
286 |
// appendData
|
|
287 |
// ---------------------------------------------------------------------------
|
|
288 |
//
|
|
289 |
void VideoListDataModel::appendData(TMPXItemId data)
|
|
290 |
{
|
|
291 |
DummyData* obj;
|
|
292 |
for(int i = 0; i < mData.count(); ++i)
|
|
293 |
{
|
|
294 |
obj = mData.at(i);
|
|
295 |
if(obj->mId == TMPXItemId::InvalidId() || obj->mId.iId1 == data.iId1)
|
|
296 |
{
|
|
297 |
obj->mId = data;
|
|
298 |
QModelIndex change = index(i,0);
|
|
299 |
emit dataChanged(change, change);
|
|
300 |
return;
|
|
301 |
}
|
|
302 |
}
|
|
303 |
beginInsertRows(QModelIndex(), mData.count(), mData.count());
|
|
304 |
obj = new DummyData;
|
|
305 |
obj->mId = data;
|
|
306 |
mData.append(obj);
|
|
307 |
endInsertRows();
|
|
308 |
}
|
|
309 |
|
|
310 |
|
|
311 |
// ---------------------------------------------------------------------------
|
|
312 |
// appendData
|
|
313 |
// ---------------------------------------------------------------------------
|
|
314 |
//
|
|
315 |
void VideoListDataModel::appendData(QString data)
|
|
316 |
{
|
|
317 |
DummyData* obj;
|
|
318 |
for(int i = 0; i < mData.count(); ++i)
|
|
319 |
{
|
|
320 |
obj = mData.at(i);
|
|
321 |
if(!obj->mName.length())
|
|
322 |
{
|
|
323 |
obj->mName = data;
|
|
324 |
QModelIndex change = index(i,0);
|
|
325 |
emit dataChanged(change, change);
|
|
326 |
return;
|
|
327 |
}
|
|
328 |
}
|
|
329 |
beginInsertRows(QModelIndex(), mData.count(), mData.count());
|
|
330 |
obj = new DummyData;
|
|
331 |
obj->mId = TMPXItemId( mData.count(), 0);
|
|
332 |
obj->mName = data;
|
|
333 |
mData.append(obj);
|
|
334 |
endInsertRows();
|
|
335 |
}
|
|
336 |
|
|
337 |
// ---------------------------------------------------------------------------
|
|
338 |
// appendData
|
|
339 |
// ---------------------------------------------------------------------------
|
|
340 |
//
|
|
341 |
void VideoListDataModel::appendData(uint data)
|
|
342 |
{
|
|
343 |
DummyData* obj;
|
|
344 |
for(int i = 0; i < mData.count(); ++i)
|
|
345 |
{
|
|
346 |
obj = mData.at(i);
|
|
347 |
if(obj->mSize == 666)
|
|
348 |
{
|
|
349 |
obj->mSize = data;
|
|
350 |
QModelIndex change = index(i,0);
|
|
351 |
emit dataChanged(change, change);
|
|
352 |
return;
|
|
353 |
}
|
|
354 |
}
|
|
355 |
beginInsertRows(QModelIndex(), mData.count(), mData.count());
|
|
356 |
obj = new DummyData;
|
|
357 |
obj->mId = TMPXItemId( mData.count(), 0);
|
|
358 |
obj->mSize = data;
|
|
359 |
mData.append(obj);
|
|
360 |
endInsertRows();
|
|
361 |
}
|
|
362 |
|
|
363 |
// ---------------------------------------------------------------------------
|
|
364 |
// appendData
|
|
365 |
// ---------------------------------------------------------------------------
|
|
366 |
//
|
|
367 |
void VideoListDataModel::appendData(QDateTime data)
|
|
368 |
{
|
|
369 |
DummyData* obj;
|
|
370 |
for(int i = 0; i < mData.count(); ++i)
|
|
371 |
{
|
|
372 |
obj = mData.at(i);
|
|
373 |
if(!obj->mDate.isValid())
|
|
374 |
{
|
|
375 |
obj->mDate = data;
|
|
376 |
QModelIndex change = index(i,0);
|
|
377 |
emit dataChanged(change, change);
|
|
378 |
return;
|
|
379 |
}
|
|
380 |
}
|
|
381 |
beginInsertRows(QModelIndex(), mData.count(), mData.count());
|
|
382 |
obj = new DummyData;
|
|
383 |
obj->mId = TMPXItemId( mData.count(), 0);
|
|
384 |
obj->mDate = data;
|
|
385 |
mData.append(obj);
|
|
386 |
endInsertRows();
|
|
387 |
}
|
|
388 |
|
|
389 |
// ---------------------------------------------------------------------------
|
|
390 |
// appendStatus
|
|
391 |
// ---------------------------------------------------------------------------
|
|
392 |
//
|
|
393 |
void VideoListDataModel::appendStatus(int status)
|
|
394 |
{
|
|
395 |
DummyData* obj;
|
|
396 |
for(int i = 0; i < mData.count(); ++i)
|
|
397 |
{
|
|
398 |
obj = mData.at(i);
|
|
399 |
if(obj->mStatus == -1)
|
|
400 |
{
|
|
401 |
obj->mStatus = status;
|
|
402 |
QModelIndex change = index(i,0);
|
|
403 |
emit dataChanged(change, change);
|
|
404 |
return;
|
|
405 |
}
|
|
406 |
}
|
|
407 |
beginInsertRows(QModelIndex(), mData.count(), mData.count());
|
|
408 |
obj = new DummyData;
|
|
409 |
obj->mId = TMPXItemId( mData.count(), 0);
|
|
410 |
obj->mStatus = status;
|
|
411 |
mData.append(obj);
|
|
412 |
endInsertRows();
|
|
413 |
}
|
|
414 |
|
|
415 |
// ---------------------------------------------------------------------------
|
|
416 |
// setAlbumInUse
|
|
417 |
// ---------------------------------------------------------------------------
|
|
418 |
//
|
|
419 |
void VideoListDataModel::setAlbumInUse(TMPXItemId itemId)
|
|
420 |
{
|
|
421 |
mAlbumInUse = itemId;
|
|
422 |
}
|
|
423 |
|
|
424 |
// ---------------------------------------------------------------------------
|
|
425 |
// albumInUse
|
|
426 |
// ---------------------------------------------------------------------------
|
|
427 |
//
|
|
428 |
TMPXItemId VideoListDataModel::albumInUse()
|
|
429 |
{
|
|
430 |
return mAlbumInUse;
|
|
431 |
}
|
|
432 |
|
|
433 |
// ---------------------------------------------------------------------------
|
|
434 |
// belongsToAlbum
|
|
435 |
// ---------------------------------------------------------------------------
|
|
436 |
//
|
|
437 |
bool VideoListDataModel::belongsToAlbum(TMPXItemId itemId, TMPXItemId albumId )
|
|
438 |
{
|
|
439 |
Q_UNUSED(itemId);
|
|
440 |
Q_UNUSED(albumId);
|
|
441 |
return mBelongsToAlbum;
|
|
442 |
}
|
|
443 |
|
|
444 |
// ---------------------------------------------------------------------------
|
35
|
445 |
// removeItemsFromAlbum
|
|
446 |
// ---------------------------------------------------------------------------
|
|
447 |
//
|
|
448 |
int VideoListDataModel::removeItemsFromAlbum(TMPXItemId &albumId, const QList<TMPXItemId> &items)
|
|
449 |
{
|
|
450 |
Q_UNUSED(albumId);
|
|
451 |
Q_UNUSED(items);
|
|
452 |
return mRemoveFrAlbumReturn;
|
|
453 |
}
|
|
454 |
|
|
455 |
// ---------------------------------------------------------------------------
|
34
|
456 |
// indexOfId
|
|
457 |
// ---------------------------------------------------------------------------
|
|
458 |
//
|
|
459 |
QModelIndex VideoListDataModel::indexOfId(TMPXItemId id)
|
|
460 |
{
|
|
461 |
QModelIndex itemIndex;
|
|
462 |
DummyData* obj;
|
|
463 |
for(int i = 0; i < mData.count(); ++i)
|
|
464 |
{
|
|
465 |
obj = mData.at(i);
|
|
466 |
if(obj->mId == id)
|
|
467 |
{
|
|
468 |
itemIndex = index(i,0,QModelIndex());
|
|
469 |
break;
|
|
470 |
}
|
|
471 |
}
|
|
472 |
return itemIndex;
|
|
473 |
}
|
|
474 |
|
|
475 |
// End of file
|
|
476 |
|
|
477 |
|
|
478 |
|