1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: CPlaylistItem class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "playlistitem.h" |
|
21 |
|
22 #include "logger.h" |
|
23 |
|
24 _LIT( KLineFeed, "\r\n" ); |
|
25 _LIT( KUrl, "#EXTURL:" ); |
|
26 _LIT( KTitle, "#EXTTITLE:" ); |
|
27 |
|
28 _LIT( KCommentChar, "#" ); |
|
29 |
|
30 const TInt KDefaultGranularity( 5 ); |
|
31 |
|
32 CPlaylistItem* CPlaylistItem::NewLC() |
|
33 { |
|
34 CPlaylistItem* self = new (ELeave) CPlaylistItem(); |
|
35 CleanupStack::PushL( self ); |
|
36 self->ConstructL(); |
|
37 return self; |
|
38 } |
|
39 |
|
40 CPlaylistItem::~CPlaylistItem() |
|
41 { |
|
42 TRACE_FUNC; |
|
43 delete iTitle; |
|
44 delete iUrl; |
|
45 delete iDescArray; |
|
46 } |
|
47 |
|
48 CPlaylistItem::CPlaylistItem() |
|
49 { |
|
50 } |
|
51 |
|
52 void CPlaylistItem::ConstructL() |
|
53 { |
|
54 TRACE_FUNC; |
|
55 iTitle = KNullDesC().AllocL(); |
|
56 iUrl = KNullDesC().AllocL(); |
|
57 iDescArray = new (ELeave) CDesCArrayFlat(KDefaultGranularity); |
|
58 } |
|
59 |
|
60 void CPlaylistItem::SetId( TInt aId ) |
|
61 { |
|
62 iId = aId; |
|
63 } |
|
64 |
|
65 TInt CPlaylistItem::Id() const |
|
66 { |
|
67 return iId; |
|
68 } |
|
69 |
|
70 void CPlaylistItem::SetTitleL( const TDesC& aTitle ) |
|
71 { |
|
72 delete iTitle; |
|
73 iTitle = NULL; |
|
74 iTitle = aTitle.AllocL(); |
|
75 } |
|
76 |
|
77 const TDesC& CPlaylistItem::Title() const |
|
78 { |
|
79 return *iTitle; |
|
80 } |
|
81 |
|
82 void CPlaylistItem::SetUrlL( const TDesC& aUrl ) |
|
83 { |
|
84 delete iUrl; |
|
85 iUrl = NULL; |
|
86 iUrl = aUrl.AllocL(); |
|
87 } |
|
88 |
|
89 const TDesC& CPlaylistItem::Url() const |
|
90 { |
|
91 return *iUrl; |
|
92 } |
|
93 |
|
94 TInt CPlaylistItem::ItemCount() const |
|
95 { |
|
96 return iDescArray->MdcaCount(); |
|
97 } |
|
98 |
|
99 TPtrC16 CPlaylistItem::ItemAt( TInt aIndex ) const |
|
100 { |
|
101 return iDescArray->MdcaPoint( aIndex ); |
|
102 } |
|
103 |
|
104 TInt CPlaylistItem::FindItem( const TDesC16& aPtr, TInt& aPos, TKeyCmpText aTextComparisonType ) const |
|
105 { |
|
106 return iDescArray->Find( aPtr, aPos, aTextComparisonType ); |
|
107 } |
|
108 |
|
109 void CPlaylistItem::ExportL( RBufWriteStream& aStream ) const |
|
110 { |
|
111 TRACE_FUNC_ENTRY; |
|
112 |
|
113 aStream.WriteL( KUrl ); |
|
114 aStream.WriteL( *iUrl, iUrl->Length() ); |
|
115 aStream.WriteL( KLineFeed ); |
|
116 |
|
117 aStream.WriteL( KTitle ); |
|
118 aStream.WriteL( *iTitle, iTitle->Length() ); |
|
119 aStream.WriteL( KLineFeed ); |
|
120 |
|
121 TInt count = iDescArray->MdcaCount(); |
|
122 for ( TInt i=0; i<count; i++ ) |
|
123 { |
|
124 TPtrC16 ptr16 = iDescArray->MdcaPoint( i ); |
|
125 aStream.WriteL( ptr16, ptr16.Length() ); |
|
126 aStream.WriteL( KLineFeed ); |
|
127 } |
|
128 |
|
129 aStream.CommitL(); |
|
130 TRACE_FUNC_EXIT; |
|
131 } |
|
132 |
|
133 void CPlaylistItem::ImportL( const TDesC& aBuffer ) |
|
134 { |
|
135 TRACE_FUNC_ENTRY; |
|
136 iDescArray->Reset(); |
|
137 TPtrC tag; |
|
138 TPtrC data; |
|
139 TInt currentPos(0); |
|
140 TInt lineLen(0); |
|
141 TBool eof(EFalse); |
|
142 while( !eof ) |
|
143 { |
|
144 lineLen = ReadNextLine( aBuffer.Mid(currentPos), data ); |
|
145 if ( lineLen >= 0) |
|
146 { |
|
147 if ( data.FindF( KTitle ) == 0 ) |
|
148 { |
|
149 TPtrC title = data.Mid( KTitle().Length() ); |
|
150 SetTitleL( title ); |
|
151 } |
|
152 else if ( data.FindF( KCommentChar ) == 0 ) |
|
153 { |
|
154 // ignore comment |
|
155 } |
|
156 else if ( data.Length() > 0 ) |
|
157 { |
|
158 // must be song url |
|
159 AddItemL( data ); |
|
160 } |
|
161 } |
|
162 else |
|
163 { |
|
164 eof = ETrue; |
|
165 } |
|
166 currentPos += lineLen; |
|
167 if ( currentPos >= aBuffer.Length() ) |
|
168 { |
|
169 eof = ETrue; |
|
170 } |
|
171 } |
|
172 TRACE_FUNC_EXIT; |
|
173 } |
|
174 |
|
175 void CPlaylistItem::AddItemL( const TDesC& aSongUri ) |
|
176 { |
|
177 //LOGGER_WRITE_1("AddItem: %S", &aSongUri); |
|
178 TFileName uri(aSongUri); |
|
179 uri.LowerCase(); |
|
180 uri.TrimAll(); |
|
181 iDescArray->InsertIsqAllowDuplicatesL( uri ); |
|
182 } |
|
183 |
|
184 TInt CPlaylistItem::ReadNextLine( const TDesC& aBuffer, TPtrC& aLine ) |
|
185 { |
|
186 //TRACE_FUNC_ENTRY; |
|
187 TInt lineLen = aBuffer.FindF( KLineFeed ); |
|
188 |
|
189 if ( lineLen == KErrNotFound ) |
|
190 { |
|
191 lineLen = aBuffer.Length(); |
|
192 if ( lineLen == 0 ) |
|
193 { |
|
194 //TRACE_FUNC_RET( lineLen ); |
|
195 return KErrNotFound; |
|
196 } |
|
197 } |
|
198 |
|
199 aLine.Set( aBuffer.Mid( 0, lineLen )); |
|
200 //LOGGER_WRITE_1("aLine: %S", &aLine); |
|
201 lineLen += 2; |
|
202 //TRACE_FUNC_RET( lineLen ); |
|
203 return lineLen; |
|
204 } |
|