srsf/vcommandexecutor/src/nssvcapplauncher.cpp
branchRCL_3
changeset 19 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
18:cad71a31b7fc 19:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  This is an implementation class for checking which 
       
    15 *               application or profile needs to be activated and then
       
    16 *               Starts it.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "rubydebug.h"
       
    23 #include "nssvcapplauncher.h"
       
    24 #include "nssvcapplauncher.hrh"
       
    25 #include "nssvcapplauncherconstants.h"
       
    26 #include <etel.h>
       
    27 #include <etelmm.h>
       
    28 #include <commdb.h>
       
    29 #include <apgtask.h>     // TApaTask, TApaTaskList
       
    30 #include <apacmdln.h>    // CApaCommandLine
       
    31 #include <e32def.h>
       
    32 #include <f32file.h>     // RFs
       
    33 #include <bautils.h>     // BaflUtils
       
    34 #include <RemConExtensionApi.h>
       
    35 #include <remconinterfaceselector.h>
       
    36 #include <remconcoreapicontroller.h>
       
    37 
       
    38 
       
    39 #include <vcommandexecutor.rsg>
       
    40 
       
    41 #include <AknGlobalConfirmationQuery.h> // Confirmation query.
       
    42 
       
    43 // CONSTANTS
       
    44 
       
    45 _LIT( KPanicCategory, "VCommandExecutor" );
       
    46 //Command line parameter for launching calendar to day view
       
    47 _LIT16( KCalendarDayCmdLine, "DATE %d %d %d 08 00 00 000000" );
       
    48 //Command line parameter for launching calendar to week view
       
    49 _LIT16( KCalendarWeekCmdLine, "WEEK %d %d %d %d 00 00 000000" );
       
    50 //Command line parameter for launching calendar to month view
       
    51 _LIT16( KCalendarMonthCmdLine, "MONTH %d %d %d 08 00 00 000000" );
       
    52 // Command line parameter for Browser application for opening the browser
       
    53 // to start page
       
    54 _LIT16( KBrowserArgStartPage, "5" );
       
    55 
       
    56 // Battery charge level in percentage scaled to five values
       
    57 const TInt KBatteryFull = 85; // full >= 85
       
    58 const TInt KBatteryAlmostFull = 65; // 65 <= almost full < 85 
       
    59 const TInt KBatteryHalfFull = 35; // 35 <= half full < 65
       
    60 const TInt KBatteryAlmostEmpty = 15; // 15 <= almost empty < 35
       
    61 // low < 15
       
    62 
       
    63 // Signal strength level in seven bars scaled to five values
       
    64 const TInt KSignalExcellent = 6; // excellent >= 6
       
    65 const TInt KSignalGood = 5; // good == 5 
       
    66 const TInt KSignalRatherGood = 3; // 3 <= rather good < 5
       
    67 const TInt KSignalLow = 1; // 1 <= low < 3
       
    68 const TInt KSignalNone = 0;
       
    69 // low < 15
       
    70 
       
    71 // letters for drives in search order
       
    72 const TBuf<1> KResourceDrivers = _L("z"); 
       
    73 _LIT( KResourceDir, "\\resource\\" );
       
    74 _LIT( KResourceFileName, "VCommandExecutor.rsc" );
       
    75 
       
    76 // String from loc-file must be modified for TTime::FormatL function
       
    77 _LIT( KLocFileHourString, "%0N" );
       
    78 _LIT( KLocFileMinuteString, "%1N" );
       
    79 _LIT( KTTimeHourString, "%J");
       
    80 _LIT( KTTimeHourStringWithZero, "0%J");
       
    81 _LIT( KTTimeMinuteString, "%T");
       
    82 
       
    83 const TInt KDaysInAWeek = 7;
       
    84 
       
    85 
       
    86 // ================= MEMBER FUNCTIONS =======================
       
    87 
       
    88 // C++ default constructor can NOT contain any code, that
       
    89 // might leave.
       
    90 //
       
    91 CNssVCAppLauncher::CNssVCAppLauncher()
       
    92     {
       
    93     }
       
    94 
       
    95 // Destructor
       
    96 CNssVCAppLauncher::~CNssVCAppLauncher()
       
    97     {
       
    98     
       
    99     if ( iApaLsSession )
       
   100         {
       
   101         iApaLsSession->Close();
       
   102         delete iApaLsSession;
       
   103         iApaLsSession = NULL;
       
   104         }
       
   105     if ( iTts )
       
   106         {
       
   107         delete iTts;
       
   108         iTts = NULL;
       
   109         }
       
   110     if ( iParsedText )
       
   111         {
       
   112         delete iParsedText;
       
   113         iParsedText = NULL;
       
   114         }
       
   115     if ( iStatusInfo )
       
   116         {
       
   117         delete iStatusInfo;
       
   118         iStatusInfo = NULL;
       
   119         }
       
   120     }
       
   121 
       
   122 // ----------------------------------------------------------------------------
       
   123 // CNssVCAppLauncher::ConstructL
       
   124 // Symbian 2nd phase constructor
       
   125 // ----------------------------------------------------------------------------
       
   126 //
       
   127 void CNssVCAppLauncher::ConstructL()
       
   128     {
       
   129     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::ConstructL" );
       
   130     }
       
   131 
       
   132 
       
   133 
       
   134 // ----------------------------------------------------------------------------
       
   135 // CNssVCAppLauncher* CNssVCAppLauncher::NewL
       
   136 // Two-phased constructor.
       
   137 // ----------------------------------------------------------------------------
       
   138 //
       
   139 CNssVCAppLauncher* CNssVCAppLauncher::NewL()                                                           
       
   140     {
       
   141     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::NewL" );
       
   142     
       
   143     CNssVCAppLauncher* self= new (ELeave) CNssVCAppLauncher();
       
   144     CleanupStack::PushL(self);
       
   145     self->ConstructL();
       
   146     CleanupStack::Pop();
       
   147     return self;
       
   148     }
       
   149 
       
   150 
       
   151 // ----------------------------------------------------------------------------
       
   152 // CNssVCAppLauncher::ExecuteCommandL
       
   153 // Checks the id and calls the appropriate function.
       
   154 // ----------------------------------------------------------------------------
       
   155 //
       
   156 TInt CNssVCAppLauncher::ExecuteCommandL( TUint aCommandId )
       
   157     {
       
   158     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::ExecuteCommandL" );
       
   159     
       
   160     TInt err = KErrNone;
       
   161 
       
   162 	switch( aCommandId )
       
   163 		{
       
   164 		case ECalendar:
       
   165 			ActivateAppL( KUidAppCalendar );
       
   166 			break;
       
   167 			
       
   168         case ECalendarToday:
       
   169 			CalendarDayViewL( EToday );
       
   170 			break;
       
   171 			
       
   172         case ECalendarTomorrow:
       
   173 			CalendarDayViewL( ETomorrow );
       
   174 			break;
       
   175 			
       
   176         case ECalendarMonday:
       
   177 			CalendarDayViewL( EMonday );
       
   178 			break;
       
   179 			
       
   180         case ECalendarTuesday:
       
   181 			CalendarDayViewL( ETuesday );
       
   182 			break;
       
   183 			
       
   184         case ECalendarWednesday:
       
   185 			CalendarDayViewL( EWednesday );
       
   186 			break;
       
   187 			
       
   188         case ECalendarThursday:
       
   189 			CalendarDayViewL( EThursday );
       
   190 			break;
       
   191 			
       
   192         case ECalendarFriday:
       
   193 			CalendarDayViewL( EFriday );
       
   194 			break;
       
   195 			
       
   196         case ECalendarSaturday:
       
   197 			CalendarDayViewL( ESaturday );
       
   198 			break;
       
   199 			
       
   200         case ECalendarSunday:
       
   201 			CalendarDayViewL( ESunday );
       
   202 			break;
       
   203 			
       
   204         case ECalendarThisWeek:
       
   205 			CalendarWeekViewL( EThisWeek );
       
   206 			break;
       
   207 			
       
   208         case ECalendarNextWeek:
       
   209 			CalendarWeekViewL( ENextWeek );
       
   210 			break;
       
   211 			
       
   212         case ECalendarThisMonth:
       
   213 			CalendarMonthViewL( EThisMonth );
       
   214 			break;
       
   215 			
       
   216         case ECalendarNextMonth:
       
   217 			CalendarMonthViewL( ENextMonth );
       
   218 			break;
       
   219 			
       
   220         case ECalendarJanuary:
       
   221 			CalendarMonthViewL( EJanuary );
       
   222 			break;
       
   223 			
       
   224         case ECalendarFebruary:
       
   225 			CalendarMonthViewL( EFebruary );
       
   226 			break;
       
   227 			
       
   228         case ECalendarMarch:
       
   229 			CalendarMonthViewL( EMarch );
       
   230 			break;
       
   231 			
       
   232         case ECalendarApril:
       
   233 			CalendarMonthViewL( EApril );
       
   234 			break;
       
   235 			
       
   236         case ECalendarMay:
       
   237 			CalendarMonthViewL( EMay );
       
   238 			break;
       
   239 			
       
   240         case ECalendarJune:
       
   241 			CalendarMonthViewL( EJune );
       
   242 			break;
       
   243 			
       
   244         case ECalendarJuly:
       
   245 			CalendarMonthViewL( EJuly );
       
   246 			break;
       
   247 			
       
   248         case ECalendarAugust:
       
   249 			CalendarMonthViewL( EAugust );
       
   250 			break;
       
   251 			
       
   252         case ECalendarSeptember:
       
   253 			CalendarMonthViewL( ESeptember );
       
   254 			break;
       
   255 			
       
   256         case ECalendarOctober:
       
   257 			CalendarMonthViewL( EOctober );
       
   258 			break;
       
   259 			
       
   260         case ECalendarNovember:
       
   261 			CalendarMonthViewL( ENovember );
       
   262 			break;
       
   263 			
       
   264         case ECalendarDecember:
       
   265 			CalendarMonthViewL( EDecember );
       
   266 			break;
       
   267 				
       
   268         case EStatusTime:
       
   269 		    StatusTimeL();
       
   270 		    break;
       
   271 		
       
   272         case EStatusOperator:
       
   273 		    StatusOperatorL();
       
   274 		    break;
       
   275 		    
       
   276         case EStatusBatteryStrength:
       
   277 		    StatusBatteryL();
       
   278 		    break;
       
   279 		    
       
   280         case EStatusSignalStrength:
       
   281 		    StatusSignalL();
       
   282 		    break;
       
   283 		    
       
   284         case EBrowser:
       
   285 		    ActivateAppL( KUidAppBrowser );
       
   286 		    break;
       
   287 		    
       
   288         /*case ESMSReader:
       
   289             ActivateAppL( KUidAppSMSReader );
       
   290             break;*/
       
   291         
       
   292         case EMediaPlay:
       
   293             ExecuteMediaCommandL( EMediaPlay );
       
   294             break;
       
   295             
       
   296         case EMediaStop:
       
   297             ExecuteMediaCommandL( EMediaStop );
       
   298             break;
       
   299             
       
   300         case EMediaPause:
       
   301             ExecuteMediaCommandL( EMediaPause );
       
   302             break;
       
   303             
       
   304         case EMediaNextSong:
       
   305             ExecuteMediaCommandL( EMediaNextSong );
       
   306             break;
       
   307             
       
   308         case EMediaNextChannel:
       
   309             ExecuteMediaCommandL( EMediaNextChannel );
       
   310             break;
       
   311             
       
   312         case EMediaPreviousSong:
       
   313             ExecuteMediaCommandL( EMediaPreviousSong );
       
   314             break;
       
   315             
       
   316         case EMediaPreviousChannel:
       
   317             ExecuteMediaCommandL( EMediaPreviousChannel );
       
   318             break;
       
   319             
       
   320         case EMediaVolumeUp:
       
   321             ExecuteMediaCommandL( EMediaVolumeUp );
       
   322             break;
       
   323        		
       
   324        case EMediaVolumeDown:
       
   325             ExecuteMediaCommandL( EMediaVolumeDown );
       
   326             break;
       
   327 
       
   328        		
       
   329 		default:
       
   330 			err = KErrNotSupported;
       
   331 			break;
       
   332 		}
       
   333 		
       
   334     return err;
       
   335     }
       
   336 
       
   337 // ----------------------------------------------------------------------------
       
   338 // CNssVCAppLauncher::CreateConnectionL
       
   339 // Connects to RApaLsSession.
       
   340 // ----------------------------------------------------------------------------
       
   341 //
       
   342 void CNssVCAppLauncher::CreateApaConnectionL()
       
   343     {
       
   344     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::CreateApaConnectionL" );
       
   345     
       
   346     iApaLsSession = new RApaLsSession();
       
   347        
       
   348     if ( !iApaLsSession->Handle() )
       
   349         {
       
   350         User::LeaveIfError( iApaLsSession->Connect() );
       
   351         }
       
   352     }
       
   353 
       
   354 // ----------------------------------------------------------------------------
       
   355 // CNssVCAppLauncher::ActivateAppL
       
   356 // Used to launch applications. Checks whether an instance of the launched
       
   357 // application is already running.
       
   358 // ----------------------------------------------------------------------------
       
   359 //
       
   360 void CNssVCAppLauncher::ActivateAppL( const TUid aUid,
       
   361                                       const TDesC16* aCmdLine,
       
   362                                       TBool aMultipleInstances )
       
   363     {
       
   364     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::ActivateAppL" );
       
   365     
       
   366     CreateApaConnectionL();
       
   367 
       
   368     if ( aMultipleInstances )
       
   369         {
       
   370         ActivateAppInstanceL( aUid );
       
   371         }
       
   372     else
       
   373         {
       
   374         // Session to window server
       
   375         RWsSession wsSession;
       
   376         User::LeaveIfError( wsSession.Connect() );
       
   377         
       
   378         TApaTaskList apaTaskList( wsSession );
       
   379         TApaTask apaTask = apaTaskList.FindApp( aUid );
       
   380         if ( apaTask.Exists() )
       
   381             {
       
   382             // Already running, close application
       
   383             apaTask.EndTask();
       
   384             }
       
   385         ActivateAppInstanceL( aUid, aCmdLine );
       
   386             
       
   387         wsSession.Close();
       
   388         }
       
   389     }
       
   390 
       
   391 // ----------------------------------------------------------------------------
       
   392 // CNssVCAppLauncher::ActivateAppInstanceL
       
   393 // Activates an instance of an application.
       
   394 // ----------------------------------------------------------------------------
       
   395 //
       
   396 void CNssVCAppLauncher::ActivateAppInstanceL( const TUid aUid, const TDesC16* aCmdLine )
       
   397     {
       
   398     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::ActivateAppInstanceL" );
       
   399     
       
   400 	TApaAppInfo appInfo;
       
   401     User::LeaveIfError( iApaLsSession->GetAppInfo( appInfo, aUid ) );
       
   402 	TFileName appName = appInfo.iFullName;
       
   403 	CApaCommandLine* apaCommandLine = CApaCommandLine::NewLC();
       
   404 
       
   405 	apaCommandLine->SetExecutableNameL( appName );
       
   406 	apaCommandLine->SetCommandL( EApaCommandRun );
       
   407 	if ( aCmdLine )
       
   408 	    {
       
   409 	    // copy the 16-bit data into 8-bit buffer
       
   410         HBufC8* paramBuf = HBufC8::NewLC( aCmdLine->Length() *2 );
       
   411         TPtr8 tailBuf = paramBuf->Des();
       
   412         tailBuf.Copy( reinterpret_cast<const TUint8*>( aCmdLine->Ptr() ), aCmdLine->Length() *2 );
       
   413 	    
       
   414 	    // Command line parameters
       
   415 	    apaCommandLine->SetTailEndL( tailBuf );
       
   416 	    
       
   417 	    CleanupStack::PopAndDestroy( paramBuf );
       
   418 	    }
       
   419 	
       
   420 	User::LeaveIfError ( iApaLsSession->StartApp( *apaCommandLine ) );
       
   421 	CleanupStack::PopAndDestroy( apaCommandLine );
       
   422 	}
       
   423     
       
   424 // ----------------------------------------------------------------------------
       
   425 // CNssVCAppLauncher::StatusTimeL
       
   426 // Provides the answer to the voice command "What time is it?"
       
   427 // ----------------------------------------------------------------------------
       
   428 //
       
   429 void CNssVCAppLauncher::StatusTimeL()
       
   430     {
       
   431     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::StatusTimeL" );
       
   432     
       
   433     TTime time;
       
   434     time.HomeTime();
       
   435     
       
   436     HBufC* timeStatusString = NULL;
       
   437     
       
   438     TLocale locale;
       
   439     if ( locale.TimeFormat() == ETime24 )
       
   440         {
       
   441         // "It is %N0:%N1"
       
   442         GetLocalizedStringL( ETime24Format, timeStatusString );
       
   443         }
       
   444     else // 12-hour format
       
   445         {
       
   446         TAmPm timeOfDay;
       
   447         GetAmOrPmL( time, timeOfDay );
       
   448         if ( timeOfDay == EAm )
       
   449             {
       
   450             // "It is %0N:%1N AM"
       
   451             GetLocalizedStringL( ETimeAm, timeStatusString );
       
   452             }
       
   453         else
       
   454             {
       
   455             // "It is %0N:%1N PM"
       
   456             GetLocalizedStringL( ETimePm, timeStatusString );
       
   457             }
       
   458         }
       
   459     
       
   460     CleanupStack::PushL( timeStatusString );
       
   461     // Modify timeStatusString for TTime:FormatL
       
   462     TInt index( KErrNotFound );
       
   463     index = timeStatusString->Find( KLocFileHourString );
       
   464     if( index != KErrNotFound )
       
   465         {
       
   466         // Hour
       
   467     	if ( locale.TimeFormat() == ETime12 && 
       
   468                  ( ( time.DateTime().Hour() > 0 && time.DateTime().Hour() < 10 ) || 
       
   469                  ( time.DateTime().Hour() > 12 && time.DateTime().Hour() < 22 ) ) )
       
   470     	    {
       
   471     	    timeStatusString->Des().Replace( index, KLocFileHourString.iTypeLength,
       
   472                                              KTTimeHourStringWithZero );
       
   473         	}
       
   474         else
       
   475         	{
       
   476         	timeStatusString->Des().Replace( index, KLocFileHourString.iTypeLength,
       
   477                                                  KTTimeHourString );
       
   478         	}
       
   479         }
       
   480     index = timeStatusString->Find( KLocFileMinuteString );
       
   481     if( index != KErrNotFound )
       
   482         {
       
   483         // Minute
       
   484         timeStatusString->Des().Replace( index, KLocFileMinuteString.iTypeLength,
       
   485                                          KTTimeMinuteString );
       
   486         }
       
   487     iStatusInfo = HBufC::NewL( timeStatusString->Length() );
       
   488     TBuf<256> string;
       
   489     time.FormatL( string, *timeStatusString );
       
   490     iStatusInfo->Des().Append( string );
       
   491     CleanupStack::PopAndDestroy( timeStatusString );
       
   492     
       
   493     PlaybackStatusInfoL();
       
   494     }
       
   495     
       
   496 // ----------------------------------------------------------------------------
       
   497 // CNssVCAppLauncher::StatusOperatorL
       
   498 // Provides the answer to the voice command "Who is my operator?"
       
   499 // ----------------------------------------------------------------------------
       
   500 //
       
   501 void CNssVCAppLauncher::StatusOperatorL()
       
   502     {
       
   503     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::StatusOperatorL" );
       
   504     
       
   505     // The operator
       
   506     TDesC* oper = NULL;
       
   507     HBufC* operStatusString = NULL;
       
   508     GetOperatorL( oper );
       
   509     
       
   510     if ( oper && oper->Length() > 0 )
       
   511         {
       
   512         CleanupStack::PushL( oper );
       
   513         // "Your operator is %U"
       
   514         GetLocalizedStringL( EOperator, operStatusString );
       
   515         CleanupStack::PushL( operStatusString );
       
   516         TInt index( -1 );
       
   517         index = operStatusString->Find( _L( "%U" ) );
       
   518         if( index > -1 )
       
   519            {
       
   520            operStatusString->Des().Replace( index, 2, _L( "%S" ) );
       
   521            }    
       
   522         iStatusInfo = HBufC::NewL( operStatusString->Length() * 2 ); // Just to be on the safe side
       
   523         iStatusInfo->Des().Format( operStatusString->Des(), oper );
       
   524         CleanupStack::PopAndDestroy( operStatusString );
       
   525         CleanupStack::PopAndDestroy( oper );
       
   526         }
       
   527     else
       
   528         {
       
   529         delete oper;
       
   530         // "Operator information not available"
       
   531         GetLocalizedStringL( EOperatorNotAvailable, operStatusString );
       
   532         CleanupStack::PushL( operStatusString );
       
   533         iStatusInfo = operStatusString->Des().Alloc();
       
   534         CleanupStack::PopAndDestroy( operStatusString );
       
   535         }
       
   536     PlaybackStatusInfoL();
       
   537     }
       
   538     
       
   539 // ----------------------------------------------------------------------------
       
   540 // CNssVCAppLauncher::StatusBatteryL
       
   541 // Provides the answer to the voice command "What is the battery strength?"
       
   542 // ----------------------------------------------------------------------------
       
   543 //
       
   544 void CNssVCAppLauncher::StatusBatteryL()
       
   545     {
       
   546     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::StatusBatteryL" );
       
   547     
       
   548     TSpokenStatusInfo battStrength;
       
   549     GetBatteryStrengthL( battStrength );
       
   550     
       
   551     HBufC* battStatusString;
       
   552     
       
   553     switch ( battStrength )
       
   554         {
       
   555         case EBatteryFull:
       
   556             // "The battery is full"
       
   557             GetLocalizedStringL( EBatteryFull, battStatusString );
       
   558             iStatusInfo = battStatusString;
       
   559             break;
       
   560             
       
   561         case EBattetteryAlmostFull:
       
   562             // "The battery is almost full"
       
   563             GetLocalizedStringL( EBattetteryAlmostFull, battStatusString );
       
   564             iStatusInfo = battStatusString;
       
   565             break;
       
   566             
       
   567         case EBatteryHalfFull:
       
   568             // "The battery is half full"
       
   569             GetLocalizedStringL( EBatteryHalfFull, battStatusString );
       
   570             iStatusInfo = battStatusString;
       
   571             break;
       
   572             
       
   573         case EBatteryAlmostEmpty:
       
   574             // "The battery is almost empty"
       
   575             GetLocalizedStringL( EBatteryAlmostEmpty, battStatusString );
       
   576             iStatusInfo = battStatusString;
       
   577             break;
       
   578             
       
   579         case EBatteryLow:
       
   580             // "The battery is low. Please recharge"
       
   581             GetLocalizedStringL( EBatteryLow, battStatusString );
       
   582             iStatusInfo = battStatusString;
       
   583             break;
       
   584             
       
   585         case EBatteryStrengthNotAvailable:
       
   586             // "Battery strength information not available"
       
   587             GetLocalizedStringL( EBatteryStrengthNotAvailable, battStatusString );
       
   588             iStatusInfo = battStatusString;
       
   589             break;
       
   590         }
       
   591         
       
   592     PlaybackStatusInfoL();
       
   593     }
       
   594     
       
   595 // ----------------------------------------------------------------------------
       
   596 // CNssVCAppLauncher::StatusSignalL
       
   597 // Provides the answer to the voice command "What is the signal strength?"
       
   598 // ----------------------------------------------------------------------------
       
   599 //
       
   600 void CNssVCAppLauncher::StatusSignalL()
       
   601     {
       
   602     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::StatusSignalL" );
       
   603     
       
   604     TSpokenStatusInfo signalStrength;
       
   605     GetSignalStrengthL( signalStrength );
       
   606     
       
   607     HBufC* signalStatusString;
       
   608     
       
   609     switch ( signalStrength )
       
   610         {
       
   611         case ESignalStrengthExcellent:
       
   612             // "The network strength is excellent"
       
   613             GetLocalizedStringL( ESignalStrengthExcellent, signalStatusString );
       
   614             iStatusInfo = signalStatusString;
       
   615             break;
       
   616             
       
   617         case ESignalStrengthGood:
       
   618             // "The network strength is good"
       
   619             GetLocalizedStringL( ESignalStrengthGood, signalStatusString );
       
   620             iStatusInfo = signalStatusString;
       
   621             break;
       
   622             
       
   623         case ESignalStrengthRatherGood:
       
   624             // "The network strength is rather good"
       
   625             GetLocalizedStringL( ESignalStrengthRatherGood, signalStatusString );
       
   626             iStatusInfo = signalStatusString;
       
   627             break;
       
   628             
       
   629         case ESignalStrengthLow:
       
   630             // "The network strength is low"
       
   631             GetLocalizedStringL( ESignalStrengthLow, signalStatusString );
       
   632             iStatusInfo = signalStatusString;
       
   633             break;
       
   634             
       
   635         case ESignalStrengthNoSignal:
       
   636             // "No network"
       
   637             GetLocalizedStringL( ESignalStrengthNoSignal, signalStatusString );
       
   638             iStatusInfo = signalStatusString;
       
   639             break;
       
   640             
       
   641         case ESignalStrengthNotAvailable:
       
   642             // "Signal strength information not available"
       
   643             GetLocalizedStringL( ESignalStrengthNotAvailable, signalStatusString );
       
   644             iStatusInfo = signalStatusString;
       
   645             break;
       
   646         }
       
   647         
       
   648     PlaybackStatusInfoL();
       
   649     }
       
   650 
       
   651 // ----------------------------------------------------------------------------
       
   652 // CNssVCAppLauncher::PlaybackStatusInfoL
       
   653 // Performs text to speech answer for a status query.
       
   654 // ----------------------------------------------------------------------------
       
   655 //
       
   656 void CNssVCAppLauncher::PlaybackStatusInfoL()
       
   657     {
       
   658     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::PlaybackStatusInfoL" );
       
   659     
       
   660     __ASSERT_ALWAYS( iStatusInfo,
       
   661                      User::Panic( KPanicCategory, KErrArgument ) );
       
   662                      
       
   663     RUBY_DEBUG1( "TTS text: \"%S\"", iStatusInfo );
       
   664     
       
   665     // TTS utility for playback
       
   666     iTts = CTtsUtility::NewL( *this );
       
   667     
       
   668     // Create TTS style with language + NLP on
       
   669     TTtsStyle style;
       
   670     style.iNlp = ETrue;
       
   671     style.iLanguage = User::Language();
       
   672     
       
   673     // Add style to TTS
       
   674     TTtsStyleID styleId = iTts->AddStyleL( style );
       
   675     
       
   676     // Segment
       
   677     TTtsSegment segment( styleId );
       
   678     
       
   679     // Parsed text
       
   680     iParsedText = CTtsParsedText::NewL();  
       
   681     iParsedText->SetTextL( *iStatusInfo );
       
   682     segment.SetTextPtr( iParsedText->Text() );
       
   683     iParsedText->AddSegmentL( segment );
       
   684         
       
   685     // Run synthesis
       
   686     iTts->OpenAndPlayParsedTextL( *iParsedText );
       
   687     
       
   688     if ( !iWait.IsStarted() )
       
   689         {
       
   690         iWait.Start();
       
   691         }
       
   692     }
       
   693     
       
   694 // -----------------------------------------------------------------------------
       
   695 // CNssVCAppLauncher::MapcPlayComplete
       
   696 // Callback, playback has been initialized.
       
   697 // -----------------------------------------------------------------------------
       
   698 //
       
   699 void CNssVCAppLauncher::MapcInitComplete( TInt aError,
       
   700                                           const TTimeIntervalMicroSeconds& /*aDuration*/ )
       
   701     {
       
   702     RUBY_DEBUG1( "CNssVCAppLauncher::MapcInitComplete [%d]", aError );
       
   703     
       
   704     if ( ( aError != KErrNone ) && ( iWait.IsStarted() ) )
       
   705         {
       
   706         iWait.AsyncStop();
       
   707         }
       
   708     }  
       
   709     
       
   710 // -----------------------------------------------------------------------------
       
   711 // CNssVCAppLauncher::MapcPlayComplete
       
   712 // Callback, playback has been completed.
       
   713 // -----------------------------------------------------------------------------
       
   714 //     
       
   715 #if defined(_DEBUG) && !defined(__RUBY_DEBUG_DISABLED)
       
   716 void CNssVCAppLauncher::MapcPlayComplete( TInt aError )
       
   717 #else
       
   718 void CNssVCAppLauncher::MapcPlayComplete( TInt /*aError*/ )
       
   719 #endif
       
   720     {
       
   721     RUBY_DEBUG1( "NssVCAppLauncher::MapcPlayComplete [%d]", aError );         
       
   722           
       
   723     if ( iTts )
       
   724         {
       
   725         iTts->Stop();
       
   726         iTts->Close();
       
   727         }
       
   728     if ( iWait.IsStarted() )
       
   729         {
       
   730         iWait.AsyncStop();
       
   731         }
       
   732     }
       
   733     
       
   734 // -----------------------------------------------------------------------------
       
   735 // CNssVCAppLauncher::GetAmOrPmL
       
   736 // Tells whether it is am or pm.
       
   737 // -----------------------------------------------------------------------------
       
   738 void CNssVCAppLauncher::GetAmOrPmL( const TTime& aTime, TAmPm& aTod )
       
   739     {
       
   740     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::GetAmOrPmL" );
       
   741     
       
   742     TTime time = aTime;
       
   743     // Add one day
       
   744     time += TTimeIntervalDays( 1 );
       
   745     // Copy to TDateTime object
       
   746     TDateTime dateTime = time.DateTime();
       
   747     // Set to midnight
       
   748     dateTime.SetHour( 0 );
       
   749     dateTime.SetMinute( 0 );
       
   750     dateTime.SetMicroSecond( 0 );
       
   751     // Copy to TTime object
       
   752     time = dateTime;
       
   753     
       
   754     TTimeIntervalHours hours;
       
   755     aTime.HoursFrom( time, hours );
       
   756     // Hours from midnight
       
   757     TInt hoursInt = hours.Int();
       
   758     if ( hours.Int() > -12 )
       
   759         {
       
   760         aTod = EPm;
       
   761         }
       
   762     else
       
   763         {
       
   764         aTod = EAm;
       
   765         }
       
   766     }
       
   767     
       
   768 // -----------------------------------------------------------------------------
       
   769 // CNssVCAppLauncher::GetOperatorL
       
   770 // Gets network operator's name.
       
   771 // -----------------------------------------------------------------------------
       
   772 void CNssVCAppLauncher::GetOperatorL( TDesC*& aOperator )
       
   773     {
       
   774     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::GetOperatorL" );
       
   775     
       
   776     TFileName tsyName;
       
   777     GetTSYNameL( tsyName );
       
   778     RTelServer server;
       
   779     User::LeaveIfError( server.Connect() );
       
   780     server.LoadPhoneModule( tsyName );
       
   781     
       
   782     RMobilePhone::TMobilePhoneNetworkInfoV1 networkInfo;
       
   783     RMobilePhone::TMobilePhoneNetworkInfoV1Pckg networkInfoPkg( networkInfo );
       
   784     RMobilePhone::TMobilePhoneLocationAreaV1 locationInfo;
       
   785 
       
   786     TRequestStatus reqStatus = KErrNone;
       
   787     RMobilePhone phone;
       
   788     RTelServer::TPhoneInfo info;
       
   789     User::LeaveIfError( server.GetPhoneInfo( 0, info ) );
       
   790     User::LeaveIfError( phone.Open( server, info.iName ) );
       
   791     phone.GetCurrentNetwork( reqStatus, networkInfoPkg, locationInfo );
       
   792     
       
   793     User::WaitForRequest( reqStatus );
       
   794     if( reqStatus == KErrNone )
       
   795         {
       
   796         TBuf<256> networkName;
       
   797         networkName.Copy( networkInfo.iLongName );
       
   798         HBufC* oper = networkName.AllocL();
       
   799         aOperator = oper;
       
   800         }
       
   801         
       
   802     phone.Close(); 
       
   803     server.UnloadPhoneModule( tsyName );
       
   804     server.Close();
       
   805     }
       
   806     
       
   807 // -----------------------------------------------------------------------------
       
   808 // CNssVCAppLauncher::GetBatteryStrengthL
       
   809 // Gets the battery strength.
       
   810 // -----------------------------------------------------------------------------
       
   811 void CNssVCAppLauncher::GetBatteryStrengthL( TSpokenStatusInfo& aBattStrength )
       
   812     {
       
   813     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::GetBatteryStrengthL" );
       
   814     
       
   815     aBattStrength = EBatteryStrengthNotAvailable;
       
   816     
       
   817     TFileName tsyName;
       
   818     GetTSYNameL( tsyName );
       
   819     RTelServer server;
       
   820     User::LeaveIfError( server.Connect() );
       
   821     server.LoadPhoneModule( tsyName );
       
   822     
       
   823     TRequestStatus reqStatus = KErrNone;
       
   824     RMobilePhone phone;
       
   825     RTelServer::TPhoneInfo info;
       
   826     User::LeaveIfError( server.GetPhoneInfo( 0, info ) );
       
   827     User::LeaveIfError( phone.Open( server, info.iName ) );
       
   828     
       
   829     TUint32 batteryCaps;
       
   830     // Test if battery strength can be obtained
       
   831     if ( phone.GetBatteryCaps( batteryCaps ) != KErrNone )
       
   832         {
       
   833         return;
       
   834         }
       
   835 
       
   836     TInt charge = -1;
       
   837     if ( batteryCaps & RMobilePhone::KCapsGetBatteryInfo )
       
   838         {
       
   839         RMobilePhone::TMobilePhoneBatteryInfoV1 mobilePhoneBatteryInfo;
       
   840         TRequestStatus status;
       
   841         phone.GetBatteryInfo( status, mobilePhoneBatteryInfo );
       
   842         User::WaitForRequest( status );
       
   843         User::LeaveIfError( status.Int() );
       
   844         if ( mobilePhoneBatteryInfo.iStatus == RMobilePhone::EPoweredByBattery )
       
   845             {
       
   846             // The percentage battery charge level
       
   847             charge = mobilePhoneBatteryInfo.iChargeLevel;
       
   848             if ( charge >= KBatteryFull )
       
   849                 {
       
   850                 aBattStrength = EBatteryFull;
       
   851                 }
       
   852             else if ( charge >= KBatteryAlmostFull )
       
   853                 {
       
   854                 aBattStrength = EBattetteryAlmostFull;
       
   855                 }
       
   856             else if ( charge >= KBatteryHalfFull )
       
   857                 {
       
   858                 aBattStrength = EBatteryHalfFull;
       
   859                 }
       
   860             else if ( charge >= KBatteryAlmostEmpty )
       
   861                 {
       
   862                 aBattStrength = EBatteryAlmostEmpty;
       
   863                 }
       
   864             else
       
   865                 {
       
   866                 aBattStrength = EBatteryLow;
       
   867                 }
       
   868             }
       
   869         }
       
   870         //else BATTERY INFO NOT AVAILABLE
       
   871         
       
   872     phone.Close(); 
       
   873     server.UnloadPhoneModule( tsyName );
       
   874     server.Close();
       
   875     }
       
   876     
       
   877 // -----------------------------------------------------------------------------
       
   878 // CNssVCAppLauncher::GetSignalStrengthL
       
   879 // Gets the signal strength.
       
   880 // -----------------------------------------------------------------------------
       
   881 void CNssVCAppLauncher::GetSignalStrengthL( TSpokenStatusInfo& aSignalStrength )
       
   882     {
       
   883     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::GetSignalStrengthL" );
       
   884     
       
   885     aSignalStrength = ESignalStrengthNotAvailable;
       
   886     
       
   887     TFileName tsyName;
       
   888     GetTSYNameL( tsyName );
       
   889     RTelServer server;
       
   890     User::LeaveIfError( server.Connect() );
       
   891     server.LoadPhoneModule( tsyName );
       
   892 
       
   893     RMobilePhone phone;
       
   894     RTelServer::TPhoneInfo info;
       
   895     User::LeaveIfError( server.GetPhoneInfo( 0, info ) );
       
   896     User::LeaveIfError( phone.Open( server, info.iName ) );
       
   897     
       
   898     TUint32 signalCaps;
       
   899     // Test if signal information can be obtained
       
   900     User::LeaveIfError( phone.GetSignalCaps( signalCaps ) );
       
   901 
       
   902     TInt32 signalStrength = -1;
       
   903     TInt8 bars = -1;
       
   904     if ( signalCaps & RMobilePhone::KCapsGetSignalStrength )
       
   905         {
       
   906         TRequestStatus status = KErrNone;
       
   907         phone.GetSignalStrength( status, signalStrength, bars );
       
   908         User::WaitForRequest( status );
       
   909         RUBY_DEBUG1( "Signal strength in dBm: %d", signalStrength );
       
   910         RUBY_DEBUG1( "Number of signal bars: %d", bars );
       
   911         if ( bars >= KSignalExcellent )
       
   912             {
       
   913             aSignalStrength = ESignalStrengthExcellent;
       
   914             }
       
   915         else if ( bars == KSignalGood )
       
   916             {
       
   917             aSignalStrength = ESignalStrengthGood;
       
   918             }
       
   919         else if ( bars >= KSignalRatherGood )
       
   920             {
       
   921             aSignalStrength = ESignalStrengthRatherGood;
       
   922             }
       
   923         else if ( bars >= KSignalLow )
       
   924             {
       
   925             aSignalStrength = ESignalStrengthLow;
       
   926             }
       
   927         else if ( bars == KSignalNone )
       
   928             {
       
   929             aSignalStrength = ESignalStrengthNoSignal;
       
   930             }
       
   931         }
       
   932     
       
   933     phone.Close(); 
       
   934     server.UnloadPhoneModule( tsyName );
       
   935     server.Close();
       
   936     }
       
   937     
       
   938 // -----------------------------------------------------------------------------
       
   939 // CNssVCAppLauncher::CalendarDayViewL
       
   940 // Activates calendars day view.
       
   941 // -----------------------------------------------------------------------------
       
   942 void CNssVCAppLauncher::CalendarDayViewL( const TInt aDay )
       
   943     {
       
   944     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::CalendarDayViewL" );
       
   945     
       
   946     __ASSERT_ALWAYS( aDay >= EMonday && aDay <= ETomorrow,
       
   947                      User::Panic( KPanicCategory, KErrArgument ) );
       
   948     
       
   949     TTime time;
       
   950     // Current date
       
   951     time.HomeTime();
       
   952     TDateTime dateTime = time.DateTime();
       
   953     // TTime::DayNoInMonth()'s first day in month is zero
       
   954     const TInt KCurrentDayInMonth = time.DayNoInMonth() + 1;
       
   955     const TInt KCurrentDayInWeek = time.DayNoInWeek();
       
   956     const TInt KCurrentMonth = dateTime.Month();
       
   957     const TInt KCurrentYear = dateTime.Year();
       
   958     // Variables used to form parameters for calendar launching
       
   959     TInt day = KCurrentDayInMonth;
       
   960     TInt month = KCurrentMonth;
       
   961     TInt year = KCurrentYear;
       
   962     
       
   963     // Command for weekday
       
   964     if( aDay >= EMonday && aDay <= ESunday )
       
   965         {
       
   966         if ( KCurrentDayInWeek <= aDay )
       
   967             {
       
   968             // Depend on existing enum values, not good
       
   969             day += aDay - KCurrentDayInWeek; 
       
   970             }
       
   971         else if ( KCurrentDayInWeek > aDay )
       
   972             {
       
   973             // Depend on existing enum values, not good
       
   974             // Go to monday of next week and add whatever is necessery
       
   975             day += KDaysInAWeek - KCurrentDayInWeek + aDay;
       
   976             }
       
   977         
       
   978         // Month changes
       
   979         if ( day > time.DaysInMonth() )
       
   980             {
       
   981             day -= time.DaysInMonth();
       
   982             // Year changes
       
   983             if ( month == EDecember )
       
   984                 {
       
   985                 month = EJanuary;
       
   986                 year++;
       
   987                 }
       
   988             else
       
   989                 {
       
   990                 month++;
       
   991                 }
       
   992             }
       
   993         }
       
   994    // Command for tomorrow     
       
   995    else if ( aDay == ETomorrow )
       
   996         {
       
   997         day++;
       
   998         // Month changes
       
   999         if ( day > time.DaysInMonth() )
       
  1000             {
       
  1001             // First day
       
  1002             day = 1;
       
  1003             month++;
       
  1004             
       
  1005             // Year changes
       
  1006             if ( KCurrentMonth == EDecember )
       
  1007                 {
       
  1008                 month = EJanuary;
       
  1009                 year++;
       
  1010                 }
       
  1011             }
       
  1012         }
       
  1013     
       
  1014     // Offset for TMonth is zero, so we add one
       
  1015     month++; 
       
  1016     
       
  1017     HBufC16* cmdLine = HBufC16::NewLC( KCalendarDayCmdLine().Length() * 2 ); // Just to be on the safe side
       
  1018     cmdLine->Des().Format( KCalendarDayCmdLine, year, month, day );
       
  1019     
       
  1020     // Launch calendar
       
  1021     ActivateAppL( KUidAppCalendar, cmdLine );
       
  1022     
       
  1023     CleanupStack::PopAndDestroy( cmdLine );
       
  1024     }
       
  1025     
       
  1026 // -----------------------------------------------------------------------------
       
  1027 // CNssVCAppLauncher::CalendarWeekViewL
       
  1028 // Launches calendars week view to a selected week.
       
  1029 // -----------------------------------------------------------------------------
       
  1030 void CNssVCAppLauncher::CalendarWeekViewL( const TInt aWeek )
       
  1031     {
       
  1032     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::CalendarWeekViewL" );
       
  1033     
       
  1034     __ASSERT_ALWAYS( aWeek == EThisWeek || aWeek == ENextWeek,
       
  1035                      User::Panic( KPanicCategory, KErrArgument ) );
       
  1036     
       
  1037     TLocale locale;
       
  1038     TTime time;
       
  1039     // Current date
       
  1040     time.HomeTime();
       
  1041     TDateTime dateTime = time.DateTime();
       
  1042     // TTime::DayNoInMonth()'s first day in month is zero
       
  1043     const TInt KCurrentDayInMonth = time.DayNoInMonth() + 1;
       
  1044     // According to documentation, TTime::DayNoInWeek() should honour the 
       
  1045     // setting specified in TLocale::SetStartOfWeek(). It doesn't though.
       
  1046     TInt currentDayInWeek;
       
  1047     if( time.DayNoInWeek() >= locale.StartOfWeek() )
       
  1048         {
       
  1049         currentDayInWeek = time.DayNoInWeek() - locale.StartOfWeek() ;
       
  1050         }
       
  1051     else
       
  1052         {
       
  1053         currentDayInWeek = KDaysInAWeek - locale.StartOfWeek() + time.DayNoInWeek();
       
  1054         }
       
  1055     const TInt KCurrentDayInWeek = currentDayInWeek;
       
  1056     const TInt KCurrentMonth = dateTime.Month();
       
  1057     const TInt KCurrentYear = dateTime.Year();
       
  1058     // Variables used to form parameters for calendar launching
       
  1059     TInt year = KCurrentYear;
       
  1060     TInt month = KCurrentMonth;
       
  1061     TInt day = KCurrentDayInMonth;
       
  1062     TInt hour = dateTime.Hour();
       
  1063     
       
  1064     if ( aWeek == ENextWeek )
       
  1065         {
       
  1066         // 8 am
       
  1067         hour = 8;
       
  1068         // Go to the first day of next week
       
  1069         day += KDaysInAWeek - KCurrentDayInWeek;
       
  1070         
       
  1071         // Month changes
       
  1072         if( day > time.DaysInMonth() )
       
  1073             {
       
  1074             day -= time.DaysInMonth();
       
  1075             month++;
       
  1076             
       
  1077             // Year changes
       
  1078             if ( KCurrentMonth == EDecember )
       
  1079                 {
       
  1080                 year++;
       
  1081                 month = EJanuary;
       
  1082                 }
       
  1083             }
       
  1084         }
       
  1085         
       
  1086     // Offset for TMonth is zero, so we add one
       
  1087     month++;
       
  1088     
       
  1089     HBufC16* cmdLine = HBufC16::NewLC( KCalendarWeekCmdLine().Length() * 2 ); // Just to be on the safe side
       
  1090     cmdLine->Des().Format( KCalendarWeekCmdLine, year, month, day, hour );
       
  1091     
       
  1092     // Launch calendar
       
  1093     ActivateAppL( KUidAppCalendar, cmdLine );
       
  1094     
       
  1095     CleanupStack::PopAndDestroy( cmdLine );
       
  1096     }
       
  1097         
       
  1098 // -----------------------------------------------------------------------------
       
  1099 // CNssVCAppLauncher::CalendarMonthViewL
       
  1100 // Launches calendars month view to a selected month.
       
  1101 // -----------------------------------------------------------------------------
       
  1102 void CNssVCAppLauncher::CalendarMonthViewL( const TInt aMonth )
       
  1103     {
       
  1104     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::CalendarMonthViewL" );
       
  1105     
       
  1106     __ASSERT_ALWAYS( aMonth >= EMonday && aMonth <= ENextMonth,
       
  1107                      User::Panic( KPanicCategory, KErrArgument ) );
       
  1108                      
       
  1109     TTime time;
       
  1110     // Current date
       
  1111     time.HomeTime();
       
  1112     TDateTime dateTime = time.DateTime();
       
  1113     const TInt KCurrentMonth = dateTime.Month();
       
  1114     // Variables used to form parameters for calendar launching
       
  1115     TInt year = dateTime.Year();
       
  1116     TInt month = KCurrentMonth;
       
  1117     // TDateTime::Day() offset is zero
       
  1118     TInt day = dateTime.Day() + 1;
       
  1119     
       
  1120     if ( aMonth >= EJanuary && aMonth <= EDecember )
       
  1121         {
       
  1122         if( aMonth != KCurrentMonth )
       
  1123             {
       
  1124             day = 1;
       
  1125             }
       
  1126         month = aMonth;
       
  1127         // If the requested month is already past for this year
       
  1128         // month view is openend for next year. 
       
  1129         if ( aMonth < KCurrentMonth )
       
  1130             {
       
  1131             year++;
       
  1132             }
       
  1133         }
       
  1134     else if ( aMonth == ENextMonth )
       
  1135         {
       
  1136         day = 1;
       
  1137         if ( KCurrentMonth == EDecember )
       
  1138             {
       
  1139             year++;
       
  1140             month = EJanuary;
       
  1141             }
       
  1142         else
       
  1143             {
       
  1144             month++;
       
  1145             }
       
  1146         }
       
  1147         
       
  1148     // Offset for TMonth is zero, so we add one
       
  1149     month++;    
       
  1150     
       
  1151     HBufC16* cmdLine = HBufC16::NewLC( KCalendarMonthCmdLine().Length() * 2 ); // Just to be on the safe side
       
  1152     cmdLine->Des().Format( KCalendarMonthCmdLine, year, month, day );
       
  1153     
       
  1154     // Launch calendar
       
  1155     ActivateAppL( KUidAppCalendar, cmdLine );
       
  1156     
       
  1157     CleanupStack::PopAndDestroy( cmdLine );
       
  1158     }
       
  1159 
       
  1160 // -----------------------------------------------------------------------------
       
  1161 // CNssVCAppLauncher::GetOpenHomepageL
       
  1162 // Opens browser with the user defined homepage.
       
  1163 // ----------------------------------------------------------------------------- 
       
  1164 void CNssVCAppLauncher::OpenHomepageL()
       
  1165     {
       
  1166     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::OpenHomepageL" );
       
  1167     
       
  1168     // Command line parameter for starting the browser with start page
       
  1169     HBufC16* cmdLine = KBrowserArgStartPage().AllocLC();
       
  1170     
       
  1171     // Launch browser
       
  1172     ActivateAppL( KUidAppBrowser, cmdLine );
       
  1173     
       
  1174     CleanupStack::PopAndDestroy( cmdLine );
       
  1175     }
       
  1176 
       
  1177 // -----------------------------------------------------------------------------
       
  1178 // CNssVCAppLauncher::GetTSYNameL
       
  1179 // Gets the name of the currently selected TSY.
       
  1180 // -----------------------------------------------------------------------------    
       
  1181 void CNssVCAppLauncher::GetTSYNameL( TDes& aTSYName )
       
  1182     {
       
  1183     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::GetTSYNameL" );
       
  1184     
       
  1185     CCommsDatabase* const db = CCommsDatabase::NewL( EDatabaseTypeUnspecified );
       
  1186     CleanupStack::PushL( db );
       
  1187     TUint32 modemId = 0;
       
  1188     db->GetGlobalSettingL( TPtrC( MODEM_PHONE_SERVICES_SMS ), modemId );
       
  1189     CCommsDbTableView* const view
       
  1190         = db->OpenViewMatchingUintLC( TPtrC( MODEM ), TPtrC( COMMDB_ID ),
       
  1191                                       modemId );
       
  1192     TInt err = view->GotoFirstRecord();
       
  1193     User::LeaveIfError( err );
       
  1194     view->ReadTextL( TPtrC( MODEM_TSY_NAME ), aTSYName );
       
  1195     CleanupStack::PopAndDestroy( view );
       
  1196     CleanupStack::PopAndDestroy( db );
       
  1197     }
       
  1198     
       
  1199 // -----------------------------------------------------------------------------
       
  1200 // CNssVCAppLauncher::ExecuteMediaCommandL
       
  1201 // Executes a media command using Symbian Remote Control FW.
       
  1202 // -----------------------------------------------------------------------------
       
  1203 void CNssVCAppLauncher::ExecuteMediaCommandL( TUint aMediaCommandId )
       
  1204     {
       
  1205     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::ExecuteMediaCommandL" );
       
  1206     
       
  1207     __ASSERT_ALWAYS( aMediaCommandId >= EMediaPlay &&
       
  1208                      aMediaCommandId <= EMediaVolumeDown,
       
  1209                      User::Panic( KPanicCategory, KErrArgument ) );
       
  1210     
       
  1211     CRemConInterfaceSelector* interfaceSelector
       
  1212         = CRemConInterfaceSelector::NewL();
       
  1213     
       
  1214     // Owned by interfaceSelector
       
  1215     CRemConCoreApiController* coreIf
       
  1216         = CRemConCoreApiController::NewL( *interfaceSelector, *this );
       
  1217     
       
  1218     interfaceSelector->OpenControllerL();
       
  1219     
       
  1220     TRemConAddress addr;
       
  1221     addr.BearerUid() = KUidVCExecutorBearer;
       
  1222     // No bearer-specific connection data
       
  1223     interfaceSelector->GoConnectionOrientedL( addr );
       
  1224         
       
  1225     TRequestStatus status;
       
  1226     
       
  1227     interfaceSelector->ConnectBearer( status );
       
  1228     User::WaitForRequest( status );    
       
  1229     
       
  1230     TUint numRemotes;
       
  1231     
       
  1232     switch ( aMediaCommandId )
       
  1233         {
       
  1234         // TODO: remove User::After calls. They are for testing purposes only.
       
  1235         case EMediaPlay:
       
  1236             coreIf->PausePlayFunction( status, numRemotes,
       
  1237                                        ERemConCoreApiButtonPress );
       
  1238             User::WaitForRequest( status );
       
  1239             break;
       
  1240          
       
  1241         case EMediaPause:
       
  1242             coreIf->Pause( status, numRemotes, ERemConCoreApiButtonClick );
       
  1243             User::WaitForRequest( status );
       
  1244             break;
       
  1245         
       
  1246         case EMediaStop:
       
  1247             coreIf->Stop( status, numRemotes, ERemConCoreApiButtonClick );
       
  1248             User::WaitForRequest( status );
       
  1249             break;    
       
  1250        
       
  1251         case EMediaNextSong:
       
  1252             coreIf->Forward( status, numRemotes, ERemConCoreApiButtonClick );
       
  1253             User::WaitForRequest( status );
       
  1254             break;
       
  1255             
       
  1256         case EMediaNextChannel:
       
  1257             coreIf->Forward( status, numRemotes, ERemConCoreApiButtonClick );
       
  1258             User::WaitForRequest( status );
       
  1259             break;
       
  1260             
       
  1261         case EMediaPreviousSong:
       
  1262             coreIf->Backward( status, numRemotes, ERemConCoreApiButtonClick );
       
  1263             User::WaitForRequest( status );
       
  1264             break;
       
  1265             
       
  1266         case EMediaPreviousChannel:
       
  1267             coreIf->Backward( status, numRemotes, ERemConCoreApiButtonClick );
       
  1268             User::WaitForRequest( status );
       
  1269             break;
       
  1270             
       
  1271         case EMediaChannelUp:
       
  1272             coreIf->ChannelUp( status, numRemotes, ERemConCoreApiButtonClick );
       
  1273             User::WaitForRequest( status );
       
  1274             break;
       
  1275             
       
  1276         case EMediaChannelDown:
       
  1277             coreIf->ChannelDown( status, numRemotes,
       
  1278                                  ERemConCoreApiButtonClick );
       
  1279             User::WaitForRequest( status );
       
  1280             break;
       
  1281             
       
  1282         case EMediaVolumeUp:
       
  1283             coreIf->VolumeUp( status, numRemotes, ERemConCoreApiButtonClick );
       
  1284             User::WaitForRequest( status );
       
  1285             break;
       
  1286             
       
  1287         case EMediaVolumeDown:
       
  1288             coreIf->VolumeDown( status, numRemotes, ERemConCoreApiButtonClick );
       
  1289             User::WaitForRequest( status );
       
  1290             break;
       
  1291         }
       
  1292     
       
  1293     delete interfaceSelector;
       
  1294     interfaceSelector = NULL;
       
  1295     }
       
  1296 
       
  1297 // -----------------------------------------------------------------------------
       
  1298 // CNssVCAppLauncher::MrccacoResponse
       
  1299 // Called by RemCon as a response for a remote control command sent by this
       
  1300 // RemCon controller client
       
  1301 // -----------------------------------------------------------------------------
       
  1302 void CNssVCAppLauncher::MrccacoResponse( TRemConCoreApiOperationId /*aOperationId*/,
       
  1303                                          TInt /*aError*/ )
       
  1304     {
       
  1305     // Nothing
       
  1306     }
       
  1307 
       
  1308 // -----------------------------------------------------------------------------
       
  1309 // CNssVCAppLauncher::GetLocalizedStringL
       
  1310 // Gets localized string from the resource file for text-to-speech status info.
       
  1311 // -----------------------------------------------------------------------------    
       
  1312     
       
  1313 void CNssVCAppLauncher::GetLocalizedStringL( TSpokenStatusInfo aStringId,
       
  1314                                              HBufC*& aString )
       
  1315     {
       
  1316     RUBY_DEBUG_BLOCKL( "CNssVCAppLauncher::GetLocalizedStringL" );
       
  1317     
       
  1318     __ASSERT_ALWAYS( aStringId >= ETime24Format &&
       
  1319                      aStringId <= ESignalStrengthNotAvailable, 
       
  1320                      User::Panic( KPanicCategory, KErrArgument ) );
       
  1321     
       
  1322     // load resources
       
  1323     RResourceFile resourceFile;
       
  1324     RFs fileServer;
       
  1325     TBool found( EFalse );
       
  1326     User::LeaveIfError( fileServer.Connect() );
       
  1327     CleanupClosePushL( fileServer );
       
  1328     
       
  1329     // try finding a localized or default resource file browsing through the drivers 
       
  1330     TFileName name;
       
  1331     TInt i( 0 );
       
  1332     // use the first drive
       
  1333     name.Append( KResourceDrivers[i] );
       
  1334     name.Append( ':' );
       
  1335     name.Append( KResourceDir );
       
  1336     name.Append( KResourceFileName );
       
  1337 
       
  1338     while ( !found && i < KResourceDrivers.Length() )
       
  1339         {
       
  1340         name[0] = KResourceDrivers[i++];
       
  1341 
       
  1342         BaflUtils::NearestLanguageFile( fileServer, name );
       
  1343        
       
  1344         if ( BaflUtils::FileExists(fileServer, name) )
       
  1345             {
       
  1346             // open resource
       
  1347             resourceFile.OpenL( fileServer, name );
       
  1348             CleanupClosePushL( resourceFile );
       
  1349             resourceFile.ConfirmSignatureL();
       
  1350             found = ETrue;
       
  1351             }
       
  1352         }
       
  1353 
       
  1354     if ( !found )
       
  1355         {
       
  1356         User::Leave( KErrNotFound );
       
  1357         }
       
  1358         
       
  1359     TResourceReader reader;
       
  1360     
       
  1361     // Get correct localized string    
       
  1362     switch ( aStringId )
       
  1363         {
       
  1364         case ETime24Format:
       
  1365         reader.SetBuffer( resourceFile.AllocReadLC( PROMPT_TIME24 ) );
       
  1366         break;
       
  1367             
       
  1368         case ETimeAm:
       
  1369         reader.SetBuffer( resourceFile.AllocReadLC( PROMPT_TIME12AM ) );
       
  1370         break;
       
  1371             
       
  1372         case ETimePm:
       
  1373         reader.SetBuffer( resourceFile.AllocReadLC( PROMPT_TIME12PM ) );
       
  1374         break;
       
  1375             
       
  1376         case EOperator:
       
  1377         reader.SetBuffer( resourceFile.AllocReadLC( PROMPT_OPERATOR ) );
       
  1378         break;
       
  1379         
       
  1380         case EOperatorNotAvailable:
       
  1381         reader.SetBuffer( resourceFile.AllocReadLC( PROMPT_NOOPERATOR ) );
       
  1382         break;
       
  1383          
       
  1384         case EBatteryFull:
       
  1385         reader.SetBuffer( resourceFile.AllocReadLC( PROMPT_BATTERYFULL ) );
       
  1386         break;
       
  1387         
       
  1388         case EBattetteryAlmostFull:
       
  1389         reader.SetBuffer( resourceFile.AllocReadLC( PROMPT_BATTERYALMOSTFULL ) );
       
  1390         break;
       
  1391         
       
  1392         case EBatteryHalfFull:
       
  1393         reader.SetBuffer( resourceFile.AllocReadLC( PROMPT_BATTERYHALF ) );
       
  1394         break;
       
  1395         
       
  1396         case EBatteryAlmostEmpty:
       
  1397         reader.SetBuffer( resourceFile.AllocReadLC( PROMPT_BATTERYALMOSTEMPTY ) );
       
  1398         break;
       
  1399         
       
  1400         case EBatteryLow:
       
  1401         reader.SetBuffer( resourceFile.AllocReadLC( PROMPT_BATTERYLOW ) );
       
  1402         break;
       
  1403         
       
  1404         case EBatteryStrengthNotAvailable:
       
  1405         reader.SetBuffer( resourceFile.AllocReadLC( PROMPT_NOBATTERY ) );
       
  1406         break;
       
  1407         
       
  1408         case ESignalStrengthExcellent:
       
  1409         reader.SetBuffer( resourceFile.AllocReadLC( PROMPT_NETWORKEXCELLENT ) );
       
  1410         break;
       
  1411             
       
  1412         case ESignalStrengthGood:
       
  1413         reader.SetBuffer( resourceFile.AllocReadLC( PROMPT_NETWORKGOOD ) );
       
  1414         break;
       
  1415         
       
  1416         case ESignalStrengthRatherGood:
       
  1417         reader.SetBuffer( resourceFile.AllocReadLC( PROMPT_NETWORKRATHERGOOD ) );
       
  1418         break;
       
  1419         
       
  1420         case ESignalStrengthLow:
       
  1421         reader.SetBuffer( resourceFile.AllocReadLC( PROMPT_NETWORKLOW ) );
       
  1422         break;
       
  1423         
       
  1424         case ESignalStrengthNoSignal:
       
  1425         reader.SetBuffer( resourceFile.AllocReadLC( PROMPT_NETWORKNONE ) );
       
  1426         break;
       
  1427         
       
  1428         case ESignalStrengthNotAvailable:
       
  1429         reader.SetBuffer( resourceFile.AllocReadLC( PROMPT_NONETWORK ) );
       
  1430         break;
       
  1431         
       
  1432         default:
       
  1433             break;
       
  1434 
       
  1435         }
       
  1436             
       
  1437     aString = reader.ReadHBufCL();
       
  1438     
       
  1439     CleanupStack::PopAndDestroy(); // AllocReadLC
       
  1440     
       
  1441     CleanupStack::PopAndDestroy( &resourceFile );
       
  1442     CleanupStack::PopAndDestroy( &fileServer );
       
  1443     }
       
  1444 
       
  1445 // End of File