Indicate connection progress

pull/53/head
michal.szwaj 2018-03-22 16:33:23 +01:00
parent 7c31bafa10
commit f77cbca876
4 changed files with 74 additions and 17 deletions

View File

@ -27,12 +27,14 @@ public:
signals:
void connectToDevice(const QString& ipAddress);
void connected(aasdk::tcp::ITCPEndpoint::SocketPointer socket);
void connectionSucceed(aasdk::tcp::ITCPEndpoint::SocketPointer socket);
void connectionFailed();
private slots:
void onConnectButtonClicked();
void onConnectionFailed();
void onConnectionSucceed();
void setControlsEnabledStatus(bool status);
private:
boost::asio::io_service& ioService_;

View File

@ -22,6 +22,7 @@ ConnectDialog::ConnectDialog(boost::asio::io_service& ioService, aasdk::tcp::ITC
ui_->setupUi(this);
connect(ui_->pushButtonCancel, &QPushButton::clicked, this, &ConnectDialog::close);
connect(ui_->pushButtonConnect, &QPushButton::clicked, this, &ConnectDialog::onConnectButtonClicked);
connect(this, &ConnectDialog::connectionSucceed, this, &ConnectDialog::onConnectionSucceed);
connect(this, &ConnectDialog::connectionFailed, this, &ConnectDialog::onConnectionFailed);
}
@ -32,28 +33,45 @@ ConnectDialog::~ConnectDialog()
void ConnectDialog::onConnectButtonClicked()
{
this->setControlsEnabledStatus(false);
const auto& ipAddress = ui_->lineEditIPAddress->text().toStdString();
auto socket = std::make_shared<boost::asio::ip::tcp::socket>(ioService_);
tcpWrapper_.asyncConnect(*socket, ipAddress, 5277, [this, socket](auto ec) mutable {
if(!ec)
{
emit connectionSucceed(std::move(socket));
this->close();
}
else
{
emit connectionFailed();
}
});
}
// !ec means no error
if(!tcpWrapper_.connect(*socket, ipAddress, 5277))
{
emit connected(socket);
this->close();
}
else
{
emit connectionFailed();
}
void ConnectDialog::onConnectionSucceed()
{
this->setControlsEnabledStatus(true);
}
void ConnectDialog::onConnectionFailed()
{
this->setControlsEnabledStatus(true);
QMessageBox errorMessage(QMessageBox::Critical, "Error", "Connection failed.", QMessageBox::Ok);
errorMessage.setWindowFlags(Qt::WindowStaysOnTopHint);
errorMessage.exec();
}
void ConnectDialog::setControlsEnabledStatus(bool status)
{
ui_->pushButtonConnect->setVisible(status);
ui_->pushButtonCancel->setEnabled(status);
ui_->lineEditIPAddress->setEnabled(status);
ui_->listViewRecent->setEnabled(status);
}
}
}
}

View File

@ -59,7 +59,7 @@
</property>
</widget>
</widget>
<widget class="QLabel" name="label_4">
<widget class="QLabel" name="labelHeadUnitServerInfo">
<property name="geometry">
<rect>
<x>60</x>
@ -91,9 +91,9 @@
<widget class="QPushButton" name="pushButtonCancel">
<property name="geometry">
<rect>
<x>100</x>
<x>40</x>
<y>340</y>
<width>89</width>
<width>121</width>
<height>41</height>
</rect>
</property>
@ -104,9 +104,9 @@
<widget class="QPushButton" name="pushButtonConnect">
<property name="geometry">
<rect>
<x>200</x>
<x>170</x>
<y>340</y>
<width>89</width>
<width>121</width>
<height>41</height>
</rect>
</property>
@ -114,6 +114,43 @@
<string>Connect</string>
</property>
</widget>
<widget class="QProgressBar" name="progressBarConnect">
<property name="geometry">
<rect>
<x>170</x>
<y>340</y>
<width>121</width>
<height>41</height>
</rect>
</property>
<property name="maximum">
<number>0</number>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
<widget class="QLabel" name="labelConnecting">
<property name="geometry">
<rect>
<x>188</x>
<y>350</y>
<width>91</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Connecting...</string>
</property>
</widget>
<zorder>groupBoxIPAddress</zorder>
<zorder>groupBoxRecent</zorder>
<zorder>labelHeadUnitServerInfo</zorder>
<zorder>labelCopyrightsInfoIcon</zorder>
<zorder>pushButtonCancel</zorder>
<zorder>progressBarConnect</zorder>
<zorder>labelConnecting</zorder>
<zorder>pushButtonConnect</zorder>
</widget>
<resources/>
<connections/>

View File

@ -116,7 +116,7 @@ int main(int argc, char* argv[])
auto connectedAccessoriesEnumerator(std::make_shared<aasdk::usb::ConnectedAccessoriesEnumerator>(usbWrapper, ioService, queryChainFactory));
auto app = std::make_shared<autoapp::App>(ioService, usbWrapper, tcpWrapper, androidAutoEntityFactory, std::move(usbHub), std::move(connectedAccessoriesEnumerator));
QObject::connect(&connectDialog, &autoapp::ui::ConnectDialog::connected, [&app](auto socket) {
QObject::connect(&connectDialog, &autoapp::ui::ConnectDialog::connectionSucceed, [&app](auto socket) {
app->start(std::move(socket));
});