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

📄 kphone.cpp

📁 KphoneSI (kpsi) is a SIP (Session Initiation Protocol) user agent for Linux, with which you can in
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include <stdio.h>#include <stdlib.h>#include <qtimer.h>#include <qsettings.h>#include <qmenubar.h>#include <qmessagebox.h>#include <qapplication.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>#include "../dissipate2/sipuser.h"#include "../dissipate2/sipclient.h"#include "../dissipate2/sipcall.h"#include "../dissipate2/siputil.h"#include "../dissipate2/sipregister.h"#include "sessioncontrol.h"#include "audiocontrol.h"#include "videocontrol.h"#include "extcontrol.h"#include "ksipregistrations.h"#include "kphoneview.h"#include "ksippreferences.h"#include "ksipoptions.h"#include "kphonebook.h"#include "kphone.h"#include "trayicon.h"#include "callaudio.h"#include "kstatics.h"KPhone::KPhone( unsigned int listenport, QString dhost, QString prefix, bool p2p, bool looseRoute, bool strictRoute, int debug ) : QMainWindow(0){	rdSock = 0;	haveRDSock = false;	rdLoop = 0;	QString uristr;	userPrefix = "default";	if( !prefix.isEmpty() ) {		setCaption( prefix );		userPrefix = prefix + "_";	}		if(dhost != "") {	    Sip::setLocalAddress(dhost);	} else {	    Sip::setLocalAddress( Sip::getLocalAddress() );	}	if( Sip::getLocalAddress().isEmpty() ) {		exit(0);	}	KStatics::debugLevel=debug;	KStatics::myInd=KStatics::dBase + getUserPrefix();	QString p = KStatics::dBase + getUserPrefix() + "Registration/";	QString socketStr;	{ //Brackets are used to close and write settings	QSettings settings;	socketStr = settings.readEntry( KStatics::dBase + getUserPrefix() + "/General/SocketMode", "UDP" );}	client = new SipClient( 0, 0, listenport, looseRoute, strictRoute, socketStr );	if(p2p) {	QSettings settings1;	settings1.writeEntry( p + "/AutoRegister", "No" );	settings1.writeEntry( p + "SipServer", "" );	settings1.writeEntry( p + "SipUri", client->getListenPort() + "<sip:" + client->getListenPort()+ "@" + Sip::getLocalAddress() + ":" + client->getListenPort() + ">");	}	QSettings settings;		uristr = settings.readEntry( p + "SipUri" );	if( settings.readEntry( p + "/UseProxyDial", "Yes" ) == "Yes" ) {			client->setUseProxyDial( true );	} else {		    client->setUseProxyDial( false );	}	client->setCallForward( settings.readBoolEntry( p + "/callforward", false ) );	client->setCallForwardUri( SipUri( settings.readEntry( p + "/forwardaddr", QString::null ) ) );	client->setCallForwardMessage( settings.readEntry( p + "/forwardmsg", QString::null ) );	client->setMaxForwards( settings.readNumEntry( p + "/maxforwards", 70 ) );	client->setBusyMessage( settings.readEntry( p + "/busymsg", QString::null ) );//	if( settings.readEntry( KStatics::dBase+ getUserPrefix()+"/Symmetric/Signalling", "Yes" ) == "Yes" ) {	client->setSymmetricMode( true );//	}	QString hvstr = settings.readEntry( KStatics::dBase+ getUserPrefix()+"/Symmetric/hideviamode", "NoHide" );	if( hvstr == "NoHide" ) { client->setHideViaMode( SipClient::DontHideVia ); }	else if( hvstr == "HideHop" ) { client->setHideViaMode( SipClient::HideHop ); }	else if( hvstr == "HideRoute" ) { client->setHideViaMode( SipClient::HideRoute ); }	user = new SipUser( client, SipUri( uristr ) );	sessionC = new SessionControl(getUserPrefix());		// Initially, none of the dialogs exist yet	qdial = 0;	userinfo = 0;	audiocontrol = 0;	videocontrol = 0;	extcontrol1 =0;	extcontrol2 =0;	extcontrol3 =0;	extcontrol4 =0;	registrations = 0;	sipprefs = 0;	queryoptions = 0;	testoptions = 0;	trayIcon = NULL;	callAudio = new CallAudio(sessionC,getUserPrefix()); //stun ??	view = new KPhoneView( sessionC, client, user, callAudio, this, getUserPrefix(), p2p );		connect( view, SIGNAL( stateChanged() ), this, SLOT( updateTrayIcon() ) );	if( uristr != QString::null ) {		p = KStatics::dBase + getUserPrefix() + "Registration/";		QString userdefaultproxy = settings.readEntry( p + "SipServer", QString::null );		if( userdefaultproxy.lower() == "sip:" ) {			userdefaultproxy = "";		}		view->updateIdentity( user );		client->updateIdentity( user, userdefaultproxy );		sessionC->setDefaultProxy(userdefaultproxy);			}	registrations = new KSipRegistrations( client, view, this, getUserPrefix() );	view->identities( registrations );	setCentralWidget( view );	QPopupMenu *popup = new QPopupMenu;//	popup->insertItem( "Identity...", this, SLOT( showRegistrations() ) );//        popup->insertItem( "Options...", this, SLOT( showQueryOptions() ) );	popup->insertSeparator();	popup->insertItem( "&Quit", this, SLOT( kphoneQuit() ) );	menuBar()->insertItem( "&File", popup );	preferencesMenu = new QPopupMenu;	preferencesMenu->insertItem( "SIP Preferences...", this, SLOT( showGlobalPreferences() ) );	preferencesMenu->insertItem( "Audio Preferences...", this, SLOT( showAudioPreferences() ) );	preferencesMenu->insertItem( "Video Preferences...", this, SLOT( showVideoPreferences() ) );	preferencesMenu->insertItem( "Phone Book", view, SLOT( showPhoneBook() ) );	preferencesMenu->insertSeparator();	preferencesMenu->insertItem( "Session Type 1...", this, SLOT( showExtPreferences1() ) );	preferencesMenu->insertItem( "Session Type 2...", this, SLOT( showExtPreferences2() ) );	preferencesMenu->insertItem( "Session Type 3...", this, SLOT( showExtPreferences3() ) );	preferencesMenu->insertItem( "Session Type 4...", this, SLOT( showExtPreferences4() ) );	int id=preferencesMenu->insertItem( "Tray Icon", this, SLOT( toggleTrayIcon(int) ) );	QString usetrayicon = settings.readEntry( KStatics::dBase + getUserPrefix() + "/General/TrayIcon", "No" );	if ( usetrayicon.lower() == "yes" ) {		preferencesMenu->setItemChecked( id, true );		createTrayIcon();	} else {		preferencesMenu->setItemChecked( id, false );	}	menuBar()->insertItem( "&Preferences", preferencesMenu );	menuBar()->insertSeparator();	popup = new QPopupMenu;	popup->insertItem( "Help", this, SLOT( showHelp() ) );	popup->insertItem( tr("About kphone"), this, SLOT( showAboutKPhone() ) );	menuBar()->insertItem( "&Help", popup );	if( registrations->getUseStun() ) {		sessionC->setStunSrv( registrations->getStunSrv() );		client->sendStunRequest( registrations->getStunSrv() );		QTimer *stun_timer = new QTimer( this );		connect( stun_timer, SIGNAL( timeout() ), this, SLOT( stun_timerTick() ) );		p = KStatics::dBase + getUserPrefix() + "/STUN/RequestPeriod";		int timeout = settings.readNumEntry( p , constStunRequestPeriod );		if( timeout > 0 ) {			stun_timer->start( timeout * 1100 );		}	}	haveRDSock = newRDialSocket();	timer = new QTimer( this );	connect( timer, SIGNAL( timeout() ), this, SLOT( timerTick() ) );	timer->start( 1,TRUE );	if(haveRDSock) {	    rdTimer = new QTimer( this );	    connect( rdTimer, SIGNAL( timeout() ), this, SLOT( rdTimerTick() ) );	    rdTimer->start( 5555,TRUE );	}	resize( 160, 250 );}KPhone::~KPhone( void ){}void KPhone::timerTick( void ){	if (rdLoop == 0) rdLoop=1;	client->doSelect( false );	view->info();	if (rdLoop == 2) rdTimer->start( 5555,TRUE );	rdLoop=0;	timer->start( 1,TRUE );	}void KPhone::rdTimerTick( void ){	if (rdLoop == 0) {		 checkRDialSocket();		 rdTimer->start( 5555,TRUE );	} else rdLoop = 2;	}void KPhone::stun_timerTick( void ) {	if(sessionC->isStun()) {		client->sendStunRequest();	} else {		client->noMoreStun();	}}void KPhone::showUsers( void ){}QString KPhone::getUserPrefix( void ){return userPrefix;}void KPhone::showUserInfo( void ){}void KPhone::showAudioPreferences( void ){	if( !audiocontrol ) {		audiocontrol = new AudioControl( sessionC, this, userPrefix); // getUserPrefix() );	}	audiocontrol->show();}void KPhone::showVideoPreferences( void ){	if( !videocontrol ) {		videocontrol = new VideoControl( sessionC, this, getUserPrefix() );	}	videocontrol->show();}void KPhone::showExtPreferences1( void ){	if( !extcontrol1 ) {		extcontrol1 = new ExtControl( 1, sessionC, this, getUserPrefix() );	}	extcontrol1->show();}void KPhone::showExtPreferences2( void ){	if( !extcontrol2 ) {		extcontrol2 = new ExtControl( 2, sessionC, this, getUserPrefix() );	}	extcontrol2->show();}void KPhone::showExtPreferences3( void ){	if( !extcontrol3 ) {		extcontrol3 = new ExtControl(3, sessionC, this, getUserPrefix() );	}

⌨️ 快捷键说明

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