mpxplugins/serviceplugins/collectionplugins/mpxsqlitepodcastdbplugin/inc/mpxdbpodcast.h
changeset 0 ff3acec5bc43
child 15 a1247965635c
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     1 /*
       
     2 * Copyright (c) 2006 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 provides the functions to manipulate the Podcast table
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef MPXDBPODCAST_H
       
    20 #define MPXDBPODCAST_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <f32file.h>
       
    25 #include <e32property.h>
       
    26 #include <badesca.h>
       
    27 #include <mpxmediageneraldefs.h>
       
    28 #include <mpxpodcastdefs.h>
       
    29 #include <mpxmessage2.h>
       
    30 
       
    31 #include "mpxdbtable.h"
       
    32 
       
    33 #include "mpxpodcastcollectiondbstd.h"
       
    34 #include "mpxdbactivetask.h"
       
    35 #include "mpxdbcommonstd.h"
       
    36 
       
    37 // CONSTANTS
       
    38 const TInt KMaxSystemPlaylistQuery = 20;
       
    39 
       
    40 // FORWARD DECLARATIONS
       
    41 class CMPXTableView;
       
    42 class CMCGenreParser;
       
    43 class CMPXCollectionPath;
       
    44 
       
    45 // CLASS DECLARATION
       
    46 
       
    47 /**
       
    48 * Observer interface for handling the category ID functionality.
       
    49 * This is needed because the incoming CMPXMedia parameters in Add and Update methods
       
    50 * contain the names for the category items and the Podcast table has to use IDs linking
       
    51 * to the category tables. Using this interface removes the dependency to the category
       
    52 * class.
       
    53 *
       
    54 * Note that this interface is only used when information is written to the Podcast table,
       
    55 * when information is retrieved the query takes care of also retrieving the names from
       
    56 * the corresponding category tables so the outgoing CMPXMedia will contain the correct
       
    57 * information.
       
    58 */
       
    59 class MMPXDbPodcastObserver
       
    60     {
       
    61     public:
       
    62         /**
       
    63         * Called when a new category item has to be added to a category table.
       
    64         * @param aCategory category type
       
    65         * @param aName name string
       
    66         * @param aDriveId drive to add the category item to
       
    67         * @param aItemChangedMessages NULL or valid changed mesages array to be updated
       
    68         * @return the ID of the category item (new or existing)
       
    69         */
       
    70         virtual TUint32 AddCategoryItemL(TMPXGeneralCategory aCategory, const TDesC& aName,
       
    71             TInt aDriveId, CMPXMessageArray* aItemChangedMessages) = 0;
       
    72 
       
    73         /**
       
    74         * Called when the ID of a category item changed for a Music record, for example when
       
    75         * the artist name changed for a song. The implementation is supposed to update the
       
    76         * category record and add corresponding item changed messages to the array parameter.
       
    77         * @param aCategory category type
       
    78         * @param aCategoryId category item ID
       
    79         * @param aItemChangedMessages NULL or valid changed mesages array to be updated
       
    80         */
       
    81         virtual void DeleteEpisodeForCategoryL(TMPXGeneralCategory aCategory,
       
    82             TUint32 aCategoryId, TInt aDriveId,
       
    83             CMPXMessageArray* aItemChangedMessages) = 0;
       
    84     };
       
    85 
       
    86 /**
       
    87 *  Podcast table handler
       
    88 *
       
    89 *  @lib mpxpodcastdbplugin.lib
       
    90 */
       
    91 class CMPXDbPodcast :
       
    92     public CMPXDbTable
       
    93     {
       
    94     public:  // Constructors and destructor
       
    95 
       
    96         /**
       
    97         * Two-phased constructor.
       
    98         * @param aDbManager database manager to use for database interactions
       
    99         * @param aObserver Observer for podcast notifications
       
   100         * @return New CMPXDbPodcast instance
       
   101         */
       
   102         static CMPXDbPodcast* NewL(CMPXDbManager& aDbManager, CMPXResource& aResource,
       
   103             MMPXDbPodcastObserver& aObserver);
       
   104 
       
   105         /**
       
   106         * Two-phased constructor.
       
   107         * @param aDbManager database manager to use for database interactions
       
   108         * @param aObserver Observer for podcast notifications
       
   109         * @return New CMPXDbPodcast instance
       
   110         */
       
   111         static CMPXDbPodcast* NewLC(CMPXDbManager& aDbManager, CMPXResource& aResource,
       
   112             MMPXDbPodcastObserver& aObserver);
       
   113 
       
   114         /**
       
   115         * Destructor.
       
   116         */
       
   117         virtual ~CMPXDbPodcast();
       
   118 
       
   119     public: // New functions
       
   120 
       
   121         /**
       
   122         * Add a episode to the podcast table
       
   123         * @param aMedia  media object which contains file path,
       
   124         *                artist, composer, name(title), track, etc...
       
   125         * @param aDrive  drive to add the episode to
       
   126         * @return The unique id of the episode added.
       
   127         */
       
   128         TUint32 AddEpisodeL(const CMPXMedia& aMedia, TInt aDrive);
       
   129 
       
   130         /**
       
   131         * Update info for an episode in the Podcast table
       
   132         * @param aEpisodeId episode ID
       
   133         * @param aMedia media object which contains file path,
       
   134         *                artist, composer, name(title), track, etc...
       
   135         * @param aItemChangedMessages a list of change events
       
   136         * @return ETrue if the change is visible in the UI
       
   137         */
       
   138         CMPXDbActiveTask::TChangeVisibility UpdateEpisodeL(TUint32 aEpisodeId, const CMPXMedia& aMedia,
       
   139             CMPXMessageArray& aItemChangedMessages);
       
   140 
       
   141         /**
       
   142         * Cleans up the deleted records
       
   143         */
       
   144         void CleanupL();
       
   145 
       
   146         /**
       
   147         * Remove an episode from the Podcast table
       
   148         * @param aEpisodeId the ID of the episode to be removed
       
   149         * @param aUriArray on return contains the URI of the deleted episode
       
   150         * @param aItemChangedMessages on return contains changed messages
       
   151         * @param aDeleteRecord indicates whether the client has explictly requested
       
   152         *                to delete the records from the database. If ETrue, records
       
   153         *                associated with the media will be deleted from the database;
       
   154         *                if EFalse, the record will be marked as deleted only.
       
   155         */
       
   156         void DeleteEpisodeL(TUint32 aEpisodeId, CDesCArray& aUriArray,
       
   157             CMPXMessageArray& aItemChangedMessages, TBool aDeleteRecord);
       
   158 
       
   159         /**
       
   160         * Remove episodes matching a category from the Podcast table
       
   161         * @param aCategory the category to remove
       
   162         * @param aCategoryId ID of the category to remove
       
   163         * @param aUriArray on return will be filled with all the paths that were removed
       
   164         * @param aItemChangedMessages change events as result of the episode removal
       
   165         */
       
   166         void DeleteCategoryL(TMPXGeneralCategory aCategory, TUint32 aCategoryId,
       
   167             CDesCArray& aUriArray, CMPXMessageArray& aItemChangedMessages);
       
   168 
       
   169         /**
       
   170         * Remove all episodes from the podcast table that are published today
       
   171         * @param aUriArray, on return will be filled with all the paths that were removed
       
   172         * @param aItemChangedMessages change events as result of the episode removal
       
   173         */
       
   174         void DeleteTodayEpisodesL(CDesCArray& aUriArray,
       
   175             CMPXMessageArray& aItemChangedMessages);
       
   176 
       
   177         /**
       
   178         * Remove all episodes from the podcast table that are published yesterday
       
   179         * @param aUriArray, on return will be filled with all the paths that were removed
       
   180         * @param aItemChangedMessages change events as result of the episode removal
       
   181         */
       
   182         void DeleteYesterdayEpisodesL(CDesCArray& aUriArray,
       
   183             CMPXMessageArray& aItemChangedMessages);
       
   184 
       
   185         /**
       
   186         * Remove all episodes from the podcast table that are published this week
       
   187         * @param aUriArray, on return will be filled with all the paths that were removed
       
   188         * @param aItemChangedMessages change events as result of the episode removal
       
   189         */
       
   190         void DeleteThisWeekEpisodesL(CDesCArray& aUriArray,
       
   191             CMPXMessageArray& aItemChangedMessages);
       
   192 
       
   193         /**
       
   194         * Remove all episodes from the podcast table that are published a week ago
       
   195         * @param aUriArray, on return will be filled with all the paths that were removed
       
   196         * @param aItemChangedMessages change events as result of the episode removal
       
   197         */
       
   198         void DeleteLastWeekEpisodesL(CDesCArray& aUriArray,
       
   199             CMPXMessageArray& aItemChangedMessages);
       
   200 
       
   201         /**
       
   202         * Remove all episodes from the podcast table that are published 2 weeks ago
       
   203         * @param aUriArray, on return will be filled with all the paths that were removed
       
   204         * @param aUpdatedPlaylists playlists updated as result of the episode removal
       
   205         * @param aUpdatedCategories, a list of updated categories
       
   206         */
       
   207         void Delete2WeeksAgoEpisodesL(CDesCArray& aUriArray,
       
   208             CMPXMessageArray& aItemChangedMessages);
       
   209 
       
   210         /**
       
   211         * Remove all episodes from the podcast table that are published 3 weeks ago
       
   212         * @param aUriArray, on return will be filled with all the paths that were removed
       
   213         * @param aItemChangedMessages change events as result of the episode removal
       
   214         */
       
   215         void Delete3WeeksAgoEpisodesL(CDesCArray& aUriArray,
       
   216             CMPXMessageArray& aItemChangedMessages);
       
   217 
       
   218         /**
       
   219         * Remove all episodes from the podcast table that are published last month
       
   220         * @param aUriArray, on return will be filled with all the paths that were removed
       
   221         * @param aUpdatedPlaylists playlists updated as result of the episode removal
       
   222         * @param aUpdatedCategories, a list of updated categories
       
   223         */
       
   224         void DeleteLastMonthEpisodesL(CDesCArray& aUriArray,
       
   225             CMPXMessageArray& aItemChangedMessages);
       
   226 
       
   227         /**
       
   228         * Remove all episodes from the podcast table that are published earlier
       
   229         * @param aUriArray, on return will be filled with all the paths that were removed
       
   230         * @param aItemChangedMessages change events as result of the episode removal
       
   231         */
       
   232         void DeleteEarlierEpisodesL(CDesCArray& aUriArray,
       
   233             CMPXMessageArray& aItemChangedMessages);
       
   234 
       
   235         /**
       
   236         * Remove all episodes from the podcast table that do not have a publish date
       
   237         * @param aUriArray on return will be filled with all the paths that were removed
       
   238         * @param aItemChangedMessages change events as result of the episode removal
       
   239         */
       
   240         void DeleteUnknownEpisodesL(CDesCArray& aUriArray,
       
   241             CMPXMessageArray& aItemChangedMessages);
       
   242 
       
   243         /**
       
   244         * Get duration for the given episode
       
   245         * @param aEpisodeId episode ID of the episode to search for
       
   246         * @return Episode duration
       
   247         */
       
   248         TInt EpisodeDurationL(TUint32 aEpisodeId);
       
   249 
       
   250         /**
       
   251         * Get duration for all episodes
       
   252         * @return Duration value
       
   253         */
       
   254         TInt AllEpisodesDurationL();
       
   255 
       
   256         /**
       
   257         * Get duration for all episodes of a specified title
       
   258         * @param aTitleId identifies the title
       
   259         * @return Duration value
       
   260         */
       
   261         TInt TitleDurationL(TUint32 aTitleId);
       
   262 
       
   263         /**
       
   264         * Get duration for not played episodes
       
   265         * @return Duration value
       
   266         */
       
   267         TInt NotPlayedDurationL();
       
   268 
       
   269         /**
       
   270         * Get duration for recently added episodes
       
   271         * @return Duration value
       
   272         */
       
   273         TInt RecentlyAddedDurationL();
       
   274 
       
   275         /**
       
   276         * Get the name of the episode that matches the given episode ID
       
   277         * @param aEpisodeId ID of the episode
       
   278         * @return Episode name, ownership is transferred.
       
   279         */
       
   280         HBufC* GetNameL(TUint32 aEpisodeId);
       
   281 
       
   282         /**
       
   283         * Get URI of the episode
       
   284         * @param aEpisodeId ID of the episode
       
   285         * @return Episode URI, ownership is transferred.
       
   286         */
       
   287         HBufC* GetUriL(TUint32 aEpisodeId);
       
   288 
       
   289         /**
       
   290         * Get the drive of the episode
       
   291         * @param aEpisodeId ID of the episode
       
   292         * @return Episode drive
       
   293         */
       
   294         TInt GetDriveL(TUint32 aEpisodeId);
       
   295 
       
   296         /**
       
   297         * Gets information for an episode
       
   298         * @param aEpisodeId identifies the episode
       
   299         * @param aAttrs attributes to be returned
       
   300         * @param aMedia returns the episode info
       
   301         */
       
   302         void GetEpisodeL(TUint32 aEpisodeId, const TArray<TMPXAttribute>& aAttrs,
       
   303             CMPXMedia& aMedia);
       
   304 
       
   305         /**
       
   306         * Gets all episodes
       
   307         * @param aAttrs attributes to be retrieved
       
   308         * @param aMediaArray returns the episode info
       
   309         */
       
   310         void GetAllEpisodesL(const TArray<TMPXAttribute>& aAttrs,
       
   311             CMPXMediaArray& aMediaArray);
       
   312 
       
   313         /**
       
   314         * Gets the episodes for a category
       
   315         * @param aCategory category type
       
   316         * @param aCategoryId category item
       
   317         * @param aAttrs attributes to be retrieved
       
   318         * @param aMediaArray returns the episodes info
       
   319         * @param aOrder should the query be ordered, default EFalse
       
   320         */
       
   321         void GetEpisodesForCategoryL(TMPXGeneralCategory aCategory, TUint32 aCategoryId,
       
   322             const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray,
       
   323             TBool aOrder = EFalse);
       
   324 
       
   325         /**
       
   326         * Get all the episodes that match the given title ID
       
   327         * @param aTitleId ID of the title to match
       
   328         * @param aAttrs Array of attributes to return
       
   329         * @param aMediaArray Array to place all the matching episodes' required info
       
   330         */
       
   331         void GetEpisodesMatchingTitleL(TUint aTitleId,
       
   332             const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray);
       
   333 
       
   334         /**
       
   335         * Get the episodes from the podcast table with playcount equal to zero
       
   336         * @param aAttrs, the attributes to include for the artist(s) matching the
       
   337         *        selection criteria
       
   338         * @param aMediaArray Array to place all the matching episodes' required info
       
   339         * @param aIndexOfCurrentlyPlayingItem index of the currently playing
       
   340         *        episode or KErrNotFound(-1) if no currently playing episode within
       
   341         *        this playlist
       
   342         */
       
   343         void GetNotYetPlayedPlaylistEpisodesL(const TArray<TMPXAttribute>& aAttrs,
       
   344             CMPXMediaArray& aMediaArray, TInt& aIndexOfCurrentlyPlayingItem);
       
   345 
       
   346         /**
       
   347         * Get the episodes from the podcast table that were added within the last 7 days
       
   348         * @param aAttrs, the attributes to include for the artist(s) matching the
       
   349         *        selection criteria
       
   350         * @param aMediaArray Array to place all the matching episodes' required info
       
   351         * @param aIndexOfCurrentlyPlayingItem index of the currently playing
       
   352         *        episode or KErrNotFound(-1) if no currently playing episode within
       
   353         *        this playlist
       
   354         */
       
   355         void GetRecentlyAddedPlaylistEpisodesL(const TArray<TMPXAttribute>& aAttrs,
       
   356             CMPXMediaArray& aMediaArray, TInt& aIndexOfCurrentlyPlayingItem);
       
   357 
       
   358         /**
       
   359         * Get the episodes from the podcast table published today
       
   360         * @param aPublishDateCategoryId if specified (> 0), record the category id in the
       
   361         *        item in the media array
       
   362         * @param aAttrs, the attributes to include for the artist(s) matching the
       
   363         *        selection criteria
       
   364         * @param aMediaArray Array to place all the matching episodes' required info
       
   365         */
       
   366         void GetTodayEpisodesL(const TMPXItemId& aPublishDateCategoryId,
       
   367             const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray);
       
   368 
       
   369         /**
       
   370         * Get the episodes from the podcast table published today
       
   371         * @param aPublishDateCategoryId if specified (> 0), record the category id in the
       
   372         *        item in the media array
       
   373         * @param aAttrs, the attributes to include for the artist(s) matching the
       
   374         *        selection criteria
       
   375         * @param aMediaArray Array to place all the matching episodes' required info
       
   376         */
       
   377         void GetYesterdayEpisodesL(const TMPXItemId& aPublishDateCategoryId,
       
   378             const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray);
       
   379 
       
   380         /**
       
   381         * Get the episodes from the podcast table published this week
       
   382         * @param aPublishDateCategoryId if specified (> 0), record the category id in the
       
   383         *        item in the media array
       
   384         * @param aAttrs, the attributes to include for the artist(s) matching the
       
   385         *        selection criteria
       
   386         * @param aMediaArray Array to place all the matching episodes' required info
       
   387         */
       
   388         void GetThisWeekEpisodesL(const TMPXItemId& aPublishDateCategoryId,
       
   389             const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray);
       
   390 
       
   391         /**
       
   392         * Get the episodes from the podcast table published last week.
       
   393         * @param aPublishDateCategoryId if specified (> 0), record the category id in the
       
   394         *        item in the media array
       
   395         * @param aAttrs, the attributes to include for the artist(s) matching the
       
   396         *        selection criteria
       
   397         * @param aMediaArray Array to place all the matching episodes' required info
       
   398         */
       
   399         void GetLastWeekEpisodesL(const TMPXItemId& aPublishDateCategoryId,
       
   400             const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray);
       
   401 
       
   402         /**
       
   403         * Get the episodes from the podcast table published two weeks ago
       
   404         * @param aPublishDateCategoryId if specified (> 0), record the category id in the
       
   405         *        item in the media array
       
   406         * @param aAttrs, the attributes to include for the artist(s) matching the
       
   407         *        selection criteria
       
   408         * @param aMediaArray Array to place all the matching episodes' required info
       
   409         */
       
   410         void Get2WeeksAgoEpisodesL(const TMPXItemId& aPublishDateCategoryId,
       
   411             const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray);
       
   412 
       
   413         /**
       
   414         * Get the episodes from the podcast table published three weeks ago
       
   415         * @param aPublishDateCategoryId if specified (> 0), record the category id in the
       
   416         *        item in the media array
       
   417         * @param aAttrs, the attributes to include for the artist(s) matching the
       
   418         *        selection criteria
       
   419         * @param aMediaArray Array to place all the matching episodes' required info
       
   420         */
       
   421         void Get3WeeksAgoEpisodesL(const TMPXItemId& aPublishDateCategoryId,
       
   422             const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray);
       
   423 
       
   424         /**
       
   425         * Get the episodes from the podcast table published last month
       
   426         * @param aPublishDateCategoryId if specified (> 0), record the category id in the
       
   427         *        item in the media array
       
   428         * @param aAttrs, the attributes to include for the artist(s) matching the
       
   429         *        selection criteria
       
   430         * @param aMediaArray Array to place all the matching episodes' required info
       
   431         */
       
   432         void GetLastMonthEpisodesL(const TMPXItemId& aPublishDateCategoryId,
       
   433             const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray);
       
   434 
       
   435         /**
       
   436         * Get the episodes from the podcast table published earlier
       
   437         * @param aPublishDateCategoryId if specified (> 0), record the category id in the
       
   438         *        item in the media array
       
   439         * @param aAttrs, the attributes to include for the artist(s) matching the
       
   440         *        selection criteria
       
   441         * @param aMediaArray Array to place all the matching episodes' required info
       
   442         */
       
   443         void GetEarlierEpisodesL(const TMPXItemId& aPublishDateCategoryId,
       
   444             const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray);
       
   445 
       
   446         /**
       
   447         * Get the episodes from the podcast table without a publish date
       
   448         * @param aPublishDateCategoryId if specified (> 0), record the category id in the
       
   449         *        item in the media array
       
   450         * @param aAttrs, the attributes to include for the artist(s) matching the
       
   451         *        selection criteria
       
   452         * @param aMediaArray Array to place all the matching episodes' required info
       
   453         */
       
   454         void GetUnknownEpisodesL(const TMPXItemId& aPublishDateCategoryId,
       
   455             const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray);
       
   456 
       
   457         /**
       
   458         * Find the total number of episodes without loading any media objects
       
   459         * Generates a simple sql query to open a column quickly to find the count
       
   460         * @return number of items
       
   461         */
       
   462         TInt CountL();
       
   463 
       
   464         /**
       
   465         * Get the number of episodes from the podcast table published today
       
   466         * @return Number of episodes published today.
       
   467         */
       
   468         TInt GetTodayEpisodesCountL();
       
   469 
       
   470         /**
       
   471         * Get the number of episodes from the podcast table published today
       
   472         * @return Number of episodes published yesterday.
       
   473         */
       
   474         TInt GetYesterdayEpisodesCountL();
       
   475 
       
   476         /**
       
   477         * Get the number of episodes from the podcast table published this week
       
   478         * @return Number of episodes published this week.
       
   479         */
       
   480         TInt GetThisWeekEpisodesCountL();
       
   481 
       
   482         /**
       
   483         * Get the number of episodes from the podcast table published last week.
       
   484         * @return Number of episodes published last week.
       
   485         */
       
   486         TInt GetLastWeekEpisodesCountL();
       
   487 
       
   488         /**
       
   489         * Get the number of episodes from the podcast table published two weeks ago
       
   490         * @return Number of episodes published 2 weeks ago.
       
   491         */
       
   492         TInt Get2WeeksAgoEpisodesCountL();
       
   493 
       
   494         /**
       
   495         * Get the number of episodes from the podcast table published three weeks ago
       
   496         * @return Number of episodes published 3 weeks ago.
       
   497         */
       
   498         TInt Get3WeeksAgoEpisodesCountL();
       
   499 
       
   500         /**
       
   501         * Get the number of episodes from the podcast table published last month
       
   502         * @return Number of episodes published last month.
       
   503         */
       
   504         TInt GetLastMonthEpisodesCountL();
       
   505 
       
   506         /**
       
   507         * Get the number of episodes from the podcast table published earlieronth.
       
   508         */
       
   509         TInt GetEarlierEpisodesCountL();
       
   510 
       
   511         /**
       
   512         * Get the episodes from the podcast table without a publish date
       
   513         * @return Number of episodes without a publish date.
       
   514         */
       
   515         TInt GetUnknownEpisodesCountL();
       
   516 
       
   517         /**
       
   518         * Find the total number of episodes recently added.
       
   519         * @return number of episodes
       
   520         */
       
   521         TInt GetRecentlyAddedEpisodesCountL();
       
   522 
       
   523         /**
       
   524         * Find the total number of episodes that have not been played without loading
       
   525         * any media objects. Generates a simple sql query to open al column quickly
       
   526         * to find the count
       
   527         * @return number of items
       
   528         */
       
   529         TInt GetNotYetPlayedEpisodesCountL();
       
   530 
       
   531         /**
       
   532         * Find episode(s) which match(es) the selection criteria
       
   533         * @param aGeneralId selection criteria (could be episode/album/artist/genre/composer Id)
       
   534         * @param aContainerId selection criteria (could be artist/album id)
       
   535         * @param aType criteria type (EMPXItem or EMPXGroup)
       
   536         * @param aPodcastType podcast criteria type (EMPXPodcastGroup or EMPXPodcastItem)
       
   537         * @param aCriteria selection criteria
       
   538         * @param aAttrs the attributes to include for the artist(s) matching the
       
   539         *        selection criteria
       
   540         * @param aMediaArray Returns the episodes matching the selection criteria
       
   541         */
       
   542         void FindEpisodesL(TUint32 aGeneralId, TUint32 aContainerId, TMPXGeneralType aType,
       
   543             TMPXPodcastType aPodcastType, const CMPXMedia& aCriteria,
       
   544             const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray);
       
   545 
       
   546         /**
       
   547         * Sets the value of the IsPlaying field for a given episode
       
   548         * @param aEpisodeId identifies the episode
       
   549         * @param aIsPlaying IsPlaying field value
       
   550         */
       
   551         void SetIsPlayingL(TUint32 aEpisodeId, TBool aIsPlaying);
       
   552 
       
   553         /**
       
   554         * Returns the podcast count for a given drive
       
   555         * @param aDrive drive
       
   556         * @return the count
       
   557         */
       
   558         TUint GetDrivePodcastCountL(TInt aDrive);
       
   559 
       
   560         /**
       
   561         * Get URIs for a given number of podcasts
       
   562         * @param aDrive, specifies drive number for db selection
       
   563         * @param aFromID, specifies unique ID of last record retrieved
       
   564         * @param aRecords, specifies the number of records to get
       
   565         * @param aUriArr, will contain all URIs on return
       
   566         * @param aLastID, will contain unique ID of a last record in the array
       
   567         */
       
   568         void GetPodcastUriArrayL(TInt aDrive, TInt aFromID, TInt aRecords,
       
   569                                  CDesCArray& aUriArr, TInt& aLastID);
       
   570 
       
   571     private:
       
   572 
       
   573         /**
       
   574         * Adds an episode to the Podcast table
       
   575         * @param aEpisodeId identifies the episode
       
   576         * @param aMedia contains the episode attributes
       
   577         * @param aDrive drive to add the episode to
       
   578         * @param aItemChangedMessages item changed messages to update
       
   579         */
       
   580         TBool DoAddEpisodeL(TUint32 aEpisodeId, const CMPXMedia& aMedia, TInt aDrive,
       
   581             CMPXMessageArray* aItemChangedMessages);
       
   582 
       
   583         /**
       
   584         * Updates an episode in the Podcast table
       
   585         * @param aEpisodeId identifies the episode
       
   586         * @param aMedia contains the episode attributes
       
   587         * @param aItemChangedMessages NULL or item changed messages to update
       
   588         */
       
   589         CMPXDbActiveTask::TChangeVisibility DoUpdateEpisodeL(TUint32 aEpisodeId, const CMPXMedia& aMedia,
       
   590             CMPXMessageArray* aItemChangedMessages);
       
   591 
       
   592         /**
       
   593         * Updates an episode in the Podcast table
       
   594         * @param aEpisodeId identifies the episode
       
   595         * @param aMedia contains the episode attributes
       
   596         * @param aDrive drive to add the episode to
       
   597         * @param aItemChangedMessages item changed messages to update
       
   598         * @param aRecordset current episode record in the Podcast table.
       
   599         *       Required to detect any field changes.
       
   600         */
       
   601         CMPXDbActiveTask::TChangeVisibility DoUpdateEpisodeL(TUint32 aEpisodeId, const CMPXMedia& aMedia, TInt aDrive,
       
   602             CMPXMessageArray* aItemChangedMessages, RSqlStatement& aRecordset);
       
   603 
       
   604         /**
       
   605         * Deletes an episode corresponding to the current record in aRecordset
       
   606         * @param aRecordset current episode record in the Podcast table.
       
   607         *       Required to detect any field changes.
       
   608         * @param aUriArray Returns the episode URI
       
   609         * @param aItemChangedMessages Returns item changed messages
       
   610         * @param aDeleteRecord ETrue if the episode should be deleted, EFalse if it
       
   611         *       should just be marked as deleted
       
   612         */
       
   613         void DeleteRecordsetL(RSqlStatement& aRecordset, CDesCArray& aUriArray,
       
   614             CMPXMessageArray& aItemChangedMessages, TBool aDeleteRecord = EFalse);
       
   615 
       
   616         /**
       
   617         * Remove a episode from the podcast table
       
   618         * @param aRecordset episode record to be removed
       
   619         * @param aUriArray, on return will be filled with all the paths that were removed
       
   620         * @param aItemChangedMessages: change events as result of the episode removal
       
   621         * @param aDeleteRecord: indicates whether the client has explictly requested
       
   622         *                to delete the records from the database. If ETrue, records
       
   623         *                associated with the media will be deleted from the database;
       
   624         *                if EFalse, whether to mark the records as deleted or to delete
       
   625         *                the records will be based on other deciding factors.
       
   626         * @return Error code.
       
   627         */
       
   628         void DoDeleteEpisodeL(RSqlStatement& aRecordset, CDesCArray& aUriArray,
       
   629             CMPXMessageArray& aItemChangedMessages, TBool aDeleteRecord = EFalse);
       
   630 
       
   631         /**
       
   632         * Constructs the fields and corresponding values to be written into the Podcast
       
   633         * table for update and insert statements.
       
   634         * @param aEpisodeId identifies the song
       
   635         * @param aMedia contains the new song attributes
       
   636         * @param aItemChangedMessages item changed mesages to add to
       
   637         * @param aPodcastTable points to the existing record in the Podcast table for
       
   638         *       updates or NULL for inserts
       
   639         * @param aFields returns the field names to be updated
       
   640         * @param aValues returns the field values to be updated
       
   641         * @param aDrive drive the song is on
       
   642         * @return ETrue if the change is visible in the UI
       
   643         */
       
   644         CMPXDbActiveTask::TChangeVisibility GeneratePodcastFieldsValuesL(TUint32 aEpisodeId, const CMPXMedia& aMedia,
       
   645             CMPXMessageArray* aItemChangedMessages, RSqlStatement* aPodcastTable,
       
   646             CDesCArray& aFields, CDesCArray& aValues, TInt aDrive);
       
   647 
       
   648         /**
       
   649         * Checks if the specified category field (artist/album/genre/composer)
       
   650         * will change and notifies the observer if so.
       
   651         * @param aCategory identifies the category
       
   652         * @param aMedia contains the new record attributes
       
   653         * @param aAttribute corresponding attribute in the media parameter
       
   654         * @param aOldId previous value of the category field or 0 if new record
       
   655         * @param aDriveId drive ID the update is for
       
   656         * @param aItemChangedMessages item changed messages to append to
       
   657         * @param aItemId returns the category item ID
       
   658         * @return ETrue if the field was modified
       
   659         */
       
   660         TBool UpdateCategoryFieldL(TMPXGeneralCategory aCategory, const CMPXMedia& aMedia,
       
   661             const TMPXAttribute& aAttribute, TUint32 aOldId, TInt aDriveId,
       
   662             CMPXMessageArray* aItemChangedMessages, TUint32& aItemId);
       
   663 
       
   664         /**
       
   665         * Update the media  with information found in DB
       
   666         * @param aPodcastTable podcast record
       
   667         * @param aAttrs, the attributes to include for the artist(s) matching the
       
   668         *        selection criteria
       
   669         * @param aMedia the episode details object
       
   670         */
       
   671         void UpdateMediaL(RSqlStatement& aPodcastTable, const TArray<TMPXAttribute>& aAttrs,
       
   672             CMPXMedia& aMedia);
       
   673 
       
   674         /**
       
   675         * Set the media general attributes in media object with its corresponding
       
   676         * value from the podcast table
       
   677         * @param aPodcastTable podcast record
       
   678         * @param aAttrId the required attributes
       
   679         * @param aMedia the media object to set
       
   680         */
       
   681         void UpdateMediaGeneralL(RSqlStatement& aPodcastTable, TUint aAttrId,
       
   682             CMPXMedia& aMedia);
       
   683 
       
   684         /**
       
   685         * Set the media podcast attributes in media object with its corresponding
       
   686         * value from the podcast table
       
   687         * @param aPodcastTable podcast record
       
   688         * @param aAttrId the required attributes
       
   689         * @param aMedia the media object to set
       
   690         */
       
   691         void UpdateMediaMusicL(RSqlStatement& aPodcastTable, TUint aAttrId,
       
   692             CMPXMedia& aMedia);
       
   693 
       
   694         /**
       
   695         * Set the media audio attributes in media object with its corresponding
       
   696         * value from the podcast table
       
   697         * @param aPodcastTable podcast record
       
   698         * @param aAttrId the required attributes
       
   699         * @param aMedia the media object to set
       
   700         */
       
   701         void UpdateMediaAudioL(RSqlStatement& aPodcastTable, TUint aAttrId,
       
   702             CMPXMedia& aMedia);
       
   703 
       
   704         /**
       
   705         * Set the podcast attributes in media object with its corresponding value
       
   706         * from the podcast table
       
   707         * @param aPodcastTable podcast record
       
   708         * @param aAttrId the required attributes
       
   709         * @param aMedia the media object to set
       
   710         */
       
   711         void UpdateMediaPodcastL(RSqlStatement& aPodcastTable, TUint aAttrId,
       
   712             CMPXMedia& aMedia);
       
   713 
       
   714         /**
       
   715         * Get the DRM type of the given file
       
   716         * @param aFile: file
       
   717         * @return DRM type.
       
   718         */
       
   719         TMCDrmType DRMTypeL(const TDesC& aFile);
       
   720 
       
   721         /**
       
   722         * Generate matching columns and matching values for podcast table from the given criteria
       
   723         * @param aGeneralId, selection criteria (could be episode/album/artist/genre/composer Id)
       
   724         * @param aContainerId, selection criteria (could be artist/album id)
       
   725         * @param aType, criteria type (EMPXItem or EMPXGroup)
       
   726         * @param aPodcastType, podcast criteria type (EMPXPodcastGroup or EMPXPodcastItem)
       
   727         * @param aCriteria, selection criteria
       
   728         * @return Newly allocated SQL criteria string on the CS.
       
   729         *       Ownership is passed to the caller.
       
   730         */
       
   731         HBufC* GeneratePodcastMatchingCriteriaLC(TUint32 aGeneralId, TUint32 aContainerId,
       
   732             TMPXGeneralType aType, TMPXPodcastType aPodcastType, const CMPXMedia& aCriteria);
       
   733 
       
   734         /**
       
   735         * Generate publish date category criteria string for the specified
       
   736         * publish date category
       
   737         * @param aPublishDateCateogry the publish date category to generate
       
   738         *        criteria string for
       
   739         * @return the generated criteria string
       
   740         */
       
   741         HBufC* GeneratePublishDateCategoryCriteriaL(const TUint& aPublishDateCategoryID);
       
   742 
       
   743         /**
       
   744         * Generates a full URI from a Podcast record.
       
   745         * @param aRecordset Podcast table record
       
   746         * @return Full URI string. The ownership is passed to the caller.
       
   747         */
       
   748         HBufC* ConstructUriL(RSqlStatement& aRecordset);
       
   749 
       
   750         /**
       
   751         * Checks if the specified episode exists.
       
   752         * @param aId identifies the episode
       
   753         * @return ETrue if it exists, EFalse otherwise
       
   754         */
       
   755         TBool EpisodeExistsL(TUint32 aEpisodeId);
       
   756 
       
   757         /**
       
   758         * Checks if extra attributes are required. The "standard" attribute set includes:
       
   759         * EMPXMediaGeneralId, EMPXMediaGeneralType, EMPXMediaGeneralCategory,
       
   760         * EMPXMediaGeneralTitle, EMPXMediaGeneralUri, and EMPXMediaGeneralFlags
       
   761         * @param aAttrs attributes to be checked
       
   762         * @return ETrue if extra attributes are required
       
   763         */
       
   764         TBool ExtraFieldsRequired(const TArray<TMPXAttribute>& aAttrs);
       
   765 
       
   766         /**
       
   767         * Adds the publish date category ID as a MPXMediaPodcastPubDateCategoryId
       
   768         * attribute to the last media item in the array. Only does this if
       
   769         * the category id is valid (<>0).
       
   770         * @param aPublishDateCategoryId category ID to be added
       
   771         * @param aMediaArray array containing media items
       
   772         */
       
   773         void ProcessPublishDateCategoryL(const TMPXItemId& aPublishDateCategoryId,
       
   774             CMPXMediaArray& aMediaArray);
       
   775 
       
   776         /**
       
   777         * Returns the index of the playing item in the arry or KErrNotFound if no
       
   778         * item is marked as playing.
       
   779         * @param aMediaArray array to be processed
       
   780         * @return index of playing item or KErrNotFound
       
   781         */
       
   782         TInt GetPlayingItemL(CMPXMediaArray& aMediaArray);
       
   783 
       
   784     private:    // from MMPXTable
       
   785 
       
   786         /**
       
   787         * @see MMPXTable
       
   788         */
       
   789         virtual void CreateTableL(RSqlDatabase& aDatabase, TBool aCorruptTable);
       
   790 
       
   791         /**
       
   792         * @see MMPXTable
       
   793         */
       
   794         virtual void DropTableL(RSqlDatabase& aDatabase);
       
   795 
       
   796         /**
       
   797         * @see MMPXTable
       
   798         */
       
   799         virtual TBool CheckTableL(RSqlDatabase& aDatabase);
       
   800 
       
   801     private:
       
   802 
       
   803         /**
       
   804         * C++ constructor.
       
   805         * @param aDbManager database manager to use for database interactions
       
   806         * @param aObserver Observer for podcast notifications
       
   807         */
       
   808         CMPXDbPodcast(CMPXDbManager& aDbManager,
       
   809             MMPXDbPodcastObserver& aObserver);
       
   810 
       
   811         /**
       
   812         * Symbian 2nd phase constructor.
       
   813         */
       
   814         void ConstructL(CMPXResource& aResource);
       
   815 
       
   816     private:
       
   817 
       
   818         /**
       
   819         * Column indexes in the music table
       
   820         */
       
   821         enum TPodcastColumns
       
   822             {
       
   823             EPodcastUniqueId = KMPXTableDefaultIndex,
       
   824             EPodcastDeleted,
       
   825             EPodcastDbFlag,
       
   826             EPodcastVolumeId,
       
   827             EPodcastIsPlaying,
       
   828             EPodcastTitle,
       
   829             EPodcastLocation,
       
   830             EPodcastPublishDate,
       
   831             EPodcastAlbumTrack,
       
   832             EPodcastPlayCount,
       
   833             EPodcastTimeAdded,
       
   834             EPodcastTimePlayed,
       
   835             EPodcastDuration,
       
   836             EPodcastSync,
       
   837             EPodcastModified,
       
   838             EPodcastArtist,
       
   839             EPodcastAlbum,
       
   840             EPodcastGenre,
       
   841             EPodcastComposer,
       
   842             EPodcastReleaseDate,
       
   843             EPodcastRating,
       
   844             EPodcastComment,
       
   845             EPodcastCopyright,
       
   846             EPodcastArt,
       
   847             EPodcastUrl,
       
   848             EPodcastDRM,
       
   849             EPodcastLastPlayPosition,
       
   850             EPodcastSampleRate,
       
   851             EPodcastBitRate,
       
   852             EPodcastNumChannels,
       
   853             EPodcastCodec,
       
   854             EPodcastMimeType,
       
   855             EPodcastArtistName,
       
   856             EPodcastAlbumName,
       
   857             EPodcastGenreName,
       
   858             EPodcastComposerName,
       
   859             EPodcastFieldCount
       
   860             };
       
   861 
       
   862     private:    // Data
       
   863 
       
   864         CDesCArrayFlat* iExtensionsDrm;    // file extensions to check DRM type, owned
       
   865         MMPXDbPodcastObserver& iObserver;
       
   866     };
       
   867 
       
   868 #endif      // MPXDBPODCAST_H
       
   869 
       
   870 // End of File