fix unix2dos issue with some files

This commit is contained in:
Volker Fischer 2009-10-24 12:24:44 +00:00
parent 1e3543f603
commit c0685e9b78
9 changed files with 4274 additions and 4274 deletions

View file

@ -1,223 +1,223 @@
/******************************************************************************\
* Copyright (c) 2004-2009
*
* Author(s):
* Volker Fischer
*
******************************************************************************
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\******************************************************************************/
#if !defined ( CLIENT_HOIHGE76GEKJH98_3_43445KJIUHF1912__INCLUDED_ )
#define CLIENT_HOIHGE76GEKJH98_3_43445KJIUHF1912__INCLUDED_
#include <qglobal.h>
#include <qhostaddress.h>
#include <qhostinfo.h>
#include <qstring.h>
#include <qdatetime.h>
#include <qmessagebox.h>
#include "celt.h"
#include "global.h"
#include "socket.h"
#include "channel.h"
#include "util.h"
#ifdef _WIN32
# include "../windows/sound.h"
#else
# include "../linux/sound.h"
# include <sched.h>
# include <socket.h>
# include <netdb.h>
#endif
/* Definitions ****************************************************************/
// audio in fader range
#define AUD_FADER_IN_MIN 0
#define AUD_FADER_IN_MAX 100
#define AUD_FADER_IN_MIDDLE ( AUD_FADER_IN_MAX / 2 )
// audio reverberation range
#define AUD_REVERB_MAX 100
// CELT number of coded bytes per audio packet
// 24: low/normal quality 156 kbsp (128) / 114 kbps (256)
// 44: high quality 216 kbps (128) / 174 kbps (256)
#define CELT_NUM_BYTES_NORMAL_QUALITY 24
#define CELT_NUM_BYTES_HIGH_QUALITY 44
/* Classes ********************************************************************/
class CClient : public QObject
{
Q_OBJECT
public:
CClient ( const quint16 iPortNumber );
virtual ~CClient() {}
void Start();
void Stop();
bool IsRunning() { return Sound.IsRunning(); }
bool SetServerAddr ( QString strNAddr );
double MicLevelL() { return SignalLevelMeter.MicLevelLeft(); }
double MicLevelR() { return SignalLevelMeter.MicLevelRight(); }
bool IsConnected() { return Channel.IsConnected(); }
double GetTimingStdDev() { return CycleTimeVariance.GetStdDev(); }
bool GetOpenChatOnNewMessage() const { return bOpenChatOnNewMessage; }
void SetOpenChatOnNewMessage ( const bool bNV ) { bOpenChatOnNewMessage = bNV; }
EGUIDesign GetGUIDesign() const { return eGUIDesign; }
void SetGUIDesign ( const EGUIDesign bNGD ) { eGUIDesign = bNGD; }
bool GetCELTHighQuality() const { return bCeltDoHighQuality; }
void SetCELTHighQuality ( const bool bNCeltHighQualityFlag );
int GetAudioInFader() const { return iAudioInFader; }
void SetAudioInFader ( const int iNV ) { iAudioInFader = iNV; }
int GetReverbLevel() const { return iReverbLevel; }
void SetReverbLevel ( const int iNL ) { iReverbLevel = iNL; }
bool IsReverbOnLeftChan() const { return bReverbOnLeftChan; }
void SetReverbOnLeftChan ( const bool bIL )
{
bReverbOnLeftChan = bIL;
AudioReverb.Clear();
}
void SetDoAutoSockBufSize ( const bool bValue ) { bDoAutoSockBufSize = bValue; }
bool GetDoAutoSockBufSize() const { return bDoAutoSockBufSize; }
void SetSockBufNumFrames ( const int iNumBlocks )
{
// only change parameter if new parameter is different from current one
if ( Channel.GetSockBufNumFrames() != iNumBlocks )
{
// set the new socket size (number of frames)
if ( !Channel.SetSockBufNumFrames ( iNumBlocks ) )
{
// if setting of socket buffer size was successful,
// tell the server that size has changed
Channel.CreateJitBufMes ( iNumBlocks );
}
}
}
int GetSockBufNumFrames() { return Channel.GetSockBufNumFrames(); }
int GetUploadRateKbps() { return Channel.GetUploadRateKbps(); }
int GetSndCrdNumDev() { return Sound.GetNumDev(); }
std::string GetSndCrdDeviceName ( const int iDiD )
{ return Sound.GetDeviceName ( iDiD ); }
QString SetSndCrdDev ( const int iNewDev );
int GetSndCrdDev() { return Sound.GetDev(); }
void OpenSndCrdDriverSetup() { Sound.OpenDriverSetup(); }
void SetSndCrdPrefFrameSizeFactor ( const int iNewFactor );
int GetSndCrdPrefFrameSizeFactor()
{ return iSndCrdPrefFrameSizeFactor; }
int GetSndCrdActualMonoBlSize() { return iMonoBlockSizeSam; }
void SetRemoteChanGain ( const int iId, const double dGain )
{ Channel.SetRemoteChanGain ( iId, dGain ); }
void SetRemoteName() { Channel.SetRemoteName ( strName ); }
void SendTextMess ( const QString& strChatText )
{ Channel.CreateChatTextMes ( strChatText ); }
void SendPingMess()
{ Channel.CreatePingMes ( PreciseTime.elapsed() ); };
CChannel* GetChannel() { return &Channel; }
// settings
CVector<QString> vstrIPAddress;
QString strName;
protected:
// callback function must be static, otherwise it does not work
static void AudioCallback ( CVector<short>& psData, void* arg );
bool Init();
void ProcessAudioData ( CVector<short>& vecsStereoSndCrd );
void UpdateSocketBufferSize();
// only one channel is needed for client application
CChannel Channel;
bool bDoAutoSockBufSize;
// audio encoder/decoder
CELTMode* CeltMode;
CELTEncoder* CeltEncoder;
CELTDecoder* CeltDecoder;
int iCeltNumCodedBytes;
bool bCeltDoHighQuality;
CVector<unsigned char> vecCeltData;
CSocket Socket;
CSound Sound;
CStereoSignalLevelMeter SignalLevelMeter;
CVector<uint8_t> vecbyNetwData;
int iAudioInFader;
bool bReverbOnLeftChan;
int iReverbLevel;
CAudioReverb AudioReverb;
int iSndCrdPrefFrameSizeFactor;
int iSndCrdFrameSizeFactor;
int iMonoBlockSizeSam;
int iStereoBlockSizeSam;
bool bOpenChatOnNewMessage;
EGUIDesign eGUIDesign;
CVector<int16_t> vecsAudioSndCrdMono;
CVector<int16_t> vecsAudioSndCrdStereo;
CVector<double> vecdAudioStereo;
CVector<int16_t> vecsNetwork;
// for ping measurement
CPreciseTime PreciseTime;
CCycleTimeVariance CycleTimeVariance;
public slots:
void OnSendProtMessage ( CVector<uint8_t> vecMessage );
void OnReqJittBufSize() { Channel.CreateJitBufMes ( Channel.GetSockBufNumFrames() ); }
void OnReqChanName() { Channel.SetRemoteName ( strName ); }
void OnNewConnection();
void OnReceivePingMessage ( int iMs );
void OnSndCrdReinitRequest();
signals:
void ConClientListMesReceived ( CVector<CChannelShortInfo> vecChanInfo );
void ChatTextReceived ( QString strChatText );
void PingTimeReceived ( int iPingTime );
void Disconnected();
void Stopped();
};
#endif /* !defined ( CLIENT_HOIHGE76GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */
/******************************************************************************\
* Copyright (c) 2004-2009
*
* Author(s):
* Volker Fischer
*
******************************************************************************
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\******************************************************************************/
#if !defined ( CLIENT_HOIHGE76GEKJH98_3_43445KJIUHF1912__INCLUDED_ )
#define CLIENT_HOIHGE76GEKJH98_3_43445KJIUHF1912__INCLUDED_
#include <qglobal.h>
#include <qhostaddress.h>
#include <qhostinfo.h>
#include <qstring.h>
#include <qdatetime.h>
#include <qmessagebox.h>
#include "celt.h"
#include "global.h"
#include "socket.h"
#include "channel.h"
#include "util.h"
#ifdef _WIN32
# include "../windows/sound.h"
#else
# include "../linux/sound.h"
# include <sched.h>
# include <socket.h>
# include <netdb.h>
#endif
/* Definitions ****************************************************************/
// audio in fader range
#define AUD_FADER_IN_MIN 0
#define AUD_FADER_IN_MAX 100
#define AUD_FADER_IN_MIDDLE ( AUD_FADER_IN_MAX / 2 )
// audio reverberation range
#define AUD_REVERB_MAX 100
// CELT number of coded bytes per audio packet
// 24: low/normal quality 156 kbsp (128) / 114 kbps (256)
// 44: high quality 216 kbps (128) / 174 kbps (256)
#define CELT_NUM_BYTES_NORMAL_QUALITY 24
#define CELT_NUM_BYTES_HIGH_QUALITY 44
/* Classes ********************************************************************/
class CClient : public QObject
{
Q_OBJECT
public:
CClient ( const quint16 iPortNumber );
virtual ~CClient() {}
void Start();
void Stop();
bool IsRunning() { return Sound.IsRunning(); }
bool SetServerAddr ( QString strNAddr );
double MicLevelL() { return SignalLevelMeter.MicLevelLeft(); }
double MicLevelR() { return SignalLevelMeter.MicLevelRight(); }
bool IsConnected() { return Channel.IsConnected(); }
double GetTimingStdDev() { return CycleTimeVariance.GetStdDev(); }
bool GetOpenChatOnNewMessage() const { return bOpenChatOnNewMessage; }
void SetOpenChatOnNewMessage ( const bool bNV ) { bOpenChatOnNewMessage = bNV; }
EGUIDesign GetGUIDesign() const { return eGUIDesign; }
void SetGUIDesign ( const EGUIDesign bNGD ) { eGUIDesign = bNGD; }
bool GetCELTHighQuality() const { return bCeltDoHighQuality; }
void SetCELTHighQuality ( const bool bNCeltHighQualityFlag );
int GetAudioInFader() const { return iAudioInFader; }
void SetAudioInFader ( const int iNV ) { iAudioInFader = iNV; }
int GetReverbLevel() const { return iReverbLevel; }
void SetReverbLevel ( const int iNL ) { iReverbLevel = iNL; }
bool IsReverbOnLeftChan() const { return bReverbOnLeftChan; }
void SetReverbOnLeftChan ( const bool bIL )
{
bReverbOnLeftChan = bIL;
AudioReverb.Clear();
}
void SetDoAutoSockBufSize ( const bool bValue ) { bDoAutoSockBufSize = bValue; }
bool GetDoAutoSockBufSize() const { return bDoAutoSockBufSize; }
void SetSockBufNumFrames ( const int iNumBlocks )
{
// only change parameter if new parameter is different from current one
if ( Channel.GetSockBufNumFrames() != iNumBlocks )
{
// set the new socket size (number of frames)
if ( !Channel.SetSockBufNumFrames ( iNumBlocks ) )
{
// if setting of socket buffer size was successful,
// tell the server that size has changed
Channel.CreateJitBufMes ( iNumBlocks );
}
}
}
int GetSockBufNumFrames() { return Channel.GetSockBufNumFrames(); }
int GetUploadRateKbps() { return Channel.GetUploadRateKbps(); }
int GetSndCrdNumDev() { return Sound.GetNumDev(); }
std::string GetSndCrdDeviceName ( const int iDiD )
{ return Sound.GetDeviceName ( iDiD ); }
QString SetSndCrdDev ( const int iNewDev );
int GetSndCrdDev() { return Sound.GetDev(); }
void OpenSndCrdDriverSetup() { Sound.OpenDriverSetup(); }
void SetSndCrdPrefFrameSizeFactor ( const int iNewFactor );
int GetSndCrdPrefFrameSizeFactor()
{ return iSndCrdPrefFrameSizeFactor; }
int GetSndCrdActualMonoBlSize() { return iMonoBlockSizeSam; }
void SetRemoteChanGain ( const int iId, const double dGain )
{ Channel.SetRemoteChanGain ( iId, dGain ); }
void SetRemoteName() { Channel.SetRemoteName ( strName ); }
void SendTextMess ( const QString& strChatText )
{ Channel.CreateChatTextMes ( strChatText ); }
void SendPingMess()
{ Channel.CreatePingMes ( PreciseTime.elapsed() ); };
CChannel* GetChannel() { return &Channel; }
// settings
CVector<QString> vstrIPAddress;
QString strName;
protected:
// callback function must be static, otherwise it does not work
static void AudioCallback ( CVector<short>& psData, void* arg );
bool Init();
void ProcessAudioData ( CVector<short>& vecsStereoSndCrd );
void UpdateSocketBufferSize();
// only one channel is needed for client application
CChannel Channel;
bool bDoAutoSockBufSize;
// audio encoder/decoder
CELTMode* CeltMode;
CELTEncoder* CeltEncoder;
CELTDecoder* CeltDecoder;
int iCeltNumCodedBytes;
bool bCeltDoHighQuality;
CVector<unsigned char> vecCeltData;
CSocket Socket;
CSound Sound;
CStereoSignalLevelMeter SignalLevelMeter;
CVector<uint8_t> vecbyNetwData;
int iAudioInFader;
bool bReverbOnLeftChan;
int iReverbLevel;
CAudioReverb AudioReverb;
int iSndCrdPrefFrameSizeFactor;
int iSndCrdFrameSizeFactor;
int iMonoBlockSizeSam;
int iStereoBlockSizeSam;
bool bOpenChatOnNewMessage;
EGUIDesign eGUIDesign;
CVector<int16_t> vecsAudioSndCrdMono;
CVector<int16_t> vecsAudioSndCrdStereo;
CVector<double> vecdAudioStereo;
CVector<int16_t> vecsNetwork;
// for ping measurement
CPreciseTime PreciseTime;
CCycleTimeVariance CycleTimeVariance;
public slots:
void OnSendProtMessage ( CVector<uint8_t> vecMessage );
void OnReqJittBufSize() { Channel.CreateJitBufMes ( Channel.GetSockBufNumFrames() ); }
void OnReqChanName() { Channel.SetRemoteName ( strName ); }
void OnNewConnection();
void OnReceivePingMessage ( int iMs );
void OnSndCrdReinitRequest();
signals:
void ConClientListMesReceived ( CVector<CChannelShortInfo> vecChanInfo );
void ChatTextReceived ( QString strChatText );
void PingTimeReceived ( int iPingTime );
void Disconnected();
void Stopped();
};
#endif /* !defined ( CLIENT_HOIHGE76GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */

