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

📄 kphoneview.cpp

📁 kphone-4.2,SHELL协议的VOIP电话
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	QPtrList<IncomingCall> m;	PhoneBook *phoneBook = new PhoneBook(file, this, getUserPrefix() +		tr("Phone Book"), r, m, rejectedContactList );	phoneBook->exec();	rejectedContactList = phoneBook->getRejectedContactsList();	saveRejectContactList();	updateContacts( file );}void KPhoneView::addContactToPhoneBook( SipCallMember *member ){	QSettings settings;	QString p = "/kphone/" + getUserPrefix() + "/local/";	QString file = settings.readEntry( p + "/PhoneBook", "" );	if( file.isEmpty() ) {		if( getUserPrefix().isEmpty() ) {			file = QDir::homeDirPath() + "/.kphone-phonebook.xml";		} else {			file = QDir::homeDirPath() + "/.kphone" +				getUserPrefix() + "phonebook.xml";		}	}	QPtrList<IncomingCall> r;	QPtrList<IncomingCall> m;	QStringList s;	PhoneBook *phoneBook = new PhoneBook(		file, this, getUserPrefix() + tr("Phone Book"), r, m, s );	phoneBook->addContact( member );	updateContacts( file );}void KPhoneView::updateSubscribes( void ){	QSettings settings;	QString p = "/kphone/" + getUserPrefix() + "/local";	QString file = settings.readEntry( p + "/PhoneBook", "" );	if( file.isEmpty() ) {		if( getUserPrefix().isEmpty() ) {			file = QDir::homeDirPath() + "/.kphone-phonebook.xml";		} else {			file = QDir::homeDirPath() + "/.kphone" +				getUserPrefix() + "phonebook.xml";		}	}	updateContacts( file );}void KPhoneView::updateContacts( QString file ){	QString uristr;	SipCallMember *member;	SipCall *newcall;	QFile xmlFile( file );	QXmlInputSource source( xmlFile );	QXmlSimpleReader reader;	ContactParser parser;	reader.setContentHandler( &parser );	reader.parse( source );	SipCallIterator it( client->getCallList() );	QStringList::Iterator itStr;	QStringList sl = parser.getListContacts();	bool find;	it.toFirst();	while ( it.current() ) {		find = true;		if( it.current()->getCallType() == SipCall::outSubscribeCall ) {			find = false;			for ( itStr = sl.begin(); itStr != sl.end(); ++itStr ) {				QString subject = QString(*itStr);				if( subject.contains( ";" ) ) {					subject = subject.left( subject.find( ";" ) );				}				if( subject == it.current()->getSubject() ) {					find = true;					break;				}			}			if( !find ) {				disconnect( it.current(), 0, 0, 0 );				delete it.current();			}		}		if( find ) {			++it;		}	}	for ( QStringList::Iterator itStr = sl.begin(); itStr != sl.end(); ++itStr ) {		uristr = QString(*itStr);		if( !uristr.isEmpty() ) {			find = false;			QString subject = QString(*itStr);			QString contactStr = "";			if( subject.contains( ";" ) ) {				contactStr = subject.mid( subject.find( ";" ) + 1 );				subject = subject.left( subject.find( ";" ) );			}			for ( it.toFirst(); it.current(); ++it ) {				if( subject == it.current()->getSubject() &&				    it.current()->getCallStatus() != SipCall::callDead ) {					if( !contactStr.isEmpty() ) {						it.current()->setContactStr( contactStr );					} else {						it.current()->setContactStr( subject );					}					find = true;					break;				}			}			if( !find ) {				newcall = new SipCall( user, QString::null, SipCall::outSubscribeCall );				newcall->setSubject( uristr );				SipUri remoteuri( uristr );				member = new SipCallMember( newcall, remoteuri );				connect( member, SIGNAL( statusUpdated( SipCallMember * ) ),					clist, SLOT( auditList() ) );				connect( member, SIGNAL( statusUpdated( SipCallMember * ) ),					sipauthentication, SLOT( authRequest( SipCallMember * ) ) );				member->requestSubscribe( subscribeExpiresTime );				if( !contactStr.isEmpty() ) {					newcall->setContactStr( contactStr );				} else {					newcall->setContactStr( subject );				}			}		}	}	clist->auditList();}void KPhoneView::localStatusUpdate( void ){	QString subject;	QIconSet icon;	SipCallIterator it( client->getCallList() );	if( reg == 0 ) {		return;	}	if( setSubscribeOffline && reg->getRegisterState() == SipRegister::Connected ) {		setSubscribeOffline = false;		isOnline = false;		QIconSet icon;		icon.setPixmap(SHARE_DIR "/icons/offline.png", QIconSet::Automatic );		buttonOffOnline->setIconSet( icon );		buttonUpdate->setEnabled( false );		buttonOffOnline->setEnabled( false );		it.toFirst();		for( it.toFirst(); it.current(); ++it ) {			if( it.current()->getCallType() == SipCall::outSubscribeCall ) {				if( it.current()->getCallStatus() == SipCall::callInProgress ) {					SipCallMember *member = it.current()->getMemberList().toFirst();					if( member ) {						member->requestClearSubscribe();					}				}			}		}	} else {		if( reg->getRegisterState() == SipRegister::NotConnected ) {			isOnline = false;			QIconSet icon1;			icon1.setPixmap(SHARE_DIR "/icons/offline.png", QIconSet::Automatic );			buttonOffOnline->setIconSet( icon1 );			buttonUpdate->setEnabled( false );			buttonOffOnline->setEnabled( false );		} else if( reg->getRegisterState() == SipRegister::Connected ) {			if( buttonSetOffline ) {				buttonOffOnline->setEnabled( true );			} else {				isOnline = true;				QIconSet icon2;				icon2.setPixmap(SHARE_DIR "/icons/online.png", QIconSet::Automatic );				buttonOffOnline->setIconSet( icon2 );				buttonUpdate->setEnabled( true );				buttonOffOnline->setEnabled( true );				it.toFirst();				for( it.toFirst(); it.current(); ++it ) {					if( it.current()->getCallType() == SipCall::outSubscribeCall ) {						if( it.current()->getCallStatus() != SipCall::callDead ) {							SipCallMember *member = it.current()->getMemberList().toFirst();							if( member ) {								member->requestSubscribe( subscribeExpiresTime );							}						}					}				}			}		}	}	emit ( stateChanged() );}void KPhoneView::buttonOffOnlineClicked( void ){	if( isOnline ) {		buttonSetOffline = true;		isOnline = false;		buttonUpdate->setEnabled( false );		stateComboBox->setEnabled( false );		QIconSet icon1;		icon1.setPixmap(SHARE_DIR "/icons/offline.png", QIconSet::Automatic );		buttonOffOnline->setIconSet( icon1 );		stateUpdated( OFFLINE );	} else {		buttonSetOffline = false;		isOnline = true;		buttonUpdate->setEnabled( true );		stateComboBox->setEnabled( true );		QIconSet icon2;		icon2.setPixmap(SHARE_DIR "/icons/online.png", QIconSet::Automatic );		buttonOffOnline->setIconSet( icon2 );		stateUpdated( ONLINE );	}}void KPhoneView::buttonUpdateClicked( void ){	if( isOnline ) {		stateUpdated( ONLINE );	}}void KPhoneView::stateUpdated( int id ){	QString subject;	if( id == OFFLINE ) {		isOnline = false;		buttonUpdate->setEnabled( false );		QIconSet icon;		icon.setPixmap(SHARE_DIR "/icons/offline.png", QIconSet::Automatic );		buttonOffOnline->setIconSet( icon );	}	SipCallIterator it( client->getCallList() );	it.toFirst();	for( it.toFirst(); it.current(); ++it ) {		if( it.current()->getCallType() == SipCall::inSubscribeCall ) {			if( it.current()->getCallStatus() == SipCall::callInProgress ) {				SipCallMember *member = it.current()->getMemberList().toFirst();				if( member ) {					sendNotify( id, member );				}			} else {				delete it.current();			}		}	}	emit( stateChanged() );	}QString KPhoneView::stateText( QString text ){	QString state;	if( text == tr("Online") ) {		state = "online";	} else if( text == tr("Busy") ) {		state = "busy";	} else if( text == tr("Be Right Back") ) {		state = "berightback";	} else if( text == tr("Away") ) {		state = "away";	} else if( text == tr("On The Phone") ) {		state = "onthephone";	} else if( text == tr("Out To Lunch") ) {		state = "outtolunch";	} else {		state = text;	}	return state;}void KPhoneView::sendNotify( int id, SipCallMember *member ){	QString s;	QString tmp;	s =  "<?xml version=\"1.0\"?>\n";	s += "<!DOCTYPE presence\n";	s += "PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n";	s += "<presence>\n";	s += "<presentity uri=\"";	s += member->getUri().reqUri();	s += ";method=SUBSCRIBE\"/>\n";	s += "<atom id=\"";	s += tmp.setNum( atomId++ ).latin1();	s += "\">\n";	s += "<address uri=\"";	s += client->getContactUri().reqUri();	s += ";user=ip\" priority=\"0,800000\">\n";	s += "<status status=\"open\"/>\n";	if( id == ONLINE ) {		if( stateComboBox->currentText().isEmpty() ) {			s += "<msnsubstatus substatus=\"online\"/>\n";		} else {			s += "<msnsubstatus substatus=\"";			s += stateText( stateComboBox->currentText() );			s += "\" />\n";		}	} else {  		s += "<msnsubstatus substatus=\"\"/>\n";	}	s += "</address>\n";	s += "</atom>\n";	s += "</presence>\n";	if( stateComboBox->currentText().lower() == "busy" ) {		client->setBusy( true );	} else {		client->setBusy( false );	}	if( member != 0 ) {		if( id == OFFLINE ) {			member->requestClearNotify( s.latin1(), MimeContentType( "application/xpidf+xml" ) );		} else {			if( !buttonSetOffline ) {				member->requestNotify( s.latin1(), MimeContentType( "application/xpidf+xml" ) );			}		}	}}void KPhoneView::redirectCall( const SipUri &calluri, const QString &subject ){	SipCall *newcall = new SipCall( user );	newcall->setSubject( subject );	callAudio = new CallAudio( this );	callAudio->readAudioSettings();	callAudio->readVideoSettings();	KCallWidget *widget = new KCallWidget( sipauthentication, callAudio, newcall, this );	cwList.append( widget );	widget->pleaseDial( calluri );	connect( widget, SIGNAL( redirectCall( const SipUri &, const QString & ) ),		this, SLOT( redirectCall( const SipUri &, const QString & ) ) );	widget->show();}KCallWidget *KPhoneView::DoCall( QString num, SipCall::CallType ctype ){	updateWidgetList();	if( !buttonSipUri->text().compare( tr("Set Identity") ) ){		QMessageBox::information( this, tr("KPhone"), tr("Set First Identity.") );		return NULL;	}	SipCall *newcall = new SipCall( user, QString::null, ctype );	QString subject;	subject.sprintf( user->getUri().uri() );	newcall->setSubject( subject );	callAudio = new CallAudio( this );	callAudio->readAudioSettings();	callAudio->readVideoSettings();	KCallWidget *widget = new KCallWidget( sipauthentication, callAudio, newcall, this );	cwList.append( widget );	widget->setRemote( num );	if( !num.isEmpty() ) {		widget->clickDial();	}	connect( widget, SIGNAL( redirectCall( const SipUri &, const QString & ) ),		this, SLOT( redirectCall( const SipUri &, const QString & ) ) );	widget->show();		return widget;}void KPhoneView::makeNewCall( void ){	if (DoCall(lineeditCall->text(), SipCall::StandardCall))		lineeditCall->setText("");}void KPhoneView::makeVideoCall( void ){	if (DoCall(lineeditCall->text(), SipCall::videoCall))		lineeditCall->setText("");}void KPhoneView::updateIdentity( SipUser *newUser, SipRegister *newReg ){	if( newReg != 0 ) {		if( reg != 0 ) {			disconnect( reg, SIGNAL( statusUpdated() ), this, SLOT( localStatusUpdate() ) );		}		reg = newReg;		connect( reg, SIGNAL( statusUpdated() ), this, SLOT( localStatusUpdate() ) );		localStatusUpdate();	}	buttonSipUri->setText( newUser->getUri().uri() );	user = newUser;}void KPhoneView::busyToggled( bool onoff ){	client->setBusy( onoff );}void KPhoneView::showIdentities( void ){	identitiesDialog->showIdentity();}void KPhoneView::identities( KSipRegistrations *i ){	identitiesDialog = i;}void KPhoneView::setContactsOffline( void ){	stateUpdated( KPhoneView::OFFLINE );	setSubscribeOffline = true;	localStatusUpdate();}void KPhoneView::setContactsOnline( void ){	stateUpdated( KPhoneView::ONLINE );}	void setStunSrv( QString );	bool getUseStun();	QString getStunStv();void KPhoneView::setStunSrv( QString stunuri ){	if( !stunuri.isEmpty() ) {		useStunProxy = true;		stunProxyUri = stunuri;	}}bool KPhoneView::useStunSrv( void ){	return useStunProxy;}QString KPhoneView::getStunSrv( void ){	return stunProxyUri;}void KPhoneView::kphoneQuit( void ){	KCallWidget *widget;	for( widget = cwList.first(); widget != 0; widget = cwList.next() ) {		if( widget->isHided() ) {			cwList.remove( widget );		} else {			widget->clickHangup();		}	}	setContactsOffline();	identitiesDialog->unregAllRegistration();}QString KPhoneView::getUserPrefix( void ){	return ((KPhone *)parentWidget())->getUserPrefix();}void KPhoneView::saveRejectContactList( void ){	QSettings settings;	QString p = "/kphone/" + getUserPrefix() + "/presence/";	QString label;	int count = 0;	label.setNum( count );	label = p + "/Rejected" + label;	QString s = settings.readEntry( label, "" );	while( !s.isEmpty() ) {		settings.writeEntry( label, "");		label.setNum( ++count );		label = p + "/Rejected" + label;		s = settings.readEntry( label, "" );	}	count = 0;	for ( QStringList::Iterator it = rejectedContactList.begin(); it != rejectedContactList.end(); ++it ) {		label.setNum( count++ );		label = p + "/Rejected" + label;		settings.writeEntry( label, QString(*it) );	}}void KPhoneView::updateWidgetList( void ){	KCallWidget *widget;	for( widget = cwList.first(); widget != 0; widget = cwList.next() ) {		if( widget->isHided() ) {			cwList.remove( widget );		}	}}bool KPhoneView::getState( void ){	return isOnline;}

⌨️ 快捷键说明

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