videocollection/videocollectionwrapper/inc/videoproxymodelgeneric.h
changeset 62 0e1e938beb1a
equal deleted inserted replaced
59:a76e86df7ccd 62:0e1e938beb1a
       
     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: VideoProxyModelGeneric class definition
       
    15 * 
       
    16 */
       
    17 
       
    18 #ifndef VIDEOPROXYMODELGENERIC_H
       
    19 #define VIDEOPROXYMODELGENERIC_H
       
    20 
       
    21 // INCLUDES
       
    22 #include <qsortfilterproxymodel.h>
       
    23 #include <e32const.h>
       
    24 #include <mpxitemid.h>
       
    25 #include "videocollectionexport.h"
       
    26 #include "videocollectioncommon.h"
       
    27 
       
    28 // FORWARD DECLARATIONS
       
    29 class QTimer;
       
    30 class VideoListDataModel;
       
    31 class VideoCollectionClient;
       
    32 
       
    33 // CLASS DECLARATION
       
    34 class VIDEOCOLLECTION_DLL_EXPORT VideoProxyModelGeneric : public QSortFilterProxyModel 
       
    35 {
       
    36     Q_OBJECT
       
    37     
       
    38 public: 
       
    39     
       
    40     /**
       
    41      * Contructor.
       
    42      *
       
    43      * @param QObject parent object.
       
    44      */
       
    45     VideoProxyModelGeneric(QObject *parent = 0);
       
    46     
       
    47     /**
       
    48      * Destructor.
       
    49      *
       
    50      */
       
    51     virtual ~VideoProxyModelGeneric();
       
    52 
       
    53     /**
       
    54      * Initializes model. Sets the given sourceModel as source model 
       
    55      * for this proxy model.
       
    56      * 
       
    57      * @param sourceModel the source model
       
    58      * 
       
    59      * @return int 0 if initialization was ok. 
       
    60      */
       
    61     virtual int initialize(VideoListDataModel *sourceModel);
       
    62 
       
    63 public:
       
    64            
       
    65     /**
       
    66      * First call opens the collection at the defined level. Subsequent calls only change the level.
       
    67      * This starts populating the model data from the MyVideos collection plugin.
       
    68      * 
       
    69      * @param level The level where the collection is opened.
       
    70      * @return 0 if opening was successful, negative if not.
       
    71      */
       
    72     int open(VideoCollectionCommon::TCollectionLevels level);
       
    73     
       
    74     /**
       
    75      * Starts sorting. If async parameter is defined as true uses idle timer: 
       
    76      * starts timer with zero interval. When system has time to run timer sort()
       
    77      * -method is called. If async is false, then the sort() -method is called
       
    78      * immediatelly.
       
    79      * 
       
    80      * @param sortingRole The role that sorting is done by.
       
    81      * @param sortingOrder The sorting order, e.g. ascending or descending.
       
    82      * @param async Defines if the sorting is done asyncronously or not. Default
       
    83      *      is true.
       
    84      */
       
    85     void doSorting(int sortingRole, Qt::SortOrder order, bool async = true);
       
    86 
       
    87     /**
       
    88      * To get current actice sorting parameters of the model
       
    89      * 
       
    90      * @param sortingRole The role that sorting is done by.
       
    91      * @param sortingOrder The sorting order, e.g. ascending or descending.
       
    92      */
       
    93     void getSorting(int &sortingRole, Qt::SortOrder &order);
       
    94     
       
    95     /**
       
    96      * Method to delete items at provided indeces
       
    97      *
       
    98      * @param indexList list of indeces.
       
    99      * @return int 0 succeeds, -1 does not succeed.
       
   100      */
       
   101     int deleteItems(const QModelIndexList &indexList);
       
   102     
       
   103     /**
       
   104     * Opens the defined item. This is quite abstract as depending
       
   105     * on the type of the item, the behaviour or result could be
       
   106     * quite different.
       
   107     * 
       
   108     * @param item id id of the item to be opened
       
   109     * @return int 0 succeeds, <0 if opening does not succeed.
       
   110     */    
       
   111     virtual int openItem(TMPXItemId mediaId);
       
   112 
       
   113     /**
       
   114     * Return to collection level
       
   115     *
       
   116     */    
       
   117     int back();
       
   118 
       
   119     /**
       
   120      * Starts fetching full details for the defined item.
       
   121      * 
       
   122      * @param index index of the item from where to get details from
       
   123      * @return int 0 succeeds, < 0 if detail fetching startup does not succeed.
       
   124      */   
       
   125     int fetchItemDetails(const QModelIndex &index);
       
   126 
       
   127     /**
       
   128      * Method checks that model exists and asks for mpx id from
       
   129      * given object.
       
   130      * 
       
   131      * @param index index of the item in UI.
       
   132      * @return TMPXItemId mpx id if succeeds TMPXItemId::InvalidId() in case of error
       
   133      *  
       
   134      */
       
   135     const TMPXItemId& getMediaIdAtIndex(const QModelIndex &index) const;
       
   136   
       
   137     /**
       
   138      * returns qmodelindex of item id provided.
       
   139      * 
       
   140      * @param item id
       
   141      * @return QModelIndex;
       
   142      */
       
   143     QModelIndex indexOfId(const TMPXItemId &id);
       
   144     
       
   145     /**
       
   146      * Method checks that model exists and asks for file path from
       
   147      * given object.
       
   148      * 
       
   149      * @param mediaId id of the item.
       
   150      * @return QString file path if succeeds, empty string in case of error.
       
   151      *  
       
   152      */
       
   153     QString getMediaFilePathForId(const TMPXItemId &mediaId);
       
   154         
       
   155     /**
       
   156      * Add a new album.
       
   157      * 
       
   158      * @param title, Album title.
       
   159      * @param mediaIds, Media items to add in the album.
       
   160      * @return TMPXItemId id of created album TMPXItemId:::InvalidId() in case of failure
       
   161      */
       
   162     TMPXItemId addNewAlbum(const QString &title);
       
   163 	
       
   164     /**
       
   165      * Remove an album.
       
   166      * 
       
   167      * @param indexList, list of album indexes to be removed.
       
   168      * @return 0 if no errors.
       
   169      */
       
   170     int removeAlbums(const QModelIndexList &indexList);
       
   171 
       
   172 	/**
       
   173 	 * Add items in an existing album.
       
   174 	 * 
       
   175 	 * @param albumId, Album where to add items.
       
   176 	 * @param mediaIds, list of item ids
       
   177 	 * @return 0 if no errors.
       
   178 	 */
       
   179     int addItemsInAlbum(TMPXItemId &albumId, const QList<TMPXItemId> &mediaIds);    
       
   180     
       
   181     /**
       
   182      * Removes items from existing album.
       
   183      * 
       
   184      * @param albumId, Album where to add items.
       
   185      * @param mediaIds, list of item ids
       
   186      * @return 0 if no errors.
       
   187      */
       
   188     int removeItemsFromAlbum(TMPXItemId &albumId, const QList<TMPXItemId> &mediaIds);    
       
   189 	
       
   190     /**
       
   191      * Renames a video or user defined colletion.
       
   192      * 
       
   193      * @param itemId, id of item  to be renamed.
       
   194      * @param newTitle, New title for the item.
       
   195      * @return 0 if no errors.
       
   196      */
       
   197     int renameItem(const TMPXItemId &itemId, const QString &newTitle);
       
   198 
       
   199     /**
       
   200 	 * Resolves duplicate album names and returns the resolved name.
       
   201 	 * 'New collection' -> 'New collection (1)' -> 'New collection (2)', etc.
       
   202 	 * 
       
   203 	 * @param albumName, Name specified by the user.
       
   204 	 * @return Resolved name given to the album.
       
   205 	 */
       
   206     QString resolveAlbumName(const QString& albumName) const;
       
   207 	
       
   208     /**
       
   209      * sets item id filter used in generic proxy model
       
   210      * while filtering rows. 
       
   211      * 
       
   212      * If provided filterValue -flag is true, we filter off items that 
       
   213      * do not exist in container indicated as itemId. 
       
   214      * If false, filtering works other way around. 
       
   215      * 
       
   216      * 
       
   217      * @param filterValue item id used as filter
       
   218      * @param filterValue
       
   219      */
       
   220     virtual void setGenericIdFilter(const TMPXItemId &itemId, bool filterValue);
       
   221     
       
   222     /**
       
   223      * Set album in use and invalidates filtering.
       
   224      * 
       
   225      * @param albumId album id
       
   226      */
       
   227     virtual void setAlbumInUse(const TMPXItemId &albumId);
       
   228     
       
   229 	/**
       
   230 	 * Gets the currently opened item.
       
   231 	 * 
       
   232 	 * @param None.
       
   233 	 * @return TMPXItemId.
       
   234 	 */
       
   235     virtual TMPXItemId getOpenItem() const;
       
   236 
       
   237 signals:
       
   238 
       
   239     /**
       
   240     * Signal to be emitted if detail fetching started ok
       
   241     * 
       
   242     * @param index, index of the item
       
   243     */ 
       
   244     void shortDetailsReady(TMPXItemId itemId);
       
   245  
       
   246     /**
       
   247      * Notifies that model has been sorted.
       
   248      */
       
   249     void modelSorted();
       
   250 
       
   251 protected:
       
   252 
       
   253     /**
       
   254      * Compares items based in the role setted before sorting. From QSortFilterProxyModel.
       
   255      *  
       
   256      */
       
   257     virtual bool lessThan(const QModelIndex & left, const QModelIndex & right) const;
       
   258     
       
   259     /**
       
   260      * Filtering functionality. Called by the FW. From QSortFilterProxyModel.
       
   261      *  
       
   262      * @param source_row row to check
       
   263      * @param source_parent row's parent
       
   264      * 
       
   265      * @return bool row accepted(true) or not accepted(false)
       
   266      */
       
   267     virtual bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const;
       
   268         
       
   269     /**
       
   270      * Connects all signals emitted from or throught this object.
       
   271      * 
       
   272      * @return bool
       
   273      */
       
   274     virtual bool connectSignals();
       
   275     
       
   276     /**
       
   277      * Disconnects all signals.
       
   278      */
       
   279     virtual void disconnectSignals();
       
   280     
       
   281     /**
       
   282      * Does actual sorting and emits sortingReady.
       
   283      *  
       
   284      */
       
   285     virtual void processSorting();
       
   286     
       
   287 private slots:
       
   288 
       
   289     /**
       
   290      * Timeout slot for zero timer. Stops timer and calls processSorting.
       
   291      *  
       
   292      */
       
   293     void processSortingSlot();
       
   294     
       
   295 protected:
       
   296     
       
   297     /**
       
   298      * Pointer to the actual model.
       
   299      * Not owned.
       
   300      */
       
   301     VideoListDataModel *mModel;
       
   302     
       
   303     /**
       
   304      * Collection client.
       
   305      * Not owned. 
       
   306      */
       
   307     VideoCollectionClient *mCollectionClient;
       
   308     
       
   309     /**
       
   310      * Currently open level.
       
   311      */
       
   312     VideoCollectionCommon::TCollectionLevels mLevel;
       
   313     
       
   314     /**
       
   315      * Item id used as filter if model type is generic model.
       
   316      */
       
   317     TMPXItemId mGenericFilterId;
       
   318     
       
   319     /**
       
   320      * Flag used. 
       
   321      */
       
   322     bool mGenericFilterValue;
       
   323     
       
   324     /**
       
   325      * Timer object. Owned.
       
   326      */
       
   327     QTimer *mIdleSortTimer;
       
   328     
       
   329     /**
       
   330      * Sort role to be setted after idle timer time outs for sorting to be able to be executed.
       
   331      */
       
   332     int mWantedSortRole;
       
   333     
       
   334     /**
       
   335      * Sort order (ascending or descending).
       
   336      */
       
   337     Qt::SortOrder mWantedSortOrder;
       
   338     
       
   339     /*
       
   340      * Default sort role for the model.
       
   341      */
       
   342     int mDefaultSortRole;
       
   343 };
       
   344 
       
   345 #endif // VIDEOPROXYMODELGENERIC_H