From 77e6eaef87941de707155830841cb9e6e31236e4 Mon Sep 17 00:00:00 2001
From: jpbl <jpbl>
Date: Wed, 12 Oct 2005 20:27:47 +0000
Subject: [PATCH] better tone handling and better answering

---
 src/gui/official/PhoneLine.cpp            | 21 +++++++++++++++------
 src/gui/official/PhoneLine.hpp            |  2 +-
 src/gui/official/PhoneLineManagerImpl.cpp | 20 ++++++++++++--------
 src/gui/official/PhoneLineManagerImpl.hpp |  6 +++---
 src/gui/official/SFLEvents.cpp            |  2 +-
 src/gui/official/SFLPhoneApp.cpp          |  1 +
 src/gui/official/Session.cpp              |  6 ++++++
 src/gui/official/Session.hpp              |  1 +
 8 files changed, 40 insertions(+), 19 deletions(-)

diff --git a/src/gui/official/PhoneLine.cpp b/src/gui/official/PhoneLine.cpp
index e3ddc1a58b..fe8f61d607 100644
--- a/src/gui/official/PhoneLine.cpp
+++ b/src/gui/official/PhoneLine.cpp
@@ -268,14 +268,23 @@ PhoneLine::answer()
 }
 
 void 
-PhoneLine::hangup() 
+PhoneLine::hangup(bool sendrequest) 
 {
+  if(sendrequest) {
+    setAction(tr("Hanguping..."));
+  }
+  else {
+    setAction(tr("Hanguped."));
+  }
+
   if(mCall) {
-    setAction("Hanguping...");
-    DebugOutput::instance() << tr("PhoneLine %1: Trying to Hangup.\n").arg(mLine);
-    mCall->hangup();
-    delete mCall;
-    mCall = NULL;
+    if(sendrequest) {
+      mCall->hangup();
+    }
+    else {
+      delete mCall;
+      mCall = NULL;
+    }
   }
   else {
     clear();
diff --git a/src/gui/official/PhoneLine.hpp b/src/gui/official/PhoneLine.hpp
index 03b1b22bf9..6c1d74fdab 100644
--- a/src/gui/official/PhoneLine.hpp
+++ b/src/gui/official/PhoneLine.hpp
@@ -21,7 +21,7 @@ public:
   void call(const QString &to);
   void call();
   void answer();
-  void hangup();
+  void hangup(bool sendrequest = true);
   void hold();
   void unhold();
 
diff --git a/src/gui/official/PhoneLineManagerImpl.cpp b/src/gui/official/PhoneLineManagerImpl.cpp
index d6291187cb..74805de378 100644
--- a/src/gui/official/PhoneLineManagerImpl.cpp
+++ b/src/gui/official/PhoneLineManagerImpl.cpp
@@ -424,12 +424,13 @@ PhoneLineManagerImpl::hold()
   mCurrentLineMutex.unlock();
 
   if(selectedLine) {
+    mSession->stopTone();
     selectedLine->hold();
   }
 }
 
 void
-PhoneLineManagerImpl::hangup()
+PhoneLineManagerImpl::hangup(bool sendrequest)
 {
   mCurrentLineMutex.lock();
   PhoneLine *selectedLine = mCurrentLine;
@@ -438,7 +439,8 @@ PhoneLineManagerImpl::hangup()
   mCurrentLineMutex.unlock();
 
   if(selectedLine) {
-    selectedLine->hangup();
+    mSession->stopTone();
+    selectedLine->hangup(sendrequest);
     lineStatusSet("");
   }
 }
@@ -471,22 +473,24 @@ PhoneLineManagerImpl::unmute()
 }
 
 void
-PhoneLineManagerImpl::hangup(const QString &callId)
+PhoneLineManagerImpl::hangup(const QString &callId, bool sendrequest)
 {
   PhoneLine *selectedLine = getPhoneLine(callId);
   if(selectedLine) {
+    mSession->stopTone();
     PhoneLineLocker guard(selectedLine);
-    selectedLine->hangup();
+    selectedLine->hangup(sendrequest);
   }
 }
 
 void
