From 995af2f92460474e980f8d50e9fa2ec9b9bed104 Mon Sep 17 00:00:00 2001
From: llea <llea>
Date: Fri, 29 Jul 2005 21:22:27 +0000
Subject: [PATCH] Add scrolling message

---
 ChangeLog                      |   3 +
 src/error.cpp                  |   2 +-
 src/gui/guiframework.h         |   2 +-
 src/gui/qt/Makefile.am         |   1 +
 src/gui/qt/mydisplay.cpp       |  78 +++++++++++++---
 src/gui/qt/mydisplay.h         |  14 +++
 src/gui/qt/phoneline.cpp       |   2 +
 src/gui/qt/phoneline.h         |   8 ++
 src/gui/qt/qtGUImainwindow.cpp | 158 ++++++++++++++++++++-------------
 src/gui/qt/qtGUImainwindow.h   |   2 +-
 src/managerimpl.cpp            |  13 ++-
 src/managerimpl.h              |   2 +-
 src/sipvoiplink.cpp            |  17 ++--
 13 files changed, 209 insertions(+), 93 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 49d5fd6420..d8981b5ecd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+Laurielle LEA (29 July 2005) version 0.4
+- Add scrolling message
+
 Laurielle LEA (27 July 2005) version 0.4
 - Migrate from libeXoSIP 0.9.0 to libeXosip2-1.9.1-pre15 
 (http://www.antisip.com/download/)
diff --git a/src/error.cpp b/src/error.cpp
index 1e39e3e420..57395a10c2 100644
--- a/src/error.cpp
+++ b/src/error.cpp
@@ -35,7 +35,7 @@ Error::errorName (Error_enum num_name) {
 	switch (num_name){
 		// Handle opening device errors
 		case OPEN_FAILED_DEVICE:
-			Manager::instance().displayErrorText("Open device failed ");
+			Manager::instance().displayError("Open device failed ");
 			issetError = 2; 
 			break;
 			
diff --git a/src/gui/guiframework.h b/src/gui/guiframework.h
index 738314234f..a667c4b487 100644
--- a/src/gui/guiframework.h
+++ b/src/gui/guiframework.h
@@ -37,7 +37,7 @@ public:
 	virtual int peerRingingCall (short id) = 0;
 	virtual int peerHungupCall (short id) = 0;
 	virtual void displayTextMessage (short id, const string& message) = 0;
-	virtual void displayErrorText (const string& message) = 0;
+	virtual void displayErrorText (short id, const string& message) = 0;
 	virtual void displayError (const string& error) = 0;
 	virtual void displayStatus (const string& status) = 0;
 	virtual void displayContext (short id) = 0;
diff --git a/src/gui/qt/Makefile.am b/src/gui/qt/Makefile.am
index d0b660fb58..d6cd37a5cf 100644
--- a/src/gui/qt/Makefile.am
+++ b/src/gui/qt/Makefile.am
@@ -11,6 +11,7 @@ BUILT_SOURCES = \
 	trayiconmoc.cpp\
 	volumecontrolmoc.cpp\
 	numerickeypadmoc.cpp \
+	mydisplaymoc.cpp \
 	qtGUImainwindowmoc.cpp
 
 libsflphoneqt_la_SOURCES = \
diff --git a/src/gui/qt/mydisplay.cpp b/src/gui/qt/mydisplay.cpp
index 9d3891125d..c1432d522b 100644
--- a/src/gui/qt/mydisplay.cpp
+++ b/src/gui/qt/mydisplay.cpp
@@ -89,6 +89,13 @@ MyDisplay::MyDisplay (QWidget *parent, const char *name, QtGUIMainWindow* qtgui)
 	_qtgui = qtgui;
 	this->initGraphics();
 	this->initText();
+
+	// For scrolling text
+	_timerForScrollingText = new QTimer(this);
+	connect (_timerForScrollingText, SIGNAL(timeout()), SLOT(shift()));
+	//emit signal every second
+	_timerForScrollingText->start(2000); 	
+	
 	// Graphics engine animation thread
 	_animationThread = new MyDisplayThread (this);
 	_animationThread->start();
@@ -103,6 +110,8 @@ MyDisplay::~MyDisplay (void) {
 	delete _qtgui;
 	delete _status;
 	delete _time;
+	_timerForScrollingText->stop();
+	delete _timerForScrollingText;
 }
 
 /**
@@ -191,6 +200,10 @@ MyDisplay::initText (void) {
 	_status = new QString(FREE_STATUS);
 	// No display call-timer
 	_inFunction = false;
+	// No scrolling
+	_isScrolling = false;
+	_reset = false;
+	len_to_shift = 0;
 }
 
 /**
@@ -211,23 +224,62 @@ MyDisplay::renderText (QPainter &painter, QFontMetrics &fm, QString &str) {
 	uint	 x_offset = 0;
 	uint	 extra_chars = 0;
 	QString	 backup_string(".");
+	QString str_tmp = str;
+
+	// If call is closed, reset len_to_shift to 0
+	if (getReset()) {
+		len_to_shift = 0;
+	}
 	
-	// If the string is larger than the screen...
-	if (fm.width(str) > (_centerImage.width() - 5)) {
-		extra_chars = str.length() - cpl;
-		x_offset = fm.width(str[0]) * extra_chars;
-
-		// Hack the scrolled string to inform the user
-		backup_string[0] = str[extra_chars];
-		str.replace (extra_chars, backup_string.length(),QString("<"));
+	// If don't need scrolling message
+	if (!getIsScrolling()) {
+		// If the string is larger than the screen...
+		if (fm.width(str) > (_centerImage.width() - 5)) {
+			extra_chars = str.length() - cpl;
+			x_offset = fm.width(str[0]) * extra_chars;
+
+			// Hack the scrolled string to inform the user
+			backup_string[0] = str[extra_chars];
+			str.replace (extra_chars, backup_string.length(),QString("<"));
+		}
+		// Render text
+		painter.drawText (TABULATION - x_offset, fm.height() * TEXT_LINE, str);
+		if (fm.width(str) > (_centerImage.width() - 5)) {
+			// Restore initial string.
+			str.replace(extra_chars, backup_string.length(), backup_string);
+		}
+	} else {
+		// if need scrolling text
+		if (_shift) {
+			len_to_shift += 1;
+		}
+
+		if (str.length() > cpl) {
+			str_tmp = str.left(len_to_shift);
+		} 
+		if (len_to_shift == cpl) {
+			str_tmp = str.right(len_to_shift);
+		}
+		if (len_to_shift == str.length()*2) {
+			str_tmp = str.left(len_to_shift);
+			len_to_shift = 0;
+		}
+
+		painter.drawText (TABULATION + _centerImage.width() - 
+				len_to_shift * fm.width(str[0]), 
+				fm.height() * TEXT_LINE, str_tmp);
 	}
 	
-	// Render text
-	painter.drawText (TABULATION - x_offset, fm.height() * TEXT_LINE, str);
+}
 
-	if (fm.width(str) > (_centerImage.width() - 5)) {
-		// Restore initial string.
-		str.replace(extra_chars, backup_string.length(), backup_string);
+void
+MyDisplay::shift (void)
+{
+	if (getReset()) {
+		_shift = false;
+		len_to_shift = 0;
+	} else {
+		_shift = true;
 	}
 }
 
diff --git a/src/gui/qt/mydisplay.h b/src/gui/qt/mydisplay.h
index 881975b4bb..aa5c6eb038 100644
--- a/src/gui/qt/mydisplay.h
+++ b/src/gui/qt/mydisplay.h
@@ -25,6 +25,7 @@
 #include <qsettings.h>
 #include <qstring.h>
 #include <qthread.h>
+#include <qtimer.h>
 #include <qwidget.h>
 
 #include "../../global.h"
@@ -48,6 +49,7 @@ class QtGUIMainWindow;
 
 // Display
 class MyDisplay : public QWidget {
+	Q_OBJECT
 public:
 	MyDisplay 	();
 	MyDisplay 	(QWidget *, const char *, QtGUIMainWindow *);
@@ -64,6 +66,12 @@ public:
 	inline bool getInFunction (void) { return _inFunction; }
 	inline void setInFunction (bool b) { _inFunction = b; }
 
+	inline bool getIsScrolling (void) { return _isScrolling; }
+	inline void setIsScrolling (bool s) { _isScrolling = s; }
+
+	inline void resetForScrolling (bool r) { _reset = r; }
+	inline bool getReset (void) { return _reset; }
+
 public slots:
 	void	 appendText	(const QString &);
 	void	 appendText	(const char *);
@@ -72,6 +80,7 @@ public slots:
 	void	 clearBuffer(void);
 	void	 clear		(const QString &);
 	void 	 backspace	(void);
+	void 	 shift		(void);
 
 protected:
 	void	 paintEvent (QPaintEvent *);
@@ -85,6 +94,11 @@ private:
 	QString*			_textBuffer;		
 	QString*			_time;
 	bool 				_inFunction;
+	bool				_shift;
+	QTimer*				_timerForScrollingText;
+	bool 				_isScrolling;
+	bool				_reset;
+	unsigned int 		len_to_shift;
 	
 	void		initText		(void);
 	void		renderText		(QPainter &, QFontMetrics &, QString &);
diff --git a/src/gui/qt/phoneline.cpp b/src/gui/qt/phoneline.cpp
index 4589e9811c..8164cd9d15 100644
--- a/src/gui/qt/phoneline.cpp
+++ b/src/gui/qt/phoneline.cpp
@@ -32,6 +32,8 @@ PhoneLine::PhoneLine (void) {
 	b_ringing = false;
 	_callid = 0;
 	_status = "";
+	_scrolling = false;
+	_stopScrolling = false;
 }
 
 PhoneLine::~PhoneLine (void) {
diff --git a/src/gui/qt/phoneline.h b/src/gui/qt/phoneline.h
index e2c003b101..904813793b 100644
--- a/src/gui/qt/phoneline.h
+++ b/src/gui/qt/phoneline.h
@@ -70,9 +70,17 @@ public:
 	inline short getCallId 		(void) { return _callid; }
 	inline void setCallId 		(short id) { _callid = id; }
 
+	inline bool scrolling		(void) { return _scrolling; }
+	inline void setScrolling    (bool s) { _scrolling = s; }
+
+	inline bool stopScrolling 	(void) { return _stopScrolling; }
+	inline void setStopScrolling(bool s) { _stopScrolling = s; }
+
 private:
 	short 			_callid;
 	QString			_status;
+	bool 			_scrolling; // if need scrolling message
+	bool			_stopScrolling;
 	
 	JPushButton*	jpb;
 	enum line_state	state;
diff --git a/src/gui/qt/qtGUImainwindow.cpp b/src/gui/qt/qtGUImainwindow.cpp
index 8eb23f2ae4..f7802412d0 100644
--- a/src/gui/qt/qtGUImainwindow.cpp
+++ b/src/gui/qt/qtGUImainwindow.cpp
@@ -672,7 +672,7 @@ QtGUIMainWindow::callIsBusy (Call* call, int id, int line, int busyLine)
 		changeLineStatePixmap(line, ONHOLD);
 		displayStatus(ONHOLD_STATUS);
 		if (qt_onHoldCall(id) != 1) {
-		  Manager::instance().displayErrorText("On-hold call failed !\n");
+		  Manager::instance().displayErrorText(id, "On-hold call failed !\n");
 		  return -1;
 		}
 	}
@@ -684,7 +684,7 @@ QtGUIMainWindow::callIsOnHold(int id, int line, int busyLine)
 {
 	changeLineStatePixmap(line, BUSY);
 	if (putOnHoldBusyLine(busyLine) == -1) {
-		Manager::instance().displayErrorText("Off-hold call failed !\n");
+		Manager::instance().displayErrorText(id, "Off-hold call failed !\n");
 		return -1;
 	}
 	if (getChooseLine()) {
@@ -697,7 +697,7 @@ QtGUIMainWindow::callIsOnHold(int id, int line, int busyLine)
 	}		
 	_lcd->setInFunction(true);
 	if (qt_offHoldCall(id) != 1) {
-		Manager::instance().displayErrorText("Off-hold call failed !\n");
+		Manager::instance().displayErrorText(id, "Off-hold call failed !\n");
 		return -1;
 	}
 	displayContext(id);
@@ -711,7 +711,7 @@ QtGUIMainWindow::callIsIncoming (int id, int line, int busyLine)
 	changeLineStatePixmap(line, BUSY);
 	putOnHoldBusyLine(busyLine);
 	if (qt_answerCall(id) != 1) {
-		Manager::instance().displayErrorText("Answered call failed !\n");
+		Manager::instance().displayErrorText(id, "Answered call failed !\n");
 		return -1;
 	}
 	return 1;
@@ -847,7 +847,15 @@ QtGUIMainWindow::incomingCall (short id)
 			// Set the status to the phoneline
 			getPhoneLine(id)->setStatus(QString(getCall(id)->getStatus()));
 		}
+		
+		// To store information about stop scrolling text
+		_lcd->resetForScrolling (false);
+		phLines[i]->setStopScrolling(false);
+		// To store information about scrolling text or not
+		phLines[i]->setScrolling(true);
+		_lcd->setIsScrolling(true);
 	}
+	
 	return i;
 }
 	
@@ -875,6 +883,10 @@ QtGUIMainWindow::peerHungupCall (short id)
 {
 	int line = id2line(id);
 
+	// To store information about scrolling text
+	_lcd->resetForScrolling (true);
+	phLines[line]->setStopScrolling(true);
+
 	if (line == getCurrentLine() or getCurrentLine() == -1) {
 		stopCallTimer(id);
 		Manager::instance().displayStatus(HUNGUP_STATUS);
@@ -905,10 +917,14 @@ QtGUIMainWindow::displayTextMessage (short id, const string& message)
 }
 	
 void 
-QtGUIMainWindow::displayErrorText (const string& message)
+QtGUIMainWindow::displayErrorText (short id, const string& message)
 {
 	_lcd->clearBuffer();
 	_lcd->appendText(message);
+
+	// To store information about scrolling text
+	_lcd->setIsScrolling(true);
+	phLines[id2line(id)]->setScrolling(true);
 }
 
 void 
@@ -932,6 +948,12 @@ void
 QtGUIMainWindow::displayContext (short id)
 {
 	displayStatus(getCall(id)->getStatus());
+	
+	// To fetch information about scrolling text according to the context 
+	// of the phoneline.
+	_lcd->setIsScrolling(phLines[id2line(id)]->scrolling());
+	_lcd->resetForScrolling(phLines[id2line(id)]->stopScrolling());
+	
 	if (getCall(id)->isIncomingType()) {
 		displayTextMessage (id, getCall(id)->getCallerIdName());
 	} else if (getCall(id)->isOutgoingType()) {
@@ -966,6 +988,8 @@ QtGUIMainWindow::qt_outgoingCall (void)
 {
 	int id;
 	int line = -1;
+
+	
 	if (_lcd->getTextBuffer() == NULL) {
 		Manager::instance().displayStatus(ENTER_NUMBER_STATUS);
 		return -1;
@@ -980,6 +1004,10 @@ QtGUIMainWindow::qt_outgoingCall (void)
 	if (id > 0) {	
 		line = associateCall2Line(id);
 		_debug("Call %d -> line %d\n", id, line);
+		
+		// To store information about stop scrolling text
+		_lcd->resetForScrolling (false);
+		phLines[line]->setStopScrolling(false);
 
 		setCurrentLine(line);
 		displayStatus(TRYING_STATUS);
@@ -1178,8 +1206,9 @@ QtGUIMainWindow::dial (void)
 	} else if (getTransfer()){
 		// If call transfer
 		setTransfer(false);
-		if(qt_transferCall (line2id(getCurrentLine())) != 1) {
-			Manager::instance().displayErrorText("Transfer failed !\n");
+		int id = line2id(getCurrentLine());
+		if(qt_transferCall (id) != 1) {
+			Manager::instance().displayErrorText(id, "Transfer failed !\n");
 		}
 	} else {
 		// If new outgoing call  
@@ -1206,6 +1235,10 @@ QtGUIMainWindow::hangupLine (void)
 
 	setTransfer(false);
 
+	// To store information about stop scrolling text
+	_lcd->resetForScrolling (true);
+	phLines[line]->setStopScrolling(true);
+
 	if (Manager::instance().getbCongestion() and line != -1) {
 		// If congestion tone
 		if (id > 0 and qt_hangupCall(id)) {
@@ -1215,38 +1248,32 @@ QtGUIMainWindow::hangupLine (void)
 			phLines[line]->setCallId(0);
 		} else if (id == 0) {
 			changeLineStatePixmap(line, FREE);
-		} else {
-			Manager::instance().displayErrorText("Hangup call failed !\n");
-		}	
+		} 
 	} else if ((i = isThereIncomingCall()) > 0){
-		_debug("&&&&&&&&&& i = %d\n", i);
 		// To refuse new incoming call 
 		_debug("Refuse call %d\n", id);
-		if (qt_refuseCall(i)) {
-			changeLineStatePixmap(id2line(i), FREE);
-			phLines[id2line(i)]->setCallId(0);
-		} else {
-			Manager::instance().displayErrorText("Refused call failed !\n");
+		if (!qt_refuseCall(i)) {
+			Manager::instance().displayErrorText(id, "Refused call failed !\n");
 		}
+		changeLineStatePixmap(id2line(i), FREE);
+		phLines[id2line(i)]->setCallId(0);
 	} else if (line >= 0 and id > 0 and getCall(id)->isProgressing()) {
 		// If I want to cancel a call before ringing.
-		if (qt_cancelCall(id)) {
-			changeLineStatePixmap(line, FREE);
-			phLines[line]->setCallId(0);
-			setChooseLine(false);
-		} else {
-			Manager::instance().displayErrorText("Cancelled call failed !\n");
+		if (!qt_cancelCall(id)) {
+			Manager::instance().displayErrorText(id, "Cancelled call failed !\n");
 		}
+		changeLineStatePixmap(line, FREE);
+		phLines[line]->setCallId(0);
+		setChooseLine(false);
 	} else if (line >= 0 and id > 0) {
 		// If hangup current line normally
 		_debug("Hangup line %d\n", line);
-		if (qt_hangupCall(id)) {
-			changeLineStatePixmap(line, FREE);
-			phLines[line]->setCallId(0);
-			setChooseLine(false);
-		} else {
-			Manager::instance().displayErrorText("Hangup call failed !\n");
+		if (!qt_hangupCall(id)) {
+			Manager::instance().displayErrorText(id, "Hangup call failed !\n");
 		}
+		changeLineStatePixmap(line, FREE);
+		phLines[line]->setCallId(0);
+		setChooseLine(false);
 	} else if (line >= 0) {
 		_debug("Just load free pixmap for the line %d\n", line);
 		changeLineStatePixmap(line, FREE);
@@ -1621,44 +1648,53 @@ QtGUIMainWindow::pressedKeySlot (int id) {
     if (callid != -1 and getCall(callid)->isBusy()) {
 	// To send DTMF during call, no display of them
         sendDtmf(callid, code); 
-    } else if (Manager::instance().isDriverLoaded()) {
-	// To compose, phone number appears in the screen
+    } else if (Manager::instance().isDriverLoaded()
+			and Manager::instance().error()->getError() == 0) {
+	// To compose, phone number appears in the screen if the driver is loaded
+	// and there is no error in configuration setup
 		_lcd->appendText (code);
-	}
 
-	// Handle dtmf
-	_key->startTone(code);
-	_key->generateDTMF(_buf, SAMPLING_RATE);
-	
-	// Determine dtmf pulse length
-	pulselen = get_config_fields_int(SIGNALISATION, PULSE_LENGTH);
-	int size = pulselen * (OCTETS /1000);
-  
-	buf_ctrl_vol = new int16[size*CHANNELS];
-	spkrVolume = Manager::instance().getSpkrVolume();
-	
-	// Control volume and format mono->stereo
-	for (int j = 0; j < size; j++) {
-		k = j*2;  
-		buf_ctrl_vol[k] = buf_ctrl_vol[k+1] = _buf[j] * spkrVolume/100;
+		// To store information about scrolling text
+		_lcd->setIsScrolling(false);
+		phLines[getCurrentLine()]->setScrolling(false);
 	}
+
+	// To generate the dtmf if there is no error in configuration
+	if (Manager::instance().error()->getError() == 0) {
+		// Handle dtmf
+		_key->startTone(code);
+		_key->generateDTMF(_buf, SAMPLING_RATE);
 		
-	Manager::instance().getAudioDriver()->urgentRingBuffer().flush();
-	// Put buffer to urgentRingBuffer 
-	Manager::instance().getAudioDriver()->urgentRingBuffer().Put(buf_ctrl_vol, 
-			size * CHANNELS);
-
-	// We activate the stream if it's not active yet.
-	if (!Manager::instance().getAudioDriver()->isStreamActive()) {
-		Manager::instance().getAudioDriver()->startStream();
-		Manager::instance().getAudioDriver()->sleep(pulselen);
-		Manager::instance().getAudioDriver()->stopStream();
-		Manager::instance().getAudioDriver()->urgentRingBuffer().flush();
-	} else {
-        Manager::instance().getAudioDriver()->sleep(pulselen);
-    }
+		// Determine dtmf pulse length
+		pulselen = get_config_fields_int(SIGNALISATION, PULSE_LENGTH);
+		int size = pulselen * (OCTETS /1000);
+	  
+		buf_ctrl_vol = new int16[size*CHANNELS];
+		spkrVolume = Manager::instance().getSpkrVolume();
 		
-	delete[] buf_ctrl_vol;
+		// Control volume and format mono->stereo
+		for (int j = 0; j < size; j++) {
+			k = j*2;  
+			buf_ctrl_vol[k] = buf_ctrl_vol[k+1] = _buf[j] * spkrVolume/100;
+		}
+			
+		Manager::instance().getAudioDriver()->urgentRingBuffer().flush();
+		// Put buffer to urgentRingBuffer 
+		Manager::instance().getAudioDriver()->urgentRingBuffer().Put(buf_ctrl_vol, 
+				size * CHANNELS);
+
+		// We activate the stream if it's not active yet.
+		if (!Manager::instance().getAudioDriver()->isStreamActive()) {
+			Manager::instance().getAudioDriver()->startStream();
+			Manager::instance().getAudioDriver()->sleep(pulselen);
+			Manager::instance().getAudioDriver()->stopStream();
+			Manager::instance().getAudioDriver()->urgentRingBuffer().flush();
+		} else {
+			Manager::instance().getAudioDriver()->sleep(pulselen);
+		}
+			
+		delete[] buf_ctrl_vol;
+	}
 }
 
 // Save settings in config-file
diff --git a/src/gui/qt/qtGUImainwindow.h b/src/gui/qt/qtGUImainwindow.h
index e9e58964e6..f2524d49a6 100644
--- a/src/gui/qt/qtGUImainwindow.h
+++ b/src/gui/qt/qtGUImainwindow.h
@@ -87,7 +87,7 @@ public:
 	virtual int peerRingingCall (short id);
 	virtual int peerHungupCall (short id);
 	virtual void displayTextMessage (short id, const string& message);
-	virtual void displayErrorText (const string& message);
+	virtual void displayErrorText (short id, const string& message);
 	virtual void displayError (const string& error);
 	virtual void displayStatus (const string& status);
 	virtual void displayContext (short id);
diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp
index 5c90db737d..b546d66bb2 100644
--- a/src/managerimpl.cpp
+++ b/src/managerimpl.cpp
@@ -111,19 +111,19 @@ ManagerImpl::init (void)
 	}
 	catch (const portaudio::PaException &e)
 	{
-		displayErrorText(e.paErrorText());
+		displayError(e.paErrorText());
 	}
 	catch (const portaudio::PaCppException &e)
 	{
-		displayErrorText(e.what());
+		displayError(e.what());
 	}
 	catch (const exception &e)
 	{
-		displayErrorText(e.what());
+		displayError(e.what());
 	}
 	catch (...)
 	{ 
-		displayErrorText("An unknown exception occured.");
+		displayError("An unknown exception occured.");
 	}
 	
 	_voIPLinkVector->at(DFT_VOIP_LINK)->init();
@@ -134,7 +134,6 @@ ManagerImpl::init (void)
 				_exist == 1) {
 			if (registerVoIPLink() != 1) {
 				_debug("Registration failed\n");
-				displayErrorText("Check your configuration fields");
 			}
 		} 
 	}
@@ -559,9 +558,9 @@ ManagerImpl::displayTextMessage (short id, const string& message)
 }
 
 void 
-ManagerImpl::displayErrorText (const string& message)
+ManagerImpl::displayErrorText (short id, const string& message)
 {
-	_gui->displayErrorText(message);
+	_gui->displayErrorText(id, message);
 }
 
 void 
diff --git a/src/managerimpl.h b/src/managerimpl.h
index fdd441ea66..be8056323a 100644
--- a/src/managerimpl.h
+++ b/src/managerimpl.h
@@ -158,7 +158,7 @@ public:
 	int peerRingingCall (short id);
 	int peerHungupCall (short id);
 	void displayTextMessage (short id, const string& message);
-	void displayErrorText (const string& message);
+	void displayErrorText (short id, const string& message);
 	void displayError (const string& error);
 	void displayStatus (const string& status);
 	int selectedCall (void);
diff --git a/src/sipvoiplink.cpp b/src/sipvoiplink.cpp
index 1594eaf161..c210903eab 100644
--- a/src/sipvoiplink.cpp
+++ b/src/sipvoiplink.cpp
@@ -203,6 +203,8 @@ SipVoIPLink::setRegister (void)
 	}
 	
 	eXosip_unlock();
+
+	Manager::instance().error()->setError(0);
 	return i;
 }
 int
@@ -233,7 +235,7 @@ SipVoIPLink::outgoingInvite (short id, const string& to_url)
 				return -1;
 			}
 		} else {
-			Manager::instance().displayErrorText("No network found\n");
+			Manager::instance().displayErrorText(id, "No network found\n");
             return -1;
         }
 		return 0;
@@ -247,7 +249,7 @@ SipVoIPLink::outgoingInvite (short id, const string& to_url)
 				return -1;
 			}
 		} else {
-			Manager::instance().displayErrorText("No network found\n");
+			Manager::instance().displayErrorText(id, "No network found\n");
             return -1;
         }
 		return 0;
@@ -582,10 +584,10 @@ SipVoIPLink::getEvent (void)
 			
 			getSipCall(id)->newIncomingCall(event);
 			if (Manager::instance().incomingCall(id) < 0) {
-				Manager::instance().displayErrorText("Incoming call failed");
+				Manager::instance().displayErrorText(id, "Incoming call failed");
 				return -1;
 			}
-
+	
 			break;
 
 		// The peer-user answers
@@ -741,12 +743,11 @@ SipVoIPLink::getEvent (void)
 			
 				// TODO: Que faire si rien trouve??
 				eXosip_lock();
-				if (_sipcallVector->at(k)->getCid() == event->cid) {
-					/* already answered! */
-				}
-				else if (k == _sipcallVector->size()) {
+				if (k == _sipcallVector->size()) {
 					/* answer 200 ok */
 					eXosip_options_send_answer (event->tid, OK, NULL);
+				} else if (_sipcallVector->at(k)->getCid() == event->cid) {
+					/* already answered! */
 				} else {
 					/* answer 486 ok */
 					eXosip_options_send_answer (event->tid, BUSY_HERE, NULL);
-- 
GitLab