XDMSettingsUI/src/XDMPluginSLContainer.cpp
changeset 0 c8caa15ef882
child 7 895b8e06c769
child 13 b7e70c0792e6
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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 Settins list container
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "XDMExternalInterface.h"
       
    23 
       
    24 #include    <aknappui.h> 
       
    25 #include    <akntitle.h>
       
    26 #include    <eikspane.h>
       
    27 #include    <barsread.h>
       
    28 #include    <eiktxlbm.h>
       
    29 #include    <aknlists.h>
       
    30 #include    <AknUtils.h>
       
    31 #include    <eiksbfrm.h>
       
    32 #include    <XdmSettingsApi.h>
       
    33 #include    <aknPopup.h>
       
    34 #include    <StringLoader.h>
       
    35 #include    <XdmSettingsCollection.h>
       
    36 #include    <AknQueryDialog.h>
       
    37 #include    <aknnotewrappers.h>
       
    38 #include    <aknnotedialog.h>
       
    39 
       
    40 #include    "XDMPluginSLContainer.h"
       
    41 #include    "XDMPluginSettinglist.h"
       
    42 #include    "SettingsData.h"
       
    43 
       
    44 #include    <csxhelp/xdm.hlp.hrh>
       
    45 
       
    46 // LOCAL CONSTANTS AND MACROS
       
    47 _LIT(KFormatPostfix, "%S(%02d)");
       
    48 _LIT(KFormatNoPostfix, "%S");
       
    49 _LIT(KFormatLargePostfix, "%S(%d)");
       
    50 const TInt KMaxPostfixLength = 5;
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CXDMPluginSLContainer::CXDMPluginSLContainer()
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CXDMPluginSLContainer::CXDMPluginSLContainer(CAknView* aView) : iView(aView)
       
    57     {
       
    58     }
       
    59     
       
    60 // ---------------------------------------------------------------------------
       
    61 // CXDMPluginSLContainer::ConstructL(const TRect& aRect)
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 void CXDMPluginSLContainer::ConstructL( const TRect& aRect)
       
    65     {
       
    66     #ifdef _DEBUG
       
    67     RDebug::Print( _L( "[CXDMPluginSLContainer] ConstructL()" ) );
       
    68 	#endif
       
    69 
       
    70     CEikStatusPane* sp = static_cast<CAknAppUi*> 
       
    71         ( CEikonEnv::Static()->EikAppUi() )->StatusPane();
       
    72     CAknTitlePane* title = static_cast<CAknTitlePane*> 
       
    73         ( sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
    74 
       
    75     // Set the proper title of this list
       
    76     TResourceReader rReader;
       
    77     iCoeEnv->CreateResourceReaderLC( rReader, R_GS_XDM_MAIN_VIEW_TITLE );
       
    78     title->SetFromResourceL( rReader );
       
    79     CleanupStack::PopAndDestroy(); //rReader
       
    80 
       
    81     CreateWindowL(); // Makes the control a window-owning control
       
    82 
       
    83     // construct the data object the settings list will use
       
    84     iData = CSettingsData::NewL();
       
    85     // construct control and set parent
       
    86     iSettingList = CXDMPluginSettinglist::NewL(*iData);
       
    87     iSettingList->SetContainerWindowL(*this);
       
    88 
       
    89     // CreateResourceReaderLC will allocate a buffer to be used by
       
    90     // the TResourceReader. This buffer is pushed onto the cleanup
       
    91     // stack - not the TResourceReader itself
       
    92     CEikonEnv::Static()->CreateResourceReaderLC(rReader, R_SETTINGS);
       
    93     iSettingList->ConstructFromResourceL(rReader);
       
    94 
       
    95     // Clean up the buffer allocated above, NOT the reader itself.
       
    96     // Cannot use expected item overload of PopAndDestroy() as buffer 
       
    97     // is inaccessible. 
       
    98     CleanupStack::PopAndDestroy();
       
    99     iSettingList->ActivateL();
       
   100 
       
   101     SetRect( aRect );
       
   102     ActivateL();
       
   103     
       
   104     #ifdef _DEBUG        
       
   105     RDebug::Print( _L( "[CXDMPluginSLContainer] Construct done" ) );
       
   106 	#endif
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // CXDMPluginSLContainer::~CXDMPluginSLContainer()
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 CXDMPluginSLContainer::~CXDMPluginSLContainer()
       
   114     {
       
   115     if (iData)
       
   116         delete iData;
       
   117     if(iSettingList)  // if setting list has been created
       
   118         {
       
   119         delete iSettingList;
       
   120         iSettingList = NULL;
       
   121         }
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // CXDMPluginSLContainer::SizeChanged()
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 void CXDMPluginSLContainer::SizeChanged()
       
   129     {
       
   130     iSettingList->SetRect(Rect());
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CXDMPluginSLContainer::CountComponentControls() const
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 TInt CXDMPluginSLContainer::CountComponentControls() const
       
   138     {
       
   139     return 1;
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // CXDMPluginSLContainer::ComponentControl( TInt aIndex ) const
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 CCoeControl* CXDMPluginSLContainer::ComponentControl( TInt aIndex ) const
       
   147     {
       
   148     switch ( aIndex )
       
   149         {
       
   150         case 0:
       
   151             return iSettingList;
       
   152         default:
       
   153             return NULL;
       
   154         }
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // CXDMPluginSLContainer::EditCurrentItemL()
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 void CXDMPluginSLContainer::EditCurrentItemL()
       
   162     {
       
   163     iSettingList->EditCurrentItemL();    
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CXDMPluginSLContainer::OfferKeyEventL()
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 TKeyResponse CXDMPluginSLContainer::OfferKeyEventL( 
       
   171     const TKeyEvent& aKeyEvent, 
       
   172     TEventCode aType )
       
   173     {
       
   174     if (iSettingList)
       
   175         return iSettingList->OfferKeyEventL(aKeyEvent, aType);
       
   176     else
       
   177         return EKeyWasNotConsumed;
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // CXDMPluginSLContainer::Draw(const TRect& aRect) const
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 void CXDMPluginSLContainer::Draw(const TRect& aRect) const
       
   185     {
       
   186     CWindowGc& gc = SystemGc();
       
   187     gc.Clear(aRect);
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CXDMPluginSLContainer::HandleListBoxEventL()
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 void CXDMPluginSLContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aListBoxEvent)
       
   195     {
       
   196     // if the Select Key has been pressed
       
   197     if ((aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) ||
       
   198     (aListBoxEvent == MEikListBoxObserver::EEventItemClicked))
       
   199         {
       
   200         iSettingList->EditCurrentItemL();
       
   201         }
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // CXDMPluginSLContainer::PrepareXDMSetForEditingL(TDesC& aXDMSetName)
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 void CXDMPluginSLContainer::PrepareXDMSetForEditingL(TDesC& aXDMSetName)
       
   209     {
       
   210     TLex16 myLex;
       
   211     iData->Reset();
       
   212     
       
   213     iData->iSettingName = aXDMSetName;
       
   214     AknTextUtils::ConvertDigitsTo(iData->iSettingName, EDigitTypeWestern );    
       
   215     iData->iSettingId = GetSettingIdL(iData->iSettingName);
       
   216     
       
   217     CXdmSettingsCollection* xDMSet = NULL;
       
   218     
       
   219     // read the source setting
       
   220     xDMSet = TXdmSettingsApi::SettingsCollectionL(iData->iSettingId);
       
   221     CleanupStack::PushL(xDMSet);
       
   222     
       
   223     iData->iSettingNameDisp = aXDMSetName;
       
   224     iData->iServerAddress = xDMSet->Property(EXdmPropUri);
       
   225     
       
   226     // AccessPoint handling
       
   227     iData->iAccessPointDes = xDMSet->Property(EXdmPropToNapId);
       
   228     myLex.Assign(iData->iAccessPointDes);
       
   229     myLex.Val(iData->iAccessPoint);
       
   230     
       
   231     iSettingList->GetAccessPointNameL(iData->iAccessPoint, iData->iAccessPointName);
       
   232     if ( (iData->iAccessPointName) == KNullDesC) // if name is not found
       
   233         {
       
   234         iData->iAccessPoint = -1;
       
   235         }
       
   236 
       
   237     iData->iUserID = xDMSet->Property(EXdmPropAuthName);
       
   238     iData->iPassword = xDMSet->Property(EXdmPropAuthSecret);
       
   239     
       
   240     CleanupStack::PopAndDestroy(1); //xDMSet
       
   241     iSettingList->LoadSettingsL();
       
   242     SetTitlePaneTextL(iData->iSettingName);
       
   243     iSettingList->ResetItemIndex();
       
   244     }
       
   245 
       
   246 // ---------------------------------------------------------------------------
       
   247 // CXDMPluginSLContainer::PrepareXDMSetNewDefaultL()
       
   248 // ---------------------------------------------------------------------------
       
   249 //
       
   250 void CXDMPluginSLContainer::PrepareXDMSetNewDefaultL()
       
   251     {
       
   252     iData->Reset();
       
   253     
       
   254     HBufC* defName = StringLoader::LoadL( R_STR_XDM_NEW_SET );
       
   255     CleanupStack::PushL( defName );
       
   256     
       
   257     TBool changed;
       
   258 
       
   259     HBufC* newName = DoMakeValidNameL(defName, changed);
       
   260         
       
   261     if ( newName )
       
   262         // name converted to unique
       
   263         {
       
   264         (iData->iSettingName).Copy(newName->Des());
       
   265         delete newName;
       
   266         }
       
   267     else
       
   268         {
       
   269         (iData->iSettingName).Copy(defName->Des());
       
   270         }
       
   271     CleanupStack::PopAndDestroy( defName );
       
   272     
       
   273     iData->iSettingNameDisp = iData->iSettingName;
       
   274     AknTextUtils::LanguageSpecificNumberConversion(iData->iSettingNameDisp);
       
   275     
       
   276     iSettingList->LoadSettingsL();
       
   277     iSettingList->ResetItemIndex();
       
   278     iSettingList->DrawNow();
       
   279     SetTitlePaneTextL(iData->iSettingName);
       
   280     }
       
   281 
       
   282 // ---------------------------------------------------------------------------
       
   283 // CXDMPluginSLContainer::PrepareNewXDMSetFromExistingL(TDesC& aXDMSetName)
       
   284 // ---------------------------------------------------------------------------
       
   285 //
       
   286 void CXDMPluginSLContainer::PrepareNewXDMSetFromExistingL(TDesC& aXDMSetName)
       
   287     {
       
   288     TLex16 myLex;
       
   289     
       
   290     // iData is already resetted in this case and iSettingId has id of 
       
   291     // existing list from which data to be copied
       
   292     // we need to find the new name, from given name
       
   293     HBufC* originalName = aXDMSetName.AllocL();
       
   294     CleanupStack::PushL( originalName );
       
   295     
       
   296     // aXDMSetName is in disp format, need to convert to western format
       
   297     TPtr corrFormat(originalName->Des());
       
   298     AknTextUtils::ConvertDigitsTo(corrFormat, EDigitTypeWestern );
       
   299     
       
   300     TBool changed;
       
   301 
       
   302     HBufC* newName = DoMakeValidNameL(originalName, changed);
       
   303         
       
   304     if ( newName )
       
   305         // name converted to unique
       
   306         {
       
   307         (iData->iSettingName).Copy(newName->Des());
       
   308         delete newName;
       
   309         }
       
   310     else
       
   311         {
       
   312         (iData->iSettingName).Copy(originalName->Des());
       
   313         }
       
   314 
       
   315     CleanupStack::PopAndDestroy( originalName );
       
   316     
       
   317     
       
   318     CXdmSettingsCollection* xDMSet = NULL;
       
   319     
       
   320     // Displayable name
       
   321     iData->iSettingNameDisp = iData->iSettingName;
       
   322     AknTextUtils::LanguageSpecificNumberConversion(iData->iSettingNameDisp);
       
   323     
       
   324     // read the source setting
       
   325     xDMSet = TXdmSettingsApi::SettingsCollectionL(iData->iSettingId);
       
   326     CleanupStack::PushL(xDMSet);
       
   327     
       
   328     iData->iServerAddress = xDMSet->Property(EXdmPropUri);
       
   329     
       
   330     // AccessPoint handling
       
   331     iData->iAccessPointDes = xDMSet->Property(EXdmPropToNapId);
       
   332     myLex.Assign(iData->iAccessPointDes);
       
   333     myLex.Val(iData->iAccessPoint);
       
   334     
       
   335     iSettingList->GetAccessPointNameL(iData->iAccessPoint, iData->iAccessPointName);
       
   336     if ( (iData->iAccessPointName) == KNullDesC) // if name is not found
       
   337         {
       
   338         iData->iAccessPoint = -1;
       
   339         }
       
   340 
       
   341     iData->iUserID = xDMSet->Property(EXdmPropAuthName);
       
   342     iData->iPassword = xDMSet->Property(EXdmPropAuthSecret);
       
   343     
       
   344     // also overwrite the setting id now since we dont need it anymore
       
   345     iData->iSettingId = -1;
       
   346     CleanupStack::PopAndDestroy(1); //xDMSet
       
   347     iSettingList->LoadSettingsL();
       
   348     SetTitlePaneTextL(iData->iSettingNameDisp);
       
   349     iSettingList->ResetItemIndex();
       
   350     }
       
   351     
       
   352 // ---------------------------------------------------------------------------
       
   353 // CXDMPluginSLContainer::DisplayNewXDMSetOptions()
       
   354 // ---------------------------------------------------------------------------
       
   355 //
       
   356 TBool CXDMPluginSLContainer::DisplayNewXDMSetOptionsL()
       
   357     {
       
   358     // First phase construction of menu list
       
   359     CAknSinglePopupMenuStyleListBox* newXDMsetMenuList =
       
   360     new (ELeave) CAknSinglePopupMenuStyleListBox;
       
   361     CleanupStack::PushL(newXDMsetMenuList);
       
   362 
       
   363     // Create a popuplist to show the menu list in
       
   364     CAknPopupList* popupList = CAknPopupList::NewL(
       
   365                   newXDMsetMenuList, 
       
   366                   R_AVKON_SOFTKEYS_OK_CANCEL);
       
   367 
       
   368     CleanupStack::PushL(popupList);
       
   369 
       
   370     // Second phase construction of menulist
       
   371     newXDMsetMenuList->ConstructL(popupList,EAknListBoxMenuList);
       
   372     // Set up scroll bars
       
   373     newXDMsetMenuList->CreateScrollBarFrameL(ETrue);
       
   374     newXDMsetMenuList->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   375     CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   376 
       
   377     // Set up menu items
       
   378     CTextListBoxModel* model = newXDMsetMenuList->Model();  // not taking ownership
       
   379     model->SetOwnershipType (ELbmOwnsItemArray); // list'll delete with listbox
       
   380     RArray<TInt> settingIDs;
       
   381     CleanupClosePushL(settingIDs);
       
   382     CDesCArray* newXDMsetMenuListArray = NULL;
       
   383 
       
   384     TRAPD(err, newXDMsetMenuListArray = LoadCollectionNamesL(settingIDs, ETrue));
       
   385     if(err!=KErrNone)    
       
   386         {
       
   387         CleanupStack::PopAndDestroy(3); //newXDMsetMenuList, popupList, settingIDs
       
   388         return EFalse;
       
   389         }
       
   390     CleanupStack::PushL(newXDMsetMenuListArray);
       
   391 
       
   392     newXDMsetMenuListArray->Sort(ECmpCollated);
       
   393     model->SetItemTextArray(newXDMsetMenuListArray);
       
   394     CleanupStack::Pop(1); // newXDMsetMenuListArray owned by model
       
   395     CleanupStack::PopAndDestroy(1); //settingIDs
       
   396 
       
   397     // Set title
       
   398     HBufC* title;
       
   399     title = StringLoader::LoadLC(R_STR_XDM_USE_EXISTING);
       
   400     popupList->SetTitleL(*title);
       
   401     CleanupStack::PopAndDestroy(1); //title
       
   402 
       
   403     // Show the menu in the popup list
       
   404     TInt popupOk = popupList->ExecuteLD();
       
   405 
       
   406     CleanupStack::Pop(popupList);
       
   407 
       
   408     // if the user selected some set
       
   409     if (popupOk)
       
   410         {
       
   411         iData->Reset();
       
   412         TPtrC setName = newXDMsetMenuListArray->MdcaPoint
       
   413                                     (newXDMsetMenuList->CurrentItemIndex());
       
   414         
       
   415         iData->iSettingId = GetSettingIdL(setName);
       
   416         (iData->iSettingNameDisp).Copy(setName);
       
   417         (iData->iSettingName).Copy(setName);
       
   418         AknTextUtils::ConvertDigitsTo(iData->iSettingName, EDigitTypeWestern );
       
   419         CleanupStack::PopAndDestroy(newXDMsetMenuList);
       
   420         return ETrue;
       
   421         }
       
   422     // otherwise return false
       
   423     CleanupStack::PopAndDestroy(1); //newXDMsetMenuList
       
   424     return EFalse;      
       
   425     }
       
   426     
       
   427 // ---------------------------------------------------------------------------
       
   428 // CXDMPluginSLContainer::SetTitlePaneTextL( const TDesC& aTitleText ) const
       
   429 // ---------------------------------------------------------------------------
       
   430 //
       
   431 void CXDMPluginSLContainer::SetTitlePaneTextL( const TDesC& aTitleText ) const
       
   432     {
       
   433     CAknTitlePane* title = static_cast< CAknTitlePane* >
       
   434         ( CEikonEnv::Static()->AppUiFactory()->StatusPane()->ControlL(
       
   435                                         TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   436     if ( !title )
       
   437         {
       
   438         User::Leave( KErrNotSupported );
       
   439         }
       
   440     title->SetTextL( aTitleText );
       
   441     }
       
   442     
       
   443 // ---------------------------------------------------------------------------
       
   444 // CXDMPluginSLContainer::AreCompulsoryItemsFilled()
       
   445 // ---------------------------------------------------------------------------
       
   446 //
       
   447 TBool CXDMPluginSLContainer::AreCompulsoryItemsFilled()
       
   448     {
       
   449     if ( (iData->iAccessPoint > -1) && ((iData->iServerAddress)!=KNullDesC) && 
       
   450         ((iData->iUserID)!=KNullDesC) )
       
   451         {
       
   452         return ETrue;
       
   453         }
       
   454     return EFalse;   
       
   455     }
       
   456     
       
   457 // ---------------------------------------------------------------------------
       
   458 // CXDMPluginSLContainer::DisplayDeleteOrDontSaveDialog()
       
   459 // ---------------------------------------------------------------------------
       
   460 //
       
   461 TBool CXDMPluginSLContainer::DisplayDeleteOrDontSaveDialogL()
       
   462     {
       
   463     TBuf<KMaxMessageToDisplayLength> myDisplayMessage;
       
   464     CAknQueryDialog* query = CAknQueryDialog::NewL
       
   465                                         (CAknQueryDialog::EConfirmationTone);
       
   466     StringLoader::Load ( myDisplayMessage, R_STR_XDM_CONF_COMPULSORY );
       
   467     return (query->ExecuteLD( R_CONFIRMATION_QUERY, myDisplayMessage ));
       
   468     }
       
   469     
       
   470 // ---------------------------------------------------------------------------
       
   471 // CXDMPluginSLContainer::DeleteXDMSetIfExistL()
       
   472 // ---------------------------------------------------------------------------
       
   473 //
       
   474 void CXDMPluginSLContainer::DeleteXDMSetIfExistL()
       
   475     {
       
   476     TRAPD(err, TXdmSettingsApi::RemoveCollectionL(iData->iSettingId));
       
   477     if ( (err!=KErrNone) && (err!=KErrNotFound) )
       
   478         {
       
   479         User::LeaveIfError(err);        
       
   480         }
       
   481     }
       
   482 
       
   483 // ---------------------------------------------------------------------------
       
   484 // CXDMPluginSLContainer::IsExitProcessingOKL()
       
   485 // ---------------------------------------------------------------------------
       
   486 //
       
   487 TBool CXDMPluginSLContainer::IsExitProcessingOKL()
       
   488     {
       
   489     if (AreCompulsoryItemsFilled())
       
   490         {
       
   491         return SaveOrCreateAndSaveXDMSetL(ETrue);
       
   492         }
       
   493     else
       
   494         {
       
   495         if (DisplayDeleteOrDontSaveDialogL())
       
   496             {
       
   497             DeleteXDMSetIfExistL();
       
   498             }
       
   499         else
       
   500             {
       
   501              return EFalse;
       
   502             }
       
   503         }
       
   504     return ETrue;
       
   505     }
       
   506     
       
   507 // ---------------------------------------------------------------------------
       
   508 // CXDMPluginSLContainer::SaveSettingsIfPossibleL()
       
   509 // ---------------------------------------------------------------------------
       
   510 //
       
   511 void CXDMPluginSLContainer::SaveSettingsIfPossibleL()
       
   512     {
       
   513     if (AreCompulsoryItemsFilled())
       
   514         SaveOrCreateAndSaveXDMSetL(EFalse);    
       
   515     }
       
   516     
       
   517 // ---------------------------------------------------------------------------
       
   518 // CXDMPluginSLContainer::SaveOrCreateAndSaveXDMSetL()
       
   519 // ---------------------------------------------------------------------------
       
   520 //
       
   521 TBool CXDMPluginSLContainer::SaveOrCreateAndSaveXDMSetL(TBool aShowDialog)
       
   522     {
       
   523     TBool ret = ETrue;
       
   524     CXdmSettingsCollection* myXDMSet(NULL);
       
   525     TInt err(KErrNotFound); // Initialize such that id not found in settings API
       
   526     
       
   527     // take the saveable name
       
   528     iData->iSettingName = iData->iSettingNameDisp;
       
   529     AknTextUtils::ConvertDigitsTo(iData->iSettingName, EDigitTypeWestern ); 
       
   530     
       
   531     // check whether this is a new set or an existing set was edited
       
   532     if ((iData->iSettingId) > NULL) // is there is valid id
       
   533         {
       
   534         TRAP(err, myXDMSet = TXdmSettingsApi::SettingsCollectionL
       
   535                                                 (iData->iSettingId));
       
   536         }
       
   537     if(myXDMSet)
       
   538         {
       
   539          delete myXDMSet; // we dont need it
       
   540         }
       
   541         
       
   542     // check if the setting name is already exist
       
   543     // ask user to change name
       
   544     if (IsXDMSetNameExistL(iData->iSettingName, iData->iSettingId))
       
   545         {
       
   546         if (!aShowDialog) // if we cant display dialog than return.
       
   547             return EFalse;
       
   548         HBufC* myDisplayMessage = NULL;
       
   549         CAknInformationNote* note = new (ELeave) CAknInformationNote( ETrue );
       
   550         note->SetTimeout( CAknNoteDialog::ELongTimeout  );
       
   551         myDisplayMessage = StringLoader::LoadLC(R_STR_XDM_NAME_ALREADY_EXIST, iData->iSettingNameDisp);
       
   552         note->ExecuteLD( *myDisplayMessage );
       
   553         CleanupStack::PopAndDestroy(1); //myDisplayMessage
       
   554         iSettingList->EditItemL(ESettingNameIndex,EFalse);
       
   555         return EFalse;                
       
   556         }
       
   557         
       
   558     if(err == KErrNone) // if set exists update it
       
   559         {
       
   560         TXdmSettingsApi::UpdatePropertyL(iData->iSettingId, 
       
   561                                         iData->iSettingName, EXdmPropName);
       
   562         TXdmSettingsApi::UpdatePropertyL(iData->iSettingId, 
       
   563                                         iData->iAccessPointDes, EXdmPropToNapId);
       
   564         TXdmSettingsApi::UpdatePropertyL(iData->iSettingId, 
       
   565                                         iData->iServerAddress, EXdmPropUri);
       
   566         TXdmSettingsApi::UpdatePropertyL(iData->iSettingId, 
       
   567                                         iData->iUserID, EXdmPropAuthName);
       
   568         TXdmSettingsApi::UpdatePropertyL(iData->iSettingId, 
       
   569                                         iData->iPassword, EXdmPropAuthSecret);
       
   570         ret = ETrue;    
       
   571         }
       
   572 
       
   573     else if (err == KErrNotFound) // if set doenst exists create and save it
       
   574         {
       
   575         myXDMSet = new (ELeave) CXdmSettingsCollection();
       
   576         CleanupStack::PushL(myXDMSet);
       
   577         myXDMSet->AppendL(iData->iSettingName, EXdmPropName);
       
   578         myXDMSet->AppendL(iData->iServerAddress, EXdmPropUri);
       
   579         myXDMSet->AppendL(iData->iAccessPointDes, EXdmPropToNapId);
       
   580         myXDMSet->AppendL(iData->iUserID, EXdmPropAuthName);
       
   581         myXDMSet->AppendL(iData->iPassword, EXdmPropAuthSecret);
       
   582         TRAPD(err,TXdmSettingsApi::CreateCollectionL(*myXDMSet));
       
   583         err = err; //just to satisfy compiler
       
   584         CleanupStack::PopAndDestroy(1); // myXDMSet
       
   585         ret = ETrue;        
       
   586         }
       
   587         
       
   588     else
       
   589         {
       
   590         User::LeaveIfError(err);            
       
   591         }
       
   592     
       
   593     return ret;
       
   594     }
       
   595     
       
   596 // ---------------------------------------------------------------------------
       
   597 // CXDMPluginSLContainer::GetSettingIdL(TDesC& aXDMSetName)
       
   598 // ---------------------------------------------------------------------------
       
   599 //
       
   600 TInt CXDMPluginSLContainer::GetSettingIdL(TDesC& aXDMSetName)
       
   601     {
       
   602     TInt myId(-1);
       
   603     RArray<TInt> settingIds;
       
   604     CleanupClosePushL(settingIds);
       
   605     CDesCArray* xdmSetList =NULL;
       
   606 
       
   607     TBuf<KMaxSettingSetNameLength> setName = aXDMSetName;
       
   608     AknTextUtils::ConvertDigitsTo(setName, EDigitTypeWestern );  
       
   609     
       
   610     TRAPD(err, xdmSetList = LoadCollectionNamesL(settingIds, EFalse));
       
   611     if(err!=KErrNone)    
       
   612         {
       
   613         CleanupStack::PopAndDestroy(1); //settingIds
       
   614         return myId;
       
   615         }
       
   616     CleanupStack::PushL(xdmSetList);
       
   617 
       
   618     TInt xdmSetListCount = xdmSetList->Count();
       
   619     for (TInt i = 0; i< xdmSetListCount; i++)
       
   620         {
       
   621         if (!((xdmSetList->MdcaPoint(i)).Compare(setName))) // if equal
       
   622             {
       
   623             myId = settingIds[i];
       
   624             break;
       
   625             }
       
   626         }
       
   627     CleanupStack::PopAndDestroy(2); //xdmSetList,settingIds
       
   628     return myId;
       
   629     }
       
   630         
       
   631 // ---------------------------------------------------------------------------
       
   632 // CXDMPluginSLContainer::IsXDMSetNameExistL(TDesC& aXDMSetName, TInt32& aSettingId)
       
   633 // ---------------------------------------------------------------------------
       
   634 //
       
   635 TBool CXDMPluginSLContainer::IsXDMSetNameExistL(TDesC& aXDMSetName, TInt32& aSettingId)
       
   636     {
       
   637     TBool ret(EFalse);
       
   638     RArray<TInt> settingIds;
       
   639     CleanupClosePushL(settingIds);
       
   640     CDesCArray* xdmSetList = NULL;
       
   641 
       
   642     TBuf<KMaxSettingSetNameLength> setName = aXDMSetName;
       
   643     AknTextUtils::ConvertDigitsTo(setName, EDigitTypeWestern );  
       
   644 
       
   645     TRAPD(err, xdmSetList = LoadCollectionNamesL(settingIds, EFalse));
       
   646     if(err!=KErrNone)    
       
   647         {
       
   648         CleanupStack::PopAndDestroy(1); //settingIds
       
   649         return EFalse;
       
   650         }
       
   651     CleanupStack::PushL(xdmSetList);
       
   652 
       
   653     TInt xdmSetListCount = xdmSetList->Count();
       
   654     for (TInt i = 0; i< xdmSetListCount; i++)
       
   655         {
       
   656         if (!((xdmSetList->MdcaPoint(i)).Compare(setName))) // if equal
       
   657             {
       
   658             if (settingIds[i] != aSettingId) // if the set is not itself
       
   659                 {
       
   660                  ret = ETrue;
       
   661                 }
       
   662             }
       
   663         }
       
   664     CleanupStack::PopAndDestroy(2); //xdmSetList,settingIds
       
   665     return ret;
       
   666     }
       
   667     
       
   668 // ---------------------------------------------------------------------------
       
   669 // CXDMPluginSLContainer::LoadCollectionNamesL
       
   670 // ---------------------------------------------------------------------------
       
   671 //
       
   672 CDesCArray* CXDMPluginSLContainer::LoadCollectionNamesL(RArray<TInt>& aSettingIDs
       
   673                                                                     , TBool aDisp)
       
   674     {
       
   675     CDesCArray* myArray = TXdmSettingsApi::CollectionNamesLC(aSettingIDs);
       
   676     TBuf<KMaxSettingSetNameLength> name;
       
   677     if(aDisp) // convert all names to disp names
       
   678         {
       
   679         TInt count = myArray->Count();
       
   680         CDesCArray* dispArray = new CDesCArrayFlat(count+1);
       
   681         CleanupStack::PushL(dispArray);
       
   682         for(TInt i=0;i<count;i++)
       
   683             {
       
   684             name.Copy(myArray->MdcaPoint(i));
       
   685             AknTextUtils::LanguageSpecificNumberConversion(name);
       
   686             TPtrC16 ptr = name;
       
   687             dispArray->AppendL(ptr);                
       
   688             }
       
   689         CleanupStack::Pop(2);
       
   690         return dispArray;        
       
   691         }
       
   692     CleanupStack::Pop(1); // myArray
       
   693     return myArray;
       
   694     }
       
   695 
       
   696 // ---------------------------------------------------------
       
   697 // CXDMPluginSLContainer::GetHelpContext
       
   698 // This function is called when Help application is launched
       
   699 // (other items were commented in a header).
       
   700 // ---------------------------------------------------------
       
   701 //
       
   702 void CXDMPluginSLContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   703     {
       
   704     aContext.iMajor = KGSXDMPluginUid;
       
   705     aContext.iContext = KXDM_HLP_EDIT_SET;
       
   706     }   
       
   707 
       
   708 // ---------------------------------------------------------------------------
       
   709 // CXDMPluginSLContainer::HandleResourceChange()
       
   710 // ---------------------------------------------------------------------------
       
   711 void CXDMPluginSLContainer::HandleResourceChange( TInt aType )
       
   712     {
       
   713     CCoeControl::HandleResourceChange( aType );
       
   714     if ( aType == KAknsMessageSkinChange ||
       
   715          aType == KEikDynamicLayoutVariantSwitch )
       
   716         {
       
   717         CXDMPlugin* iTempView = static_cast<CXDMPlugin*> (iView);    
       
   718         iTempView->HandleResourceChangeManual(aType);      
       
   719         }
       
   720     }
       
   721 
       
   722 
       
   723 // ---------------------------------------------------------------------------
       
   724 // CXDMPluginSLContainer::HandleResourceChangeManual()
       
   725 // ---------------------------------------------------------------------------    
       
   726 void CXDMPluginSLContainer::HandleResourceChangeManual(TInt aType)
       
   727     {
       
   728     TRect mainPaneRect;
       
   729     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane,
       
   730                                        mainPaneRect);
       
   731     SetRect( mainPaneRect );
       
   732 	DrawDeferred();
       
   733 	
       
   734 	iSettingList->HandleResourceChange(aType);
       
   735     }
       
   736 
       
   737 // ---------------------------------------------------------------------------
       
   738 // CXDMPluginSLContainer::FocusChanged
       
   739 // Set focus on the selected listbox. For animated skins feature.
       
   740 // ---------------------------------------------------------------------------
       
   741 void CXDMPluginSLContainer::FocusChanged(TDrawNow aDrawNow)
       
   742     {
       
   743     if(iSettingList)
       
   744         {
       
   745         iSettingList->SetFocus( IsFocused(), aDrawNow );
       
   746         }
       
   747     }
       
   748 
       
   749 // ---------------------------------------------------------------------------
       
   750 // CXDMPluginSLContainer::GetCurrentSetName()
       
   751 // See header for details.
       
   752 // ---------------------------------------------------------------------------    
       
   753 // 
       
   754 TDes& CXDMPluginSLContainer::GetCurrentSetName()
       
   755     {
       
   756     return iData->iSettingName;    
       
   757     }
       
   758     
       
   759 // ---------------------------------------------------------------------------
       
   760 // CXDMPluginSLContainer::DoMakeValidNameL()
       
   761 // See header for details.
       
   762 // ---------------------------------------------------------------------------
       
   763 // 
       
   764 HBufC* CXDMPluginSLContainer::DoMakeValidNameL(HBufC* aName, TBool& aChanged)
       
   765     {
       
   766     aChanged = EFalse;
       
   767     HBufC* temp = HBufC::NewLC( KMaxSettingSetNameLength );
       
   768     HBufC* temp2 = HBufC::NewLC( KMaxSettingSetNameLength );
       
   769     
       
   770     HBufC* corrname = EnsureMaxLengthLC( aName, aChanged);
       
   771     *temp = *corrname;
       
   772     TInt postfix( 0 );
       
   773     TInt pf( 0 );
       
   774     TInt i( 0 );
       
   775     
       
   776     
       
   777     // Load the names
       
   778     RArray<TInt> settingIDs;
       
   779     CleanupClosePushL(settingIDs);
       
   780     CDesCArray* xdmSetList = NULL;
       
   781 
       
   782     TRAPD(err, xdmSetList = LoadCollectionNamesL(settingIDs, EFalse));
       
   783     if(err!=KErrNone)    
       
   784         {
       
   785         CleanupStack::PopAndDestroy(4); //settingIds
       
   786         return corrname; 
       
   787         }
       
   788     CleanupStack::PushL(xdmSetList);
       
   789     
       
   790     // do the actual checking of name
       
   791     TInt found(0);
       
   792     TInt pos(0);
       
   793     
       
   794     TPtrC prefix = GetPrefix( *corrname );
       
   795     
       
   796     postfix = GetPostfix( *temp, prefix );
       
   797     postfix = -1;
       
   798     do
       
   799         {       
       
   800         found = xdmSetList->Find( *temp, pos );
       
   801         if ( found == KErrNone )
       
   802             {
       
   803             aChanged = ETrue;
       
   804             postfix++;
       
   805             // check the length of postfix, check text length accordingly
       
   806             pf = postfix;
       
   807             for (i=1; i<10; i++)
       
   808                 {
       
   809                 pf /= 10;
       
   810                 if ( !pf )
       
   811                     break;
       
   812                 }
       
   813             TPtr sgdptr( temp->Des() );
       
   814             TPtr sgdptr2( temp2->Des() );
       
   815             if ( postfix )
       
   816                 {
       
   817                 if ( postfix < 10 )
       
   818         {
       
   819                     sgdptr2 = prefix.Left( KMaxSettingSetNameLength - i - 3 );
       
   820                     }
       
   821                 else
       
   822             {
       
   823                     sgdptr2 = prefix.Left( KMaxSettingSetNameLength - i - 2 );
       
   824                     }
       
   825                 }
       
   826             else
       
   827                 {
       
   828                 sgdptr2 = prefix.Left( KMaxSettingSetNameLength );
       
   829                 }
       
   830             if ( postfix )
       
   831                 {
       
   832                 if ( postfix > 9 )
       
   833                     {
       
   834                     sgdptr.Format( KFormatLargePostfix, &sgdptr2,
       
   835                                        postfix );
       
   836                     }
       
   837                 else
       
   838                     {
       
   839                     sgdptr.Format( KFormatPostfix, &sgdptr2,
       
   840                                        postfix );
       
   841                 }
       
   842             }
       
   843             else
       
   844                 {
       
   845                 sgdptr.Format( KFormatNoPostfix, &sgdptr2 );
       
   846         }
       
   847             }
       
   848         } while (found == KErrNone);
       
   849         
       
   850     CleanupStack::PopAndDestroy(xdmSetList);
       
   851     CleanupStack::PopAndDestroy(1); //settingIds
       
   852     CleanupStack::PopAndDestroy( corrname );
       
   853     CleanupStack::PopAndDestroy( temp2 );
       
   854 
       
   855     if ( aChanged )
       
   856         {
       
   857         CleanupStack::Pop( temp );
       
   858         }
       
   859     else
       
   860         {
       
   861         CleanupStack::PopAndDestroy( temp );
       
   862         temp = NULL;
       
   863         }
       
   864     
       
   865     return temp;
       
   866     }
       
   867     
       
   868 // ---------------------------------------------------------------------------
       
   869 // CXDMPluginSLContainer::EnsureMaxLengthLC()
       
   870 // See header for details.
       
   871 // ---------------------------------------------------------------------------
       
   872 HBufC* CXDMPluginSLContainer::EnsureMaxLengthLC( const TDesC* aName, TBool& aChanged)
       
   873     {
       
   874     TInt length = aName->Length();
       
   875     
       
   876     aChanged = EFalse;
       
   877     
       
   878     if ( !length )
       
   879         {
       
   880         // Name is required.
       
   881         User::Leave(KErrArgument);
       
   882         }
       
   883 
       
   884     HBufC* corrname;
       
   885     if ( KMaxSettingSetNameLength < length )
       
   886         { // name too long, truncate.
       
   887         corrname = aName->Left( KMaxSettingSetNameLength ).AllocLC();
       
   888         aChanged = ETrue;
       
   889         }
       
   890     else
       
   891         {
       
   892         corrname = aName->AllocLC();
       
   893         corrname->Des().Trim();
       
   894         if ( corrname->Length() == 0 )
       
   895             {
       
   896             User::Leave(KErrArgument);
       
   897             }
       
   898         // comes here only if name is valid
       
   899         if ( corrname->Length() != aName->Length() )
       
   900     {
       
   901             aChanged = ETrue;
       
   902             }
       
   903         }
       
   904 
       
   905     return corrname;
       
   906     }
       
   907     
       
   908 // ---------------------------------------------------------------------------
       
   909 // CXDMPluginSLContainer::GetPrefix()
       
   910 // See header for details.
       
   911 // ---------------------------------------------------------------------------
       
   912 TPtrC CXDMPluginSLContainer::GetPrefix( const TDesC& aName )
       
   913     {
       
   914     TPtrC prefix = aName;
       
   915     TInt lastBrace = aName.LocateReverse('(');
       
   916     if ( lastBrace != KErrNotFound )
       
   917         {
       
   918         // aName looks like "<prefix><brace><something>".
       
   919         // See if <something> is an integer number.
       
   920         TPtrC num = aName.Right( aName.Length() - lastBrace - 1 );
       
   921         TInt val;
       
   922         TLex lex( num );
       
   923         if ( lex.Val( val ) == KErrNone )
       
   924             {
       
   925             // Yes, the trailer is an integer.
       
   926             prefix.Set( aName.Left( lastBrace ) );
       
   927             }
       
   928         }
       
   929     return prefix;
       
   930     }
       
   931 
       
   932 // ---------------------------------------------------------------------------
       
   933 // CXDMPluginSLContainer::GetPostfix()
       
   934 // See header for details.
       
   935 // ---------------------------------------------------------------------------
       
   936 TInt CXDMPluginSLContainer::GetPostfix( const TDesC& aName, const TDesC& aPrefix )
       
   937     {
       
   938     TInt postfix( KErrNotFound );
       
   939     TInt nameLength = aName.Length();
       
   940     TInt prefixLength = aPrefix.Length();
       
   941     if ( nameLength >= prefixLength && aName.FindF( aPrefix ) == 0 )
       
   942         {
       
   943         // aName is longer or equal length, and
       
   944         // aPrefix can be found in the beginning of aName.
       
   945         if ( nameLength == prefixLength )
       
   946             {
       
   947             // They have the same length; they equal.
       
   948             postfix = 0;
       
   949             }
       
   950         else
       
   951             {
       
   952             if ( aName[ prefixLength ] == '(' )
       
   953                 {
       
   954                 // (Now we know that aName is longer than aPrefix.)
       
   955                 // aName looks like "aPrefix<brace><something>".
       
   956                 // See if <something> is an integer number.
       
   957                 TPtrC num = aName.Right( nameLength - prefixLength - 1 );
       
   958                 TBuf< KMaxPostfixLength > pf;
       
   959                 if (num.Length() <= pf.Length())
       
   960                     pf = num;
       
   961                 TInt val;
       
   962                 TLex lex( pf );
       
   963                 if ( lex.Val( val ) == KErrNone )
       
   964                     {
       
   965                     // Yes, the trailer is an integer.
       
   966                     if ( val > 0 )
       
   967                         {
       
   968                         postfix = val;
       
   969                         }
       
   970                     else
       
   971                         {
       
   972                         // signal that it is invalid...
       
   973                         postfix = -1;
       
   974                         }
       
   975                     }
       
   976                 }
       
   977             }
       
   978         }
       
   979     return postfix;
       
   980     }
       
   981 // end of file