videocollection/videocollectionwrapper/inc/videodatacontainer.h
author hgs
Fri, 14 May 2010 15:14:51 +0300
changeset 38 ff53afa8ad05
parent 34 bbb98528c666
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: videodatacontainer class definition*
hgs
parents:
diff changeset
    15
*/
hgs
parents:
diff changeset
    16
hgs
parents:
diff changeset
    17
#ifndef __VIDEODATACONTAINER_H__
hgs
parents:
diff changeset
    18
#define __VIDEODATACONTAINER_H__
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
// INCLUDES
hgs
parents:
diff changeset
    21
#include <qhash.h>
hgs
parents:
diff changeset
    22
#include <qlist.h>
hgs
parents:
diff changeset
    23
#include <qpair.h>
hgs
parents:
diff changeset
    24
#include <mpxitemid.h>
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
// FORWARD DECLARATIONS
hgs
parents:
diff changeset
    27
class CMPXMedia;
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
class VideoDataContainer
hgs
parents:
diff changeset
    30
{
hgs
parents:
diff changeset
    31
public:
hgs
parents:
diff changeset
    32
    
hgs
parents:
diff changeset
    33
    /**
hgs
parents:
diff changeset
    34
     * contructor
hgs
parents:
diff changeset
    35
     */
hgs
parents:
diff changeset
    36
    VideoDataContainer();
hgs
parents:
diff changeset
    37
    
hgs
parents:
diff changeset
    38
    /**
hgs
parents:
diff changeset
    39
     * destructor
hgs
parents:
diff changeset
    40
     */
hgs
parents:
diff changeset
    41
    virtual ~VideoDataContainer();
hgs
parents:
diff changeset
    42
    
hgs
parents:
diff changeset
    43
public:  // from QHash
hgs
parents:
diff changeset
    44
    
hgs
parents:
diff changeset
    45
    /**
hgs
parents:
diff changeset
    46
     * Deallocates all CMPXMedia objects and clear containers
hgs
parents:
diff changeset
    47
     */
hgs
parents:
diff changeset
    48
    void clear();
hgs
parents:
diff changeset
    49
hgs
parents:
diff changeset
    50
    /**
hgs
parents:
diff changeset
    51
     * Deallocates and removes item of provided id.
hgs
parents:
diff changeset
    52
     * 
hgs
parents:
diff changeset
    53
     * @param id media item id
hgs
parents:
diff changeset
    54
     */
hgs
parents:
diff changeset
    55
    void remove(const TMPXItemId &id);
hgs
parents:
diff changeset
    56
     
hgs
parents:
diff changeset
    57
    /**
hgs
parents:
diff changeset
    58
     * Appends provided media object to container.
hgs
parents:
diff changeset
    59
     * If item with same id exists allready, old item is being
hgs
parents:
diff changeset
    60
     * removed and replaced by the new item
hgs
parents:
diff changeset
    61
     * 
hgs
parents:
diff changeset
    62
     * @param media - media object to append
hgs
parents:
diff changeset
    63
     */
hgs
parents:
diff changeset
    64
    void append(CMPXMedia *media);
hgs
parents:
diff changeset
    65
hgs
parents:
diff changeset
    66
    /**
hgs
parents:
diff changeset
    67
     * Returns a media object from provided index
hgs
parents:
diff changeset
    68
     * 
hgs
parents:
diff changeset
    69
     * @param index position of wanted object
hgs
parents:
diff changeset
    70
     * 
hgs
parents:
diff changeset
    71
     * @return CMPXMedia pointer to media object or null if 
hgs
parents:
diff changeset
    72
     *                   object is not found from wanted index
hgs
parents:
diff changeset
    73
     * 
hgs
parents:
diff changeset
    74
     */
hgs
parents:
diff changeset
    75
    CMPXMedia* fromIndex(int index) const;
hgs
parents:
diff changeset
    76
  
hgs
parents:
diff changeset
    77
    /**
hgs
parents:
diff changeset
    78
     * Returns an index of id.
hgs
parents:
diff changeset
    79
     * 
hgs
parents:
diff changeset
    80
     * @param id item id
hgs
parents:
diff changeset
    81
     * 
hgs
parents:
diff changeset
    82
     * @return int index of item or -1 if item with provided id is not found
hgs
parents:
diff changeset
    83
     */
hgs
parents:
diff changeset
    84
    int indexOfId(const TMPXItemId &id) const;
hgs
parents:
diff changeset
    85
hgs
parents:
diff changeset
    86
    /**
hgs
parents:
diff changeset
    87
     * Returns id of item from provided index
hgs
parents:
diff changeset
    88
     * 
hgs
parents:
diff changeset
    89
     * @param index potisiotn where to look for item
hgs
parents:
diff changeset
    90
     * 
hgs
parents:
diff changeset
    91
     * @return id of item or invalid TMPXItemId if item is not found from provided index
hgs
parents:
diff changeset
    92
     */
hgs
parents:
diff changeset
    93
    TMPXItemId idFromIndex(int index) const;
hgs
parents:
diff changeset
    94
hgs
parents:
diff changeset
    95
    /**
hgs
parents:
diff changeset
    96
     * returns count of items
hgs
parents:
diff changeset
    97
     * 
hgs
parents:
diff changeset
    98
     * @return int 
hgs
parents:
diff changeset
    99
     */
hgs
parents:
diff changeset
   100
    int count() const;
hgs
parents:
diff changeset
   101
    
hgs
parents:
diff changeset
   102
    /**
hgs
parents:
diff changeset
   103
     * Method removes item from data container at provided index and 
hgs
parents:
diff changeset
   104
     * appends it into removed buffer.
hgs
parents:
diff changeset
   105
     * 
hgs
parents:
diff changeset
   106
     * Note that calling this method decreases item count and causes
hgs
parents:
diff changeset
   107
     * indexes after provided index to be resynch. This causes callers
hgs
parents:
diff changeset
   108
     * index list to be out of sync if not called starting from the 
hgs
parents:
diff changeset
   109
     * biggest index
hgs
parents:
diff changeset
   110
     * 
hgs
parents:
diff changeset
   111
     * @param inteIndex index of item
hgs
parents:
diff changeset
   112
     * @return TMPXItemId id of the item marked as removed
hgs
parents:
diff changeset
   113
     */
hgs
parents:
diff changeset
   114
    TMPXItemId markItemRemoved(const int &itemIndex);
hgs
parents:
diff changeset
   115
    
hgs
parents:
diff changeset
   116
    /**
hgs
parents:
diff changeset
   117
     * Method removes provided items from mRemovedMedia
hgs
parents:
diff changeset
   118
     * 
hgs
parents:
diff changeset
   119
     * @param itemIds ids of items to be removed. If null, removes all
hgs
parents:
diff changeset
   120
     * @return int count of items actually removed
hgs
parents:
diff changeset
   121
     */
hgs
parents:
diff changeset
   122
    int clearRemoved(QList<TMPXItemId> *itemIds = 0);
hgs
parents:
diff changeset
   123
    
hgs
parents:
diff changeset
   124
    /**
hgs
parents:
diff changeset
   125
     * Method removed provided items from mRemovedMedia and returns them
hgs
parents:
diff changeset
   126
     * int actual container
hgs
parents:
diff changeset
   127
     * 
hgs
parents:
diff changeset
   128
     * @param itemIds ids of items to be restored. If null, restores all
hgs
parents:
diff changeset
   129
     * 
hgs
parents:
diff changeset
   130
     * @return int count of items actually restored
hgs
parents:
diff changeset
   131
     */
hgs
parents:
diff changeset
   132
    int restoreRemovedItems(QList<TMPXItemId> *itemIds = 0);
hgs
parents:
diff changeset
   133
    
hgs
parents:
diff changeset
   134
    /**
hgs
parents:
diff changeset
   135
     * Returns item from removed buffer
hgs
parents:
diff changeset
   136
     * 
hgs
parents:
diff changeset
   137
     * @param itemId id of item to be returned
hgs
parents:
diff changeset
   138
     */
hgs
parents:
diff changeset
   139
    CMPXMedia* getRemovedMedia(TMPXItemId itemId);
hgs
parents:
diff changeset
   140
hgs
parents:
diff changeset
   141
private:
hgs
parents:
diff changeset
   142
    
hgs
parents:
diff changeset
   143
    /**
hgs
parents:
diff changeset
   144
     * Decrements indexes of items in mMediaData by one after
hgs
parents:
diff changeset
   145
     * provided items. 
hgs
parents:
diff changeset
   146
     * Item iterator is first found based on item id gotten from id list
hgs
parents:
diff changeset
   147
     * and items' indexes after that are to be decreased.
hgs
parents:
diff changeset
   148
     * 
hgs
parents:
diff changeset
   149
     * @param fromindex - index from where to start decreasing  
hgs
parents:
diff changeset
   150
     */
hgs
parents:
diff changeset
   151
    void decIndexesAfter(int fromIndex);
hgs
parents:
diff changeset
   152
    
hgs
parents:
diff changeset
   153
private: // data
hgs
parents:
diff changeset
   154
    
hgs
parents:
diff changeset
   155
    /**
hgs
parents:
diff changeset
   156
     * list of media ids used to fetch item thought index.
hgs
parents:
diff changeset
   157
     */
hgs
parents:
diff changeset
   158
    QList<TMPXItemId> mMediaIds;
hgs
parents:
diff changeset
   159
    
hgs
parents:
diff changeset
   160
    /**
hgs
parents:
diff changeset
   161
     * lookup hash for fetching correct item based on id
hgs
parents:
diff changeset
   162
     * Key: item id
hgs
parents:
diff changeset
   163
     * value: pair, where first is item index and second is item data
hgs
parents:
diff changeset
   164
     */
hgs
parents:
diff changeset
   165
    QHash<TMPXItemId, QPair<int, CMPXMedia*> > mMediaData;
hgs
parents:
diff changeset
   166
    
hgs
parents:
diff changeset
   167
    /**
hgs
parents:
diff changeset
   168
     * lookup hash for media items that are deleted, but not yet completely
hgs
parents:
diff changeset
   169
     * removed from the filesystem.
hgs
parents:
diff changeset
   170
     */
hgs
parents:
diff changeset
   171
    QHash<TMPXItemId, CMPXMedia*> mRemovedMedia;
hgs
parents:
diff changeset
   172
hgs
parents:
diff changeset
   173
};
hgs
parents:
diff changeset
   174
hgs
parents:
diff changeset
   175
#endif  // __VIDEODATACONTAINER_H__
hgs
parents:
diff changeset
   176
hgs
parents:
diff changeset
   177
hgs
parents:
diff changeset
   178
    
hgs
parents:
diff changeset
   179
hgs
parents:
diff changeset
   180