htiui/HtiAdminQt/mainview.cpp
branchRCL_3
changeset 11 454d022d514b
child 12 aefcba28a3e0
equal deleted inserted replaced
9:404ad6c9bc20 11:454d022d514b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of HtiAdmin main.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <hbmainwindow.h>
       
    20 #include <hbapplication.h>
       
    21 #include <hbmenu.h>
       
    22 #include <hbaction.h>
       
    23 #include <hblabel.h>
       
    24 #include <HbInputDialog.h>
       
    25 #include <qgraphicslinearlayout.h>
       
    26 #include <HbListDialog.h>
       
    27 #include <hbmessagebox.h>
       
    28 
       
    29 
       
    30 
       
    31 #include "htienginewrapper.h"
       
    32 #include "mainview.h"
       
    33 #include "hbtoolbar.h"
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 
       
    37 MainView::MainView(HbMainWindow &mainWindow, HtiEngineWrapper& engineWrapper):
       
    38     mMainWindow(mainWindow),
       
    39     mEngineWrapper(engineWrapper)
       
    40 {
       
    41 }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 
       
    45 MainView::~MainView()
       
    46 {
       
    47 
       
    48 }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 
       
    52 void MainView::init(HbApplication &app)
       
    53 {
       
    54     this->setTitle("Hti Admin");
       
    55     createToolbar();
       
    56     createMenu(app);
       
    57     createTexts();
       
    58     
       
    59     mEngineWrapper.updateStatuses();
       
    60     
       
    61     QString version;
       
    62     mEngineWrapper.getVersionIfo(version);
       
    63     mEngineWrapper.listCommPlugins();
       
    64     
       
    65     mHtiVersionTxt->setPlainText("Hti Version: " + version);
       
    66 }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 void MainView::createMenu(HbApplication& app)
       
    70 {
       
    71     
       
    72     HbMenu* menu = new HbMenu();
       
    73     
       
    74     if (menu != NULL) {
       
    75         
       
    76         mActionExit = menu->addAction("Exit");
       
    77         connect(mActionExit, SIGNAL(triggered()), &app, SLOT( quit() ) );
       
    78 
       
    79         connect(mActionStartHti, SIGNAL(triggered()), this, SLOT( startHti() ) );
       
    80         connect(mActionStopHti, SIGNAL(triggered()), this, SLOT( stopHti() ) );
       
    81         
       
    82         mActionSelectComm = menu->addAction("Select Communication");
       
    83         connect(mActionSelectComm, SIGNAL(triggered()), this, SLOT( enableComm() ) );
       
    84         
       
    85         mActionSetPriority = menu->addAction("Set Priority");
       
    86         connect(mActionSetPriority, SIGNAL(triggered()), this, SLOT( setPriority() ) );
       
    87         
       
    88         mActionEnableAuto = menu->addAction("Enable Auto Start");
       
    89         connect(mActionEnableAuto, SIGNAL(triggered()), this, SLOT( enableAutoStart() ) );
       
    90         
       
    91         mActionDisableAuto = menu->addAction("Disable Auto Start");
       
    92         connect(mActionDisableAuto, SIGNAL(triggered()), this, SLOT( disableAutoStart() ) );
       
    93         
       
    94         mActionEnableWdog = menu->addAction("Enable Watchdog");
       
    95         connect(mActionEnableWdog, SIGNAL(triggered()), this, SLOT( enableWatchdog() ) );
       
    96                 
       
    97         mActionDisableWdog = menu->addAction("Disable Watchdog");
       
    98         connect(mActionDisableWdog, SIGNAL(triggered()), this, SLOT( disableWatchdog() ) );
       
    99         
       
   100         mActionEnableConsole = menu->addAction("Enable Console");
       
   101         connect(mActionEnableConsole, SIGNAL(triggered()), this, SLOT( enableConsole() ) );
       
   102                         
       
   103 		mActionDisableConsole = menu->addAction("Disable Console");
       
   104 		connect(mActionDisableConsole, SIGNAL(triggered()), this, SLOT( disableConsole() ) );
       
   105 		
       
   106 		mActionSetParameter = menu->addAction("Set Parameter");
       
   107 		connect(mActionSetParameter, SIGNAL(triggered()), this, SLOT( showParamList() ) );
       
   108         
       
   109         this->setMenu(menu);
       
   110     }
       
   111     
       
   112     
       
   113     connect(&mEngineWrapper, SIGNAL(statusChanged(HtiEngineWrapper::HtiStatus)), this, SLOT(htiStatusChanged(HtiEngineWrapper::HtiStatus)));
       
   114     connect(&mEngineWrapper, SIGNAL(commSet(QString&)), this, SLOT(commStatusChanged(QString&)));
       
   115     connect(&mEngineWrapper, SIGNAL(commDetails(QString&)), this, SLOT(commDetailsChanged(QString&)));
       
   116     connect(&mEngineWrapper, SIGNAL(autostartSet(HtiEngineWrapper::AutoStartStatus)), this, SLOT(autostartStatusChanged(HtiEngineWrapper::AutoStartStatus)));
       
   117     connect(&mEngineWrapper, SIGNAL(consoleSet(bool)), this, SLOT(consoleStatusChanged(bool)));
       
   118     connect(&mEngineWrapper, SIGNAL(watchDogSet(bool)), this, SLOT(watchDogStatusChanged(bool)));
       
   119     connect(&mEngineWrapper, SIGNAL(commPluginsRetrieved(QStringList&)), this, SLOT(updatePluginInfo(QStringList&)));
       
   120     
       
   121     
       
   122 }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 void MainView::createTexts()
       
   126 {
       
   127 	QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical, this);
       
   128 	
       
   129 	mCommDetailsTxt = new HbLabel(this);
       
   130 	mHtiStatusTxt = new HbLabel(this);
       
   131 	mHtiVersionTxt = new HbLabel(this);
       
   132 	
       
   133 	mHtiAutoStartStatusTxt = new HbLabel(this);
       
   134 	mCommunicationTxt = new HbLabel(this);
       
   135 	
       
   136 	mHtiStatusTxt->setPlainText("Hti Status:");
       
   137 	mHtiVersionTxt->setPlainText("Hti Version:");
       
   138 	mHtiAutoStartStatusTxt->setPlainText("Auto Start:");
       
   139 	mCommunicationTxt->setPlainText("Communication ");
       
   140 		
       
   141 	layout->addItem(mHtiStatusTxt);
       
   142 	layout->addItem(mHtiVersionTxt);
       
   143 	layout->addItem(mHtiAutoStartStatusTxt);
       
   144 	layout->addItem(mCommunicationTxt);
       
   145 	layout->addItem(mCommDetailsTxt);
       
   146 
       
   147 	layout->setMaximumHeight(300);
       
   148 	this->setLayout(layout);
       
   149 }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 void MainView::htiStatusChanged(HtiEngineWrapper::HtiStatus newStatus)
       
   153 {
       
   154 	switch(newStatus)
       
   155 			{
       
   156 			case HtiEngineWrapper::Running:
       
   157 				mHtiStatusTxt->setPlainText("Hti Status: Running" );
       
   158 				break;
       
   159 			case HtiEngineWrapper::Stopped:
       
   160 				mHtiStatusTxt->setPlainText("Hti Status: Stopped" );
       
   161 				break;
       
   162 			case HtiEngineWrapper::Panic:
       
   163 				mHtiStatusTxt->setPlainText("Hti Status: Panic" );
       
   164 				break;
       
   165 			default:
       
   166 				mHtiStatusTxt->setPlainText("Hti Status: Error" );
       
   167 			}
       
   168 	
       
   169 	// Update menu items status
       
   170 	bool isRunning = (newStatus == HtiEngineWrapper::Running);
       
   171     mActionStartHti->setEnabled(!isRunning);
       
   172     mActionStopHti->setEnabled(isRunning);
       
   173     mActionSelectComm->setEnabled(!isRunning);
       
   174     mActionSetPriority->setEnabled(!isRunning);
       
   175     mActionEnableAuto->setEnabled(!isRunning);
       
   176     mActionDisableAuto->setEnabled(!isRunning);
       
   177     mActionEnableWdog->setEnabled(!isRunning);
       
   178     mActionDisableWdog->setEnabled(!isRunning);
       
   179     mActionEnableConsole->setEnabled(!isRunning);
       
   180     mActionDisableConsole->setEnabled(!isRunning);
       
   181     mActionSetParameter->setEnabled(!isRunning);
       
   182 }
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 void MainView::commStatusChanged(QString& newStatus)
       
   186 {
       
   187 	if (mCommunicationTxt) {
       
   188 		mCommunicationTxt->setPlainText("Communication: " + newStatus);
       
   189 	}
       
   190 }
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 void MainView::commDetailsChanged(QString& newStatus)
       
   194 {
       
   195 	if (mCommDetailsTxt) {
       
   196 		mCommDetailsTxt->setPlainText(newStatus);
       
   197 	}
       
   198 }
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 void MainView::updatePluginInfo(QStringList& pluginList)
       
   202 {
       
   203 	mPluginList = pluginList;
       
   204 }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 void MainView::autostartStatusChanged(HtiEngineWrapper::AutoStartStatus newStatus)
       
   208 {
       
   209 	switch(newStatus)
       
   210 		{
       
   211 		case HtiEngineWrapper::AutoStartDisabled:
       
   212 			mHtiAutoStartStatusTxt->setPlainText("Auto Start: Disabled" );
       
   213 			break;
       
   214 		case HtiEngineWrapper::AutoStartEnabled:
       
   215 			mHtiAutoStartStatusTxt->setPlainText("Auto Start: Enabled" );
       
   216 			break;
       
   217 		default:
       
   218 			mHtiAutoStartStatusTxt->setPlainText("Auto Start: Unknown" );
       
   219 		}
       
   220 	
       
   221 	bool isAutoStartEnabled = (newStatus == HtiEngineWrapper::AutoStartEnabled);
       
   222     mActionEnableAuto->setVisible(!isAutoStartEnabled);
       
   223     mActionDisableAuto->setVisible(isAutoStartEnabled);
       
   224 }
       
   225 
       
   226 // ---------------------------------------------------------------------------
       
   227 void MainView::consoleStatusChanged(bool enabled)
       
   228 {
       
   229     mActionEnableConsole->setVisible(!enabled);
       
   230     mActionDisableConsole->setVisible(enabled);
       
   231 }
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 void MainView::watchDogStatusChanged(bool enabled)
       
   235 {
       
   236     mActionEnableWdog->setVisible(!enabled);
       
   237     mActionDisableWdog->setVisible(enabled);
       
   238 }
       
   239 
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 
       
   243 void MainView::createToolbar()
       
   244 {
       
   245 	mActionStartHti = toolBar()->addAction("Start Hti");
       
   246 	mActionStopHti = toolBar()->addAction("Stop Hti");
       
   247 }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 
       
   251 void MainView::startHti()
       
   252 {
       
   253 	mEngineWrapper.startHti();
       
   254 }
       
   255 
       
   256 // ---------------------------------------------------------------------------
       
   257 
       
   258 void MainView::stopHti()
       
   259 {
       
   260 	mEngineWrapper.stopHti();
       
   261 }
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 void MainView::enableComm()
       
   265 {
       
   266     //Get current selection
       
   267 	QString currentComm;
       
   268 	mEngineWrapper.getSelectedComm(currentComm);
       
   269 	int curSelection = mPluginList.indexOf(currentComm, 0);
       
   270 	
       
   271 	QStringList selection;
       
   272 	bool ok = false;
       
   273 	selection = HbListDialog::getStringItems("Select Comm", mPluginList, curSelection, &ok, HbAbstractItemView::SingleSelection);
       
   274 		
       
   275 	if(ok){
       
   276 			if(selection[0] == QString("Bt serial comm")){
       
   277 				enableBTComm();
       
   278 			}
       
   279 			else if(selection[0] == QString("IP comm")){
       
   280 				enableIPComm();
       
   281 			}
       
   282 			else if(selection[0] == QString("SERIAL comm")){
       
   283 				enableSerialComm();
       
   284 			}
       
   285 			else{
       
   286 				//All other comm plugins
       
   287 				mEngineWrapper.enableOtherComm(selection[0]);
       
   288 			}	
       
   289 		}
       
   290 }
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 void MainView::enableSerialComm()
       
   294 {
       
   295 	bool ok = false;
       
   296     QString str = HbInputDialog::getText(
       
   297 					"Set Comm Port number ",
       
   298 					"",
       
   299 					&ok);
       
   300     
       
   301     if(ok){
       
   302     	mEngineWrapper.enableSerial(str);
       
   303     }
       
   304 }
       
   305 
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 void MainView::enableIPComm()
       
   309 {
       
   310     // Get IAPs list
       
   311     QStringList iapsList;
       
   312     mEngineWrapper.listIAPs(iapsList); 
       
   313     if(iapsList.count() == 0)
       
   314     {
       
   315         HbMessageBox msg("No IAPs for selection!", HbMessageBox::MessageTypeWarning);
       
   316         msg.exec();
       
   317         return;
       
   318     }
       
   319     
       
   320     // Get current selection
       
   321     QString curIapName;
       
   322     QString param = "IAPName";
       
   323     mEngineWrapper.getIPCfgParam(param, curIapName);
       
   324     int curSelction = iapsList.indexOf(curIapName, 0);
       
   325     
       
   326     QString iap;
       
   327 	QStringList selection;
       
   328 	bool ok = false;
       
   329 	selection = HbListDialog::getStringItems("Select IAP:", iapsList, curSelction, &ok, HbAbstractItemView::SingleSelection);
       
   330 	
       
   331 	if(ok)
       
   332 	{
       
   333         iap = selection[0];
       
   334 	}
       
   335 	else
       
   336 	{
       
   337         return;
       
   338 	}
       
   339 	
       
   340 	QStringList srcList;
       
   341 	srcList <<"Listen" <<"Connect";
       
   342 	
       
   343 	selection = HbListDialog::getStringItems("Select IP Comm", srcList, 0, &ok, HbAbstractItemView::SingleSelection);
       
   344 	
       
   345 	if(ok){
       
   346 		if(selection[0] == srcList[0]){
       
   347 			QString port = HbInputDialog::getText(
       
   348 								"Local port",
       
   349 								"",
       
   350 								&ok);	
       
   351 		
       
   352 			if(ok){
       
   353 				mEngineWrapper.ipListen(port, iap);
       
   354 			}
       
   355 			
       
   356 		}
       
   357 		else{
       
   358 			QString host = HbInputDialog::getText(
       
   359 								"Remote Host",
       
   360 								"",
       
   361 								&ok);	
       
   362 					
       
   363 			if(ok){
       
   364 				QString port = HbInputDialog::getText(
       
   365 												"Remote port",
       
   366 												"",
       
   367 												&ok);	
       
   368 			
       
   369 				if(ok){
       
   370 					mEngineWrapper.ipConnect(host, port, iap);
       
   371 				}
       
   372 			}
       
   373 		}
       
   374 			
       
   375 	}
       
   376 }
       
   377 
       
   378 // ---------------------------------------------------------------------------
       
   379 void MainView::enableBTComm()
       
   380 {
       
   381 	QStringList srcList;
       
   382 	QStringList selection;
       
   383 	 
       
   384 	srcList <<"BT address" <<"BT name" <<"Search when starting" ;
       
   385 	
       
   386 	bool ok = false;
       
   387 	selection = HbListDialog::getStringItems("", srcList, 0, &ok, HbAbstractItemView::SingleSelection);
       
   388 	
       
   389 	if(ok){
       
   390 		if(selection[0] == srcList[0]){
       
   391 			QString address = HbInputDialog::getText(
       
   392 						"BT address",
       
   393 						"",
       
   394 						&ok);
       
   395 		
       
   396 			if(ok){
       
   397 				mEngineWrapper.enableBtByAddress(address);	
       
   398 			}
       
   399 		}
       
   400 		else if(selection[0] == srcList[1]){
       
   401 			QString name = HbInputDialog::getText(
       
   402 								"BT name",
       
   403 								"",
       
   404 								&ok);
       
   405 				
       
   406 					if(ok){
       
   407 						mEngineWrapper.enableBtByName(name);	
       
   408 					}
       
   409 		}
       
   410 		else if(selection[0] == srcList[2]){
       
   411 			mEngineWrapper.btSearch();
       
   412 		}
       
   413 	}
       
   414 }
       
   415 
       
   416 
       
   417 // ---------------------------------------------------------------------------
       
   418 void MainView::setPriority()
       
   419 {
       
   420     // Get current priority
       
   421     bool ok = false;
       
   422     QString curPriority;
       
   423     QString param = "Priority";
       
   424     mEngineWrapper.getHtiCfgParam(param, curPriority);
       
   425     int curSelection = curPriority.toInt(&ok);
       
   426     if(ok){
       
   427         curSelection--;
       
   428     }
       
   429     else{
       
   430     curSelection = 2;
       
   431     }
       
   432     
       
   433 	QStringList srcList;
       
   434 	QStringList selection;
       
   435 	 
       
   436 	srcList <<"Backgroung" <<"Foregound" <<"High" << "Absolute High";
       
   437 	
       
   438 	
       
   439 	selection = HbListDialog::getStringItems("Select Hti Priority", srcList, curSelection, &ok, HbAbstractItemView::SingleSelection);
       
   440 	
       
   441 	if(ok){
       
   442 		if(selection[0] == srcList[0]){
       
   443 			mEngineWrapper.setPriorityBackground();
       
   444 		}
       
   445 		else if(selection[0] == srcList[1]){
       
   446 					mEngineWrapper.setPriorityForeground();
       
   447 		}
       
   448 		else if(selection[0] == srcList[2]){
       
   449 			mEngineWrapper.setPriorityHigh();
       
   450 		}
       
   451 		else{
       
   452 			mEngineWrapper.setPriorityAbsoluteHigh();
       
   453 		}	
       
   454 	}
       
   455 }
       
   456 
       
   457 // ---------------------------------------------------------------------------
       
   458 void MainView::enableAutoStart()
       
   459 {
       
   460 	mEngineWrapper.autoStartEnable(true);
       
   461 }
       
   462 
       
   463 // ---------------------------------------------------------------------------
       
   464 void MainView::disableAutoStart()
       
   465 {
       
   466 	mEngineWrapper.autoStartEnable(false);
       
   467 }
       
   468 
       
   469 // ---------------------------------------------------------------------------
       
   470 void MainView::enableWatchdog()
       
   471 {
       
   472 	mEngineWrapper.watchDogEnable(true);
       
   473 }
       
   474 
       
   475 // ---------------------------------------------------------------------------
       
   476 void MainView::disableWatchdog()
       
   477 {
       
   478 	mEngineWrapper.watchDogEnable(false);
       
   479 }
       
   480 
       
   481 // ---------------------------------------------------------------------------
       
   482 void MainView::enableConsole()
       
   483 {
       
   484 	mEngineWrapper.consoleEnable(true);
       
   485 }
       
   486 
       
   487 // ---------------------------------------------------------------------------
       
   488 void MainView::disableConsole()
       
   489 {
       
   490 	mEngineWrapper.consoleEnable(false);
       
   491 }
       
   492 
       
   493 // ---------------------------------------------------------------------------
       
   494 void MainView::showParamList()
       
   495 {
       
   496 	QStringList srcList;
       
   497 	QStringList selection;
       
   498 	QString value;
       
   499 	QString name;
       
   500 	QString cfgSelection;
       
   501 	QString paramSelection;
       
   502 	QString cfgHti = "Hti.cfg";
       
   503 	QString cfgBtComm ="HtiBtComm.cfg";
       
   504 	QString cfgSerialComm = "HtiSerialComm.cfg";
       
   505 	QString cfgIPComm = "HtiIPComm.cfg";
       
   506 	 
       
   507 	srcList <<cfgHti <<cfgBtComm <<cfgSerialComm << cfgIPComm;
       
   508 	
       
   509 	bool ok = false;
       
   510 	selection = HbListDialog::getStringItems("Select cfg file to modify", srcList, 0, &ok, HbAbstractItemView::SingleSelection);
       
   511 	
       
   512 	if(ok){
       
   513         cfgSelection = selection[0];
       
   514         srcList.clear();
       
   515 	    if(cfgSelection == cfgHti){
       
   516 	    srcList <<"CommPlugin" <<"MaxMsgSize" <<"MaxQueueSize" <<"MaxHeapSize"<<"Priority"
       
   517 	            <<"ShowConsole"<<"MaxWaitTime"<<"StartUpDelay"<<"EnableHtiWatchDog"
       
   518 	            <<"EnableHtiAutoStart"<<"ShowErrorDialogs"<<"ReconnectDelay";
       
   519 	    }
       
   520 	    else if(cfgSelection == cfgBtComm){
       
   521 	        srcList <<"BtDeviceName" <<"BtDeviceName";
       
   522 	    }
       
   523 	    else if(cfgSelection == cfgSerialComm){
       
   524             srcList <<"CommPort" <<"DataRate"<<"Parity"<<"DataBits"<<"StopBits"<<"SendDelay"<<"Handshake";
       
   525 	    }
       
   526 	    else{
       
   527 	    srcList <<"IAPName"<<"LocalPort"<<"RemoteHost"<<"RemotePort"<<"ConnectTimeout";
       
   528 	    }
       
   529 	    
       
   530 	    selection = HbListDialog::getStringItems("Select a parameter name in" + cfgSelection, srcList, 0, &ok, HbAbstractItemView::SingleSelection);
       
   531 	}
       
   532     
       
   533     if(ok){
       
   534         name = selection[0];
       
   535         value = HbInputDialog::getText("Value for paramater " + name, "", &ok);
       
   536     }
       
   537     
       
   538     if(ok){
       
   539        if(cfgSelection == cfgHti){
       
   540             mEngineWrapper.setHtiCfgParam(name, value);
       
   541         }
       
   542         else if(cfgSelection == cfgBtComm){
       
   543             mEngineWrapper.setBtCfgParam(name, value);
       
   544         }
       
   545         else if(cfgSelection == cfgSerialComm){
       
   546             mEngineWrapper.setSerialCfgParam(name, value);
       
   547         }
       
   548         else{
       
   549             mEngineWrapper.setIPCfgParam(name, value);
       
   550         }   
       
   551     }
       
   552 }
       
   553 
       
   554