videocollection/videocollectionwrapper/src/videolistdatamodel_p.cpp
author hgs
Fri, 06 Aug 2010 09:43:48 +0300
changeset 50 21fe8338c6bf
parent 49 824471cb468a
child 58 d2b028fd1f7d
permissions -rw-r--r--
201031
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description: VideoListDataModelPrivate class implementation
hgs
parents:
diff changeset
    15
* 
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
50
hgs
parents: 49
diff changeset
    18
// Version : %version: 38.1.6 %
30
hgs
parents:
diff changeset
    19
36
hgs
parents: 35
diff changeset
    20
// INCLUDE FILES
hgs
parents: 35
diff changeset
    21
#include <hbglobal.h>
30
hgs
parents:
diff changeset
    22
#include <mpxmediageneraldefs.h>
36
hgs
parents: 35
diff changeset
    23
#include <mpxmediavideodefs.h>
30
hgs
parents:
diff changeset
    24
#include <thumbnailmanager_qt.h>
hgs
parents:
diff changeset
    25
#include <mpxmediaarray.h>
hgs
parents:
diff changeset
    26
#include <mpxmedia.h>
hgs
parents:
diff changeset
    27
#include <qvariant.h>
36
hgs
parents: 35
diff changeset
    28
#include <hbextendedlocale.h>
50
hgs
parents: 49
diff changeset
    29
#include <qfileinfo.h>
30
hgs
parents:
diff changeset
    30
hgs
parents:
diff changeset
    31
#include "videolistdatamodel.h"
34
hgs
parents: 30
diff changeset
    32
#include "videocollectionclient.h"
hgs
parents: 30
diff changeset
    33
#include "videodeleteworker.h"
30
hgs
parents:
diff changeset
    34
#include "videolistdatamodel_p.h"
hgs
parents:
diff changeset
    35
#include "videothumbnaildata.h"
hgs
parents:
diff changeset
    36
#include "vcxmyvideosdefs.h"
hgs
parents:
diff changeset
    37
#include "videocollectionutils.h"
hgs
parents:
diff changeset
    38
#include "videocollectioncommon.h"
36
hgs
parents: 35
diff changeset
    39
#include "videocollectiontrace.h"
30
hgs
parents:
diff changeset
    40
hgs
parents:
diff changeset
    41
/**
34
hgs
parents: 30
diff changeset
    42
 * global qHash function required fo creating hash values for TMPXItemId -keys
30
hgs
parents:
diff changeset
    43
 */
hgs
parents:
diff changeset
    44
inline uint qHash(TMPXItemId key) 
hgs
parents:
diff changeset
    45
{ 
hgs
parents:
diff changeset
    46
    QPair<uint, uint> keyPair(key.iId1, key.iId2); 
hgs
parents:
diff changeset
    47
    return qHash(keyPair);
hgs
parents:
diff changeset
    48
}
hgs
parents:
diff changeset
    49
hgs
parents:
diff changeset
    50
// ================= MEMBER FUNCTIONS =======================
hgs
parents:
diff changeset
    51
//
hgs
parents:
diff changeset
    52
hgs
parents:
diff changeset
    53
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    54
// VideoListDataModelPrivate
hgs
parents:
diff changeset
    55
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    56
//
hgs
parents:
diff changeset
    57
VideoListDataModelPrivate::VideoListDataModelPrivate(VideoListDataModel *model) :
hgs
parents:
diff changeset
    58
q_ptr(model),
34
hgs
parents: 30
diff changeset
    59
mVideoThumbnailData(0),
hgs
parents: 30
diff changeset
    60
mInitialized(false),
hgs
parents: 30
diff changeset
    61
mCurrentAlbum(TMPXItemId::InvalidId())
30
hgs
parents:
diff changeset
    62
{
36
hgs
parents: 35
diff changeset
    63
	FUNC_LOG;
30
hgs
parents:
diff changeset
    64
}
hgs
parents:
diff changeset
    65
	
hgs
parents:
diff changeset
    66
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    67
// ~VideoListDataModelPrivate
hgs
parents:
diff changeset
    68
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    69
//
hgs
parents:
diff changeset
    70
VideoListDataModelPrivate::~VideoListDataModelPrivate()
hgs
parents:
diff changeset
    71
{
36
hgs
parents: 35
diff changeset
    72
	FUNC_LOG;
34
hgs
parents: 30
diff changeset
    73
    QHash<TMPXItemId, QSet<TMPXItemId> >::iterator iter = mAlbumData.begin();
hgs
parents: 30
diff changeset
    74
    while(iter != mAlbumData.end())
hgs
parents: 30
diff changeset
    75
    {
hgs
parents: 30
diff changeset
    76
        iter->clear();
hgs
parents: 30
diff changeset
    77
        ++iter;
hgs
parents: 30
diff changeset
    78
    }
hgs
parents: 30
diff changeset
    79
    mAlbumData.clear();
30
hgs
parents:
diff changeset
    80
    mMediaData.clear();
hgs
parents:
diff changeset
    81
}
hgs
parents:
diff changeset
    82
hgs
parents:
diff changeset
    83
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    84
// initialize
hgs
parents:
diff changeset
    85
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    86
//
hgs
parents:
diff changeset
    87
int VideoListDataModelPrivate::initialize()
hgs
parents:
diff changeset
    88
{
36
hgs
parents: 35
diff changeset
    89
	FUNC_LOG;
30
hgs
parents:
diff changeset
    90
    if(mInitialized)
hgs
parents:
diff changeset
    91
    {
hgs
parents:
diff changeset
    92
        return 0;
hgs
parents:
diff changeset
    93
    }
34
hgs
parents: 30
diff changeset
    94
    mVideoThumbnailData = &(VideoThumbnailData::instance());
50
hgs
parents: 49
diff changeset
    95
    if(!connect( mVideoThumbnailData, SIGNAL(thumbnailsFetched( QList<TMPXItemId>& )), 
hgs
parents: 49
diff changeset
    96
                  this, SLOT(thumbnailsFetchedSlot( QList<TMPXItemId>& ))))
30
hgs
parents:
diff changeset
    97
    {
hgs
parents:
diff changeset
    98
        return -1;
hgs
parents:
diff changeset
    99
    }
hgs
parents:
diff changeset
   100
hgs
parents:
diff changeset
   101
    mInitialized = true;
hgs
parents:
diff changeset
   102
    return 0;
hgs
parents:
diff changeset
   103
}
hgs
parents:
diff changeset
   104
hgs
parents:
diff changeset
   105
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   106
// getVideoCount
hgs
parents:
diff changeset
   107
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   108
//
hgs
parents:
diff changeset
   109
int VideoListDataModelPrivate::getVideoCount()
hgs
parents:
diff changeset
   110
{
hgs
parents:
diff changeset
   111
    return mMediaData.count();
hgs
parents:
diff changeset
   112
}
hgs
parents:
diff changeset
   113
hgs
parents:
diff changeset
   114
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   115
// getMediaIdFromIndex
hgs
parents:
diff changeset
   116
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   117
//
50
hgs
parents: 49
diff changeset
   118
const TMPXItemId& VideoListDataModelPrivate::getMediaIdFromIndex(const int &index ) const
30
hgs
parents:
diff changeset
   119
{
hgs
parents:
diff changeset
   120
    return mMediaData.idFromIndex(index);
hgs
parents:
diff changeset
   121
}
hgs
parents:
diff changeset
   122
hgs
parents:
diff changeset
   123
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   124
// getVideoNameFromIndex
hgs
parents:
diff changeset
   125
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   126
//
50
hgs
parents: 49
diff changeset
   127
const QString VideoListDataModelPrivate::getVideoNameFromIndex(const int &index )  const
30
hgs
parents:
diff changeset
   128
{
hgs
parents:
diff changeset
   129
    QString txt;
hgs
parents:
diff changeset
   130
    CMPXMedia* media = mMediaData.fromIndex(index);
hgs
parents:
diff changeset
   131
    VideoCollectionUtils::instance().mediaValue<QString>(media, KMPXMediaGeneralTitle, txt );
hgs
parents:
diff changeset
   132
    return txt;
hgs
parents:
diff changeset
   133
}
hgs
parents:
diff changeset
   134
 
hgs
parents:
diff changeset
   135
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   136
// getVideoThumbnailFromIndex
hgs
parents:
diff changeset
   137
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   138
//
50
hgs
parents: 49
diff changeset
   139
