2015-05-11 15:40:07 -04:00
/****************************************************************
* RetroShare is distributed under the following license :
*
* Copyright ( C ) 2015
*
* 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 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 . , 51 Franklin Street , Fifth Floor ,
* Boston , MA 02110 - 1301 , USA .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2015-10-12 12:25:03 -04:00
//C++
# include <time.h>
//Qt
2014-07-13 09:57:25 -04:00
# include <QIcon>
# include <QLayout>
2015-10-02 20:11:52 -04:00
# include <QPropertyAnimation>
# include <QToolButton>
2015-10-12 12:25:03 -04:00
//VOIP
2014-07-13 09:57:25 -04:00
# include <gui/audiodevicehelper.h>
2015-05-11 15:40:07 -04:00
# include "interface/rsVOIP.h"
2015-10-12 12:25:03 -04:00
# include "VOIPChatWidgetHolder.h"
# include "VideoProcessor.h"
# include "QVideoDevice.h"
//retroshare GUI
2014-07-13 09:57:25 -04:00
# include "gui/SoundManager.h"
# include "util/HandleRichText.h"
# include "gui/common/StatusDefs.h"
# include "gui/chat/ChatWidget.h"
2015-10-12 12:25:03 -04:00
//libretroshare
2014-07-13 09:57:25 -04:00
# include <retroshare/rsstatus.h>
2015-05-28 09:59:20 -04:00
# include <retroshare/rspeers.h>
2014-07-13 09:57:25 -04:00
2014-12-19 07:17:58 -05:00
# define CALL_START ": / images / call-start.png"
# define CALL_STOP ": / images / call-stop.png"
# define CALL_HOLD ": / images / call-hold.png"
2014-07-13 09:57:25 -04:00
2015-05-26 11:19:57 -04:00
VOIPChatWidgetHolder : : VOIPChatWidgetHolder ( ChatWidget * chatWidget , VOIPNotify * notify )
: QObject ( ) , ChatWidgetHolder ( chatWidget ) , mVOIPNotify ( notify )
2014-07-13 09:57:25 -04:00
{
2015-10-05 15:04:20 -04:00
int S = QFontMetricsF ( chatWidget - > font ( ) ) . height ( ) ;
2015-10-06 12:54:43 -04:00
QSize iconSize = QSize ( 3 * S , 3 * S ) ;
QSize buttonSize = QSize ( iconSize + QSize ( 3 , 3 ) ) ;
2015-10-05 15:04:20 -04:00
2015-10-04 08:12:20 -04:00
QIcon iconaudioListenToggleButton ;
2016-01-18 07:36:38 -05:00
iconaudioListenToggleButton . addPixmap ( QPixmap ( " :/images/speaker_mute.png " ) ) ;
iconaudioListenToggleButton . addPixmap ( QPixmap ( " :/images/speaker.png " ) , QIcon : : Normal , QIcon : : On ) ;
iconaudioListenToggleButton . addPixmap ( QPixmap ( " :/images/speaker.png " ) , QIcon : : Disabled , QIcon : : On ) ;
iconaudioListenToggleButton . addPixmap ( QPixmap ( " :/images/speaker.png " ) , QIcon : : Active , QIcon : : On ) ;
iconaudioListenToggleButton . addPixmap ( QPixmap ( " :/images/speaker.png " ) , QIcon : : Selected , QIcon : : On ) ;
2014-07-13 09:57:25 -04:00
audioListenToggleButton = new QToolButton ;
2015-10-04 08:12:20 -04:00
audioListenToggleButton - > setIcon ( iconaudioListenToggleButton ) ;
2015-10-05 15:04:20 -04:00
audioListenToggleButton - > setIconSize ( iconSize ) ;
audioListenToggleButton - > setMinimumSize ( buttonSize ) ;
audioListenToggleButton - > setMaximumSize ( buttonSize ) ;
2015-10-04 08:12:20 -04:00
audioListenToggleButton - > setCheckable ( true ) ;
audioListenToggleButton - > setAutoRaise ( true ) ;
2014-07-13 09:57:25 -04:00
audioListenToggleButton - > setText ( QString ( ) ) ;
audioListenToggleButton - > setToolTip ( tr ( " Mute " ) ) ;
2015-10-10 09:21:59 -04:00
audioListenToggleButton - > setEnabled ( false ) ;
2014-07-13 09:57:25 -04:00
2015-10-04 08:12:20 -04:00
QIcon iconaudioCaptureToggleButton ;
2016-01-18 07:36:38 -05:00
iconaudioCaptureToggleButton . addPixmap ( QPixmap ( " :/images/phone.png " ) ) ;
iconaudioCaptureToggleButton . addPixmap ( QPixmap ( " :/images/microphone_mute.png " ) , QIcon : : Normal , QIcon : : On ) ;
iconaudioCaptureToggleButton . addPixmap ( QPixmap ( " :/images/microphone_mute.png " ) , QIcon : : Disabled , QIcon : : On ) ;
iconaudioCaptureToggleButton . addPixmap ( QPixmap ( " :/images/microphone_mute.png " ) , QIcon : : Active , QIcon : : On ) ;
iconaudioCaptureToggleButton . addPixmap ( QPixmap ( " :/images/microphone_mute.png " ) , QIcon : : Selected , QIcon : : On ) ;
2014-07-13 09:57:25 -04:00
audioCaptureToggleButton = new QToolButton ;
2015-10-04 08:12:20 -04:00
audioCaptureToggleButton - > setIcon ( iconaudioCaptureToggleButton ) ;
2015-10-05 15:04:20 -04:00
audioCaptureToggleButton - > setIconSize ( iconSize ) ;
audioCaptureToggleButton - > setMinimumSize ( buttonSize ) ;
audioCaptureToggleButton - > setMaximumSize ( buttonSize ) ;
2015-10-04 08:12:20 -04:00
audioCaptureToggleButton - > setCheckable ( true ) ;
audioCaptureToggleButton - > setAutoRaise ( true ) ;
2014-07-13 09:57:25 -04:00
audioCaptureToggleButton - > setText ( QString ( ) ) ;
audioCaptureToggleButton - > setToolTip ( tr ( " Start Call " ) ) ;
2015-10-04 08:12:20 -04:00
QIcon iconvideoCaptureToggleButton ;
2016-01-18 07:36:38 -05:00
iconvideoCaptureToggleButton . addPixmap ( QPixmap ( " :/images/filmcam.png " ) ) ;
iconvideoCaptureToggleButton . addPixmap ( QPixmap ( " :/images/filmcam-off.png " ) , QIcon : : Normal , QIcon : : On ) ;
iconvideoCaptureToggleButton . addPixmap ( QPixmap ( " :/images/filmcam-off.png " ) , QIcon : : Disabled , QIcon : : On ) ;
iconvideoCaptureToggleButton . addPixmap ( QPixmap ( " :/images/filmcam-off.png " ) , QIcon : : Active , QIcon : : On ) ;
iconvideoCaptureToggleButton . addPixmap ( QPixmap ( " :/images/filmcam-off.png " ) , QIcon : : Selected , QIcon : : On ) ;
2015-10-04 08:12:20 -04:00
videoCaptureToggleButton = new QToolButton ;
videoCaptureToggleButton - > setIcon ( iconvideoCaptureToggleButton ) ;
2015-10-05 15:04:20 -04:00
videoCaptureToggleButton - > setIconSize ( iconSize ) ;
videoCaptureToggleButton - > setMinimumSize ( buttonSize ) ;
videoCaptureToggleButton - > setMaximumSize ( buttonSize ) ;
2015-10-04 08:12:20 -04:00
videoCaptureToggleButton - > setCheckable ( true ) ;
videoCaptureToggleButton - > setAutoRaise ( true ) ;
videoCaptureToggleButton - > setText ( QString ( ) ) ;
videoCaptureToggleButton - > setToolTip ( tr ( " Start Video Call " ) ) ;
2014-12-19 07:17:58 -05:00
hangupButton = new QToolButton ;
2016-01-18 07:36:38 -05:00
hangupButton - > setIcon ( QIcon ( " :/images/phone_hangup.png " ) ) ;
2015-10-05 15:04:20 -04:00
hangupButton - > setIconSize ( iconSize ) ;
hangupButton - > setMinimumSize ( buttonSize ) ;
hangupButton - > setMaximumSize ( buttonSize ) ;
2014-12-19 07:17:58 -05:00
hangupButton - > setCheckable ( false ) ;
2015-10-04 08:12:20 -04:00
hangupButton - > setAutoRaise ( true ) ;
2014-12-19 07:17:58 -05:00
hangupButton - > setText ( QString ( ) ) ;
hangupButton - > setToolTip ( tr ( " Hangup Call " ) ) ;
2015-10-04 08:12:20 -04:00
hangupButton - > hide ( ) ;
2014-07-13 09:57:25 -04:00
2015-10-04 08:12:20 -04:00
QIcon iconhideChatTextToggleButton ;
2016-01-18 07:36:38 -05:00
iconhideChatTextToggleButton . addPixmap ( QPixmap ( " :/images/chat-bubble.png " ) ) ;
iconhideChatTextToggleButton . addPixmap ( QPixmap ( " :/images/chat-bubble.png " ) , QIcon : : Normal , QIcon : : On ) ;
iconhideChatTextToggleButton . addPixmap ( QPixmap ( " :/images/chat-bubble.png " ) , QIcon : : Disabled , QIcon : : On ) ;
iconhideChatTextToggleButton . addPixmap ( QPixmap ( " :/images/chat-bubble.png " ) , QIcon : : Active , QIcon : : On ) ;
iconhideChatTextToggleButton . addPixmap ( QPixmap ( " :/images/chat-bubble.png " ) , QIcon : : Selected , QIcon : : On ) ;
2015-10-01 17:41:34 -04:00
hideChatTextToggleButton = new QToolButton ;
2015-10-04 08:12:20 -04:00
hideChatTextToggleButton - > setIcon ( iconhideChatTextToggleButton ) ;
2015-10-05 15:04:20 -04:00
hideChatTextToggleButton - > setIconSize ( iconSize ) ;
hideChatTextToggleButton - > setMinimumSize ( buttonSize ) ;
hideChatTextToggleButton - > setMaximumSize ( buttonSize ) ;
2015-10-04 08:12:20 -04:00
hideChatTextToggleButton - > setCheckable ( true ) ;
hideChatTextToggleButton - > setAutoRaise ( true ) ;
2015-10-01 17:41:34 -04:00
hideChatTextToggleButton - > setText ( QString ( ) ) ;
hideChatTextToggleButton - > setToolTip ( tr ( " Hide Chat Text " ) ) ;
hideChatTextToggleButton - > setEnabled ( false ) ;
2015-10-04 08:12:20 -04:00
QIcon iconfullscreenToggleButton ;
2016-01-18 07:36:38 -05:00
iconfullscreenToggleButton . addPixmap ( QPixmap ( " :/images/fullscreen_arrows.png " ) ) ;
iconfullscreenToggleButton . addPixmap ( QPixmap ( " :/images/fullscreen.png " ) , QIcon : : Normal , QIcon : : On ) ;
iconfullscreenToggleButton . addPixmap ( QPixmap ( " :/images/fullscreen.png " ) , QIcon : : Disabled , QIcon : : On ) ;
iconfullscreenToggleButton . addPixmap ( QPixmap ( " :/images/fullscreen.png " ) , QIcon : : Active , QIcon : : On ) ;
iconfullscreenToggleButton . addPixmap ( QPixmap ( " :/images/fullscreen.png " ) , QIcon : : Selected , QIcon : : On ) ;
2015-10-04 08:12:20 -04:00
fullscreenToggleButton = new QToolButton ;
fullscreenToggleButton - > setIcon ( iconfullscreenToggleButton ) ;
2015-10-05 15:04:20 -04:00
fullscreenToggleButton - > setIconSize ( iconSize ) ;
fullscreenToggleButton - > setMinimumSize ( buttonSize ) ;
fullscreenToggleButton - > setMaximumSize ( buttonSize ) ;
2015-10-04 08:12:20 -04:00
fullscreenToggleButton - > setCheckable ( true ) ;
fullscreenToggleButton - > setAutoRaise ( true ) ;
fullscreenToggleButton - > setText ( QString ( ) ) ;
fullscreenToggleButton - > setToolTip ( tr ( " Fullscreen mode " ) ) ;
fullscreenToggleButton - > setEnabled ( false ) ;
2014-07-13 09:57:25 -04:00
connect ( audioListenToggleButton , SIGNAL ( clicked ( ) ) , this , SLOT ( toggleAudioListen ( ) ) ) ;
connect ( audioCaptureToggleButton , SIGNAL ( clicked ( ) ) , this , SLOT ( toggleAudioCapture ( ) ) ) ;
2015-10-01 17:41:34 -04:00
connect ( videoCaptureToggleButton , SIGNAL ( clicked ( ) ) , this , SLOT ( toggleVideoCapture ( ) ) ) ;
2015-10-04 08:12:20 -04:00
connect ( hangupButton , SIGNAL ( clicked ( ) ) , this , SLOT ( hangupCall ( ) ) ) ;
2015-10-01 17:41:34 -04:00
connect ( hideChatTextToggleButton , SIGNAL ( clicked ( ) ) , this , SLOT ( toggleHideChatText ( ) ) ) ;
2015-10-04 08:12:20 -04:00
connect ( fullscreenToggleButton , SIGNAL ( clicked ( ) ) , this , SLOT ( toggleFullScreen ( ) ) ) ;
2014-07-13 09:57:25 -04:00
2015-10-01 17:41:34 -04:00
mChatWidget - > addTitleBarWidget ( audioListenToggleButton ) ;
mChatWidget - > addTitleBarWidget ( audioCaptureToggleButton ) ;
mChatWidget - > addTitleBarWidget ( videoCaptureToggleButton ) ;
2015-10-04 08:12:20 -04:00
mChatWidget - > addTitleBarWidget ( hangupButton ) ;
2015-10-01 17:41:34 -04:00
mChatWidget - > addTitleBarWidget ( hideChatTextToggleButton ) ;
2015-10-04 08:12:20 -04:00
mChatWidget - > addTitleBarWidget ( fullscreenToggleButton ) ;
2014-07-13 09:57:25 -04:00
outputAudioProcessor = NULL ;
outputAudioDevice = NULL ;
inputAudioProcessor = NULL ;
inputAudioDevice = NULL ;
inputVideoDevice = new QVideoInputDevice ( mChatWidget ) ; // not started yet ;-)
2015-08-14 16:44:20 -04:00
videoProcessor = new VideoProcessor ;
2014-07-13 09:57:25 -04:00
// Make a widget with two video devices, one for echo, and one for the talking peer.
videoWidget = new QWidget ( mChatWidget ) ;
2014-12-04 08:49:04 -05:00
videoWidget - > setLayout ( new QVBoxLayout ( ) ) ;
2014-07-13 09:57:25 -04:00
videoWidget - > layout ( ) - > addWidget ( outputVideoDevice = new QVideoOutputDevice ( videoWidget ) ) ;
2014-12-06 09:21:36 -05:00
videoWidget - > layout ( ) - > addWidget ( echoVideoDevice = new QVideoOutputDevice ( videoWidget ) ) ;
2014-09-20 12:28:26 -04:00
videoWidget - > hide ( ) ;
2014-07-13 09:57:25 -04:00
2014-07-15 16:04:31 -04:00
connect ( inputVideoDevice , SIGNAL ( networkPacketReady ( ) ) , this , SLOT ( sendVideoData ( ) ) ) ;
2015-10-02 20:11:52 -04:00
echoVideoDevice - > setMinimumSize ( 320 , 240 ) ; //4/3
outputVideoDevice - > setMinimumSize ( 320 , 240 ) ; //4/3
echoVideoDevice - > showFrameOff ( ) ;
outputVideoDevice - > showFrameOff ( ) ;
2014-12-04 08:49:04 -05:00
2014-12-05 11:47:59 -05:00
echoVideoDevice - > setStyleSheet ( " border: 4px solid #CCCCCC; border-radius: 4px; " ) ;
outputVideoDevice - > setStyleSheet ( " border: 4px solid #CCCCCC; border-radius: 4px; " ) ;
2014-07-13 09:57:25 -04:00
2015-10-02 20:11:52 -04:00
/// FULLSCREEN ///
fullScreenFrame = new QFrame ( ) ;
outputVideoDeviceFS = new QVideoOutputDevice ( fullScreenFrame ) ;
outputVideoDeviceFS - > setGeometry ( QRect ( QPoint ( 0 , 0 ) , fullScreenFrame - > geometry ( ) . size ( ) ) ) ;
outputVideoDeviceFS - > showFrameOff ( ) ;
2015-10-05 15:04:20 -04:00
echoVideoDeviceFS = new QVideoOutputDevice ( fullScreenFrame ) ;
echoVideoDeviceFS - > setGeometry ( QRect ( QPoint ( fullScreenFrame - > width ( ) , fullScreenFrame - > height ( ) ) - QPoint ( 320 , 240 ) , QSize ( 320 , 240 ) ) ) ;
echoVideoDeviceFS - > showFrameOff ( ) ;
2015-10-04 08:12:20 -04:00
toolBarFS = new QFrame ( fullScreenFrame ) ;
QHBoxLayout * toolBarFSLayout = new QHBoxLayout ( toolBarFS ) ;
audioListenToggleButtonFS = new QToolButton ( fullScreenFrame ) ;
audioListenToggleButtonFS - > setIcon ( iconaudioListenToggleButton ) ;
2015-10-06 13:58:42 -04:00
audioListenToggleButtonFS - > setIconSize ( iconSize ) ;
audioListenToggleButtonFS - > setMinimumSize ( buttonSize ) ;
audioListenToggleButtonFS - > setMaximumSize ( buttonSize ) ;
2015-10-04 08:12:20 -04:00
audioListenToggleButtonFS - > setCheckable ( true ) ;
audioListenToggleButtonFS - > setAutoRaise ( true ) ;
audioListenToggleButtonFS - > setText ( QString ( ) ) ;
audioListenToggleButtonFS - > setToolTip ( tr ( " Mute " ) ) ;
audioCaptureToggleButtonFS = new QToolButton ( fullScreenFrame ) ;
audioCaptureToggleButtonFS - > setIcon ( iconaudioCaptureToggleButton ) ;
2015-10-06 13:58:42 -04:00
audioCaptureToggleButtonFS - > setIconSize ( iconSize ) ;
audioCaptureToggleButtonFS - > setMinimumSize ( buttonSize ) ;
audioCaptureToggleButtonFS - > setMaximumSize ( buttonSize ) ;
2015-10-04 08:12:20 -04:00
audioCaptureToggleButtonFS - > setCheckable ( true ) ;
audioCaptureToggleButtonFS - > setAutoRaise ( true ) ;
audioCaptureToggleButtonFS - > setText ( QString ( ) ) ;
audioCaptureToggleButtonFS - > setToolTip ( tr ( " Start Call " ) ) ;
videoCaptureToggleButtonFS = new QToolButton ( fullScreenFrame ) ;
videoCaptureToggleButtonFS - > setIcon ( iconvideoCaptureToggleButton ) ;
2015-10-06 13:58:42 -04:00
videoCaptureToggleButtonFS - > setIconSize ( iconSize ) ;
videoCaptureToggleButtonFS - > setMinimumSize ( buttonSize ) ;
videoCaptureToggleButtonFS - > setMaximumSize ( buttonSize ) ;
2015-10-04 08:12:20 -04:00
videoCaptureToggleButtonFS - > setCheckable ( true ) ;
videoCaptureToggleButtonFS - > setAutoRaise ( true ) ;
videoCaptureToggleButtonFS - > setText ( QString ( ) ) ;
videoCaptureToggleButtonFS - > setToolTip ( tr ( " Start Video Call " ) ) ;
hangupButtonFS = new QToolButton ( fullScreenFrame ) ;
2016-01-18 07:36:38 -05:00
hangupButtonFS - > setIcon ( QIcon ( " :/images/phone_hangup.png " ) ) ;
2015-10-06 13:58:42 -04:00
hangupButtonFS - > setIconSize ( iconSize ) ;
hangupButtonFS - > setMinimumSize ( buttonSize ) ;
hangupButtonFS - > setMaximumSize ( buttonSize ) ;
2015-10-04 08:12:20 -04:00
hangupButtonFS - > setCheckable ( false ) ;
hangupButtonFS - > setAutoRaise ( true ) ;
hangupButtonFS - > setText ( QString ( ) ) ;
hangupButtonFS - > setToolTip ( tr ( " Hangup Call " ) ) ;
hangupButtonFS - > hide ( ) ;
fullscreenToggleButtonFS = new QToolButton ( fullScreenFrame ) ;
fullscreenToggleButtonFS - > setIcon ( iconfullscreenToggleButton ) ;
2015-10-06 13:58:42 -04:00
fullscreenToggleButtonFS - > setIconSize ( iconSize ) ;
fullscreenToggleButtonFS - > setMinimumSize ( buttonSize ) ;
fullscreenToggleButtonFS - > setMaximumSize ( buttonSize ) ;
2015-10-04 08:12:20 -04:00
fullscreenToggleButtonFS - > setCheckable ( true ) ;
fullscreenToggleButtonFS - > setAutoRaise ( true ) ;
fullscreenToggleButtonFS - > setText ( QString ( ) ) ;
fullscreenToggleButtonFS - > setToolTip ( tr ( " Fullscreen mode " ) ) ;
fullscreenToggleButtonFS - > setEnabled ( false ) ;
connect ( audioListenToggleButtonFS , SIGNAL ( clicked ( ) ) , this , SLOT ( toggleAudioListenFS ( ) ) ) ;
connect ( audioCaptureToggleButtonFS , SIGNAL ( clicked ( ) ) , this , SLOT ( toggleAudioCaptureFS ( ) ) ) ;
connect ( videoCaptureToggleButtonFS , SIGNAL ( clicked ( ) ) , this , SLOT ( toggleVideoCaptureFS ( ) ) ) ;
connect ( hangupButtonFS , SIGNAL ( clicked ( ) ) , this , SLOT ( hangupCall ( ) ) ) ;
connect ( fullscreenToggleButtonFS , SIGNAL ( clicked ( ) ) , this , SLOT ( toggleFullScreenFS ( ) ) ) ;
toolBarFSLayout - > setDirection ( QBoxLayout : : LeftToRight ) ;
toolBarFSLayout - > setSpacing ( 2 ) ;
toolBarFSLayout - > setSizeConstraint ( QLayout : : SetMinAndMaxSize ) ;
toolBarFSLayout - > addWidget ( audioListenToggleButtonFS ) ;
toolBarFSLayout - > addWidget ( audioCaptureToggleButtonFS ) ;
toolBarFSLayout - > addWidget ( videoCaptureToggleButtonFS ) ;
toolBarFSLayout - > addWidget ( hangupButtonFS ) ;
toolBarFSLayout - > addWidget ( fullscreenToggleButtonFS ) ;
toolBarFS - > setLayout ( toolBarFSLayout ) ;
2015-10-02 20:11:52 -04:00
fullScreenFrame - > setParent ( 0 ) ;
2015-10-05 15:04:20 -04:00
fullScreenFrame - > setWindowFlags ( Qt : : WindowStaysOnTopHint ) ;
fullScreenFrame - > setFocusPolicy ( Qt : : StrongFocus ) ;
2015-10-02 20:11:52 -04:00
fullScreenFrame - > setWindowState ( Qt : : WindowFullScreen ) ;
fullScreenFrame - > hide ( ) ;
fullScreenFrame - > installEventFilter ( this ) ;
2014-07-13 09:57:25 -04:00
mChatWidget - > addChatHorizontalWidget ( videoWidget ) ;
inputVideoDevice - > setEchoVideoTarget ( echoVideoDevice ) ;
2015-08-14 16:44:20 -04:00
inputVideoDevice - > setVideoProcessor ( videoProcessor ) ;
videoProcessor - > setDisplayTarget ( outputVideoDevice ) ;
2015-10-10 09:21:59 -04:00
//Ring
pbAudioRing = new QProgressBar ( ) ;
pbAudioRing - > setOrientation ( Qt : : Horizontal ) ;
pbAudioRing - > setRange ( 0 , 99 ) ;
pbAudioRing - > setTextVisible ( false ) ;
pbAudioRing - > setHidden ( true ) ;
pbVideoRing = new QProgressBar ( ) ;
pbVideoRing - > setOrientation ( Qt : : Horizontal ) ;
pbVideoRing - > setRange ( 0 , 99 ) ;
pbVideoRing - > setTextVisible ( false ) ;
pbVideoRing - > setHidden ( true ) ;
mChatWidget - > addChatBarWidget ( pbAudioRing ) ;
mChatWidget - > addChatBarWidget ( pbVideoRing ) ;
sendAudioRingTime = - 1 ;
sendVideoRingTime = - 1 ;
recAudioRingTime = - 1 ;
recVideoRingTime = - 1 ;
timerAudioRing = new QTimer ( this ) ;
timerAudioRing - > setInterval ( 300 ) ;
timerAudioRing - > setSingleShot ( true ) ;
connect ( timerAudioRing , SIGNAL ( timeout ( ) ) , this , SLOT ( timerAudioRingTimeOut ( ) ) ) ;
timerVideoRing = new QTimer ( this ) ;
timerVideoRing - > setInterval ( 300 ) ;
timerVideoRing - > setSingleShot ( true ) ;
connect ( timerVideoRing , SIGNAL ( timeout ( ) ) , this , SLOT ( timerVideoRingTimeOut ( ) ) ) ;
2015-10-12 12:25:03 -04:00
lastTimePlayOccurs = time ( NULL ) ;
2014-07-13 09:57:25 -04:00
}
VOIPChatWidgetHolder : : ~ VOIPChatWidgetHolder ( )
{
2015-10-10 12:47:07 -04:00
hangupCall ( ) ;
2014-07-13 09:57:25 -04:00
if ( inputAudioDevice ! = NULL )
inputAudioDevice - > stop ( ) ;
delete inputVideoDevice ;
2015-08-14 16:44:20 -04:00
delete videoProcessor ;
2015-10-10 09:21:59 -04:00
deleteButtonMap ( ) ;
2015-05-11 15:40:07 -04:00
2015-10-10 09:21:59 -04:00
// stop and delete timers
timerAudioRing - > stop ( ) ;
delete ( timerAudioRing ) ;
timerVideoRing - > stop ( ) ;
delete ( timerVideoRing ) ;
}
void VOIPChatWidgetHolder : : deleteButtonMap ( int flags )
{
button_map : : iterator it = buttonMapTakeCall . begin ( ) ;
while ( it ! = buttonMapTakeCall . end ( ) ) {
if ( ( ( it . key ( ) . left ( 1 ) = = " a " ) & & ( flags & RS_VOIP_FLAGS_AUDIO_DATA ) )
| | ( ( it . key ( ) . left ( 1 ) = = " v " ) & & ( flags & RS_VOIP_FLAGS_VIDEO_DATA ) ) ) {
QPair < RSButtonOnText * , RSButtonOnText * > pair = it . value ( ) ;
delete pair . second ;
delete pair . first ;
if ( flags & RS_VOIP_FLAGS_AUDIO_DATA ) recAudioRingTime = - 1 ;
if ( flags & RS_VOIP_FLAGS_VIDEO_DATA ) recVideoRingTime = - 1 ;
it = buttonMapTakeCall . erase ( it ) ;
} else {
+ + it ;
}
}
}
void VOIPChatWidgetHolder : : addNewAudioButtonMap ( const RsPeerId & peer_id )
{
if ( mChatWidget ) {
recAudioRingTime = 0 ;
timerAudioRingTimeOut ( ) ;
QString buttonName = QString : : fromUtf8 ( rsPeers - > getPeerName ( peer_id ) . c_str ( ) ) ;
if ( buttonName . isEmpty ( ) ) buttonName = QString : : fromStdString ( peer_id . toStdString ( ) . c_str ( ) ) ;
if ( buttonName . isEmpty ( ) ) buttonName = " VoIP " ;
button_map : : iterator it = buttonMapTakeCall . find ( QString ( " a " ) . append ( buttonName ) ) ;
if ( it = = buttonMapTakeCall . end ( ) ) {
mChatWidget - > addChatMsg ( true , tr ( " VoIP Status " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( )
, tr ( " %1 inviting you to start an audio conversation. Do you want Accept or Decline the invitation? " ) . arg ( buttonName ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
RSButtonOnText * buttonT = mChatWidget - > getNewButtonOnTextBrowser ( tr ( " Accept Audio Call " ) ) ;
buttonT - > setToolTip ( tr ( " Activate audio " ) ) ;
buttonT - > setStyleSheet ( QString ( " border: 1px solid #199909; " )
. append ( " font-size: 12pt; color: white; " )
. append ( " min-width: 128px; min-height: 24px; " )
. append ( " border-radius: 6px; " )
2015-10-12 18:38:46 -04:00
. append ( " padding: 3px; " )
2015-10-27 13:52:01 -04:00
. append ( " background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(122, 230, 110, 255), "
" stop:0.494318 rgba(36, 191, 16, 255), stop:0.505682 rgba(26, 162, 9, 255), stop:1 rgba(17, 106, 6, 255)); " )
2015-10-10 09:21:59 -04:00
) ;
buttonT - > updateImage ( ) ;
connect ( buttonT , SIGNAL ( clicked ( ) ) , this , SLOT ( startAudioCapture ( ) ) ) ;
connect ( buttonT , SIGNAL ( mouseEnter ( ) ) , this , SLOT ( botMouseEnterTake ( ) ) ) ;
connect ( buttonT , SIGNAL ( mouseLeave ( ) ) , this , SLOT ( botMouseLeaveTake ( ) ) ) ;
RSButtonOnText * buttonD = mChatWidget - > getNewButtonOnTextBrowser ( tr ( " Decline Audio Call " ) ) ;
buttonD - > setToolTip ( tr ( " Refuse audio call " ) ) ;
2015-10-12 18:38:46 -04:00
buttonD - > setStyleSheet ( QString ( " border: 1px solid #6a1106; " )
2015-10-10 09:21:59 -04:00
. append ( " font-size: 12pt; color: white; " )
. append ( " min-width: 128px; min-height: 24px; " )
. append ( " border-radius: 6px; " )
2015-10-12 18:38:46 -04:00
. append ( " padding: 3px; " )
2015-10-27 13:52:01 -04:00
. append ( " background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(230, 124, 110, 255), stop:0.494318 rgba(191, 35, 16, 255), "
" stop:0.505682 rgba(162, 26, 9, 255), stop:1 rgba(106, 17, 6, 255)); " )
2015-10-10 09:21:59 -04:00
) ;
buttonD - > updateImage ( ) ;
connect ( buttonD , SIGNAL ( clicked ( ) ) , this , SLOT ( hangupCallAudio ( ) ) ) ;
connect ( buttonD , SIGNAL ( mouseEnter ( ) ) , this , SLOT ( botMouseEnterDecline ( ) ) ) ;
connect ( buttonD , SIGNAL ( mouseLeave ( ) ) , this , SLOT ( botMouseLeaveDecline ( ) ) ) ;
buttonMapTakeCall . insert ( QString ( " a " ) . append ( buttonName ) , QPair < RSButtonOnText * , RSButtonOnText * > ( buttonT , buttonD ) ) ;
}
}
}
void VOIPChatWidgetHolder : : addNewVideoButtonMap ( const RsPeerId & peer_id )
{
if ( mChatWidget ) {
recVideoRingTime = 0 ;
timerVideoRingTimeOut ( ) ;
QString buttonName = QString : : fromUtf8 ( rsPeers - > getPeerName ( peer_id ) . c_str ( ) ) ;
if ( buttonName . isEmpty ( ) ) buttonName = QString : : fromStdString ( peer_id . toStdString ( ) . c_str ( ) ) ;
if ( buttonName . isEmpty ( ) ) buttonName = " VoIP " ;
button_map : : iterator it = buttonMapTakeCall . find ( QString ( " v " ) . append ( buttonName ) ) ;
if ( it = = buttonMapTakeCall . end ( ) ) {
mChatWidget - > addChatMsg ( true , tr ( " VoIP Status " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( )
, tr ( " %1 inviting you to start a video conversation. Do you want Accept or Decline the invitation? " ) . arg ( buttonName ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
RSButtonOnText * buttonT = mChatWidget - > getNewButtonOnTextBrowser ( tr ( " Accept Video Call " ) ) ;
buttonT - > setToolTip ( tr ( " Activate camera " ) ) ;
buttonT - > setStyleSheet ( QString ( " border: 1px solid #199909; " )
. append ( " font-size: 12pt; color: white; " )
. append ( " min-width: 128px; min-height: 24px; " )
. append ( " border-radius: 6px; " )
2015-10-12 18:38:46 -04:00
. append ( " padding: 3px; " )
2015-10-27 13:52:01 -04:00
. append ( " background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(122, 230, 110, 255), "
" stop:0.494318 rgba(36, 191, 16, 255), stop:0.505682 rgba(26, 162, 9, 255), stop:1 rgba(17, 106, 6, 255)); " )
2015-10-10 09:21:59 -04:00
) ;
buttonT - > updateImage ( ) ;
connect ( buttonT , SIGNAL ( clicked ( ) ) , this , SLOT ( startVideoCapture ( ) ) ) ;
connect ( buttonT , SIGNAL ( mouseEnter ( ) ) , this , SLOT ( botMouseEnterTake ( ) ) ) ;
connect ( buttonT , SIGNAL ( mouseLeave ( ) ) , this , SLOT ( botMouseLeaveTake ( ) ) ) ;
RSButtonOnText * buttonD = mChatWidget - > getNewButtonOnTextBrowser ( tr ( " Decline Video Call " ) ) ;
buttonD - > setToolTip ( tr ( " Refuse video call " ) ) ;
2015-10-12 18:38:46 -04:00
buttonD - > setStyleSheet ( QString ( " border: 1px solid #6a1106; " )
2015-10-10 09:21:59 -04:00
. append ( " font-size: 12pt; color: white; " )
. append ( " min-width: 128px; min-height: 24px; " )
. append ( " border-radius: 6px; " )
2015-10-12 18:38:46 -04:00
. append ( " padding: 3px; " )
2015-10-27 13:52:01 -04:00
. append ( " background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(230, 124, 110, 255), stop:0.494318 rgba(191, 35, 16, 255), "
" stop:0.505682 rgba(162, 26, 9, 255), stop:1 rgba(106, 17, 6, 255)); " )
2015-10-10 09:21:59 -04:00
) ;
buttonD - > updateImage ( ) ;
connect ( buttonD , SIGNAL ( clicked ( ) ) , this , SLOT ( hangupCallVideo ( ) ) ) ;
connect ( buttonD , SIGNAL ( mouseEnter ( ) ) , this , SLOT ( botMouseEnterDecline ( ) ) ) ;
connect ( buttonD , SIGNAL ( mouseLeave ( ) ) , this , SLOT ( botMouseLeaveDecline ( ) ) ) ;
buttonMapTakeCall . insert ( QString ( " v " ) . append ( buttonName ) , QPair < RSButtonOnText * , RSButtonOnText * > ( buttonT , buttonD ) ) ;
}
}
2014-07-13 09:57:25 -04:00
}
2015-10-04 08:12:20 -04:00
2015-10-02 20:11:52 -04:00
bool VOIPChatWidgetHolder : : eventFilter ( QObject * obj , QEvent * event )
{
if ( obj = = fullScreenFrame ) {
if ( event - > type ( ) = = QEvent : : Close | | event - > type ( ) = = QEvent : : MouseButtonDblClick ) {
2015-10-04 08:12:20 -04:00
showNormalView ( ) ;
2015-10-02 20:11:52 -04:00
}
if ( event - > type ( ) = = QEvent : : Resize ) {
2015-10-04 08:12:20 -04:00
replaceFullscreenWidget ( ) ;
2015-10-02 20:11:52 -04:00
}
}
// pass the event on to the parent class
return QObject : : eventFilter ( obj , event ) ;
}
2014-07-13 09:57:25 -04:00
2015-10-04 08:12:20 -04:00
void VOIPChatWidgetHolder : : hangupCall ( )
{
2015-10-10 09:21:59 -04:00
hangupCallAudio ( ) ;
hangupCallVideo ( ) ;
hangupButton - > hide ( ) ;
hangupButtonFS - > hide ( ) ;
deleteButtonMap ( ) ;
}
void VOIPChatWidgetHolder : : hangupCallAudio ( )
{
bool atLeastOneChecked = false ;
2015-10-04 08:12:20 -04:00
if ( audioCaptureToggleButton - > isChecked ( ) ) {
audioCaptureToggleButton - > setChecked ( false ) ;
toggleAudioCapture ( ) ;
2015-10-10 09:21:59 -04:00
atLeastOneChecked = true ;
2015-10-04 08:12:20 -04:00
}
2015-10-10 09:21:59 -04:00
if ( ! atLeastOneChecked ) {
2015-10-10 12:47:07 -04:00
//Decline button ,Friend hang up or chat close
2015-10-10 09:21:59 -04:00
if ( recAudioRingTime ! = - 1 ) {
rsVOIP - > sendVoipHangUpCall ( mChatWidget - > getChatId ( ) . toPeerId ( ) , RS_VOIP_FLAGS_AUDIO_DATA ) ;
deleteButtonMap ( RS_VOIP_FLAGS_AUDIO_DATA ) ;
}
sendAudioRingTime = - 1 ;
recAudioRingTime = - 1 ;
}
}
void VOIPChatWidgetHolder : : hangupCallVideo ( )
{
bool atLeastOneChecked = false ;
2015-10-04 08:12:20 -04:00
if ( videoCaptureToggleButton - > isChecked ( ) ) {
videoCaptureToggleButton - > setChecked ( false ) ;
toggleVideoCapture ( ) ;
2015-10-10 09:21:59 -04:00
atLeastOneChecked = true ;
2015-10-04 08:12:20 -04:00
}
if ( fullscreenToggleButton - > isChecked ( ) ) {
fullscreenToggleButton - > setChecked ( false ) ;
toggleFullScreen ( ) ;
2015-10-10 09:21:59 -04:00
atLeastOneChecked = true ;
2015-10-04 08:12:20 -04:00
}
if ( hideChatTextToggleButton - > isChecked ( ) ) {
hideChatTextToggleButton - > setChecked ( false ) ;
toggleHideChatText ( ) ;
2015-10-10 09:21:59 -04:00
atLeastOneChecked = true ;
}
if ( ! atLeastOneChecked ) {
2015-10-10 12:47:07 -04:00
//Decline button ,Friend hang up or chat close
2015-10-10 09:21:59 -04:00
if ( recVideoRingTime ! = - 1 ) {
rsVOIP - > sendVoipHangUpCall ( mChatWidget - > getChatId ( ) . toPeerId ( ) , RS_VOIP_FLAGS_VIDEO_DATA ) ;
deleteButtonMap ( RS_VOIP_FLAGS_VIDEO_DATA ) ;
}
sendVideoRingTime = - 1 ;
recVideoRingTime = - 1 ;
2015-10-04 08:12:20 -04:00
}
}
void VOIPChatWidgetHolder : : toggleAudioListenFS ( )
{
audioListenToggleButton - > setChecked ( audioListenToggleButtonFS - > isChecked ( ) ) ;
toggleAudioListen ( ) ;
}
2014-07-13 09:57:25 -04:00
void VOIPChatWidgetHolder : : toggleAudioListen ( )
{
if ( audioListenToggleButton - > isChecked ( ) ) {
audioListenToggleButton - > setToolTip ( tr ( " Mute yourself " ) ) ;
} else {
audioListenToggleButton - > setToolTip ( tr ( " Unmute yourself " ) ) ;
//audioListenToggleButton->setChecked(false);
/*if (outputAudioDevice) {
outputAudioDevice - > stop ( ) ;
} */
}
2015-10-04 08:12:20 -04:00
audioListenToggleButtonFS - > setChecked ( audioListenToggleButton - > isChecked ( ) ) ;
audioListenToggleButtonFS - > setToolTip ( audioListenToggleButton - > toolTip ( ) ) ;
2014-07-13 09:57:25 -04:00
}
2015-10-04 08:12:20 -04:00
void VOIPChatWidgetHolder : : startAudioCapture ( )
2014-07-13 09:57:25 -04:00
{
2015-10-10 09:21:59 -04:00
recAudioRingTime = - 2 ;
2015-10-04 08:12:20 -04:00
audioCaptureToggleButton - > setChecked ( true ) ;
toggleAudioCapture ( ) ;
2014-07-13 09:57:25 -04:00
}
2015-10-04 08:12:20 -04:00
void VOIPChatWidgetHolder : : toggleAudioCaptureFS ( )
2015-05-22 12:02:16 -04:00
{
2015-10-04 08:12:20 -04:00
audioCaptureToggleButton - > setChecked ( audioCaptureToggleButtonFS - > isChecked ( ) ) ;
2015-05-22 12:02:16 -04:00
toggleAudioCapture ( ) ;
}
2014-07-13 09:57:25 -04:00
void VOIPChatWidgetHolder : : toggleAudioCapture ( )
{
2015-10-10 09:21:59 -04:00
if ( audioCaptureToggleButton - > isChecked ( ) ) {
if ( recAudioRingTime = = - 1 ) {
if ( sendAudioRingTime = = - 1 ) {
sendAudioRingTime = 0 ;
timerAudioRingTimeOut ( ) ;
rsVOIP - > sendVoipRinging ( mChatWidget - > getChatId ( ) . toPeerId ( ) , RS_VOIP_FLAGS_AUDIO_DATA ) ;
return ; //Start Audio when accept received
}
}
if ( recAudioRingTime ! = - 1 )
rsVOIP - > sendVoipAcceptCall ( mChatWidget - > getChatId ( ) . toPeerId ( ) , RS_VOIP_FLAGS_AUDIO_DATA ) ;
recAudioRingTime = - 1 ; //Stop ringing
//activate buttons
audioListenToggleButton - > setEnabled ( true ) ;
audioListenToggleButton - > setChecked ( true ) ;
audioListenToggleButtonFS - > setEnabled ( true ) ;
audioListenToggleButtonFS - > setChecked ( true ) ;
audioCaptureToggleButton - > setToolTip ( tr ( " Hold Call " ) ) ;
hangupButton - > show ( ) ;
hangupButtonFS - > show ( ) ;
//activate audio input
if ( ! inputAudioProcessor ) {
inputAudioProcessor = new QtSpeex : : SpeexInputProcessor ( ) ;
if ( outputAudioProcessor ) {
connect ( outputAudioProcessor , SIGNAL ( playingFrame ( QByteArray * ) ) , inputAudioProcessor , SLOT ( addEchoFrame ( QByteArray * ) ) ) ;
}
inputAudioProcessor - > open ( QIODevice : : WriteOnly | QIODevice : : Unbuffered ) ;
}
if ( ! inputAudioDevice ) {
inputAudioDevice = AudioDeviceHelper : : getPreferedInputDevice ( ) ;
}
connect ( inputAudioProcessor , SIGNAL ( networkPacketReady ( ) ) , this , SLOT ( sendAudioData ( ) ) ) ;
inputAudioDevice - > start ( inputAudioProcessor ) ;
//send system message
if ( mChatWidget )
mChatWidget - > addChatMsg ( true , tr ( " VoIP Status " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( ) , tr ( " Outgoing Call is started... " ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
deleteButtonMap ( RS_VOIP_FLAGS_AUDIO_DATA ) ;
} else {
//desactivate buttons
audioListenToggleButton - > setEnabled ( false ) ;
audioListenToggleButton - > setChecked ( false ) ;
audioListenToggleButtonFS - > setEnabled ( false ) ;
audioListenToggleButtonFS - > setChecked ( false ) ;
audioCaptureToggleButton - > setToolTip ( tr ( " Resume Call " ) ) ;
if ( ! videoCaptureToggleButton - > isChecked ( ) ) {
hangupButton - > hide ( ) ;
hangupButtonFS - > hide ( ) ;
}
if ( recAudioRingTime < = - 1 ) {
//desactivate audio input
disconnect ( inputAudioProcessor , SIGNAL ( networkPacketReady ( ) ) , this , SLOT ( sendAudioData ( ) ) ) ;
if ( inputAudioDevice ) {
inputAudioDevice - > stop ( ) ;
}
//send system message
if ( mChatWidget )
mChatWidget - > addChatMsg ( true , tr ( " VoIP Status " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( )
, tr ( " Outgoing Audio Call stopped. " ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
rsVOIP - > sendVoipHangUpCall ( mChatWidget - > getChatId ( ) . toPeerId ( ) , RS_VOIP_FLAGS_AUDIO_DATA ) ;
}
sendAudioRingTime = - 1 ;
recAudioRingTime = - 1 ;
}
audioCaptureToggleButtonFS - > setChecked ( audioCaptureToggleButton - > isChecked ( ) ) ;
audioCaptureToggleButtonFS - > setToolTip ( audioCaptureToggleButton - > toolTip ( ) ) ;
2014-07-13 09:57:25 -04:00
}
2015-05-11 15:40:07 -04:00
void VOIPChatWidgetHolder : : startVideoCapture ( )
{
2015-10-10 09:21:59 -04:00
recVideoRingTime = - 2 ;
2015-05-11 15:40:07 -04:00
videoCaptureToggleButton - > setChecked ( true ) ;
toggleVideoCapture ( ) ;
}
2015-10-04 08:12:20 -04:00
void VOIPChatWidgetHolder : : toggleVideoCaptureFS ( )
{
videoCaptureToggleButton - > setChecked ( videoCaptureToggleButtonFS - > isChecked ( ) ) ;
toggleVideoCapture ( ) ;
}
2014-07-13 09:57:25 -04:00
void VOIPChatWidgetHolder : : toggleVideoCapture ( )
{
if ( videoCaptureToggleButton - > isChecked ( ) )
{
2015-10-10 09:21:59 -04:00
if ( recVideoRingTime = = - 1 ) {
if ( sendVideoRingTime = = - 1 ) {
sendVideoRingTime = 0 ;
timerVideoRingTimeOut ( ) ;
rsVOIP - > sendVoipRinging ( mChatWidget - > getChatId ( ) . toPeerId ( ) , RS_VOIP_FLAGS_VIDEO_DATA ) ;
return ; //Start Video when accept received
}
}
if ( recVideoRingTime ! = - 1 )
rsVOIP - > sendVoipAcceptCall ( mChatWidget - > getChatId ( ) . toPeerId ( ) , RS_VOIP_FLAGS_VIDEO_DATA ) ;
recVideoRingTime = - 1 ; //Stop ringing
//activate buttons
2015-10-01 17:41:34 -04:00
hideChatTextToggleButton - > setEnabled ( true ) ;
2015-10-04 08:12:20 -04:00
fullscreenToggleButton - > setEnabled ( true ) ;
fullscreenToggleButtonFS - > setEnabled ( true ) ;
2015-10-10 09:21:59 -04:00
videoCaptureToggleButton - > setToolTip ( tr ( " Shut camera off " ) ) ;
2015-10-04 08:12:20 -04:00
hangupButton - > show ( ) ;
hangupButtonFS - > show ( ) ;
2015-10-10 09:21:59 -04:00
2014-07-13 09:57:25 -04:00
//activate video input
2014-09-20 12:28:26 -04:00
videoWidget - > show ( ) ;
2014-07-13 09:57:25 -04:00
inputVideoDevice - > start ( ) ;
2015-10-10 09:21:59 -04:00
//send system message
if ( mChatWidget )
2015-05-11 15:40:07 -04:00
mChatWidget - > addChatMsg ( true , tr ( " VoIP Status " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( )
, tr ( " You're now sending video... " ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
2015-10-10 09:21:59 -04:00
deleteButtonMap ( RS_VOIP_FLAGS_VIDEO_DATA ) ;
} else {
//desactivate buttons
2015-10-01 17:41:34 -04:00
hideChatTextToggleButton - > setEnabled ( false ) ;
hideChatTextToggleButton - > setChecked ( false ) ;
toggleHideChatText ( ) ;
2015-10-04 08:12:20 -04:00
fullscreenToggleButton - > setEnabled ( false ) ;
fullscreenToggleButton - > setChecked ( false ) ;
fullscreenToggleButtonFS - > setEnabled ( false ) ;
fullscreenToggleButtonFS - > setChecked ( false ) ;
toggleFullScreen ( ) ;
2014-07-13 09:57:25 -04:00
videoCaptureToggleButton - > setToolTip ( tr ( " Activate camera " ) ) ;
2015-10-10 09:21:59 -04:00
if ( ! audioCaptureToggleButton - > isChecked ( ) ) {
hangupButton - > hide ( ) ;
hangupButtonFS - > hide ( ) ;
}
if ( recVideoRingTime < = - 1 ) {
//desactivate video input
inputVideoDevice - > stop ( ) ;
outputVideoDevice - > showFrameOff ( ) ;
videoWidget - > hide ( ) ;
//send system message
if ( mChatWidget )
mChatWidget - > addChatMsg ( true , tr ( " VoIP Status " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( )
, tr ( " Video call stopped " ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
rsVOIP - > sendVoipHangUpCall ( mChatWidget - > getChatId ( ) . toPeerId ( ) , RS_VOIP_FLAGS_VIDEO_DATA ) ;
}
sendVideoRingTime = - 1 ;
recVideoRingTime = - 1 ;
2014-07-13 09:57:25 -04:00
}
2015-10-04 08:12:20 -04:00
videoCaptureToggleButtonFS - > setChecked ( videoCaptureToggleButton - > isChecked ( ) ) ;
videoCaptureToggleButtonFS - > setToolTip ( videoCaptureToggleButton - > toolTip ( ) ) ;
2014-07-13 09:57:25 -04:00
}
2015-05-26 11:19:57 -04:00
void VOIPChatWidgetHolder : : addVideoData ( const RsPeerId & peer_id , QByteArray * array )
2014-07-15 16:04:31 -04:00
{
2015-10-10 09:21:59 -04:00
sendVideoRingTime = - 2 ; //Receive Video so Accepted
if ( ! videoCaptureToggleButton - > isChecked ( ) ) {
addNewVideoButtonMap ( peer_id ) ;
return ;
}
RsVOIPDataChunk chunk ;
chunk . type = RsVOIPDataChunk : : RS_VOIP_DATA_TYPE_VIDEO ;
chunk . size = array - > size ( ) ;
chunk . data = array - > data ( ) ;
videoProcessor - > receiveEncodedData ( chunk ) ;
2015-05-11 15:40:07 -04:00
}
2015-10-01 17:41:34 -04:00
void VOIPChatWidgetHolder : : toggleHideChatText ( )
{
2015-10-04 08:12:20 -04:00
QBoxLayout * layout = static_cast < QBoxLayout * > ( videoWidget - > layout ( ) ) ;
2015-10-01 17:41:34 -04:00
if ( hideChatTextToggleButton - > isChecked ( ) ) {
2015-10-04 08:12:20 -04:00
mChatWidget - > hideChatText ( true ) ;
if ( layout ) layout - > setDirection ( QBoxLayout : : LeftToRight ) ;
2015-10-01 17:41:34 -04:00
hideChatTextToggleButton - > setToolTip ( tr ( " Show Chat Text " ) ) ;
2015-10-04 08:12:20 -04:00
} else {
mChatWidget - > hideChatText ( false ) ;
if ( layout ) layout - > setDirection ( QBoxLayout : : TopToBottom ) ;
hideChatTextToggleButton - > setToolTip ( tr ( " Hide Chat Text " ) ) ;
fullscreenToggleButton - > setChecked ( false ) ;
toggleFullScreen ( ) ;
}
}
void VOIPChatWidgetHolder : : toggleFullScreenFS ( )
{
fullscreenToggleButton - > setChecked ( fullscreenToggleButtonFS - > isChecked ( ) ) ;
toggleFullScreen ( ) ;
}
void VOIPChatWidgetHolder : : toggleFullScreen ( )
{
if ( fullscreenToggleButton - > isChecked ( ) ) {
fullscreenToggleButton - > setToolTip ( tr ( " Return to normal view. " ) ) ;
2015-10-02 20:11:52 -04:00
inputVideoDevice - > setEchoVideoTarget ( echoVideoDeviceFS ) ;
videoProcessor - > setDisplayTarget ( outputVideoDeviceFS ) ;
fullScreenFrame - > show ( ) ;
2015-10-01 17:41:34 -04:00
} else {
mChatWidget - > hideChatText ( false ) ;
2015-10-04 08:12:20 -04:00
fullscreenToggleButton - > setToolTip ( tr ( " Fullscreen mode " ) ) ;
2015-10-02 20:11:52 -04:00
inputVideoDevice - > setEchoVideoTarget ( echoVideoDevice ) ;
videoProcessor - > setDisplayTarget ( outputVideoDevice ) ;
fullScreenFrame - > hide ( ) ;
2015-10-01 17:41:34 -04:00
}
2015-10-04 08:12:20 -04:00
fullscreenToggleButtonFS - > setChecked ( fullscreenToggleButton - > isChecked ( ) ) ;
fullscreenToggleButtonFS - > setToolTip ( fullscreenToggleButton - > toolTip ( ) ) ;
}
void VOIPChatWidgetHolder : : replaceFullscreenWidget ( )
{
2015-10-05 15:04:20 -04:00
if ( QSize ( toolBarFS - > geometry ( ) . size ( ) - fullScreenFrame - > geometry ( ) . size ( ) ) . isValid ( ) ) {
QRect fsRect = fullScreenFrame - > geometry ( ) ;
fsRect . setSize ( toolBarFS - > geometry ( ) . size ( ) ) ;
fullScreenFrame - > setGeometry ( fsRect ) ;
}
2015-10-04 08:12:20 -04:00
outputVideoDeviceFS - > setGeometry ( QRect ( QPoint ( 0 , 0 ) , fullScreenFrame - > geometry ( ) . size ( ) ) ) ;
echoVideoDeviceFS - > setGeometry ( QRect ( QPoint ( fullScreenFrame - > width ( ) , fullScreenFrame - > height ( ) ) - QPoint ( 320 , 240 ) , QSize ( 320 , 240 ) ) ) ;
QRect toolBarFSGeo = QRect ( ( fullScreenFrame - > width ( ) - toolBarFS - > geometry ( ) . width ( ) ) / 2
2015-10-12 17:17:00 -04:00
, fullScreenFrame - > height ( ) - ( toolBarFS - > geometry ( ) . height ( ) * 2 )
2015-10-04 08:12:20 -04:00
, toolBarFS - > geometry ( ) . width ( ) , toolBarFS - > geometry ( ) . height ( ) ) ;
toolBarFS - > setGeometry ( toolBarFSGeo ) ;
if ( ! videoCaptureToggleButton - > isChecked ( ) ) {
outputVideoDeviceFS - > showFrameOff ( ) ;
echoVideoDeviceFS - > showFrameOff ( ) ;
}
2015-10-02 20:11:52 -04:00
}
2015-10-04 08:12:20 -04:00
void VOIPChatWidgetHolder : : showNormalView ( )
2015-10-02 20:11:52 -04:00
{
hideChatTextToggleButton - > setChecked ( false ) ;
toggleHideChatText ( ) ;
2015-10-04 08:12:20 -04:00
fullscreenToggleButton - > setChecked ( false ) ;
fullscreenToggleButtonFS - > setChecked ( false ) ;
toggleFullScreen ( ) ;
2015-10-01 17:41:34 -04:00
}
2015-10-10 09:21:59 -04:00
void VOIPChatWidgetHolder : : botMouseEnterTake ( )
2015-05-11 15:40:07 -04:00
{
RSButtonOnText * source = qobject_cast < RSButtonOnText * > ( QObject : : sender ( ) ) ;
if ( source ) {
2015-05-22 12:02:16 -04:00
source - > setStyleSheet ( QString ( " border: 1px solid #333333; " )
2015-10-10 09:21:59 -04:00
. append ( " font-size: 12pt; color: white; " )
. append ( " min-width: 128px; min-height: 24px; " )
. append ( " border-radius: 6px; " )
2015-10-12 18:38:46 -04:00
. append ( " padding: 3px; " )
2015-10-10 09:21:59 -04:00
. append ( " background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 0.67, "
2015-10-27 13:52:01 -04:00
" stop: 0 #444444, stop: 1 #222222); " )
2015-10-10 09:21:59 -04:00
) ;
2015-05-11 15:40:07 -04:00
//source->setDown(true);
}
}
2015-10-10 09:21:59 -04:00
void VOIPChatWidgetHolder : : botMouseLeaveTake ( )
2015-05-11 15:40:07 -04:00
{
RSButtonOnText * source = qobject_cast < RSButtonOnText * > ( QObject : : sender ( ) ) ;
if ( source ) {
2015-10-12 18:38:46 -04:00
source - > setStyleSheet ( QString ( " border: 1px solid #116a06; " )
2015-10-10 09:21:59 -04:00
. append ( " font-size: 12pt; color: white; " )
. append ( " min-width: 128px; min-height: 24px; " )
. append ( " border-radius: 6px; " )
2015-10-12 18:38:46 -04:00
. append ( " padding: 3px; " )
2015-10-27 13:52:01 -04:00
. append ( " background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(153, 240, 143, 255), "
" stop:0.494318 rgba(59, 201, 40, 255), stop:0.505682 rgba(46, 172, 29, 255), stop:1 rgba(30, 116, 20, 255)); " )
2015-10-10 09:21:59 -04:00
) ;
//source->setDown(false);
}
}
2015-05-22 12:02:16 -04:00
2015-10-10 09:21:59 -04:00
void VOIPChatWidgetHolder : : botMouseEnterDecline ( )
{
RSButtonOnText * source = qobject_cast < RSButtonOnText * > ( QObject : : sender ( ) ) ;
if ( source ) {
source - > setStyleSheet ( QString ( " border: 1px solid #333333; " )
. append ( " font-size: 12pt; color: white; " )
. append ( " min-width: 128px; min-height: 24px; " )
. append ( " border-radius: 6px; " )
2015-10-12 18:38:46 -04:00
. append ( " padding: 3px; " )
2015-10-27 13:52:01 -04:00
. append ( " background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 0.67, "
" stop: 0 #444444, stop: 1 #222222); " )
2015-10-10 09:21:59 -04:00
) ;
//source->setDown(true);
}
}
void VOIPChatWidgetHolder : : botMouseLeaveDecline ( )
{
RSButtonOnText * source = qobject_cast < RSButtonOnText * > ( QObject : : sender ( ) ) ;
if ( source ) {
2015-10-12 18:38:46 -04:00
source - > setStyleSheet ( QString ( " border: 1px solid #6a1106; " )
2015-10-10 09:21:59 -04:00
. append ( " font-size: 12pt; color: white; " )
. append ( " min-width: 128px; min-height: 24px; " )
2015-10-12 18:38:46 -04:00
. append ( " border-radius: 6px; " )
. append ( " padding: 3px; " )
2015-10-27 13:52:01 -04:00
. append ( " background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(240, 154, 143, 255), "
" stop:0.494318 rgba(201, 57, 40, 255), stop:0.505682 rgba(172, 45, 29, 255), stop:1 rgba(116, 30, 20, 255)); " )
2015-10-10 09:21:59 -04:00
) ;
2015-05-11 15:40:07 -04:00
//source->setDown(false);
}
2014-07-15 16:04:31 -04:00
}
2015-05-26 11:19:57 -04:00
void VOIPChatWidgetHolder : : setAcceptedBandwidth ( uint32_t bytes_per_sec )
2014-07-20 16:50:36 -04:00
{
2015-08-24 21:15:33 -04:00
videoProcessor - > setMaximumBandwidth ( bytes_per_sec ) ;
2014-07-20 16:50:36 -04:00
}
2015-05-26 11:19:57 -04:00
void VOIPChatWidgetHolder : : addAudioData ( const RsPeerId & peer_id , QByteArray * array )
2014-07-13 09:57:25 -04:00
{
2015-10-10 09:21:59 -04:00
sendAudioRingTime = - 2 ; //Receive Audio so Accepted
2014-07-13 09:57:25 -04:00
if ( ! audioCaptureToggleButton - > isChecked ( ) ) {
2015-10-10 09:21:59 -04:00
addNewAudioButtonMap ( peer_id ) ;
2014-07-13 09:57:25 -04:00
return ;
}
if ( ! outputAudioDevice ) {
outputAudioDevice = AudioDeviceHelper : : getDefaultOutputDevice ( ) ;
}
if ( ! outputAudioProcessor ) {
//start output audio device
outputAudioProcessor = new QtSpeex : : SpeexOutputProcessor ( ) ;
if ( inputAudioProcessor ) {
connect ( outputAudioProcessor , SIGNAL ( playingFrame ( QByteArray * ) ) , inputAudioProcessor , SLOT ( addEchoFrame ( QByteArray * ) ) ) ;
}
outputAudioProcessor - > open ( QIODevice : : ReadOnly | QIODevice : : Unbuffered ) ;
outputAudioDevice - > start ( outputAudioProcessor ) ;
}
if ( outputAudioDevice & & outputAudioDevice - > error ( ) ! = QAudio : : NoError ) {
std : : cerr < < " Restarting output device. Error before reset " < < outputAudioDevice - > error ( ) < < " buffer size : " < < outputAudioDevice - > bufferSize ( ) < < std : : endl ;
outputAudioDevice - > stop ( ) ;
outputAudioDevice - > reset ( ) ;
if ( outputAudioDevice - > error ( ) = = QAudio : : UnderrunError )
outputAudioDevice - > setBufferSize ( 20 ) ;
outputAudioDevice - > start ( outputAudioProcessor ) ;
}
2015-05-26 11:19:57 -04:00
outputAudioProcessor - > putNetworkPacket ( QString : : fromStdString ( peer_id . toStdString ( ) ) , * array ) ;
2014-07-13 09:57:25 -04:00
//check the input device for errors
if ( inputAudioDevice & & inputAudioDevice - > error ( ) ! = QAudio : : NoError ) {
std : : cerr < < " Restarting input device. Error before reset " < < inputAudioDevice - > error ( ) < < std : : endl ;
inputAudioDevice - > stop ( ) ;
inputAudioDevice - > reset ( ) ;
inputAudioDevice - > start ( inputAudioProcessor ) ;
}
}
2014-07-15 16:04:31 -04:00
void VOIPChatWidgetHolder : : sendVideoData ( )
{
2015-05-11 15:40:07 -04:00
RsVOIPDataChunk chunk ;
2014-07-15 16:04:31 -04:00
while ( inputVideoDevice & & inputVideoDevice - > getNextEncodedPacket ( chunk ) )
2015-10-10 09:21:59 -04:00
rsVOIP - > sendVoipData ( mChatWidget - > getChatId ( ) . toPeerId ( ) , chunk ) ;
2014-07-15 16:04:31 -04:00
}
2014-07-13 09:57:25 -04:00
void VOIPChatWidgetHolder : : sendAudioData ( )
{
while ( inputAudioProcessor & & inputAudioProcessor - > hasPendingPackets ( ) ) {
QByteArray qbarray = inputAudioProcessor - > getNetworkPacket ( ) ;
2015-05-11 15:40:07 -04:00
RsVOIPDataChunk chunk ;
2014-07-13 09:57:25 -04:00
chunk . size = qbarray . size ( ) ;
chunk . data = ( void * ) qbarray . constData ( ) ;
2015-10-10 09:21:59 -04:00
chunk . type = RsVOIPDataChunk : : RS_VOIP_DATA_TYPE_AUDIO ;
2015-05-11 15:40:07 -04:00
rsVOIP - > sendVoipData ( mChatWidget - > getChatId ( ) . toPeerId ( ) , chunk ) ;
2014-07-13 09:57:25 -04:00
}
}
void VOIPChatWidgetHolder : : updateStatus ( int status )
{
2015-10-04 08:12:20 -04:00
bool enabled = ( status ! = RS_STATUS_OFFLINE ) ;
2015-10-10 09:21:59 -04:00
audioListenToggleButton - > setEnabled ( audioCaptureToggleButton - > isChecked ( ) & & enabled ) ;
audioListenToggleButtonFS - > setEnabled ( audioCaptureToggleButton - > isChecked ( ) & & enabled ) ;
2015-10-04 08:12:20 -04:00
audioCaptureToggleButton - > setEnabled ( enabled ) ;
audioCaptureToggleButtonFS - > setEnabled ( enabled ) ;
videoCaptureToggleButton - > setEnabled ( enabled ) ;
videoCaptureToggleButtonFS - > setEnabled ( enabled ) ;
hideChatTextToggleButton - > setEnabled ( videoCaptureToggleButton - > isChecked ( ) & & enabled ) ;
fullscreenToggleButton - > setEnabled ( videoCaptureToggleButton - > isChecked ( ) & & enabled ) ;
fullscreenToggleButtonFS - > setEnabled ( videoCaptureToggleButton - > isChecked ( ) & & enabled ) ;
hangupButton - > setEnabled ( enabled ) ;
hangupButtonFS - > setEnabled ( enabled ) ;
2014-07-13 09:57:25 -04:00
}
2015-10-10 09:21:59 -04:00
void VOIPChatWidgetHolder : : ReceivedInvitation ( const RsPeerId & peer_id , int flags )
{
switch ( flags ) {
case RS_VOIP_FLAGS_AUDIO_DATA : {
if ( audioCaptureToggleButton - > isChecked ( ) ) {
if ( recAudioRingTime ! = - 1 )
toggleAudioCapture ( ) ;
} else {
addNewAudioButtonMap ( peer_id ) ;
}
}
break ;
case RS_VOIP_FLAGS_VIDEO_DATA : {
if ( videoCaptureToggleButton - > isChecked ( ) ) {
if ( recVideoRingTime ! = - 1 )
toggleVideoCapture ( ) ;
} else {
addNewVideoButtonMap ( peer_id ) ;
}
}
break ;
default :
std : : cerr < < " VOIPChatWidgetHolder::ReceivedInvitation(): Received unknown flags item # " < < flags < < " : not handled yet ! Sorry " < < std : : endl ;
break ;
}
}
void VOIPChatWidgetHolder : : ReceivedVoipHangUp ( const RsPeerId & peer_id , int flags )
{
switch ( flags ) {
case RS_VOIP_FLAGS_AUDIO_DATA | RS_VOIP_FLAGS_VIDEO_DATA : {
if ( mChatWidget ) {
if ( videoCaptureToggleButton - > isChecked ( ) | | audioCaptureToggleButton - > isChecked ( ) ) {
QString peerName = QString : : fromUtf8 ( rsPeers - > getPeerName ( peer_id ) . c_str ( ) ) ;
mChatWidget - > addChatMsg ( true , tr ( " VoIP Status " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( )
, tr ( " %1 hang up. Your call is closed. " ) . arg ( peerName ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
}
hangupCall ( ) ;
}
}
break ;
case RS_VOIP_FLAGS_AUDIO_DATA : {
if ( mChatWidget ) {
if ( audioCaptureToggleButton - > isChecked ( ) ) {
QString peerName = QString : : fromUtf8 ( rsPeers - > getPeerName ( peer_id ) . c_str ( ) ) ;
mChatWidget - > addChatMsg ( true , tr ( " VoIP Status " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( )
, tr ( " %1 hang up. Your audio call is closed. " ) . arg ( peerName ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
}
hangupCallAudio ( ) ;
}
}
break ;
case RS_VOIP_FLAGS_VIDEO_DATA : {
if ( mChatWidget ) {
if ( videoCaptureToggleButton - > isChecked ( ) ) {
QString peerName = QString : : fromUtf8 ( rsPeers - > getPeerName ( peer_id ) . c_str ( ) ) ;
mChatWidget - > addChatMsg ( true , tr ( " VoIP Status " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( )
, tr ( " %1 hang up. Your video call is closed. " ) . arg ( peerName ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
}
hangupCallVideo ( ) ;
}
}
break ;
default :
std : : cerr < < " VOIPChatWidgetHolder::ReceivedVoipHangUp(): Received unknown flags item # " < < flags < < " : not handled yet ! Sorry " < < std : : endl ;
break ;
}
//deleteButtonMap();
}
void VOIPChatWidgetHolder : : ReceivedVoipAccept ( const RsPeerId & peer_id , int flags )
{
switch ( flags ) {
case RS_VOIP_FLAGS_AUDIO_DATA : {
if ( mChatWidget ) {
sendAudioRingTime = - 2 ;
QString peerName = QString : : fromUtf8 ( rsPeers - > getPeerName ( peer_id ) . c_str ( ) ) ;
mChatWidget - > addChatMsg ( true , tr ( " VoIP Status " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( )
, tr ( " %1 accepted your audio call. " ) . arg ( peerName ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
if ( audioCaptureToggleButton - > isChecked ( ) )
toggleAudioCapture ( ) ;
}
}
break ;
case RS_VOIP_FLAGS_VIDEO_DATA : {
if ( mChatWidget ) {
sendVideoRingTime = - 2 ;
QString peerName = QString : : fromUtf8 ( rsPeers - > getPeerName ( peer_id ) . c_str ( ) ) ;
mChatWidget - > addChatMsg ( true , tr ( " VoIP Status " ) , QDateTime : : currentDateTime ( ) , QDateTime : : currentDateTime ( )
, tr ( " %1 accepted your video call. " ) . arg ( peerName ) , ChatWidget : : MSGTYPE_SYSTEM ) ;
if ( videoCaptureToggleButton - > isChecked ( ) )
toggleVideoCapture ( ) ;
}
}
break ;
default :
std : : cerr < < " VOIPChatWidgetHolder::ReceivedVoipHangUp(): Received unknown flags item # " < < flags < < " : not handled yet ! Sorry " < < std : : endl ;
break ;
}
}
void VOIPChatWidgetHolder : : timerAudioRingTimeOut ( )
{
//Sending or receiving (-2 connected, -1 reseted, >=0 in progress)
if ( sendAudioRingTime > = 0 ) {
//Sending
+ + sendAudioRingTime ;
if ( sendAudioRingTime = = 100 ) sendAudioRingTime = 0 ;
pbAudioRing - > setValue ( sendAudioRingTime ) ;
pbAudioRing - > setToolTip ( tr ( " Waiting your friend respond your audio call. " ) ) ;
pbAudioRing - > setVisible ( true ) ;
2015-10-12 12:25:03 -04:00
if ( time ( NULL ) > lastTimePlayOccurs ) {
soundManager - > play ( VOIP_SOUND_OUTGOING_AUDIO_CALL ) ;
lastTimePlayOccurs = time ( NULL ) + 1 ;
}
2015-10-10 09:21:59 -04:00
timerAudioRing - > start ( ) ;
} else if ( recAudioRingTime > = 0 ) {
//Receiving
+ + recAudioRingTime ;
if ( recAudioRingTime = = 100 ) recAudioRingTime = 0 ;
pbAudioRing - > setValue ( recAudioRingTime ) ;
pbAudioRing - > setToolTip ( tr ( " Your friend is calling you for audio. Respond. " ) ) ;
pbAudioRing - > setVisible ( true ) ;
//launch an animation. Don't launch it if already animating
if ( ! audioCaptureToggleButton - > graphicsEffect ( )
| | ( audioCaptureToggleButton - > graphicsEffect ( ) - > inherits ( " QGraphicsOpacityEffect " )
& & ( ( QGraphicsOpacityEffect * ) audioCaptureToggleButton - > graphicsEffect ( ) ) - > opacity ( ) = = 1 )
) {
QGraphicsOpacityEffect * effect = new QGraphicsOpacityEffect ( audioListenToggleButton ) ;
audioCaptureToggleButton - > setGraphicsEffect ( effect ) ;
QPropertyAnimation * anim = new QPropertyAnimation ( effect , " opacity " , effect ) ;
anim - > setStartValue ( 1 ) ;
anim - > setKeyValueAt ( 0.5 , 0 ) ;
anim - > setEndValue ( 1 ) ;
anim - > setDuration ( timerAudioRing - > interval ( ) ) ;
anim - > start ( ) ;
}
audioCaptureToggleButton - > setToolTip ( tr ( " Answer " ) ) ;
2015-10-12 12:25:03 -04:00
if ( time ( NULL ) > lastTimePlayOccurs ) {
soundManager - > play ( VOIP_SOUND_INCOMING_AUDIO_CALL ) ;
lastTimePlayOccurs = time ( NULL ) + 1 ;
}
2015-10-11 04:31:06 -04:00
if ( mVOIPNotify ) mVOIPNotify - > notifyReceivedVoipAudioCall ( mChatWidget - > getChatId ( ) . toPeerId ( ) ) ;
2015-10-10 09:21:59 -04:00
timerAudioRing - > start ( ) ;
} else {
//Nothing to do, reset stat
pbAudioRing - > setHidden ( true ) ;
pbAudioRing - > setValue ( 0 ) ;
pbAudioRing - > setToolTip ( " " ) ;
audioCaptureToggleButton - > setGraphicsEffect ( 0 ) ;
}
}
void VOIPChatWidgetHolder : : timerVideoRingTimeOut ( )
{
//Sending or receiving (-2 connected, -1 reseted, >=0 in progress)
if ( sendVideoRingTime > = 0 ) {
//Sending
+ + sendVideoRingTime ;
if ( sendVideoRingTime = = 100 ) sendVideoRingTime = 0 ;
pbVideoRing - > setValue ( sendVideoRingTime ) ;
pbVideoRing - > setToolTip ( tr ( " Waiting your friend respond your video call. " ) ) ;
pbVideoRing - > setVisible ( true ) ;
2015-10-12 12:25:03 -04:00
if ( time ( NULL ) > lastTimePlayOccurs ) {
soundManager - > play ( VOIP_SOUND_OUTGOING_VIDEO_CALL ) ;
lastTimePlayOccurs = time ( NULL ) + 1 ;
}
2015-10-10 09:21:59 -04:00
timerVideoRing - > start ( ) ;
} else if ( recVideoRingTime > = 0 ) {
//Receiving
+ + recVideoRingTime ;
if ( recVideoRingTime = = 100 ) recVideoRingTime = 0 ;
pbVideoRing - > setValue ( recVideoRingTime ) ;
pbVideoRing - > setToolTip ( tr ( " Your friend is calling you for video. Respond. " ) ) ;
pbVideoRing - > setVisible ( true ) ;
//launch an animation. Don't launch it if already animating
if ( ! videoCaptureToggleButton - > graphicsEffect ( )
| | ( videoCaptureToggleButton - > graphicsEffect ( ) - > inherits ( " QGraphicsOpacityEffect " )
& & ( ( QGraphicsOpacityEffect * ) videoCaptureToggleButton - > graphicsEffect ( ) ) - > opacity ( ) = = 1 )
) {
QGraphicsOpacityEffect * effect = new QGraphicsOpacityEffect ( audioListenToggleButton ) ;
videoCaptureToggleButton - > setGraphicsEffect ( effect ) ;
QPropertyAnimation * anim = new QPropertyAnimation ( effect , " opacity " , effect ) ;
anim - > setStartValue ( 1 ) ;
anim - > setKeyValueAt ( 0.5 , 0 ) ;
anim - > setEndValue ( 1 ) ;
anim - > setDuration ( timerVideoRing - > interval ( ) ) ;
anim - > start ( ) ;
}
videoCaptureToggleButton - > setToolTip ( tr ( " Answer " ) ) ;
2015-10-12 12:25:03 -04:00
if ( time ( NULL ) > lastTimePlayOccurs ) {
soundManager - > play ( VOIP_SOUND_INCOMING_VIDEO_CALL ) ;
lastTimePlayOccurs = time ( NULL ) + 1 ;
}
2015-10-11 04:31:06 -04:00
if ( mVOIPNotify ) mVOIPNotify - > notifyReceivedVoipVideoCall ( mChatWidget - > getChatId ( ) . toPeerId ( ) ) ;
2015-10-10 09:21:59 -04:00
timerVideoRing - > start ( ) ;
} else {
//Nothing to do, reset stat
pbVideoRing - > setHidden ( true ) ;
pbVideoRing - > setValue ( 0 ) ;
pbVideoRing - > setToolTip ( " " ) ;
videoCaptureToggleButton - > setGraphicsEffect ( 0 ) ;
}
}