first working version of the connect dialog

This commit is contained in:
Volker Fischer 2011-04-23 19:03:51 +00:00
parent b6ba0cc93b
commit 7392762f6c
4 changed files with 261 additions and 312 deletions

View File

@ -28,7 +28,9 @@
/* Implementation *************************************************************/ /* Implementation *************************************************************/
CConnectDlg::CConnectDlg ( QWidget* parent, Qt::WindowFlags f ) CConnectDlg::CConnectDlg ( QWidget* parent, Qt::WindowFlags f )
: QDialog ( parent, f ), : QDialog ( parent, f ),
bServerListReceived ( false ) strSelectedAddress ( "" ),
bServerListReceived ( false ),
bCancelPressed ( false )
{ {
setupUi ( this ); setupUi ( this );
@ -38,8 +40,7 @@ CConnectDlg::CConnectDlg ( QWidget* parent, Qt::WindowFlags f )
QString strServAddrH = tr ( "<b>Server Address:</b> The IP address or URL " QString strServAddrH = tr ( "<b>Server Address:</b> The IP address or URL "
"of the server running the llcon server software must be set here. " "of the server running the llcon server software must be set here. "
"A list of the most recent used server URLs is available for " "A list of the most recent used server URLs is available for "
"selection. If an invalid address was chosen, an error message is " "selection." );
"shown in the status bar." );
TextLabelServerAddr->setWhatsThis ( strServAddrH ); TextLabelServerAddr->setWhatsThis ( strServAddrH );
LineEditServerAddr->setWhatsThis ( strServAddrH ); LineEditServerAddr->setWhatsThis ( strServAddrH );
@ -51,7 +52,7 @@ CConnectDlg::CConnectDlg ( QWidget* parent, Qt::WindowFlags f )
// init server address combo box (max MAX_NUM_SERVER_ADDR_ITEMS entries) // init server address combo box (max MAX_NUM_SERVER_ADDR_ITEMS entries)
LineEditServerAddr->setMaxCount ( MAX_NUM_SERVER_ADDR_ITEMS ); LineEditServerAddr->setMaxCount ( MAX_NUM_SERVER_ADDR_ITEMS );
LineEditServerAddr->setInsertPolicy ( QComboBox::InsertAtTop ); LineEditServerAddr->setInsertPolicy ( QComboBox::NoInsert );
// set up list view for connected clients // set up list view for connected clients
ListViewServers->setColumnWidth ( 0, 170 ); ListViewServers->setColumnWidth ( 0, 170 );
@ -67,13 +68,8 @@ CConnectDlg::CConnectDlg ( QWidget* parent, Qt::WindowFlags f )
QObject::connect ( CancelButton, SIGNAL ( clicked() ), QObject::connect ( CancelButton, SIGNAL ( clicked() ),
this, SLOT ( OnCancelButtonClicked() ) ); this, SLOT ( OnCancelButtonClicked() ) );
// line edits QObject::connect ( ConnectButton, SIGNAL ( clicked() ),
QObject::connect ( LineEditServerAddr, SIGNAL ( editTextChanged ( const QString ) ), this, SLOT ( close() ) );
this, SLOT ( OnLineEditServerAddrTextChanged ( const QString ) ) );
QObject::connect ( LineEditServerAddr, SIGNAL ( activated ( int ) ),
this, SLOT ( OnLineEditServerAddrActivated ( int ) ) );
// timers // timers
QObject::connect ( &TimerPing, SIGNAL ( timeout() ), QObject::connect ( &TimerPing, SIGNAL ( timeout() ),
@ -83,14 +79,14 @@ CConnectDlg::CConnectDlg ( QWidget* parent, Qt::WindowFlags f )
this, SLOT ( OnTimerReRequestServList() ) ); this, SLOT ( OnTimerReRequestServList() ) );
} }
void CConnectDlg::LoadStoredServers ( const CVector<QString>& vstrIPAddress ) void CConnectDlg::LoadStoredServers ( const CVector<QString>& vstrIPAddresses )
{ {
// load stored IP addresses in combo box // load stored IP addresses in combo box
for ( int iLEIdx = 0; iLEIdx < MAX_NUM_SERVER_ADDR_ITEMS; iLEIdx++ ) for ( int iLEIdx = 0; iLEIdx < MAX_NUM_SERVER_ADDR_ITEMS; iLEIdx++ )
{ {
if ( !vstrIPAddress[iLEIdx].isEmpty() ) if ( !vstrIPAddresses[iLEIdx].isEmpty() )
{ {
LineEditServerAddr->addItem ( vstrIPAddress[iLEIdx] ); LineEditServerAddr->addItem ( vstrIPAddresses[iLEIdx] );
} }
} }
} }
@ -102,6 +98,9 @@ void CConnectDlg::showEvent ( QShowEvent* )
bServerListReceived = false; bServerListReceived = false;
bCancelPressed = false; bCancelPressed = false;
// clear current address
strSelectedAddress = "";
// TEST // TEST
QString strNAddr = "llcon.dyndns.org:22122"; QString strNAddr = "llcon.dyndns.org:22122";
@ -124,20 +123,25 @@ QString strNAddr = "llcon.dyndns.org:22122";
void CConnectDlg::hideEvent ( QHideEvent* ) void CConnectDlg::hideEvent ( QHideEvent* )
{ {
// get the IP address to be used according to the following definitions:
// - if the list has focus and a line is selected, use this line
// - if the list has no focus, use the current combo box text
QList<QTreeWidgetItem*> CurSelListItemList =
ListViewServers->selectedItems();
if ( CurSelListItemList.count() > 0 )
{
strSelectedAddress =
CurSelListItemList[0]->data ( 0, Qt::UserRole ).toString();
}
else
{
strSelectedAddress = LineEditServerAddr->currentText();
}
// if window is closed, stop timers // if window is closed, stop timers
TimerPing.stop(); TimerPing.stop();
TimerReRequestServList.stop(); TimerReRequestServList.stop();
// TODO
/*
// store IP addresses
for ( int iLEIdx = 0; iLEIdx < LineEditServerAddr->count(); iLEIdx++ )
{
pClient->vstrIPAddress[iLEIdx] =
LineEditServerAddr->itemText ( iLEIdx );
}
*/
} }
void CConnectDlg::OnTimerReRequestServList() void CConnectDlg::OnTimerReRequestServList()
@ -228,17 +232,6 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr,
TimerPing.start ( PING_UPDATE_TIME_SERVER_LIST_MS ); TimerPing.start ( PING_UPDATE_TIME_SERVER_LIST_MS );
} }
void CConnectDlg::OnLineEditServerAddrTextChanged ( const QString )
{
// if the maximum number of items in the combo box is reached,
// delete the last item so that the new item can be added (first
// in - first out)
if ( LineEditServerAddr->count() == MAX_NUM_SERVER_ADDR_ITEMS )
{
LineEditServerAddr->removeItem ( MAX_NUM_SERVER_ADDR_ITEMS - 1 );
}
}
void CConnectDlg::OnCancelButtonClicked() void CConnectDlg::OnCancelButtonClicked()
{ {
// set cancel flag // set cancel flag
@ -248,15 +241,6 @@ void CConnectDlg::OnCancelButtonClicked()
close(); close();
} }
void CConnectDlg::OnLineEditServerAddrActivated ( int index )
{
// move activated list item to the top
const QString strCurIPAddress = LineEditServerAddr->itemText ( index );
LineEditServerAddr->removeItem ( index );
LineEditServerAddr->insertItem ( 0, strCurIPAddress );
LineEditServerAddr->setCurrentIndex ( 0 );
}
void CConnectDlg::OnTimerPing() void CConnectDlg::OnTimerPing()
{ {
// send ping messages to the servers in the list // send ping messages to the servers in the list

View File

@ -59,26 +59,29 @@ public:
void SetServerList ( const CHostAddress& InetAddr, void SetServerList ( const CHostAddress& InetAddr,
const CVector<CServerInfo>& vecServerInfo ); const CVector<CServerInfo>& vecServerInfo );
void LoadStoredServers ( const CVector<QString>& vstrIPAddress ); void LoadStoredServers ( const CVector<QString>& vstrNewIPAddresses );
void SetPingTimeResult ( CHostAddress& InetAddr, void SetPingTimeResult ( CHostAddress& InetAddr,
const int iPingTime, const int iPingTime,
const int iPingTimeLEDColor ); const int iPingTimeLEDColor );
bool GetCancelPressed() const { return bCancelPressed; }
QString GetSelectedAddress() const { return strSelectedAddress; }
protected: protected:
virtual void showEvent ( QShowEvent* ); virtual void showEvent ( QShowEvent* );
virtual void hideEvent ( QHideEvent* ); virtual void hideEvent ( QHideEvent* );
QTimer TimerPing; QTimer TimerPing;
QTimer TimerReRequestServList; QTimer TimerReRequestServList;
CHostAddress CentralServerAddress; CHostAddress CentralServerAddress;
bool bServerListReceived; CVector<QString> vstrIPAddresses;
bool bCancelPressed; QString strSelectedAddress;
bool bServerListReceived;
bool bCancelPressed;
public slots: public slots:
void OnCancelButtonClicked(); void OnCancelButtonClicked();
void OnLineEditServerAddrTextChanged ( const QString );
void OnLineEditServerAddrActivated ( int index );
void OnTimerPing(); void OnTimerPing();
void OnTimerReRequestServList(); void OnTimerReRequestServList();

View File

@ -105,20 +105,6 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP,
"Disconnect, i.e., it implements a toggle functionality for connecting " "Disconnect, i.e., it implements a toggle functionality for connecting "
"and disconnecting the llcon software." ) ); "and disconnecting the llcon software." ) );
// server address
QString strServAddrH = tr ( "<b>Server Address:</b> The IP address or URL "
"of the server running the llcon server software must be set here. "
"A list of the most recent used server URLs is available for "
"selection. If an invalid address was chosen, an error message is "
"shown in the status bar." );
TextLabelServerAddr->setWhatsThis ( strServAddrH );
LineEditServerAddr->setWhatsThis ( strServAddrH );
LineEditServerAddr->setAccessibleName ( tr ( "Server address edit box" ) );
LineEditServerAddr->setAccessibleDescription ( tr ( "Holds the current server "
"URL. It also stores old URLs in the combo box list." ) );
// fader tag // fader tag
QString strFaderTag = tr ( "<b>Fader Tag:</b> The fader tag of the local " QString strFaderTag = tr ( "<b>Fader Tag:</b> The fader tag of the local "
"client is set in the fader tag edit box. This tag will appear " "client is set in the fader tag edit box. This tag will appear "
@ -253,22 +239,6 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP,
// init fader tag line edit // init fader tag line edit
LineEditFaderTag->setText ( pClient->strName ); LineEditFaderTag->setText ( pClient->strName );
// init server address combo box (max MAX_NUM_SERVER_ADDR_ITEMS entries)
LineEditServerAddr->setMaxCount ( MAX_NUM_SERVER_ADDR_ITEMS );
LineEditServerAddr->setInsertPolicy ( QComboBox::InsertAtTop );
// load data from ini file
for ( int iLEIdx = 0; iLEIdx < MAX_NUM_SERVER_ADDR_ITEMS; iLEIdx++ )
{
if ( !pClient->vstrIPAddress[iLEIdx].isEmpty() )
{
LineEditServerAddr->addItem ( pClient->vstrIPAddress[iLEIdx] );
}
}
// we want the cursor to be at IP address line edit at startup
LineEditServerAddr->setFocus();
// init status label // init status label
OnTimerStatus(); OnTimerStatus();
@ -395,12 +365,6 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP,
QObject::connect ( LineEditFaderTag, SIGNAL ( textChanged ( const QString& ) ), QObject::connect ( LineEditFaderTag, SIGNAL ( textChanged ( const QString& ) ),
this, SLOT ( OnFaderTagTextChanged ( const QString& ) ) ); this, SLOT ( OnFaderTagTextChanged ( const QString& ) ) );
QObject::connect ( LineEditServerAddr, SIGNAL ( editTextChanged ( const QString ) ),
this, SLOT ( OnLineEditServerAddrTextChanged ( const QString ) ) );
QObject::connect ( LineEditServerAddr, SIGNAL ( activated ( int ) ),
this, SLOT ( OnLineEditServerAddrActivated ( int ) ) );
// other // other
QObject::connect ( pClient, QObject::connect ( pClient,
SIGNAL ( ConClientListMesReceived ( CVector<CChannelShortInfo> ) ), SIGNAL ( ConClientListMesReceived ( CVector<CChannelShortInfo> ) ),
@ -453,13 +417,6 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP,
// Timers ------------------------------------------------------------------ // Timers ------------------------------------------------------------------
// start timer for status bar // start timer for status bar
TimerStatus.start ( LED_BAR_UPDATE_TIME_MS ); TimerStatus.start ( LED_BAR_UPDATE_TIME_MS );
// TEST
ConnectDlg.LoadStoredServers ( pClient->vstrIPAddress );
ConnectDlg.setModal ( true );
ConnectDlg.show();
} }
void CLlconClientDlg::closeEvent ( QCloseEvent* Event ) void CLlconClientDlg::closeEvent ( QCloseEvent* Event )
@ -475,13 +432,6 @@ void CLlconClientDlg::closeEvent ( QCloseEvent* Event )
pClient->Stop(); pClient->Stop();
} }
// store IP addresses
for ( int iLEIdx = 0; iLEIdx < LineEditServerAddr->count(); iLEIdx++ )
{
pClient->vstrIPAddress[iLEIdx] =
LineEditServerAddr->itemText ( iLEIdx );
}
// store fader tag // store fader tag
pClient->strName = LineEditFaderTag->text(); pClient->strName = LineEditFaderTag->text();
@ -551,26 +501,6 @@ void CLlconClientDlg::OnSliderAudInFader ( int value )
UpdateAudioFaderSlider(); UpdateAudioFaderSlider();
} }
void CLlconClientDlg::OnLineEditServerAddrTextChanged ( const QString )
{
// if the maximum number of items in the combo box is reached,
// delete the last item so that the new item can be added (first
// in - first out)
if ( LineEditServerAddr->count() == MAX_NUM_SERVER_ADDR_ITEMS )
{
LineEditServerAddr->removeItem ( MAX_NUM_SERVER_ADDR_ITEMS - 1 );
}
}
void CLlconClientDlg::OnLineEditServerAddrActivated ( int index )
{
// move activated list item to the top
const QString strCurIPAddress = LineEditServerAddr->itemText ( index );
LineEditServerAddr->removeItem ( index );
LineEditServerAddr->insertItem ( 0, strCurIPAddress );
LineEditServerAddr->setCurrentIndex ( 0 );
}
void CLlconClientDlg::OnConnectDisconBut() void CLlconClientDlg::OnConnectDisconBut()
{ {
// the connect/disconnect button implements a toggle functionality // the connect/disconnect button implements a toggle functionality
@ -800,39 +730,73 @@ void CLlconClientDlg::ConnectDisconnect ( const bool bDoStart )
// start/stop client, set button text // start/stop client, set button text
if ( bDoStart ) if ( bDoStart )
{ {
// set address and check if address is valid // init the connect dialog and execute it (modal dialog)
if ( pClient->SetServerAddr ( LineEditServerAddr->currentText() ) ) ConnectDlg.LoadStoredServers ( pClient->vstrIPAddress );
ConnectDlg.exec();
// check if cancel was pressed
if ( !ConnectDlg.GetCancelPressed() )
{ {
bool bStartOk = true; const QString strSelectedAddress = ConnectDlg.GetSelectedAddress();
// try to start client, if error occurred, do not go in if ( !strSelectedAddress.isEmpty() )
// running state but show error message
try
{ {
pClient->Start(); CVector<QString> vstrTempList ( 0 );
// store the new address in the current server storage list at
// the top, make sure we do not have more than allowed stored
// servers
vstrTempList.Add ( strSelectedAddress );
for ( int iIdx = 0; ( iIdx < pClient->vstrIPAddress.Size() ) &&
( iIdx < ( MAX_NUM_SERVER_ADDR_ITEMS - 1 ) ); iIdx++ )
{
// only add old server address if it is not the same as the
// selected one
if ( pClient->vstrIPAddress[iIdx].compare ( strSelectedAddress ) )
{
vstrTempList.Add ( pClient->vstrIPAddress[iIdx] );
}
}
// copy new generated list to client
pClient->vstrIPAddress = vstrTempList;
} }
catch ( CGenErr generr ) // set address and check if address is valid
if ( pClient->SetServerAddr ( strSelectedAddress ) )
{ {
QMessageBox::critical ( bool bStartOk = true;
this, APP_NAME, generr.GetErrorText(), "Close", 0 );
bStartOk = false; // try to start client, if error occurred, do not go in
// running state but show error message
try
{
pClient->Start();
}
catch ( CGenErr generr )
{
QMessageBox::critical (
this, APP_NAME, generr.GetErrorText(), "Close", 0 );
bStartOk = false;
}
if ( bStartOk )
{
PushButtonConnect->setText ( CON_BUT_DISCONNECTTEXT );
// start timer for level meter bar and ping time measurement
TimerSigMet.start ( LEVELMETER_UPDATE_TIME_MS );
TimerPing.start ( PING_UPDATE_TIME_MS );
}
}
else
{
// show the error as red light
LEDConnection->SetLight ( MUL_COL_LED_RED );
} }
if ( bStartOk )
{
PushButtonConnect->setText ( CON_BUT_DISCONNECTTEXT );
// start timer for level meter bar and ping time measurement
TimerSigMet.start ( LEVELMETER_UPDATE_TIME_MS );
TimerPing.start ( PING_UPDATE_TIME_MS );
}
}
else
{
// show the error as red light
LEDConnection->SetLight ( MUL_COL_LED_RED );
} }
} }
else else

View File

@ -152,8 +152,6 @@ public slots:
CVector<CServerInfo> vecServerInfo ) CVector<CServerInfo> vecServerInfo )
{ ConnectDlg.SetServerList ( InetAddr, vecServerInfo ); } { ConnectDlg.SetServerList ( InetAddr, vecServerInfo ); }
void OnLineEditServerAddrTextChanged ( const QString );
void OnLineEditServerAddrActivated ( int index );
void OnDisconnected(); void OnDisconnected();
void OnStopped(); void OnStopped();