videocollection/videocollectionwrapper/src/videolistdatamodel_p.cpp
changeset 35 3738fe97f027
parent 34 bbb98528c666
child 36 8aed59de29f9
equal deleted inserted replaced
34:bbb98528c666 35:3738fe97f027
   137     }
   137     }
   138     return 0;
   138     return 0;
   139 }
   139 }
   140 
   140 
   141 // -----------------------------------------------------------------------------
   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 // -----------------------------------------------------------------------------
   142 // getVideoSizeFromIndex
   154 // getVideoSizeFromIndex
   143 // -----------------------------------------------------------------------------
   155 // -----------------------------------------------------------------------------
   144 //
   156 //
   145 quint32 VideoListDataModelPrivate::getVideoSizeFromIndex( int index ) const
   157 quint32 VideoListDataModelPrivate::getVideoSizeFromIndex( int index ) const
   146 {
   158 {
   147     quint32 size(0);
   159     quint32 size(0);
   148     CMPXMedia *media = mMediaData.fromIndex(index);
   160     CMPXMedia *media = mMediaData.fromIndex(index);
   149     VideoCollectionUtils::instance().mediaValue<quint32>(media, KMPXMediaGeneralSize, size );    
   161     VideoCollectionUtils::instance().mediaValue<quint32>(media, KMPXMediaGeneralSize, size );    
   150     return size;    
   162     return size;
   151 }
   163 }
   152 
   164 
   153 // -----------------------------------------------------------------------------
   165 // -----------------------------------------------------------------------------
   154 // getVideoAgeProfileFromIndex
   166 // getVideoAgeProfileFromIndex
   155 // ---------------------------------------------------------------------------
   167 // ---------------------------------------------------------------------------
   364     }
   376     }
   365     return contains;
   377     return contains;
   366 }
   378 }
   367 
   379 
   368 // -----------------------------------------------------------------------------
   380 // -----------------------------------------------------------------------------
   369 // belongsToAlbum
   381 // setAlbumInUse
   370 // -----------------------------------------------------------------------------
   382 // -----------------------------------------------------------------------------
   371 //
   383 //
   372 void VideoListDataModelPrivate::setAlbumInUse(TMPXItemId albumId)
   384 void VideoListDataModelPrivate::setAlbumInUse(TMPXItemId albumId)
   373 {
   385 {
   374     mCurrentAlbum = albumId;
   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;
   375 }
   411 }
   376 
   412 
   377 // -----------------------------------------------------------------------------
   413 // -----------------------------------------------------------------------------
   378 // getMediaId
   414 // getMediaId
   379 // -----------------------------------------------------------------------------
   415 // -----------------------------------------------------------------------------
   447     }
   483     }
   448     return true;
   484     return true;
   449 }
   485 }
   450 
   486 
   451 // -----------------------------------------------------------------------------
   487 // -----------------------------------------------------------------------------
   452 // appendDataToAlbumL
   488 // albumDataChangedL
   453 // -----------------------------------------------------------------------------
   489 // -----------------------------------------------------------------------------
   454 //
   490 //
   455 void VideoListDataModelPrivate::appendDataToAlbumL(TMPXItemId albumId,
   491 void VideoListDataModelPrivate::albumDataChangedL(TMPXItemId albumId,
   456     CMPXMediaArray *videoArray)
   492     CMPXMediaArray *videoArray)
   457 {
   493 {
   458     if (!videoArray || albumId == TMPXItemId::InvalidId())
   494     if (!videoArray || albumId == TMPXItemId::InvalidId())
   459     {
   495     {
   460         return;
   496         return;
   461     }
   497     }
   462     QSet<TMPXItemId> items;
   498     QSet<TMPXItemId> items;
   463     QHash<TMPXItemId, QSet<TMPXItemId> >::iterator iter;
   499        
   464     // if album exists fetch existing items
   500     // remove existing
   465     iter =  mAlbumData.find(albumId);
   501     mAlbumData.remove(albumId);
   466     if(iter != mAlbumData.end())
   502     
   467     {
       
   468         items = iter.value();
       
   469     }
       
   470     bool albumUpdated = false;
       
   471     int videoCount = videoArray->Count();
   503     int videoCount = videoArray->Count();
   472     CMPXMedia *media = 0;
   504     CMPXMedia *media = 0;
   473     TMPXItemId id = TMPXItemId::InvalidId();
   505     TMPXItemId id = TMPXItemId::InvalidId();
   474     QModelIndex index;
   506     QModelIndex index;
   475     for (int i = videoCount - 1; i >= 0; i--)
   507     for (int i = videoCount - 1; i >= 0; i--)
   476     {
   508     {
   477         media = videoArray->AtL(i);
   509         media = videoArray->AtL(i);
   478         id = getMediaId(media);
   510         id = getMediaId(media);
   479         if (id != TMPXItemId::InvalidId())
   511         if (id != TMPXItemId::InvalidId() && id.iId2 == KVcxMvcMediaTypeVideo)
   480         {
   512         {          
   481             
       
   482             items.insert(id);
   513             items.insert(id);
   483             albumUpdated = true;
       
   484         }
   514         }
   485     }  
   515     }  
   486     // overwrite existing or create new
   516  
   487     mAlbumData[albumId] = items;
   517     mAlbumData[albumId] = items;
       
   518     
   488     // signal that album has been updated
   519     // signal that album has been updated
   489     if (albumUpdated)
   520     emit q_ptr->albumChanged();
   490     {
       
   491         emit q_ptr->albumChanged();
       
   492     }
       
   493 
   521 
   494     // signal that model is ready
   522     // signal that model is ready
   495     emit q_ptr->modelReady();
   523     emit q_ptr->modelReady();
   496 }
   524 }
   497 
   525 
   659     QHash<TMPXItemId, QSet<TMPXItemId> >::iterator iter;
   687     QHash<TMPXItemId, QSet<TMPXItemId> >::iterator iter;
   660     iter =  mAlbumData.find(albumId);
   688     iter =  mAlbumData.find(albumId);
   661     if(iter != mAlbumData.end())
   689     if(iter != mAlbumData.end())
   662     {
   690     {
   663         iter->clear();
   691         iter->clear();
       
   692         mAlbumData.remove(albumId);
   664         changed = true;
   693         changed = true;
   665     }
   694     }
   666 
   695 
   667     if(changed)
   696     if(changed)
   668     {
   697     {
   743 // albumRemoveFailureSlot
   772 // albumRemoveFailureSlot
   744 // -----------------------------------------------------------------------------
   773 // -----------------------------------------------------------------------------
   745 //
   774 //
   746 void VideoListDataModelPrivate::albumRemoveFailureSlot(QList<TMPXItemId> *failedMediaIds)
   775 void VideoListDataModelPrivate::albumRemoveFailureSlot(QList<TMPXItemId> *failedMediaIds)
   747 {
   776 {
       
   777     if(!failedMediaIds)
       
   778     {
       
   779         return;
       
   780     }
   748     int status(VideoCollectionCommon::statusRemoveSucceed);
   781     int status(VideoCollectionCommon::statusRemoveSucceed);
   749     QVariant data;
   782     QVariant data;
   750     if(failedMediaIds->count() > 0)
   783     if(failedMediaIds->count() > 0)
   751     {     
   784     {     
   752         QString nameOfFirstFailed("");
   785         QString nameOfFirstFailed("");
   784 //
   817 //
   785 void VideoListDataModelPrivate::albumListAvailableSlot(TMPXItemId albumId,
   818 void VideoListDataModelPrivate::albumListAvailableSlot(TMPXItemId albumId,
   786     CMPXMediaArray *albumItems)
   819     CMPXMediaArray *albumItems)
   787 {
   820 {
   788     // currently only one album is kept in memory
   821     // currently only one album is kept in memory
   789     TRAP_IGNORE(appendDataToAlbumL(albumId, albumItems));
   822     TRAP_IGNORE(albumDataChangedL(albumId, albumItems));
   790 }
   823 }
   791 
   824 
   792 // End of file
   825 // End of file