⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gnuboxcontainer.cpp

📁 一套Symbian平台的工具库源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		txtBuf.SetMax();
			iLabel->SetTextL(txtBuf);		iTextLines.Close();		User::LeaveIfError(iTextLines.Append(_L("Loading CommDb")));		User::LeaveIfError(iTextLines.Append(_L("Infrared settings...")));		iLoader->Fire();		break;	case EBluetoothDirect:
		txtBuf=KDirectOverBTTxt;
		txtBuf.SetMax();
			iLabel->SetTextL(txtBuf);		iTextLines.Close();		User::LeaveIfError(iTextLines.Append(_L("Loading CommDb")));		User::LeaveIfError(iTextLines.Append(_L("Bluetooth settings...")));		iLoader->Fire();		break;	case EBluetoothDialup:
		txtBuf=KDialupOverBTTxt;
		txtBuf.SetMax();
		iLabel->SetTextL(txtBuf);		iTextLines.Close();		User::LeaveIfError(iTextLines.Append(_L("Loading CommDb")));		User::LeaveIfError(iTextLines.Append(_L("Bluetooth settings...")));		iLoader->Fire();		break;	default:
		txtBuf=KPPPoverCSDGPRSTxt;
		txtBuf.SetMax();
			iLabel->SetTextL(txtBuf);		iTextLines.Close();		User::LeaveIfError(iTextLines.Append(_L("Loading CommDb")));		User::LeaveIfError(iTextLines.Append(_L("CSD/GPRS settings...")));		iLoader->Fire();		break;		}	}void CGnuboxContainer::ReadTextFieldL(CCommsDbTableView* aTable, const TDesC& aRecord)/**	CGnuboxContainer::ReadTextFieldL(CCommsDbTableView* aTable, const TDesC& aRecord)	Reads a particular field and appends it to iTextLines.	@TODO: Need to add scrolling text window support - migrate to CTextView?*/	{	TBuf<KCommsDbSvrMaxFieldLength> printBuffer;	TBuf<KCommsDbSvrMaxFieldLength-10> recBuffer;
	printBuffer=_L(" ");	printBuffer.Append(aRecord);	printBuffer.Append(_L(": "));	aTable->ReadTextL(aRecord,recBuffer);	// Need to store the value in dummyBuffer too...	//If the array is already at the maximum size, delete the first line of text	if (iTextLines.Count() >= KMaxTextLines)		{		iTextLines.Remove(0);		}	if (printBuffer.Length() + recBuffer.Length() > KMaxLineLength)		{		iTextLines.Append(printBuffer);		TBuf<KCommsDbSvrMaxFieldLength> tempBuffer=_L("  ");		tempBuffer.Append(recBuffer);		iTextLines.Append(tempBuffer);		}	else		{		printBuffer.Append(recBuffer);		iTextLines.Append(printBuffer);		}

	if ((iParent->GetMode() == ECSD_GPRS))
		{// Need to store these away because they are important
		// @TODO: Only do the following if it is different from current record...
		TBuf<KCommsDbSvrMaxFieldLength-10> currentBuffer;
		iParent->GetDocument()->RetrieveRecordL(aRecord,currentBuffer);
		if (currentBuffer != recBuffer)
			iParent->GetDocument()->StoreRecordL(aRecord,recBuffer);
		}
	}
