htiui/HtiAdmin/src/HtiAdminAppUi.cpp
changeset 0 d6fe6244b863
child 3 2703485a934c
equal deleted inserted replaced
-1:000000000000 0:d6fe6244b863
       
     1 /*
       
     2 * Copyright (c) 2009 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:  AppUi implementation, all functions here
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <avkon.hrh>
       
    20 #include <aknnotewrappers.h>
       
    21 #include <aknquerydialog.h>
       
    22 #include <aknmessagequerydialog.h>
       
    23 #include <w32std.h>
       
    24 #include <eikmenup.h>
       
    25 #include <commdb.h>
       
    26 
       
    27 #include <HtiAdmin.rsg>
       
    28 #include <HtiCommPluginInterface.h> // for KHTICommInterfaceUid
       
    29 #include <HtiCfg.h>
       
    30 #include <HtiVersion.h>
       
    31 
       
    32 #include "HtiAdmin.pan"
       
    33 #include "HtiAdminAppUi.h"
       
    34 #include "HtiAdminAppView.h"
       
    35 #include "HtiAdmin.hrh"
       
    36 
       
    37 
       
    38 #ifdef __ENABLE_LOGGING__
       
    39 
       
    40 #include <flogger.h>
       
    41 
       
    42 _LIT(KLogFolder, "hti");
       
    43 _LIT(KLogFile, "htiadmin.txt");
       
    44 #define HTI_LOG_TEXT(a1) {_LIT(temp, a1); RFileLogger::Write(KLogFolder, KLogFile, EFileLoggingModeAppend, temp);}
       
    45 #define HTI_LOG_FORMAT(a1,a2) {_LIT(temp, a1); RFileLogger::WriteFormat(KLogFolder, KLogFile, EFileLoggingModeAppend, temp, (a2));}
       
    46 #define HTI_LOG_DES(a1) {RFileLogger::Write(KLogFolder, KLogFile, EFileLoggingModeAppend, (a1));}
       
    47 
       
    48 #else // __ENABLE_LOGGING__
       
    49 
       
    50 #define HTI_LOG_TEXT(a1)
       
    51 #define HTI_LOG_FORMAT(a1,a2)
       
    52 #define HTI_LOG_DES(a1)
       
    53 
       
    54 #endif // __ENABLE_LOGGING__
       
    55 
       
    56 // CONSTANTS
       
    57 _LIT( KHtiWatchDogMatchPattern, "HtiWatchDog*" );
       
    58 _LIT( KHtiFrameworkExe, "HtiFramework.exe" );
       
    59 _LIT( KHtiMatchPattern, "HtiFramework*" );
       
    60 _LIT( KHtiFrameworkCaption, "HTI status: " );
       
    61 _LIT( KHtiAutoStartCaption, "AutoStart: " );
       
    62 _LIT( KHtiVersionCaption, "Version: " );
       
    63 _LIT( KHtiSelectedCommCaption, "Communication: " );
       
    64 _LIT( KHtiAdminStartParameter, "admin" );
       
    65 _LIT( KHtiAdminVersionFormat, "%u.%u.%u (%uwk%02u)" );
       
    66 _LIT( KHtiAdminAboutVersionFormat, "Version %u.%u.%u - " );
       
    67 const static TInt KTerminateReason = 1;
       
    68 
       
    69 
       
    70 const TInt32 KHTIImplUidSerial    = {0x10210CCA};
       
    71 const TInt32 KHTIImplUidBluetooth = {0x200212CC};
       
    72 const TInt32 KHTIImplUidIPComm    = {0x200212CE};
       
    73 
       
    74 // configuration file constants
       
    75 _LIT( KCfgFilePath,         "\\");
       
    76 _LIT( KHtiCfg,              "hti.cfg" );
       
    77 _LIT( KHtiBtCommCfg,        "HTIBtComm.cfg" );
       
    78 _LIT( KHtiSerialCommCfg ,   "HTISerialComm.cfg" );
       
    79 _LIT( KHtiIPCommCfg,        "HTIIPComm.cfg" );
       
    80 // hti.cfg
       
    81 _LIT8( KCommPlugin,         "CommPlugin" );
       
    82 _LIT8( KPriority,           "Priority" );
       
    83 _LIT8( KShowConsole,        "ShowConsole" );
       
    84 _LIT8( KEnableHtiWatchDog,  "EnableHtiWatchDog" );
       
    85 _LIT8( KEnableHtiAutoStart, "EnableHtiAutoStart" );
       
    86 _LIT8( KShowErrorDialogs,   "ShowErrorDialogs" );
       
    87 // HtiBtComm.cfg
       
    88 _LIT8( KBtDeviceAddress,    "BtDeviceAddress" );
       
    89 _LIT8( KBtDeviceName,       "BtDeviceName" );
       
    90 // HtiSerialComm.cfg
       
    91 _LIT8( KCommPortNumber,     "CommPort" );
       
    92 // HTIIPComm.cfg
       
    93 _LIT8( KLocalPort,          "LocalPort" );
       
    94 _LIT8( KRemoteHost,         "RemoteHost" );
       
    95 _LIT8( KRemotePort,         "RemotePort" );
       
    96 _LIT8( KIAPName,            "IAPName" );
       
    97 
       
    98 
       
    99 // ConstructL is called by the application framework
       
   100 void CHtiAdminAppUi::ConstructL()
       
   101     {
       
   102     BaseConstructL( EAknEnableSkin );
       
   103     iAppView = CHtiAdminAppView::NewL( ClientRect() );
       
   104     AddToStackL( iAppView );
       
   105 
       
   106     iAppView->SetCaption( KHtiFrameworkCaption );
       
   107     iAppView->SetVersionCaption( KHtiVersionCaption );
       
   108     iAppView->SetAutoStartCaption( KHtiAutoStartCaption );
       
   109     iAppView->SetSelectedCommCaption( KHtiSelectedCommCaption );
       
   110     UpdateVersion();
       
   111     UpdateStatusL();
       
   112     iHtiCfg = CHtiCfg::NewL();
       
   113     UpdateAutoStartStatus(); // uses iHtiCfg
       
   114     UpdateSelectedComm(); // uses iHtiCfg
       
   115     }
       
   116 
       
   117 CHtiAdminAppUi::CHtiAdminAppUi()
       
   118     {
       
   119     iHtiCfg = NULL;
       
   120     }
       
   121 
       
   122 CHtiAdminAppUi::~CHtiAdminAppUi()
       
   123     {
       
   124     KillTimer();
       
   125     if ( iAppView )
       
   126         {
       
   127         RemoveFromStack( iAppView );
       
   128         delete iAppView;
       
   129         iAppView = NULL;
       
   130         }
       
   131 
       
   132     if ( iHtiCfg )
       
   133         delete iHtiCfg;
       
   134     }
       
   135 
       
   136 void CHtiAdminAppUi::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane *aMenuPane)
       
   137     {
       
   138     HTI_LOG_FORMAT( "DynInitMenuPaneL 0x%x", aResourceId );
       
   139 
       
   140     if ( aResourceId == R_HTIADMIN_MENU )
       
   141         {
       
   142         RProcess prs;
       
   143         if ( OpenHtiProcess( prs ) )
       
   144             {
       
   145             if ( prs.ExitType() == EExitPending )
       
   146                 {
       
   147                 aMenuPane->SetItemDimmed( EHtiAdminStart, ETrue );
       
   148                 aMenuPane->SetItemDimmed( EHtiAdminSubOptions, ETrue );
       
   149                 prs.Close();
       
   150                 return;
       
   151                 }
       
   152             }
       
   153         aMenuPane->SetItemDimmed( EHtiAdminStop, ETrue );
       
   154         prs.Close();
       
   155         }
       
   156 
       
   157     else if ( aResourceId == R_HTIADMIN_SUBMENU_OPTIONS )
       
   158         {
       
   159 #if !defined(__ENABLE_LOGGING__)
       
   160         aMenuPane->SetItemDimmed( EHtiAdminSubLogs, ETrue );
       
   161 #endif
       
   162         }
       
   163     else if ( aResourceId == R_HTIADMIN_SUBMENU_PRIORITY )
       
   164         {
       
   165         TInt priority = 3; // default value
       
   166         TRAPD( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   167         if ( !err )
       
   168             {
       
   169             TRAP( err, priority = iHtiCfg->GetParameterIntL( KPriority ) );
       
   170             }
       
   171 
       
   172         switch ( priority )
       
   173             {
       
   174             case 1:
       
   175                 aMenuPane->SetItemButtonState( EHtiAdminPriorityBackground, EEikMenuItemSymbolOn );
       
   176                 break;
       
   177             case 2:
       
   178                 aMenuPane->SetItemButtonState( EHtiAdminPriorityForeground, EEikMenuItemSymbolOn );
       
   179                 break;
       
   180             case 4:
       
   181                 aMenuPane->SetItemButtonState( EHtiAdminPriorityAbsoluteHigh, EEikMenuItemSymbolOn );
       
   182                 break;
       
   183             default:
       
   184                 aMenuPane->SetItemButtonState( EHtiAdminPriorityHigh, EEikMenuItemSymbolOn );
       
   185                 break;
       
   186             }
       
   187         }
       
   188 
       
   189     else if ( aResourceId == R_HTIADMIN_SUBMENU_AUTOSTART )
       
   190         {
       
   191 #ifdef __WINS__
       
   192         TInt value = 0; // default value for emulator
       
   193 #else
       
   194         TInt value = 1; // default value for hardware
       
   195 #endif
       
   196         TRAPD( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   197         if ( !err )
       
   198             {
       
   199             TRAP( err, value = iHtiCfg->GetParameterIntL( KEnableHtiAutoStart ) );
       
   200             }
       
   201 
       
   202         if ( value )
       
   203             aMenuPane->SetItemButtonState( EHtiAdminAutoStartEnable, EEikMenuItemSymbolOn );
       
   204         else
       
   205             aMenuPane->SetItemButtonState( EHtiAdminAutoStartDisable, EEikMenuItemSymbolOn );
       
   206         }
       
   207 
       
   208     else if ( aResourceId == R_HTIADMIN_SUBMENU_WATCHDOG )
       
   209         {
       
   210         TInt value = 0; // default value
       
   211         TRAPD( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   212         if ( !err )
       
   213             {
       
   214             TRAP( err, value = iHtiCfg->GetParameterIntL( KEnableHtiWatchDog ) );
       
   215             }
       
   216 
       
   217         if ( value )
       
   218             aMenuPane->SetItemButtonState( EHtiAdminWatchDogEnable, EEikMenuItemSymbolOn );
       
   219         else
       
   220             aMenuPane->SetItemButtonState( EHtiAdminWatchDogDisable, EEikMenuItemSymbolOn );
       
   221         }
       
   222 
       
   223     else if ( aResourceId == R_HTIADMIN_SUBMENU_CONSOLE )
       
   224         {
       
   225         TInt value = 0; // default value
       
   226         TRAPD( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   227         if ( !err )
       
   228             {
       
   229             TRAP( err, value = iHtiCfg->GetParameterIntL( KShowConsole ) );
       
   230             }
       
   231 
       
   232         if ( value )
       
   233             aMenuPane->SetItemButtonState( EHtiAdminConsoleEnable, EEikMenuItemSymbolOn );
       
   234         else
       
   235             aMenuPane->SetItemButtonState( EHtiAdminConsoleDisable, EEikMenuItemSymbolOn );
       
   236         }
       
   237 
       
   238     else if ( aResourceId == R_HTIADMIN_SUBMENU_ERROR_DIALOGS )
       
   239         {
       
   240         TInt value = 1; // default value
       
   241         TRAPD( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   242         if ( !err )
       
   243             {
       
   244             TRAP( err, value = iHtiCfg->GetParameterIntL( KShowErrorDialogs ) );
       
   245             }
       
   246 
       
   247         if ( value )
       
   248             aMenuPane->SetItemButtonState( EHtiAdminErrorDialogsEnable, EEikMenuItemSymbolOn );
       
   249         else
       
   250             aMenuPane->SetItemButtonState( EHtiAdminErrorDialogsDisable, EEikMenuItemSymbolOn );
       
   251         }
       
   252     }
       
   253 
       
   254 
       
   255 // Helper function to get data from a dialog
       
   256 TInt ShowDialog(TInt aResourceId, const TDesC &aText, TDes8 &aValue)
       
   257     {
       
   258     TBuf<KMaxParameterValueLength> data;
       
   259 
       
   260     CAknTextQueryDialog* dlg;
       
   261     dlg = new (ELeave) CAknTextQueryDialog(data);
       
   262     CleanupStack::PushL(dlg);
       
   263     dlg->SetPromptL(aText);
       
   264     dlg->SetMaxLength(KMaxParameterValueLength);
       
   265     CleanupStack::Pop(); // dlg
       
   266 
       
   267     if ( dlg->ExecuteLD( aResourceId ) )
       
   268         {
       
   269         aValue.Copy(data);
       
   270         return KErrNone;
       
   271         }
       
   272 
       
   273     return KErrCancel;
       
   274     }
       
   275 
       
   276 void CHtiAdminAppUi::ShowBTListQueryL()
       
   277 	{
       
   278 	TInt selectedOption( KErrNotFound );
       
   279 	        	 
       
   280 	CDesCArrayFlat* array = new (ELeave) CDesCArrayFlat(20);
       
   281 	CleanupStack::PushL(array);
       
   282 	
       
   283 	array->AppendL(_L("By BT address"));
       
   284 	array->AppendL(_L("By BT Name"));
       
   285 	array->AppendL(_L("Search when starting"));
       
   286 				 
       
   287 	CAknListQueryDialog* dlg = new(ELeave) CAknListQueryDialog( &selectedOption );
       
   288 	dlg->PrepareLC(R_QUERY_DIALOG);
       
   289 	dlg->SetItemTextArray(array);
       
   290 	dlg->SetOwnershipType(ELbmDoesNotOwnItemArray);
       
   291 	dlg->RunLD();
       
   292 	
       
   293 	CleanupStack::PopAndDestroy(array); 
       
   294 	
       
   295 	if(selectedOption == 0)
       
   296 		{
       
   297 		HandleBtByAddress();
       
   298 		}
       
   299 	else if(selectedOption == 1)
       
   300 		{
       
   301 		HandleBtByName();
       
   302 		}
       
   303 	else if (selectedOption == 2)
       
   304 		{
       
   305 		HandleBtSearch();
       
   306 		}
       
   307 	}
       
   308 
       
   309 void CHtiAdminAppUi::ShowIPListQueryL()
       
   310 	{
       
   311 	TInt selectedOption( KErrNotFound );
       
   312 	        	 
       
   313 	CDesCArrayFlat* array = new (ELeave) CDesCArrayFlat(10);
       
   314 	CleanupStack::PushL(array);
       
   315 	
       
   316 	array->AppendL(_L("Listen"));
       
   317 	array->AppendL(_L("Connect"));
       
   318 	
       
   319 	CAknListQueryDialog* dlg = new(ELeave) CAknListQueryDialog( &selectedOption );
       
   320 	dlg->PrepareLC(R_QUERY_DIALOG);
       
   321 	dlg->SetItemTextArray(array);
       
   322 	dlg->SetOwnershipType(ELbmDoesNotOwnItemArray);
       
   323 	dlg->RunLD();
       
   324 	
       
   325 	CleanupStack::PopAndDestroy(array); 
       
   326 	
       
   327 	if(selectedOption == 0)
       
   328 		{
       
   329 		HandleIPListen();
       
   330 		}
       
   331 	else if(selectedOption == 1)
       
   332 		{
       
   333 		HandleIPConnect();
       
   334 		}
       
   335 	}
       
   336 
       
   337 void CleanupRArray( TAny* object )
       
   338     {
       
   339     ( ( RImplInfoPtrArray* ) object )->ResetAndDestroy();
       
   340     }
       
   341 
       
   342 void CHtiAdminAppUi::ShowCommsListQueryL()
       
   343 	{
       
   344 	TInt selectedOption( KErrNotFound );
       
   345 	        	 
       
   346 	const TInt pluginNameArrayGranularity (15);
       
   347 	CDesCArrayFlat* pluginNameArray = new (ELeave) CDesCArrayFlat(pluginNameArrayGranularity);
       
   348 	CleanupStack::PushL(pluginNameArray);
       
   349 		
       
   350 	RImplInfoPtrArray implInfoArray;
       
   351 	CleanupStack::PushL( TCleanupItem( CleanupRArray, &implInfoArray ) );
       
   352 	
       
   353 	REComSession::ListImplementationsL( KHTICommInterfaceUid, implInfoArray );
       
   354 
       
   355 	for ( TInt i = 0; i < implInfoArray.Count(); ++i )
       
   356 		{
       
   357 		pluginNameArray->AppendL(implInfoArray[i]->DisplayName());
       
   358 		}
       
   359 	
       
   360 	CAknListQueryDialog* dlg = new(ELeave) CAknListQueryDialog( &selectedOption );
       
   361 	
       
   362 	dlg->PrepareLC(R_QUERY_DIALOG);
       
   363 	dlg->SetHeaderTextL(_L("Select communication"));
       
   364 	dlg->SetItemTextArray(pluginNameArray);
       
   365 	dlg->SetOwnershipType(ELbmDoesNotOwnItemArray);
       
   366 	
       
   367 	if(dlg->RunLD())
       
   368 		{
       
   369 		TInt32 uid = implInfoArray[selectedOption]->ImplementationUid().iUid;
       
   370 		switch(uid)
       
   371 			{
       
   372 			case KHTIImplUidSerial:  
       
   373 				{
       
   374 				TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   375 				iHtiCfg->SetParameterL( KCommPlugin, _L8( "SERIAL" ) );
       
   376 				iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   377 
       
   378 				TBuf8<KMaxParameterValueLength> portNum;
       
   379 				if ( !ShowDialog( R_NUMERIC_QUERY, _L("Com port number:"), portNum ) )
       
   380 					{
       
   381 					TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiSerialCommCfg ) );
       
   382 					iHtiCfg->SetParameterL( KCommPortNumber, portNum );
       
   383 					iHtiCfg->SaveCfgL( KCfgFilePath, KHtiSerialCommCfg );
       
   384 					}
       
   385 				UpdateSelectedComm();
       
   386 				}
       
   387 				break;
       
   388 				
       
   389 			case KHTIImplUidBluetooth:  
       
   390 				{
       
   391 				ShowBTListQueryL();				
       
   392 				}
       
   393 				break;
       
   394 				
       
   395 			case KHTIImplUidIPComm:  
       
   396 				{
       
   397 				ShowIPListQueryL();
       
   398 				}
       
   399 				break;
       
   400 			default:
       
   401 				{
       
   402 				//Just save the conf info for other plugins
       
   403 				TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   404 				iHtiCfg->SetParameterL( KCommPlugin, implInfoArray[selectedOption]->DataType() );
       
   405 				iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   406 				UpdateSelectedComm();
       
   407 				}
       
   408 			}
       
   409 		}
       
   410 	CleanupStack::PopAndDestroy(2, pluginNameArray);  
       
   411 	}
       
   412 
       
   413 void CHtiAdminAppUi::HandleBtByAddress()
       
   414 	{
       
   415 	TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath,  KHtiCfg ) );
       
   416 	iHtiCfg->SetParameterL( KCommPlugin, _L8( "BTSERIAL" ) );
       
   417 	iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   418 
       
   419 	TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiBtCommCfg ) );
       
   420 	iHtiCfg->RemoveParameterL( KBtDeviceName );
       
   421 	iHtiCfg->RemoveParameterL( KBtDeviceAddress );
       
   422 
       
   423 	TBuf8<KMaxParameterValueLength> address;
       
   424 	if ( !ShowDialog( R_TEXT_QUERY, _L("BT address:"), address) )
       
   425 		{
       
   426 		iHtiCfg->SetParameterL( KBtDeviceAddress, address);
       
   427 		}
       
   428 
       
   429 	iHtiCfg->SaveCfgL( KCfgFilePath, KHtiBtCommCfg);
       
   430 	UpdateSelectedComm();
       
   431 	}
       
   432 
       
   433 void CHtiAdminAppUi::HandleBtByName()
       
   434 	{
       
   435 	TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   436 	iHtiCfg->SetParameterL( KCommPlugin, _L8( "BTSERIAL" ) );
       
   437 	iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   438 
       
   439 	TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiBtCommCfg ) );
       
   440 	iHtiCfg->RemoveParameterL( KBtDeviceName );
       
   441 	iHtiCfg->RemoveParameterL( KBtDeviceAddress );
       
   442 
       
   443 	TBuf8<KMaxParameterValueLength> name;
       
   444 	if ( !ShowDialog( R_TEXT_QUERY, _L( "BT name:" ), name ) )
       
   445 		{
       
   446 		iHtiCfg->SetParameterL( KBtDeviceName, name );
       
   447 		}
       
   448 
       
   449 	iHtiCfg->SaveCfgL( KCfgFilePath, KHtiBtCommCfg );
       
   450 	UpdateSelectedComm();
       
   451 	}
       
   452 
       
   453 void CHtiAdminAppUi::HandleBtSearch()
       
   454 	{
       
   455 	TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   456 	iHtiCfg->SetParameterL( KCommPlugin, _L8( "BTSERIAL" ) );
       
   457 	iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   458 
       
   459 	TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiBtCommCfg ) );
       
   460 	iHtiCfg->RemoveParameterL( KBtDeviceName );
       
   461 	iHtiCfg->RemoveParameterL( KBtDeviceAddress );
       
   462 	iHtiCfg->SaveCfgL( KCfgFilePath, KHtiBtCommCfg );
       
   463 	UpdateSelectedComm();
       
   464 	}
       
   465 
       
   466 void CHtiAdminAppUi::HandleIPListen()
       
   467 	{
       
   468 	TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   469 	iHtiCfg->SetParameterL( KCommPlugin, _L8("IPCOMM"));
       
   470 	iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   471 
       
   472 	TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiIPCommCfg ) );
       
   473 	iHtiCfg->RemoveParameterL( KRemotePort );
       
   474 	iHtiCfg->RemoveParameterL( KRemoteHost );
       
   475 	
       
   476 	TBuf8<KMaxParameterValueLength> localPort;
       
   477 	if ( !ShowDialog( R_TEXT_QUERY, _L( "Local port:" ), localPort ) )
       
   478 		{
       
   479 		iHtiCfg->SetParameterL( KLocalPort, localPort );
       
   480 		ShowCommsDBListQueryL();
       
   481 		}
       
   482 	iHtiCfg->SaveCfgL( KCfgFilePath, KHtiIPCommCfg );
       
   483 	UpdateSelectedComm();
       
   484 	}
       
   485 	
       
   486 void CHtiAdminAppUi::HandleIPConnect()
       
   487 	{
       
   488 	TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   489 	iHtiCfg->SetParameterL( KCommPlugin, _L8( "IPCOMM" ) );
       
   490 	iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   491 
       
   492 	TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiIPCommCfg ) );
       
   493 	iHtiCfg->RemoveParameterL( KLocalPort );
       
   494 	TBuf8<KMaxParameterValueLength> remoteHost;
       
   495 	TBuf8<KMaxParameterValueLength> remotePort;
       
   496 	if ( !ShowDialog( R_TEXT_QUERY, _L("Remote host:"), remoteHost ) )
       
   497 		{
       
   498 		iHtiCfg->SetParameterL( KRemoteHost, remoteHost );
       
   499 		if ( !ShowDialog( R_TEXT_QUERY, _L( "Remote port:" ), remotePort ) )
       
   500 			{
       
   501 			iHtiCfg->SetParameterL( KRemotePort, remotePort );
       
   502 			ShowCommsDBListQueryL();
       
   503 			}
       
   504 		}
       
   505 	iHtiCfg->SaveCfgL( KCfgFilePath, KHtiIPCommCfg );
       
   506 	UpdateSelectedComm();
       
   507 	}
       
   508 	
       
   509 
       
   510 // handle any menu commands
       
   511 void CHtiAdminAppUi::HandleCommandL(TInt aCommand)
       
   512     {
       
   513     TFileName cfgFile;
       
   514 
       
   515     switch ( aCommand )
       
   516         {
       
   517         case EEikCmdExit:
       
   518         case EAknSoftkeyExit:
       
   519             Exit();
       
   520             break;
       
   521 
       
   522         case EHtiAdminStart:
       
   523             {
       
   524             HTI_LOG_TEXT( "Start" );
       
   525             RProcess prs;
       
   526             TInt err;
       
   527             TBool isRunning = EFalse;
       
   528             if ( OpenHtiProcess( prs ) )
       
   529                 {
       
   530                 if ( prs.ExitType() == EExitPending )
       
   531                     {
       
   532                     isRunning = ETrue;
       
   533                     _LIT(KText, "Already running");
       
   534                     iAppView->SetStatus( KText );
       
   535                     }
       
   536                 prs.Close();
       
   537                 }
       
   538 
       
   539             if ( !isRunning )
       
   540                 {
       
   541                 HTI_LOG_TEXT( "create process" );
       
   542                 err = prs.Create( KHtiFrameworkExe, KHtiAdminStartParameter );
       
   543                 if ( err == KErrNone )
       
   544                     {
       
   545                     prs.Resume();
       
   546                     prs.Close();
       
   547                     UpdateStatusL();
       
   548                     HTI_LOG_TEXT("create done");
       
   549                     }
       
   550                 else
       
   551                     {
       
   552                     TBuf<64> msg;
       
   553                     msg.Format( _L("Error in starting: %d"), err );
       
   554                     iAppView->SetStatus( msg );
       
   555                     HTI_LOG_TEXT("create error");
       
   556                     }
       
   557                 }
       
   558             }
       
   559             break;
       
   560 
       
   561         case EHtiAdminStop:
       
   562             {
       
   563             HTI_LOG_TEXT("Stop");
       
   564 
       
   565             // kill the watchdog to prevent it from restarting HTI again
       
   566             KillHtiWatchDogL();
       
   567 
       
   568             RProcess prs;
       
   569             if ( OpenHtiProcess( prs ) )
       
   570                 {
       
   571                 if ( prs.ExitType() == EExitPending )
       
   572                     {
       
   573                     HTI_LOG_TEXT("try to kill");
       
   574                     prs.Kill( KTerminateReason );
       
   575                     UpdateStatusL();
       
   576                     }
       
   577                 else
       
   578                     {
       
   579                     _LIT(KText, "Already stopped");
       
   580                     iAppView->SetStatus( KText );
       
   581                     }
       
   582                 prs.Close();
       
   583                 }
       
   584             }
       
   585             break;
       
   586 
       
   587         case EHtiAdminAbout:
       
   588             {
       
   589             HTI_LOG_TEXT("About");
       
   590             TDateSuffix suffix( KHtiVersionDay - 1 );
       
   591             TMonthName month( ( TMonth ) ( KHtiVersionMonth - 1 ) );
       
   592             TBuf<64> msgPart1;
       
   593             msgPart1.Format( KHtiAdminAboutVersionFormat,
       
   594                     KHtiVersionMajor, KHtiVersionMinor, KHtiVersionBuild );
       
   595             msgPart1.AppendNum( KHtiVersionDay );
       
   596             msgPart1.Append( suffix );
       
   597             msgPart1.Append( ' ' );
       
   598             msgPart1.Append( month );
       
   599             msgPart1.Append( ' ' );
       
   600             msgPart1.AppendNum( KHtiVersionYear );
       
   601             msgPart1.Append( '.' );
       
   602             msgPart1.Append( ' ' );
       
   603             HBufC* msgPart2 = iEikonEnv->AllocReadResourceLC( R_HTIADMIN_ABOUT_TEXT );
       
   604             HBufC* fullMsg = HBufC::NewLC( msgPart1.Length() + msgPart2->Length() );
       
   605             fullMsg->Des().Append( msgPart1 );
       
   606             fullMsg->Des().Append( *msgPart2 );
       
   607             CAknMessageQueryDialog* dialog = new ( ELeave ) CAknMessageQueryDialog;
       
   608             dialog->PrepareLC( R_HTIADMIN_ABOUT_DIALOG );
       
   609             dialog->SetMessageTextL( *fullMsg );
       
   610             dialog->RunLD();
       
   611             CleanupStack::PopAndDestroy( 2 ); // fullMsg, msgPart2
       
   612             }
       
   613             break;
       
   614 
       
   615         case EHtiAdminSubOptions:
       
   616             break;
       
   617 
       
   618         case EHtiAdminSubLogs:
       
   619             break;
       
   620 
       
   621         case EHtiAdminCreateLogFolder:
       
   622 #ifdef __ENABLE_LOGGING__
       
   623             {
       
   624             TInt err = KErrNone;
       
   625             RFs fs;
       
   626             err = fs.Connect();
       
   627             if ( err == KErrNone )
       
   628                 {
       
   629                 err = fs.MkDirAll(_L("c:\\logs\\hti\\"));
       
   630                 }
       
   631             fs.Close();
       
   632             }
       
   633 #endif
       
   634             break;
       
   635 
       
   636         case EHtiAdminRemoveLogFolder:
       
   637 #ifdef __ENABLE_LOGGING__
       
   638             {
       
   639             TInt err = KErrNone;
       
   640             RFs fs;
       
   641             err = fs.Connect();
       
   642             if ( err == KErrNone )
       
   643                 {
       
   644                 CFileMan *fileman = CFileMan::NewL( fs );
       
   645                 fileman->RmDir( _L( "c:\\logs\\hti\\" ) );
       
   646                 delete fileman;
       
   647                 }
       
   648             fs.Close();
       
   649             }
       
   650 #endif
       
   651             break;
       
   652 
       
   653         case EHtiAdminClearLogs:
       
   654 #ifdef __ENABLE_LOGGING__
       
   655             {
       
   656             TInt err = KErrNone;
       
   657             RFs fs;
       
   658             err = fs.Connect();
       
   659             if ( err == KErrNone )
       
   660                 {
       
   661                 CFileMan *fileman = CFileMan::NewL( fs );
       
   662                 fileman->Delete( _L( "c:\\logs\\hti\\*" ) );
       
   663                 fileman->Delete( _L( "c:\\HTI_*.log" ) );
       
   664                 delete fileman;
       
   665                 }
       
   666             fs.Close();
       
   667             }
       
   668 #endif
       
   669             break;
       
   670 
       
   671         case EHtiAdminSubComms:
       
   672         	{
       
   673         	ShowCommsListQueryL();
       
   674         	}
       
   675             break;
       
   676 
       
   677         case EHtiAdminSubPriority:
       
   678             break;
       
   679 
       
   680         case EHtiAdminPriorityBackground:
       
   681             TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   682             iHtiCfg->SetParameterL( KPriority, _L8("1"));
       
   683             iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   684             break;
       
   685 
       
   686         case EHtiAdminPriorityForeground:
       
   687             TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   688             iHtiCfg->SetParameterL( KPriority, _L8("2"));
       
   689             iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   690             break;
       
   691 
       
   692         case EHtiAdminPriorityHigh:
       
   693             TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   694             iHtiCfg->SetParameterL( KPriority, _L8("3"));
       
   695             iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   696             break;
       
   697 
       
   698         case EHtiAdminPriorityAbsoluteHigh:
       
   699             TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   700             iHtiCfg->SetParameterL( KPriority, _L8("4"));
       
   701             iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   702             break;
       
   703 
       
   704         case EHtiAdminSubAutoStart:
       
   705             break;
       
   706 
       
   707         case EHtiAdminAutoStartEnable:
       
   708             TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   709             iHtiCfg->SetParameterL( KEnableHtiAutoStart, _L8("1"));
       
   710             iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   711             UpdateAutoStartStatus();
       
   712             break;
       
   713 
       
   714         case EHtiAdminAutoStartDisable:
       
   715             TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   716             iHtiCfg->SetParameterL( KEnableHtiAutoStart, _L8("0"));
       
   717             iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   718             UpdateAutoStartStatus();
       
   719             break;
       
   720 
       
   721         case EHtiAdminSubWatchDog:
       
   722             break;
       
   723 
       
   724         case EHtiAdminWatchDogEnable:
       
   725             TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   726             iHtiCfg->SetParameterL( KEnableHtiWatchDog, _L8("1"));
       
   727             iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   728             break;
       
   729 
       
   730         case EHtiAdminWatchDogDisable:
       
   731             TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   732             iHtiCfg->SetParameterL( KEnableHtiWatchDog, _L8("0"));
       
   733             iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   734             break;
       
   735 
       
   736         case EHtiAdminSubConsole:
       
   737             break;
       
   738 
       
   739         case EHtiAdminConsoleEnable:
       
   740             TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   741             iHtiCfg->SetParameterL( KShowConsole, _L8("1"));
       
   742             iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   743             break;
       
   744 
       
   745         case EHtiAdminConsoleDisable:
       
   746             TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   747             iHtiCfg->SetParameterL( KShowConsole, _L8("0"));
       
   748             iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   749             break;
       
   750 
       
   751         case EHtiAdminErrorDialogsEnable:
       
   752             TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   753             iHtiCfg->SetParameterL( KShowErrorDialogs, _L8("1"));
       
   754             iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   755             break;
       
   756 
       
   757         case EHtiAdminErrorDialogsDisable:
       
   758             TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   759             iHtiCfg->SetParameterL( KShowErrorDialogs, _L8("0"));
       
   760             iHtiCfg->SaveCfgL( KCfgFilePath, KHtiCfg );
       
   761             break;
       
   762 
       
   763         case EHtiAdminSubSetParam:
       
   764             break;
       
   765 
       
   766         case EHtiAdminHtiCfg:
       
   767             cfgFile = KHtiCfg;
       
   768 
       
   769         case EHtiAdminHtiBtCommCfg:
       
   770             if ( !cfgFile.Length() )
       
   771                 cfgFile = KHtiBtCommCfg;
       
   772 
       
   773         case EHtiAdminHtiIPCommCfg:
       
   774             if ( !cfgFile.Length() )
       
   775                 cfgFile = KHtiIPCommCfg;
       
   776 
       
   777         case EHtiAdminHtiSerialCommCfg:
       
   778             {
       
   779             if ( !cfgFile.Length() )
       
   780                 cfgFile = KHtiSerialCommCfg;
       
   781 
       
   782             TBuf8<KMaxParameterNameLength> parameterName;
       
   783             if ( !ShowDialog( R_TEXT_QUERY, _L("Parameter name:"), parameterName) )
       
   784                 {
       
   785                 TBuf8<KMaxParameterValueLength> parameterValue;
       
   786                 if ( !ShowDialog( R_TEXT_QUERY, _L("Parameter value:"), parameterValue ) )
       
   787                     {
       
   788                     TRAP_IGNORE( iHtiCfg->LoadCfgL( KCfgFilePath, cfgFile ) );
       
   789                     iHtiCfg->SetParameterL( parameterName, parameterValue );
       
   790                     iHtiCfg->SaveCfgL( KCfgFilePath, cfgFile);
       
   791                     }
       
   792                 }
       
   793             }
       
   794             break;
       
   795 
       
   796         default:
       
   797         	{
       
   798 			CAknErrorNote* dialog = new(ELeave)CAknErrorNote(ETrue);			 
       
   799 			dialog->ExecuteLD(_L("Unknown Command Recieved"));
       
   800 			}
       
   801         	break;
       
   802         }
       
   803     }
       
   804 
       
   805 void CHtiAdminAppUi::HandleForegroundEventL( TBool aForeground )
       
   806     {
       
   807     CAknAppUi::HandleForegroundEventL( aForeground );
       
   808 
       
   809     if ( aForeground )
       
   810         {
       
   811         UpdateStatusL();
       
   812         UpdateAutoStartStatus();
       
   813         }
       
   814     else
       
   815         {
       
   816         KillTimer();
       
   817         }
       
   818     }
       
   819 
       
   820 TBool CHtiAdminAppUi::OpenHtiProcess( RProcess& aPrs )
       
   821     {
       
   822     HTI_LOG_TEXT( "OpenHtiProcess" );
       
   823 
       
   824     TFullName processName;
       
   825     TInt err;
       
   826 
       
   827     TFindProcess finder( KHtiMatchPattern );
       
   828     err = finder.Next( processName );
       
   829     if ( err == KErrNone )
       
   830         {
       
   831         HTI_LOG_TEXT( "try to open..." );
       
   832         err = aPrs.Open( finder );
       
   833         HTI_LOG_TEXT( "opened" );
       
   834 
       
   835         if ( err == KErrNone )
       
   836             {
       
   837             HTI_LOG_TEXT( "OpenHtiProcess OK" );
       
   838             return ETrue;
       
   839             }
       
   840         else
       
   841             {
       
   842             HTI_LOG_TEXT( "Failed to open process" );
       
   843             TBuf<64> msg;
       
   844             msg.Format( _L( "Error: %d" ), err );
       
   845             iAppView->SetStatus( msg );
       
   846             }
       
   847         }
       
   848     else if ( err == KErrNotFound )
       
   849         {
       
   850         HTI_LOG_TEXT( "Not found" );
       
   851         _LIT( KNotFound, "Stopped" );
       
   852         iAppView->SetStatus( KNotFound );
       
   853         }
       
   854     else
       
   855         {
       
   856         TBuf<64> msg;
       
   857         msg.Format( _L( "Error: %d" ), err );
       
   858         iAppView->SetStatus( msg );
       
   859         }
       
   860 
       
   861     HTI_LOG_TEXT( "OpenHtiProcess NOK" );
       
   862 
       
   863     return EFalse;
       
   864     }
       
   865 
       
   866 
       
   867 void CHtiAdminAppUi::UpdateVersion()
       
   868     {
       
   869     HTI_LOG_TEXT( "UpdateVersion" );
       
   870     TBuf<128> tmp;
       
   871     tmp.Format( KHtiAdminVersionFormat, KHtiVersionMajor, KHtiVersionMinor,
       
   872         KHtiVersionBuild, KHtiVersionYear, KHtiVersionWeek );
       
   873      iAppView->SetVersion( tmp );
       
   874     }
       
   875 
       
   876 
       
   877 void CHtiAdminAppUi::UpdateStatusL()
       
   878     {
       
   879     HTI_LOG_TEXT( "UpdateStatusL" );
       
   880     RProcess prs;
       
   881     if ( OpenHtiProcess( prs ) )
       
   882         {
       
   883         HTI_LOG_TEXT( "Update display" );
       
   884         TExitType exT = prs.ExitType();
       
   885 
       
   886         switch ( exT )
       
   887             {
       
   888             case EExitPending:
       
   889                 {
       
   890                 _LIT( KTxt, "Running" );
       
   891                 iAppView->SetStatus( KTxt );
       
   892 
       
   893                 // start timer to watch the status
       
   894                 if ( !iPeriodic )
       
   895                     {
       
   896                     iPeriodic = CPeriodic::NewL( CActive::EPriorityStandard );
       
   897                     iPeriodic->Start( 5 * 1000 * 1000,
       
   898                                       5 * 1000 * 1000,
       
   899                                       TCallBack( TimerCallBackL, this ) );
       
   900                     }
       
   901                 }
       
   902                 break;
       
   903 
       
   904             case EExitKill:
       
   905             case EExitTerminate:
       
   906                 {
       
   907                 _LIT( KTxt, "Stopped" );
       
   908                 iAppView->SetStatus( KTxt );
       
   909                 KillTimer();
       
   910                 }
       
   911                 break;
       
   912 
       
   913             case EExitPanic:
       
   914                 {
       
   915                 _LIT( KTxt, "Panic" );
       
   916                 iAppView->SetStatus( KTxt );
       
   917                 KillTimer();
       
   918                 }
       
   919                 break;
       
   920             };
       
   921         prs.Close();
       
   922         }
       
   923     else
       
   924         {
       
   925         KillTimer();
       
   926         }
       
   927     }
       
   928 
       
   929 void CHtiAdminAppUi::UpdateAutoStartStatus()
       
   930     {
       
   931     HTI_LOG_TEXT( "UpdateAutoStartStatus" );
       
   932     TInt value = KErrNotFound;
       
   933     TRAPD( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   934     if ( !err )
       
   935         {
       
   936         TRAP( err, value = iHtiCfg->GetParameterIntL(KEnableHtiAutoStart) );
       
   937         }
       
   938 
       
   939     if ( value == KErrNotFound )
       
   940         {
       
   941         // Use default values if not found from config.
       
   942 #ifdef __WINS__
       
   943         value = 0;
       
   944 #else
       
   945         value = 1;
       
   946 #endif
       
   947         }
       
   948 
       
   949     if ( value == 0 )
       
   950         {
       
   951         _LIT( KTxt, "Disabled" );
       
   952         iAppView->SetAutoStartStatus( KTxt );
       
   953         }
       
   954     else if ( value == 1 )
       
   955         {
       
   956         _LIT( KTxt, "Enabled" );
       
   957         iAppView->SetAutoStartStatus( KTxt );
       
   958         }
       
   959     else
       
   960         {
       
   961         _LIT( KTxt, "Unknown" );
       
   962         iAppView->SetAutoStartStatus( KTxt );
       
   963         }
       
   964     }
       
   965 
       
   966 void CHtiAdminAppUi::UpdateSelectedComm()
       
   967     {
       
   968     HTI_LOG_TEXT( "UpdateSelectedComm" );
       
   969     TBuf<64> commPlugin;
       
   970     TRAPD( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiCfg ) );
       
   971     if ( !err )
       
   972         {
       
   973         TBuf8<KMaxParameterValueLength> commValue;
       
   974         TRAP( err, commValue = iHtiCfg->GetParameterL( KCommPlugin ) );
       
   975         if ( err == KErrNone )
       
   976             {
       
   977             commPlugin.Copy( commValue );
       
   978             }
       
   979         }
       
   980     // Use default if not found from config
       
   981     if ( commPlugin.Length() == 0 )
       
   982         {
       
   983         commPlugin.Copy(KCommDefaultImplementation  );        
       
   984         }
       
   985     iAppView->SetSelectedComm( commPlugin );
       
   986 
       
   987     if ( commPlugin.Compare( _L( "SERIAL" ) ) == 0 )
       
   988         {
       
   989         TInt portNum = 0;
       
   990         TRAP( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiSerialCommCfg ) );
       
   991         if ( err == KErrNone )
       
   992             {
       
   993             TRAP( err, portNum = iHtiCfg->GetParameterIntL( KCommPortNumber ) );
       
   994             }
       
   995         TBuf<16> portBuf;
       
   996         portBuf.Copy( _L( "Port: " ) );
       
   997         portBuf.AppendNum( portNum );
       
   998         iAppView->SetCommDetails( portBuf );
       
   999         }
       
  1000 
       
  1001     else if ( commPlugin.Compare( _L( "BTSERIAL" ) ) == 0 )
       
  1002         {
       
  1003         TBuf<64> hostBuf;
       
  1004         TRAP( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiBtCommCfg ) );
       
  1005         if ( err == KErrNone )
       
  1006             {
       
  1007             TBuf8<KMaxParameterValueLength> hostValue;
       
  1008             TRAP( err, hostValue = iHtiCfg->GetParameterL( KBtDeviceAddress ) );
       
  1009             if ( err != KErrNone )
       
  1010                 {
       
  1011                 TRAP( err, hostValue = iHtiCfg->GetParameterL( KBtDeviceName ) );
       
  1012                 }
       
  1013             if ( err == KErrNone )
       
  1014                 {
       
  1015                 hostBuf.Copy( hostValue );
       
  1016                 }
       
  1017             }
       
  1018         if ( hostBuf.Length() > 0 )
       
  1019             {
       
  1020             hostBuf.Insert( 0, _L( "Host: " ) );
       
  1021             }
       
  1022         iAppView->SetCommDetails( hostBuf );
       
  1023         }
       
  1024 
       
  1025     else if ( commPlugin.Compare( _L( "IPCOMM" ) ) == 0 )
       
  1026         {
       
  1027         TBuf<128> hostBuf;
       
  1028         TRAP( err, iHtiCfg->LoadCfgL( KCfgFilePath, KHtiIPCommCfg ) );
       
  1029         if ( err == KErrNone )
       
  1030             {
       
  1031             TInt localPort = 0;
       
  1032             TRAP( err, localPort = iHtiCfg->GetParameterIntL( KLocalPort ) );
       
  1033             if ( err == KErrNone && localPort > 0 )
       
  1034                 {
       
  1035                 hostBuf.Copy( _L( "Listen: " ) );
       
  1036                 hostBuf.AppendNum( localPort );
       
  1037                 }
       
  1038             else
       
  1039                 {
       
  1040                 TBuf8<KMaxParameterValueLength> remoteHost;
       
  1041                 TInt remotePort = 0;
       
  1042                 TRAP( err, remoteHost = iHtiCfg->GetParameterL( KRemoteHost ) );
       
  1043                 if ( err == KErrNone )
       
  1044                     {
       
  1045                     TRAP( err, remotePort = iHtiCfg->GetParameterIntL(
       
  1046                             KRemotePort ) );
       
  1047                     }
       
  1048                 if ( err == KErrNone )
       
  1049                     {
       
  1050                     hostBuf.Copy( remoteHost );
       
  1051                     hostBuf.Insert( 0, _L("Connect: " ) );
       
  1052                     hostBuf.Append( ':' );
       
  1053                     hostBuf.AppendNum( remotePort );
       
  1054                     }
       
  1055                 else
       
  1056                     {
       
  1057                     hostBuf.Copy( _L( "Invalid config!" ) );
       
  1058                     }
       
  1059                 }
       
  1060             }
       
  1061         iAppView->SetCommDetails( hostBuf );
       
  1062         }
       
  1063 
       
  1064     else
       
  1065         {
       
  1066         iAppView->SetCommDetails( KNullDesC );
       
  1067         }
       
  1068     }
       
  1069 
       
  1070 void CHtiAdminAppUi::KillHtiWatchDogL()
       
  1071     {
       
  1072     TFullName processName;
       
  1073     TFindProcess finder( KHtiWatchDogMatchPattern );
       
  1074     TInt err = finder.Next( processName );
       
  1075     if ( err == KErrNone )
       
  1076         {
       
  1077         HTI_LOG_TEXT( "HTI watchdog process found. Trying to open and kill it..." );
       
  1078         RProcess prs;
       
  1079         User::LeaveIfError( prs.Open( finder ) );
       
  1080         prs.Kill( KTerminateReason );
       
  1081         prs.Close();
       
  1082         HTI_LOG_TEXT( "HTI watchdog killed" );
       
  1083         }
       
  1084     }
       
  1085 
       
  1086 void CHtiAdminAppUi::KillTimer()
       
  1087     {
       
  1088     if ( iPeriodic )
       
  1089         {
       
  1090         iPeriodic->Cancel();
       
  1091         delete iPeriodic;
       
  1092         iPeriodic = NULL;
       
  1093         }
       
  1094     }
       
  1095 
       
  1096 TInt CHtiAdminAppUi::TimerCallBackL( TAny* aPtr )
       
  1097     {
       
  1098     ( (CHtiAdminAppUi*)aPtr )->UpdateStatusL();
       
  1099     return ETrue;
       
  1100     }
       
  1101 
       
  1102 void CHtiAdminAppUi::ShowCommsDBListQueryL()
       
  1103     {
       
  1104     TInt selectedOption( KErrNotFound );
       
  1105     TBuf<KMaxParameterValueLength> name;
       
  1106                  
       
  1107     CDesCArrayFlat* array = new (ELeave) CDesCArrayFlat(16);
       
  1108     CleanupStack::PushL(array);
       
  1109 
       
  1110     // Get IAP names from the database
       
  1111     CCommsDatabase* db = CCommsDatabase::NewL(EDatabaseTypeIAP);;
       
  1112     CleanupStack::PushL(db);
       
  1113     db->ShowHiddenRecords();
       
  1114     CCommsDbTableView* view = db->OpenTableLC(TPtrC(IAP));
       
  1115     TInt res = view->GotoFirstRecord();
       
  1116 
       
  1117     while(res == KErrNone)
       
  1118         {
       
  1119         view->ReadTextL(TPtrC(COMMDB_NAME), name);
       
  1120         array->InsertL(0, name);
       
  1121         res = view->GotoNextRecord();
       
  1122         }
       
  1123 
       
  1124     CleanupStack::PopAndDestroy(view); //view
       
  1125     CleanupStack::PopAndDestroy(db); //db    
       
  1126 
       
  1127     // Show IAP selection dialog
       
  1128     CAknListQueryDialog* dlg = new(ELeave) CAknListQueryDialog(&selectedOption);
       
  1129     dlg->PrepareLC(R_SELECT_IAP_DIALOG);
       
  1130     dlg->SetItemTextArray(array);
       
  1131     dlg->SetOwnershipType(ELbmDoesNotOwnItemArray);
       
  1132     dlg->RunLD();
       
  1133 
       
  1134     if(selectedOption != KErrNotFound)
       
  1135         {
       
  1136         // Write selected IAP name to config file
       
  1137         name = array->MdcaPoint(selectedOption); 
       
  1138         TBuf8<KMaxParameterValueLength> iapName;
       
  1139         iapName.Copy(name);
       
  1140         iHtiCfg->SetParameterL(KIAPName, iapName);
       
  1141         }
       
  1142     CleanupStack::PopAndDestroy(array); 
       
  1143     }
       
  1144 // End of file