@@ -40,7 +40,7 @@ MainWindow::MainWindow(QWidget *parent, const char *config_file)
4040 connect (ui->refreshButton , &QPushButton::clicked, this , &MainWindow::refreshStreams);
4141 connect (ui->selectAllButton , &QPushButton::clicked, this , &MainWindow::selectAllStreams);
4242 connect (ui->selectNoneButton , &QPushButton::clicked, this , &MainWindow::selectNoStreams);
43- connect (ui->startButton , &QPushButton::clicked, this , &MainWindow:: startRecording);
43+ connect (ui->startButton , &QPushButton::clicked, this , [ this ]() { startRecording (); } );
4444 connect (ui->stopButton , &QPushButton::clicked, this , &MainWindow::stopRecording);
4545 connect (ui->actionAbout , &QAction::triggered, this , [this ]() {
4646 QString infostr = QStringLiteral (" LSL library version: " ) +
@@ -312,12 +312,11 @@ void MainWindow::rebuildStreamList() {
312312 item->setData (Qt::UserRole, i);
313313 item->setCheckState (k.checked ? Qt::Checked : Qt::Unchecked);
314314 item->setForeground (good_brush);
315- item->setToolTip (QString (" Name: %1\n Type: %2\n Source ID: %3\n Hostname: %4\n UID: %5 " )
315+ item->setToolTip (QString (" Name: %1\n Type: %2\n Source ID: %3\n Hostname: %4" )
316316 .arg (QString::fromStdString (k.name ),
317317 QString::fromStdString (k.type ),
318318 QString::fromStdString (k.id ),
319- QString::fromStdString (k.host ),
320- QString::fromStdString (k.uid )));
319+ QString::fromStdString (k.host )));
321320 ui->streamList ->addItem (item);
322321 }
323322}
@@ -384,9 +383,8 @@ std::vector<lsl::stream_info> MainWindow::refreshStreams() {
384383 return requestedAndAvailableStreams;
385384}
386385
387- void MainWindow::startRecording () {
386+ MainWindow::StartResult MainWindow::startRecording () {
388387 if (!currentRecording) {
389-
390388 // automatically refresh streams
391389 const std::vector<lsl::stream_info> requestedAndAvailableStreams = refreshStreams ();
392390
@@ -399,29 +397,29 @@ void MainWindow::startRecording() {
399397 QMessageBox::Yes | QMessageBox::No, this );
400398 msgBox.setInformativeText (" Do you want to start recording anyway?" );
401399 msgBox.setDefaultButton (QMessageBox::No);
402- if (msgBox.exec () != QMessageBox::Yes) return ;
400+ if (msgBox.exec () != QMessageBox::Yes) return StartResult::Failed ;
403401 }
404402
405403 if (requestedAndAvailableStreams.size () == 0 ) {
406404 QMessageBox msgBox (QMessageBox::Warning, " No available streams selected" ,
407405 " You have selected no streams" , QMessageBox::Yes | QMessageBox::No, this );
408406 msgBox.setInformativeText (" Do you want to start recording anyway?" );
409407 msgBox.setDefaultButton (QMessageBox::No);
410- if (msgBox.exec () != QMessageBox::Yes) return ;
408+ if (msgBox.exec () != QMessageBox::Yes) return StartResult::Failed ;
411409 }
412410 }
413411
414412 // don't hide critical errors.
415413 QString recFilename = replaceFilename (QDir::cleanPath (ui->lineEdit_template ->text ()));
416414 if (recFilename.isEmpty ()) {
417415 QMessageBox::critical (this , " Filename empty" , " Can not record without a file name" );
418- return ;
416+ return StartResult::Failed ;
419417 }
420418 if (ui->rootEdit ->text ().trimmed ().isEmpty ()) {
421419 QMessageBox::critical (this , " Study Root empty" ,
422420 " Can not record without a Study Root folder. "
423421 " Please set a Study Root before recording." );
424- return ;
422+ return StartResult::Failed ;
425423 }
426424 recFilename.prepend (QDir::cleanPath (ui->rootEdit ->text ()) + ' /' );
427425
@@ -430,7 +428,7 @@ void MainWindow::startRecording() {
430428 if (recFileInfo.isDir ()) {
431429 QMessageBox::warning (
432430 this , " Error" , " Recording path already exists and is a directory" );
433- return ;
431+ return StartResult::Failed ;
434432 }
435433 QString rename_to = recFileInfo.absolutePath () + ' /' + recFileInfo.baseName () +
436434 " _old%1." + recFileInfo.suffix ();
@@ -441,7 +439,7 @@ void MainWindow::startRecording() {
441439 if (!QFile::rename (recFileInfo.absoluteFilePath (), newname)) {
442440 QMessageBox::warning (this , " Permissions issue" ,
443441 " Cannot rename the file " + recFilename + " to " + newname);
444- return ;
442+ return StartResult::Failed ;
445443 }
446444 qInfo () << " Moved existing file to " << newname;
447445 recFileInfo.refresh ();
@@ -452,7 +450,7 @@ void MainWindow::startRecording() {
452450 QMessageBox::warning (this , " Permissions issue" ,
453451 " Can not create the directory " + recFileInfo.dir ().path () +
454452 " . Please check your permissions." );
455- return ;
453+ return StartResult::Failed ;
456454 }
457455
458456 std::vector<std::string> watchfor;
@@ -483,11 +481,13 @@ void MainWindow::startRecording() {
483481 ui->stopButton ->setEnabled (true );
484482 ui->startButton ->setEnabled (false );
485483 startTime = (int )lsl::local_clock ();
484+ return StartResult::Started;
486485
487486 } else if (!hideWarnings) {
488487 QMessageBox::information (
489488 this , " Already recording" , " The recording is already running" , QMessageBox::Ok);
490489 }
490+ return StartResult::AlreadyRecording;
491491}
492492
493493void MainWindow::stopRecording () {
@@ -527,15 +527,16 @@ bool MainWindow::hasSelectedStreams() const {
527527 return false ;
528528}
529529
530- void MainWindow::selectStreams (const QString &query) {
530+ MainWindow::SelectResult MainWindow::selectStreams (const QString &query) {
531531 updateKnownStreamSelectionFromUi ();
532532 std::vector<lsl::stream_info> matchedStreams;
533533 try {
534534 matchedStreams = lsl::resolve_stream (query.toStdString (), 0 , 1.0 );
535535 } catch (std::exception &e) {
536536 qWarning () << " Invalid stream selection query" << query << " :" << e.what ();
537- return ;
537+ return SelectResult::InvalidQuery ;
538538 }
539+ if (matchedStreams.empty ()) return SelectResult::NoMatches;
539540
540541 for (const auto &stream : matchedStreams) {
541542 bool known = false ;
@@ -551,6 +552,7 @@ void MainWindow::selectStreams(const QString &query) {
551552 missingStreams.remove (info_to_listName (stream));
552553 }
553554 rebuildStreamList ();
555+ return SelectResult::Selected;
554556}
555557
556558void MainWindow::buildBidsTemplate () {
@@ -693,7 +695,7 @@ void MainWindow::enableRcs(bool bEnable) {
693695 connect (rcs.get (), &RemoteControlSocket::filename, this , &MainWindow::rcsUpdateFilename);
694696 connect (rcs.get (), &RemoteControlSocket::select_all, this , &MainWindow::selectAllStreams);
695697 connect (rcs.get (), &RemoteControlSocket::select_none, this , &MainWindow::selectNoStreams);
696- connect (rcs.get (), &RemoteControlSocket::select_stream, this , &MainWindow::selectStreams );
698+ connect (rcs.get (), &RemoteControlSocket::select_stream, this , &MainWindow::rcsSelectStreams );
697699 }
698700 bool oldState = ui->rcsCheckBox ->blockSignals (true );
699701 ui->rcsCheckBox ->setChecked (bEnable);
@@ -711,16 +713,37 @@ void MainWindow::rcsStartRecording(QTcpSocket *sock) {
711713 // Remote start should record the current stream selection. Do not call
712714 // selectAllStreams() here; doing so would override TCP `select <query>` commands.
713715 // hideWarnings suppresses non-critical confirmation dialogs for remote control.
716+ if (currentRecording) {
717+ if (sock) sock->write (" WARNING already recording" );
718+ return ;
719+ }
714720 if (!hasSelectedStreams ()) {
715721 qWarning () << " Remote start rejected: no streams selected" ;
716722 if (sock) sock->write (" ERROR no streams selected" );
717723 return ;
718724 }
719725 const bool oldHideWarnings = hideWarnings;
720726 hideWarnings = true ;
721- startRecording ();
727+ const StartResult result = startRecording ();
722728 hideWarnings = oldHideWarnings;
723- if (sock) sock->write (" OK" );
729+ if (!sock) return ;
730+ if (result == StartResult::Started)
731+ sock->write (" OK" );
732+ else if (result == StartResult::AlreadyRecording)
733+ sock->write (" WARNING already recording" );
734+ else
735+ sock->write (" ERROR failed to start recording" );
736+ }
737+
738+ void MainWindow::rcsSelectStreams (const QString &query, QTcpSocket *sock) {
739+ const SelectResult result = selectStreams (query);
740+ if (!sock) return ;
741+ if (result == SelectResult::Selected)
742+ sock->write (" OK" );
743+ else if (result == SelectResult::NoMatches)
744+ sock->write (" WARNING no streams matched" );
745+ else
746+ sock->write (" ERROR invalid select query" );
724747}
725748
726749void MainWindow::rcsStopRecording () {
0 commit comments