diff options
| author | 2016-04-29 23:57:30 +0100 | |
|---|---|---|
| committer | 2016-04-29 23:57:48 +0100 | |
| commit | 690dd7a33ddc90678367d73adf313533536e10f2 (patch) | |
| tree | 2276fe7c384ebbc222b40a19c536d5c3c5606ce8 /src/modules/dcc/DccVideoWindow.cpp | |
| parent | Add config for clang-format. (diff) | |
| download | KVIrc-690dd7a33ddc90678367d73adf313533536e10f2.tar.gz KVIrc-690dd7a33ddc90678367d73adf313533536e10f2.tar.bz2 KVIrc-690dd7a33ddc90678367d73adf313533536e10f2.zip | |
Apply clang-format
Diffstat (limited to 'src/modules/dcc/DccVideoWindow.cpp')
| -rw-r--r-- | src/modules/dcc/DccVideoWindow.cpp | 450 |
1 files changed, 246 insertions, 204 deletions
diff --git a/src/modules/dcc/DccVideoWindow.cpp b/src/modules/dcc/DccVideoWindow.cpp index 546043804..3cedf19af 100644 --- a/src/modules/dcc/DccVideoWindow.cpp +++ b/src/modules/dcc/DccVideoWindow.cpp @@ -48,11 +48,11 @@ #include <QBuffer> #ifdef COMPILE_CRYPT_SUPPORT - #include "KviCryptController.h" +#include "KviCryptController.h" #endif #ifdef COMPILE_SSL_SUPPORT - #include "KviSSLMaster.h" +#include "KviSSLMaster.h" #endif #include <sys/ioctl.h> @@ -63,10 +63,10 @@ extern DccBroker * g_pDccBroker; bool kvi_dcc_video_is_valid_codec(const char * codecName) { - if(kvi_strEqualCI("sjpeg",codecName)) + if(kvi_strEqualCI("sjpeg", codecName)) return true; #ifndef COMPILE_DISABLE_OGG_THEORA - if(kvi_strEqualCI("theora",codecName)) + if(kvi_strEqualCI("theora", codecName)) return true; #endif return false; @@ -76,15 +76,14 @@ static DccVideoCodec * kvi_dcc_video_get_codec(const char * codecName) { Q_UNUSED(codecName); #ifndef COMPILE_DISABLE_OGG_THEORA - if(kvi_strEqualCI("theora",codecName)) + if(kvi_strEqualCI("theora", codecName)) return new DccVideoTheoraCodec(); #endif return new DccVideoSJpegCodec(); } - -DccVideoThread::DccVideoThread(KviWindow * wnd,kvi_socket_t fd,KviDccVideoThreadOptions * opt) -: DccThread(wnd,fd) +DccVideoThread::DccVideoThread(KviWindow * wnd, kvi_socket_t fd, KviDccVideoThreadOptions * opt) + : DccThread(wnd, fd) { m_pOpt = opt; m_bPlaying = false; @@ -104,25 +103,28 @@ DccVideoThread::~DccVideoThread() bool DccVideoThread::readWriteStep() { -// qDebug("DccVideoThread::readWriteStep()"); + // qDebug("DccVideoThread::readWriteStep()"); // Socket management bool bCanRead; bool bCanWrite; - if(kvi_select(m_fd,&bCanRead,&bCanWrite)) + if(kvi_select(m_fd, &bCanRead, &bCanWrite)) { while(bCanRead) { unsigned int actualSize = m_inFrameBuffer.size(); m_inFrameBuffer.resize(actualSize + 16384); - int readLen = kvi_socket_recv(m_fd,(void *)(m_inFrameBuffer.data() + actualSize),16384); + int readLen = kvi_socket_recv(m_fd, (void *)(m_inFrameBuffer.data() + actualSize), 16384); if(readLen > 0) { - if(readLen < 16384)m_inFrameBuffer.resize(actualSize + readLen); - m_pOpt->pCodec->decode(&m_inFrameBuffer,&m_videoInSignalBuffer,&m_textInSignalBuffer); - } else { - bCanRead=false; -// if(!handleInvalidSocketRead(readLen))return false; + if(readLen < 16384) + m_inFrameBuffer.resize(actualSize + readLen); + m_pOpt->pCodec->decode(&m_inFrameBuffer, &m_videoInSignalBuffer, &m_textInSignalBuffer); + } + else + { + bCanRead = false; + // if(!handleInvalidSocketRead(readLen))return false; m_inFrameBuffer.resize(actualSize); } } @@ -132,12 +134,15 @@ bool DccVideoThread::readWriteStep() // Have somethihg to write ? if(m_outFrameBuffer.size() > 0) { - int written = kvi_socket_send(m_fd,m_outFrameBuffer.data(),m_outFrameBuffer.size()); + int written = kvi_socket_send(m_fd, m_outFrameBuffer.data(), m_outFrameBuffer.size()); if(written > 0) { m_outFrameBuffer.remove(written); - } else { - if(!handleInvalidSocketRead(written))return false; + } + else + { + if(!handleInvalidSocketRead(written)) + return false; } } } @@ -147,7 +152,7 @@ bool DccVideoThread::readWriteStep() bool DccVideoThread::videoStep() { -// qDebug("DccVideoThread::videoStep()"); + // qDebug("DccVideoThread::videoStep()"); // Are we playing ? if(m_bPlaying) @@ -164,17 +169,17 @@ bool DccVideoThread::videoStep() // Are we recording ? if(m_bRecording) { - QImage * pImage = ((DccVideoWindow*)parent())->m_pCameraImage; + QImage * pImage = ((DccVideoWindow *)parent())->m_pCameraImage; if(pImage) { // grab the frame - m_videoOutSignalBuffer.append((const unsigned char*) pImage->bits(), pImage->byteCount()); - m_pOpt->pCodec->encodeVideo(&m_videoOutSignalBuffer,&m_outFrameBuffer); + m_videoOutSignalBuffer.append((const unsigned char *)pImage->bits(), pImage->byteCount()); + m_pOpt->pCodec->encodeVideo(&m_videoOutSignalBuffer, &m_outFrameBuffer); // tell our parent to prepare a new frame KviThreadDataEvent<int> * e = new KviThreadDataEvent<int>(KVI_DCC_THREAD_EVENT_ACTION); e->setData(new int(KVI_DCC_VIDEO_THREAD_ACTION_GRAB_FRAME)); - postEvent(DccThread::parent(),e); + postEvent(DccThread::parent(), e); } } return true; @@ -182,7 +187,7 @@ bool DccVideoThread::videoStep() bool DccVideoThread::textStep() { -// qDebug("DccVideoThread::textStep()"); + // qDebug("DccVideoThread::textStep()"); // Are we playing ? if(m_bPlaying) { @@ -190,9 +195,9 @@ bool DccVideoThread::textStep() { KviDccThreadIncomingData data; data.iLen = m_textInSignalBuffer.size(); - data.buffer = (char*) KviMemory::allocate(data.iLen); + data.buffer = (char *)KviMemory::allocate(data.iLen); memcpy(data.buffer, m_textInSignalBuffer.data(), data.iLen); - handleIncomingData(&data,false); + handleIncomingData(&data, false); m_textInSignalBuffer.clear(); } @@ -201,20 +206,20 @@ bool DccVideoThread::textStep() // Are we recording ? if(m_bRecording) { - if(((DccVideoWindow*)parent())->m_tmpTextDataOut.size()) + if(((DccVideoWindow *)parent())->m_tmpTextDataOut.size()) { - m_textOutSignalBuffer.append((const unsigned char*) ((DccVideoWindow*)parent())->m_tmpTextDataOut.constData(), ((DccVideoWindow*)parent())->m_tmpTextDataOut.size()); - ((DccVideoWindow*)parent())->m_tmpTextDataOut.clear(); + m_textOutSignalBuffer.append((const unsigned char *)((DccVideoWindow *)parent())->m_tmpTextDataOut.constData(), ((DccVideoWindow *)parent())->m_tmpTextDataOut.size()); + ((DccVideoWindow *)parent())->m_tmpTextDataOut.clear(); } if(m_textOutSignalBuffer.size()) - m_pOpt->pCodec->encodeText(&m_textOutSignalBuffer,&m_outFrameBuffer); + m_pOpt->pCodec->encodeText(&m_textOutSignalBuffer, &m_outFrameBuffer); } return true; } -bool DccVideoThread::handleIncomingData(KviDccThreadIncomingData * data,bool bCritical) +bool DccVideoThread::handleIncomingData(KviDccThreadIncomingData * data, bool bCritical) { //qDebug("DccVideoThread::handleIncomingData"); KVI_ASSERT(data->iLen); @@ -228,34 +233,39 @@ bool DccVideoThread::handleIncomingData(KviDccThreadIncomingData * data,bool bCr KviThreadDataEvent<KviCString> * e = new KviThreadDataEvent<KviCString>(KVI_DCC_THREAD_EVENT_DATA); // The left part is len chars long int len = aux - data->buffer; -// qDebug("LEN = %d, iLen = %d",len,data->iLen); -//#warning "DO IT BETTER (the \r cutting)" - KviCString * s = new KviCString(data->buffer,len); - if(s->lastCharIs('\r'))s->cutRight(1); + // qDebug("LEN = %d, iLen = %d",len,data->iLen); + //#warning "DO IT BETTER (the \r cutting)" + KviCString * s = new KviCString(data->buffer, len); + if(s->lastCharIs('\r')) + s->cutRight(1); e->setData(s); // but we cut also \n (or \0) ++aux; // so len += 1; --> new data->iLen -= len; data->iLen -= (len + 1); -// qDebug("iLen now = %d",data->iLen); + // qDebug("iLen now = %d",data->iLen); KVI_ASSERT(data->iLen >= 0); if(data->iLen > 0) { // memmove the remaining part to the beginning // aux points after \n or \0 - KviMemory::move(data->buffer,aux,data->iLen); - data->buffer = (char *)KviMemory::reallocate(data->buffer,data->iLen); + KviMemory::move(data->buffer, aux, data->iLen); + data->buffer = (char *)KviMemory::reallocate(data->buffer, data->iLen); end = data->buffer + data->iLen; aux = data->buffer; - } else { + } + else + { // no more data in the buffer KVI_ASSERT(data->iLen == 0); KviMemory::free(data->buffer); data->buffer = end = aux = 0; } - postEvent(parent(),e); - } else aux++; -// qDebug("PASSING CHAR %c",*aux); + postEvent(parent(), e); + } + else + aux++; + // qDebug("PASSING CHAR %c",*aux); } // now aux == end if(bCritical) @@ -265,13 +275,14 @@ bool DccVideoThread::handleIncomingData(KviDccThreadIncomingData * data,bool bCr { // in the last part there are no NULL and \n chars KviThreadDataEvent<KviCString> * e = new KviThreadDataEvent<KviCString>(KVI_DCC_THREAD_EVENT_DATA); - KviCString * s = new KviCString(data->buffer,data->iLen); - if(s->lastCharIs('\r'))s->cutRight(1); + KviCString * s = new KviCString(data->buffer, data->iLen); + if(s->lastCharIs('\r')) + s->cutRight(1); e->setData(s); data->iLen = 0; KviMemory::free(data->buffer); data->buffer = 0; - postEvent(parent(),e); + postEvent(parent(), e); } } return true; @@ -279,7 +290,7 @@ bool DccVideoThread::handleIncomingData(KviDccThreadIncomingData * data,bool bCr void DccVideoThread::restartRecording(int iDevice, int iInput, int) { - m_bRecording=false; + m_bRecording = false; /* if(!g_pVideoDevicePool) g_pVideoDevicePool = Kopete::AV::VideoDevicePool::self(); @@ -291,21 +302,22 @@ void DccVideoThread::restartRecording(int iDevice, int iInput, int) g_pVideoDevicePool->selectInput(iInput); g_pVideoDevicePool->startCapturing(); */ - m_bRecording=true; + m_bRecording = true; } void DccVideoThread::startRecording() { //qDebug("Start recording"); - if(m_bRecording)return; // already started + if(m_bRecording) + return; // already started //ensure capturing -// g_pVideoDevicePool->startCapturing(); + // g_pVideoDevicePool->startCapturing(); //qDebug("Posting event"); KviThreadDataEvent<int> * e = new KviThreadDataEvent<int>(KVI_DCC_THREAD_EVENT_ACTION); e->setData(new int(KVI_DCC_VIDEO_THREAD_ACTION_START_RECORDING)); - postEvent(DccThread::parent(),e); + postEvent(DccThread::parent(), e); m_bRecording = true; } @@ -313,11 +325,12 @@ void DccVideoThread::startRecording() void DccVideoThread::stopRecording() { //qDebug("Stop recording"); - if(!m_bRecording)return; // already stopped + if(!m_bRecording) + return; // already stopped KviThreadDataEvent<int> * e = new KviThreadDataEvent<int>(KVI_DCC_THREAD_EVENT_ACTION); e->setData(new int(KVI_DCC_VIDEO_THREAD_ACTION_STOP_RECORDING)); - postEvent(DccThread::parent(),e); + postEvent(DccThread::parent(), e); m_bRecording = false; } @@ -325,22 +338,24 @@ void DccVideoThread::stopRecording() void DccVideoThread::startPlaying() { //qDebug("Start playing"); - if(m_bPlaying)return; + if(m_bPlaying) + return; KviThreadDataEvent<int> * e = new KviThreadDataEvent<int>(KVI_DCC_THREAD_EVENT_ACTION); e->setData(new int(KVI_DCC_VIDEO_THREAD_ACTION_START_PLAYING)); - postEvent(DccThread::parent(),e); + postEvent(DccThread::parent(), e); m_bPlaying = true; } void DccVideoThread::stopPlaying() { //qDebug("Stop playing"); - if(!m_bPlaying)return; + if(!m_bPlaying) + return; KviThreadDataEvent<int> * e = new KviThreadDataEvent<int>(KVI_DCC_THREAD_EVENT_ACTION); e->setData(new int(KVI_DCC_VIDEO_THREAD_ACTION_STOP_PLAYING)); - postEvent(DccThread::parent(),e); + postEvent(DccThread::parent(), e); m_bPlaying = false; } @@ -356,36 +371,43 @@ void DccVideoThread::run() { delete e; goto exit_dcc; - } else if(e->id() == KVI_DCC_THREAD_EVENT_ACTION) + } + else if(e->id() == KVI_DCC_THREAD_EVENT_ACTION) { int * act = ((KviThreadDataEvent<int> *)e)->getData(); - if(*act)startRecording(); - else stopRecording(); + if(*act) + startRecording(); + else + stopRecording(); delete act; delete e; - } else { + } + else + { // Other events are senseless to us delete e; } } - if(!readWriteStep())goto exit_dcc; - if(!videoStep())goto exit_dcc; - if(!textStep())goto exit_dcc; + if(!readWriteStep()) + goto exit_dcc; + if(!videoStep()) + goto exit_dcc; + if(!textStep()) + goto exit_dcc; - usleep(FRAME_DURATION*1000); + usleep(FRAME_DURATION * 1000); //qDebug("in %d out %d in_sig %d out_sig %d", m_inFrameBuffer.size(), m_outFrameBuffer.size(), m_videoInSignalBuffer.size(), m_videoOutSignalBuffer.size()); } - exit_dcc: kvi_socket_close(m_fd); m_fd = KVI_INVALID_SOCKET; } -DccVideoWindow::DccVideoWindow(DccDescriptor * dcc,const char * name) -: DccWindow(KviWindow::DccVideo,name,dcc) +DccVideoWindow::DccVideoWindow(DccDescriptor * dcc, const char * name) + : DccWindow(KviWindow::DccVideo, name, dcc) { m_pDescriptor = dcc; m_pSlaveThread = 0; @@ -395,7 +417,7 @@ DccVideoWindow::DccVideoWindow(DccDescriptor * dcc,const char * name) m_pLabel = new KviThemedLabel(m_pButtonBox, this, "dcc_video_label"); m_pLabel->setText(name); - m_pButtonBox->setStretchFactor(m_pLabel,1); + m_pButtonBox->setStretchFactor(m_pLabel, 1); createTextEncodingButton(m_pButtonBox); @@ -404,7 +426,7 @@ DccVideoWindow::DccVideoWindow(DccDescriptor * dcc,const char * name) #endif // Central splitter - m_pSplitter = new KviTalSplitter(Qt::Horizontal,this); + m_pSplitter = new KviTalSplitter(Qt::Horizontal, this); m_pSplitter->setObjectName("dcc_video_splitter"); m_pSplitter->setChildrenCollapsible(false); @@ -412,9 +434,9 @@ DccVideoWindow::DccVideoWindow(DccDescriptor * dcc,const char * name) m_pLayout = new QGridLayout(m_pContainerWidget); m_pContainerWidget->setLayout(m_pLayout); - m_pIrcView = new KviIrcView(this,this); - connect(m_pIrcView,SIGNAL(rightClicked()),this,SLOT(textViewRightClicked())); - m_pInput = new KviInput(this); + m_pIrcView = new KviIrcView(this, this); + connect(m_pIrcView, SIGNAL(rightClicked()), this, SLOT(textViewRightClicked())); + m_pInput = new KviInput(this); //remote video m_pInVideoLabel = new QLabel(); @@ -427,7 +449,7 @@ DccVideoWindow::DccVideoWindow(DccDescriptor * dcc,const char * name) //local video QByteArray cameraDevice; - if (cameraDevice.isEmpty()) + if(cameraDevice.isEmpty()) m_pCamera = new QCamera; else m_pCamera = new QCamera(cameraDevice); @@ -445,39 +467,40 @@ DccVideoWindow::DccVideoWindow(DccDescriptor * dcc,const char * name) //local video input: config m_pVideoLabel[0] = new QLabel(); - m_pVideoLabel[0]->setText(__tr2qs_ctx("Video device:","dcc")); + m_pVideoLabel[0]->setText(__tr2qs_ctx("Video device:", "dcc")); m_pLayout->addWidget(m_pVideoLabel[0], 1, 2, 1, 1); m_pCDevices = new QComboBox(); m_pLayout->addWidget(m_pCDevices, 2, 2, 1, 1); m_pVideoLabel[1] = new QLabel(); - m_pVideoLabel[1]->setText(__tr2qs_ctx("Input:","dcc")); + m_pVideoLabel[1]->setText(__tr2qs_ctx("Input:", "dcc")); m_pLayout->addWidget(m_pVideoLabel[1], 3, 2, 1, 1); m_pCInputs = new QComboBox(); m_pLayout->addWidget(m_pCInputs, 4, 2, 1, 1); m_pVideoLabel[2] = new QLabel(); - m_pVideoLabel[2]->setText(__tr2qs_ctx("Standard:","dcc")); + m_pVideoLabel[2]->setText(__tr2qs_ctx("Standard:", "dcc")); m_pLayout->addWidget(m_pVideoLabel[2], 5, 2, 1, 1); m_pCStandards = new QComboBox(); m_pLayout->addWidget(m_pCStandards, 6, 2, 1, 1); m_pLayout->addWidget(m_pIrcView, 7, 0, 1, 3); - m_pLayout->setRowStretch(7,1); + m_pLayout->setRowStretch(7, 1); - if(KVI_OPTION_BOOL(KviOption_boolAutoLogDccChat))m_pIrcView->startLogging(); + if(KVI_OPTION_BOOL(KviOption_boolAutoLogDccChat)) + m_pIrcView->startLogging(); - connect(&m_Timer, SIGNAL(timeout()), this, SLOT(slotUpdateImage()) ); + connect(&m_Timer, SIGNAL(timeout()), this, SLOT(slotUpdateImage())); m_Timer.start(FRAME_DURATION); m_pMarshal = new DccMarshal(this); - connect(m_pMarshal,SIGNAL(error(KviError::Code)),this,SLOT(handleMarshalError(KviError::Code))); - connect(m_pMarshal,SIGNAL(connected()),this,SLOT(connected())); - connect(m_pMarshal,SIGNAL(inProgress()),this,SLOT(connectionInProgress())); + connect(m_pMarshal, SIGNAL(error(KviError::Code)), this, SLOT(handleMarshalError(KviError::Code))); + connect(m_pMarshal, SIGNAL(connected()), this, SLOT(connected())); + connect(m_pMarshal, SIGNAL(inProgress()), this, SLOT(connectionInProgress())); connect(m_pCDevices, SIGNAL(currentIndexChanged(int)), this, SLOT(videoInputChanged(int))); connect(m_pCInputs, SIGNAL(currentIndexChanged(int)), this, SLOT(videoInputChanged(int))); @@ -492,37 +515,37 @@ DccVideoWindow::~DccVideoWindow() if(m_pInVideoLabel) { delete m_pInVideoLabel; - m_pInVideoLabel=0; + m_pInVideoLabel = 0; } if(m_pCameraView) { delete m_pCameraView; - m_pCameraView=0; + m_pCameraView = 0; } if(m_pCameraImage) { delete m_pCameraImage; - m_pCameraImage=0; + m_pCameraImage = 0; } if(m_pCamera) { delete m_pCamera; - m_pCamera=0; + m_pCamera = 0; } if(m_pCDevices) { delete m_pCDevices; - m_pCDevices=0; + m_pCDevices = 0; } if(m_pCInputs) { delete m_pCInputs; - m_pCInputs=0; + m_pCInputs = 0; } if(m_pCStandards) { delete m_pCStandards; - m_pCStandards=0; + m_pCStandards = 0; } if(m_pVideoLabel[0]) { @@ -536,7 +559,7 @@ DccVideoWindow::~DccVideoWindow() if(m_pLayout) { delete m_pLayout; - m_pLayout=0; + m_pLayout = 0; } g_pDccBroker->unregisterDccWindow(this); @@ -561,31 +584,31 @@ void DccVideoWindow::resizeEvent(QResizeEvent *) { int iHeight = m_pInput->heightHint(); int iHeight2 = m_pButtonBox->sizeHint().height(); - m_pButtonBox->setGeometry(0,0,width(),iHeight2); - m_pSplitter->setGeometry(0,iHeight2,width(),height() - (iHeight + iHeight2)); - m_pInput->setGeometry(0,height() - iHeight, width(),iHeight); + m_pButtonBox->setGeometry(0, 0, width(), iHeight2); + m_pSplitter->setGeometry(0, iHeight2, width(), height() - (iHeight + iHeight2)); + m_pInput->setGeometry(0, height() - iHeight, width(), iHeight); } QSize DccVideoWindow::sizeHint() const { QSize ret(m_pSplitter->sizeHint().width(), - m_pContainerWidget->sizeHint().height() + m_pButtonBox->sizeHint().height()); + m_pContainerWidget->sizeHint().height() + m_pButtonBox->sizeHint().height()); return ret; } void DccVideoWindow::textViewRightClicked() { - KVS_TRIGGER_EVENT_1(KviEvent_OnDCCChatPopupRequest,this,m_pDescriptor->idString()); + KVS_TRIGGER_EVENT_1(KviEvent_OnDCCChatPopupRequest, this, m_pDescriptor->idString()); } void DccVideoWindow::triggerCreationEvents() { - KVS_TRIGGER_EVENT_1(KviEvent_OnDCCChatWindowCreated,this,m_pDescriptor->idString()); + KVS_TRIGGER_EVENT_1(KviEvent_OnDCCChatWindowCreated, this, m_pDescriptor->idString()); } void DccVideoWindow::triggerDestructionEvents() { - KVS_TRIGGER_EVENT_1(KviEvent_OnDCCChatWindowClosing,this,m_pDescriptor->idString()); + KVS_TRIGGER_EVENT_1(KviEvent_OnDCCChatWindowClosing, this, m_pDescriptor->idString()); } void DccVideoWindow::startConnection() @@ -593,14 +616,16 @@ void DccVideoWindow::startConnection() if(!(m_pDescriptor->bActive)) { // PASSIVE CONNECTION - output(KVI_OUT_DCCMSG,__tr2qs_ctx("Attempting a passive DCC VIDEO connection","dcc")); - KviError::Code eError = m_pMarshal->dccListen(m_pDescriptor->szListenIp,m_pDescriptor->szListenPort,m_pDescriptor->bDoTimeout); + output(KVI_OUT_DCCMSG, __tr2qs_ctx("Attempting a passive DCC VIDEO connection", "dcc")); + KviError::Code eError = m_pMarshal->dccListen(m_pDescriptor->szListenIp, m_pDescriptor->szListenPort, m_pDescriptor->bDoTimeout); if(eError != KviError::Success) handleMarshalError(eError); - } else { + } + else + { // ACTIVE CONNECTION - output(KVI_OUT_DCCMSG,__tr2qs_ctx("Attempting an active DCC VIDEO connection","dcc")); - KviError::Code eError = m_pMarshal->dccConnect(m_pDescriptor->szIp.toUtf8().data(),m_pDescriptor->szPort.toUtf8().data(),m_pDescriptor->bDoTimeout); + output(KVI_OUT_DCCMSG, __tr2qs_ctx("Attempting an active DCC VIDEO connection", "dcc")); + KviError::Code eError = m_pMarshal->dccConnect(m_pDescriptor->szIp.toUtf8().data(), m_pDescriptor->szPort.toUtf8().data(), m_pDescriptor->bDoTimeout); if(eError != KviError::Success) handleMarshalError(eError); } @@ -610,29 +635,34 @@ void DccVideoWindow::connectionInProgress() { if(m_pDescriptor->bActive) { - output(KVI_OUT_DCCMSG,__tr2qs_ctx("Contacting host %Q on port %Q","dcc"),&(m_pDescriptor->szIp),&(m_pDescriptor->szPort)); - } else { + output(KVI_OUT_DCCMSG, __tr2qs_ctx("Contacting host %Q on port %Q", "dcc"), &(m_pDescriptor->szIp), &(m_pDescriptor->szPort)); + } + else + { - output(KVI_OUT_DCCMSG,__tr2qs_ctx("Listening on interface %Q port %Q","dcc"), - &(m_pMarshal->localIp()),&(m_pMarshal->localPort())); + output(KVI_OUT_DCCMSG, __tr2qs_ctx("Listening on interface %Q port %Q", "dcc"), + &(m_pMarshal->localIp()), &(m_pMarshal->localPort())); if(m_pDescriptor->bSendRequest) { - QString ip = !m_pDescriptor->szFakeIp.isEmpty() ? m_pDescriptor->szFakeIp : m_pDescriptor->szListenIp; - KviCString port = !m_pDescriptor->szFakePort.isEmpty() ? m_pDescriptor->szFakePort : m_pMarshal->localPort(); -//#warning "OPTION FOR SENDING 127.0.0.1 and so on (not an unsigned nuumber)" + QString ip = !m_pDescriptor->szFakeIp.isEmpty() ? m_pDescriptor->szFakeIp : m_pDescriptor->szListenIp; + KviCString port = !m_pDescriptor->szFakePort.isEmpty() ? m_pDescriptor->szFakePort : m_pMarshal->localPort(); + //#warning "OPTION FOR SENDING 127.0.0.1 and so on (not an unsigned nuumber)" struct in_addr a; - if(KviNetUtils::stringIpToBinaryIp(ip,&a)) { + if(KviNetUtils::stringIpToBinaryIp(ip, &a)) + { ip.setNum(htonl(a.s_addr)); } m_pDescriptor->console()->connection()->sendFmtData("PRIVMSG %s :%cDCC VIDEO %s %Q %s %d%c", - m_pDescriptor->console()->connection()->encodeText(m_pDescriptor->szNick).data(), - 0x01,m_pDescriptor->szCodec.ptr(), - &ip,port.ptr(),m_pDescriptor->iSampleRate,0x01); - output(KVI_OUT_DCCMSG,__tr2qs_ctx("Sent DCC VIDEO (%s) request to %Q, waiting for the remote client to connect...","dcc"), - m_pDescriptor->szCodec.ptr(),&(m_pDescriptor->szNick)); - } else output(KVI_OUT_DCCMSG,__tr2qs_ctx("DCC VIDEO request not sent: awaiting manual connection","dcc")); + m_pDescriptor->console()->connection()->encodeText(m_pDescriptor->szNick).data(), + 0x01, m_pDescriptor->szCodec.ptr(), + &ip, port.ptr(), m_pDescriptor->iSampleRate, 0x01); + output(KVI_OUT_DCCMSG, __tr2qs_ctx("Sent DCC VIDEO (%s) request to %Q, waiting for the remote client to connect...", "dcc"), + m_pDescriptor->szCodec.ptr(), &(m_pDescriptor->szNick)); + } + else + output(KVI_OUT_DCCMSG, __tr2qs_ctx("DCC VIDEO request not sent: awaiting manual connection", "dcc")); } } @@ -642,20 +672,20 @@ const QString & DccVideoWindow::target() if(!m_pszTarget) m_pszTarget = new QString(); - m_pszTarget->sprintf("%s@%s:%s",m_pDescriptor->szNick.toUtf8().data(),m_pDescriptor->szIp.toUtf8().data(),m_pDescriptor->szPort.toUtf8().data()); + m_pszTarget->sprintf("%s@%s:%s", m_pDescriptor->szNick.toUtf8().data(), m_pDescriptor->szIp.toUtf8().data(), m_pDescriptor->szPort.toUtf8().data()); return *m_pszTarget; } -void DccVideoWindow::getBaseLogFileName(QString &buffer) +void DccVideoWindow::getBaseLogFileName(QString & buffer) { - buffer.sprintf("dccvideo_%s_%s_%s",m_pDescriptor->szNick.toUtf8().data(),m_pDescriptor->szLocalFileName.toUtf8().data(),m_pDescriptor->szPort.toUtf8().data()); + buffer.sprintf("dccvideo_%s_%s_%s", m_pDescriptor->szNick.toUtf8().data(), m_pDescriptor->szLocalFileName.toUtf8().data(), m_pDescriptor->szPort.toUtf8().data()); } void DccVideoWindow::fillCaptionBuffers() { - KviCString tmp(KviCString::Format,"DCC Video %s@%s:%s %s", - m_pDescriptor->szNick.toUtf8().data(),m_pDescriptor->szIp.toUtf8().data(),m_pDescriptor->szPort.toUtf8().data(), - m_pDescriptor->szLocalFileName.toUtf8().data()); + KviCString tmp(KviCString::Format, "DCC Video %s@%s:%s %s", + m_pDescriptor->szNick.toUtf8().data(), m_pDescriptor->szIp.toUtf8().data(), m_pDescriptor->szPort.toUtf8().data(), + m_pDescriptor->szLocalFileName.toUtf8().data()); m_szPlainTextCaption = tmp; } @@ -665,17 +695,18 @@ QPixmap * DccVideoWindow::myIconPtr() return g_pIconManager->getSmallIcon(KviIconManager::DccVoice); } -void DccVideoWindow::ownMessage(const QString &text, bool bUserFeedback) +void DccVideoWindow::ownMessage(const QString & text, bool bUserFeedback) { if(!m_pSlaveThread) { - output(KVI_OUT_SYSTEMWARNING,__tr2qs_ctx("Can't send data: no active connection","dcc")); + output(KVI_OUT_SYSTEMWARNING, __tr2qs_ctx("Can't send data: no active connection", "dcc")); return; } QByteArray szData = encodeText(text); const char * d = szData.data(); - if(!d)return; + if(!d) + return; #ifdef COMPILE_CRYPT_SUPPORT if(cryptSessionInfo()) @@ -686,28 +717,28 @@ void DccVideoWindow::ownMessage(const QString &text, bool bUserFeedback) { KviCString encrypted; cryptSessionInfo()->m_pEngine->setMaxEncryptLen(-1); - switch(cryptSessionInfo()->m_pEngine->encrypt(d,encrypted)) + switch(cryptSessionInfo()->m_pEngine->encrypt(d, encrypted)) { case KviCryptEngine::Encrypted: { - KviCString buf(KviCString::Format,"%s\r\n",encrypted.ptr()); + KviCString buf(KviCString::Format, "%s\r\n", encrypted.ptr()); m_tmpTextDataOut.append(buf.ptr(), buf.len()); if(bUserFeedback) - g_pMainWindow->firstConsole()->outputPrivmsg(this,KVI_OUT_OWNPRIVMSGCRYPTED, - m_pDescriptor->szLocalNick.toUtf8().data(),m_pDescriptor->szLocalUser.toUtf8().data(), - m_pDescriptor->szLocalHost.toUtf8().data(),text,KviConsoleWindow::NoNotifications); + g_pMainWindow->firstConsole()->outputPrivmsg(this, KVI_OUT_OWNPRIVMSGCRYPTED, + m_pDescriptor->szLocalNick.toUtf8().data(), m_pDescriptor->szLocalUser.toUtf8().data(), + m_pDescriptor->szLocalHost.toUtf8().data(), text, KviConsoleWindow::NoNotifications); } break; case KviCryptEngine::Encoded: { - KviCString buf(KviCString::Format,"%s\r\n",encrypted.ptr()); + KviCString buf(KviCString::Format, "%s\r\n", encrypted.ptr()); m_tmpTextDataOut.append(buf.ptr(), buf.len()); if(bUserFeedback) { QString encr = decodeText(encrypted.ptr()); - g_pMainWindow->firstConsole()->outputPrivmsg(this,KVI_OUT_OWNPRIVMSG, - m_pDescriptor->szLocalNick.toUtf8().data(),m_pDescriptor->szLocalUser.toUtf8().data(), - m_pDescriptor->szLocalHost.toUtf8().data(),encr,KviConsoleWindow::NoNotifications); + g_pMainWindow->firstConsole()->outputPrivmsg(this, KVI_OUT_OWNPRIVMSG, + m_pDescriptor->szLocalNick.toUtf8().data(), m_pDescriptor->szLocalUser.toUtf8().data(), + m_pDescriptor->szLocalHost.toUtf8().data(), encr, KviConsoleWindow::NoNotifications); } } break; @@ -715,34 +746,36 @@ void DccVideoWindow::ownMessage(const QString &text, bool bUserFeedback) { QString szErr = cryptSessionInfo()->m_pEngine->lastError(); output(KVI_OUT_SYSTEMERROR, - __tr2qs_ctx("The encryption engine was not able to encrypt the current message (%Q): %Q, no data was sent to the remote end","dcc"), - &text,&szErr); + __tr2qs_ctx("The encryption engine was not able to encrypt the current message (%Q): %Q, no data was sent to the remote end", "dcc"), + &text, &szErr); } break; } return; - } else { + } + else + { d++; //eat the escape code - KviCString buf(KviCString::Format,"%s\r\n",d); + KviCString buf(KviCString::Format, "%s\r\n", d); QString tmp = text.right(text.length() - 1); m_tmpTextDataOut.append(buf.ptr(), buf.len()); if(bUserFeedback) - g_pMainWindow->firstConsole()->outputPrivmsg(this,KVI_OUT_OWNPRIVMSG, - m_pDescriptor->szLocalNick.toUtf8().data(),m_pDescriptor->szLocalUser.toUtf8().data(), - m_pDescriptor->szLocalHost.toUtf8().data(),tmp,KviConsoleWindow::NoNotifications); + g_pMainWindow->firstConsole()->outputPrivmsg(this, KVI_OUT_OWNPRIVMSG, + m_pDescriptor->szLocalNick.toUtf8().data(), m_pDescriptor->szLocalUser.toUtf8().data(), + m_pDescriptor->szLocalHost.toUtf8().data(), tmp, KviConsoleWindow::NoNotifications); return; } } } #endif - KviCString buf(KviCString::Format,"%s\r\n",d); + KviCString buf(KviCString::Format, "%s\r\n", d); m_tmpTextDataOut.append(buf.ptr(), buf.len()); if(bUserFeedback) - g_pMainWindow->firstConsole()->outputPrivmsg(this,KVI_OUT_OWNPRIVMSG, - m_pDescriptor->szLocalNick.toUtf8().data(),m_pDescriptor->szLocalUser.toUtf8().data(), - m_pDescriptor->szLocalHost.toUtf8().data(),text,KviConsoleWindow::NoNotifications); + g_pMainWindow->firstConsole()->outputPrivmsg(this, KVI_OUT_OWNPRIVMSG, + m_pDescriptor->szLocalNick.toUtf8().data(), m_pDescriptor->szLocalUser.toUtf8().data(), + m_pDescriptor->szLocalHost.toUtf8().data(), text, KviConsoleWindow::NoNotifications); } const QString & DccVideoWindow::localNick() @@ -752,7 +785,7 @@ const QString & DccVideoWindow::localNick() return m_szLocalNick; } -void DccVideoWindow::ownAction(const QString &text) +void DccVideoWindow::ownAction(const QString & text) { if(m_pSlaveThread) { @@ -761,22 +794,27 @@ void DccVideoWindow::ownAction(const QString &text) if(KVI_OPTION_BOOL(KviOption_boolStripMircColorsInUserMessages)) { szTmpBuffer = KviControlCodes::stripControlBytes(text); - } else { + } + else + { szTmpBuffer = text; } QByteArray szData = encodeText(szTmpBuffer); const char * d = szData.data(); - if(!d)return; - KviCString buf(KviCString::Format,"%cACTION %s%c\r\n",0x01,d,0x01); + if(!d) + return; + KviCString buf(KviCString::Format, "%cACTION %s%c\r\n", 0x01, d, 0x01); m_tmpTextDataOut.append(buf.ptr(), buf.len()); - output(KVI_OUT_ACTION,"%Q %Q",&(m_pDescriptor->szLocalNick),&szTmpBuffer); - } else { - output(KVI_OUT_SYSTEMWARNING,__tr2qs_ctx("Can't send data: no active connection","dcc")); + output(KVI_OUT_ACTION, "%Q %Q", &(m_pDescriptor->szLocalNick), &szTmpBuffer); + } + else + { + output(KVI_OUT_SYSTEMWARNING, __tr2qs_ctx("Can't send data: no active connection", "dcc")); } } -bool DccVideoWindow::event(QEvent *e) +bool DccVideoWindow::event(QEvent * e) { if(e->type() == KVI_THREAD_EVENT) { @@ -786,7 +824,7 @@ bool DccVideoWindow::event(QEvent *e) { KviError::Code * pError = ((KviThreadDataEvent<KviError::Code> *)e)->getData(); QString ssss = KviError::getDescription(*pError); - output(KVI_OUT_DCCERROR,__tr2qs_ctx("ERROR: %Q","dcc"),&(ssss)); + output(KVI_OUT_DCCERROR, __tr2qs_ctx("ERROR: %Q", "dcc"), &(ssss)); delete pError; return true; } @@ -794,16 +832,16 @@ bool DccVideoWindow::event(QEvent *e) case KVI_DCC_THREAD_EVENT_DATA: { KviCString * encoded = ((KviThreadDataEvent<KviCString> *)e)->getData(); - KviCString d=KviCString(decodeText(encoded->ptr())); + KviCString d = KviCString(decodeText(encoded->ptr())); if(d.firstCharIs(0x01)) { d.cutLeft(1); if(d.lastCharIs(0x01)) d.cutRight(1); - if(kvi_strEqualCIN("ACTION",d.ptr(),6)) + if(kvi_strEqualCIN("ACTION", d.ptr(), 6)) d.cutLeft(6); d.stripLeftWhiteSpace(); - output(KVI_OUT_ACTION,"%Q %s",&(m_pDescriptor->szNick),d.ptr()); + output(KVI_OUT_ACTION, "%Q %s", &(m_pDescriptor->szNick), d.ptr()); if(!hasAttention(KviWindow::MainWindowIsVisible)) { if(KVI_OPTION_BOOL(KviOption_boolFlashDccChatWindowOnNewMessages)) @@ -817,10 +855,12 @@ bool DccVideoWindow::event(QEvent *e) szMsg += "</b> "; szMsg += KviQString::toHtmlEscaped(QString(d.ptr())); //qDebug("KviIrcServerParser_ctcp.cpp:975 debug: %s",szMsg.data()); - g_pApp->notifierMessage(this,KVI_OPTION_MSGTYPE(KVI_OUT_ACTION).pixId(),szMsg,KVI_OPTION_UINT(KviOption_uintNotifierAutoHideTime)); + g_pApp->notifierMessage(this, KVI_OPTION_MSGTYPE(KVI_OUT_ACTION).pixId(), szMsg, KVI_OPTION_UINT(KviOption_uintNotifierAutoHideTime)); } } - } else { + } + else + { #ifdef COMPILE_CRYPT_SUPPORT if(KviCryptSessionInfo * cinf = cryptSessionInfo()) @@ -828,39 +868,41 @@ bool DccVideoWindow::event(QEvent *e) if(cinf->m_bDoDecrypt) { KviCString decryptedStuff; - switch(cinf->m_pEngine->decrypt(d.ptr(),decryptedStuff)) + switch(cinf->m_pEngine->decrypt(d.ptr(), decryptedStuff)) { case KviCryptEngine::DecryptOkWasEncrypted: case KviCryptEngine::DecryptOkWasEncoded: case KviCryptEngine::DecryptOkWasPlainText: - if(!KVS_TRIGGER_EVENT_2_HALTED(KviEvent_OnDCCChatMessage,this,QString(decryptedStuff.ptr()),m_pDescriptor->idString())) + if(!KVS_TRIGGER_EVENT_2_HALTED(KviEvent_OnDCCChatMessage, this, QString(decryptedStuff.ptr()), m_pDescriptor->idString())) { - g_pMainWindow->firstConsole()->outputPrivmsg(this,KVI_OUT_DCCCHATMSG, - m_pDescriptor->szNick.toUtf8().data(),m_pDescriptor->szUser.toUtf8().data(), - m_pDescriptor->szHost.toUtf8().data(),decryptedStuff.ptr()); + g_pMainWindow->firstConsole()->outputPrivmsg(this, KVI_OUT_DCCCHATMSG, + m_pDescriptor->szNick.toUtf8().data(), m_pDescriptor->szUser.toUtf8().data(), + m_pDescriptor->szHost.toUtf8().data(), decryptedStuff.ptr()); } delete encoded; return true; - break; + break; default: // also case KviCryptEngine::DecryptError { QString szErr = cinf->m_pEngine->lastError(); output(KVI_OUT_SYSTEMERROR, - __tr2qs_ctx("The following message appears to be encrypted, but the encryption engine failed to decode it: %Q","dcc"), - &szErr); + __tr2qs_ctx("The following message appears to be encrypted, but the encryption engine failed to decode it: %Q", "dcc"), + &szErr); } break; } } - } else { + } + else + { #endif // FIXME! - if(!KVS_TRIGGER_EVENT_2_HALTED(KviEvent_OnDCCChatMessage,this,QString(d.ptr()),m_pDescriptor->idString())) + if(!KVS_TRIGGER_EVENT_2_HALTED(KviEvent_OnDCCChatMessage, this, QString(d.ptr()), m_pDescriptor->idString())) { - g_pMainWindow->firstConsole()->outputPrivmsg(this,KVI_OUT_DCCCHATMSG, - m_pDescriptor->szNick.toUtf8().data(),m_pDescriptor->szUser.toUtf8().data(), - m_pDescriptor->szHost.toUtf8().data(),d.ptr()); + g_pMainWindow->firstConsole()->outputPrivmsg(this, KVI_OUT_DCCCHATMSG, + m_pDescriptor->szNick.toUtf8().data(), m_pDescriptor->szUser.toUtf8().data(), + m_pDescriptor->szHost.toUtf8().data(), d.ptr()); if(!hasAttention(KviWindow::MainWindowIsVisible)) { if(KVI_OPTION_BOOL(KviOption_boolFlashDccChatWindowOnNewMessages)) @@ -870,7 +912,7 @@ bool DccVideoWindow::event(QEvent *e) if(KVI_OPTION_BOOL(KviOption_boolPopupNotifierOnNewDccChatMessages)) { QString szMsg = KviQString::toHtmlEscaped(QString(d.ptr())); - g_pApp->notifierMessage(this,KviIconManager::DccChatMsg,szMsg,KVI_OPTION_UINT(KviOption_uintNotifierAutoHideTime)); + g_pApp->notifierMessage(this, KviIconManager::DccChatMsg, szMsg, KVI_OPTION_UINT(KviOption_uintNotifierAutoHideTime)); } } } @@ -885,7 +927,7 @@ bool DccVideoWindow::event(QEvent *e) case KVI_DCC_THREAD_EVENT_MESSAGE: { KviCString * str = ((KviThreadDataEvent<KviCString> *)e)->getData(); - outputNoFmt(KVI_OUT_DCCMSG,__tr_no_xgettext_ctx(str->ptr(),"dcc")); + outputNoFmt(KVI_OUT_DCCMSG, __tr_no_xgettext_ctx(str->ptr(), "dcc")); delete str; return true; } @@ -896,31 +938,29 @@ bool DccVideoWindow::event(QEvent *e) switch(*act) { case KVI_DCC_VIDEO_THREAD_ACTION_START_RECORDING: -// m_pRecordingLabel->setEnabled(true); - break; + // m_pRecordingLabel->setEnabled(true); + break; case KVI_DCC_VIDEO_THREAD_ACTION_STOP_RECORDING: -// m_pRecordingLabel->setEnabled(false); - break; + // m_pRecordingLabel->setEnabled(false); + break; case KVI_DCC_VIDEO_THREAD_ACTION_START_PLAYING: -// m_pPlayingLabel->setEnabled(true); - break; + // m_pPlayingLabel->setEnabled(true); + break; case KVI_DCC_VIDEO_THREAD_ACTION_STOP_PLAYING: -// m_pPlayingLabel->setEnabled(false); - break; + // m_pPlayingLabel->setEnabled(false); + break; case KVI_DCC_VIDEO_THREAD_ACTION_GRAB_FRAME: - m_pCameraView->render( m_pCameraImage ); - break; - + m_pCameraView->render(m_pCameraImage); + break; } delete act; return true; } break; default: - qDebug("Invalid event type %d received",((KviThreadEvent *)e)->id()); - break; + qDebug("Invalid event type %d received", ((KviThreadEvent *)e)->id()); + break; } - } return KviWindow::event(e); @@ -929,18 +969,18 @@ bool DccVideoWindow::event(QEvent *e) void DccVideoWindow::handleMarshalError(KviError::Code eError) { QString ssss = KviError::getDescription(eError); - output(KVI_OUT_DCCERROR,__tr2qs_ctx("DCC Failed: %Q","dcc"),&ssss); + output(KVI_OUT_DCCERROR, __tr2qs_ctx("DCC Failed: %Q", "dcc"), &ssss); } void DccVideoWindow::connected() { - output(KVI_OUT_DCCMSG,__tr2qs_ctx("Connected to %Q:%Q","dcc"), - &(m_pMarshal->remoteIp()),&(m_pMarshal->remotePort())); - output(KVI_OUT_DCCMSG,__tr2qs_ctx("Local end is %Q:%Q","dcc"), - &(m_pMarshal->localIp()),&(m_pMarshal->localPort())); + output(KVI_OUT_DCCMSG, __tr2qs_ctx("Connected to %Q:%Q", "dcc"), + &(m_pMarshal->remoteIp()), &(m_pMarshal->remotePort())); + output(KVI_OUT_DCCMSG, __tr2qs_ctx("Local end is %Q:%Q", "dcc"), + &(m_pMarshal->localIp()), &(m_pMarshal->localPort())); if(!(m_pDescriptor->bActive)) { - m_pDescriptor->szIp = m_pMarshal->remoteIp(); + m_pDescriptor->szIp = m_pMarshal->remoteIp(); m_pDescriptor->szPort = m_pMarshal->remotePort(); m_pDescriptor->szHost = m_pMarshal->remoteIp(); } @@ -950,10 +990,10 @@ void DccVideoWindow::connected() opt->pCodec = kvi_dcc_video_get_codec(m_pDescriptor->szCodec.ptr()); - output(KVI_OUT_DCCMSG,__tr2qs_ctx("Actual codec used is '%s'","dcc"),opt->pCodec->name()); + output(KVI_OUT_DCCMSG, __tr2qs_ctx("Actual codec used is '%s'", "dcc"), opt->pCodec->name()); - m_pSlaveThread = new DccVideoThread(this,m_pMarshal->releaseSocket(),opt); -/* + m_pSlaveThread = new DccVideoThread(this, m_pMarshal->releaseSocket(), opt); + /* #ifndef COMPILE_DISABLE_DCC_VIDEO if(g_pVideoDevicePool) { @@ -985,8 +1025,10 @@ void DccVideoWindow::startTalking() void DccVideoWindow::startOrStopTalking(bool bStart) { - if(bStart)startTalking(); - else stopTalking(); + if(bStart) + startTalking(); + else + stopTalking(); } void DccVideoWindow::slotUpdateImage() @@ -997,9 +1039,9 @@ void DccVideoWindow::slotUpdateImage() } } -void DccVideoWindow::videoInputChanged(int ) +void DccVideoWindow::videoInputChanged(int) { -// FIXME this currently leads to a segfault -// if(m_pSlaveThread) -// m_pSlaveThread->restartRecording(m_pCDevices->currentIndex(), m_pCInputs->currentIndex(), m_pCStandards->currentIndex()); + // FIXME this currently leads to a segfault + // if(m_pSlaveThread) + // m_pSlaveThread->restartRecording(m_pCDevices->currentIndex(), m_pCInputs->currentIndex(), m_pCStandards->currentIndex()); } |
