dbgagents/trkagent/app/s60/TrkAppView.cpp
changeset 0 c6b0df440bee
equal deleted inserted replaced
-1:000000000000 0:c6b0df440bee
       
     1 /*
       
     2 * Copyright (c) 2005 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <coecntrl.h>
       
    22 #include <eikenv.h>
       
    23 #include <eikmenup.h>
       
    24 #include <akntitle.h>
       
    25 #include <AknUtils.h>
       
    26 #include <aknmessagequerydialog.h>
       
    27 #include <AknGlobalNote.h>
       
    28 
       
    29 #include <avkon.rsg>
       
    30 #include <trkapp_200170bb.rsg>
       
    31 
       
    32 #include "trkservereventlistener.h"
       
    33 #include "trkdebugstatelistener.h"
       
    34 #include "trkconnstatelistener.h"
       
    35 #include "TrkUids.h"
       
    36 #include "TrkSettingsData.h"
       
    37 #include "TrkAppContainer.h"
       
    38 #include "TrkAppUi.h"
       
    39 #include "TrkAppView.h"
       
    40 #include "TrkApp.hrh"
       
    41 
       
    42 #ifdef __OEM_TRK__
       
    43 _LIT(KAboutText, "System TRK \nVersion %d.%d.%d \nTRK API Version %d.%d\nCopyright (c) 2006-2008, Nokia\n All rights reserved");
       
    44 #else
       
    45 _LIT(KAboutText, "Application TRK \nVersion %d.%d.%d \nTRK API Version %d.%d\nCopyright (c) 2006-2008, Nokia\n All rights reserved");
       
    46 #endif
       
    47 
       
    48 #define DISABLE_CRASH_LOGGER
       
    49 #define KMaxCmdLineLength 20
       
    50 
       
    51 // ---------------------------------------------------------
       
    52 // CTrkAppView::CTrkAppView
       
    53 // Constructor
       
    54 // ---------------------------------------------------------
       
    55 //
       
    56 CTrkAppView::CTrkAppView(CTrkSettingsData* aSettingsData, RTrkSrvCliSession& aTrkSession)
       
    57 	: //iVwsSession(NULL),
       
    58 	  iSettingsData(aSettingsData),
       
    59 	  iContainer(NULL),
       
    60 	  iTrkSession(aTrkSession),
       
    61 	  iConnStatus(ETrkNotConnected),
       
    62 	  iConnMsg(KNullDesC),
       
    63 	  iDebugging(EFalse),
       
    64 	  iTrkDebugStateListener(NULL),
       
    65 	  iTrkConnStateListener(NULL)
       
    66 {
       
    67 }
       
    68 
       
    69 // ---------------------------------------------------------
       
    70 // CTrkAppView::NewL
       
    71 // 
       
    72 // ---------------------------------------------------------
       
    73 //
       
    74 CTrkAppView* CTrkAppView::NewL(CTrkSettingsData* aSettingsData, RTrkSrvCliSession& aTrkSession)
       
    75 {
       
    76 	CTrkAppView* self = new(ELeave) CTrkAppView(aSettingsData, aTrkSession);
       
    77 	CleanupStack::PushL(self);
       
    78 	self->ConstructL();
       
    79 	CleanupStack::Pop();
       
    80 	return self;
       
    81 }
       
    82 // ---------------------------------------------------------
       
    83 // CTrkAppView::~CTrkAppView
       
    84 // Desctructor
       
    85 // ---------------------------------------------------------
       
    86 //
       
    87 CTrkAppView::~CTrkAppView()
       
    88 {
       
    89 	//if (iVwsSession)
       
    90 	//{
       
    91 	//	iVwsSession->EnableServerEventTimeOut(ETrue);
       
    92 	//	delete iVwsSession;
       
    93 	//}
       
    94 	
       
    95     if (iContainer)
       
    96     {
       
    97 	    AppUi()->RemoveFromStack(iContainer);
       
    98 	    delete iContainer;
       
    99 	    iContainer = NULL;
       
   100     }
       
   101 
       
   102     if (iTrkDebugStateListener)
       
   103     {
       
   104         delete iTrkDebugStateListener;
       
   105         iTrkDebugStateListener = NULL;
       
   106     }
       
   107     if (iTrkConnStateListener)
       
   108     {
       
   109         delete iTrkConnStateListener;
       
   110         iTrkConnStateListener = NULL;
       
   111     }
       
   112 }
       
   113 
       
   114 // ---------------------------------------------------------
       
   115 // CTrkAppView::ConstructL
       
   116 // 
       
   117 // ---------------------------------------------------------
       
   118 //
       
   119 
       
   120 void CTrkAppView::ConstructL()
       
   121 {
       
   122     BaseConstructL(R_TRKAPP_VIEW);
       
   123 
       
   124 	RProcess().SetPriority(EPriorityHigh);
       
   125 	RThread().SetPriority(EPriorityAbsoluteHigh);
       
   126 
       
   127 #ifdef DISABLE_CRASH_LOGGER	
       
   128 	//Close the Mobile Crash Logger.
       
   129 	//CloseCrashLogger();
       
   130 #endif
       
   131 	
       
   132     iTrkSession.GetTrkVersion(iMajorVersion, iMinorVersion, iMajorAPIVersion, iMinorAPIVersion, iBuildNumber);    
       
   133     iTrkSession.GetDebugConnStatus(iConnStatus, iConnMsg);
       
   134     iTrkSession.GetDebuggingStatus(iDebugging);
       
   135     
       
   136     iTrkDebugStateListener = new CTrkDebugStateListener(iTrkSession, this);
       
   137     iTrkDebugStateListener->ListenL();
       
   138     
       
   139     iTrkConnStateListener = new CTrkConnStateListener(iTrkSession, this);
       
   140     iTrkConnStateListener->ListenL();
       
   141 	}
       
   142 	
       
   143 // ---------------------------------------------------------
       
   144 // CTrkAppView::GetCmdLineConnTypeL
       
   145 // Now this function wont be used
       
   146 // ---------------------------------------------------------
       
   147 //
       
   148 TTrkConnType CTrkAppView::GetCmdLineConnTypeL()
       
   149 {
       
   150     TTrkConnType connType = ETrkConnInvalid;
       
   151     
       
   152 	// Get command line argument
       
   153     if (User::CommandLineLength() > 0)
       
   154     {
       
   155         TBuf<512> commandLineArguments;
       
   156 		User::CommandLine( commandLineArguments );
       
   157 
       
   158 		// Check command line argument
       
   159 	    if (0 == commandLineArguments.Compare(KCmdLineConnTypeUsb))
       
   160 	    {
       
   161 	        connType = ETrkUsbDbgTrc;
       
   162 	    }
       
   163 	    else if (0 == commandLineArguments.Compare(KCmdLineConnTypeXti))
       
   164 	    {
       
   165             connType =  ETrkXti;
       
   166         }
       
   167     }
       
   168     if (connType == ETrkConnInvalid)
       
   169     	User::Leave(KErrNotFound);
       
   170     
       
   171     return connType;  
       
   172 }
       
   173 
       
   174 // ---------------------------------------------------------
       
   175 // TUid CTrkAppView::Id()
       
   176 // Return id of this view instance
       
   177 // ---------------------------------------------------------
       
   178 //
       
   179 TUid CTrkAppView::Id() const
       
   180 {
       
   181     return KUidTrkAppView;
       
   182 }
       
   183 
       
   184 // ---------------------------------------------------------
       
   185 // CTrkAppView::HandleCommandL(TInt aCommand)
       
   186 // Command handler
       
   187 // ---------------------------------------------------------
       
   188 //
       
   189 void CTrkAppView::HandleCommandL(TInt aCommand)
       
   190 {
       
   191   	switch (aCommand)
       
   192 	{
       
   193   	    case EAknSoftkeyBack:
       
   194   	    {
       
   195             AppUi()->ActivateViewL(iPrevViewId);
       
   196             break;
       
   197   	    }
       
   198 		case ETrkConnect:
       
   199 		{
       
   200             TInt err = iTrkSession.Connect();
       
   201             if(!err)
       
   202             {
       
   203                 iTrkSession.GetDebugConnStatus(iConnStatus, iConnMsg);
       
   204 			}
       
   205 			
       
   206 			// force redraw here
       
   207 			iContainer->DrawNow();
       
   208 			break;
       
   209 		}
       
   210 		case ETrkDisconnect:
       
   211 		{
       
   212             iTrkSession.DisConnect();
       
   213             iConnStatus = ETrkNotConnected;
       
   214 			iConnMsg = KNullDesC;
       
   215 			// force redraw here
       
   216 			iContainer->DrawNow();
       
   217 			break;
       
   218 		}		
       
   219 		case ETrkSettings:
       
   220 		{
       
   221 			AppUi()->ActivateLocalViewL(KUidTrkConnSettingsView);
       
   222 			break;
       
   223 		}
       
   224 		case ETrkAbout:
       
   225 		{
       
   226     		// Show the dialog.
       
   227     		TBuf<KMaxPath> versionInfo;
       
   228     		versionInfo.Format(KAboutText, iMajorVersion, iMinorVersion, iBuildNumber, iMajorAPIVersion, iMinorAPIVersion);
       
   229     		
       
   230 		    CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL(versionInfo);
       
   231 		    dlg->PrepareLC(R_TRK_ABOUT_DIALOG);
       
   232 		    CAknPopupHeadingPane* hPane = dlg->QueryHeading();
       
   233 
       
   234 		    if (hPane)
       
   235 			{
       
   236 				hPane->SetTextL(_L("TRK for Symbian OS"));
       
   237 			}
       
   238 		    dlg->RunLD();
       
   239 
       
   240     		break;
       
   241 		}
       
   242 		default:
       
   243 		{
       
   244 			AppUi()->HandleCommandL(aCommand);
       
   245 			break;
       
   246 		}
       
   247 	}
       
   248 }
       
   249 
       
   250 
       
   251 // ---------------------------------------------------------
       
   252 // CTrkAppView::DoActivateL(...)
       
   253 // Activation of this view instance.
       
   254 // ---------------------------------------------------------
       
   255 //
       
   256 void CTrkAppView::DoActivateL(const TVwsViewId& /*aPrevViewId*/, TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/)
       
   257 {
       
   258     if (!iContainer)
       
   259 	{
       
   260         iContainer = new (ELeave) CTrkAppContainer(this);
       
   261         iContainer->SetMopParent(this);
       
   262         iContainer->ConstructL(ClientRect());
       
   263 	    AppUi()->AddToStackL(*this, iContainer);
       
   264 			    
       
   265 	    iContainer->MakeVisible(ETrue);
       
   266 	    iContainer->ActivateL();
       
   267 	} 
       
   268 }
       
   269 
       
   270 // ---------------------------------------------------------
       
   271 // CConnTestView::DoDeactivate()
       
   272 // Deactivation of this view instance. Controls are not 
       
   273 // deleted, so that old information in status and output
       
   274 // windows stays visible.
       
   275 // ---------------------------------------------------------
       
   276 //
       
   277 void CTrkAppView::DoDeactivate()
       
   278 {
       
   279     if (iContainer)
       
   280     {
       
   281         AppUi()->RemoveFromStack(iContainer);
       
   282 	   	iContainer->MakeVisible(EFalse);
       
   283 	    delete iContainer;
       
   284 	    iContainer = NULL;    
       
   285     }
       
   286  }
       
   287 
       
   288 void CTrkAppView::ViewActivatedL(const TVwsViewId& aPrevViewId, TUid aCustomMessageId, const TDesC8& aCustomMessage)
       
   289 {
       
   290     // save the previous view id
       
   291     if ((KUidTrk != aPrevViewId.iAppUid) && (KUidTrkConnSettingsView != aPrevViewId.iViewUid))
       
   292     {
       
   293         iPrevViewId = aPrevViewId;
       
   294     }
       
   295     CAknView::ViewActivatedL(aPrevViewId, aCustomMessageId, aCustomMessage);
       
   296 }
       
   297 
       
   298 void CTrkAppView::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
       
   299 {
       
   300 	if (R_TRK_MAIN_MENU == aResourceId)
       
   301 	{
       
   302 		switch (iConnStatus)
       
   303 	    {
       
   304 		    case ETrkConnected:
       
   305 			{
       
   306 				aMenuPane->SetItemDimmed(ETrkConnect, ETrue);
       
   307 				//If there is an active debug session, don't allow the user to disconnect.
       
   308 		        aMenuPane->SetItemDimmed(ETrkDisconnect, iDebugging);
       
   309 		        aMenuPane->SetItemDimmed(EAknSoftkeyExit, EFalse);
       
   310 		        break;
       
   311 	        }
       
   312 		    case ETrkNotConnected:
       
   313 		    case ETrkConnectionError:
       
   314 			{
       
   315 				aMenuPane->SetItemDimmed(ETrkConnect, EFalse);
       
   316 		        aMenuPane->SetItemDimmed(ETrkDisconnect, ETrue);            
       
   317 		        aMenuPane->SetItemDimmed(EAknSoftkeyExit, EFalse);
       
   318 		        break;
       
   319 	        }
       
   320 		    case ETrkConnecting:
       
   321 	        {
       
   322 		        aMenuPane->SetItemDimmed(ETrkConnect, ETrue);
       
   323 				aMenuPane->SetItemDimmed(ETrkDisconnect, ETrue);			
       
   324 		        aMenuPane->SetItemDimmed(EAknSoftkeyExit, ETrue);
       
   325 		        break;
       
   326 	        }		    	        	        
       
   327 		}
       
   328 	}
       
   329 }
       
   330 
       
   331 // -----------------------------------------------------------------------------
       
   332 // CTrkAppView::HandleSizeChange
       
   333 // Handle screen size change.
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 void CTrkAppView::HandleSizeChange()
       
   337 {
       
   338     if (iContainer)
       
   339     {
       
   340         TRect mainPaneRect;
       
   341         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
       
   342         iContainer->SetRect(mainPaneRect);
       
   343     }
       
   344 }
       
   345 
       
   346 /** 
       
   347  * Handle status pane size change for this view (override)
       
   348  */
       
   349 void CTrkAppView::HandleStatusPaneSizeChange()
       
   350 {
       
   351 	CAknView::HandleStatusPaneSizeChange();
       
   352 }
       
   353 
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // CTrkAppView::GetConnectionMsg
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 void CTrkAppView::GetConnectionMsg(TDes& aMessage)
       
   360 {
       
   361 	aMessage = iConnMsg;
       
   362 }
       
   363 
       
   364 void CTrkAppView::DebugStateChanged(TBool& aDebugging)
       
   365 {
       
   366     iDebugging = aDebugging;
       
   367 }
       
   368 
       
   369 void CTrkAppView::ConnectionStateChanged(TTrkConnStatus& aConnStatus) 
       
   370 {
       
   371     iConnStatus = aConnStatus;
       
   372     
       
   373     switch(iConnStatus)
       
   374     {
       
   375         case ETrkConnected:
       
   376         case ETrkConnecting:
       
   377         case ETrkConnectionError:
       
   378         case ETrkNotConnected:
       
   379              iTrkSession.GetDebugConnStatus(iConnStatus, iConnMsg);
       
   380              break;
       
   381                     
       
   382         default: 
       
   383             iConnMsg = KNullDesC;
       
   384             break;
       
   385 	}
       
   386 
       
   387     // force redraw here
       
   388     iContainer->DrawDeferred();
       
   389 }
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // CTrkAppView::CloseCrashLogger
       
   393 // -----------------------------------------------------------------------------
       
   394 //
       
   395 TInt CTrkAppView::CloseCrashLogger()
       
   396 {
       
   397 	TInt err = KErrNone;
       
   398 	
       
   399 	//The old mobile crash file name is "d_exc_mc.exe" and the new one is "mc_useragent.exe"	
       
   400 	//This is the string that needs to be passed to the RProcess::Open call to get a handle.
       
   401 	//The complete process name actually includes the UID info as well.
       
   402 	//Instead of hard coding the process name, its better to just 
       
   403 	//search for the process and find it that way.		
       
   404 	//_LIT16(KCrashLoggerName, "mc_useragent.exe[1020e519]0001");
       
   405 	_LIT16(KOldCrashLoggerName, "d_exc_mc*");
       
   406 	_LIT16(KCrashLoggerName, "mc_useragent*");
       
   407 	
       
   408 	err = TerminateProcess(KOldCrashLoggerName);
       
   409 	err = TerminateProcess(KCrashLoggerName);
       
   410 
       
   411 	return err;
       
   412 }
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 // CTrkAppView::TerminateProcess()
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 TInt CTrkAppView::TerminateProcess(const TDesC& aProcessName)
       
   419 {
       
   420 	_LIT16(KCrashLoggerClMsg, "Closing crash logger");
       
   421 	
       
   422 	TFindProcess find(aProcessName);
       
   423 	TFullName name;	
       
   424 		
       
   425 	TInt err = find.Next(name);
       
   426 	if (KErrNone == err)
       
   427 	{	
       
   428 		RProcess process;
       
   429 		err = process.Open(find);
       
   430 	
       
   431 		if (KErrNone == err)
       
   432 		{
       
   433 			User::InfoPrint(KCrashLoggerClMsg);
       
   434 			process.Kill(KErrNone);
       
   435 		}
       
   436 	}
       
   437 	return err;
       
   438 }
       
   439