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 *************************************************************/
CConnectDlg::CConnectDlg ( QWidget* parent, Qt::WindowFlags f )
: QDialog ( parent, f ),
bServerListReceived ( false )
strSelectedAddress ( "" ),
bServerListReceived ( false ),
bCancelPressed ( false )
{
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 "
"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." );
"selection." );
TextLabelServerAddr->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)
LineEditServerAddr->setMaxCount ( MAX_NUM_SERVER_ADDR_ITEMS );
LineEditServerAddr->setInsertPolicy ( QComboBox::InsertAtTop );
LineEditServerAddr->setInsertPolicy ( QComboBox::NoInsert );
// set up list view for connected clients
ListViewServers->setColumnWidth ( 0, 170 );
@ -67,13 +68,8 @@ CConnectDlg::CConnectDlg ( QWidget* parent, Qt::WindowFlags f )
QObject::connect ( CancelButton, SIGNAL ( clicked() ),
this, SLOT ( OnCancelButtonClicked() ) );
// line edits
QObject::connect ( LineEditServerAddr, SIGNAL ( editTextChanged ( const QString ) ),
this, SLOT ( OnLineEditServerAddrTextChanged ( const QString ) ) );
QObject::connect ( LineEditServerAddr, SIGNAL ( activated ( int ) ),
this, SLOT ( OnLineEditServerAddrActivated ( int ) ) );
QObject::connect ( ConnectButton, SIGNAL ( clicked() ),
this, SLOT ( close() ) );
// timers
QObject::connect ( &TimerPing, SIGNAL ( timeout() ),
@ -83,14 +79,14 @@ CConnectDlg::CConnectDlg ( QWidget* parent, Qt::WindowFlags f )
this, SLOT ( OnTimerReRequestServList() ) );
}
void CConnectDlg::LoadStoredServers ( const CVector<QString>& vstrIPAddress )
void CConnectDlg::LoadStoredServers ( const CVector<QString>& vstrIPAddresses )
{
// load stored IP addresses in combo box
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;
bCancelPressed = false;
// clear current address
strSelectedAddress = "";
// TEST
QString strNAddr = "llcon.dyndns.org:22122";
@ -124,20 +123,25 @@ QString strNAddr = "llcon.dyndns.org:22122";
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
TimerPing.stop();
TimerReRequestServList.stop();
// TODO
/*
// store IP addresses
for ( int iLEIdx = 0; iLEIdx < LineEditServerAddr->count(); iLEIdx++ )
{
pClient->vstrIPAddress[iLEIdx] =
LineEditServerAddr->itemText ( iLEIdx );
}
*/
}
void CConnectDlg::OnTimerReRequestServList()
@ -228,17 +232,6 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr,
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()
{
// set cancel flag
@ -248,15 +241,6 @@ void CConnectDlg::OnCancelButtonClicked()
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()
{
// send ping messages to the servers in the list

View file

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

View file

@ -105,20 +105,6 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP,
"Disconnect, i.e., it implements a toggle functionality for connecting "
"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
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 "
@ -253,22 +239,6 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP,
// init fader tag line edit
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
OnTimerStatus();
@ -395,12 +365,6 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP,
QObject::connect ( LineEditFaderTag, SIGNAL ( textChanged ( 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
QObject::connect ( pClient,
SIGNAL ( ConClientListMesReceived ( CVector<CChannelShortInfo> ) ),
@ -453,13 +417,6 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP,
// Timers ------------------------------------------------------------------
// start timer for status bar
TimerStatus.start ( LED_BAR_UPDATE_TIME_MS );
// TEST
ConnectDlg.LoadStoredServers ( pClient->vstrIPAddress );
ConnectDlg.setModal ( true );
ConnectDlg.show();
}
void CLlconClientDlg::closeEvent ( QCloseEvent* Event )
@ -475,13 +432,6 @@ void CLlconClientDlg::closeEvent ( QCloseEvent* Event )
pClient->Stop();
}
// store IP addresses
for ( int iLEIdx = 0; iLEIdx < LineEditServerAddr->count(); iLEIdx++ )
{
pClient->vstrIPAddress[iLEIdx] =
LineEditServerAddr->itemText ( iLEIdx );
}
// store fader tag
pClient->strName = LineEditFaderTag->text();
@ -551,26 +501,6 @@ void CLlconClientDlg::OnSliderAudInFader ( int value )
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()
{
// the connect/disconnect button implements a toggle functionality
@ -800,8 +730,40 @@ void CLlconClientDlg::ConnectDisconnect ( const bool bDoStart )
// start/stop client, set button text
if ( bDoStart )
{
// init the connect dialog and execute it (modal dialog)
ConnectDlg.LoadStoredServers ( pClient->vstrIPAddress );
ConnectDlg.exec();
// check if cancel was pressed
if ( !ConnectDlg.GetCancelPressed() )
{
const QString strSelectedAddress = ConnectDlg.GetSelectedAddress();
if ( !strSelectedAddress.isEmpty() )
{
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;
}
// set address and check if address is valid
if ( pClient->SetServerAddr ( LineEditServerAddr->currentText() ) )
if ( pClient->SetServerAddr ( strSelectedAddress ) )
{
bool bStartOk = true;
@ -834,6 +796,8 @@ void CLlconClientDlg::ConnectDisconnect ( const bool bDoStart )
// show the error as red light
LEDConnection->SetLight ( MUL_COL_LED_RED );
}
}
}
else
{

View file

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