homesync/contentmanager/mediaservant/src/msruleserverssetting.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:  CMSRuleServersSetting class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <mediaservant.rsg>
       
    20 #include <StringLoader.h>
       
    21 
       
    22 
       
    23 #include "msruleserverssetting.h"
       
    24 #include "msmultiselectionsettingpage.h"
       
    25 #include "msdebug.h"
       
    26 
       
    27 
       
    28 // --------------------------------------------------------------------------
       
    29 // CMSRuleServersSetting::NewL
       
    30 // --------------------------------------------------------------------------
       
    31 //
       
    32 CMSRuleServersSetting* CMSRuleServersSetting::NewL(
       
    33                                 TInt aIdentifier,
       
    34                                 CSelectionItemList& aServerList,
       
    35                                 TDes& aText,
       
    36                                 TInt aSecondaryTextResource )
       
    37     {
       
    38     LOG(_L("[MediaServant]\t CMSRuleServersSetting::NewL"));
       
    39 
       
    40     CMSRuleServersSetting* self = CMSRuleServersSetting::NewLC(
       
    41                                              aIdentifier,
       
    42                                              aServerList,
       
    43                                              aText,
       
    44                                              aSecondaryTextResource );
       
    45 
       
    46     CleanupStack::Pop(self);
       
    47     
       
    48     return self;
       
    49     }
       
    50 
       
    51 // --------------------------------------------------------------------------
       
    52 // CMSRuleServersSetting::NewLC
       
    53 // --------------------------------------------------------------------------
       
    54 //
       
    55 CMSRuleServersSetting* CMSRuleServersSetting::NewLC(
       
    56                                 TInt aIdentifier,
       
    57                                 CSelectionItemList& aServerList,
       
    58                                 TDes& aText,
       
    59                                 TInt aSecondaryTextResource )
       
    60     {
       
    61     LOG(_L("[MediaServant]\t CMSRuleServersSetting::NewLC"));
       
    62 
       
    63     CMSRuleServersSetting* self = new (ELeave) CMSRuleServersSetting(
       
    64                                              aIdentifier,
       
    65                                              aServerList,
       
    66                                              aText,
       
    67                                              aSecondaryTextResource );
       
    68 
       
    69     CleanupStack::PushL(self);
       
    70     self->ConstructL();
       
    71     
       
    72     return self;
       
    73     }
       
    74 
       
    75 // --------------------------------------------------------------------------
       
    76 // CMSRuleServersSetting::ConstructL
       
    77 // --------------------------------------------------------------------------
       
    78 //
       
    79 void CMSRuleServersSetting::ConstructL()
       
    80     {
       
    81     LOG(_L("[MediaServant]\t CMSRuleServersSetting::ConstructL"));
       
    82 
       
    83     iSettingText = HBufC16::NewL( KMaxFileName );
       
    84 
       
    85     SetSettingItemTextL();
       
    86     }
       
    87 
       
    88 // --------------------------------------------------------------------------
       
    89 // CMSRuleServersSetting::CMSRuleServersSetting
       
    90 // --------------------------------------------------------------------------
       
    91 //
       
    92 CMSRuleServersSetting::CMSRuleServersSetting(
       
    93     TInt aIdentifier,
       
    94     CSelectionItemList& aServerList,
       
    95     TDes& aText,
       
    96     TInt aSecondaryTextResource
       
    97      ) :
       
    98     CMSTextSettingItem( aIdentifier, aText ),
       
    99     iText( aText ),
       
   100     iItemArray( aServerList ),
       
   101     iSecondaryTextResource( aSecondaryTextResource )
       
   102     {
       
   103     }
       
   104 // --------------------------------------------------------------------------
       
   105 // CMSRuleServersSetting::~CMSRuleServersSetting()
       
   106 // --------------------------------------------------------------------------
       
   107 //
       
   108 CMSRuleServersSetting::~CMSRuleServersSetting()
       
   109     {
       
   110     LOG(_L("[MediaServant]\t CMSRuleServersSetting::\
       
   111     ~CMSRuleServersSetting"));
       
   112 
       
   113     delete iSettingText;
       
   114     }
       
   115 
       
   116 // --------------------------------------------------------------------------
       
   117 // CMSRuleServersSetting::EditItemL( TBool aCalledFromMenu )
       
   118 // --------------------------------------------------------------------------
       
   119 //
       
   120 void CMSRuleServersSetting::EditItemL( TBool /*aCalledFromMenu*/ )
       
   121     {
       
   122     LOG(_L("[MediaServant]\t CMSRuleServersSetting::EditItemL"));
       
   123 
       
   124     // reset dialog acceptance indicator
       
   125     SetAcceptState( EFalse );
       
   126 
       
   127     // Create setting page
       
   128     CAknSettingPage* dlg = CMSMultiselectionSettingPage::NewL(
       
   129             R_MS_FILL_RULE_SERVERS_SETTING_PAGE,
       
   130             iItemArray, ETrue );
       
   131     // launch setting page
       
   132     if ( dlg->ExecuteLD( CAknSettingPage::EUpdateWhenChanged ) )
       
   133         {
       
   134         // dialog accepted
       
   135         SetAcceptState( ETrue );
       
   136 
       
   137         SetSettingItemTextL();
       
   138         LoadL();
       
   139         // show value on screen
       
   140         UpdateListBoxTextL();
       
   141         }
       
   142     }
       
   143 
       
   144 // --------------------------------------------------------------------------
       
   145 // CMSRuleServersSetting::CountSelectedItems
       
   146 // Counts selected items
       
   147 // --------------------------------------------------------------------------
       
   148 //
       
   149 TInt CMSRuleServersSetting::CountSelectedItems()
       
   150     {
       
   151     LOG(_L("[MediaServant]\t CMSRuleServersSetting::\
       
   152     CountSelectedItems"));
       
   153 
       
   154     TInt count(0);
       
   155 
       
   156     // don't calculate first item
       
   157     for ( TInt index = 1; index < iItemArray.Count(); index++ )
       
   158         {
       
   159         if ( iItemArray[ index ]->SelectionStatus() )
       
   160             {
       
   161             count++;
       
   162             }
       
   163         }
       
   164 
       
   165     return count;
       
   166     }
       
   167 
       
   168 // --------------------------------------------------------------------------
       
   169 // CMSRuleServersSetting::SetSettingItemTextL
       
   170 // Sets setting item secondary text according to selected items
       
   171 // --------------------------------------------------------------------------
       
   172 //
       
   173 void CMSRuleServersSetting::SetSettingItemTextL()
       
   174     {
       
   175     LOG(_L("[MediaServant]\t CMSRuleServersSetting::\
       
   176     SetSettingItemTextL"));
       
   177 
       
   178     TInt count = CountSelectedItems();
       
   179 
       
   180     HBufC* itemText = NULL;
       
   181     // Check if there is no selected items
       
   182     if ( count == 0 )
       
   183         {
       
   184         itemText = StringLoader::LoadLC( iSecondaryTextResource );
       
   185         iSettingText->Des().Copy( *itemText );
       
   186         }
       
   187     // Check if only one item is selected
       
   188     else if ( count == 1 )
       
   189         {
       
   190         TInt itemCount = iItemArray.Count();
       
   191         for ( TInt index = 1; index < itemCount; index++ )
       
   192             {
       
   193             CSelectableItem* item = iItemArray[ index ];
       
   194             if ( item->SelectionStatus() )
       
   195                 {
       
   196                 iSettingText->Des().Copy( item->ItemText() );
       
   197                 index = itemCount; // break loop
       
   198                 }
       
   199             }
       
   200         }
       
   201     // more than one item selected
       
   202     else
       
   203         {
       
   204         itemText = StringLoader::LoadLC( R_MS_ITEM_DEVICES, count );
       
   205 
       
   206         // do number conversion
       
   207         TPtr ptr = itemText->Des();
       
   208         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr );
       
   209 
       
   210         iSettingText->Des().Copy( *itemText );
       
   211         }
       
   212 
       
   213     if ( itemText )
       
   214         {
       
   215         CleanupStack::PopAndDestroy( itemText );
       
   216         }
       
   217 
       
   218      // Set new value
       
   219     SetExternalText( *iSettingText );
       
   220     }
       
   221 
       
   222 // End of File
       
   223