const QIcon* VideoListDataModelPrivate::getVideoThumbnailFromIndex(const int &index ) const
30
hgs
parents:
diff changeset
   140
{
34
hgs
parents: 30
diff changeset
   141
    if(mVideoThumbnailData)
hgs
parents: 30
diff changeset
   142
    {
hgs
parents: 30
diff changeset
   143
        return mVideoThumbnailData->getThumbnail( mMediaData.idFromIndex(index) );
hgs
parents: 30
diff changeset
   144
    }
hgs
parents: 30
diff changeset
   145
    return 0;
30
hgs
parents:
diff changeset
   146
}
hgs
parents:
diff changeset
   147
hgs
parents:
diff changeset
   148
// -----------------------------------------------------------------------------
35
hgs
parents: 34
diff changeset
   149
// getCategoryVideoCountFromIndex
hgs
parents: 34
diff changeset
   150
// -----------------------------------------------------------------------------
hgs
parents: 34
diff changeset
   151
//
50
hgs
parents: 49
diff changeset
   152
quint32 VideoListDataModelPrivate::getCategoryVideoCountFromIndex(const int &index ) const
35
hgs
parents: 34
diff changeset
   153
{
hgs
parents: 34
diff changeset
   154
    quint32 count(0);
hgs
parents: 34
diff changeset
   155
    CMPXMedia *media = mMediaData.fromIndex(index);
hgs
parents: 34
diff changeset
   156
    VideoCollectionUtils::instance().mediaValue<quint32>(media, KVcxMediaMyVideosCategoryItemCount, count );
hgs
parents: 34
diff changeset
   157
    return count;
hgs
parents: 34
diff changeset
   158
}
hgs
parents: 34
diff changeset
   159
hgs
parents: 34
diff changeset
   160
// -----------------------------------------------------------------------------
30
hgs
parents:
diff changeset
   161
// getVideoSizeFromIndex
hgs
parents:
diff changeset
   162
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   163
//
50
hgs
parents: 49
diff changeset
   164
quint32 VideoListDataModelPrivate::getVideoSizeFromIndex(const int &index ) const
30
hgs
parents:
diff changeset
   165
{
hgs
parents:
diff changeset
   166
    quint32 size(0);
hgs
parents:
diff changeset
   167
    CMPXMedia *media = mMediaData.fromIndex(index);
hgs
parents:
diff changeset
   168
    VideoCollectionUtils::instance().mediaValue<quint32>(media, KMPXMediaGeneralSize, size );    
35
hgs
parents: 34
diff changeset
   169
    return size;
30
hgs
parents:
diff changeset
   170
}
hgs
parents:
diff changeset
   171
hgs
parents:
diff changeset
   172
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   173
// getVideoAgeProfileFromIndex
hgs
parents:
diff changeset
   174
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   175
//
50
hgs
parents: 49
diff changeset
   176
quint32 VideoListDataModelPrivate::getVideoAgeProfileFromIndex(const int &index ) const
30
hgs
parents:
diff changeset
   177
{
hgs
parents:
diff changeset
   178
    quint32 ageProfile(0);
hgs
parents:
diff changeset
   179
    CMPXMedia *media = mMediaData.fromIndex(index);
hgs
parents:
diff changeset
   180
    VideoCollectionUtils::instance().mediaValue<quint32>(media, KVcxMediaMyVideosAgeProfile, ageProfile );    
hgs
parents:
diff changeset
   181
    return ageProfile; 
hgs
parents:
diff changeset
   182
}
hgs
parents:
diff changeset
   183
hgs
parents:
diff changeset
   184
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   185
// getVideodurationFromIndex
hgs
parents:
diff changeset
   186
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   187
//
50
hgs
parents: 49
diff changeset
   188
quint32 VideoListDataModelPrivate::getVideodurationFromIndex(const int &index ) const
30
hgs
parents:
diff changeset
   189
{
36
hgs
parents: 35
diff changeset
   190
    CMPXMedia *media = mMediaData.fromIndex(index);
hgs
parents: 35
diff changeset
   191
    return getVideoDuration(media);
hgs
parents: 35
diff changeset
   192
}
hgs
parents: 35
diff changeset
   193
hgs
parents: 35
diff changeset
   194
// -----------------------------------------------------------------------------
hgs
parents: 35
diff changeset
   195
// getVideodurationFromIndex
hgs
parents: 35
diff changeset
   196
// -----------------------------------------------------------------------------
hgs
parents: 35
diff changeset
   197
//
hgs
parents: 35
diff changeset
   198
quint32 VideoListDataModelPrivate::getVideoDuration(CMPXMedia* media) const
hgs
parents: 35
diff changeset
   199
{
30
hgs
parents:
diff changeset
   200
    quint32 returnDuration(0);
hgs
parents:
diff changeset
   201
    float duration(0);
hgs
parents:
diff changeset
   202
    VideoCollectionUtils::instance().mediaValue<float>(media, KVcxMediaMyVideosDuration, duration );
hgs
parents:
diff changeset
   203
    returnDuration = static_cast<quint32>(duration);
hgs
parents:
diff changeset
   204
    return returnDuration;
hgs
parents:
diff changeset
   205
}
hgs
parents:
diff changeset
   206
hgs
parents:
diff changeset
   207
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   208
// getVideoDateFromIndex
hgs
parents:
diff changeset
   209
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   210
//
50
hgs
parents: 49
diff changeset
   211
QDateTime VideoListDataModelPrivate::getVideoDateFromIndex(const int &index ) const
30
hgs
parents:
diff changeset
   212
{
36
hgs
parents: 35
diff changeset
   213
    return getVideoDate(mMediaData.fromIndex(index));
hgs
parents: 35
diff changeset
   214
}
hgs
parents: 35
diff changeset
   215
hgs
parents: 35
diff changeset
   216
// -----------------------------------------------------------------------------
hgs
parents: 35
diff changeset
   217
// getVideoDate
hgs
parents: 35
diff changeset
   218
// -----------------------------------------------------------------------------
hgs
parents: 35
diff changeset
   219
//
hgs
parents: 35
diff changeset
   220
QDateTime VideoListDataModelPrivate::getVideoDate(CMPXMedia* media) const
hgs
parents: 35
diff changeset
   221
{
30
hgs
parents:
diff changeset
   222
    QDateTime date;
hgs
parents:
diff changeset
   223
    quint64 dateTimeValue;
36
hgs
parents: 35
diff changeset
   224
    if(!VideoCollectionUtils::instance().mediaValue<quint64>(media, KMPXMediaGeneralDate, dateTimeValue)) 
30
hgs
parents:
diff changeset
   225
    {
hgs
parents:
diff changeset
   226
        return date;
hgs
parents:
diff changeset
   227
    }
hgs
parents:
diff changeset
   228
    TDateTime temp = TTime( dateTimeValue ).DateTime();
hgs
parents:
diff changeset
   229
    date = QDateTime(QDate(temp.Year(), temp.Month()+1, temp.Day()+1), 
hgs
parents:
diff changeset
   230
                       QTime(temp.Hour(), temp.Minute(), temp.Second(), temp.MicroSecond()));
hgs
parents:
diff changeset
   231
    return date;
hgs
parents:
diff changeset
   232
}
hgs
parents:
diff changeset
   233
hgs
parents:
diff changeset
   234
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   235
// markVideosRemoved
hgs
parents:
diff changeset
   236
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   237
//
50
hgs
parents: 49
diff changeset
   238
const TMPXItemId VideoListDataModelPrivate::markVideoRemoved(const QModelIndex &itemIndex)
30
hgs
parents:
diff changeset
   239
{
34
hgs
parents: 30
diff changeset
   240
    return mMediaData.markItemRemoved(itemIndex.row());
30
hgs
parents:
diff changeset
   241
}
hgs
parents:
diff changeset
   242
hgs
parents:
diff changeset
   243
// -----------------------------------------------------------------------------
34
hgs
parents: 30
diff changeset
   244
// restoreRemoved
30
hgs
parents:
diff changeset
   245
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   246
//
34
hgs
parents: 30
diff changeset
   247
void VideoListDataModelPrivate::restoreRemoved(QList<TMPXItemId> *idList)
30
hgs
parents:
diff changeset
   248
{
36
hgs
parents: 35
diff changeset
   249
	FUNC_LOG;
34
hgs
parents: 30
diff changeset
   250
    int startIndex = mMediaData.count();
hgs
parents: 30
diff changeset
   251
    int restored = mMediaData.restoreRemovedItems(idList);
hgs
parents: 30
diff changeset
   252
    if(restored > 0)
30
hgs
parents:
diff changeset
   253
    {
34
hgs
parents: 30
diff changeset
   254
        q_ptr->beginInsertRows(QModelIndex(), startIndex, startIndex + (restored - 1));
hgs
parents: 30
diff changeset
   255
        q_ptr->endInsertRows();
30
hgs
parents:
diff changeset
   256
    }
hgs
parents:
diff changeset
   257
}
hgs
parents:
diff changeset
   258
