videocollection/videocollectionwrapper/inc/videolistdatamodel.h
author hgs
Fri, 14 May 2010 15:14:51 +0300
changeset 38 ff53afa8ad05
parent 37 4eb2df7f7cbe
child 50 21fe8338c6bf
permissions -rw-r--r--
201019
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34
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: VideoListDataModel class definition*
hgs
parents:
diff changeset
    15
*/
hgs
parents:
diff changeset
    16
hgs
parents:
diff changeset
    17
#ifndef __VIDEOLISTDATAMODEL_H__
hgs
parents:
diff changeset
    18
#define __VIDEOLISTDATAMODEL_H__
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
hgs
parents:
diff changeset
    21
// INCLUDES
hgs
parents:
diff changeset
    22
#include <QObject>
hgs
parents:
diff changeset
    23
#include <qabstractitemmodel.h>
hgs
parents:
diff changeset
    24
#include <e32const.h>
hgs
parents:
diff changeset
    25
#include <mpxitemid.h>
hgs
parents:
diff changeset
    26
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
// FORWARD DECLARATIONS
hgs
parents:
diff changeset
    29
class VideoListDataModelPrivate;
hgs
parents:
diff changeset
    30
class VideoThumbnailData;
hgs
parents:
diff changeset
    31
class VideoCollectionClient;
hgs
parents:
diff changeset
    32
class VideoDeleteWorker;
hgs
parents:
diff changeset
    33
hgs
parents:
diff changeset
    34
hgs
parents:
diff changeset
    35
