From 45e8bd3edd98b05063460d6738e0f4e6d67a439d Mon Sep 17 00:00:00 2001
From: llea <llea>
Date: Fri, 15 Jul 2005 22:29:07 +0000
Subject: [PATCH] Fix configuration init. Fix volume control

---
 ChangeLog                      |  3 +++
 src/audio/audiortp.cpp         | 11 ++++++-----
 src/audio/audiortp.h           |  2 +-
 src/audio/tonegenerator.cpp    | 13 +++++++------
 src/gui/guiframework.cpp       |  4 ++--
 src/gui/qt/qtGUImainwindow.cpp | 25 +++++++++++++------------
 src/main.cpp                   |  3 ++-
 src/managerimpl.cpp            | 19 ++++++++++---------
 src/managerimpl.h              | 10 ++++++----
 9 files changed, 50 insertions(+), 40 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 20cc6cab3d..d6f7f4496a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+Laurielle LEA (15 July 2005) version 0.4
+- Fix configuration init
+
 Jerome OUFELLA (13 July 2005) version 0.4
 - Fix tone.
 
diff --git a/src/audio/audiortp.cpp b/src/audio/audiortp.cpp
index be4018f531..a88d8e6b50 100644
--- a/src/audio/audiortp.cpp
+++ b/src/audio/audiortp.cpp
@@ -247,11 +247,10 @@ AudioRtpRTX::sendSessionFromMic (unsigned char* data_to_send, int16* data_from_m
 
 void
 AudioRtpRTX::receiveSessionForSpkr (int16* data_for_speakers, 
-		int16* data_for_speakers_tmp, int spkrVolume)
+		int16* data_for_speakers_tmp, int spkrVolume, int& countTime)
 {
 	int expandedSize;
 	int k;
-	int	countTime = 0;
 	const AppDataUnit* adu = NULL;
 
 	// Get audio data stream
@@ -288,9 +287,10 @@ AudioRtpRTX::receiveSessionForSpkr (int16* data_for_speakers,
 	
 	// Notify (with a bip) an incoming call when there is already a call 
 	countTime += time->getSecond();
-	if (Manager::instance().getNumberOfCalls() > 0 and Manager::instance().getbRingtone()) {
+	if (Manager::instance().getNumberOfCalls() > 0 
+			and Manager::instance().getbRingtone()) {
 		countTime = countTime % 2000;
-		if (countTime < 10 and countTime > 0) {
+		if (countTime < 100 and countTime > 0) {
 			Manager::instance().notificationIncomingCall();
 		}
 	} 
@@ -310,6 +310,7 @@ AudioRtpRTX::run (void) {
 	int				 timestamp;
 	int16			*data_for_speakers = NULL;
 	int16			*data_for_speakers_tmp = NULL;
+	int              countTime = 0;
 	
 	data_from_mic = new int16[SIZEDATA]; 
 	data_from_mic_tmp = new int16[SIZEDATA];
@@ -350,7 +351,7 @@ AudioRtpRTX::run (void) {
 		// Recv session
 		////////////////////////////
 		receiveSessionForSpkr(data_for_speakers, data_for_speakers_tmp,
-				spkrVolume);
+				spkrVolume, countTime);
 		
 		// Let's wait for the next transmit cycle
 		Thread::sleep(TimerPort::getTimer());
diff --git a/src/audio/audiortp.h b/src/audio/audiortp.h
index 3288ae9743..6e2ad85153 100644
--- a/src/audio/audiortp.h
+++ b/src/audio/audiortp.h
@@ -55,7 +55,7 @@ private:
 
 	void initAudioRtpSession (void);
 	void sendSessionFromMic (unsigned char*, int16*, int16*, int, int);
-	void receiveSessionForSpkr (int16*, int16*, int);
+	void receiveSessionForSpkr (int16*, int16*, int, int&);
 };
 
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/src/audio/tonegenerator.cpp b/src/audio/tonegenerator.cpp
index 91d219d19c..5b210a0376 100644
--- a/src/audio/tonegenerator.cpp
+++ b/src/audio/tonegenerator.cpp
@@ -60,14 +60,15 @@ ToneThread::run (void) {
 	// How long do 'size' samples play ?
 	unsigned int play_time = (size * 1000) / SAMPLING_RATE;
 
-	// Create a new stereo buffer with the volume adjusted
-	spkrVolume = Manager::instance().getSpkrVolume();
-	for (int j = 0; j < size; j++) {
-		k = j*2;
-		buf_ctrl_vol[k] = buf_ctrl_vol[k+1] = buffer[j] * spkrVolume/100;
-	}
 
 	while (Manager::instance().getZonetone()) {
+		// Create a new stereo buffer with the volume adjusted
+		spkrVolume = Manager::instance().getSpkrVolume();
+		for (int j = 0; j < size; j++) {
+			k = j*2;
+			buf_ctrl_vol[k] = buf_ctrl_vol[k+1] = buffer[j] * spkrVolume/100;
+		}
+
 		// Push the tone to the audio FIFO
 		Manager::instance().getAudioDriver()->mainSndRingBuffer().Put(buf_ctrl_vol, 
 			SAMPLES_SIZE(size));
diff --git a/src/gui/guiframework.cpp b/src/gui/guiframework.cpp
index 08a8ba0ce4..8eb652c25e 100644
--- a/src/gui/guiframework.cpp
+++ b/src/gui/guiframework.cpp
@@ -57,7 +57,7 @@ GuiFramework::cancelCall (short id)
 int 
 GuiFramework::answerCall (short id)
 {
-	if (Manager::instance().answerCall(id)) {
+	if (Manager::instance().answerCall(id) == 0) {
 		return 1;
 	} else {
 		return 0;
@@ -87,7 +87,7 @@ GuiFramework::offHoldCall (short id)
 int 
 GuiFramework::transferCall (short id, const string& to)
 {
-	if (Manager::instance().transferCall(id, to) == 1) {
+	if (Manager::instance().transferCall(id, to) == 0) {
 		return 1;
 	} else {
 		return 0;
diff --git a/src/gui/qt/qtGUImainwindow.cpp b/src/gui/qt/qtGUImainwindow.cpp
index 94edb06a61..ef1e8e3627 100644
--- a/src/gui/qt/qtGUImainwindow.cpp
+++ b/src/gui/qt/qtGUImainwindow.cpp
@@ -773,7 +773,7 @@ QtGUIMainWindow::getPhoneLine (short id)
 		} 
 	}
 	if (i == NUMBER_OF_LINES) {
-		_debug("Id is not attributed to a phoneline\n");
+		_debug("getPhoneLine(id): Id %d is not attributed to a phoneline\n", id);
 		return NULL;
 	}
 	return NULL;
@@ -1028,7 +1028,7 @@ QtGUIMainWindow::qt_transferCall (short id)
 {
 	int i;
 	const string to(_lcd->getTextBuffer().ascii());;
-	_debug("Transfer call %d to %s\n", id, to.data());
+	_debug("qt_transferCall: Transfer call %d to %s\n", id, to.data());
 	i = transferCall(id, to);
 	getPhoneLine(id)->setStatus(QString(getCall(id)->getStatus()));
 	return i;	
@@ -1058,6 +1058,7 @@ QtGUIMainWindow::qt_refuseCall (short id)
 	displayStatus(HUNGUP_STATUS);
 	getPhoneLine(id)->setbRinging(false);
 	_TabIncomingCalls[id2line(id)] = -1;
+	setCurrentLine(-1);
 	return i;	
 }	
 	
@@ -1146,13 +1147,12 @@ QtGUIMainWindow::dial (void)
 		if (line != -1) {
 			_TabIncomingCalls[line] = -1;
 			toggleLine(line);
-			//setPrevLine(line);
 		} else {
 			return;
 		}
 	} else if (getTransfer()){
 		// If call transfer
-		if(qt_transferCall (line2id(getCurrentLine()) != 1)) {
+		if(qt_transferCall (line2id(getCurrentLine())) != 1) {
 			Manager::instance().displayErrorText("Transfer failed !\n");
 		}
 	} else {
@@ -1177,6 +1177,7 @@ QtGUIMainWindow::hangupLine (void)
 	int i;
 	int line = getCurrentLine();
 	int id = phLines[line]->getCallId();
+	_debug("id = %d et line = %d\n", id, line);
 
 	if (Manager::instance().getbCongestion()) {
 		// If congestion tone
@@ -1188,6 +1189,14 @@ QtGUIMainWindow::hangupLine (void)
 		} else {
 			Manager::instance().displayErrorText("Hangup call failed !\n");
 		}
+	} else if ((i = isThereIncomingCall()) > 0){
+		// To refuse new incoming call 
+		_debug("Refuse call %d\n", id);
+		if (qt_refuseCall(i)) {
+			changeLineStatePixmap(id2line(i), FREE);
+		} else {
+			Manager::instance().displayErrorText("Refused call failed !\n");
+		}
 	} else if (line >= 0 and id > 0 and getCall(id)->isProgressing()) {
 		// If I want to cancel a call before ringing.
 		if (qt_cancelCall(id)) {
@@ -1207,14 +1216,6 @@ QtGUIMainWindow::hangupLine (void)
 		} else {
 			Manager::instance().displayErrorText("Hangup call failed !\n");
 		}
-	} else if ((i = isThereIncomingCall()) > 0){
-		// To refuse new incoming call 
-		_debug("Refuse call %d\n", id);
-		if (qt_refuseCall(i)) {
-			changeLineStatePixmap(id2line(i), FREE);
-		} else {
-			Manager::instance().displayErrorText("Refused call failed !\n");
-		}
 	} else if (line >= 0) {
 		_debug("Just load free pixmap for the line %d\n", line);
 		changeLineStatePixmap(line, FREE);
diff --git a/src/main.cpp b/src/main.cpp
index 060fa72265..bb45b2abfe 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -43,12 +43,13 @@ main (int argc, char **argv) {
 
 #if defined(GUI_QT)
   QApplication a(argc, argv);
+  Manager::instance().initConfigFile();		
   GUI = new QtGUIMainWindow (0, 0 ,
 			     Qt::WDestructiveClose |
 			     Qt::WStyle_Customize |
 			     Qt::WStyle_NoBorder);
-  Manager::instance().setGui(GUI);
   Manager::instance().init();		
+  Manager::instance().setGui(GUI);
 		
   a.setMainWidget((QtGUIMainWindow*)GUI);
   return a.exec();
diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp
index d3ce37b098..085d345932 100644
--- a/src/managerimpl.cpp
+++ b/src/managerimpl.cpp
@@ -96,8 +96,6 @@ ManagerImpl::init (void)
 	// Set a sip voip link by default
 	_voIPLinkVector->push_back(new SipVoIPLink(DFT_VOIP_LINK));
 
-	initConfigFile();
-	_exist = createSettingsPath();
 	if (_exist == 0) {
 		_debug("Cannot create config file in your home directory\n");
 	} 
@@ -371,11 +369,7 @@ ManagerImpl::transferCall (short id, const string& to)
 		return -1;
 	call->setStatus(string(TRANSFER_STATUS));
 	call->setState(Transfered);
-	if (call->transfer(to) != 0) {
-		return -1;
-	} else {
-		return 1;
-	}
+	return call->transfer(to);
 }
 
 void 
@@ -410,7 +404,6 @@ ManagerImpl::refuseCall (short id)
 	call->setStatus(string(HUNGUP_STATUS));
 	call->setState(Refused);	
 	ringtone(false);
-	delete call;
 	return call->refuse();
 }
 
@@ -547,6 +540,9 @@ ManagerImpl::peerHungupCall (short id)
 	if (getbRingback()) {
 		ringback(false);
 	}
+	if (getbRingtone()) {
+		ringtone(false);
+	}
 	_mutex.enterMutex();
 	_nCalls -= 1;
 	_mutex.leaveMutex();
@@ -660,12 +656,15 @@ ManagerImpl::notificationIncomingCall (void) {
 	getAudioDriver()->urgentRingBuffer().Put(buf_ctrl_vol, 
 			size * CHANNELS);
 
+	_debug("---- Notification call\n");
+#if 0
 	getAudioDriver()->startStream();
 	getAudioDriver()->sleep(NOTIFICATION_LEN);
 	getAudioDriver()->stopStream();
+#endif
 	
-    delete[] buffer;
     delete[] buf_ctrl_vol;
+    delete[] buffer;
 }
 
 void
@@ -799,6 +798,8 @@ ManagerImpl::createSettingsPath (void) {
 void
 ManagerImpl::initConfigFile (void) 
 {
+	_exist = createSettingsPath();
+
 	fill_config_fields_int(SIGNALISATION, VOIP_LINK_ID, DFT_VOIP_LINK); 	
 	fill_config_fields_str(SIGNALISATION, FULL_NAME, EMPTY_FIELD);
 	fill_config_fields_str(SIGNALISATION, USER_PART, EMPTY_FIELD); 
diff --git a/src/managerimpl.h b/src/managerimpl.h
index cc515b67e3..fdd441ea66 100644
--- a/src/managerimpl.h
+++ b/src/managerimpl.h
@@ -212,6 +212,11 @@ public:
 	int deviceCount (void);
 	bool defaultDevice (int);
 	
+	/*
+	 * Init default values for the different fields
+	 */
+	void initConfigFile (void);
+
 private:
 
 	/*
@@ -229,10 +234,7 @@ private:
  	 */
 	int createSettingsPath (void);
 		
-	/*
-	 * Init default values for the different fields
-	 */
-	void initConfigFile (void);
+
 
 	void initAudioCodec(void);
 	void selectAudioDriver (void);
-- 
GitLab