videofeeds/vcnsscheduleview/src/CVcxNsScheduleSettingsDlTimeItem.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2006 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:    Video on Demand setting item class for dowload time selection.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include <StringLoader.h>
       
    22 #include <vcxnsscheduleview.rsg>
       
    23 
       
    24 #include "vcxnsservicesettings.h"
       
    25 #include "CVcxNsScheduleSettingsDlTimeItem.h"
       
    26 #include "CVcxNsScheduleSettingsDlTimePage.h"
       
    27 
       
    28 // CONSTANTS
       
    29 
       
    30 // Needed for enum value iteration
       
    31 const TInt KScheduleDlTimesCount = 5;     
       
    32 const TInt KScheduleDlTimes[] = { 
       
    33         ENight,
       
    34         EMorning,
       
    35         ENoon,
       
    36         EAfternoon,
       
    37         EEvening 
       
    38         };
       
    39 
       
    40 const TInt KItemArrayGranularity = 5;
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CVcxNsScheduleSettingsDlTimeItem::CVcxNsScheduleSettingsDlTimeItem
       
    44 // C++ default constructor can NOT contain any code, that
       
    45 // might leave.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CVcxNsScheduleSettingsDlTimeItem::CVcxNsScheduleSettingsDlTimeItem( 
       
    49         TInt aIdentifier, 
       
    50         TUint& aDlTimes )
       
    51     : CAknSettingItem( aIdentifier ),
       
    52       iPopupArray( KItemArrayGranularity ),
       
    53       iExtDlTimes( aDlTimes )
       
    54     {
       
    55    
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // Destructor
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CVcxNsScheduleSettingsDlTimeItem::~CVcxNsScheduleSettingsDlTimeItem()
       
    63     {
       
    64     iPopupArray.ResetAndDestroy();
       
    65     delete iSettingText;
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CVcxNsScheduleSettingsDlTimeItem::InitializePopupArrayL
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CVcxNsScheduleSettingsDlTimeItem::InitializePopupArrayL()
       
    73     {
       
    74     iPopupArray.ResetAndDestroy();
       
    75 
       
    76     RPointerArray<HBufC> stringArray;
       
    77     CleanupClosePushL( stringArray );
       
    78     stringArray.AppendL( StringLoader::LoadLC( R_VCXNS_SCHEDULE_NIGHT ) );
       
    79     stringArray.AppendL( StringLoader::LoadLC( R_VCXNS_SCHEDULE_MORNING ) );
       
    80     stringArray.AppendL( StringLoader::LoadLC( R_VCXNS_SCHEDULE_NOON ) );
       
    81     stringArray.AppendL( StringLoader::LoadLC( R_VCXNS_SCHEDULE_AFTERNOON ) );
       
    82     stringArray.AppendL( StringLoader::LoadLC( R_VCXNS_SCHEDULE_EVENING ) );
       
    83 
       
    84     for ( TInt i=0; i<stringArray.Count(); i++ )
       
    85         {
       
    86         CSelectableItem* item = 
       
    87             new (ELeave) CSelectableItem( *stringArray[i], EFalse );
       
    88         CleanupStack::PushL( item );
       
    89         item->ConstructL();
       
    90         iPopupArray.AppendL( item ); // Ownership is transferred to popup array
       
    91         CleanupStack::Pop( item );                 
       
    92         }
       
    93     
       
    94     CleanupStack::PopAndDestroy( stringArray.Count() );  // Pop all strings
       
    95     CleanupStack::PopAndDestroy( &stringArray );
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CVcxNsScheduleSettingsDlTimeItem::PopulatePopupArrayL
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CVcxNsScheduleSettingsDlTimeItem::PopulatePopupArrayL()
       
   103     {
       
   104     TInt indexOfOnlyItem = 0;
       
   105 
       
   106     iSelectedItems = 0;
       
   107     for ( TInt i=0; i<iPopupArray.Count(); i++ )
       
   108         {
       
   109         if ( i<KScheduleDlTimesCount )
       
   110             {
       
   111             if ( iDownloadTimes & KScheduleDlTimes[i] )
       
   112                 {
       
   113                 iPopupArray[i]->SetSelectionStatus( ETrue );					
       
   114                 iSelectedItems++;
       
   115                 indexOfOnlyItem = i;
       
   116                 }
       
   117             else
       
   118                 {
       
   119                 iPopupArray[i]->SetSelectionStatus( EFalse );   
       
   120                 }
       
   121             }
       
   122         }
       
   123     if ( iSelectedItems == 1 )
       
   124         {
       
   125         delete iSettingText;
       
   126         iSettingText = NULL;
       
   127         iSettingText = 
       
   128             HBufC::NewL( iPopupArray[indexOfOnlyItem]->ItemText().Length() );
       
   129         *iSettingText = iPopupArray[indexOfOnlyItem]->ItemText();
       
   130         }
       
   131     }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CVcxNsScheduleSettingsDlTimeItem::CompleteConstructionL
       
   135 // -----------------------------------------------------------------------------
       
   136 //	
       
   137 void CVcxNsScheduleSettingsDlTimeItem::CompleteConstructionL()
       
   138     {
       
   139     InitializePopupArrayL();
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CVcxNsScheduleSettingsDlTimeItem::EditItemL
       
   144 // -----------------------------------------------------------------------------
       
   145 //	
       
   146 void CVcxNsScheduleSettingsDlTimeItem::EditItemL(TBool /*aCalledFromMenu*/)
       
   147     {
       
   148     CVcxNsScheduleSettingsDlTimePage* dlg;
       
   149     TInt settingPageResId;
       
   150       
       
   151     // Note: Two separate setting page recources with different initial softkeys
       
   152     // are needed because correct CBA for setting page must be set before showing
       
   153     // the setting page.
       
   154     
       
   155     if ( iPopupArray.At(0)->SelectionStatus() )  // Check if first item is marked 
       
   156         {
       
   157         settingPageResId = R_VCXNS_SCHEDULE_SCHEDULESETTINGSVIEW_DOWNLOAD_TIME_PAGE_UNMARKED;
       
   158         }
       
   159     else
       
   160         {
       
   161         settingPageResId = R_VCXNS_SCHEDULE_SCHEDULESETTINGSVIEW_DOWNLOAD_TIME_PAGE_MARKED;     
       
   162         }   
       
   163     
       
   164     dlg = new (ELeave) CVcxNsScheduleSettingsDlTimePage( 
       
   165             settingPageResId,
       
   166             &iPopupArray );
       
   167               
       
   168     SetSettingPage( dlg );
       
   169     dlg->SetSettingPageObserver( this );
       
   170     dlg->ExecuteLD();
       
   171     SetSettingPage( NULL );
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CVcxNsScheduleSettingsDlTimeItem::SettingTextL
       
   176 // -----------------------------------------------------------------------------
       
   177 //  
       
   178 const TDesC& CVcxNsScheduleSettingsDlTimeItem::SettingTextL()
       
   179     {
       
   180     if ( iSelectedItems == 0 )
       
   181         {
       
   182         delete iSettingText;
       
   183         iSettingText = NULL;
       
   184         iSettingText = StringLoader::LoadL( R_VCXNS_SCHEDULE_NONE_SELECTED );
       
   185     }
       
   186     else if ( iSelectedItems > 1 )
       
   187         {
       
   188         delete iSettingText;
       
   189         iSettingText = NULL;
       
   190         iSettingText = StringLoader::LoadL( R_VCXNS_SCHEDULE_MULTIPLE_SELECTED, 
       
   191                                             iSelectedItems );
       
   192         }	
       
   193     return *iSettingText;
       
   194     }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CVcxNsScheduleSettingsDlTimeItem::HandleSettingPageEventL
       
   198 // -----------------------------------------------------------------------------
       
   199 //  
       
   200 void CVcxNsScheduleSettingsDlTimeItem::HandleSettingPageEventL(
       
   201     CAknSettingPage* aSettingPage,
       
   202     TAknSettingPageEvent aEventType )
       
   203     {
       
   204     if ( aEventType == EEventSettingOked )	
       
   205         {
       
   206         SaveSelectionsL();
       
   207         PopulatePopupArrayL();
       
   208 	    UpdateListBoxTextL();
       
   209         }
       
   210     else if ( aEventType == EEventSettingChanged )
       
   211         {
       
   212         static_cast<CVcxNsScheduleSettingsDlTimePage*>(aSettingPage)->SetCbaL();
       
   213         }
       
   214     else if ( aEventType == EEventSettingCancelled )
       
   215         {
       
   216         PopulatePopupArrayL(); // Restore old settings
       
   217         }
       
   218 
       
   219     CAknSettingItem::HandleSettingPageEventL( aSettingPage, aEventType );
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CVcxNsScheduleSettingsDlTimeItem::SaveSelectionsL
       
   224 // -----------------------------------------------------------------------------
       
   225 //  
       
   226 void CVcxNsScheduleSettingsDlTimeItem::SaveSelectionsL()
       
   227     {
       
   228     iDownloadTimes = 0;
       
   229     for ( TInt i=0; i<KScheduleDlTimesCount; i++ )
       
   230         {
       
   231         if ( iPopupArray.Count() > i && iPopupArray[i]->SelectionStatus() )
       
   232             {
       
   233             iDownloadTimes = iDownloadTimes | KScheduleDlTimes[i];
       
   234             }	
       
   235         }
       
   236     }
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // CVcxNsScheduleSettingsDlTimeItem::LoadL
       
   240 // -----------------------------------------------------------------------------
       
   241 //  
       
   242 void CVcxNsScheduleSettingsDlTimeItem::LoadL()
       
   243     {
       
   244     iDownloadTimes = iExtDlTimes;
       
   245     PopulatePopupArrayL();
       
   246     }
       
   247 
       
   248 // -----------------------------------------------------------------------------
       
   249 // CVcxNsScheduleSettingsDlTimeItem::StoreL
       
   250 // -----------------------------------------------------------------------------
       
   251 //     
       
   252 void CVcxNsScheduleSettingsDlTimeItem::StoreL()
       
   253     {
       
   254     iExtDlTimes = iDownloadTimes;
       
   255     }
       
   256     
       
   257 // End of File