hgs
parents:
diff changeset
   259
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   260
// getFilePathFromIndex
hgs
parents:
diff changeset
   261
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   262
//
50
hgs
parents: 49
diff changeset
   263
const QString VideoListDataModelPrivate::getFilePathFromIndex(const int &index) const
30
hgs
parents:
diff changeset
   264
{
hgs
parents:
diff changeset
   265
    QString filePath;
hgs
parents:
diff changeset
   266
    VideoCollectionUtils::instance().mediaValue<QString>(mMediaData.fromIndex(index), 
hgs
parents:
diff changeset
   267
            KMPXMediaGeneralUri, filePath );
hgs
parents:
diff changeset
   268
    return filePath;
hgs
parents:
diff changeset
   269
}
hgs
parents:
diff changeset
   270
hgs
parents:
diff changeset
   271
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   272
// getFilePathForId
hgs
parents:
diff changeset
   273
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   274
//
50
hgs
parents: 49
diff changeset
   275
const QString VideoListDataModelPrivate::getFilePathForId(const TMPXItemId &mediaId)
30
hgs
parents:
diff changeset
   276
{
hgs
parents:
diff changeset
   277
    QString filePath;
hgs
parents:
diff changeset
   278
    int index = mMediaData.indexOfId(mediaId);
hgs
parents:
diff changeset
   279
    VideoCollectionUtils::instance().mediaValue<QString>(mMediaData.fromIndex(index), 
hgs
parents:
diff changeset
   280
            KMPXMediaGeneralUri, filePath );
hgs
parents:
diff changeset
   281
    return filePath;
hgs
parents:
diff changeset
   282
}
hgs
parents:
diff changeset
   283
hgs
parents:
diff changeset
   284
// -----------------------------------------------------------------------------
34
hgs
parents: 30
diff changeset
   285
// belongsToAlbum
hgs
parents: 30
diff changeset
   286
// -----------------------------------------------------------------------------
hgs
parents: 30
diff changeset
   287
//
hgs
parents: 30
diff changeset
   288
bool VideoListDataModelPrivate::belongsToAlbum(const TMPXItemId &itemId, TMPXItemId albumId) const
hgs
parents: 30
diff changeset
   289
{
hgs
parents: 30
diff changeset
   290
    bool contains(false);
hgs
parents: 30
diff changeset
   291
    QHash<TMPXItemId, QSet<TMPXItemId> >::const_iterator iter;
hgs
parents: 30
diff changeset
   292
    if(albumId == TMPXItemId::InvalidId())
hgs
parents: 30
diff changeset
   293
    {    
hgs
parents: 30
diff changeset
   294
        // album id not specified, use the current album
hgs
parents: 30
diff changeset
   295
        iter = mAlbumData.constFind(mCurrentAlbum);
hgs
parents: 30
diff changeset
   296
    }
hgs
parents: 30
diff changeset
   297
    else
hgs
parents: 30
diff changeset
   298
    {
hgs
parents: 30
diff changeset
   299
        iter = mAlbumData.constFind(albumId);
hgs
parents: 30
diff changeset
   300
    }     
hgs
parents: 30
diff changeset
   301
    if (iter != mAlbumData.constEnd())
hgs
parents: 30
diff changeset
   302
    {
hgs
parents: 30
diff changeset
   303
        contains = iter->contains(itemId);
hgs
parents: 30
diff changeset
   304
    }
hgs
parents: 30
diff changeset
   305
    return contains;
hgs
parents: 30
diff changeset
   306
}
hgs
parents: 30
diff changeset
   307
hgs
parents: 30
diff changeset
   308
// -----------------------------------------------------------------------------
35
hgs
parents: 34
diff changeset
   309
// setAlbumInUse
34
hgs
parents: 30
diff changeset
   310
// -----------------------------------------------------------------------------
hgs
parents: 30
diff changeset
   311
//
50
hgs
parents: 49
diff changeset
   312
void VideoListDataModelPrivate::setAlbumInUse(const TMPXItemId &albumId)
34
hgs
parents: 30
diff changeset
   313
{
36
hgs
parents: 35
diff changeset
   314
	FUNC_LOG;
34
hgs
parents: 30
diff changeset
   315
    mCurrentAlbum = albumId;
hgs
parents: 30
diff changeset
   316
}
hgs
parents: 30
diff changeset
   317
hgs
parents: 30
diff changeset
   318
// -----------------------------------------------------------------------------
35
hgs
parents: 34
diff changeset
   319
// removeItemsFromAlbum
hgs
parents: 34
diff changeset
   320
// -----------------------------------------------------------------------------
hgs
parents: 34
diff changeset
   321
//
50
hgs
parents: 49
diff changeset
   322
int VideoListDataModelPrivate::removeItemsFromAlbum(const TMPXItemId &albumId, 
35
hgs
parents: 34
diff changeset
   323
                                        const QList<TMPXItemId> &items)
hgs
parents: 34
diff changeset
   324
{
36
hgs
parents: 35
diff changeset
   325
	FUNC_LOG;
35
hgs
parents: 34
diff changeset
   326
    QHash<TMPXItemId, QSet<TMPXItemId> >::iterator iter = mAlbumData.find(albumId);
hgs
parents: 34
diff changeset
   327
    if(iter == mAlbumData.end())
hgs
parents: 34
diff changeset
   328
    {
hgs
parents: 34
diff changeset
   329
        return 0;
hgs
parents: 34
diff changeset
   330
    }
hgs
parents: 34
diff changeset
   331
    int removeCount = 0;
hgs
parents: 34
diff changeset
   332
    int count = items.count();
hgs
parents: 34
diff changeset
   333
    for(int i = 0; i < count; ++i)
hgs
parents: 34
diff changeset
   334
    {
hgs
parents: 34
diff changeset
   335
        if(iter->remove(items.at(i)))
hgs
parents: 34
diff changeset
   336
        {
hgs
parents: 34
diff changeset
   337
            ++removeCount;
hgs
parents: 34
diff changeset
   338
        }
hgs
parents: 34
diff changeset
   339
    }   
hgs
parents: 34
diff changeset
   340
    return removeCount;
hgs
parents: 34
diff changeset
   341
}
hgs
parents: 34
diff changeset
   342
hgs
parents: 34
diff changeset
   343
// -----------------------------------------------------------------------------
30
hgs
parents:
diff changeset
   344
// getMediaId
hgs
parents:
diff changeset
   345
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   346
//
hgs
parents:
diff changeset
   347
TMPXItemId VideoListDataModelPrivate::getMediaId(const CMPXMedia *media ) const
hgs
parents:
diff changeset
   348
{
hgs
parents:
diff changeset
   349
    TMPXItemId mediaId = TMPXItemId::InvalidId();
hgs
parents:
diff changeset
   350
    
hgs
parents:
diff changeset
   351
    VideoCollectionUtils::instance().mediaValue<TMPXItemId>(media, KMPXMediaGeneralId, mediaId );
hgs
parents:
diff changeset
   352
hgs
parents:
diff changeset
   353
    return mediaId;
hgs
parents:
diff changeset
   354
}
hgs
parents:
diff changeset
   355
hgs
parents:
diff changeset
   356
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   357
// appendDataToContainerL
hgs
parents:
diff changeset
   358
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   359
//
34
hgs
parents: 30
diff changeset
   360
void VideoListDataModelPrivate::appendDataToContainerL(
hgs
parents: 30
diff changeset
   361
    CMPXMediaArray *videoArray,
hgs
parents: 30
diff changeset
   362
    unsigned int startIndex)
