mediasettings/mediasettingsapp/src/MPSettingsAdvancedBwSettingItem.cpp
branchRCL_3
changeset 57 befca0ec475f
equal deleted inserted replaced
56:839377eedc2b 57:befca0ec475f
       
     1 /*
       
     2 * Copyright (c) 2002 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:   CAknSettingItemList compliant setting item class for Advanced bandwidth settings.*
       
    15 */
       
    16 
       
    17 
       
    18 // Version : %version: 7 %
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDE FILES
       
    24 #include    <AknQueryDialog.h>
       
    25 #include    <aknradiobuttonsettingpage.h>
       
    26 #include    <eikenv.h>
       
    27 #include    <MediaSettings.rsg>
       
    28 #include    <StringLoader.h>
       
    29 #include    <AknUtils.h>
       
    30 
       
    31 #include    "MPSettingsAdvancedBwSettingItem.h"
       
    32 #include	"mpxlog.h"
       
    33 
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CMPSettingsAdvancedBwSettingItem::CMPSettingsAdvancedBwSettingItem
       
    39 // C++ default constructor can NOT contain any code, that
       
    40 // might leave.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CMPSettingsAdvancedBwSettingItem::CMPSettingsAdvancedBwSettingItem(
       
    44                                                             TInt aIdentifier,
       
    45                                                             RArray<TInt>& aValueArray,
       
    46                                                             TInt& aValue,
       
    47                                                             TInt& aListValue,
       
    48                                                             TInt aQueryRes) :
       
    49     CAknEnumeratedTextPopupSettingItem(aIdentifier, aListValue),
       
    50     iValueArray(aValueArray),
       
    51     iValue(aValue),
       
    52     iQueryRes(aQueryRes)
       
    53     {
       
    54     MPX_FUNC("#MS# CMPSettingsAdvancedBwSettingItem::CMPSettingsAdvancedBwSettingItem()");
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CMPSettingsAdvancedBwSettingItem::~CMPSettingsAdvancedBwSettingItem
       
    59 // Destructor
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CMPSettingsAdvancedBwSettingItem::~CMPSettingsAdvancedBwSettingItem()
       
    63     {
       
    64     MPX_FUNC("#MS# CMPSettingsAdvancedBwSettingItem::~CMPSettingsAdvancedBwSettingItem()");
       
    65 	if (iSettingText) 
       
    66 		{
       
    67 		delete iSettingText;
       
    68 		}
       
    69 
       
    70     if (iEnumTextArray)
       
    71         {
       
    72         iEnumTextArray->ResetAndDestroy();
       
    73         delete iEnumTextArray;
       
    74         }
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CMPSettingsAdvancedBwSettingItem::SettingTextL
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 const TDesC& CMPSettingsAdvancedBwSettingItem::SettingTextL()
       
    82     {
       
    83     MPX_FUNC("#MS# CMPSettingsAdvancedBwSettingItem::SettingTextL()");
       
    84     delete iSettingText;
       
    85     iSettingText = NULL;
       
    86 
       
    87     iSettingText = CreateValueTextL(iValue);
       
    88 
       
    89     return *iSettingText;
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CMPSettingsAdvancedBwSettingItem::EditItemL
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 void CMPSettingsAdvancedBwSettingItem::EditItemL(TBool aCalledFromMenu)
       
    97     {
       
    98 	MPX_DEBUG2(_L("#MS# CMPSettingsAdvancedBwSettingItem::EditItemL(%d)"),aCalledFromMenu);
       
    99     CAknEnumeratedTextPopupSettingItem::EditItemL(aCalledFromMenu);
       
   100 
       
   101     TInt count = iValueArray.Count();
       
   102 
       
   103     for (TInt index = 0; index < count; ++index)
       
   104         {
       
   105         if (iValueArray[index] == iValue)
       
   106             {
       
   107             SetInternalValue(index);
       
   108             SetSelectedIndex(IndexFromValue(index));
       
   109             break;
       
   110             }
       
   111         }
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CMPSettingsAdvancedBwSettingItem::CompleteConstructionL
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 void CMPSettingsAdvancedBwSettingItem::CompleteConstructionL()
       
   119     {
       
   120     MPX_FUNC("#MS# CMPSettingsAdvancedBwSettingItem::CompleteConstructionL()");
       
   121     __ASSERT_DEBUG(!iEnumTextArray, User::Leave(KErrAlreadyExists));
       
   122 
       
   123     TInt count = iValueArray.Count();
       
   124     iEnumTextArray = new(ELeave) CArrayPtrFlat<CAknEnumeratedText>(count + 1);
       
   125     CAknEnumeratedText* enumText = NULL;
       
   126     HBufC* text = NULL;
       
   127 
       
   128     for (TInt index = 0; index < count; ++index)
       
   129         {
       
   130         text = CreateValueTextL(iValueArray[index]);
       
   131         CleanupStack::PushL(text);
       
   132         enumText = new(ELeave) CAknEnumeratedText(index, text);
       
   133         CleanupStack::Pop(); // text
       
   134         text = NULL;
       
   135         CleanupStack::PushL(enumText);
       
   136         iEnumTextArray->AppendL(enumText);
       
   137         CleanupStack::Pop(); //enumText
       
   138         enumText = NULL;
       
   139         }
       
   140 
       
   141     // Append "User defined" to the end of the array
       
   142     text = StringLoader::LoadLC(R_MPSETT_USER_DEFINED);
       
   143     enumText = new(ELeave) CAknEnumeratedText(count, text);
       
   144     CleanupStack::Pop(); // text
       
   145     CleanupStack::PushL(enumText);
       
   146     iEnumTextArray->AppendL(enumText);
       
   147     CleanupStack::Pop(); //enumText                
       
   148 
       
   149     // poppedTextArray should be left empty! Magic number: array granularity
       
   150     CArrayPtr<HBufC>* poppedTextArray = new(ELeave) CArrayPtrFlat<HBufC>(1);
       
   151     // The ownership of both arrays is transferred to the base class.
       
   152     SetEnumeratedTextArrays(iEnumTextArray, poppedTextArray);
       
   153     iEnumTextArray = NULL;
       
   154     poppedTextArray = NULL;
       
   155 
       
   156     HandleTextArrayUpdateL();
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CMPSettingsAdvancedBwSettingItem::HandleSettingPageEventL
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CMPSettingsAdvancedBwSettingItem::HandleSettingPageEventL(CAknSettingPage* aSettingPage,
       
   164                                                            TAknSettingPageEvent aEventType)
       
   165     {
       
   166     MPX_FUNC("#MS# CMPSettingsAdvancedBwSettingItem::HandleSettingPageEventL()");
       
   167     if (aEventType != EEventSettingCancelled)
       
   168         {
       
   169         CEikListBox* listbox = static_cast<CAknRadioButtonSettingPage*>(aSettingPage)->ListBoxControl();
       
   170     
       
   171         TInt current = listbox->CurrentItemIndex();
       
   172         TInt count = listbox->Model()->NumberOfItems();
       
   173 
       
   174         if (current == count - 1)
       
   175             {
       
   176             ShowAdvancedBwQueryL();
       
   177             }
       
   178         else
       
   179             {
       
   180             iValue = iValueArray[current];
       
   181             }
       
   182         }
       
   183 
       
   184     CAknSettingItem::HandleSettingPageEventL(aSettingPage, aEventType);
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CMPSettingsAdvancedBwSettingItem::ShowAdvancedBwQueryL
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 void CMPSettingsAdvancedBwSettingItem::ShowAdvancedBwQueryL()
       
   192     {
       
   193     MPX_FUNC("#MS# CMPSettingsAdvancedBwSettingItem::ShowAdvancedBwQueryL()");
       
   194     TReal value = static_cast<TReal>(iValue) / 1000;
       
   195     CAknFloatingPointQueryDialog* dlg = new (ELeave) CAknFloatingPointQueryDialog(value);
       
   196     if (dlg->ExecuteLD(iQueryRes))
       
   197         {
       
   198         iValue = static_cast<TInt>(value * 1000);
       
   199         }
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CMPSettingsAdvancedBwSettingItem::CreateValueTextL
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 HBufC* CMPSettingsAdvancedBwSettingItem::CreateValueTextL(TInt aValue)
       
   207     {
       
   208     MPX_DEBUG2(_L("#MS# CMPSettingsAdvancedBwSettingItem::CreateValueTextL(%d)"),aValue);
       
   209     TRealFormat format(10, 2);
       
   210     TBuf<10> valueString;
       
   211     HBufC* convert;
       
   212     TReal value = static_cast<TReal>(aValue) / 1000;
       
   213 
       
   214     if (value >= 1000)
       
   215         {
       
   216         User::LeaveIfError(valueString.Num(value/1000, format));
       
   217         convert = StringLoader::LoadL(R_MPSETT_ADVANCED_BW_VALUE_MBIT, valueString);
       
   218         }
       
   219     else
       
   220         {
       
   221         User::LeaveIfError(valueString.Num(value, format));
       
   222         convert = StringLoader::LoadL(R_MPSETT_ADVANCED_BW_VALUE, valueString);
       
   223         }
       
   224 
       
   225     TPtr tmp( convert->Des() );
       
   226     AknTextUtils::LanguageSpecificNumberConversion(tmp);
       
   227     MPX_DEBUG2(_L("#MS# CMPSettingsAdvancedBwSettingItem::CreateValueTextL() ret (%S)"),&tmp);
       
   228     return convert;
       
   229 
       
   230     }
       
   231 
       
   232 //  End of File