From e1ca46e6502604ec9bd51cd37d5f0f6c5b0ba327 Mon Sep 17 00:00:00 2001 From: Asier Lacasta Date: Wed, 8 Apr 2020 22:52:38 +0200 Subject: [PATCH 1/2] Adding the progress indication for new connections. Fixing the parameter for _custom_usleep(int sleepUs) (before was sleepMs, which was incorrect). --- src/remote.cpp | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/src/remote.cpp b/src/remote.cpp index fc169d2..92c5ade 100644 --- a/src/remote.cpp +++ b/src/remote.cpp @@ -10,8 +10,11 @@ #include "passworddialog.h" #include "exceptions.h" +#include #include #include +#include +#include #ifdef WIN32 #include @@ -19,13 +22,13 @@ #include #endif -void _custom_usleep(int sleepMs) +void _custom_usleep(int sleepUs) { #ifdef WIN32 - Sleep(sleepMs/1000); + Sleep(sleepUs/1000); #else - usleep(sleepMs); // usleep takes sleep time in us (1 millionth of a second) + usleep(sleepUs); // usleep takes sleep time in us (1 millionth of a second) #endif } @@ -37,9 +40,41 @@ Remote::Remote(QObject *qObject, SSHConnectionSettings *sshSettings) ssh_options_set(ssh, SSH_OPTIONS_HOST, sshSettings->getHostname()); ssh_options_set(ssh, SSH_OPTIONS_USER, sshSettings->getUsername()); ssh_options_set(ssh, SSH_OPTIONS_PORT, sshSettings->getPort()); - int ok; + int ok, progressIndex; + bool finished; + + auto connectingIndication = new QProgressDialog(); + auto bar = new QProgressBar(connectingIndication); + + bar->setTextVisible(false); + connectingIndication->setBar(bar); + connectingIndication->setWindowTitle("Connecting"); + connectingIndication->setLabelText("Establishing the connection with" + QString::fromUtf8(sshSettings->getHostname()) + ". Please wait..."); + connectingIndication->setCancelButton(nullptr); + connectingIndication->setRange(0, 0); + connectingIndication->setWindowModality(Qt::WindowModal); + connectingIndication->setMinimumDuration(0); + + // A Progress indicator is launched + connectingIndication->show(); + + finished = false; + std::thread *connectThread = new std::thread([&]() { + // Let's stablish the connection + ok = ssh_connect(ssh); + finished = true; + }); + + progressIndex = 0; + while(!finished) + { + connectingIndication->setValue(progressIndex); + progressIndex+=1; + progressIndex=progressIndex%100; + _custom_usleep(100000); + } - ok = ssh_connect(ssh); + connectingIndication->hide(); if(ok != SSH_OK){ ssh_free(ssh); throw new Error("Establishing a connection to the remote host failed. Please try again!"); From 02602885e14119be78e7b2a916d079b5b6e94dfb Mon Sep 17 00:00:00 2001 From: Asier Lacasta Date: Wed, 8 Apr 2020 23:00:18 +0200 Subject: [PATCH 2/2] Adding an additional space in the message. --- src/remote.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/remote.cpp b/src/remote.cpp index 92c5ade..fd39d03 100644 --- a/src/remote.cpp +++ b/src/remote.cpp @@ -49,7 +49,7 @@ Remote::Remote(QObject *qObject, SSHConnectionSettings *sshSettings) bar->setTextVisible(false); connectingIndication->setBar(bar); connectingIndication->setWindowTitle("Connecting"); - connectingIndication->setLabelText("Establishing the connection with" + QString::fromUtf8(sshSettings->getHostname()) + ". Please wait..."); + connectingIndication->setLabelText("Establishing the connection with " + QString::fromUtf8(sshSettings->getHostname()) + ". Please wait..."); connectingIndication->setCancelButton(nullptr); connectingIndication->setRange(0, 0); connectingIndication->setWindowModality(Qt::WindowModal);