View file

@ -1,473 +1,473 @@
/******************************************************************************\
* Copyright (c) 2004-2009
*
* Author(s):
* Volker Fischer
*
******************************************************************************
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\******************************************************************************/
#include "clientsettingsdlg.h"
/* Implementation *************************************************************/
CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent,
Qt::WindowFlags f ) : pClient ( pNCliP ), QDialog ( parent, f )
{
setupUi ( this );
// add help text to controls
QString strJitterBufferSize = tr ( "<b>Jitter Buffer Size:</b> The size of "
"the network buffer (jitter buffer). The jitter buffer compensates for "
"the network jitter. The larger this buffer is, the more robust the "
"connection is against network jitter but the higher is the latency. "
"This setting is therefore a trade-off between audio drop outs and "
"overall audio delay.<br>By changing this setting, both, the client "
"and the server jitter buffer is set to the same value." );
SliderNetBuf->setWhatsThis ( strJitterBufferSize );
TextNetBuf->setWhatsThis ( strJitterBufferSize );
GroupBoxJitterBuffer->setWhatsThis ( strJitterBufferSize );
// init driver button
#ifdef _WIN32
ButtonDriverSetup->setText ( "ASIO Setup" );
#else
// no use for this button for Linux right now, maybe later used
// for Jack
ButtonDriverSetup->hide();
#endif
// init delay and other information controls
CLEDOverallDelay->SetUpdateTime ( 2 * PING_UPDATE_TIME );
CLEDOverallDelay->Reset();
TextLabelPingTime->setText ( "" );
TextLabelOverallDelay->setText ( "" );
TextUpstreamValue->setText ( "" );
// init slider controls ---
// network buffer
SliderNetBuf->setRange ( MIN_NET_BUF_SIZE_NUM_BL, MAX_NET_BUF_SIZE_NUM_BL );
UpdateJitterBufferFrame();
// init combo box containing all available sound cards in the system
cbSoundcard->clear();
for ( int iSndDevIdx = 0; iSndDevIdx < pClient->GetSndCrdNumDev(); iSndDevIdx++ )
{
cbSoundcard->addItem ( pClient->GetSndCrdDeviceName ( iSndDevIdx ).c_str() );
}
cbSoundcard->setCurrentIndex ( pClient->GetSndCrdDev() );
// "OpenChatOnNewMessage" check box
if ( pClient->GetOpenChatOnNewMessage() )
{
cbOpenChatOnNewMessage->setCheckState ( Qt::Checked );
}
else
{
cbOpenChatOnNewMessage->setCheckState ( Qt::Unchecked );
}
// fancy GUI design check box
if ( pClient->GetGUIDesign() == GD_STANDARD )
{
cbGUIDesignFancy->setCheckState ( Qt::Unchecked );
}
else
{
cbGUIDesignFancy->setCheckState ( Qt::Checked );
}
// TODO we disable the fancy GUI switch because the new design
// is not yet finished
cbGUIDesignFancy->setVisible ( false );
// "High Quality Audio" check box
if ( pClient->GetCELTHighQuality() )
{
cbUseHighQualityAudio->setCheckState ( Qt::Checked );
}
else
{
cbUseHighQualityAudio->setCheckState ( Qt::Unchecked );
}
// set text for sound card buffer delay radio buttons
rButBufferDelayPreferred->setText ( GenSndCrdBufferDelayString (
FRAME_SIZE_FACTOR_PREFERRED * SYSTEM_FRAME_SIZE_SAMPLES,
", preferred" ) );
rButBufferDelayDefault->setText ( GenSndCrdBufferDelayString (
FRAME_SIZE_FACTOR_DEFAULT * SYSTEM_FRAME_SIZE_SAMPLES,
", default" ) );
rButBufferDelaySafe->setText ( GenSndCrdBufferDelayString (
FRAME_SIZE_FACTOR_SAFE * SYSTEM_FRAME_SIZE_SAMPLES ) );
// sound card buffer delay inits
SndCrdBufferDelayButtonGroup.addButton ( rButBufferDelayPreferred );
SndCrdBufferDelayButtonGroup.addButton ( rButBufferDelayDefault );
SndCrdBufferDelayButtonGroup.addButton ( rButBufferDelaySafe );
UpdateSoundCardFrame();
// Connections -------------------------------------------------------------
// timers
QObject::connect ( &TimerStatus, SIGNAL ( timeout() ),
this, SLOT ( OnTimerStatus() ) );
QObject::connect ( &TimerPing, SIGNAL ( timeout() ),
this, SLOT ( OnTimerPing() ) );
// slider controls
QObject::connect ( SliderNetBuf, SIGNAL ( valueChanged ( int ) ),
this, SLOT ( OnSliderNetBuf ( int ) ) );
// check boxes
QObject::connect ( cbOpenChatOnNewMessage, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnOpenChatOnNewMessageStateChanged ( int ) ) );
QObject::connect ( cbGUIDesignFancy, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnGUIDesignFancyStateChanged ( int ) ) );
QObject::connect ( cbUseHighQualityAudio, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnUseHighQualityAudioStateChanged ( int ) ) );
QObject::connect ( cbAutoJitBuf, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnAutoJitBuf ( int ) ) );
// combo boxes
QObject::connect ( cbSoundcard, SIGNAL ( activated ( int ) ),
this, SLOT ( OnSoundCrdSelection ( int ) ) );
// buttons
QObject::connect ( ButtonDriverSetup, SIGNAL ( clicked() ),
this, SLOT ( OnDriverSetupBut() ) );
// misc
QObject::connect ( pClient, SIGNAL ( PingTimeReceived ( int ) ),
this, SLOT ( OnPingTimeResult ( int ) ) );
QObject::connect ( &SndCrdBufferDelayButtonGroup,
SIGNAL ( buttonClicked ( QAbstractButton* ) ), this,
SLOT ( OnSndCrdBufferDelayButtonGroupClicked ( QAbstractButton* ) ) );
// Timers ------------------------------------------------------------------
// start timer for status bar
TimerStatus.start ( DISPLAY_UPDATE_TIME );
}
void CClientSettingsDlg::UpdateJitterBufferFrame()
{
// update slider value and text
const int iCurNumNetBuf = pClient->GetSockBufNumFrames();
SliderNetBuf->setValue ( iCurNumNetBuf );
TextNetBuf->setText ( "Size: " + QString().setNum ( iCurNumNetBuf ) );
// if auto setting is enabled, disable slider control
cbAutoJitBuf->setChecked ( pClient->GetDoAutoSockBufSize() );
SliderNetBuf->setEnabled ( !pClient->GetDoAutoSockBufSize() );
TextNetBuf->setEnabled ( !pClient->GetDoAutoSockBufSize() );
}
QString CClientSettingsDlg::GenSndCrdBufferDelayString ( const int iFrameSize,
const QString strAddText )
{
// use two times the buffer delay for the entire delay since
// we have input and output
return QString().setNum ( (double) iFrameSize * 2 *
1000 / SYSTEM_SAMPLE_RATE, 'f', 2 ) + " ms (" +
QString().setNum ( iFrameSize ) + strAddText + ")";
}
void CClientSettingsDlg::UpdateSoundCardFrame()
{
// update slider value and text
const int iCurPrefFrameSizeFactor =
pClient->GetSndCrdPrefFrameSizeFactor();
const int iCurActualBufSize =
pClient->GetSndCrdActualMonoBlSize();
// update radio buttons
switch ( iCurPrefFrameSizeFactor )
{
case FRAME_SIZE_FACTOR_PREFERRED:
rButBufferDelayPreferred->setChecked ( true );
break;
case FRAME_SIZE_FACTOR_DEFAULT:
rButBufferDelayDefault->setChecked ( true );
break;
case FRAME_SIZE_FACTOR_SAFE:
rButBufferDelaySafe->setChecked ( true );
break;
}
// preferred size
const int iPrefBufSize =
iCurPrefFrameSizeFactor * SYSTEM_FRAME_SIZE_SAMPLES;
// actual size (use yellow color if different from preferred size)
const QString strActSizeValues =
GenSndCrdBufferDelayString ( iCurActualBufSize );
if ( iPrefBufSize != iCurActualBufSize )
{
// yellow color if actual buffer size is not the selected one
// but a valid one, red color if actual buffer size is not the
// selected one and is not a vaild one
if ( ( iCurActualBufSize != ( SYSTEM_FRAME_SIZE_SAMPLES * FRAME_SIZE_FACTOR_PREFERRED ) ) &&
( iCurActualBufSize != ( SYSTEM_FRAME_SIZE_SAMPLES * FRAME_SIZE_FACTOR_DEFAULT ) ) &&
( iCurActualBufSize != ( SYSTEM_FRAME_SIZE_SAMPLES * FRAME_SIZE_FACTOR_SAFE ) ) )
{
TextLabelActualSndCrdBufDelay->setText ( "<b><font color=""red"">" +
strActSizeValues + "</font></b>" );
}
else
{
TextLabelActualSndCrdBufDelay->setText ( "<b><font color=""yellow"">" +
strActSizeValues + "</font></b>" );
}
}
else
{
TextLabelActualSndCrdBufDelay->setText ( strActSizeValues );
}
}
void CClientSettingsDlg::showEvent ( QShowEvent* showEvent )
{
// only activate ping timer if window is actually shown
TimerPing.start ( PING_UPDATE_TIME );
UpdateDisplay();
}
void CClientSettingsDlg::hideEvent ( QHideEvent* hideEvent )
{
// if window is closed, stop timer for ping
TimerPing.stop();
}
void CClientSettingsDlg::OnDriverSetupBut()
{
pClient->OpenSndCrdDriverSetup();
}
void CClientSettingsDlg::OnSliderNetBuf ( int value )
{
pClient->SetSockBufNumFrames ( value );
UpdateJitterBufferFrame();
}
void CClientSettingsDlg::OnSliderSndCrdBufferDelay ( int value )
{
pClient->SetSndCrdPrefFrameSizeFactor ( value );
UpdateDisplay();
}
void CClientSettingsDlg::OnSoundCrdSelection ( int iSndDevIdx )
{
const QString strError = pClient->SetSndCrdDev ( iSndDevIdx );
if ( !strError.isEmpty() )
{
QMessageBox::critical ( 0, APP_NAME,
QString ( "The selected audio device could not be used because "
"of the following error: " ) + strError +
QString ( " The previous driver will be selected." ), "Ok", 0 );
// recover old selection
cbSoundcard->setCurrentIndex ( pClient->GetSndCrdDev() );
}
UpdateDisplay();
}
void CClientSettingsDlg::OnAutoJitBuf ( int value )
{
pClient->SetDoAutoSockBufSize ( value == Qt::Checked );
UpdateJitterBufferFrame();
}
void CClientSettingsDlg::OnOpenChatOnNewMessageStateChanged ( int value )
{
pClient->SetOpenChatOnNewMessage ( value == Qt::Checked );
UpdateDisplay();
}
void CClientSettingsDlg::OnGUIDesignFancyStateChanged ( int value )
{
if ( value == Qt::Unchecked )
{
pClient->SetGUIDesign ( GD_STANDARD );
}
else
{
pClient->SetGUIDesign ( GD_ORIGINAL );
}
emit GUIDesignChanged();
UpdateDisplay();
}
void CClientSettingsDlg::OnUseHighQualityAudioStateChanged ( int value )
{
pClient->SetCELTHighQuality ( value == Qt::Checked );
UpdateDisplay();
}
void CClientSettingsDlg::OnSndCrdBufferDelayButtonGroupClicked ( QAbstractButton* button )
{
if ( button == rButBufferDelayPreferred )
{
pClient->SetSndCrdPrefFrameSizeFactor ( FRAME_SIZE_FACTOR_PREFERRED );
}
if ( button == rButBufferDelayDefault )
{
pClient->SetSndCrdPrefFrameSizeFactor ( FRAME_SIZE_FACTOR_DEFAULT );
}
if ( button == rButBufferDelaySafe )
{
pClient->SetSndCrdPrefFrameSizeFactor ( FRAME_SIZE_FACTOR_SAFE );
}
UpdateDisplay();
}
void CClientSettingsDlg::OnTimerPing()
{
// send ping message to server
pClient->SendPingMess();
}
void CClientSettingsDlg::OnPingTimeResult ( int iPingTime )
{
/*
For estimating the overall delay, use the following assumptions:
- the mean delay of a cyclic buffer is half the buffer size (since
for the average it is assumed that the buffer is half filled)
- consider the jitter buffer on the server side, too
*/
// 2 times buffers at client and server divided by 2 (half the buffer
// for the delay) is simply the total socket buffer size
const double dTotalJitterBufferDelayMS =
SYSTEM_BLOCK_DURATION_MS_FLOAT * pClient->GetSockBufNumFrames();
// we assume that we have two period sizes for the input and one for the
// output, therefore we have "3 *" instead of "2 *" (for input and output)
// the actual sound card buffer size
const double dTotalSoundCardDelayMS =
3 * pClient->GetSndCrdActualMonoBlSize() *
1000 / SYSTEM_SAMPLE_RATE;
// network packets are of the same size as the audio packets per definition
const double dDelayToFillNetworkPackets =
pClient->GetSndCrdActualMonoBlSize() *
1000 / SYSTEM_SAMPLE_RATE;
// CELT additional delay at small frame sizes is half a frame size
const double dAdditionalAudioCodecDelay =
SYSTEM_BLOCK_DURATION_MS_FLOAT / 2;
const double dTotalBufferDelay =
dDelayToFillNetworkPackets +
dTotalJitterBufferDelayMS +
dTotalSoundCardDelayMS +
dAdditionalAudioCodecDelay;
const int iOverallDelay =
LlconMath::round ( dTotalBufferDelay + iPingTime );
// apply values to GUI labels, take special care if ping time exceeds
// a certain value
if ( iPingTime > 500 )
{
const QString sErrorText =
"<font color=""red""><b>&#62;500 ms</b></font>";
TextLabelPingTime->setText ( sErrorText );
TextLabelOverallDelay->setText ( sErrorText );
}
else
{
TextLabelPingTime->setText ( QString().setNum ( iPingTime ) + " ms" );
TextLabelOverallDelay->setText (
QString().setNum ( iOverallDelay ) + " ms" );
}
// color definition: < 40 ms green, < 65 ms yellow, otherwise red
if ( iOverallDelay <= 40 )
{
CLEDOverallDelay->SetLight ( MUL_COL_LED_GREEN );
}
else
{
if ( iOverallDelay <= 65 )
{
CLEDOverallDelay->SetLight ( MUL_COL_LED_YELLOW );
}
else
{
CLEDOverallDelay->SetLight ( MUL_COL_LED_RED );
}
}
}
void CClientSettingsDlg::UpdateDisplay()
{
// update slider controls (settings might have been changed)
UpdateJitterBufferFrame();
UpdateSoundCardFrame();
if ( !pClient->IsRunning() )
{
// clear text labels with client parameters
TextLabelPingTime->setText ( "" );
TextLabelOverallDelay->setText ( "" );
TextUpstreamValue->setText ( "" );
}
else
{
// update upstream rate information label (only if client is running)
TextUpstreamValue->setText (
QString().setNum ( pClient->GetUploadRateKbps() ) + " kbps" );
}
}
void CClientSettingsDlg::SetStatus ( const int iMessType, const int iStatus )
{
switch ( iMessType )
{
case MS_JIT_BUF_PUT:
case MS_JIT_BUF_GET:
// network LED shows combined status of put and get
CLEDNetw->SetLight ( iStatus );
break;
case MS_RESET_ALL:
CLEDNetw->Reset();
break;
}
}
/******************************************************************************\
* Copyright (c) 2004-2009
*
* Author(s):
* Volker Fischer
*
******************************************************************************
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\******************************************************************************/
#include "clientsettingsdlg.h"
/* Implementation *************************************************************/
CClientSettingsDlg::CClientSettingsDlg ( CClient* pNCliP, QWidget* parent,
Qt::WindowFlags f ) : pClient ( pNCliP ), QDialog ( parent, f )
{
setupUi ( this );
// add help text to controls
QString strJitterBufferSize = tr ( "<b>Jitter Buffer Size:</b> The size of "
"the network buffer (jitter buffer). The jitter buffer compensates for "
"the network jitter. The larger this buffer is, the more robust the "
"connection is against network jitter but the higher is the latency. "
"This setting is therefore a trade-off between audio drop outs and "
"overall audio delay.<br>By changing this setting, both, the client "
"and the server jitter buffer is set to the same value." );
SliderNetBuf->setWhatsThis ( strJitterBufferSize );
TextNetBuf->setWhatsThis ( strJitterBufferSize );
GroupBoxJitterBuffer->setWhatsThis ( strJitterBufferSize );
// init driver button
#ifdef _WIN32
ButtonDriverSetup->setText ( "ASIO Setup" );
#else
// no use for this button for Linux right now, maybe later used
// for Jack
ButtonDriverSetup->hide();
#endif
// init delay and other information controls
CLEDOverallDelay->SetUpdateTime ( 2 * PING_UPDATE_TIME );
CLEDOverallDelay->Reset();
TextLabelPingTime->setText ( "" );
TextLabelOverallDelay->setText ( "" );
TextUpstreamValue->setText ( "" );
// init slider controls ---
// network buffer
SliderNetBuf->setRange ( MIN_NET_BUF_SIZE_NUM_BL, MAX_NET_BUF_SIZE_NUM_BL );
UpdateJitterBufferFrame();
// init combo box containing all available sound cards in the system
cbSoundcard->clear();
for ( int iSndDevIdx = 0; iSndDevIdx < pClient->GetSndCrdNumDev(); iSndDevIdx++ )
{
cbSoundcard->addItem ( pClient->GetSndCrdDeviceName ( iSndDevIdx ).c_str() );
}
cbSoundcard->setCurrentIndex ( pClient->GetSndCrdDev() );
// "OpenChatOnNewMessage" check box
if ( pClient->GetOpenChatOnNewMessage() )
{
cbOpenChatOnNewMessage->setCheckState ( Qt::Checked );
}
else
{
cbOpenChatOnNewMessage->setCheckState ( Qt::Unchecked );
}
// fancy GUI design check box
if ( pClient->GetGUIDesign() == GD_STANDARD )
{
cbGUIDesignFancy->setCheckState ( Qt::Unchecked );
}
else
{
cbGUIDesignFancy->setCheckState ( Qt::Checked );
}
// TODO we disable the fancy GUI switch because the new design
// is not yet finished
cbGUIDesignFancy->setVisible ( false );
// "High Quality Audio" check box
if ( pClient->GetCELTHighQuality() )
{
cbUseHighQualityAudio->setCheckState ( Qt::Checked );
}
else
{
cbUseHighQualityAudio->setCheckState ( Qt::Unchecked );
}
// set text for sound card buffer delay radio buttons
rButBufferDelayPreferred->setText ( GenSndCrdBufferDelayString (
FRAME_SIZE_FACTOR_PREFERRED * SYSTEM_FRAME_SIZE_SAMPLES,
", preferred" ) );
rButBufferDelayDefault->setText ( GenSndCrdBufferDelayString (
FRAME_SIZE_FACTOR_DEFAULT * SYSTEM_FRAME_SIZE_SAMPLES,
", default" ) );
rButBufferDelaySafe->setText ( GenSndCrdBufferDelayString (
FRAME_SIZE_FACTOR_SAFE * SYSTEM_FRAME_SIZE_SAMPLES ) );
// sound card buffer delay inits
SndCrdBufferDelayButtonGroup.addButton ( rButBufferDelayPreferred );
SndCrdBufferDelayButtonGroup.addButton ( rButBufferDelayDefault );
SndCrdBufferDelayButtonGroup.addButton ( rButBufferDelaySafe );
UpdateSoundCardFrame();
// Connections -------------------------------------------------------------
// timers
QObject::connect ( &TimerStatus, SIGNAL ( timeout() ),
this, SLOT ( OnTimerStatus() ) );
QObject::connect ( &TimerPing, SIGNAL ( timeout() ),
this, SLOT ( OnTimerPing() ) );
// slider controls
QObject::connect ( SliderNetBuf, SIGNAL ( valueChanged ( int ) ),
this, SLOT ( OnSliderNetBuf ( int ) ) );
// check boxes
QObject::connect ( cbOpenChatOnNewMessage, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnOpenChatOnNewMessageStateChanged ( int ) ) );
QObject::connect ( cbGUIDesignFancy, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnGUIDesignFancyStateChanged ( int ) ) );
QObject::connect ( cbUseHighQualityAudio, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnUseHighQualityAudioStateChanged ( int ) ) );
QObject::connect ( cbAutoJitBuf, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnAutoJitBuf ( int ) ) );
// combo boxes
QObject::connect ( cbSoundcard, SIGNAL ( activated ( int ) ),
this, SLOT ( OnSoundCrdSelection ( int ) ) );
// buttons
QObject::connect ( ButtonDriverSetup, SIGNAL ( clicked() ),
this, SLOT ( OnDriverSetupBut() ) );
// misc
QObject::connect ( pClient, SIGNAL ( PingTimeReceived ( int ) ),
this, SLOT ( OnPingTimeResult ( int ) ) );
QObject::connect ( &SndCrdBufferDelayButtonGroup,
SIGNAL ( buttonClicked ( QAbstractButton* ) ), this,
SLOT ( OnSndCrdBufferDelayButtonGroupClicked ( QAbstractButton* ) ) );
// Timers ------------------------------------------------------------------
// start timer for status bar
TimerStatus.start ( DISPLAY_UPDATE_TIME );
}
void CClientSettingsDlg::UpdateJitterBufferFrame()
{
// update slider value and text
const int iCurNumNetBuf = pClient->GetSockBufNumFrames();
SliderNetBuf->setValue ( iCurNumNetBuf );
TextNetBuf->setText ( "Size: " + QString().setNum ( iCurNumNetBuf ) );
// if auto setting is enabled, disable slider control
cbAutoJitBuf->setChecked ( pClient->GetDoAutoSockBufSize() );
SliderNetBuf->setEnabled ( !pClient->GetDoAutoSockBufSize() );
TextNetBuf->setEnabled ( !pClient->GetDoAutoSockBufSize() );
}
QString CClientSettingsDlg::GenSndCrdBufferDelayString ( const int iFrameSize,
const QString strAddText )
{
// use two times the buffer delay for the entire delay since
// we have input and output
return QString().setNum ( (double) iFrameSize * 2 *
1000 / SYSTEM_SAMPLE_RATE, 'f', 2 ) + " ms (" +
QString().setNum ( iFrameSize ) + strAddText + ")";
}
void CClientSettingsDlg::UpdateSoundCardFrame()
{
// update slider value and text
const int iCurPrefFrameSizeFactor =
pClient->GetSndCrdPrefFrameSizeFactor();
const int iCurActualBufSize =
pClient->GetSndCrdActualMonoBlSize();
// update radio buttons
switch ( iCurPrefFrameSizeFactor )
{
case FRAME_SIZE_FACTOR_PREFERRED:
rButBufferDelayPreferred->setChecked ( true );
break;
case FRAME_SIZE_FACTOR_DEFAULT:
rButBufferDelayDefault->setChecked ( true );
break;
case FRAME_SIZE_FACTOR_SAFE:
rButBufferDelaySafe->setChecked ( true );
break;
}
// preferred size
const int iPrefBufSize =
iCurPrefFrameSizeFactor * SYSTEM_FRAME_SIZE_SAMPLES;
// actual size (use yellow color if different from preferred size)
const QString strActSizeValues =
GenSndCrdBufferDelayString ( iCurActualBufSize );
if ( iPrefBufSize != iCurActualBufSize )
{
// yellow color if actual buffer size is not the selected one
// but a valid one, red color if actual buffer size is not the
// selected one and is not a vaild one
if ( ( iCurActualBufSize != ( SYSTEM_FRAME_SIZE_SAMPLES * FRAME_SIZE_FACTOR_PREFERRED ) ) &&
( iCurActualBufSize != ( SYSTEM_FRAME_SIZE_SAMPLES * FRAME_SIZE_FACTOR_DEFAULT ) ) &&
( iCurActualBufSize != ( SYSTEM_FRAME_SIZE_SAMPLES * FRAME_SIZE_FACTOR_SAFE ) ) )
{
TextLabelActualSndCrdBufDelay->setText ( "<b><font color=""red"">" +
strActSizeValues + "</font></b>" );
}
else
{
TextLabelActualSndCrdBufDelay->setText ( "<b><font color=""yellow"">" +
strActSizeValues + "</font></b>" );
}
}
else
{
TextLabelActualSndCrdBufDelay->setText ( strActSizeValues );
}
}
void CClientSettingsDlg::showEvent ( QShowEvent* showEvent )
{
// only activate ping timer if window is actually shown
TimerPing.start ( PING_UPDATE_TIME );
UpdateDisplay();
}
void CClientSettingsDlg::hideEvent ( QHideEvent* hideEvent )
{
// if window is closed, stop timer for ping
TimerPing.stop();
}
void CClientSettingsDlg::OnDriverSetupBut()
{
pClient->OpenSndCrdDriverSetup();
}
void CClientSettingsDlg::OnSliderNetBuf ( int value )
{
pClient->SetSockBufNumFrames ( value );
UpdateJitterBufferFrame();
}
void CClientSettingsDlg::OnSliderSndCrdBufferDelay ( int value )
{
pClient->SetSndCrdPrefFrameSizeFactor ( value );
UpdateDisplay();
}
void CClientSettingsDlg::OnSoundCrdSelection ( int iSndDevIdx )
{
const QString strError = pClient->SetSndCrdDev ( iSndDevIdx );
if ( !strError.isEmpty() )
{
QMessageBox::critical ( 0, APP_NAME,
QString ( "The selected audio device could not be used because "
"of the following error: " ) + strError +
QString ( " The previous driver will be selected." ), "Ok", 0 );
// recover old selection
cbSoundcard->setCurrentIndex ( pClient->GetSndCrdDev() );
}
UpdateDisplay();
}
void CClientSettingsDlg::OnAutoJitBuf ( int value )
{
pClient->SetDoAutoSockBufSize ( value == Qt::Checked );
UpdateJitterBufferFrame();
}
void CClientSettingsDlg::OnOpenChatOnNewMessageStateChanged ( int value )
{
pClient->SetOpenChatOnNewMessage ( value == Qt::Checked );
UpdateDisplay();
}
void CClientSettingsDlg::OnGUIDesignFancyStateChanged ( int value )
{
if ( value == Qt::Unchecked )
{
pClient->SetGUIDesign ( GD_STANDARD );
}
else
{
pClient->SetGUIDesign ( GD_ORIGINAL );
}
emit GUIDesignChanged();
UpdateDisplay();
}
void CClientSettingsDlg::OnUseHighQualityAudioStateChanged ( int value )
{
pClient->SetCELTHighQuality ( value == Qt::Checked );
UpdateDisplay();
}
void CClientSettingsDlg::OnSndCrdBufferDelayButtonGroupClicked ( QAbstractButton* button )
{
if ( button == rButBufferDelayPreferred )
{
pClient->SetSndCrdPrefFrameSizeFactor ( FRAME_SIZE_FACTOR_PREFERRED );
}
if ( button == rButBufferDelayDefault )
{
pClient->SetSndCrdPrefFrameSizeFactor ( FRAME_SIZE_FACTOR_DEFAULT );
}
if ( button == rButBufferDelaySafe )
{
pClient->SetSndCrdPrefFrameSizeFactor ( FRAME_SIZE_FACTOR_SAFE );
}
UpdateDisplay();
}
void CClientSettingsDlg::OnTimerPing()
{
// send ping message to server
pClient->SendPingMess();
}
void CClientSettingsDlg::OnPingTimeResult ( int iPingTime )
{
/*
For estimating the overall delay, use the following assumptions:
- the mean delay of a cyclic buffer is half the buffer size (since
for the average it is assumed that the buffer is half filled)
- consider the jitter buffer on the server side, too
*/
// 2 times buffers at client and server divided by 2 (half the buffer
// for the delay) is simply the total socket buffer size
const double dTotalJitterBufferDelayMS =
SYSTEM_BLOCK_DURATION_MS_FLOAT * pClient->GetSockBufNumFrames();
// we assume that we have two period sizes for the input and one for the
// output, therefore we have "3 *" instead of "2 *" (for input and output)
// the actual sound card buffer size
const double dTotalSoundCardDelayMS =
3 * pClient->GetSndCrdActualMonoBlSize() *
1000 / SYSTEM_SAMPLE_RATE;
// network packets are of the same size as the audio packets per definition
const double dDelayToFillNetworkPackets =
pClient->GetSndCrdActualMonoBlSize() *
1000 / SYSTEM_SAMPLE_RATE;
// CELT additional delay at small frame sizes is half a frame size
const double dAdditionalAudioCodecDelay =
SYSTEM_BLOCK_DURATION_MS_FLOAT / 2;
const double dTotalBufferDelay =
dDelayToFillNetworkPackets +
dTotalJitterBufferDelayMS +
dTotalSoundCardDelayMS +
dAdditionalAudioCodecDelay;
const int iOverallDelay =
LlconMath::round ( dTotalBufferDelay + iPingTime );
// apply values to GUI labels, take special care if ping time exceeds
// a certain value
if ( iPingTime > 500 )
{
const QString sErrorText =
"<font color=""red""><b>&#62;500 ms</b></font>";
TextLabelPingTime->setText ( sErrorText );
TextLabelOverallDelay->setText ( sErrorText );
}
else
{
TextLabelPingTime->setText ( QString().setNum ( iPingTime ) + " ms" );
TextLabelOverallDelay->setText (
QString().setNum ( iOverallDelay ) + " ms" );
}
// color definition: < 40 ms green, < 65 ms yellow, otherwise red
if ( iOverallDelay <= 40 )
{
CLEDOverallDelay->SetLight ( MUL_COL_LED_GREEN );
}
else
{
if ( iOverallDelay <= 65 )
{
CLEDOverallDelay->SetLight ( MUL_COL_LED_YELLOW );
}
else
{
CLEDOverallDelay->SetLight ( MUL_COL_LED_RED );
}
}
}
void CClientSettingsDlg::UpdateDisplay()
{
// update slider controls (settings might have been changed)
UpdateJitterBufferFrame();
UpdateSoundCardFrame();
if ( !pClient->IsRunning() )
{
// clear text labels with client parameters
TextLabelPingTime->setText ( "" );
TextLabelOverallDelay->setText ( "" );
TextUpstreamValue->setText ( "" );
}
else
{
// update upstream rate information label (only if client is running)
TextUpstreamValue->setText (
QString().setNum ( pClient->GetUploadRateKbps() ) + " kbps" );
}
}
void CClientSettingsDlg::SetStatus ( const int iMessType, const int iStatus )
{
switch ( iMessType )
{
case MS_JIT_BUF_PUT:
case MS_JIT_BUF_GET:
// network LED shows combined status of put and get
CLEDNetw->SetLight ( iStatus );
break;
case MS_RESET_ALL:
CLEDNetw->Reset();
break;
}
}

