Reimplemented handling of already occupied ports

remotes/origin/HEAD
markuspg 8 years ago
parent 60d0efa31f
commit 54ec27518f

@ -512,7 +512,7 @@ void lc::MainWindow::on_PBStartLocalzLeaf_clicked() {
}
void lc::MainWindow::on_PBStartSession_clicked() {
SessionStarter *sessionStarter = new SessionStarter{ this };
SessionStarter *sessionStarter = new SessionStarter{ lablib->GetOccupiedPorts(), this };
sessionStarter->setWindowFlags( Qt::Window );
sessionStarter->show();
connect( sessionStarter, &SessionStarter::RequestNewSession,
@ -535,22 +535,6 @@ void lc::MainWindow::on_PBStartSession_clicked() {
// return;
// }
// // Show an error message, if there is already a zTree instance using the currently chosen port
// QVector<int> *occupiedPorts = lablib->GetOccupiedPorts();
// if ( occupiedPorts->length() != 0 ) {
// int chosenPort = ui->SBPort->value();
// for ( auto cit = occupiedPorts->cbegin(); cit != occupiedPorts->cend(); ++cit ) {
// if ( *cit == chosenPort ) {
// QMessageBox messageBox{ QMessageBox::Warning, tr( "Port is already used" ),
// tr( "The chosen port is already used by another started zTree instance.\nPlease choose another port." ), QMessageBox::Ok, this };
// messageBox.exec();
// occupiedPorts = nullptr;
// return;
// }
// }
// }
// occupiedPorts = nullptr;
// ui->CBDataTargetPath->setStyleSheet( "" );
// ui->CBPrintanonymousreceipts->setStyleSheet( "" );
// ui->CBReceiptsHeader->setStyleSheet( "" );

@ -29,16 +29,16 @@
extern std::unique_ptr< lc::Settings > settings;
lc::SessionStarter::SessionStarter( QWidget *argParent ) :
lc::SessionStarter::SessionStarter( const QVector< quint16 > &argOccupiedPorts,
QWidget *argParent ) :
QWidget{ argParent },
clientsViewModel{ new QStandardItemModel{ this } },
occupiedPorts{ argOccupiedPorts },
ui{ new Ui::SessionStarter }
{
ui->setupUi( this );
if ( settings->GetChosenZTreePort() ) {
ui->SBPort->setValue( settings->GetChosenZTreePort() );
}
CheckIfPortIsOccupied( settings->GetChosenZTreePort() );
if ( settings->dvipsCmd.isEmpty() || settings->latexCmd.isEmpty()
|| settings->lcInstDir.isEmpty() || settings->lprCmd.isEmpty()
@ -98,6 +98,13 @@ lc::SessionStarter::SessionStarter( QWidget *argParent ) :
lc::SessionStarter::~SessionStarter() {
delete ui;
}
void lc::SessionStarter::CheckIfPortIsOccupied( quint16 argPort ) {
if ( occupiedPorts.contains( argPort ) ) {
CheckIfPortIsOccupied( argPort + 1 );
} else {
ui->SBPort->setValue( argPort );
}
}
void lc::SessionStarter::GetNewDataTargetPath() {
QFileDialog fileDialog{ this };
@ -184,4 +191,6 @@ void lc::SessionStarter::on_PBStartSession_clicked() {
void lc::SessionStarter::on_SBPort_editingFinished() {
ui->SBPort->setStyleSheet( "" );
CheckIfPortIsOccupied( ui->SBPort->value() );
}

@ -36,7 +36,8 @@ class SessionStarter : public QWidget {
Q_OBJECT
public:
explicit SessionStarter( QWidget *argParent = nullptr );
explicit SessionStarter( const QVector< quint16 > &argOccupiedPorts,
QWidget *argParent = nullptr );
~SessionStarter();
signals:
@ -47,7 +48,10 @@ signals:
QString argzTreeVersion );
private:
void CheckIfPortIsOccupied( quint16 argPort );
QStandardItemModel *clientsViewModel = nullptr;
const QVector< quint16 > &occupiedPorts;
Ui::SessionStarter *ui = nullptr;
private slots:

Loading…
Cancel
Save