|
1 /* |
|
2 * Copyright (c) 2010 Ixonos Plc. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "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 * Ixonos Plc |
|
14 * |
|
15 * Description: |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include <bautils.h> |
|
23 #include <eikenv.h> |
|
24 #include <badesca.h> |
|
25 #include <PathInfo.h> |
|
26 #include <sysutil.h> |
|
27 #include <DRMCommon.h> |
|
28 #include <AknUtils.h> |
|
29 #include <data_caging_path_literals.hrh> |
|
30 #include <AknListQueryDialog.h> |
|
31 #include <VedSimpleCutVideo.rsg> |
|
32 #include <BAUTILS.H> |
|
33 |
|
34 #include "VideoEditorUtils.h" |
|
35 #include "VideoEditorCommon.h" |
|
36 #include "VeiSettings.h" |
|
37 #include "VideoEditorDebugUtils.h" |
|
38 |
|
39 |
|
40 // CONSTANTS |
|
41 _LIT (KEditedSuffix, "-"); |
|
42 _LIT(KManualVideoEditorMifFile, "ManualVideoEditor.mif"); |
|
43 _LIT(KVideoEditorUiComponentsMifFile, "VideoEditorUiComponents.mif"); |
|
44 _LIT(KVideoEditorMbmFile, "VideoEditorBitmaps.mbm"); |
|
45 |
|
46 //============================================================================= |
|
47 EXPORT_C void VideoEditorUtils::NotifyNewMediaDocumentL ( |
|
48 RFs& /*aFsSession*/, |
|
49 const TDesC& aFileName ) |
|
50 { |
|
51 LOGFMT(KVideoEditorLogFile, "VideoEditorUtils::NotifyNewMediaDocumentL: In (%S)", &aFileName); |
|
52 LOG(KVideoEditorLogFile, "VideoEditorUtils::NotifyNewMediaDocumentL: Out"); |
|
53 } |
|
54 |
|
55 //============================================================================= |
|
56 EXPORT_C TInt VideoEditorUtils::GenerateNewDocumentNameL ( |
|
57 RFs& aFsSession, |
|
58 const TDesC& aSourceFileName, |
|
59 TDes& aTargetFileName, |
|
60 TVedVideoFormat aOutputFormat, |
|
61 TInt aTargetSizeEstimate, |
|
62 VideoEditor::TMemory aMemoryInUse ) |
|
63 { |
|
64 LOG(KVideoEditorLogFile, "VideoEditorUtils::GenerateNewDocumentNameL, in:"); |
|
65 LOGFMT4(KVideoEditorLogFile, "VideoEditorUtils::GenerateNewDocumentNameL 1\tSource file: %S, output format: %d, required space: %d, memory in use: %d", &aSourceFileName, aOutputFormat, aTargetSizeEstimate, aMemoryInUse); |
|
66 |
|
67 TInt err = KErrNone; |
|
68 |
|
69 // Set file name to parser |
|
70 TParsePtrC fileParse (aSourceFileName); |
|
71 |
|
72 // Test filename is already too long |
|
73 if (fileParse.NameAndExt().Length() > KMaxFileName - 5) |
|
74 { |
|
75 err = KErrArgument; |
|
76 } |
|
77 |
|
78 // Otherwise proceed to generate the filename |
|
79 else |
|
80 { |
|
81 // If the memory is specified as EMemAutomatic, the target is primarily |
|
82 // on the memory card, and if that is full, on the phone memory. |
|
83 // If EMemPhoneMemory or EMemMemoryCard is specified, only that one is used. |
|
84 VideoEditor::TMemory selectedMemoryInUse; |
|
85 aMemoryInUse == VideoEditor::EMemAutomatic ? |
|
86 selectedMemoryInUse = VideoEditor::EMemMemoryCard : |
|
87 selectedMemoryInUse = aMemoryInUse; |
|
88 |
|
89 // Find file suffix that is not yet used |
|
90 TInt val = 1; |
|
91 TFileName temp; |
|
92 |
|
93 // First try the above selected primary location. |
|
94 TFileName driveAndPath; |
|
95 if (selectedMemoryInUse == VideoEditor::EMemPhoneMemory) |
|
96 { |
|
97 driveAndPath.Copy( PathInfo::PhoneMemoryRootPath() ); |
|
98 } |
|
99 else |
|
100 { |
|
101 driveAndPath.Copy( PathInfo::MemoryCardRootPath() ); |
|
102 } |
|
103 driveAndPath.Append( PathInfo::VideosPath() ); |
|
104 TRAPD(errBafl, BaflUtils::EnsurePathExistsL (aFsSession, driveAndPath)); |
|
105 LOGFMT(KVideoEditorLogFile, "VideoEditorUtils::GenerateNewDocumentNameL 2, errBafl:%d", errBafl ); |
|
106 TBool primaryLocationFull = ( KErrNone != errBafl |
|
107 || !IsEnoughFreeSpaceToSaveL ( aFsSession, driveAndPath, aTargetSizeEstimate ) ); |
|
108 |
|
109 |
|
110 // If the memory is full, and the memory is selected as automatic, |
|
111 // try alternative location. |
|
112 if (primaryLocationFull && aMemoryInUse == VideoEditor::EMemAutomatic) |
|
113 { |
|
114 if (selectedMemoryInUse == VideoEditor::EMemMemoryCard) |
|
115 { |
|
116 driveAndPath.Copy (PathInfo::PhoneMemoryRootPath() ); |
|
117 } |
|
118 else |
|
119 { |
|
120 driveAndPath.Copy (PathInfo::MemoryCardRootPath() ); |
|
121 } |
|
122 driveAndPath.Append ( PathInfo::VideosPath() ); |
|
123 TBool secondaryLocationFull = ( !BaflUtils::FolderExists (aFsSession, driveAndPath) |
|
124 || !IsEnoughFreeSpaceToSaveL ( aFsSession, driveAndPath, aTargetSizeEstimate ) ); |
|
125 if (secondaryLocationFull) |
|
126 { |
|
127 err = KErrDiskFull; |
|
128 } |
|
129 } |
|
130 |
|
131 // Now sufficient disk space has been verified. |
|
132 // Proceed to generate the unique file name. |
|
133 if (KErrNone == err) |
|
134 { |
|
135 LOGFMT(KVideoEditorLogFile, "VideoEditorUtils::GenerateNewDocumentNameL 3, File will be saved to path: %S", &driveAndPath ); |
|
136 |
|
137 // Copy drive and path to temporary file name |
|
138 temp.Copy( driveAndPath ); |
|
139 |
|
140 // Add file name without suffix |
|
141 TPtrC name = fileParse.Name(); |
|
142 TInt offset = FindSuffix ( name ); |
|
143 if (offset == KErrNotFound) |
|
144 { |
|
145 temp.Append ( fileParse.Name() ); |
|
146 } |
|
147 else |
|
148 { |
|
149 temp.Append ( name.Left (offset) ); |
|
150 } |
|
151 |
|
152 temp.Append ( KEditedSuffix ); |
|
153 temp.AppendNumFixedWidth (val, EDecimal, 3); |
|
154 temp.Append ( aOutputFormat == EVedVideoFormat3GPP ? KExt3gp : KExtMp4 ); |
|
155 |
|
156 // Increase edit number until we find a file name that is not used |
|
157 while ( FileAlreadyExistsL(aFsSession, temp) ) |
|
158 { |
|
159 ++val; |
|
160 temp.Zero(); |
|
161 temp.Copy ( driveAndPath ); |
|
162 if (offset == KErrNotFound) |
|
163 { |
|
164 temp.Append ( fileParse.Name() ); |
|
165 } |
|
166 else |
|
167 { |
|
168 temp.Append ( name.Left (offset) ); |
|
169 } |
|
170 |
|
171 temp.Append ( KEditedSuffix ); |
|
172 if (val < 1000) |
|
173 { |
|
174 temp.AppendNumFixedWidth ( val, EDecimal, 3); |
|
175 } |
|
176 else |
|
177 { |
|
178 temp.AppendNumFixedWidth ( val, EDecimal, 4); |
|
179 } |
|
180 |
|
181 temp.Append ( aOutputFormat == EVedVideoFormat3GPP ? KExt3gp : KExtMp4 ); |
|
182 } |
|
183 |
|
184 // Set document name |
|
185 aTargetFileName.Copy ( temp ); |
|
186 } |
|
187 } |
|
188 |
|
189 LOGFMT(KVideoEditorLogFile, "VideoEditorUtils::GenerateNewDocumentNameL: out (%d)", err); |
|
190 return err; |
|
191 } |
|
192 |
|
193 |
|
194 //============================================================================= |
|
195 EXPORT_C TInt VideoEditorUtils::GenerateFileNameL ( |
|
196 RFs& aFsSession, |
|
197 const TDesC& aSourceFileName, |
|
198 TDes& aTargetFileName, |
|
199 TVedVideoFormat aOutputFormat, |
|
200 TInt aTargetSizeEstimate, |
|
201 TFileName aDrive ) |
|
202 { |
|
203 LOG(KVideoEditorLogFile, "VideoEditorUtils::GenerateNewDocumentNameL, in:"); |
|
204 LOGFMT4(KVideoEditorLogFile, "VideoEditorUtils::GenerateNewDocumentNameL 1\tSource file: %S, output format: %d, required space: %d, memory in use: %d", &aSourceFileName, &aOutputFormat, &aTargetSizeEstimate, &aDrive); |
|
205 |
|
206 TInt err = KErrNone; |
|
207 |
|
208 // Set file name to parser |
|
209 TParsePtrC fileParse (aSourceFileName); |
|
210 |
|
211 // Test if filename is already too long |
|
212 if (fileParse.NameAndExt().Length() > KMaxFileName - 5) |
|
213 { |
|
214 err = KErrArgument; |
|
215 } |
|
216 |
|
217 // Otherwise proceed to generate the filename |
|
218 else |
|
219 { |
|
220 // Find file suffix that is not yet used |
|
221 TInt val = 1; |
|
222 TFileName temp; |
|
223 |
|
224 TFileName driveAndPath = aDrive; |
|
225 driveAndPath.Append( PathInfo::VideosPath() ); |
|
226 |
|
227 // create the folder if it doesn't exist |
|
228 TRAPD(errBafl, BaflUtils::EnsurePathExistsL (aFsSession, driveAndPath)); |
|
229 LOGFMT(KVideoEditorLogFile, "VideoEditorUtils::GenerateNewDocumentNameL 2, errBafl:%d", errBafl ); |
|
230 |
|
231 TBool selectedLocationFull = ( KErrNone != errBafl |
|
232 |
|
233 || !IsEnoughFreeSpaceToSaveL ( aFsSession, driveAndPath, aTargetSizeEstimate ) ); |
|
234 |
|
235 if (selectedLocationFull) |
|
236 { |
|
237 err = KErrDiskFull; |
|
238 } |
|
239 |
|
240 // Now sufficient disk space has been verified. |
|
241 // Proceed to generate the unique file name. |
|
242 if (KErrNone == err) |
|
243 { |
|
244 LOGFMT(KVideoEditorLogFile, "VideoEditorUtils::GenerateNewDocumentNameL 3, File will be saved to path: %S", &driveAndPath ); |
|
245 |
|
246 // Copy drive and path to temporary file name |
|
247 temp.Copy( driveAndPath ); |
|
248 |
|
249 // Add file name without suffix |
|
250 TPtrC name = fileParse.Name(); |
|
251 |
|
252 TInt offset = FindSuffix ( name ); |
|
253 |
|
254 if (offset == KErrNotFound) |
|
255 { |
|
256 temp.Append ( fileParse.Name() ); |
|
257 } |
|
258 else |
|
259 { |
|
260 temp.Append ( name.Left (offset) ); |
|
261 } |
|
262 |
|
263 temp.Append ( KEditedSuffix ); |
|
264 temp.AppendNumFixedWidth (val, EDecimal, 3); |
|
265 temp.Append ( aOutputFormat == EVedVideoFormat3GPP ? KExt3gp : KExtMp4 ); |
|
266 |
|
267 // Increase edit number until we find a file name that is not used |
|
268 while ( FileAlreadyExistsL(aFsSession, temp) ) |
|
269 { |
|
270 ++val; |
|
271 temp.Zero(); |
|
272 temp.Copy ( driveAndPath ); |
|
273 if (offset == KErrNotFound) |
|
274 { |
|
275 temp.Append ( fileParse.Name() ); |
|
276 } |
|
277 else |
|
278 { |
|
279 temp.Append ( name.Left (offset) ); |
|
280 } |
|
281 |
|
282 temp.Append ( KEditedSuffix ); |
|
283 if (val < 1000) |
|
284 { |
|
285 temp.AppendNumFixedWidth ( val, EDecimal, 3); |
|
286 } |
|
287 else |
|
288 { |
|
289 temp.AppendNumFixedWidth ( val, EDecimal, 4); |
|
290 } |
|
291 |
|
292 temp.Append ( aOutputFormat == EVedVideoFormat3GPP ? KExt3gp : KExtMp4 ); |
|
293 } |
|
294 |
|
295 // Set document name |
|
296 aTargetFileName.Copy ( temp ); |
|
297 } |
|
298 } |
|
299 |
|
300 LOGFMT(KVideoEditorLogFile, "VideoEditorUtils::GenerateNewDocumentNameL: out (%d)", err); |
|
301 return err; |
|
302 } |
|
303 |
|
304 |
|
305 //============================================================================= |
|
306 EXPORT_C TBool VideoEditorUtils::IsEnoughFreeSpaceToSaveL( |
|
307 RFs& aFsSession, |
|
308 const TDesC& aFileName, |
|
309 TInt aSizeEstimate ) |
|
310 { |
|
311 LOGFMT(KVideoEditorLogFile, "VideoEditorUtils::IsEnoughFreeSpaceToSaveL: in: %S", &aFileName); |
|
312 |
|
313 TBool spaceBelowCriticalLevel( EFalse ); |
|
314 |
|
315 TParsePtrC fileParse (aFileName); |
|
316 |
|
317 TInt mmc = fileParse.Drive().Left(1).CompareF( PathInfo::MemoryCardRootPath().Left(1) ); |
|
318 if( mmc == 0 ) |
|
319 { |
|
320 spaceBelowCriticalLevel = SysUtil::MMCSpaceBelowCriticalLevelL( |
|
321 &aFsSession, aSizeEstimate ); |
|
322 } |
|
323 else |
|
324 { |
|
325 spaceBelowCriticalLevel = SysUtil::DiskSpaceBelowCriticalLevelL( |
|
326 &aFsSession, aSizeEstimate, EDriveC ); |
|
327 } |
|
328 |
|
329 LOGFMT(KVideoEditorLogFile, "VideoEditorUtils::IsEnoughFreeSpaceToSaveL: out: %d", !spaceBelowCriticalLevel); |
|
330 return !spaceBelowCriticalLevel; |
|
331 } |
|
332 |
|
333 //============================================================================= |
|
334 EXPORT_C TBool VideoEditorUtils::IsDrmProtectedL( const TDesC& aFileName ) |
|
335 { |
|
336 LOGFMT(KVideoEditorLogFile, "VideoEditorUtils::IsDrmProtectedL: in: %S", &aFileName); |
|
337 |
|
338 TBool isProtected = EFalse; |
|
339 DRMCommon* drm = DRMCommon::NewL(); |
|
340 CleanupStack::PushL (drm); |
|
341 drm->IsProtectedFile( aFileName, isProtected ); |
|
342 CleanupStack::PopAndDestroy (drm); |
|
343 |
|
344 LOGFMT(KVideoEditorLogFile, "VideoEditorUtils::IsDrmProtectedL: out: %d", isProtected); |
|
345 return isProtected; |
|
346 } |
|
347 |
|
348 //============================================================================= |
|
349 EXPORT_C TFileName VideoEditorUtils::IconFileNameAndPath( TInt aInconFileIndex ) |
|
350 { |
|
351 LOG(KVideoEditorLogFile, "VideoEditorUtils::IconFileNameAndPath: in:"); |
|
352 |
|
353 TFileName fileName; |
|
354 Dll::FileName(fileName); |
|
355 TParse p; |
|
356 |
|
357 switch (aInconFileIndex) |
|
358 { |
|
359 case KManualVideoEditorIconFileId: |
|
360 p.Set(KManualVideoEditorMifFile, &KDC_APP_BITMAP_DIR, &fileName); |
|
361 break; |
|
362 case KVideoEditorUiComponentsIconFileId: |
|
363 p.Set(KVideoEditorUiComponentsMifFile, &KDC_APP_BITMAP_DIR, &fileName); |
|
364 break; |
|
365 case KVeiNonScalableIconFileId: |
|
366 p.Set(KVideoEditorMbmFile, &KDC_APP_BITMAP_DIR, &fileName); |
|
367 break; |
|
368 default: |
|
369 User::Invariant(); |
|
370 } |
|
371 |
|
372 TPtrC fullName = p.FullName(); |
|
373 LOGFMT2(KVideoEditorLogFile, "VideoEditorUtils::IconFileNameAndPath: Id: %d, name: %S", aInconFileIndex, &fullName); |
|
374 |
|
375 return fullName; |
|
376 } |
|
377 |
|
378 //============================================================================= |
|
379 TInt VideoEditorUtils::FindSuffix ( |
|
380 const TDesC & aName |
|
381 ) |
|
382 { |
|
383 TInt offset = KErrNotFound; |
|
384 TInt l = aName.Length(); |
|
385 |
|
386 while (l) |
|
387 { |
|
388 l--; |
|
389 |
|
390 if ( l <= (aName.Length() - 3) && aName[l] == TChar('-') ) |
|
391 { |
|
392 offset = l; |
|
393 break; |
|
394 } |
|
395 else if ( aName[l] < 0x30 || aName[l] > 0x39 ) |
|
396 { |
|
397 break; |
|
398 } |
|
399 |
|
400 } |
|
401 |
|
402 return offset; |
|
403 } |
|
404 |
|
405 //============================================================================= |
|
406 TBool VideoEditorUtils::FileAlreadyExistsL ( RFs& aFsSession, const TDesC& aFileName ) |
|
407 { |
|
408 LOGFMT(KVideoEditorLogFile, "VideoEditorUtils::FileAlreadyExistsL: %S", &aFileName); |
|
409 |
|
410 TBool fileExists = BaflUtils::FileExists( aFsSession, aFileName ); |
|
411 |
|
412 LOGFMT(KVideoEditorLogFile, "VideoEditorUtils::FileAlreadyExistsL: Out: %d", fileExists); |
|
413 return fileExists; |
|
414 } |
|
415 |
|
416 //============================================================================= |
|
417 EXPORT_C void VideoEditorUtils::GetMGAlbumsListForMediaFileL ( |
|
418 RArray<TInt>& /*aAlbumIdList*/, |
|
419 const TDesC& /*aFileName*/ ) |
|
420 { |
|
421 LOG(KVideoEditorLogFile, "VideoEditorUtils::GetMGAlbumsListForMediaFileL: In" ); |
|
422 LOG(KVideoEditorLogFile, "VideoEditorUtils::GetMGAlbumsListForMediaFileL: Out" ); |
|
423 } |
|
424 |
|
425 |
|
426 //============================================================================= |
|
427 EXPORT_C void VideoEditorUtils::AddMediaFileToMGAlbumL( |
|
428 const TDesC& /*aFilename*/, |
|
429 TInt /*aAlbumId*/ ) |
|
430 { |
|
431 LOG(KVideoEditorLogFile, "VideoEditorUtils::AddMediaFileToMGAlbumL: In"); |
|
432 LOG(KVideoEditorLogFile, "VideoEditorUtils::AddMediaFileToMGAlbumL: Out"); |
|
433 } |
|
434 |
|
435 //============================================================================= |
|
436 EXPORT_C TBool VideoEditorUtils::IsLandscapeScreenOrientation() |
|
437 { |
|
438 TRect rect; |
|
439 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EScreen, rect); |
|
440 return rect.Width() > rect.Height(); |
|
441 } |
|
442 |
|
443 |
|
444 //============================================================================= |
|
445 EXPORT_C TInt VideoEditorUtils::LaunchQueryDialogL (const TDesC & aPrompt) |
|
446 { |
|
447 CAknQueryDialog * dlg = |
|
448 new (ELeave) CAknQueryDialog ( const_cast<TDesC&>(aPrompt) ); |
|
449 |
|
450 return dlg->ExecuteLD (R_VIE_CONFIRMATION_QUERY); |
|
451 } |
|
452 |
|
453 |
|
454 //============================================================================= |
|
455 EXPORT_C TInt VideoEditorUtils::LaunchListQueryDialogL ( |
|
456 MDesCArray * aTextItems, |
|
457 const TDesC & aPrompt |
|
458 ) |
|
459 { |
|
460 // Selected text item index |
|
461 TInt index (-1); |
|
462 |
|
463 // Create a new list dialog |
|
464 CAknListQueryDialog * dlg = new (ELeave) CAknListQueryDialog (&index); |
|
465 |
|
466 // Prepare list query dialog |
|
467 dlg->PrepareLC (R_VIE_LIST_QUERY); |
|
468 |
|
469 // Set heading |
|
470 dlg->QueryHeading()->SetTextL (aPrompt); |
|
471 |
|
472 // Set text item array |
|
473 dlg->SetItemTextArray (aTextItems); |
|
474 |
|
475 // Set item ownership |
|
476 dlg->SetOwnershipType (ELbmDoesNotOwnItemArray); |
|
477 |
|
478 // Execute |
|
479 if (dlg->RunLD()) |
|
480 { |
|
481 return index; |
|
482 } |
|
483 else |
|
484 { |
|
485 return -1; |
|
486 } |
|
487 } |
|
488 |
|
489 //============================================================================= |
|
490 EXPORT_C TInt VideoEditorUtils::LaunchSaveVideoQueryL () |
|
491 { |
|
492 // Create dialog heading and options |
|
493 HBufC * heading = CEikonEnv::Static()->AllocReadResourceLC ( R_VIE_QUERY_HEADING_SAVE ); |
|
494 HBufC * option1 = CEikonEnv::Static()->AllocReadResourceLC ( R_VIE_QUERY_SAVE_NEW ); |
|
495 HBufC * option2 = CEikonEnv::Static()->AllocReadResourceLC ( R_VIE_QUERY_SAVE_REPLACE ); |
|
496 |
|
497 // Query dialog texts |
|
498 CDesCArray * options = new (ELeave) CDesCArraySeg ( 2 ); |
|
499 CleanupStack::PushL (options); |
|
500 options->AppendL( option1->Des() ); |
|
501 options->AppendL( option2->Des() ); |
|
502 |
|
503 // Execute query dialog |
|
504 TInt ret = LaunchListQueryDialogL ( options, *heading ); |
|
505 |
|
506 options->Reset(); |
|
507 |
|
508 CleanupStack::PopAndDestroy( options ); |
|
509 CleanupStack::PopAndDestroy( option2 ); |
|
510 CleanupStack::PopAndDestroy( option1 ); |
|
511 CleanupStack::PopAndDestroy( heading ); |
|
512 |
|
513 return ret; |
|
514 } |
|
515 |
|
516 |
|
517 //============================================================================= |
|
518 EXPORT_C TInt VideoEditorUtils::LaunchSaveChangesQueryL () |
|
519 { |
|
520 // Create dialog prompt |
|
521 HBufC * prompt = CEikonEnv::Static()->AllocReadResourceLC ( R_VIE_QUERY_SAVE_CHANGES ); |
|
522 |
|
523 // Execute query dialog |
|
524 TInt ret = LaunchQueryDialogL ( *prompt ); |
|
525 |
|
526 CleanupStack::PopAndDestroy( prompt ); |
|
527 |
|
528 return ret; |
|
529 } |
|
530 |
|
531 // End of File |