View file

@ -1,95 +1,95 @@
/******************************************************************************\
* Copyright (c) 2004-2009
*
* Author(s):
* Volker Fischer
*
******************************************************************************
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\******************************************************************************/
#include <qlabel.h>
#include <qstring.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qprogressbar.h>
#include <qwhatsthis.h>
#include <qtimer.h>
#include <qslider.h>
#include <qradiobutton.h>
#include <qmenubar.h>
#include <qlayout.h>
#include <qbuttongroup.h>
#include "global.h"
#include "client.h"
#include "multicolorled.h"
#ifdef _WIN32
# include "../windows/moc/clientsettingsdlgbase.h"
#else
# include "moc/clientsettingsdlgbase.h"
#endif
/* Definitions ****************************************************************/
// update time for GUI controls
#define DISPLAY_UPDATE_TIME 1000 // ms
#define PING_UPDATE_TIME 500 // ms
/* Classes ********************************************************************/
class CClientSettingsDlg : public QDialog, private Ui_CClientSettingsDlgBase
{
Q_OBJECT
public:
CClientSettingsDlg ( CClient* pNCliP, QWidget* parent = 0,
Qt::WindowFlags f = 0 );
void SetStatus ( const int iMessType, const int iStatus );
protected:
void UpdateJitterBufferFrame();
void UpdateSoundCardFrame();
QString GenSndCrdBufferDelayString ( const int iFrameSize,
const QString strAddText = "" );
virtual void showEvent ( QShowEvent* showEvent );
virtual void hideEvent ( QHideEvent* hideEvent );
CClient* pClient;
QTimer TimerStatus;
QTimer TimerPing;
QButtonGroup SndCrdBufferDelayButtonGroup;
void UpdateDisplay();
public slots:
void OnTimerStatus() { UpdateDisplay(); }
void OnTimerPing();
void OnSliderNetBuf ( int value );
void OnSliderSndCrdBufferDelay ( int value );
void OnAutoJitBuf ( int value );
void OnOpenChatOnNewMessageStateChanged ( int value );
void OnGUIDesignFancyStateChanged ( int value );
void OnUseHighQualityAudioStateChanged ( int value );
void OnSndCrdBufferDelayButtonGroupClicked ( QAbstractButton* button );
void OnPingTimeResult ( int iPingTime );
void OnSoundCrdSelection ( int iSndDevIdx );
void OnDriverSetupBut();
signals:
void GUIDesignChanged();
};
/******************************************************************************\
* Copyright (c) 2004-2009
*
* Author(s):
* Volker Fischer
*
******************************************************************************
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\******************************************************************************/
#include <qlabel.h>
#include <qstring.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qprogressbar.h>
#include <qwhatsthis.h>
#include <qtimer.h>
#include <qslider.h>
#include <qradiobutton.h>
#include <qmenubar.h>
#include <qlayout.h>
#include <qbuttongroup.h>
#include "global.h"
#include "client.h"
#include "multicolorled.h"
#ifdef _WIN32
# include "../windows/moc/clientsettingsdlgbase.h"
#else
# include "moc/clientsettingsdlgbase.h"
#endif
/* Definitions ****************************************************************/
// update time for GUI controls
#define DISPLAY_UPDATE_TIME 1000 // ms
#define PING_UPDATE_TIME 500 // ms
/* Classes ********************************************************************/
class CClientSettingsDlg : public QDialog, private Ui_CClientSettingsDlgBase
{
Q_OBJECT
public:
CClientSettingsDlg ( CClient* pNCliP, QWidget* parent = 0,
Qt::WindowFlags f = 0 );
void SetStatus ( const int iMessType, const int iStatus );
protected:
void UpdateJitterBufferFrame();
void UpdateSoundCardFrame();
QString GenSndCrdBufferDelayString ( const int iFrameSize,
const QString strAddText = "" );
virtual void showEvent ( QShowEvent* showEvent );
virtual void hideEvent ( QHideEvent* hideEvent );
CClient* pClient;
QTimer TimerStatus;
QTimer TimerPing;
QButtonGroup SndCrdBufferDelayButtonGroup;
void UpdateDisplay();
public slots:
void OnTimerStatus() { UpdateDisplay(); }
void OnTimerPing();
void OnSliderNetBuf ( int value );
void OnSliderSndCrdBufferDelay ( int value );
void OnAutoJitBuf ( int value );
void OnOpenChatOnNewMessageStateChanged ( int value );
void OnGUIDesignFancyStateChanged ( int value );
void OnUseHighQualityAudioStateChanged ( int value );
void OnSndCrdBufferDelayButtonGroupClicked ( QAbstractButton* button );
void OnPingTimeResult ( int iPingTime );
void OnSoundCrdSelection ( int iSndDevIdx );
void OnDriverSetupBut();
signals:
void GUIDesignChanged();
};