30
hgs
parents:
diff changeset
   363
{
36
hgs
parents: 35
diff changeset
   364
	FUNC_LOG;
hgs
parents: 35
diff changeset
   365
	
34
hgs
parents: 30
diff changeset
   366
    if (!videoArray ||
41
hgs
parents: 38
diff changeset
   367
        startIndex >= videoArray->Count())
30
hgs
parents:
diff changeset
   368
    {
hgs
parents:
diff changeset
   369
        return;
hgs
parents:
diff changeset
   370
    }
hgs
parents:
diff changeset
   371
    
41
hgs
parents: 38
diff changeset
   372
    INFO_2("VideoListDataModelPrivate::appendDataToContainerL() array count: %d, start index: %d", videoArray->Count(), startIndex);
hgs
parents: 38
diff changeset
   373
    
30
hgs
parents:
diff changeset
   374
    CMPXMedia *newMedia = 0;
34
hgs
parents: 30
diff changeset
   375
    CMPXMedia *mediaFromArray = 0;
30
hgs
parents:
diff changeset
   376
    TMPXItemId itemId = TMPXItemId::InvalidId();
41
hgs
parents: 38
diff changeset
   377
    int count = videoArray->Count();
hgs
parents: 38
diff changeset
   378
    
30
hgs
parents:
diff changeset
   379
    for(int i = startIndex; i < count; ++i)
hgs
parents:
diff changeset
   380
    {
34
hgs
parents: 30
diff changeset
   381
        mediaFromArray = videoArray->AtL(i);
hgs
parents: 30
diff changeset
   382
        itemId = getMediaId(mediaFromArray);
hgs
parents: 30
diff changeset
   383
        if (isValid(*mediaFromArray, itemId))
30
hgs
parents:
diff changeset
   384
        {
34
hgs
parents: 30
diff changeset
   385
            newMedia = CMPXMedia::NewL(*mediaFromArray);
30
hgs
parents:
diff changeset
   386
            mMediaData.append(newMedia);
34
hgs
parents: 30
diff changeset
   387
            newMedia = 0;
30
hgs
parents:
diff changeset
   388
        }
36
hgs
parents: 35
diff changeset
   389
    }
30
hgs
parents:
diff changeset
   390
}
hgs
parents:
diff changeset
   391
hgs
parents:
diff changeset
   392
// -----------------------------------------------------------------------------
34
hgs
parents: 30
diff changeset
   393
// isValid
hgs
parents: 30
diff changeset
   394
// -----------------------------------------------------------------------------
hgs
parents: 30
diff changeset
   395
//
hgs
parents: 30
diff changeset
   396
bool VideoListDataModelPrivate::isValid(const CMPXMedia &media,
hgs
parents: 30
diff changeset
   397
    const TMPXItemId &itemId) const
hgs
parents: 30
diff changeset
   398
{
hgs
parents: 30
diff changeset
   399
    if(itemId == TMPXItemId::InvalidId())
hgs
parents: 30
diff changeset
   400
    {
hgs
parents: 30
diff changeset
   401
        return false;
hgs
parents: 30
diff changeset
   402
    }    
hgs
parents: 30
diff changeset
   403
    // temporary to remove all items with out a title
hgs
parents: 30
diff changeset
   404
    QString title;
hgs
parents: 30
diff changeset
   405
    VideoCollectionUtils::instance().mediaValue<QString>(&media,
hgs
parents: 30
diff changeset
   406
        KMPXMediaGeneralTitle,
hgs
parents: 30
diff changeset
   407
        title);
hgs
parents: 30
diff changeset
   408
    if (!title.length())
hgs
parents: 30
diff changeset
   409
    {
hgs
parents: 30
diff changeset
   410
        return false;
hgs
parents: 30
diff changeset
   411
    }
hgs
parents: 30
diff changeset
   412
    // recently played and podcasts are not yet supported
hgs
parents: 30
diff changeset
   413
    if(itemId.iId2 == KVcxMvcMediaTypeCategory && 
hgs
parents: 30
diff changeset
   414
        (itemId.iId1 != KVcxMvcCategoryIdDownloads &&
hgs
parents: 30
diff changeset
   415
         itemId.iId1 != KVcxMvcCategoryIdCaptured))
hgs
parents: 30
diff changeset
   416
    {
hgs
parents: 30
diff changeset
   417
        return false;
hgs
parents: 30
diff changeset
   418
    }
hgs
parents: 30
diff changeset
   419
    return true;
hgs
parents: 30
diff changeset
   420
}
hgs
parents: 30
diff changeset
   421
hgs
parents: 30
diff changeset
   422
// -----------------------------------------------------------------------------
35
hgs
parents: 34
diff changeset
   423
// albumDataChangedL
34
hgs
parents: 30
diff changeset
   424
// -----------------------------------------------------------------------------
hgs
parents: 30
diff changeset
   425
//
50
hgs
parents: 49
diff changeset
   426
void VideoListDataModelPrivate::albumDataChangedL(TMPXItemId &albumId,
34
hgs
parents: 30
diff changeset
   427
    CMPXMediaArray *videoArray)
hgs
parents: 30
diff changeset
   428
{
36
hgs
parents: 35
diff changeset
   429
	FUNC_LOG;
34
hgs
parents: 30
diff changeset
   430
    if (!videoArray || albumId == TMPXItemId::InvalidId())
hgs
parents: 30
diff changeset
   431
    {
hgs
parents: 30
diff changeset
   432
        return;
hgs
parents: 30
diff changeset
   433
    }
hgs
parents: 30
diff changeset
   434
    QSet<TMPXItemId> items;
49
hgs
parents: 41
diff changeset
   435
    
hgs
parents: 41
diff changeset
   436
    int oldCount = mAlbumData[albumId].count();
hgs
parents: 41
diff changeset
   437
    
35
hgs
parents: 34
diff changeset
   438
    // remove existing
hgs
parents: 34
diff changeset
   439
    mAlbumData.remove(albumId);
hgs
parents: 34
diff changeset
   440
    
34
hgs
parents: 30
diff changeset
   441
    int videoCount = videoArray->Count();
hgs
parents: 30
diff changeset
   442
    CMPXMedia *media = 0;
hgs
parents: 30
diff changeset
   443
    TMPXItemId id = TMPXItemId::InvalidId();
hgs
parents: 30
diff changeset
   444
    for (int i = videoCount - 1; i >= 0; i--)
hgs
parents: 30
diff changeset
   445
    {
hgs
parents: 30
diff changeset
   446
        media = videoArray->AtL(i);
hgs
parents: 30
diff changeset
   447
        id = getMediaId(media);
35
hgs
parents: 34
diff changeset
   448
        if (id != TMPXItemId::InvalidId() && id.iId2 == KVcxMvcMediaTypeVideo)
hgs
parents: 34
diff changeset
   449
        {          
34
hgs
parents: 30
diff changeset
   450
            items.insert(id);
hgs
parents: 30
diff changeset
   451
        }
hgs
parents: 30
diff changeset
   452
    }  
35
hgs
parents: 34
diff changeset
   453
 
34
hgs
parents: 30
diff changeset
   454
    mAlbumData[albumId] = items;
35
hgs
parents: 34
diff changeset
   455
    
49
hgs
parents: 41
diff changeset
   456
    if(oldCount != items.count())
hgs
parents: 41
diff changeset
   457
    {
hgs
parents: 41
diff changeset
   458
        // signal that album has been updated
hgs
parents: 41
diff changeset
   459
        emit q_ptr->albumChanged();
34
hgs
parents: 30
diff changeset
   460
49
hgs
parents: 41
diff changeset
   461
        // signal that model has changed.
hgs
parents: 41
diff changeset
   462
        emit q_ptr->modelChanged();
hgs
parents: 41
diff changeset
   463
    }
34
hgs
parents: 30
diff changeset
   464
}
hgs
parents: 30
diff changeset
   465
hgs
parents: 30
diff changeset
   466
hgs
parents: 30
diff changeset
   467
// -----------------------------------------------------------------------------
30
hgs
parents:
diff changeset
   468
// thumbnailsFetchedSlot
hgs
parents:
diff changeset
   469
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   470
//
50
hgs
parents: 49
diff changeset
   471
void VideoListDataModelPrivate::thumbnailsFetchedSlot(QList<TMPXItemId> &mediaIds)
30
hgs
parents:
diff changeset
   472
{
hgs
parents:
diff changeset
   473
    TMPXItemId id;
hgs
parents:
diff changeset
   474
    QModelIndex rowIndex;
hgs
parents:
diff changeset
   475
    
hgs
parents:
diff changeset
   476
    while(!mediaIds.isEmpty())
hgs
parents:
diff changeset
   477
    {
hgs
parents:
diff changeset
   478
        id = mediaIds.takeFirst();
hgs
parents:
diff changeset
   479
        rowIndex = q_ptr->index(mMediaData.indexOfId(id), 0);
hgs
parents:
diff changeset
   480
		if(rowIndex.isValid())
hgs
parents:
diff changeset
   481
		{
50
hgs
parents: 49
diff changeset
   482
	        emit q_ptr->dataChanged( rowIndex, rowIndex);
30
hgs
parents:
diff changeset
   483
		}
hgs
parents:
diff changeset
   484
    }
hgs
parents:
diff changeset
   485
}
hgs
parents:
diff changeset
   486
hgs
parents:
diff changeset
   487
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   488
// newVideoListSlot
hgs
parents:
diff changeset
   489
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   490
//
hgs
parents:
diff changeset
   491
