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