File diff suppressed because it is too large Load diff

View file

@ -88,9 +88,9 @@ public:
void CreateAndImmSendAcknMess ( const int& iID, const int& iCnt );
bool ParseMessage ( const CVector<uint8_t>& vecbyData,
const int iNumBytes );
bool IsProtocolMessage ( const CVector<uint8_t>& vecbyData,
const int iNumBytes );
bool IsProtocolMessage ( const CVector<uint8_t>& vecbyData,
const int iNumBytes );
protected:

File diff suppressed because it is too large Load diff

View file

@ -1,452 +1,452 @@
/******************************************************************************\
* Copyright (c) 2004-2009
*
* Author(s):
* Volker Fischer
*
******************************************************************************
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\******************************************************************************/
#include "serverlogging.h"
/* Implementation *************************************************************/
CHistoryGraph::CHistoryGraph() :
sFileName ( "" ),
bDoHistory ( false ),
vHistoryDataFifo ( NUM_ITEMS_HISTORY ),
PlotCanvasRect ( 0, 0, 600, 450 ), // defines total size of graph
iNumTicksX ( 0 ), // just an initialization value, will be overwritten
iYAxisStart ( 0 ),
iYAxisEnd ( 24 ),
iNumTicksY ( 5 ),
iGridFrameOffset ( 10 ),
iGridWidthWeekend ( 3 ), // should be odd value
iTextOffsetToGrid ( 3 ),
iXAxisTextHeight ( 22 ),
iMarkerSizeNewCon ( 11 ),
iMarkerSizeServSt ( 9 ),
AxisFont ( "Arial", 12 ),
iTextOffsetX ( 18 ),
PlotBackgroundColor ( Qt::white ), // background
PlotFrameColor ( Qt::black ), // frame
PlotGridColor ( Qt::gray ), // grid
PlotTextColor ( Qt::black ), // text
PlotMarkerNewColor ( Qt::darkCyan ), // marker for new connection
PlotMarkerNewLocalColor ( Qt::blue ), // marker for new local connection
PlotMarkerStopColor ( Qt::red ), // marker for server stop
PlotPixmap ( 1, 1, QImage::Format_RGB32 )
{
// generate plot grid frame rectangle
PlotGridFrame.setRect ( PlotCanvasRect.x() + iGridFrameOffset,
PlotCanvasRect.y() + iGridFrameOffset,
PlotCanvasRect.width() - 2 * iGridFrameOffset,
PlotCanvasRect.height() - 2 * iGridFrameOffset - iXAxisTextHeight );
// scale pixmap to correct size
PlotPixmap = PlotPixmap.scaled (
PlotCanvasRect.width(), PlotCanvasRect.height() );
// connections
QObject::connect ( &TimerDailyUpdate, SIGNAL ( timeout() ),
this, SLOT ( OnTimerDailyUpdate() ) );
}
void CHistoryGraph::Start ( const QString& sNewFileName )
{
if ( !sNewFileName.isEmpty() )
{
// save file name
sFileName = sNewFileName;
// set enable flag
bDoHistory = true;
// enable timer (update once a day)
TimerDailyUpdate.start ( 3600000 * 24 );
// initial update (empty graph)
Update();
}
}
void CHistoryGraph::DrawFrame ( const int iNewNumTicksX )
{
int i;
// store number of x-axis ticks (number of days we want to draw
// the history for
iNumTicksX = iNewNumTicksX;
// clear base pixmap for new plotting
PlotPixmap.fill ( PlotBackgroundColor.rgb() ); // fill background
// create painter
QPainter PlotPainter ( &PlotPixmap );
// create actual plot region (grid frame) ----------------------------------
PlotPainter.setPen ( PlotFrameColor );
PlotPainter.drawRect ( PlotGridFrame );
// calculate step for x-axis ticks so that we get the desired number of
// ticks -> 5 ticks
// TODO the following equation does not work as expected but results are acceptable
// we want to have "floor ( iNumTicksX / 5 )" which is the same as
// "iNumTicksX / 5" since "iNumTicksX" is an integer variable
const int iXAxisTickStep = iNumTicksX / 5 + 1;
// grid (ticks) for x-axis
dXSpace = static_cast<double> ( PlotGridFrame.width() ) / ( iNumTicksX + 1 );
for ( i = 0; i < iNumTicksX; i++ )
{
int iBottomExtraTickLen = 0;
const int iCurX = PlotGridFrame.x() + static_cast<int> ( dXSpace * ( i + 1 ) );
const QDate curXAxisDate = curDate.addDays ( i - iNumTicksX + 1 );
// text (print only every "iXAxisTickStep" tick)
if ( !( i % iXAxisTickStep ) )
{
PlotPainter.setPen ( PlotTextColor );
PlotPainter.setFont ( AxisFont );
PlotPainter.drawText (
QPoint ( iCurX - iTextOffsetX,
PlotGridFrame.bottom() + iXAxisTextHeight + iTextOffsetToGrid ),
curXAxisDate.toString ( "dd.MM." ) );
iBottomExtraTickLen = 5;
}
// regular grid
PlotPainter.setPen ( PlotGridColor );
PlotPainter.drawLine ( iCurX, 1 + PlotGridFrame.y(),
iCurX, PlotGridFrame.bottom() + iBottomExtraTickLen );
// different grid width for weekends (overwrite regular grid)
if ( ( curXAxisDate.dayOfWeek() == 6 ) || // check for Saturday
( curXAxisDate.dayOfWeek() == 7 ) ) // check for Sunday
{
const int iGridWidthWeekendHalf = iGridWidthWeekend / 2;
PlotPainter.setPen ( QPen ( PlotGridColor, iGridWidthWeekend ) );
PlotPainter.drawLine ( iCurX, 1 + PlotGridFrame.y() + iGridWidthWeekendHalf,
iCurX, PlotGridFrame.bottom() - iGridWidthWeekendHalf );
}
}
// grid (ticks) for y-axis, draw iNumTicksY - 2 grid lines and
// iNumTicksY - 1 text labels (the lowest grid line is the grid frame)
iYSpace = PlotGridFrame.height() / ( iNumTicksY - 1 );
for ( i = 0; i < ( iNumTicksY - 1 ); i++ )
{
const int iCurY = PlotGridFrame.y() + iYSpace * ( i + 1 );
// text
PlotPainter.setPen ( PlotTextColor );
PlotPainter.setFont ( AxisFont );
PlotPainter.drawText ( QPoint (
PlotGridFrame.x() + iTextOffsetToGrid,
iCurY - iTextOffsetToGrid ),
QString ( "%1:00" ).arg (
( iYAxisEnd - iYAxisStart ) / ( iNumTicksY - 1 ) *
( ( iNumTicksY - 2 ) - i ) ) );
// grid (do not overwrite frame)
if ( i < ( iNumTicksY - 2 ) )
{
PlotPainter.setPen ( PlotGridColor );
PlotPainter.drawLine ( PlotGridFrame.x(), iCurY,
PlotGridFrame.right(), iCurY );
}
}
}
void CHistoryGraph::AddMarker ( const SHistoryData& curHistoryData )
{
// calculate x-axis offset (difference of days compared to
// current date)
const int iXAxisOffs =
curDate.daysTo ( curHistoryData.DateTime.date() );
// check range, if out of range, do not plot anything
if ( -iXAxisOffs > ( iNumTicksX - 1 ) )
{
return;
}
// calculate y-axis offset (consider hours and minutes)
const double dYAxisOffs = 24 - curHistoryData.DateTime.time().hour() -
static_cast<double> ( curHistoryData.DateTime.time().minute() ) / 60;
// calculate the actual point in the graph (in pixels)
const QPoint curPoint (
PlotGridFrame.x() + static_cast<int> ( dXSpace * ( iNumTicksX + iXAxisOffs ) ),
PlotGridFrame.y() + static_cast<int> ( static_cast<double> (
PlotGridFrame.height() ) / ( iYAxisEnd - iYAxisStart ) * dYAxisOffs ) );
// create painter for plot
QPainter PlotPainter ( &PlotPixmap );
// we use different markers for new connection and server stop items
switch ( curHistoryData.Type )
{
case HIT_SERVER_STOP:
// filled circle marker
PlotPainter.setPen ( QPen ( QBrush ( PlotMarkerStopColor ),
iMarkerSizeServSt, Qt::SolidLine, Qt::RoundCap ) );
break;
case HIT_LOCAL_CONNECTION:
// filled square marker
PlotPainter.setPen ( QPen ( QBrush ( PlotMarkerNewLocalColor ),
iMarkerSizeNewCon ) );
break;
case HIT_REMOTE_CONNECTION:
// filled square marker
PlotPainter.setPen ( QPen ( QBrush ( PlotMarkerNewColor ),
iMarkerSizeNewCon ) );
break;
}
PlotPainter.drawPoint ( curPoint );
}
void CHistoryGraph::Save ( const QString sFileName )
{
// save plot as a file
PlotPixmap.save ( sFileName, "JPG", 90 );
}
void CHistoryGraph::Add ( const QDateTime& newDateTime,
const QHostAddress ClientInetAddr )
{
if ( bDoHistory )
{
// add element to history, distinguish between a local connection
// and a remote connection
if ( ( ClientInetAddr == QHostAddress ( "127.0.0.1" ) ) ||
( ClientInetAddr.toString().left ( 7 ).compare ( "192.168" ) == 0 ) )
{
// local connection
Add ( newDateTime, CHistoryGraph::HIT_LOCAL_CONNECTION );
}
else
{
// remote connection
Add ( newDateTime, CHistoryGraph::HIT_REMOTE_CONNECTION );
}
}
}
void CHistoryGraph::Add ( const QDateTime& newDateTime,
const EHistoryItemType curType )
{
if ( bDoHistory )
{
// create and add new element in FIFO
SHistoryData curHistoryData;
curHistoryData.DateTime = newDateTime;
curHistoryData.Type = curType;
vHistoryDataFifo.Add ( curHistoryData );
}
}
void CHistoryGraph::Update()
{
if ( bDoHistory )
{
int i;
// store current date for reference
curDate = QDate::currentDate();
// get oldest date in history
QDate oldestDate = curDate.addDays ( 1 ); // one day in the future
const int iNumItemsForHistory = vHistoryDataFifo.Size();
for ( i = 0; i < iNumItemsForHistory; i++ )
{
// only use valid dates
if ( vHistoryDataFifo[i].DateTime.date().isValid() )
{
if ( vHistoryDataFifo[i].DateTime.date() < oldestDate )
{
oldestDate = vHistoryDataFifo[i].DateTime.date();
}
}
}
const int iNumDaysInHistory = -curDate.daysTo ( oldestDate ) + 1;
// draw frame of the graph
DrawFrame ( iNumDaysInHistory );
// add markers
for ( i = 0; i < iNumItemsForHistory; i++ )
{
AddMarker ( vHistoryDataFifo[i] );
}
// save graph as picture in file
Save ( sFileName );
}
}
// Server logging --------------------------------------------------------------
CServerLogging::~CServerLogging()
{
// close logging file of open
if ( File.isOpen() )
{
File.close();
}
}
void CServerLogging::Start ( const QString& strLoggingFileName )
{
// open file
File.setFileName ( strLoggingFileName );
if ( File.open ( QIODevice::Append | QIODevice::Text ) )
{
bDoLogging = true;
}
}
void CServerLogging::EnableHistory ( const QString& strHistoryFileName )
{
HistoryGraph.Start ( strHistoryFileName );
}
void CServerLogging::AddNewConnection ( const QHostAddress& ClientInetAddr )
{
// logging of new connected channel
const QString strLogStr = CurTimeDatetoLogString() + ", " +
ClientInetAddr.toString() + ", connected";
#ifndef _WIN32
QTextStream tsConsoloeStream ( stdout );
tsConsoloeStream << strLogStr << endl; // on console
#endif
*this << strLogStr; // in log file
// add element to history
HistoryGraph.Add ( QDateTime::currentDateTime(), ClientInetAddr );
}
void CServerLogging::AddServerStopped()
{
const QString strLogStr = CurTimeDatetoLogString() + ",, server stopped "
"-------------------------------------";
#ifndef _WIN32
QTextStream tsConsoloeStream ( stdout );
tsConsoloeStream << strLogStr << endl; // on console
#endif
*this << strLogStr; // in log file
// add element to history and update on server stop
HistoryGraph.Add ( QDateTime::currentDateTime(),
CHistoryGraph::HIT_SERVER_STOP );
HistoryGraph.Update();
}
void CServerLogging::operator<< ( const QString& sNewStr )
{
if ( bDoLogging )
{
// append new line in logging file
QTextStream out ( &File );
out << sNewStr << endl;
File.flush();
}
}
void CServerLogging::ParseLogFile ( const QString& strFileName )
{
// open file for reading
QFile LogFile ( strFileName );
LogFile.open ( QIODevice::ReadOnly | QIODevice::Text );
QTextStream inStream ( &LogFile );
// read all content from file
while ( !inStream.atEnd() )
{
// get a new line from log file
QString strCurLine = inStream.readLine();
// parse log file line
QStringList strlistCurLine = strCurLine.split( "," );
// check number of separated strings condition
if ( strlistCurLine.size() == 4 )
{
// first entry
QDate curDate =
QDate::fromString ( strlistCurLine.at ( 0 ).trimmed(),
"d.M.yyyy" );
// second entry
QTime curTime =
QTime::fromString ( strlistCurLine.at ( 1 ).trimmed(),
"hh:mm:ss" );
if ( curDate.isValid() && curTime.isValid() )
{
QDateTime curDateTime ( curDate, curTime );
// check if server stop or new client connection
QString strAddress = strlistCurLine.at ( 2 ).trimmed();
if ( strAddress.isEmpty() )
{
// server stop
HistoryGraph.Add ( curDateTime,
CHistoryGraph::HIT_SERVER_STOP );
}
else
{
QHostAddress curAddress;
// third entry is IP address
if ( curAddress.setAddress ( strlistCurLine.at ( 2 ).trimmed() ) )
{
// new client connection
HistoryGraph.Add ( curDateTime, curAddress );
}
}
}
}
}
HistoryGraph.Update();
}
QString CServerLogging::CurTimeDatetoLogString()
{
// time and date to string conversion
const QDateTime curDateTime = QDateTime::currentDateTime();
// format date and time output according to "3.9.2006, 11:38:08"
return QString().setNum ( curDateTime.date().day() ) + "." +
QString().setNum ( curDateTime.date().month() ) + "." +
QString().setNum ( curDateTime.date().year() ) + ", " +
curDateTime.time().toString();
}
/******************************************************************************\
* Copyright (c) 2004-2009
*
* Author(s):
* Volker Fischer
*
******************************************************************************
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\******************************************************************************/
#include "serverlogging.h"
/* Implementation *************************************************************/
CHistoryGraph::CHistoryGraph() :
sFileName ( "" ),
bDoHistory ( false ),
vHistoryDataFifo ( NUM_ITEMS_HISTORY ),
PlotCanvasRect ( 0, 0, 600, 450 ), // defines total size of graph
iNumTicksX ( 0 ), // just an initialization value, will be overwritten
iYAxisStart ( 0 ),
iYAxisEnd ( 24 ),
iNumTicksY ( 5 ),
iGridFrameOffset ( 10 ),
iGridWidthWeekend ( 3 ), // should be odd value
iTextOffsetToGrid ( 3 ),
iXAxisTextHeight ( 22 ),
iMarkerSizeNewCon ( 11 ),
iMarkerSizeServSt ( 9 ),
AxisFont ( "Arial", 12 ),
iTextOffsetX ( 18 ),
PlotBackgroundColor ( Qt::white ), // background
PlotFrameColor ( Qt::black ), // frame
PlotGridColor ( Qt::gray ), // grid
PlotTextColor ( Qt::black ), // text
PlotMarkerNewColor ( Qt::darkCyan ), // marker for new connection
PlotMarkerNewLocalColor ( Qt::blue ), // marker for new local connection
PlotMarkerStopColor ( Qt::red ), // marker for server stop
PlotPixmap ( 1, 1, QImage::Format_RGB32 )
{
// generate plot grid frame rectangle
PlotGridFrame.setRect ( PlotCanvasRect.x() + iGridFrameOffset,
PlotCanvasRect.y() + iGridFrameOffset,
PlotCanvasRect.width() - 2 * iGridFrameOffset,
PlotCanvasRect.height() - 2 * iGridFrameOffset - iXAxisTextHeight );
// scale pixmap to correct size
PlotPixmap = PlotPixmap.scaled (
PlotCanvasRect.width(), PlotCanvasRect.height() );
// connections
QObject::connect ( &TimerDailyUpdate, SIGNAL ( timeout() ),
this, SLOT ( OnTimerDailyUpdate() ) );
}
void CHistoryGraph::Start ( const QString& sNewFileName )
{
if ( !sNewFileName.isEmpty() )
{
// save file name
sFileName = sNewFileName;
// set enable flag
bDoHistory = true;
// enable timer (update once a day)
TimerDailyUpdate.start ( 3600000 * 24 );
// initial update (empty graph)
Update();
}
}
void CHistoryGraph::DrawFrame ( const int iNewNumTicksX )
{
int i;
// store number of x-axis ticks (number of days we want to draw
// the history for
iNumTicksX = iNewNumTicksX;
// clear base pixmap for new plotting
PlotPixmap.fill ( PlotBackgroundColor.rgb() ); // fill background
// create painter
QPainter PlotPainter ( &PlotPixmap );
// create actual plot region (grid frame) ----------------------------------
PlotPainter.setPen ( PlotFrameColor );
PlotPainter.drawRect ( PlotGridFrame );
// calculate step for x-axis ticks so that we get the desired number of
// ticks -> 5 ticks
// TODO the following equation does not work as expected but results are acceptable
// we want to have "floor ( iNumTicksX / 5 )" which is the same as
// "iNumTicksX / 5" since "iNumTicksX" is an integer variable
const int iXAxisTickStep = iNumTicksX / 5 + 1;
// grid (ticks) for x-axis
dXSpace = static_cast<double> ( PlotGridFrame.width() ) / ( iNumTicksX + 1 );
for ( i = 0; i < iNumTicksX; i++ )
{
int iBottomExtraTickLen = 0;
const int iCurX = PlotGridFrame.x() + static_cast<int> ( dXSpace * ( i + 1 ) );
const QDate curXAxisDate = curDate.addDays ( i - iNumTicksX + 1 );
// text (print only every "iXAxisTickStep" tick)
if ( !( i % iXAxisTickStep ) )
{
PlotPainter.setPen ( PlotTextColor );
PlotPainter.setFont ( AxisFont );
PlotPainter.drawText (
QPoint ( iCurX - iTextOffsetX,
PlotGridFrame.bottom() + iXAxisTextHeight + iTextOffsetToGrid ),
curXAxisDate.toString ( "dd.MM." ) );
iBottomExtraTickLen = 5;
}
// regular grid
PlotPainter.setPen ( PlotGridColor );
PlotPainter.drawLine ( iCurX, 1 + PlotGridFrame.y(),
iCurX, PlotGridFrame.bottom() + iBottomExtraTickLen );
// different grid width for weekends (overwrite regular grid)
if ( ( curXAxisDate.dayOfWeek() == 6 ) || // check for Saturday
( curXAxisDate.dayOfWeek() == 7 ) ) // check for Sunday
{
const int iGridWidthWeekendHalf = iGridWidthWeekend / 2;
PlotPainter.setPen ( QPen ( PlotGridColor, iGridWidthWeekend ) );
PlotPainter.drawLine ( iCurX, 1 + PlotGridFrame.y() + iGridWidthWeekendHalf,
iCurX, PlotGridFrame.bottom() - iGridWidthWeekendHalf );
}
}
// grid (ticks) for y-axis, draw iNumTicksY - 2 grid lines and
// iNumTicksY - 1 text labels (the lowest grid line is the grid frame)
iYSpace = PlotGridFrame.height() / ( iNumTicksY - 1 );
for ( i = 0; i < ( iNumTicksY - 1 ); i++ )
{
const int iCurY = PlotGridFrame.y() + iYSpace * ( i + 1 );
// text
PlotPainter.setPen ( PlotTextColor );
PlotPainter.setFont ( AxisFont );
PlotPainter.drawText ( QPoint (
PlotGridFrame.x() + iTextOffsetToGrid,
iCurY - iTextOffsetToGrid ),
QString ( "%1:00" ).arg (
( iYAxisEnd - iYAxisStart ) / ( iNumTicksY - 1 ) *
( ( iNumTicksY - 2 ) - i ) ) );
// grid (do not overwrite frame)
if ( i < ( iNumTicksY - 2 ) )
{
PlotPainter.setPen ( PlotGridColor );
PlotPainter.drawLine ( PlotGridFrame.x(), iCurY,
PlotGridFrame.right(), iCurY );
}
}
}
void CHistoryGraph::AddMarker ( const SHistoryData& curHistoryData )
{
// calculate x-axis offset (difference of days compared to
// current date)
const int iXAxisOffs =
curDate.daysTo ( curHistoryData.DateTime.date() );
// check range, if out of range, do not plot anything
if ( -iXAxisOffs > ( iNumTicksX - 1 ) )
{
return;
}
// calculate y-axis offset (consider hours and minutes)
const double dYAxisOffs = 24 - curHistoryData.DateTime.time().hour() -
static_cast<double> ( curHistoryData.DateTime.time().minute() ) / 60;
// calculate the actual point in the graph (in pixels)
const QPoint curPoint (
PlotGridFrame.x() + static_cast<int> ( dXSpace * ( iNumTicksX + iXAxisOffs ) ),
PlotGridFrame.y() + static_cast<int> ( static_cast<double> (
PlotGridFrame.height() ) / ( iYAxisEnd - iYAxisStart ) * dYAxisOffs ) );
// create painter for plot
QPainter PlotPainter ( &PlotPixmap );
// we use different markers for new connection and server stop items
switch ( curHistoryData.Type )
{
case HIT_SERVER_STOP:
// filled circle marker
PlotPainter.setPen ( QPen ( QBrush ( PlotMarkerStopColor ),
iMarkerSizeServSt, Qt::SolidLine, Qt::RoundCap ) );
break;
case HIT_LOCAL_CONNECTION:
// filled square marker
PlotPainter.setPen ( QPen ( QBrush ( PlotMarkerNewLocalColor ),
iMarkerSizeNewCon ) );
break;
case HIT_REMOTE_CONNECTION:
// filled square marker
PlotPainter.setPen ( QPen ( QBrush ( PlotMarkerNewColor ),
iMarkerSizeNewCon ) );
break;
}
PlotPainter.drawPoint ( curPoint );
}
void CHistoryGraph::Save ( const QString sFileName )
{
// save plot as a file
PlotPixmap.save ( sFileName, "JPG", 90 );
}
void CHistoryGraph::Add ( const QDateTime& newDateTime,
const QHostAddress ClientInetAddr )
{
if ( bDoHistory )
{
// add element to history, distinguish between a local connection
// and a remote connection
if ( ( ClientInetAddr == QHostAddress ( "127.0.0.1" ) ) ||
( ClientInetAddr.toString().left ( 7 ).compare ( "192.168" ) == 0 ) )
{
// local connection
Add ( newDateTime, CHistoryGraph::HIT_LOCAL_CONNECTION );
}
else
{
// remote connection
Add ( newDateTime, CHistoryGraph::HIT_REMOTE_CONNECTION );
}
}
}
void CHistoryGraph::Add ( const QDateTime& newDateTime,
const EHistoryItemType curType )
{
if ( bDoHistory )
{
// create and add new element in FIFO
SHistoryData curHistoryData;
curHistoryData.DateTime = newDateTime;
curHistoryData.Type = curType;
vHistoryDataFifo.Add ( curHistoryData );
}
}
void CHistoryGraph::Update()
{
if ( bDoHistory )
{
int i;
// store current date for reference
curDate = QDate::currentDate();
// get oldest date in history
QDate oldestDate = curDate.addDays ( 1 ); // one day in the future
const int iNumItemsForHistory = vHistoryDataFifo.Size();
for ( i = 0; i < iNumItemsForHistory; i++ )
{
// only use valid dates
if ( vHistoryDataFifo[i].DateTime.date().isValid() )
{
if ( vHistoryDataFifo[i].DateTime.date() < oldestDate )
{
oldestDate = vHistoryDataFifo[i].DateTime.date();
}
}
}
const int iNumDaysInHistory = -curDate.daysTo ( oldestDate ) + 1;
// draw frame of the graph
DrawFrame ( iNumDaysInHistory );
// add markers
for ( i = 0; i < iNumItemsForHistory; i++ )
{
AddMarker ( vHistoryDataFifo[i] );
}
// save graph as picture in file
Save ( sFileName );
}
}
// Server logging --------------------------------------------------------------
CServerLogging::~CServerLogging()
{
// close logging file of open
if ( File.isOpen() )
{
File.close();
}
}
void CServerLogging::Start ( const QString& strLoggingFileName )
{
// open file
File.setFileName ( strLoggingFileName );
if ( File.open ( QIODevice::Append | QIODevice::Text ) )
{
bDoLogging = true;
}
}
void CServerLogging::EnableHistory ( const QString& strHistoryFileName )
{
HistoryGraph.Start ( strHistoryFileName );
}
void CServerLogging::AddNewConnection ( const QHostAddress& ClientInetAddr )
{
// logging of new connected channel
const QString strLogStr = CurTimeDatetoLogString() + ", " +
ClientInetAddr.toString() + ", connected";
#ifndef _WIN32
QTextStream tsConsoloeStream ( stdout );
tsConsoloeStream << strLogStr << endl; // on console
#endif
*this << strLogStr; // in log file
// add element to history
HistoryGraph.Add ( QDateTime::currentDateTime(), ClientInetAddr );
}
void CServerLogging::AddServerStopped()
{
const QString strLogStr = CurTimeDatetoLogString() + ",, server stopped "
"-------------------------------------";
#ifndef _WIN32
QTextStream tsConsoloeStream ( stdout );
tsConsoloeStream << strLogStr << endl; // on console
#endif
*this << strLogStr; // in log file
// add element to history and update on server stop
HistoryGraph.Add ( QDateTime::currentDateTime(),
CHistoryGraph::HIT_SERVER_STOP );
HistoryGraph.Update();
}
void CServerLogging::operator<< ( const QString& sNewStr )
{
if ( bDoLogging )
{
// append new line in logging file
QTextStream out ( &File );
out << sNewStr << endl;
File.flush();
}
}
void CServerLogging::ParseLogFile ( const QString& strFileName )
{
// open file for reading
QFile LogFile ( strFileName );
LogFile.open ( QIODevice::ReadOnly | QIODevice::Text );
QTextStream inStream ( &LogFile );
// read all content from file
while ( !inStream.atEnd() )
{
// get a new line from log file
QString strCurLine = inStream.readLine();
// parse log file line
QStringList strlistCurLine = strCurLine.split( "," );
// check number of separated strings condition
if ( strlistCurLine.size() == 4 )
{
// first entry
QDate curDate =
QDate::fromString ( strlistCurLine.at ( 0 ).trimmed(),
"d.M.yyyy" );
// second entry
QTime curTime =
QTime::fromString ( strlistCurLine.at ( 1 ).trimmed(),
"hh:mm:ss" );
if ( curDate.isValid() && curTime.isValid() )
{
QDateTime curDateTime ( curDate, curTime );
// check if server stop or new client connection
QString strAddress = strlistCurLine.at ( 2 ).trimmed();
if ( strAddress.isEmpty() )
{
// server stop
HistoryGraph.Add ( curDateTime,
CHistoryGraph::HIT_SERVER_STOP );
}
else
{
QHostAddress curAddress;
// third entry is IP address
if ( curAddress.setAddress ( strlistCurLine.at ( 2 ).trimmed() ) )
{
// new client connection
HistoryGraph.Add ( curDateTime, curAddress );
}
}
}
}
}
HistoryGraph.Update();
}
QString CServerLogging::CurTimeDatetoLogString()
{
// time and date to string conversion
const QDateTime curDateTime = QDateTime::currentDateTime();
// format date and time output according to "3.9.2006, 11:38:08"
return QString().setNum ( curDateTime.date().day() ) + "." +
QString().setNum ( curDateTime.date().month() ) + "." +
QString().setNum ( curDateTime.date().year() ) + ", " +
curDateTime.time().toString();
}