void VideoListDataModelPrivate::newVideoListSlot( CMPXMediaArray *newVideoList )
hgs
parents:
diff changeset
   492
{
36
hgs
parents: 35
diff changeset
   493
	FUNC_LOG;
30
hgs
parents:
diff changeset
   494
    if( !newVideoList )
hgs
parents:
diff changeset
   495
    {
hgs
parents:
diff changeset
   496
        return;
hgs
parents:
diff changeset
   497
    }
36
hgs
parents: 35
diff changeset
   498
    
34
hgs
parents: 30
diff changeset
   499
    int startIndex = mMediaData.count();
30
hgs
parents:
diff changeset
   500
hgs
parents:
diff changeset
   501
    TRAP_IGNORE(appendDataToContainerL(newVideoList));
hgs
parents:
diff changeset
   502
	
34
hgs
parents: 30
diff changeset
   503
    int endIndex = mMediaData.count() - 1;
hgs
parents: 30
diff changeset
   504
    if(startIndex <= endIndex)
hgs
parents: 30
diff changeset
   505
    {
hgs
parents: 30
diff changeset
   506
        q_ptr->beginInsertRows(QModelIndex(), startIndex, endIndex);
hgs
parents: 30
diff changeset
   507
        q_ptr->endInsertRows();
38
hgs
parents: 37
diff changeset
   508
        emit q_ptr->modelChanged();
34
hgs
parents: 30
diff changeset
   509
    }
30
hgs
parents:
diff changeset
   510
}
hgs
parents:
diff changeset
   511
hgs
parents:
diff changeset
   512
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   513
// appendVideoListSlot
hgs
parents:
diff changeset
   514
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   515
//
hgs
parents:
diff changeset
   516
void VideoListDataModelPrivate::appendVideoListSlot(CMPXMediaArray* videoList)
hgs
parents:
diff changeset
   517
{
36
hgs
parents: 35
diff changeset
   518
	FUNC_LOG;
30
hgs
parents:
diff changeset
   519
    if(!videoList)
hgs
parents:
diff changeset
   520
    {
hgs
parents:
diff changeset
   521
        return;
hgs
parents:
diff changeset
   522
    }
hgs
parents:
diff changeset
   523
    if(videoList->Count() == 0 || videoList->Count() <= mMediaData.count())
hgs
parents:
diff changeset
   524
    {
hgs
parents:
diff changeset
   525
        // nothing to append or count matches, no changes -> nothing to append
hgs
parents:
diff changeset
   526
        return;
hgs
parents:
diff changeset
   527
    }
hgs
parents:
diff changeset
   528
            
hgs
parents:
diff changeset
   529
    // array gotten is in same order as existing data from the start,
hgs
parents:
diff changeset
   530
    // so we only need to go throught the appendding array from the index
hgs
parents:
diff changeset
   531
    // at position where first new items is excepted to exists.    
hgs
parents:
diff changeset
   532
    int startIndex = mMediaData.count();
hgs
parents:
diff changeset
   533
    
hgs
parents:
diff changeset
   534
    q_ptr->beginInsertRows(QModelIndex(), startIndex, videoList->Count() - 1);
hgs
parents:
diff changeset
   535
hgs
parents:
diff changeset
   536
    TRAP_IGNORE(appendDataToContainerL(videoList, startIndex));
hgs
parents:
diff changeset
   537
hgs
parents:
diff changeset
   538
    q_ptr->endInsertRows();
34
hgs
parents: 30
diff changeset
   539
    emit q_ptr->modelChanged();
30
hgs
parents:
diff changeset
   540
}
hgs
parents:
diff changeset
   541
hgs
parents:
diff changeset
   542
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   543
// newVideoAvailable
hgs
parents:
diff changeset
   544
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   545
//
hgs
parents:
diff changeset
   546
void VideoListDataModelPrivate::newVideoAvailableSlot(CMPXMedia *newVideo)
hgs
parents:
diff changeset
   547
{
36
hgs
parents: 35
diff changeset
   548
	FUNC_LOG;
30
hgs
parents:
diff changeset
   549
    if(!newVideo ) 
hgs
parents:
diff changeset
   550
    {
hgs
parents:
diff changeset
   551
        return;        
hgs
parents:
diff changeset
   552
    }
hgs
parents:
diff changeset
   553
hgs
parents:
diff changeset
   554
    // try to get id of the video, if not found consider invalid clip
hgs
parents:
diff changeset
   555
    TMPXItemId mediaId = getMediaId(newVideo);
hgs
parents:
diff changeset
   556
    if( mediaId == TMPXItemId::InvalidId())
hgs
parents:
diff changeset
   557
    {
hgs
parents:
diff changeset
   558
        return;
hgs
parents:
diff changeset
   559
    }
hgs
parents:
diff changeset
   560
hgs
parents:
diff changeset
   561
    // append video into list, ownership of provided mediaobject is not transferred, 
hgs
parents:
diff changeset
   562
    // so we need to create copy of CMPXMedia
34
hgs
parents: 30
diff changeset
   563
    if (isValid(*newVideo, mediaId))
hgs
parents: 30
diff changeset
   564
    {
hgs
parents: 30
diff changeset
   565
        CMPXMedia *videoToAppend = 0;
hgs
parents: 30
diff changeset
   566
        TRAP_IGNORE(videoToAppend = CMPXMedia::NewL(*newVideo));  
30
hgs
parents:
diff changeset
   567
    
34
hgs
parents: 30
diff changeset
   568
        q_ptr->beginInsertRows(QModelIndex(), mMediaData.count(), mMediaData.count());
hgs
parents: 30
diff changeset
   569
    
hgs
parents: 30
diff changeset
   570
        mMediaData.append(videoToAppend);    
hgs
parents: 30
diff changeset
   571
  
hgs
parents: 30
diff changeset
   572
        q_ptr->endInsertRows();
30
hgs
parents:
diff changeset
   573
    
34
hgs
parents: 30
diff changeset
   574
        emit q_ptr->modelChanged();
hgs
parents: 30
diff changeset
   575
    }
hgs
parents: 30
diff changeset
   576
}
hgs
parents: 30
diff changeset
   577
hgs
parents: 30
diff changeset
   578
// -----------------------------------------------------------------------------
hgs
parents: 30
diff changeset
   579
// itemDeletedSlot
hgs
parents: 30
diff changeset
   580
// -----------------------------------------------------------------------------
hgs
parents: 30
diff changeset
   581
//
50
hgs
parents: 49
diff changeset
   582
void VideoListDataModelPrivate::itemDeletedSlot(TMPXItemId &itemId)
34
hgs
parents: 30
diff changeset
   583
{
36
hgs
parents: 35
diff changeset
   584
	FUNC_LOG;
34
hgs
parents: 30
diff changeset
   585
	if(itemId == TMPXItemId::InvalidId())
hgs
parents: 30
diff changeset
   586
    {
hgs
parents: 30
diff changeset
   587
        return;
hgs
parents: 30
diff changeset
   588
    }    
hgs
parents: 30
diff changeset
   589
hgs
parents: 30
diff changeset
   590
	if(itemId.iId2 == KVcxMvcMediaTypeVideo)
hgs
parents: 30
diff changeset
   591
    {
hgs
parents: 30
diff changeset
   592
    	videoDeleted(itemId);
hgs
parents: 30
diff changeset
   593
    }
hgs
parents: 30
diff changeset
   594
    else if (itemId.iId2 == KVcxMvcMediaTypeAlbum)
hgs
parents: 30
diff changeset
   595
    {
hgs
parents: 30
diff changeset
   596
    	albumRemoved(itemId);
hgs
parents: 30
diff changeset
   597
    }
hgs
parents: 30
diff changeset
   598
}
30
hgs
parents:
diff changeset
   599
34
hgs
parents: 30
diff changeset
   600
// -----------------------------------------------------------------------------
hgs
parents: 30
diff changeset
   601
// albumRemoved 
hgs
parents: 30
diff changeset
   602
// -----------------------------------------------------------------------------
hgs
parents: 30
diff changeset
   603
//
50
hgs
parents: 49
diff changeset
   604
