|
1 /* |
|
2 * Copyright (c) 2010 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 |
|
19 // SYSTEM INCLUDES |
|
20 #include <XQConversions> |
|
21 #include <pathinfo.h> |
|
22 #include <bautils.h> |
|
23 #include <centralrepository.h> |
|
24 #include <ProfileEngineDomainCRKeys.h> |
|
25 |
|
26 // USER INCLUDES |
|
27 #include "msgaudioselectionengine.h" |
|
28 |
|
29 // CONSTANTS |
|
30 _LIT( KAmrMime, "audio/amr" ); |
|
31 |
|
32 MsgAudioSelectionEngine::MsgAudioSelectionEngine() |
|
33 { |
|
34 |
|
35 } |
|
36 |
|
37 MsgAudioSelectionEngine::~MsgAudioSelectionEngine() |
|
38 { |
|
39 delete iQuery; |
|
40 delete iSession; |
|
41 } |
|
42 |
|
43 |
|
44 void MsgAudioSelectionEngine::CreateMetaDataSession() |
|
45 { |
|
46 TRAP_IGNORE(iSession = CMdESession::NewL(*this)); |
|
47 } |
|
48 |
|
49 |
|
50 void MsgAudioSelectionEngine::HandleSessionOpened(CMdESession& /*aSession*/, |
|
51 TInt aError) |
|
52 { |
|
53 if (aError != KErrNone) |
|
54 { |
|
55 delete iSession; |
|
56 iSession = 0; |
|
57 iSessionOpen = EFalse; |
|
58 emit mdeSessionError(aError); |
|
59 } |
|
60 else |
|
61 { |
|
62 iSessionOpen = ETrue; |
|
63 TRAP_IGNORE( AddObjectObserverL() ); |
|
64 emit mdeSessionOpened(); |
|
65 } |
|
66 } |
|
67 |
|
68 void MsgAudioSelectionEngine::HandleSessionError(CMdESession& /*aSession*/, |
|
69 TInt aError) |
|
70 { |
|
71 if (aError == KErrNone) |
|
72 { |
|
73 return; |
|
74 } |
|
75 |
|
76 delete iSession; |
|
77 iSession = 0; |
|
78 iSessionOpen = EFalse; |
|
79 emit mdeSessionError(aError); |
|
80 } |
|
81 |
|
82 void MsgAudioSelectionEngine::HandleQueryNewResults(CMdEQuery& /*aQuery*/, |
|
83 TInt /*aFirstNewItemIndex*/, TInt /*aNewItemCount*/) |
|
84 { |
|
85 } |
|
86 |
|
87 void MsgAudioSelectionEngine::HandleObjectNotification( |
|
88 CMdESession& /*aSession*/, TObserverNotificationType aType, |
|
89 const RArray<TItemId>& /*aObjectIdArray*/) |
|
90 { |
|
91 if (aType == ENotifyAdd || aType == ENotifyModify || aType |
|
92 == ENotifyRemove) |
|
93 { |
|
94 emit notifyObjectChanged(); |
|
95 } |
|
96 } |
|
97 |
|
98 void MsgAudioSelectionEngine::AddObjectObserverL() |
|
99 { |
|
100 if (iSessionOpen) |
|
101 { |
|
102 TUint32 notificationType = ENotifyAdd | ENotifyModify | ENotifyRemove; |
|
103 User::LeaveIfNull(iSession); |
|
104 CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL(); |
|
105 iSession->AddObjectObserverL(*this, 0, notificationType, &defNS); |
|
106 iSession->AddObjectPresentObserverL(*this); |
|
107 } |
|
108 } |
|
109 |
|
110 void MsgAudioSelectionEngine::HandleObjectPresentNotification( |
|
111 CMdESession& /*aSession*/, TBool /*aPresent*/, |
|
112 const RArray<TItemId>& aObjectIdArray) |
|
113 { |
|
114 if (aObjectIdArray.Count() > 0) |
|
115 { |
|
116 emit notifyObjectChanged(); |
|
117 } |
|
118 } |
|
119 |
|
120 void MsgAudioSelectionEngine::HandleQueryCompleted(CMdEQuery& aQuery, |
|
121 TInt aError) |
|
122 { |
|
123 TRAP_IGNORE(HandleQueryCompletedL(aQuery, aError)); |
|
124 } |
|
125 |
|
126 void MsgAudioSelectionEngine::HandleQueryCompletedL(CMdEQuery& aQuery, |
|
127 TInt aError) |
|
128 { |
|
129 iNameList.clear(); |
|
130 iUriList.clear(); |
|
131 if (aError == KErrCancel) |
|
132 { |
|
133 emit queryError(aError); |
|
134 return; |
|
135 } |
|
136 else |
|
137 { |
|
138 CMdEObjectQuery* query = static_cast<CMdEObjectQuery*> (&aQuery); |
|
139 TInt count = query->Count(); |
|
140 for (TInt i = 0; i < count; ++i) |
|
141 { |
|
142 CMdEObject* object = |
|
143 (CMdEObject*) query->TakeOwnershipOfResult(i); |
|
144 CleanupStack::PushL(object); |
|
145 CMdEPropertyDef& propDef = MsgAudioSelectionEngine::PropertyDefL( |
|
146 iSession, MsgAudioSelectionEngine::EAttrFileName); |
|
147 |
|
148 CMdEProperty* property = 0; |
|
149 TInt err = object->Property(propDef, property, 0); |
|
150 if (err != KErrNotFound && property) |
|
151 { |
|
152 QString songName(XQConversions::s60DescToQString( |
|
153 property->TextValueL())); |
|
154 QString uriValue(XQConversions::s60DescToQString( |
|
155 object->Uri())); |
|
156 iNameList.append(songName); |
|
157 iUriList.append(uriValue); |
|
158 } |
|
159 CleanupStack::PopAndDestroy(object); |
|
160 } |
|
161 emit queryComplete(iNameList, iUriList); |
|
162 } |
|
163 } |
|
164 |
|
165 void MsgAudioSelectionEngine::QueryTones() |
|
166 { |
|
167 TRAP_IGNORE(QueryTonesL()); |
|
168 } |
|
169 |
|
170 void MsgAudioSelectionEngine::QueryTonesL() |
|
171 { |
|
172 LeaveIfSessionClosedL(); |
|
173 CMdENamespaceDef& defNS = iSession->GetDefaultNamespaceDefL(); |
|
174 CMdEObjectDef& musicObjectDef = defNS.GetObjectDefL( |
|
175 MdeConstants::Audio::KAudioObject); |
|
176 |
|
177 delete iQuery; |
|
178 iQuery = 0; |
|
179 iQuery = iSession->NewObjectQueryL(defNS, musicObjectDef, this); |
|
180 CMdEPropertyDef& titlePropertyDef = musicObjectDef.GetPropertyDefL( |
|
181 MdeConstants::Object::KTitleProperty); |
|
182 CMdEPropertyDef& typePropertyDef = musicObjectDef.GetPropertyDefL( |
|
183 MdeConstants::Object::KItemTypeProperty); |
|
184 |
|
185 // set attributes that are included in query result |
|
186 iQuery->AddPropertyFilterL(&titlePropertyDef); |
|
187 iQuery->AddPropertyFilterL(&typePropertyDef); |
|
188 |
|
189 iQuery->SetResultMode(EQueryResultModeItem); |
|
190 |
|
191 |
|
192 // get root condition |
|
193 CMdELogicCondition& conditions = iQuery->Conditions(); |
|
194 conditions.AddPropertyConditionL(typePropertyDef, |
|
195 ETextPropertyConditionCompareEquals, KAmrMime); |
|
196 |
|
197 iQuery->FindL(); |
|
198 } |
|
199 |
|
200 void MsgAudioSelectionEngine::LeaveIfSessionClosedL() |
|
201 { |
|
202 if (!iSession || !iSessionOpen) |
|
203 { |
|
204 User::Leave(KErrDisconnected); |
|
205 } |
|
206 } |
|
207 |
|
208 CMdEPropertyDef& MsgAudioSelectionEngine::PropertyDefL(TInt aAttr) |
|
209 { |
|
210 User::LeaveIfNull(iSession); |
|
211 return PropertyDefL(iSession, aAttr); |
|
212 } |
|
213 |
|
214 CMdEPropertyDef& MsgAudioSelectionEngine::PropertyDefL(CMdESession* aSession, |
|
215 TInt aAttr) |
|
216 { |
|
217 CMdENamespaceDef& defNS = aSession->GetDefaultNamespaceDefL(); |
|
218 |
|
219 CMdEObjectDef& objectDef = defNS.GetObjectDefL( |
|
220 MdeConstants::Audio::KAudioObject); |
|
221 |
|
222 if (aAttr == EAttrFileSize) |
|
223 { |
|
224 return objectDef.GetPropertyDefL(MdeConstants::Object::KSizeProperty); |
|
225 } |
|
226 else if (aAttr == EAttrMediaType) |
|
227 { |
|
228 return objectDef.GetPropertyDefL( |
|
229 MdeConstants::Object::KItemTypeProperty); |
|
230 } |
|
231 else if (aAttr == EAttrSongName || aAttr == EAttrFileName) |
|
232 { |
|
233 return objectDef.GetPropertyDefL(MdeConstants::Object::KTitleProperty); |
|
234 } |
|
235 else if (aAttr == EAttrArtist) |
|
236 { |
|
237 return objectDef.GetPropertyDefL( |
|
238 MdeConstants::MediaObject::KArtistProperty); |
|
239 } |
|
240 else if (aAttr == EAttrAlbum) |
|
241 { |
|
242 return objectDef.GetPropertyDefL(MdeConstants::Audio::KAlbumProperty); |
|
243 } |
|
244 else if (aAttr == EAttrGenre) |
|
245 { |
|
246 return objectDef.GetPropertyDefL( |
|
247 MdeConstants::MediaObject::KGenreProperty); |
|
248 } |
|
249 else if (aAttr == EAttrComposer) |
|
250 { |
|
251 return objectDef.GetPropertyDefL( |
|
252 MdeConstants::Audio::KComposerProperty); |
|
253 } |
|
254 else |
|
255 { |
|
256 User::Leave(KErrNotSupported); |
|
257 } |
|
258 |
|
259 return objectDef.GetPropertyDefL(MdeConstants::Object::KTitleProperty); |
|
260 } |
|
261 |
|
262 |
|
263 void MsgAudioSelectionEngine::SetAttr(int attr, int value) |
|
264 { |
|
265 switch (attr) |
|
266 { |
|
267 case MsgAudioSelectionEngine::EAttrFileSize: |
|
268 { |
|
269 iMaxFileSize = value; |
|
270 break; |
|
271 } |
|
272 default: |
|
273 { |
|
274 break; |
|
275 } |
|
276 } |
|
277 } |
|
278 // End of File |
|
279 |