|         |      1 /* | 
|         |      2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). | 
|         |      3 * All rights reserved. | 
|         |      4 * This component and the accompanying materials are made available | 
|         |      5 * under the terms of the License "Eclipse Public License v1.0" | 
|         |      6 * which accompanies this distribution, and is available | 
|         |      7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". | 
|         |      8 * | 
|         |      9 * Initial Contributors: | 
|         |     10 * Nokia Corporation - initial contribution. | 
|         |     11 * | 
|         |     12 * Contributors: | 
|         |     13 * | 
|         |     14 * Description:  | 
|         |     15 *      View images popup box | 
|         |     16 *       | 
|         |     17 * | 
|         |     18 */ | 
|         |     19  | 
|         |     20  | 
|         |     21 // USER INCLUDES | 
|         |     22 #include "BrowserDialogsProvider.h" | 
|         |     23 #include "BrowserDialogsProvider.hrh" | 
|         |     24 #include "BrowserViewImagesPopup.h" | 
|         |     25 #include "PhotoOperationWait.h" | 
|         |     26 #include "BrowserViewImagesListBox.h" | 
|         |     27  | 
|         |     28 // SYSTEM INCLUDES | 
|         |     29 #include <documenthandler.h> | 
|         |     30 #include <apmstd.h> | 
|         |     31 #include <Uri16.h> | 
|         |     32 #include <aknenv.h> | 
|         |     33 #include <avkon.mbg> | 
|         |     34 #include <akneditstateindicator.h> | 
|         |     35 #include <AknsListBoxBackgroundControlContext.h> | 
|         |     36 #include <AiwGenericParam.h> | 
|         |     37  | 
|         |     38 // Resources | 
|         |     39 #include <BrowserDialogsProvider.rsg> | 
|         |     40  | 
|         |     41 //----------------------------------------------------------------------------- | 
|         |     42 //  CBrowserViewImagesPopup::CBrowserViewImagesPopup() | 
|         |     43 // | 
|         |     44 //  Default Constructor | 
|         |     45 //----------------------------------------------------------------------------- | 
|         |     46 // | 
|         |     47 CBrowserViewImagesPopup::CBrowserViewImagesPopup() | 
|         |     48     { | 
|         |     49     } | 
|         |     50  | 
|         |     51 //----------------------------------------------------------------------------- | 
|         |     52 //  CBrowserViewImagesPopup::~CBrowserViewImagesPopup() | 
|         |     53 // | 
|         |     54 //  Destructor | 
|         |     55 //----------------------------------------------------------------------------- | 
|         |     56 // | 
|         |     57 CBrowserViewImagesPopup::~CBrowserViewImagesPopup() | 
|         |     58     { | 
|         |     59     delete iListBox; | 
|         |     60     delete iPhotoOperationWait; | 
|         |     61     delete iSkinContext; | 
|         |     62     } | 
|         |     63  | 
|         |     64  | 
|         |     65 //----------------------------------------------------------------------------- | 
|         |     66 //  CBrowserViewImagesPopup::ConstructL(  | 
|         |     67 //                            CArrayFixFlat<TBrCtlImageCarrier>& aPageImages ) | 
|         |     68 //----------------------------------------------------------------------------- | 
|         |     69 // | 
|         |     70 void CBrowserViewImagesPopup::ConstructL(  | 
|         |     71                             CArrayFixFlat<TBrCtlImageCarrier>& aPageImages ) | 
|         |     72     { | 
|         |     73     delete iListBox; | 
|         |     74     iListBox = NULL; | 
|         |     75     iListBox = new (ELeave) CBrowserViewImagesListBox(); | 
|         |     76      | 
|         |     77     ConstructL( iListBox,  | 
|         |     78                         R_DIALOGSPROVIDER_VIEWIMAGES_BUTTONS,  | 
|         |     79                         AknPopupLayouts::EMenuDoubleLargeGraphicWindow ); | 
|         |     80  | 
|         |     81     iListBox->ConstructL( *this, aPageImages ); | 
|         |     82     iListBox->CreateScrollBarFrameL( ETrue ); | 
|         |     83     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(  | 
|         |     84                         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); | 
|         |     85     iListBox->SetObserver(this); | 
|         |     86  | 
|         |     87     iListBox->StartConversionL();        // start thumbnailing | 
|         |     88  | 
|         |     89     HBufC* title = CEikonEnv::Static()->AllocReadResourceL( | 
|         |     90                                                 R_BROWSER_QUERY_SELECT_IMAGE); | 
|         |     91     CleanupStack::PushL(title); | 
|         |     92     SetTitleL(*title); | 
|         |     93     CleanupStack::PopAndDestroy();  // title | 
|         |     94     } | 
|         |     95  | 
|         |     96  | 
|         |     97 //----------------------------------------------------------------------------- | 
|         |     98 //  CBrowserViewImagesPopup::ConstructL( CEikListBox *aListBox,  | 
|         |     99 //                                      TInt aCbaResource, | 
|         |    100 //                                      AknPopupLayouts::TAknPopupLayouts aType ) | 
|         |    101 //  Private constructor | 
|         |    102 //----------------------------------------------------------------------------- | 
|         |    103 // | 
|         |    104 void CBrowserViewImagesPopup::ConstructL( CEikListBox *aListBox,  | 
|         |    105                                         TInt aCbaResource, | 
|         |    106                                         AknPopupLayouts::TAknPopupLayouts aType ) | 
|         |    107     { | 
|         |    108     CAknPopupList::ConstructL(aListBox, aCbaResource, aType); | 
|         |    109     iPhotoOperationWait = CPhotoOperationWait::NewL(); | 
|         |    110  | 
|         |    111     TAknsItemID tileIID = KAknsIIDSkinBmpListPaneNarrowA; | 
|         |    112  | 
|         |    113     AknLayoutUtils::SAknLayoutRect tile = { 0, 0,0, ELayoutEmpty, ELayoutEmpty, 20, 144 }; | 
|         |    114     AknLayoutUtils::SAknLayoutRect bg = { 0, 0, 0, ELayoutEmpty, ELayoutEmpty, 176, 144 }; | 
|         |    115     if (AknLayoutUtils::LayoutMirrored()) | 
|         |    116     { | 
|         |    117         tile.iL = ELayoutEmpty; | 
|         |    118         tile.iR = 0; | 
|         |    119     } | 
|         |    120      | 
|         |    121     TRect clientRect( 0, 0, 176, 144 ); | 
|         |    122     TAknLayoutRect tileRect; | 
|         |    123     tileRect.LayoutRect(clientRect, tile);   | 
|         |    124     TAknLayoutRect bgRect; | 
|         |    125     bgRect.LayoutRect(clientRect, bg); | 
|         |    126  | 
|         |    127     iSkinContext = CAknsListBoxBackgroundControlContext::NewL( | 
|         |    128         KAknsIIDSkinBmpMainPaneUsual,  | 
|         |    129         bgRect.Rect(), //TODOVRa: Should come from LAF! | 
|         |    130         EFalse, tileIID, | 
|         |    131         tileRect.Rect() ); //TODOVRa: Should come from LAF!     | 
|         |    132     } | 
|         |    133  | 
|         |    134  | 
|         |    135 // --------------------------------------------------------------------------- | 
|         |    136 // CBrowserViewImagesPopup::HandleListBoxEventL( CEikListBox* aListBox, | 
|         |    137 //                                                  TListBoxEvent aEventType ) | 
|         |    138 // --------------------------------------------------------------------------- | 
|         |    139 // | 
|         |    140 void CBrowserViewImagesPopup::HandleListBoxEventL( CEikListBox* aListBox,  | 
|         |    141                                                     TListBoxEvent aEventType ) | 
|         |    142     { | 
|         |    143     if((aEventType==EEventEnterKeyPressed || aEventType==EEventItemDoubleClicked) && aListBox==ListBox()) | 
|         |    144         { | 
|         |    145         ProcessCommandL( EDialogsProviderCmdViewImagesView ); | 
|         |    146         } | 
|         |    147     } | 
|         |    148  | 
|         |    149  | 
|         |    150 // --------------------------------------------------------------------------- | 
|         |    151 // CBrowserViewImagesPopup::HandleControlEventL( CCoeControl* /*aControl*/,  | 
|         |    152 //                                                  TCoeEvent /*aEventType*/ ) | 
|         |    153 // --------------------------------------------------------------------------- | 
|         |    154 // | 
|         |    155 void CBrowserViewImagesPopup::HandleControlEventL( CCoeControl* /*aControl*/,  | 
|         |    156                                                     TCoeEvent /*aEventType*/ ) | 
|         |    157     { | 
|         |    158     // CAknPopupList::HandleControlEventL(aControl, aEventType); | 
|         |    159     } | 
|         |    160  | 
|         |    161  | 
|         |    162 // --------------------------------------------------------------------------- | 
|         |    163 // CBrowserViewImagesPopup::PhotoOperationL() | 
|         |    164 // --------------------------------------------------------------------------- | 
|         |    165 // | 
|         |    166 void CBrowserViewImagesPopup::PhotoOperationL() | 
|         |    167     { | 
|         |    168     const TBrCtlImageCarrier& img = STATIC_CAST( CBrowserViewImagesListBox*, ListBox() )->CurrentlySelectedImage(); | 
|         |    169     iPopupFader.FadeBehindPopup( this, this, EFalse ); | 
|         |    170     PhotoOperationL(img, iPhotoOperationWait); | 
|         |    171     iPopupFader.FadeBehindPopup( this, this, ETrue ); | 
|         |    172     } | 
|         |    173  | 
|         |    174  | 
|         |    175 // --------------------------------------------------------------------------- | 
|         |    176 // CBrowserViewImagesPopup::LaunchPhotoAlbumL() | 
|         |    177 // --------------------------------------------------------------------------- | 
|         |    178 // | 
|         |    179 void CBrowserViewImagesPopup::LaunchPhotoAlbumL() | 
|         |    180     { | 
|         |    181     if(!iPhotoOperationWait->IsStarted()) | 
|         |    182         { | 
|         |    183         iPhotoOperationWait->SetViewActivate(ETrue); | 
|         |    184  | 
|         |    185         TRAPD( err, PhotoOperationL() ) | 
|         |    186  | 
|         |    187         if ( err == KErrNone ) | 
|         |    188             { | 
|         |    189             iPhotoOperationWait->SetViewActivate(EFalse); | 
|         |    190             } | 
|         |    191         else | 
|         |    192             { | 
|         |    193             iPhotoOperationWait->SetViewActivate(EFalse); | 
|         |    194             User::Leave( err ); | 
|         |    195             }                | 
|         |    196         } | 
|         |    197     } | 
|         |    198  | 
|         |    199  | 
|         |    200 // --------------------------------------------------------------------------- | 
|         |    201 // CBrowserViewImagesPopup::ProcessCommandL( TInt aCommandId ) | 
|         |    202 // --------------------------------------------------------------------------- | 
|         |    203 // | 
|         |    204 void CBrowserViewImagesPopup::ProcessCommandL( TInt aCommandId ) | 
|         |    205     { | 
|         |    206     switch(aCommandId) | 
|         |    207         { | 
|         |    208         case EDialogsProviderCmdViewImagesView: | 
|         |    209             LaunchPhotoAlbumL(); | 
|         |    210             break; | 
|         |    211         case EAknSoftkeyCancel: | 
|         |    212         default: | 
|         |    213             CancelPopup(); | 
|         |    214             break; | 
|         |    215         } | 
|         |    216     } | 
|         |    217  | 
|         |    218 // --------------------------------------------------------------------------- | 
|         |    219 // CBrowserViewImagesPopup::ProcessCommandL( TInt aCommandId ) | 
|         |    220 // --------------------------------------------------------------------------- | 
|         |    221 // | 
|         |    222 void CBrowserViewImagesPopup::PhotoOperationL(const TBrCtlImageCarrier& aImg, CPhotoOperationWait* aPhotoOperationWait) | 
|         |    223     { | 
|         |    224     TBool ownPhotoOperationWait = EFalse; | 
|         |    225     if (!aPhotoOperationWait) | 
|         |    226         { | 
|         |    227         aPhotoOperationWait = CPhotoOperationWait::NewL(); | 
|         |    228         ownPhotoOperationWait = ETrue; | 
|         |    229         } | 
|         |    230     HBufC* apu; | 
|         |    231     TInt locate; | 
|         |    232      | 
|         |    233     CEikProcess* process = CEikonEnv::Static()->Process(); | 
|         |    234     CDocumentHandler* docHandler = CDocumentHandler::NewLC(process); | 
|         |    235      | 
|         |    236     // Getting name for image from url. | 
|         |    237     TUriParser16 urlParser; | 
|         |    238     if ( aImg.AltText().Length() ) | 
|         |    239         { | 
|         |    240         urlParser.Parse( aImg.AltText() ); | 
|         |    241         } | 
|         |    242     else | 
|         |    243         { | 
|         |    244         urlParser.Parse( aImg.Url() ); | 
|         |    245         } | 
|         |    246     apu = urlParser.Extract(EUriPath).AllocLC(); | 
|         |    247     locate = apu->LocateReverseF('/'); | 
|         |    248     locate++; | 
|         |    249     apu->Des().Delete(0, locate); | 
|         |    250      | 
|         |    251     // Inform DocumentHandler of image type, if not recognized but handled | 
|         |    252     TBuf8<128> mimeType; | 
|         |    253     _LIT(KWbmpDataType, "image/vnd.wap.wbmp"); | 
|         |    254     _LIT(KOtaDataType, "image/vnd.nokia.ota-bitmap"); | 
|         |    255     _LIT( KEmptyDataType, "" ); | 
|         |    256      | 
|         |    257     if ( aImg.ImageType() == EImageTypeWbmp ) | 
|         |    258         { | 
|         |    259         // WBMP image | 
|         |    260         mimeType.Copy(KWbmpDataType); | 
|         |    261         } | 
|         |    262     else if ( aImg.ImageType() == EImageTypeOta ) | 
|         |    263         { | 
|         |    264         // OTA image | 
|         |    265         mimeType.Copy( KOtaDataType ); | 
|         |    266         } | 
|         |    267     else | 
|         |    268         { | 
|         |    269         mimeType.Copy( KEmptyDataType  ); | 
|         |    270         } | 
|         |    271      | 
|         |    272     TDataType dataType( mimeType ); | 
|         |    273      | 
|         |    274     // remove fading behind popup during displaying the image | 
|         |    275 //    iPopupFader.FadeBehindPopup( this, this, EFalse ); | 
|         |    276      | 
|         |    277     // launch photo album | 
|         |    278     CAiwGenericParamList& paramList = docHandler->InParamListL(); | 
|         |    279      | 
|         |    280      // Allow save | 
|         |    281     TBool allowSave( ETrue ); | 
|         |    282     TAiwVariant allowSaveVariant(allowSave); | 
|         |    283     TAiwGenericParam genericParamAllowSave( EGenericParamAllowSave,  | 
|         |    284                                             allowSaveVariant ); | 
|         |    285     paramList.AppendL( genericParamAllowSave ); | 
|         |    286      | 
|         |    287     RFile tempFile;  | 
|         |    288     TRAPD(err, docHandler->SaveTempFileL( aImg.RawData(), dataType, apu->Des(), tempFile )); | 
|         |    289     if (err != KErrNone) | 
|         |    290         { | 
|         |    291         if (aImg.AltText().Length()) | 
|         |    292             { | 
|         |    293             urlParser.Parse( aImg.Url() ); | 
|         |    294             CleanupStack::PopAndDestroy(); // apu | 
|         |    295             apu = NULL; | 
|         |    296             apu = urlParser.Extract(EUriPath).AllocLC(); | 
|         |    297             locate = apu->LocateReverseF('/'); | 
|         |    298             locate++; | 
|         |    299             apu->Des().Delete(0, locate); | 
|         |    300             docHandler->SaveTempFileL( aImg.RawData(), dataType, apu->Des(), tempFile ); | 
|         |    301             } | 
|         |    302         else | 
|         |    303             { | 
|         |    304             User::Leave(err); | 
|         |    305             } | 
|         |    306         } | 
|         |    307     CleanupClosePushL( tempFile ); | 
|         |    308     docHandler->OpenFileEmbeddedL( tempFile, dataType, paramList ); | 
|         |    309     CleanupStack::PopAndDestroy( &tempFile ); // tempFile | 
|         |    310  | 
|         |    311     // wait until user returns from the photo album | 
|         |    312     docHandler->SetExitObserver(aPhotoOperationWait); | 
|         |    313     aPhotoOperationWait->Wait(); | 
|         |    314      | 
|         |    315     // restore fading behind popup | 
|         |    316 //    iPopupFader.FadeBehindPopup( this, this, ETrue ); | 
|         |    317      | 
|         |    318     CleanupStack::PopAndDestroy(2);  // docHandler,apu | 
|         |    319  | 
|         |    320     if (ownPhotoOperationWait) | 
|         |    321         { | 
|         |    322         delete aPhotoOperationWait; | 
|         |    323         aPhotoOperationWait = NULL; | 
|         |    324         } | 
|         |    325     } | 
|         |    326  | 
|         |    327  | 
|         |    328 // --------------------------------------------------------------------------- | 
|         |    329 // CBrowserViewImagesPopup::MopSupplyObject( TTypeUid aId ) | 
|         |    330 // --------------------------------------------------------------------------- | 
|         |    331 // | 
|         |    332 TTypeUid::Ptr CBrowserViewImagesPopup::MopSupplyObject( TTypeUid aId ) | 
|         |    333     { | 
|         |    334     return CAknPopupList::MopSupplyObject(aId); | 
|         |    335     } | 
|         |    336  | 
|         |    337 // --------------------------------------------------------------------------- | 
|         |    338 // CBrowserViewImagesPopup::AttemptExitL(TBool aAccept) | 
|         |    339 // | 
|         |    340 // Overrides CAknPopupList's AttemptExitL | 
|         |    341 // Popup should not be deleted if still in use | 
|         |    342 // --------------------------------------------------------------------------- | 
|         |    343 // | 
|         |    344 void CBrowserViewImagesPopup::AttemptExitL(TBool aAccept) | 
|         |    345     { | 
|         |    346  | 
|         |    347     if ( IsAppShutterActive() && iPhotoOperationWait->IsStarted() ) | 
|         |    348         { | 
|         |    349         iPhotoOperationWait->DoCancel(); | 
|         |    350         } | 
|         |    351  | 
|         |    352     if (!iPhotoOperationWait->IsStarted()) | 
|         |    353         { | 
|         |    354         if (iReturn) //Always not null unless ExecuteLD leaves | 
|         |    355             *iReturn = aAccept; | 
|         |    356         //delete this; | 
|         |    357         } | 
|         |    358         //Need to call the base class api also | 
|         |    359         CAknPopupList::AttemptExitL(aAccept); | 
|         |    360     } | 
|         |    361  | 
|         |    362 // --------------------------------------------------------------------------- | 
|         |    363 // CBrowserViewImagesPopup::IsAppShutterActive | 
|         |    364 // --------------------------------------------------------------------------- | 
|         |    365 // | 
|         |    366 TBool CBrowserViewImagesPopup::IsAppShutterActive() | 
|         |    367     { | 
|         |    368     CAknAppUi* shuttingApp = CAknEnv::AppWithShutterRunning(); | 
|         |    369  | 
|         |    370     if ( shuttingApp ) | 
|         |    371         { | 
|         |    372         return ETrue; | 
|         |    373         } | 
|         |    374     else | 
|         |    375         { | 
|         |    376         return EFalse; | 
|         |    377         } | 
|         |    378     } | 
|         |    379 // End of File |