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

📄 settingsdialog.cxx

📁 这是一个开源码的sip用户代理 写的都很清楚是用C++语言开发的 对于研究sip协议的朋友绝对是有很好的参考价值
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/* *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU Library General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *//* Copyright (C) 2004  * * Authors: Erik Eliasson <eliasson@it.kth.se> *          Johan Bilien <jobi@via.ecp.fr>*/#include"MinisipMainWindowWidget.h"#include"SettingsDialog.h"#include<qpushbutton.h>#include<qmessagebox.h>#include<libmsip/SipKeyAgreement.h>#include<libmsip/SipMessageTransport.h>#include<libmsip/SipCommandString.h>#include"../../../sip/DefaultDialogHandler.h"#include<libmutil/itoa.h>#include<libmutil/XMLParser.h>#include<libmutil/cert.h>#include<libmnetutil/IP4Address.h>#ifdef HAVE_LIBASOUND#include"../../../soundcard/AlsaCard.h"#include"../../../soundcard/SoundIO.h"#endifSettingsDialog::SettingsDialog(QWidget *parent, const char *name, bool destroy) : 		QTabDialog(parent,name, true, destroy?Qt::WDestructiveClose:0),		certDialog( this ),		generalWidget(this, name), 		securityWidget(this, name), #ifndef DISABLE_PHONEBOOK		phoneBooksWidget( this, name), #endif		advancedWidget(this, name){	addTab( &generalWidget, "General");	addTab( &securityWidget, "Security");#ifndef DISABLE_PHONEBOOK	addTab( &phoneBooksWidget, "Phone books");#endif	addTab( &stunWidget, "STUN");	addTab( &advancedWidget, "Advanced");	setCancelButton();}SettingsDialog::~SettingsDialog(){}void SettingsDialog::setConfig(MRef<SipSoftPhoneConfiguration *> config){	this->config=config;	generalWidget.setConfig(config);	securityWidget.setConfig(config);#ifndef DISABLE_PHONEBOOK	phoneBooksWidget.setConfig(config);#endif	stunWidget.setConfig(config);	advancedWidget.setConfig(config);	certDialog.setCertChain(config->inherited.cert);	certDialog.setRootCa(config->inherited.cert_db);	fprintf( stderr, "Exiting setConfig\n");}void SettingsDialog::show(){	generalWidget.backupSettings();	stunWidget.backupSettings();	advancedWidget.backupSettings();	securityWidget.backupSettings();	QTabDialog::show();	}void SettingsDialog::accept(){	string errReport = advancedWidget.apply() + generalWidget.apply() + securityWidget.apply() + stunWidget.apply(); #ifndef DISABLE_PHONEBOOK	errReport = errReport + phoneBooksWidget.apply(parser);#endif	if (errReport.length()>0){				QMessageBox msg("Apply warnings!", ("The warnings were reported when applying changes:\n"+errReport).c_str(),QMessageBox::Warning,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton,this);		msg.exec();	}	config->save();	QDialog::accept();}void SettingsDialog::reject(){	generalWidget.restoreSettings();	stunWidget.restoreSettings();	advancedWidget.restoreSettings();	securityWidget.restoreSettings();//	hide();	QDialog::reject();	//TODO: add restore for phonebook settings	}void SettingsDialog::showCertDialog(){	certDialog.show();}GeneralTabWidget::GeneralTabWidget(QWidget *parent, const char *name): 		QWidget(parent, name), 		layout( this, 2, 1),		groupboxSip(2,Qt::Horizontal,"SIP",this),				autodetectRadioGroup(),		labelUserURI( "User's SIP address:", &groupboxSip, "sipuri"), 		editUserURI(&groupboxSip),			labelProxyUsername( "User's proxy username:", &groupboxSip), 		editProxyUsername(&groupboxSip),				labelProxyPassword( "User's proxy password:", &groupboxSip), 		editProxyPassword(&groupboxSip),				radioAutodetect("Autodetect proxy",&groupboxSip),		labelEmpty( "", &groupboxSip),				radioManualProxy("Manual proxy:",&groupboxSip),		editManualProxy(&groupboxSip),		checkRegister("Register to proxy", &groupboxSip),			groupboxDevices(2,Qt::Horizontal,"Devices", this),				labelSoundDevice("Sound I/O device:",&groupboxDevices),		comboboxSoundDevice(&groupboxDevices),			labelNIC("Network interface:",&groupboxDevices),		comboboxNIC(&groupboxDevices){	layout.addWidget(&groupboxSip, 0, 0);	layout.addWidget(&groupboxDevices, 1, 0);			#ifndef OPIE	editUserURI.setMinimumWidth(250);#endif	tabDialog = (SettingsDialog *)parent;	}GeneralTabWidget::~GeneralTabWidget(){}void GeneralTabWidget::setConfig(MRef<SipSoftPhoneConfiguration *> config){	this->config = config;	editUserURI.setText((config->inherited.userUri).c_str());	editProxyUsername.setText((config->inherited.proxyUsername).c_str());	editProxyPassword.setEchoMode(QLineEdit::Password);	editProxyPassword.setText((config->inherited.proxyPassword).c_str());	autodetectRadioGroup.insert(&radioAutodetect,1);	radioAutodetect.setChecked(config->autodetectProxy);	connect(&radioAutodetect, SIGNAL(stateChanged(int)), this, SLOT(autodetectStateChanged(int)) );		autodetectRadioGroup.insert(&radioManualProxy,2);	autodetectRadioGroup.setRadioButtonExclusive(true);	if(config->inherited.proxyAddr!=NULL)		editManualProxy.setText(config->inherited.proxyAddr->getString().c_str());		checkRegister.setChecked(config->doRegister);	#ifdef HAVE_LIBASOUND	list<AlsaCard *> cards = AlsaCard::getCardList();	list<AlsaCard *>::iterator i;	int j = 0;		comboboxSoundDevice.clear();		for( i = cards.begin(); i != cards.end(); i++ ){		comboboxSoundDevice.insertItem((*i)->getCardName().c_str());		if( config->soundcard != NULL && 		    config->soundcard->getDevice() == (string("hw:")+itoa(j)) ){			comboboxSoundDevice.setCurrentItem(j);		}		j++;	}	#endif	checkStates();}void GeneralTabWidget::backupSettings(){//	cerr << "Saving GeneralTabWidget settings"<< endl;	userUristring = editUserURI.text();	proxyUsernamestring = editProxyUsername.text();	proxyPasswordstring = editProxyPassword.text();	autodetectProxy = radioAutodetect.isChecked();	manualProxystring = editManualProxy.text();	doRegister = checkRegister.isChecked();	soundDeviceIndex=comboboxSoundDevice.currentItem();	nicDeviceIndex= comboboxNIC.currentItem();}void GeneralTabWidget::restoreSettings(){//	cerr << "Restoring GeneralTabWidget settings"<< endl;	editUserURI.setText(userUristring);	editProxyUsername.setText(proxyUsernamestring);	editProxyPassword.setText(proxyPasswordstring);	radioAutodetect.setChecked(autodetectProxy);	editManualProxy.setText(manualProxystring);	checkRegister.setChecked(doRegister);		comboboxSoundDevice.setCurrentItem(soundDeviceIndex);	comboboxNIC.setCurrentItem(nicDeviceIndex);}string GeneralTabWidget::apply(){	string ret = "";	if (editUserURI.text() != userUristring){		//sipphone->setUserURI(editUserURI.text().ascii());		config->inherited.userUri = editUserURI.text().ascii();		//cerr << "Changing user uri setting to "<<  editUserURI.text();	}	if (editProxyUsername.text() != proxyUsernamestring){		//sipphone->setProxyUsername(editProxyUsername.text().ascii());		config->inherited.proxyUsername = editProxyUsername.text().ascii();//		cerr << "Changing proxy username setting to "<< editProxyUsername.text();	}	if (editProxyPassword.text()!= proxyPasswordstring){		//sipphone->setProxyPassword(editProxyPassword.text().ascii());		config->inherited.proxyPassword = editProxyPassword.text().ascii();//		cerr << "Changing proxy password setting to "<< editProxyPassword.text();	}		if (radioAutodetect.isChecked() != autodetectProxy){		config->autodetectProxy= radioAutodetect.isChecked();	}		if (editManualProxy.text() != manualProxystring){		try{			IPAddress *ip;			ip = new IP4Address(string(editManualProxy.text().ascii()));			if( config->inherited.proxyAddr != NULL )				delete config->inherited.proxyAddr;			config->inherited.proxyAddr = ip;		} catch (IPAddressHostNotFoundException * exc){			cerr << "Could not resolve proxy address:";			cerr << exc->what() << endl;		}	}		if (checkRegister.isChecked()!= doRegister){//		sipphone->setDoRegisterToProxy(checkRegister.isChecked());		config->doRegister = checkRegister.isChecked();		if (config->doRegister){			CommandString reg("",SipCommandString::proxy_register);//			if (!config->dialogContainer.isNull()){			if (!config->sip.isNull()){                                SipSMCommand cmd(reg, SipSMCommand::remote, SipSMCommand::TU);				//config->dialogContainer->handleCommand(cmd);				config->sip->handleCommand(cmd);                        }		}	}			//	cerr << "Register setting changed to "<< checkRegister.isChecked() << endl;	if (comboboxSoundDevice.currentItem()!= soundDeviceIndex){#ifndef HAVE_LIBASOUND		cerr << "WARNING: UNHANDLED: Sound device changed to "<<comboboxSoundDevice.currentText()<< endl;	}#else		ret += "WARNING: Changing the sound device requires to restart the application\n";	}#endif		if (comboboxNIC.currentItem()!=nicDeviceIndex)		cerr << "WARNING: UNHANDLED: NIC device changed to "<< comboboxNIC.currentText()<< endl;		return ret; //"Error from GTW\n";	}void GeneralTabWidget::checkStates(){	if (!radioManualProxy.isChecked()){		radioAutodetect.setChecked(true);		editManualProxy.setEnabled(false);	}}void GeneralTabWidget::autodetectStateChanged(int state){	int32_t toState=false;	switch(state){		case QButton::On:			toState=false;			break;		case QButton::Off:			toState=true;			break;		case QButton::NoChange:			return;	}		editManualProxy.setEnabled(toState);	radioManualProxy.setChecked(toState);}SecurityTabWidget::SecurityTabWidget(QWidget *parent, const char *name): QWidget(parent, name), 		layout( this, 3, 1),		#ifndef OPIE		groupboxOutGoing(3,Qt::Horizontal,"Outgoing Calls", this),#else		groupboxOutGoing(2,Qt::Horizontal,"Outgoing Calls", this),#endif		checkSecured("Use secured outgoing calls if possible", &groupboxOutGoing),		labelOGEmpty("", &groupboxOutGoing ),#ifndef OPIE		labelOGEmpty2("", &groupboxOutGoing ),		labelKaType("Key agreement for outgoing calls",&groupboxOutGoing),#endif		comboboxKaType(false,&groupboxOutGoing),		//layoutDH(&groupboxDH,5,4), #ifndef OPIE		groupboxDH(3,Qt::Horizontal,"Diffie-Hellman", this),#else		groupboxDH(2,Qt::Horizontal,"Diffie-Hellman", this),#endif#ifndef OPIE		checkDH("Enable Diffie-Hellman key agreement", &groupboxDH),#else		checkDH("Diffie-Hellman", &groupboxDH),#endif		labelDHEmpty("",&groupboxDH),#ifndef OPIE		labelDHEmpty2("",&groupboxDH),#endif		buttonCert( "Certificate settings...", &groupboxDH ),#ifndef OPIE		groupboxPSK(3,Qt::Horizontal,"Pre-Shared Key", this),#else		groupboxPSK(2,Qt::Horizontal,"Pre-Shared Key", this),#endif#ifndef OPIE		checkPSK("Enable Pre-Shared Key key agreement", &groupboxPSK),#else		checkPSK("Pre-Shared Key", &groupboxPSK),#endif		labelPSKEmpty("", &groupboxPSK ),#ifndef OPIE		labelPSKEmpty2("", &groupboxPSK ),#endif		labelPSK("Pre-Shared Key", &groupboxPSK),		editPSK(&groupboxPSK)		{	// Outgoing	layout.addWidget(&groupboxOutGoing, 0, 0);	connect(&checkSecured, SIGNAL(stateChanged(int)), this, SLOT(checkSecuredPressed(int)) );	//layout.addWidget(&labelKaType, 1,0);	//layout.addWidget(&comboboxKaType, 1,1);	//	tabDialog = (SettingsDialog *)parent;}SecurityTabWidget::~SecurityTabWidget(){}void SecurityTabWidget::setConfig(MRef<SipSoftPhoneConfiguration *> config){	this->config = config;	checkSecured.setChecked(config->inherited.secured);	// Diffie-Hellman	layout.addWidget(&groupboxDH, 1,0);	connect(&checkDH, SIGNAL(stateChanged(int)), this, SLOT(checkDHPressed(int)) );	checkDH.setChecked(config->inherited.dh_enabled);	connect(&buttonCert, SIGNAL(clicked()), tabDialog, 		SLOT( showCertDialog() ) );	// Pre-Shared Key	layout.addWidget(&groupboxPSK, 2, 0);	connect(&checkPSK, SIGNAL(stateChanged(int)), this, SLOT(checkPSKPressed(int)) );		checkPSK.setChecked(config->inherited.psk_enabled);		string psk( (const char *)config->inherited.psk, config->inherited.psk_length );		editPSK.setText(psk.c_str());		checkStates();#if (QT_VERSION > 0x030000)	if( config->inherited.ka_type == KEY_MGMT_METHOD_MIKEY_DH )		comboboxKaType.setCurrentText( "Diffie-Hellman" );	else if( config->inherited.ka_type == KEY_MGMT_METHOD_MIKEY_PSK )		comboboxKaType.setCurrentText( "Pre-Shared Keys" );#else	if( config->inherited.psk_enabled && config->inherited.dh_enabled ){		if( config->inherited.ka_type == KEY_MGMT_METHOD_MIKEY_DH )			comboboxKaType.setCurrentItem( 1 );		else if( config->inherited.ka_type == KEY_MGMT_METHOD_MIKEY_PSK )			comboboxKaType.setCurrentItem( 0 );	}#endif}void SecurityTabWidget::backupSettings(){	doSecured = checkSecured.isChecked();	doDH = checkDH.isChecked();	doPSK = checkPSK.isChecked();	pskstring = editPSK.text();	kaTypeSelected = comboboxKaType.currentItem();}void SecurityTabWidget::restoreSettings(){	checkSecured.setChecked(doSecured);	checkDH.setChecked(doDH);	checkPSK.setChecked(doPSK);	editPSK.setText(pskstring);	comboboxKaType.setCurrentItem(kaTypeSelected);}void SecurityTabWidget::checkStates(){	bool secured_checked = checkSecured.isChecked();	bool dh_checked = checkDH.isChecked();	bool psk_checked = checkPSK.isChecked();		comboboxKaType.clear();	if( psk_checked )		comboboxKaType.insertItem("Pre-Shared Keys");	if( dh_checked )		comboboxKaType.insertItem("Diffie-Hellman");	labelPSK.setEnabled(psk_checked);	editPSK.setEnabled(psk_checked);	checkSecured.setEnabled( dh_checked || psk_checked );//	if( !(dh_checked || psk_checked) ){//		checkSecured.setChecked(false);//	}#ifndef OPIE	labelKaType.setEnabled( dh_checked || psk_checked );#endif	comboboxKaType.setEnabled( (dh_checked || psk_checked) && secured_checked );}void SecurityTabWidget::checkSecuredPressed(int state){	checkStates();}void SecurityTabWidget::checkDHPressed(int state){	checkStates();}void SecurityTabWidget::checkPSKPressed(int state){	checkStates();}string SecurityTabWidget::apply(){	string error = "";		if (checkSecured.isChecked()!= doSecured){		config->inherited.secured = (checkDH.isChecked() || checkPSK.isChecked()) && checkSecured.isChecked();	}		if (checkPSK.isChecked()!= doPSK){		config->inherited.psk_enabled = checkPSK.isChecked();	}	if (checkDH.isChecked()!= doDH){		config->inherited.dh_enabled = checkDH.isChecked();	}		if (editPSK.text() != pskstring){		string s = editPSK.text().ascii();		unsigned char * psk = (unsigned char *)s.c_str();		unsigned int psk_length = s.size();		if( config->inherited.psk != NULL )			delete [] config->inherited.psk;		config->inherited.psk = new unsigned char[psk_length];		memcpy( config->inherited.psk, psk, psk_length );		config->inherited.psk_length = psk_length;	}	if (checkSecured.isEnabled() && checkSecured.isChecked()){		if (comboboxKaType.currentText() == "Pre-Shared Keys"){			config->inherited.ka_type = KEY_MGMT_METHOD_MIKEY_PSK;		}		else if (comboboxKaType.currentText() == "Diffie-Hellman"){			config->inherited.ka_type = KEY_MGMT_METHOD_MIKEY_DH;		}	}		return error; //"Error from GTW\n";	}#ifndef DISABLE_PHONEBOOKPhoneBooksWidget::PhoneBooksWidget(QWidget *parent, const char *name): 		QWidget(parent,name),		hLayout(),		vLayout(this),//		labelDesc("Description:",this),//		editDesc(this),		labelPath("URL (file:// or http://):",this),		editPath(this),

⌨️ 快捷键说明

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