Blame view

LiveChat/FeiTalk/JusCall/SessionVoice.cpp 7.74 KB
9f17d59e   陈明泉   no message
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
  /************************************************************************
  
          Copyright (c) 2005-2012 by Juphoon System Software Co., Ltd.
                         All rights reserved.
  
       This software is confidential and proprietary to Juphoon System Software Co.,
       Ltd.. No part of this software may be reproduced, stored, transmitted,
       disclosed or used in any form or by any means other than as expressly
       provided by the written license agreement between JusTel and its
       licensee.
  
       THIS SOFTWARE IS PROVIDED BY JusTel "AS IS" AND ANY EXPRESS OR 
       IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
       WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
       ARE DISCLAIMED. IN NO EVENT SHALL JusTel BE LIABLE FOR ANY DIRECT, 
       INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
       (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
       OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
       HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
       STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
       IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
       POSSIBILITY OF SUCH DAMAGE. 
  
                      Juphoon System Software Co., Ltd.
  
  ************************************************************************/
  /*************************************************
    File name     : rsessvoice.cpp
    Module        : UI Dialog
    Author       	: vic.ren
    Created on    : 2012-11-05
    Description   :
  	The session dialog
    Modify History:
    1. Date:        Author:         Modification:
  	 2012-11-05   Vic Ren		  Create
  *************************************************/
  #include "JusCallPch.h"
  
  const QSize SIZEAUDIO = QSize(410 + SHADOW_WIDTH, 160 + SHADOW_HEIGHT);
  RSessVoice::RSessVoice(RSession *pSession, QWidget *parent) 
      : RMetroDlg(parent)
      , m_pSession(pSession)
      , m_nSessTime(0)
      , m_pStatistics(ZNULL)
  {
      setWindowFlags(Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint);
      setFocusPolicy(Qt::StrongFocus);
      setAttribute(Qt::WA_DeleteOnClose);
      initDlg();
      updateContact();
  }
  
  void RSessVoice::resizeEvent(QResizeEvent * event)
  {
      RMetroDlg::resizeEvent(event);
      m_pBtnInfo->move(width() - 61, BORDER_TOP);
      m_pLabelName->move(BORDER_LEFT + 7, BORDER_TOP);
      m_pLabelTime->move(width() - BORDER_RIGHT - m_pLabelTime->width() - 10,
          height() - BORDER_BOTTOM - m_pLabelTime->height() - 10);
  
      m_pControlPad->move(BORDER_LEFT + 15, BORDER_TOP + 50);
  }
  
  void RSessVoice::closeEvent(QCloseEvent * event)
  {
      RClient::Instance()->widgetClosed(this);
      if (m_pSession->sessId() != ZINVALIDID)
          Mtc_CallTerm(m_pSession->sessId(), EN_MTC_CALL_TERM_STATUS_NORMAL, ZNULL);
      emit signalVoiceEnded();
      if (m_pStatistics)
          m_pStatistics->close();
  
      RMetroDlg::closeEvent(event);
  }
  
  void RSessVoice::mousePressEvent(QMouseEvent * event)
  {
      if (!event) return;
      RMetroDlg::mousePressEvent(event);
      m_pControlPad->hideVolumeControl();
  }
  
  void RSessVoice::focusOutEvent(QFocusEvent * event)
  {
      QWidget::focusOutEvent(event);
      m_pControlPad->hideVolumeControl();
  }
  
  void RSessVoice::initDlg()
  {
      connect(this, SIGNAL(signalClickedBtnClose()), SLOT(close()));
      connect(this, SIGNAL(signalClickedBtnMin()), SLOT(showMinimized()));
  
      resize(SIZEAUDIO);
      addBoder();
      addTitle("", (EN_UI_DLG_BTN_CLOSE | EN_UI_DLG_BTN_MIN));
      setDragEnabled(true);
  
      m_pBtnInfo = new RRightTopBtn(this, ":/images/ic_btn_information.png");
      m_pBtnInfo->resize(20, 20);
  	connect(m_pBtnInfo, SIGNAL(clicked()), SLOT(slotClickedBtnInfo()));
  
      m_pControlPad = new RControlPad(m_pSession, false, this);
      m_pControlPad->setWindowFlags(Qt::FramelessWindowHint);
      connect(m_pControlPad, SIGNAL(signalClickedBtnAnswer()), 
          SLOT(slotClickedBtnAnswer()));
      connect(m_pControlPad, SIGNAL(signalClickedBtnDecline()), 
          SLOT(slotClickedBtnDecline()));
      connect(m_pControlPad, SIGNAL(signalClickedBtnEnd()), 
          SLOT(slotClickedBtnEnd()));
  
      m_pLabelName = new QLabel(this);
      m_pLabelName->setFixedHeight(38);
      m_pLabelName->setFont(RStyle::fontSize(28));
      m_pLabelName->setAlignment(Qt::AlignBottom);
  
      m_pLabelCurPhone = new QLabel(this);
      m_pLabelCurPhone->setFixedHeight(38);
      m_pLabelCurPhone->setFont(RStyle::fontSize(24));
      m_pLabelCurPhone->setAlignment(Qt::AlignBottom);
  
      m_pLabelTime = new QLabel(this);
      m_pLabelTime->setFont(RStyle::fontSize(14));
      m_pLabelTime->setFixedSize(110, 20);
      m_pLabelTime->setAlignment(Qt::AlignRight);
  }
  
  void RSessVoice::moveToPositon()
  {
      RClient::Instance()->moveToPositon(this);
  }
  
  void RSessVoice::updateContact()
  {
      m_pLabelCurPhone->setText("");
      m_pLabelName->setText("");
      if (!m_pSession) return;
  
      QString qsName = m_pSession->name();
      if (qsName.isEmpty())
          qsName = m_pSession->currentPhone();
      
      setWindowTitle(QString(tr("Voice-")) + qsName);
      m_pLabelName->setText(qsName);
      m_pLabelName->adjustSize();
      
      if (m_pSession->name().isEmpty())
          return;
      
      int nX = m_pLabelName->width() + 20;
      m_pLabelCurPhone->setFixedWidth(340 - m_pLabelName->width());
      
      m_pLabelCurPhone->move(nX, 0);
  	QFontMetrics fmPhone(m_pLabelCurPhone->font());
      QString qsPhone = fmPhone.elidedText(m_pSession->currentPhone(), 
          Qt::ElideRight, m_pLabelCurPhone->width());
      m_pLabelCurPhone->setText(qsPhone);
  }
  
  void RSessVoice::showSessFailed()
  {
      m_pLabelTime->setText(tr("Call failed"));
      QTimer::singleShot(2000, this, SLOT(close()));
  }
  
  void RSessVoice::showSessOut()
  {
      m_pLabelTime->setText(tr("Calling..."));
      m_pControlPad->showSessOut();
  }
  
  void RSessVoice::showSessIncoming()
  {
      m_pControlPad->showSessIncoming();
      m_pLabelTime->setText(tr(""));
      moveToPositon();
  }
  
  void RSessVoice::showSessAlerted()
  {
      m_pLabelTime->setText(tr("Ringing..."));
  }
  
  void RSessVoice::showSessConnecting()
  {
      m_pLabelTime->setText(tr("Connecting..."));
  }
  
  void RSessVoice::showSessTalking()
  {
      m_pLabelTime->setText(tr("00:00"));
      disconnect(&m_TimerSess, SIGNAL(timeout()), 0, 0);
      connect(&m_TimerSess, SIGNAL(timeout()), this, SLOT(slotSessTimer()));
      m_TimerSess.start(1000);
      m_pControlPad->showSessTalking();
  }
  
  void RSessVoice::showSessTermed()
  {
      m_TimerSess.stop();
      m_pLabelTime->setText(tr("Ending..."));
      m_nSessTime = 0;
      QTimer::singleShot(2000, this, SLOT(close()));
      m_pControlPad->showSessTermed();
  }
  
  void RSessVoice::slotClickedBtnInfo()
  {
      if (m_pStatistics)
      {
          m_pStatistics->close();
          m_pStatistics->deleteLater();
          m_pStatistics = ZNULL;
          return;
      }
      m_pStatistics = new RStatistics(m_pSession->sessId());
      connect(m_pStatistics, SIGNAL(signalClosed()), 
          SLOT(slotStatisticsClosed()));
      m_pStatistics->show();
      m_pStatistics->move(x() + 40, y() + 40);
  }
  
  void RSessVoice::slotClickedBtnAnswer()
  {
      Mtc_CallAnswer(m_pSession->sessId(), 0, ZTRUE, ZFALSE);
  }
  
  void RSessVoice::slotClickedBtnDecline()
  {
      Mtc_CallTerm(m_pSession->sessId(), EN_MTC_CALL_TERM_STATUS_DECLINE, ZNULL);
      showSessTermed();
  }
  
  void RSessVoice::slotClickedBtnEnd()
  {
      Mtc_CallTerm(m_pSession->sessId(), EN_MTC_CALL_TERM_STATUS_NORMAL, ZNULL);
      showSessTermed();
  }
  
  void RSessVoice::slotClickedBtnSpkMute()
  {
      //Mtc_CallSetSpkMute(m_pSession->sessId(), m_pBtnSpk->isChecked());
  }
  
  void RSessVoice::slotClickedBtnMicMute()
  {
      //Mtc_CallSetMicMute(m_pSession->sessId(), m_pBtnMic->isChecked());
  }
  
  void RSessVoice::slotStatisticsClosed()
  {
      m_pStatistics = ZNULL;
  }
  
  void RSessVoice::slotSessTimer()
  {
      m_nSessTime ++;
      char strTimer[100] = {0};
      sprintf(strTimer, "%02d:%02d", m_nSessTime/60, m_nSessTime%60);
      m_pLabelTime->setText(QString(strTimer));
  }