📄 kcallwidget.cpp
字号:
label.setNum( count ); label = p + "/Missed" + label; s = settings.readEntry( label, "" ); while( !s.isEmpty() ) { settings.writeEntry( label, ""); label.setNum( ++count ); label = p + "/Missed" + label; s = settings.readEntry( label, "" ); } count = 0; label.setNum( count ); label = p + "/Received" + label; s = settings.readEntry( label, "" ); while( !s.isEmpty() ) { settings.writeEntry( label, ""); label.setNum( ++count ); label = p + "/Received" + label; s = settings.readEntry( label, "" ); } count = 0; label.setNum( count ); label = p + "/Dialled" + label; s = settings.readEntry( label, "" ); while( !s.isEmpty() ) { settings.writeEntry( label, ""); label.setNum( ++count ); label = p + "/Dialled" + label; s = settings.readEntry( label, "" ); } int i = 0; int last = receivedCalls.count(); if ( last > 30 ) { first = receivedCalls.at( last - 30 ); } else { first = receivedCalls.first(); } for ( c = first; c != 0; c = receivedCalls.next() ) { label.setNum( i++ ); label = p + "/Received" + label; t = c->getDateTime().time(); d = c->getDateTime().date(); ss = s1.setNum( d.year() ) + "." + s2.setNum( d.month() ) + "." + s3.setNum( d.day() ) + "-" + t.toString(); settings.writeEntry( label, ss + " [" + c->getContact() + "]"); } i = 0; last = missedCalls.count(); if ( last > 30 ) { first = missedCalls.at( last - 30 ); } else { first = missedCalls.first(); } for ( c = first; c != 0; c = missedCalls.next() ) { label.setNum( i++ ); label = p + "/Missed" + label; t = c->getDateTime().time(); d = c->getDateTime().date(); ss = s1.setNum( d.year() ) + "." + s2.setNum( d.month() ) + "." + s3.setNum( d.day() ) + "-" + t.toString(); settings.writeEntry( label, ss + "[" + c->getContact() + "]"); } i = 0; last = dialledCalls.count(); if ( last > 30 ) { first = dialledCalls.at( last - 30 ); } else { first = dialledCalls.first(); } for ( c = first; c != 0; c = dialledCalls.next() ) { label.setNum( i++ ); label = p + "/Dialled" + label; t = c->getDateTime().time(); d = c->getDateTime().date(); ss = s1.setNum( d.year() ) + "." + s2.setNum( d.month() ) + "." + s3.setNum( d.day() ) + "-" + t.toString(); settings.writeEntry( label, ss + "[" + c->getContact() + "]"); }}void KCallWidget::hideCall( void ){ if( curstate == PreDial ) { if(call) { delete call; call = 0; } hided = true; } hide(); }QString KCallWidget::getUserPrefix( void ) { return ((KPhone *)parentWidget()->parentWidget())->getUserPrefix();}void KCallWidget::MyIdentity(void) { QSettings settings; int i,j; QString p = KStatics::dBase + getUserPrefix() + "Registration/SipUri"; QString s = settings.readEntry( p, "" ); QString si; i=s.find("<sip:"); j=s.find(">"); thatsMe = s.mid(i+1,j-i-1);}bool KCallWidget::cmpUri(QString uri1, QString uri2) {int i,j,l;i = uri1.find("@");if (i<0) return true;j = uri1.find(";");if(j>0) l=j; else l = uri1.length();QString user1 = uri1.mid(4,i-4); QString host1 = uri1.mid(i+1, l-i-1);i = uri2.find("@");j = uri2.find(";");if(j>0) l=j; else l = uri2.length();QString user2 = uri2.mid(4,i-4);QString host2 = uri2.mid(i+1, l-i-1); if (user1 == user2) { if (cmpHostDot(host1,host2)) { return true; } else { return false; } } else { return false; }}bool KCallWidget::cmpHostDot(QString host1, QString host2) { struct addrinfo hints, *res1,*res2; int errcode,cmp; char addrstr1[100],addrstr2[100]; void *ptr1, *ptr2; time_t begin, end; double gaidiff; if(KStatics::noLine >=1 ) { if(debug >= 2) printf("===== KCallWidget::cmpHostDot no getaddrinfo\n"); return false; } memset (&hints, 0, sizeof (hints)); time(&begin); errcode = getaddrinfo (host1.latin1(), NULL, &hints, &res1); time(&end); gaidiff=difftime(end,begin); if (gaidiff > 1.50E1) { //printf (" too big \n"); KStatics::noLine=1; } if (errcode != 0) { perror ("getaddrinfo"); return true; }errcode = getaddrinfo (host2.latin1(), NULL, &hints, &res2); if (errcode != 0) { perror ("getaddrinfo"); return true; } inet_ntop (res1->ai_family, res1->ai_addr->sa_data, addrstr1, 100); switch (res1->ai_family) { case AF_INET: ptr1 = &((struct sockaddr_in *) res1->ai_addr)->sin_addr; break; } inet_ntop (res2->ai_family, res2->ai_addr->sa_data, addrstr2, 100); switch (res2->ai_family) { case AF_INET: ptr2 = &((struct sockaddr_in *) res2->ai_addr)->sin_addr; break; } memset (&addrstr1,0, 100); memset (&addrstr2,0, 100); inet_ntop (res1->ai_family, ptr1, addrstr1, 100); inet_ntop (res2->ai_family, ptr2, addrstr2, 100); cmp=memcmp(addrstr1, addrstr2, 100); freeaddrinfo(res1); freeaddrinfo(res2); if(cmp==0) return true; else return false;}void KCallWidget::setHide( void ){ hided = true; hide();}void KCallWidget::hangupCall( void ){ if( !hangup->isEnabled() ) { return; } if(debug >= 2) printf( "=====KCallWidget hangupCall: curstate = %d memberstate = %d \n",curstate, member->getState()); preventSessionStart=true; //don't accept call, while hangup is in the queue stopRinging(); // Reject call if that's our current state if( curstate == Called ) { member->declineInvite(); } else if( call->getCallStatus() != SipCall::callDead ) { hangup->setEnabled( false ); if( ( member->getState() == SipCallMember::state_Connected) || ( member->getState() >= SipCallMember::state_Refer ) ) { member->requestDisconnect(); } else { member->cancelTransaction(); } } curstate=Releasing; //we begin to release the session detachFromCall( call ); // stop audio and external resources if any if(call) call->setHoldCall(SipCall::preCall); //having no resources setHide(); return;}void KCallWidget::detachFromCall( SipCall *lcall ){ if(debug >= 2) printf("=====KCallWidget: detachFromCall %d ",myNumber); int locPid = 0; if( lcall ) { locPid = lcall->getCurPid(); } if( locPid ) { if(debug >= 2) printf (" kill Pid %d", locPid); kill( locPid, SIGKILL ); lcall->setCurPid(0); } if(dspe) { if(debug >= 2) printf (" stop early media"); delete dspe; dspe=0; } if(audio) { if(debug >= 2) printf (" stop sending audio"); audio->stopSendingAudio(myNumber); audio = 0; } if (KWsocket != 0) { if(debug >= 2) printf (" delete KWsocket"); delete KWsocket; KWsocket=0; } if(debug >= 2) printf("\n");}void KCallWidget::forceDisconnect( void ){ curstate=Releasing; //we begin to release the session if(sdpS) { delete sdpS; sdpS=0; } if(debug >= 2) printf( "=====KCallWidget: Starting force disconnect... \n" ); preventSessionStart=true; //don't accept call, while hangup is in the queue detachFromCall(call); if(call) call->setHoldCall(SipCall::preCall); //having no resources if( call ) delete call; call=0; callDeleted(); stopRinging(); //a running notiTimer interfers with short refer! if (notiTimer->isActive()) notiTimer->stop(); setHide(); informPhoneView(UPDATEWLIST,myNumber);}void KCallWidget::doPayload( int load ){ if(preventSessionStart) { preventSessionStart=false; return; //do exactly what the flag tells you } QSettings xsettings; QString xSW; QString str1; QString xSP; QString xSWmod = xSW; QString xSPmod = xSP; QString xpCodec; // That's a nasty trick, to protect us from illicit 200OK from Xten if(isForceHold()) { load = (int)SipCall::putMeOnHold; } switch(load){ case (int)SipCall::extCall1: case (int)SipCall::extCall2: case (int)SipCall::extCall3: case (int)SipCall::extCall4: holdbutton->setText( "Hold" ); xSP = sessionC->forkSP(load); xSW = sessionC->forkSW(load); xSWmod = xSW; xSPmod = xSP; if( xSWmod.contains( "/" ) ) { xSWmod = xSWmod.mid( xSWmod.findRev( '/' ) + 1 ); } xSPmod.replace( "\n" , ""); if(xSPmod.contains("%A")) { QString xSWAdr = sdpS->getExtHost(); xSWAdr.replace( "\n" , ""); xSPmod.replace( "%A" , xSWAdr); } if(xSPmod.contains("%P")) { QString xSWPp = sdpS->getExtPort(); xSWPp.replace( "\n" , ""); xSPmod.replace( "%P" , xSWPp); } if(xSPmod.contains("%O")) { QString xSWPort = sdpS->getExtHomePort(); xSWPort.replace( "\n" , ""); xSPmod.replace( "%O" , xSWPort); } if(xSPmod.contains("%I")) { xSPmod.replace( "%I" , dirFlag); } if(xSPmod.contains("%D")) { xSPmod.replace( "%D" , getUserPrefix() + " " + dirFlag + " " + call->getCallId() ); } if(xSPmod.contains("%M")) { xSPmod.replace( "%M" , thatsMe); } if(xSPmod.contains("%C")) { xSPmod.replace( "%C" , member->getUri().uri().latin1()); } if(xSPmod.contains("%L")) { QString my = KStatics::myIP; my.replace("[",""); my.replace("]",""); xSPmod.replace( "%L" , my); } if(xSPmod.contains("%T")) { xSPmod.replace( "%T" , QString::number(sessionC->useL4((int)call->getCallType()))); } if(xSPmod.contains("%R")) { if(referTo == "") { if(referedNr!=0) { referTo = member->getUri().uri().latin1(); } else { referTo = thatsMe; } } xSPmod.replace( "%R" , referTo.latin1()); } break; case (int)SipCall::StandardCall: if(debug >= 2) printf("\n=====KCallWidget: doPayload Audio\n" ); audio->audioIn(sdpS,myNumber); holdbutton->setText( "Hold" ); call->setHoldCall(SipCall::callActive); if(!call->getNoHold()) { call->setHoldMaster(false); // Holdmaster blocks subsequent INVITEs } return; case (int)SipCall::auviCall: if(debug >= 2) printf("\n=====KCallWidget: doPayload Audio\n" ); audio->audioIn(sdpS,myNumber); holdbutton->setText( "Hold" ); call->setHoldCall(SipCall::callActive); if(!call->getNoHold()) { call->setHoldMaster(false); // Holdmaster blocks subsequent INVITEs } case (int)SipCall::videoCall: if(debug >= 2) printf("\n=====KCallWidget: doPayload Video\n" ); xSW = sessionC->getVideoSW(); xSP = ""; xSWmod = xSW; xSPmod = xSP; xpCodec = sdpS->getVidPrefCodec().lower(); if(xpCodec.contains("h263-1998")) xpCodec = "h263+";// Xten if( xSWmod.contains( "/" ) ) { xSWmod = xSWmod.mid( xSWmod.findRev( '/' ) + 1 ); } xSPmod = sdpS->getExtHost() + "/" + sdpS->getExtPort() + "/" + xpCodec + "/16/" + sdpS->getExtHomePort() ; break; case (int)SipCall::putMeOnHold: if(debug >= 2) printf("\n=====KCallWidget: doPayload On Hold\n" ); if(call->getNoHold()){ forceDisconnect(); return; } call->setHoldCall(SipCall::callHold); if(call->getHoldMaster()) { holdbutton->setText( "Retrieve" ); } else { holdbutton->setText( "Held" ); } if (KWsocket != 0) { if(debug >= 2) printf (" delete KWsocket\n"); delete KWsocket; KWsocket=0; } detachFromCall(call); return; } // common part for all external Payloads call->setHoldCall(SipCall::callActive); if(!call->getNoHold()) { call->setHoldMaster(false); // Holdmaster blocks subsequent INVITEs } if (KWsocket != 0) { if(debug >= 2) printf (" delete KWsocket\n"); delete KWsocket; KWsocket=0; } int locPid; if(debug >= 2) printf ("\n=====KCallWidget: doPayload We are forking (%s)(%s) (%s) \n", xSW.latin1(), xSWmod.latin1(), xSPmod.latin1()); locPid = fork(); call->setCurPid(locPid); if( !locPid ) { execlp( xSW.latin1(), xSWmod.latin1(), xSPmod.latin1(),(char*)NULL ); exit(1); } }void KCallWidget::sendDTMFSeq(void) { if( (dirFlag=="o") && call->withAudioCall()) { audio->startDTMFSeq(dtmfStr,dtmfSize); } dtmfSize = 0;}void KCallWidget::getExtSocket(int callt) { int minP=0; int maxP=0; maxP= sessionC->getMaxApplPort(); minP= sessionC->getMinApplPort(); if(dirFlag == "o") minP+=2; KWsocket = new UDPMessageSocket(); KWsocket->listenOnEvenPort(minP,maxP); //Max und MinPort!!! }void KCallWidget::setCS (QString in) { curstat->setText(in); myCS=in; }void KCallWidget::setAS (QString in) { curaudiostat->setText("in"); myAS=in; }void KCallWidget::setLT (QString in) { curload->setText(in); myLT=in; }int KCallWidget::getStunPort(void) { int portnum=0; SipUri stun; stun = SipUri( sessionC->getStunSrv() ); if ( KWsocket->sendStunRequest( stun.getHostname(), stun.getPortNumber() ) == 0) { portnum = KWsocket->receiveStunResponse(); } if(debug >= 2) printf ("\n=====KCallWidget::getStunport port=%d \n", portnum); return portnum;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -