idlefw/plugins/shortcutplugin/src/caiscutsettingsapplist.cpp
branchRCL_3
changeset 9 d0529222e3f0
parent 4 1a2a00e78665
child 10 5ef93ea513cb
child 18 bd874ee5e5e2
equal deleted inserted replaced
4:1a2a00e78665 9:d0529222e3f0
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  Application list for settings listbox
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <msvuids.h>        // For KMsvRootIndexEntryIdValue
       
    20 #include <SenduiMtmUids.h>
       
    21 #include <StringLoader.h>
       
    22 
       
    23 #include <aiscutsettingsres.rsg>
       
    24 #include <aiscuttexts.rsg>
       
    25 
       
    26 #include <featmgr.h>
       
    27 #include <centralrepository.h>
       
    28 #include <settingsinternalcrkeys.h>
       
    29 #include <javaregistry.h>
       
    30 #include <javaregistryentry.h>
       
    31 #include <pathinfo.h>
       
    32 
       
    33 #include "caiscutsettingsapplist.h"
       
    34 #include "taiscutparser.h"
       
    35 #include "caiscutsettingsitem.h"
       
    36 #include "aiscutdefs.h"
       
    37 #include <activeidle2domaincrkeys.h>
       
    38 
       
    39 #include "debug.h"
       
    40 
       
    41 using namespace Java;
       
    42 
       
    43 
       
    44 const TInt KDriveAndColon = 2; //drive char and colon string length, e.g. "c:"
       
    45 
       
    46 // ======== MEMBER FUNCTIONS ========
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CAiScutSettingsAppList::CAiScutSettingsAppList(CCoeEnv* aEnv, MAiScutListObserver& aObserver)
       
    53     : CActive(CActive::EPriorityLow)    // Background task priority.
       
    54                                         // Higher priority would block the wait dialog.
       
    55     , iEnv(aEnv)
       
    56     , iObserver(aObserver)
       
    57     {
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 void CAiScutSettingsAppList::ConstructL()
       
    65     {
       
    66     User::LeaveIfError(iApaSession.Connect());
       
    67     iMsvSession = CMsvSession::OpenAsObserverL(*this);
       
    68 
       
    69     CActiveScheduler::Add(this);
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CAiScutSettingsAppList* CAiScutSettingsAppList::NewL(CCoeEnv* aEnv,
       
    77     MAiScutListObserver& aObserver)
       
    78     {
       
    79     CAiScutSettingsAppList* self = new (ELeave) CAiScutSettingsAppList(aEnv, aObserver);
       
    80     CleanupStack::PushL(self);
       
    81     self->ConstructL();
       
    82     CleanupStack::Pop(self);
       
    83     return self;
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 CAiScutSettingsAppList::~CAiScutSettingsAppList()
       
    91     {
       
    92     if (IsActive())
       
    93         {
       
    94         Cancel();
       
    95         }
       
    96 
       
    97     delete iAppNotifier;
       
    98     delete iMsvSession;
       
    99     iApaSession.Close();
       
   100     iListItems.ResetAndDestroy();
       
   101     iMailboxes.Close(); // Do not call ResetAndDestroy() to this.
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------------------------
       
   105 // From MDesCArray
       
   106 // Returns the number of descriptor elements in a descriptor array.
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 TInt CAiScutSettingsAppList::MdcaCount() const
       
   110     {
       
   111     return iListItems.Count();
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // From MDesCArray
       
   116 // Indexes into a descriptor array.
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 TPtrC CAiScutSettingsAppList::MdcaPoint(TInt aIndex) const
       
   120     {
       
   121     if (aIndex < 0 || aIndex >= iListItems.Count())
       
   122         {
       
   123         TPtrC ret(KNullDesC);
       
   124         return ret;
       
   125         }
       
   126     return iListItems[aIndex]->Caption();
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // From class MMsvSessionObserver.
       
   131 // Handles an event from the message server.
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 void CAiScutSettingsAppList::HandleSessionEventL(
       
   135     TMsvSessionEvent aEvent, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
   136     {
       
   137     TBool updated = ETrue;
       
   138     TBool added   = EFalse;
       
   139 
       
   140     switch (aEvent)
       
   141         {
       
   142     case EMsvEntriesCreated:
       
   143     case EMsvEntriesDeleted:
       
   144     case EMsvEntriesChanged:
       
   145         if (iObserving)
       
   146             {
       
   147             CMsvEntry* rootEntry = GetRootEntryL();
       
   148             
       
   149             CleanupStack::PushL(rootEntry);
       
   150             TBuf<255> mailboxId;
       
   151             
       
   152             // Reset iMailboxes
       
   153             for (TInt j = iMailboxes.Count() - 1; j >= 0; --j)
       
   154             {            
       
   155               RemoveMailboxL(iMailboxes[j]->Params());
       
   156             }
       
   157 
       
   158       // Add all mailboxes
       
   159       for (TInt i = rootEntry->Count() - 1; i >= 0; --i)
       
   160                 {
       
   161                     const TMsvEntry& tentry = (*rootEntry)[i];
       
   162 
       
   163               if (tentry.iMtm == KSenduiMtmImap4Uid || tentry.iMtm == KSenduiMtmPop3Uid)
       
   164                 {   
       
   165                   mailboxId.Num(tentry.Id());       
       
   166                         AddMailboxL(tentry.iDetails, mailboxId);
       
   167                     }                      
       
   168               }      
       
   169               
       
   170             CleanupStack::PopAndDestroy(rootEntry);
       
   171             }
       
   172 
       
   173         if (updated)
       
   174             {
       
   175             iObserver.HandleScutListEventL(MAiScutListObserver::EAppListUpdated, added);
       
   176             }
       
   177         break;
       
   178 
       
   179     default:
       
   180         break;
       
   181         }
       
   182     }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // From class MApaAppListServObserver.
       
   186 // Handles a change in the application list.
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 void CAiScutSettingsAppList::HandleAppListEvent(TInt /*aEvent*/)
       
   190     {
       
   191     TRAP_IGNORE(UpdateAppListL());
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // Starts the asynchronous application list initialization.
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 void CAiScutSettingsAppList::StartL()
       
   199     {
       
   200     iListItems.ResetAndDestroy();
       
   201 
       
   202     AddStaticItemsL();
       
   203     AddMailboxesL();
       
   204     AddExtraItemsFromCRL();
       
   205 
       
   206     if (iApaSession.GetAllApps() == KErrNone &&
       
   207         iApaSession.AppCount(iTotalAppCount) == KErrNone)
       
   208         {
       
   209         CompleteSelf();
       
   210         }
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // Checks if the application list is ready to be shown.
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 TBool CAiScutSettingsAppList::IsReady() const
       
   218     {
       
   219     return iReady;
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // Tells the application list to start or stop observing for changes.
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CAiScutSettingsAppList::SetObservingL(TBool aObserving)
       
   227     {
       
   228     delete iAppNotifier;
       
   229     iAppNotifier = NULL;
       
   230 
       
   231     if (aObserving)
       
   232         {
       
   233         UpdateAppListL();
       
   234 
       
   235         iAppNotifier = CApaAppListNotifier::NewL(this, CActive::EPriorityStandard);
       
   236         }
       
   237 
       
   238     iObserving = aObserving;
       
   239     }
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 // Finds the index of the given settings item in the application list.
       
   243 // ---------------------------------------------------------------------------
       
   244 //
       
   245 TInt CAiScutSettingsAppList::FindIndex(CAiScutSettingsItem& aItem)
       
   246     {
       
   247     TInt index = KErrNotFound;
       
   248 
       
   249     TAiScutParser parser;
       
   250     parser.Parse(aItem.Value());
       
   251     TPtrC params(parser.Get(EScutDefParamNameAndValue));
       
   252 
       
   253     TUid uid = aItem.Uid();
       
   254     for (TInt i = iListItems.Count() - 1; i >= 0; --i)
       
   255         {
       
   256         CAppListItem* item = iListItems[i];
       
   257         if ( (item->Uid() == uid) && params.Compare(item->Params()) == 0)
       
   258         {
       
   259             index = i;
       
   260             break;
       
   261         }
       
   262         // Url => compare the whole url not just the parameters
       
   263         else if( item->Type() == EAiScutSettingTypeUrl )
       
   264             {
       
   265             if ( parser.Get(EScutDefComplete).Compare(item->Params()) == 0 )
       
   266                 {
       
   267                 index = i;
       
   268                 break;
       
   269                 }
       
   270             }
       
   271         }
       
   272 
       
   273     return index;
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------------------------
       
   277 // Returns target application data from the given index.
       
   278 // ---------------------------------------------------------------------------
       
   279 //
       
   280 TInt CAiScutSettingsAppList::GetDataByIndex(TInt aIndex, TUid& aUid,
       
   281     TPtrC& aParams, TPtrC& aCaption, TAiScutSettingType& aType ) const
       
   282     {
       
   283     if (aIndex >= 0 && aIndex < iListItems.Count())
       
   284         {
       
   285         CAppListItem* item = iListItems[aIndex];
       
   286         aUid = item->Uid();
       
   287         aType = item->Type();
       
   288         aParams.Set(item->Params());
       
   289         aCaption.Set(item->Caption());
       
   290         return KErrNone;
       
   291         }
       
   292 
       
   293     return KErrNotFound;
       
   294     }
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 // From CActive
       
   298 // Implements cancellation of an outstanding request.
       
   299 // ---------------------------------------------------------------------------
       
   300 //
       
   301 void CAiScutSettingsAppList::DoCancel()
       
   302     {
       
   303     }
       
   304 
       
   305 // ---------------------------------------------------------------------------
       
   306 // From CActive
       
   307 // Performs one step of the app list initialization.
       
   308 // ---------------------------------------------------------------------------
       
   309 //
       
   310 void CAiScutSettingsAppList::RunL()
       
   311     {
       
   312     TApaAppInfo appInfo;
       
   313     TInt err = GetNextValidApp(appInfo);
       
   314 
       
   315     switch (err)
       
   316         {
       
   317     case KErrNone:
       
   318         AddApplicationL(appInfo);
       
   319         CompleteSelf();
       
   320         break;
       
   321 
       
   322     case RApaLsSession::ENoMoreAppsInList:
       
   323         iReady = ETrue;
       
   324         iObserver.HandleScutListEventL(MAiScutListObserver::EAppListReady, EFalse);
       
   325         break;
       
   326 
       
   327     //Indicates that an RApaLsSession member function was called before the session's 
       
   328     //  application list is fully populated. 
       
   329     case RApaLsSession::EAppListInvalid:
       
   330         StartL(); // Just try again.
       
   331         break;
       
   332 
       
   333     default:
       
   334         User::LeaveIfError(err);
       
   335         break;
       
   336         }
       
   337     }
       
   338 
       
   339 // ---------------------------------------------------------------------------
       
   340 // From CActive
       
   341 // Handles an error situation.
       
   342 // ---------------------------------------------------------------------------
       
   343 //
       
   344 TInt CAiScutSettingsAppList::RunError(TInt aError)
       
   345     {
       
   346     return aError;
       
   347     }
       
   348 
       
   349 // ---------------------------------------------------------------------------
       
   350 // Completes own request status to make sure active scheduler calls RunL again.
       
   351 // ---------------------------------------------------------------------------
       
   352 //
       
   353 void CAiScutSettingsAppList::CompleteSelf()
       
   354     {
       
   355     if (!IsActive())
       
   356         {
       
   357         TRequestStatus* status = &iStatus;
       
   358         User::RequestComplete(status, KErrNone);
       
   359         SetActive();
       
   360         }
       
   361     }
       
   362 
       
   363 // ---------------------------------------------------------------------------
       
   364 // Adds an application to the list.
       
   365 // ---------------------------------------------------------------------------
       
   366 //
       
   367 void CAiScutSettingsAppList::AddApplicationL(TApaAppInfo& aAppInfo)
       
   368     {
       
   369     TBool allowed = ETrue;
       
   370 
       
   371     // EasyVoIP is only added when VoIP is supported
       
   372     if (aAppInfo.iUid == KScutEasyVoIPApplicationUid)
       
   373         {
       
   374         // Check VoIP variation status
       
   375         TInt voipStatus = 0;
       
   376         // For checking VoIP variation status
       
   377         CRepository* repository = CRepository::NewL(KCRUidTelephonySettings);
       
   378         repository->Get(KDynamicVoIP, voipStatus);
       
   379         delete repository;
       
   380         allowed = (voipStatus && FeatureManager::FeatureSupported(KFeatureIdCommonVoip));
       
   381 
       
   382         __PRINTS( "XAI: CAiScutSettingsAppList::AddApplicationL");
       
   383         __PRINT( __DBG_FORMAT( "XAI:   voipStatus = %d, allowed = %d"), voipStatus, allowed);
       
   384         }
       
   385 
       
   386     // VoIP launcher is always invisible in shortcuts.
       
   387     if (aAppInfo.iUid == KScutVoIPLauncherUid)
       
   388         {
       
   389         allowed = EFalse;
       
   390         }
       
   391 
       
   392     if (iObserver.IsHidden(aAppInfo.iUid))
       
   393         {
       
   394         allowed = EFalse;
       
   395         }
       
   396 
       
   397     if (allowed)
       
   398         {
       
   399         CAppListItem* listItem = CAppListItem::NewLC(aAppInfo.iUid, aAppInfo.iCaption);
       
   400         listItem->SetType( EAiScutSettingTypeApplication );
       
   401         TLinearOrder<CAppListItem> sortMethod(CAppListItem::CompareCaption);
       
   402         User::LeaveIfError(iListItems.InsertInOrderAllowRepeats(listItem, sortMethod));
       
   403         CleanupStack::Pop(listItem);
       
   404         }
       
   405     }
       
   406 
       
   407 // ---------------------------------------------------------------------------
       
   408 // Adds the static list items to the application list.
       
   409 // ---------------------------------------------------------------------------
       
   410 //
       
   411 void CAiScutSettingsAppList::AddStaticItemsL()
       
   412     {
       
   413     HBufC* caption = NULL;
       
   414     CAppListItem* listItem = NULL;
       
   415     TLinearOrder<CAppListItem> sortMethod(CAppListItem::CompareCaption);
       
   416 
       
   417     // Connectivity Status item
       
   418     caption = StringLoader::LoadLC(R_SCUT_SETTINGS_CONNECTIVITY_STATUS, iEnv);
       
   419     listItem = CAppListItem::NewLC(KScutGeneralSettingsUid, *caption);
       
   420     listItem->SetParamsL(KScutParamConnectivityView);
       
   421     listItem->SetType( EAiScutSettingTypeApplication );
       
   422     User::LeaveIfError(iListItems.InsertInOrderAllowRepeats(listItem, sortMethod));
       
   423     CleanupStack::Pop(listItem);
       
   424     CleanupStack::PopAndDestroy(caption);
       
   425     caption = NULL;
       
   426     listItem = NULL;
       
   427 
       
   428     // New Message item.
       
   429     caption = StringLoader::LoadLC(R_SCUT_SETTINGS_NEW_MSG, iEnv);
       
   430     listItem = CAppListItem::NewLC(KScutMessagingUid, *caption);
       
   431     listItem->SetParamsL(KScutParamNewMsg);
       
   432     listItem->SetType( EAiScutSettingTypeApplication );
       
   433     User::LeaveIfError(iListItems.InsertInOrderAllowRepeats(listItem, sortMethod));
       
   434     CleanupStack::Pop(listItem);
       
   435     CleanupStack::PopAndDestroy(caption);
       
   436     caption = NULL;
       
   437     listItem = NULL;
       
   438 
       
   439     // New Email item.
       
   440     caption = StringLoader::LoadLC(R_SCUT_SETTINGS_NEW_EMAIL, iEnv);
       
   441     listItem = CAppListItem::NewLC(KScutMessagingUid, *caption);
       
   442     listItem->SetParamsL(KScutParamNewEmail);
       
   443     listItem->SetType( EAiScutSettingTypeApplication );
       
   444     User::LeaveIfError(iListItems.InsertInOrderAllowRepeats(listItem, sortMethod));
       
   445     CleanupStack::Pop(listItem);
       
   446     CleanupStack::PopAndDestroy(caption);
       
   447     caption = NULL;
       
   448     listItem = NULL;
       
   449 
       
   450 #ifdef __SYNCML_DS_EMAIL
       
   451     // New SyncML mail item.
       
   452     caption = StringLoader::LoadLC(R_SCUT_SETTINGS_NEW_SYNCML_MAIL, iEnv);
       
   453     listItem = CAppListItem::NewLC(KScutMessagingUid, *caption);
       
   454     listItem->SetParamsL(KScutParamNewSyncMLMail);
       
   455     listItem->SetType( EAiScutSettingTypeApplication );
       
   456     User::LeaveIfError(iListItems.InsertInOrderAllowRepeats(listItem, sortMethod));
       
   457     CleanupStack::Pop(listItem);
       
   458     CleanupStack::PopAndDestroy(caption);
       
   459     caption = NULL;
       
   460     listItem = NULL;
       
   461 #endif
       
   462 
       
   463     if (FeatureManager::FeatureSupported(KFeatureIdMmsPostcard)
       
   464         && IsInRom( KScutPostcardEditorUid ) )
       
   465         {
       
   466         // New Postcard item.
       
   467         caption = StringLoader::LoadLC(R_SCUT_SETTINGS_NEW_POSTCARD, iEnv);
       
   468         listItem = CAppListItem::NewLC(KScutMessagingUid, *caption);
       
   469         listItem->SetParamsL(KScutParamNewPostcard);
       
   470         listItem->SetType( EAiScutSettingTypeApplication );
       
   471         User::LeaveIfError(iListItems.InsertInOrderAllowRepeats(listItem, sortMethod));
       
   472         CleanupStack::Pop(listItem);
       
   473         CleanupStack::PopAndDestroy(caption);
       
   474         caption = NULL;
       
   475         listItem = NULL;
       
   476         }
       
   477 
       
   478     if (FeatureManager::FeatureSupported(KFeatureIdAudioMessaging))
       
   479         {
       
   480         // New Audio Message item.
       
   481         caption = StringLoader::LoadLC(R_SCUT_SETTINGS_NEW_AUDIO_MSG, iEnv);
       
   482         listItem = CAppListItem::NewLC(KScutMessagingUid, *caption);
       
   483         listItem->SetParamsL(KScutParamNewAudioMsg);
       
   484         listItem->SetType( EAiScutSettingTypeApplication );
       
   485         User::LeaveIfError(iListItems.InsertInOrderAllowRepeats(listItem, sortMethod));
       
   486         CleanupStack::Pop(listItem);
       
   487         CleanupStack::PopAndDestroy(caption);
       
   488         caption = NULL;
       
   489         listItem = NULL;
       
   490         }
       
   491 
       
   492     // Select Message type item.
       
   493     caption = StringLoader::LoadLC(R_SCUT_SETTINGS_SELECT_MSG_TYPE, iEnv);
       
   494     listItem = CAppListItem::NewLC(KScutMessagingUid, *caption);
       
   495     listItem->SetParamsL(KScutParamSelectMsgType);
       
   496     listItem->SetType( EAiScutSettingTypeApplication );
       
   497     User::LeaveIfError(iListItems.InsertInOrderAllowRepeats(listItem, sortMethod));
       
   498     CleanupStack::Pop(listItem);
       
   499     CleanupStack::PopAndDestroy(caption);
       
   500     caption = NULL;
       
   501     listItem = NULL;
       
   502     // Installation view.
       
   503     caption = StringLoader::LoadLC(R_SCUT_SETTINGS_APPMNGR, iEnv); 
       
   504     listItem = CAppListItem::NewLC(KScutGeneralSettingsUid, *caption);
       
   505     listItem->SetParamsL(KScutParamInstallationsView);
       
   506     listItem->SetType( EAiScutSettingTypeApplication );
       
   507     User::LeaveIfError(iListItems.InsertInOrderAllowRepeats(listItem, sortMethod));
       
   508     CleanupStack::Pop(listItem);
       
   509     CleanupStack::PopAndDestroy(caption);
       
   510     caption = NULL;
       
   511     listItem = NULL;
       
   512     }
       
   513 
       
   514 // ---------------------------------------------------------------------------
       
   515 // Adds extra list items to the application list.
       
   516 // ---------------------------------------------------------------------------
       
   517 //
       
   518 void CAiScutSettingsAppList::AddExtraItemsL()
       
   519     {
       
   520     // No Effect item.
       
   521     HBufC* caption = StringLoader::LoadLC(R_SCUT_SETTINGS_NO_EFFECT, iEnv);
       
   522     CAppListItem* listItem = CAppListItem::NewLC(KScutSettingsDllUid, *caption);
       
   523     listItem->SetParamsL(KScutParamNoEffect);
       
   524     listItem->SetType( EAiScutSettingTypeApplication );
       
   525     User::LeaveIfError(iListItems.Insert(listItem, 0)); // insert as first item.
       
   526     CleanupStack::Pop(listItem);
       
   527     CleanupStack::PopAndDestroy(caption);
       
   528     }
       
   529 
       
   530 void CAiScutSettingsAppList::AddExtraItemsFromCRL()
       
   531     {
       
   532     CRepository *cr = CRepository::NewL( TUid::Uid( KCRUidActiveIdleLV ) );        
       
   533     User::LeaveIfNull( cr );
       
   534     
       
   535     CleanupStack::PushL( cr );
       
   536     
       
   537     TUint32 crKey = KAIExtraShortcutsKeyRangeStart;
       
   538     TBool moreSettings = ETrue;
       
   539     TInt err = KErrNone;
       
   540     TAiScutParser parser;
       
   541     
       
   542     HBufC* settingValue = HBufC::NewLC(NCentralRepositoryConstants::KMaxUnicodeStringLength);
       
   543     TPtr settingValuePtr = settingValue->Des();
       
   544     
       
   545     while( moreSettings )
       
   546         {
       
   547         err = cr->Get( crKey++, settingValuePtr ); 
       
   548         if ( err == KErrNone && settingValue->Length() > 0 )
       
   549             {
       
   550             CAppListItem* listItem = NULL;
       
   551             parser.Parse( *settingValue );
       
   552             
       
   553             // First try to find the custom title
       
   554             HBufC* caption = HBufC::NewLC( settingValue->Length() );
       
   555             TPtr captionPtr = caption->Des();
       
   556             TInt err = parser.CustomTitle( captionPtr );    
       
   557             TUid appUid = parser.Uid();
       
   558                 
       
   559             if ( err != KErrNone || caption->Length() <= 0 )
       
   560                 {
       
   561                 CleanupStack::PopAndDestroy( caption );
       
   562                 caption = NULL;
       
   563                 }
       
   564             
       
   565             if ( !caption )
       
   566                 {
       
   567                 // Web address...
       
   568                  if ( parser.Type() == EScutWebAddress || parser.Type() == EScutUnknown )
       
   569                      {
       
   570                      TUriParser parser;
       
   571                      TInt err = parser.Parse(*settingValue);
       
   572 
       
   573                      if (err == KErrNone)
       
   574                          {
       
   575                          // Remove scheme from the url.
       
   576                          caption = parser.Extract(EUriHost).AllocLC();
       
   577                          }
       
   578                      else
       
   579                          {
       
   580                          caption = settingValue->AllocLC();
       
   581                          }
       
   582                      }
       
   583                  //  ...application. Nothing else supported at the moment
       
   584                  else
       
   585                      {
       
   586                      TApaAppInfo appInfo;
       
   587                      err = iApaSession.GetAppInfo(appInfo, appUid);
       
   588                      if (err == KErrNone)
       
   589                          {
       
   590                          caption = appInfo.iCaption.AllocLC();
       
   591                          }
       
   592                      }
       
   593                 }
       
   594             if ( caption )
       
   595                 {
       
   596                 listItem = CAppListItem::NewLC( KNullUid , *caption  );
       
   597                 listItem->SetParamsL( *settingValue );
       
   598                 listItem->SetType( EAiScutSettingTypeUrl );
       
   599                 TLinearOrder<CAppListItem> sortMethod(CAppListItem::CompareCaption);
       
   600                 User::LeaveIfError(iListItems.InsertInOrderAllowRepeats(listItem, sortMethod));
       
   601                 CleanupStack::Pop( listItem );
       
   602                 CleanupStack::PopAndDestroy( caption );
       
   603                 }
       
   604             }
       
   605         else
       
   606             {
       
   607             moreSettings = EFalse;
       
   608             }
       
   609         }
       
   610     
       
   611 
       
   612     
       
   613     CleanupStack::PopAndDestroy( settingValue );
       
   614     CleanupStack::PopAndDestroy( cr );
       
   615     }
       
   616 // ---------------------------------------------------------------------------
       
   617 // Removes extra list items from the application list.
       
   618 // ---------------------------------------------------------------------------
       
   619 //
       
   620 void CAiScutSettingsAppList::RemoveExtraItemsL()
       
   621     {
       
   622     // No Effect item.
       
   623     CAppListItem* listItem = iListItems[0];
       
   624     iListItems.Remove(0);
       
   625     if (listItem)
       
   626         {
       
   627         delete listItem;
       
   628         listItem = NULL;      
       
   629         }
       
   630     }
       
   631 
       
   632 // ---------------------------------------------------------------------------
       
   633 // Returns the root entry containing mailboxes.
       
   634 // ---------------------------------------------------------------------------
       
   635 //
       
   636 CMsvEntry* CAiScutSettingsAppList::GetRootEntryL()
       
   637     {
       
   638     return iMsvSession->GetEntryL(KMsvRootIndexEntryIdValue);
       
   639     }
       
   640 
       
   641 // ---------------------------------------------------------------------------
       
   642 // Adds remote mailboxes to the application list.
       
   643 // ---------------------------------------------------------------------------
       
   644 //
       
   645 void CAiScutSettingsAppList::AddMailboxesL()
       
   646     {
       
   647     CMsvEntry* rootEntry = GetRootEntryL();
       
   648 
       
   649     CleanupStack::PushL(rootEntry);
       
   650     TBuf<255> mailboxId;
       
   651 
       
   652     for (TInt i = rootEntry->Count() - 1; i >= 0; --i)
       
   653         {
       
   654         const TMsvEntry& tentry = (*rootEntry)[i];
       
   655 
       
   656         if (tentry.iMtm == KSenduiMtmImap4Uid || tentry.iMtm == KSenduiMtmPop3Uid)
       
   657             {
       
   658             mailboxId.Num(tentry.Id());
       
   659             AddMailboxL(tentry.iDetails, mailboxId);
       
   660             }
       
   661         }
       
   662 
       
   663     CleanupStack::PopAndDestroy(rootEntry);
       
   664     }
       
   665 
       
   666 // ---------------------------------------------------------------------------
       
   667 // Adds a mailbox to the list.
       
   668 // ---------------------------------------------------------------------------
       
   669 //
       
   670 void CAiScutSettingsAppList::AddMailboxL(const TDesC& aMailbox, const TDesC& aMailboxId)
       
   671 {
       
   672     CAppListItem* listItem = CAppListItem::NewLC(KScutMessagingUid, aMailbox);
       
   673 
       
   674   // Insert params containing mailbox id
       
   675     HBufC* params = HBufC::NewLC(KScutParamMailbox().Length() + aMailboxId.Length());
       
   676     params->Des().Copy(KScutParamMailbox);
       
   677     params->Des().Append(aMailboxId);
       
   678     listItem->SetParamsL(*params);
       
   679     listItem->SetType( EAiScutSettingTypeApplication );
       
   680     CleanupStack::PopAndDestroy(params);
       
   681 
       
   682     TLinearOrder<CAppListItem> sortMethod(CAppListItem::CompareCaption);
       
   683     User::LeaveIfError(iListItems.InsertInOrderAllowRepeats(listItem, sortMethod));
       
   684     CleanupStack::Pop(listItem);
       
   685     User::LeaveIfError(iMailboxes.Append(listItem));
       
   686     listItem = NULL;
       
   687 }
       
   688 
       
   689 // ---------------------------------------------------------------------------
       
   690 // Removes a mailbox from the list.
       
   691 // ---------------------------------------------------------------------------
       
   692 //
       
   693 void CAiScutSettingsAppList::RemoveMailboxL(const TDesC& aMailboxParam)
       
   694     {
       
   695     for (TInt i = iListItems.Count() - 1; i >= 0; --i)
       
   696         {
       
   697         CAppListItem* listItem = iListItems[i];
       
   698         if (aMailboxParam.Compare(listItem->Params()) == 0)
       
   699             {
       
   700             // Also remove the mailbox from the mailbox array
       
   701             for (TInt j = iMailboxes.Count() - 1; j >= 0; --j)
       
   702                 {
       
   703                 if (aMailboxParam.Compare(iMailboxes[j]->Params()) == 0)
       
   704                     {
       
   705                     iMailboxes.Remove(j);
       
   706                     }
       
   707                 }
       
   708 
       
   709             iListItems.Remove(i);
       
   710             delete listItem;
       
   711             listItem = NULL;
       
   712 
       
   713             break;
       
   714             }
       
   715         }
       
   716     }
       
   717 
       
   718 // ---------------------------------------------------------------------------
       
   719 // Gets the next valid application from application architecture server.
       
   720 // ---------------------------------------------------------------------------
       
   721 //
       
   722 TInt CAiScutSettingsAppList::GetNextValidApp(TApaAppInfo& aAppInfo)
       
   723     {
       
   724     TInt err = KErrNone;
       
   725     TBool validAppFound = EFalse;
       
   726 
       
   727     while (!validAppFound)
       
   728         {
       
   729         TApaAppInfo appInfo;
       
   730         err = iApaSession.GetNextApp(appInfo);
       
   731         if (err == KErrNone)
       
   732             {
       
   733             TApaAppCapabilityBuf capBuf;
       
   734             TApaAppCapability cap;
       
   735 
       
   736             if ((iApaSession.GetAppCapability(capBuf, appInfo.iUid) == KErrNone))
       
   737                 {
       
   738                 cap = capBuf();
       
   739 
       
   740                 TInt screenNumber(0);
       
   741                 err = iApaSession.GetDefaultScreenNumber( screenNumber, appInfo.iUid );
       
   742 
       
   743                 if ((err == KErrNone) && (cap.iAppIsHidden == EFalse) && (screenNumber == 0)) 
       
   744                     {
       
   745                     aAppInfo = appInfo;
       
   746                     validAppFound = ETrue;
       
   747                     }
       
   748                 }
       
   749             }
       
   750         else
       
   751             {
       
   752             return err;
       
   753             }
       
   754         }
       
   755 
       
   756     return err;
       
   757     }
       
   758 
       
   759 // ---------------------------------------------------------------------------
       
   760 // Updates the application list.
       
   761 // ---------------------------------------------------------------------------
       
   762 //
       
   763 void CAiScutSettingsAppList::UpdateAppListL()
       
   764     {
       
   765     TBool updated = EFalse;
       
   766     TBool added   = EFalse;
       
   767 
       
   768     TInt totalAppCount = 0;
       
   769 
       
   770     if (iApaSession.AppCount(totalAppCount) == KErrNone)
       
   771         {
       
   772         if (totalAppCount < iTotalAppCount)
       
   773             {
       
   774             RemoveUninstalledAppFromListL(iTotalAppCount - totalAppCount);
       
   775             updated = ETrue;
       
   776             added = EFalse;
       
   777             }
       
   778         else if (totalAppCount > iTotalAppCount)
       
   779             {
       
   780             AddInstalledAppToListL(totalAppCount - iTotalAppCount);
       
   781             updated = ETrue;
       
   782             added = ETrue;
       
   783             }
       
   784 
       
   785         iTotalAppCount = totalAppCount;
       
   786         }
       
   787 
       
   788     if (updated)
       
   789         {
       
   790         iObserver.HandleScutListEventL(MAiScutListObserver::EAppListUpdated, added);
       
   791         }
       
   792     }
       
   793 
       
   794 // ---------------------------------------------------------------------------
       
   795 // Figures out which application is missing from the list and adds it.
       
   796 // ---------------------------------------------------------------------------
       
   797 //
       
   798 void CAiScutSettingsAppList::AddInstalledAppToListL(TInt aCount)
       
   799     {
       
   800     TInt added = 0;
       
   801     TApaAppInfo appInfo;
       
   802     TInt err = GetNextValidApp(appInfo);
       
   803 
       
   804     while (err == KErrNone)
       
   805         {
       
   806         TBool found = EFalse;
       
   807 
       
   808         for (TInt i = iListItems.Count() - 1; i >= 0; --i)
       
   809             {
       
   810             if (iListItems[i]->Uid() == appInfo.iUid)
       
   811                 {
       
   812                 found = ETrue;
       
   813                 break;
       
   814                 }
       
   815             }
       
   816 
       
   817         if (!found)
       
   818             {
       
   819             AddApplicationL(appInfo);
       
   820             if (++added == aCount)
       
   821                 {
       
   822                 // Found all of them, no need to go further
       
   823                 return ;
       
   824                 }
       
   825             }
       
   826 
       
   827         err = GetNextValidApp(appInfo);
       
   828         }
       
   829 
       
   830     // create registry 
       
   831     CJavaRegistry* registry = CJavaRegistry::NewLC();
       
   832 
       
   833     // get all uids stored in registry
       
   834     RArray<TUid> uids;
       
   835     registry->GetRegistryEntryUidsL( uids );
       
   836 
       
   837     CleanupClosePushL(uids);
       
   838 
       
   839     for (TInt javaIndex = 0; javaIndex < uids.Count(); ++javaIndex)
       
   840         {
       
   841         TInt found = EFalse;
       
   842         for (TInt listIndex = 0; listIndex < iListItems.Count(); ++listIndex )
       
   843             {
       
   844             if (iListItems[listIndex]->Uid() == uids[javaIndex])
       
   845                 {
       
   846                 found = ETrue;
       
   847                 }
       
   848             }
       
   849         if (!found)
       
   850             {
       
   851             // get registry entry by uid (i.e. the first entry)
       
   852             CJavaRegistryEntry* entry =
       
   853                 registry->RegistryEntryL( uids[javaIndex] );
       
   854             if( entry )
       
   855                 {
       
   856                 CleanupStack::PushL(entry);
       
   857 
       
   858                 // get entry properties (i.e. name)
       
   859                 const TDesC& name = entry->Name();
       
   860                 TUid uid = entry->Uid();
       
   861 
       
   862                     CAppListItem* listItem = CAppListItem::NewLC(uid, name);
       
   863                   listItem->SetType( EAiScutSettingTypeApplication );
       
   864                 TLinearOrder<CAppListItem> sortMethod(CAppListItem::CompareCaption);
       
   865                 if (entry->Type() >= EGeneralApplication)
       
   866                     {
       
   867                     User::LeaveIfError(iListItems.InsertInOrderAllowRepeats(listItem, sortMethod));
       
   868                     ++added;
       
   869                     }
       
   870                 else
       
   871                     {
       
   872                     delete listItem;
       
   873                     }
       
   874                 CleanupStack::Pop(listItem);
       
   875 
       
   876                 CleanupStack::PopAndDestroy(entry);
       
   877                 }
       
   878             if (added == aCount)
       
   879                 {
       
   880                 break;
       
   881                 }
       
   882             }
       
   883         }
       
   884     CleanupStack::PopAndDestroy(); // uids
       
   885     CleanupStack::PopAndDestroy(registry);
       
   886     }
       
   887 
       
   888 // ---------------------------------------------------------------------------
       
   889 // Figures out which application should not be in the list and removes it.
       
   890 // ---------------------------------------------------------------------------
       
   891 //
       
   892 void CAiScutSettingsAppList::RemoveUninstalledAppFromListL(TInt aCount)
       
   893     {
       
   894     TInt removed = 0;
       
   895 
       
   896     for (TInt i = iListItems.Count() - 1; i >= 0; --i)
       
   897         {
       
   898         CAppListItem* listItem = iListItems[i];
       
   899         TApaAppInfo ignored;
       
   900         if (iApaSession.GetAppInfo(ignored, listItem->Uid()) == KErrNotFound)
       
   901             {
       
   902             iListItems.Remove(i);
       
   903             delete listItem;
       
   904             listItem = NULL;
       
   905 
       
   906             if (++removed == aCount)
       
   907                 {
       
   908                 return ;
       
   909                 }
       
   910             }
       
   911         }
       
   912     // create registry 
       
   913     CJavaRegistry* registry = CJavaRegistry::NewLC();
       
   914     // get all uids stored in registry
       
   915     RArray<TUid> uids;
       
   916     registry->GetRegistryEntryUidsL( uids );
       
   917 
       
   918     CleanupClosePushL(uids);
       
   919 
       
   920     for (TInt listIndex = iListItems.Count(); listIndex >= 0 ; --listIndex )
       
   921         {
       
   922         TInt found = EFalse;
       
   923         for (TInt javaIndex = 0; javaIndex < uids.Count(); ++javaIndex)
       
   924             {
       
   925             if (iListItems[listIndex]->Uid() == uids[javaIndex])
       
   926                 {
       
   927                 found = ETrue;
       
   928                 }
       
   929             }
       
   930         if (!found)
       
   931             {
       
   932             // Item removed, remove from item list
       
   933             CAppListItem* listItem = iListItems[listIndex];
       
   934             iListItems.Remove(listIndex);
       
   935             delete listItem;
       
   936             if (++removed == aCount)
       
   937                 {
       
   938                 break;
       
   939                 }
       
   940             }
       
   941         }
       
   942     CleanupStack::PopAndDestroy(); // uids
       
   943     CleanupStack::PopAndDestroy(registry);
       
   944     }
       
   945 
       
   946 TBool CAiScutSettingsAppList::IsNonNative(const TUid& aUid)
       
   947     {
       
   948     TBool ret = EFalse;
       
   949 
       
   950     const TUid KMidletAppType = { 0x10210E26 };
       
   951     TUid typeuid = KNullUid;
       
   952 
       
   953     if (KErrNone == iApaSession.GetAppType(typeuid, aUid))
       
   954         {
       
   955         if (typeuid == KMidletAppType)
       
   956             {
       
   957             ret = ETrue;
       
   958             }
       
   959         }
       
   960 
       
   961     return ret;
       
   962     }
       
   963 
       
   964 
       
   965 TBool CAiScutSettingsAppList::IsInRom( const TUid& aUid )
       
   966     {
       
   967     TBool inROM = EFalse;
       
   968 
       
   969     TApaAppInfo appInfo;    
       
   970     if( iApaSession.GetAppInfo( appInfo, aUid ) == KErrNone )
       
   971         {
       
   972         // Does the full path start with z: 
       
   973         if( appInfo.iFullName.FindC( 
       
   974                 PathInfo::RomRootPath().Left( KDriveAndColon ) ) >= 0 )            
       
   975             {          
       
   976             inROM = ETrue;                     
       
   977             }
       
   978         }
       
   979     return inROM;
       
   980     }
       
   981 
       
   982 
       
   983 // ---------------------------------------------------------------------------
       
   984 // Nested class to store individual application list items
       
   985 // ---------------------------------------------------------------------------
       
   986 //
       
   987 CAiScutSettingsAppList::CAppListItem::CAppListItem(TUid aUid) : iUid(aUid)
       
   988     {
       
   989     }
       
   990 
       
   991 // ---------------------------------------------------------------------------
       
   992 //
       
   993 // ---------------------------------------------------------------------------
       
   994 //
       
   995 void CAiScutSettingsAppList::CAppListItem::ConstructL(const TDesC& aCaption)
       
   996     {
       
   997     iCaption = aCaption.AllocL();
       
   998     // Defaults to application
       
   999     iType = EAiScutSettingTypeApplication;
       
  1000     }
       
  1001 
       
  1002 // ---------------------------------------------------------------------------
       
  1003 //
       
  1004 // ---------------------------------------------------------------------------
       
  1005 //
       
  1006 CAiScutSettingsAppList::CAppListItem* CAiScutSettingsAppList::CAppListItem::NewLC(
       
  1007     TUid aUid, const TDesC& aCaption)
       
  1008     {
       
  1009     CAppListItem* self = new (ELeave) CAppListItem(aUid);
       
  1010     CleanupStack::PushL(self);
       
  1011     self->ConstructL(aCaption);
       
  1012     return self;
       
  1013     }
       
  1014 
       
  1015 // ---------------------------------------------------------------------------
       
  1016 //
       
  1017 // ---------------------------------------------------------------------------
       
  1018 //
       
  1019 CAiScutSettingsAppList::CAppListItem::~CAppListItem()
       
  1020     {
       
  1021     delete iCaption;
       
  1022     delete iParams;
       
  1023     }
       
  1024 
       
  1025 // ---------------------------------------------------------------------------
       
  1026 // Compare method used to add the items to the list in sorted order.
       
  1027 // ---------------------------------------------------------------------------
       
  1028 //
       
  1029 TInt CAiScutSettingsAppList::CAppListItem::CompareCaption(const CAppListItem& aFirst,
       
  1030     const CAppListItem& aSecond)
       
  1031     {
       
  1032     return aFirst.iCaption->Des().CompareC(*aSecond.iCaption);
       
  1033     }
       
  1034 
       
  1035 // ---------------------------------------------------------------------------
       
  1036 // Returns the item target application uid.
       
  1037 // ---------------------------------------------------------------------------
       
  1038 //
       
  1039 TUid CAiScutSettingsAppList::CAppListItem::Uid() const
       
  1040     {
       
  1041     return iUid;
       
  1042     }
       
  1043 
       
  1044 // ---------------------------------------------------------------------------
       
  1045 // Returns the item target application caption.
       
  1046 // ---------------------------------------------------------------------------
       
  1047 //
       
  1048 TPtrC CAiScutSettingsAppList::CAppListItem::Caption() const
       
  1049     {
       
  1050     return TPtrC(*iCaption);
       
  1051     }
       
  1052 
       
  1053 // ---------------------------------------------------------------------------
       
  1054 // Returns the possible parameters for item target.
       
  1055 // ---------------------------------------------------------------------------
       
  1056 //
       
  1057 TPtrC CAiScutSettingsAppList::CAppListItem::Params() const
       
  1058     {
       
  1059     TPtrC params;
       
  1060     if (iParams)
       
  1061         {
       
  1062         params.Set(*iParams);
       
  1063         }
       
  1064     return params;
       
  1065     }
       
  1066 
       
  1067 // ---------------------------------------------------------------------------
       
  1068 // Sets the parameters for the item target.
       
  1069 // ---------------------------------------------------------------------------
       
  1070 //
       
  1071 void CAiScutSettingsAppList::CAppListItem::SetParamsL(const TDesC& aParams)
       
  1072     {
       
  1073     HBufC* newParams = aParams.AllocL();
       
  1074     delete iParams;
       
  1075     iParams = newParams;
       
  1076     }
       
  1077 
       
  1078 TAiScutSettingType CAiScutSettingsAppList::CAppListItem::Type() const
       
  1079 {
       
  1080     return iType;
       
  1081 }
       
  1082 
       
  1083 void CAiScutSettingsAppList::CAppListItem::SetType( TAiScutSettingType aType )
       
  1084 {
       
  1085     iType = aType;
       
  1086 }
       
  1087 // End of File.