--- a/videocollection/videocollectionwrapper/src/videosortfilterproxymodel.cpp Tue Jul 06 14:17:50 2010 +0300
+++ b/videocollection/videocollectionwrapper/src/videosortfilterproxymodel.cpp Wed Aug 18 09:50:14 2010 +0300
@@ -15,7 +15,7 @@
*
*/
-// Version : %version: 66 %
+// Version : %version: 66.1.8 %
// INCLUDE FILES
#include <qstringlist.h>
@@ -32,6 +32,8 @@
#include "videocollectionwrapper.h"
#include "videocollectiontrace.h"
+const TMPXItemId INVALID_ID = TMPXItemId::InvalidId();
+
// -----------------------------------------------------------------------------
// VideoSortFilterProxyModel::VideoSortFilterProxyModel
// -----------------------------------------------------------------------------
@@ -96,13 +98,9 @@
bool VideoSortFilterProxyModel::connectSignals()
{
FUNC_LOG_ADDR(this);
- if(!connect(mModel, SIGNAL(modelReady()),
- this, SIGNAL(modelReady())))
- {
- return false;
- }
+
if(!connect(mModel, SIGNAL(modelChanged()),
- this, SIGNAL(modelChanged())))
+ this, SLOT(invalidate())))
{
return false;
}
@@ -114,14 +112,7 @@
return false;
}
}
- if(mType == VideoCollectionCommon::EModelTypeCollections)
- {
- if(!connect(mModel, SIGNAL(itemModified(const TMPXItemId &)),
- this, SLOT(itemModifiedSlot(const TMPXItemId &))))
- {
- return false;
- }
- }
+
return true;
}
@@ -132,8 +123,7 @@
void VideoSortFilterProxyModel::disconnectSignals()
{
FUNC_LOG_ADDR(this);
- disconnect(mModel, SIGNAL(modelReady()), this, SIGNAL(modelReady()));
- disconnect(mModel, SIGNAL(modelChanged()), this, SIGNAL(modelChanged()));
+ disconnect(mModel, SIGNAL(modelChanged()), this, SLOT(invalidate()));
if(mType == VideoCollectionCommon::EModelTypeCollectionContent)
{
disconnect(mModel, SIGNAL(albumChanged()), this, SLOT(albumChangedSlot()));
@@ -158,12 +148,16 @@
{
return -1;
}
-
+
if(mLevel != level)
{
- INFO_1("VideoSortFilterProxyModel::open() [0x%x] opening different level, invalidating.", this);
- mLevel = level;
- invalidateFilter();
+ INFO_1("VideoSortFilterProxyModel::open() [0x%x] opening different level, invalidating.", this);
+ mLevel = level;
+ invalidateFilter();
+ // sorting call required here to setup correct sort order in cases where source model allready
+ // contains items but proxy is not yet updated. (invalidate -call does not work since it updates proxy and
+ // calls sort in different order for us to use)
+ sort(0, mWantedSortOrder);
}
// need to call open every time to make sure all items are
// inserted to UI ( recent open might have been cancelled)
@@ -241,6 +235,10 @@
int VideoSortFilterProxyModel::deleteItems(const QModelIndexList &indexList)
{
FUNC_LOG_ADDR(this);
+
+ // Disable thumbnail fetching while items are removed from the model.
+ VideoThumbnailData::instance().enableBackgroundFetching(false);
+
if(mModel)
{
QModelIndexList mappedList;
@@ -252,10 +250,13 @@
if(mModel->removeRows(mappedList))
{
// Start fetching thumbnails at start of the model.
+ VideoThumbnailData::instance().enableBackgroundFetching(true);
VideoThumbnailData::instance().startBackgroundFetching(0, 0);
return 0;
}
}
+
+ VideoThumbnailData::instance().enableBackgroundFetching(true);
return -1;
}
@@ -276,6 +277,10 @@
mModel->setAlbumInUse(mediaId);
INFO_1("VideoSortFilterProxyModel::open() [0x%x] opening album or category, invalidating.", this);
invalidateFilter();
+ // sorting call required here to setup correct sort order in cases where source model allready
+ // contains items but proxy is not yet updated. (invalidate -call does not work since it updates proxy and
+ // calls sort in different order for us to use)
+ sort(0, mWantedSortOrder);
}
return 0;
}
@@ -371,8 +376,10 @@
{
return false;
}
- TMPXItemId leftId = mModel->mediaIdAtIndex(left.row());
- TMPXItemId rightId = mModel->mediaIdAtIndex(right.row());
+ int index = left.row();
+ TMPXItemId leftId = mModel->mediaIdAtIndex(index);
+ index = right.row();
+ TMPXItemId rightId = mModel->mediaIdAtIndex(index);
// Default categories are always first in the following order:
// Recently played (missing currently)
@@ -523,25 +530,24 @@
// VideoSortFilterProxyModel::getMediaIdAtIndex()
// -----------------------------------------------------------------------------
//
-TMPXItemId VideoSortFilterProxyModel::getMediaIdAtIndex(const QModelIndex &index) const
+const TMPXItemId& VideoSortFilterProxyModel::getMediaIdAtIndex(const QModelIndex &index) const
{
- TMPXItemId mpxId = TMPXItemId::InvalidId();
if(index.isValid())
{
- QModelIndex sourceIndex = mapToSource(index);
- if(mModel && sourceIndex.isValid())
+ int rowIndex = mapToSource(index).row();
+ if(mModel)
{
- mpxId = mModel->mediaIdAtIndex(sourceIndex.row());
+ return mModel->mediaIdAtIndex(rowIndex);
}
}
- return mpxId;
+ return INVALID_ID;
}
// -----------------------------------------------------------------------------
// VideoSortFilterProxyModel::indexOfId()
// -----------------------------------------------------------------------------
//
-QModelIndex VideoSortFilterProxyModel::indexOfId(TMPXItemId id)
+QModelIndex VideoSortFilterProxyModel::indexOfId(const TMPXItemId &id)
{
QModelIndex sourceIndex;
if(!mModel || id == TMPXItemId::InvalidId())
@@ -556,7 +562,7 @@
// VideoSortFilterProxyModel::getMediaFilePathForId()
// -----------------------------------------------------------------------------
//
-QString VideoSortFilterProxyModel::getMediaFilePathForId(TMPXItemId mediaId)
+QString VideoSortFilterProxyModel::getMediaFilePathForId(const TMPXItemId &mediaId)
{
QString filePath;
if(mModel)
@@ -692,9 +698,12 @@
{
FUNC_LOG_ADDR(this);
int err(-1);
-
+
+ // Disable thumbnail fetching while items are removed from the model.
+ VideoThumbnailData::instance().enableBackgroundFetching(false);
+
if (mModel)
- {
+ {
// remove items in album
err = mModel->removeItemsFromAlbum(albumId, mediaIds);
if(err > 0)
@@ -705,21 +714,23 @@
err = 0;
}
}
+
+ VideoThumbnailData::instance().enableBackgroundFetching(true);
return err;
}
// -----------------------------------------------------------------------------
-// VideoSortFilterProxyModel::renameAlbum()
+// VideoSortFilterProxyModel::renameItem()
// -----------------------------------------------------------------------------
//
-int VideoSortFilterProxyModel::renameAlbum(const TMPXItemId &albumId, const QString &newTitle)
+int VideoSortFilterProxyModel::renameItem(const TMPXItemId &itemId, const QString &newTitle)
{
FUNC_LOG_ADDR(this);
int err(-1);
if(mCollectionClient)
{
- return mCollectionClient->renameAlbum(albumId, newTitle);
+ return mCollectionClient->renameItem(itemId, newTitle);
}
return err;
}
@@ -755,7 +766,7 @@
// VideoSortFilterProxyModel::setGenericIdFilter()
// -----------------------------------------------------------------------------
//
-void VideoSortFilterProxyModel::setGenericIdFilter(TMPXItemId itemId, bool filterValue)
+void VideoSortFilterProxyModel::setGenericIdFilter(const TMPXItemId &itemId, bool filterValue)
{
FUNC_LOG_ADDR(this);
if(mType == VideoCollectionCommon::EModelTypeGeneric)
@@ -772,7 +783,7 @@
// VideoSortFilterProxyModel::setAlbumInUse()
// -----------------------------------------------------------------------------
//
-void VideoSortFilterProxyModel::setAlbumInUse(TMPXItemId albumId)
+void VideoSortFilterProxyModel::setAlbumInUse(const TMPXItemId &albumId)
{
FUNC_LOG_ADDR(this);
if(mModel)
@@ -794,29 +805,14 @@
if (mType == VideoCollectionCommon::EModelTypeCollectionContent)
{
INFO_1("VideoSortFilterProxyModel::albumChangedSlot() [0x%x] invalidating.", this);
- // sort and invalidate filtering, otherwise newle created album content won't sort
+ // sort and invalidate filtering, otherwise newly created album content won't sort
invalidateFilter();
- setSortRole(mWantedSortRole);
+ setSortRole(mWantedSortRole);
sort(0, mWantedSortOrder);
}
}
// -----------------------------------------------------------------------------
-// VideoSortFilterProxyModel::itemModifiedSlot()
-// -----------------------------------------------------------------------------
-//
-void VideoSortFilterProxyModel::itemModifiedSlot(const TMPXItemId &itemId)
-{
- FUNC_LOG_ADDR(this);
- if(mType == VideoCollectionCommon::EModelTypeCollections &&
- (itemId.iId2 == KVcxMvcMediaTypeAlbum || itemId.iId2 == KVcxMvcMediaTypeCategory))
- {
- INFO_1("VideoSortFilterProxyModel::itemModifiedSlot() [0x%x] invalidating.", this);
- invalidate();
- }
-}
-
-// -----------------------------------------------------------------------------
// VideoSortFilterProxyModel::getType()
// -----------------------------------------------------------------------------
//