void CGnuboxContainer::LoadCommDbSettingsL()/**	CGnuboxContainer::LoadCommDbSettingsL()	This function loads the relevant CommDb settings	Note that we store a couple of tables.	Namely the MODEM table and the DIAL_OUT_ISP table.	@TODO: Need to be pulling out the "Nokia CSD" IAP settings
	@TODO: There is a bug here relating to DIAL_OUT_ISP - what if we're GPRS??!!*/	{	FLOG(_L("**** CGnuboxContainer::LoadCommDbSettingsL ****"));
	// UPDATE THE CURRENT MODE IN - need to do this to pick up changes
	TConnectionMode mode=iParent->GetMode();
	iParent->GetDocument()->StoreRecordL(KModeTxt,TInt(mode));
	// CREATE NEW COMMDB HANDLE	if (iCommDb)		User::Leave(KErrInUse);	iCommDb=CCommsDatabase::NewL(EDatabaseTypeIAP);	CleanupStack::PushL(iCommDb);	// DIAL_OUT_ISP TABLE	CCommsDbTableView* table=iCommDb->OpenTableLC(TPtrC(DIAL_OUT_ISP));	TBuf<KCommsDbSvrMaxColumnNameLength> tableName;	table->GetTableName(tableName);	// Now you need to do something with it...	iTextLines.Append(tableName);	TInt ret=table->GotoFirstRecord();	if (ret != 0)		User::Leave(ret);	ReadTextFieldL(table,TPtrC(ISP_DESCRIPTION));	//ReadTextFieldL(table,TPtrC(ISP_TYPE));	ReadTextFieldL(table,TPtrC(ISP_DEFAULT_TEL_NUM));	CleanupStack::PopAndDestroy();  // table	// MODEM	table=iCommDb->OpenTableLC(TPtrC(MODEM));	table->GetTableName(tableName);	// Now you need to do something with it...	iTextLines.Append(tableName);	ret=table->GotoFirstRecord();	if (ret != 0)		User::Leave(ret);	ReadTextFieldL(table,TPtrC(MODEM_PORT_NAME));	ReadTextFieldL(table,TPtrC(MODEM_CSY_NAME));	ReadTextFieldL(table,TPtrC(MODEM_TSY_NAME));	CleanupStack::PopAndDestroy();  // table	// GET RID OF COMMDB HANDLE	CleanupStack::PopAndDestroy();  // dbs	iCommDb = NULL;	// **** The (re)drawing bit ****	//TRect textRect(KXOffset,23,(KWidth-KXOffset),KHeight);	//SetRect(textRect);	DrawNow();	}TBool CGnuboxContainer::UpdateCommDbL(const TConnectionMode aMode)/**	TBool CGnubox::UpdateCommDbL(TConnectionMode aMode)	Here we update the CommDb MODEM record to reflect the	change in connection mode we have solicited.	Currently there are five options:	1) Direct PPP connection over Infrared	2) Direct PPP connection over Bluetooth	3) Dialup PPP connection over Infrared	4) Dialup PPP connection over Bluetooth	5) Default PPP over CSD/GPRS phone stack	@TODO: Need to work out how to restore CSD/GPRS settings*/	{	FLOG(_L("**** CGnuboxContainer::UpdateCommDbL ****"));
	TBool ok=TRUE;	// CREATE NEW COMMDB HANDLE	if(iCommDb)		User::Leave(KErrInUse);	iCommDb=CCommsDatabase::NewL(EDatabaseTypeIAP);	CleanupStack::PushL(iCommDb);	// LOCK COMMDB - only needed for writes	TInt ret = iCommDb->BeginTransaction();	if (ret != 0)		{		iEikonEnv->InfoMsg(_L("Failed to lock CommDB"));		User::Leave(KErrGeneral);		}	// Populate templates - in ProfCfg at this point...	// ...	//TUint32 id;	//CCommsDbTableView* table=iCommDb->OpenTableLC(TPtrC(IAP));	// Goto first record	//User::LeaveIfError(table->GotoFirstRecord());	// Update it with the relevant fields	//User::LeaveIfError(table->UpdateRecord(id));	//table->WriteTextL(TPtrC(COMMDB_NAME),_L("Direct PPP over IR"));	//table->WriteUintL(TPtrC(IAP_SERVICE),NTRasISPId);	//table->WriteTextL(TPtrC(IAP_SERVICE_TYPE),TPtrC(DIAL_OUT_ISP));	//test(table->PutRecordChanges()==KErrNone);	switch (aMode)		{	case EInfraredDirect:		{// Modify default (ie. first) ISP record: Direct PPP over IR		 // DIRECT PPP OVER IR:		 // 1) insert NULL ISP_DEFAULT_TEL_NUM and MODEM_TSY_NAME		 // 2) insert IrCOMM::0 into CSY slot		CCommsDbTableView* table=iCommDb->OpenTableLC(TPtrC(DIAL_OUT_ISP));		User::LeaveIfError(table->GotoFirstRecord());		User::LeaveIfError(table->UpdateRecord());		table->WriteTextL(TPtrC(ISP_DESCRIPTION),KDirect2BoxTxt);		//table->WriteUintL(TPtrC(ISP_TYPE),(TUint32)EIspTypeInternetOnly);		// Insert NULL ISP telephone number to kick into direct PPP mode		table->WriteTextL(TPtrC(ISP_DEFAULT_TEL_NUM),KNullDesC);		User::LeaveIfError(table->PutRecordChanges());		CleanupStack::PopAndDestroy();  // table		// Modify default (ie. first) MODEM record: IrCOMM::0		table=iCommDb->OpenTableLC(TPtrC(MODEM));		User::LeaveIfError(table->GotoFirstRecord());		User::LeaveIfError(table->UpdateRecord());		table->WriteTextL(TPtrC(MODEM_PORT_NAME),KIrCOMMPortNumTxt);		table->WriteTextL(TPtrC(MODEM_CSY_NAME),KIrCOMMTxt);		// Just leave the TSY as was...		// Trying to set it to NULL won't work as it appears		// to default to GSMBSC anyways...		//table->WriteTextL(TPtrC(MODEM_TSY_NAME),KNullDesC);		User::LeaveIfError(table->PutRecordChanges());		CleanupStack::PopAndDestroy();  // table		break;		}	case EInfraredDialup:		{// Modify default (ie. first) ISP record: Direct PPP over IR		 // DIRECT PPP OVER IR (IR access point):		 // 1) insert GSMBSC ISP TEL		 // 2) insert IrCOMM::0 into CSY slot		CCommsDbTableView* table=iCommDb->OpenTableLC(TPtrC(DIAL_OUT_ISP));		User::LeaveIfError(table->GotoFirstRecord());		User::LeaveIfError(table->UpdateRecord());		table->WriteTextL(TPtrC(ISP_DESCRIPTION),KDialup2BoxTxt);		//table->WriteUintL(TPtrC(ISP_TYPE),(TUint32)EIspTypeInternetOnly);		
		TBuf<20> telnum;
		iParent->GetDocument()->RetrieveRecordL(KISPTelNumTxt,telnum);	
		table->WriteTextL(TPtrC(ISP_DEFAULT_TEL_NUM),telnum); // freeserve @TODO: RESTORE PROPERLY from file store!!
		//table->WriteBoolL(TPtrC(ISP_PROMPT_FOR_LOGIN),ETrue);  // pass in your login		User::LeaveIfError(table->PutRecordChanges());		CleanupStack::PopAndDestroy();  // table		// Modify default (ie. first) MODEM record: IrCOMM::0		table=iCommDb->OpenTableLC(TPtrC(MODEM));		User::LeaveIfError(table->GotoFirstRecord());		User::LeaveIfError(table->UpdateRecord());		table->WriteTextL(TPtrC(MODEM_PORT_NAME),KIrCOMMPortNumTxt);		table->WriteTextL(TPtrC(MODEM_CSY_NAME),KIrCOMMTxt);		// You have to change the default TSY to GSMBSC...		// It seems that doing this does the trick...		table->WriteTextL(TPtrC(MODEM_TSY_NAME),KNullDesC);		User::LeaveIfError(table->PutRecordChanges());		CleanupStack::PopAndDestroy();  // table		break;		}	case EBluetoothDirect:		{// Modify default (ie. first) ISP record: Dialup PPP over BT		 // DIRECT PPP OVER Bluetooth (LANP):		 // 1) insert NULL ISP_DEFAULT_TEL_NUM and MODEM_TSY_NAME		 // 2) insert BTCOMM::0 into CSY slot		// Throw up a dialog here to allow the user		// to select the device they want to try and do LANP with...		TRAPD(err,SelectBluetoothDeviceL(ELANAccess));
		if (err != 0)
			{// We failed to select a device - user probably didn't choose one
			ok=FALSE;
			break; // ensures we unlock and NULL iCommDb
			}		CCommsDbTableView* table=iCommDb->OpenTableLC(TPtrC(DIAL_OUT_ISP));		User::LeaveIfError(table->GotoFirstRecord());		User::LeaveIfError(table->UpdateRecord());		table->WriteTextL(TPtrC(ISP_DESCRIPTION),KDirect2BoxTxt);		//table->WriteUintL(TPtrC(ISP_TYPE),(TUint32)EIspTypeInternetOnly);		// Insert NULL ISP telephone number to kick into direct PPP mode		table->WriteTextL(TPtrC(ISP_DEFAULT_TEL_NUM),KNullDesC);		User::LeaveIfError(table->PutRecordChanges());		CleanupStack::PopAndDestroy();  // table		// Modify default (ie. first) MODEM record: BTCOMM::0		table=iCommDb->OpenTableLC(TPtrC(MODEM));		User::LeaveIfError(table->GotoFirstRecord());		User::LeaveIfError(table->UpdateRecord());		table->WriteTextL(TPtrC(MODEM_PORT_NAME),KBTCOMMPortNumTxt);		table->WriteTextL(TPtrC(MODEM_CSY_NAME),KBTCOMMTxt);		// Just leave the TSY as was...		// Trying to set it to NULL won't work as it appears		// to default to GSMBSC anyways...		//table->WriteTextL(TPtrC(MODEM_TSY_NAME),KNullDesC);		User::LeaveIfError(table->PutRecordChanges());		CleanupStack::PopAndDestroy();  // table		break;		}	case EBluetoothDialup:		{// Modify default (ie. first) ISP record: Direct PPP over Bluetooth		 // DIRECT PPP OVER Bluetooth (DUNP):		 // 1) insert GSMBSC ISP TEL		 // 2) insert BTCOMM::0 into CSY slot		// Throw up a dialog here to allow the user		// to select the device they want to try and do DUNP with...		TRAPD(ret,SelectBluetoothDeviceL(EDialupNetworking));
		if (ret != 0)
			{// We failed to select a device - user probably didn't choose one
			ok=FALSE;
			break; // ensures we unlock and NULL iCommDb
			}		CCommsDbTableView* table=iCommDb->OpenTableLC(TPtrC(DIAL_OUT_ISP));		User::LeaveIfError(table->GotoFirstRecord());		User::LeaveIfError(table->UpdateRecord());		table->WriteTextL(TPtrC(ISP_DESCRIPTION),KDialup2BoxTxt);		//table->WriteUintL(TPtrC(ISP_TYPE),(TUint32)EIspTypeInternetOnly);

		TBuf<20> telnum;
		iParent->GetDocument()->RetrieveRecordL(KISPTelNumTxt,telnum);	
		table->WriteTextL(TPtrC(ISP_DEFAULT_TEL_NUM),telnum); // freeserve @TODO: RESTORE PROPERLY from file store!!
		//table->WriteBoolL(TPtrC(ISP_PROMPT_FOR_LOGIN),EFalse);  // pass in your login		User::LeaveIfError(table->PutRecordChanges());		CleanupStack::PopAndDestroy();  // table		// Modify default (ie. first) MODEM record: BTCOMM::0		table=iCommDb->OpenTableLC(TPtrC(MODEM));		User::LeaveIfError(table->GotoFirstRecord());		User::LeaveIfError(table->UpdateRecord());		table->WriteTextL(TPtrC(MODEM_PORT_NAME),KBTCOMMPortNumTxt);		table->WriteTextL(TPtrC(MODEM_CSY_NAME),KBTCOMMTxt);		// It seems that doing this does the trick...		table->WriteTextL(TPtrC(MODEM_TSY_NAME),KNullDesC);		User::LeaveIfError(table->PutRecordChanges());		CleanupStack::PopAndDestroy();  // table		break;		}	default:		{// Ideally you need to be restoring here from the defaults you stowed		 // away earlier in document...		 // ie. ISP_DESCRIPTION, ISP_DEFAULT_TEL_NUM		CCommsDbTableView* table=iCommDb->OpenTableLC(TPtrC(DIAL_OUT_ISP));		User::LeaveIfError(table->GotoFirstRecord());		User::LeaveIfError(table->UpdateRecord());		table->WriteTextL(TPtrC(ISP_DESCRIPTION),KNullDesC);		table->WriteUintL(TPtrC(ISP_TYPE),(TUint32)EIspTypeInternetAndWAP);
		//table->WriteTextL(TPtrC(ISP_DEFAULT_TEL_NUM),_L("08450796699")); // freeserve @TODO: RESTORE PROPERLY from file store!!		
		TBuf<20> telnum;
		iParent->GetDocument()->RetrieveRecordL(KISPTelNumTxt,telnum);	
		table->WriteTextL(TPtrC(ISP_DEFAULT_TEL_NUM),telnum); // freeserve @TODO: RESTORE PROPERLY from file store!!
		//table->WriteBoolL(TPtrC(ISP_PROMPT_FOR_LOGIN),ETrue);  // pass in your login		User::LeaveIfError(table->PutRecordChanges());		CleanupStack::PopAndDestroy();  // table		// Modify default (ie. first) MODEM record: DATAPORT::0		table=iCommDb->OpenTableLC(TPtrC(MODEM));		User::LeaveIfError(table->GotoFirstRecord());		User::LeaveIfError(table->UpdateRecord());		table->WriteTextL(TPtrC(MODEM_PORT_NAME),KDataportPortNumTxt);		table->WriteTextL(TPtrC(MODEM_CSY_NAME),KDataportTxt);		// You have to change back to the default TSY...		table->WriteTextL(TPtrC(MODEM_TSY_NAME),KPhoneTSYTxt);		User::LeaveIfError(table->PutRecordChanges());		CleanupStack::PopAndDestroy();  // table		break;		}		}	// COMMIT AND UNLOCK THE COMMDB	ret=iCommDb->CommitTransaction();	if(ret != KErrNone)		{		iEikonEnv->InfoMsg(_L("Failed to unlock CommDB"));		User::Leave(KErrGeneral);		}	// GET RID OF COMMDB HANDLE	CleanupStack::PopAndDestroy();  // dbs	iCommDb = NULL;
	return ok;	}void CGnuboxContainer::SelectBluetoothDeviceL(TBTProfile aProfile)/**	CGnuboxContainer::SelectBluetoothDeviceL()	Deals with Bluetooth device selection.*/	{	FLOG(_L("CGnuboxContainer::SelectBluetoothDevice"));	TBTDeviceResponseParamsPckg pckg;	TBTDeviceSelectionParamsPckg resPckg;	RNotifier not;	User::LeaveIfError(not.Connect());	TRequestStatus stat;	not.StartNotifierAndGetResponse(stat,KDeviceSelectionNotifierUid,resPckg,pckg);	User::WaitForRequest(stat);	// check response	// and if it's positive then slap the resp into CommDb BT settings...	not.CancelNotifier(KDeviceSelectionNotifierUid);	not.Close();	// Currently we're leaving if the user presses Cancel...
	User::LeaveIfError(stat.Int());	iDevAddr = pckg().BDAddr();	iDevName = pckg().DeviceName();	SetupCSYL(aProfile);	}void CGnuboxContainer::SetupCSYL(TBTProfile aProfile)	{	TBTCommPortSettings	settings;	settings.SetEncryption();	settings.SetAuthentication();	settings.SetUUID(TUint(aProfile));  // The service - e.g. DUNP=0x1103	settings.SetPort(0);				// n where BTCOMM::n	settings.SetBTAddr(iDevAddr);	TBuf<12> addrAsText;	addrAsText.Zero();	addrAsText.Format(_L("%02x%02x%02x%02x%02x%02x"),			iDevAddr[0], iDevAddr[1], iDevAddr[2], iDevAddr[3], iDevAddr[4], iDevAddr[5]);	//FLOG(addrAsText);	FLOG(_L("BTCOMM CSY Configured\n"));	CBTRegistry* registry=CBTRegistry::NewL();	CleanupStack::PushL(registry);
	//User::LeaveIfError(registry->SetDefaultCommPort(settings));	iEikonEnv->InfoMsg(_L("Set registry here"));
	
	FLOG(_L("BTCOMM CSY Configured\n"));	CleanupStack::PopAndDestroy(registry);	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -