mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbplugin/inc/mpxdbplaylist.h
changeset 0 ff3acec5bc43
child 11 13afc0e517bd
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     1 /*
       
     2 * Copyright (c) 2007 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:  This class manages the Playlist table and owns a
       
    15 *                CMPXPlaylistSongs instance for managing the PlaylistSongs and
       
    16 *                PlaylistSongInfo tables.
       
    17 *
       
    18 *                The Playlist table stores one record for each playlist.
       
    19 *
       
    20 *
       
    21 */
       
    22 
       
    23 
       
    24 #ifndef MPXDBPLAYLIST_H
       
    25 #define MPXDBPLAYLIST_H
       
    26 
       
    27 // INCLUDES
       
    28 #include "mpxdbtable.h"
       
    29 
       
    30 // CLASS FORWARDS
       
    31 class RSqlStatement;
       
    32 class CMPXDbPlaylistSongs;
       
    33 class CMPXMedia;
       
    34 class CMPXMediaArray;
       
    35 
       
    36 // CLASS DECLARATION
       
    37 
       
    38 /**
       
    39 * Responsible for managing the playlist tables
       
    40 *
       
    41 * @lib MPXDbPlugin.lib
       
    42 */
       
    43 class MMPXDbPlaylistObserver
       
    44 	{
       
    45 	public:
       
    46 		virtual TInt HandlePlaylistDurationL(TUint32 aPlaylistId) = 0;
       
    47 	};
       
    48 class CMPXDbPlaylist : public CMPXDbTable
       
    49     {
       
    50     public:
       
    51 
       
    52         /**
       
    53         * Two-phased constructor.
       
    54         * @param aDbManager database manager to use for database interactions
       
    55         * @return New CMPXDbPlaylist instance.
       
    56         */
       
    57         static CMPXDbPlaylist* NewL(CMPXDbManager& aDbManager, MMPXDbPlaylistObserver& aObserver);
       
    58 
       
    59         /**
       
    60         * Two-phased constructor.
       
    61         * @param aDbManager database manager to use for database interactions
       
    62         * @return New CMPXDbManager instance on the cleanup stack.
       
    63         */
       
    64         static CMPXDbPlaylist* NewLC(CMPXDbManager& aDbManager, MMPXDbPlaylistObserver& aObserver);
       
    65 
       
    66         /**
       
    67         * Destructor
       
    68         */
       
    69         virtual ~CMPXDbPlaylist();
       
    70 
       
    71     public:
       
    72 
       
    73         /**
       
    74         * Add a playlist to the playlist table.  If playlist already exists,
       
    75         * it is updated.
       
    76         * @param aMedia playlist media to be added to the collection
       
    77         * @return The unique id of the playlist
       
    78         */
       
    79         TUint32 AddPlaylistL(const CMPXMedia& aMedia);
       
    80 
       
    81         /**
       
    82         * Add one or multiple songs to the playlist.
       
    83         * @param aPlaylistId identifies the playlist
       
    84         * @param aMediaArray contains the song information to be added
       
    85         */
       
    86         void AddSongsL(TUint32 aPlaylistId, const CMPXMediaArray& aMediaArray);
       
    87 
       
    88         /**
       
    89         * Update playlist info
       
    90         * @param aMedia playlist object which contains playlist Id, file path,
       
    91         *               timestamp, etc... to be updated in the playlist table
       
    92         * @param aMessage change event message for the playlist updated
       
    93         */
       
    94         void UpdatePlaylistL(const CMPXMedia& aMedia, CMPXMessage& aMessage, TInt aDriveId);
       
    95 
       
    96         /**
       
    97         * Update a playlist song
       
    98         * @param aMedia song info
       
    99         * @param aResetFlags indicates whether the song db flags should be reset or just updated
       
   100         * @param aItemChangedMessages returns the change messages for the playlists updated
       
   101         * @return ETrue if the change is visible in the UI
       
   102         */
       
   103         TBool UpdateSongL(const CMPXMedia& aMedia, TBool aResetFlags,
       
   104             CMPXMessageArray* aItemChangedMessages = NULL);
       
   105 
       
   106         /**
       
   107         * Remove a playlist and return its URI
       
   108         * @param aPlaylistId identifies the playlist
       
   109         * @return HBufC containing the URI. Ownership is transferred.
       
   110         */
       
   111         HBufC* DeletePlaylistL(TUint32 aPlaylistId);
       
   112 
       
   113         /**
       
   114         * Remove a playlist
       
   115         * @param aPlaylistId identifies the playlist
       
   116         */
       
   117         void DeletePlaylistNoUriL(TUint32 aPlaylistId);
       
   118 
       
   119         /**
       
   120         * Delete a song from the playlist tables.
       
   121         * @param aSongId identifies the song
       
   122         * @param aItemChangedMessages returns the item changed messages
       
   123         */
       
   124         void DeleteSongL(TUint32 aSongId, CMPXMessageArray& aItemChangedMessages);
       
   125 
       
   126         /**
       
   127         * Delete a song from the playlist tables.
       
   128         * @param aPlaylistId identifies the playlist
       
   129         * @param aSongId identifies the song
       
   130         * @param aOrdinal song ordinal
       
   131         */
       
   132         void DeleteSongL(TUint32 aPlaylistId, TUint32 aSongId, TInt aOrdinal);
       
   133 
       
   134         /**
       
   135         * Remove all playlists.
       
   136         */
       
   137         void DeleteAllPlaylistsL();
       
   138 
       
   139         /**
       
   140         * Gets the total number of playlists.
       
   141         * @return number of playlists
       
   142         */
       
   143         TInt CountL();
       
   144 
       
   145         /**
       
   146         * Get information on a specified playlist
       
   147         * @param aPlaylistId identifies the playlist
       
   148         * @param aAttrs the attributes to include for the playlists found.
       
   149         * @param aMedia returns the playlist information
       
   150         */
       
   151         void GetPlaylistL(TUint32 aPlaylistId, const TArray<TMPXAttribute>& aAttrs,
       
   152             CMPXMedia& aMedia);
       
   153 
       
   154         /**
       
   155         * Get all playlists
       
   156         * @param aAttrs the attributes to include for the playlists found.
       
   157         * @param aMediaArray returns the playlist information
       
   158         */
       
   159         void GetAllPlaylistsL(const TArray<TMPXAttribute>& aAttrs,
       
   160             CMPXMediaArray& aMediaArray);
       
   161 
       
   162         /**
       
   163         * Get the name of a playlist.
       
   164         * @param aPlaylistId identifies the playlist
       
   165         * @return name matching the specified playlist ID. Ownership is transferred.
       
   166         */
       
   167         HBufC* GetNameL(TUint32 aPlaylistId);
       
   168 
       
   169         /**
       
   170         * Get a playlist' uri
       
   171         * @param aPlaylistId identifies the playlist
       
   172         * @return URI matching the specified playlist ID. Ownership is transferred.
       
   173         */
       
   174         HBufC* GetUriL(TUint32 aPlaylistId);
       
   175 
       
   176         /**
       
   177         * Return the playlist ID for a specified URI.
       
   178         * @param aUri URI of the playlistId
       
   179         * @return playlist ID
       
   180         */
       
   181         TUint32 GetIdL(const TDesC& aUri);
       
   182 
       
   183         /**
       
   184         * Find playlist(s) which match(es) the selection criteria
       
   185         * @param aCriteria selection criteria
       
   186         * @param aAttrs the attributes to include for the playlist(s) matching the
       
   187         *        selection criteria
       
   188         * @param aMediaArray playlist(s) matching the selection criteria
       
   189         */
       
   190         void FindAllL(const CMPXMedia& aCriteria, const TArray<TMPXAttribute>& aAttrs,
       
   191             CMPXMediaArray& aMediaArray);
       
   192 
       
   193         /**
       
   194         * Find the drive Id for a playlist
       
   195         * @param aPlaylistId identifies the playlist
       
   196         * @return corresponding drive id
       
   197         */
       
   198         TInt GetDriveIdL(TUint32 aPlaylistId);
       
   199 
       
   200         /**
       
   201         * Provides access to the songs for the current playlist.
       
   202         * @return CMPXDbPlaylistSongs reference to be used to access the songs
       
   203         */
       
   204         CMPXDbPlaylistSongs& Songs();
       
   205 
       
   206         /**
       
   207         * Returns the playlist count for a given drive
       
   208         * @param aDrive drive
       
   209         * @return the count
       
   210         */
       
   211         TUint GetDrivePlaylistCountL(TInt aDrive);
       
   212 
       
   213         /**
       
   214         * Get URIs for a given number of playlists
       
   215         * @param aDrive, specifies drive number for db selection
       
   216         * @param aFromID, specifies unique ID of last record retrieved
       
   217         * @param aRecords, specifies the number of records to get
       
   218         * @param aUriArr, will contain all URIs on return
       
   219         * @param aLastID, will contain unique ID of a last record in the array
       
   220         */
       
   221         void GetPlaylistUriArrayL(TInt aDrive, TInt aFromID, TInt aRecords,
       
   222                                   CDesCArray& aUriArr, TInt& aLastID);
       
   223 
       
   224     private:
       
   225 
       
   226         /**
       
   227         * Update the media with information found in the Playlist table
       
   228         * @param aRecord playlist table
       
   229         * @param aAttrs the attributes to include for the playlist matching the
       
   230         *        selection criteria
       
   231         * @param aMedia returns playlist details
       
   232         */
       
   233         void UpdateMediaL(RSqlStatement& aRecord, const TArray<TMPXAttribute>& aAttrs,
       
   234             CMPXMedia& aMedia);
       
   235 
       
   236         /**
       
   237         * Create playlist table view and have the current row point to aPlaylistId
       
   238         * @param aPlaylistId ID of the playlist to match
       
   239         * @return RSqlStatement with row pointing to selected aPlaylistId
       
   240         * Function leaves with KErrNotFound if RSqlStatement is unable to initialize
       
   241         * or row cannot be found
       
   242         */
       
   243         RSqlStatement GetPlaylistRecordL(TUint32 aPlaylistId);
       
   244 
       
   245         /**
       
   246         * Add a new playlist
       
   247         * @param aMedia contains the playlist info
       
   248         * @param aDriveId drive to add the playlist to
       
   249         * @return ID of the new playlist
       
   250         */
       
   251         TUint32 DoAddPlaylistL(const CMPXMedia& aMedia, TInt aDriveId);
       
   252 
       
   253         /**
       
   254         * Update a playlist
       
   255         * @param aPlaylistId identifies the playlist
       
   256         * @param aMedia contains the playlist info
       
   257         * @param aDriveId drive to add the playlist to
       
   258         * @param aMessage change event message for the playlist updated
       
   259         */
       
   260         void DoUpdatePlaylistL(TUint32 aPlaylistId, const CMPXMedia& aMedia, TInt aDriveId,
       
   261             CMPXMessage& aMessage);
       
   262 
       
   263         /**
       
   264         * Sets the Time field for all playlists that contain the specified song to the
       
   265         * current time
       
   266         * @param aSongId identifies the song
       
   267         * @param aItemChangedMessages if not NULL item changed messages are added for all
       
   268         *           updated playlists
       
   269         * @param aSongInPlaylists out parameter that flags if the song is part of a playlist or not
       
   270         */
       
   271         void UpdatePlaylistsForSongL(TUint32 aSongId, CMPXMessageArray* aItemChangedMessages,TBool &aSongInPlaylists);
       
   272 
       
   273         /**
       
   274         * Sets the Time field for a playlist to the current time.
       
   275         * @param aPlaylistId identifies the playlist
       
   276         * @param aDrive playlist drive
       
   277         */
       
   278         void UpdatePlaylistTimeL(TUint32 aPlaylistId, TInt aDrive);
       
   279 
       
   280         TInt GetDrivePlaylistDuration(TUint32 aPlaylistId);
       
   281     private:    // from MMPXTable
       
   282 
       
   283         /**
       
   284         * @see MMPXTable
       
   285         */
       
   286         virtual void CreateTableL(RSqlDatabase& aDatabase, TBool aCorruptTable);
       
   287 
       
   288         /**
       
   289         * @see MMPXTable
       
   290         */
       
   291         virtual void DropTableL(RSqlDatabase& aDatabase);
       
   292 
       
   293         /**
       
   294         * @see MMPXTable
       
   295         */
       
   296         virtual TBool CheckTableL(RSqlDatabase& aDatabase);
       
   297 
       
   298      private:
       
   299 
       
   300         /**
       
   301         * C++ constructor
       
   302         * @param aDbManager database manager to use for database interactions
       
   303         */
       
   304         CMPXDbPlaylist(CMPXDbManager& aDbManager, MMPXDbPlaylistObserver& aObserver);
       
   305 
       
   306         /**
       
   307         * Second phase constructor
       
   308         */
       
   309         void ConstructL();
       
   310 
       
   311     private:
       
   312 
       
   313         /**
       
   314         * Column indexes in the playlist table
       
   315         */
       
   316         enum TPlaylistColumns
       
   317             {
       
   318             EPlaylistUniqueId = KMPXTableDefaultIndex,
       
   319             EPlaylistVolumeId,
       
   320             EPlaylistDbFlag,
       
   321             EPlaylistSync,
       
   322             EPlaylistName,
       
   323             EPlaylistUri,
       
   324             EPlaylistTime
       
   325             };
       
   326 
       
   327     private:    // Data
       
   328 
       
   329         CMPXDbPlaylistSongs* iPlaylistSongs;
       
   330 		MMPXDbPlaylistObserver& iObserver;
       
   331     };
       
   332 
       
   333 #endif // MPXDBPLAYLIST_H
       
   334 
       
   335 // End of File