eventsui/eventshandlerui/eventsnotifier/evtinfonote/src/evtinfonoteimpl.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 2008 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:  Info Note implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // System Includes
       
    20 #include <evtinfonote.rsg>
       
    21 #include <eikbtgpc.h>
       
    22 #include <gulicon.h>
       
    23 #include <AknsUtils.h>
       
    24 #include <avkon.mbg>
       
    25 #include <evtinfonote.mbg>
       
    26 #include <eikimage.h>
       
    27 #include <StringLoader.h>
       
    28 #include <aknlists.h> 
       
    29 #include <aknPopup.h> 
       
    30 #include <badesca.h> 
       
    31 #include <data_caging_path_literals.hrh>
       
    32 #include <AknsConstants.h> 		// Skin Ids
       
    33 #include <AknIconUtils.h>
       
    34 #include <AknsSkinInstance.h>
       
    35 
       
    36 // User Includes
       
    37 #include "evtinfonoteimpl.h"
       
    38 #include "evtinfonoteparams.h"
       
    39 #include "evtinfonoteconsts.hrh"
       
    40 #include "evtkeylockhandler.h"
       
    41 
       
    42 // Constant Defintions
       
    43 _LIT( KEvtDefaultIconFileName, "evtinfonote.mif" );
       
    44 static const TInt KTimetoPlay = 60;
       
    45 static const TInt KTimetoSnooze = 60;
       
    46 
       
    47 // Context menu Array
       
    48  	const TInt KListGranularity = 5;
       
    49 static const TInt KEvtOpenEvent = 0;
       
    50 static const TInt KEvtViewDesc = 1;
       
    51 static const TInt KEvtNone = 2;
       
    52 
       
    53 #include "evtdebug.h"
       
    54 
       
    55 //
       
    56 // ------------------------- Member Function definition ----------------------
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // CEvtInfoNoteImpl::CEvtInfoNoteImpl()
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 CEvtInfoNoteImpl::CEvtInfoNoteImpl( CEvtInfoNoteInputParam*      aInputParam )
       
    63     :CAknQueryDialog( CAknQueryDialog::ENoTone ),
       
    64     iInputParam( aInputParam )
       
    65     {
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // CEvtInfoNoteImpl::~CEvtInfoNoteImpl()
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 CEvtInfoNoteImpl::~CEvtInfoNoteImpl()
       
    73     {
       
    74     // Delete the tone player
       
    75     delete iTonePlayer;
       
    76 
       
    77     // Delete the timer
       
    78     if( iTimer )
       
    79         {
       
    80         iTimer->Cancel();
       
    81         delete iTimer;
       
    82         }
       
    83     
       
    84 		// Update the Key Lock state before Close.
       
    85     if(iKeyLockHandler)
       
    86     		{
       
    87     		if(*iExitFlag == EEvtCloseInfoNote || *iExitFlag == EEvtCmdSnoozeEvent )
       
    88 						iKeyLockHandler->UpdateStateWithNote();
       
    89 				else
       
    90 						iKeyLockHandler->UpdateStateWithoutNote();
       
    91     		}
       
    92     
       
    93     // Delete Key Lock Handler
       
    94     delete iKeyLockHandler;
       
    95     
       
    96     // Delete the Input parameter object
       
    97     delete iInputParam;          
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // void CEvtInfoNoteImpl::ConstructL()
       
   102 // ---------------------------------------------------------------------------
       
   103 //    
       
   104 void CEvtInfoNoteImpl::ConstructLC()
       
   105     {
       
   106     EVTUIDEBUG( "+ CEvtInfoNoteImpl::ConstructL" );
       
   107     
       
   108     CAknQueryDialog::PrepareLC( R_LOC_EVT_INFO_QUERY );
       
   109     
       
   110     // Prepare the Heading resource
       
   111     TPtrC debug( iInputParam->Subject() );
       
   112     EVTUIDEBUG1( "Notifier for - Subject = %S", &debug );
       
   113     
       
   114 	// Set the Heading
       
   115     QueryHeading()->SetTextL( iInputParam->Subject());
       
   116     
       
   117     // Set the Query Text   
       
   118     SetPromptL( iInputParam->Description());
       
   119     
       
   120     // Load the Image fpr the query
       
   121     LoadImageL();
       
   122         
       
   123     iKeyLockHandler = CEvtKeyLockHandler::NewL( );
       
   124     
       
   125     // Check if the tone needs to be played. In case, it is true then
       
   126     // create the player and update the CBA
       
   127     if ( iInputParam->ShowSnooze() )
       
   128         {
       
   129         if ( iInputParam->ToneEnabled() )
       
   130             {
       
   131             // Create the tone player
       
   132             iTonePlayer = CEvtTonePlayer::NewL( *this );
       
   133             
       
   134             // Update the CBA - Snooze context silence
       
   135             ButtonGroupContainer().SetCommandSetL( R_LOC_EVT_INFONOTE_SNOOZE_TONE_CBA );            
       
   136             }
       
   137         else
       
   138             {
       
   139             // Update the CBA - Snooze context close
       
   140             ButtonGroupContainer().SetCommandSetL( R_LOC_EVT_INFONOTE_SNOOZE_CBA );     
       
   141             }
       
   142         }
       
   143         else
       
   144         {
       
   145         if ( iInputParam->ToneEnabled() )
       
   146             {
       
   147             // Create the tone player
       
   148             iTonePlayer = CEvtTonePlayer::NewL( *this );
       
   149             
       
   150             // Update the CBA - open context silence
       
   151             ButtonGroupContainer().SetCommandSetL( R_LOC_EVT_INFONOTE_OPEN_TONE_CBA );            
       
   152             }
       
   153         }
       
   154     EVTUIDEBUG( "- CEvtInfoNoteImpl::ConstructL" )     		           		             
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // void CEvtInfoNoteImpl::NewL()
       
   159 // ---------------------------------------------------------------------------
       
   160 //     
       
   161 CEvtInfoNoteImpl* CEvtInfoNoteImpl::NewLC( CEvtInfoNoteInputParam*      aInputParam )
       
   162     {
       
   163     CEvtInfoNoteImpl* self = new ( ELeave ) CEvtInfoNoteImpl( aInputParam );
       
   164     CleanupStack::PushL( self );
       
   165     self->ConstructLC();
       
   166     CleanupStack::Pop( self );
       
   167     return self;    
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // TInt CEvtInfoNoteImpl::RunLD()
       
   172 // ---------------------------------------------------------------------------
       
   173 //  
       
   174 TInt CEvtInfoNoteImpl::RunLD(TEvtInfoNoteCmds* aFlag)
       
   175     {
       
   176     // Call RunLD
       
   177     iExitFlag = aFlag;
       
   178     return RunLD();
       
   179     } 
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // TInt CEvtInfoNoteImpl::RunLD()
       
   183 // ---------------------------------------------------------------------------
       
   184 //  
       
   185 TInt CEvtInfoNoteImpl::RunLD()
       
   186     {
       
   187     // Maintain the Key Lock State and Enable if it is already not enabled
       
   188     if ( iKeyLockHandler )
       
   189         {
       
   190         iKeyLockHandler->MaintainState();
       
   191         }
       
   192     
       
   193     TInt timeToPlay = KTimetoPlay;
       
   194     if ( iInputParam->ShowSnooze() )
       
   195         {
       
   196 		// Start the Timer if the Event has to be snoozed.
       
   197         if( !iTimer )
       
   198             {
       
   199             iTimer = CPeriodic::NewL( 0 ); // neutral priority
       
   200             }
       
   201         iTimer->Start( TTimeIntervalMicroSeconds32( KTimetoSnooze * 1000000 ),
       
   202                           TTimeIntervalMicroSeconds32( KTimetoSnooze * 1000000 ),
       
   203                           TCallBack(TickL, this));
       
   204         
       
   205         timeToPlay = 0;
       
   206         }
       
   207     
       
   208     // If tone player is there, then start tone playing
       
   209     if ( iTonePlayer )
       
   210         {
       
   211         iTonePlayer->PlayFileL( iInputParam->Tone(), iInputParam->ToneRepeat(), timeToPlay );
       
   212         }
       
   213         
       
   214     // Pass the function to the base class
       
   215     return CAknQueryDialog::RunLD();
       
   216     }                  
       
   217                          
       
   218 // ---------------------------------------------------------------------------
       
   219 // void CEvtInfoNoteImpl::OkToExitL()
       
   220 // ---------------------------------------------------------------------------
       
   221 //                                       
       
   222 TBool CEvtInfoNoteImpl::OkToExitL( TInt aButtonId )
       
   223     {
       
   224     EVTUIDEBUG1( "+ CEvtInfoNoteImpl::OkToExitL - ButtonId = %d", aButtonId );
       
   225     switch(aButtonId)
       
   226         {
       
   227         case EEvtCmdSnoozeEvent: // when LSK Snooze is pressed
       
   228             {
       
   229 	        *iExitFlag = EEvtCmdSnoozeEvent; 
       
   230 	        return ETrue;
       
   231             }
       
   232         case EEvtCmdOpenEvent: // when LSK Open is pressed
       
   233             {
       
   234 			// Disable the Key Lock irrespective of previously maintained state.
       
   235 		    if ( iKeyLockHandler )
       
   236 		        {
       
   237 		        iKeyLockHandler->EnableKeyLock( EFalse );
       
   238 		        }
       
   239 	        *iExitFlag = EEvtCmdOpenEvent; 
       
   240 	        return ETrue;
       
   241             }
       
   242         case EEvtCmdSilence: // when RSK Silence is pressed
       
   243             {
       
   244 	        // If tone player is there, then start tone playing
       
   245 	        if ( iTonePlayer )
       
   246 	            {
       
   247 	            iTonePlayer->StopPlayingL( EFalse );
       
   248 	            } 
       
   249 	        *iExitFlag = EEvtCmdSilence; 
       
   250 	        return EFalse;
       
   251             }
       
   252         case EAknSoftkeyContextOptions: //when MSK is pressed
       
   253             {
       
   254  
       
   255 	    	switch( GetMskOptionL() )
       
   256 	    		{
       
   257 	    		case KEvtOpenEvent:
       
   258 	    			// Disable the Key Lock irrespective of previously maintained state.
       
   259 				    if ( iKeyLockHandler )
       
   260 				        {
       
   261 				        iKeyLockHandler->EnableKeyLock( EFalse );
       
   262 				        }
       
   263 	    			*iExitFlag = EEvtCmdOpenEvent;
       
   264 	    			 return ETrue;
       
   265 	    		case KEvtViewDesc:
       
   266 	    			// Disable the Key Lock irrespective of previously maintained state.
       
   267 				    if ( iKeyLockHandler )
       
   268 				        {
       
   269 				        iKeyLockHandler->EnableKeyLock( EFalse );
       
   270 				        }
       
   271 	    			*iExitFlag = EEvtCmdShowDetails;
       
   272 	    			 return ETrue;
       
   273 	    		default:
       
   274 	    			 return EFalse;
       
   275 	    		}
       
   276             }
       
   277         case EEvtCloseInfoNote: // when RSK Silence is pressed
       
   278             {
       
   279 		    *iExitFlag = EEvtCloseInfoNote;
       
   280 	        return ETrue;
       
   281             }
       
   282         default: // close dialog
       
   283             {
       
   284             return ETrue;
       
   285             }
       
   286         }
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // void CEvtInfoNoteImpl::PostLayoutDynInitL()
       
   291 // ---------------------------------------------------------------------------
       
   292 //     
       
   293 void CEvtInfoNoteImpl::PostLayoutDynInitL()
       
   294     {
       
   295     }
       
   296 
       
   297 // ---------------------------------------------------------------------------
       
   298 // void CEvtInfoNoteImpl::TonePlayCompleteL()
       
   299 // ---------------------------------------------------------------------------
       
   300 //  
       
   301 void CEvtInfoNoteImpl::TonePlayCompleteL( TBool aTimeout )
       
   302 	{
       
   303 		// Enable KeyLock on Timeout.
       
   304     if ( iKeyLockHandler && aTimeout )
       
   305         {
       
   306         iKeyLockHandler->EnableKeyLock( ETrue );
       
   307         iKeyLockHandler->UpdateStateWithoutNote();
       
   308         }
       
   309         
       
   310     // Update the CBA
       
   311     if ( iInputParam->ShowSnooze() )
       
   312         {
       
   313         ButtonGroupContainer().SetCommandSetL( R_LOC_EVT_INFONOTE_SNOOZE_CBA );
       
   314         }
       
   315     else
       
   316         {
       
   317         ButtonGroupContainer().SetCommandSetL( R_LOC_EVT_INFONOTE_OPEN_CBA );
       
   318         }
       
   319 	}
       
   320 
       
   321 
       
   322 // ---------------------------------------------------------------------------
       
   323 // TInt CEvtInfoNoteImpl::GetMskOptionL()
       
   324 // ---------------------------------------------------------------------------
       
   325 //  
       
   326 TInt CEvtInfoNoteImpl::GetMskOptionL()
       
   327 	{
       
   328     EVTUIDEBUG( "+ CEvtInfoNoteImpl::GetMskOptionL()" );
       
   329 	TInt selected(KEvtNone);
       
   330 	
       
   331     CAknSinglePopupMenuStyleListBox* list = new(ELeave)CAknSinglePopupMenuStyleListBox;
       
   332     CleanupStack::PushL(list);
       
   333  
       
   334     CAknPopupList* popupList = CAknPopupList::NewL(list, R_AVKON_SOFTKEYS_OK_CANCEL,
       
   335 												 AknPopupLayouts::EMenuWindow);  
       
   336     CleanupStack::PushL(popupList);
       
   337  
       
   338     list->ConstructL(popupList, 0);
       
   339     list->CreateScrollBarFrameL(ETrue);
       
   340     list->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,
       
   341 														CEikScrollBarFrame::EAuto);
       
   342  	
       
   343     CDesCArrayFlat* itemArray = new(ELeave)CDesCArrayFlat( KListGranularity );
       
   344     CleanupStack::PushL(itemArray);
       
   345  
       
   346     // add the item popup item here
       
   347     HBufC* openevent = StringLoader::LoadLC( R_LOCEV_OPTIONS_OPEN_EVENT );
       
   348     itemArray->AppendL(*openevent);
       
   349     CleanupStack::PopAndDestroy(); // openevent
       
   350     
       
   351     if( iInputParam->Description().Length() != 0 )
       
   352     	{
       
   353 	    HBufC* viewdesc = StringLoader::LoadLC( R_LOCEV_OPTIONS_VIEW_DESCRIPTION );
       
   354 	    itemArray->AppendL(*viewdesc);
       
   355 	    CleanupStack::PopAndDestroy(); // viewdesc
       
   356     	}
       
   357  
       
   358     CleanupStack::Pop();            //itemArray
       
   359     list->Model()->SetItemTextArray(itemArray);
       
   360     list->Model()->SetOwnershipType(ELbmOwnsItemArray);
       
   361   
       
   362     // Show popup list and then show return value.
       
   363     TInt popupOk = popupList->ExecuteLD();
       
   364     if (popupOk)
       
   365     {
       
   366     selected = list->CurrentItemIndex();
       
   367     }
       
   368 	
       
   369     CleanupStack::Pop();            // popuplist
       
   370     CleanupStack::PopAndDestroy(); // list
       
   371     
       
   372     EVTUIDEBUG1( "- CEvtInfoNoteImpl::GetMskOptionL() - Selected = %d", selected );
       
   373     return selected;
       
   374 	}
       
   375 	
       
   376 // ---------------------------------------------------------------------------
       
   377 // void CEvtInfoNoteImpl::LoadImageL()
       
   378 // ---------------------------------------------------------------------------
       
   379 //     
       
   380 void CEvtInfoNoteImpl::LoadImageL()
       
   381     {   
       
   382     EVTUIDEBUG( "+ CEvtInfoNoteImpl::LoadImageL" )
       
   383         
       
   384     // Obtain the text query control
       
   385     CAknQueryControl* control = QueryControl();
       
   386     if ( control )
       
   387         {
       
   388         TFileName dllFileName;    
       
   389         Dll::FileName( dllFileName );
       
   390         //dllFileName.Copy( KTempDrive );
       
   391     	
       
   392     	TParse parse;
       
   393     	User::LeaveIfError( parse.Set( KEvtDefaultIconFileName, &KDC_APP_BITMAP_DIR, &dllFileName ));
       
   394         TFileName fileName( parse.FullName() );
       
   395         
       
   396 
       
   397          //retrieve accuracy level       
       
   398         CEvtInfoNoteInputParam::TEvtTriggerAccuracy accuracy = iInputParam->TrigerringAccuracy();
       
   399         EVTUIDEBUG1( "Icon creation:Accuracy level = %d", accuracy )
       
   400         
       
   401 	    MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   402 	
       
   403 	    EVTUIDEBUG( "AknsUtils::SkinInstance" );
       
   404 	    
       
   405 	    CFbsBitmap* bitmap = NULL;
       
   406 	    CFbsBitmap* bitmapMask = NULL;
       
   407 	    TAknsItemID aSkinID;
       
   408 	    TInt bmpID;
       
   409 	    TInt bmpMaskID;
       
   410 	    
       
   411 	    switch( accuracy )
       
   412 	    	{
       
   413 	    	case CEvtInfoNoteInputParam::EEvtAccurateTrigger:
       
   414 	    		aSkinID = KAknsIIDQgnNoteLocevAlarmAcc;
       
   415 	    		bmpID = EMbmEvtinfonoteQgn_note_locev_alarm_acc;
       
   416 	    		bmpMaskID = EMbmEvtinfonoteQgn_note_locev_alarm_acc_mask;
       
   417 	    		break;
       
   418 	    	case CEvtInfoNoteInputParam::EEvtInaccurateTrigger:
       
   419 	    		aSkinID = KAknsIIDQgnNoteLocevAlarmInacc;
       
   420 	    		bmpID = EMbmEvtinfonoteQgn_note_locev_alarm_inacc;
       
   421 	    		bmpMaskID = EMbmEvtinfonoteQgn_note_locev_alarm_inacc_mask;
       
   422 	    		break;
       
   423 	    	case CEvtInfoNoteInputParam::EEvtHighlyInaccurateTrigger:
       
   424 	    	default:
       
   425 	    		aSkinID = KAknsIIDQgnNoteLocevAlarmInaccHeavy;
       
   426 	    		bmpID = EMbmEvtinfonoteQgn_note_locev_alarm_inacc_heavy;
       
   427 	    		bmpMaskID = EMbmEvtinfonoteQgn_note_locev_alarm_inacc_heavy_mask;
       
   428 	    		break;
       
   429 	    	}
       
   430 	    
       
   431 	    TRAPD( err, AknsUtils::CreateIconL( skin,
       
   432 	                            aSkinID,
       
   433 	                            bitmap,
       
   434 	                            bitmapMask,
       
   435 	                            fileName,
       
   436 	                            bmpID,
       
   437 	                            bmpMaskID ) );
       
   438 	
       
   439 		
       
   440 	    EVTUIDEBUG1( "AknsUtils::CreateIconL - %d", err );
       
   441 	    if(err != KErrNone)
       
   442 		    {
       
   443 		    TRAP( err, AknIconUtils::CreateIconL( bitmap,
       
   444 		                            bitmapMask,
       
   445 		                            fileName,
       
   446 		                            bmpID,
       
   447 		                            bmpMaskID ) );
       
   448 	    	EVTUIDEBUG1( "AknIconUtils::CreateIconL - %d", err );
       
   449 		    }
       
   450 		    
       
   451     	User::LeaveIfError( err );
       
   452     	
       
   453         EVTUIDEBUG( "Bitmap validation" )
       
   454         
       
   455         User::LeaveIfNull( bitmap );
       
   456         
       
   457         EVTUIDEBUG( "Mask validation" )
       
   458         User::LeaveIfNull( bitmapMask );               
       
   459 
       
   460 	    CleanupStack::PushL( bitmap );
       
   461 	    CleanupStack::PushL( bitmapMask );
       
   462 
       
   463 		CEikImage*  image = new ( ELeave ) CEikImage;
       
   464 		CleanupStack::PushL( image );
       
   465 		
       
   466 		EVTUIDEBUG( "Settings image" )
       
   467 		image->SetPicture( bitmap, bitmapMask );
       
   468 		
       
   469 		control->SetImageL( image );
       
   470     			        
       
   471         // Set the image			    		
       
   472 	    // control->SetImageL( fileName, EMbmAvkonQgn_note_query, EMbmAvkonQgn_note_query_mask );
       
   473 	    
       
   474 		CleanupStack::Pop( 3 );	    
       
   475         }
       
   476         
       
   477     EVTUIDEBUG( "- CEvtInfoNoteImpl::LoadImageL" )      
       
   478     }
       
   479 
       
   480 // ---------------------------------------------------------------------------
       
   481 // CEvtInfoNoteImpl::TickL()
       
   482 // ---------------------------------------------------------------------------
       
   483 //
       
   484 TInt CEvtInfoNoteImpl::TickL(TAny* aObject)
       
   485     {
       
   486     ((CEvtInfoNoteImpl*)aObject)->TryExitL(EEvtCmdSnoozeEvent);
       
   487     return KErrNone;
       
   488     }
       
   489     
       
   490 // ---------------------------------------------------------------------------
       
   491 // void CEvtInfoNoteImpl::HandlePointerEventL()
       
   492 // ---------------------------------------------------------------------------
       
   493 //  
       
   494 void CEvtInfoNoteImpl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   495     {
       
   496     CEikDialog::HandlePointerEventL( aPointerEvent );      
       
   497         if(aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   498            {
       
   499            TryExitL(EAknSoftkeyContextOptions);
       
   500            }
       
   501     }
       
   502