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: |
|
15 * The source file for mde tone fetcher. |
|
16 * |
|
17 */ |
|
18 #include "toneselectionengine_p.h" |
|
19 #include <XQConversions> |
|
20 #include <pathinfo.h> |
|
21 #include <bautils.h> |
|
22 #include "tonepreviewprivate.h" |
|
23 #include "tonefetcherengine.h" |
|
24 #include <centralrepository.h> |
|
25 #include <ProfileEngineDomainCRKeys.h> |
|
26 #include <cplogger.h> |
|
27 |
|
28 |
|
29 CTimeOutTimer* CTimeOutTimer::NewL(ToneSelectionEnginePrivate& aObserver) |
|
30 { |
|
31 CTimeOutTimer* self = CTimeOutTimer::NewLC(aObserver); |
|
32 CleanupStack::Pop(self); |
|
33 return self; |
|
34 } |
|
35 |
|
36 |
|
37 |
|
38 CTimeOutTimer* CTimeOutTimer::NewLC(ToneSelectionEnginePrivate& aObserver) |
|
39 { |
|
40 CTimeOutTimer* self = new (ELeave) CTimeOutTimer(aObserver); |
|
41 CleanupStack::PushL(self); |
|
42 self->ConstructL(); |
|
43 return self; |
|
44 } |
|
45 |
|
46 |
|
47 |
|
48 CTimeOutTimer::CTimeOutTimer(ToneSelectionEnginePrivate& aObserver) |
|
49 : CTimer(EPriorityStandard), |
|
50 iObserver( aObserver ) |
|
51 { |
|
52 |
|
53 } |
|
54 |
|
55 |
|
56 |
|
57 CTimeOutTimer::~CTimeOutTimer() |
|
58 { |
|
59 Cancel(); |
|
60 } |
|
61 |
|
62 |
|
63 |
|
64 void CTimeOutTimer::ConstructL() |
|
65 { |
|
66 CTimer::ConstructL(); |
|
67 CActiveScheduler::Add(this); |
|
68 } |
|
69 |
|
70 |
|
71 |
|
72 void CTimeOutTimer::RunL() |
|
73 { |
|
74 iObserver.ChangeObject(); |
|
75 } |
|
76 |
|
77 ToneSelectionEnginePrivate::ToneSelectionEnginePrivate( ToneFetcherEngine *engine ) : mServiceEngine( engine ) |
|
78 |
|
79 { |
|
80 iSession = CMdESession::NewL( *this ); |
|
81 |
|
82 iTimer = CTimeOutTimer::NewLC( *this ); |
|
83 iContinue = EFalse; |
|
84 iTimerStarted = EFalse; |
|
85 iFreshing = EFalse; |
|
86 CleanupStack::Pop(); |
|
87 |
|
88 |
|
89 } |
|
90 |
|
91 ToneSelectionEnginePrivate::~ToneSelectionEnginePrivate() |
|
92 { |
|
93 delete iQuery; |
|
94 delete iSession; |
|
95 } |
|
96 |
|
97 void ToneSelectionEnginePrivate::HandleSessionOpened( CMdESession& /*aSession*/, TInt aError ) |
|
98 { |
|
99 if ( aError != KErrNone ) |
|
100 { |
|
101 delete iSession; |
|
102 iSession = 0; |
|
103 iSessionOpen = EFalse; |
|
104 emit mdeSessionError( aError ); |
|
105 } |
|
106 else |
|
107 { |
|
108 iSessionOpen = ETrue; |
|
109 TRAP_IGNORE( AddObjectObserverL() ); |
|
110 emit mdeSessionOpened(); |
|
111 } |
|
112 } |
|
113 |
|
114 |
|
115 |
|
116 void ToneSelectionEnginePrivate::HandleSessionError( CMdESession& /*aSession*/, TInt aError ) |
|
117 { |
|
118 if ( aError == KErrNone ) |
|
119 { |
|
120 return; |
|
121 } |
|
122 |
|
123 delete iSession; |
|
124 iSession = 0; |
|
125 iSessionOpen = EFalse; |
|
126 emit mdeSessionError( aError ); |
|
127 } |
|
128 |
|
129 |
|
130 void ToneSelectionEnginePrivate::HandleQueryNewResults( CMdEQuery& /*aQuery*/, |
|
131 TInt /*aFirstNewItemIndex*/, |
|
132 TInt /*aNewItemCount*/ ) |
|
133 { |
|
134 } |
|
135 |
|
136 void ToneSelectionEnginePrivate::HandleObjectNotification( CMdESession& /*aSession*/, |
|
137 TObserverNotificationType aType, |
|
138 const RArray<TItemId>& aObjectIdArray ) |
|
139 { |
|
140 if ( aObjectIdArray.Count() > 0 && ( aType == ENotifyAdd || aType == ENotifyModify || aType == ENotifyRemove ) ) |
|
141 { |
|
142 CPFW_LOG("ToneSelectionEnginePrivate::HandleObjectNotification count = " + QVariant(aObjectIdArray.Count()).toString() + " type = " + QVariant(aType).toString()); |
|
143 const TInt KOneSecond = 1000*1000; |
|
144 if ( !iFreshing ) |
|
145 { |
|
146 emit notifyRefreshStart(); |
|
147 iFreshing = ETrue; |
|
148 } |
|
149 if ( !iTimerStarted ) |
|
150 { |
|
151 iTimer->After( 5 * KOneSecond ); |
|
152 iTimerStarted = ETrue; |
|
153 } |
|
154 iContinue = ETrue; |
|
155 } |
|
156 } |
|
157 |
|
158 void ToneSelectionEnginePrivate::AddObjectObserverL() |
|
159 { |
|
160 if ( iSessionOpen ) |
|
161 { |
|
162 TUint32 notificationType = ENotifyAdd | ENotifyModify | ENotifyRemove; |
|
163 CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL(); |
|
164 iSession->AddObjectObserverL( *this, 0, notificationType, &defNS ); |
|
165 |
|
166 iSession->AddObjectPresentObserverL( *this ); |
|
167 } |
|
168 } |
|
169 |
|
170 void ToneSelectionEnginePrivate::HandleObjectPresentNotification( CMdESession& /*aSession*/, |
|
171 TBool /*aPresent*/, const RArray<TItemId>& aObjectIdArray ) |
|
172 { |
|
173 if( aObjectIdArray.Count() > 0 ) |
|
174 { |
|
175 const TInt KOneSecond = 1000*1000; |
|
176 if ( !iFreshing ) |
|
177 { |
|
178 emit notifyRefreshStart(); |
|
179 iFreshing = ETrue; |
|
180 } |
|
181 if ( !iTimerStarted ) |
|
182 { |
|
183 iTimer->After( 5 * KOneSecond ); |
|
184 iTimerStarted = ETrue; |
|
185 } |
|
186 iContinue = ETrue; |
|
187 } |
|
188 } |
|
189 |
|
190 void ToneSelectionEnginePrivate::HandleQueryCompleted( CMdEQuery& aQuery, TInt aError ) |
|
191 { |
|
192 iNameList.clear(); |
|
193 iUriList.clear(); |
|
194 if ( aError == KErrCancel ) |
|
195 { |
|
196 emit queryError( aError ); |
|
197 return; |
|
198 } |
|
199 else |
|
200 { |
|
201 CMdEObjectQuery* query = static_cast<CMdEObjectQuery*> (&aQuery); |
|
202 TInt count = query->Count(); |
|
203 for (TInt i = 0; i < count; ++i) |
|
204 { |
|
205 CMdEObject* object = |
|
206 (CMdEObject*) query->TakeOwnershipOfResult(i); |
|
207 CleanupStack::PushL(object); |
|
208 CMdEPropertyDef& propDef = |
|
209 ToneSelectionEnginePrivate::PropertyDefL( iSession, ToneSelectionEnginePrivate::EAttrSongName ); |
|
210 |
|
211 CMdEProperty* property = 0; |
|
212 TInt err = object->Property( propDef, property, 0 ); |
|
213 if ( err != KErrNotFound && property ) |
|
214 { |
|
215 QString songName( XQConversions::s60DescToQString( property->TextValueL() ) ); |
|
216 QString uriValue( XQConversions::s60DescToQString( object->Uri() ) ); |
|
217 iNameList.append( songName ); |
|
218 iUriList.append( uriValue ); |
|
219 } |
|
220 CleanupStack::PopAndDestroy(object); |
|
221 } |
|
222 emit queryComplete(iNameList, iUriList ); |
|
223 } |
|
224 } |
|
225 |
|
226 void ToneSelectionEnginePrivate::QueryTones() |
|
227 { |
|
228 LeaveIfSessionClosedL(); |
|
229 |
|
230 CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL(); |
|
231 CMdEObjectDef& musicObjectDef = |
|
232 defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject ); |
|
233 |
|
234 delete iQuery; |
|
235 iQuery = 0; |
|
236 iQuery = iSession->NewObjectQueryL( defNS, musicObjectDef, this ); |
|
237 |
|
238 |
|
239 // set attributes that are included in query result |
|
240 CMdEPropertyDef& namePropertyDef = PropertyDefL( EAttrSongName ); |
|
241 iQuery->AddPropertyFilterL( &namePropertyDef ); |
|
242 |
|
243 iQuery->SetResultMode( EQueryResultModeItem ); |
|
244 |
|
245 CMdELogicCondition& conditions = iQuery->Conditions(); |
|
246 ExcludeMusicPropertiesL( conditions ); |
|
247 |
|
248 iQuery->FindL(); |
|
249 } |
|
250 |
|
251 void ToneSelectionEnginePrivate::LeaveIfSessionClosedL() |
|
252 { |
|
253 if ( !iSession || !iSessionOpen ) |
|
254 { |
|
255 User::Leave( KErrDisconnected ); |
|
256 } |
|
257 } |
|
258 |
|
259 CMdEPropertyDef& ToneSelectionEnginePrivate::PropertyDefL( TInt aAttr ) |
|
260 { |
|
261 return PropertyDefL( iSession, aAttr ); |
|
262 } |
|
263 |
|
264 CMdEPropertyDef& ToneSelectionEnginePrivate::PropertyDefL( CMdESession* aSession, TInt aAttr ) |
|
265 { |
|
266 CMdENamespaceDef& defNS = aSession->GetDefaultNamespaceDefL(); |
|
267 |
|
268 CMdEObjectDef& objectDef = |
|
269 defNS.GetObjectDefL( MdeConstants::Audio::KAudioObject ); |
|
270 |
|
271 if ( aAttr == EAttrFileSize ) |
|
272 { |
|
273 return objectDef.GetPropertyDefL( MdeConstants::Object::KSizeProperty ); |
|
274 } |
|
275 else if ( aAttr == EAttrMediaType ) |
|
276 { |
|
277 return objectDef.GetPropertyDefL( MdeConstants::Object::KItemTypeProperty ); |
|
278 } |
|
279 else if ( aAttr == EAttrSongName || aAttr == EAttrFileName ) |
|
280 { |
|
281 return objectDef.GetPropertyDefL( MdeConstants::Object::KTitleProperty ); |
|
282 } |
|
283 else if ( aAttr == EAttrArtist ) |
|
284 { |
|
285 return objectDef.GetPropertyDefL( MdeConstants::MediaObject::KArtistProperty ); |
|
286 } |
|
287 else if ( aAttr == EAttrAlbum ) |
|
288 { |
|
289 return objectDef.GetPropertyDefL( MdeConstants::Audio::KAlbumProperty ); |
|
290 } |
|
291 else if ( aAttr == EAttrGenre ) |
|
292 { |
|
293 return objectDef.GetPropertyDefL( MdeConstants::MediaObject::KGenreProperty ); |
|
294 } |
|
295 else if ( aAttr == EAttrComposer ) |
|
296 { |
|
297 return objectDef.GetPropertyDefL( MdeConstants::Audio::KComposerProperty ); |
|
298 } |
|
299 else |
|
300 { |
|
301 User::Leave( KErrNotSupported ); |
|
302 } |
|
303 |
|
304 return objectDef.GetPropertyDefL( MdeConstants::Object::KTitleProperty ); |
|
305 } |
|
306 |
|
307 void ToneSelectionEnginePrivate::ExcludeMusicPropertiesL( CMdELogicCondition& aCondition ) |
|
308 { |
|
309 TInt sizeLimitKB = 0; |
|
310 CRepository* cenrep = CRepository::NewL( KCRUidProfileEngine ); |
|
311 CleanupStack::PushL( cenrep ); |
|
312 User::LeaveIfError( cenrep->Get( KProEngRingingToneMaxSize, sizeLimitKB ) ); |
|
313 CleanupStack::PopAndDestroy(); // cenrep |
|
314 |
|
315 SetAttr( ToneFetcherEngine::EAttrFileSize, sizeLimitKB ); |
|
316 CMdEPropertyDef& sizeTypeDef = PropertyDefL( EAttrFileSize ); |
|
317 CMdEPropertyDef& mimeTypeDef = PropertyDefL( EAttrMediaType ); |
|
318 CMdEPropertyDef& artistTypeDef = PropertyDefL( EAttrArtist ); |
|
319 CMdEPropertyDef& albumTypeDef = PropertyDefL( EAttrAlbum ); |
|
320 CMdEPropertyDef& genreTypeDef = PropertyDefL( EAttrGenre ); |
|
321 CMdEPropertyDef& composerTypeDef = PropertyDefL( EAttrComposer ); |
|
322 |
|
323 CMdELogicCondition& condition = |
|
324 aCondition.AddLogicConditionL( ELogicConditionOperatorAnd ); |
|
325 condition.AddPropertyConditionL( sizeTypeDef, TMdEIntRange(0, iMaxFileSize, EMdERangeTypeBetween) ); |
|
326 condition.AddPropertyConditionL( mimeTypeDef, |
|
327 ETextPropertyConditionCompareContains, KMimeMp3 ); |
|
328 condition.AddPropertyConditionL( artistTypeDef ); |
|
329 condition.AddPropertyConditionL( albumTypeDef ); |
|
330 condition.AddPropertyConditionL( genreTypeDef ); |
|
331 condition.AddPropertyConditionL( composerTypeDef ); |
|
332 |
|
333 condition.SetNegate( ETrue ); |
|
334 } |
|
335 |
|
336 void ToneSelectionEnginePrivate::SetAttr( int attr, int value ) |
|
337 { |
|
338 switch ( attr ) |
|
339 { |
|
340 case ToneFetcherEngine::EAttrFileSize: |
|
341 { |
|
342 iMaxFileSize = value; |
|
343 break; |
|
344 } |
|
345 default: |
|
346 { |
|
347 break; |
|
348 } |
|
349 } |
|
350 } |
|
351 |
|
352 void ToneSelectionEnginePrivate::ChangeObject() |
|
353 { |
|
354 if ( iTimerStarted ) |
|
355 { |
|
356 emit notifyObjectChanged(); |
|
357 iTimerStarted = EFalse; |
|
358 } |
|
359 |
|
360 if ( iContinue ) |
|
361 { |
|
362 iContinue = EFalse; |
|
363 iTimer->After( 5000*1000 ); |
|
364 iTimerStarted = ETrue; |
|
365 } |
|
366 else |
|
367 { |
|
368 if ( iFreshing ) |
|
369 { |
|
370 emit notifyRefreshFinish(); |
|
371 iFreshing = EFalse; |
|
372 } |
|
373 } |
|
374 } |
|
375 // End of File |
|
376 |
|