XDMSettingsUI/src/XDMPluginContainer.cpp
branchGCC_SURGE
changeset 28 d9861ae9169c
parent 23 77cb48a03620
parent 26 04ca1926b01c
equal deleted inserted replaced
23:77cb48a03620 28:d9861ae9169c
     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 main 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 <StringLoader.h>
       
    30 #include <aknlists.h>
       
    31 #include <AknUtils.h>
       
    32 #include <eiksbfrm.h>
       
    33 #include <AknQueryDialog.h>
       
    34 #include <XdmSettingsApi.h>
       
    35 
       
    36 #include "SettingsData.h"
       
    37 #include "XDMPluginContainer.h"
       
    38 
       
    39 #include <csxhelp/xdm.hlp.hrh>
       
    40 
       
    41 
       
    42 
       
    43    
       
    44 // ---------------------------------------------------------------------------
       
    45 // CXDMPluginContainer::CXDMPluginContainer()
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CXDMPluginContainer::CXDMPluginContainer(CAknView* aView) : iView(aView)
       
    49     {
       
    50     
       
    51     }
       
    52     
       
    53 // ---------------------------------------------------------------------------
       
    54 // CXDMPluginContainer::ConstructL(const TRect& aRect)
       
    55 // Symbian OS two phased constructor
       
    56 // 
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 void CXDMPluginContainer::ConstructL( const TRect& aRect )
       
    60     {
       
    61     #ifdef _DEBUG  
       
    62     RDebug::Print( _L( "[CXDMPluginContainer] ConstructL()" ) );
       
    63 	#endif
       
    64 
       
    65     CEikStatusPane* sp = static_cast<CAknAppUi*> 
       
    66         ( CEikonEnv::Static()->EikAppUi() )->StatusPane();
       
    67     iTitlePane = static_cast<CAknTitlePane*> 
       
    68         ( sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
    69 
       
    70     // Set title
       
    71     
       
    72     StringLoader::Load ( iTitle, R_STR_XDM_TITLE_PANE_TEXT );
       
    73     iTitlePane->SetTextL(iTitle);// FromResourceL( rReader );
       
    74     CreateWindowL(); // Makes the control a window-owning control
       
    75 
       
    76     // Main List creation and initialization
       
    77     iMainList = new(ELeave) CAknSingleStyleListBox();
       
    78     iMainList->SetContainerWindowL(*this);
       
    79     iMainList->ConstructL(this, EAknListBoxLoopScrolling);
       
    80 
       
    81     // Main list scroll bar issues
       
    82     iMainList->CreateScrollBarFrameL(EFalse);
       
    83     iMainList->ScrollBarFrame()->SetScrollBarVisibilityL(
       
    84     CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
    85     
       
    86     // Empty text processing
       
    87     _LIT (KStringHeader, "%S\n%S");
       
    88     HBufC* emptyText = iEikonEnv->AllocReadResourceLC( R_STR_XDM_EMPTY_TEXT );
       
    89     HBufC* emptyText2 = iEikonEnv->AllocReadResourceLC( R_STR_XDM_EMPTY_TEXT_SEC);   
       
    90     HBufC* emptyFinal = HBufC::NewLC( 
       
    91         emptyText->Length() + emptyText2->Length() + 2 );// 2 is length of "\n" 
       
    92     emptyFinal->Des().Format(KStringHeader, emptyText, emptyText2);
       
    93     
       
    94     iMainList->SetListBoxObserver(this);
       
    95     iMainList->View()->SetListEmptyTextL(*emptyFinal);
       
    96     CleanupStack::PopAndDestroy(3, emptyText);//emptyText, emptyText2, emptyFinal
       
    97 
       
    98     // This call fails if Problems in XDM API, so leave if error
       
    99     TRAPD(err,SetupListL());
       
   100     User::LeaveIfError(err);
       
   101 
       
   102     SetRect( aRect );
       
   103     ActivateL();
       
   104     
       
   105     #ifdef _DEBUG           
       
   106     RDebug::Print( _L( "[CXDMPluginContainer] Construct done" ) );
       
   107 	#endif
       
   108 
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CXDMPluginContainer::~CXDMPluginContainer()
       
   113 // Destructor
       
   114 //  
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 CXDMPluginContainer::~CXDMPluginContainer()
       
   118     {
       
   119     if (iMainList)
       
   120         {
       
   121          delete iMainList;
       
   122         }
       
   123     }
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CXDMPluginContainer::SizeChanged()
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 void CXDMPluginContainer::SizeChanged()
       
   130     {
       
   131     iMainList->SetRect(Rect());
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CXDMPluginContainer::CountComponentControls() const
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 TInt CXDMPluginContainer::CountComponentControls() const
       
   139     {
       
   140     return 1;
       
   141     }
       
   142     
       
   143 // ---------------------------------------------------------------------------
       
   144 // CXDMPluginContainer::ComponentControl() const
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 CCoeControl* CXDMPluginContainer::ComponentControl( TInt aIndex ) const
       
   148     {
       
   149     switch ( aIndex )
       
   150         {
       
   151         case 0:
       
   152             return iMainList;
       
   153         default:
       
   154             return NULL;
       
   155         }
       
   156     }
       
   157     
       
   158 // ---------------------------------------------------------------------------
       
   159 // CXDMPluginContainer::EditCurrentItemL()
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 void CXDMPluginContainer::EditCurrentItemL()
       
   163     {
       
   164     TPtrC16 xDMSetName;
       
   165     TPtrC16 xDMSetNameClipped;
       
   166     xDMSetName.Set(iSettingListArray->MdcaPoint(iMainList->CurrentItemIndex()));
       
   167     xDMSetNameClipped.Set(xDMSetName.Mid(1)); // remove '/t' from the begining
       
   168     }
       
   169     
       
   170 // ---------------------------------------------------------------------------
       
   171 // CXDMPluginContainer::GetCurrentSetNameLC()
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 HBufC* CXDMPluginContainer::GetCurrentSetNameLC()
       
   175     {
       
   176     TPtrC16 xDMSetName;
       
   177     TPtrC16 xDMSetNameClipped;
       
   178     xDMSetName.Set(iSettingListArray->MdcaPoint(iMainList->CurrentItemIndex()));
       
   179     xDMSetNameClipped.Set(xDMSetName.Mid(1)); // remove '/t' from the begining
       
   180     
       
   181     HBufC* name = xDMSetNameClipped.AllocLC();
       
   182     TPtr ptr(name->Des());
       
   183     AknTextUtils::ConvertDigitsTo(ptr, EDigitTypeWestern );
       
   184     
       
   185     return name;    
       
   186     }
       
   187     
       
   188    
       
   189 // ---------------------------------------------------------------------------
       
   190 // CXDMPluginContainer::OfferKeyEventL()
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 TKeyResponse CXDMPluginContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, 
       
   194                                                             TEventCode aType )
       
   195     {
       
   196     if (iMainList)
       
   197         {
       
   198         // if cancel key is pressed and list is not empty, invoke deletion
       
   199         if ((aKeyEvent.iCode == EKeyBackspace ) && (aType == EEventKey) )
       
   200             {
       
   201             if(!IsListEmpty())
       
   202                 DeleteSetProcedureL();
       
   203             return EKeyWasConsumed;
       
   204             }
       
   205         else
       
   206             return iMainList->OfferKeyEventL (aKeyEvent, aType);
       
   207         }
       
   208     return EKeyWasNotConsumed;
       
   209     }
       
   210     
       
   211 // ---------------------------------------------------------------------------
       
   212 // CXDMPluginContainer::HandleListBoxEventL()
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 void CXDMPluginContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aListBoxEvent)
       
   216     {
       
   217     // if the Select Key has been pressed
       
   218     if ((aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) ||
       
   219     (aListBoxEvent == MEikListBoxObserver::EEventItemDoubleClicked))
       
   220         {
       
   221         EditCurrentItemL();           
       
   222         }
       
   223     }
       
   224   
       
   225 // ---------------------------------------------------------------------------
       
   226 // CXDMPluginContainer::SetupListL()
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void CXDMPluginContainer::SetupListL()
       
   230     {
       
   231     CTextListBoxModel* model = iMainList->Model();
       
   232     model->SetOwnershipType(ELbmOwnsItemArray);
       
   233     
       
   234     iSettingListArray = STATIC_CAST(CDesCArray*,model->ItemTextArray());
       
   235     LoadSettingsListArrayL();
       
   236     }
       
   237     
       
   238 // ---------------------------------------------------------------------------
       
   239 // CXDMPluginContainer::LoadSettingsListArrayL()
       
   240 // ---------------------------------------------------------------------------
       
   241 //
       
   242 void CXDMPluginContainer::LoadSettingsListArrayL()
       
   243     {
       
   244     iTitlePane->SetTextL(iTitle);
       
   245     TBuf <KMaxSettingSetNameLength+2> myString; // maximum name + \t
       
   246     RArray<TInt> settingIds;
       
   247     CleanupClosePushL(settingIds);
       
   248     CDesCArray* xdmSetList = NULL;
       
   249     TRAPD(err, xdmSetList = LoadCollectionNamesL(settingIds));
       
   250     if(err!=KErrNone)    
       
   251         {
       
   252         CleanupStack::PopAndDestroy(1); //settingIds
       
   253         return;
       
   254         }
       
   255     CleanupStack::PushL(xdmSetList);
       
   256     TInt xdmSetListCount = xdmSetList->Count();
       
   257     iSettingListArray->Reset();
       
   258     for (TInt i = 0; i< xdmSetListCount; i++)
       
   259         {
       
   260         }
       
   261     iSettingListArray->Sort(ECmpCollated);
       
   262     CleanupStack::PopAndDestroy(2); //xdmSetList,settingIds
       
   263     iMainList->HandleItemRemovalL();
       
   264     iMainList->HandleItemAdditionL();
       
   265     }
       
   266     
       
   267 // ---------------------------------------------------------------------------
       
   268 // CXDMPluginContainer::IsListEmpty()
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 TBool CXDMPluginContainer::IsListEmpty()
       
   272     {
       
   273     if (iSettingListArray->Count())
       
   274         return EFalse;
       
   275     return ETrue;    
       
   276     }
       
   277     
       
   278 // ---------------------------------------------------------------------------
       
   279 // CXDMPluginContainer::IsLastItem()
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 TBool CXDMPluginContainer::IsLastItem()
       
   283     {
       
   284     if (iSettingListArray->Count() == 1)
       
   285         return ETrue;
       
   286     return EFalse;    
       
   287     }
       
   288     
       
   289 // ---------------------------------------------------------------------------
       
   290 // CXDMPluginContainer::DeleteCurrentSetL()
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 void CXDMPluginContainer::DeleteCurrentSetL()
       
   294     {
       
   295     TXdmSettingsApi::RemoveCollectionL( GetCurrentSetIdL() );    
       
   296     TInt deletedItemIndex = iMainList->CurrentItemIndex();
       
   297     iSettingListArray->Delete( deletedItemIndex );
       
   298     
       
   299     AknListBoxUtils::HandleItemRemovalAndPositionHighlightL(
       
   300         iMainList, deletedItemIndex, ETrue );
       
   301     iMainList->DrawNow();
       
   302     }
       
   303     
       
   304 // ---------------------------------------------------------------------------
       
   305 // CXDMPluginContainer::GetCurrentSetIdL()
       
   306 // ---------------------------------------------------------------------------
       
   307 //
       
   308 TInt CXDMPluginContainer::GetCurrentSetIdL()
       
   309     {
       
   310     TInt myId(-1);
       
   311     RArray<TInt> settingIds;
       
   312     CleanupClosePushL(settingIds);
       
   313     CDesCArray* xdmSetList = NULL;
       
   314 
       
   315     TRAPD(err, xdmSetList = LoadCollectionNamesL(settingIds));
       
   316     if(err!=KErrNone)    
       
   317         {
       
   318         CleanupStack::PopAndDestroy(1); //settingIds
       
   319         return myId;
       
   320         }
       
   321     CleanupStack::PushL(xdmSetList);
       
   322 
       
   323     TInt xdmSetListCount = xdmSetList->Count();
       
   324     HBufC* currentSetName = GetCurrentSetNameLC();
       
   325     for (TInt i = 0; i< xdmSetListCount; i++)
       
   326         {
       
   327         if (!((xdmSetList->MdcaPoint(i)).Compare(*currentSetName))) // if equal
       
   328             {
       
   329             myId = settingIds[i];
       
   330             break;
       
   331             }
       
   332         }
       
   333     CleanupStack::PopAndDestroy(3); //xdmSetList,settingIds,currentSetName
       
   334     return myId;
       
   335     }
       
   336 
       
   337 // ---------------------------------------------------------------------------
       
   338 // CXDMPluginContainer::LoadCollectionNamesL()
       
   339 // ---------------------------------------------------------------------------
       
   340 //
       
   341 CDesCArray* CXDMPluginContainer::LoadCollectionNamesL(RArray<TInt>& aSettingIDs)
       
   342     {
       
   343     CDesCArray* myArray = TXdmSettingsApi::CollectionNamesLC(aSettingIDs);
       
   344     CleanupStack::Pop(1); // will be pop if above doesnt leave
       
   345     return myArray;
       
   346     }
       
   347 
       
   348 // ---------------------------------------------------------
       
   349 // CXDMPluginContainer::GetHelpContext
       
   350 // This function is called when Help application is launched
       
   351 // (other items were commented in a header).
       
   352 // ---------------------------------------------------------
       
   353 //
       
   354 void CXDMPluginContainer::GetHelpContext( TCoeHelpContext& aContext ) const
       
   355     {
       
   356     aContext.iMajor = KGSXDMPluginUid;
       
   357     aContext.iContext = KXDM_HLP_LIST_VIEW;
       
   358     }
       
   359     
       
   360 // ---------------------------------------------------------------------------
       
   361 // CXDMPluginContainer::DeleteSetProcedureL()
       
   362 // ---------------------------------------------------------------------------
       
   363 //
       
   364 void CXDMPluginContainer::DeleteSetProcedureL()
       
   365     {
       
   366     HBufC* myDisplayMessage = NULL;
       
   367     HBufC* currentSetName = GetCurrentSetNameLC();
       
   368     TPtr myname(currentSetName->Des());
       
   369     AknTextUtils::LanguageSpecificNumberConversion(myname); 
       
   370     
       
   371     CAknQueryDialog* query = CAknQueryDialog::NewL(CAknQueryDialog::EConfirmationTone);
       
   372     if (IsLastItem())
       
   373         myDisplayMessage = StringLoader::LoadLC(R_STR_XDM_CONF_DELETE_LAST, *currentSetName );
       
   374     else
       
   375         myDisplayMessage = StringLoader::LoadLC(R_STR_XDM_CONF_DELETE, *currentSetName );
       
   376     
       
   377     if ( query->ExecuteLD( R_CONFIRMATION_QUERY, *myDisplayMessage ) )
       
   378         {
       
   379         DeleteCurrentSetL();
       
   380         }
       
   381     CleanupStack::PopAndDestroy(2); //currentSetName, myDisplayMessage
       
   382     }
       
   383   
       
   384 // ---------------------------------------------------------------------------
       
   385 // CXDMPluginContainer::HandleResourceChange()
       
   386 // ---------------------------------------------------------------------------
       
   387 void CXDMPluginContainer::HandleResourceChange( TInt aType )
       
   388     {
       
   389     if ( aType == KAknsMessageSkinChange ||
       
   390          aType == KEikDynamicLayoutVariantSwitch )
       
   391         {
       
   392         }
       
   393     CCoeControl::HandleResourceChange( aType );
       
   394     }
       
   395   
       
   396 // ---------------------------------------------------------------------------
       
   397 // CXDMPluginContainer::HandleResourceChangeManual()
       
   398 // ---------------------------------------------------------------------------
       
   399 void CXDMPluginContainer::HandleResourceChangeManual(TInt aType)
       
   400     {
       
   401     TRect mainPaneRect;
       
   402     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane,
       
   403                                        mainPaneRect);
       
   404     SetRect( mainPaneRect );
       
   405     //DrawNow();
       
   406     
       
   407     iMainList->HandleResourceChange(aType);
       
   408     }
       
   409 
       
   410 // ---------------------------------------------------------------------------
       
   411 // CXDMPluginContainer::FocusChanged
       
   412 // Set focus on the selected listbox. For animated skins feature.
       
   413 // ---------------------------------------------------------------------------
       
   414 void CXDMPluginContainer::FocusChanged(TDrawNow aDrawNow)
       
   415     {
       
   416     if(iMainList)
       
   417         {
       
   418         iMainList->SetFocus( IsFocused(),aDrawNow );
       
   419         }
       
   420     }
       
   421 
       
   422 // ---------------------------------------------------------------------------
       
   423 // CXDMPluginContainer::SetFocusIfExist
       
   424 // Set focus on the given set name
       
   425 // ---------------------------------------------------------------------------
       
   426 void CXDMPluginContainer::SetFocusIfExist(TDes& aSetName)
       
   427     {
       
   428     _LIT (KStringHeader, "\t%S");
       
   429     TBuf <KMaxSettingSetNameLength+2> myString; // maximum name + \t
       
   430     myString.Format(KStringHeader, &aSetName);
       
   431     AknTextUtils::LanguageSpecificNumberConversion(myString);
       
   432 
       
   433     TInt xdmSetListCount = iSettingListArray->Count();
       
   434     for (TInt i = 0; i< xdmSetListCount; i++)
       
   435         {
       
   436         if (!((iSettingListArray->MdcaPoint(i)).Compare(myString))) // if equal
       
   437             {
       
   438             iMainList->SetCurrentItemIndex(i);
       
   439             break;
       
   440             }
       
   441         }
       
   442     }
       
   443     
       
   444 // End of File