| 1 | """ |
|---|
| 2 | QuteCom, a voice over Internet phone |
|---|
| 3 | Copyright (C) Wengo Wengo |
|---|
| 4 | |
|---|
| 5 | This program is free software you can redistribute it and/or modify |
|---|
| 6 | it under the terms of the GNU General Public License as published by |
|---|
| 7 | the Free Software Foundation either version 2 of the License, or |
|---|
| 8 | (at your option) any later version. |
|---|
| 9 | |
|---|
| 10 | This program is distributed in the hope that it will be useful, |
|---|
| 11 | but WITHOUT ANY WARRANTY without even the implied warranty of |
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | GNU General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU General Public License |
|---|
| 16 | along with this program if not, write to the Free Software |
|---|
| 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 18 | """ |
|---|
| 19 | |
|---|
| 20 | """ |
|---|
| 21 | Test program for PyCoIpManager |
|---|
| 22 | |
|---|
| 23 | @author Ovidiu Ciule |
|---|
| 24 | @author Philippe Bernery |
|---|
| 25 | """ |
|---|
| 26 | |
|---|
| 27 | from SafeConnect import * |
|---|
| 28 | from CallWidget_ui import Ui_CallWidget |
|---|
| 29 | from QVideoWidget import QVideoWidget |
|---|
| 30 | from PyQt4 import QtCore, QtGui |
|---|
| 31 | from PyCoIpManager import * |
|---|
| 32 | import logging, sys |
|---|
| 33 | |
|---|
| 34 | log = logging.getLogger("PyWengoCall") |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | class CallWidget(QtGui.QWidget): |
|---|
| 38 | |
|---|
| 39 | def __init__(self, tCoIpManager): |
|---|
| 40 | self._tCoIpManager = tCoIpManager |
|---|
| 41 | self._tCallSession = None |
|---|
| 42 | self._ctImages = 0 |
|---|
| 43 | |
|---|
| 44 | # Init GUI |
|---|
| 45 | QtGui.QWidget.__init__(self, None) |
|---|
| 46 | self._ui = Ui_CallWidget() |
|---|
| 47 | self._ui.setupUi(self) |
|---|
| 48 | |
|---|
| 49 | connect(self._ui.callButton, QtCore.SIGNAL("clicked()"), self.callButtonClicked) |
|---|
| 50 | connect(self._ui.hangUpButton, QtCore.SIGNAL("clicked()"), self.hangUpButtonClicked) |
|---|
| 51 | |
|---|
| 52 | self._ui.hangUpButton.setEnabled(False) |
|---|
| 53 | self._ui.phoneNumberLineEdit.setText("sip:335@voip.qutecom.fr") |
|---|
| 54 | |
|---|
| 55 | def callButtonClicked(self): |
|---|
| 56 | self._tCallSession = self._tCoIpManager.getTCallSessionManager().createTCallSession() |
|---|
| 57 | |
|---|
| 58 | connect(self._tCallSession, |
|---|
| 59 | QtCore.SIGNAL("videoFrameReceivedSignal2(QImage, QImage)"), |
|---|
| 60 | self.videoFrameReceivedSlot) |
|---|
| 61 | connect(self._tCallSession, |
|---|
| 62 | QtCore.SIGNAL("phoneCallStateChangedSignal(EnumPhoneCallState::PhoneCallState)"), |
|---|
| 63 | self.phoneCallStateChangedSlot) |
|---|
| 64 | |
|---|
| 65 | contact = Contact() |
|---|
| 66 | contact.addIMContact(IMContact(EnumAccountType.AccountTypeWengo, |
|---|
| 67 | str(self._ui.phoneNumberLineEdit.text()))) |
|---|
| 68 | self._tCallSession.addContact(contact) |
|---|
| 69 | self._tCallSession.enableVideo(True) |
|---|
| 70 | self._tCallSession.start() |
|---|
| 71 | self._ctImages = 0 |
|---|
| 72 | |
|---|
| 73 | def hangUpButtonClicked(self): |
|---|
| 74 | self.callSessionEnd() |
|---|
| 75 | |
|---|
| 76 | def phoneCallStateChangedSlot(self, state): |
|---|
| 77 | try: |
|---|
| 78 | {EnumPhoneCallState.PhoneCallStateUnknown: self.callSessionEnd, |
|---|
| 79 | EnumPhoneCallState.PhoneCallStateClosed: self.callSessionEnd, |
|---|
| 80 | EnumPhoneCallState.PhoneCallStateError: self.callSessionEnd, |
|---|
| 81 | |
|---|
| 82 | EnumPhoneCallState.PhoneCallStateTalking: self.callSessionStart, |
|---|
| 83 | EnumPhoneCallState.PhoneCallStateDialing: self.callSessionStart, |
|---|
| 84 | EnumPhoneCallState.PhoneCallStateRinging: self.callSessionStart |
|---|
| 85 | }[state]() |
|---|
| 86 | except KeyError: pass |
|---|
| 87 | |
|---|
| 88 | def callSessionEnd(self): |
|---|
| 89 | if (self._tCallSession!=None): |
|---|
| 90 | QtCore.QObject.disconnect(self._tCallSession, |
|---|
| 91 | QtCore.SIGNAL("videoFrameReceivedSignal(piximage *, piximage *)"), |
|---|
| 92 | self.videoFrameReceivedSlot) |
|---|
| 93 | disconnect(self._tCallSession, |
|---|
| 94 | QtCore.SIGNAL("phoneCallStateChangedSignal(EnumPhoneCallState::PhoneCallState)"), |
|---|
| 95 | self.phoneCallStateChangedSlot) |
|---|
| 96 | |
|---|
| 97 | self._tCallSession.stop() |
|---|
| 98 | self._tCallSession = None |
|---|
| 99 | self._ui.hangUpButton.setEnabled(False) |
|---|
| 100 | self._ui.callButton.setEnabled(True) |
|---|
| 101 | |
|---|
| 102 | def callSessionStart(self): |
|---|
| 103 | self._ui.hangUpButton.setEnabled(True) |
|---|
| 104 | self._ui.callButton.setEnabled(False) |
|---|
| 105 | |
|---|
| 106 | def videoFrameReceivedSlot(self, remoteVideoFrame, localVideoFrame): |
|---|
| 107 | self._ui.localWebcamLabel.setImage(localVideoFrame) |
|---|
| 108 | self._ui.remoteWebcamLabel.setImage(remoteVideoFrame) |
|---|
| 109 | |
|---|
| 110 | def closeEvent(self, event): |
|---|
| 111 | self.callSessionEnd() |
|---|
| 112 | event.accept() |
|---|
| 113 | self.emit(QtCore.SIGNAL("closing()")) |
|---|