void VideoListDataModelPrivate::albumRemoved(TMPXItemId &albumId)
34
hgs
parents: 30
diff changeset
   605
{
36
hgs
parents: 35
diff changeset
   606
	FUNC_LOG;
34
hgs
parents: 30
diff changeset
   607
    if (albumId == TMPXItemId::InvalidId() || albumId.iId2 != KVcxMvcMediaTypeAlbum)
hgs
parents: 30
diff changeset
   608
    {
hgs
parents: 30
diff changeset
   609
        return;
hgs
parents: 30
diff changeset
   610
    }
hgs
parents: 30
diff changeset
   611
    
hgs
parents: 30
diff changeset
   612
    bool changed(false);
hgs
parents: 30
diff changeset
   613
hgs
parents: 30
diff changeset
   614
    if(mVideoThumbnailData)
hgs
parents: 30
diff changeset
   615
    {
hgs
parents: 30
diff changeset
   616
        mVideoThumbnailData->removeThumbnail( albumId );
hgs
parents: 30
diff changeset
   617
    }
hgs
parents: 30
diff changeset
   618
hgs
parents: 30
diff changeset
   619
    int index = mMediaData.indexOfId(albumId);
hgs
parents: 30
diff changeset
   620
    if(index >= 0)
hgs
parents: 30
diff changeset
   621
    {
hgs
parents: 30
diff changeset
   622
        q_ptr->beginRemoveRows(QModelIndex(), index, index);
hgs
parents: 30
diff changeset
   623
        mMediaData.remove(albumId);            
hgs
parents: 30
diff changeset
   624
        q_ptr->endRemoveRows();
hgs
parents: 30
diff changeset
   625
        changed = true;
hgs
parents: 30
diff changeset
   626
    }
hgs
parents: 30
diff changeset
   627
hgs
parents: 30
diff changeset
   628
    //remove album data
hgs
parents: 30
diff changeset
   629
    QHash<TMPXItemId, QSet<TMPXItemId> >::iterator iter;
hgs
parents: 30
diff changeset
   630
    iter =  mAlbumData.find(albumId);
hgs
parents: 30
diff changeset
   631
    if(iter != mAlbumData.end())
hgs
parents: 30
diff changeset
   632
    {
hgs
parents: 30
diff changeset
   633
        iter->clear();
35
hgs
parents: 34
diff changeset
   634
        mAlbumData.remove(albumId);
34
hgs
parents: 30
diff changeset
   635
        changed = true;
hgs
parents: 30
diff changeset
   636
    }
hgs
parents: 30
diff changeset
   637
hgs
parents: 30
diff changeset
   638
    if(changed)
hgs
parents: 30
diff changeset
   639
    {
hgs
parents: 30
diff changeset
   640
    	emit q_ptr->modelChanged();
hgs
parents: 30
diff changeset
   641
    }
30
hgs
parents:
diff changeset
   642
}
hgs
parents:
diff changeset
   643
hgs
parents:
diff changeset
   644
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   645
// videoDeleted
hgs
parents:
diff changeset
   646
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   647
//
50
hgs
parents: 49
diff changeset
   648
void VideoListDataModelPrivate::videoDeleted(TMPXItemId &videoId)
30
hgs
parents:
diff changeset
   649
{
36
hgs
parents: 35
diff changeset
   650
	FUNC_LOG;
34
hgs
parents: 30
diff changeset
   651
    if(videoId == TMPXItemId::InvalidId())
hgs
parents: 30
diff changeset
   652
    {
hgs
parents: 30
diff changeset
   653
        return;
hgs
parents: 30
diff changeset
   654
    }    
hgs
parents: 30
diff changeset
   655
    // check if provided id is in the deleted -container and remove 
hgs
parents: 30
diff changeset
   656
    // it from there if it is.
hgs
parents: 30
diff changeset
   657
    QList<TMPXItemId> ids;
hgs
parents: 30
diff changeset
   658
    ids.append(videoId);
hgs
parents: 30
diff changeset
   659
    if(!mMediaData.clearRemoved(&ids))
30
hgs
parents:
diff changeset
   660
    {
34
hgs
parents: 30
diff changeset
   661
        q_ptr->mDeleteWorker->removeFromRequest(videoId);
hgs
parents: 30
diff changeset
   662
        if(mVideoThumbnailData)
hgs
parents: 30
diff changeset
   663
        {
hgs
parents: 30
diff changeset
   664
            mVideoThumbnailData->removeThumbnail( videoId );
hgs
parents: 30
diff changeset
   665
        }
hgs
parents: 30
diff changeset
   666
        // media removed was not in the deleted -container, so we have external 
hgs
parents: 30
diff changeset
   667
        // removal: in this case we need to indicate UI         
hgs
parents: 30
diff changeset
   668
        int index = mMediaData.indexOfId(videoId);
hgs
parents: 30
diff changeset
   669
        if(index >= 0)
hgs
parents: 30
diff changeset
   670
        {
hgs
parents: 30
diff changeset
   671
            q_ptr->beginRemoveRows(QModelIndex(), index, index);
36
hgs
parents: 35
diff changeset
   672
            mMediaData.remove(videoId);
34
hgs
parents: 30
diff changeset
   673
            q_ptr->endRemoveRows();
hgs
parents: 30
diff changeset
   674
            emit q_ptr->modelChanged();
hgs
parents: 30
diff changeset
   675
        }
hgs
parents: 30
diff changeset
   676
    }     
30
hgs
parents:
diff changeset
   677
}
hgs
parents:
diff changeset
   678
hgs
parents:
diff changeset
   679
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   680
// videoDeleteCompleted
hgs
parents:
diff changeset
   681
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   682
//
hgs
parents:
diff changeset
   683
void VideoListDataModelPrivate::videoDeleteCompletedSlot(int overallCount, QList<TMPXItemId> *failedMediaIds)
34
hgs
parents: 30
diff changeset
   684
{    
36
hgs
parents: 35
diff changeset
   685
	FUNC_LOG;
30
hgs
parents:
diff changeset
   686
    Q_UNUSED(overallCount);
hgs
parents:
diff changeset
   687
    if(!failedMediaIds)
hgs
parents:
diff changeset
   688
    {
34
hgs
parents: 30
diff changeset
   689
        // invalid signal received, do nothing
30
hgs
parents:
diff changeset
   690
        return;
hgs
parents:
diff changeset
   691
    }
34
hgs
parents: 30
diff changeset
   692
    int status(VideoCollectionCommon::statusDeleteSucceed);
hgs
parents: 30
diff changeset
   693
    QVariant data;
hgs
parents: 30
diff changeset
   694
    if(failedMediaIds->count() > 0)
hgs
parents: 30
diff changeset
   695
    {     
hgs
parents: 30
diff changeset
   696
        QString nameOfFirstFailed("");
50
hgs
parents: 49
diff changeset
   697
        CMPXMedia *media = mMediaData.getRemovedMedia(failedMediaIds->first());
34
hgs
parents: 30
diff changeset
   698
        VideoCollectionUtils::instance().mediaValue<QString>(media, KMPXMediaGeneralTitle, nameOfFirstFailed );
hgs
parents: 30
diff changeset
   699
        if(failedMediaIds->count() == 1)
30
hgs
parents:
diff changeset
   700
        {
34
hgs
parents: 30
diff changeset
   701
            status = VideoCollectionCommon::statusSingleDeleteFail;
hgs
parents: 30
diff changeset
   702
            data = nameOfFirstFailed;
30
hgs
parents:
diff changeset
   703
        }
hgs
parents:
diff changeset
   704
        else
hgs
parents:
diff changeset
   705
        {
34
hgs
parents: 30
diff changeset
   706
            status = VideoCollectionCommon::statusMultipleDeleteFail;
hgs
parents: 30
diff changeset
   707
            data = failedMediaIds->count();
hgs
parents: 30
diff changeset
   708
        }  
hgs
parents: 30
diff changeset
   709
        restoreRemoved(failedMediaIds);
36
hgs
parents: 35
diff changeset
   710
    }
34
hgs
parents: 30
diff changeset
   711
    q_ptr->reportAsyncStatus(status, data);
hgs
parents: 30
diff changeset
   712
    emit q_ptr->modelChanged();
hgs
parents: 30
diff changeset
   713
}
hgs
parents: 30
diff changeset
   714
hgs
parents: 30
diff changeset
   715
// -----------------------------------------------------------------------------
hgs
parents: 30
diff changeset
   716
// albumRemoveFailureSlot
hgs
parents: 30
diff changeset
   717
// -----------------------------------------------------------------------------
hgs
parents: 30
diff changeset
   718
//
hgs
parents: 30
diff changeset
   719
