photosgallery/controllers/fetcher/src/glxfetcherdialog.cpp
branchRCL_3
changeset 60 5b3385a43d68
child 75 01504893d9cb
equal deleted inserted replaced
59:8e5f6eea9c9f 60:5b3385a43d68
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    Creates a Fetcher Dialog
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //  EXTERNAL INCLUDES
       
    21 #include <aknappui.h>
       
    22 #include <akntoolbar.h>
       
    23 #include <eikdialg.h>					  // for CEikDialog
       
    24 #include <AknUtils.h>
       
    25 #include <StringLoader.h>
       
    26 #include <eikdialogext.h>
       
    27 #include <AknsBasicBackgroundControlContext.h>
       
    28 #include <MMGFetchVerifier.h>             // For VerifySelectionL()
       
    29 #include <glxresourceutilities.h>         // for CGlxResourceUtilities
       
    30 #include <glxuiutility.h>
       
    31 #include <glxscreenfurniture.h>
       
    32 #include <glxtracer.h> 					  // Logging macros
       
    33 #include <glxlog.h>
       
    34 #include <glxcommandhandlers.hrh>         //command ids
       
    35 #include <data_caging_path_literals.hrh>  // KDC_APP_RESOURCE_DIR
       
    36 #include <mglxmedialist.h>				  // MGlxMediaList, CMPXCollectionPath
       
    37 
       
    38 #include <alf/alfevent.h>
       
    39 #include <alf/alfdisplay.h>
       
    40 
       
    41 //  CLASS HEADER
       
    42 #include <glxfetcherdialog.rsg>           // FOR GETTING VIEW ID AND RESOURCE ID
       
    43 #include "glxfetcherdialog.h"
       
    44 #include "glxfetchercontainer.h"
       
    45 #include "glxfetcher.hrh"
       
    46 
       
    47 const TInt KControlId = 1;
       
    48 
       
    49 _LIT(KGlxGridviewResource, "glxgridviewdata.rsc");
       
    50 
       
    51 //-----------------------------------------------------------------------------
       
    52 // C++ default constructor.
       
    53 //-----------------------------------------------------------------------------
       
    54 inline CGlxFetcherDialog::CGlxFetcherDialog(
       
    55             CDesCArray& aSelectedFiles, 
       
    56             MMGFetchVerifier* aVerifier, 
       
    57             TGlxFilterItemType aFilterType,
       
    58             const TDesC& aTitle,
       
    59             TBool aMultiSelectionEnabled)
       
    60         : iSelectedFiles( aSelectedFiles ),
       
    61           iVerifier( aVerifier ),
       
    62           iFilterType( aFilterType ),
       
    63           iTitle( aTitle ),
       
    64           iMultiSelectionEnabled(aMultiSelectionEnabled)
       
    65 	{
       
    66 	TRACER("CGlxFetcherDialog::CGlxFetcherDialog");
       
    67 	// No implementation required
       
    68 	}
       
    69 
       
    70 //-----------------------------------------------------------------------------
       
    71 // Two-phased constructor.
       
    72 //-----------------------------------------------------------------------------
       
    73 CGlxFetcherDialog* CGlxFetcherDialog::NewL(CDesCArray& aSelectedFiles, 
       
    74                MMGFetchVerifier* aVerifier, TGlxFilterItemType aFilterType ,
       
    75                 const TDesC& aTitle, TBool aMultiSelectionEnabled )
       
    76 	{
       
    77 	TRACER("CGlxFetcherDialog::NewL");
       
    78 	CGlxFetcherDialog* self=
       
    79 	    new( ELeave ) CGlxFetcherDialog(
       
    80 	        aSelectedFiles, aVerifier, aFilterType, aTitle, aMultiSelectionEnabled );
       
    81     CleanupStack::PushL( self );
       
    82     self->ConstructL();
       
    83     CleanupStack::Pop( self );
       
    84     return self;
       
    85    	}
       
    86 
       
    87 //-----------------------------------------------------------------------------
       
    88 // Destructor
       
    89 //-----------------------------------------------------------------------------
       
    90 CGlxFetcherDialog::~CGlxFetcherDialog()
       
    91 	{
       
    92 	TRACER("CGlxFetcherDialog::~CGlxFetcherDialog");
       
    93     if (iResourceOffset)
       
    94         {
       
    95         CCoeEnv::Static()->DeleteResourceFile(iResourceOffset);
       
    96         }
       
    97     
       
    98 	if(iMMCNotifier)
       
    99 	    {
       
   100         delete iMMCNotifier;
       
   101         iMMCNotifier = NULL;
       
   102 	    }
       
   103 	if(iFetcherContainer)
       
   104 	    {
       
   105 	    // Restore the Toolbar as it was in the Calling application
       
   106 	    if(iAvkonAppUi->CurrentFixedToolbar())  // there is Hardware Specific Output for Fixed ToolBar
       
   107 	        {
       
   108 	        iAvkonAppUi->CurrentFixedToolbar()->SetToolbarVisibility(ETrue);
       
   109 	        }
       
   110 
       
   111 	    TRAP_IGNORE(iFetcherContainer->SetPreviousTitleL());
       
   112 		}
       
   113 	if (iUiUtility)
       
   114 		{
       
   115 	    iUiUtility->Close();
       
   116 		}
       
   117 	}
       
   118 
       
   119 //-----------------------------------------------------------------------------
       
   120 // Symbian 2nd phase constructor can leave.
       
   121 // Create the alfscreenbuffer with a generic buffer screen id
       
   122 //-----------------------------------------------------------------------------
       
   123 void CGlxFetcherDialog::ConstructL()
       
   124 	{
       
   125 	TRACER("CGlxFetcherDialog::ConstructL");
       
   126 	// always first call the base class
       
   127     CAknDialog::ConstructL( R_MULTISELECT_FETCHER_MENUBAR );
       
   128 
       
   129     // Get the Instance of the toolbar and disable it as it is note required in the Fetcher Application
       
   130     if (iAvkonAppUi->CurrentFixedToolbar())  // there is Hardware Specific Output for Fixed ToolBar
       
   131         {
       
   132         iAvkonAppUi->CurrentFixedToolbar()->SetToolbarVisibility(EFalse);
       
   133         }
       
   134     
       
   135     // Load resource file for grid view empty text
       
   136     TParse parse;
       
   137     parse.Set(KGlxGridviewResource, &KDC_APP_RESOURCE_DIR, NULL);
       
   138     TFileName resourceFile;
       
   139     resourceFile.Append(parse.FullName());
       
   140     CGlxResourceUtilities::GetResourceFilenameL(resourceFile);  
       
   141     iResourceOffset = CCoeEnv::Static()->AddResourceFileL(resourceFile);
       
   142     
       
   143 	// Get the Hitchcock environment.
       
   144     iUiUtility = CGlxUiUtility::UtilityL();
       
   145     iFetchUri = EFalse;
       
   146     iMMCNotifier = CGlxMMCNotifier::NewL(*this);
       
   147     }
       
   148     
       
   149 //-----------------------------------------------------------------------------
       
   150 // CGlxFetcherDialog::CreateCustomControlL
       
   151 //-----------------------------------------------------------------------------
       
   152 SEikControlInfo CGlxFetcherDialog::CreateCustomControlL(TInt aControlType)
       
   153     {
       
   154     TRACER("CGlxFetcherDialog::CreateCustomControlL");
       
   155     // Create Carousal control and add it to HUI CCoecontrol
       
   156     SEikControlInfo controlInfo;
       
   157     controlInfo.iControl = NULL;
       
   158     controlInfo.iTrailerTextId = 0;
       
   159     controlInfo.iFlags = 0;
       
   160 
       
   161     switch( aControlType )
       
   162         {
       
   163         case EFetcherControl :
       
   164             {
       
   165             iFetcherContainer = CGlxFetcherContainer::NewL( 
       
   166                     iFilterType, iTitle, *this, iMultiSelectionEnabled );
       
   167             controlInfo.iControl = iFetcherContainer;  // transfers ownership      
       
   168             break;
       
   169             }
       
   170         default :
       
   171             break;
       
   172         }
       
   173     return controlInfo;
       
   174     }
       
   175 
       
   176 //-----------------------------------------------------------------------------
       
   177 // CGlxFetcherDialog::ProcessCommandL
       
   178 // This processes the events to the OkToExitL
       
   179 //-----------------------------------------------------------------------------
       
   180 void CGlxFetcherDialog::ProcessCommandL(TInt aCommandId)
       
   181 	{
       
   182 	TRACER("CGlxFetcherDialog::ProcessCommandL");
       
   183 
       
   184 	if( iMenuBar )
       
   185 	    {
       
   186 	    iMenuBar->StopDisplayingMenuBar();
       
   187 	    }
       
   188 	switch( aCommandId )
       
   189 		{
       
   190 		case EAknSoftkeyCancel :
       
   191 			{
       
   192 			TryExitL( aCommandId );
       
   193 			break;
       
   194 			}
       
   195 		case EAknSoftkeySelect :
       
   196 		case EGlxCmdSelectMarked :
       
   197         case EAknSoftkeyOk :
       
   198             {
       
   199             GLX_LOG_INFO("CGlxFetcherDialog::ProcessCommandL() : EAknSoftkeyOk");
       
   200 			TryExitL( aCommandId );
       
   201 			break;
       
   202             }
       
   203 		default :
       
   204 		    {
       
   205             iFetcherContainer->DoExecuteL( aCommandId );
       
   206             break;
       
   207 		    }
       
   208 		}
       
   209 	}
       
   210 
       
   211 //-----------------------------------------------------------------------------
       
   212 // CGlxFetcherDialog::OkToExitL
       
   213 //-----------------------------------------------------------------------------
       
   214 TBool CGlxFetcherDialog::OkToExitL(TInt aKeycode)
       
   215 	{
       
   216     TRACER("CGlxFetcherDialog::OkToExitL");
       
   217     GLX_LOG_INFO1("CGlxFetcherDialog::OkToExitL : %d",aKeycode );
       
   218     TBool retVal = ETrue;
       
   219     TBool retrieveUriValue = EFalse;
       
   220     switch (aKeycode)
       
   221         {
       
   222         case EAknSoftkeySelect:
       
   223         case EGlxCmdSelectMarked:
       
   224         case EAknSoftkeyOk:
       
   225         case EAknCmdOpen:
       
   226             {
       
   227             // Retreives the uri's of the selected files and verifies if it is a 
       
   228             // supported format
       
   229             if (!iFetchUri)
       
   230                 {
       
   231                 iFetchUri = ETrue;
       
   232                 retrieveUriValue = iFetcherContainer->RetrieveUrisL(
       
   233                         iSelectedFiles, iFetchUri);
       
   234                 if (iVerifier
       
   235                         && !iVerifier->VerifySelectionL(&iSelectedFiles))
       
   236                     {
       
   237                     GLX_LOG_INFO("CGlxFetcherDialog::OkToExitL : "
       
   238                             " VerifySelectionL() failed!");
       
   239                     iSelectedFiles.Reset();
       
   240                     retVal = EFalse;
       
   241                     //if the corrupt file is selected then reset the flag to again enable
       
   242                     //the selection.
       
   243                     iFetcherContainer->SetFileAttached(EFalse);
       
   244                     }
       
   245                 if (!retrieveUriValue)
       
   246                     {
       
   247                     retVal = EFalse;
       
   248                     }
       
   249                 if (iMultiSelectionEnabled && retVal)
       
   250                     {
       
   251                     iFetcherContainer->DoExecuteL(EGlxCmdEndMultipleMarking);
       
   252                     }
       
   253                 }
       
   254             else
       
   255                 {
       
   256                 // if uri is being fetched then do not set the return value true, else it would cause
       
   257                 // Destructor of Dialog to be called and result in a crash when OKtoExitL is called multiple times.
       
   258                 retVal = EFalse;
       
   259                 }
       
   260             break;
       
   261             }
       
   262         case EAknSoftkeyCancel: // exit dialog
       
   263         case EAknCmdExit:
       
   264             {
       
   265             break;
       
   266             }
       
   267         case EAknCmdMark:
       
   268         case EAknSoftkeyMark:
       
   269             {
       
   270             if (iMultiSelectionEnabled)
       
   271                 {
       
   272                 if (iUiUtility->IsPenSupported())
       
   273                     {
       
   274                     //Since the MSK is disabled we always get EAknCmdMark
       
   275                     //when we select msk hardkey in touch phone, so we need 
       
   276                     //to toggle between mark/unmark on the same hardkey event
       
   277                     if (!iMarkStarted)
       
   278                         {
       
   279                         iFetcherContainer->DoExecuteL(
       
   280                                 EGlxCmdStartMultipleMarking);
       
   281                         iMarkStarted = ETrue;
       
   282                         }
       
   283                     else
       
   284                         {
       
   285                         MGlxMediaList& mediaList =
       
   286                                 iFetcherContainer->MediaList();
       
   287                         TInt focusIdx = mediaList.FocusIndex();
       
   288                         if (mediaList.IsSelected(focusIdx))
       
   289                             iFetcherContainer->DoExecuteL(EAknCmdUnmark);
       
   290                         else
       
   291                             iFetcherContainer->DoExecuteL(EAknCmdMark);
       
   292                         }
       
   293                     }
       
   294                 else
       
   295                     {
       
   296                     if (!iMarkStarted)
       
   297                         {
       
   298                         iFetcherContainer->DoExecuteL(
       
   299                                 EGlxCmdStartMultipleMarking);
       
   300                         iMarkStarted = ETrue;
       
   301                         }
       
   302                     else
       
   303                         {
       
   304                         iFetcherContainer->DoExecuteL(EAknCmdMark);
       
   305                         }
       
   306                     }
       
   307                 }
       
   308             retVal = EFalse;
       
   309             break;
       
   310             }
       
   311         case EAknCmdUnmark:
       
   312         case EAknSoftkeyUnmark:
       
   313             {
       
   314             if (iMultiSelectionEnabled)
       
   315                 {
       
   316                 iFetcherContainer->DoExecuteL(EAknCmdUnmark);
       
   317 
       
   318                 //@ fix for ELWU-7RA7NX 
       
   319                 //@ Reset the flag on no selection, else it'll not pass the events to container for
       
   320                 //@ EGlxCmdStartMultipleMarking  case.
       
   321                 MGlxMediaList& mediaList = iFetcherContainer->MediaList();
       
   322                 if (mediaList.SelectionCount() <= 0)
       
   323                     {
       
   324                     iMarkStarted = EFalse;
       
   325                     }
       
   326 
       
   327                 HBufC* mskTextMark = StringLoader::LoadLC(R_GLX_MARKING_MARK);
       
   328                 HBufC* rskTextCancel = StringLoader::LoadLC(
       
   329                         R_GLX_SOFTKEY_CANCEL);
       
   330                 iUiUtility->ScreenFurniture()->ModifySoftkeyIdL(
       
   331                         CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   332                         EAknCmdMark, 0, *mskTextMark);
       
   333                 iUiUtility->ScreenFurniture()->ModifySoftkeyIdL(
       
   334                         CEikButtonGroupContainer::ERightSoftkeyPosition,
       
   335                         EAknSoftkeyCancel, 0, *rskTextCancel);
       
   336                 CleanupStack::PopAndDestroy(rskTextCancel);
       
   337                 CleanupStack::PopAndDestroy(mskTextMark);
       
   338                 }
       
   339             retVal = EFalse;
       
   340             break;
       
   341             }
       
   342         default:
       
   343             break;
       
   344         }
       
   345 
       
   346     GLX_LOG_INFO1("CGlxFetcherDialog::OkToExitL : retVal(%d)", retVal);
       
   347     return retVal;
       
   348     }
       
   349 
       
   350 //-----------------------------------------------------------------------------
       
   351 // CGlxFetcherDialog::SizeChanged
       
   352 //-----------------------------------------------------------------------------
       
   353 void CGlxFetcherDialog::SizeChanged()
       
   354 	{
       
   355 	TRACER("CGlxFetcherDialog::SizeChanged");
       
   356 	if (iFetcherContainer)
       
   357 	    {
       
   358 	    TRAP_IGNORE (iFetcherContainer->HandleSizeChangeL());    
       
   359 	    }
       
   360 	}
       
   361 
       
   362 //-----------------------------------------------------------------------------
       
   363 // CGlxFetcherDialog::PreLayoutDynInitL
       
   364 //-----------------------------------------------------------------------------
       
   365 void CGlxFetcherDialog::PreLayoutDynInitL()
       
   366     {
       
   367     TRACER("CGlxFetcherDialog::PreLayoutDynInitL");
       
   368     CreateLineByTypeL( KNullDesC, KControlId, EFetcherControl, NULL );
       
   369     }
       
   370 //-----------------------------------------------------------------------------
       
   371 // CGlxFetcherDialog::PostLayoutDynInitL
       
   372 //-----------------------------------------------------------------------------
       
   373 void CGlxFetcherDialog::PostLayoutDynInitL()
       
   374     {
       
   375     TRACER("CGlxFetcherDialog::PostLayoutDynInitL");
       
   376     
       
   377     if (!iUiUtility->IsPenSupported())
       
   378         {
       
   379         CEikButtonGroupContainer& cbaContainer = ButtonGroupContainer();
       
   380         if (iMultiSelectionEnabled)
       
   381             {
       
   382             cbaContainer.SetCommandSetL(R_AVKON_SOFTKEYS_OK_CANCEL__MARK);
       
   383             }
       
   384         else
       
   385             {
       
   386             cbaContainer.SetCommandSetL(
       
   387                     R_AVKON_SOFTKEYS_SELECT_CANCEL__SELECT);
       
   388             }
       
   389         cbaContainer.DrawNow();
       
   390         }
       
   391 
       
   392     // Create and Display Grid widget 
       
   393     iFetcherContainer->CreateAndDisplayGridL();
       
   394     }
       
   395 
       
   396 //-----------------------------------------------------------------------------
       
   397 // CGlxFetcherDialog::OfferKeyEventL
       
   398 //-----------------------------------------------------------------------------
       
   399 TKeyResponse CGlxFetcherDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,
       
   400         TEventCode aType)
       
   401     {
       
   402     TRACER("CGlxFetcherDialog::OfferKeyEventL");
       
   403     TKeyResponse response = EKeyWasNotConsumed;
       
   404     response = iFetcherContainer->OfferKeyEventL(aKeyEvent,aType);
       
   405  
       
   406     if(response == EKeyWasNotConsumed)
       
   407         {
       
   408         response = CAknDialog::OfferKeyEventL(aKeyEvent,aType);
       
   409         }
       
   410 
       
   411     return response;    
       
   412     }
       
   413 
       
   414 //-----------------------------------------------------------------------------
       
   415 // CGlxFetcherDialog::HandleDoubleTapEventL
       
   416 // Callback from the container for double tap events
       
   417 // Offers the event from container to Dialog
       
   418 //-----------------------------------------------------------------------------
       
   419 void CGlxFetcherDialog::HandleDoubleTapEventL(TInt aCommandId)
       
   420     {
       
   421     TRACER("CGlxFetcherDialog::HandleDoubleTapEventL");
       
   422     Extension()->iPublicFlags.Set(CEikDialogExtension::EDelayedExit);
       
   423     ProcessCommandL(aCommandId);
       
   424     Extension()->iPublicFlags.Clear(CEikDialogExtension::EDelayedExit);
       
   425     }
       
   426     
       
   427 //-----------------------------------------------------------------------------
       
   428 // CGlxFetcherDialog::HandleMarkEventL
       
   429 // Callback from the container to process the mark/unmark events.
       
   430 //-----------------------------------------------------------------------------
       
   431 void CGlxFetcherDialog::HandleMarkEventL()
       
   432     {
       
   433     TRACER("CGlxFetcherDialog::HandleMarkEventL");
       
   434     if ( iUiUtility->IsPenSupported() )
       
   435         {
       
   436         MGlxMediaList& mediaList = iFetcherContainer->MediaList();
       
   437         CEikButtonGroupContainer& cbaContainer = ButtonGroupContainer();
       
   438         if (mediaList.SelectionCount())
       
   439             {
       
   440             cbaContainer.SetCommandSetL(R_AVKON_SOFTKEYS_OK_CANCEL__MARK);
       
   441             }
       
   442         else
       
   443             {
       
   444             cbaContainer.SetCommandSetL(R_AVKON_SOFTKEYS_CANCEL);
       
   445             }
       
   446         cbaContainer.DrawNow();
       
   447         }
       
   448     }
       
   449     
       
   450 //-----------------------------------------------------------------------------
       
   451 // CGlxFetcherDialog::CallCancelFetcherL
       
   452 // This function will be called from CGlxFetcher::CancelFetcherL
       
   453 // This will ensure exit of fetcher dialog & fetcher app
       
   454 //-----------------------------------------------------------------------------
       
   455 
       
   456 void CGlxFetcherDialog::CallCancelFetcherL(TInt aCommandId)
       
   457 	{
       
   458 	TRACER("CGlxFetcherDialog::CallCancelFetcherL");
       
   459 	TryExitL(aCommandId);
       
   460 	}
       
   461 
       
   462 //-----------------------------------------------------------------------------
       
   463 // CGlxFetcherDialog::HandleMMCRemovalL
       
   464 // This function will be called when MMC is removed
       
   465 // This will ensure exit of fetcher dialog.
       
   466 //-----------------------------------------------------------------------------
       
   467 void CGlxFetcherDialog::HandleMMCRemovalL()
       
   468     {
       
   469     TRACER("CGlxFetcherDialog::HandleMMCRemovalL");
       
   470     /*
       
   471      * need to delay the destruction of dialog.
       
   472      */
       
   473     Extension()->iPublicFlags.Set(CEikDialogExtension::EDelayedExit);
       
   474     ProcessCommandL(EAknSoftkeyCancel);
       
   475     Extension()->iPublicFlags.Clear(CEikDialogExtension::EDelayedExit);
       
   476     }
       
   477 //  End of File