homesync/contentmanager/mediaservant/src/msmultiselectionsettingpage.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     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:  CMSMultiselectionSettingPage class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <mediaservant.rsg>
       
    20 #include "msmultiselectionsettingpage.h"
       
    21 #include "msdebug.h"
       
    22 
       
    23 // --------------------------------------------------------------------------
       
    24 // CMSMultiSelectionSettingPage::NewL
       
    25 // --------------------------------------------------------------------------
       
    26 //
       
    27 CMSMultiselectionSettingPage* CMSMultiselectionSettingPage::NewL(
       
    28                                 TInt aIdentifier,
       
    29                                 CSelectionItemList& aItemArray,
       
    30                                 TBool aFirstItemSwitch )
       
    31     {
       
    32     LOG(_L("[MediaServant]\t CMSMultiSelectionSettingPage::NewL"));
       
    33 
       
    34     CMSMultiselectionSettingPage* self =
       
    35             CMSMultiselectionSettingPage::NewLC( aIdentifier,
       
    36                                                  aItemArray,
       
    37                                                  aFirstItemSwitch );
       
    38     CleanupStack::Pop(self);
       
    39 
       
    40     return self;
       
    41     }
       
    42 
       
    43 // --------------------------------------------------------------------------
       
    44 // CMSMultiSelectionSettingPage::NewLC
       
    45 // --------------------------------------------------------------------------
       
    46 //
       
    47 CMSMultiselectionSettingPage* CMSMultiselectionSettingPage::NewLC(
       
    48                                 TInt aIdentifier,
       
    49                                 CSelectionItemList& aItemArray,
       
    50                                 TBool aFirstItemSwitch )
       
    51     {
       
    52     LOG(_L("[MediaServant]\t CMSMultiSelectionSettingPage::NewLC"));
       
    53 
       
    54     CMSMultiselectionSettingPage* self = new (ELeave)
       
    55                            CMSMultiselectionSettingPage( aIdentifier,
       
    56                                                          aItemArray,
       
    57                                                          aFirstItemSwitch  );
       
    58 
       
    59     CleanupStack::PushL(self);
       
    60     self->ConstructL();
       
    61         
       
    62     return self;
       
    63     }
       
    64     
       
    65 // --------------------------------------------------------------------------
       
    66 // CMSMultiSelectionSettingPage::ConstructL
       
    67 // --------------------------------------------------------------------------
       
    68 //
       
    69 void CMSMultiselectionSettingPage::ConstructL()
       
    70     {
       
    71     LOG(_L("[MediaServant]\t CMSMultiSelectionSettingPage::ConstructL"));
       
    72 
       
    73     CAknCheckBoxSettingPage::ConstructL();
       
    74     }
       
    75 
       
    76 // --------------------------------------------------------------------------
       
    77 // CMSMultiSelectionSettingPage::CMSMultiSelectionSettingPage
       
    78 // --------------------------------------------------------------------------
       
    79 //
       
    80 CMSMultiselectionSettingPage::CMSMultiselectionSettingPage(
       
    81     TInt aIdentifier,
       
    82     CSelectionItemList& aItemArray,
       
    83     TBool aFirstItemSwitch
       
    84      ) :
       
    85     CAknCheckBoxSettingPage( aIdentifier, &aItemArray ),
       
    86     iItemArray ( &aItemArray ),
       
    87     iFirstItemSwitch ( aFirstItemSwitch )
       
    88     {
       
    89     }
       
    90 
       
    91 // --------------------------------------------------------------------------
       
    92 // CMSMultiSelectionSettingPage::~CMSMultiSelectionSettingPage()
       
    93 // --------------------------------------------------------------------------
       
    94 //
       
    95 CMSMultiselectionSettingPage::~CMSMultiselectionSettingPage()
       
    96     {
       
    97     LOG(_L("[MediaServant]\t CMSMultiSelectionSettingPage::\
       
    98     ~CMSMultiSelectionSettingPage"));
       
    99 
       
   100     }
       
   101 
       
   102 // --------------------------------------------------------------------------
       
   103 // CMSMultiSelectionSettingPage::SelectCurrentItemL()
       
   104 // --------------------------------------------------------------------------
       
   105 //
       
   106 void CMSMultiselectionSettingPage::SelectCurrentItemL()
       
   107     {
       
   108     if ( iFirstItemSwitch )
       
   109         {
       
   110         HandleSelectionsL();
       
   111         }
       
   112     else
       
   113         {
       
   114         CAknCheckBoxSettingPage::SelectCurrentItemL();
       
   115         }
       
   116     }
       
   117 
       
   118 // --------------------------------------------------------------------------
       
   119 // CMSMultiselectionSettingPage::HandleSelectionsL
       
   120 // Removes selection marks from other items if first one is selected
       
   121 // --------------------------------------------------------------------------
       
   122 //
       
   123 void CMSMultiselectionSettingPage::HandleSelectionsL()
       
   124     {
       
   125     LOG(_L("[MediaServant]\t CMSMultiSelectionSettingPage::\
       
   126     HandleSelectionsL"));
       
   127 
       
   128     CEikListBox* listBox = ListBoxControl();
       
   129 
       
   130     const CArrayFix<TInt>* indexes = listBox->View()->SelectionIndexes();
       
   131 
       
   132     if ( indexes->Count() )
       
   133         {
       
   134         TKeyArrayFix sortKey(0,ECmpTUint);
       
   135         TInt dummy;
       
   136 
       
   137         // check if firs item selected
       
   138         if ( indexes->Find(0, sortKey, dummy) == 0 )
       
   139             {
       
   140             // clear all
       
   141             listBox->View()->ClearSelection();
       
   142             // select current item
       
   143             listBox->View()->SelectItemL( listBox->CurrentItemIndex());
       
   144             }
       
   145         else // first item not selected
       
   146             {
       
   147             // check if first item is highlighted
       
   148             if ( listBox->CurrentItemIndex() == 0 )
       
   149                 {
       
   150                 // remove all selections...
       
   151                 listBox->View()->ClearSelection();
       
   152                 }
       
   153             //...and toggle highlighted item
       
   154             listBox->View()->ToggleItemL( listBox->CurrentItemIndex());
       
   155 
       
   156             // check if we don't have selected items
       
   157             if ( indexes->Count() == 0 )
       
   158                 {
       
   159                 // check the first one
       
   160                 listBox->View()->SelectItemL(0);
       
   161                 }
       
   162             }
       
   163         }
       
   164     else // no items selected
       
   165         {
       
   166         listBox->View()->SelectItemL(0);
       
   167         }
       
   168     }
       
   169 // --------------------------------------------------------------------------
       
   170 // CMSMultiselectionSettingPage::UpdateAllSelections
       
   171 // Updates selection status of the items in the item array
       
   172 // --------------------------------------------------------------------------
       
   173 //
       
   174 void CMSMultiselectionSettingPage::UpdateAllSelections()
       
   175     {
       
   176     LOG(_L("[MediaServant]\t CMSMultiSelectionSettingPage::\
       
   177     UpdateAllSelections"));
       
   178 
       
   179     TInt count = iItemArray->Count();
       
   180 
       
   181     CListBoxView* view = ListBoxControl()->View();
       
   182 
       
   183     for (TInt index = 0; index < count; index++)
       
   184         {
       
   185         (*iItemArray)[ index ]->SetSelectionStatus(
       
   186                                     view->ItemIsSelected( index ) );
       
   187         }
       
   188     }
       
   189 
       
   190 // --------------------------------------------------------------------------
       
   191 // CMSMultiselectionSettingPage::HandlePointerEventL
       
   192 // called by framework when the pointer device is pressed
       
   193 // --------------------------------------------------------------------------
       
   194 //
       
   195 void CMSMultiselectionSettingPage::HandlePointerEventL(const TPointerEvent &aPointerEvent) 
       
   196 	{
       
   197 	CCoeControl::HandlePointerEventL(aPointerEvent);
       
   198 	if ( TPointerEvent::EButton1Up == aPointerEvent.iType )
       
   199 		{
       
   200 		SelectCurrentItemL();
       
   201 		}
       
   202 	}
       
   203 
       
   204 // --------------------------------------------------------------------------
       
   205 // CMSMultiselectionSettingPage::OkToExitL(TInt aButtonId)
       
   206 // called by framework when the softkey is pressed
       
   207 // --------------------------------------------------------------------------
       
   208 //
       
   209 TBool CMSMultiselectionSettingPage::OkToExitL( TInt aButtonId )
       
   210     {
       
   211     LOG(_L("[MediaServant]\t CMSMultiSelectionSettingPage::OkToExitL"));
       
   212 
       
   213     if ( aButtonId != EEikCmdCanceled )
       
   214         {
       
   215         // Update item selections to the list
       
   216         UpdateAllSelections();
       
   217         }
       
   218 
       
   219     return ETrue;
       
   220     }
       
   221 
       
   222 // End of File
       
   223