void VideoListDataModelPrivate::albumRemoveFailureSlot(QList<TMPXItemId> *failedMediaIds)
hgs
parents: 30
diff changeset
   720
{
36
hgs
parents: 35
diff changeset
   721
	FUNC_LOG;
35
hgs
parents: 34
diff changeset
   722
    if(!failedMediaIds)
hgs
parents: 34
diff changeset
   723
    {
hgs
parents: 34
diff changeset
   724
        return;
hgs
parents: 34
diff changeset
   725
    }
34
hgs
parents: 30
diff changeset
   726
    int status(VideoCollectionCommon::statusRemoveSucceed);
hgs
parents: 30
diff changeset
   727
    QVariant data;
hgs
parents: 30
diff changeset
   728
    if(failedMediaIds->count() > 0)
hgs
parents: 30
diff changeset
   729
    {     
hgs
parents: 30
diff changeset
   730
        QString nameOfFirstFailed("");
50
hgs
parents: 49
diff changeset
   731
        CMPXMedia *media = mMediaData.getRemovedMedia(failedMediaIds->first());
34
hgs
parents: 30
diff changeset
   732
        VideoCollectionUtils::instance().mediaValue<QString>(media, KMPXMediaGeneralTitle, nameOfFirstFailed );
hgs
parents: 30
diff changeset
   733
        if(failedMediaIds->count() == 1)
hgs
parents: 30
diff changeset
   734
        {
hgs
parents: 30
diff changeset
   735
            status = VideoCollectionCommon::statusSingleRemoveFail;
hgs
parents: 30
diff changeset
   736
            data = nameOfFirstFailed;
hgs
parents: 30
diff changeset
   737
        }
hgs
parents: 30
diff changeset
   738
        else
hgs
parents: 30
diff changeset
   739
        {
hgs
parents: 30
diff changeset
   740
            status = VideoCollectionCommon::statusMultiRemoveFail;
hgs
parents: 30
diff changeset
   741
            data = failedMediaIds->count();
hgs
parents: 30
diff changeset
   742
        }  
hgs
parents: 30
diff changeset
   743
    }   
hgs
parents: 30
diff changeset
   744
    q_ptr->reportAsyncStatus(status, data);
30
hgs
parents:
diff changeset
   745
}
hgs
parents:
diff changeset
   746
hgs
parents:
diff changeset
   747
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   748
// VideoDetailsCompleted 
hgs
parents:
diff changeset
   749
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
   750
//
36
hgs
parents: 35
diff changeset
   751
void VideoListDataModelPrivate::videoDetailsCompletedSlot(CMPXMedia* media)
30
hgs
parents:
diff changeset
   752
{
36
hgs
parents: 35
diff changeset
   753
	FUNC_LOG;
hgs
parents: 35
diff changeset
   754
    if(!media)
hgs
parents: 35
diff changeset
   755
    {
hgs
parents: 35
diff changeset
   756
        return;
hgs
parents: 35
diff changeset
   757
    }
hgs
parents: 35
diff changeset
   758
    
hgs
parents: 35
diff changeset
   759
    using namespace VideoCollectionCommon;
hgs
parents: 35
diff changeset
   760
    QMap<QString, QVariant> map;
hgs
parents: 35
diff changeset
   761
hgs
parents: 35
diff changeset
   762
    HbExtendedLocale locale = HbExtendedLocale::system();
hgs
parents: 35
diff changeset
   763
    
hgs
parents: 35
diff changeset
   764
    // MetaKeyDate
hgs
parents: 35
diff changeset
   765
    QDateTime date = getVideoDate(media);
hgs
parents: 35
diff changeset
   766
    if(date.isValid()) {
hgs
parents: 35
diff changeset
   767
        map[MetaKeyDate] = locale.format( date.date(), r_qtn_date_usual );
hgs
parents: 35
diff changeset
   768
    }
hgs
parents: 35
diff changeset
   769
    
hgs
parents: 35
diff changeset
   770
    // MetaKeyDurationString
hgs
parents: 35
diff changeset
   771
    quint32 dur = getVideoDuration(media);
hgs
parents: 35
diff changeset
   772
    QString duration = VideoCollectionUtils::instance().prepareLengthString(dur);
hgs
parents: 35
diff changeset
   773
    if(!duration.isNull() && !duration.isEmpty()) {
hgs
parents: 35
diff changeset
   774
        map[MetaKeyDurationString] = duration;
hgs
parents: 35
diff changeset
   775
    }
hgs
parents: 35
diff changeset
   776
    
hgs
parents: 35
diff changeset
   777
    // MetaKeySizeString
hgs
parents: 35
diff changeset
   778
    quint32 s;
hgs
parents: 35
diff changeset
   779
    VideoCollectionUtils::instance().mediaValue<quint32>(media, KMPXMediaGeneralSize, s );
hgs
parents: 35
diff changeset
   780
    QString size = VideoCollectionUtils::instance().prepareSizeString(s);
hgs
parents: 35
diff changeset
   781
    if(!size.isNull() && !size.isEmpty()) {
hgs
parents: 35
diff changeset
   782
        map[MetaKeySizeString] = size; 
hgs
parents: 35
diff changeset
   783
    }
hgs
parents: 35
diff changeset
   784
    
hgs
parents: 35
diff changeset
   785
    // MetaKeyStarRating
hgs
parents: 35
diff changeset
   786
    quint8 rating = 0;
hgs
parents: 35
diff changeset
   787
    if(VideoCollectionUtils::instance().mediaValue<quint8>(media, KVcxMediaMyVideosRating, rating)) 
30
hgs
parents:
diff changeset
   788
    {
36
hgs
parents: 35
diff changeset
   789
        map[MetaKeyStarRating] = rating;
hgs
parents: 35
diff changeset
   790
    }
hgs
parents: 35
diff changeset
   791
    
hgs
parents: 35
diff changeset
   792
    // MetaKeyDRMInfo
hgs
parents: 35
diff changeset
   793
    
hgs
parents: 35
diff changeset
   794
    // MetaKeyServiceURL
hgs
parents: 35
diff changeset
   795
    
hgs
parents: 35
diff changeset
   796
    // MetaKeyDescription
hgs
parents: 35
diff changeset
   797
    QString desc;
hgs
parents: 35
diff changeset
   798
    if(VideoCollectionUtils::instance().mediaValue<QString>(media, KMPXMediaGeneralComment, desc)) {
hgs
parents: 35
diff changeset
   799
        map[MetaKeyDescription] = desc;
hgs
parents: 35
diff changeset
   800
    }
hgs
parents: 35
diff changeset
   801
    
hgs
parents: 35
diff changeset
   802
    // MetaKeyModifiedDate
hgs
parents: 35
diff changeset
   803
    quint64 dateTimeValue;
hgs
parents: 35
diff changeset
   804
    if(VideoCollectionUtils::instance().mediaValue<quint64>(media, KVcxMediaMyVideosModifiedDate, dateTimeValue)) {
hgs
parents: 35
diff changeset
   805
        TDateTime temp = TTime( dateTimeValue ).DateTime();
37
hgs
parents: 36
diff changeset
   806
        QDateTime date = QDateTime(QDate(temp.Year(), temp.Month()+1, temp.Day()+1), 
36
hgs
parents: 35
diff changeset
   807
                           QTime(temp.Hour(), temp.Minute(), temp.Second(), temp.MicroSecond()));
hgs
parents: 35
diff changeset
   808
        map[MetaKeyModifiedDate] = locale.format( date.date(), r_qtn_date_usual );
hgs
parents: 35
diff changeset
   809
    }
hgs
parents: 35
diff changeset
   810
hgs
parents: 35
diff changeset
   811
    // MetaKeyShotLocation
hgs
parents: 35
diff changeset
   812
    
hgs
parents: 35
diff changeset
   813
    // MetaKeyAuthor
hgs
parents: 35
diff changeset
   814
    QString author;
hgs
parents: 35
diff changeset
   815
    if(VideoCollectionUtils::instance().mediaValue<QString>(media, KVcxMediaMyVideosAuthor, author)) {
hgs
parents: 35
diff changeset
   816
        map[MetaKeyAuthor] = author;
hgs
parents: 35
diff changeset
   817
    }
hgs
parents: 35
diff changeset
   818
    
hgs
parents: 35
diff changeset
   819
    // MetaKeyCopyright
hgs
parents: 35
diff changeset
   820
    QString copyright;
hgs
parents: 35
diff changeset
   821
    if(VideoCollectionUtils::instance().mediaValue<QString>(media, KMPXMediaGeneralCopyright, copyright)) {
hgs
parents: 35
diff changeset
   822
        map[MetaKeyCopyright] = copyright;
30
hgs
parents:
diff changeset
   823
    }
36
hgs
parents: 35
diff changeset
   824
    
hgs
parents: 35
diff changeset
   825
    // MetaKeyAudioType
hgs
parents: 35
diff changeset
   826
    
hgs
parents: 35
diff changeset
   827
    // MetaKeyLanguageString
hgs
parents: 35
diff changeset
   828
    QString language;
hgs
parents: 35
diff changeset
   829
    if(VideoCollectionUtils::instance().mediaValue<QString>(media, KVcxMediaMyVideosAudioLanguage, language)) {
hgs
parents: 35
diff changeset
   830
        map[MetaKeyLanguageString] = language;
hgs
parents: 35
diff changeset
   831
    }
hgs
parents: 35
diff changeset
   832
    
hgs
parents: 35
diff changeset
   833
    // MetaKeyKeywords
hgs
parents: 35
diff changeset
   834
    
hgs
parents: 35
diff changeset
   835
    // MetaKeyVideoResolutionString
hgs
parents: 35
diff changeset
   836
    quint16 width;
hgs
parents: 35
diff changeset
   837
    quint16 heigth;
hgs
parents: 35
diff changeset
   838
    if(VideoCollectionUtils::instance().mediaValue<quint16>(media, KMPXMediaVideoWidth, width) &&
hgs
parents: 35
diff changeset
   839
       VideoCollectionUtils::instance().mediaValue<quint16>(media, KMPXMediaVideoHeight, heigth)) 
hgs
parents: 35
diff changeset
   840
    {
hgs
parents: 35
diff changeset
   841
        map[MetaKeyVideoResolutionString] = hbTrId("txt_videos_list_l1l2").arg(width).arg(heigth);
hgs
parents: 35
diff changeset
   842
    }
hgs
parents: 35
diff changeset
   843
    
hgs
parents: 35
diff changeset
   844
    // MetaKeyBitRate
hgs
parents: 35
diff changeset
   845
    qint16 bitrate;
hgs
parents: 35
diff changeset
   846
    if(VideoCollectionUtils::instance().mediaValue<qint16>(media, KMPXMediaVideoBitRate, bitrate)) 
hgs
parents: 35
diff changeset
   847
    {
hgs
parents: 35
diff changeset
   848
        const char* loc = "txt_videos_list_l1_kbps";
hgs
parents: 35
diff changeset
   849
        
hgs
parents: 35
diff changeset
   850
        if(bitrate > 999)
hgs
parents: 35
diff changeset
   851
        {
hgs
parents: 35
diff changeset
   852
            loc = "txt_videos_list_l1_mbps";
hgs
parents: 35
diff changeset
   853
            bitrate = (double)bitrate / (double)1000 + 0.5;
hgs
parents: 35
diff changeset
   854
        }
hgs
parents: 35
diff changeset
   855
        
37
hgs
parents: 36
diff changeset
   856
        map[MetaKeyBitRate] = hbTrId(loc).arg(bitrate);
36
hgs
parents: 35
diff changeset
   857
    }
hgs
parents: 35
diff changeset
   858
    
hgs
parents: 35
diff changeset
   859
    // MetaKeyFormat
hgs
parents: 35
diff changeset
   860
    QString format;
hgs
parents: 35
diff changeset
   861
    if(VideoCollectionUtils::instance().mediaValue<QString>(media, KMPXMediaGeneralMimeType, format)) {
hgs
parents: 35
diff changeset
   862
        map[MetaKeyFormat] = format;
hgs
parents: 35
diff changeset
   863
    }
hgs
parents: 35
diff changeset
   864
    
50
hgs
parents: 49
diff changeset
   865
    // MetaKeyFileName and MetaKeyFilePath
hgs
parents: 49
diff changeset
   866
    QString fileName;
hgs
parents: 49
diff changeset
   867
    if(VideoCollectionUtils::instance().mediaValue<QString>(media, KMPXMediaGeneralUri, fileName)) {
hgs
parents: 49
diff changeset
   868
         
hgs
parents: 49
diff changeset
   869
        QFileInfo fInfo(fileName);
hgs
parents: 49
diff changeset
   870
        if(fInfo.isFile())
hgs
parents: 49
diff changeset
   871
        {
hgs
parents: 49
diff changeset
   872
            map[MetaKeyFileName] = fInfo.fileName();
hgs
parents: 49
diff changeset
   873
            map[MetaKeyFilePath] = fInfo.absolutePath();
hgs
parents: 49
diff changeset
   874
        }
hgs
parents: 49
diff changeset
   875
    }
hgs
parents: 49
diff changeset
   876
    
hgs
parents: 49
diff changeset
   877
    // Metakey video title
hgs
parents: 49
diff changeset
   878
    QString videoTitle;
hgs
parents: 49
diff changeset
   879
    if(VideoCollectionUtils::instance().mediaValue<QString>(media, KMPXMediaGeneralTitle, videoTitle)) {
hgs
parents: 49
diff changeset
   880
        map[MetaKeyVideoTitle] = videoTitle;
hgs
parents: 49
diff changeset
   881
    }
hgs
parents: 49
diff changeset
   882
            
hgs
parents: 49
diff changeset
   883
        
36
hgs
parents: 35
diff changeset
   884
    QVariant variant = QVariant(map);
50
hgs
parents: 49
diff changeset
   885
    emit q_ptr->fullVideoDetailsReady(variant);
30
hgs
parents:
diff changeset
   886
}
hgs
parents:
diff changeset
   887
