|
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 // |
|
16 |
|
17 #include <bautils.h> |
|
18 #include <f32file.h> |
|
19 #include <e32math.h> |
|
20 #include <e32def.h> |
|
21 #include <caf/content.h> |
|
22 |
|
23 #include <mtp/tmtptyperequest.h> |
|
24 #include <mtp/mmtpdataproviderframework.h> |
|
25 #include <mtp/cmtpobjectmetadata.h> |
|
26 #include <mtp/mmtpobjectmgr.h> |
|
27 #include <mtp/mtpprotocolconstants.h> |
|
28 #include <mtp/cmtpdataproviderplugin.h> |
|
29 |
|
30 #include "rmtputility.h" |
|
31 #include "cmtpdataprovidercontroller.h" |
|
32 #include "cmtpextensionmapping.h" |
|
33 #include "cmtpdataprovider.h" |
|
34 |
|
35 using namespace ContentAccess; |
|
36 // Class constants. |
|
37 const TInt KMTPDateStringLength = 15; |
|
38 const TInt KMTPDateStringTIndex = 8; |
|
39 const TInt KMimeTypeMaxLength = 76; |
|
40 const TInt KMAXPackageIDStringLen = 32; |
|
41 |
|
42 _LIT( KTxtBackSlash, "\\" ); |
|
43 |
|
44 _LIT( KTxtExtensionODF, ".odf" ); |
|
45 |
|
46 _LIT( KMimeTypeAudio3gpp, "audio/3gpp" ); |
|
47 _LIT( KMimeTypeVideo3gpp, "video/3gpp" ); |
|
48 _LIT( KMimeTypeAudioMp4, "audio/mp4" ); |
|
49 _LIT( KMimeTypeVideoMp4, "video/mp4" ); |
|
50 |
|
51 __FLOG_STMT(_LIT8(KComponent,"RMTPUtility");) |
|
52 |
|
53 RMTPUtility::RMTPUtility(): |
|
54 iFramework(NULL) |
|
55 { |
|
56 } |
|
57 |
|
58 void RMTPUtility::OpenL(MMTPDataProviderFramework& aFramework) |
|
59 { |
|
60 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
61 __FLOG(_L8("OpenL - Entry")); |
|
62 |
|
63 iFramework = &aFramework; |
|
64 iSingleton.OpenL(); |
|
65 |
|
66 __FLOG(_L8("OpenL - Exit")); |
|
67 } |
|
68 |
|
69 void RMTPUtility::Close() |
|
70 { |
|
71 iSingleton.Close(); |
|
72 iFramework = NULL; |
|
73 iFormatMappings.ResetAndDestroy(); |
|
74 __FLOG_CLOSE; |
|
75 } |
|
76 |
|
77 /* |
|
78 * Convert the TTime to the MTP datatime string |
|
79 * |
|
80 * MTP datatime string format: YYYYMMDDThhmmss.s Optional(.s) |
|
81 * TTime string format : YYYYMMDD:HHMMSS.MMMMMM |
|
82 * |
|
83 */ |
|
84 EXPORT_C TBool RMTPUtility::TTime2MTPTimeStr(const TTime& aTime, TDes& aRet ) const |
|
85 { |
|
86 _LIT(KMTPDateStringFormat,"%F%Y%M%DT%H%T%S"); |
|
87 TRAPD(err, aTime.FormatL(aRet,KMTPDateStringFormat)); |
|
88 if(err == KErrNone) |
|
89 { |
|
90 return ETrue; |
|
91 } |
|
92 else |
|
93 { |
|
94 return EFalse; |
|
95 } |
|
96 } |
|
97 |
|
98 /* |
|
99 * Convert the MTP datatime string to TTime: |
|
100 * |
|
101 * MTP datatime string format: YYYYMMDDThhmmss.s Optional(.s) |
|
102 * TTime string format : YYYYMMDD:HHMMSS.MMMMMM |
|
103 * |
|
104 */ |
|
105 EXPORT_C TBool RMTPUtility::MTPTimeStr2TTime(const TDesC& aTimeString, TTime& aRet) const |
|
106 { |
|
107 __FLOG(_L8("ConvertMTPTimeStr2TTimeL - Entry")); |
|
108 |
|
109 TBool result = EFalse; |
|
110 TInt year = 0; |
|
111 TMonth month = EJanuary; |
|
112 TInt day = 0; |
|
113 TInt hour = 0; |
|
114 TInt minute = 0; |
|
115 TInt second = 0; |
|
116 TInt tenthSecond = 0; |
|
117 TBool positiveTimeZone = ETrue; |
|
118 TInt timeZoneInHour = 0; |
|
119 TInt timeZoneInMinute = 0; |
|
120 |
|
121 const TChar KCharT = 'T'; |
|
122 if( aTimeString.Length() >= KMTPDateStringLength && ( aTimeString.Locate(KCharT) == KMTPDateStringTIndex ) && GetYear(aTimeString, year) && GetMonth(aTimeString, month) && |
|
123 GetDay(aTimeString, day) && GetHour(aTimeString, hour) && GetMinute(aTimeString, minute) && |
|
124 GetSecond(aTimeString, second) && GetTenthSecond(aTimeString, tenthSecond) && GetTimeZone(aTimeString, positiveTimeZone, timeZoneInHour, timeZoneInMinute)) |
|
125 { |
|
126 TDateTime dateTime(year, month, day, hour, minute, second, tenthSecond * 100000); |
|
127 |
|
128 TTime dateTimeInTTime(dateTime); |
|
129 if(positiveTimeZone) |
|
130 { |
|
131 dateTimeInTTime += TTimeIntervalHours(timeZoneInHour); |
|
132 dateTimeInTTime += TTimeIntervalMinutes(timeZoneInMinute); |
|
133 } |
|
134 else |
|
135 { |
|
136 dateTimeInTTime -= TTimeIntervalHours(timeZoneInHour); |
|
137 dateTimeInTTime -= TTimeIntervalMinutes(timeZoneInMinute); |
|
138 } |
|
139 |
|
140 aRet = dateTimeInTTime.Int64(); |
|
141 result = ETrue; |
|
142 } |
|
143 |
|
144 return result; |
|
145 } |
|
146 |
|
147 TBool RMTPUtility::GetYear(const TDesC& aTimeString, TInt& aYear) const |
|
148 { |
|
149 aYear = 0; |
|
150 TLex dateBuf(aTimeString.Left(4)); |
|
151 return dateBuf.Val(aYear) == KErrNone; |
|
152 } |
|
153 |
|
154 TBool RMTPUtility::GetMonth(const TDesC& aTimeString, TMonth& aMonth) const |
|
155 { |
|
156 TBool result = EFalse; |
|
157 aMonth = EJanuary; |
|
158 TInt month = 0; |
|
159 TLex dateBuf(aTimeString.Mid(4, 2)); |
|
160 if(dateBuf.Val(month) == KErrNone && month > 0 && month < 13) |
|
161 { |
|
162 month--; |
|
163 aMonth = (TMonth)month; |
|
164 result = ETrue; |
|
165 } |
|
166 return result; |
|
167 } |
|
168 |
|
169 TBool RMTPUtility::GetDay(const TDesC& aTimeString, TInt& aDay) const |
|
170 { |
|
171 TBool result = EFalse; |
|
172 aDay = 0; |
|
173 TLex dateBuf(aTimeString.Mid(6, 2)); |
|
174 if(dateBuf.Val(aDay) == KErrNone && aDay > 0 && aDay < 32) |
|
175 { |
|
176 aDay--; |
|
177 result = ETrue; |
|
178 } |
|
179 return result; |
|
180 } |
|
181 |
|
182 TBool RMTPUtility::GetHour(const TDesC& aTimeString, TInt& aHour) const |
|
183 { |
|
184 aHour = 0; |
|
185 TLex dateBuf(aTimeString.Mid(9, 2)); |
|
186 return (dateBuf.Val(aHour) == KErrNone && aHour >=0 && aHour < 60); |
|
187 } |
|
188 |
|
189 TBool RMTPUtility::GetMinute(const TDesC& aTimeString, TInt& aMinute) const |
|
190 { |
|
191 aMinute = 0; |
|
192 TLex dateBuf(aTimeString.Mid(11, 2)); |
|
193 return (dateBuf.Val(aMinute) == KErrNone && aMinute >=0 && aMinute < 60); |
|
194 } |
|
195 |
|
196 TBool RMTPUtility::GetSecond(const TDesC& aTimeString, TInt& aSecond) const |
|
197 { |
|
198 aSecond = 0; |
|
199 TLex dateBuf(aTimeString.Mid(13, 2)); |
|
200 return (dateBuf.Val(aSecond) == KErrNone && aSecond >= 0 && aSecond < 60); |
|
201 } |
|
202 |
|
203 TBool RMTPUtility::GetTenthSecond(const TDesC& aTimeString, TInt& aTenthSecond) const |
|
204 { |
|
205 TBool result = EFalse; |
|
206 aTenthSecond = 0; |
|
207 TInt dotPos = aTimeString.Find(_L(".")); |
|
208 if(dotPos != KErrNotFound && dotPos == KMTPDateStringLength && aTimeString.Length() > KMTPDateStringLength + 1) |
|
209 { |
|
210 TLex dateBuf(aTimeString.Mid(dotPos + 1, 1)); |
|
211 result = (dateBuf.Val(aTenthSecond) == KErrNone && aTenthSecond >=0 && aTenthSecond < 10); |
|
212 } |
|
213 else if(dotPos == KErrNotFound) |
|
214 { |
|
215 result = ETrue; |
|
216 } |
|
217 |
|
218 return result; |
|
219 } |
|
220 |
|
221 TBool RMTPUtility::GetTimeZone(const TDesC& aTimeString, TBool& aPositiveTimeZone, TInt& aTimeZoneInHour, TInt& aTimeZoneInMinute) const |
|
222 { |
|
223 TBool result = EFalse; |
|
224 aTimeZoneInHour = 0; |
|
225 aTimeZoneInMinute = 0; |
|
226 TInt plusTimeZonePos = aTimeString.Find(_L("+")); |
|
227 TInt minusTimeZonePos = aTimeString.Find(_L("-")); |
|
228 TInt timeZoneIndicatorPos = Max(plusTimeZonePos, minusTimeZonePos); |
|
229 aPositiveTimeZone = (plusTimeZonePos != KErrNotFound); |
|
230 if(timeZoneIndicatorPos != KErrNotFound) |
|
231 { |
|
232 if(aTimeString.Length() - timeZoneIndicatorPos == 5) |
|
233 { |
|
234 TLex dateBuf(aTimeString.Mid(timeZoneIndicatorPos + 1, 2)); |
|
235 if(dateBuf.Val(aTimeZoneInHour) == KErrNone) |
|
236 { |
|
237 dateBuf.Assign(aTimeString.Mid(timeZoneIndicatorPos + 3, 2)); |
|
238 if(dateBuf.Val(aTimeZoneInMinute) == KErrNone) |
|
239 { |
|
240 result = ETrue; |
|
241 } |
|
242 } |
|
243 } |
|
244 } |
|
245 else |
|
246 { |
|
247 result = ETrue; |
|
248 } |
|
249 return result; |
|
250 } |
|
251 |
|
252 EXPORT_C void RMTPUtility::RenameObjectL( TUint aObjectHandle, const TDesC& aNewName ) |
|
253 { |
|
254 __FLOG(_L8("RenameAssocationObjectL - Entry")); |
|
255 |
|
256 CMTPObjectMetaData* meta = CMTPObjectMetaData::NewLC(); |
|
257 |
|
258 if( !iFramework->ObjectMgr().ObjectL(aObjectHandle, *meta) ) |
|
259 { |
|
260 User::Leave(KErrNotFound); |
|
261 } |
|
262 |
|
263 if( !BaflUtils::FileExists( iFramework->Fs(), meta->DesC(CMTPObjectMetaData::ESuid) ) ) |
|
264 { |
|
265 User::Leave(KErrNotFound); |
|
266 } |
|
267 |
|
268 TFileName filename; |
|
269 User::LeaveIfError(BaflUtils::MostSignificantPartOfFullName(meta->DesC(CMTPObjectMetaData::ESuid), filename)); |
|
270 RBuf oldFullName; |
|
271 oldFullName.CleanupClosePushL(); |
|
272 |
|
273 TInt maxLen = (KMaxFileName > meta->DesC(CMTPObjectMetaData::ESuid).Length()? KMaxFileName: meta->DesC(CMTPObjectMetaData::ESuid).Length()); |
|
274 oldFullName.CreateL(maxLen); |
|
275 oldFullName = meta->DesC(CMTPObjectMetaData::ESuid); |
|
276 |
|
277 // Update the folder name using the new passed value. |
|
278 RBuf newFullName; |
|
279 newFullName.CleanupClosePushL(); |
|
280 newFullName.CreateL(maxLen); |
|
281 newFullName.Append(oldFullName); |
|
282 if(meta->Uint(CMTPObjectMetaData::EFormatCode) == EMTPFormatCodeAssociation) |
|
283 { |
|
284 newFullName.SetLength(newFullName.Length() - filename.Length() - 1); |
|
285 } |
|
286 else |
|
287 { |
|
288 newFullName.SetLength(newFullName.Length() - filename.Length()); |
|
289 } |
|
290 |
|
291 maxLen = newFullName.Length() + aNewName.Length() + 1; |
|
292 if(maxLen > newFullName.MaxLength()) |
|
293 { |
|
294 newFullName.ReAllocL(maxLen); |
|
295 } |
|
296 newFullName.Append(aNewName); |
|
297 |
|
298 if(meta->Uint(CMTPObjectMetaData::EFormatCode) != EMTPFormatCodeAssociation) |
|
299 { |
|
300 // Modify the filename |
|
301 User::LeaveIfError( iFramework->Fs().Rename(meta->DesC(CMTPObjectMetaData::ESuid), newFullName) ); |
|
302 |
|
303 meta->SetDesCL( CMTPObjectMetaData::ESuid, newFullName ); |
|
304 iFramework->ObjectMgr().ModifyObjectL(*meta); |
|
305 } |
|
306 else |
|
307 { |
|
308 // Add backslash. |
|
309 _LIT(KBackSlash, "\\"); |
|
310 newFullName.Append(KBackSlash); |
|
311 // Modify the filename |
|
312 User::LeaveIfError( iFramework->Fs().Rename(meta->DesC(CMTPObjectMetaData::ESuid), newFullName) ); |
|
313 |
|
314 meta->SetDesCL( CMTPObjectMetaData::ESuid, newFullName ); |
|
315 iFramework->ObjectMgr().ModifyObjectL(*meta); |
|
316 |
|
317 RenameAllChildrenL( meta->Uint(CMTPObjectMetaData::EStorageId), meta->Uint(CMTPObjectMetaData::EHandle), newFullName, oldFullName); |
|
318 |
|
319 if(meta->Uint(CMTPObjectMetaData::EFormatCode) == EMTPFormatCodeAssociation) |
|
320 { |
|
321 TMTPNotificationParamsHandle param = { meta->Uint(CMTPObjectMetaData::EHandle) ,oldFullName}; |
|
322 iSingleton.DpController().NotifyDataProvidersL(EMTPRenameObject, static_cast<TAny*>(¶m)); |
|
323 } |
|
324 } |
|
325 |
|
326 CleanupStack::PopAndDestroy(3);//oldFullName, newFullName,meta |
|
327 __FLOG(_L8("RenameAssocationObjectL - Exit")); |
|
328 } |
|
329 |
|
330 EXPORT_C TMTPFormatCode RMTPUtility::FormatFromFilename( const TDesC& aFullFileName ) |
|
331 { |
|
332 if ( aFullFileName.Right( 1 ).CompareF( KTxtBackSlash ) == 0 ) |
|
333 { |
|
334 return EMTPFormatCodeAssociation; |
|
335 } |
|
336 |
|
337 TParsePtrC file( aFullFileName ); |
|
338 |
|
339 if ( file.Ext().CompareF( KTxtExtensionODF ) == 0 ) |
|
340 { |
|
341 HBufC* mime =ContainerMimeType( file.FullName() ); |
|
342 |
|
343 // 3GP |
|
344 if ( mime->CompareF( KMimeTypeAudio3gpp ) == 0 || mime->CompareF( KMimeTypeVideo3gpp ) == 0) |
|
345 { |
|
346 delete mime; |
|
347 mime = NULL; |
|
348 return EMTPFormatCode3GPContainer; |
|
349 } |
|
350 else if ( mime->CompareF( KMimeTypeAudioMp4 ) == 0 || mime->CompareF( KMimeTypeVideoMp4 ) == 0 ) |
|
351 { |
|
352 delete mime; |
|
353 mime = NULL; |
|
354 return EMTPFormatCodeMP4Container; |
|
355 } |
|
356 if ( mime != NULL ) |
|
357 { |
|
358 delete mime; |
|
359 mime = NULL; |
|
360 } |
|
361 } |
|
362 |
|
363 return EMTPFormatCodeUndefined; |
|
364 } |
|
365 |
|
366 EXPORT_C HBufC* RMTPUtility::ContainerMimeType( const TDesC& aFullPath ) |
|
367 { |
|
368 |
|
369 TParsePtrC file( aFullPath ); |
|
370 HBufC* mime = NULL; |
|
371 TInt err = KErrNone; |
|
372 |
|
373 if ( file.Ext().CompareF( KTxtExtensionODF ) == 0 ) |
|
374 { |
|
375 TRAP( err, mime = OdfMimeTypeL( aFullPath ) ); |
|
376 } |
|
377 |
|
378 return mime; |
|
379 } |
|
380 |
|
381 EXPORT_C void RMTPUtility::FormatExtensionMapping() |
|
382 { |
|
383 TInt count = iSingleton.DpController().Count(); |
|
384 |
|
385 while(count--) |
|
386 { |
|
387 CDesCArraySeg* FormatExtensionMapping = new (ELeave) CDesCArraySeg(4); |
|
388 CleanupStack::PushL(FormatExtensionMapping); |
|
389 TRAP_IGNORE(iSingleton.DpController().DataProviderByIndexL(count).Plugin().SupportedL(EFormatExtensionSets,*FormatExtensionMapping)); |
|
390 AppendFormatExtensionMapping(*FormatExtensionMapping,iSingleton.DpController().DataProviderByIndexL(count).DataProviderId()); |
|
391 CleanupStack::PopAndDestroy(FormatExtensionMapping); |
|
392 } |
|
393 } |
|
394 |
|
395 EXPORT_C TMTPFormatCode RMTPUtility::GetFormatByExtension(const TDesC& aExtension) |
|
396 { |
|
397 CMTPExtensionMapping* extensionMapping = CMTPExtensionMapping::NewL(aExtension, EMTPFormatCodeUndefined); |
|
398 CleanupStack::PushL(extensionMapping); |
|
399 TInt found = iFormatMappings.FindInOrder(extensionMapping, TLinearOrder<CMTPExtensionMapping>(CMTPExtensionMapping::Compare)); |
|
400 if ( KErrNotFound != found) |
|
401 { |
|
402 CleanupStack::PopAndDestroy(extensionMapping); |
|
403 return iFormatMappings[found]->FormatCode(); |
|
404 } |
|
405 CleanupStack::PopAndDestroy(extensionMapping); |
|
406 return EMTPFormatCodeUndefined; |
|
407 } |
|
408 |
|
409 EXPORT_C TUint32 RMTPUtility::GetDpId(const TDesC& aExtension,const TDesC& aMIMEType) |
|
410 { |
|
411 CMTPExtensionMapping* extensionMapping = CMTPExtensionMapping::NewL(aExtension, EMTPFormatCodeUndefined,aMIMEType); |
|
412 CleanupStack::PushL(extensionMapping); |
|
413 TInt found = iFormatMappings.FindInOrder(extensionMapping, TLinearOrder<CMTPExtensionMapping>(CMTPExtensionMapping::ComparewithMIME)); |
|
414 if ( KErrNotFound != found) |
|
415 { |
|
416 CleanupStack::PopAndDestroy(extensionMapping); |
|
417 return iFormatMappings[found]->DpId(); |
|
418 } |
|
419 CleanupStack::PopAndDestroy(extensionMapping); |
|
420 return 255; |
|
421 } |
|
422 |
|
423 EXPORT_C TUint RMTPUtility::GetEnumerationFlag(const TDesC& aExtension) |
|
424 { |
|
425 CMTPExtensionMapping* extensionMapping = CMTPExtensionMapping::NewL(aExtension, EMTPFormatCodeUndefined); |
|
426 CleanupStack::PushL(extensionMapping); |
|
427 TInt found = iFormatMappings.FindInOrder(extensionMapping, TLinearOrder<CMTPExtensionMapping>(CMTPExtensionMapping::Compare)); |
|
428 if ( KErrNotFound != found) |
|
429 { |
|
430 CleanupStack::PopAndDestroy(extensionMapping); |
|
431 return iFormatMappings[found]->EnumerationFlag(); |
|
432 } |
|
433 CleanupStack::PopAndDestroy(extensionMapping); |
|
434 return 1; |
|
435 } |
|
436 |
|
437 |
|
438 void RMTPUtility::RenameAllChildrenL(TUint32 aStorageId, TUint32 aParentHandle, const TDesC& aNewFolderName, const TDesC& aOldFolderName) |
|
439 { |
|
440 __FLOG(_L8("RenameAllChildrenL - Entry")); |
|
441 |
|
442 RMTPObjectMgrQueryContext context; |
|
443 RArray<TUint> handles; |
|
444 TMTPObjectMgrQueryParams params(aStorageId, KMTPFormatsAll, aParentHandle); |
|
445 CleanupClosePushL(context); |
|
446 CleanupClosePushL(handles); |
|
447 |
|
448 CMTPObjectMetaData* objectInfo(CMTPObjectMetaData::NewLC()); |
|
449 TInt count = 0; |
|
450 TEntry entry; |
|
451 |
|
452 do |
|
453 { |
|
454 iFramework->ObjectMgr().GetObjectHandlesL(params, context, handles); |
|
455 count = handles.Count(); |
|
456 |
|
457 for(TInt i(0); (i < count); i++) |
|
458 { |
|
459 if (!iFramework->ObjectMgr().ObjectL(handles[i], *objectInfo)) |
|
460 { |
|
461 User::Leave(KErrCorrupt); |
|
462 } |
|
463 |
|
464 /** |
|
465 * [SP-Format-0x3002]Special processing for PictBridge DP which own 6 dps file with format 0x3002, |
|
466 * but it does not really own the format 0x3002. |
|
467 * |
|
468 * Make the same behavior betwen 0x3000 and 0x3002. |
|
469 */ |
|
470 if( (objectInfo->Uint(CMTPObjectMetaData::EFormatCode) != EMTPFormatCodeAssociation) |
|
471 && (objectInfo->Uint(CMTPObjectMetaData::EFormatCode) != EMTPFormatCodeUndefined) |
|
472 && (objectInfo->Uint(CMTPObjectMetaData::EFormatCode) != EMTPFormatCodeScript) ) |
|
473 continue; |
|
474 |
|
475 RBuf entryName; |
|
476 entryName.CreateL(KMaxFileName); |
|
477 entryName.CleanupClosePushL(); |
|
478 entryName = objectInfo->DesC(CMTPObjectMetaData::ESuid); |
|
479 |
|
480 RBuf rightPartName; |
|
481 rightPartName.CreateL(KMaxFileName); |
|
482 rightPartName.CleanupClosePushL(); |
|
483 rightPartName = entryName.Right(entryName.Length() - aOldFolderName.Length()); |
|
484 |
|
485 if ((aNewFolderName.Length() + rightPartName.Length()) > entryName.MaxLength()) |
|
486 { |
|
487 entryName.ReAllocL(aNewFolderName.Length() + rightPartName.Length()); |
|
488 } |
|
489 |
|
490 entryName.Zero(); |
|
491 entryName.Append(aNewFolderName); |
|
492 entryName.Append(rightPartName); |
|
493 |
|
494 if (KErrNone != iFramework->Fs().Entry(entryName, entry)) |
|
495 { |
|
496 // Skip objects that don't use the file path as SUID. |
|
497 CleanupStack::PopAndDestroy(&entryName); |
|
498 continue; |
|
499 } |
|
500 |
|
501 // Recursively update all this object's children. |
|
502 // The maximum recursion depth is as deep as the association hierarchy. |
|
503 RenameAllChildrenL(objectInfo->Uint(CMTPObjectMetaData::EStorageId), objectInfo->Uint(CMTPObjectMetaData::EHandle), entryName, objectInfo->DesC(CMTPObjectMetaData::ESuid) ); |
|
504 |
|
505 TFileName oldfilename(objectInfo->DesC(CMTPObjectMetaData::ESuid)); |
|
506 objectInfo->SetDesCL(CMTPObjectMetaData::ESuid, entryName); |
|
507 iFramework->ObjectMgr().ModifyObjectL(*objectInfo); |
|
508 |
|
509 if(objectInfo->Uint(CMTPObjectMetaData::EFormatCode) == EMTPFormatCodeAssociation) |
|
510 { |
|
511 //Send the Rename notification |
|
512 TMTPNotificationParamsHandle param = { handles[i], oldfilename}; |
|
513 iSingleton.DpController().NotifyDataProvidersL(EMTPRenameObject, static_cast<TAny*>(¶m)); |
|
514 } |
|
515 CleanupStack::PopAndDestroy(2); // rightPartName, entryName |
|
516 } |
|
517 } |
|
518 while (!context.QueryComplete()); |
|
519 |
|
520 CleanupStack::PopAndDestroy(3);//objectInfo; &handles; &context |
|
521 |
|
522 __FLOG(_L8("RenameAllChildrenL - Exit")); |
|
523 } |
|
524 |
|
525 HBufC* RMTPUtility::OdfMimeTypeL( const TDesC& aFullPath ) |
|
526 { |
|
527 HBufC* mimebuf = NULL; |
|
528 |
|
529 TParsePtrC file( aFullPath ); |
|
530 |
|
531 if ( file.Ext().CompareF( KTxtExtensionODF ) == 0 ) |
|
532 { |
|
533 RFs tempFsSession; |
|
534 User::LeaveIfError(tempFsSession.Connect()); |
|
535 CleanupClosePushL(tempFsSession); |
|
536 User::LeaveIfError(tempFsSession.ShareProtected()); |
|
537 |
|
538 RFile tempFile; |
|
539 User::LeaveIfError(tempFile.Open(tempFsSession, aFullPath, EFileRead|EFileShareAny)); |
|
540 CleanupClosePushL(tempFile); |
|
541 |
|
542 //CContent* content = CContent::NewL( aFullPath ); |
|
543 CContent* content = CContent::NewL( tempFile ); |
|
544 CleanupStack::PushL( content ); // + content |
|
545 |
|
546 HBufC* buffer = HBufC::NewL( KMimeTypeMaxLength ); |
|
547 CleanupStack::PushL( buffer ); // + buffer |
|
548 |
|
549 TPtr data = buffer->Des(); |
|
550 TInt err = content->GetStringAttribute( EMimeType, data ); |
|
551 |
|
552 if ( err == KErrNone ) |
|
553 { |
|
554 mimebuf = HBufC::New( buffer->Length() ); |
|
555 |
|
556 if (mimebuf == NULL) |
|
557 { |
|
558 User::LeaveIfError( KErrNotFound ); |
|
559 } |
|
560 |
|
561 mimebuf->Des().Copy( *buffer ); |
|
562 } |
|
563 |
|
564 // leave if NULL |
|
565 if ( mimebuf == NULL ) |
|
566 { |
|
567 User::Leave( KErrNotFound ); |
|
568 } |
|
569 |
|
570 CleanupStack::PopAndDestroy( buffer ); // - buffer |
|
571 CleanupStack::PopAndDestroy( content ); // - content |
|
572 CleanupStack::PopAndDestroy(&tempFile); // close |
|
573 CleanupStack::PopAndDestroy(&tempFsSession); // close |
|
574 } |
|
575 else |
|
576 { |
|
577 User::Leave( KErrNotSupported ); |
|
578 } |
|
579 |
|
580 return mimebuf; |
|
581 } |
|
582 |
|
583 void RMTPUtility::AppendFormatExtensionMapping(const CDesCArray& aFormatExtensionMapping,TUint32 aDpId) |
|
584 { |
|
585 //Parse the descriptor formatcode,fileextension, e.g. 0x3009:mp3 |
|
586 TBuf<KMAXPackageIDStringLen> stringSeg; |
|
587 TInt splitter1(0); |
|
588 TInt splitter2(0); |
|
589 TInt found(0); |
|
590 TUint formatCode = 0; |
|
591 TUint isNeedFileDp = 1; |
|
592 |
|
593 for(TInt i=0; i < aFormatExtensionMapping.Count(); ++i) |
|
594 { |
|
595 CMTPExtensionMapping* extensionMapping = CMTPExtensionMapping::NewL(KNullDesC, EMTPFormatCodeUndefined); |
|
596 CleanupStack::PushL(extensionMapping); |
|
597 _LIT(KSPLITTER,":"); |
|
598 splitter1 = aFormatExtensionMapping[i].FindF(KSPLITTER); |
|
599 //Skip "0x", 2 is the length of "0x" |
|
600 stringSeg = aFormatExtensionMapping[i].Mid(2, 4); |
|
601 TLex lex(stringSeg); |
|
602 User::LeaveIfError(lex.Val(formatCode, EHex)); |
|
603 //Skip ":" |
|
604 stringSeg = aFormatExtensionMapping[i].Mid(splitter1 + 1); |
|
605 splitter2 = stringSeg.FindF(KSPLITTER); |
|
606 if ( splitter2 == KErrNotFound ) |
|
607 { |
|
608 extensionMapping->SetExtensionL(stringSeg); |
|
609 } |
|
610 else |
|
611 { |
|
612 extensionMapping->SetExtensionL(aFormatExtensionMapping[i].Mid(splitter1+1,splitter2)); |
|
613 stringSeg = stringSeg.Mid(splitter2+1); |
|
614 splitter1 = stringSeg.FindF(KSPLITTER); |
|
615 if ( splitter1==KErrNotFound ) |
|
616 { |
|
617 extensionMapping->SetMIMETypeL(stringSeg); |
|
618 } |
|
619 else if ( splitter1==0 ) |
|
620 { |
|
621 TLex lex1(stringSeg.Mid(splitter1+1)); |
|
622 User::LeaveIfError(lex1.Val(isNeedFileDp, EDecimal)); |
|
623 } |
|
624 else |
|
625 { |
|
626 extensionMapping->SetMIMETypeL(stringSeg.Mid(0,splitter1)); |
|
627 TLex lex2(stringSeg.Mid(splitter1+1)); |
|
628 User::LeaveIfError(lex2.Val(isNeedFileDp, EDecimal)); |
|
629 } |
|
630 |
|
631 } |
|
632 |
|
633 found = iFormatMappings.FindInOrder(extensionMapping, TLinearOrder<CMTPExtensionMapping>(CMTPExtensionMapping::ComparewithMIME)); |
|
634 if (KErrNotFound == found) |
|
635 { |
|
636 extensionMapping->SetFormatCode((TMTPFormatCode)formatCode); |
|
637 extensionMapping->SetDpId(aDpId); |
|
638 extensionMapping->SetEnumerationFlag(isNeedFileDp); |
|
639 iFormatMappings.InsertInOrderL(extensionMapping, TLinearOrder<CMTPExtensionMapping>(CMTPExtensionMapping::ComparewithMIME)); |
|
640 } |
|
641 CleanupStack::Pop(extensionMapping); |
|
642 } |
|
643 } |