videocollection/videocollectionwrapper/src/videosortfilterproxymodel.cpp
changeset 35 3738fe97f027
parent 34 bbb98528c666
child 36 8aed59de29f9
equal deleted inserted replaced
34:bbb98528c666 35:3738fe97f027
    31 // -----------------------------------------------------------------------------
    31 // -----------------------------------------------------------------------------
    32 // VideoSortFilterProxyModel::VideoSortFilterProxyModel
    32 // VideoSortFilterProxyModel::VideoSortFilterProxyModel
    33 // -----------------------------------------------------------------------------
    33 // -----------------------------------------------------------------------------
    34 //
    34 //
    35 VideoSortFilterProxyModel::VideoSortFilterProxyModel(int type, QObject *parent) :
    35 VideoSortFilterProxyModel::VideoSortFilterProxyModel(int type, QObject *parent) :
    36  QSortFilterProxyModel(parent),
    36 QSortFilterProxyModel(parent),
    37  mModel(0),
    37 mModel(0),
    38  mCollectionClient(0),
    38 mCollectionClient(0),
    39  mType(type),
    39 mType(type),
    40  mLevel(-1),
    40 mLevel(-1),
    41  mGenericFilterId(TMPXItemId::InvalidId()),
    41 mGenericFilterId(TMPXItemId::InvalidId()),
    42 mGenericFilterValue(false),
    42 mGenericFilterValue(false),
    43  mIdleSortTimer(0),
    43 mIdleSortTimer(0),
    44  mWantedSortRole(VideoCollectionCommon::KeyDateTime)
    44 mWantedSortRole(VideoCollectionCommon::KeyDateTime)
    45 {
    45 {
    46     // NOP
    46     // NOP
    47 }
    47 }
    48 
    48 
    49 // -----------------------------------------------------------------------------
    49 // -----------------------------------------------------------------------------
    85 // VideoSortFilterProxyModel::connectSignals
    85 // VideoSortFilterProxyModel::connectSignals
    86 // -----------------------------------------------------------------------------
    86 // -----------------------------------------------------------------------------
    87 //
    87 //
    88 bool VideoSortFilterProxyModel::connectSignals()
    88 bool VideoSortFilterProxyModel::connectSignals()
    89 {
    89 {
    90     if(!connect(mModel, SIGNAL(fullVideoDetailsReady(TMPXItemId)),
       
    91                     this, SIGNAL(fullDetailsReady(TMPXItemId)))) 
       
    92     {
       
    93         return false;
       
    94     }
       
    95     
       
    96     if(!connect(mModel, SIGNAL(modelReady()),
    90     if(!connect(mModel, SIGNAL(modelReady()),
    97             this, SIGNAL(modelReady()))) 
    91             this, SIGNAL(modelReady()))) 
    98     {
    92     {
    99         return false;
    93         return false;
   100     }
    94     }
   101     if(!connect(mModel, SIGNAL(modelChanged()),
    95     if(!connect(mModel, SIGNAL(modelChanged()),
   102                     this, SIGNAL(modelChanged()))) 
    96                     this, SIGNAL(modelChanged()))) 
   103     {
    97     {
   104         return false;
    98         return false;
   105     }
    99     }
   106     if(!connect(mModel, SIGNAL(albumChanged()),
   100     if(mType == VideoCollectionWrapper::ECollectionContent)
   107                   this, SLOT(albumChangedSlot()))) 
   101     {
   108     {
   102         if(!connect(mModel, SIGNAL(albumChanged()),
   109         return false;
   103                     this, SLOT(albumChangedSlot()))) 
       
   104         {
       
   105             return false;
       
   106         }
   110     }
   107     }
   111     return true;
   108     return true;
   112 }
   109 }
   113    
   110    
   114 // -----------------------------------------------------------------------------
   111 // -----------------------------------------------------------------------------
   115 // VideoSortFilterProxyModel::disconnectSignals
   112 // VideoSortFilterProxyModel::disconnectSignals
   116 // -----------------------------------------------------------------------------
   113 // -----------------------------------------------------------------------------
   117 //
   114 //
   118 void VideoSortFilterProxyModel::disconnectSignals()
   115 void VideoSortFilterProxyModel::disconnectSignals()
   119 {
   116 {
   120     disconnect(mModel, SIGNAL(fullVideoDetailsReady(TMPXItemId)),
   117 	disconnect(mModel, SIGNAL(modelReady()), this, SIGNAL(modelReady()));
   121                                 this, SIGNAL(fullDetailsReady(TMPXItemId)));
       
   122     disconnect(mModel, SIGNAL(modelReady()), this, SIGNAL(modelReady()));
       
   123     disconnect(mModel, SIGNAL(modelChanged()), this, SIGNAL(modelChanged()));
   118     disconnect(mModel, SIGNAL(modelChanged()), this, SIGNAL(modelChanged()));
   124     disconnect(mModel, SIGNAL(albumChanged()), this, SLOT(albumChangedSlot())); 
   119     if(mType == VideoCollectionWrapper::ECollectionContent)
       
   120     {
       
   121         disconnect(mModel, SIGNAL(albumChanged()), this, SLOT(albumChangedSlot()));
       
   122     }
       
   123 
   125 }
   124 }
   126 
   125 
   127 // -----------------------------------------------------------------------------
   126 // -----------------------------------------------------------------------------
   128 // VideoSortFilterProxyModel::open
   127 // VideoSortFilterProxyModel::open
   129 // -----------------------------------------------------------------------------
   128 // -----------------------------------------------------------------------------
   135         return -1;
   134         return -1;
   136     }
   135     }
   137     
   136     
   138     if(mLevel != level) 
   137     if(mLevel != level) 
   139     {
   138     {
   140         mLevel = level;   
   139         mLevel = level;
   141         invalidateFilter();
   140         invalidateFilter();
   142     }
   141     }
   143     // need to call open every time to make sure all items are 
   142     // need to call open every time to make sure all items are 
   144     // inserted to UI ( recent open might have been cancelled)
   143     // inserted to UI ( recent open might have been cancelled)
   145     return mCollectionClient->startOpenCollection(level);
   144     return mCollectionClient->startOpenCollection(level);
   211         
   210         
   212         if(mModel->removeRows(mappedList))
   211         if(mModel->removeRows(mappedList))
   213         {
   212         {
   214             // Start fetching thumbnails at start of the model.
   213             // Start fetching thumbnails at start of the model.
   215             VideoThumbnailData::instance().startBackgroundFetching(0, 0);
   214             VideoThumbnailData::instance().startBackgroundFetching(0, 0);
   216             
       
   217             return 0;
   215             return 0;
   218         }
   216         }
   219     }
   217     }
   220     return -1;
   218     return -1;
   221 }
   219 }
   226 //
   224 //
   227 int VideoSortFilterProxyModel::openItem(TMPXItemId mediaId)
   225 int VideoSortFilterProxyModel::openItem(TMPXItemId mediaId)
   228 {
   226 {
   229     if(mediaId != TMPXItemId::InvalidId() && mCollectionClient)
   227     if(mediaId != TMPXItemId::InvalidId() && mCollectionClient)
   230     {
   228     {
   231         mModel->setAlbumInUse(TMPXItemId::InvalidId());
       
   232         
       
   233         if(mCollectionClient->openItem(mediaId) == 0)
   229         if(mCollectionClient->openItem(mediaId) == 0)
   234         {
   230         {
   235             if(mediaId.iId2 != KVcxMvcMediaTypeVideo)
   231             if(mediaId.iId2 != KVcxMvcMediaTypeVideo)
   236             { 
   232             { 
   237                 mLevel = VideoCollectionCommon::ELevelAlbum;
   233                 mLevel = VideoCollectionCommon::ELevelAlbum;
   248 // VideoSortFilterProxyModel::back
   244 // VideoSortFilterProxyModel::back
   249 // -----------------------------------------------------------------------------
   245 // -----------------------------------------------------------------------------
   250 //
   246 //
   251 int VideoSortFilterProxyModel::back()
   247 int VideoSortFilterProxyModel::back()
   252 {
   248 {
   253 
       
   254     if(mCollectionClient && mCollectionClient->back() == 0)
   249     if(mCollectionClient && mCollectionClient->back() == 0)
   255     {
   250     {
   256 
       
   257         if(mLevel == VideoCollectionCommon::ELevelAlbum)
   251         if(mLevel == VideoCollectionCommon::ELevelAlbum)
   258         {
   252         {
   259             mLevel = VideoCollectionCommon::ELevelCategory;
   253             mLevel = VideoCollectionCommon::ELevelCategory;
   260         }
   254         }
   261         else
   255         else
   262         {
   256         {
   263             mLevel = VideoCollectionCommon::ELevelVideos;
   257             mLevel = VideoCollectionCommon::ELevelVideos;
   264         }
   258         }
   265         return 0;
   259         return 0;
   266     }
   260     }
   267 
       
   268     return -1;
   261     return -1;
   269 }
   262 }
   270 
   263 
   271 // -----------------------------------------------------------------------------
   264 // -----------------------------------------------------------------------------
   272 // VideoSortFilterProxyModel::fetchItemDetails
   265 // VideoSortFilterProxyModel::fetchItemDetails
   412 
   405 
   413 // -----------------------------------------------------------------------------
   406 // -----------------------------------------------------------------------------
   414 // VideoSortFilterProxyModel::filterAcceptsRow
   407 // VideoSortFilterProxyModel::filterAcceptsRow
   415 // -----------------------------------------------------------------------------
   408 // -----------------------------------------------------------------------------
   416 //
   409 //
   417 bool VideoSortFilterProxyModel::filterAcceptsRow (int source_row, const QModelIndex &source_parent) const
   410 bool VideoSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
   418 {
   411 {
   419     Q_UNUSED(source_parent);
   412     Q_UNUSED(source_parent);
   420 
   413     
   421     if(!sourceModel())
   414     if(!sourceModel())
   422         return false;
   415         return false;
   423 
   416 
   424     if(source_row < 0 || source_row >= sourceModel()->rowCount())
   417     if(source_row < 0 || source_row >= sourceModel()->rowCount())
   425     {
   418     {
   438             return true;
   431             return true;
   439         }
   432         }
   440     }
   433     }
   441     else if(mType == VideoCollectionWrapper::ECollections)
   434     else if(mType == VideoCollectionWrapper::ECollections)
   442     {
   435     {
   443         
       
   444         if(mLevel == VideoCollectionCommon::ELevelCategory && id.iId2 != KVcxMvcMediaTypeVideo)
   436         if(mLevel == VideoCollectionCommon::ELevelCategory && id.iId2 != KVcxMvcMediaTypeVideo)
   445         {
   437         {
   446             return true;
   438             return true;
   447         }       
   439         }       
   448     }
   440     }
   454             return true;
   446             return true;
   455         }
   447         }
   456     }
   448     }
   457     else if(mType == VideoCollectionWrapper::EGeneric)
   449     else if(mType == VideoCollectionWrapper::EGeneric)
   458     {
   450     {
   459 
       
   460         if(mLevel == VideoCollectionCommon::ELevelVideos && id.iId2 == KVcxMvcMediaTypeVideo)
   451         if(mLevel == VideoCollectionCommon::ELevelVideos && id.iId2 == KVcxMvcMediaTypeVideo)
   461         {
   452         {
   462             //  filter items that belong to that album setted as filter id
   453             //  filter items that belong to that album setted as filter id
   463             // if there's no filter or setted filter is "all videos", we accept everything
   454             // if there's no filter or setted filter is "all videos", we accept everything
   464             if(mGenericFilterId == TMPXItemId::InvalidId() || 
   455             if(mGenericFilterId == TMPXItemId::InvalidId() || 
   622 
   613 
   623 // -----------------------------------------------------------------------------
   614 // -----------------------------------------------------------------------------
   624 // VideoSortFilterProxyModel::addItemsInAlbum()
   615 // VideoSortFilterProxyModel::addItemsInAlbum()
   625 // -----------------------------------------------------------------------------
   616 // -----------------------------------------------------------------------------
   626 //
   617 //
   627 int VideoSortFilterProxyModel::addItemsInAlbum(TMPXItemId albumId,
   618 int VideoSortFilterProxyModel::addItemsInAlbum(TMPXItemId &albumId,
   628         const QList<TMPXItemId> &mediaIds)
   619         const QList<TMPXItemId> &mediaIds)
   629 {
   620 {
   630     int err(-1);
   621     int err(-1);
   631     
   622     
   632     if (mCollectionClient)
   623     if (mCollectionClient)
   637     
   628     
   638     return err;
   629     return err;
   639 }
   630 }
   640 
   631 
   641 // -----------------------------------------------------------------------------
   632 // -----------------------------------------------------------------------------
       
   633 // VideoSortFilterProxyModel::removeItemsFromAlbum()
       
   634 // -----------------------------------------------------------------------------
       
   635 //
       
   636 int VideoSortFilterProxyModel::removeItemsFromAlbum(TMPXItemId &albumId, 
       
   637         const QList<TMPXItemId> &mediaIds)
       
   638 {
       
   639     int err(-1);
       
   640        
       
   641     if (mModel)
       
   642     {        
       
   643         // remove items in album
       
   644         err = mModel->removeItemsFromAlbum(albumId, mediaIds);
       
   645         if(err > 0)
       
   646         {
       
   647             // if there really were items to be removed, invalid filter
       
   648             invalidateFilter();
       
   649             err = 0;
       
   650         }
       
   651     }
       
   652     return err;
       
   653 }
       
   654 
       
   655 // -----------------------------------------------------------------------------
   642 // VideoSortFilterProxyModel::getOpenItem()
   656 // VideoSortFilterProxyModel::getOpenItem()
   643 // -----------------------------------------------------------------------------
   657 // -----------------------------------------------------------------------------
   644 //
   658 //
   645 TMPXItemId VideoSortFilterProxyModel::getOpenItem() const
   659 TMPXItemId VideoSortFilterProxyModel::getOpenItem() const
   646 {
   660 {
   675         invalidateFilter();
   689         invalidateFilter();
   676     }
   690     }
   677 }
   691 }
   678 
   692 
   679 // -----------------------------------------------------------------------------
   693 // -----------------------------------------------------------------------------
       
   694 // VideoSortFilterProxyModel::setAlbumInUse()
       
   695 // -----------------------------------------------------------------------------
       
   696 //
       
   697 void VideoSortFilterProxyModel::setAlbumInUse(TMPXItemId albumId)
       
   698 {
       
   699     mModel->setAlbumInUse(albumId);
       
   700     invalidateFilter();
       
   701 }
       
   702 
       
   703 // -----------------------------------------------------------------------------
   680 // VideoSortFilterProxyModel::albumChangedSlot()
   704 // VideoSortFilterProxyModel::albumChangedSlot()
   681 // -----------------------------------------------------------------------------
   705 // -----------------------------------------------------------------------------
   682 //
   706 //
   683 void VideoSortFilterProxyModel::albumChangedSlot()
   707 void VideoSortFilterProxyModel::albumChangedSlot()
   684 {
   708 {