class VideoListDataModel : public QAbstractItemModel
hgs
parents:
diff changeset
    36
{    
hgs
parents:
diff changeset
    37
    /**
hgs
parents:
diff changeset
    38
     * define to be able to use signals and slots
hgs
parents:
diff changeset
    39
     */
hgs
parents:
diff changeset
    40
    Q_OBJECT
hgs
parents:
diff changeset
    41
    
hgs
parents:
diff changeset
    42
    /**
hgs
parents:
diff changeset
    43
     * disable copy-constructor and assignment operator
hgs
parents:
diff changeset
    44
     */
hgs
parents:
diff changeset
    45
	Q_DISABLE_COPY(VideoListDataModel) 
hgs
parents:
diff changeset
    46
    
hgs
parents:
diff changeset
    47
    /**
hgs
parents:
diff changeset
    48
     * private class declaration macro
hgs
parents:
diff changeset
    49
     */    
hgs
parents:
diff changeset
    50
    Q_DECLARE_PRIVATE_D( d_ptr, VideoListDataModel )
hgs
parents:
diff changeset
    51
hgs
parents:
diff changeset
    52
public: 
hgs
parents:
diff changeset
    53
hgs
parents:
diff changeset
    54
	/**
hgs
parents:
diff changeset
    55
	 * Default constructor
hgs
parents:
diff changeset
    56
     */
hgs
parents:
diff changeset
    57
	VideoListDataModel(QObject *parent = 0);	
hgs
parents:
diff changeset
    58
	
hgs
parents:
diff changeset
    59
	/**
hgs
parents:
diff changeset
    60
     * Destructor
hgs
parents:
diff changeset
    61
     */
hgs
parents:
diff changeset
    62
	~VideoListDataModel();	
hgs
parents:
diff changeset
    63
hgs
parents:
diff changeset
    64
	/**
hgs
parents:
diff changeset
    65
     * Initializes model. Sets model cache proxy and cache's plugin to 
hgs
parents:
diff changeset
    66
     * to be this object. Creates videolist and puts it to observe 
hgs
parents:
diff changeset
    67
     * collection client. Calls  connectSignals to connect signals into
hgs
parents:
diff changeset
    68
     * appropriate slots
hgs
parents:
diff changeset
    69
     * 
hgs
parents:
diff changeset
    70
     * 
hgs
parents:
diff changeset
    71
     * @return int: 0 if everything ok
hgs
parents:
diff changeset
    72
     */
hgs
parents:
diff changeset
    73
	int initialize( );
hgs
parents:
diff changeset
    74
	
hgs
parents:
diff changeset
    75
	/**
hgs
parents:
diff changeset
    76
	 * returns collectionclient object
hgs
parents:
diff changeset
    77
	 * 
hgs
parents:
diff changeset
    78
	 * @return VideoCollectionClient*
hgs
parents:
diff changeset
    79
	 */
hgs
parents:
diff changeset
    80
	VideoCollectionClient* getCollectionClient();
hgs
parents:
diff changeset
    81
	
hgs
parents:
diff changeset
    82
	/**
hgs
parents:
diff changeset
    83
     * Method calls video list data to check if there are valid media object 
hgs
parents:
diff changeset
    84
     * at the given index. If there is, item id is returned.
hgs
parents:
diff changeset
    85
     * 
hgs
parents:
diff changeset
    86
     * @param index index of the item to be opened
hgs
parents:
diff changeset
    87
     * @return TMPXItemId item id  or TMPXItemId::Invalid() if no valid item.
hgs
parents:
diff changeset
    88
     */ 
hgs
parents:
diff changeset
    89
	TMPXItemId mediaIdAtIndex(int index) const;
hgs
parents:
diff changeset
    90
hgs
parents:
diff changeset
    91
	/**
hgs
parents:
diff changeset
    92
	 * returns model index of id provided
hgs
parents:
diff changeset
    93
	 * 
hgs
parents:
diff changeset
    94
	 * @param id of the item
hgs
parents:
diff changeset
    95
	 * @return modelIndex
hgs
parents:
diff changeset
    96
	 */
hgs
parents:
diff changeset
    97
	QModelIndex indexOfId(TMPXItemId id);
hgs
parents:
diff changeset
    98
	
hgs
parents:
diff changeset
    99
    /**
hgs
parents:
diff changeset
   100
     * Method calls video list data to check if there are valid media object 
hgs
parents:
diff changeset
   101
     * for the given media id. If there is, file path for is returned.
hgs
parents:
diff changeset
   102
     * 
hgs
parents:
diff changeset
   103
     * @param mediaId id of the item to be opened
hgs
parents:
diff changeset
   104
     * @return QString file path of the media at index, empty string if not valid item.
hgs
parents:
diff changeset
   105
     */ 
hgs
parents:
diff changeset
   106
	QString mediaFilePathForId(TMPXItemId mediaId) const;
hgs
parents:
diff changeset
   107
    
hgs
parents:
diff changeset
   108
	/**
hgs
parents:
diff changeset
   109
     * Called by the client when removal of videos are requested.
hgs
parents:
diff changeset
   110
     * Sets video status to be removed to videolistdata and
hgs
parents:
diff changeset
   111
     * eventually calls collection to handle the actual removing.
hgs
parents:
diff changeset
   112
     * 
hgs
parents:
diff changeset
   113
     * @param indexlist list of indeces of items requested for deletion
hgs
parents:
diff changeset
   114
     * 
hgs
parents:
diff changeset
   115
     * @return bool true if removal startup succeeds
hgs
parents:
diff changeset
   116
     */
hgs
parents:
diff changeset
   117
    bool removeRows(const QModelIndexList &indexList);
hgs
parents:
diff changeset
   118
hgs
parents:
diff changeset
   119
    /**
hgs
parents:
diff changeset
   120
     * Checks if the specified item belongs to currently open album.
hgs
parents:
diff changeset
   121
     * 
hgs
parents:
diff changeset
   122
     * @param albumId, Album to be checked. If zero, using the currently open album.
hgs
parents:
diff changeset
   123
     * @param itemId, Item to be checked.
hgs
parents:
diff changeset
   124
     * @return true if item belongs to the album.
hgs
parents:
diff changeset
   125
     */
hgs
parents:
diff changeset
   126
    bool belongsToAlbum(const TMPXItemId &itemId, TMPXItemId albumId = TMPXItemId::InvalidId()) const;
hgs
parents:
diff changeset
   127
    
hgs
parents:
diff changeset
   128
    /**
hgs
parents:
diff changeset
   129
     * Set album in use.
hgs
parents:
diff changeset
   130
     * 
hgs
parents:
diff changeset
   131
     * @param albumId, Album to set in use.
hgs
parents:
diff changeset
   132
     * @return None.
hgs
parents:
diff changeset
   133
     */
hgs
parents:
diff changeset
   134
    void setAlbumInUse(TMPXItemId albumId);
hgs
parents:
diff changeset
   135
    
hgs
parents:
diff changeset
   136
    /**
hgs
parents:
diff changeset
   137
     * returns album id currently in use
hgs
parents:
diff changeset
   138
     * 
hgs
parents:
diff changeset
   139
     * @return TMPXItemId
hgs
parents:
diff changeset
   140
     */
hgs
parents:
diff changeset
   141
    TMPXItemId albumInUse();
hgs
parents:
diff changeset
   142
    
35
hgs
parents: 34
diff changeset
   143
    /**
hgs
parents: 34
diff changeset
   144
     * removes provided items from provided album id and calls
hgs
parents: 34
diff changeset
   145
     * collectionclient to update mds as well.
hgs
parents: 34
diff changeset
   146
     * 
hgs
parents: 34
diff changeset
   147
     * @param albumId album from where to remove
hgs
parents: 34
diff changeset
   148
     * @param items items to remove
hgs
parents: 34
diff changeset
   149
     * 
hgs
parents: 34
diff changeset
   150
     * @return count of items removed or -1 if failed 
hgs
parents: 34
diff changeset
   151
     */
hgs
parents: 34
diff changeset
   152
    int removeItemsFromAlbum(TMPXItemId &albumId, const QList<TMPXItemId> &items);    
hgs
parents: 34
diff changeset
   153
    
34
hgs
parents:
diff changeset
   154
public: // from QAbstractItemModel
hgs
parents:
diff changeset
   155
    
hgs
parents:
diff changeset
   156
    /**
hgs
parents:
diff changeset
   157
     * Returns video item count to the proxy cache
hgs
parents:
diff changeset
   158
     * 
hgs
parents:
diff changeset
   159
     * @param parent, parent's index, not used
hgs
parents:
diff changeset
   160
     * 
hgs
parents:
diff changeset
   161
     * @return int count of items
hgs
parents:
diff changeset
   162
     */
hgs
parents:
diff changeset
   163
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
hgs
parents:
diff changeset
   164
hgs
parents:
diff changeset
   165
    /**
hgs
parents:
diff changeset
   166
     * Returns video item data from index pointed by
hgs
parents:
diff changeset
   167
     * given QModelIndex's row index:
hgs
parents:
diff changeset
   168
     * - video name
hgs
parents:
diff changeset
   169
     * - video detail row
hgs
parents:
diff changeset
   170
     * - video thumbnail 
hgs
parents:
diff changeset
   171
     * 
hgs
parents:
diff changeset
   172
     * If fetch more is setted for given index tries to append
hgs
parents:
diff changeset
   173
     * additional details into map as well. 
hgs
parents:
diff changeset
   174
     * 
hgs
parents:
diff changeset
   175
     * @param index, index of the item data is requested
hgs
parents:
diff changeset
   176
     * 
hgs
parents:
diff changeset
   177
     * @return QMap<int, QVariant> item data
hgs
parents:
diff changeset
   178
     */
hgs
parents:
diff changeset
   179
    QMap<int, QVariant> itemData(const QModelIndex &index) const;
hgs
parents:
diff changeset
   180
    
hgs
parents:
diff changeset
   181
    /**
hgs
parents:
diff changeset
   182
     * data
hgs
parents:
diff changeset
   183
     */
hgs
parents:
diff changeset
   184
    QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
hgs
parents:
diff changeset
   185
    
hgs
parents:
diff changeset
   186
    /**
hgs
parents:
diff changeset
   187
     * columnCount
hgs
parents:
diff changeset
   188
     */
hgs
parents:
diff changeset
   189
    int columnCount(const QModelIndex & parent = QModelIndex()) const;
hgs
parents:
diff changeset
   190
    
hgs
parents:
diff changeset
   191
    /**
hgs
parents:
diff changeset
   192
     * index
hgs
parents:
diff changeset
   193
     */
hgs
parents:
diff changeset
   194
    QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const;
hgs
parents:
diff changeset
   195
    
hgs
parents:
diff changeset
   196
    /**
hgs
parents:
diff changeset
   197
     * Parent
hgs
parents:
diff changeset
   198
     */
hgs
parents:
diff changeset
   199
    QModelIndex parent(const QModelIndex & index) const;
hgs
parents:
diff changeset
   200
   
hgs
parents:
diff changeset
   201
signals:
hgs
parents:
diff changeset
   202
hgs
parents:
diff changeset
   203
    /**
hgs
parents:
diff changeset
   204
    * This signal is connected to video list's details ready
36
hgs
parents: 35
diff changeset
   205
    * -signal indicating that video details data is fetched
hgs
parents: 35
diff changeset
   206
    * and provides a QMap of the details'.
34
hgs
parents:
diff changeset
   207
    */
36
hgs
parents: 35
diff changeset
   208
    void fullVideoDetailsReady(QVariant &);
34
hgs
parents:
diff changeset
   209
    
hgs
parents:
diff changeset
   210
    /**
hgs
parents:
diff changeset
   211
    * This signal is connected to proxy models short details ready
hgs
parents:
diff changeset
   212
    * -signal indicating that video details data fetching started ok
hgs
parents:
diff changeset
   213
    * 
hgs
parents:
diff changeset
   214
    * @param id of the video item
hgs
parents:
diff changeset
   215
    */
hgs
parents:
diff changeset
   216
    void shortDetailsReady(TMPXItemId id);
hgs
parents:
diff changeset
   217
    
hgs
parents:
diff changeset
   218
    /**
hgs
parents:
diff changeset
   219
     * Signals that the model is ready, ie. loaded all data from
hgs
parents:
diff changeset
   220
     * myvideocollection.
hgs
parents:
diff changeset
   221
     */
hgs
parents:
diff changeset
   222
    void modelReady();
hgs
parents:
diff changeset
   223
hgs
parents:
diff changeset
   224
    /**
hgs
parents:
diff changeset
   225
     * Signal to be emitted when something has happened in the 
hgs
parents:
diff changeset
   226
     * model's data container
hgs
parents:
diff changeset
   227
     */
hgs
parents:
diff changeset
   228
    void modelChanged();
hgs
parents:
diff changeset
   229
    
hgs
parents:
diff changeset
   230
    /**
hgs
parents:
diff changeset
   231
     * Signals that album content has been updated.
hgs
parents:
diff changeset
   232
     */
hgs
parents:
diff changeset
   233
    void albumChanged();
36
hgs
parents: 35
diff changeset
   234
hgs
parents: 35
diff changeset
   235
    /**
hgs
parents: 35
diff changeset
   236
     * Signals that item data has changed.
hgs
parents: 35
diff changeset
   237
     */
hgs
parents: 35
diff changeset
   238
    void itemModified(const TMPXItemId &itemId);
34
hgs
parents:
diff changeset
   239
    
hgs
parents:
diff changeset
   240
private slots:
hgs
parents:
diff changeset
   241
    
hgs
parents:
diff changeset
   242
    /**
hgs
parents:
diff changeset
   243
     * signaled by the deleteworker in case some delete startup fails
hgs
parents:
diff changeset
   244
     * 
hgs
parents:
diff changeset
   245
     * @param ids list of ids whose deletion fails 
hgs
parents:
diff changeset
   246
     */
hgs
parents:
diff changeset
   247
    void deleteStartingFailsSlot(QList<TMPXItemId> ids);
hgs
parents:
diff changeset
   248
    
hgs
parents:
diff changeset
   249
private:
hgs
parents:
diff changeset
   250
      
hgs
parents:
diff changeset
   251
    /**
hgs
parents:
diff changeset
   252
     * Method connects signals emitted from or throught this object
hgs
parents:
diff changeset
   253
     */
hgs
parents:
diff changeset
   254
    int connectSignals();
hgs
parents:
diff changeset
   255
    
hgs
parents:
diff changeset
   256
    /**
hgs
parents:
diff changeset
   257
     * method disconnects signals
hgs
parents:
diff changeset
   258
     */
hgs
parents:
diff changeset
   259
    void disconnectSignals();
hgs
parents:
diff changeset
   260
    
hgs
parents:
diff changeset
   261
    /**
hgs
parents:
diff changeset
   262
     * Generates a detail row string for the video item
hgs
parents:
diff changeset
   263
     * at the given index. 
hgs
parents:
diff changeset
   264
     * 
hgs
parents:
diff changeset
   265
     * In case item is not found in the provided index, empty
hgs
parents:
diff changeset
   266
     * string is returned.
hgs
parents:
diff changeset
   267
     * 
hgs
parents:
diff changeset
   268
     * @param index, index of the item data is requested
hgs
parents:
diff changeset
   269
     * 
hgs
parents:
diff changeset
   270
     * @return QString detail string
hgs
parents:
diff changeset
   271
     */
35
hgs
parents: 34
diff changeset
   272
    QString prepareDetailRow(int index) const; 
hgs
parents: 34
diff changeset
   273
36
hgs
parents: 35
diff changeset
   274
      /**
hgs
parents: 35
diff changeset
   275
     * Formats a detail row string for the video item
hgs
parents: 35
diff changeset
   276
     * at the given index. 
hgs
parents: 35
diff changeset
   277
     * 
hgs
parents: 35
diff changeset
   278
     * In case item is not found in the provided index, empty
hgs
parents: 35
diff changeset
   279
     * string is returned.
hgs
parents: 35
diff changeset
   280
     * 
hgs
parents: 35
diff changeset
   281
     * @param index, index of the item data is requested
hgs
parents: 35
diff changeset
   282
     * @param duration, duration of the video
hgs
parents: 35
diff changeset
   283
     *
hgs
parents: 35
diff changeset
   284
     * @return QString detail string
hgs
parents: 35
diff changeset
   285
     */
37
hgs
parents: 36
diff changeset
   286
    QString doDetailRow(int index) const;
36
hgs
parents: 35
diff changeset
   287
35
hgs
parents: 34
diff changeset
   288
    /**
hgs
parents: 34
diff changeset
   289
     * Generates a video count string for category or album at given index.
hgs
parents: 34
diff changeset
   290
     * 
hgs
parents: 34
diff changeset
   291
     * In case item is not found in the provided index, empty
hgs
parents: 34
diff changeset
   292
     * string is returned.
hgs
parents: 34
diff changeset
   293
     * 
hgs
parents: 34
diff changeset
   294
     * @param index, index of the item data is requested
hgs
parents: 34
diff changeset
   295
     * @param index, item id of the item data is requested  
hgs
parents: 34
diff changeset
   296
     * 
hgs
parents: 34
diff changeset
   297
     * @return QString video count string
hgs
parents: 34
diff changeset
   298
     */
hgs
parents: 34
diff changeset
   299
    QString prepareVideoCountString(int index) const;
34
hgs
parents:
diff changeset
   300
    
hgs
parents:
diff changeset
   301
    /**
hgs
parents:
diff changeset
   302
     * Generates a video size string from video item at given index
hgs
parents:
diff changeset
   303
     * 
hgs
parents:
diff changeset
   304
     * In case item is not found in the provided index, empty
hgs
parents:
diff changeset
   305
     * string is returned.
hgs
parents:
diff changeset
   306
     * 
hgs
parents:
diff changeset
   307
     * @param index, index of the item data is requested
hgs
parents:
diff changeset
   308
     * 
hgs
parents:
diff changeset
   309
     * @return QString size string
hgs
parents:
diff changeset
   310
     */
35
hgs
parents: 34
diff changeset
   311
    QString prepareSizeString(int index) const;
34
hgs
parents:
diff changeset
   312
    
hgs
parents:
diff changeset
   313
    /**
hgs
parents:
diff changeset
   314
     * Called when there are status changes in some async operation
hgs
parents:
diff changeset
   315
     * 
hgs
parents:
diff changeset
   316
     * @param statusCode status of operation
hgs
parents:
diff changeset
   317
     * @data data from operation
hgs
parents:
diff changeset
   318
     */
hgs
parents:
diff changeset
   319
    void reportAsyncStatus(int statusCode, QVariant &additional);
hgs
parents:
diff changeset
   320
hgs
parents:
diff changeset
   321
private:
hgs
parents:
diff changeset
   322
    
hgs
parents:
diff changeset
   323
    /**
hgs
parents:
diff changeset
   324
     * Private implementation Contains the actual video data and
hgs
parents:
diff changeset
   325
     * video array. Own.
hgs
parents:
diff changeset
   326
     */
hgs
parents:
diff changeset
   327
    VideoListDataModelPrivate* const d_ptr;
hgs
parents:
diff changeset
   328
        
hgs
parents:
diff changeset
   329
    /**
hgs
parents:
diff changeset
   330
     * Pointer to collection client. Used to send commands to collection.
hgs
parents:
diff changeset
   331
     * Owned.
hgs
parents:
diff changeset
   332
     */
hgs
parents:
diff changeset
   333
    VideoCollectionClient *mCollectionClient;
hgs
parents:
diff changeset
   334
    
hgs
parents:
diff changeset
   335
    /**
hgs
parents:
diff changeset
   336
     * object for handling item deletion conveniently in small blocks.
hgs
parents:
diff changeset
   337
     * Own
hgs
parents:
diff changeset
   338
     */
hgs
parents:
diff changeset
   339
    VideoDeleteWorker *mDeleteWorker;
hgs
parents:
diff changeset
   340
            
hgs
parents:
diff changeset
   341
    /**
hgs
parents:
diff changeset
   342
     * initialized flag
hgs
parents:
diff changeset
   343
     */
hgs
parents:
diff changeset
   344
    bool mInitialized;
hgs
parents:
diff changeset
   345
   
hgs
parents:
diff changeset
   346
};
hgs
parents:
diff changeset
   347
#endif  // __VIDEOLISTDATAMODEL_H__
hgs
parents:
diff changeset
   348
hgs
parents:
diff changeset
   349
// End of file
hgs
parents:
diff changeset
   350