profilesservices/ProfileEngine/ProfileScheduleEventSrc/CProfileChangeEvent.cpp
changeset 0 8c5d936e5675
child 8 f62c3a3d66b8
equal deleted inserted replaced
-1:000000000000 0:8c5d936e5675
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Handles reactivation of the previous profile when the scheduler
       
    15 *                runs.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CProfileChangeEvent.h"
       
    22 
       
    23 #include    <e32svr.h>
       
    24 #include    <MProfileEngine.h>
       
    25 #include    <AknGlobalNote.h>
       
    26 #include    <data_caging_path_literals.hrh>
       
    27 #include    <centralrepository.h>
       
    28 #include    <barsc.h>
       
    29 #include    <bautils.h>
       
    30 
       
    31 #include	<SecondaryDisplay/SecondaryDisplayProfilesAPI.h>
       
    32 #include	<aknSDData.h>
       
    33 #include	<featmgr.h>
       
    34 
       
    35 #include    <ProfileScheduleEvent.rsg>
       
    36 #include    "ProfileEnginePrivateCRKeys.h"
       
    37 #include    "ProfileEngineConstants.h"
       
    38 #include    "ProfilesDebug.h"
       
    39 
       
    40 
       
    41 // CONSTANTS
       
    42 namespace
       
    43     {
       
    44     _LIT( KProfileScheduleEventResourceDriveAndDir, "Z:ProfileScheduleEvent.rsc" );
       
    45     }
       
    46 
       
    47 // ============================ MEMBER FUNCTIONS ===============================
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CProfileChangeEvent::CProfileChangeEvent
       
    51 // C++ default constructor can NOT contain any code, that
       
    52 // might leave.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CProfileChangeEvent::CProfileChangeEvent()
       
    56     {
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CProfileChangeEvent::ConstructL
       
    61 // Symbian 2nd phase constructor can leave.
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 void CProfileChangeEvent::ConstructL()
       
    65     {
       
    66     FeatureManager::InitializeLibL();
       
    67     iCoverDisplay = FeatureManager::FeatureSupported( KFeatureIdCoverDisplay );
       
    68     
       
    69     
       
    70     User::LeaveIfError( iFs.Connect() );
       
    71     // Open/Create mutex
       
    72     TInt error( KErrNotFound );
       
    73     while( error == KErrNotFound )
       
    74         {
       
    75         error = iMutex.CreateGlobal( KProfileMutexName );
       
    76         if( error != KErrAlreadyExists )
       
    77             {
       
    78             break;
       
    79             }
       
    80         error = iMutex.OpenGlobal( KProfileMutexName );
       
    81         }
       
    82     User::LeaveIfError( error );
       
    83     iProfileEngine = CreateProfileEngineL( &iFs );
       
    84     iGlobalNote = CAknGlobalNote::NewL();
       
    85     ReadResourcesL();
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CProfileChangeEvent::NewL
       
    90 // Two-phased constructor.
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 CProfileChangeEvent* CProfileChangeEvent::NewL()
       
    94     {
       
    95     CProfileChangeEvent* self = CProfileChangeEvent::NewLC();
       
    96     CleanupStack::Pop();
       
    97 
       
    98     return self;
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CProfileChangeEvent::NewLC
       
   103 // Two-phased constructor.
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 CProfileChangeEvent* CProfileChangeEvent::NewLC()
       
   107     {
       
   108     CProfileChangeEvent* self = new( ELeave ) CProfileChangeEvent;
       
   109 
       
   110     CleanupStack::PushL( self );
       
   111     self->ConstructL();
       
   112 
       
   113     return self;
       
   114     }
       
   115 
       
   116 
       
   117 // Destructor
       
   118 CProfileChangeEvent::~CProfileChangeEvent()
       
   119     {
       
   120     delete iNoteText;
       
   121     delete iGlobalNote;
       
   122     if( iProfileEngine )
       
   123         {
       
   124         iProfileEngine->Release();
       
   125         }
       
   126     iFs.Close();
       
   127     iMutex.Close();
       
   128     
       
   129     FeatureManager::UnInitializeLib();
       
   130     }
       
   131 
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CProfileChangeEvent::ExecuteL
       
   135 // (other items were commented in a header).
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 void CProfileChangeEvent::ExecuteL()
       
   139     {
       
   140 	PRODEBUG( " CProfileChangeEvent:ExecuteL" );
       
   141     CProfileChangeEvent* profileChangeEvent = CProfileChangeEvent::NewLC();
       
   142 	PRODEBUG( " CProfileChangeEvent:ExecuteL 2" );
       
   143 
       
   144     profileChangeEvent->DoProfileExpirationL();
       
   145 
       
   146     CleanupStack::PopAndDestroy(); // profileChangeEvent
       
   147 	PRODEBUG( " CProfileChangeEvent:ExecuteL end" );
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CProfileChangeEvent::DoProfileExpirationL
       
   152 // (other items were commented in a header).
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 void CProfileChangeEvent::DoProfileExpirationL()
       
   156     {
       
   157     iMutex.Wait();
       
   158     TRAPD( err,
       
   159         if( ReadProfileIdL() )
       
   160             {
       
   161             ShowNoteL();
       
   162             ChangeProfileL();
       
   163             }
       
   164          );
       
   165     iMutex.Signal();
       
   166     User::LeaveIfError( err );
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CProfileChangeEvent::ChangeProfileL
       
   171 // (other items were commented in a header).
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 void CProfileChangeEvent::ChangeProfileL()
       
   175     {
       
   176 	PRODEBUG( " CProfileChangeEvent:ChangeProfileL" );
       
   177 
       
   178     iProfileEngine->SetActiveProfileL( iPreviousId );
       
   179 
       
   180     }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 // CProfileChangeEvent::ReadProfileIdL
       
   184 // (other items were commented in a header).
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 TBool CProfileChangeEvent::ReadProfileIdL()
       
   188     {
       
   189 	PRODEBUG( " CProfileChangeEvent:ReadProfileIdL" );
       
   190     CRepository* cenrep = CRepository::NewLC( KCRUidProfileEngine );
       
   191     User::LeaveIfError( cenrep->Get( KProEngPreviousActiveId, iPreviousId ) );
       
   192     CleanupStack::PopAndDestroy( cenrep );
       
   193     // If someone called SetActiveProfileL() right after scheduler started the
       
   194     // execution of this dll, the previous id would be resetted to KErrNotFound
       
   195     return ( iPreviousId > KErrNotFound );
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CProfileChangeEvent::ShowNoteL
       
   200 // (other items were commented in a header).
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 void CProfileChangeEvent::ShowNoteL()
       
   204     {
       
   205 	PRODEBUG1( " CProfileChangeEvent:ShowNoteL(%S)", iNoteText );
       
   206 	// Set secondary display data if cover ui is supported
       
   207 	if ( iCoverDisplay )
       
   208 		{
       
   209 		CAknSDData* sd = CAknSDData::NewL(KCatProfiles,
       
   210 							ECmdShowTimedProfileExpiryNote, KNullDesC8);
       
   211 		iGlobalNote->SetSecondaryDisplayData( sd ); // ownership transferred
       
   212 		}
       
   213     iGlobalNote->ShowNoteL( EAknGlobalConfirmationNote, *iNoteText );
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // CProfileChangeEvent::ReadResourcesL
       
   218 // (other items were commented in a header).
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 void CProfileChangeEvent::ReadResourcesL()
       
   222     {
       
   223 	PRODEBUG( " CProfileChangeEvent:ReadResourcesL" );
       
   224     TParse* fp = new ( ELeave ) TParse();
       
   225     fp->Set( KProfileScheduleEventResourceDriveAndDir,
       
   226              &KDC_RESOURCE_FILES_DIR, NULL );
       
   227     iResourceFile.Copy( fp->FullName() );
       
   228     delete fp;
       
   229 
       
   230 	PRODEBUG( " CProfileChangeEvent:ReadResourcesL 2" );
       
   231     BaflUtils::NearestLanguageFile( iFs, iResourceFile );
       
   232 	PRODEBUG1( " CProfileChangeEvent:ReadResourcesL 3 iResourceFile=%S", &iResourceFile );
       
   233 
       
   234     RResourceFile resourceFile;
       
   235     resourceFile.OpenL( iFs, iResourceFile );
       
   236     CleanupClosePushL( resourceFile );
       
   237 
       
   238 	PRODEBUG( " CProfileChangeEvent:ReadResourcesL 4" );
       
   239     resourceFile.ConfirmSignatureL();
       
   240 	PRODEBUG( " CProfileChangeEvent:ReadResourcesL 5" );
       
   241 
       
   242     HBufC8* dataBuffer = resourceFile.AllocReadLC( R_PROFILES_CONFIRM_TIMED_EXPIRED );
       
   243 
       
   244 	PRODEBUG( " CProfileChangeEvent:ReadResourcesL 6" );
       
   245     TResourceReader rsReader;
       
   246     rsReader.SetBuffer( dataBuffer );
       
   247     iNoteText = rsReader.ReadHBufCL();
       
   248 	PRODEBUG( " CProfileChangeEvent:ReadResourcesL 7" );
       
   249 
       
   250     CleanupStack::PopAndDestroy( 2 ); // dataBuffer, resourceFile
       
   251 	PRODEBUG( " CProfileChangeEvent:ReadResourcesL 8" );
       
   252     }
       
   253 
       
   254 //  End of File
       
   255