idlefw/plugins/mcsplugin/settings/src/mcspluginsettingsmodel.cpp
branchRCL_3
changeset 14 15e4dd19031c
parent 12 502e5d91ad42
child 16 b276298d5729
equal deleted inserted replaced
12:502e5d91ad42 14:15e4dd19031c
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009 - 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    16 */
    16 */
    17 
    17 
    18 #include <eikenv.h>
    18 #include <eikenv.h>
    19 #include <itemmap.h>
    19 #include <itemmap.h>
    20 #include <mhomescreensettingsif.h>
    20 #include <mhomescreensettingsif.h>
    21 
       
    22 #include <aistrcnv.h>
    21 #include <aistrcnv.h>
    23 #include <StringLoader.h>
    22 #include <StringLoader.h>
    24 #include <uri16.h>
    23 #include <uri16.h>
    25 #include <mcspluginsettingsres.rsg>
    24 #include <mcspluginsettingsres.rsg>
    26 
    25 #include <mcsmenuitem.h>
    27 
    26 
    28 #include "mcspluginsettings.h"
       
    29 #include "mcspluginsettingsmodel.h"
    27 #include "mcspluginsettingsmodel.h"
       
    28 #include "mcspluginsettingsapplist.h"
       
    29 #include "mcspluginsettingsbkmlist.h"
    30 #include "mcspluginsettingscontainer.h"
    30 #include "mcspluginsettingscontainer.h"
    31 
    31 
    32 
       
    33 #include "debug.h"
       
    34 
       
    35 #include <mcsmenuitem.h>
       
    36 
    32 
    37 /**
    33 /**
    38  * Line format for the settings list box
    34  * Line format for the settings list box
    39  */
    35  */
    40 _LIT(KSettingListboxLineFormat, " \t%S\t\t%S");
    36 _LIT(KSettingListboxLineFormat, " \t%S\t\t%S");
    49 _LIT8( KProperNameLocked, "locked" );
    45 _LIT8( KProperNameLocked, "locked" );
    50 _LIT8( KProperValueFolder, "folder" );
    46 _LIT8( KProperValueFolder, "folder" );
    51 _LIT8( KProperValueSuite, "suite" );
    47 _LIT8( KProperValueSuite, "suite" );
    52 _LIT8( KProperValueBookmark, "bookmark" );
    48 _LIT8( KProperValueBookmark, "bookmark" );
    53 _LIT8( KProperValueAppl, "application" );
    49 _LIT8( KProperValueAppl, "application" );
       
    50 _LIT8( KProperValueMailbox, "mailbox" );
       
    51 _LIT( KMenuTypeMailbox, "menu:mailbox" );
    54 
    52 
    55 using namespace HSPluginSettingsIf;
    53 using namespace HSPluginSettingsIf;
    56 
    54 
    57 // -----------------------------------------------------------------------------
    55 // -----------------------------------------------------------------------------
    58 // Creates a formatted listbox line.
    56 // Creates a formatted listbox line.
   145 // ---------------------------------------------------------------------------
   143 // ---------------------------------------------------------------------------
   146 // Second phase construction
   144 // Second phase construction
   147 // ---------------------------------------------------------------------------
   145 // ---------------------------------------------------------------------------
   148 //
   146 //
   149 void CMCSPluginSettingsModel::ConstructL()
   147 void CMCSPluginSettingsModel::ConstructL()
   150 {
   148     {
   151     CHomescreenSettings::InitializeL( KAppUid );
   149     CHomescreenSettings::InitializeL( KAppUid );
   152     
   150     
   153     iPluginSettings = CHomescreenSettings::Instance();
   151     iPluginSettings = CHomescreenSettings::Instance();
   154     if( iPluginSettings == NULL )
   152     if( iPluginSettings == NULL )
   155         {
   153         {
   156         User::Leave( KErrUnknown );
   154         User::Leave( KErrUnknown );
   157         }
   155         }
   158     
   156     }
   159     iAppList = CMCSPluginSettingsAppList::NewL();
       
   160     iAppList->StartL();
       
   161     iBkmList = CMCSPluginSettingsBkmList::NewL();
       
   162 }
       
   163 
       
   164 
   157 
   165 // ---------------------------------------------------------------------------
   158 // ---------------------------------------------------------------------------
   166 // Gets the latest settings from HSPS and updates
   159 // Gets the latest settings from HSPS and updates
   167 // ---------------------------------------------------------------------------
   160 // ---------------------------------------------------------------------------
   168 //
   161 //
   169 void CMCSPluginSettingsModel::UpdateSettingsL( const TDesC8& aPluginId )
   162 void CMCSPluginSettingsModel::UpdateSettingsL()
   170     {
   163     {
   171     if( !iPlugin.Activated() )
   164     if( !iPluginId )
   172         {
   165         {
   173         return;
   166         return;
   174         }
   167         }
   175     
   168     
   176     if( iPluginId )
   169     if (iContainer)
   177         {
   170         {
   178         delete iPluginId;
   171         iContainer->CloseChangeDialog();
   179         iPluginId = NULL;
   172         }
   180         }
   173 
   181     iPluginId = aPluginId.AllocL();    
       
   182     
       
   183     iSettings.Reset();
   174     iSettings.Reset();
   184     RPointerArray<CItemMap> settingItems;
   175     RPointerArray<CItemMap> settingItems;
   185     CleanupClosePushL( settingItems );
   176     CleanupClosePushL( settingItems );
   186 
   177 
   187     iPluginSettings->GetSettingsL( *iPluginId, settingItems );
   178     iPluginSettings->GetSettingsL( *iPluginId, settingItems );
   195         TSettingItem item = ItemL( properties );
   186         TSettingItem item = ItemL( properties );
   196         iSettings.AppendL( item );
   187         iSettings.AppendL( item );
   197         }
   188         }
   198     CleanupStack::Pop( &settingItems );
   189     CleanupStack::Pop( &settingItems );
   199     settingItems.ResetAndDestroy();
   190     settingItems.ResetAndDestroy();
   200     }
   191     
   201 
   192     if (iContainer)
   202 // ---------------------------------------------------------------------------
   193         {
   203 // Gets the latest settings from HSPS and updates
   194         iContainer->ResetCurrentListL(0);
   204 // ---------------------------------------------------------------------------
   195         }
   205 //
       
   206 void CMCSPluginSettingsModel::UpdateSettingModelL( const TDesC8& aPluginId )
       
   207     {
       
   208     if( iPluginId )
       
   209         {
       
   210         delete iPluginId;
       
   211         iPluginId = NULL;
       
   212         }
       
   213     iPluginId = aPluginId.AllocL();
       
   214     
       
   215     iSettings.Reset();
       
   216     RPointerArray<CItemMap> settingItems;
       
   217     CleanupClosePushL( settingItems );
       
   218 
       
   219     iPluginSettings->GetSettingsL( *iPluginId, settingItems );
       
   220 
       
   221     TInt count = settingItems.Count();
       
   222     for ( TInt i = 0; i < count; i++ )
       
   223         {
       
   224         CItemMap* itemMap = settingItems[i];
       
   225         RPointerArray<HSPluginSettingsIf::CPropertyMap> properties;
       
   226         properties = itemMap->Properties();
       
   227         TSettingItem item = ItemL( properties );
       
   228         iSettings.AppendL( item );
       
   229         }
       
   230     CleanupStack::Pop( &settingItems );
       
   231     settingItems.ResetAndDestroy();
       
   232     }
   196     }
   233 
   197 
   234 // ---------------------------------------------------------------------------
   198 // ---------------------------------------------------------------------------
   235 // Tries to find menuitem which matches given HSPS entry
   199 // Tries to find menuitem which matches given HSPS entry
   236 // ---------------------------------------------------------------------------
   200 // ---------------------------------------------------------------------------
   239                  RPointerArray<HSPluginSettingsIf::CPropertyMap>& aProperties )
   203                  RPointerArray<HSPluginSettingsIf::CPropertyMap>& aProperties )
   240     {
   204     {
   241     TSettingItem setting = { KErrNotFound, EApplication , EFalse };
   205     TSettingItem setting = { KErrNotFound, EApplication , EFalse };
   242 
   206 
   243     TSettingType type = SettingTypeL( aProperties );
   207     TSettingType type = SettingTypeL( aProperties );
   244     if ( type == EApplication )
   208     if ( type == EApplication || type == EMailbox )
   245         {
   209         {
   246         setting = iAppList->FindItemL( aProperties );
   210         setting = iAppList->FindItemL( aProperties );
   247         }
   211         }
   248     else if ( type == EBookmark )
   212     else if ( type == EBookmark )
   249         {
   213         {
   305             }
   269             }
   306         }   
   270         }   
   307     
   271     
   308     return EFalse;
   272     return EFalse;
   309     }
   273     }
   310 
       
   311 
   274 
   312 // ---------------------------------------------------------------------------
   275 // ---------------------------------------------------------------------------
   313 // Saves menuitem to HSPS to the given shortcut index
   276 // Saves menuitem to HSPS to the given shortcut index
   314 // ---------------------------------------------------------------------------
   277 // ---------------------------------------------------------------------------
   315 //
   278 //
   344                     properties[ i ]->SetValueL( KProperValueFolder );
   307                     properties[ i ]->SetValueL( KProperValueFolder );
   345                     }
   308                     }
   346                 else if ( type == KMenuTypeSuite )
   309                 else if ( type == KMenuTypeSuite )
   347                     {
   310                     {
   348                     properties[ i ]->SetValueL( KProperValueSuite );
   311                     properties[ i ]->SetValueL( KProperValueSuite );
       
   312                     }
       
   313                 else if( type == KMenuTypeMailbox )
       
   314                     {
       
   315                     properties[ i ]->SetValueL( KProperValueMailbox );
   349                     }
   316                     }
   350                 else
   317                 else
   351                     {
   318                     {
   352                     properties[ i ]->SetValueL( KProperValueAppl );
   319                     properties[ i ]->SetValueL( KProperValueAppl );
   353                     }
   320                     }
   446 
   413 
   447 // ---------------------------------------------------------------------------
   414 // ---------------------------------------------------------------------------
   448 // Updates settings container.
   415 // Updates settings container.
   449 // ---------------------------------------------------------------------------
   416 // ---------------------------------------------------------------------------
   450 //
   417 //
   451 void CMCSPluginSettingsModel::UpdateSettingsContainerL( const TDesC8& aPluginId )
   418 void CMCSPluginSettingsModel::SetPluginIdL( const TDesC8& aPluginId )
   452 {
   419     {
   453     if (iContainer)
   420     delete iPluginId;
   454     {
   421     iPluginId = NULL;
   455         if (iContainer->IsChangeDialogShowing())
   422     iPluginId = aPluginId.AllocL();    
   456         {
   423     }
   457             iContainer->CloseChangeDialog();
       
   458         }
       
   459     }
       
   460 
       
   461     UpdateSettingsL( aPluginId );
       
   462 
       
   463     if (iContainer)
       
   464     {
       
   465         iContainer->ResetCurrentListL(0);
       
   466     }
       
   467 }
       
   468 
   424 
   469 // ---------------------------------------------------------------------------
   425 // ---------------------------------------------------------------------------
   470 // From MDesCArray
   426 // From MDesCArray
   471 // Returns the number of descriptor elements in a descriptor array.
   427 // Returns the number of descriptor elements in a descriptor array.
   472 // ---------------------------------------------------------------------------
   428 // ---------------------------------------------------------------------------
   489         return ret;
   445         return ret;
   490     }
   446     }
   491     if ( iSettings[aIndex].type == EApplication )
   447     if ( iSettings[aIndex].type == EApplication )
   492         {
   448         {
   493         // first, we need to check if the item is missing 
   449         // first, we need to check if the item is missing 
   494         // (application unistaled or mmc card removed)
   450         // (application uninstalled or mmc card removed)
   495         // If it is, we return "Undefined" application name instead
   451         // If it is, we return "Undefined" application name instead
   496         if ( iSettings[ aIndex ].id == KErrNotFound )
   452         if ( iSettings[ aIndex ].id == KErrNotFound )
   497             {
   453             {
   498             const TDesC& caption = iAppList->iUndefinedText->Des();
   454             const TDesC& caption = iAppList->UndefinedText();
   499             TPtrC line; 
   455             TPtrC line; 
   500             TRAP_IGNORE( line.Set( ListBoxLineL( caption, aIndex ) ) )
   456             TRAP_IGNORE( line.Set( ListBoxLineL( caption, aIndex ) ) )
   501             return line; 
   457             return line; 
   502             }
   458             }
   503         else
   459         else
   555                                              TInt aId,
   511                                              TInt aId,
   556                                              TSettingType aType )
   512                                              TSettingType aType )
   557     {
   513     {
   558     if (aSettingIndex >= 0 && aSettingIndex < iSettings.Count())
   514     if (aSettingIndex >= 0 && aSettingIndex < iSettings.Count())
   559         {
   515         {
   560         TSettingItem oldItem = iSettings[ aSettingIndex ];
       
   561         iSettings[ aSettingIndex ].id = aId;
   516         iSettings[ aSettingIndex ].id = aId;
   562         iSettings[ aSettingIndex ].type = aType;
   517         iSettings[ aSettingIndex ].type = aType;
   563 
   518 
   564         if ( aType == EApplication )
   519         if ( aType == EApplication )
   565             {
   520             {
   566             CMenuItem& item = iAppList->ItemL( aId );
   521             CMenuItem* item = iAppList->ItemL( aId );
   567             SaveSettingsL( aSettingIndex, item );
   522             SaveSettingsL( aSettingIndex, *item );
   568             }
   523             }
   569          else
   524          else
   570             {
   525             {
   571             CMenuItem& item = iBkmList->ItemL( aId );
   526             CMenuItem& item = iBkmList->ItemL( aId );
   572             SaveSettingsL( aSettingIndex, item );
   527             SaveSettingsL( aSettingIndex, item );
   573             }
   528             }
   574         
       
   575         // Old setting type is bookmark. Remove bookmark item from MCS 
       
   576         // if it was created in runtime.
       
   577         if ( oldItem.type == EBookmark )
       
   578             {
       
   579                 iBkmList->RemoveMenuItemL( oldItem.id );
       
   580             }
       
   581 
       
   582         // Old setting type is application.
       
   583         // Remove app item from MCS if it was created in runtime (mailbox).
       
   584         if ( oldItem.type == EApplication )
       
   585             {
       
   586                 iAppList->RemoveMenuItemL( oldItem.id );
       
   587             }
       
   588 
       
   589         return ETrue;
   529         return ETrue;
   590         }
   530         }
   591     return EFalse;
   531     return EFalse;
   592     }
   532     }
   593 
   533 
   621 // ---------------------------------------------------------------------------
   561 // ---------------------------------------------------------------------------
   622 // Updates application list
   562 // Updates application list
   623 // ---------------------------------------------------------------------------
   563 // ---------------------------------------------------------------------------
   624 //
   564 //
   625 void CMCSPluginSettingsModel::UpdateAppListL()
   565 void CMCSPluginSettingsModel::UpdateAppListL()
   626 {
   566     {
       
   567     if( !iAppList )
       
   568         {
       
   569         iAppList = CMCSPluginSettingsAppList::NewL();
       
   570         }
   627     iAppList->StartL();
   571     iAppList->StartL();
   628 }
   572     }
   629 
   573 
   630 // ---------------------------------------------------------------------------
   574 // ---------------------------------------------------------------------------
   631 // Updates bookmark list
   575 // Updates bookmark list
   632 // ---------------------------------------------------------------------------
   576 // ---------------------------------------------------------------------------
   633 //
   577 //