34
hgs
parents: 30
diff changeset
   888
// -----------------------------------------------------------------------------
hgs
parents: 30
diff changeset
   889
// albumListAvailableSlot 
hgs
parents: 30
diff changeset
   890
// -----------------------------------------------------------------------------
hgs
parents: 30
diff changeset
   891
//
50
hgs
parents: 49
diff changeset
   892
void VideoListDataModelPrivate::albumListAvailableSlot(TMPXItemId &albumId,
34
hgs
parents: 30
diff changeset
   893
    CMPXMediaArray *albumItems)
hgs
parents: 30
diff changeset
   894
{
36
hgs
parents: 35
diff changeset
   895
	FUNC_LOG;
34
hgs
parents: 30
diff changeset
   896
    // currently only one album is kept in memory
35
hgs
parents: 34
diff changeset
   897
    TRAP_IGNORE(albumDataChangedL(albumId, albumItems));
34
hgs
parents: 30
diff changeset
   898
}
hgs
parents: 30
diff changeset
   899
36
hgs
parents: 35
diff changeset
   900
// -----------------------------------------------------------------------------
hgs
parents: 35
diff changeset
   901
// itemModifiedSlot 
hgs
parents: 35
diff changeset
   902
// -----------------------------------------------------------------------------
hgs
parents: 35
diff changeset
   903
//
hgs
parents: 35
diff changeset
   904
void VideoListDataModelPrivate::itemModifiedSlot(const TMPXItemId &itemId)
hgs
parents: 35
diff changeset
   905
{
hgs
parents: 35
diff changeset
   906
	FUNC_LOG;
hgs
parents: 35
diff changeset
   907
    int index = mMediaData.indexOfId(itemId);
hgs
parents: 35
diff changeset
   908
    if(index != -1)
hgs
parents: 35
diff changeset
   909
    {
hgs
parents: 35
diff changeset
   910
        QModelIndex rowIndex = q_ptr->index(index, 0);
hgs
parents: 35
diff changeset
   911
        if(rowIndex.isValid())
50
hgs
parents: 49
diff changeset
   912
        {            
hgs
parents: 49
diff changeset
   913
            emit q_ptr->dataChanged(rowIndex, rowIndex);            
hgs
parents: 49
diff changeset
   914
            emit q_ptr->modelChanged();
36
hgs
parents: 35
diff changeset
   915
        }
hgs
parents: 35
diff changeset
   916
    }
hgs
parents: 35
diff changeset
   917
}
hgs
parents: 35
diff changeset
   918
38
hgs
parents: 37
diff changeset
   919
// -----------------------------------------------------------------------------
50
hgs
parents: 49
diff changeset
   920
// videoListCompleteSlot 
38
hgs
parents: 37
diff changeset
   921
// -----------------------------------------------------------------------------
hgs
parents: 37
diff changeset
   922
//
50
hgs
parents: 49
diff changeset
   923
void VideoListDataModelPrivate::videoListCompleteSlot()
38
hgs
parents: 37
diff changeset
   924
{
hgs
parents: 37
diff changeset
   925
    emit q_ptr->modelReady();
hgs
parents: 37
diff changeset
   926
}
hgs
parents: 37
diff changeset
   927
50
hgs
parents: 49
diff changeset
   928
// -----------------------------------------------------------------------------
hgs
parents: 49
diff changeset
   929
// albumListCompleteSlot 
hgs
parents: 49
diff changeset
   930
// -----------------------------------------------------------------------------
hgs
parents: 49
diff changeset
   931
//
hgs
parents: 49
diff changeset
   932
void VideoListDataModelPrivate::albumListCompleteSlot()
hgs
parents: 49
diff changeset
   933
{
hgs
parents: 49
diff changeset
   934
    emit q_ptr->albumListReady();
hgs
parents: 49
diff changeset
   935
}
hgs
parents: 49
diff changeset
   936
30
hgs
parents:
diff changeset
   937
// End of file