idlefw/plugins/shortcutplugin/src/caiscutsettings.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:  Shortcut settings plug-in main class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <eikmenup.h>
       
    21 #include <eikbtgpc.h>
       
    22 #include <StringLoader.h>
       
    23 #include <gsfwviewuids.h>
       
    24 #include <gsprivatepluginproviderids.h>
       
    25 #include <bautils.h>
       
    26 #include <pathinfo.h>
       
    27 #include <hlplch.h>
       
    28 #include <featmgr.h>
       
    29 #include <e32property.h>                // For RProperty
       
    30 #include <activeidle2domainpskeys.h>    // For KPSUidActiveIdle2
       
    31 
       
    32 #include <avkon.rsg>
       
    33 #include <aiscutsettingsres.rsg>
       
    34 #include <aiscuttexts.rsg>
       
    35 
       
    36 #include "aiscutsettings.hrh"
       
    37 #include "caiscutsettings.h"
       
    38 #include "caiscutsettingsitem.h"
       
    39 #include "caiscutsettingscontainer.h"
       
    40 #include "caiscutsettingsmodel.h"
       
    41 #include <platform/mw/aiscutuids.hrh>
       
    42 #include "aiscutdefs.h"
       
    43 #include <aisystemuids.hrh>
       
    44 
       
    45 const TUid KUidScutSettingsPlugin =
       
    46 {
       
    47     AI_UID_ECOM_IMPLEMENTATION_SETTINGS_SCUTPLUGIN
       
    48 };
       
    49 
       
    50 _LIT(KScutSettingsResourceFileName, "aiscutsettingsres.rsc");
       
    51 _LIT(KScutTextsResourceFileName,    "aiscuttexts.rsc");
       
    52 _LIT8(KScutDirectOpenTag,    "?open");
       
    53 
       
    54 
       
    55 // ======== LOCAL FUNCTIONS ========
       
    56 
       
    57 
       
    58 static void ParseKeysL( const TDesC8& aCustomMessage, RArray<TUint32>& aKeys, TBool& aOpen )
       
    59     {
       
    60     HBufC8* message = aCustomMessage.AllocLC();
       
    61     
       
    62     TPtr8 ptr( message->Des() );
       
    63             
       
    64     TInt pos;
       
    65     TInt openPos;
       
    66     TBool openTag=EFalse;
       
    67     
       
    68     do
       
    69         {                
       
    70         pos = ptr.Locate( ',' );
       
    71         
       
    72         if( pos != KErrNotFound )
       
    73             {
       
    74             const TDesC8& str1 = ptr.Left( pos );
       
    75             const TDesC8& str2 = str1.Right( str1.Length() - 2 );
       
    76             
       
    77             TUint32 value;
       
    78             TLex8 lex( str2 );
       
    79                         
       
    80             if( lex.Val( value, EHex ) == KErrNone )
       
    81                 {
       
    82                 aKeys.AppendL( value );
       
    83                 }
       
    84                                     
       
    85             ptr = ptr.MidTPtr( pos + 1 );
       
    86             }
       
    87         else
       
    88             {
       
    89             const TDesC8& str1 = ptr;
       
    90             const TDesC8& str2 = str1.Right( str1.Length() - 2 );
       
    91             openPos = ptr.Find( KScutDirectOpenTag );
       
    92             TLex8 lex;
       
    93             if( openPos != KErrNotFound )
       
    94                 {
       
    95                 openTag=ETrue;
       
    96                 const TDesC8& str3 = str2.Left( openPos -2 );
       
    97                 lex.Assign( str3 );
       
    98                 }
       
    99             else
       
   100                 {
       
   101                 lex.Assign( str2 );
       
   102                 }
       
   103             TUint32 value;
       
   104             
       
   105             
       
   106             if( lex.Val( value, EHex ) == KErrNone )
       
   107                 {
       
   108                 aKeys.AppendL( value );
       
   109                 }                        
       
   110             }                                           
       
   111         }
       
   112     while( pos != KErrNotFound );        
       
   113             
       
   114     if( openTag && aKeys.Count() == 1 )
       
   115         {
       
   116         aOpen = ETrue;
       
   117         }
       
   118     CleanupStack::PopAndDestroy();
       
   119     }
       
   120 // ======== MEMBER FUNCTIONS ========
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 CAiScutSettings::CAiScutSettings() : iResourceLoaderTexts(*iCoeEnv)
       
   127 {
       
   128 }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 void CAiScutSettings::ConstructL()
       
   135 {
       
   136     FeatureManager::InitializeLibL();
       
   137 
       
   138     TParsePtrC driveParse(PathInfo::RomRootPath());
       
   139     TFileName resourceName(driveParse.Drive());
       
   140 
       
   141     // Find the resource file.
       
   142     TParse parse;
       
   143     parse.Set(KScutSettingsResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL);
       
   144     resourceName.Append(parse.FullName());
       
   145 
       
   146     // Open resource file.
       
   147     iResourceLoader.OpenL(resourceName);
       
   148 
       
   149     resourceName.Copy(driveParse.Drive());
       
   150     parse.Set(KScutTextsResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL);
       
   151     resourceName.Append(parse.FullName());
       
   152 
       
   153     // Open resource file.
       
   154     iResourceLoaderTexts.OpenL(resourceName);
       
   155 
       
   156     iModel = CAiScutSettingsModel::NewL(*this, iCoeEnv);
       
   157     
       
   158     iListBoxTimer = CIdle::NewL(CActive::EPriorityHigh);
       
   159 
       
   160 
       
   161     BaseConstructL(R_SCUT_SETTINGS_VIEW);
       
   162 }
       
   163 
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 // ---------------------------------------------------------------------------
       
   167 //
       
   168 CAiScutSettings* CAiScutSettings::NewL(TAny* /*aInitParams*/)
       
   169 {
       
   170     CAiScutSettings* self = new (ELeave) CAiScutSettings;
       
   171     CleanupStack::PushL(self);
       
   172     self->ConstructL();
       
   173     CleanupStack::Pop(self);
       
   174     return self;
       
   175 }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 CAiScutSettings::~CAiScutSettings()
       
   182 {
       
   183     FeatureManager::UnInitializeLib();
       
   184     
       
   185     if( iListBoxTimer )
       
   186         {
       
   187         iListBoxTimer->Cancel();
       
   188         delete iListBoxTimer;
       
   189         }    
       
   190 
       
   191     iResourceLoader.Close();
       
   192     iResourceLoaderTexts.Close();
       
   193 
       
   194     delete iModel;
       
   195 }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // From CAknView
       
   199 // Returns view id.
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 TUid CAiScutSettings::Id() const
       
   203 {
       
   204     return KUidScutSettingsPlugin;
       
   205 }
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // From CAknView
       
   209 // Handles commands.
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 void CAiScutSettings::HandleCommandL(TInt aCommand)
       
   213 {
       
   214     switch (aCommand)
       
   215     {
       
   216     case EAiScutSettingsCmdChange:
       
   217         Container()->HandleChangeCommandL();
       
   218         break;
       
   219 
       
   220     case EAknCmdHelp:
       
   221 	/*
       
   222         TUid fwUid = TUid::Uid( AI_UID3_AIFW_COMMON );
       
   223         TCoeContextName helpString;
       
   224         helpString.Copy( KSET_HLP_HOME_SCREEN_SHORTCUTS );
       
   225         
       
   226         CArrayFixFlat<TCoeHelpContext>* array = 
       
   227             new (ELeave) CArrayFixFlat<TCoeHelpContext>(1);
       
   228         CleanupStack::PushL( array );
       
   229         array->AppendL( TCoeHelpContext( fwUid, helpString ) );
       
   230         HlpLauncher::LaunchHelpApplicationL( CCoeEnv::Static()->WsSession(), array );
       
   231         CleanupStack::Pop( array );
       
   232 	*/
       
   233         break;
       
   234 
       
   235     case EAknSoftkeyBack:
       
   236         if (iAppUi->View(KGSMainViewUid))
       
   237         {
       
   238             // if we are in GS activate parent plugin view (standby view)...
       
   239             iAppUi->ActivateLocalViewL(KGSPrslnPluginUid);
       
   240         }
       
   241         else
       
   242         {
       
   243             iAppUi->ActivateLocalViewL(iPrevViewId.iViewUid);
       
   244         }
       
   245         break;
       
   246 
       
   247     case EAknSoftkeyExit:
       
   248         iAppUi->HandleCommandL(EAknCmdExit);
       
   249         break;
       
   250 
       
   251     default:
       
   252         iAppUi->HandleCommandL(aCommand);
       
   253         break;
       
   254     }
       
   255 }
       
   256 
       
   257 // ----------------------------------------------------------------------------
       
   258 // From CAknView
       
   259 // First method called by the Avkon framwork
       
   260 // ----------------------------------------------------------------------------
       
   261 //
       
   262 void CAiScutSettings::DoActivateL(const TVwsViewId& aPrevViewId, TUid aCustomMessageId, const TDesC8& aCustomMessage)
       
   263 {
       
   264 #ifdef MY_DEBUG
       
   265     RDebug::Print(_L("XAI: CAiScutSettings::DoActivateL"));
       
   266     RDebug::Print(_L("XAI:   aCustomMessageId = 0x%08x"), aCustomMessageId.iUid);
       
   267     RDebug::Print(_L("XAI:   aPrevViewId      = 0x%08x"), aPrevViewId.iAppUid.iUid);
       
   268 #endif
       
   269 
       
   270     CEikButtonGroupContainer* cba = Cba();
       
   271 
       
   272     if (cba)
       
   273     {
       
   274         if (aCustomMessageId == KScutActiveIdleUid)
       
   275         {
       
   276             cba->SetCommandSetL(R_SCUT_SOFTKEYS_OPTIONS_EXIT_CHANGE);
       
   277         }
       
   278         else
       
   279         {
       
   280             cba->SetCommandSetL(R_SCUT_SOFTKEYS_OPTIONS_BACK_CHANGE);
       
   281         }
       
   282         cba->DrawDeferred();
       
   283     }
       
   284 
       
   285     CGSBaseView::DoActivateL(aPrevViewId, aCustomMessageId, aCustomMessage);
       
   286 
       
   287     TBool open=EFalse;
       
   288     if( aCustomMessage != KNullDesC8 )
       
   289         {
       
   290         RArray<TUint32> keys;
       
   291         CleanupClosePushL( keys );
       
   292 
       
   293         ParseKeysL( aCustomMessage, keys, open );
       
   294         
       
   295         iModel->SetSettingsKeys( keys );
       
   296         
       
   297         CleanupStack::PopAndDestroy();
       
   298         }
       
   299     
       
   300     iModel->UpdateSettingsContainerL();
       
   301 
       
   302     if( open )
       
   303         {
       
   304         /* Let idle timer do this job. */
       
   305         iListBoxTimer->Cancel();
       
   306         iListBoxTimer->Start(TCallBack(DoHandleListBoxSelectionL, this));
       
   307         }
       
   308 }
       
   309 
       
   310 // ----------------------------------------------------------------------------
       
   311 // From CAknView
       
   312 // Called by the Avkon view framework when closing.
       
   313 // ----------------------------------------------------------------------------
       
   314 //
       
   315 void CAiScutSettings::DoDeactivate()
       
   316 {
       
   317     iModel->ActivateObservers(EFalse);
       
   318 
       
   319     // deletes iContainer.
       
   320     CGSBaseView::DoDeactivate();
       
   321 
       
   322     iModel->SetContainer(Container());
       
   323 }
       
   324 
       
   325 void CAiScutSettings::HandleForegroundEventL(TBool /*aForeground*/)
       
   326     {
       
   327     // No implementation required
       
   328     }
       
   329 
       
   330 // ----------------------------------------------------------------------------
       
   331 // From MEikMenuObserver
       
   332 // ----------------------------------------------------------------------------
       
   333 //
       
   334 void CAiScutSettings::DynInitMenuPaneL(
       
   335     TInt aResourceId, CEikMenuPane* aMenuPane)
       
   336 {
       
   337     if (aMenuPane && aResourceId == R_SCUTSETTINGS_MENUPANE)
       
   338     {
       
   339         if (!FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   340         {
       
   341             // Disable help if not supported
       
   342             aMenuPane->SetItemDimmed(EAknCmdHelp, ETrue);
       
   343         }
       
   344         if (iModel->MdcaCount() == 0)
       
   345         {
       
   346             aMenuPane->SetItemDimmed(EAiScutSettingsCmdChange, ETrue);
       
   347         }
       
   348     }
       
   349 }
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // From CGSPluginInterface. 256
       
   353 // ---------------------------------------------------------------------------
       
   354 //
       
   355 void CAiScutSettings::GetCaptionL(TDes& aCaption) const
       
   356 {
       
   357     iCoeEnv->ReadResourceL(aCaption, R_SCUT_SETTINGS_VIEW_CAPTION);
       
   358 }
       
   359 
       
   360 // ---------------------------------------------------------------------------
       
   361 // From CGSPluginInterface
       
   362 // ---------------------------------------------------------------------------
       
   363 //
       
   364 TInt CAiScutSettings::PluginProviderCategory() const
       
   365 {
       
   366     return KGSPluginProviderInternal;
       
   367 }
       
   368 
       
   369 // ---------------------------------------------------------------------------
       
   370 // From CGSPluginInterface
       
   371 // ---------------------------------------------------------------------------
       
   372 //
       
   373 TBool CAiScutSettings::Visible() const
       
   374 {
       
   375     return EFalse;
       
   376 }
       
   377 
       
   378 // ---------------------------------------------------------------------------
       
   379 // From CGSBaseView
       
   380 // Returns view id.
       
   381 // ---------------------------------------------------------------------------
       
   382 //
       
   383 CAiScutSettingsContainer* CAiScutSettings::Container()
       
   384 {
       
   385     return static_cast<CAiScutSettingsContainer*>(iContainer);
       
   386 }
       
   387 
       
   388 // ---------------------------------------------------------------------------
       
   389 // From CGSBaseView
       
   390 // ---------------------------------------------------------------------------
       
   391 //
       
   392 void CAiScutSettings::NewContainerL()
       
   393 {
       
   394     delete iContainer;
       
   395     iContainer = NULL;
       
   396     
       
   397     iContainer = new (ELeave) CAiScutSettingsContainer();
       
   398     Container()->SetModel(iModel);
       
   399     iModel->SetContainer(Container());
       
   400 }
       
   401 
       
   402 // ---------------------------------------------------------------------------
       
   403 // From CGSBaseView
       
   404 // ---------------------------------------------------------------------------
       
   405 //
       
   406 void CAiScutSettings::HandleListBoxSelectionL()
       
   407 {
       
   408     Container()->HandleChangeCommandL();
       
   409 }
       
   410 
       
   411 // ---------------------------------------------------------------------------
       
   412 // ---------------------------------------------------------------------------
       
   413 //
       
   414 TBool CAiScutSettings::Activated() const
       
   415     {
       
   416     return iContainer ? ETrue : EFalse;
       
   417     }
       
   418 
       
   419 // -----------------------------------------------------------------------------
       
   420 // CActiveIdleState::DoUpdateSaSetting
       
   421 // -----------------------------------------------------------------------------
       
   422 //
       
   423 TInt CAiScutSettings::DoHandleListBoxSelectionL(TAny* aAny)
       
   424     {
       
   425     CAiScutSettings* self = static_cast<CAiScutSettings*>(aAny);
       
   426     if(self)
       
   427         {
       
   428         self->iListBoxTimer->Cancel();
       
   429         self->HandleListBoxSelectionL();
       
   430         }
       
   431     return KErrNone;
       
   432     }
       
   433 
       
   434 
       
   435 // End of File.