XDMSettingsUI/src/XDMPluginSettinglist.cpp
branchRCL_3
changeset 35 fbd2e7cec7ef
equal deleted inserted replaced
34:2669f8761a99 35:fbd2e7cec7ef
       
     1 /*
       
     2 * Copyright (c) 2005-2010 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:    XDM GS plugin, Setting List class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "XDMExternalInterface.h"
       
    23 
       
    24 #include <barsread.h>
       
    25 #include <ApSettingsHandlerUI.h>
       
    26 #include <ApUtils.h>
       
    27 #include <commdb.h>
       
    28 #include <avkon.loc>
       
    29 #include <StringLoader.h>
       
    30 #include <akntitle.h>
       
    31 #include <eikspane.h>
       
    32 
       
    33 #include "XDMPlugin.hrh"
       
    34 #include "XDMPluginSettinglist.h"
       
    35 #include "SettingsData.h"
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CXDMPluginSettinglist::NewL(CSettingsData &aData)
       
    39 // -----------------------------------------------------------------------------
       
    40 // 
       
    41 CXDMPluginSettinglist *CXDMPluginSettinglist::NewL(CSettingsData &aData)
       
    42     {
       
    43     CXDMPluginSettinglist* self = CXDMPluginSettinglist::NewLC(aData);
       
    44     CleanupStack::Pop(self);
       
    45     return self;
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CXDMPluginSettinglist::NewLC(CSettingsData &aData)
       
    50 // -----------------------------------------------------------------------------
       
    51 // 
       
    52 CXDMPluginSettinglist *CXDMPluginSettinglist::NewLC(CSettingsData &aData)
       
    53     {
       
    54     CXDMPluginSettinglist* self = new (ELeave) CXDMPluginSettinglist(aData);
       
    55     CleanupStack::PushL(self);
       
    56     return self;
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CXDMPluginSettinglist::CXDMPluginSettinglist(CSettingsData &aData)
       
    61 // -----------------------------------------------------------------------------
       
    62 // 
       
    63 CXDMPluginSettinglist::CXDMPluginSettinglist(CSettingsData &aData) : 
       
    64     CAknSettingItemList(),
       
    65     iSettingsData(aData)  
       
    66     {
       
    67     SetComponentsToInheritVisibility( ETrue );
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CXDMPluginSettinglist::~CXDMPluginSettinglist()
       
    72 // -----------------------------------------------------------------------------
       
    73 // 
       
    74 CXDMPluginSettinglist::~CXDMPluginSettinglist()
       
    75   {
       
    76   // no specific destruction code required - no owned data
       
    77   }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CXDMPluginSettinglist::SizeChanged()
       
    81 // -----------------------------------------------------------------------------
       
    82 // 
       
    83 void CXDMPluginSettinglist::SizeChanged()
       
    84     {
       
    85     // if size changes, make sure component takes whole available space
       
    86     if (ListBox()) 
       
    87         {
       
    88         ListBox()->SetRect(Rect());
       
    89         }
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CXDMPluginSettinglist::EditCurrentItemL()
       
    94 // -----------------------------------------------------------------------------
       
    95 // 
       
    96 void CXDMPluginSettinglist::EditCurrentItemL()
       
    97     {
       
    98     // invoke EditItemL on the current item
       
    99     TInt index = ListBox()->CurrentItemIndex();
       
   100 
       
   101     //Cause SIP setting is hidden
       
   102     if(index >= 3) //ESipURLIndex == 3
       
   103       index++;
       
   104     
       
   105     // if access point need to be edit
       
   106     if (index == EAccessPointIndex)
       
   107         {
       
   108         EditAccessPointL();
       
   109         SaveSettingL(index);
       
   110         }
       
   111     else 
       
   112         EditItemL(index,ETrue); // invoked from menu
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CXDMPluginSettinglist::EditItemL (TInt aIndex, TBool aCalledFromMenu)
       
   117 // -----------------------------------------------------------------------------
       
   118 // 
       
   119 void CXDMPluginSettinglist::EditItemL (TInt aIndex, TBool aCalledFromMenu)
       
   120     {
       
   121     if (aIndex == EAccessPointIndex)
       
   122       {
       
   123       EditAccessPointL();
       
   124       }
       
   125     else
       
   126         {
       
   127          CAknSettingItemList::EditItemL(aIndex, aCalledFromMenu);
       
   128         }
       
   129     (*SettingItemArray())[aIndex]->StoreL();
       
   130     SaveSettingL(aIndex);
       
   131     }
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CXDMPluginSettinglist::SaveSettingL(TInt aIndex)
       
   135 // -----------------------------------------------------------------------------
       
   136 // 
       
   137 void CXDMPluginSettinglist::SaveSettingL(TInt aIndex)
       
   138     {
       
   139     
       
   140     switch (aIndex)
       
   141         {
       
   142         case ESettingNameIndex:
       
   143             SetTitlePaneTextL(iSettingsData.iSettingNameDisp);         
       
   144             break;
       
   145  
       
   146          case EAccessPointIndex:
       
   147             if (iSettingsData.iAccessPoint > -1) // if Valid AP number
       
   148                 {
       
   149                 (iSettingsData.iAccessPointDes).Num(iSettingsData.iAccessPoint);
       
   150                 GetAccessPointNameL(iSettingsData.iAccessPoint, 
       
   151                                                     iSettingsData.iAccessPointName);
       
   152                 }
       
   153             LoadSettingsL();
       
   154             break;
       
   155  
       
   156         case EServerAddressIndex:
       
   157             break;
       
   158         
       
   159         
       
   160         case ESipURLIndex:
       
   161             break;
       
   162         case EUserIDIndex:
       
   163             break;
       
   164             
       
   165         case EPasswordIndex:
       
   166             break;
       
   167             
       
   168         default:
       
   169             break;
       
   170         }
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CXDMPluginSettinglist::CreateSettingItemL (TInt aIdentifier) 
       
   175 // -----------------------------------------------------------------------------
       
   176 // 
       
   177 CAknSettingItem * CXDMPluginSettinglist::CreateSettingItemL (TInt aIdentifier) 
       
   178     {
       
   179     // method is used to create specific setting item as required at run-time.
       
   180     // aIdentifier is used to determine what kind of setting item should be 
       
   181     // created
       
   182 
       
   183     CAknSettingItem* settingItem = NULL;
       
   184 
       
   185     switch (aIdentifier)
       
   186         {
       
   187         case ESettingItemSettingName:
       
   188             
       
   189             settingItem = new (ELeave) CAknTextSettingItem ( aIdentifier,
       
   190                                                    iSettingsData.iSettingNameDisp);
       
   191             break;
       
   192 
       
   193         case ESettingItemAccessPoint:
       
   194             GetAccessPointNameL(iSettingsData.iAccessPoint, iSettingsData.iAccessPointName);
       
   195             settingItem = new (ELeave) CAknTextSettingItem (
       
   196                           aIdentifier, iSettingsData.iAccessPointName);
       
   197             break;
       
   198 
       
   199         case ESettingItemServerAddress:
       
   200             settingItem = new (ELeave) CAknTextSettingItem (
       
   201                           aIdentifier, 
       
   202                           iSettingsData.iServerAddress);
       
   203             break;
       
   204 
       
   205 
       
   206         
       
   207         case ESettingItemSipURL:
       
   208             settingItem = new (ELeave) CAknTextSettingItem (
       
   209                           aIdentifier, 
       
   210                           iSettingsData.iSipURL);
       
   211                 settingItem->SetHidden(ETrue);
       
   212             break;
       
   213         
       
   214 
       
   215         case ESettingItemUserID:
       
   216             settingItem = new (ELeave) CAknTextSettingItem (
       
   217                           aIdentifier, 
       
   218                           iSettingsData.iUserID);
       
   219             break;
       
   220         case ESettingItemPassword:
       
   221             settingItem = new (ELeave) CAknPasswordSettingItem (
       
   222                           aIdentifier, 
       
   223                           CAknPasswordSettingItem::EAlpha,
       
   224                           iSettingsData.iPassword);
       
   225             break;
       
   226         default:
       
   227             break;
       
   228         }
       
   229     return settingItem;
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // CXDMPluginSettinglist::EditAccessPoint()
       
   234 // -----------------------------------------------------------------------------
       
   235 // 
       
   236 void CXDMPluginSettinglist::EditAccessPointL()
       
   237     {
       
   238     // After dialog server for access point selection (RGenConAgentDialogServer)
       
   239     // has deprecated wins emulator mode needs a different technique to show
       
   240     // emulator-lan access point.
       
   241     
       
   242     CCommsDatabase* commsDb = CCommsDatabase::NewL( EDatabaseTypeIAP );
       
   243     CleanupStack::PushL(commsDb);
       
   244     CApUtils* aPUtils = CApUtils::NewLC( *commsDb );
       
   245 
       
   246     CApSettingsHandler *apUi = CApSettingsHandler::NewLC(
       
   247                                                         ETrue, 
       
   248                                                         EApSettingsSelListIsPopUp,
       
   249                                                         EApSettingsSelMenuSelectNormal,
       
   250                                                         KEApIspTypeAll,
       
   251                                                         EApBearerTypeAllBearers,
       
   252                                                         KEApSortNameAscending,
       
   253                                                         EIPv4 | EIPv6
       
   254                                                         );
       
   255     TUint32 id;
       
   256     
       
   257     TRAP_IGNORE(id = aPUtils->WapIdFromIapIdL(iSettingsData.iAccessPoint));
       
   258     
       
   259     //err can also be in case this is new set, iSettingsData.iAccessPoint = -1
       
   260     //so ignoring the error
       
   261     
       
   262     if ( apUi->RunSettingsL( id, id ) == KApUiEventSelected)
       
   263         {
       
   264     iSettingsData.iAccessPoint = aPUtils->IapIdFromWapIdL(id);
       
   265         }
       
   266     CleanupStack::PopAndDestroy(3, commsDb); //commsDb, aPUtils, apUi
       
   267     }
       
   268 
       
   269 // -----------------------------------------------------------------------------
       
   270 // CXDMPluginSettinglist::GetAccessPointNameL(TInt32 aAP, TDes& aAccessPoint)
       
   271 // -----------------------------------------------------------------------------
       
   272 // 
       
   273 void CXDMPluginSettinglist::GetAccessPointNameL(TInt32 aAP, TDes& aAccessPoint)
       
   274     {
       
   275 #if defined __WINS__ && defined _DEBUG // handled differently in wins+debug
       
   276     if (aAP != KErrNotFound) // if access point is defined take a general name
       
   277         StringLoader::Load ( aAccessPoint, R_STR_XDM_AP_NAME_FOR_DEBUG_ONLY);    
       
   278 #else
       
   279     CCommsDatabase* commsDb = CCommsDatabase::NewL( EDatabaseTypeIAP );
       
   280     CleanupStack::PushL(commsDb);
       
   281     CApUtils* aPUtils = CApUtils::NewLC( *commsDb );
       
   282     TInt err(KErrNone);
       
   283     // to remove id bug
       
   284     TRAP(err, aAP = aPUtils->WapIdFromIapIdL(aAP)); 
       
   285     TRAP(err, aPUtils->NameL(aAP, aAccessPoint));
       
   286     // dont do anything if name not found or if some error occur
       
   287     CleanupStack::PopAndDestroy(2); // commsDb, aPUtils
       
   288 #endif 
       
   289     }
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // CXDMPluginSettinglist::IsAccessPointInUseL(TInt32 aAP)
       
   293 // -----------------------------------------------------------------------------
       
   294 // 
       
   295 TBool CXDMPluginSettinglist::IsAccessPointInUseL(TInt32 aAP)
       
   296     {
       
   297     TBool inUse( EFalse );
       
   298     
       
   299     CCommsDatabase* commsDb = CCommsDatabase::NewL( EDatabaseTypeIAP );
       
   300     CleanupStack::PushL(commsDb);
       
   301     CApUtils* aPUtils = CApUtils::NewLC( *commsDb );
       
   302     TInt err(KErrNone);
       
   303     // to remove id bug
       
   304     TRAP(err, aAP = aPUtils->WapIdFromIapIdL(aAP)); 
       
   305     inUse = aPUtils->IsAPInUseL( aAP );   
       
   306     // dont do anything if name not found or if some error occur
       
   307     CleanupStack::PopAndDestroy(2); // commsDb, aPUtils
       
   308     
       
   309     return inUse;
       
   310     }
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // CXDMPluginSettinglist::SetTitlePaneTextL( const TDesC& aTitleText ) const
       
   314 // -----------------------------------------------------------------------------
       
   315 // 
       
   316 void CXDMPluginSettinglist::SetTitlePaneTextL( const TDesC& aTitleText ) const
       
   317     {
       
   318     CAknTitlePane* title = static_cast< CAknTitlePane* >
       
   319         ( CEikonEnv::Static()->AppUiFactory()->StatusPane()->ControlL(
       
   320                                         TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   321     if ( !title )
       
   322         {
       
   323         User::Leave( KErrNotSupported );
       
   324         }
       
   325 
       
   326     title->SetTextL( aTitleText );
       
   327     }
       
   328 
       
   329 // -----------------------------------------------------------------------------
       
   330 // CXDMPluginSettinglist::ResetItemIndex()
       
   331 // -----------------------------------------------------------------------------
       
   332 // 
       
   333 void CXDMPluginSettinglist::ResetItemIndex()
       
   334     {
       
   335     ListBox()->SetCurrentItemIndexAndDraw(NULL);
       
   336     }
       
   337 
       
   338 // End of File