dbgsrv/coredumpserver/ui/coredumpui/src/coredumpuiresourceview.cpp
changeset 0 c6b0df440bee
equal deleted inserted replaced
-1:000000000000 0:c6b0df440bee
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Source file for the implementation of the 
       
    15 // application view class - CResourceView
       
    16 //
       
    17 
       
    18 #include "coredumpui.h"
       
    19 
       
    20 CResourceView::CResourceView()
       
    21 	{
       
    22 	}
       
    23 
       
    24 CResourceView* CResourceView::NewL(const TRect& aRect, CResourceAppUi *aAppUi)
       
    25 	{
       
    26 	CResourceView* self = new(ELeave) CResourceView();
       
    27 	CleanupStack::PushL(self);
       
    28 	self->ConstructL(aRect, aAppUi);
       
    29 	CleanupStack::Pop();
       
    30 	return self;
       
    31 	}
       
    32 
       
    33 CResourceView::~CResourceView()
       
    34 	{
       
    35     delete iCommandButton;
       
    36     delete iObserveButton;
       
    37     delete iLoadButton;
       
    38 	}
       
    39 
       
    40 void CResourceView::ConstructL(const TRect& aRect, CResourceAppUi* aAppUi)
       
    41     {
       
    42 	// Initialisation
       
    43 	iAppUi = aAppUi;
       
    44 	iObjectsViewed = EObjectProcess;
       
    45 
       
    46 	CreateWindowL();
       
    47 	           
       
    48 	// Whole extent of view
       
    49 	SetRect(aRect);
       
    50 
       
    51 	// Border around components in pixels
       
    52 	iBorder = 1;
       
    53 
       
    54 	// Place the refresh button	
       
    55 	iCommandButton = new(ELeave) CEikCommandButton;
       
    56 	iCommandButton->SetTextL(_L("Refresh"));
       
    57 	iCommandButton->SetSize(iCommandButton->MinimumSize());
       
    58 	iCommandButton->SetPosition(TPoint(Rect().Width() - iCommandButton->Size().iWidth - iBorder, iBorder));
       
    59 	iCommandButton->SetContainerWindowL(*this);
       
    60 	iCommandButton->SetObserver(this);
       
    61 
       
    62 	// Place the observe button	
       
    63 	iObserveButton = new(ELeave) CEikCommandButton;
       
    64 	iObserveButton->SetTextL(_L("Observe"));
       
    65 	iObserveButton->SetSize(iObserveButton->MinimumSize());
       
    66 	TInt x = Rect().Width() - iObserveButton->Size().iWidth - iCommandButton->Size().iWidth - iBorder;
       
    67 	iObserveButton->SetPosition(TPoint(x , iBorder));
       
    68 	iObserveButton->SetContainerWindowL(*this);
       
    69 	iObserveButton->SetObserver(this);
       
    70 
       
    71 	// Place the load button
       
    72 	iLoadButton = new(ELeave) CEikCommandButton;
       
    73 	iLoadButton->SetTextL(_L("Load"));
       
    74 	iLoadButton->SetSize(iLoadButton->MinimumSize());
       
    75 	x -= iLoadButton->Size().iWidth;
       
    76 	iLoadButton->SetPosition(TPoint(x , iBorder));
       
    77 	iLoadButton->SetContainerWindowL(*this);
       
    78 	iLoadButton->SetObserver(this);
       
    79 	iLoadButton->SetDimmed(ETrue);
       
    80 
       
    81 	TInt buttonHeight = iCommandButton->Size().iHeight;	
       
    82 
       
    83 	// Get the title font height
       
    84 	TInt titleHeight = iEikonEnv->TitleFont()->HeightInPixels();
       
    85 	TInt tablePosition = 0;
       
    86 	if (titleHeight>=buttonHeight) 
       
    87 		tablePosition=titleHeight;
       
    88 	else
       
    89 		tablePosition=buttonHeight;
       
    90 
       
    91 	CResourceList::ConstructL(tablePosition);// Activate the main window control - this will also activate the contained controls
       
    92 	
       
    93 	ActivateL();
       
    94 	DrawNow();
       
    95 	
       
    96 	}
       
    97 
       
    98 TDes& CResourceView::CrashProgress()
       
    99 	{
       
   100     return iCrashProgress;
       
   101 	}
       
   102 
       
   103 void CResourceView::Draw(const TRect& /*aRect*/) const
       
   104 	{
       
   105 	CWindowGc& gc = SystemGc();                     
       
   106 
       
   107 	gc.Clear();
       
   108 		
       
   109 	// Put title on view
       
   110 	const CFont* fontUsed = iEikonEnv->TitleFont();
       
   111 	gc.UseFont(fontUsed);
       
   112 	gc.SetPenColor(KRgbBlack);
       
   113 	TPoint pos(iBorder,fontUsed->AscentInPixels()+iBorder);
       
   114 	gc.DrawText(iTitle, pos);
       
   115 
       
   116 	gc.DiscardFont();
       
   117 	}
       
   118 
       
   119 TInt CResourceView::CountComponentControls() const
       
   120 	{
       
   121 	return 4;
       
   122 	}
       
   123 
       
   124 CCoeControl* CResourceView::ComponentControl(TInt aIndex) const
       
   125 	{
       
   126 	CCoeControl* cmd = NULL;
       
   127 	switch (aIndex)
       
   128 		{
       
   129 		case 0:
       
   130 			{
       
   131 			cmd = iCommandButton;
       
   132 			break;
       
   133 			}		
       
   134 		case 1:
       
   135 			{
       
   136 			cmd = iObserveButton;
       
   137 			break;
       
   138 			}		
       
   139 		case 2:
       
   140 			{
       
   141 			cmd = iLoadButton;
       
   142 			break;
       
   143 			}		
       
   144 		default:
       
   145 			{
       
   146 			cmd = CResourceList::GetListBox();
       
   147 			}
       
   148 		}
       
   149 	return cmd;
       
   150 	}
       
   151 
       
   152 // for use by refresh button control
       
   153 void CResourceView::HandleControlEventL(CCoeControl* aControl,TCoeEvent /*aEventType*/)
       
   154 	{	
       
   155 	// This code is not nice. A better solution is to extend the CEikCommandButton class to have an enumerator 
       
   156 	// that distinguishes the buttons purpose in a given context. This avoids relying on the text of the label. I dont
       
   157 	// have the time to do it now. Also, the button names make no sense. They were named originally in the context of 
       
   158 	// 1 function, now they serve many
       
   159 	
       
   160 	LOG_MSG("->[UI]CResourceView::HandleControlEventL()");
       
   161 	if (aControl == iCommandButton)
       
   162 		{
       
   163 		if(iCommandButton->Label()->Text()->Compare(_L("Refresh")) == 0)
       
   164 			{
       
   165 			UpdateViewL();
       
   166 			}
       
   167 		else if(iCommandButton->Label()->Text()->Compare(_L("Bind")) == 0)
       
   168 			{
       
   169 			BindPluginsL();
       
   170 			}
       
   171 		UpdateViewL();
       
   172 		}
       
   173 	else if (aControl == iObserveButton)
       
   174 		{
       
   175 		if (iObserveButton->Label()->Text()->Compare(_L("Configure"))==0)
       
   176 			{
       
   177 			ConfigurePluginL();
       
   178 			}
       
   179 		else if(iObserveButton->Label()->Text()->Compare(_L("Observe"))==0)
       
   180 			{
       
   181 			SetObservedL();
       
   182 			}
       
   183 		else if(iObserveButton->Label()->Text()->Compare(_L("Process"))==0)
       
   184 			{
       
   185 			ProcessCrashL();
       
   186 			}
       
   187 		UpdateViewL();
       
   188 		}
       
   189 	else if (aControl == iLoadButton)
       
   190 		{
       
   191 		if(iLoadButton->Label()->Text()->Compare(_L("Load")) == 0)
       
   192 			{
       
   193 			LoadPluginL(); 
       
   194 			}
       
   195 		else if(iLoadButton->Label()->Text()->Compare(_L("Unload")) == 0)
       
   196 			{
       
   197 			UnloadPluginL(); 
       
   198 			}
       
   199 		else if(iLoadButton->Label()->Text()->Compare(_L("Delete")) == 0)
       
   200 			{
       
   201 			DeleteEntireCrashPartitionL();
       
   202 			}
       
   203 		UpdateViewL();
       
   204 		}
       
   205 	}
       
   206 
       
   207 void CResourceView::InvalidateView(void) const
       
   208 	{
       
   209 	Window().Invalidate(Rect()); //calls Draw()
       
   210 	}
       
   211 
       
   212 void CResourceView::UpdateViewL(void)
       
   213 	{
       
   214 	LOG_MSG("->[UI]CResourceView::UpdateView(void)");
       
   215 	UpdateListDataL();	
       
   216 	InvalidateView();
       
   217 	UpdateTitleL();
       
   218 	}
       
   219 
       
   220 void CResourceView::UpdateCrashProgressL()
       
   221 {    
       
   222     InvalidateView();
       
   223     UpdateTitleL();
       
   224 }
       
   225 
       
   226 void CResourceView::UpdateTitleL(void)
       
   227 	{
       
   228 	// assume the table data, iResourceCount and iObjectViewed data are up to date
       
   229 	TBufC<20> title;
       
   230 
       
   231 	// Set the title appropriately
       
   232 	switch (iObjectsViewed)
       
   233 		{
       
   234 		case EObjectProcess: 
       
   235 			{
       
   236 			iLoadButton->SetDimmed(ETrue);
       
   237 			iObserveButton->SetTextL(_L("Observe"));
       
   238 			title = _L("Processes");
       
   239 			iCommandButton->SetTextL(_L("Refresh"));
       
   240 			break;
       
   241 			}
       
   242 		case EObjectThread:
       
   243 			{
       
   244 			iLoadButton->SetDimmed(ETrue);
       
   245 			iObserveButton->SetTextL(_L("Observe"));
       
   246 			title = _L("Threads");
       
   247 			iCommandButton->SetTextL(_L("Refresh"));
       
   248 			break;
       
   249 			}
       
   250 		case EObjectPlugin:
       
   251 			{
       
   252 			iLoadButton->SetDimmed(EFalse);
       
   253 			title = _L("Plugins");
       
   254 			// for plugins, also change the label of the observe button to Configure
       
   255 			iObserveButton->SetDimmed(ETrue);
       
   256 			iLoadButton->SetTextL(_L("Load"));
       
   257 			iLoadButton->SetDimmed(EFalse);
       
   258 			iCommandButton->SetTextL(_L("Refresh"));
       
   259 			break;
       
   260 			}
       
   261 		case EObjectExecutable:
       
   262 			{
       
   263 			iLoadButton->SetDimmed(ETrue);
       
   264 			title = _L("Executables");
       
   265 			iObserveButton->SetTextL(_L("Observe"));
       
   266 			iObserveButton->SetDimmed(EFalse);
       
   267 			iCommandButton->SetTextL(_L("Refresh"));
       
   268 			break;
       
   269 			}
       
   270 		case EObjectPluginInstance:
       
   271 			{
       
   272 			title = _L("Plugin Instances");
       
   273 			iObserveButton->SetTextL(_L("Configure"));
       
   274 			iObserveButton->SetDimmed(EFalse);
       
   275 			iLoadButton->SetTextL(_L("Unload"));
       
   276 			iLoadButton->SetDimmed(EFalse);
       
   277 			iCommandButton->SetTextL(_L("Bind"));
       
   278 			break;
       
   279 			}
       
   280 		case EObjectCrashList:
       
   281 			{
       
   282 			title = _L("Crash List in Flash");
       
   283 			iObserveButton->SetTextL(_L("Process"));
       
   284 			iObserveButton->SetDimmed(EFalse);
       
   285 			iLoadButton->SetTextL(_L("Delete"));
       
   286 			iLoadButton->SetDimmed(EFalse);
       
   287 			iCommandButton->SetTextL(_L(""));
       
   288 			iCommandButton->SetDimmed(ETrue);
       
   289 			break;
       
   290 			}
       
   291 		default:
       
   292 			{
       
   293 			break;
       
   294 			}
       
   295 		}
       
   296 		
       
   297 	iObserveButton->SetSize(iObserveButton->MinimumSize());
       
   298 	TInt x = Rect().Width() - iObserveButton->Size().iWidth - iCommandButton->Size().iWidth - iBorder;
       
   299 	iObserveButton->SetPosition(TPoint(x, iBorder));
       
   300 	iObserveButton->SetContainerWindowL(*this);
       
   301 	iObserveButton->SetObserver(this);
       
   302     
       
   303 	iLoadButton->SetSize(iLoadButton->MinimumSize());
       
   304 	x -= iLoadButton->Size().iWidth;
       
   305 	iLoadButton->SetPosition(TPoint(x, iBorder));
       
   306 	iLoadButton->SetContainerWindowL(*this);
       
   307 	iLoadButton->SetObserver(this);
       
   308 
       
   309 	//set title and resource count
       
   310 	TBuf<2> openingBracket(_L(" ("));
       
   311 	TBuf<1> closingBracket(_L(")"));
       
   312 	iTitle.Format(_L("%S%S%u%S %S"), &title, &openingBracket, iResourceCount, &closingBracket, &iCrashProgress);
       
   313 	}