videocollection/videocollectionwrapper/src/videoproxymodelgeneric.cpp
changeset 62 0e1e938beb1a
equal deleted inserted replaced
59:a76e86df7ccd 62:0e1e938beb1a
       
     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: VideoProxyModelGeneric implementation
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <qstringlist.h>
       
    22 #include <qset.h>
       
    23 #include <qtimer.h>
       
    24 #include <qdatetime.h>
       
    25 #include <vcxmyvideosdefs.h>
       
    26 
       
    27 #include "videothumbnaildata.h"
       
    28 #include "videocollectioncommon.h"
       
    29 #include "videoproxymodelgeneric.h"
       
    30 #include "videolistdatamodel.h"
       
    31 #include "videocollectionclient.h"
       
    32 #include "videocollectionwrapper.h"
       
    33 #include "videocollectiontrace.h"
       
    34 
       
    35 const TMPXItemId INVALID_ID = TMPXItemId::InvalidId();
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // VideoProxyModelGeneric::VideoProxyModelGeneric
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 VideoProxyModelGeneric::VideoProxyModelGeneric(QObject *parent) :
       
    42 QSortFilterProxyModel(parent),
       
    43 mModel(0),
       
    44 mCollectionClient(0),
       
    45 mLevel(VideoCollectionCommon::ELevelInvalid),
       
    46 mGenericFilterId(TMPXItemId::InvalidId()),
       
    47 mGenericFilterValue(false),
       
    48 mIdleSortTimer(0),
       
    49 mWantedSortRole(VideoCollectionCommon::KeyDateTime),
       
    50 mWantedSortOrder(Qt::AscendingOrder),
       
    51 mDefaultSortRole(VideoCollectionCommon::KeyTitle)
       
    52 {
       
    53 	FUNC_LOG_ADDR(this);
       
    54 }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // VideoProxyModelGeneric::~VideoProxyModelGeneric
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 VideoProxyModelGeneric::~VideoProxyModelGeneric()
       
    61 {
       
    62 	FUNC_LOG_ADDR(this);
       
    63 }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // VideoProxyModelGeneric::initialize
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 int VideoProxyModelGeneric::initialize(VideoListDataModel *sourceModel)
       
    70 {
       
    71     FUNC_LOG_ADDR(this);
       
    72     if(!sourceModel) 
       
    73     {
       
    74         return -1;
       
    75     }
       
    76     mModel = sourceModel;
       
    77     if(!connectSignals())
       
    78     {
       
    79         ERROR_1(-1, "VideoProxyModelGeneric::initialize() [0x%x] failed to connect signals.", this);
       
    80         disconnectSignals();
       
    81         mModel = 0;
       
    82         return -1;
       
    83     }
       
    84     mCollectionClient = sourceModel->getCollectionClient();
       
    85     if(!mCollectionClient)
       
    86     {
       
    87         mModel = 0;
       
    88         return -1;
       
    89     }
       
    90     setSourceModel(sourceModel);
       
    91     return 0;
       
    92 }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // VideoProxyModelGeneric::connectSignals
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 bool VideoProxyModelGeneric::connectSignals()
       
    99 {
       
   100     FUNC_LOG_ADDR(this);
       
   101 
       
   102     if(!connect(mModel, SIGNAL(modelChanged()),
       
   103                     this, SLOT(invalidate()))) 
       
   104     {
       
   105         return false;
       
   106     }
       
   107 
       
   108     return true;
       
   109 }
       
   110    
       
   111 // -----------------------------------------------------------------------------
       
   112 // VideoProxyModelGeneric::disconnectSignals
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void VideoProxyModelGeneric::disconnectSignals()
       
   116 {
       
   117     FUNC_LOG_ADDR(this);
       
   118     
       
   119     disconnect(mModel, SIGNAL(modelChanged()), this, SLOT(invalidate()));
       
   120 }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // VideoProxyModelGeneric::open
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 int VideoProxyModelGeneric::open(VideoCollectionCommon::TCollectionLevels level)
       
   127 {
       
   128     FUNC_LOG_ADDR(this);
       
   129     INFO_2("VideoProxyModelGeneric::open() [0x%x] level: %d", this, level);
       
   130     
       
   131     if(!mCollectionClient)
       
   132     {
       
   133         return -1;
       
   134     }
       
   135 
       
   136     if(mLevel != level) 
       
   137     {
       
   138        INFO_1("VideoProxyModelGeneric::open() [0x%x] opening different level, invalidating.", this);
       
   139        mLevel = level;
       
   140        invalidateFilter();
       
   141        // sorting call required here to setup correct sort order in cases where source model allready 
       
   142        // contains items but proxy is not yet updated. (invalidate -call does not work since it updates proxy and
       
   143        // calls sort in different order for us to use)
       
   144        sort(0, mWantedSortOrder);
       
   145     }
       
   146     // need to call open every time to make sure all items are 
       
   147     // inserted to UI ( recent open might have been cancelled)
       
   148     return mCollectionClient->startOpenCollection(level);
       
   149 }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // VideoProxyModelGeneric::doSorting
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 void VideoProxyModelGeneric::doSorting(int sortingRole, Qt::SortOrder order, 
       
   156         bool async)
       
   157 {
       
   158     FUNC_LOG_ADDR(this);
       
   159     INFO_3("VideoProxyModelGeneric::doSorting() [0x%x] sortingRole: %d, order: %d", this, sortingRole, order);
       
   160     
       
   161     if(sortingRole != VideoCollectionCommon::KeyTitle &&
       
   162        sortingRole != VideoCollectionCommon::KeySizeValue &&
       
   163        sortingRole != VideoCollectionCommon::KeyDateTime &&
       
   164        sortingRole != VideoCollectionCommon::KeyNumberOfItems)
       
   165     {
       
   166         mWantedSortRole = mDefaultSortRole;
       
   167     }
       
   168     else
       
   169     {
       
   170         mWantedSortRole = sortingRole;
       
   171     }
       
   172     
       
   173     mWantedSortOrder = order;
       
   174     
       
   175     if(async)
       
   176     {
       
   177         if(mIdleSortTimer)
       
   178         {
       
   179             if(mIdleSortTimer->isActive())
       
   180             {
       
   181                 mIdleSortTimer->stop();
       
   182             }
       
   183         }
       
   184         else
       
   185         {
       
   186             mIdleSortTimer = new QTimer(this);
       
   187             connect(mIdleSortTimer, SIGNAL(timeout()), 
       
   188                     this, SLOT(processSortingSlot()));
       
   189         }
       
   190         mIdleSortTimer->start(0);
       
   191     }
       
   192     else
       
   193     {
       
   194         processSorting();
       
   195     }
       
   196 }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // VideoProxyModelGeneric::getSorting
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void VideoProxyModelGeneric::getSorting(int &sortingRole, Qt::SortOrder &order)
       
   203 {
       
   204     FUNC_LOG_ADDR(this);
       
   205     sortingRole = mWantedSortRole;
       
   206     order       = mWantedSortOrder;
       
   207 }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // VideoProxyModelGeneric::deleteItems
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 int VideoProxyModelGeneric::deleteItems(const QModelIndexList &indexList)
       
   214 {
       
   215     FUNC_LOG_ADDR(this);
       
   216     
       
   217     // Disable thumbnail fetching while items are removed from the model. 
       
   218     VideoThumbnailData::instance().enableBackgroundFetching(false);
       
   219     
       
   220     if(mModel)
       
   221     {
       
   222         QModelIndexList mappedList;
       
   223         for(int i = 0; i < indexList.count(); ++i)
       
   224         {
       
   225             mappedList.append(mapToSource(indexList.at(i)));
       
   226         }
       
   227         
       
   228         if(mModel->removeRows(mappedList))
       
   229         {
       
   230             // Start fetching thumbnails at start of the model.
       
   231             VideoThumbnailData::instance().enableBackgroundFetching(true);
       
   232             VideoThumbnailData::instance().startBackgroundFetching(0, 0);
       
   233             return 0;
       
   234         }
       
   235     }
       
   236     
       
   237     VideoThumbnailData::instance().enableBackgroundFetching(true);
       
   238     return -1;
       
   239 }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // VideoProxyModelGeneric::openItem
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 int VideoProxyModelGeneric::openItem(TMPXItemId mediaId)
       
   246 {
       
   247     FUNC_LOG_ADDR(this);
       
   248     if(mediaId != TMPXItemId::InvalidId() && mCollectionClient)
       
   249     {
       
   250         if(mCollectionClient->openItem(mediaId) == 0)
       
   251         {
       
   252             if(mediaId.iId2 != KVcxMvcMediaTypeVideo)
       
   253             { 
       
   254                 mLevel = VideoCollectionCommon::ELevelAlbum;
       
   255                 mModel->setAlbumInUse(mediaId);
       
   256                 INFO_1("VideoProxyModelGeneric::open() [0x%x] opening album or category, invalidating.", this);
       
   257                 invalidateFilter();
       
   258                 // sorting call required here to setup correct sort order in cases where source model allready 
       
   259                 // contains items but proxy is not yet updated. (invalidate -call does not work since it updates proxy and
       
   260                 // calls sort in different order for us to use)
       
   261                 sort(0, mWantedSortOrder);
       
   262             } 
       
   263             return 0;
       
   264         }
       
   265     }
       
   266     return -1;
       
   267 }
       
   268 
       
   269 // -----------------------------------------------------------------------------
       
   270 // VideoProxyModelGeneric::back
       
   271 // -----------------------------------------------------------------------------
       
   272 //
       
   273 int VideoProxyModelGeneric::back()
       
   274 {
       
   275     FUNC_LOG_ADDR(this);
       
   276     if(mCollectionClient && mCollectionClient->back() == 0)
       
   277     {
       
   278         if(mLevel == VideoCollectionCommon::ELevelAlbum)
       
   279         {
       
   280             mLevel = VideoCollectionCommon::ELevelCategory;
       
   281         }
       
   282         else
       
   283         {
       
   284             mLevel = VideoCollectionCommon::ELevelVideos;
       
   285         }
       
   286         return 0;
       
   287     }
       
   288     return -1;
       
   289 }
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // VideoProxyModelGeneric::fetchItemDetails
       
   293 // -----------------------------------------------------------------------------
       
   294 //
       
   295 int VideoProxyModelGeneric::fetchItemDetails(const QModelIndex &index)
       
   296 {
       
   297     FUNC_LOG_ADDR(this);
       
   298     // no need to map index beforehand, because 
       
   299     // getMediaIdAtIndex maps it
       
   300     TMPXItemId mpxId1 = getMediaIdAtIndex(index);
       
   301     if(mpxId1 != TMPXItemId::InvalidId() && mCollectionClient)
       
   302     {
       
   303         if(mCollectionClient->getVideoDetails(mpxId1) == 0)
       
   304         {
       
   305             emit shortDetailsReady(mpxId1);
       
   306             return 0;
       
   307         }
       
   308     }
       
   309     return -1;
       
   310 }
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // VideoProxyModelGeneric::lessThan
       
   314 // -----------------------------------------------------------------------------
       
   315 //
       
   316 bool VideoProxyModelGeneric::lessThan(const QModelIndex &left,
       
   317     const QModelIndex &right) const
       
   318 {
       
   319     if (!mModel)
       
   320     {
       
   321         return false;
       
   322     }
       
   323     
       
   324     // Do comparisation based on the role:
       
   325     //  VideoCollectionCommon::KeyTitle,
       
   326     //  VideoCollectionCommon::KeySizeValue,
       
   327     //  VideoCollectionCommon::KeyNumberOfItems,
       
   328     //  VideoCollectionCommon::KeyDateValue
       
   329     // 
       
   330     // If role does not match, do not sort
       
   331     int sRole = sortRole();
       
   332     QVariant leftData = sourceModel()->data(left, sRole);
       
   333     QVariant rightData = sourceModel()->data(right, sRole);
       
   334 
       
   335     if(!leftData.isValid() || !rightData.isValid())
       
   336     {
       
   337         return false;
       
   338     }
       
   339     if(sRole == VideoCollectionCommon::KeyTitle)
       
   340     {
       
   341         QString leftString = leftData.toString().toUpper();
       
   342         QString rightString = rightData.toString().toUpper();
       
   343         return QString::localeAwareCompare(leftString, rightString) < 0;
       
   344     }
       
   345     else if(sRole == VideoCollectionCommon::KeySizeValue ||
       
   346             sRole == VideoCollectionCommon::KeyNumberOfItems)
       
   347     {
       
   348         quint32 leftSize = leftData.toUInt();
       
   349         quint32 rightSize = rightData.toUInt();
       
   350         return leftSize < rightSize;
       
   351     }
       
   352     else if(sRole == VideoCollectionCommon::KeyDateTime)
       
   353     {
       
   354         QDateTime leftDateTime = leftData.toDateTime();
       
   355         QDateTime rightDateTime = rightData.toDateTime();
       
   356         // datetime sorting role has inverted sorting order compared to other roles 
       
   357         return rightDateTime < leftDateTime;
       
   358     }
       
   359     return false;
       
   360 }
       
   361 
       
   362 // -----------------------------------------------------------------------------
       
   363 // VideoProxyModelGeneric::filterAcceptsRow
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 bool VideoProxyModelGeneric::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
       
   367 {
       
   368     Q_UNUSED(source_parent);
       
   369     
       
   370     if(!sourceModel())
       
   371     {
       
   372         return false;
       
   373     }
       
   374 
       
   375     if(source_row < 0 || source_row >= sourceModel()->rowCount())
       
   376     {
       
   377         return false;
       
   378     }
       
   379     TMPXItemId id = mModel->mediaIdAtIndex(source_row);
       
   380     if(id == TMPXItemId::InvalidId())
       
   381     {
       
   382         return false;
       
   383     }
       
   384 
       
   385     if(mLevel == VideoCollectionCommon::ELevelVideos && id.iId2 == KVcxMvcMediaTypeVideo)
       
   386     {
       
   387         //  filter items that belong to that album setted as filter id
       
   388         // if there's no filter or setted filter is "all videos", we accept everything
       
   389         if(mGenericFilterId == TMPXItemId::InvalidId() || 
       
   390            (mGenericFilterId.iId1 == KVcxMvcCategoryIdAll && 
       
   391             mGenericFilterId.iId2 == KVcxMvcMediaTypeCategory) ||
       
   392             mGenericFilterValue == mModel->belongsToAlbum(id, mGenericFilterId))
       
   393         {
       
   394             return true;
       
   395         }
       
   396     }
       
   397     else if(mLevel == VideoCollectionCommon::ELevelCategory && id.iId2 == KVcxMvcMediaTypeAlbum)    
       
   398     {
       
   399         // we do not filter albums yet
       
   400         return true;
       
   401     }  
       
   402 
       
   403     return false;
       
   404 }
       
   405 
       
   406 // -----------------------------------------------------------------------------
       
   407 // VideoProxyModelGeneric::getMediaIdAtIndex()
       
   408 // -----------------------------------------------------------------------------
       
   409 //
       
   410 const TMPXItemId& VideoProxyModelGeneric::getMediaIdAtIndex(const QModelIndex &index) const
       
   411 {
       
   412     if(index.isValid())
       
   413     {
       
   414         int rowIndex = mapToSource(index).row();
       
   415         if(mModel)
       
   416         {
       
   417             return mModel->mediaIdAtIndex(rowIndex);
       
   418         }
       
   419     }
       
   420     return INVALID_ID;
       
   421 }
       
   422 
       
   423 // -----------------------------------------------------------------------------
       
   424 // VideoProxyModelGeneric::indexOfId()
       
   425 // -----------------------------------------------------------------------------
       
   426 //
       
   427 QModelIndex VideoProxyModelGeneric::indexOfId(const TMPXItemId &id)
       
   428 {    
       
   429     QModelIndex sourceIndex;
       
   430     if(!mModel || id == TMPXItemId::InvalidId())
       
   431     {
       
   432         return sourceIndex;
       
   433     }
       
   434     sourceIndex = mModel->indexOfId(id);
       
   435     return mapFromSource(sourceIndex);
       
   436 }
       
   437 
       
   438 // -----------------------------------------------------------------------------
       
   439 // VideoProxyModelGeneric::getMediaFilePathForId()
       
   440 // -----------------------------------------------------------------------------
       
   441 //
       
   442 QString VideoProxyModelGeneric::getMediaFilePathForId(const TMPXItemId &mediaId)
       
   443 {
       
   444     QString filePath;
       
   445     if(mModel)
       
   446     {
       
   447         filePath = mModel->mediaFilePathForId(mediaId);
       
   448     }
       
   449     return filePath;
       
   450 }
       
   451 
       
   452 // -----------------------------------------------------------------------------
       
   453 // VideoProxyModelGeneric::addNewAlbum()
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 TMPXItemId VideoProxyModelGeneric::addNewAlbum(const QString &title)
       
   457 {
       
   458     FUNC_LOG_ADDR(this);
       
   459     TMPXItemId id = TMPXItemId::InvalidId();
       
   460     
       
   461     if (mCollectionClient)
       
   462     {
       
   463         id = mCollectionClient->addNewAlbum(title);
       
   464     }
       
   465     
       
   466     return id;
       
   467 }
       
   468 
       
   469 // -----------------------------------------------------------------------------
       
   470 // VideoProxyModelGeneric::removeAlbums()
       
   471 // -----------------------------------------------------------------------------
       
   472 //
       
   473 int VideoProxyModelGeneric::removeAlbums(const QModelIndexList &indexList)
       
   474 {
       
   475     FUNC_LOG_ADDR(this);
       
   476     int err(-1);
       
   477     
       
   478     if (mCollectionClient)
       
   479     {
       
   480         TMPXItemId mpxId;
       
   481         QList<TMPXItemId> ids;
       
   482 
       
   483         for(int i = 0; i < indexList.count(); ++i)
       
   484         {
       
   485             mpxId = getMediaIdAtIndex(indexList.at(i));
       
   486             if(mpxId != TMPXItemId::InvalidId() && 
       
   487                mpxId.iId2 == KVcxMvcMediaTypeAlbum)
       
   488             {
       
   489                 ids.append(getMediaIdAtIndex(indexList.at(i)));
       
   490             }
       
   491         }
       
   492         
       
   493         if (ids.count())
       
   494         {
       
   495             err = mCollectionClient->removeAlbums(ids);
       
   496         }
       
   497     }
       
   498 
       
   499     return err;
       
   500 }
       
   501 
       
   502 // -----------------------------------------------------------------------------
       
   503 // VideoProxyModelGeneric::resolveAlbumName()
       
   504 // -----------------------------------------------------------------------------
       
   505 //
       
   506 QString VideoProxyModelGeneric::resolveAlbumName(
       
   507     const QString& albumName) const
       
   508 {
       
   509     FUNC_LOG_ADDR(this);
       
   510     QString resolvedName = albumName.trimmed();
       
   511 
       
   512     // for checking names, we need to use collection list proxy model 
       
   513     // to get all existing album names including default ones
       
   514     VideoProxyModelGeneric *collectionModel = 
       
   515                        VideoCollectionWrapper::instance().getCollectionsModel();
       
   516     if(!collectionModel || !mModel)
       
   517     {
       
   518         return resolvedName;
       
   519     }    
       
   520 
       
   521     int i(0);
       
   522     QModelIndex proxyIndex = collectionModel->index(i, 0);
       
   523     QSet<QString> names;
       
   524     QVariant data;
       
   525     // create set of existing names
       
   526     while (proxyIndex.isValid())
       
   527     {
       
   528         data = mModel->data(collectionModel->mapToSource(proxyIndex), 
       
   529                 VideoCollectionCommon::KeyTitle);
       
   530         if (data.isValid())
       
   531         {
       
   532             names.insert(data.toString());
       
   533         }
       
   534         proxyIndex = collectionModel->index(++i, 0, QModelIndex());
       
   535     }
       
   536     i = 0;
       
   537     QString firstMatch("");
       
   538     // find a name that does not yet exists
       
   539     while(names.contains(resolvedName))
       
   540     {
       
   541         if (!firstMatch.length())
       
   542         {
       
   543             firstMatch = resolvedName;
       
   544         }
       
   545         ++i;
       
   546         resolvedName = tr("%1 (%2)").arg(firstMatch).arg(i);
       
   547     }
       
   548     return resolvedName;
       
   549 }
       
   550 
       
   551 // -----------------------------------------------------------------------------
       
   552 // VideoProxyModelGeneric::addItemsInAlbum()
       
   553 // -----------------------------------------------------------------------------
       
   554 //
       
   555 int VideoProxyModelGeneric::addItemsInAlbum(TMPXItemId &albumId,
       
   556         const QList<TMPXItemId> &mediaIds)
       
   557 {
       
   558     FUNC_LOG_ADDR(this);
       
   559     int err(-1);
       
   560     
       
   561     if (mCollectionClient)
       
   562     {        
       
   563         // add items in album
       
   564         err = mCollectionClient->addItemsInAlbum(albumId, mediaIds);
       
   565     }
       
   566     
       
   567     return err;
       
   568 }
       
   569 
       
   570 // -----------------------------------------------------------------------------
       
   571 // VideoProxyModelGeneric::removeItemsFromAlbum()
       
   572 // -----------------------------------------------------------------------------
       
   573 //
       
   574 int VideoProxyModelGeneric::removeItemsFromAlbum(TMPXItemId &albumId, 
       
   575         const QList<TMPXItemId> &mediaIds)
       
   576 {
       
   577     FUNC_LOG_ADDR(this);
       
   578     int err(-1);
       
   579 
       
   580     // Disable thumbnail fetching while items are removed from the model. 
       
   581     VideoThumbnailData::instance().enableBackgroundFetching(false);
       
   582     
       
   583     if (mModel)
       
   584     {
       
   585         // remove items in album
       
   586         err = mModel->removeItemsFromAlbum(albumId, mediaIds);
       
   587         if(err > 0)
       
   588         {
       
   589             // if there really were items to be removed, invalid filter
       
   590             INFO_1("VideoProxyModelGeneric::removeItemsFromAlbum() [0x%x] items removed, invaliding.", this);
       
   591             invalidateFilter();
       
   592             err = 0;
       
   593         }
       
   594     }
       
   595  
       
   596     VideoThumbnailData::instance().enableBackgroundFetching(true);
       
   597     return err;
       
   598 }
       
   599 
       
   600 // -----------------------------------------------------------------------------
       
   601 // VideoProxyModelGeneric::renameItem()
       
   602 // -----------------------------------------------------------------------------
       
   603 //
       
   604 int VideoProxyModelGeneric::renameItem(const TMPXItemId &itemId, const QString &newTitle)
       
   605 {
       
   606     FUNC_LOG_ADDR(this);
       
   607     int err(-1);
       
   608 
       
   609     if(mCollectionClient)
       
   610     {
       
   611         return mCollectionClient->renameItem(itemId, newTitle);
       
   612     }
       
   613     return err;
       
   614 }
       
   615 
       
   616 // -----------------------------------------------------------------------------
       
   617 // VideoProxyModelGeneric::getOpenItem()
       
   618 // -----------------------------------------------------------------------------
       
   619 //
       
   620 TMPXItemId VideoProxyModelGeneric::getOpenItem() const
       
   621 {
       
   622     FUNC_LOG_ADDR(this);
       
   623     TMPXItemId itemId = TMPXItemId::InvalidId();
       
   624     return itemId;
       
   625 }
       
   626 
       
   627 // -----------------------------------------------------------------------------
       
   628 // VideoProxyModelGeneric::setGenericIdFilter()
       
   629 // -----------------------------------------------------------------------------
       
   630 //
       
   631 void VideoProxyModelGeneric::setGenericIdFilter(const TMPXItemId &itemId, bool filterValue)
       
   632 {
       
   633     FUNC_LOG_ADDR(this);
       
   634     INFO_3("VideoProxyModelGeneric::setGenericIdFilter() [0x%x] itemId.iId2: %d, filterValue: %d", this, itemId.iId2, filterValue);
       
   635     mGenericFilterId = itemId;
       
   636     mGenericFilterValue = filterValue;
       
   637     INFO_1("VideoProxyModelGeneric::setGenericIdFilter() [0x%x] invalidating.", this);
       
   638     invalidateFilter();
       
   639 }
       
   640 
       
   641 // -----------------------------------------------------------------------------
       
   642 // VideoProxyModelGeneric::setAlbumInUse()
       
   643 // -----------------------------------------------------------------------------
       
   644 //
       
   645 void VideoProxyModelGeneric::setAlbumInUse(const TMPXItemId &albumId)
       
   646 {
       
   647     FUNC_LOG_ADDR(this);
       
   648     if(mModel)
       
   649     {
       
   650         INFO_1("VideoProxyModelGeneric::setAlbumInUse() [0x%x] invalidating.", this);
       
   651         mModel->setAlbumInUse(albumId);
       
   652         invalidateFilter();
       
   653     }
       
   654 }
       
   655 
       
   656 // -----------------------------------------------------------------------------
       
   657 // VideoProxyModelGeneric::processSortingSlot
       
   658 // -----------------------------------------------------------------------------
       
   659 //
       
   660 void VideoProxyModelGeneric::processSortingSlot()
       
   661 {
       
   662     FUNC_LOG_ADDR(this);
       
   663     if(mIdleSortTimer)
       
   664     {
       
   665         mIdleSortTimer->stop();
       
   666     }    
       
   667     processSorting();
       
   668 }
       
   669 
       
   670 // -----------------------------------------------------------------------------
       
   671 // VideoProxyModelGeneric::processSorting
       
   672 // -----------------------------------------------------------------------------
       
   673 //
       
   674 void VideoProxyModelGeneric::processSorting()
       
   675 {
       
   676     FUNC_LOG_ADDR(this);
       
   677 
       
   678     if(sortRole() != mWantedSortRole)
       
   679     {
       
   680         setSortRole(mWantedSortRole);
       
   681     }
       
   682     
       
   683     if(sortColumn() == -1 || sortOrder() != mWantedSortOrder)
       
   684     {
       
   685         // if sorting column is not yet setted, it indicates
       
   686         // that we've setted the sorting order for the first time
       
   687         // and sorting has not yet been done. After we have called sort once,
       
   688         // the sort columnt gets updated and following sorts gets executed
       
   689         // by setSortRole -call as long as role changes.
       
   690     
       
   691         // Another case is when we need to change the sort order, as there is
       
   692         // no other way of setting the sort order than calling sort().
       
   693         sort(0, mWantedSortOrder);
       
   694     }
       
   695 
       
   696     emit modelSorted();
       
   697 }
       
   698 
       
   699 // End of file