htiui/HtiAdminQt/htienginewrapper.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 "htienginewrapper.h"
       
    20 #include "chtiadminengine.h"
       
    21 
       
    22 #include <coecntrl.h>
       
    23 #include <QString>
       
    24 #include <QLocale.h>
       
    25 
       
    26 
       
    27 #include <HtiVersion.h>
       
    28 
       
    29 
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 
       
    33 HtiEngineWrapper::HtiEngineWrapper():
       
    34 	iEngine(0)
       
    35 {
       
    36 }
       
    37 // ---------------------------------------------------------------------------	
       
    38 HtiEngineWrapper::~HtiEngineWrapper()
       
    39 {
       
    40 	delete iEngine;
       
    41 }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 bool HtiEngineWrapper::init()
       
    45 {
       
    46     TRAPD(error, iEngine = CHtiAdminEngine::NewL(this));
       
    47     
       
    48     if (error != KErrNone) {
       
    49 		return false;
       
    50 	}
       
    51 	else {
       
    52 		return true;
       
    53 	}
       
    54 }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 bool HtiEngineWrapper::startHti()
       
    58 {
       
    59 	TRAPD(error, iEngine->StartHtiL());
       
    60 	
       
    61 	if (error != KErrNone) {
       
    62 		return false;
       
    63 	}
       
    64 	else {
       
    65 		return true;
       
    66 	}
       
    67 }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 bool HtiEngineWrapper::stopHti()
       
    71 {
       
    72 	TRAPD(error, iEngine->StopHtiL());
       
    73 	
       
    74 	if (error != KErrNone) {
       
    75 		return false;
       
    76 	}
       
    77 	else {
       
    78 		return true;
       
    79 	}
       
    80 }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 bool HtiEngineWrapper::enableBtByAddress(QString& address)
       
    84 {
       
    85 	// A conversion between a TBuf and QString is needed here.
       
    86 	TBuf<64> convertedAddress(address.utf16());
       
    87 	
       
    88 	
       
    89 	TRAPD(error, iEngine->EnableBtByAddressL(convertedAddress));
       
    90 		
       
    91 		if (error != KErrNone) {
       
    92 			return false;
       
    93 		}
       
    94 		else {
       
    95 			return true;
       
    96 		}
       
    97 	
       
    98 }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 bool HtiEngineWrapper::ipListen(QString& port, QString& iap)
       
   102 {
       
   103 	// A conversion between a TBuf and QString is needed here.
       
   104 	TBuf<64> convertedPort(port.utf16());
       
   105 	TBuf<64> convertedIAP(iap.utf16());
       
   106 	
       
   107 	TRAPD(error, iEngine->IPListenL(convertedPort, convertedIAP));
       
   108 		
       
   109 	if (error != KErrNone) {
       
   110 		return false;
       
   111 	}
       
   112 	else {
       
   113 		return true;
       
   114 	}
       
   115 	
       
   116 }
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 bool HtiEngineWrapper::ipConnect(QString& host, QString& port, QString& iap)
       
   120 {
       
   121 	// A conversion between a TBuf and QString is needed here.
       
   122 	TBuf<64> convertedHostAddress(host.utf16());
       
   123 	TBuf<64> convertedPort(port.utf16());
       
   124 	TBuf<64> convertedIAP(iap.utf16());
       
   125 		
       
   126 	TRAPD(error, iEngine->IPConnectL(convertedHostAddress, convertedPort, convertedIAP));
       
   127 		
       
   128 	if (error != KErrNone) {
       
   129 		return false;
       
   130 	}
       
   131 	else {
       
   132 		return true;
       
   133 	}
       
   134 	
       
   135 }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 bool HtiEngineWrapper::enableBtByName(QString& address)
       
   139 	{
       
   140 	// A conversion between a TBuf and QString is needed here.
       
   141 	TBuf<64> convertedAddress(address.utf16());
       
   142 	
       
   143 	
       
   144 	TRAPD(error, iEngine->EnableBtByNameL(convertedAddress));
       
   145 		
       
   146 		if (error != KErrNone) {
       
   147 			return false;
       
   148 		}
       
   149 		else {
       
   150 			return true;
       
   151 		}
       
   152 	
       
   153 	}
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 bool HtiEngineWrapper::btSearch()
       
   157 	{
       
   158 	TRAPD(error, iEngine->BtSearchL());
       
   159 		
       
   160 		if (error != KErrNone) {
       
   161 			return false;
       
   162 		}
       
   163 		else {
       
   164 			return true;
       
   165 		}
       
   166 	
       
   167 	}
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 bool HtiEngineWrapper::enableSerial(QString& commPort)
       
   171 {
       
   172 	// A conversion between a TBuf and QString is needed here.
       
   173 	TBuf<64> convertedText(commPort.utf16());
       
   174 		
       
   175 	TRAPD(error, iEngine->EnableSerialL(convertedText));
       
   176 		
       
   177 	if (error != KErrNone) {
       
   178 		return false;
       
   179 	}
       
   180 	else {
       
   181 		return true;
       
   182 	}
       
   183 	
       
   184 }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 bool HtiEngineWrapper::enableOtherComm(QString& pluginName)
       
   188 	{
       
   189 	// A conversion between a TBuf and QString is needed here.
       
   190 	TBuf<64> convertedText(pluginName.utf16());
       
   191 	
       
   192 	TRAPD(error, iEngine->EnableOtherCommL(convertedText));
       
   193 		
       
   194 		if (error != KErrNone) {
       
   195 			return false;
       
   196 		}
       
   197 		else {
       
   198 			return true;
       
   199 		}
       
   200 	
       
   201 	}
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 bool HtiEngineWrapper::setPriorityBackground()
       
   205 	{
       
   206 	TRAPD(error, iEngine->SetPriorityBackgroundL());
       
   207 		
       
   208 		if (error != KErrNone) {
       
   209 			return false;
       
   210 		}
       
   211 		else {
       
   212 			return true;
       
   213 		}
       
   214 	}
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 bool HtiEngineWrapper::setPriorityForeground()
       
   218 	{
       
   219 	TRAPD(error, iEngine->SetPriorityForegroundL());
       
   220 		
       
   221 		if (error != KErrNone) {
       
   222 			return false;
       
   223 		}
       
   224 		else {
       
   225 			return true;
       
   226 		}
       
   227 	}
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 bool HtiEngineWrapper::setPriorityHigh()
       
   231 	{
       
   232 	TRAPD(error, iEngine->SetPriorityHighL());
       
   233 		
       
   234 		if (error != KErrNone) {
       
   235 			return false;
       
   236 		}
       
   237 		else {
       
   238 			return true;
       
   239 		}
       
   240 	}
       
   241 
       
   242 // ---------------------------------------------------------------------------
       
   243 bool HtiEngineWrapper::setPriorityAbsoluteHigh()
       
   244 	{
       
   245 	TRAPD(error, iEngine->SetPriorityAbsoluteHighL());
       
   246 		
       
   247 		if (error != KErrNone) {
       
   248 			return false;
       
   249 		}
       
   250 		else {
       
   251 			return true;
       
   252 		}
       
   253 	}
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 bool HtiEngineWrapper::watchDogEnable(bool enable)
       
   257 	{
       
   258 	TRAPD(error, iEngine->WatchDogEnableL(enable));
       
   259 		
       
   260 		if (error != KErrNone) {
       
   261 			return false;
       
   262 		}
       
   263 		else {
       
   264 			return true;
       
   265 		}
       
   266 	}
       
   267 
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 bool HtiEngineWrapper::autoStartEnable(bool enable)
       
   271 	{
       
   272 	TRAPD(error, iEngine->AutoStartEnableL(enable));
       
   273 		
       
   274 		if (error != KErrNone) {
       
   275 			return false;
       
   276 		}
       
   277 		else {
       
   278 			return true;
       
   279 		}
       
   280 	}
       
   281 
       
   282 // ---------------------------------------------------------------------------
       
   283 bool HtiEngineWrapper::consoleEnable(bool enable)
       
   284 	{
       
   285 	TRAPD(error, iEngine->ConsoleEnableL(enable));
       
   286 		
       
   287 		if (error != KErrNone) {
       
   288 			return false;
       
   289 		}
       
   290 		else {
       
   291 			return true;
       
   292 		}
       
   293 	}
       
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 bool HtiEngineWrapper::errorDialogsEnable(bool enable)
       
   297 	{
       
   298 	TRAPD(error, iEngine->ErrorDialogsEnableL(enable));
       
   299 		
       
   300 		if (error != KErrNone) {
       
   301 			return false;
       
   302 		}
       
   303 		else {
       
   304 			return true;
       
   305 		}
       
   306 	}
       
   307 
       
   308 // ---------------------------------------------------------------------------
       
   309 bool HtiEngineWrapper::setHtiCfgParam(QString& paramName, QString& paramValue)
       
   310 {
       
   311 	// A conversion between a TBuf and QString is needed here.
       
   312 	TBuf<64> convertedName(paramName.utf16());
       
   313 	TBuf<64> convertedValue(paramValue.utf16());
       
   314 		
       
   315 	TRAPD(error, iEngine->SetHtiCfgParamL(convertedName, convertedValue));
       
   316 		
       
   317 	if (error != KErrNone) {
       
   318 		return false;
       
   319 	}
       
   320 	else {
       
   321 		return true;
       
   322 	}
       
   323 }
       
   324 
       
   325 // ---------------------------------------------------------------------------
       
   326 bool HtiEngineWrapper::getHtiCfgParam(QString& paramName, QString& paramValue)
       
   327 {
       
   328     // A conversion between a TBuf and QString is needed here.
       
   329     TBuf<64> convertedName(paramName.utf16());
       
   330     TBuf<64> value;
       
   331         
       
   332     TRAPD(error, iEngine->GetHtiCfgParamL(convertedName, value));
       
   333         
       
   334     paramValue = QString((QChar*)value.Ptr(),value.Length());
       
   335     if (error != KErrNone) {
       
   336         return false;
       
   337     }
       
   338     else {
       
   339         return true;
       
   340     }
       
   341 }
       
   342 
       
   343 // ---------------------------------------------------------------------------
       
   344 bool HtiEngineWrapper::setBtCfgParam(QString& paramName, QString& paramValue)
       
   345 {
       
   346 	// A conversion between a TBuf and QString is needed here.
       
   347 	TBuf<64> convertedName(paramName.utf16());
       
   348 	TBuf<64> convertedValue(paramValue.utf16());
       
   349 		
       
   350 	TRAPD(error, iEngine->SetBtCfgParamL(convertedName, convertedValue));
       
   351 		
       
   352 	if (error != KErrNone) {
       
   353 		return false;
       
   354 	}
       
   355 	else {
       
   356 		return true;
       
   357 	}
       
   358 }
       
   359 
       
   360 // ---------------------------------------------------------------------------
       
   361 bool HtiEngineWrapper::getBtCfgParam(QString& paramName, QString& paramValue)
       
   362 {
       
   363     // A conversion between a TBuf and QString is needed here.
       
   364     TBuf<64> convertedName(paramName.utf16());
       
   365     TBuf<64> value;
       
   366         
       
   367     TRAPD(error, iEngine->GetBtCfgParamL(convertedName, value));
       
   368     paramValue = QString((QChar*)value.Ptr(),value.Length());    
       
   369     if (error != KErrNone) {
       
   370         return false;
       
   371     }
       
   372     else {
       
   373         return true;
       
   374     }
       
   375 }
       
   376 
       
   377 // ---------------------------------------------------------------------------
       
   378 bool HtiEngineWrapper::setSerialCfgParam(QString& paramName, QString& paramValue)
       
   379 {
       
   380 	// A conversion between a TBuf and QString is needed here.
       
   381 	TBuf<64> convertedName(paramName.utf16());
       
   382 	TBuf<64> convertedValue(paramValue.utf16());
       
   383 		
       
   384 	TRAPD(error, iEngine->SetSerialCfgParamL(convertedName, convertedValue));
       
   385 		
       
   386 	if (error != KErrNone) {
       
   387 		return false;
       
   388 	}
       
   389 	else {
       
   390 		return true;
       
   391 	}
       
   392 }
       
   393 
       
   394 // ---------------------------------------------------------------------------
       
   395 bool HtiEngineWrapper::getSerialCfgParam(QString& paramName, QString& paramValue)
       
   396 {
       
   397     // A conversion between a TBuf and QString is needed here.
       
   398     TBuf<64> convertedName(paramName.utf16());
       
   399     TBuf<64> value;
       
   400         
       
   401     TRAPD(error, iEngine->GetSerialCfgParamL(convertedName, value));
       
   402     paramValue = QString((QChar*)value.Ptr(),value.Length());
       
   403     
       
   404     if (error != KErrNone) {
       
   405         return false;
       
   406     }
       
   407     else {
       
   408         return true;
       
   409     }
       
   410 }
       
   411 
       
   412 // ---------------------------------------------------------------------------
       
   413 bool HtiEngineWrapper::setIPCfgParam(QString& paramName, QString& paramValue)
       
   414 {
       
   415 	// A conversion between a TBuf and QString is needed here.
       
   416 	TBuf<64> convertedName(paramName.utf16());
       
   417 	TBuf<64> convertedValue(paramValue.utf16());
       
   418 		
       
   419 	TRAPD(error, iEngine->SetIPCfgParamL(convertedName, convertedValue));
       
   420 		
       
   421 	if (error != KErrNone) {
       
   422 		return false;
       
   423 	}
       
   424 	else {
       
   425 		return true;
       
   426 	}
       
   427 }
       
   428 
       
   429 // ---------------------------------------------------------------------------
       
   430 bool HtiEngineWrapper::getIPCfgParam(QString& paramName, QString& paramValue)
       
   431 {
       
   432     // A conversion between a TBuf and QString is needed here.
       
   433     TBuf<64> convertedName(paramName.utf16());
       
   434     TBuf<64> value;
       
   435         
       
   436     TRAPD(error, iEngine->GetIPCfgParamL(convertedName, value));
       
   437     paramValue = QString((QChar*)value.Ptr(),value.Length());    
       
   438     if (error != KErrNone) {
       
   439         return false;
       
   440     }
       
   441     else {
       
   442         return true;
       
   443     }
       
   444 }
       
   445 
       
   446 // ---------------------------------------------------------------------------
       
   447 void HtiEngineWrapper::getVersionIfo(QString& version)
       
   448 {
       
   449 	version= QString("%1.%2.%3 (%4 wk%5)")
       
   450 				.arg(KHtiVersionMajor).arg(KHtiVersionMinor).arg(KHtiVersionBuild)
       
   451 				.arg(KHtiVersionYear).arg(KHtiVersionWeek);
       
   452 }
       
   453 
       
   454 // ---------------------------------------------------------------------------
       
   455 bool HtiEngineWrapper::updateStatuses()
       
   456 {
       
   457 	TRAPD(error, iEngine->CheckStatusesL());
       
   458 	
       
   459 	if (error != KErrNone) {
       
   460 		return false;
       
   461 	}
       
   462 	else {
       
   463 		return true;
       
   464 	}
       
   465 }
       
   466 
       
   467 // ---------------------------------------------------------------------------
       
   468 void HtiEngineWrapper::updateStatus(HtiStatus status)
       
   469 {
       
   470 	emit statusChanged(status);
       
   471 }
       
   472 
       
   473 // ---------------------------------------------------------------------------
       
   474 void HtiEngineWrapper::updateSelectedComm(const TDesC& aText)
       
   475 {
       
   476 	iSelectedCommText = QString((QChar*)aText.Ptr(),aText.Length());
       
   477 
       
   478 	emit commSet(iSelectedCommText);
       
   479 }
       
   480 
       
   481 // ---------------------------------------------------------------------------
       
   482 void HtiEngineWrapper::updateCommDetails(const TDesC& aText)
       
   483 {
       
   484 	iCommDetailsText = QString((QChar*)aText.Ptr(),aText.Length());
       
   485 
       
   486 	emit commDetails(iCommDetailsText);
       
   487 }
       
   488 
       
   489 // ---------------------------------------------------------------------------
       
   490 void HtiEngineWrapper::updateAutostartStatus(AutoStartStatus status)
       
   491 {
       
   492 	emit autostartSet(status);
       
   493 }
       
   494 
       
   495 void HtiEngineWrapper::updateConsoleStatus(bool bEnabled)
       
   496 {
       
   497     emit consoleSet(bEnabled);
       
   498 }
       
   499 
       
   500 void HtiEngineWrapper::updateWatchDogStatus(bool bEnabled)
       
   501 {
       
   502     emit watchDogSet(bEnabled);
       
   503 }
       
   504 
       
   505 // ---------------------------------------------------------------------------
       
   506 bool HtiEngineWrapper::listCommPlugins()
       
   507 {
       
   508 	CDesCArray* pluginsArray = NULL;
       
   509 	
       
   510 	TRAPD(error, pluginsArray = iEngine->SearchCommPluginsL());
       
   511 		
       
   512 	if (error != KErrNone) {
       
   513 		return false;
       
   514 	}
       
   515 	else {
       
   516 		for(TInt i = 0; i < pluginsArray->Count(); ++i)
       
   517 			{
       
   518 			TPtrC16 plugin (pluginsArray->MdcaPoint(i));
       
   519 			int len = pluginsArray->MdcaPoint(i).Length();
       
   520 			
       
   521 			QString name ((QChar*)plugin.Ptr(), len);
       
   522 			iPluginNames << name;
       
   523 			}
       
   524 		
       
   525 		emit commPluginsRetrieved(iPluginNames);
       
   526 		
       
   527 		return true;
       
   528 	}
       
   529 }
       
   530 
       
   531 // ---------------------------------------------------------------------------
       
   532 bool HtiEngineWrapper::listIAPs(QStringList& list)
       
   533 {
       
   534     CDesCArray* arrayIAPs = NULL;
       
   535     
       
   536     TRAPD(error, arrayIAPs = iEngine->SearchIAPsL());
       
   537         
       
   538     if (error != KErrNone) {
       
   539         return false;
       
   540     }
       
   541     else {
       
   542         for(TInt i = 0; i < arrayIAPs->Count(); ++i)
       
   543             {
       
   544             TPtrC16 iap (arrayIAPs->MdcaPoint(i));
       
   545             int len = arrayIAPs->MdcaPoint(i).Length();
       
   546             
       
   547             QString name ((QChar*)iap.Ptr(), len);
       
   548             list << name;
       
   549             }
       
   550         
       
   551         return true;
       
   552     }
       
   553     return true;
       
   554 }
       
   555 
       
   556 // ---------------------------------------------------------------------------
       
   557 bool HtiEngineWrapper::getSelectedComm(QString& commName)
       
   558 {
       
   559     TBuf<64> pluginName;
       
   560     iEngine->GetSelectedComm(pluginName);
       
   561     commName = QString((QChar*)pluginName.Ptr(), pluginName.Length());
       
   562     return true;
       
   563 }