examples/ForumNokia/ImageConverter/src/ImageConverterAppUi.cpp

00001 /*
00002  * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */
00029 
00030 
00031 // INCLUDE FILES
00032 #include "ImageConverterApp.h"
00033 #include "ImageConverterAppUi.h"
00034 #include "ImageConverterContainer.h" 
00035 #include "ImageConverterEngine.h"
00036 #include "imageconverter.hrh"
00037 #include "encoderselectiondialog.h"
00038 #include "showinfodialog.h"
00039 #include <ImageConverter.rsg>
00040 
00041 
00042 #include <aknmessagequerydialog.h>
00043 #include <hlplch.h>
00044 #include <avkon.hrh>
00045 #include <avkon.rsg>
00046 #include <caknfileselectiondialog.h>
00047 #include <akncommondialogs.h>
00048 #include <imageconversion.h>
00049 #include <eikmenup.h>
00050 #include <aknglobalnote.h>
00051 #include <pathinfo.h>
00052 #include <aknquerydialog.h>
00053 
00054 const TInt KScaleUpFactor = 150;    // Scale up by 50%
00055 const TInt KScaleDownFactor = 50;   // Scale down by 50%
00056 const TInt KMaxInfoMsgLength = 50;
00057 
00058 const TInt KMaxInfoDescriptorLength = 80;
00059 
00060 
00061 // We specify a custom cleanup method for the RImageTypeDescriptionArray used
00062 // in CImageConverterAppUi::HandleSaveAsL(). This way we can, in that method, 
00063 // simply call CleanupStack::PopAndDestroy() on the array and do whatever 
00064 // additional cleanup we need here. In this case ResetAndDestroy() is called 
00065 // on the array to release resources consumed by it.
00066 // In general, creating a custom cleanup method allows cleanup to be more 
00067 // sophisticated than simply deleting objects, for example, releasing access to 
00068 // some shared resource.
00069 void CleanupRArray( TAny* object )
00070     {
00071     ((RImageTypeDescriptionArray*)object)->ResetAndDestroy();
00072     }
00073 
00074 // ================= MEMBER FUNCTIONS =======================
00075 //
00076 // ----------------------------------------------------------
00077 // CImageConverterAppUi::ConstructL()
00078 // 
00079 // ----------------------------------------------------------
00080 //
00081 void CImageConverterAppUi::ConstructL()
00082     {
00083     #ifdef __TUI_SUPPORTED__
00084     BaseConstructL(EAknEnableSkin | EAknTouchCompatible);
00085     #else
00086     BaseConstructL(EAknEnableSkin);
00087     #endif
00088     
00089     
00090     SearchOptionsButtonPosition();
00091 
00092     iImageLoaded = EFalse;
00093     iConverter = CImageConverterEngine::NewL( this );
00094     
00095     iAppContainer = new (ELeave) CImageConverterContainer;
00096     iAppContainer->SetMopParent( this );
00097     iAppContainer->ConstructL( ClientRect() );
00098     AddToStackL( iAppContainer );   
00099     
00100 
00101     ReadImageDirectoryL();
00102     ReadImage(0);
00103     }
00104 
00105 // ----------------------------------------------------
00106 // CImageConverterAppUi::~CImageConverterAppUi()
00107 // Destructor
00108 // Frees reserved resources
00109 // ----------------------------------------------------
00110 //
00111 CImageConverterAppUi::~CImageConverterAppUi()
00112     {
00113     if (iAppContainer)
00114         {
00115         RemoveFromStack( iAppContainer );
00116         delete iAppContainer;
00117         }
00118  
00119     if (iConverter)
00120         {
00121         iConverter->Cancel();
00122         delete iConverter;
00123         }
00124 
00125     delete iSaveAs;
00126     delete iInfoDialog;
00127     delete iInfoStrings;
00128     
00129     iFiles.Close();
00130     }
00131 
00132 // ----------------------------------------------------
00133 // CImageConverterAppUi::DynInitMenuPaneL(
00134 //    TInt aResourceId,CEikMenuPane* aMenuPane)
00135 // Handle dynamic menu initialization
00136 // ----------------------------------------------------
00137 //
00138 void CImageConverterAppUi::DynInitMenuPaneL(
00139     TInt aResourceId,CEikMenuPane* aMenuPane)
00140     {
00141     if( aResourceId == R_IMAGECONVERTER_MENU ) 
00142         {
00143         if( !iImageLoaded ) 
00144             {
00145             // if there is no image loaded do not show these menu items
00146             aMenuPane->SetItemDimmed( EImageConverterCmdSaveAs, true );
00147             aMenuPane->SetItemDimmed( EImageConverterCmdInfo, true );
00148             aMenuPane->SetItemDimmed( EImageConverterCmdRotate, true );
00149             aMenuPane->SetItemDimmed( EImageConverterCmdZoomOut, true );
00150             aMenuPane->SetItemDimmed( EImageConverterCmdZoomIn, true );
00151             }
00152         else 
00153             {
00154             aMenuPane->SetItemDimmed( EImageConverterCmdSaveAs, false );
00155             aMenuPane->SetItemDimmed( EImageConverterCmdInfo, false );
00156             aMenuPane->SetItemDimmed( EImageConverterCmdRotate, false );
00157             aMenuPane->SetItemDimmed( EImageConverterCmdZoomOut, false );
00158             if (iConverter && iConverter->CanDownScaleMore())
00159                 {
00160                 aMenuPane->SetItemDimmed( EImageConverterCmdZoomIn, false );
00161                 }
00162             else
00163                 {
00164                 aMenuPane->SetItemDimmed( EImageConverterCmdZoomIn, true );
00165                 }
00166             }
00167         }
00168     }
00169 
00170 void CImageConverterAppUi::DoEvent(EPointerEvents aEvent)
00171     {
00172     switch (aEvent)
00173         {
00174         case EZoomIn:
00175             {
00176             iAppContainer->SetTitleText(ETitleZoomIn,EFalse);
00177             if (iConverter->Scale( KScaleUpFactor )==KErrNone)
00178                 {
00179                 iImageLoaded = false;
00180                 }
00181             break;
00182             }
00183         case EZoomOut:
00184             {
00185             iAppContainer->ResetTitleText(EFalse);
00186             if (iConverter->Scale( KScaleDownFactor )==KErrNone)
00187                 {
00188                 iImageLoaded = false;
00189                 }
00190             break;
00191             }
00192         case ENextImage:
00193             {
00194             ReadImage(1);
00195             break;
00196             }
00197         case EPrevImage:
00198             {
00199             ReadImage(-1);
00200             break;
00201             }
00202         case ERotateRight:
00203             {
00204             iImageLoaded = false;
00205             iAppContainer->SetTitleText(ETitleRotateRight,EFalse);
00206             iConverter->Rotate( CImageConverterEngine::EClockwise90 );
00207             break;
00208             }
00209         case ERotateLeft:
00210             {
00211             iImageLoaded = false;
00212             iAppContainer->SetTitleText(ETitleRotateLeft,EFalse);
00213             iConverter->Rotate( CImageConverterEngine::EAntiClockwise90 );
00214             break;
00215             }
00216         default:
00217             {
00218             break;
00219             }
00220         };
00221     }
00222 
00223 TState CImageConverterAppUi::EngineState()
00224     {
00225     return iConverter->EngineState();
00226     }
00227 
00228 // ----------------------------------------------------
00229 // CImageConverterAppUi::HandleKeyEventL(
00230 //     const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
00231 // takes care of key event handling
00232 // ----------------------------------------------------
00233 //
00234 TKeyResponse CImageConverterAppUi::HandleKeyEventL(
00235     const TKeyEvent& aKeyEvent,TEventCode aType)
00236     {
00237     // if there is an image loaded, pressing arrow keys causes
00238     // scale and rotate
00239     if( iImageLoaded && (aType == EEventKey) ) 
00240         {
00241         if( aKeyEvent.iCode == EKeyLeftArrow ) 
00242             {
00243             iAppContainer->ChangePrevPictureL();
00244             return EKeyWasConsumed;
00245             }
00246         else if( aKeyEvent.iCode == EKeyRightArrow ) 
00247             {
00248             iAppContainer->ChangeNextPictureL();
00249             return EKeyWasConsumed;
00250             }
00251         else if( aKeyEvent.iCode == EKeyUpArrow ) 
00252             {
00253             iAppContainer->SetTitleText(ETitleZoomIn,ETrue);
00254             if (iConverter->Scale( KScaleUpFactor )==KErrNone) // scale up
00255                 {
00256                 iImageLoaded = false;
00257                 }
00258             return EKeyWasConsumed;
00259             }
00260         else if( aKeyEvent.iCode == EKeyDownArrow ) 
00261             {
00262             iAppContainer->ResetTitleText(ETrue);
00263             if (iConverter->Scale( KScaleDownFactor )==KErrNone) // scale up
00264                 {
00265                 iImageLoaded = false;
00266                 }
00267             return EKeyWasConsumed;
00268             }
00269         }
00270     else if ( iImageLoaded && aType == EEventKeyDown)
00271         {
00272         if (aKeyEvent.iScanCode == '1' || aKeyEvent.iScanCode == '*')
00273             {
00274             iAppContainer->SetTitleText(ETitleRotateLeft,ETrue);
00275             iImageLoaded = false;
00276             iConverter->Rotate( CImageConverterEngine::EAntiClockwise90 );
00277             return EKeyWasConsumed;
00278             }
00279         else if (aKeyEvent.iScanCode == '3' || aKeyEvent.iScanCode == EStdKeyHash)
00280             {
00281             iAppContainer->SetTitleText(ETitleRotateRight,ETrue);
00282             iImageLoaded = false;
00283             iConverter->Rotate( CImageConverterEngine::EClockwise90 );
00284             return EKeyWasConsumed;
00285             }
00286         }
00287     return EKeyWasNotConsumed;
00288     }
00289 
00290 // ----------------------------------------------------
00291 // CImageConverterAppUi::HandleCommandL(TInt aCommand)
00292 // takes care of command handling
00293 // ----------------------------------------------------
00294 //
00295 void CImageConverterAppUi::HandleCommandL(TInt aCommand)
00296     {
00297     switch ( aCommand )
00298         {
00299         case EAknSoftkeyExit:
00300         case EEikCmdExit:
00301             {
00302             Exit();
00303             break;
00304             }
00305         case EImageConverterCmdOpen:
00306             {
00307             HandleOpenL();
00308             break;
00309             }
00310         case EImageConverterCmdSaveAs:
00311             {
00312             HandleSaveAsL();
00313             break;
00314             }
00315         case EImageConverterCmdInfo:
00316             {
00317             HandleInfoL();
00318             break;
00319             }
00320         case EImageConverterCmdOrientation:
00321             {
00322             if(Orientation() == CAknAppUiBase::EAppUiOrientationLandscape)
00323                 {
00324                 SetOrientationL(CAknAppUiBase::EAppUiOrientationPortrait);
00325                 iAppContainer->SetPictureScreenCenter(ETrue);
00326                 }
00327             else
00328                 {
00329                 SetOrientationL(CAknAppUiBase::EAppUiOrientationLandscape);
00330                 iAppContainer->SetPictureScreenCenter(ETrue);
00331                 }
00332             break;
00333             }
00334         case EImageConverterCmdRotateLeft:
00335             {
00336             iAppContainer->SetTitleText(ETitleRotateLeft,ETrue);
00337             iImageLoaded = false;
00338             iConverter->Rotate( CImageConverterEngine::EAntiClockwise90 );
00339             break;
00340             }
00341         case EImageConverterCmdRotateRight:
00342             {
00343             iAppContainer->SetTitleText(ETitleRotateRight,ETrue);
00344             iImageLoaded = false;
00345             iConverter->Rotate( CImageConverterEngine::EClockwise90 );
00346             break;
00347             }
00348         case EImageConverterCmdZoomIn:
00349             {
00350             iAppContainer->SetTitleText(ETitleZoomIn,ETrue);
00351             if (iConverter->Scale( KScaleUpFactor )==KErrNone) // scale down
00352                 {
00353                 iImageLoaded = false;
00354                 }
00355             break;
00356             }
00357         case EImageConverterCmdZoomOut:
00358             {
00359             iAppContainer->ResetTitleText(ETrue);
00360             if (iConverter->Scale( KScaleDownFactor )==KErrNone) // scale down
00361                 {
00362                 iImageLoaded = false;
00363                 }
00364             break;
00365             }
00366         case EImageConverterCmdNext:
00367             {
00368             iAppContainer->ChangeNextPictureL();
00369             break;
00370             }
00371         case EImageConverterCmdPrev:
00372             {
00373             iAppContainer->ChangePrevPictureL();
00374             break;
00375             }
00376         case EImageConverterCmdHelp:
00377             {
00378             CArrayFix<TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL ( );
00379             HlpLauncher::LaunchHelpApplicationL (iEikonEnv->WsSession ( ), buf );
00380             break;
00381             }
00382         case EImageConverterCmdAbout:
00383             {
00384             CAknMessageQueryDialog* dlg = new (ELeave)CAknMessageQueryDialog();
00385             dlg->PrepareLC (R_ABOUT_QUERY_DIALOG );
00386             HBufC* title = iEikonEnv->AllocReadResourceLC (R_ABOUT_DIALOG_TITLE );
00387             dlg->QueryHeading()->SetTextL (*title );
00388             CleanupStack::PopAndDestroy ( ); //title
00389             HBufC* msg = iEikonEnv->AllocReadResourceLC (R_ABOUT_DIALOG_TEXT );
00390             dlg->SetMessageTextL (*msg );
00391             CleanupStack::PopAndDestroy ( ); //msg
00392             dlg->RunLD ( );
00393             break;
00394             }
00395         default:
00396             break;      
00397         }
00398     }
00399 
00400 
00401 CArrayFix<TCoeHelpContext>* CImageConverterAppUi::HelpContextL ( ) const
00402     {
00403     CArrayFixFlat<TCoeHelpContext>* array = new(ELeave)CArrayFixFlat<TCoeHelpContext>(1);
00404     CleanupStack::PushL (array );
00405     _LIT(KGeneral_Information, "General Information about the application"); 
00406     array->AppendL (TCoeHelpContext (KUidHelpFile, KGeneral_Information ) );
00407     CleanupStack::Pop (array );
00408     return array;
00409     }
00410 
00411 
00412 void CImageConverterAppUi::ReadImageDirectoryL()
00413     {
00414     RFs& rfs = iEikonEnv->FsSession();
00415     CDir* fileList = NULL;
00416     
00417     iFiles.Reset();
00418 
00419     TFileName path = PathInfo::PhoneMemoryRootPath(); 
00420     path.Append(PathInfo::ImagesPath());
00421     
00422     User::LeaveIfError(rfs.GetDir(path,KEntryAttNormal,ESortByName,fileList));
00423     
00424     for( TInt i = 0; i < fileList->Count(); i++ )
00425         {
00426         // Read only files to array
00427         if (!fileList->operator[](i).IsDir())
00428             {
00429             TFileName filename;
00430             filename.Append(path);
00431             filename.Append(fileList->operator[](i).iName);
00432             filename.LowerCase();
00433             // We support only JPG, BMP,  GIF
00434             if ( filename.Find(_L(".jpg"))!=KErrNotFound || 
00435                  filename.Find(_L(".jpeg"))!=KErrNotFound || 
00436                  filename.Find(_L(".bmp"))!=KErrNotFound ||
00437                  filename.Find(_L(".gif"))!=KErrNotFound )
00438                 {
00439                 iFiles.Append(filename);
00440                 }
00441             }
00442         }
00443     
00444     delete fileList;
00445     }
00446 
00447 
00448 
00449 TInt CImageConverterAppUi::ImageIndex()
00450     {
00451     return iOpenFileIndex;
00452     }
00453 
00454 TInt CImageConverterAppUi::ImageCount()
00455     {
00456     return iFiles.Count();
00457     }
00458 
00459 void CImageConverterAppUi::ImageName(TFileName& aFilename)
00460     {
00461     aFilename.Copy(iFiles[iOpenFileIndex]);
00462     if (aFilename.Find(_L("\\")) > -1)
00463         {
00464         aFilename.Delete(0,aFilename.LocateReverse('\\')+1);
00465         }
00466     }
00467 
00468 void CImageConverterAppUi::PlainImageName(TFileName& aFilename)
00469     {
00470     aFilename.Copy(iFiles[iOpenFileIndex]);
00471     if (aFilename.Find(_L("\\")) > -1)
00472         {
00473         aFilename.Delete(0,aFilename.LocateReverse('\\')+1);
00474         }
00475     if (aFilename.Find(_L(".")) > -1)
00476         {
00477         aFilename.SetLength(aFilename.Find(_L(".")));
00478         }
00479     }
00480 
00481 void CImageConverterAppUi::ReadImage(TInt aDirection)
00482     {
00483     TFileName fileToOpen;
00484     
00485     if (iFiles.Count()==0)
00486         {
00487         return; // No images found
00488         }
00489     
00490     iOpenFileIndex = iOpenFileIndex + aDirection;
00491     if (iOpenFileIndex < 0)
00492         {
00493         iOpenFileIndex = iFiles.Count()-1;
00494         }
00495     else if(iOpenFileIndex > iFiles.Count()-1)
00496         {
00497         iOpenFileIndex = 0;
00498         }
00499     
00500     fileToOpen.Append(iFiles[iOpenFileIndex]);
00501     
00502     iImageLoaded = false;
00503     iAppContainer->SetBitmap(NULL);
00504     
00505     // request the actuall open/decode
00506     // asynchronous, the result is reported via callback
00507     // NotifyCompletion
00508     TRAPD( err, iConverter->StartToDecodeL(fileToOpen) );
00509 
00510     // report errors in issuing the asynchronous call
00511     if( err != KErrNone ) 
00512         {
00513         _LIT( KMsg, "Error when starting to decode:%d" );
00514         TBuf<KMaxInfoMsgLength> buf;
00515         buf.Format( KMsg, err );
00516         ShowMessage(buf);
00517         }
00518     }
00519 
00520 
00521 
00522 // ----------------------------------------------------
00523 // CImageConverterAppUi::HandleOpenL( )
00524 // Handle open command
00525 // ----------------------------------------------------
00526 //
00527 void CImageConverterAppUi::HandleOpenL( )
00528     {
00529     TFileName fileToOpen;
00530     
00531     _LIT( KFileSelectionTitle, "Select image to open" );
00532     
00533     // show fileopen dialog from akncommondialogs
00534     if( !AknCommonDialogs::RunSelectDlgLD(fileToOpen, 
00535         R_MEMORY_SELECTION_DIALOG, KFileSelectionTitle) ) 
00536         {
00537         return;
00538         }
00539 
00540     iImageLoaded = false;
00541     iAppContainer->SetBitmap(NULL); 
00542 
00543     // request the actuall open/decode
00544     // asynchronous, the result is reported via callback
00545     // NotifyCompletion
00546     TRAPD( err, iConverter->StartToDecodeL(fileToOpen) );
00547 
00548     // report errors in issuing the asynchronous call
00549     if( err != KErrNone ) 
00550         {
00551         _LIT( KMsg, "Error when starting to decode:%d" );
00552         TBuf<KMaxInfoMsgLength> buf;
00553         buf.Format( KMsg, err );
00554         ShowMessage(buf);
00555         }
00556     else
00557         {
00558         iFiles.Append(fileToOpen);
00559         iOpenFileIndex = iFiles.Count()-1;
00560         }
00561     }
00562 
00563 // ----------------------------------------------------
00564 // CImageConverterAppUi::HandleSaveAsL()
00565 // Handle save command
00566 // ----------------------------------------------------
00567 //
00568 void CImageConverterAppUi::HandleSaveAsL()
00569     {
00570     TInt selectedIdx = 0;
00571 
00572     // get encoder types from engine
00573     RImageTypeDescriptionArray imageTypes; 
00574     iConverter->GetEncoderImageTypesL( imageTypes); 
00575     
00576     // Create a custom cleanup item and specify CleanupRArray to be the
00577     // method that is called once we call CleanupStack::PopAndDestroy() at the
00578     // end of this method.
00579     CleanupStack::PushL( TCleanupItem(CleanupRArray, &imageTypes) );
00580 
00581     // Create path for filename
00582     TFileName path = PathInfo::PhoneMemoryRootPath(); 
00583     path.Append(PathInfo::ImagesPath());
00584     // Get filename of current image for save image dialog
00585     TFileName fileToSave;
00586     PlainImageName(fileToSave);
00587 
00588     // Create image format array for the dialog
00589     CDesCArrayFlat* array = new (ELeave) CDesCArrayFlat(imageTypes.Count());
00590     CleanupStack::PushL(array);
00591     for( TInt i=0; i<imageTypes.Count(); i++ ) 
00592         {
00593         TBuf<KMaxInfoDescriptorLength> desc;
00594         desc.Append( imageTypes[i]->Description() );
00595         array->AppendL( desc );
00596         }
00597     
00598     // Show dialog
00599     TRAPD(err, 
00600         iSaveAs = new(ELeave)CAknListQueryDialog(&selectedIdx);
00601         iSaveAs->PrepareLC(R_SELECTION_QUERY);
00602         iSaveAs->SetItemTextArray(array); 
00603         iSaveAs->SetOwnershipType(ELbmDoesNotOwnItemArray); 
00604         if(iSaveAs->RunLD())
00605             {
00606             // Ask filename
00607             CAknTextQueryDialog* dlg = CAknTextQueryDialog::NewL(fileToSave,CAknQueryDialog::ENoTone);
00608             dlg->PrepareLC(R_QUERY_DIALOG);
00609             dlg->SetPromptL(_L("Save As"));
00610             if(dlg->RunLD())
00611                 {
00612                 fileToSave.Append(_L("."));
00613                 fileToSave.Append(imageTypes[selectedIdx]->Description());
00614     
00615                 path.Append(fileToSave);
00616                 iConverter->StartToEncodeL(path, 
00617                     imageTypes[selectedIdx]->ImageType(),
00618                     imageTypes[selectedIdx]->SubType());
00619                 }
00620             }
00621         );
00622     iSaveAs = NULL;
00623     CleanupStack::PopAndDestroy(); // array
00624 
00625     if (err)
00626         {
00627         User::Leave(err);
00628         }
00629 
00630     // This will lead to a call to CleanupRArray, our custom cleanup method.
00631     CleanupStack::PopAndDestroy(&imageTypes);
00632     }
00633 
00634 // ----------------------------------------------------
00635 // CImageConverterAppUi::HandleInfoL()
00636 // Handle info command
00637 // ----------------------------------------------------
00638 //
00639 void CImageConverterAppUi::HandleInfoL()
00640     {
00641     // Get the info strings
00642     delete iInfoStrings;
00643     iInfoStrings = NULL;
00644     iInfoStrings = iConverter->GetImageInfoL();
00645 
00646     if (iInfoStrings)
00647         {
00648         // Show the info strings in a separate dialog
00649         iInfoDialog = new(ELeave) CShowInfoDialog( iInfoStrings );
00650         iInfoDialog->ExecuteLD( R_IMAGECONVERTER_SHOWINFO_DIALOG );
00651         iInfoDialog = NULL;
00652         }
00653     }
00654 
00655 TBool CImageConverterAppUi::IsAnimating()
00656     {
00657     return iAppContainer->IsAnimating();
00658     }
00659 
00660 TBool CImageConverterAppUi::IsEngineBusy()
00661     {
00662     return iConverter->IsActive();
00663     }
00664 
00665 // ----------------------------------------------------
00666 // CImageConverterAppUi::NotifyCompletion( TInt aErr, 
00667 //                const TDesC& aMsg )
00668 // Handle completion notifications
00669 // ----------------------------------------------------
00670 //
00671 void CImageConverterAppUi::NotifyCompletion( TInt aErr, const TDesC& aMsg ) 
00672     {
00673     if( aErr == KErrNone ) 
00674         {
00675         // we have succesfully decoded an image, now make the view
00676         // to display it
00677         iAppContainer->SetBitmap(iConverter->GetBitmap());
00678         iImageLoaded = true;
00679         }
00680     else 
00681         {
00682         iAppContainer->SetBitmap(NULL);
00683         iImageLoaded = false;
00684         }
00685 
00686         iAppContainer->DrawToBackBuffer();
00687         iAppContainer->DrawNow();
00688 
00689     if (aErr && aErr != KErrNotReady)
00690         {
00691         ShowMessage(aMsg);
00692         }
00693     }
00694 
00695 // ----------------------------------------------------
00696 // CImageConverterAppUi::ShowMessage(const TDesC& aMsg) const
00697 // Show a message to the user
00698 // ----------------------------------------------------
00699 //
00700 void CImageConverterAppUi::ShowMessage(const TDesC& aMsg) const
00701     {
00702     if (aMsg.Length())  // If there's something to show, otherwise do nothing
00703         {
00704         // No need to react if this leaves, just trap
00705         TRAPD(err, ShowMessageL(aMsg));
00706         }
00707     }
00708 // ----------------------------------------------------
00709 // CImageConverterAppUi::ShowMessageL(const TDesC& aMsg) const
00710 // Show a message to the user
00711 // ----------------------------------------------------
00712 //
00713 void CImageConverterAppUi::ShowMessageL(const TDesC& aMsg) const
00714     {
00715     CAknGlobalNote* note = CAknGlobalNote::NewLC();
00716     note->ShowNoteL(EAknGlobalConfirmationNote, aMsg);
00717     CleanupStack::PopAndDestroy(note);
00718     }
00719 
00720 TBool CImageConverterAppUi::IsOptionsButtonOnTop()
00721     {
00722     return iOptionButtonOnTop;
00723     }
00724 
00725 void CImageConverterAppUi::SearchOptionsButtonPosition()
00726     {
00727     iOptionButtonOnTop = EFalse;
00728     CEikButtonGroupContainer* cba = Cba();
00729     if(!cba)
00730         {
00731         return;
00732         }
00733     CCoeControl* options = cba->ControlOrNull(EAknSoftkeyOptions);
00734     CCoeControl* exit = cba->ControlOrNull(EAknSoftkeyExit);
00735     if( options && exit )
00736         {
00737         if( options->Position().iY < exit->Position().iY )
00738             {
00739             iOptionButtonOnTop = ETrue;
00740             }
00741         }
00742     }
00743 
00744 void CImageConverterAppUi::HandleResourceChangeL( TInt aType )
00745     {
00746     CAknAppUi::HandleResourceChangeL( aType );
00747        
00748     if ( aType==KEikDynamicLayoutVariantSwitch )
00749         {
00750         SearchOptionsButtonPosition();
00751 
00752         TRect rect;
00753         AknLayoutUtils::LayoutMetricsRect(
00754         AknLayoutUtils::EMainPane,rect);
00755         if (iSaveAs)
00756             {
00757             iSaveAs->SetRect(rect);
00758             }
00759         if (iInfoDialog)
00760             {
00761             iInfoDialog->SetRect(rect);
00762             }
00763         }           
00764     }
00765 
00766 
00767 // End of File
00768 

Generated by  doxygen 1.6.2