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