loadgen/ui/hb/src/settingsview.cpp
branchRCL_3
changeset 22 fad26422216a
parent 21 b3cee849fa46
child 23 f8280f3bfeb7
equal deleted inserted replaced
21:b3cee849fa46 22:fad26422216a
     1 /*
       
     2 * Copyright (c) 2010 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 #include "settingsview.h"
       
    19 #include "enginewrapper.h"
       
    20 #include "loadgen.hrh"
       
    21 #include "loadgen_loadattributes.h"
       
    22 #include <hbmainwindow.h>
       
    23 #include <hbview.h>
       
    24 //#include <hbformitem.h>
       
    25 #include <hbmenu.h>
       
    26 #include <hbaction.h>
       
    27 #include <hbmessagebox.h>
       
    28 //#include <hbcommonnote.h>
       
    29 #include <hbtoolbar.h>
       
    30 #include <hbdataform.h>
       
    31 #include <hbdataformmodelitem.h>
       
    32 #include <hbdataformmodel.h>
       
    33 #include <hbdataformviewitem.h>
       
    34 #include <hbabstractviewitem.h>
       
    35 #include <hbradiobuttonlist.h>
       
    36 
       
    37 
       
    38 #include <QStringList>
       
    39 
       
    40 QStringList PRIORITIES = (QStringList() << "Much less (-20)" << "Less (-10)" << "Normal (0)" << "More (10)" 
       
    41 						 << "Much more (20)" << "Real time (30)" << "Abs. very low (100)" << "Abs. low (200)" 
       
    42 						 << "Abs. backgr. (300)" << "Abs. foregr. (400)" << "Abs. high (500)");
       
    43 QStringList LOADMODES = (QStringList() << "Yielding" << "Blocking");
       
    44 QStringList CPULOADTYPES = (QStringList() << "Continuous" << "Periodic");		   
       
    45 QStringList MEMSOURCES = (QStringList() << "RAM" << "C:" << "D:" << "E:" << "F:" << "G:" << "H:" << "J:" << "K:" 
       
    46 										<< "L:" << "M:" << "N:");
       
    47 QStringList MEMEATTYPES = (QStringList() << "Memory to eat" << "Memory to be left" << "Alternate min/max");
       
    48 QStringList KEYPRESSTYPES = (QStringList() << "None" << "Arrow keys");
       
    49 QStringList MESSAGETYPES = (QStringList() << "SMS" << "MMS");
       
    50 
       
    51 		   
       
    52 SettingsView::SettingsView(HbView &mainView, HbMainWindow &parent, EngineWrapper &engine)
       
    53                           
       
    54     : mMainWindow(parent),
       
    55       mMainView(mainView),
       
    56       mEngineWrapper(engine),
       
    57 	  mAmount(NULL),
       
    58 	  mMinAmountToBeLeft(NULL),
       
    59 	  mMaxAmountToBeLeft(NULL),
       
    60 	  mLength(NULL),
       
    61 	  mIdle(NULL),
       
    62 	  mRandomVar(NULL)
       
    63 {
       
    64 }
       
    65 
       
    66 SettingsView::~SettingsView()
       
    67 {
       
    68 
       
    69 }
       
    70 
       
    71 // TODO HbDataFormModelItem data operations does not work correctly with WK38.
       
    72 // Item data does not get updated correctly as set by initial settings(HbDataFormModelItem::RadioButtonListItem) 
       
    73 // or user settings.(HbDataFormModelItem::TextItem)
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 
       
    77 void SettingsView::open(const QString &settingsName, TLoadGenCommandIds cmdId)
       
    78 {
       
    79 	mCmdId = cmdId;
       
    80     // Remove main view from main window and add this view to main window
       
    81     mMainWindow.addView(this);
       
    82     mMainWindow.setCurrentView(this);
       
    83     setTitle(settingsName);
       
    84 
       
    85     //create toolbar showing launch popup
       
    86     HbToolBar *toolBar = this->toolBar();
       
    87     HbAction *actionOk = new HbAction("Ok", toolBar);
       
    88     HbAction *actionCancel = new HbAction("Cancel", toolBar);
       
    89     toolBar->addAction( actionOk );
       
    90     toolBar->addAction( actionCancel );	
       
    91 
       
    92     //create setting form
       
    93     mSettingForm = new HbDataForm();
       
    94     
       
    95     //create a model class
       
    96     mModel = new HbDataFormModel(this);
       
    97 	createItems(mModel, 0);
       
    98     // Set created model to form
       
    99     mSettingForm->setModel(mModel);
       
   100     setWidget(mSettingForm);
       
   101 	loadAttributes();	
       
   102 	
       
   103     connect(actionOk, SIGNAL(triggered()), this, SLOT(okExit()));
       
   104 	connect(actionCancel, SIGNAL(triggered()), this, SLOT(cancelled()));
       
   105 	connect(this, SIGNAL(aboutToClose()), this, SLOT(backButtonPressed()));
       
   106 	connect(mSettingForm, SIGNAL(activated(const QModelIndex)), this, SLOT(dataItemDisplayed(const QModelIndex)));  
       
   107 	show();
       
   108 }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 
       
   112 void SettingsView::createItems(HbDataFormModel *model, 
       
   113 							   HbDataFormModelItem *parent)
       
   114 {
       
   115 	switch (mCmdId) {
       
   116 		case ELoadGenCmdNewLoadCPULoad: {
       
   117 			createCpuLoadItems(model, parent);
       
   118 			break;
       
   119 		}
       
   120 		case ELoadGenCmdNewLoadEatMemory: {
       
   121 			createEatMemoryItems(model, parent);
       
   122 			break;
       
   123 		}
       
   124 		case ELoadGenCmdNewLoadPhoneCall: {
       
   125 			createPhoneCallItems(model, parent);
       
   126 			break;
       
   127 		}
       
   128 		case ELoadGenCmdNewLoadNetConn: {
       
   129 			createNetConnItems(model, parent);
       
   130 			break;
       
   131 		}
       
   132 		case ELoadGenCmdNewLoadKeyPress:
       
   133 		case ELoadGenCmdNewLoadPointerEvent: {
       
   134 			createKeyOrPointerItems(model, parent);
       
   135 			break;
       
   136 		}
       
   137 		case ELoadGenCmdNewLoadMessages: {
       
   138 			createMessageItems(model, parent);
       
   139 			break;
       
   140 		}
       
   141 		case ELoadGenCmdNewLoadApplications: {
       
   142 			createAppsItems(model, parent);
       
   143 			break;
       
   144 		}
       
   145 		case ELoadGenCmdNewLoadPhotoCaptures: {
       
   146 			createPhotoItems(model, parent);
       
   147 			break;
       
   148 		}
       
   149 		case ELoadGenCmdNewLoadBluetooth: {
       
   150 			createBtItems(model, parent);
       
   151 			break;
       
   152 		}
       
   153 		default: {
       
   154 			break;
       
   155 		}
       
   156 	}
       
   157 }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 
       
   161 void SettingsView::createCpuLoadItems(HbDataFormModel *model, HbDataFormModelItem *parent)
       
   162 {
       
   163 
       
   164 	mLoadSettings = model->appendDataFormGroup(QString("CPU load settings"), parent);
       
   165 	
       
   166 	// DataFormItem for priority selection
       
   167 	mPriority = model->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, 
       
   168 										  QString("Priority"), 
       
   169 										  mLoadSettings);
       
   170 	mPriority->setContentWidgetData(QString("items"), PRIORITIES);
       
   171 
       
   172 	// DataFormItem for load mode selection
       
   173 	mLoadMode = model->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, 
       
   174 										  QString("Load mode"), 
       
   175 										  mLoadSettings);
       
   176 	mLoadMode->setContentWidgetData(QString("items"), LOADMODES);		
       
   177 
       
   178 	// DataFormItem for load type selection
       
   179 	mType = model->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, 
       
   180 									  QString("Type"), 
       
   181 									  mLoadSettings);
       
   182 	mType->setContentWidgetData(QString("items"), CPULOADTYPES);
       
   183 
       
   184 }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 
       
   188 void SettingsView::createEatMemoryItems(HbDataFormModel *model, HbDataFormModelItem *parent)
       
   189 {
       
   190 	mLoadSettings = model->appendDataFormGroup(QString("Eat memory settings"), parent);
       
   191 	
       
   192 	// DataFormItem for priority selection
       
   193 	mPriority = model->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, 
       
   194 										  QString("Priority"), 
       
   195 										  mLoadSettings);
       
   196 	mPriority->setContentWidgetData(QString("items"), PRIORITIES);
       
   197 
       
   198 	// DataFormItem for memory eat type selection
       
   199 	mSource = model->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, 
       
   200 									  QString("Source"), 
       
   201 									  mLoadSettings);
       
   202 	mSource->setContentWidgetData(QString("items"), MEMSOURCES);
       
   203 
       
   204 	
       
   205 	// DataFormItem for memory eat type selection
       
   206 	mType = model->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, 
       
   207 									  QString("Type"), 
       
   208 									  mLoadSettings);
       
   209 	mType->setContentWidgetData(QString("items"), MEMEATTYPES);
       
   210 
       
   211 	// DataFormItem for idle length selection
       
   212 	mBuffer = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   213 									  QString("Buffer (B)"), 
       
   214 									  mLoadSettings);
       
   215 	mBuffer->setContentWidgetData("maximum" , 999999999);
       
   216 	mBuffer->setContentWidgetData("minimum", 0);	
       
   217 	
       
   218 	// DataFormItem for idle length selection
       
   219 	mIdle = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   220 									  QString("Idle after buffer (ms)"), 
       
   221 									  mLoadSettings);
       
   222 	mIdle->setContentWidgetData("maximum" , 999999999);
       
   223 	mIdle->setContentWidgetData("minimum", 0);			
       
   224 
       
   225 	mRandomVar = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   226 										   QString("Random variance (%)"), 
       
   227 										   mLoadSettings);
       
   228 	mRandomVar->setContentWidgetData("maximum" , 100);
       
   229 	mRandomVar->setContentWidgetData("minimum", 0);	
       
   230 }	
       
   231 
       
   232 // ---------------------------------------------------------------------------
       
   233 
       
   234 void SettingsView::createPhoneCallItems(HbDataFormModel *model, HbDataFormModelItem *parent)
       
   235 {
       
   236 
       
   237 	mLoadSettings = model->appendDataFormGroup(QString("Phone calls settings"), parent);
       
   238 	
       
   239 	// DataFormItem for priority selection
       
   240 	mPriority = model->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, 
       
   241 										  QString("Priority"), 
       
   242 										  mLoadSettings);
       
   243 	mPriority->setContentWidgetData(QString("items"), PRIORITIES);
       
   244 
       
   245 	mDestination = mModel->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   246 										QString("Phone number:"), 
       
   247 										mLoadSettings);
       
   248 	mDestination->setContentWidgetData("maximum" , 99999999999999999999.0 );
       
   249 	mDestination->setContentWidgetData("minimum", 0);
       
   250 
       
   251 	mLength = mModel->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   252 										QString("Length (ms)"), 
       
   253 										mLoadSettings);
       
   254 	mLength->setContentWidgetData("maximum" , 999999999);
       
   255 	mLength->setContentWidgetData("minimum", 0);
       
   256 	
       
   257 	// DataFormItem for idle length selection
       
   258 	mIdle = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   259 									  QString("Idle (ms)"), 
       
   260 									  mLoadSettings);
       
   261 	mIdle->setContentWidgetData("maximum" , 999999999);
       
   262 	mIdle->setContentWidgetData("minimum", 0);			
       
   263 
       
   264 	mRandomVar = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   265 										   QString("Random variance (%)"), 
       
   266 										   mLoadSettings);
       
   267 	mRandomVar->setContentWidgetData("maximum" , 100);
       
   268 	mRandomVar->setContentWidgetData("minimum", 0);	
       
   269 }
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 
       
   273 void SettingsView::createNetConnItems(HbDataFormModel *model, HbDataFormModelItem *parent)
       
   274 {
       
   275 
       
   276 	mLoadSettings = model->appendDataFormGroup(QString("Network conn. settings"), parent);
       
   277 	
       
   278 	// DataFormItem for priority selection
       
   279 	mPriority = model->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, 
       
   280 										  QString("Priority"), 
       
   281 										  mLoadSettings);
       
   282 	mPriority->setContentWidgetData(QString("items"), PRIORITIES);
       
   283 
       
   284 	mDestination = mModel->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   285 										QString("Destination URL:"), 
       
   286 										mLoadSettings);
       
   287 	
       
   288 	// DataFormItem for idle length selection
       
   289 	mIdle = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   290 									  QString("Idle (ms)"), 
       
   291 									  mLoadSettings);
       
   292 	mIdle->setContentWidgetData("maximum" , 999999999);
       
   293 	mIdle->setContentWidgetData("minimum", 0);			
       
   294 
       
   295 	mRandomVar = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   296 										   QString("Random variance (%)"), 
       
   297 										   mLoadSettings);
       
   298 	mRandomVar->setContentWidgetData("maximum" , 100);
       
   299 	mRandomVar->setContentWidgetData("minimum", 0);	
       
   300 }
       
   301 
       
   302 // ---------------------------------------------------------------------------
       
   303 
       
   304 void SettingsView::createKeyOrPointerItems(HbDataFormModel *model, HbDataFormModelItem *parent)
       
   305 {
       
   306 	QString settingsName;
       
   307 	if (mCmdId == ELoadGenCmdNewLoadPointerEvent) {
       
   308 		settingsName = "Pointer events settings";
       
   309 	}
       
   310 	else {
       
   311 		settingsName = "Key presses settings";
       
   312 	}
       
   313 	mLoadSettings = model->appendDataFormGroup(settingsName, parent);
       
   314 	
       
   315 	// DataFormItem for priority selection
       
   316 	mPriority = model->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, 
       
   317 										  QString("Priority"), 
       
   318 										  mLoadSettings);
       
   319 	mPriority->setContentWidgetData(QString("items"), PRIORITIES);
       
   320 
       
   321 	
       
   322 	// DataFormItem for heartbeat length selection
       
   323 	mHeartBeat = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   324 									  QString("Heartbeat (ms)"), 
       
   325 									  mLoadSettings);
       
   326 	mHeartBeat->setContentWidgetData("maximum" , 999999999);
       
   327 	mHeartBeat->setContentWidgetData("minimum", 0);		
       
   328 	
       
   329 	// Random variance
       
   330 	mRandomVar = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   331 										   QString("Random variance (%)"), 
       
   332 										   mLoadSettings);
       
   333 	mRandomVar->setContentWidgetData("maximum" , 100);
       
   334 	mRandomVar->setContentWidgetData("minimum", 0);	
       
   335 }
       
   336 
       
   337 // ---------------------------------------------------------------------------
       
   338 
       
   339 void SettingsView::createMessageItems(HbDataFormModel *model, HbDataFormModelItem *parent)
       
   340 {
       
   341 	mLoadSettings = model->appendDataFormGroup(QString("Messages settings"), parent);
       
   342 	
       
   343 	// DataFormItem for priority selection
       
   344 	mPriority = model->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, 
       
   345 										  QString("Priority"), 
       
   346 										  mLoadSettings);
       
   347 	mPriority->setContentWidgetData(QString("items"), PRIORITIES);
       
   348 
       
   349 	
       
   350 	mType = model->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, 
       
   351 									  QString("Type"), 
       
   352 									  mLoadSettings);
       
   353 	mType->setContentWidgetData(QString("items"), MESSAGETYPES);	
       
   354 
       
   355 
       
   356 	mDestination = mModel->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   357 										QString("Phone number:"), 
       
   358 										mLoadSettings);
       
   359 	mDestination->setContentWidgetData("maximum" , 99999999999999999999.0 );
       
   360 	mDestination->setContentWidgetData("minimum", 0);
       
   361 	
       
   362 	mAmount	= mModel->insertDataFormItem(3, HbDataFormModelItem::TextItem, 
       
   363 									  QString("Maximum amount of messages"), 
       
   364 									  mLoadSettings);
       
   365 	mAmount->setContentWidgetData("maximum" , 1000);
       
   366 	mAmount->setContentWidgetData("minimum", 0);
       
   367 
       
   368 	mLength = mModel->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   369 										QString("Message length"), 
       
   370 										mLoadSettings);
       
   371 	mLength->setContentWidgetData("maximum" , 999999999);
       
   372 	mLength->setContentWidgetData("minimum", 0);
       
   373 
       
   374 	// DataFormItem for idle length selection
       
   375 	mIdle = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   376 									  QString("Idle (ms)"), 
       
   377 									  mLoadSettings);
       
   378 	mIdle->setContentWidgetData("maximum" , 999999999);
       
   379 	mIdle->setContentWidgetData("minimum", 0);			
       
   380 
       
   381 	mRandomVar = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   382 										   QString("Random variance (%)"), 
       
   383 										   mLoadSettings);
       
   384 	mRandomVar->setContentWidgetData("maximum" , 100);
       
   385 	mRandomVar->setContentWidgetData("minimum", 0);	
       
   386 }
       
   387 
       
   388 // ---------------------------------------------------------------------------
       
   389 
       
   390 void SettingsView::createAppsItems(HbDataFormModel *model, HbDataFormModelItem *parent)
       
   391 {
       
   392 	mLoadSettings = model->appendDataFormGroup(QString("Applications settings"), parent);
       
   393 	
       
   394 	// DataFormItem for priority selection
       
   395 	mPriority = model->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, 
       
   396 										  QString("Priority"), 
       
   397 										  mLoadSettings);
       
   398 	mPriority->setContentWidgetData(QString("items"), PRIORITIES);
       
   399 
       
   400 	mMaxParallelApps = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   401 									  QString("Max parallel applications"), 
       
   402 									  mLoadSettings);
       
   403 	mMaxParallelApps->setContentWidgetData("maximum" , 100);
       
   404 	mMaxParallelApps->setContentWidgetData("minimum", 0);	
       
   405 
       
   406 
       
   407 	// DataFormItem for launching interval length selection
       
   408 	mLaunchingInterval = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   409 									  QString("Launching interval (ms)"), 
       
   410 									  mLoadSettings);
       
   411 	mLaunchingInterval->setContentWidgetData("maximum" , 999999999);
       
   412 	mLaunchingInterval->setContentWidgetData("minimum", 0);	
       
   413 	
       
   414 	// DataFormItem for key press type selection
       
   415 	mKeyPressType = model->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, 
       
   416 										  QString("Key press type"), 
       
   417 										  mLoadSettings);
       
   418 	mKeyPressType->setContentWidgetData(QString("items"), KEYPRESSTYPES);	
       
   419 
       
   420 	// DataFormItem for heartbeat length selection
       
   421 	mHeartBeat = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   422 									  QString("Key press interval (ms)"), 
       
   423 									  mLoadSettings);
       
   424 	mHeartBeat->setContentWidgetData("maximum" , 999999999);
       
   425 	mHeartBeat->setContentWidgetData("minimum", 0);		
       
   426 	
       
   427 	// Random variance
       
   428 	mRandomVar = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   429 										   QString("Random variance (%)"), 
       
   430 										   mLoadSettings);
       
   431 	mRandomVar->setContentWidgetData("maximum" , 100);
       
   432 	mRandomVar->setContentWidgetData("minimum", 0);	
       
   433 }
       
   434 
       
   435 // ---------------------------------------------------------------------------
       
   436 
       
   437 void SettingsView::createPhotoItems(HbDataFormModel *model, HbDataFormModelItem *parent)
       
   438 {
       
   439 	mLoadSettings = model->appendDataFormGroup(QString("Camera settings"), parent);
       
   440 	
       
   441 	// DataFormItem for priority selection
       
   442 	mPriority = model->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, 
       
   443 										  QString("Priority"), 
       
   444 										  mLoadSettings);
       
   445 	mPriority->setContentWidgetData(QString("items"), PRIORITIES);
       
   446 
       
   447 	
       
   448 	// DataFormItem for idle length selection
       
   449 	mIdle = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   450 									  QString("Idle (ms)"), 
       
   451 									  mLoadSettings);
       
   452 	mIdle->setContentWidgetData("maximum" , 999999999);
       
   453 	mIdle->setContentWidgetData("minimum", 0);		
       
   454 	
       
   455 	// Random variance
       
   456 	mRandomVar = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   457 										   QString("Random variance (%)"), 
       
   458 										   mLoadSettings);
       
   459 	mRandomVar->setContentWidgetData("maximum" , 100);
       
   460 	mRandomVar->setContentWidgetData("minimum", 0);	
       
   461 }
       
   462 
       
   463 // ---------------------------------------------------------------------------
       
   464 
       
   465 void SettingsView::createBtItems(HbDataFormModel *model, HbDataFormModelItem *parent)
       
   466 {
       
   467 	mLoadSettings = model->appendDataFormGroup(QString("Bluetooth settings"), parent);
       
   468 	
       
   469 	// DataFormItem for priority selection
       
   470 	mPriority = model->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, 
       
   471 										  QString("Priority"), 
       
   472 										  mLoadSettings);
       
   473 	mPriority->setContentWidgetData(QString("items"), PRIORITIES);
       
   474 
       
   475 	
       
   476 	// DataFormItem for idle length selection
       
   477 	mIdle = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   478 									  QString("Idle (ms)"), 
       
   479 									  mLoadSettings);
       
   480 	mIdle->setContentWidgetData("maximum" , 999999999);
       
   481 	mIdle->setContentWidgetData("minimum", 0);		
       
   482 	
       
   483 	// Random variance
       
   484 	mRandomVar = model->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   485 										   QString("Random variance (%)"), 
       
   486 										   mLoadSettings);
       
   487 	mRandomVar->setContentWidgetData("maximum" , 100);
       
   488 	mRandomVar->setContentWidgetData("minimum", 0);	
       
   489 }
       
   490 
       
   491 // ---------------------------------------------------------------------------
       
   492 // Load attributes from engine & set the data into each form model item:
       
   493 
       
   494 void SettingsView::loadAttributes()
       
   495 {
       
   496 	switch (mCmdId)
       
   497 	{
       
   498 		case ELoadGenCmdNewLoadCPULoad: {
       
   499 			mCPULoadAttributes = mEngineWrapper.getCpuLoadAttributes();
       
   500 			mPriority->setContentWidgetData(QString("selected"), mCPULoadAttributes.mPriority);
       
   501 			mLoadMode->setContentWidgetData(QString("selected"), mCPULoadAttributes.mMode);
       
   502 			mType->setContentWidgetData(QString("selected"), mCPULoadAttributes.mType);
       
   503 			
       
   504 			if (mCPULoadAttributes.mType == ECpuLoadTypePeriodic) {	//if (mCPULoadAttributes.mMode == ECpuLoadTypePeriodic) {
       
   505 			// Create and append to model these items: Length, Idle, Random variance, if load type is peridodic.
       
   506 				
       
   507 				// DataFormItem for load length selection
       
   508 				mLength = mModel->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   509 													QString("Length (ms)"), 
       
   510 													mLoadSettings);
       
   511 				mLength->setContentWidgetData("maximum" , 999999999);
       
   512 				mLength->setContentWidgetData("minimum", 0);
       
   513 				
       
   514 				
       
   515 				// DataFormItem for load length selection
       
   516 				mIdle = mModel->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   517 												  QString("Idle (ms)"), 
       
   518 												  mLoadSettings);
       
   519 				mIdle->setContentWidgetData("maximum" , 999999999);
       
   520 				mIdle->setContentWidgetData("minimum", 0);			
       
   521 
       
   522 				mRandomVar = mModel->appendDataFormItem(HbDataFormModelItem::TextItem, 
       
   523 													   QString("Random variance (%)"), 
       
   524 													   mLoadSettings);
       
   525 				mRandomVar->setContentWidgetData("maximum" , 100);
       
   526 				mRandomVar->setContentWidgetData("minimum", 0);	
       
   527 			
       
   528 				mLength->setContentWidgetData(QString("text"), mCPULoadAttributes.mLength);
       
   529 				mIdle->setContentWidgetData(QString("text"), mCPULoadAttributes.mIdle);
       
   530 				mRandomVar->setContentWidgetData(QString("text"), mCPULoadAttributes.mRandomVariance);
       
   531 			}
       
   532 
       
   533 			// if there's more than one cpu available in the system, 
       
   534 			// insert possibility to select which cpu the load is generated to
       
   535 			if (mCPULoadAttributes.mCpuCount > 1)
       
   536             {
       
   537 				QStringList cpuArray;
       
   538 				cpuArray.append("Free scheduling");
       
   539 				// add cpus to list:
       
   540 				for (int i = 0; i < mCPULoadAttributes.mCpuCount; i++) 
       
   541 					{
       
   542 					QString cpu = QString("CPU%1").arg(i);
       
   543 					cpuArray.append(cpu);
       
   544 					}    
       
   545 				// "All CPUs" means that one thread is started for each CPU.	
       
   546 				cpuArray.append("All CPUs");
       
   547 
       
   548 				mCpu = mModel->appendDataFormItem(HbDataFormModelItem::RadioButtonListItem, 
       
   549 													 QString("CPU"), 
       
   550 													 mLoadSettings);
       
   551 				mCpu->setContentWidgetData(QString("items"), cpuArray);				
       
   552 
       
   553 				if (mCPULoadAttributes.mCpu < 0) {
       
   554 					mCpu->setContentWidgetData(QString("selected"), 0);
       
   555 				}				
       
   556 
       
   557 				else if (mCPULoadAttributes.mCpu == KCPUSelection_AllCPUs) {
       
   558 					mCpu->setContentWidgetData(QString("selected"), cpuArray.count()-1);
       
   559 				}
       
   560 				// CPU is defined, set the correct CPU as default selection in query list
       
   561 				else {
       
   562 				// mCpu starts from zero (i.e. CPU0 is first CPU), but index zero
       
   563 				// in settings Ui form item is reserved for "Free scheduling", hence iCpu+1.
       
   564 					mCpu->setContentWidgetData(QString("selected"), mCPULoadAttributes.mCpu+1);
       
   565 				}
       
   566             }
       
   567 			break;
       
   568 		}
       
   569 		case ELoadGenCmdNewLoadEatMemory: {
       
   570 			mMemoryEatAttributes = mEngineWrapper.getMemoryEatAttributes();
       
   571 			mPriority->setContentWidgetData(QString("selected"), mMemoryEatAttributes.mPriority);
       
   572 			mSource->setContentWidgetData(QString("selected"), mMemoryEatAttributes.mSource);
       
   573 			mType->setContentWidgetData(QString("selected"), mMemoryEatAttributes.mType);
       
   574 			
       
   575 			if (mMemoryEatAttributes.mType == EMemoryEatTypeWavy) {
       
   576 				mMinAmountToBeLeft	= mModel->insertDataFormItem(3, HbDataFormModelItem::TextItem, 
       
   577 												  QString("Min to be left (B)"), 
       
   578 												  mLoadSettings);
       
   579 				mMinAmountToBeLeft->setContentWidgetData("maximum" , 99999999999999);
       
   580 				mMinAmountToBeLeft->setContentWidgetData("minimum", 0);
       
   581 				
       
   582 				mMaxAmountToBeLeft	= mModel->insertDataFormItem(4, HbDataFormModelItem::TextItem, 
       
   583 												  QString("Max to be left (B)"), 
       
   584 												  mLoadSettings);
       
   585 				mMaxAmountToBeLeft->setContentWidgetData("maximum" , 99999999999999);
       
   586 				mMaxAmountToBeLeft->setContentWidgetData("minimum", 0);
       
   587 
       
   588 				mMinAmountToBeLeft->setContentWidgetData(QString("text"), mMemoryEatAttributes.mRandomMinDes);
       
   589 				mMaxAmountToBeLeft->setContentWidgetData(QString("text"), mMemoryEatAttributes.mRandomMaxDes);
       
   590 			}
       
   591 			else if (mMemoryEatAttributes.mType == EMemoryEatTypeMemoryToEat ||
       
   592 			         mMemoryEatAttributes.mType == EMemoryEatTypeMemoryToBeLeft ) {
       
   593 				mAmount	= mModel->insertDataFormItem(3, HbDataFormModelItem::TextItem, 
       
   594 												  QString("Amout(B)"), 
       
   595 												  mLoadSettings);
       
   596 				mAmount->setContentWidgetData("maximum" , 99999999999999);
       
   597 				mAmount->setContentWidgetData("minimum", 0);
       
   598 				
       
   599 				mAmount->setContentWidgetData(QString("text"), mMemoryEatAttributes.mAmount);	 
       
   600 			}
       
   601 			mBuffer->setContentWidgetData(QString("text"), mMemoryEatAttributes.mBuffer);
       
   602 			mIdle->setContentWidgetData(QString("text"), mMemoryEatAttributes.mIdle);
       
   603 			mRandomVar->setContentWidgetData(QString("text"), mMemoryEatAttributes.mRandomVariance);
       
   604 			break;
       
   605 		}
       
   606 		case ELoadGenCmdNewLoadPhoneCall: {
       
   607 			mPhoneCallAttributes = mEngineWrapper.getPhoneCallAttributes();
       
   608 			mPriority->setContentWidgetData(QString("selected"), mPhoneCallAttributes.mPriority);
       
   609 			mDestination->setContentWidgetData(QString("text"), mPhoneCallAttributes.mDestination);
       
   610 			mLength->setContentWidgetData(QString("text"), mPhoneCallAttributes.mLength);
       
   611 			mIdle->setContentWidgetData(QString("text"), mPhoneCallAttributes.mIdle);
       
   612 			mRandomVar->setContentWidgetData(QString("text"), mPhoneCallAttributes.mRandomVariance);
       
   613 			break;
       
   614 		}
       
   615 		case ELoadGenCmdNewLoadNetConn: {
       
   616 			mNetConnAttributes = mEngineWrapper.getNetConnAttributes();
       
   617 			mPriority->setContentWidgetData(QString("selected"), mNetConnAttributes.mPriority);
       
   618 			mDestination->setContentWidgetData(QString("text"), mNetConnAttributes.mDestination);
       
   619 			mIdle->setContentWidgetData(QString("text"), mNetConnAttributes.mIdle);
       
   620 			mRandomVar->setContentWidgetData(QString("text"), mNetConnAttributes.mRandomVariance);
       
   621 			break;
       
   622 		}
       
   623 		case ELoadGenCmdNewLoadKeyPress: {
       
   624 			mKeyPressAttributes = mEngineWrapper.getKeyPressAttributes();
       
   625 			mPriority->setContentWidgetData(QString("selected"), mKeyPressAttributes.mPriority);
       
   626 			mHeartBeat->setContentWidgetData(QString("text"), mKeyPressAttributes.mHeartBeat);
       
   627 			mRandomVar->setContentWidgetData(QString("text"), mKeyPressAttributes.mRandomVariance);			
       
   628 			break;
       
   629 		}
       
   630 		case ELoadGenCmdNewLoadPointerEvent: { 
       
   631 			mPointerEventAttributes = mEngineWrapper.getPointerEventAttributes();
       
   632 			mPriority->setContentWidgetData(QString("selected"), mPointerEventAttributes.mPriority);
       
   633 			mHeartBeat->setContentWidgetData(QString("text"), mPointerEventAttributes.mHeartBeat);
       
   634 			mRandomVar->setContentWidgetData(QString("text"), mPointerEventAttributes.mRandomVariance);				
       
   635 			break;
       
   636 		}
       
   637 		case ELoadGenCmdNewLoadMessages: {
       
   638 			mMessageAttributes = mEngineWrapper.getMessageAttributes();
       
   639 			mPriority->setContentWidgetData(QString("selected"), mMessageAttributes.mPriority);
       
   640 			mType->setContentWidgetData(QString("selected"), mMessageAttributes.mMessageType);
       
   641 			mDestination->setContentWidgetData(QString("text"), mMessageAttributes.mDestination);
       
   642 			mAmount->setContentWidgetData(QString("text"), mMessageAttributes.mAmount);	 
       
   643 			mLength->setContentWidgetData(QString("text"), mMessageAttributes.mLength);
       
   644 			mIdle->setContentWidgetData(QString("text"), mMessageAttributes.mIdle);
       
   645 			mRandomVar->setContentWidgetData(QString("text"), mMessageAttributes.mRandomVariance);
       
   646 			break;
       
   647 		}
       
   648 		case ELoadGenCmdNewLoadApplications: {
       
   649 			mApplicationsAttributes = mEngineWrapper.getApplicationsAttributes();
       
   650 			mPriority->setContentWidgetData(QString("selected"), mApplicationsAttributes.mPriority);
       
   651 			mMaxParallelApps->setContentWidgetData(QString("text"), mApplicationsAttributes.mMaxOpen);
       
   652 			mHeartBeat->setContentWidgetData(QString("text"), mApplicationsAttributes.mHeartBeat);
       
   653 			mLaunchingInterval->setContentWidgetData(QString("text"), mApplicationsAttributes.mLaunchingInterval);
       
   654 			mKeyPressType->setContentWidgetData(QString("selected"), mApplicationsAttributes.mKeyPressType);
       
   655 			mRandomVar->setContentWidgetData(QString("text"), mApplicationsAttributes.mRandomVariance);						
       
   656 			break;
       
   657 		}
       
   658 		case ELoadGenCmdNewLoadPhotoCaptures: {
       
   659 			mPhotoCaptureAttributes = mEngineWrapper.getPhotoCaptureAttributes();
       
   660 			mPriority->setContentWidgetData(QString("selected"), mPhotoCaptureAttributes.mPriority);
       
   661 			mIdle->setContentWidgetData(QString("text"), mPhotoCaptureAttributes.mIdle);
       
   662 			mRandomVar->setContentWidgetData(QString("text"), mPhotoCaptureAttributes.mRandomVariance);
       
   663 			
       
   664 			// if there's any cameras avaialable in system, construct form item for it/them:
       
   665 			if (mPhotoCaptureAttributes.mCameraCount > 0)
       
   666             {
       
   667 				QStringList devices;
       
   668 				// add cameras to list:
       
   669 				for (int i = 0; i < mPhotoCaptureAttributes.mCameraCount; i++) 
       
   670 					{
       
   671 					QString cam = QString("Camera %1").arg(i);
       
   672 					devices.append(cam);
       
   673 					}    
       
   674 				mCamera = mModel->insertDataFormItem(1, HbDataFormModelItem::RadioButtonListItem, 
       
   675 													 QString("Device"), 
       
   676 													 mLoadSettings);
       
   677 				mCamera->setContentWidgetData(QString("items"), devices);
       
   678 				mCamera->setContentWidgetData(QString("selected"), mPhotoCaptureAttributes.mCamera);
       
   679             }
       
   680 			break;
       
   681 		}
       
   682 		case ELoadGenCmdNewLoadBluetooth: {
       
   683 			mBluetoothAttributes = mEngineWrapper.getBluetoothAttributes();
       
   684 			mPriority->setContentWidgetData(QString("selected"), mBluetoothAttributes.mPriority);
       
   685 			mIdle->setContentWidgetData(QString("text"), mBluetoothAttributes.mIdle);
       
   686 			mRandomVar->setContentWidgetData(QString("text"), mBluetoothAttributes.mRandomVariance);	
       
   687 			break;
       
   688 		}
       
   689 		
       
   690 		default: {
       
   691 			break;
       
   692 		}
       
   693 	}
       
   694 }
       
   695 
       
   696 // ---------------------------------------------------------------------------
       
   697 
       
   698 void SettingsView::setDefaultSettings()
       
   699 {
       
   700 
       
   701 }
       
   702 
       
   703 // ---------------------------------------------------------------------------
       
   704 
       
   705 void SettingsView::backButtonPressed()
       
   706 {
       
   707 	okExit();	
       
   708 }
       
   709 
       
   710 // ---------------------------------------------------------------------------
       
   711 
       
   712 void SettingsView::saveSettings()
       
   713 {
       
   714 	switch (mCmdId) {
       
   715 		case ELoadGenCmdNewLoadCPULoad: {
       
   716 			saveCpuLoadSettings();
       
   717 			break;
       
   718 		}
       
   719 		case ELoadGenCmdNewLoadEatMemory: {
       
   720 			saveEatMemorySettings();
       
   721 			break;
       
   722 		}
       
   723 		case ELoadGenCmdNewLoadPhoneCall: {
       
   724 			savePhoneCallSettings();
       
   725 			break;
       
   726 		}
       
   727 		case ELoadGenCmdNewLoadNetConn: {
       
   728 			saveNetConnSettings();
       
   729 			break;
       
   730 		}
       
   731 		case ELoadGenCmdNewLoadKeyPress: {
       
   732 			saveKeyPressSettings();
       
   733 			break;
       
   734 		}
       
   735 		case ELoadGenCmdNewLoadPointerEvent: {
       
   736 			savePointerEventSettings();
       
   737 			break;
       
   738 		}
       
   739 		case ELoadGenCmdNewLoadMessages: {
       
   740 			saveMessageSettings();
       
   741 			break;
       
   742 		}
       
   743 		case ELoadGenCmdNewLoadApplications: {
       
   744 			saveApplicationsSettings();
       
   745 			break;
       
   746 		}
       
   747 		case ELoadGenCmdNewLoadPhotoCaptures: {
       
   748 			savePhotoSettings();
       
   749 			break;
       
   750 		}
       
   751 		case ELoadGenCmdNewLoadBluetooth: {
       
   752 			saveBtSettings();
       
   753 			break;
       
   754 		}
       
   755 		default: {
       
   756 			break;
       
   757 		}
       
   758 	}
       
   759 }
       
   760 
       
   761 // ---------------------------------------------------------------------------	
       
   762 	
       
   763 void SettingsView::saveCpuLoadSettings()
       
   764 {
       
   765 	mCPULoadAttributes.mPriority = mPriority->contentWidgetData("selected").toInt();
       
   766 	mCPULoadAttributes.mMode = mLoadMode->contentWidgetData("selected").toInt();
       
   767 	mCPULoadAttributes.mType = mType->contentWidgetData("selected").toInt();
       
   768 	if (mType->contentWidgetData("selected").toInt() == ECpuLoadTypePeriodic) {
       
   769 		// TODO: remove temp checks if (mLength != NULL) etc. when HbDataFormModelItem bugs fixed.
       
   770 		if (mLength != NULL) {
       
   771 			mCPULoadAttributes.mLength = mLength->contentWidgetData("text").toInt();
       
   772 		}
       
   773 		if (mIdle != NULL) {			
       
   774 			mCPULoadAttributes.mIdle = mIdle->contentWidgetData("text").toInt();
       
   775 		}
       
   776 		if (mRandomVar != NULL) {
       
   777 			int randVar = mRandomVar->contentWidgetData("text").toInt();
       
   778 			if( randVar >=0 && randVar <= mRandomVar->contentWidgetData("maximum").toInt() )
       
   779 				{
       
   780 				mCPULoadAttributes.mRandomVariance = mRandomVar->contentWidgetData("text").toInt();
       
   781 				}
       
   782 			else
       
   783 				{
       
   784 				mCPULoadAttributes.mRandomVariance = mRandomVar->contentWidgetData("maximum").toInt();
       
   785 				}
       
   786 		}
       
   787 	}
       
   788 
       
   789 	// we are running in SMP environment
       
   790 	if (mCPULoadAttributes.mCpuCount > 1)
       
   791 		{
       
   792 		TInt currentValueIndex = mCpu->contentWidgetData("selected").toInt();
       
   793 		// user selected a specific CPU in which the load thread should be run in.
       
   794 		if (currentValueIndex == 0)
       
   795 			{
       
   796 			// User selected "Free scheduling"
       
   797 			mCPULoadAttributes.mCpu = KCPUSelection_FreeScheduling;
       
   798 			}            
       
   799 		else if( currentValueIndex == (mCpu->childCount()-1) )
       
   800 			{
       
   801 			// User selected "All CPUs", which is the last item in the form radio button selection list
       
   802 			mCPULoadAttributes.mCpu = KCPUSelection_AllCPUs;
       
   803 			}
       
   804 		else
       
   805 			{                
       
   806 			// mCpu should start from zero (CPU0 is the first cpu)
       
   807 			// but zero in Ui form item index means "Free scheduling". CPU0 in
       
   808 			// index of form radio button list is at index 1, hence -1.
       
   809 			mCPULoadAttributes.mCpu = currentValueIndex - 1;
       
   810 			}
       
   811 		}
       
   812 
       
   813 	
       
   814 }
       
   815 
       
   816 // ---------------------------------------------------------------------------
       
   817 
       
   818 void SettingsView::saveEatMemorySettings()
       
   819 {
       
   820 	mMemoryEatAttributes.mPriority = mPriority->contentWidgetData("selected").toInt();
       
   821 	mMemoryEatAttributes.mSource = mSource->contentWidgetData("selected").toInt();
       
   822 	mMemoryEatAttributes.mType = mType->contentWidgetData("selected").toInt();
       
   823 	
       
   824 	if (mType->contentWidgetData("selected").toInt() == EMemoryEatTypeWavy) {
       
   825 		// TODO: remove temp checks if (mLength != NULL) etc. when HbDataFormModelItem bugs fixed.
       
   826 		if (mMinAmountToBeLeft != NULL) {
       
   827 			mMemoryEatAttributes.mRandomMin = 
       
   828 				mMinAmountToBeLeft->contentWidgetData("text").toInt();
       
   829 		}
       
   830 		if (mMaxAmountToBeLeft != NULL) {
       
   831 			mMemoryEatAttributes.mRandomMax = 
       
   832 				mMaxAmountToBeLeft->contentWidgetData("text").toInt();
       
   833 		}
       
   834 	}
       
   835 	else if (mType->contentWidgetData("selected").toInt() == EMemoryEatTypeMemoryToEat ||
       
   836 	         mType->contentWidgetData("selected").toInt() == EMemoryEatTypeMemoryToBeLeft) {
       
   837 		if (mAmount != NULL) {
       
   838 			mMemoryEatAttributes.mAmount = mAmount->contentWidgetData("text").toInt();
       
   839 		}
       
   840 	}
       
   841 	mMemoryEatAttributes.mBuffer = mBuffer->contentWidgetData("text").toInt();
       
   842 	mMemoryEatAttributes.mIdle = mIdle->contentWidgetData("text").toInt();
       
   843 	
       
   844 	int randVar = mRandomVar->contentWidgetData("text").toInt();
       
   845 	if( randVar >=0 && randVar <= mRandomVar->contentWidgetData("maximum").toInt() )
       
   846 		{
       
   847 		mMemoryEatAttributes.mRandomVariance = mRandomVar->contentWidgetData("text").toInt();
       
   848 		}
       
   849 	else
       
   850 		{
       
   851 		mMemoryEatAttributes.mRandomVariance = mRandomVar->contentWidgetData("maximum").toInt();
       
   852 		}
       
   853 	
       
   854     // swap min- & max values if they are in wrong order
       
   855 	if (mMemoryEatAttributes.mRandomMin > mMemoryEatAttributes.mRandomMax)
       
   856 		{
       
   857 		qint64 temp(mMemoryEatAttributes.mRandomMin);
       
   858 		mMemoryEatAttributes.mRandomMin = mMemoryEatAttributes.mRandomMax;
       
   859 		mMemoryEatAttributes.mRandomMax = temp; 
       
   860 		}	
       
   861 }
       
   862 
       
   863 // ---------------------------------------------------------------------------	
       
   864 	
       
   865 void SettingsView::savePhoneCallSettings()
       
   866 {
       
   867 	mPhoneCallAttributes.mPriority = mPriority->contentWidgetData("selected").toInt();
       
   868 	mPhoneCallAttributes.mLength   = mLength->contentWidgetData("text").toInt();
       
   869 	mPhoneCallAttributes.mIdle     = mIdle->contentWidgetData("text").toInt();
       
   870 	
       
   871 	int randVar = mRandomVar->contentWidgetData("text").toInt();
       
   872 	if( randVar >=0 && randVar <= mRandomVar->contentWidgetData("maximum").toInt() )
       
   873 		{
       
   874 		mPhoneCallAttributes.mRandomVariance = mRandomVar->contentWidgetData("text").toInt();
       
   875 		}
       
   876 	else
       
   877 		{
       
   878 		mPhoneCallAttributes.mRandomVariance = mRandomVar->contentWidgetData("maximum").toInt();
       
   879 		}
       
   880 	
       
   881 	
       
   882 	mPhoneCallAttributes.mDestination    = mDestination->contentWidgetData("text").toString();
       
   883 }
       
   884 
       
   885 // ---------------------------------------------------------------------------	
       
   886 	
       
   887 void SettingsView::saveNetConnSettings()
       
   888 {
       
   889 	mPhoneCallAttributes.mPriority = mPriority->contentWidgetData("selected").toInt();
       
   890 	mPhoneCallAttributes.mIdle     = mIdle->contentWidgetData("text").toInt();
       
   891 	int randVar = mRandomVar->contentWidgetData("text").toInt();
       
   892 	if( randVar >=0 && randVar <= mRandomVar->contentWidgetData("maximum").toInt() )
       
   893 		{
       
   894 		mPhoneCallAttributes.mRandomVariance = mRandomVar->contentWidgetData("text").toInt();
       
   895 		}
       
   896 	else
       
   897 		{
       
   898 		mPhoneCallAttributes.mRandomVariance = mRandomVar->contentWidgetData("maximum").toInt();
       
   899 		}
       
   900 	mPhoneCallAttributes.mDestination    = mDestination->contentWidgetData("text").toString();
       
   901 }
       
   902 
       
   903 // ---------------------------------------------------------------------------
       
   904 
       
   905 void SettingsView::saveKeyPressSettings()
       
   906 {
       
   907 	mKeyPressAttributes.mPriority  = mPriority->contentWidgetData("selected").toInt();
       
   908 	mKeyPressAttributes.mHeartBeat = mHeartBeat->contentWidgetData("text").toInt();
       
   909 	int randVar = mRandomVar->contentWidgetData("text").toInt();
       
   910 	if( randVar >=0 && randVar <= mRandomVar->contentWidgetData("maximum").toInt() )
       
   911 		{
       
   912 		mKeyPressAttributes.mRandomVariance = mRandomVar->contentWidgetData("text").toInt();
       
   913 		}
       
   914 	else
       
   915 		{
       
   916 		mKeyPressAttributes.mRandomVariance =  mRandomVar->contentWidgetData("maximum").toInt();
       
   917 		}
       
   918 	
       
   919 }
       
   920 
       
   921 // ---------------------------------------------------------------------------
       
   922 
       
   923 void SettingsView::savePointerEventSettings()
       
   924 {
       
   925 	mPointerEventAttributes.mPriority  = mPriority->contentWidgetData("selected").toInt();
       
   926 	mPointerEventAttributes.mHeartBeat = mHeartBeat->contentWidgetData("text").toInt();
       
   927 	int randVar = mRandomVar->contentWidgetData("text").toInt();
       
   928 	if( randVar >=0 && randVar <= mRandomVar->contentWidgetData("maximum").toInt() )
       
   929 		{
       
   930 		mPointerEventAttributes.mRandomVariance = mRandomVar->contentWidgetData("text").toInt();
       
   931 		}
       
   932 	else
       
   933 		{
       
   934 		mPointerEventAttributes.mRandomVariance = mRandomVar->contentWidgetData("maximum").toInt();
       
   935 		}
       
   936 	
       
   937 }
       
   938 
       
   939 // ---------------------------------------------------------------------------
       
   940 
       
   941 void SettingsView::saveMessageSettings()
       
   942 {
       
   943 	mMessageAttributes.mPriority    = mPriority->contentWidgetData("selected").toInt();
       
   944 	mMessageAttributes.mMessageType = mType->contentWidgetData("selected").toInt();
       
   945 	mMessageAttributes.mDestination = mDestination->contentWidgetData("text").toString();
       
   946 	int amount = mAmount->contentWidgetData("text").toInt();
       
   947 	if( amount  >=0 && amount <= mAmount->contentWidgetData("maximum").toInt() )
       
   948 		{
       
   949 		mMessageAttributes.mAmount = mAmount->contentWidgetData("text").toInt();
       
   950 		}
       
   951 	else
       
   952 		{
       
   953 		mMessageAttributes.mAmount = mAmount->contentWidgetData("maximum").toInt();
       
   954 		}
       
   955 	mMessageAttributes.mLength = mLength->contentWidgetData("text").toInt();
       
   956 	mMessageAttributes.mIdle = mIdle->contentWidgetData("text").toInt();
       
   957 	int randVar = mRandomVar->contentWidgetData("text").toInt();
       
   958 	if( randVar >=0 && randVar <= mRandomVar->contentWidgetData("maximum").toInt() )
       
   959 		{
       
   960 		mMessageAttributes.mRandomVariance = mRandomVar->contentWidgetData("text").toInt();
       
   961 		}
       
   962 	else
       
   963 		{
       
   964 		mMessageAttributes.mRandomVariance =  mRandomVar->contentWidgetData("maximum").toInt();
       
   965 		}
       
   966 
       
   967 }
       
   968 
       
   969 // ---------------------------------------------------------------------------
       
   970 
       
   971 void SettingsView::saveApplicationsSettings()
       
   972 {
       
   973 	mApplicationsAttributes.mPriority  = mPriority->contentWidgetData("selected").toInt();
       
   974 	int maxApps = mMaxParallelApps->contentWidgetData("text").toInt();
       
   975 	if( maxApps >=0 && maxApps <= mMaxParallelApps->contentWidgetData("maximum").toInt() )
       
   976 		{
       
   977 		mApplicationsAttributes.mMaxOpen   = mMaxParallelApps->contentWidgetData("text").toInt();
       
   978 		}
       
   979 	else
       
   980 		{
       
   981 		mApplicationsAttributes.mMaxOpen   = mMaxParallelApps->contentWidgetData("maximum").toInt();
       
   982 		}
       
   983 	mApplicationsAttributes.mLaunchingInterval   = mLaunchingInterval->contentWidgetData("text").toInt();
       
   984 	mApplicationsAttributes.mKeyPressType  = mKeyPressType->contentWidgetData("selected").toInt();
       
   985 	mPointerEventAttributes.mHeartBeat = mHeartBeat->contentWidgetData("text").toInt();
       
   986 	int randVar = mRandomVar->contentWidgetData("text").toInt();
       
   987 	if( randVar >=0 && randVar <= mRandomVar->contentWidgetData("maximum").toInt() )
       
   988 		{
       
   989 		mApplicationsAttributes.mRandomVariance = mRandomVar->contentWidgetData("text").toInt();
       
   990 		}
       
   991 	else
       
   992 		{
       
   993 		mApplicationsAttributes.mRandomVariance = mRandomVar->contentWidgetData("maximum").toInt();
       
   994 		}
       
   995 }
       
   996 
       
   997 // ---------------------------------------------------------------------------
       
   998 
       
   999 void SettingsView::savePhotoSettings()
       
  1000 {
       
  1001 	mPhotoCaptureAttributes.mPriority  = mPriority->contentWidgetData("selected").toInt();
       
  1002 	mPhotoCaptureAttributes.mIdle = mIdle->contentWidgetData("text").toInt();
       
  1003 	int randVar = mRandomVar->contentWidgetData("text").toInt();
       
  1004 	if( randVar >=0 && randVar <= mRandomVar->contentWidgetData("maximum").toInt() )
       
  1005 		{
       
  1006 		mPhotoCaptureAttributes.mRandomVariance = mRandomVar->contentWidgetData("text").toInt();
       
  1007 		}
       
  1008 	else
       
  1009 		{
       
  1010 		mPhotoCaptureAttributes.mRandomVariance = mRandomVar->contentWidgetData("maximum").toInt();
       
  1011 		}
       
  1012 	
       
  1013 	// update only if there's more than one camera device available in the system, 
       
  1014 	// for use case of one camera available, the selection cannot be changed by user.
       
  1015 	if (mPhotoCaptureAttributes.mCameraCount > 1)
       
  1016 	{
       
  1017 	mPhotoCaptureAttributes.mCamera = mCamera->contentWidgetData("selected").toInt();
       
  1018 	}
       
  1019 }
       
  1020 
       
  1021 // ---------------------------------------------------------------------------
       
  1022 
       
  1023 void SettingsView::saveBtSettings()
       
  1024 {
       
  1025 	mBluetoothAttributes.mPriority  = mPriority->contentWidgetData("selected").toInt();
       
  1026 	mBluetoothAttributes.mIdle = mIdle->contentWidgetData("text").toInt();
       
  1027 	int randVar = mRandomVar->contentWidgetData("text").toInt();
       
  1028 	if( randVar >=0 && randVar <= mRandomVar->contentWidgetData("maximum").toInt() )
       
  1029 		{
       
  1030 		mBluetoothAttributes.mRandomVariance = mRandomVar->contentWidgetData("text").toInt();
       
  1031 		}
       
  1032 	else
       
  1033 		{
       
  1034 		mBluetoothAttributes.mRandomVariance =  mRandomVar->contentWidgetData("maximum").toInt();
       
  1035 		}
       
  1036 	
       
  1037 }
       
  1038 
       
  1039 // ---------------------------------------------------------------------------
       
  1040 
       
  1041 void SettingsView::cancelled()
       
  1042 {
       
  1043 	connect(this, 
       
  1044 		SIGNAL(loadCanclled()), 
       
  1045 		&mEngineWrapper, 
       
  1046 		SLOT(loadSettingsCanclled()));
       
  1047 	emit loadCanclled();
       
  1048 	
       
  1049     mMainWindow.removeView(this);
       
  1050     mMainWindow.setCurrentView(&mMainView, true);
       
  1051     deleteLater();
       
  1052 }
       
  1053 
       
  1054 // ---------------------------------------------------------------------------
       
  1055 
       
  1056 void SettingsView::okExit()
       
  1057 {
       
  1058 	saveSettings();
       
  1059 	setLoadAttributes();
       
  1060     connect(this, 
       
  1061 			SIGNAL(loadCompleted(TLoadGenCommandIds)), 
       
  1062 			&mEngineWrapper, 
       
  1063 			SLOT(loadAddedOrEdited(TLoadGenCommandIds)));
       
  1064 	emit loadCompleted(mCmdId);
       
  1065 			
       
  1066     mMainWindow.removeView(this);
       
  1067     mMainWindow.setCurrentView(&mMainView, true);
       
  1068     deleteLater();
       
  1069 }
       
  1070 
       
  1071 // ---------------------------------------------------------------------------
       
  1072 
       
  1073 void SettingsView::setLoadAttributes()
       
  1074 {
       
  1075 	switch (mCmdId) {
       
  1076 		case ELoadGenCmdNewLoadCPULoad: {
       
  1077 			mEngineWrapper.setCpuLoadAttributes(mCPULoadAttributes);
       
  1078 			break;
       
  1079 		}
       
  1080 		case ELoadGenCmdNewLoadEatMemory: {
       
  1081 			mEngineWrapper.setMemoryEatAttributes(mMemoryEatAttributes);
       
  1082 			break;
       
  1083 		}
       
  1084 		case ELoadGenCmdNewLoadPhoneCall: {
       
  1085 			mEngineWrapper.setPhoneCallAttributes(mPhoneCallAttributes);
       
  1086 			break;
       
  1087 		}
       
  1088 		case ELoadGenCmdNewLoadNetConn: {
       
  1089 			mEngineWrapper.setNetConnAttributes(mNetConnAttributes);
       
  1090 			break;
       
  1091 		}
       
  1092 		case ELoadGenCmdNewLoadKeyPress: {
       
  1093 			mEngineWrapper.setKeyPressAttributes(mKeyPressAttributes);
       
  1094 			break;
       
  1095 		}
       
  1096 		case ELoadGenCmdNewLoadPointerEvent: {
       
  1097 			mEngineWrapper.setPointerEventAttributes(mPointerEventAttributes);
       
  1098 			break;
       
  1099 		}
       
  1100 		case ELoadGenCmdNewLoadMessages: {
       
  1101 			mEngineWrapper.setMessageAttributes(mMessageAttributes);
       
  1102 			break;
       
  1103 		}
       
  1104 		case ELoadGenCmdNewLoadApplications: {
       
  1105 			mEngineWrapper.setApplicationsAttributes(mApplicationsAttributes);
       
  1106 			break;
       
  1107 		}
       
  1108 		case ELoadGenCmdNewLoadPhotoCaptures: {
       
  1109 			mEngineWrapper.setPhotoCaptureAttributes(mPhotoCaptureAttributes); 
       
  1110 			break;		
       
  1111 		}
       
  1112 		case ELoadGenCmdNewLoadBluetooth: {
       
  1113 			mEngineWrapper.setBluetoothAttributes(mBluetoothAttributes);
       
  1114 			break;
       
  1115 		}
       
  1116 		default: {
       
  1117 			break;
       
  1118 		}
       
  1119 	}
       
  1120 }
       
  1121 
       
  1122 // ---------------------------------------------------------------------------
       
  1123 
       
  1124 void SettingsView::dataItemDisplayed(const QModelIndex &index)
       
  1125 {
       
  1126 	HbDataFormViewItem *item = static_cast<HbDataFormViewItem*>(mSettingForm->itemByIndex(index)); 
       
  1127 	HbWidget *contentWidget = static_cast<HbWidget*>(item->dataItemContentWidget());
       
  1128 	switch(mCmdId){
       
  1129 		case ELoadGenCmdNewLoadCPULoad: {
       
  1130 			if (index.row() == 2) { // Cpu load type selection is in this row: periodic vs. continuous
       
  1131 				mModes = static_cast<HbRadioButtonList*>(contentWidget);
       
  1132 				connect(mModes , SIGNAL(itemSelected(int)), this, SLOT(selectionChanged(int)));
       
  1133 			}
       
  1134 			break;
       
  1135 		}
       
  1136 		case ELoadGenCmdNewLoadEatMemory: {
       
  1137 				// Memory eat type is in this row: mem to eat/ mem to be left vs. alternate min/max
       
  1138 				if (index.row() == 2) { 
       
  1139 				mTypes = static_cast<HbRadioButtonList*>(contentWidget );
       
  1140 				connect(mTypes ,SIGNAL(itemSelected(int)), this,SLOT(selectionChanged(int)));
       
  1141 				}
       
  1142 			break;
       
  1143 		}
       
  1144 	}
       
  1145 }
       
  1146 
       
  1147 // ---------------------------------------------------------------------------
       
  1148 
       
  1149 void SettingsView::selectionChanged(int index)
       
  1150 {
       
  1151 	switch (mCmdId) {
       
  1152 		case ELoadGenCmdNewLoadCPULoad: {
       
  1153 			if (index == ECpuLoadTypePeriodic) {
       
  1154 			// if periodic selected, add Length, Idle and Random variance to settings,
       
  1155 			// if they does not exist yet.
       
  1156 				if (mLength == NULL) {
       
  1157 					mLength = mModel->insertDataFormItem(3, 
       
  1158 														 HbDataFormModelItem::TextItem, 
       
  1159 														 QString("Length (ms)"), 
       
  1160 														 mLoadSettings);
       
  1161 					mLength->setContentWidgetData("maximum" , 999999999);
       
  1162 					mLength->setContentWidgetData("minimum", 0);
       
  1163 					mLength->setContentWidgetData(QString("text"), mCPULoadAttributes.mLength);
       
  1164 					}
       
  1165 				if (mIdle == NULL) {
       
  1166 					// DataFormItem for load length selection
       
  1167 					mIdle = mModel->insertDataFormItem(4,
       
  1168 					                                   HbDataFormModelItem::TextItem, 
       
  1169 													   QString("Idle (ms)"), 
       
  1170 													   mLoadSettings);
       
  1171 					mIdle->setContentWidgetData("maximum" , 999999999);
       
  1172 					mIdle->setContentWidgetData("minimum", 0);			
       
  1173 					mIdle->setContentWidgetData(QString("text"), mCPULoadAttributes.mIdle);
       
  1174 					}
       
  1175 				if (mRandomVar == NULL) {
       
  1176 					mRandomVar = mModel->insertDataFormItem(5,
       
  1177 					                                        HbDataFormModelItem::TextItem,  
       
  1178 														    QString("Random variance (%)"), 
       
  1179 														    mLoadSettings);
       
  1180 					mRandomVar->setContentWidgetData("maximum" , 100);
       
  1181 					mRandomVar->setContentWidgetData("minimum", 0);	
       
  1182 					mRandomVar->setContentWidgetData(QString("text"), mCPULoadAttributes.mRandomVariance);
       
  1183 				}
       
  1184 			}
       
  1185 			else if (index == ECpuLoadTypeContinuous) {
       
  1186 				// if continuous selected, remove existing Length, Idle and Random variance from settings view:
       
  1187 				// if they does not exist do nothing.
       
  1188 				if (mLength != NULL) {
       
  1189 					mModel->removeItem(mLength);
       
  1190 					mLength = NULL;
       
  1191 				}
       
  1192 				if (mIdle != NULL) {
       
  1193 					mModel->removeItem(mIdle);
       
  1194 					mIdle = NULL;
       
  1195 				}
       
  1196 				if (mRandomVar != NULL) {
       
  1197 					mModel->removeItem(mRandomVar);
       
  1198 					mRandomVar = NULL;
       
  1199 				}	
       
  1200 			}
       
  1201 			break;
       
  1202 		}
       
  1203 		case ELoadGenCmdNewLoadEatMemory: {
       
  1204 			if (index == EMemoryEatTypeWavy) {
       
  1205 				// remove one item, if exists. 
       
  1206 				if (mAmount != NULL) {
       
  1207 					mModel->removeItem(mAmount);
       
  1208 					mAmount = NULL;
       
  1209 				}
       
  1210 				// insert two new item rows, if not exists.
       
  1211 				if (mMinAmountToBeLeft == NULL) {
       
  1212 					mMinAmountToBeLeft	= mModel->insertDataFormItem(3, HbDataFormModelItem::TextItem, 
       
  1213 													  QString("Min to be left (B)"), 
       
  1214 													  mLoadSettings);
       
  1215 					mMinAmountToBeLeft->setContentWidgetData("maximum" , 99999999999999);
       
  1216 					mMinAmountToBeLeft->setContentWidgetData("minimum", 0);
       
  1217 					mMinAmountToBeLeft->setContentWidgetData( QString("text"),mMemoryEatAttributes.mRandomMin );
       
  1218 				}
       
  1219 				if (mMaxAmountToBeLeft == NULL) {
       
  1220 					mMaxAmountToBeLeft	= mModel->insertDataFormItem(4, HbDataFormModelItem::TextItem, 
       
  1221 													  QString("Max to be left (B)"), 
       
  1222 													  mLoadSettings);
       
  1223 					mMaxAmountToBeLeft->setContentWidgetData("maximum" , 99999999999999);
       
  1224 					mMaxAmountToBeLeft->setContentWidgetData("minimum", 0);				
       
  1225 					mMaxAmountToBeLeft->setContentWidgetData( QString("text"),mMemoryEatAttributes.mRandomMax );
       
  1226 				}
       
  1227 			}
       
  1228 			else if (index == EMemoryEatTypeMemoryToEat || index == EMemoryEatTypeMemoryToBeLeft) {
       
  1229 				// remove two item rows, if exists.
       
  1230 				if (mMinAmountToBeLeft != NULL) {
       
  1231 					mModel->removeItem(mMinAmountToBeLeft);
       
  1232 					mMinAmountToBeLeft = NULL;
       
  1233 				}
       
  1234 				if (mMaxAmountToBeLeft != NULL) {
       
  1235 					mModel->removeItem(mMaxAmountToBeLeft);
       
  1236 					mMaxAmountToBeLeft = NULL;
       
  1237 				}
       
  1238 				// insert one item, if not exists.
       
  1239 				if (mAmount == NULL) {
       
  1240 					mAmount	= mModel->insertDataFormItem(3, HbDataFormModelItem::TextItem, 
       
  1241 													  QString("Amout(B)"), 
       
  1242 													  mLoadSettings);
       
  1243 					mAmount->setContentWidgetData("maximum" , 99999999999999);
       
  1244 					mAmount->setContentWidgetData("minimum", 0);
       
  1245 					mAmount->setContentWidgetData( QString("text"),mMemoryEatAttributes.mAmount );
       
  1246 				}				
       
  1247 			}
       
  1248 		}
       
  1249 		default: {
       
  1250 			break;
       
  1251 		}
       
  1252 	}
       
  1253 }
       
  1254 
       
  1255 // ---------------------------------------------------------------------------