|
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: VideoListDataModelPrivate class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 |
|
20 #include <mpxmediageneraldefs.h> |
|
21 #include <thumbnailmanager_qt.h> |
|
22 #include <mpxmediaarray.h> |
|
23 #include <mpxmedia.h> |
|
24 #include <qvariant.h> |
|
25 |
|
26 #include "videolistdatamodel.h" |
|
27 #include "videocollectionclient.h" |
|
28 #include "videodeleteworker.h" |
|
29 |
|
30 #include "videolistdatamodel_p.h" |
|
31 #include "videothumbnaildata.h" |
|
32 #include "vcxmyvideosdefs.h" |
|
33 #include "videocollectionutils.h" |
|
34 #include "videocollectioncommon.h" |
|
35 |
|
36 /** |
|
37 * global qHash function required fo creating hash values for TMPXItemId -keys |
|
38 */ |
|
39 inline uint qHash(TMPXItemId key) |
|
40 { |
|
41 QPair<uint, uint> keyPair(key.iId1, key.iId2); |
|
42 |
|
43 return qHash(keyPair); |
|
44 } |
|
45 |
|
46 // ================= MEMBER FUNCTIONS ======================= |
|
47 // |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // VideoListDataModelPrivate |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 VideoListDataModelPrivate::VideoListDataModelPrivate(VideoListDataModel *model) : |
|
54 q_ptr(model), |
|
55 mVideoThumbnailData(0), |
|
56 mInitialized(false), |
|
57 mCurrentAlbum(TMPXItemId::InvalidId()) |
|
58 { |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // ~VideoListDataModelPrivate |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 VideoListDataModelPrivate::~VideoListDataModelPrivate() |
|
66 { |
|
67 QHash<TMPXItemId, QSet<TMPXItemId> >::iterator iter = mAlbumData.begin(); |
|
68 while(iter != mAlbumData.end()) |
|
69 { |
|
70 iter->clear(); |
|
71 ++iter; |
|
72 } |
|
73 mAlbumData.clear(); |
|
74 mMediaData.clear(); |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // initialize |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 int VideoListDataModelPrivate::initialize() |
|
82 { |
|
83 if(mInitialized) |
|
84 { |
|
85 return 0; |
|
86 } |
|
87 mVideoThumbnailData = &(VideoThumbnailData::instance()); |
|
88 if(!connect( mVideoThumbnailData, SIGNAL(thumbnailsFetched( QList<TMPXItemId> )), |
|
89 this, SLOT(thumbnailsFetchedSlot( QList<TMPXItemId> )))) |
|
90 { |
|
91 return -1; |
|
92 } |
|
93 |
|
94 mInitialized = true; |
|
95 return 0; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // getVideoCount |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 int VideoListDataModelPrivate::getVideoCount() |
|
103 { |
|
104 return mMediaData.count(); |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // getMediaIdFromIndex |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 TMPXItemId VideoListDataModelPrivate::getMediaIdFromIndex( int index ) const |
|
112 { |
|
113 return mMediaData.idFromIndex(index); |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // getVideoNameFromIndex |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 const QString VideoListDataModelPrivate::getVideoNameFromIndex( int index ) const |
|
121 { |
|
122 QString txt; |
|
123 CMPXMedia* media = mMediaData.fromIndex(index); |
|
124 VideoCollectionUtils::instance().mediaValue<QString>(media, KMPXMediaGeneralTitle, txt ); |
|
125 return txt; |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // getVideoThumbnailFromIndex |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 const QIcon* VideoListDataModelPrivate::getVideoThumbnailFromIndex( int index ) const |
|
133 { |
|
134 if(mVideoThumbnailData) |
|
135 { |
|
136 return mVideoThumbnailData->getThumbnail( mMediaData.idFromIndex(index) ); |
|
137 } |
|
138 return 0; |
|
139 } |
|
140 |
|
141 // ----------------------------------------------------------------------------- |
|
142 // getCategoryVideoCountFromIndex |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 quint32 VideoListDataModelPrivate::getCategoryVideoCountFromIndex( int index ) const |
|
146 { |
|
147 quint32 count(0); |
|
148 CMPXMedia *media = mMediaData.fromIndex(index); |
|
149 VideoCollectionUtils::instance().mediaValue<quint32>(media, KVcxMediaMyVideosCategoryItemCount, count ); |
|
150 return count; |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // getVideoSizeFromIndex |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 quint32 VideoListDataModelPrivate::getVideoSizeFromIndex( int index ) const |
|
158 { |
|
159 quint32 size(0); |
|
160 CMPXMedia *media = mMediaData.fromIndex(index); |
|
161 VideoCollectionUtils::instance().mediaValue<quint32>(media, KMPXMediaGeneralSize, size ); |
|
162 return size; |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // getVideoAgeProfileFromIndex |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 quint32 VideoListDataModelPrivate::getVideoAgeProfileFromIndex( int index ) const |
|
170 { |
|
171 quint32 ageProfile(0); |
|
172 CMPXMedia *media = mMediaData.fromIndex(index); |
|
173 VideoCollectionUtils::instance().mediaValue<quint32>(media, KVcxMediaMyVideosAgeProfile, ageProfile ); |
|
174 return ageProfile; |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // getVideodurationFromIndex |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 quint32 VideoListDataModelPrivate::getVideodurationFromIndex( int index ) const |
|
182 { |
|
183 quint32 returnDuration(0); |
|
184 float duration(0); |
|
185 CMPXMedia *media = mMediaData.fromIndex(index); |
|
186 VideoCollectionUtils::instance().mediaValue<float>(media, KVcxMediaMyVideosDuration, duration ); |
|
187 returnDuration = static_cast<quint32>(duration); |
|
188 return returnDuration; |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // getVideoDateFromIndex |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 QDateTime VideoListDataModelPrivate::getVideoDateFromIndex( int index ) const |
|
196 { |
|
197 QDateTime date; |
|
198 quint64 dateTimeValue; |
|
199 if(!VideoCollectionUtils::instance().mediaValue<quint64>(mMediaData.fromIndex(index), KMPXMediaGeneralDate, dateTimeValue)) |
|
200 { |
|
201 return date; |
|
202 } |
|
203 TDateTime temp = TTime( dateTimeValue ).DateTime(); |
|
204 date = QDateTime(QDate(temp.Year(), temp.Month()+1, temp.Day()+1), |
|
205 QTime(temp.Hour(), temp.Minute(), temp.Second(), temp.MicroSecond())); |
|
206 return date; |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // getMetaDataFromIndex |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 QMap<QString, QVariant> VideoListDataModelPrivate::getMetaDataFromIndex(int index) const |
|
214 { |
|
215 using namespace VideoCollectionCommon; |
|
216 QMap<QString, QVariant> map; |
|
217 CMPXMedia *media = mMediaData.fromIndex(index); |
|
218 if(!media) { |
|
219 return map; |
|
220 } |
|
221 |
|
222 // MetaKeyDate |
|
223 QDateTime date = getVideoDateFromIndex(index); |
|
224 if(date.isValid()) { |
|
225 map[MetaKeyDate] = date.date(); |
|
226 } |
|
227 |
|
228 //TODO: Localisation |
|
229 // MetaKeyDurationString |
|
230 quint32 dur = getVideodurationFromIndex(index); |
|
231 QString duration = VideoCollectionUtils::instance().prepareLengthString(dur); |
|
232 if(!duration.isNull() && !duration.isEmpty()) { |
|
233 map[MetaKeyDurationString] = duration; |
|
234 } |
|
235 |
|
236 //TODO: Localisation |
|
237 // MetaKeySizeString |
|
238 quint32 s = getVideoSizeFromIndex(index); |
|
239 QString size = VideoCollectionUtils::instance().prepareSizeString(s); |
|
240 if(!size.isNull() && !size.isEmpty()) { |
|
241 map[MetaKeySizeString] = size; |
|
242 } |
|
243 |
|
244 // MetaKeyStarRating |
|
245 quint8 rating = 0; |
|
246 if(VideoCollectionUtils::instance().mediaValue<quint8>(media, KVcxMediaMyVideosRating, rating)) |
|
247 { |
|
248 map[MetaKeyStarRating] = rating; |
|
249 } |
|
250 |
|
251 // MetaKeyDRMInfo |
|
252 |
|
253 // MetaKeyServiceURL |
|
254 |
|
255 // MetaKeyDescription |
|
256 QString desc; |
|
257 if(VideoCollectionUtils::instance().mediaValue<QString>(media, KMPXMediaGeneralComment, desc)) { |
|
258 map[MetaKeyDescription] = desc; |
|
259 } |
|
260 |
|
261 // MetaKeyModifiedDate |
|
262 quint64 dateTimeValue; |
|
263 if(VideoCollectionUtils::instance().mediaValue<quint64>(media, KVcxMediaMyVideosModifiedDate, dateTimeValue)) { |
|
264 TDateTime temp = TTime( dateTimeValue ).DateTime(); |
|
265 QDateTime date = QDateTime(QDate(temp.Year(), temp.Month()+1, temp.Day()), |
|
266 QTime(temp.Hour(), temp.Minute(), temp.Second(), temp.MicroSecond())); |
|
267 map[MetaKeyModifiedDate] = date.date(); |
|
268 } |
|
269 |
|
270 // MetaKeyShotLocation |
|
271 |
|
272 // MetaKeyAuthor |
|
273 QString author; |
|
274 if(VideoCollectionUtils::instance().mediaValue<QString>(media, KVcxMediaMyVideosAuthor, author)) { |
|
275 map[MetaKeyAuthor] = author; |
|
276 } |
|
277 |
|
278 // MetaKeyCopyright |
|
279 QString copyright; |
|
280 if(VideoCollectionUtils::instance().mediaValue<QString>(media, KMPXMediaGeneralCopyright, copyright)) { |
|
281 map[MetaKeyCopyright] = copyright; |
|
282 } |
|
283 |
|
284 // MetaKeyAudioType |
|
285 |
|
286 // MetaKeyLanguageString |
|
287 QString language; |
|
288 if(VideoCollectionUtils::instance().mediaValue<QString>(media, KVcxMediaMyVideosAudioLanguage, language)) { |
|
289 map[MetaKeyLanguageString] = language; |
|
290 } |
|
291 |
|
292 // MetaKeyKeywords |
|
293 |
|
294 // MetaKeyVideoResolutionString |
|
295 |
|
296 // MetaKeyBitRate |
|
297 |
|
298 // MetaKeyFormat |
|
299 QString format; |
|
300 if(VideoCollectionUtils::instance().mediaValue<QString>(media, KMPXMediaGeneralMimeType, format)) { |
|
301 map[MetaKeyFormat] = format; |
|
302 } |
|
303 |
|
304 return map; |
|
305 } |
|
306 |
|
307 // ----------------------------------------------------------------------------- |
|
308 // markVideosRemoved |
|
309 // ----------------------------------------------------------------------------- |
|
310 // |
|
311 TMPXItemId VideoListDataModelPrivate::markVideoRemoved(const QModelIndex &itemIndex) |
|
312 { |
|
313 return mMediaData.markItemRemoved(itemIndex.row()); |
|
314 } |
|
315 |
|
316 // ----------------------------------------------------------------------------- |
|
317 // restoreRemoved |
|
318 // ----------------------------------------------------------------------------- |
|
319 // |
|
320 void VideoListDataModelPrivate::restoreRemoved(QList<TMPXItemId> *idList) |
|
321 { |
|
322 int startIndex = mMediaData.count(); |
|
323 int restored = mMediaData.restoreRemovedItems(idList); |
|
324 if(restored > 0) |
|
325 { |
|
326 q_ptr->beginInsertRows(QModelIndex(), startIndex, startIndex + (restored - 1)); |
|
327 q_ptr->endInsertRows(); |
|
328 } |
|
329 } |
|
330 |
|
331 // ----------------------------------------------------------------------------- |
|
332 // getFilePathFromIndex |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 const QString VideoListDataModelPrivate::getFilePathFromIndex(int index) const |
|
336 { |
|
337 QString filePath; |
|
338 VideoCollectionUtils::instance().mediaValue<QString>(mMediaData.fromIndex(index), |
|
339 KMPXMediaGeneralUri, filePath ); |
|
340 return filePath; |
|
341 } |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // getFilePathForId |
|
345 // ----------------------------------------------------------------------------- |
|
346 // |
|
347 const QString VideoListDataModelPrivate::getFilePathForId(TMPXItemId mediaId) const |
|
348 { |
|
349 QString filePath; |
|
350 int index = mMediaData.indexOfId(mediaId); |
|
351 VideoCollectionUtils::instance().mediaValue<QString>(mMediaData.fromIndex(index), |
|
352 KMPXMediaGeneralUri, filePath ); |
|
353 return filePath; |
|
354 } |
|
355 |
|
356 // ----------------------------------------------------------------------------- |
|
357 // belongsToAlbum |
|
358 // ----------------------------------------------------------------------------- |
|
359 // |
|
360 bool VideoListDataModelPrivate::belongsToAlbum(const TMPXItemId &itemId, TMPXItemId albumId) const |
|
361 { |
|
362 bool contains(false); |
|
363 QHash<TMPXItemId, QSet<TMPXItemId> >::const_iterator iter; |
|
364 if(albumId == TMPXItemId::InvalidId()) |
|
365 { |
|
366 // album id not specified, use the current album |
|
367 iter = mAlbumData.constFind(mCurrentAlbum); |
|
368 } |
|
369 else |
|
370 { |
|
371 iter = mAlbumData.constFind(albumId); |
|
372 } |
|
373 if (iter != mAlbumData.constEnd()) |
|
374 { |
|
375 contains = iter->contains(itemId); |
|
376 } |
|
377 return contains; |
|
378 } |
|
379 |
|
380 // ----------------------------------------------------------------------------- |
|
381 // setAlbumInUse |
|
382 // ----------------------------------------------------------------------------- |
|
383 // |
|
384 void VideoListDataModelPrivate::setAlbumInUse(TMPXItemId albumId) |
|
385 { |
|
386 mCurrentAlbum = albumId; |
|
387 } |
|
388 |
|
389 // ----------------------------------------------------------------------------- |
|
390 // removeItemsFromAlbum |
|
391 // ----------------------------------------------------------------------------- |
|
392 // |
|
393 int VideoListDataModelPrivate::removeItemsFromAlbum(TMPXItemId &albumId, |
|
394 const QList<TMPXItemId> &items) |
|
395 { |
|
396 QHash<TMPXItemId, QSet<TMPXItemId> >::iterator iter = mAlbumData.find(albumId); |
|
397 if(iter == mAlbumData.end()) |
|
398 { |
|
399 return 0; |
|
400 } |
|
401 int removeCount = 0; |
|
402 int count = items.count(); |
|
403 for(int i = 0; i < count; ++i) |
|
404 { |
|
405 if(iter->remove(items.at(i))) |
|
406 { |
|
407 ++removeCount; |
|
408 } |
|
409 } |
|
410 return removeCount; |
|
411 } |
|
412 |
|
413 // ----------------------------------------------------------------------------- |
|
414 // getMediaId |
|
415 // ----------------------------------------------------------------------------- |
|
416 // |
|
417 TMPXItemId VideoListDataModelPrivate::getMediaId(const CMPXMedia *media ) const |
|
418 { |
|
419 TMPXItemId mediaId = TMPXItemId::InvalidId(); |
|
420 |
|
421 VideoCollectionUtils::instance().mediaValue<TMPXItemId>(media, KMPXMediaGeneralId, mediaId ); |
|
422 |
|
423 return mediaId; |
|
424 } |
|
425 |
|
426 // ----------------------------------------------------------------------------- |
|
427 // appendDataToContainerL |
|
428 // ----------------------------------------------------------------------------- |
|
429 // |
|
430 void VideoListDataModelPrivate::appendDataToContainerL( |
|
431 CMPXMediaArray *videoArray, |
|
432 unsigned int startIndex) |
|
433 { |
|
434 int count = videoArray->Count(); |
|
435 if (!videoArray || |
|
436 startIndex >= count) |
|
437 { |
|
438 return; |
|
439 } |
|
440 |
|
441 CMPXMedia *newMedia = 0; |
|
442 CMPXMedia *mediaFromArray = 0; |
|
443 TMPXItemId itemId = TMPXItemId::InvalidId(); |
|
444 for(int i = startIndex; i < count; ++i) |
|
445 { |
|
446 mediaFromArray = videoArray->AtL(i); |
|
447 itemId = getMediaId(mediaFromArray); |
|
448 if (isValid(*mediaFromArray, itemId)) |
|
449 { |
|
450 newMedia = CMPXMedia::NewL(*mediaFromArray); |
|
451 mMediaData.append(newMedia); |
|
452 newMedia = 0; |
|
453 } |
|
454 } |
|
455 } |
|
456 |
|
457 // ----------------------------------------------------------------------------- |
|
458 // isValid |
|
459 // ----------------------------------------------------------------------------- |
|
460 // |
|
461 bool VideoListDataModelPrivate::isValid(const CMPXMedia &media, |
|
462 const TMPXItemId &itemId) const |
|
463 { |
|
464 if(itemId == TMPXItemId::InvalidId()) |
|
465 { |
|
466 return false; |
|
467 } |
|
468 // temporary to remove all items with out a title |
|
469 QString title; |
|
470 VideoCollectionUtils::instance().mediaValue<QString>(&media, |
|
471 KMPXMediaGeneralTitle, |
|
472 title); |
|
473 if (!title.length()) |
|
474 { |
|
475 return false; |
|
476 } |
|
477 // recently played and podcasts are not yet supported |
|
478 if(itemId.iId2 == KVcxMvcMediaTypeCategory && |
|
479 (itemId.iId1 != KVcxMvcCategoryIdDownloads && |
|
480 itemId.iId1 != KVcxMvcCategoryIdCaptured)) |
|
481 { |
|
482 return false; |
|
483 } |
|
484 return true; |
|
485 } |
|
486 |
|
487 // ----------------------------------------------------------------------------- |
|
488 // albumDataChangedL |
|
489 // ----------------------------------------------------------------------------- |
|
490 // |
|
491 void VideoListDataModelPrivate::albumDataChangedL(TMPXItemId albumId, |
|
492 CMPXMediaArray *videoArray) |
|
493 { |
|
494 if (!videoArray || albumId == TMPXItemId::InvalidId()) |
|
495 { |
|
496 return; |
|
497 } |
|
498 QSet<TMPXItemId> items; |
|
499 |
|
500 // remove existing |
|
501 mAlbumData.remove(albumId); |
|
502 |
|
503 int videoCount = videoArray->Count(); |
|
504 CMPXMedia *media = 0; |
|
505 TMPXItemId id = TMPXItemId::InvalidId(); |
|
506 QModelIndex index; |
|
507 for (int i = videoCount - 1; i >= 0; i--) |
|
508 { |
|
509 media = videoArray->AtL(i); |
|
510 id = getMediaId(media); |
|
511 if (id != TMPXItemId::InvalidId() && id.iId2 == KVcxMvcMediaTypeVideo) |
|
512 { |
|
513 items.insert(id); |
|
514 } |
|
515 } |
|
516 |
|
517 mAlbumData[albumId] = items; |
|
518 |
|
519 // signal that album has been updated |
|
520 emit q_ptr->albumChanged(); |
|
521 |
|
522 // signal that model is ready |
|
523 emit q_ptr->modelReady(); |
|
524 } |
|
525 |
|
526 |
|
527 // ----------------------------------------------------------------------------- |
|
528 // thumbnailsFetchedSlot |
|
529 // ----------------------------------------------------------------------------- |
|
530 // |
|
531 void VideoListDataModelPrivate::thumbnailsFetchedSlot(QList<TMPXItemId> mediaIds) |
|
532 { |
|
533 // TODO: find way to optimize dataChanged events |
|
534 |
|
535 TMPXItemId id; |
|
536 QModelIndex rowIndex; |
|
537 |
|
538 while(!mediaIds.isEmpty()) |
|
539 { |
|
540 id = mediaIds.takeFirst(); |
|
541 rowIndex = q_ptr->index(mMediaData.indexOfId(id), 0); |
|
542 if(rowIndex.isValid()) |
|
543 { |
|
544 emit dataChanged( rowIndex, rowIndex); |
|
545 } |
|
546 } |
|
547 } |
|
548 |
|
549 // ----------------------------------------------------------------------------- |
|
550 // newVideoListSlot |
|
551 // ----------------------------------------------------------------------------- |
|
552 // |
|
553 void VideoListDataModelPrivate::newVideoListSlot( CMPXMediaArray *newVideoList ) |
|
554 { |
|
555 if( !newVideoList ) |
|
556 { |
|
557 return; |
|
558 } |
|
559 |
|
560 int startIndex = mMediaData.count(); |
|
561 |
|
562 TRAP_IGNORE(appendDataToContainerL(newVideoList)); |
|
563 |
|
564 int endIndex = mMediaData.count() - 1; |
|
565 if(startIndex <= endIndex) |
|
566 { |
|
567 q_ptr->beginInsertRows(QModelIndex(), startIndex, endIndex); |
|
568 q_ptr->endInsertRows(); |
|
569 } |
|
570 |
|
571 emit q_ptr->modelReady(); |
|
572 } |
|
573 |
|
574 // ----------------------------------------------------------------------------- |
|
575 // appendVideoListSlot |
|
576 // ----------------------------------------------------------------------------- |
|
577 // |
|
578 void VideoListDataModelPrivate::appendVideoListSlot(CMPXMediaArray* videoList) |
|
579 { |
|
580 if(!videoList) |
|
581 { |
|
582 return; |
|
583 } |
|
584 if(videoList->Count() == 0 || videoList->Count() <= mMediaData.count()) |
|
585 { |
|
586 // nothing to append or count matches, no changes -> nothing to append |
|
587 return; |
|
588 } |
|
589 |
|
590 // array gotten is in same order as existing data from the start, |
|
591 // so we only need to go throught the appendding array from the index |
|
592 // at position where first new items is excepted to exists. |
|
593 int startIndex = mMediaData.count(); |
|
594 |
|
595 q_ptr->beginInsertRows(QModelIndex(), startIndex, videoList->Count() - 1); |
|
596 |
|
597 TRAP_IGNORE(appendDataToContainerL(videoList, startIndex)); |
|
598 |
|
599 q_ptr->endInsertRows(); |
|
600 emit q_ptr->modelChanged(); |
|
601 } |
|
602 |
|
603 // ----------------------------------------------------------------------------- |
|
604 // newVideoAvailable |
|
605 // ----------------------------------------------------------------------------- |
|
606 // |
|
607 void VideoListDataModelPrivate::newVideoAvailableSlot(CMPXMedia *newVideo) |
|
608 { |
|
609 if(!newVideo ) |
|
610 { |
|
611 return; |
|
612 } |
|
613 |
|
614 // try to get id of the video, if not found consider invalid clip |
|
615 TMPXItemId mediaId = getMediaId(newVideo); |
|
616 if( mediaId == TMPXItemId::InvalidId()) |
|
617 { |
|
618 return; |
|
619 } |
|
620 |
|
621 // append video into list, ownership of provided mediaobject is not transferred, |
|
622 // so we need to create copy of CMPXMedia |
|
623 if (isValid(*newVideo, mediaId)) |
|
624 { |
|
625 CMPXMedia *videoToAppend = 0; |
|
626 TRAP_IGNORE(videoToAppend = CMPXMedia::NewL(*newVideo)); |
|
627 |
|
628 q_ptr->beginInsertRows(QModelIndex(), mMediaData.count(), mMediaData.count()); |
|
629 |
|
630 mMediaData.append(videoToAppend); |
|
631 |
|
632 q_ptr->endInsertRows(); |
|
633 |
|
634 emit q_ptr->modelChanged(); |
|
635 } |
|
636 } |
|
637 |
|
638 // ----------------------------------------------------------------------------- |
|
639 // itemDeletedSlot |
|
640 // ----------------------------------------------------------------------------- |
|
641 // |
|
642 void VideoListDataModelPrivate::itemDeletedSlot(TMPXItemId itemId) |
|
643 { |
|
644 if(itemId == TMPXItemId::InvalidId()) |
|
645 { |
|
646 return; |
|
647 } |
|
648 |
|
649 if(itemId.iId2 == KVcxMvcMediaTypeVideo) |
|
650 { |
|
651 videoDeleted(itemId); |
|
652 } |
|
653 else if (itemId.iId2 == KVcxMvcMediaTypeAlbum) |
|
654 { |
|
655 albumRemoved(itemId); |
|
656 } |
|
657 } |
|
658 |
|
659 // ----------------------------------------------------------------------------- |
|
660 // albumRemoved |
|
661 // ----------------------------------------------------------------------------- |
|
662 // |
|
663 void VideoListDataModelPrivate::albumRemoved(TMPXItemId albumId) |
|
664 { |
|
665 if (albumId == TMPXItemId::InvalidId() || albumId.iId2 != KVcxMvcMediaTypeAlbum) |
|
666 { |
|
667 return; |
|
668 } |
|
669 |
|
670 bool changed(false); |
|
671 |
|
672 if(mVideoThumbnailData) |
|
673 { |
|
674 mVideoThumbnailData->removeThumbnail( albumId ); |
|
675 } |
|
676 |
|
677 int index = mMediaData.indexOfId(albumId); |
|
678 if(index >= 0) |
|
679 { |
|
680 q_ptr->beginRemoveRows(QModelIndex(), index, index); |
|
681 mMediaData.remove(albumId); |
|
682 q_ptr->endRemoveRows(); |
|
683 changed = true; |
|
684 } |
|
685 |
|
686 //remove album data |
|
687 QHash<TMPXItemId, QSet<TMPXItemId> >::iterator iter; |
|
688 iter = mAlbumData.find(albumId); |
|
689 if(iter != mAlbumData.end()) |
|
690 { |
|
691 iter->clear(); |
|
692 mAlbumData.remove(albumId); |
|
693 changed = true; |
|
694 } |
|
695 |
|
696 if(changed) |
|
697 { |
|
698 emit q_ptr->modelChanged(); |
|
699 } |
|
700 } |
|
701 |
|
702 // ----------------------------------------------------------------------------- |
|
703 // videoDeleted |
|
704 // ----------------------------------------------------------------------------- |
|
705 // |
|
706 void VideoListDataModelPrivate::videoDeleted(TMPXItemId videoId) |
|
707 { |
|
708 if(videoId == TMPXItemId::InvalidId()) |
|
709 { |
|
710 return; |
|
711 } |
|
712 // check if provided id is in the deleted -container and remove |
|
713 // it from there if it is. |
|
714 QList<TMPXItemId> ids; |
|
715 ids.append(videoId); |
|
716 if(!mMediaData.clearRemoved(&ids)) |
|
717 { |
|
718 q_ptr->mDeleteWorker->removeFromRequest(videoId); |
|
719 if(mVideoThumbnailData) |
|
720 { |
|
721 mVideoThumbnailData->removeThumbnail( videoId ); |
|
722 } |
|
723 // media removed was not in the deleted -container, so we have external |
|
724 // removal: in this case we need to indicate UI |
|
725 int index = mMediaData.indexOfId(videoId); |
|
726 if(index >= 0) |
|
727 { |
|
728 q_ptr->beginRemoveRows(QModelIndex(), index, index); |
|
729 mMediaData.remove(videoId); |
|
730 q_ptr->endRemoveRows(); |
|
731 emit q_ptr->modelChanged(); |
|
732 } |
|
733 } |
|
734 } |
|
735 |
|
736 // ----------------------------------------------------------------------------- |
|
737 // videoDeleteCompleted |
|
738 // ----------------------------------------------------------------------------- |
|
739 // |
|
740 void VideoListDataModelPrivate::videoDeleteCompletedSlot(int overallCount, QList<TMPXItemId> *failedMediaIds) |
|
741 { |
|
742 Q_UNUSED(overallCount); |
|
743 if(!failedMediaIds) |
|
744 { |
|
745 // invalid signal received, do nothing |
|
746 return; |
|
747 } |
|
748 int status(VideoCollectionCommon::statusDeleteSucceed); |
|
749 QVariant data; |
|
750 if(failedMediaIds->count() > 0) |
|
751 { |
|
752 QString nameOfFirstFailed(""); |
|
753 CMPXMedia *media = mMediaData.getRemovedMedia( TMPXItemId(failedMediaIds->at(0))); |
|
754 VideoCollectionUtils::instance().mediaValue<QString>(media, KMPXMediaGeneralTitle, nameOfFirstFailed ); |
|
755 if(failedMediaIds->count() == 1) |
|
756 { |
|
757 status = VideoCollectionCommon::statusSingleDeleteFail; |
|
758 data = nameOfFirstFailed; |
|
759 } |
|
760 else |
|
761 { |
|
762 status = VideoCollectionCommon::statusMultipleDeleteFail; |
|
763 data = failedMediaIds->count(); |
|
764 } |
|
765 restoreRemoved(failedMediaIds); |
|
766 } |
|
767 q_ptr->reportAsyncStatus(status, data); |
|
768 emit q_ptr->modelChanged(); |
|
769 } |
|
770 |
|
771 // ----------------------------------------------------------------------------- |
|
772 // albumRemoveFailureSlot |
|
773 // ----------------------------------------------------------------------------- |
|
774 // |
|
775 void VideoListDataModelPrivate::albumRemoveFailureSlot(QList<TMPXItemId> *failedMediaIds) |
|
776 { |
|
777 if(!failedMediaIds) |
|
778 { |
|
779 return; |
|
780 } |
|
781 int status(VideoCollectionCommon::statusRemoveSucceed); |
|
782 QVariant data; |
|
783 if(failedMediaIds->count() > 0) |
|
784 { |
|
785 QString nameOfFirstFailed(""); |
|
786 CMPXMedia *media = mMediaData.getRemovedMedia( TMPXItemId(failedMediaIds->at(0))); |
|
787 VideoCollectionUtils::instance().mediaValue<QString>(media, KMPXMediaGeneralTitle, nameOfFirstFailed ); |
|
788 if(failedMediaIds->count() == 1) |
|
789 { |
|
790 status = VideoCollectionCommon::statusSingleRemoveFail; |
|
791 data = nameOfFirstFailed; |
|
792 } |
|
793 else |
|
794 { |
|
795 status = VideoCollectionCommon::statusMultiRemoveFail; |
|
796 data = failedMediaIds->count(); |
|
797 } |
|
798 } |
|
799 q_ptr->reportAsyncStatus(status, data); |
|
800 } |
|
801 |
|
802 // ----------------------------------------------------------------------------- |
|
803 // VideoDetailsCompleted |
|
804 // ----------------------------------------------------------------------------- |
|
805 // |
|
806 void VideoListDataModelPrivate::videoDetailsCompletedSlot(TMPXItemId videoId) |
|
807 { |
|
808 if(videoId != TMPXItemId::InvalidId()) |
|
809 { |
|
810 emit videoDetailsReady(videoId); |
|
811 } |
|
812 } |
|
813 |
|
814 // ----------------------------------------------------------------------------- |
|
815 // albumListAvailableSlot |
|
816 // ----------------------------------------------------------------------------- |
|
817 // |
|
818 void VideoListDataModelPrivate::albumListAvailableSlot(TMPXItemId albumId, |
|
819 CMPXMediaArray *albumItems) |
|
820 { |
|
821 // currently only one album is kept in memory |
|
822 TRAP_IGNORE(albumDataChangedL(albumId, albumItems)); |
|
823 } |
|
824 |
|
825 // End of file |