-PhoneLineManagerImpl::hangup(unsigned int line)
+PhoneLineManagerImpl::hangup(unsigned int line, bool sendrequest)
 {
   PhoneLine *selectedLine = getPhoneLine(line);
   if(selectedLine) {
+    mSession->stopTone();
     PhoneLineLocker guard(selectedLine);
-    selectedLine->hangup();
+    selectedLine->hangup(sendrequest);
   }
 }
 
@@ -505,8 +509,8 @@ PhoneLineManagerImpl::clear()
 
 void 
 PhoneLineManagerImpl::incomming(const QString &accountId,
-				const QString &peer,
-				const QString &callId)
+				const QString &callId,
+				const QString &peer)
 {
   Call call(mSession->id(), accountId, callId, true);
   addCall(call, peer, "Incomming");
diff --git a/src/gui/official/PhoneLineManagerImpl.hpp b/src/gui/official/PhoneLineManagerImpl.hpp
index e17bdcd1bf..5bbaf0267f 100644
--- a/src/gui/official/PhoneLineManagerImpl.hpp
+++ b/src/gui/official/PhoneLineManagerImpl.hpp
@@ -95,7 +95,7 @@ public slots:
    * This function will hanp up the current line
    * If there's no current line, it will do nothing.
    */
-  void hangup();
+  void hangup(bool sendrequest = true);
 
   /**
    * This function will mute the microphone if muting
@@ -118,14 +118,14 @@ public slots:
    * argument. Be aware that the first line is 1, not 
    * zero.
    */
-  void hangup(unsigned int line);
+  void hangup(unsigned int line, bool sendrequest = true);
 
   /**
    * This function will hanp up the line with the
    * following call ID. If there's no line with 
    * the call ID, it will do nothing.
    */
-  void hangup(const QString &callId);
+  void hangup(const QString &callId, bool sendrequest = true);
 
   /**
    * This function will make a call on the 
diff --git a/src/gui/official/SFLEvents.cpp b/src/gui/official/SFLEvents.cpp
index 6e191bb174..e985b065e3 100644
--- a/src/gui/official/SFLEvents.cpp
+++ b/src/gui/official/SFLEvents.cpp
@@ -28,7 +28,7 @@ HangupEvent::execute()
   if(id.length() > 0) {
     DebugOutput::instance() << QObject::tr("Hangup Event received for call ID: %1.\n")
       .arg(id);
-    PhoneLineManager::instance().hangup(id);
+    PhoneLineManager::instance().hangup(id, false);
   }
   else {
     DebugOutput::instance() << QObject::tr("Hangup Event invalid (missing call ID): %1\n")
diff --git a/src/gui/official/SFLPhoneApp.cpp b/src/gui/official/SFLPhoneApp.cpp
index 486c1c1d28..05f4785ade 100644
--- a/src/gui/official/SFLPhoneApp.cpp
+++ b/src/gui/official/SFLPhoneApp.cpp
@@ -20,6 +20,7 @@ SFLPhoneApp::SFLPhoneApp(int argc, char **argv)
   PhoneLineManager::instance().initialize();
   PhoneLineManager::instance().setNbLines(NB_PHONELINES);
   Requester::instance().registerObject< Request >(QString("playtone"));
+  Requester::instance().registerObject< Request >(QString("stoptone"));
   Requester::instance().registerObject< Request >(QString("playdtmf"));
   Requester::instance().registerObject< CallRequest >(QString("call"));
   Requester::instance().registerObject< EventRequest >(QString("getevents"));
diff --git a/src/gui/official/Session.cpp b/src/gui/official/Session.cpp
index 3e8c0b1dfc..815baea42d 100644
--- a/src/gui/official/Session.cpp
+++ b/src/gui/official/Session.cpp
@@ -49,6 +49,12 @@ Session::playTone() const
   return Requester::instance().send(mId, "playtone", std::list< QString >());
 }
 
+QString
+Session::stopTone() const
+{
+  return Requester::instance().send(mId, "stoptone", std::list< QString >());
+}
+
 void
 Session::connect() const
 {
diff --git a/src/gui/official/Session.hpp b/src/gui/official/Session.hpp
index 6af32f0e93..7062f03bf9 100644
--- a/src/gui/official/Session.hpp
+++ b/src/gui/official/Session.hpp
@@ -83,6 +83,7 @@ class Session
   void connect() const;
 
   QString id() const;
+  QString stopTone() const;
   QString playTone() const;
 
  private:
-- 
GitLab