upnpsettings/multiselectionui/src/upnpappmultiselectionpopup.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2008 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:      Multiselection popup implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDE FILES
       
    24 #include <StringLoader.h>
       
    25 #include <avkon.mbg>
       
    26 #include <eikclbd.h>
       
    27 #include <eiklbv.h> //clistboxview
       
    28 #include <aknlists.h>
       
    29 #include <AknsUtils.h>
       
    30 #include <eikcmbut.h>
       
    31 #include <badesca.h>
       
    32 
       
    33 #include "upnpappmultiselectionpopup.h"
       
    34 #include "upnpmultiselectionutility.h"
       
    35 #include "upnpfilesharingengine.h"
       
    36 
       
    37 #include "cupnpmultiselectionui.hrh"
       
    38 #include <cupnpmultiselectionui.rsg>
       
    39 
       
    40 _LIT( KComponentLogfile, "multiselectionui.txt");
       
    41 #include "upnplog.h"
       
    42 
       
    43 
       
    44 //CONSTANTS
       
    45 const TInt KOkSoftkeyCode = 63585;
       
    46 
       
    47 //FORWARD DECLARATIONS
       
    48 class CUPnPAppMultiselectionDialog;
       
    49 
       
    50 // ================= MEMBER FUNCTIONS =======================
       
    51 
       
    52 // --------------------------------------------------------------------------
       
    53 // CUPnPAppMultiselectionPopup::NewL
       
    54 // Two-phased constructor.
       
    55 // --------------------------------------------------------------------------
       
    56 //
       
    57 CUPnPAppMultiselectionPopup* CUPnPAppMultiselectionPopup::NewL(
       
    58     THomeConnectMediaType aMediaType,
       
    59     CUPnPFileSharingEngine* aFileSharingEngine,
       
    60     CListBoxView::CSelectionIndexArray* aSelectionIndexArray,
       
    61     const HBufC* aHeading )
       
    62     {
       
    63     __LOG( "CUPnPAppMultiselectionPopup::NewL begin" );
       
    64 
       
    65     CUPnPAppMultiselectionPopup* self =
       
    66                    new(ELeave) CUPnPAppMultiselectionPopup( NULL, aHeading );
       
    67 
       
    68     self->ConstructL( aMediaType, aFileSharingEngine,aSelectionIndexArray );
       
    69 
       
    70     __LOG("CUPnPAppMultiselectionPopup::NewL end");
       
    71     return self;
       
    72     }
       
    73 
       
    74 
       
    75 // --------------------------------------------------------------------------
       
    76 // CUPnPAppMultiselectionPopup::ConstructL
       
    77 // Symbian 2nd phase constructor can leave.
       
    78 // --------------------------------------------------------------------------
       
    79 //
       
    80 void CUPnPAppMultiselectionPopup::ConstructL(
       
    81     THomeConnectMediaType aMediaType,
       
    82     CUPnPFileSharingEngine* aFileSharingEngine,
       
    83     CListBoxView::CSelectionIndexArray* aSelectionIndexArray )
       
    84     {
       
    85     __LOG("CUPnPAppMultiselectionPopup::ConstructL begin");
       
    86 
       
    87     iMediaType = aMediaType;
       
    88     iFileSharingEngine = aFileSharingEngine;
       
    89     iPreviousSelection = aSelectionIndexArray;
       
    90     iUiMarked = new(ELeave) CArrayFixFlat<TInt>(3);
       
    91     iMarkedItems = new(ELeave) CArrayFixFlat<TInt>(3);
       
    92     iUtility = new (ELeave) CUpnpMultiselectionUtility();
       
    93     iMskSelectText = 
       
    94         StringLoader::LoadL( R_UPNP_MULTISELECTION_SELECT_TEXT );
       
    95     iMskUnselectText = 
       
    96         StringLoader::LoadL( R_UPNP_MULTISELECTION_UNSELECT_TEXT );
       
    97     
       
    98     __LOG("CUPnPAppMultiselectionPopup::ConstructL end");
       
    99     }
       
   100 
       
   101 // --------------------------------------------------------------------------
       
   102 // CUPnPAppMultiselectionPopup::CUPnPAppMultiselectionPopup
       
   103 // C++ default constructor can NOT contain any code, that
       
   104 // might leave.
       
   105 // --------------------------------------------------------------------------
       
   106 //
       
   107 CUPnPAppMultiselectionPopup::CUPnPAppMultiselectionPopup(
       
   108     CListBoxView::CSelectionIndexArray* aSelectionIndexArray, 
       
   109     const HBufC* aHeading )
       
   110     : CAknListQueryDialog( aSelectionIndexArray )
       
   111 
       
   112     {
       
   113     iHeading = aHeading;
       
   114     __LOG("CUPnPAppMultiselectionPopup::CUPnPAppMultiselectionPopup");
       
   115     }
       
   116 
       
   117 // --------------------------------------------------------------------------
       
   118 // CUPnPAppMultiselectionPopup::~CUPnPAppMultiselectionPopup
       
   119 // C++ default destructor.
       
   120 // --------------------------------------------------------------------------
       
   121 //
       
   122 CUPnPAppMultiselectionPopup::~CUPnPAppMultiselectionPopup()
       
   123     {
       
   124     __LOG("CUPnPAppMultiselectionPopup::~CUPnPAppMultiselectionPopup");
       
   125 
       
   126     iFileSharingEngine = NULL;
       
   127 
       
   128     delete iUiMarked;
       
   129     delete iMarkedItems;
       
   130     delete iUtility;
       
   131     delete iMskSelectText;
       
   132     delete iMskUnselectText;
       
   133 
       
   134     __LOG("CUPnPAppMultiselectionPopup::~CUPnPAppMultiselectionPopup end");
       
   135     }
       
   136 
       
   137 
       
   138 // --------------------------------------------------------------------------
       
   139 // CUPnPAppMultiselectionPopup::OkToExitL(TInt aButtonId)
       
   140 // called by framework when the softkey is pressed
       
   141 // --------------------------------------------------------------------------
       
   142 //
       
   143 TBool CUPnPAppMultiselectionPopup::OkToExitL( TInt aButtonId )
       
   144     {
       
   145     __LOG("CUPnPAppMultiselectionPopup::OkToExitL begin");
       
   146 
       
   147     if ( aButtonId == EAknSoftkeyOk )
       
   148         {
       
   149         __LOG("CUPnPAppMultiselectionPopup::OkToExitL: OK");
       
   150 
       
   151         const CArrayFix<TInt>* selected;
       
   152 
       
   153         //get the true indexes of marked items
       
   154         CAknListBoxFilterItems* filter 
       
   155                 = static_cast < CAknFilteredTextListBoxModel* >     
       
   156                                 ( iListBox->Model() )->Filter();
       
   157         if ( filter )
       
   158             {
       
   159             // Filter knows all.
       
   160             filter->UpdateSelectionIndexesL();
       
   161             selected = filter->SelectionIndexes();
       
   162             }
       
   163         else
       
   164             {
       
   165             // No filter.
       
   166             selected = ListBox()->View()->SelectionIndexes();
       
   167             }
       
   168             
       
   169         if ( iPreviousSelection )
       
   170             {
       
   171             iPreviousSelection->Reset();
       
   172             for ( TInt i = 0; i < selected->Count(); i++ )
       
   173                 {
       
   174                 TInt tmp = selected->At( i );
       
   175                 iPreviousSelection->AppendL( tmp );
       
   176                 }
       
   177             iUtility->ConvertSelectionsForEngineL( *iPreviousSelection );
       
   178             }
       
   179         }
       
   180 
       
   181 
       
   182     __LOG("CUPnPAppMultiselectionPopup::OkToExitL end");
       
   183     return ETrue;
       
   184     }
       
   185 
       
   186 
       
   187 // --------------------------------------------------------------------------
       
   188 // CUPnPAppMultiselectionPopup::PreLayoutDynInitL();
       
   189 // called by framework before dialog is shown
       
   190 // --------------------------------------------------------------------------
       
   191 //
       
   192 void CUPnPAppMultiselectionPopup::PreLayoutDynInitL()
       
   193     {
       
   194     __LOG("CUPnPAppMultiselectionPopup::PreLayoutDynInitL begin");
       
   195 
       
   196     //mark selected albums
       
   197 
       
   198     iListBox = ListBox();
       
   199     iModel = STATIC_CAST(
       
   200         CAknFilteredTextListBoxModel*, iListBox->Model());
       
   201 
       
   202     iSettingsTextArray = static_cast<CDesCArray*>(
       
   203         iModel->ItemTextArray());
       
   204 
       
   205     iUtility->AppendShareAllSelectionL( iSettingsTextArray );
       
   206 
       
   207     iFileSharingEngine->RequestSelectionContentL( iMediaType );
       
   208     iState = ELoadContent;
       
   209 
       
   210     CAknWaitNoteWrapper* waitNoteWrapper = CAknWaitNoteWrapper::NewL();
       
   211     CleanupStack::PushL(reinterpret_cast<CBase*>(waitNoteWrapper));
       
   212     waitNoteWrapper->ExecuteL(
       
   213         R_UPNP_MULTISELECTION_SEARCHING_FILES_NOTE,      // TInt aResId,
       
   214         *this,           // MAknBackgroundProcess& aBackgroundProcess
       
   215         EFalse);   // ETrue = Show immediately
       
   216 
       
   217     CleanupStack::PopAndDestroy(waitNoteWrapper);
       
   218 
       
   219     CAknIconArray* icons = new (ELeave) CAknIconArray(2);
       
   220     CleanupStack::PushL( icons );
       
   221 
       
   222     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   223     TFileName iconsPath( AknIconUtils::AvkonIconFileName( ) );
       
   224 
       
   225     iUtility->AppendIconToArrayL( icons, skin,
       
   226                         iconsPath,
       
   227                         KAknsIIDQgnPropCheckboxOn,
       
   228                         EMbmAvkonQgn_prop_checkbox_on,
       
   229                         EMbmAvkonQgn_prop_checkbox_on_mask );
       
   230 
       
   231     iUtility->AppendIconToArrayL( icons, skin,
       
   232                         iconsPath,
       
   233                         KAknsIIDQgnPropCheckboxOff,
       
   234                         EMbmAvkonQgn_prop_checkbox_off,
       
   235                         EMbmAvkonQgn_prop_checkbox_off_mask );
       
   236 
       
   237 
       
   238     CAknListQueryDialog::SetIconArrayL(icons);
       
   239 
       
   240     CleanupStack::Pop(icons);
       
   241     
       
   242     SetHeaderTextL( *iHeading );
       
   243     
       
   244     ListBox()->ActivateL();
       
   245 
       
   246     CAknListQueryDialog::PreLayoutDynInitL();
       
   247 
       
   248     __LOG("CUPnPAppMultiselectionPopup::PreLayoutDynInitL end");
       
   249     }
       
   250 
       
   251 // --------------------------------------------------------------------------
       
   252 // CUPnPAppMultiselectionPopup::PostLayoutDynInitL()
       
   253 // Called by framework before dialog is shown.
       
   254 // Needed because filter is not active until PreLayoutDynInitL().
       
   255 // --------------------------------------------------------------------------
       
   256 //
       
   257 void  CUPnPAppMultiselectionPopup::PostLayoutDynInitL()
       
   258     {
       
   259     __LOG("CUPnPAppMultiselectionPopup::PostLayoutDynInitL begin");
       
   260 
       
   261     // Get state of do not share and share all selections and set them 
       
   262     // to utility.
       
   263     TShareSelectionState selectionState = 
       
   264         iUtility->ShareSelectionStateFromArray( *iMarkedItems );
       
   265     iUtility->SetShareSelectionState( selectionState );
       
   266         
       
   267     TBool useMarked = EFalse;
       
   268     //mark selected albums
       
   269     if ( iMarkedItems && iMarkedItems->Count() )
       
   270         {
       
   271         if( iMarkedItems->At(0) != 0 )
       
   272             {
       
   273             __LOG("CUPnPAppMultiselectionPopup::PostLayoutDynInitL using iMarkedItems");
       
   274             // if got selections stored in content server use that
       
   275             iListBox->SetSelectionIndexesL( iMarkedItems );
       
   276             useMarked = ETrue;
       
   277             }
       
   278         }
       
   279     if( !useMarked && iUiMarked->Count() )
       
   280         {
       
   281         __LOG("CUPnPAppMultiselectionPopup::PostLayoutDynInitL using iUiMarked");
       
   282         iListBox->SetSelectionIndexesL( iUiMarked );
       
   283         }
       
   284 
       
   285     iUtility->CollectSelectedItemsL( iListBox, ETrue );
       
   286 
       
   287     //set msk's label depending on is item selected or not
       
   288     HBufC* mskLabel( iMskSelectText );
       
   289     if( iListBox->View()->ItemIsSelected( iListBox->CurrentItemIndex() ) )
       
   290         {
       
   291         mskLabel = iMskUnselectText;
       
   292         }
       
   293     ButtonGroupContainer().SetCommandL( 
       
   294         EAknSoftkeyForwardKeyEvent, *mskLabel );
       
   295 
       
   296     __LOG("CUPnPAppMultiselectionPopup::PostLayoutDynInitL end");
       
   297     }
       
   298 
       
   299 // --------------------------------------------------------------------------
       
   300 // CUPnPAppMultiselectionPopup::OfferKeyEventL();
       
   301 // called by framework when key is pressed
       
   302 // --------------------------------------------------------------------------
       
   303 //
       
   304 TKeyResponse CUPnPAppMultiselectionPopup::OfferKeyEventL (
       
   305             const TKeyEvent &aKeyEvent,
       
   306             TEventCode aType)
       
   307     {
       
   308     __LOG("CUPnPAppMultiselectionPopup::OfferKeyEventL begin");
       
   309 
       
   310     TKeyResponse status( EKeyWasNotConsumed );
       
   311     if ( aType == EEventKey ) // Is not key event
       
   312         {
       
   313         if (aKeyEvent.iCode == EKeyOK)
       
   314             {
       
   315             status = ListBox()->OfferKeyEventL( aKeyEvent, aType );
       
   316             iUtility->CollectSelectedItemsL( iListBox );
       
   317             }
       
   318         else if (aKeyEvent.iCode == KOkSoftkeyCode)
       
   319             {
       
   320             // disable draw
       
   321             status = CAknListQueryDialog::OfferKeyEventL( aKeyEvent, aType );
       
   322             }
       
   323         else
       
   324             {
       
   325             // Let the Akn dialog handle the key event.
       
   326             // EKeyEscape key event deletes this dialog.
       
   327             status = CAknListQueryDialog::OfferKeyEventL( aKeyEvent, aType );
       
   328             }
       
   329         }
       
   330 
       
   331     //
       
   332     // Set msk's label depending on is item selected or not.
       
   333     //
       
   334     // In case of EKeyEscape we cannot access objects in heap any more.
       
   335     // Only local variables in stack. This is because CAknSelectionListDialog
       
   336     // ::OfferKeyEventL deletes this dialog. When call returns heap memory is cleared
       
   337     // and we cannot rely on values of member variables.
       
   338     //
       
   339     if ( status == EKeyWasConsumed &&
       
   340          aKeyEvent.iCode != EKeyEscape )
       
   341         {
       
   342         HBufC* mskLabel(iMskSelectText);
       
   343         if( iListBox->View()->ItemIsSelected( 
       
   344                 iListBox->CurrentItemIndex() ) )
       
   345             {
       
   346             mskLabel = iMskUnselectText;
       
   347             }
       
   348         ButtonGroupContainer().SetCommandL( 
       
   349             EAknSoftkeyForwardKeyEvent, *mskLabel );
       
   350         ButtonGroupContainer().DrawDeferred();
       
   351         }
       
   352 
       
   353     __LOG("CUPnPAppMultiselectionPopup::OfferKeyEventL end");
       
   354     return status;
       
   355     }
       
   356 
       
   357 
       
   358 
       
   359 // --------------------------------------------------------------------------
       
   360 // CUPnPAppMultiselectionPopup::StepL
       
   361 // Step done during wait note
       
   362 // --------------------------------------------------------------------------
       
   363 //
       
   364 void CUPnPAppMultiselectionPopup::StepL(void)
       
   365     {
       
   366     switch ( iState )
       
   367         {
       
   368         case ELoadContent:
       
   369             {
       
   370             TRAPD( err, iFileSharingEngine->GetSelectionContentL( 
       
   371                 *iSettingsTextArray ) );
       
   372             if ( err == KErrNone )
       
   373                 {
       
   374                 iState = ELoadIndexes;
       
   375                 iFileSharingEngine->RequestSelectionIndexesL( iMediaType );
       
   376                 }
       
   377             else if ( err == KErrInUse )
       
   378                 {
       
   379                 //do nothing, request is being proceeded
       
   380                 }
       
   381             else
       
   382                 {
       
   383                 User::Leave( err );
       
   384                 }
       
   385             break;
       
   386             }
       
   387         case ELoadIndexes:
       
   388             {
       
   389             TRAPD( err, iFileSharingEngine->GetSelectionIndexesL( 
       
   390                 *iMarkedItems ) );
       
   391             if ( err == KErrNone )
       
   392                 {
       
   393                 iState = ELoadDone;
       
   394                 iDone = ETrue;
       
   395                 }
       
   396             else if ( err == KErrInUse )
       
   397                 {
       
   398                 //do nothing, request is being proceeded
       
   399                 }
       
   400             else
       
   401                 {
       
   402                 User::Leave( err );
       
   403                 }
       
   404             break;
       
   405             }
       
   406         case ELoadDone:
       
   407             {
       
   408             break;
       
   409             }
       
   410         default:
       
   411             {
       
   412             __PANICD( __FILE__, __LINE__ );
       
   413             break;
       
   414             }
       
   415         }
       
   416     }
       
   417 
       
   418 // --------------------------------------------------------------------------
       
   419 // CUPnPAppMultiselectionPopup::IsProcessDone
       
   420 // Returns ETrue if process finished
       
   421 // --------------------------------------------------------------------------
       
   422 //
       
   423 TBool CUPnPAppMultiselectionPopup::IsProcessDone(void) const
       
   424     {
       
   425     return iDone;
       
   426     }
       
   427 
       
   428 // --------------------------------------------------------------------------
       
   429 // CUPnPAppMultiselectionPopup::SetMarkedItemsL
       
   430 // --------------------------------------------------------------------------
       
   431 //
       
   432 void CUPnPAppMultiselectionPopup::SetMarkedItemsL(CArrayFix<TInt>& aMarkedItems)
       
   433     {
       
   434     iUiMarked->Reset();
       
   435     for( TInt i=0 ; i < aMarkedItems.Count() ; ++i )
       
   436         {
       
   437         iUiMarked->AppendL( aMarkedItems.At(i) );
       
   438         }
       
   439     }
       
   440 
       
   441 // End of file