upnpframework/upnpmusicadapter/src/upnplitefiller.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     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:  Provides services for filling MPX playlist
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 // System
       
    21 #include <escapeutils.h> // for unicode conversion
       
    22 #include <escapeutils.h> // for unicode conversion
       
    23 
       
    24 // XML framework api
       
    25 #include <mpxcollectionplaylist.h>
       
    26 #include <mpxmediaarray.h>
       
    27 #include <mpxmediageneraldefs.h>
       
    28 
       
    29 // upnpframework / avcontroller api
       
    30 #include "upnpavdevice.h" // for the device
       
    31 
       
    32 // upnpframework / avcontroller helper api
       
    33 #include "upnpconstantdefs.h" // for KClassAudio
       
    34 
       
    35 // upnpframework / xmlparser api
       
    36 #include "upnpobjectlite.h"
       
    37 
       
    38 // musicadapter internal
       
    39 #include "upnpmusicadapter.h" // for Complete(this)
       
    40 #include "upnplitefiller.h"
       
    41 
       
    42 // debug
       
    43 _LIT16( KComponentLogfile, "musicadapter.txt" );
       
    44 #include "upnplog.h"
       
    45 
       
    46 // CONSTANTS
       
    47 _LIT16( KUPnPPrefix, "upnp:" );
       
    48 _LIT16( KSeparator, "*" );
       
    49 const TInt KMaxElementSize = 256; // from UPNP/DLNA
       
    50 
       
    51 // METHODS
       
    52 
       
    53 // --------------------------------------------------------------------------
       
    54 // CUPnPLiteFiller::NewL
       
    55 //---------------------------------------------------------------------------
       
    56 CUPnPLiteFiller* CUPnPLiteFiller::NewL()
       
    57     {
       
    58     CUPnPLiteFiller* filler = 
       
    59         new(ELeave)CUPnPLiteFiller();
       
    60     CleanupStack::PushL( filler );
       
    61     filler->ConstructL();
       
    62     CleanupStack::Pop( filler );
       
    63     return filler;
       
    64     }
       
    65 
       
    66 // --------------------------------------------------------------------------
       
    67 // CUPnPLiteFiller::SetSelectedIndex
       
    68 // Sets the index of pre-selected item
       
    69 // --------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C void CUPnPLiteFiller::SetSelectedIndex(
       
    72     TInt aSelectedIndex )
       
    73     {
       
    74     __ASSERTD( aSelectedIndex >= 0, __FILE__, __LINE__ );
       
    75     iSelectedIndex = aSelectedIndex;
       
    76     }
       
    77 
       
    78 // --------------------------------------------------------------------------
       
    79 // CUPnPLiteFiller::SetSourceDeviceL
       
    80 // Set the media server the playlist is located
       
    81 // --------------------------------------------------------------------------
       
    82 //
       
    83 void CUPnPLiteFiller::SetSourceDeviceL( const CUpnpAVDevice& aDevice )
       
    84     {
       
    85     if ( !iSourceDevice )
       
    86         {
       
    87         iSourceDevice = &aDevice;        
       
    88         iDeviceUid = HBufC::NewL( aDevice.Uuid().Length() );
       
    89         iDeviceUid->Des().Copy( aDevice.Uuid() );
       
    90         }
       
    91     else
       
    92         {
       
    93         // we only support playlists from a single device.
       
    94         __ASSERTD( &aDevice == iSourceDevice , __FILE__, __LINE__ );
       
    95         }
       
    96     }
       
    97 
       
    98 // --------------------------------------------------------------------------
       
    99 // CUPnPLiteFiller::SetHost
       
   100 // Assigns the host music adapter
       
   101 // --------------------------------------------------------------------------
       
   102 //
       
   103 void CUPnPLiteFiller::SetHost( CUPnPMusicAdapter& aHost )
       
   104     {
       
   105     iHost = &aHost;
       
   106     }
       
   107 
       
   108 // --------------------------------------------------------------------------
       
   109 // CUPnPLiteFiller::Host
       
   110 // returns the host music adapter
       
   111 // --------------------------------------------------------------------------
       
   112 //
       
   113 CUPnPMusicAdapter& CUPnPLiteFiller::Host() const
       
   114     {
       
   115     __ASSERTD( iHost != 0 , __FILE__, __LINE__ );
       
   116     return *iHost;
       
   117     }
       
   118 
       
   119 // --------------------------------------------------------------------------
       
   120 // CUPnPLiteFiller::DoComplete
       
   121 // Completes the object, causing it to be destroyed.
       
   122 // --------------------------------------------------------------------------
       
   123 //
       
   124 void CUPnPLiteFiller::DoComplete()
       
   125     {
       
   126     Host().Complete( this );
       
   127     }
       
   128 
       
   129 // --------------------------------------------------------------------------
       
   130 // CUPnPLiteFiller::FillL
       
   131 // Fill track data into the playlist
       
   132 // --------------------------------------------------------------------------
       
   133 //
       
   134 void CUPnPLiteFiller::FillL(
       
   135     CUPnPMusicAdapter& /*aHost*/,
       
   136     CMPXMediaArray& /*aPlaylist*/ )
       
   137     {
       
   138     // no implementation required
       
   139     }
       
   140 
       
   141 // --------------------------------------------------------------------------
       
   142 // CUPnPLiteFiller::CancelFill
       
   143 // --------------------------------------------------------------------------
       
   144 //
       
   145 void CUPnPLiteFiller::CancelFill()
       
   146     {
       
   147     // no implementation required
       
   148     // - this class does not have async nature
       
   149     }
       
   150 
       
   151 // --------------------------------------------------------------------------
       
   152 // CUPnPLiteFiller::PlaylistSize
       
   153 // Returns the total playlist size
       
   154 // --------------------------------------------------------------------------
       
   155 //
       
   156 TInt CUPnPLiteFiller::PlaylistSize()
       
   157     {
       
   158     // no implementation required
       
   159     return 0;
       
   160     }
       
   161 
       
   162 // --------------------------------------------------------------------------
       
   163 // CUPnPLiteFiller::SelectedIndex
       
   164 // Index of selected item
       
   165 // --------------------------------------------------------------------------
       
   166 //
       
   167 TInt CUPnPLiteFiller::SelectedIndex() const
       
   168     {
       
   169     return iSelectedIndex;
       
   170     }
       
   171 
       
   172 // --------------------------------------------------------------------------
       
   173 // CUPnPLiteFiller::~CUPnPLiteFiller
       
   174 //---------------------------------------------------------------------------
       
   175 EXPORT_C CUPnPLiteFiller::~CUPnPLiteFiller()
       
   176     {
       
   177     delete iDeviceUid;
       
   178     iDeviceUid = 0;
       
   179     }
       
   180 
       
   181 // --------------------------------------------------------------------------
       
   182 // CUPnPLiteFiller::FillItemMpxPlaylistL
       
   183 // Fills a single item to mpx playlist
       
   184 // --------------------------------------------------------------------------
       
   185 //
       
   186 void CUPnPLiteFiller::FillItemMpxPlaylistL(  CMPXMediaArray& aPlaylist,
       
   187     const CUpnpObjectLite& aItem, TInt /*aIndex*/ )
       
   188     {
       
   189     // Create new media object for track
       
   190     CMPXMedia* media = CMPXMedia::NewL();
       
   191     CleanupStack::PushL( media );
       
   192     // Set type
       
   193     media->SetTObjectValueL<TMPXGeneralType>( 
       
   194         KMPXMediaGeneralType, EMPXItem );
       
   195     // Set gategory
       
   196     media->SetTObjectValueL<TMPXGeneralCategory>( 
       
   197         KMPXMediaGeneralCategory, EMPXSong );
       
   198     // URI
       
   199     if( aItem.IsTypeOf( CUpnpObjectLite::EMusicItem ) )
       
   200         {
       
   201         ConvertToURI( *iDeviceUid, aItem, iTempBuf );
       
   202         }
       
   203     else // item is non audio set uri to zero
       
   204         {
       
   205         iTempBuf.Zero();
       
   206         }
       
   207     media->SetTextValueL( 
       
   208         KMPXMediaGeneralUri, iTempBuf );
       
   209     // Title        
       
   210     media->SetTextValueL( 
       
   211         KMPXMediaGeneralTitle, aItem.Title() );
       
   212     // Add track to the object list
       
   213     aPlaylist.AppendL( media );
       
   214     CleanupStack::Pop( media );
       
   215     }
       
   216 
       
   217 // --------------------------------------------------------------------------
       
   218 // CUPnPLiteFiller::CUPnPLiteFiller
       
   219 // 1st phase constructor.
       
   220 // --------------------------------------------------------------------------
       
   221 //
       
   222 CUPnPLiteFiller::CUPnPLiteFiller()
       
   223     {
       
   224     iSelectedIndex = 0;
       
   225     }
       
   226 
       
   227 // --------------------------------------------------------------------------
       
   228 // CUPnPLiteFiller::ConstructL
       
   229 // 2nd phase constructor.
       
   230 // --------------------------------------------------------------------------
       
   231 // 
       
   232 void CUPnPLiteFiller::ConstructL()
       
   233     {
       
   234     // None.
       
   235     }
       
   236 
       
   237 // --------------------------------------------------------------------------
       
   238 // CUPnPLiteFiller::ConvertToURI
       
   239 // Convert UPnP item to playlist item URI string
       
   240 // --------------------------------------------------------------------------
       
   241 //  
       
   242 void CUPnPLiteFiller::ConvertToURI( const TDesC& aDeviceUid,
       
   243     const CUpnpObjectLite& aItem, TDes& aBuffer )
       
   244     {
       
   245     // Start with upnp prefix
       
   246     aBuffer.Copy( KUPnPPrefix );
       
   247     aBuffer.Append( aDeviceUid );
       
   248 
       
   249     aBuffer.Append( KSeparator );
       
   250     // add object id (converting 8->16 bit)
       
   251     TBuf<KMaxElementSize> id16;
       
   252     id16.Copy( aItem.ObjectId() );
       
   253     aBuffer.Append( id16 );
       
   254     }
       
   255 
       
   256