|
1 /* |
|
2 * Copyright (c) 2008 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: Notifies mpx |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 class MMPXCollection; |
|
20 |
|
21 #include <mpxcollectionmediator.h> |
|
22 #include <mpxharvesterutility.h> |
|
23 #include <mpxcollectionutility.h> |
|
24 #include <mpxmediageneraldefs.h> // for KMPXMediaGeneralCollectionId |
|
25 #include <mpxmediamusicdefs.h> // music-specific attribute keys |
|
26 #include <upnpitem.h> // s60 upnp stack |
|
27 #include <escapeutils.h> // for unicode conversion |
|
28 #include "upnpitemutility.h" // for FindElementByName & ResourceFromItemL |
|
29 #include "upnpconstantdefs.h" // for element names |
|
30 #include "cmfmmpxnotifier.h" |
|
31 #include "msdebug.h" |
|
32 |
|
33 // CONSTANTS |
|
34 const TUid KMpxLocalCollectionUid = { 0x101FFC3A }; |
|
35 const TUid KCmServerUid = { 0x10281FA7 }; |
|
36 |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // CCmFmMpxNotifier::NewL |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CCmFmMpxNotifier* CCmFmMpxNotifier::NewL( ) |
|
43 { |
|
44 LOG(_L("[FILL MNGR]\t CCmFmMpxNotifier::NewL() start")); |
|
45 CCmFmMpxNotifier* self = CCmFmMpxNotifier::NewLC( ); |
|
46 CleanupStack::Pop( self ); |
|
47 LOG(_L("[FILL MNGR]\t CCmFmMpxNotifier::NewL() end")); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // CCmFmMpxNotifier::NewLC |
|
53 // --------------------------------------------------------------------------- |
|
54 // |
|
55 CCmFmMpxNotifier* CCmFmMpxNotifier::NewLC( ) |
|
56 { |
|
57 LOG(_L("[FILL MNGR]\t CCmFmMpxNotifier::NewLC() start")); |
|
58 CCmFmMpxNotifier* self = new ( ELeave ) CCmFmMpxNotifier( ); |
|
59 CleanupStack::PushL( self ); |
|
60 self->ConstructL(); |
|
61 LOG(_L("[FILL MNGR]\t CCmFmMpxNotifier::NewLC() end")); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CCmFmMpxNotifier::~CCmFmMpxNotifier |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 CCmFmMpxNotifier::~CCmFmMpxNotifier() |
|
70 { |
|
71 LOG(_L("[FILL MNGR]\t CCmFmMpxNotifier::~CCmFmMpxNotifier()")); |
|
72 if( iHarvester ) |
|
73 { |
|
74 iHarvester->Close(); |
|
75 } |
|
76 if( iCollectionUtil ) |
|
77 { |
|
78 iCollectionUtil->Close(); |
|
79 } |
|
80 delete iMediator; |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // CCmFmMpxNotifier::CCmFmMpxNotifier |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 CCmFmMpxNotifier::CCmFmMpxNotifier( ) |
|
88 { |
|
89 LOG(_L("[FILL MNGR]\t CCmFmMpxNotifier::CCmFmMpxNotifier")); |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // CCmFmMpxNotifier::ConstructL |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 void CCmFmMpxNotifier::ConstructL() |
|
97 { |
|
98 LOG(_L("[FILL MNGR]\t CCmFmMpxNotifier::ConstructL")); |
|
99 |
|
100 iHarvester = CMPXHarvesterFactory::NewL(); |
|
101 iCollectionUtil = MMPXCollectionUtility::NewL( 0, KCmServerUid ); |
|
102 |
|
103 iMediator = CMPXCollectionMediator::NewL( |
|
104 iCollectionUtil->Collection(), this ); |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // CCmFmMpxNotifier::NotifyMpxL |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 void CCmFmMpxNotifier::NotifyMpxL( const TDesC& aTrackPath, |
|
112 const CUpnpItem& aTrackMetadata ) |
|
113 { |
|
114 LOG(_L("[FILL MNGR]\t CCmFmMpxNotifier::NotifyMpxL")); |
|
115 |
|
116 CMPXMedia* item = CMPXMedia::NewL(); |
|
117 CleanupStack::PushL( item ); |
|
118 item->SetTObjectValueL<TUid>( |
|
119 KMPXMediaGeneralCollectionId, KMpxLocalCollectionUid ); |
|
120 item->SetTObjectValueL<TMPXGeneralType>( |
|
121 KMPXMediaGeneralType, EMPXItem ); |
|
122 item->SetTObjectValueL<TMPXGeneralCategory>( |
|
123 KMPXMediaGeneralCategory, EMPXSong ); |
|
124 item->SetTextValueL( |
|
125 KMPXMediaGeneralUri, aTrackPath ); |
|
126 // Insert metadata |
|
127 HBufC16* buf = NULL; |
|
128 // title |
|
129 buf = EscapeUtils::ConvertToUnicodeFromUtf8L( aTrackMetadata.Title() ); |
|
130 CleanupStack::PushL( buf ); |
|
131 if( buf ) |
|
132 { |
|
133 item->SetTextValueL( |
|
134 KMPXMediaGeneralTitle, *buf ); |
|
135 } |
|
136 CleanupStack::PopAndDestroy( buf ); |
|
137 // artist |
|
138 if ( ( buf = GetElementL( aTrackMetadata, KElementCreator ) ) != 0 ) |
|
139 { |
|
140 CleanupStack::PushL( buf ); |
|
141 item->SetTextValueL( |
|
142 KMPXMediaMusicArtist, *buf ); |
|
143 CleanupStack::PopAndDestroy( buf ); |
|
144 } |
|
145 else if ( ( buf = GetElementL( aTrackMetadata, KElementArtist ) ) != 0 ) |
|
146 { |
|
147 CleanupStack::PushL( buf ); |
|
148 item->SetTextValueL( |
|
149 KMPXMediaMusicArtist, *buf ); |
|
150 CleanupStack::PopAndDestroy( buf ); |
|
151 } |
|
152 // album |
|
153 if ( ( buf = GetElementL( aTrackMetadata, KElementAlbum ) ) != 0 ) |
|
154 { |
|
155 CleanupStack::PushL( buf ); |
|
156 item->SetTextValueL( |
|
157 KMPXMediaMusicAlbum, *buf ); |
|
158 CleanupStack::PopAndDestroy( buf ); |
|
159 } |
|
160 // genre |
|
161 if ( ( buf = GetElementL( aTrackMetadata, KElementGenre ) ) != 0 ) |
|
162 { |
|
163 CleanupStack::PushL( buf ); |
|
164 item->SetTextValueL( |
|
165 KMPXMediaMusicGenre, *buf ); |
|
166 CleanupStack::PopAndDestroy( buf ); |
|
167 } |
|
168 |
|
169 // tracknumber |
|
170 if ( ( buf = GetElementL( aTrackMetadata, KElementTrackNumber ) ) != 0 ) |
|
171 { |
|
172 CleanupStack::PushL( buf ); |
|
173 TLex16 iLex(*buf); |
|
174 TInt tracknumber(0); |
|
175 iLex.Val(tracknumber); |
|
176 item->SetTObjectValueL<TInt>( |
|
177 KMPXMediaMusicAlbumTrack, tracknumber ); |
|
178 CleanupStack::PopAndDestroy( buf ); |
|
179 } |
|
180 |
|
181 |
|
182 // year |
|
183 const CUpnpElement* elem = UPnPItemUtility::FindElementByName( |
|
184 aTrackMetadata, KElementDate ); |
|
185 if ( elem != 0 ) |
|
186 { |
|
187 TTime timestamp; |
|
188 TInt err = |
|
189 UPnPItemUtility::UPnPDateAsTTime( elem->Value(), timestamp ); |
|
190 if( err == KErrNone ) |
|
191 { |
|
192 item->SetTObjectValueL<TInt64>( |
|
193 KMPXMediaMusicYear, timestamp.Int64() ); |
|
194 } |
|
195 } |
|
196 |
|
197 // duration |
|
198 const CUpnpElement* trackResource = |
|
199 &UPnPItemUtility::ResourceFromItemL( aTrackMetadata ); |
|
200 |
|
201 if( trackResource != 0 ) |
|
202 { |
|
203 const CUpnpAttribute* attr = UPnPItemUtility |
|
204 ::FindAttributeByName( *trackResource, KAttributeDuration ); |
|
205 |
|
206 if ( attr != 0 ) |
|
207 { |
|
208 TInt ms = 0; |
|
209 UPnPItemUtility |
|
210 ::UPnPDurationAsMilliseconds( attr->Value(), ms ); |
|
211 |
|
212 item->SetTObjectValueL<TInt>( |
|
213 KMPXMediaGeneralDuration, ms ); |
|
214 } |
|
215 } |
|
216 |
|
217 // Add to harvester |
|
218 TRACE(Print(_L("[FILL MNGR]\t iHarvester->AddFileL "))); |
|
219 TInt colUid = iHarvester->AddFileL( item ); |
|
220 |
|
221 // Add to collection, make sure we set the collection ID |
|
222 item->SetTObjectValueL<TUid>( |
|
223 KMPXMediaGeneralCollectionId, TUid::Uid( colUid ) ); |
|
224 |
|
225 TRACE(Print(_L("[FILL MNGR]\t iMediator->AddItemL "))); |
|
226 iMediator->AddItemL( item ); |
|
227 |
|
228 CleanupStack::PopAndDestroy( item ); |
|
229 TRACE(Print(_L("[FILL MNGR]\t CCmFmMpxNotifier::NotifyMpxL end"))); |
|
230 } |
|
231 |
|
232 // -------------------------------------------------------------------------- |
|
233 // CCmFmMpxNotifier::GetElementL |
|
234 // -------------------------------------------------------------------------- |
|
235 // |
|
236 HBufC16* CCmFmMpxNotifier::GetElementL( |
|
237 const CUpnpItem& aSource, const TDesC8& aSourceField ) const |
|
238 { |
|
239 LOG(_L("[FILL MNGR]\t CCmFmMpxNotifier::GetElementL")); |
|
240 HBufC16* result = 0; |
|
241 const CUpnpElement* elem = UPnPItemUtility::FindElementByName( |
|
242 aSource, aSourceField ); |
|
243 if ( elem != 0 ) |
|
244 { |
|
245 result = EscapeUtils::ConvertToUnicodeFromUtf8L( elem->Value() ); |
|
246 } |
|
247 return result; |
|
248 } |
|
249 |
|
250 // End of file |
|
251 |
|
252 |