View file

@ -1,352 +1,352 @@
/******************************************************************************\
* Copyright (c) 2004-2009
*
* Author(s):
* Volker Fischer
*
******************************************************************************
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\******************************************************************************/
#include "settings.h"
/* Implementation *************************************************************/
void CSettings::ReadIniFile ( const QString& sFileName )
{
int iValue;
bool bValue;
QDomDocument IniXMLDocument;
// load data from init-file
// prepare file name for loading initialization data from XML file
QString sCurFileName = sFileName;
if ( sCurFileName.isEmpty() )
{
// if no file name is available, use default file name
sCurFileName = LLCON_INIT_FILE_NAME;
}
// read data from file if possible
QFile file ( sCurFileName );
if ( file.open ( QIODevice::ReadOnly ) )
{
QTextStream in ( &file );
IniXMLDocument.setContent ( in.readAll(), false );
file.close();
}
// actual settings data ---------------------------------------------------
// IP addresses
for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ )
{
QString sDefaultIP = "";
// use default only for first entry
if ( iIPAddrIdx == 0 )
{
sDefaultIP = DEFAULT_SERVER_ADDRESS;
}
pClient->vstrIPAddress[iIPAddrIdx] =
GetIniSetting ( IniXMLDocument, "client",
QString ( "ipaddress%1" ).arg ( iIPAddrIdx ), sDefaultIP );
}
// name
pClient->strName = GetIniSetting ( IniXMLDocument, "client", "name" );
// audio fader
if ( GetNumericIniSet ( IniXMLDocument, "client", "audfad",
AUD_FADER_IN_MIN, AUD_FADER_IN_MAX, iValue ) )
{
pClient->SetAudioInFader ( iValue );
}
// reverberation level
if ( GetNumericIniSet ( IniXMLDocument, "client", "revlev",
0, AUD_REVERB_MAX, iValue ) )
{
pClient->SetReverbLevel ( iValue );
}
// reverberation channel assignment
if ( GetFlagIniSet ( IniXMLDocument, "client", "reverblchan", bValue ) )
{
pClient->SetReverbOnLeftChan ( bValue );
}
// sound card selection
// special case with this setting: the sound card initialization depends on this setting
// call, therefore, if no setting file parameter could be retrieved, the sound card is
// initialized with a default setting defined here
if ( GetNumericIniSet ( IniXMLDocument, "client", "auddevidx",
1, MAX_NUMBER_SOUND_CARDS, iValue ) )
{
pClient->SetSndCrdDev ( iValue );
}
else
{
// use "INVALID_SNC_CARD_DEVICE" to tell the sound card driver that no
// device selection was done previously
pClient->SetSndCrdDev ( INVALID_SNC_CARD_DEVICE );
}
// sound card preferred buffer size index
if ( GetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx",
FRAME_SIZE_FACTOR_PREFERRED, FRAME_SIZE_FACTOR_SAFE, iValue ) )
{
// additional check required since only a subset of factors are
// defined
if ( ( iValue == FRAME_SIZE_FACTOR_PREFERRED ) ||
( iValue == FRAME_SIZE_FACTOR_DEFAULT ) ||
( iValue == FRAME_SIZE_FACTOR_SAFE ) )
{
pClient->SetSndCrdPrefFrameSizeFactor ( iValue );
}
}
// automatic network jitter buffer size setting
if ( GetFlagIniSet ( IniXMLDocument, "client", "autojitbuf", bValue ) )
{
pClient->SetDoAutoSockBufSize ( bValue );
}
// network jitter buffer size
if ( GetNumericIniSet ( IniXMLDocument, "client", "jitbuf",
MIN_NET_BUF_SIZE_NUM_BL, MAX_NET_BUF_SIZE_NUM_BL, iValue ) )
{
pClient->SetSockBufNumFrames ( iValue );
}
// flag whether the chat window shall be opened on a new chat message
if ( GetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage", bValue ) )
{
pClient->SetOpenChatOnNewMessage ( bValue );
}
// GUI design
if ( GetNumericIniSet ( IniXMLDocument, "client", "guidesign",
0, 1 /* GD_ORIGINAL */, iValue ) )
{
pClient->SetGUIDesign ( static_cast<EGUIDesign> ( iValue ) );
}
// flag whether using high quality audio or not
if ( GetFlagIniSet ( IniXMLDocument, "client", "highqualityaudio", bValue ) )
{
pClient->SetCELTHighQuality ( bValue );
}
}
void CSettings::WriteIniFile ( const QString& sFileName )
{
// create XML document for storing initialization parameters
QDomDocument IniXMLDocument;
// actual settings data ---------------------------------------------------
// IP addresses
for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ )
{
PutIniSetting ( IniXMLDocument, "client",
QString ( "ipaddress%1" ).arg ( iIPAddrIdx ),
pClient->vstrIPAddress[iIPAddrIdx] );
}
// name
PutIniSetting ( IniXMLDocument, "client", "name",
pClient->strName );
// audio fader
SetNumericIniSet ( IniXMLDocument, "client", "audfad",
pClient->GetAudioInFader() );
// reverberation level
SetNumericIniSet ( IniXMLDocument, "client", "revlev",
pClient->GetReverbLevel() );
// reverberation channel assignment
SetFlagIniSet ( IniXMLDocument, "client", "reverblchan",
pClient->IsReverbOnLeftChan() );
// sound card selection
SetNumericIniSet ( IniXMLDocument, "client", "auddevidx",
pClient->GetSndCrdDev() );
// sound card preferred buffer size index
SetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx",
pClient->GetSndCrdPrefFrameSizeFactor() );
// automatic network jitter buffer size setting
SetFlagIniSet ( IniXMLDocument, "client", "autojitbuf",
pClient->GetDoAutoSockBufSize() );
// network jitter buffer size
SetNumericIniSet ( IniXMLDocument, "client", "jitbuf",
pClient->GetSockBufNumFrames() );
// flag whether the chat window shall be opened on a new chat message
SetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage",
pClient->GetOpenChatOnNewMessage() );
// GUI design
SetNumericIniSet ( IniXMLDocument, "client", "guidesign",
static_cast<int> ( pClient->GetGUIDesign() ) );
// flag whether using high quality audio or not
SetFlagIniSet ( IniXMLDocument, "client", "highqualityaudio",
pClient->GetCELTHighQuality() );
// prepare file name for storing initialization data in XML file
QString sCurFileName = sFileName;
if ( sCurFileName.isEmpty() )
{
// if no file name is available, use default file name
sCurFileName = LLCON_INIT_FILE_NAME;
}
// store XML data in file
QFile file ( sCurFileName );
if ( file.open ( QIODevice::WriteOnly ) )
{
QTextStream out ( &file );
out << IniXMLDocument.toString();
}
}
void CSettings::SetNumericIniSet ( QDomDocument& xmlFile, const QString& strSection,
const QString& strKey, const int iValue )
{
// convert input parameter which is an integer to string and store
PutIniSetting ( xmlFile, strSection, strKey, QString("%1").arg(iValue) );
}
bool CSettings::GetNumericIniSet ( const QDomDocument& xmlFile, const QString& strSection,
const QString& strKey, const int iRangeStart,
const int iRangeStop, int& iValue )
{
// init return value
bool bReturn = false;
const QString strGetIni = GetIniSetting ( xmlFile, strSection, strKey );
// check if it is a valid parameter
if ( !strGetIni.isEmpty() )
{
// convert string from init file to integer
iValue = strGetIni.toInt();
// check range
if ( ( iValue >= iRangeStart ) && ( iValue <= iRangeStop ) )
{
bReturn = true;
}
}
return bReturn;
}
void CSettings::SetFlagIniSet ( QDomDocument& xmlFile, const QString& strSection,
const QString& strKey, const bool bValue )
{
// we encode true -> "1" and false -> "0"
if ( bValue == true )
{
PutIniSetting ( xmlFile, strSection, strKey, "1" );
}
else
{
PutIniSetting ( xmlFile, strSection, strKey, "0" );
}
}
bool CSettings::GetFlagIniSet ( const QDomDocument& xmlFile, const QString& strSection,
const QString& strKey, bool& bValue )
{
// init return value
bool bReturn = false;
const QString strGetIni = GetIniSetting ( xmlFile, strSection, strKey );
if ( !strGetIni.isEmpty() )
{
if ( strGetIni.toInt() )
{
bValue = true;
}
else
{
bValue = false;
}
bReturn = true;
}
return bReturn;
}
// Init-file routines using XML ***********************************************
QString CSettings::GetIniSetting ( const QDomDocument& xmlFile, const QString& sSection,
const QString& sKey, const QString& sDefaultVal )
{
// init return parameter with default value
QString sResult ( sDefaultVal );
// get section
QDomElement xmlSection = xmlFile.firstChildElement ( sSection );
if ( !xmlSection.isNull() )
{
// get key
QDomElement xmlKey = xmlSection.firstChildElement ( sKey );
if ( !xmlKey.isNull() )
{
// get value
sResult = xmlKey.text();
}
}
return sResult;
}
void CSettings::PutIniSetting ( QDomDocument& xmlFile, const QString& sSection,
const QString& sKey, const QString& sValue )
{
// check if section is already there, if not then create it
QDomElement xmlSection = xmlFile.firstChildElement ( sSection );
if ( xmlSection.isNull() )
{
// create new root element and add to document
xmlSection = xmlFile.createElement ( sSection );
xmlFile.appendChild ( xmlSection );
}
// check if key is already there, if not then create it
QDomElement xmlKey = xmlSection.firstChildElement ( sKey );
if ( xmlKey.isNull() )
{
xmlKey = xmlFile.createElement ( sKey );
xmlSection.appendChild ( xmlKey );
}
// add actual data to the key
QDomText currentValue = xmlFile.createTextNode ( sValue );
xmlKey.appendChild ( currentValue );
}
/******************************************************************************\
* Copyright (c) 2004-2009
*
* Author(s):
* Volker Fischer
*
******************************************************************************
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\******************************************************************************/
#include "settings.h"
/* Implementation *************************************************************/
void CSettings::ReadIniFile ( const QString& sFileName )
{
int iValue;
bool bValue;
QDomDocument IniXMLDocument;
// load data from init-file
// prepare file name for loading initialization data from XML file
QString sCurFileName = sFileName;
if ( sCurFileName.isEmpty() )
{
// if no file name is available, use default file name
sCurFileName = LLCON_INIT_FILE_NAME;
}
// read data from file if possible
QFile file ( sCurFileName );
if ( file.open ( QIODevice::ReadOnly ) )
{
QTextStream in ( &file );
IniXMLDocument.setContent ( in.readAll(), false );
file.close();
}
// actual settings data ---------------------------------------------------
// IP addresses
for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ )
{
QString sDefaultIP = "";
// use default only for first entry
if ( iIPAddrIdx == 0 )
{
sDefaultIP = DEFAULT_SERVER_ADDRESS;
}
pClient->vstrIPAddress[iIPAddrIdx] =
GetIniSetting ( IniXMLDocument, "client",
QString ( "ipaddress%1" ).arg ( iIPAddrIdx ), sDefaultIP );
}
// name
pClient->strName = GetIniSetting ( IniXMLDocument, "client", "name" );
// audio fader
if ( GetNumericIniSet ( IniXMLDocument, "client", "audfad",
AUD_FADER_IN_MIN, AUD_FADER_IN_MAX, iValue ) )
{
pClient->SetAudioInFader ( iValue );
}
// reverberation level
if ( GetNumericIniSet ( IniXMLDocument, "client", "revlev",
0, AUD_REVERB_MAX, iValue ) )
{
pClient->SetReverbLevel ( iValue );
}
// reverberation channel assignment
if ( GetFlagIniSet ( IniXMLDocument, "client", "reverblchan", bValue ) )
{
pClient->SetReverbOnLeftChan ( bValue );
}
// sound card selection
// special case with this setting: the sound card initialization depends on this setting
// call, therefore, if no setting file parameter could be retrieved, the sound card is
// initialized with a default setting defined here
if ( GetNumericIniSet ( IniXMLDocument, "client", "auddevidx",
1, MAX_NUMBER_SOUND_CARDS, iValue ) )
{
pClient->SetSndCrdDev ( iValue );
}
else
{
// use "INVALID_SNC_CARD_DEVICE" to tell the sound card driver that no
// device selection was done previously
pClient->SetSndCrdDev ( INVALID_SNC_CARD_DEVICE );
}
// sound card preferred buffer size index
if ( GetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx",
FRAME_SIZE_FACTOR_PREFERRED, FRAME_SIZE_FACTOR_SAFE, iValue ) )
{
// additional check required since only a subset of factors are
// defined
if ( ( iValue == FRAME_SIZE_FACTOR_PREFERRED ) ||
( iValue == FRAME_SIZE_FACTOR_DEFAULT ) ||
( iValue == FRAME_SIZE_FACTOR_SAFE ) )
{
pClient->SetSndCrdPrefFrameSizeFactor ( iValue );
}
}
// automatic network jitter buffer size setting
if ( GetFlagIniSet ( IniXMLDocument, "client", "autojitbuf", bValue ) )
{
pClient->SetDoAutoSockBufSize ( bValue );
}
// network jitter buffer size
if ( GetNumericIniSet ( IniXMLDocument, "client", "jitbuf",
MIN_NET_BUF_SIZE_NUM_BL, MAX_NET_BUF_SIZE_NUM_BL, iValue ) )
{
pClient->SetSockBufNumFrames ( iValue );
}
// flag whether the chat window shall be opened on a new chat message
if ( GetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage", bValue ) )
{
pClient->SetOpenChatOnNewMessage ( bValue );
}
// GUI design
if ( GetNumericIniSet ( IniXMLDocument, "client", "guidesign",
0, 1 /* GD_ORIGINAL */, iValue ) )
{
pClient->SetGUIDesign ( static_cast<EGUIDesign> ( iValue ) );
}
// flag whether using high quality audio or not
if ( GetFlagIniSet ( IniXMLDocument, "client", "highqualityaudio", bValue ) )
{
pClient->SetCELTHighQuality ( bValue );
}
}
void CSettings::WriteIniFile ( const QString& sFileName )
{
// create XML document for storing initialization parameters
QDomDocument IniXMLDocument;
// actual settings data ---------------------------------------------------
// IP addresses
for ( int iIPAddrIdx = 0; iIPAddrIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIPAddrIdx++ )
{
PutIniSetting ( IniXMLDocument, "client",
QString ( "ipaddress%1" ).arg ( iIPAddrIdx ),
pClient->vstrIPAddress[iIPAddrIdx] );
}
// name
PutIniSetting ( IniXMLDocument, "client", "name",
pClient->strName );
// audio fader
SetNumericIniSet ( IniXMLDocument, "client", "audfad",
pClient->GetAudioInFader() );
// reverberation level
SetNumericIniSet ( IniXMLDocument, "client", "revlev",
pClient->GetReverbLevel() );
// reverberation channel assignment
SetFlagIniSet ( IniXMLDocument, "client", "reverblchan",
pClient->IsReverbOnLeftChan() );
// sound card selection
SetNumericIniSet ( IniXMLDocument, "client", "auddevidx",
pClient->GetSndCrdDev() );
// sound card preferred buffer size index
SetNumericIniSet ( IniXMLDocument, "client", "prefsndcrdbufidx",
pClient->GetSndCrdPrefFrameSizeFactor() );
// automatic network jitter buffer size setting
SetFlagIniSet ( IniXMLDocument, "client", "autojitbuf",
pClient->GetDoAutoSockBufSize() );
// network jitter buffer size
SetNumericIniSet ( IniXMLDocument, "client", "jitbuf",
pClient->GetSockBufNumFrames() );
// flag whether the chat window shall be opened on a new chat message
SetFlagIniSet ( IniXMLDocument, "client", "openchatonnewmessage",
pClient->GetOpenChatOnNewMessage() );
// GUI design
SetNumericIniSet ( IniXMLDocument, "client", "guidesign",
static_cast<int> ( pClient->GetGUIDesign() ) );
// flag whether using high quality audio or not
SetFlagIniSet ( IniXMLDocument, "client", "highqualityaudio",
pClient->GetCELTHighQuality() );
// prepare file name for storing initialization data in XML file
QString sCurFileName = sFileName;
if ( sCurFileName.isEmpty() )
{
// if no file name is available, use default file name
sCurFileName = LLCON_INIT_FILE_NAME;
}
// store XML data in file
QFile file ( sCurFileName );
if ( file.open ( QIODevice::WriteOnly ) )
{
QTextStream out ( &file );
out << IniXMLDocument.toString();
}
}
void CSettings::SetNumericIniSet ( QDomDocument& xmlFile, const QString& strSection,
const QString& strKey, const int iValue )
{
// convert input parameter which is an integer to string and store
PutIniSetting ( xmlFile, strSection, strKey, QString("%1").arg(iValue) );
}
bool CSettings::GetNumericIniSet ( const QDomDocument& xmlFile, const QString& strSection,
const QString& strKey, const int iRangeStart,
const int iRangeStop, int& iValue )
{
// init return value
bool bReturn = false;
const QString strGetIni = GetIniSetting ( xmlFile, strSection, strKey );
// check if it is a valid parameter
if ( !strGetIni.isEmpty() )
{
// convert string from init file to integer
iValue = strGetIni.toInt();
// check range
if ( ( iValue >= iRangeStart ) && ( iValue <= iRangeStop ) )
{
bReturn = true;
}
}
return bReturn;
}
void CSettings::SetFlagIniSet ( QDomDocument& xmlFile, const QString& strSection,
const QString& strKey, const bool bValue )
{
// we encode true -> "1" and false -> "0"
if ( bValue == true )
{
PutIniSetting ( xmlFile, strSection, strKey, "1" );
}
else
{
PutIniSetting ( xmlFile, strSection, strKey, "0" );
}
}
bool CSettings::GetFlagIniSet ( const QDomDocument& xmlFile, const QString& strSection,
const QString& strKey, bool& bValue )
{
// init return value
bool bReturn = false;
const QString strGetIni = GetIniSetting ( xmlFile, strSection, strKey );
if ( !strGetIni.isEmpty() )
{
if ( strGetIni.toInt() )
{
bValue = true;
}
else
{
bValue = false;
}
bReturn = true;
}
return bReturn;
}
// Init-file routines using XML ***********************************************
QString CSettings::GetIniSetting ( const QDomDocument& xmlFile, const QString& sSection,
const QString& sKey, const QString& sDefaultVal )
{
// init return parameter with default value
QString sResult ( sDefaultVal );
// get section
QDomElement xmlSection = xmlFile.firstChildElement ( sSection );
if ( !xmlSection.isNull() )
{
// get key
QDomElement xmlKey = xmlSection.firstChildElement ( sKey );
if ( !xmlKey.isNull() )
{
// get value
sResult = xmlKey.text();
}
}
return sResult;
}
void CSettings::PutIniSetting ( QDomDocument& xmlFile, const QString& sSection,
const QString& sKey, const QString& sValue )
{
// check if section is already there, if not then create it
QDomElement xmlSection = xmlFile.firstChildElement ( sSection );
if ( xmlSection.isNull() )
{
// create new root element and add to document
xmlSection = xmlFile.createElement ( sSection );
xmlFile.appendChild ( xmlSection );
}
// check if key is already there, if not then create it
QDomElement xmlKey = xmlSection.firstChildElement ( sKey );
if ( xmlKey.isNull() )
{
xmlKey = xmlFile.createElement ( sKey );
xmlSection.appendChild ( xmlKey );
}
// add actual data to the key
QDomText currentValue = xmlFile.createTextNode ( sValue );
xmlKey.appendChild ( currentValue );
}

1294
src/util.h

File diff suppressed because it is too large Load diff