videocollection/videocollectionwrapper/src/videolistdatamodel.cpp
changeset 52 e3cecb93e76a
parent 20 b9e04db066d4
child 65 a9d57bd8d7b7
equal deleted inserted replaced
47:45e72b57a2fd 52:e3cecb93e76a
    13 *
    13 *
    14 * Description: VideoListDataModel class implementation
    14 * Description: VideoListDataModel class implementation
    15 * 
    15 * 
    16 */
    16 */
    17 
    17 
    18 // Version : %version: 52 %
    18 // Version : %version: 52.1.2 %
    19 
    19 
    20 // INCLUDE FILES
    20 // INCLUDE FILES
    21 #include <hbglobal.h>
    21 #include <hbglobal.h>
    22 #include <vcxmyvideosdefs.h>
    22 #include <vcxmyvideosdefs.h>
    23 
    23 
    97     {
    97     {
    98         ERROR(-1, "VideoListDataModel::initialize() private model init failed.");
    98         ERROR(-1, "VideoListDataModel::initialize() private model init failed.");
    99         return -1;
    99         return -1;
   100     }
   100     }
   101 
   101 
   102     if(connectSignals() == -1)
       
   103     {
       
   104         ERROR(-1, "VideoListDataModel::initialize() failed to connect signals.");
       
   105         disconnectSignals();
       
   106         return -1;
       
   107     }
       
   108 
       
   109     mInitialized = true;
   102     mInitialized = true;
   110     return 0;
   103     return 0;
   111 }
   104 }
   112 
   105 
   113 // -----------------------------------------------------------------------------
   106 // -----------------------------------------------------------------------------
   122  
   115  
   123 // -----------------------------------------------------------------------------
   116 // -----------------------------------------------------------------------------
   124 // connectSignals()
   117 // connectSignals()
   125 // -----------------------------------------------------------------------------
   118 // -----------------------------------------------------------------------------
   126 //
   119 //
   127 int VideoListDataModel::connectSignals()
   120 void VideoListDataModel::connectSignals()
   128 {
   121 {
   129 	FUNC_LOG;
   122 	FUNC_LOG;
   130     if(!connect(d_ptr, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
   123 
   131                            this, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&))))
   124     connect(this, SIGNAL(modelChanged()), mDeleteWorker, SLOT(continueSlot()), Qt::UniqueConnection);
   132     {
   125 
   133         return -1;
   126     connect(this, SIGNAL(modelReady()), mDeleteWorker, SLOT(continueSlot()), Qt::UniqueConnection);
   134     }
   127 
   135     if(!connect(d_ptr, SIGNAL(videoDetailsReady(QVariant&)),
   128     connect(mDeleteWorker, SIGNAL(deleteStartupFailed(QList<TMPXItemId>&)), 
   136                        this, SIGNAL(fullVideoDetailsReady(QVariant&))))
   129             this, SLOT(deleteStartingFailsSlot(QList<TMPXItemId>&)), Qt::UniqueConnection);
   137     {
       
   138         return -1;
       
   139     }
       
   140     if(!connect(this, SIGNAL(modelChanged()), mDeleteWorker, SLOT(continueSlot())))
       
   141     {
       
   142         return -1;
       
   143     }
       
   144     if(!connect(this, SIGNAL(modelReady()), mDeleteWorker, SLOT(continueSlot())))
       
   145     {
       
   146         return -1;
       
   147     }
       
   148     if(!connect(mDeleteWorker, SIGNAL(deleteStartupFailed(QList<TMPXItemId>)), 
       
   149             this, SLOT(deleteStartingFailsSlot(QList<TMPXItemId>))))
       
   150     {
       
   151         return -1;
       
   152     }
       
   153    
       
   154     return 0;
       
   155 }
   130 }
   156 
   131 
   157 // -----------------------------------------------------------------------------
   132 // -----------------------------------------------------------------------------
   158 // disconnectSignals()
   133 // disconnectSignals()
   159 // -----------------------------------------------------------------------------
   134 // -----------------------------------------------------------------------------
   160 //
   135 //
   161 void VideoListDataModel::disconnectSignals()
   136 void VideoListDataModel::disconnectSignals()
   162 {
   137 {
   163 	FUNC_LOG;
   138 	FUNC_LOG;
   164     disconnect(d_ptr, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
       
   165                                this, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)));
       
   166     disconnect(d_ptr, SIGNAL(videoDetailsReady(QVariant&)),
       
   167                            this, SIGNAL(fullVideoDetailsReady(QVariant&)));
       
   168     disconnect(this, SIGNAL(modelChanged()), mDeleteWorker, SLOT(continueSlot()));
   139     disconnect(this, SIGNAL(modelChanged()), mDeleteWorker, SLOT(continueSlot()));
   169     disconnect(this, SIGNAL(modelReady()), mDeleteWorker, SLOT(continueSlot()));
   140     disconnect(this, SIGNAL(modelReady()), mDeleteWorker, SLOT(continueSlot()));
   170     disconnect(mDeleteWorker, SIGNAL(deleteStartupFailed(QList<TMPXItemId>)), 
   141     disconnect(mDeleteWorker, SIGNAL(deleteStartupFailed(QList<TMPXItemId>&)), 
   171                 this, SLOT(deleteStartingFailsSlot(QList<TMPXItemId>)));
   142                 this, SLOT(deleteStartingFailsSlot(QList<TMPXItemId>&)));
   172 }
   143 }
   173 
   144 
   174 // -----------------------------------------------------------------------------
   145 // -----------------------------------------------------------------------------
   175 // mediaIdAtIndex()
   146 // mediaIdAtIndex()
   176 // -----------------------------------------------------------------------------
   147 // -----------------------------------------------------------------------------
   177 //
   148 //
   178 TMPXItemId VideoListDataModel::mediaIdAtIndex(int index) const
   149 const TMPXItemId& VideoListDataModel::mediaIdAtIndex(const int &index) const
   179 {
   150 {
   180     TMPXItemId mpxId =TMPXItemId::InvalidId();
   151     return d_ptr->getMediaIdFromIndex(index); 
   181 
       
   182     if(index >= 0 && index < d_ptr->getVideoCount())
       
   183     {
       
   184         mpxId = d_ptr->getMediaIdFromIndex(index);
       
   185     }
       
   186 
       
   187     return mpxId;
       
   188 }
   152 }
   189 
   153 
   190 // -----------------------------------------------------------------------------
   154 // -----------------------------------------------------------------------------
   191 // indexOfId()
   155 // indexOfId()
   192 // -----------------------------------------------------------------------------
   156 // -----------------------------------------------------------------------------
   193 //
   157 //
   194 QModelIndex VideoListDataModel::indexOfId(TMPXItemId id)
   158 QModelIndex VideoListDataModel::indexOfId(const TMPXItemId &id)
   195 {
   159 {
   196     int rowIndex = d_ptr->mMediaData.indexOfId(id);
   160     int rowIndex = d_ptr->mMediaData.indexOfId(id);
   197     return index(rowIndex, 0, QModelIndex());     
   161     return index(rowIndex, 0, QModelIndex());     
   198 }
   162 }
   199 
   163 
   200 // -----------------------------------------------------------------------------
   164 // -----------------------------------------------------------------------------
   201 // mediaFilePathForId()
   165 // mediaFilePathForId()
   202 // -----------------------------------------------------------------------------
   166 // -----------------------------------------------------------------------------
   203 //
   167 //
   204 QString VideoListDataModel::mediaFilePathForId(TMPXItemId mediaId) const
   168 QString VideoListDataModel::mediaFilePathForId(const TMPXItemId &mediaId) const
   205 {
   169 {
   206     QString filePath;
   170     return d_ptr->getFilePathForId(mediaId);;
   207     filePath = d_ptr->getFilePathForId(mediaId);
       
   208 
       
   209     return filePath;
       
   210 }
   171 }
   211 
   172 
   212 // -----------------------------------------------------------------------------
   173 // -----------------------------------------------------------------------------
   213 // rowCount()
   174 // rowCount()
   214 // -----------------------------------------------------------------------------
   175 // -----------------------------------------------------------------------------
   246 
   207 
   247 // -----------------------------------------------------------------------------
   208 // -----------------------------------------------------------------------------
   248 // prepareDetailRow()
   209 // prepareDetailRow()
   249 // -----------------------------------------------------------------------------
   210 // -----------------------------------------------------------------------------
   250 //
   211 //
   251 QString VideoListDataModel::prepareDetailRow(int index) const
   212 QString VideoListDataModel::prepareDetailRow(int &index) const
   252 {
   213 {
   253     // TODO: download -status?
   214     // TODO: download -status?
   254 
   215 
   255     QString retString;
   216     QString retString;
   256     
   217     
   269 
   230 
   270 // -----------------------------------------------------------------------------
   231 // -----------------------------------------------------------------------------
   271 // prepareVideoCountString()
   232 // prepareVideoCountString()
   272 // -----------------------------------------------------------------------------
   233 // -----------------------------------------------------------------------------
   273 //
   234 //
   274 QString VideoListDataModel::prepareVideoCountString(int index) const
   235 QString VideoListDataModel::prepareVideoCountString(int &index) const
   275 {
   236 {
   276     QString videoCountString("");
   237     QString videoCountString("");
   277 
   238 
   278     quint32 items = d_ptr->getCategoryVideoCountFromIndex(index);
   239     quint32 items = d_ptr->getCategoryVideoCountFromIndex(index);
   279     if(items > 0)
   240     if(items > 0)
   290 
   251 
   291 // -----------------------------------------------------------------------------
   252 // -----------------------------------------------------------------------------
   292 // prepareSizeString()
   253 // prepareSizeString()
   293 // -----------------------------------------------------------------------------
   254 // -----------------------------------------------------------------------------
   294 //
   255 //
   295 QString VideoListDataModel::prepareSizeString(int index) const
   256 QString VideoListDataModel::prepareSizeString(int &index) const
   296 {
   257 {
   297     QString sizeStr("");
   258     QString sizeStr("");
   298 
   259 
   299     quint32 size = d_ptr->getVideoSizeFromIndex(index);
   260     quint32 size = d_ptr->getVideoSizeFromIndex(index);
   300     sizeStr = VideoCollectionUtils::instance().prepareSizeString(size);
   261     sizeStr = VideoCollectionUtils::instance().prepareSizeString(size);
   304 
   265 
   305 // -----------------------------------------------------------------------------
   266 // -----------------------------------------------------------------------------
   306 // VideoListDataModel::doDetailRow()
   267 // VideoListDataModel::doDetailRow()
   307 // -----------------------------------------------------------------------------
   268 // -----------------------------------------------------------------------------
   308 //
   269 //
   309 QString VideoListDataModel::doDetailRow(int index) const
   270 QString VideoListDataModel::doDetailRow(int &index) const
   310 {
   271 {
   311 	QString detailStr("");
   272 	QString detailStr("");
   312 	
   273 	
   313     quint32 size = d_ptr->getVideoSizeFromIndex(index);
   274     quint32 size = d_ptr->getVideoSizeFromIndex(index);
   314     
   275     
   510             removedIds.append(id);
   471             removedIds.append(id);
   511         }
   472         }
   512     }
   473     }
   513     emit modelChanged();
   474     emit modelChanged();
   514     if(removedIds.count() > 0 )
   475     if(removedIds.count() > 0 )
   515     {                         
   476     {    
       
   477         connectSignals();
   516         mDeleteWorker->requestDelete(removedIds);
   478         mDeleteWorker->requestDelete(removedIds);
   517         return true;
   479         return true;
   518     }
   480     }
   519     return false;
   481     return false;
   520 }
   482 }
   531 
   493 
   532 // -----------------------------------------------------------------------------
   494 // -----------------------------------------------------------------------------
   533 // setAlbumInUse()
   495 // setAlbumInUse()
   534 // -----------------------------------------------------------------------------
   496 // -----------------------------------------------------------------------------
   535 //
   497 //
   536 void VideoListDataModel::setAlbumInUse(TMPXItemId albumId)
   498 void VideoListDataModel::setAlbumInUse(const TMPXItemId &albumId)
   537 {
   499 {
   538 	FUNC_LOG;
   500 	FUNC_LOG;
   539     d_ptr->setAlbumInUse(albumId);
   501     d_ptr->setAlbumInUse(albumId);
   540 }
   502 }
   541 
   503 
   542 // -----------------------------------------------------------------------------
   504 // -----------------------------------------------------------------------------
   543 // albumInUse()
   505 // albumInUse()
   544 // -----------------------------------------------------------------------------
   506 // -----------------------------------------------------------------------------
   545 //
   507 //
   546 TMPXItemId VideoListDataModel::albumInUse()
   508 const TMPXItemId& VideoListDataModel::albumInUse() const
   547 {
   509 {
   548 	FUNC_LOG;
   510 	FUNC_LOG;
   549     return d_ptr->mCurrentAlbum;
   511     return d_ptr->mCurrentAlbum;
   550 }
   512 }
   551 
   513 
   552 // -----------------------------------------------------------------------------
   514 // -----------------------------------------------------------------------------
   553 // removeItemsFromAlbum()
   515 // removeItemsFromAlbum()
   554 // -----------------------------------------------------------------------------
   516 // -----------------------------------------------------------------------------
   555 //
   517 //
   556 int VideoListDataModel::removeItemsFromAlbum(TMPXItemId &albumId, const QList<TMPXItemId> &items)
   518 int VideoListDataModel::removeItemsFromAlbum(const TMPXItemId &albumId, const QList<TMPXItemId> &items)
   557 {
   519 {
   558 	FUNC_LOG;
   520 	FUNC_LOG;
   559     int removeCount = d_ptr->removeItemsFromAlbum(albumId, items);
   521     int removeCount = d_ptr->removeItemsFromAlbum(albumId, items);
   560     if(removeCount)
   522     if(removeCount)
   561     {
   523     {
   571 
   533 
   572 // -----------------------------------------------------------------------------
   534 // -----------------------------------------------------------------------------
   573 // deleteStartingFailsSlot()
   535 // deleteStartingFailsSlot()
   574 // -----------------------------------------------------------------------------
   536 // -----------------------------------------------------------------------------
   575 //
   537 //
   576 void VideoListDataModel::deleteStartingFailsSlot(QList<TMPXItemId> ids)
   538 void VideoListDataModel::deleteStartingFailsSlot(QList<TMPXItemId>& ids)
   577 {
   539 {
   578 	FUNC_LOG;
   540 	FUNC_LOG;
   579     if(ids.count())
   541     if(ids.count())
   580     {        
   542     {        
   581         d_ptr->restoreRemoved(&ids);
   543         d_ptr->restoreRemoved(&ids);
   608         if(!mDeleteWorker->isDeleting())
   570         if(!mDeleteWorker->isDeleting())
   609         {
   571         {
   610             report = true;
   572             report = true;
   611             // delete procedure ends, reset statuses
   573             // delete procedure ends, reset statuses
   612             mDeleteWorker->clearStatus();
   574             mDeleteWorker->clearStatus();
       
   575             disconnectSignals();
   613         }
   576         }
   614     }
   577     }
   615     if(report)
   578     if(report)
   616     {
   579     {
   617         VideoCollectionWrapper::instance().sendAsyncStatus(statusCode, additional); 
   580         VideoCollectionWrapper::instance().sendAsyncStatus(statusCode, additional);