| 571 | } |
| 572 | |
| 573 | void RemoteManager::on_connect_clicked() |
| 574 | { |
| 575 | RDTreeWidgetItem *node = ui->hosts->selectedItem(); |
| 576 | |
| 577 | if(!node) |
| 578 | return; |
| 579 | |
| 580 | RemoteConnect connect = getRemoteConnect(node); |
| 581 | RemoteHost host = getRemoteHost(node); |
| 582 | |
| 583 | if(connect.ident > 0) |
| 584 | { |
| 585 | connectToApp(node); |
| 586 | } |
| 587 | else if(host.IsValid()) |
| 588 | { |
| 589 | if(host.IsServerRunning()) |
| 590 | { |
| 591 | QMessageBox::StandardButton res = RDDialog::question( |
| 592 | this, tr("Remote server shutdown"), |
| 593 | tr("Are you sure you wish to shut down running remote server on %1?").arg(host.Name()), |
| 594 | RDDialog::YesNoCancel); |
| 595 | |
| 596 | if(res == QMessageBox::Cancel || res == QMessageBox::No) |
| 597 | return; |
| 598 | |
| 599 | // shut down |
| 600 | if(host.IsConnected()) |
| 601 | { |
| 602 | m_Ctx.Replay().ShutdownServer(); |
| 603 | setRemoteServerLive(node, false, false); |
| 604 | } |
| 605 | else |
| 606 | { |
| 607 | ResultDetails result = {ResultCode::Succeeded}; |
| 608 | LambdaThread *th = new LambdaThread([&host, &result]() { |
| 609 | IRemoteServer *server = NULL; |
| 610 | result = host.Connect(&server); |
| 611 | if(server) |
| 612 | server->ShutdownServerAndConnection(); |
| 613 | }); |
| 614 | th->start(); |
| 615 | th->wait(500); |
| 616 | if(th->isRunning()) |
| 617 | { |
| 618 | ShowProgressDialog(this, tr("Shutting down server, please wait..."), |
| 619 | [th]() { return !th->isRunning(); }); |
| 620 | } |
| 621 | th->deleteLater(); |
| 622 | |
| 623 | setRemoteServerLive(node, false, false); |
| 624 | |
| 625 | if(!result.OK()) |
| 626 | RDDialog::critical(this, tr("Shutdown error"), |
| 627 | tr("Error shutting down remote server: %1").arg(result.Message())); |
| 628 | } |
| 629 | |
| 630 | // kick off a thread to check the status |
nothing calls this directly
no test coverage detected