videocollection/videocollectionwrapper/src/videosortfilterproxymodel.cpp
changeset 36 8aed59de29f9
parent 35 3738fe97f027
child 37 4eb2df7f7cbe
equal deleted inserted replaced
35:3738fe97f027 36:8aed59de29f9
    13 *
    13 *
    14 * Description:   Videosortfilterproxymodel implementation
    14 * Description:   Videosortfilterproxymodel implementation
    15 *
    15 *
    16 */
    16 */
    17 
    17 
       
    18 // Version : %version: 63 %
       
    19 
       
    20 // INCLUDE FILES
    18 #include <qstringlist.h>
    21 #include <qstringlist.h>
    19 #include <qset.h>
    22 #include <qset.h>
    20 #include <qtimer.h>
    23 #include <qtimer.h>
    21 #include <qdatetime.h>
    24 #include <qdatetime.h>
    22 #include <vcxmyvideosdefs.h>
    25 #include <vcxmyvideosdefs.h>
    25 #include "videocollectioncommon.h"
    28 #include "videocollectioncommon.h"
    26 #include "videosortfilterproxymodel.h"
    29 #include "videosortfilterproxymodel.h"
    27 #include "videolistdatamodel.h"
    30 #include "videolistdatamodel.h"
    28 #include "videocollectionclient.h"
    31 #include "videocollectionclient.h"
    29 #include "videocollectionwrapper.h"
    32 #include "videocollectionwrapper.h"
       
    33 #include "videocollectiontrace.h"
    30 
    34 
    31 // -----------------------------------------------------------------------------
    35 // -----------------------------------------------------------------------------
    32 // VideoSortFilterProxyModel::VideoSortFilterProxyModel
    36 // VideoSortFilterProxyModel::VideoSortFilterProxyModel
    33 // -----------------------------------------------------------------------------
    37 // -----------------------------------------------------------------------------
    34 //
    38 //
    35 VideoSortFilterProxyModel::VideoSortFilterProxyModel(int type, QObject *parent) :
    39 VideoSortFilterProxyModel::VideoSortFilterProxyModel(VideoCollectionCommon::TModelType type, QObject *parent) :
    36 QSortFilterProxyModel(parent),
    40 QSortFilterProxyModel(parent),
    37 mModel(0),
    41 mModel(0),
    38 mCollectionClient(0),
    42 mCollectionClient(0),
    39 mType(type),
    43 mType(type),
    40 mLevel(-1),
    44 mLevel(VideoCollectionCommon::ELevelInvalid),
    41 mGenericFilterId(TMPXItemId::InvalidId()),
    45 mGenericFilterId(TMPXItemId::InvalidId()),
    42 mGenericFilterValue(false),
    46 mGenericFilterValue(false),
    43 mIdleSortTimer(0),
    47 mIdleSortTimer(0),
    44 mWantedSortRole(VideoCollectionCommon::KeyDateTime)
    48 mWantedSortRole(VideoCollectionCommon::KeyDateTime),
    45 {
    49 mWantedSortOrder(Qt::AscendingOrder)
    46     // NOP
    50 {
       
    51 	FUNC_LOG_ADDR(this);
       
    52 	INFO_2("VideoSortFilterProxyModel::VideoSortFilterProxyModel() [0x%x]: type: %d", this, type);
    47 }
    53 }
    48 
    54 
    49 // -----------------------------------------------------------------------------
    55 // -----------------------------------------------------------------------------
    50 // VideoSortFilterProxyModel::~VideoSortFilterProxyModel
    56 // VideoSortFilterProxyModel::~VideoSortFilterProxyModel
    51 // -----------------------------------------------------------------------------
    57 // -----------------------------------------------------------------------------
    52 //
    58 //
    53 VideoSortFilterProxyModel::~VideoSortFilterProxyModel()
    59 VideoSortFilterProxyModel::~VideoSortFilterProxyModel()
    54 {
    60 {
    55     // NOP
    61 	FUNC_LOG_ADDR(this);
    56 }
    62 }
    57 
    63 
    58 // -----------------------------------------------------------------------------
    64 // -----------------------------------------------------------------------------
    59 // VideoSortFilterProxyModel::initialize
    65 // VideoSortFilterProxyModel::initialize
    60 // -----------------------------------------------------------------------------
    66 // -----------------------------------------------------------------------------
    61 //
    67 //
    62 int VideoSortFilterProxyModel::initialize(VideoListDataModel *sourceModel)
    68 int VideoSortFilterProxyModel::initialize(VideoListDataModel *sourceModel)
    63 {
    69 {
       
    70 	FUNC_LOG_ADDR(this);
    64     if(!sourceModel)
    71     if(!sourceModel)
    65     {
    72     {
    66         return -1;
    73         return -1;
    67     }
    74     }
    68     
    75     
    69     if(!mModel) 
    76     if(!mModel) 
    70     {
    77     {
    71         mModel = sourceModel;
    78         mModel = sourceModel;
    72         if(!connectSignals()) 
    79         if(!connectSignals()) 
    73         {
    80         {
       
    81             ERROR_1(-1, "VideoSortFilterProxyModel::initialize() [0x%x] failed to connect signals.", this);
    74             disconnectSignals();
    82             disconnectSignals();
    75             mModel = 0;
    83             mModel = 0;
    76             return -1;
    84             return -1;
    77         }
    85         }
    78         mCollectionClient = mModel->getCollectionClient();
    86         mCollectionClient = mModel->getCollectionClient();
    85 // VideoSortFilterProxyModel::connectSignals
    93 // VideoSortFilterProxyModel::connectSignals
    86 // -----------------------------------------------------------------------------
    94 // -----------------------------------------------------------------------------
    87 //
    95 //
    88 bool VideoSortFilterProxyModel::connectSignals()
    96 bool VideoSortFilterProxyModel::connectSignals()
    89 {
    97 {
       
    98 	FUNC_LOG_ADDR(this);
    90     if(!connect(mModel, SIGNAL(modelReady()),
    99     if(!connect(mModel, SIGNAL(modelReady()),
    91             this, SIGNAL(modelReady()))) 
   100             this, SIGNAL(modelReady()))) 
    92     {
   101     {
    93         return false;
   102         return false;
    94     }
   103     }
    95     if(!connect(mModel, SIGNAL(modelChanged()),
   104     if(!connect(mModel, SIGNAL(modelChanged()),
    96                     this, SIGNAL(modelChanged()))) 
   105                     this, SIGNAL(modelChanged()))) 
    97     {
   106     {
    98         return false;
   107         return false;
    99     }
   108     }
   100     if(mType == VideoCollectionWrapper::ECollectionContent)
   109     if(mType == VideoCollectionCommon::EModelTypeCollectionContent)
   101     {
   110     {
   102         if(!connect(mModel, SIGNAL(albumChanged()),
   111         if(!connect(mModel, SIGNAL(albumChanged()),
   103                     this, SLOT(albumChangedSlot()))) 
   112                     this, SLOT(albumChangedSlot()))) 
   104         {
   113         {
   105             return false;
   114             return false;
   106         }
   115         }
   107     }
   116     }
       
   117     if(mType == VideoCollectionCommon::EModelTypeCollections)
       
   118     {
       
   119         if(!connect(mModel, SIGNAL(itemModified(const TMPXItemId &)),
       
   120                     this, SLOT(itemModifiedSlot(const TMPXItemId &)))) 
       
   121         {
       
   122             return false;
       
   123         }
       
   124     }
   108     return true;
   125     return true;
   109 }
   126 }
   110    
   127    
   111 // -----------------------------------------------------------------------------
   128 // -----------------------------------------------------------------------------
   112 // VideoSortFilterProxyModel::disconnectSignals
   129 // VideoSortFilterProxyModel::disconnectSignals
   113 // -----------------------------------------------------------------------------
   130 // -----------------------------------------------------------------------------
   114 //
   131 //
   115 void VideoSortFilterProxyModel::disconnectSignals()
   132 void VideoSortFilterProxyModel::disconnectSignals()
   116 {
   133 {
       
   134 	FUNC_LOG_ADDR(this);
   117 	disconnect(mModel, SIGNAL(modelReady()), this, SIGNAL(modelReady()));
   135 	disconnect(mModel, SIGNAL(modelReady()), this, SIGNAL(modelReady()));
   118     disconnect(mModel, SIGNAL(modelChanged()), this, SIGNAL(modelChanged()));
   136     disconnect(mModel, SIGNAL(modelChanged()), this, SIGNAL(modelChanged()));
   119     if(mType == VideoCollectionWrapper::ECollectionContent)
   137     if(mType == VideoCollectionCommon::EModelTypeCollectionContent)
   120     {
   138     {
   121         disconnect(mModel, SIGNAL(albumChanged()), this, SLOT(albumChangedSlot()));
   139         disconnect(mModel, SIGNAL(albumChanged()), this, SLOT(albumChangedSlot()));
   122     }
   140     }
   123 
   141     if(mType == VideoCollectionCommon::EModelTypeCollections)
       
   142     {
       
   143         disconnect(mModel, SIGNAL(itemModified(const TMPXItemId &)), 
       
   144                    this, SLOT(itemModifiedSlot(const TMPXItemId &)));
       
   145     }
   124 }
   146 }
   125 
   147 
   126 // -----------------------------------------------------------------------------
   148 // -----------------------------------------------------------------------------
   127 // VideoSortFilterProxyModel::open
   149 // VideoSortFilterProxyModel::open
   128 // -----------------------------------------------------------------------------
   150 // -----------------------------------------------------------------------------
   129 //
   151 //
   130 int VideoSortFilterProxyModel::open(int level)
   152 int VideoSortFilterProxyModel::open(VideoCollectionCommon::TCollectionLevels level)
   131 {
   153 {
       
   154 	FUNC_LOG_ADDR(this);
       
   155 	INFO_2("VideoSortFilterProxyModel::open() [0x%x] level: %d", this, level);
       
   156 	
   132     if(!mCollectionClient)
   157     if(!mCollectionClient)
   133     {
   158     {
   134         return -1;
   159         return -1;
   135     }
   160     }
   136     
   161     
   137     if(mLevel != level) 
   162     if(mLevel != level) 
   138     {
   163     {
       
   164         INFO_1("VideoSortFilterProxyModel::open() [0x%x] opening different level, invalidating.", this);
   139         mLevel = level;
   165         mLevel = level;
   140         invalidateFilter();
   166         invalidateFilter();
   141     }
   167     }
   142     // need to call open every time to make sure all items are 
   168     // need to call open every time to make sure all items are 
   143     // inserted to UI ( recent open might have been cancelled)
   169     // inserted to UI ( recent open might have been cancelled)
   149 // -----------------------------------------------------------------------------
   175 // -----------------------------------------------------------------------------
   150 //
   176 //
   151 void VideoSortFilterProxyModel::doSorting(int sortingRole, Qt::SortOrder order, 
   177 void VideoSortFilterProxyModel::doSorting(int sortingRole, Qt::SortOrder order, 
   152         bool async)
   178         bool async)
   153 {
   179 {
   154     if((sortingRole != Qt::DisplayRole) &&
   180 	FUNC_LOG_ADDR(this);
   155        (sortingRole != VideoCollectionCommon::KeySizeValue) &&
   181 	INFO_3("VideoSortFilterProxyModel::doSorting() [0x%x] sortingRole: %d, order: %d", this, sortingRole, order);
   156        (sortingRole != VideoCollectionCommon::KeyDateTime))
   182 	
   157     {
   183     if(sortingRole != VideoCollectionCommon::KeyTitle &&
   158         // default sorting order is by date
   184        sortingRole != VideoCollectionCommon::KeySizeValue &&
   159         mWantedSortRole = VideoCollectionCommon::KeyDateTime;
   185        sortingRole != VideoCollectionCommon::KeyDateTime &&
       
   186        sortingRole != VideoCollectionCommon::KeyNumberOfItems)
       
   187     {
       
   188         // default sorting order is by date for other models but collections.
       
   189         if(mType != VideoCollectionCommon::EModelTypeCollections)
       
   190         {   
       
   191             mWantedSortRole = VideoCollectionCommon::KeyDateTime;
       
   192         }
       
   193         else
       
   194         {
       
   195             mWantedSortRole = VideoCollectionCommon::KeyTitle;
       
   196         }
   160     }
   197     }
   161     else
   198     else
   162     {
   199     {
   163         mWantedSortRole = sortingRole;
   200         mWantedSortRole = sortingRole;
   164     }
   201     }
   178         {
   215         {
   179             mIdleSortTimer = new QTimer(this);
   216             mIdleSortTimer = new QTimer(this);
   180             connect(mIdleSortTimer, SIGNAL(timeout()), this, SLOT(processSorting()));
   217             connect(mIdleSortTimer, SIGNAL(timeout()), this, SLOT(processSorting()));
   181         }
   218         }
   182         mIdleSortTimer->start(0);
   219         mIdleSortTimer->start(0);
   183     } else {
   220     }
       
   221     else
       
   222     {
   184         processSorting();
   223         processSorting();
   185     }
   224     }
   186 }
   225 }
   187 // -----------------------------------------------------------------------------
   226 // -----------------------------------------------------------------------------
   188 // VideoSortFilterProxyModel::getSorting
   227 // VideoSortFilterProxyModel::getSorting
   189 // -----------------------------------------------------------------------------
   228 // -----------------------------------------------------------------------------
   190 //
   229 //
   191 void VideoSortFilterProxyModel::getSorting(int &sortingRole, Qt::SortOrder &order)
   230 void VideoSortFilterProxyModel::getSorting(int &sortingRole, Qt::SortOrder &order)
   192 {
   231 {
       
   232 	FUNC_LOG_ADDR(this);
   193 	sortingRole = mWantedSortRole;
   233 	sortingRole = mWantedSortRole;
   194 	order       = mWantedSortOrder;
   234 	order       = mWantedSortOrder;
   195 }
   235 }
   196 
   236 
   197 // -----------------------------------------------------------------------------
   237 // -----------------------------------------------------------------------------
   198 // VideoSortFilterProxyModel::deleteItems
   238 // VideoSortFilterProxyModel::deleteItems
   199 // -----------------------------------------------------------------------------
   239 // -----------------------------------------------------------------------------
   200 //
   240 //
   201 int VideoSortFilterProxyModel::deleteItems(const QModelIndexList &indexList)
   241 int VideoSortFilterProxyModel::deleteItems(const QModelIndexList &indexList)
   202 {
   242 {
       
   243 	FUNC_LOG_ADDR(this);
   203     if(mModel)
   244     if(mModel)
   204     {
   245     {
   205         QModelIndexList mappedList;
   246         QModelIndexList mappedList;
   206         for(int i = 0; i < indexList.count(); ++i)
   247         for(int i = 0; i < indexList.count(); ++i)
   207         {
   248         {
   222 // VideoSortFilterProxyModel::openItem
   263 // VideoSortFilterProxyModel::openItem
   223 // -----------------------------------------------------------------------------
   264 // -----------------------------------------------------------------------------
   224 //
   265 //
   225 int VideoSortFilterProxyModel::openItem(TMPXItemId mediaId)
   266 int VideoSortFilterProxyModel::openItem(TMPXItemId mediaId)
   226 {
   267 {
       
   268 	FUNC_LOG_ADDR(this);
   227     if(mediaId != TMPXItemId::InvalidId() && mCollectionClient)
   269     if(mediaId != TMPXItemId::InvalidId() && mCollectionClient)
   228     {
   270     {
   229         if(mCollectionClient->openItem(mediaId) == 0)
   271         if(mCollectionClient->openItem(mediaId) == 0)
   230         {
   272         {
   231             if(mediaId.iId2 != KVcxMvcMediaTypeVideo)
   273             if(mediaId.iId2 != KVcxMvcMediaTypeVideo)
   232             { 
   274             { 
   233                 mLevel = VideoCollectionCommon::ELevelAlbum;
   275                 mLevel = VideoCollectionCommon::ELevelAlbum;
   234                 mModel->setAlbumInUse(mediaId);
   276                 mModel->setAlbumInUse(mediaId);
       
   277                 INFO_1("VideoSortFilterProxyModel::open() [0x%x] opening album or category, invalidating.", this);
   235                 invalidateFilter();
   278                 invalidateFilter();
   236             } 
   279             } 
   237             return 0;
   280             return 0;
   238         }
   281         }
   239     }
   282     }
   244 // VideoSortFilterProxyModel::back
   287 // VideoSortFilterProxyModel::back
   245 // -----------------------------------------------------------------------------
   288 // -----------------------------------------------------------------------------
   246 //
   289 //
   247 int VideoSortFilterProxyModel::back()
   290 int VideoSortFilterProxyModel::back()
   248 {
   291 {
       
   292 	FUNC_LOG_ADDR(this);
   249     if(mCollectionClient && mCollectionClient->back() == 0)
   293     if(mCollectionClient && mCollectionClient->back() == 0)
   250     {
   294     {
   251         if(mLevel == VideoCollectionCommon::ELevelAlbum)
   295         if(mLevel == VideoCollectionCommon::ELevelAlbum)
   252         {
   296         {
   253             mLevel = VideoCollectionCommon::ELevelCategory;
   297             mLevel = VideoCollectionCommon::ELevelCategory;
   265 // VideoSortFilterProxyModel::fetchItemDetails
   309 // VideoSortFilterProxyModel::fetchItemDetails
   266 // -----------------------------------------------------------------------------
   310 // -----------------------------------------------------------------------------
   267 //
   311 //
   268 int VideoSortFilterProxyModel::fetchItemDetails(const QModelIndex &index)
   312 int VideoSortFilterProxyModel::fetchItemDetails(const QModelIndex &index)
   269 {
   313 {
       
   314 	FUNC_LOG_ADDR(this);
   270     // no need to map index beforehand, because 
   315     // no need to map index beforehand, because 
   271 	// getMediaIdAtIndex maps it
   316 	// getMediaIdAtIndex maps it
   272     TMPXItemId mpxId1 = getMediaIdAtIndex(index);
   317     TMPXItemId mpxId1 = getMediaIdAtIndex(index);
   273     if(mpxId1 != TMPXItemId::InvalidId() && mCollectionClient)
   318     if(mpxId1 != TMPXItemId::InvalidId() && mCollectionClient)
   274     {
   319     {
   275         if(mCollectionClient->getVideoDetails(mpxId1) == 0)
   320         if(mCollectionClient->getVideoDetails(mpxId1) == 0)
   276         {
   321         {
   277 
       
   278             emit shortDetailsReady(mpxId1);
   322             emit shortDetailsReady(mpxId1);
   279             return 0;
   323             return 0;
   280         }
   324         }
   281     }
   325     }
   282     return -1;
   326     return -1;
   286 // VideoSortFilterProxyModel::processSorting
   330 // VideoSortFilterProxyModel::processSorting
   287 // -----------------------------------------------------------------------------
   331 // -----------------------------------------------------------------------------
   288 //
   332 //
   289 void VideoSortFilterProxyModel::processSorting()
   333 void VideoSortFilterProxyModel::processSorting()
   290 {
   334 {
       
   335 	FUNC_LOG_ADDR(this);
   291     if(mIdleSortTimer)
   336     if(mIdleSortTimer)
   292     {
   337     {
   293         mIdleSortTimer->stop();
   338         mIdleSortTimer->stop();
   294     }
   339     }
   295 
   340 
   328     }
   373     }
   329     TMPXItemId leftId = mModel->mediaIdAtIndex(left.row());
   374     TMPXItemId leftId = mModel->mediaIdAtIndex(left.row());
   330     TMPXItemId rightId = mModel->mediaIdAtIndex(right.row());
   375     TMPXItemId rightId = mModel->mediaIdAtIndex(right.row());
   331     
   376     
   332     // Default categories are always first in the following order:
   377     // Default categories are always first in the following order:
   333     // Recently played (missing currently
   378     // Recently played (missing currently)
   334     // Captured
   379     // Captured
   335     // Downloaded
   380     // Downloaded
   336     // Podcasts (missing currently)
   381     // Podcasts (missing currently)
   337     bool lessThan(false);
   382     bool lessThan(false);
   338     bool proceedDataSorting(false);
   383     bool proceedDataSorting(false);
   366     {
   411     {
   367         return mWantedSortOrder == Qt::AscendingOrder ? lessThan : !lessThan;
   412         return mWantedSortOrder == Qt::AscendingOrder ? lessThan : !lessThan;
   368     }
   413     }
   369     
   414     
   370     // Do comparisation based on the role:
   415     // Do comparisation based on the role:
   371     //  Qt::DisplayRole,
   416     //  VideoCollectionCommon::KeyTitle,
   372     //  VideoCollectionCommon::KeySizeValue,
   417     //  VideoCollectionCommon::KeySizeValue,
       
   418     //  VideoCollectionCommon::KeyNumberOfItems,
   373     //  VideoCollectionCommon::KeyDateValue
   419     //  VideoCollectionCommon::KeyDateValue
   374     // 
   420     // 
   375     // If role does not match, do not sort
   421     // If role does not match, do not sort
   376     int sRole = sortRole();
   422     int sRole = sortRole();
   377     QVariant leftData = sourceModel()->data(left, sRole);
   423     QVariant leftData = sourceModel()->data(left, sRole);
   379 
   425 
   380     if(!leftData.isValid() || !rightData.isValid())
   426     if(!leftData.isValid() || !rightData.isValid())
   381     {
   427     {
   382         return false;
   428         return false;
   383     }
   429     }
   384     if(sRole == Qt::DisplayRole)
   430     if(sRole == VideoCollectionCommon::KeyTitle)
   385     {
   431     {
   386         QString leftString = leftData.toStringList().first().toUpper();
   432         QString leftString = leftData.toString().toUpper();
   387         QString rightString = rightData.toStringList().first().toUpper();
   433         QString rightString = rightData.toString().toUpper();
   388         return QString::localeAwareCompare(leftString, rightString) < 0;
   434         return QString::localeAwareCompare(leftString, rightString) < 0;
   389     }
   435     }
   390     else if(sRole == VideoCollectionCommon::KeySizeValue)
   436     else if(sRole == VideoCollectionCommon::KeySizeValue ||
       
   437             sRole == VideoCollectionCommon::KeyNumberOfItems)
   391     {
   438     {
   392         quint32 leftSize = leftData.toUInt();
   439         quint32 leftSize = leftData.toUInt();
   393         quint32 rightSize = rightData.toUInt();
   440         quint32 rightSize = rightData.toUInt();
   394         return leftSize < rightSize;
   441         return leftSize < rightSize;
   395     }
   442     }
   410 bool VideoSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
   457 bool VideoSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
   411 {
   458 {
   412     Q_UNUSED(source_parent);
   459     Q_UNUSED(source_parent);
   413     
   460     
   414     if(!sourceModel())
   461     if(!sourceModel())
       
   462     {
   415         return false;
   463         return false;
       
   464     }
   416 
   465 
   417     if(source_row < 0 || source_row >= sourceModel()->rowCount())
   466     if(source_row < 0 || source_row >= sourceModel()->rowCount())
   418     {
   467     {
   419         return false;
   468         return false;
   420     }
   469     }
   422     if(id == TMPXItemId::InvalidId())
   471     if(id == TMPXItemId::InvalidId())
   423     {
   472     {
   424         return false;
   473         return false;
   425     }
   474     }
   426     
   475     
   427     if (mType == VideoCollectionWrapper::EAllVideos)
   476     if (mType == VideoCollectionCommon::EModelTypeAllVideos)
   428     {
   477     {
   429         if(id.iId2 == KVcxMvcMediaTypeVideo)
   478         if(id.iId2 == KVcxMvcMediaTypeVideo)
   430         {
   479         {
   431             return true;
   480             return true;
   432         }
   481         }
   433     }
   482     }
   434     else if(mType == VideoCollectionWrapper::ECollections)
   483     else if(mType == VideoCollectionCommon::EModelTypeCollections)
   435     {
   484     {
   436         if(mLevel == VideoCollectionCommon::ELevelCategory && id.iId2 != KVcxMvcMediaTypeVideo)
   485         if(mLevel == VideoCollectionCommon::ELevelCategory && id.iId2 != KVcxMvcMediaTypeVideo)
   437         {
   486         {
   438             return true;
   487             return true;
   439         }       
   488         }       
   440     }
   489     }
   441     else if (mType == VideoCollectionWrapper::ECollectionContent)
   490     else if (mType == VideoCollectionCommon::EModelTypeCollectionContent)
   442     {
   491     {
   443         // if item belongs to the open album, accept it
   492         // if item belongs to the open album, accept it
   444         if (mModel->belongsToAlbum(id))
   493         if (mModel->belongsToAlbum(id))
   445         {
   494         {
   446             return true;
   495             return true;
   447         }
   496         }
   448     }
   497     }
   449     else if(mType == VideoCollectionWrapper::EGeneric)
   498     else if(mType == VideoCollectionCommon::EModelTypeGeneric)
   450     {
   499     {
   451         if(mLevel == VideoCollectionCommon::ELevelVideos && id.iId2 == KVcxMvcMediaTypeVideo)
   500         if(mLevel == VideoCollectionCommon::ELevelVideos && id.iId2 == KVcxMvcMediaTypeVideo)
   452         {
   501         {
   453             //  filter items that belong to that album setted as filter id
   502             //  filter items that belong to that album setted as filter id
   454             // if there's no filter or setted filter is "all videos", we accept everything
   503             // if there's no filter or setted filter is "all videos", we accept everything
   457                 mGenericFilterId.iId2 == KVcxMvcMediaTypeCategory) ||
   506                 mGenericFilterId.iId2 == KVcxMvcMediaTypeCategory) ||
   458                 mGenericFilterValue == mModel->belongsToAlbum(id, mGenericFilterId))
   507                 mGenericFilterValue == mModel->belongsToAlbum(id, mGenericFilterId))
   459             {
   508             {
   460                 return true;
   509                 return true;
   461             }
   510             }
   462             
       
   463         }
   511         }
   464         else if(mLevel == VideoCollectionCommon::ELevelCategory && id.iId2 == KVcxMvcMediaTypeAlbum)    
   512         else if(mLevel == VideoCollectionCommon::ELevelCategory && id.iId2 == KVcxMvcMediaTypeAlbum)    
   465         {
   513         {
   466             // we do not filter albums yet
   514             // we do not filter albums yet
   467             return true;
   515             return true;
   519 // VideoSortFilterProxyModel::addNewAlbum()
   567 // VideoSortFilterProxyModel::addNewAlbum()
   520 // -----------------------------------------------------------------------------
   568 // -----------------------------------------------------------------------------
   521 //
   569 //
   522 TMPXItemId VideoSortFilterProxyModel::addNewAlbum(const QString &title)
   570 TMPXItemId VideoSortFilterProxyModel::addNewAlbum(const QString &title)
   523 {
   571 {
       
   572 	FUNC_LOG_ADDR(this);
   524     TMPXItemId id = TMPXItemId::InvalidId();
   573     TMPXItemId id = TMPXItemId::InvalidId();
   525     
   574     
   526     if (mCollectionClient)
   575     if (mCollectionClient)
   527     {
   576     {
   528         id = mCollectionClient->addNewAlbum(title);
   577         id = mCollectionClient->addNewAlbum(title);
   535 // VideoSortFilterProxyModel::removeAlbums()
   584 // VideoSortFilterProxyModel::removeAlbums()
   536 // -----------------------------------------------------------------------------
   585 // -----------------------------------------------------------------------------
   537 //
   586 //
   538 int VideoSortFilterProxyModel::removeAlbums(const QModelIndexList &indexList)
   587 int VideoSortFilterProxyModel::removeAlbums(const QModelIndexList &indexList)
   539 {
   588 {
       
   589 	FUNC_LOG_ADDR(this);
   540 	int err(-1);
   590 	int err(-1);
   541     
   591     
   542 	if (mCollectionClient)
   592 	if (mCollectionClient)
   543 	{
   593 	{
   544 		TMPXItemId mpxId;
   594 		TMPXItemId mpxId;
   567 // -----------------------------------------------------------------------------
   617 // -----------------------------------------------------------------------------
   568 //
   618 //
   569 QString VideoSortFilterProxyModel::resolveAlbumName(
   619 QString VideoSortFilterProxyModel::resolveAlbumName(
   570     const QString& albumName) const
   620     const QString& albumName) const
   571 {
   621 {
       
   622 	FUNC_LOG_ADDR(this);
   572     QString resolvedName = albumName.trimmed();
   623     QString resolvedName = albumName.trimmed();
   573 
   624 
   574     // for checking names, we need to use collection list proxy model 
   625     // for checking names, we need to use collection list proxy model 
   575     // to get all existing album names including default ones
   626     // to get all existing album names including default ones
   576     VideoSortFilterProxyModel *collectionModel = 
   627     VideoSortFilterProxyModel *collectionModel = 
   577                        VideoCollectionWrapper::instance().getModel(
   628                        VideoCollectionWrapper::instance().getModel(
   578                                    VideoCollectionWrapper::ECollections);
   629                                    VideoCollectionCommon::EModelTypeCollections);
   579     if(!collectionModel || !mModel)
   630     if(!collectionModel || !mModel)
   580     {
   631     {
   581         return resolvedName;
   632         return resolvedName;
   582     }    
   633     }    
   583     
   634     
   586     QSet<QString> names;
   637     QSet<QString> names;
   587     QVariant data;
   638     QVariant data;
   588     // create set of existing names
   639     // create set of existing names
   589     while (proxyIndex.isValid())
   640     while (proxyIndex.isValid())
   590     {
   641     {
   591         data = mModel->data(collectionModel->mapToSource(proxyIndex), Qt::DisplayRole);
   642         data = mModel->data(collectionModel->mapToSource(proxyIndex), VideoCollectionCommon::KeyTitle);
   592         if (data.isValid())
   643         if (data.isValid())
   593         {
   644         {
   594             QStringList stringList = data.toStringList();
   645             names.insert(data.toString());
   595             names.insert(stringList.at(0));
       
   596         }
   646         }
   597         proxyIndex = collectionModel->index(++i, 0, QModelIndex());
   647         proxyIndex = collectionModel->index(++i, 0, QModelIndex());
   598     }
   648     }
   599     i = 0;
   649     i = 0;
   600     QString firstMatch("");
   650     QString firstMatch("");
   616 // -----------------------------------------------------------------------------
   666 // -----------------------------------------------------------------------------
   617 //
   667 //
   618 int VideoSortFilterProxyModel::addItemsInAlbum(TMPXItemId &albumId,
   668 int VideoSortFilterProxyModel::addItemsInAlbum(TMPXItemId &albumId,
   619         const QList<TMPXItemId> &mediaIds)
   669         const QList<TMPXItemId> &mediaIds)
   620 {
   670 {
       
   671 	FUNC_LOG_ADDR(this);
   621     int err(-1);
   672     int err(-1);
   622     
   673     
   623     if (mCollectionClient)
   674     if (mCollectionClient)
   624     {        
   675     {        
   625         // add items in album
   676         // add items in album
   634 // -----------------------------------------------------------------------------
   685 // -----------------------------------------------------------------------------
   635 //
   686 //
   636 int VideoSortFilterProxyModel::removeItemsFromAlbum(TMPXItemId &albumId, 
   687 int VideoSortFilterProxyModel::removeItemsFromAlbum(TMPXItemId &albumId, 
   637         const QList<TMPXItemId> &mediaIds)
   688         const QList<TMPXItemId> &mediaIds)
   638 {
   689 {
       
   690 	FUNC_LOG_ADDR(this);
   639     int err(-1);
   691     int err(-1);
   640        
   692        
   641     if (mModel)
   693     if (mModel)
   642     {        
   694     {        
   643         // remove items in album
   695         // remove items in album
   644         err = mModel->removeItemsFromAlbum(albumId, mediaIds);
   696         err = mModel->removeItemsFromAlbum(albumId, mediaIds);
   645         if(err > 0)
   697         if(err > 0)
   646         {
   698         {
   647             // if there really were items to be removed, invalid filter
   699             // if there really were items to be removed, invalid filter
       
   700             INFO_1("VideoSortFilterProxyModel::removeItemsFromAlbum() [0x%x] items removed, invaliding.", this);
   648             invalidateFilter();
   701             invalidateFilter();
   649             err = 0;
   702             err = 0;
   650         }
   703         }
   651     }
   704     }
   652     return err;
   705     return err;
   653 }
   706 }
   654 
   707 
   655 // -----------------------------------------------------------------------------
   708 // -----------------------------------------------------------------------------
       
   709 // VideoSortFilterProxyModel::renameAlbum()
       
   710 // -----------------------------------------------------------------------------
       
   711 //
       
   712 int VideoSortFilterProxyModel::renameAlbum(const TMPXItemId &albumId, const QString &newTitle)
       
   713 {
       
   714 	FUNC_LOG_ADDR(this);
       
   715     int err(-1);
       
   716 
       
   717     if(mCollectionClient)
       
   718     {
       
   719         return mCollectionClient->renameAlbum(albumId, newTitle);
       
   720     }
       
   721     return err;
       
   722 }
       
   723 
       
   724 // -----------------------------------------------------------------------------
   656 // VideoSortFilterProxyModel::getOpenItem()
   725 // VideoSortFilterProxyModel::getOpenItem()
   657 // -----------------------------------------------------------------------------
   726 // -----------------------------------------------------------------------------
   658 //
   727 //
   659 TMPXItemId VideoSortFilterProxyModel::getOpenItem() const
   728 TMPXItemId VideoSortFilterProxyModel::getOpenItem() const
   660 {
   729 {
       
   730 	FUNC_LOG_ADDR(this);
   661     TMPXItemId itemId = TMPXItemId::InvalidId();
   731     TMPXItemId itemId = TMPXItemId::InvalidId();
   662     
   732     
   663     if(mModel && mCollectionClient)
   733     if(mModel && mCollectionClient)
   664     {
   734     {
   665         if(mType == VideoCollectionWrapper::EAllVideos)
   735         if(mType == VideoCollectionCommon::EModelTypeAllVideos)
   666         {
   736         {
       
   737             INFO_1("VideoSortFilterProxyModel::getOpenItem() [0x%x] all videos is open.", this);
   667             itemId.iId1 = KVcxMvcCategoryIdAll;
   738             itemId.iId1 = KVcxMvcCategoryIdAll;
   668             itemId.iId2 = KVcxMvcMediaTypeCategory;        
   739             itemId.iId2 = KVcxMvcMediaTypeCategory;
   669         }
   740         }
   670         else if(mType == VideoCollectionWrapper::ECollectionContent)
   741         else if(mType == VideoCollectionCommon::EModelTypeCollectionContent)
   671         {
   742         {
       
   743             INFO_1("VideoSortFilterProxyModel::getOpenItem() [0x%x] category or album is open.", this);
   672             itemId = mModel->albumInUse();
   744             itemId = mModel->albumInUse();
   673         }
   745         }
   674     }
   746     }
   675 
   747 
   676     return itemId;
   748     return itemId;
   680 // VideoSortFilterProxyModel::setGenericIdFilter()
   752 // VideoSortFilterProxyModel::setGenericIdFilter()
   681 // -----------------------------------------------------------------------------
   753 // -----------------------------------------------------------------------------
   682 //
   754 //
   683 void VideoSortFilterProxyModel::setGenericIdFilter(TMPXItemId itemId, bool filterValue)
   755 void VideoSortFilterProxyModel::setGenericIdFilter(TMPXItemId itemId, bool filterValue)
   684 {
   756 {
   685     if(mType == VideoCollectionWrapper::EGeneric)
   757 	FUNC_LOG_ADDR(this);
   686     {
   758     if(mType == VideoCollectionCommon::EModelTypeGeneric)
       
   759     {
       
   760         INFO_3("VideoSortFilterProxyModel::setGenericIdFilter() [0x%x] itemId.iId2: %d, filterValue: %d", this, itemId.iId2, filterValue);
   687         mGenericFilterId = itemId;
   761         mGenericFilterId = itemId;
   688         mGenericFilterValue = filterValue;
   762         mGenericFilterValue = filterValue;
       
   763         INFO_1("VideoSortFilterProxyModel::setGenericIdFilter() [0x%x] invalidating.", this);
   689         invalidateFilter();
   764         invalidateFilter();
   690     }
   765     }
   691 }
   766 }
   692 
   767 
   693 // -----------------------------------------------------------------------------
   768 // -----------------------------------------------------------------------------
   694 // VideoSortFilterProxyModel::setAlbumInUse()
   769 // VideoSortFilterProxyModel::setAlbumInUse()
   695 // -----------------------------------------------------------------------------
   770 // -----------------------------------------------------------------------------
   696 //
   771 //
   697 void VideoSortFilterProxyModel::setAlbumInUse(TMPXItemId albumId)
   772 void VideoSortFilterProxyModel::setAlbumInUse(TMPXItemId albumId)
   698 {
   773 {
   699     mModel->setAlbumInUse(albumId);
   774 	FUNC_LOG_ADDR(this);
   700     invalidateFilter();
   775     if(mModel)
       
   776     {
       
   777         INFO_1("VideoSortFilterProxyModel::setAlbumInUse() [0x%x] invalidating.", this);
       
   778         mModel->setAlbumInUse(albumId);
       
   779         invalidateFilter();
       
   780     }
   701 }
   781 }
   702 
   782 
   703 // -----------------------------------------------------------------------------
   783 // -----------------------------------------------------------------------------
   704 // VideoSortFilterProxyModel::albumChangedSlot()
   784 // VideoSortFilterProxyModel::albumChangedSlot()
   705 // -----------------------------------------------------------------------------
   785 // -----------------------------------------------------------------------------
   706 //
   786 //
   707 void VideoSortFilterProxyModel::albumChangedSlot()
   787 void VideoSortFilterProxyModel::albumChangedSlot()
   708 {
   788 {
       
   789 	FUNC_LOG_ADDR(this);
   709     // ignore if not collection content model
   790     // ignore if not collection content model
   710     if (mType == VideoCollectionWrapper::ECollectionContent)
   791     if (mType == VideoCollectionCommon::EModelTypeCollectionContent)
   711     {
   792     {
   712         invalidateFilter();
   793         INFO_1("VideoSortFilterProxyModel::albumChangedSlot() [0x%x] invalidating.", this);
   713     }
   794 	    //otherwise newle created album content won't sort
   714 }
   795         setSortRole(mWantedSortRole);
   715 
   796         sort(0, mWantedSortOrder);
   716 // end of file
   797     	invalidateFilter();
   717 
   798     }
       
   799 }
       
   800 
       
   801 // -----------------------------------------------------------------------------
       
   802 // VideoSortFilterProxyModel::itemModifiedSlot()
       
   803 // -----------------------------------------------------------------------------
       
   804 //
       
   805 void VideoSortFilterProxyModel::itemModifiedSlot(const TMPXItemId &itemId)
       
   806 {
       
   807 	FUNC_LOG_ADDR(this);
       
   808     if(mType == VideoCollectionCommon::EModelTypeCollections &&
       
   809        (itemId.iId2 == KVcxMvcMediaTypeAlbum || itemId.iId2 == KVcxMvcMediaTypeCategory))
       
   810     {
       
   811         INFO_1("VideoSortFilterProxyModel::itemModifiedSlot() [0x%x] invalidating.", this);
       
   812         invalidate();
       
   813     }
       
   814 }
       
   815 
       
   816 // -----------------------------------------------------------------------------
       
   817 // VideoSortFilterProxyModel::getType()
       
   818 // -----------------------------------------------------------------------------
       
   819 //
       
   820 VideoCollectionCommon::TModelType VideoSortFilterProxyModel::getType()
       
   821 {
       
   822 	FUNC_LOG_ADDR(this);
       
   823 	return mType;
       
   824 }
       
   825 
       
   826 // End of file