imagingandcamerafws/imagingfws/src/Test/TImageDisplay/TImageDisplay.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <barsread.h>
       
    17 #include <bidi.h>
       
    18 #include <eikenv.h>
       
    19 #include <techview/eikchlst.h>
       
    20 #include <techview/eikinfo.h>
       
    21 #include <techview/eikmenup.h>
       
    22 #include <e32math.h>
       
    23 #include <badesca.h>
       
    24 #include <techview/eikon.rsg>
       
    25 #include <eikpriv.rsg>
       
    26 #include <bitmaptransforms.h>
       
    27 #include <icl/imagedisplayplugin.h>
       
    28 #include <icl/geniclimagedisplayext.h>
       
    29 
       
    30 #include "plugininfoarray.h"
       
    31 #include "TImageDisplayAppView.h"
       
    32 #include "TImageDisplayDlgs.h"
       
    33 
       
    34 #include "TImageDisplay.h"
       
    35 
       
    36 
       
    37 const TInt KVideoMinZoomFactor = -3;
       
    38 const TInt KVideoMaxZoomFactor = 3;
       
    39 
       
    40 const TInt KDefaultFolderDelay = 2000000; // 2s. Used when playing a folder
       
    41 
       
    42 const TInt KButtonMoveIncr = 16;
       
    43 
       
    44 const TInt KInfoBufferSize = 1024;
       
    45 const TInt KNoRotation=-1;
       
    46 const TInt KAutoRotate=(1<<16);
       
    47 
       
    48 _LIT(KDefPath, "C:\\");
       
    49 const TInt KShortestPossiblePath=4;
       
    50 
       
    51 // #define __CLEAR_BITMAPS_FIRST // for debugging purposes, get TImageViewer to clear bitmaps prior to
       
    52 							  // decode conversion. Really the codecs should do this, but...
       
    53 
       
    54 CPluginInfoArray* CPluginInfoArray::NewL()
       
    55 	{
       
    56 	CPluginInfoArray* self;
       
    57 	self = new (ELeave) CPluginInfoArray;
       
    58 	CleanupStack::PushL(self);
       
    59 	self->ConstructL();
       
    60 	CleanupStack::Pop(self);
       
    61 	return self;
       
    62 	}
       
    63 
       
    64 void CPluginInfoArray::ConstructL()
       
    65 	{
       
    66 	RefreshPluginListL();
       
    67 	}
       
    68 
       
    69 CPluginInfoArray::CPluginInfoArray()
       
    70 	{
       
    71 	}
       
    72 
       
    73 void CPluginInfoArray::Reset()
       
    74 	{
       
    75 	iPluginArray.ResetAndDestroy();
       
    76 	}
       
    77 
       
    78 void CPluginInfoArray::RefreshPluginListL()
       
    79 	{
       
    80 	Reset();
       
    81 	CImageEncoder::GetImageTypesL(iPluginArray);
       
    82 	}
       
    83 
       
    84 CPluginInfoArray::~CPluginInfoArray()
       
    85 	{
       
    86 	Reset();
       
    87 	}
       
    88 
       
    89 TInt CPluginInfoArray::MdcaCount() const
       
    90 	{
       
    91 	return iPluginArray.Count();
       
    92 	}
       
    93 
       
    94 TPtrC CPluginInfoArray::MdcaPoint(TInt aIndex) const
       
    95 	{
       
    96 	return iPluginArray[aIndex]->Description(); 
       
    97 	}
       
    98 
       
    99 TUid CPluginInfoArray::ImageType(TInt aIndex)
       
   100 	{
       
   101 	return iPluginArray[aIndex]->ImageType(); 
       
   102 	}
       
   103 
       
   104 TUid CPluginInfoArray::SubType(TInt aIndex)
       
   105 	{
       
   106 	return iPluginArray[aIndex]->SubType(); 
       
   107 	}
       
   108 
       
   109 // CFrameInfoDialog
       
   110 class CFrameInfoDialog : public CEikDialog
       
   111 	{
       
   112 public:
       
   113 	CFrameInfoDialog(const TDesC& aPropertiesText);
       
   114 
       
   115 protected:
       
   116 	void PreLayoutDynInitL();
       
   117 
       
   118 private:
       
   119 	const TDesC& iPropertiesText;
       
   120 	};
       
   121 
       
   122 CFrameInfoDialog::CFrameInfoDialog(const TDesC& aPropertiesText)
       
   123 	: iPropertiesText(aPropertiesText)
       
   124 	{
       
   125 	}
       
   126 
       
   127 void CFrameInfoDialog::PreLayoutDynInitL()
       
   128 	{
       
   129 	// Grab each Edwin and set the text.
       
   130 	CEikEdwin* page = static_cast<CEikEdwin*>(Control(EFramePropertiesPage));
       
   131 	page->SetTextL(&iPropertiesText);
       
   132 
       
   133 	}
       
   134 
       
   135 
       
   136 //
       
   137 // CVideoWalker
       
   138 //
       
   139 
       
   140 class CVideoWalker : public CActive
       
   141 	{
       
   142 public:
       
   143 	static CVideoWalker* NewL(CImgDisplAppUi* aAppUi);
       
   144 	~CVideoWalker();
       
   145 	TRequestStatus& ActiveStatus();
       
   146 	void SelfComplete(TInt aError);
       
   147 protected:
       
   148 	CVideoWalker(CImgDisplAppUi* aAppUi);
       
   149 	// from CActive
       
   150 	void RunL();
       
   151 	void DoCancel();
       
   152 protected:
       
   153 	CImgDisplAppUi*const iAppUi; // not owned
       
   154 	};
       
   155 
       
   156 
       
   157 //
       
   158 //  CImgDisplAppUi
       
   159 //
       
   160 
       
   161 CImgDisplAppUi::CImgDisplAppUi():
       
   162 			iRotationAngle(KNoRotation),
       
   163 			iDrmIntent(ContentAccess::EPeek),
       
   164 			iScalingQuality(CBitmapScaler::EMinimumQuality)
       
   165 	{
       
   166 	}
       
   167 
       
   168 void CImgDisplAppUi::ConstructL()
       
   169     {
       
   170 	CEikAppUi::ConstructL();
       
   171 
       
   172     iAppView = CImgDisplayAppView::NewL(ClientRect());
       
   173 
       
   174 	iBackgroundColor = KRgbWhite.Color16();
       
   175 	(void) iAppView->SetBackgroundColor(TRgb::Color16(iBackgroundColor), ENoDrawNow);
       
   176 
       
   177 	iWalker = CVideoWalker::NewL(this);
       
   178 	User::LeaveIfError(iTimer.CreateLocal());
       
   179 
       
   180 	// Note iStreamSeed deliberated left as 0 to give consistent behaviour
       
   181 
       
   182 	iSaveInfo.iImageTypeUid = KImageTypeJPGUid;
       
   183 	iSaveInfo.iBpp = 6;
       
   184 	iSaveInfo.iColor = ETrue;
       
   185 	iSaveInfo.iQualityFactor = 40;
       
   186 	iSaveInfo.iSampling = 2;
       
   187 	}
       
   188 
       
   189 CImgDisplAppUi::~CImgDisplAppUi()
       
   190 	{
       
   191 	Cancel();
       
   192 
       
   193 	if (iAppView)
       
   194 		{
       
   195 		RemoveFromStack(iAppView);
       
   196 		delete iAppView;
       
   197 		}
       
   198 	delete iFrameImageData;
       
   199 	delete iSaveUtil;
       
   200 	delete iImageDisplay;
       
   201 	delete iWalker;
       
   202 	iTimer.Close();
       
   203 	delete iDir;
       
   204 	}
       
   205 
       
   206 void CImgDisplAppUi::Cancel()
       
   207 	{
       
   208 	if (iWalker)
       
   209 		{
       
   210 		iWalker->Cancel(); // if active will callback on DoCancel()
       
   211 		}
       
   212 	iState = EIdle;
       
   213 	}
       
   214 
       
   215 TKeyResponse CImgDisplAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   216 	{
       
   217 	TKeyResponse ret = EKeyWasConsumed;
       
   218 
       
   219 	if (aType!=EEventKey)
       
   220 		return ret;
       
   221 
       
   222 	TUint code = aKeyEvent.iCode;
       
   223 
       
   224 	switch (code)
       
   225 		{
       
   226 	case EKeyLeftArrow:
       
   227 	case EKeyRightArrow:
       
   228 	case EKeyUpArrow:
       
   229 	case EKeyDownArrow:
       
   230 		{
       
   231 		TPoint moveBy;
       
   232 		switch (code)
       
   233 			{
       
   234 		case EKeyLeftArrow:
       
   235 			moveBy.SetXY(KButtonMoveIncr,0);
       
   236 			break;
       
   237 		case EKeyRightArrow:
       
   238 			moveBy.SetXY(-KButtonMoveIncr,0);
       
   239 			break;
       
   240 		case EKeyUpArrow:
       
   241 			moveBy.SetXY(0,KButtonMoveIncr);
       
   242 			break;
       
   243 		case EKeyDownArrow:
       
   244 			moveBy.SetXY(0,-KButtonMoveIncr);
       
   245 			break;
       
   246 			}
       
   247 		iAppView->MoveBy(moveBy);
       
   248 		}
       
   249 		break;
       
   250 	case EKeyEscape:
       
   251 		Cancel();
       
   252 		ASSERT(iState==EIdle);
       
   253 		iEikonEnv->BusyMsgCancel();
       
   254 		iEikonEnv->InfoMsg(_L("Cancelled"));
       
   255 		break;
       
   256 	default:
       
   257 		ret = EKeyWasNotConsumed;
       
   258 		break;
       
   259 		}
       
   260 	return ret;
       
   261 	}
       
   262 
       
   263 void CImgDisplAppUi::HandleCommandL(TInt aCommand)
       
   264 	{
       
   265 	switch (aCommand)
       
   266 		{
       
   267 	case EVideoCmdOpenFile:
       
   268 		OpenFileL(EFileTypeUnknown);
       
   269 		break;
       
   270 	case EVideoCmdOpenFolder:
       
   271 		OpenFolderL();
       
   272 		break;
       
   273 	case EVideoCmdSaveAs:
       
   274 		SaveAsL();
       
   275 		break;
       
   276 	case EVideoCmdMask:
       
   277 		iDisableMask = ! iDisableMask;
       
   278 		if (iDisableMask)
       
   279 			{
       
   280 			iEikonEnv->InfoMsg(_L("Mask reset"));
       
   281 			}
       
   282 		else
       
   283 			{
       
   284 			iEikonEnv->InfoMsg(_L("Mask enabled"));
       
   285 			}
       
   286 
       
   287 		break;
       
   288 	case EVideoCmdToggleFrameDump:
       
   289 		iDumpFrames = !iDumpFrames;
       
   290 		if (iDumpFrames)
       
   291 			{
       
   292 			iEikonEnv->InfoMsg(_L("Frame dump is ON"));
       
   293 			}
       
   294 		else
       
   295 			{
       
   296 			iEikonEnv->InfoMsg(_L("Frame dump is OFF"));
       
   297 			}
       
   298 		break;
       
   299 	case EVideoCmdDrmParams:
       
   300 		DrmParamsL();
       
   301 		break;
       
   302 	case EVideoCmdClipRectParams:
       
   303 		ClipRectParamsL();
       
   304 		break;
       
   305 	case EVideoCmdDecodeThumbnail:
       
   306 		iUseThumbnail = !iUseThumbnail;
       
   307 		LoadFileL();
       
   308 		break;
       
   309 	case EVideoCmdPauseAfterEachFrame:
       
   310 		iPauseAfterEachFrame = !iPauseAfterEachFrame;
       
   311 		if (iPauseAfterEachFrame)
       
   312 			{
       
   313 			iEikonEnv->InfoMsg(_L("Pause after each frame is ON"));
       
   314 			}
       
   315 		else
       
   316 			{
       
   317 			iEikonEnv->InfoMsg(_L("Pause after each frame is OFF"));
       
   318 			}
       
   319 		break;
       
   320 	case EVideoCmdScalingQuality:
       
   321 		ScalingQualityL();
       
   322 		break;
       
   323 	case EVideoCmdZoomIn:
       
   324 		iZoomFactor++;
       
   325 		if (iZoomFactor > KVideoMaxZoomFactor)
       
   326 			iZoomFactor = KVideoMinZoomFactor;
       
   327 		LoadFileL();
       
   328 		break;
       
   329 	case EVideoCmdZoomOut:
       
   330 		iZoomFactor--;
       
   331 		if (iZoomFactor < KVideoMinZoomFactor)
       
   332 			iZoomFactor = KVideoMaxZoomFactor;
       
   333 		LoadFileL();
       
   334 		break;
       
   335 	case EVideoCmdResetZoom:
       
   336 		iZoomFactor=0;
       
   337 		LoadFileL();
       
   338 		break;
       
   339 	case EVideoCmdDisplayMode:
       
   340 		DisplayModeL();
       
   341 		break;
       
   342 	case EVideoCmdMaxReduction:
       
   343 		MaxReductionL();
       
   344 		break;
       
   345 	case EVideoCmdBackgroundColor:
       
   346 		BackgroundColorL();
       
   347 		break;
       
   348 	case EVideoCmdPlay:
       
   349 		if (iState == ELoading)
       
   350 			iEikonEnv->InfoMsg(_L("Busy..."));
       
   351 		else
       
   352 			PlayClipL();
       
   353 		break;
       
   354 	case EVideoCmdPause:
       
   355 		Pause();
       
   356 		break;
       
   357 	case EVideoCmdRefresh:
       
   358 		LoadFileL();
       
   359 		break;
       
   360 	case EVideoCmdExtractFrame:
       
   361 		ExtractFrameL();
       
   362 		break;
       
   363 	case EVideoCmdFrameInfo:
       
   364 		FrameInfoL(); 
       
   365 		break;
       
   366 	case EVideoCmdRotateClockwise:
       
   367 		FrameRotateL(ETrue);
       
   368 		LoadFileL();
       
   369 		break;
       
   370 	case EVideoCmdRotateAntiClockwise:
       
   371 		FrameRotateL(EFalse);
       
   372 		LoadFileL();
       
   373 		break;
       
   374 	case EVideoCmdFlipVertical:
       
   375 		FrameFlipL(ETrue);
       
   376 		LoadFileL();
       
   377 		break;
       
   378 	case EVideoCmdFlipHorizontal:
       
   379 		FrameFlipL(EFalse);
       
   380 		LoadFileL();
       
   381 		break;
       
   382 	case EVideoCmdAutoRotate:
       
   383 		AutoRotateL();
       
   384 		LoadFileL();
       
   385 		break;
       
   386 	case EEikCmdExit:
       
   387 		Exit();
       
   388 		break;
       
   389 	default:
       
   390 		iEikonEnv->InfoMsg(R_VIDEO_UNKNOWN);
       
   391 		break;
       
   392 		}
       
   393 	}
       
   394 
       
   395 TBool CImgDisplAppUi::ProcessCommandParametersL(TApaCommand aCommand,TFileName& aDocumentName,const TDesC8& aTail)
       
   396 	{
       
   397 	switch (aCommand)
       
   398 		{
       
   399 	case EApaCommandOpen:
       
   400 		iLoadFileName = aDocumentName;
       
   401 		break;
       
   402 	case EApaCommandCreate:
       
   403 	case EApaCommandRun:
       
   404 		break;
       
   405 	case EApaCommandBackground:
       
   406 	default:
       
   407 		break;
       
   408 		}
       
   409 
       
   410 	return CEikAppUi::ProcessCommandParametersL(aCommand,aDocumentName,aTail);
       
   411 	}
       
   412 
       
   413 void CImgDisplAppUi::OpenFileL(TFileType aFileType)
       
   414 	{
       
   415 	if (iLoadFileName.Length() < KShortestPossiblePath)
       
   416 		{
       
   417 		iLoadFileName = KDefPath;
       
   418 		}
       
   419 
       
   420 	Cancel();
       
   421 
       
   422 	CEikDialog* dialog = new(ELeave) CEikFileOpenDialog(&iLoadFileName, 0);
       
   423 	if (!dialog->ExecuteLD(R_EIK_DIALOG_FILE_OPEN))
       
   424 		{
       
   425 		return;
       
   426 		}
       
   427 
       
   428 	iLastFileType = aFileType;
       
   429 	iOpeningFolder = EFalse;
       
   430 	LoadFileL();
       
   431 	}
       
   432 
       
   433 void CImgDisplAppUi::OpenFolderL()
       
   434 	{
       
   435 	Cancel();
       
   436 
       
   437 	if (iLoadFileName.Length() < KShortestPossiblePath)
       
   438 		iLoadFileName = KDefPath;
       
   439 
       
   440 	TFileName folderName = iLoadFileName;
       
   441 
       
   442 	CEikDialog* dialog = new(ELeave) CEikFileOpenDialog(&folderName, R_VIDEO_SELECT_FOLDER);
       
   443 	if (!dialog->ExecuteLD(R_EIK_DIALOG_FILE_OPEN))
       
   444 		return;
       
   445 
       
   446 	iLastFileType = EFileTypeUnknown;
       
   447 	iOpeningFolder = ETrue;
       
   448 	LoadFolderL(folderName);
       
   449 	}
       
   450 
       
   451 void CImgDisplAppUi::LoadFileL()
       
   452 	{
       
   453 	if (iLoadFileName.Length() < KShortestPossiblePath)
       
   454 		{
       
   455 		return;
       
   456 		}
       
   457 
       
   458 	Cancel();
       
   459 
       
   460 	TInt error=KErrNone;
       
   461 	if (iImageDisplay==NULL)
       
   462 		{
       
   463 		TRAP(error,iImageDisplay = CImageDisplay::NewL(*this, iCoeEnv->FsSession()));
       
   464 		}
       
   465 	else
       
   466 		{
       
   467 		iImageDisplay->Reset();
       
   468 		}
       
   469 	iFrameNumber = 0;
       
   470 	if (error!=KErrNone)
       
   471 		{
       
   472 		iEikonEnv->HandleError(error);
       
   473 		iAppView->Reset(EDrawNow); // ensure we redraw whole screen - replace previous cross if required
       
   474 		return;
       
   475 		}
       
   476 
       
   477 	HandleNewlyOpenedImageL();
       
   478 
       
   479 	StartFrameOpen(EPlaying);
       
   480 	}
       
   481 
       
   482 void CImgDisplAppUi::LoadFolderL(const TDesC& aDirName)
       
   483 	{
       
   484 	delete iDir; iDir = NULL;
       
   485 
       
   486 	TParsePtrC parse(aDirName);
       
   487 	iDirName = parse.DriveAndPath();
       
   488 
       
   489 	iEikonEnv->FsSession().GetDir(iDirName, 0, 0, iDir);
       
   490 
       
   491 	if (iDir->Count()==0)
       
   492 		{
       
   493 		iEikonEnv->InfoMsg(R_VIDEO_EMPTY_FOLDER);
       
   494 		return;
       
   495 		}
       
   496 
       
   497 	iDirIndex = 0; 
       
   498 	OpenNextFolderEntry();
       
   499 	}
       
   500 
       
   501 void CImgDisplAppUi::OpenNextFolderEntry()
       
   502 	{
       
   503 	if (iDirIndex >= iDir->Count())
       
   504 		{
       
   505 		// end of processing - so stop
       
   506 		iEikonEnv->BusyMsgCancel();
       
   507 		Cancel(); 
       
   508 		iState = EIdle;
       
   509 		return;
       
   510 		}
       
   511 
       
   512 	const TEntry& entry = (*iDir)[iDirIndex];
       
   513 	iLoadFileName.Copy(iDirName);
       
   514 	iLoadFileName.Append(entry.iName);
       
   515 
       
   516 	TRAPD(error, LoadFileL());
       
   517 
       
   518 	if (error==KErrNone)
       
   519 		iEikonEnv->InfoMsg(entry.iName);
       
   520 	else
       
   521 		{
       
   522 		TBuf<64> errorMsg;
       
   523 		errorMsg.Format(_L("%S - error %d"), &entry.iName, error);
       
   524 		iEikonEnv->InfoMsg(errorMsg);
       
   525 		LoadFolderWait();
       
   526 		}
       
   527 	}
       
   528 
       
   529 void CImgDisplAppUi::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
       
   530 	{
       
   531 	if(aResourceId==R_VIDEO_CLIP_MENU)
       
   532 		{
       
   533 		if (iImageDisplay==NULL || iState!=EPlaying)
       
   534 			{
       
   535 			aMenuPane->SetItemDimmed(EVideoCmdPlay, (iImageDisplay==NULL) );
       
   536 			aMenuPane->SetItemDimmed(EVideoCmdPause, (iImageDisplay==NULL || iState!=EPlaying) );
       
   537 			aMenuPane->SetItemDimmed(EVideoCmdRefresh, (iImageDisplay==NULL) );
       
   538 			aMenuPane->SetItemDimmed(EVideoCmdFrameInfo,(iImageDisplay==NULL ));
       
   539 			}
       
   540 		if (iPauseAfterEachFrame)
       
   541 			{
       
   542 			aMenuPane->SetItemButtonState(EVideoCmdPauseAfterEachFrame, EEikMenuItemSymbolOn);
       
   543 			}
       
   544 		if (iDumpFrames)
       
   545 			{
       
   546 			aMenuPane->SetItemButtonState(EVideoCmdToggleFrameDump, EEikMenuItemSymbolOn);
       
   547 			}
       
   548 		}
       
   549 	else if (aResourceId==R_VIDEO_VIEW_MENU)
       
   550 		{
       
   551 		
       
   552 		switch (iRotationAngle)
       
   553 			{
       
   554 			case  CBitmapRotator::ERotation90DegreesClockwise:
       
   555 				aMenuPane->SetItemButtonState(EVideoCmdRotateClockwise,EEikMenuItemSymbolOn);
       
   556 				break;
       
   557 			case  CBitmapRotator::ERotation270DegreesClockwise:
       
   558 				aMenuPane->SetItemButtonState(EVideoCmdRotateAntiClockwise,EEikMenuItemSymbolOn);
       
   559 				break;
       
   560 			case  CBitmapRotator::EMirrorHorizontalAxis:
       
   561 				aMenuPane->SetItemButtonState(EVideoCmdFlipVertical,EEikMenuItemSymbolOn);
       
   562 				break;
       
   563 			case  CBitmapRotator::EMirrorVerticalAxis:
       
   564 				aMenuPane->SetItemButtonState(EVideoCmdFlipHorizontal,EEikMenuItemSymbolOn);
       
   565 				break;
       
   566 			case KAutoRotate:
       
   567 				aMenuPane->SetItemButtonState(EVideoCmdAutoRotate,EEikMenuItemSymbolOn);
       
   568 				break;
       
   569 			}
       
   570 		if (iUseThumbnail)
       
   571 			{
       
   572 			aMenuPane->SetItemButtonState(EVideoCmdDecodeThumbnail, EEikMenuItemSymbolOn);
       
   573 			}
       
   574 			
       
   575 		if (iImageDisplay==NULL || iState!=EPlaying)
       
   576 			{
       
   577 			
       
   578 			}
       
   579 		}
       
   580 	else if (aResourceId==R_OPTIONS_MENU)
       
   581 		{
       
   582 		}
       
   583 	}
       
   584 
       
   585 TBool CImgDisplAppUi::CheckHotKeyNotDimmedL(TInt aCommandId)
       
   586 	{
       
   587 	TInt result = ETrue;
       
   588 	switch (aCommandId)
       
   589 		{
       
   590 		case EVideoCmdRefresh:
       
   591 			result = (iImageDisplay!=NULL);
       
   592 			break;
       
   593 		case EVideoCmdPause:
       
   594 			result = (iImageDisplay!=NULL && iState==EPlaying);
       
   595 			break;
       
   596 		case EVideoCmdPlay:
       
   597 			result = (iImageDisplay!=NULL && iState!=EPlaying);
       
   598 			break;
       
   599 		case EVideoCmdFrameInfo:
       
   600 			result = (iImageDisplay!=NULL);
       
   601 			break;
       
   602 		}
       
   603 
       
   604 	return result;
       
   605 	}
       
   606 
       
   607 void CImgDisplAppUi::LoadFolderWait()
       
   608 	{
       
   609 	ASSERT(!iWalker->IsActive()); // if we get here, should not be doing anything
       
   610 	
       
   611 	iTimer.After(iWalker->ActiveStatus(), KDefaultFolderDelay);
       
   612 	iState = EFolderWait;
       
   613 	}
       
   614 
       
   615 TUint CImgDisplAppUi::ImageOptions() const
       
   616 	{
       
   617 	TUint options=0;
       
   618 	switch (iRotationAngle)
       
   619 		{
       
   620 		case  CBitmapRotator::ERotation90DegreesClockwise:
       
   621 			options |= CImageDisplay::EOptionRotateCw90;
       
   622 		break;
       
   623 		case  CBitmapRotator::ERotation180DegreesClockwise:
       
   624 			options |= CImageDisplay::EOptionRotateCw180;
       
   625 			break;
       
   626 		case  CBitmapRotator::ERotation270DegreesClockwise:
       
   627 			options |= CImageDisplay::EOptionRotateCw270;
       
   628 			break;
       
   629 		case  CBitmapRotator::EMirrorHorizontalAxis:
       
   630 			options |= CImageDisplay::EOptionMirrorHorizontal;
       
   631 			break;
       
   632 		case  CBitmapRotator::EMirrorVerticalAxis:
       
   633 			options |= CImageDisplay::EOptionMirrorVertical;
       
   634 			break;
       
   635 		case  KAutoRotate:
       
   636 			options |= CImageDisplay::EOptionAutoRotate;
       
   637 			break;
       
   638 		}
       
   639 	if (iUseThumbnail)
       
   640 		{
       
   641 		options |= CImageDisplay::EOptionThumbnail;
       
   642 		}
       
   643 	else
       
   644 		{
       
   645 		options |= CImageDisplay::EOptionMainImage;
       
   646 		}
       
   647 	return options;
       
   648 	}
       
   649 
       
   650 void CImgDisplAppUi::HandleNewlyOpenedImageL()
       
   651 	{
       
   652 	ASSERT(iImageDisplay); // should have already been opened
       
   653 
       
   654 	iImageDisplay->Reset();
       
   655 	iImageDisplay->SetImageSource(iDrmContentId.Length()==0? 
       
   656 									TMMFileSource(iLoadFileName):
       
   657 									TMMFileSource(iLoadFileName, iDrmContentId, iDrmIntent)
       
   658 								);
       
   659 	iImageDisplay->SetOptions(ImageOptions());
       
   660 	iImageDisplay->SetDisplayMode( iAppView->DisplayMode() );
       
   661 	if (iClippingSet)
       
   662 		{
       
   663 		iImageDisplay->SetSourceRect(iClipRect);
       
   664 		}
       
   665 	//
       
   666 	iImageDisplay->SetupL();
       
   667 	ASSERT( iImageDisplay->RecommendedImageSizes().Count() >0 ); // the mustn't be empty
       
   668 	TSize original(iImageDisplay->RecommendedImageSizes()[0]);
       
   669 	if (iZoomFactor>0)
       
   670 		{
       
   671 		iOverallSize.SetSize(original.iWidth<<iZoomFactor, original.iHeight<<iZoomFactor);
       
   672 		}
       
   673 	else
       
   674 		{
       
   675 		const TInt zoom=-iZoomFactor;
       
   676 		if (iImageDisplay->RecommendedImageSizes().Count() > zoom)
       
   677 			{
       
   678 			iOverallSize = iImageDisplay->RecommendedImageSizes()[zoom];
       
   679 			}
       
   680 		else
       
   681 			{
       
   682 			iOverallSize.SetSize(original.iWidth>>zoom, original.iHeight>>zoom);
       
   683 			}
       
   684 		}
       
   685 	
       
   686 	MGenIclImageDisplayExtension* iFace;
       
   687 	if (KErrNone == iImageDisplay->ExtensionInterface(KUidGenIclImageDisplayPluginExtUid, reinterpret_cast<TAny*&>(iFace)))
       
   688 		{
       
   689 		TInt err=iFace->SetScaleQuality(iScalingQuality);
       
   690 		ASSERT(err==KErrNone);
       
   691 		err=iFace->SetMaximumReductionFactor(iMaxReduction);
       
   692 		ASSERT(err==KErrNone);
       
   693 		iFace->Release();
       
   694 		}
       
   695 	iImageDisplay->SetSizeInPixels(iOverallSize);
       
   696 	iFrameNumber	= 0;
       
   697 	iViewResized	= EFalse;
       
   698 
       
   699 	iTime.HomeTime();
       
   700 	}
       
   701 
       
   702 void CImgDisplAppUi::MakeName(const TDesC& aDir, TBool aIsMask, TDes& aFileName) const
       
   703 	{
       
   704 	TParse parse;
       
   705 	parse.SetNoWild(iLoadFileName, NULL, NULL);
       
   706 	aFileName.Copy(aDir);
       
   707 	aFileName.Append(parse.Name());
       
   708 	if (aIsMask)
       
   709 		{
       
   710 		_LIT(KMask,"_mask_");
       
   711 		aFileName.Append(KMask);
       
   712 		}
       
   713 	else
       
   714 		{
       
   715 		_LIT(KFrame,"_frame_");
       
   716 		aFileName.Append(KFrame);
       
   717 		}
       
   718 	aFileName.AppendNum(iFrameNumber);
       
   719 	_LIT(KExt, ".mbm");
       
   720 	aFileName.Append(KExt);
       
   721 	}
       
   722 
       
   723 void CImgDisplAppUi::MiidoImageReady(const CFbsBitmap* /*aBitmap*/, TUint aStatus, const TRect& /*aUpdatedArea*/, TInt aError)
       
   724 	{
       
   725 	iLatestError	= aError;
       
   726 	iLatestStatus	= aStatus;
       
   727 	if (aError!=KErrNone)
       
   728 		{
       
   729 		TBuf<64> err;
       
   730 		err.Format(_L("Play error: %d"),aError);
       
   731 		User::InfoPrint(err);
       
   732 		iState = EIdle;
       
   733 		return;
       
   734 		}
       
   735 	if (aStatus&CImageDisplayPlugin::EStatusFrameReady)
       
   736 		{
       
   737 		++iFrameNumber;
       
   738 		iImageDisplay->GetBitmap(iFrame, iMask);
       
   739 		if (iDumpFrames)
       
   740 			{
       
   741 			_LIT(KDumpDir, "c:\\temp\\");
       
   742 			iEikonEnv->FsSession().MkDirAll(KDumpDir);
       
   743 			TFileName nm;
       
   744 			MakeName(KDumpDir, EFalse, nm);
       
   745 			const_cast<CFbsBitmap*>(iFrame)->Save(nm);
       
   746 			if (iMask && !iDisableMask)
       
   747 				{
       
   748 				MakeName(KDumpDir, ETrue, nm);
       
   749 				const_cast<CFbsBitmap*>(iMask)->Save(nm);
       
   750 				}
       
   751 			}
       
   752 		const TSize frameSize(iFrame->SizeInPixels());
       
   753 		if (!iViewResized )
       
   754 			{
       
   755 			TRAPD(error, iAppView->ResizeL(frameSize) );
       
   756 			iViewResized = ETrue;
       
   757 			TBuf<64> err;
       
   758 			err.Format(_L("Resize error: %d"),error);
       
   759 			if (error != KErrNone)
       
   760 				{
       
   761 				User::InfoPrint(err);
       
   762 				}
       
   763 			iAppView->Center(ENoDrawNow);
       
   764 			}
       
   765 
       
   766 		DrawConvertedFrame();
       
   767 		}
       
   768 	else
       
   769 		{
       
   770 		TBuf<64> err;
       
   771 		err.Format(_L("Strange status: %x"),aStatus);
       
   772 		User::InfoPrint(err);
       
   773 		iState = EIdle;
       
   774 		return;
       
   775 		}
       
   776 	if ((aStatus&CImageDisplayPlugin::EStatusNoMoreToDecode)==0)
       
   777 		{
       
   778 		if (iPauseAfterEachFrame)
       
   779 			{
       
   780 			User::InfoPrint(_L("Paused"));
       
   781 			iState = EPlayPaused;
       
   782 			}
       
   783 		else
       
   784 			{
       
   785 			iImageDisplay->Play();
       
   786 			}
       
   787 		}
       
   788 	else
       
   789 		{
       
   790 		User::InfoPrint(_L("Completed"));
       
   791 		iState = EIdle;
       
   792 		}
       
   793 	}
       
   794 
       
   795 void CImgDisplAppUi::ExtractFrameL()
       
   796 	{
       
   797 #if 0
       
   798 	if (iLoadFileName.Length() < KShortestPossiblePath)
       
   799 		return;
       
   800 
       
   801 	ASSERT(iImageDisplay);
       
   802 
       
   803 	Cancel();
       
   804 
       
   805 	TInt frameCount = iImageDisplay->FrameCount();
       
   806 
       
   807 	if (iFrameNumber >= frameCount)
       
   808 		iFrameNumber = 0;
       
   809 
       
   810 	CEikDialog* dialog = new(ELeave) CVideoCurrentFrameDialog(iFrameNumber,frameCount);
       
   811 	if (!dialog->ExecuteLD(R_VIDEO_FRAME_DIALOG))
       
   812 		return;
       
   813 
       
   814 	StartFrameOpen(ELoading);
       
   815 #endif
       
   816 	}
       
   817 
       
   818 void CImgDisplAppUi::StartFrameOpen(TState aNextState)
       
   819 	{
       
   820 	iImageDisplay->Play();
       
   821 	iState = aNextState; // what ever happens we go to next state, and will handle any error there
       
   822 	}
       
   823 
       
   824 void CImgDisplAppUi::PlayClipL()
       
   825 	{
       
   826 	if (iState != EPlayPaused)
       
   827 		{
       
   828 		iFrameNumber = 0;
       
   829 		}
       
   830 	iTime.HomeTime();
       
   831 
       
   832 	StartFrameOpen(EPlaying);
       
   833 	}
       
   834 
       
   835 void CImgDisplAppUi::Pause()
       
   836 	{
       
   837 	if (iImageDisplay && iState == EPlaying)
       
   838 		{
       
   839 		iImageDisplay->Pause();
       
   840 		iState = EPlayPaused;
       
   841 		}
       
   842 	}
       
   843 
       
   844 void CImgDisplAppUi::SaveAsL()
       
   845 	{
       
   846 	if (iSaveFileName.Length() < KShortestPossiblePath)
       
   847 		iSaveFileName = KDefPath;
       
   848 
       
   849 	Cancel();
       
   850 
       
   851 	CEikDialog* dialog = new(ELeave) CVideoSaveAsDialog(&iSaveFileName,iSaveInfo);
       
   852 	if (!dialog->ExecuteLD(R_VIDEO_FILE_SAVEAS_DIALOG))
       
   853 		return;
       
   854 	iEikonEnv->FsSession().Delete(iSaveFileName);
       
   855 
       
   856 	delete iFrameImageData; iFrameImageData = NULL;
       
   857 
       
   858 	const TUid imageType = iSaveInfo.iImageTypeUid;
       
   859 	TImageDataBlock *imageData = NULL;
       
   860 	TFrameDataBlock *frameData = NULL;
       
   861 
       
   862 	if(imageType == KImageTypeBMPUid)
       
   863 		{
       
   864 		imageData = new (ELeave) TBmpImageData;
       
   865 		TBmpImageData* data = STATIC_CAST(TBmpImageData*, imageData);
       
   866 		switch (iSaveInfo.iBpp)
       
   867 			{
       
   868 		case 0:		data->iBitsPerPixel = 1; break;
       
   869 		case 2:		data->iBitsPerPixel = 4; break;
       
   870 		case 3:		data->iBitsPerPixel = 8; break;
       
   871 		case 6:		data->iBitsPerPixel = 24; break;
       
   872 		default:	ASSERT(EFalse);			break;
       
   873 			}
       
   874 		}
       
   875 	else if(imageType == KImageTypeGIFUid)
       
   876 		{// gif does not have encoding options
       
   877 		}
       
   878 	else if(imageType == KImageTypeJPGUid)
       
   879 		{
       
   880 		imageData = new (ELeave) TJpegImageData;
       
   881 		TJpegImageData* data = STATIC_CAST(TJpegImageData*, imageData);
       
   882 		if (!iSaveInfo.iColor)
       
   883 			data->iSampleScheme = TJpegImageData::EMonochrome;
       
   884 		else
       
   885 			data->iSampleScheme = TJpegImageData::TColorSampling(3 - iSaveInfo.iSampling);
       
   886 		data->iQualityFactor = iSaveInfo.iQualityFactor;
       
   887 		}
       
   888 	else if(imageType == KImageTypeMBMUid)
       
   889 		{
       
   890 		frameData = new (ELeave) TMbmEncodeData;
       
   891 		TMbmEncodeData* data = STATIC_CAST(TMbmEncodeData*, frameData);
       
   892 		switch (iSaveInfo.iBpp)
       
   893 			{
       
   894 		case 0:		data->iDisplayMode = EGray2;		break;
       
   895 		case 1:		data->iDisplayMode = EGray4;		break;
       
   896 		case 2:		data->iDisplayMode = iSaveInfo.iColor ? EColor16 : EGray16;	break;
       
   897 		case 3:		data->iDisplayMode = iSaveInfo.iColor ? EColor256 : EGray256;	break;
       
   898 		case 4:		data->iDisplayMode = EColor4K;		break;
       
   899 		case 5:		data->iDisplayMode = EColor64K;	break;
       
   900 		case 6:		data->iDisplayMode = EColor16M;	break;
       
   901 		case 7:		data->iDisplayMode = EColor16MU;	break;
       
   902 		default:	ASSERT(EFalse);	break;
       
   903 			}
       
   904 		}
       
   905 	else if(imageType == KImageTypePNGUid)
       
   906 		{
       
   907 		frameData = new (ELeave) TPngEncodeData;
       
   908 		TPngEncodeData* data = STATIC_CAST(TPngEncodeData*, frameData);
       
   909 		// bpp
       
   910 		switch (iSaveInfo.iBpp)
       
   911 			{
       
   912 			case 0:		data->iBitsPerPixel = 1; break;		// 1 bpp 
       
   913 			case 1:		data->iBitsPerPixel = 2; break;		// 2 bpp
       
   914 			case 2:		data->iBitsPerPixel = 4; break;		// 4 bpp
       
   915 			case 3:		data->iBitsPerPixel = 8; break;		// 8 bpp
       
   916 			case 6:		data->iBitsPerPixel = 24; break;	// 24 bpp
       
   917 			default:	ASSERT(EFalse);	break;				// unsupported bit depth
       
   918 			}
       
   919 		// colour or grayscale?
       
   920 		data->iColor = iSaveInfo.iColor;
       
   921 		// compression level
       
   922 		switch (iSaveInfo.iCompression)
       
   923 			{
       
   924 			case 0:
       
   925 				data->iLevel = TPngEncodeData::EDefaultCompression;
       
   926 				break;
       
   927 			case 1:
       
   928 				data->iLevel = TPngEncodeData::ENoCompression;
       
   929 				break;
       
   930 			case 2:
       
   931 				data->iLevel = TPngEncodeData::EBestSpeed;
       
   932 				break;
       
   933 			case 3:
       
   934 				data->iLevel = TPngEncodeData::EBestCompression;
       
   935 				break;
       
   936 			default:			// unsupported compression
       
   937 				ASSERT(EFalse);
       
   938 				break;		
       
   939 			}
       
   940 		}
       
   941 	else
       
   942 		{
       
   943 		//custom encoder
       
   944 		}
       
   945 
       
   946 	if (frameData)
       
   947 		CleanupStack::PushL(frameData);
       
   948 
       
   949 	if (imageData)
       
   950 		CleanupStack::PushL(imageData);
       
   951 
       
   952 	delete iSaveUtil; iSaveUtil = NULL;
       
   953 	iSaveUtil = CImageEncoder::FileNewL(iCoeEnv->FsSession(), iSaveFileName, CImageEncoder::EOptionNone, imageType);
       
   954 
       
   955 	ASSERT(iFrameImageData==NULL); // deleted above
       
   956 	if (imageData)
       
   957 		{
       
   958 		iFrameImageData = CFrameImageData::NewL();
       
   959 
       
   960 		User::LeaveIfError(iFrameImageData->AppendImageData(imageData));
       
   961 		CleanupStack::Pop(); // imageData - ownership now passed to iFrameImageData
       
   962 		}
       
   963 
       
   964 	if (frameData)
       
   965 		{
       
   966 		if (iFrameImageData == NULL)
       
   967 			iFrameImageData = CFrameImageData::NewL();
       
   968 
       
   969 		User::LeaveIfError(iFrameImageData->AppendFrameData(frameData));
       
   970 		CleanupStack::Pop(); // frameData - ownership now passed to iFrameImageData
       
   971 		}
       
   972 
       
   973 	StartFrameSave();
       
   974 	}
       
   975 
       
   976 void CImgDisplAppUi::DisplayModeL()
       
   977 	{
       
   978 	TDisplayMode displayMode = iAppView->DisplayMode();
       
   979 	CEikDialog* dialog = new(ELeave) CDisplayModeDialog(displayMode);
       
   980 	if (dialog->ExecuteLD(R_VIDEO_DISPLAY_MODE_DIALOG))
       
   981 		{
       
   982 		iAppView->SetDisplayModeL(displayMode);
       
   983 		LoadFileL(); // redraw
       
   984 		}
       
   985 	}
       
   986 
       
   987 void CImgDisplAppUi::ScalingQualityL()
       
   988 	{
       
   989 	CEikDialog* dialog = new(ELeave) CScalingQualityDialog(iScalingQuality);
       
   990 	if (dialog->ExecuteLD(R_SCALING_QUALITY_DIALOG))
       
   991 		{
       
   992 		LoadFileL(); // redraw
       
   993 		}
       
   994 	}
       
   995 
       
   996 void CImgDisplAppUi::DrmParamsL()
       
   997 	{
       
   998 	CEikDialog* dialog = new(ELeave) CDrmContentIdDialog(iDrmContentId);
       
   999 	dialog->ExecuteLD(R_DRM_CONTENT_PARAMS_DIALOG);
       
  1000 	}
       
  1001 
       
  1002 void CImgDisplAppUi::MaxReductionL()
       
  1003 	{
       
  1004 	CEikDialog* dialog = new(ELeave) CMaxReductionDialog(iMaxReduction);
       
  1005 	dialog->ExecuteLD(R_IMAGE_MAX_REDUCTION_FACTOR);
       
  1006 	}
       
  1007 
       
  1008 void CImgDisplAppUi::ClipRectParamsL()
       
  1009 	{
       
  1010 	CEikDialog* dialog = new(ELeave) CClipRectParamsDialog(iClippingSet, iClipRect);
       
  1011 	dialog->ExecuteLD(R_IMAGE_CLIP_RECT_DIALOG);
       
  1012 	}
       
  1013 
       
  1014 void CImgDisplAppUi::BackgroundColorL()
       
  1015 	{
       
  1016 	TInt backgroundColor = iBackgroundColor;
       
  1017 	TBool override = iOverrideBackgroundColor;
       
  1018 	CEikDialog* dialog = new(ELeave) CVideoBackgroundColorDialog(backgroundColor, override);
       
  1019 	if (dialog->ExecuteLD(R_VIDEO_BACKGROUND_COLOR_DIALOG))
       
  1020 		{
       
  1021 		iBackgroundColor = backgroundColor;
       
  1022 		iOverrideBackgroundColor = override;
       
  1023 		LoadFileL(); // redraw
       
  1024 		}
       
  1025 	}
       
  1026 
       
  1027 void CImgDisplAppUi::FrameInfoL()
       
  1028 	{
       
  1029 	HBufC* info=HBufC::NewLC(KInfoBufferSize);
       
  1030 	TPtr commentTPtr(info->Des());
       
  1031 
       
  1032 	_LIT(KImgStatus, "Img status value=0x%x (");
       
  1033 	TUint status=iImageDisplay->ImageStatus();
       
  1034 	commentTPtr.AppendFormat(KImgStatus, status);
       
  1035 	if (status&CImageDisplay::EImageSingleFrame)
       
  1036 		{
       
  1037 		commentTPtr.Append(_L("EImageSingleFrame "));
       
  1038 		}
       
  1039 	if (status&CImageDisplay::EImageMultiFrame)
       
  1040 		{
       
  1041 		commentTPtr.Append(_L("EImageMultiFrame "));
       
  1042 		}
       
  1043 	if (status&CImageDisplay::EImageAnimated)
       
  1044 		{
       
  1045 		commentTPtr.Append(_L("EImageAnimated "));
       
  1046 		}
       
  1047 	if (status&CImageDisplay::EImageMasked)
       
  1048 		{
       
  1049 		commentTPtr.Append(_L("EImageMasked "));
       
  1050 		}
       
  1051 	if (status&CImageDisplay::EImageHasThumbnail)
       
  1052 		{
       
  1053 		commentTPtr.Append(_L("EImageHasThumbnail "));
       
  1054 		}
       
  1055 	if (status&CImageDisplay::EImageTypeUnknown)
       
  1056 		{
       
  1057 		commentTPtr.Append(_L("EImageTypeUnknown "));
       
  1058 		}
       
  1059 	commentTPtr.Append(_L(")\n"));
       
  1060 
       
  1061 	TInt numFrames;
       
  1062 	TInt err=iImageDisplay->NumFrames(numFrames);
       
  1063 	_LIT(KImgNumFrames, "Num Frames=%d (err=%d)\n");
       
  1064 	commentTPtr.AppendFormat(KImgNumFrames,numFrames,err);
       
  1065 	commentTPtr.Append(_L("---------\n"));
       
  1066 	commentTPtr.AppendFormat(_L("Frame number %d\n"),iFrameNumber);
       
  1067 	if (iFrame)
       
  1068 		{
       
  1069 		commentTPtr.AppendFormat(_L("Frame size %d x %d\n"),iFrame->SizeInPixels().iWidth,iFrame->SizeInPixels().iHeight);
       
  1070 		}
       
  1071 	commentTPtr.AppendFormat(_L("Latest status 0x%x\n"),iLatestStatus);
       
  1072 	commentTPtr.AppendFormat(_L("Latest error %d\n"),iLatestError);
       
  1073 	if (iState == EPlaying)
       
  1074 		{
       
  1075 		if (iImageDisplay->ValidBitmap())
       
  1076 			{
       
  1077 			commentTPtr.Append(_L("Bitmap status: Valid\n"));
       
  1078 			}
       
  1079 		else
       
  1080 			{
       
  1081 			commentTPtr.Append(_L("Bitmap status: NOT Valid\n"));
       
  1082 			}
       
  1083 		}
       
  1084 	
       
  1085 	ReplaceNewlinesWithLineBreaks(commentTPtr);
       
  1086 	TBool needPlay= (iState == EPlaying);
       
  1087 	Pause();	
       
  1088 
       
  1089 	CEikDialog* dialog = new(ELeave) CFrameInfoDialog(commentTPtr);
       
  1090 	TRAP(err, dialog->ExecuteLD(R_VIDEO_INFO_DIALOG) );
       
  1091 	CleanupStack::PopAndDestroy(); //info
       
  1092 	if (needPlay)
       
  1093 		{
       
  1094 		PlayClipL();
       
  1095 		}
       
  1096 	}
       
  1097 
       
  1098 void CImgDisplAppUi::FrameRotateL(TBool aClockwise)
       
  1099 	{
       
  1100 	TInt newAngle= aClockwise ?
       
  1101 			CBitmapRotator::ERotation90DegreesClockwise :
       
  1102 			CBitmapRotator::ERotation270DegreesClockwise;
       
  1103 	if (iRotationAngle  == newAngle )
       
  1104 		{
       
  1105 		iRotationAngle = KNoRotation;
       
  1106 		}
       
  1107 	else
       
  1108 		{
       
  1109 		iRotationAngle  = newAngle;
       
  1110 		}
       
  1111 
       
  1112 	iViewResized = EFalse;
       
  1113 	}
       
  1114 
       
  1115 void CImgDisplAppUi::FrameFlipL(TBool aVertical)
       
  1116 	{
       
  1117 	TInt newAngle=aVertical ?
       
  1118 						CBitmapRotator::EMirrorHorizontalAxis :
       
  1119 						CBitmapRotator::EMirrorVerticalAxis;
       
  1120 
       
  1121 	if (iRotationAngle  == newAngle )
       
  1122 		{
       
  1123 		iRotationAngle = KNoRotation;
       
  1124 		}
       
  1125 	else
       
  1126 		{
       
  1127 		iRotationAngle  = newAngle;
       
  1128 		}
       
  1129 	iViewResized = EFalse;
       
  1130 	}
       
  1131 void CImgDisplAppUi::AutoRotateL()
       
  1132 	{
       
  1133 	if (iRotationAngle  == KAutoRotate )
       
  1134 		{
       
  1135 		iRotationAngle  = KNoRotation;
       
  1136 		}
       
  1137 	else
       
  1138 		{
       
  1139 		iRotationAngle  = KAutoRotate;
       
  1140 		}
       
  1141 	iViewResized = EFalse;
       
  1142 	}
       
  1143 
       
  1144 void CImgDisplAppUi::StartFrameSave()
       
  1145 	{
       
  1146 	ASSERT(iSaveUtil); // should be true by now
       
  1147 	ASSERT(iState==EIdle); 
       
  1148 	ASSERT(!iWalker->IsActive()); // we are going to use it
       
  1149 #if 0
       
  1150 	iSaveUtil->Convert(&(iWalker->ActiveStatus()),iFrame,iFrameImageData); 
       
  1151 #endif
       
  1152 	iState = ESaving;
       
  1153 	}
       
  1154 
       
  1155 void CImgDisplAppUi::DrawConvertedFrame()
       
  1156 	{
       
  1157 	if (iOverrideBackgroundColor)
       
  1158 		{
       
  1159 		iAppView->SetBackgroundColor(TRgb(iBackgroundColor), ENoDrawNow);
       
  1160 		}
       
  1161 	TBool fullRedrawReq=ETrue;
       
  1162 	if (iMask==NULL || iDisableMask)
       
  1163 		iAppView->DrawImage(iFrame, iOffset, fullRedrawReq?ENoDrawNow:EDrawNow);
       
  1164 	else
       
  1165 		iAppView->DrawImage(iFrame, iMask, iOffset, fullRedrawReq?ENoDrawNow:EDrawNow);
       
  1166 
       
  1167 	if (fullRedrawReq)
       
  1168 		{
       
  1169 		iAppView->DrawNow();
       
  1170 		}
       
  1171 	}
       
  1172 
       
  1173 void CImgDisplAppUi::HandleConvertCompleteL()
       
  1174 	{
       
  1175 	DrawConvertedFrame();
       
  1176 
       
  1177 	iPrevFrameNumber = iFrameNumber;
       
  1178 
       
  1179 	if (iState==EPlaying)
       
  1180 		{
       
  1181 		ASSERT(!iWalker->IsActive()); // we will use it again
       
  1182 
       
  1183 		if (iState==EPlaying)
       
  1184 			{
       
  1185 			iState = EPlayingWait;
       
  1186 			}
       
  1187 			
       
  1188 		else 
       
  1189 			{
       
  1190 			ASSERT(EFalse);
       
  1191 			}
       
  1192 		}
       
  1193 	else if (iOpeningFolder)
       
  1194 		{
       
  1195 		LoadFolderWait();
       
  1196 		}
       
  1197 	else
       
  1198 		{
       
  1199 		iEikonEnv->BusyMsgCancel();
       
  1200 		Cancel(); // cancel any background streaming
       
  1201 		iState = EIdle;
       
  1202 		}
       
  1203 	}
       
  1204 
       
  1205 void CImgDisplAppUi::RunL(CVideoWalker* aWalker, TInt aStatus)
       
  1206 	{
       
  1207 	ASSERT(aWalker==iWalker); // ones we know about
       
  1208 
       
  1209 #if defined(_DEBUG) && defined(__ENABLE_DEBUG_OUTPUT)
       
  1210 	RDebug::Print(_L("RunL(%x,%d,%d)(%x,%x)"), aWalker, aStatus, iState, iWalker, iStreamGen);
       
  1211 #endif 
       
  1212 
       
  1213 	switch (iState)
       
  1214 		{
       
  1215 	case EIdle:
       
  1216 		ASSERT(EFalse); // should not happen
       
  1217 		break;
       
  1218 	case ELoading:
       
  1219 	case EPlaying:
       
  1220 		{
       
  1221 		ASSERT(aWalker==iWalker);
       
  1222 		TInt error = aStatus;
       
  1223 		if (error==KErrNone)
       
  1224 			TRAP(error, HandleConvertCompleteL());
       
  1225 		if (error!=KErrNone)
       
  1226 			HandleRunError(aWalker, error);
       
  1227 		}
       
  1228 		break;
       
  1229 	case EPlayingWait:
       
  1230 		{
       
  1231 		ASSERT(iWalker==aWalker);
       
  1232 		iTime.HomeTime(); // whatever reset the time here
       
  1233 		if (aStatus!=KErrNone)
       
  1234 			{
       
  1235 			HandleRunError(aWalker, aStatus);
       
  1236 			}
       
  1237 		else if (iOpeningFolder)
       
  1238 			{
       
  1239 			LoadFolderWait();
       
  1240 			}
       
  1241 		else
       
  1242 			{
       
  1243 			ASSERT(!iWalker->IsActive()); // should have stopped naturally
       
  1244 			iEikonEnv->BusyMsgCancel();
       
  1245 			iState = EIdle;
       
  1246 			}
       
  1247 		}
       
  1248 		break;
       
  1249 	case ESaving:
       
  1250 		{
       
  1251 		ASSERT(iWalker==aWalker);
       
  1252 		iEikonEnv->BusyMsgCancel();
       
  1253 		iState = EIdle;
       
  1254 		if (aStatus!=KErrNone)
       
  1255 			HandleRunError(aWalker, aStatus);
       
  1256 		}
       
  1257 		break;
       
  1258 	case EFolderWait:
       
  1259 		iDirIndex++;
       
  1260 		OpenNextFolderEntry();
       
  1261 		break;
       
  1262 	default:
       
  1263 		ASSERT(EFalse); // unknown state
       
  1264 		}
       
  1265 	}
       
  1266 
       
  1267 void CImgDisplAppUi::DoCancel(CVideoWalker *aWalker)
       
  1268 	{
       
  1269 	ASSERT(aWalker==iWalker); // only ones we know about
       
  1270 
       
  1271 #if defined(_DEBUG) && defined(__ENABLE_DEBUG_OUTPUT)
       
  1272 	RDebug::Print(_L("DoCancel(%x,%d)(%x,%x)"), aWalker, iState, iWalker, iStreamGen); 
       
  1273 #endif 
       
  1274 
       
  1275 	if (aWalker==iWalker)
       
  1276 		{
       
  1277 		switch (iState)
       
  1278 			{
       
  1279 		case ELoading:
       
  1280 		case EPlaying:
       
  1281 			iImageDisplay->StopPlay();
       
  1282 			break;
       
  1283 		case ESaving:
       
  1284 			iSaveUtil->Cancel();
       
  1285 			break;
       
  1286 		case EPlayingWait: // ignore scenario where we self complete - will not get here
       
  1287 		case EFolderWait:
       
  1288 			iTimer.Cancel();
       
  1289 			break;
       
  1290 		default:
       
  1291 			ASSERT(EFalse); // unknown state or should not happen
       
  1292 			}
       
  1293 		}
       
  1294 	else
       
  1295 		{
       
  1296 		ASSERT(EFalse); // unknown state or should not happen
       
  1297 		}
       
  1298 	}
       
  1299 
       
  1300 void CImgDisplAppUi::HandleRunError(CVideoWalker* /*aWalker*/, TInt aError)
       
  1301 	{
       
  1302 	Cancel();
       
  1303 	iEikonEnv->BusyMsgCancel();
       
  1304 	iEikonEnv->HandleError(aError);
       
  1305 	ASSERT(iState == EIdle);
       
  1306 	}
       
  1307 
       
  1308 void CImgDisplAppUi::ReplaceNewlinesWithLineBreaks(TDes& aText)
       
  1309 	{
       
  1310 	TInt pos=0;
       
  1311 
       
  1312 	for (;;)
       
  1313 		{
       
  1314 		if (pos >= aText.Length()) // will occur if last character in comment is new line
       
  1315 			break;
       
  1316 		const TPtrC restOfText(aText.Mid(pos));
       
  1317 		TInt posOfNextNewLine = restOfText.Locate(TChar('\n'));
       
  1318 		if (posOfNextNewLine<0) // no more new lines in text
       
  1319 			break;
       
  1320 		posOfNextNewLine += pos; // position relative to whole descriptor
       
  1321 		aText[posOfNextNewLine] = CEditableText::ELineBreak;
       
  1322 		pos = posOfNextNewLine + 1; // next cycle, start at next character
       
  1323 		}
       
  1324 	}
       
  1325 
       
  1326 
       
  1327 //
       
  1328 // CVideoWalker implementation
       
  1329 //
       
  1330 
       
  1331 CVideoWalker* CVideoWalker::NewL(CImgDisplAppUi* aAppUi)
       
  1332 	{
       
  1333 	CVideoWalker* result = new (ELeave) CVideoWalker(aAppUi);
       
  1334 	return result;
       
  1335 	}
       
  1336 
       
  1337 CVideoWalker::CVideoWalker(CImgDisplAppUi* aAppUi):
       
  1338 	CActive(CActive::EPriorityStandard),
       
  1339 	iAppUi(aAppUi)
       
  1340 	{
       
  1341 	CActiveScheduler::Add(this);
       
  1342 	}
       
  1343 
       
  1344 CVideoWalker::~CVideoWalker()
       
  1345 	{
       
  1346 	Cancel();
       
  1347 	}
       
  1348 
       
  1349 // used when we need to pass status variable - simultaneously calls SetActive
       
  1350 TRequestStatus& CVideoWalker::ActiveStatus()
       
  1351 	{
       
  1352 	SetActive();
       
  1353 	return iStatus;
       
  1354 	}
       
  1355 
       
  1356 // for completion ASAP on this
       
  1357 void CVideoWalker::SelfComplete(TInt aError)
       
  1358 	{
       
  1359 	TRequestStatus* status = &ActiveStatus();
       
  1360 	User::RequestComplete(status, aError);
       
  1361 	}
       
  1362 
       
  1363 // calls AppUi->RunL() which is expected to handle the call
       
  1364 void CVideoWalker::RunL()
       
  1365 	{
       
  1366 	iAppUi->RunL(this, iStatus.Int());
       
  1367 	}
       
  1368 
       
  1369 // calls AppUi->DoCancel() which is expected to handle the call
       
  1370 void CVideoWalker::DoCancel()
       
  1371 	{
       
  1372 	iAppUi->DoCancel(this);
       
  1373 	}
       
  1374 
       
  1375 //
       
  1376 // CImgDisplDocument
       
  1377 //
       
  1378 
       
  1379 CImgDisplDocument::CImgDisplDocument(CEikApplication& aApp)
       
  1380 		: CEikDocument(aApp)
       
  1381 	{
       
  1382 	}
       
  1383 
       
  1384 CEikAppUi* CImgDisplDocument::CreateAppUiL()
       
  1385 	{
       
  1386     return new(ELeave) CImgDisplAppUi;
       
  1387 	}
       
  1388 
       
  1389 //
       
  1390 // CImgDisplApp
       
  1391 //
       
  1392 
       
  1393 TUid CImgDisplApp::AppDllUid() const
       
  1394 	{
       
  1395 	return KUidTVideo;
       
  1396 	}
       
  1397 
       
  1398 CApaDocument* CImgDisplApp::CreateDocumentL()
       
  1399 	{
       
  1400 	return new(ELeave) CImgDisplDocument(*this);
       
  1401 	}
       
  1402 
       
  1403 #include <eikstart.h>
       
  1404 
       
  1405 
       
  1406 CApaApplication* NewApplication()
       
  1407    {
       
  1408    return new CImgDisplApp;
       
  1409    }
       
  1410 
       
  1411 TInt E32Main()
       
  1412    {
       
  1413    return EikStart::RunApplication(NewApplication);
       
  1414    }
       
  1415 
       
  1416