Skip to content

Commit

Permalink
Load recent addresses list
Browse files Browse the repository at this point in the history
  • Loading branch information
f1xpl committed Mar 25, 2018
1 parent 258a6a3 commit f01f057
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
11 changes: 5 additions & 6 deletions include/f1x/openauto/autoapp/UI/ConnectDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,25 @@ class ConnectDialog : public QDialog

signals:
void connectToDevice(const QString& ipAddress);
void connectionSucceed(aasdk::tcp::ITCPEndpoint::SocketPointer socket, std::string ipAddress);
void connectionSucceed(aasdk::tcp::ITCPEndpoint::SocketPointer socket, const std::string& ipAddress);
void connectionFailed(const QString& message);

private slots:
void onConnectButtonClicked();
void onConnectionFailed(const QString& message);
void onConnectionSucceed(aasdk::tcp::ITCPEndpoint::SocketPointer socket, std::string ipAddress);
void setControlsEnabledStatus(bool status);
void connectHandler(const boost::system::error_code& ec, std::string ipAddress, aasdk::tcp::ITCPEndpoint::SocketPointer socket);
void onConnectionSucceed(aasdk::tcp::ITCPEndpoint::SocketPointer socket, const std::string& ipAddress);

private:
void insertIpAddress(std::string ipAddress);
void insertIpAddress(const std::string& ipAddress);
void loadRecentList();
void setControlsEnabledStatus(bool status);
void connectHandler(const boost::system::error_code& ec, const std::string& ipAddress, aasdk::tcp::ITCPEndpoint::SocketPointer socket);

boost::asio::io_service& ioService_;
aasdk::tcp::ITCPWrapper& tcpWrapper_;
openauto::autoapp::configuration::IRecentAddressesList& recentAddressesList_;
Ui::ConnectDialog *ui_;
QStringListModel recentAddressesModel_;
QStringList recentAddressesModelList_;
};

}
Expand Down
15 changes: 9 additions & 6 deletions src/autoapp/UI/ConnectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ ConnectDialog::ConnectDialog(boost::asio::io_service& ioService, aasdk::tcp::ITC
, ui_(new Ui::ConnectDialog)
{
qRegisterMetaType<aasdk::tcp::ITCPEndpoint::SocketPointer>("aasdk::tcp::ITCPEndpoint::SocketPointer");
qRegisterMetaType<std::string>("std::string");

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);

recentAddressesModel_.setStringList(recentAddressesModelList_);
ui_->listViewRecent->setModel(&recentAddressesModel_);
this->loadRecentList();
}

ConnectDialog::~ConnectDialog()
Expand All @@ -52,7 +53,7 @@ void ConnectDialog::onConnectButtonClicked()
}
}

void ConnectDialog::connectHandler(const boost::system::error_code& ec, std::string ipAddress, aasdk::tcp::ITCPEndpoint::SocketPointer socket)
void ConnectDialog::connectHandler(const boost::system::error_code& ec, const std::string& ipAddress, aasdk::tcp::ITCPEndpoint::SocketPointer socket)
{
if(!ec)
{
Expand All @@ -65,7 +66,7 @@ void ConnectDialog::connectHandler(const boost::system::error_code& ec, std::str
}
}

void ConnectDialog::onConnectionSucceed(aasdk::tcp::ITCPEndpoint::SocketPointer, std::string ipAddress)
void ConnectDialog::onConnectionSucceed(aasdk::tcp::ITCPEndpoint::SocketPointer, const std::string& ipAddress)
{
this->insertIpAddress(ipAddress);
this->setControlsEnabledStatus(true);
Expand All @@ -90,16 +91,18 @@ void ConnectDialog::setControlsEnabledStatus(bool status)

void ConnectDialog::loadRecentList()
{
recentAddressesModelList_.clear();
QStringList stringList;
const auto& configList = recentAddressesList_.getList();

for(const auto& element : configList)
{
recentAddressesModelList_.append(QString::fromStdString(element));
stringList.append(QString::fromStdString(element));
}

recentAddressesModel_.setStringList(stringList);
}

void ConnectDialog::insertIpAddress(std::string ipAddress)
void ConnectDialog::insertIpAddress(const std::string& ipAddress)
{
recentAddressesList_.insertAddress(ipAddress);
this->loadRecentList();
Expand Down
6 changes: 5 additions & 1 deletion src/autoapp/autoapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <f1x/aasdk/TCP/TCPWrapper.hpp>
#include <f1x/openauto/autoapp/App.hpp>
#include <f1x/openauto/autoapp/Configuration/IConfiguration.hpp>
#include <f1x/openauto/autoapp/Configuration/RecentAddressesList.hpp>
#include <f1x/openauto/autoapp/Projection/AndroidAutoEntityFactory.hpp>
#include <f1x/openauto/autoapp/Projection/ServiceFactory.hpp>
#include <f1x/openauto/autoapp/Configuration/Configuration.hpp>
Expand Down Expand Up @@ -90,8 +91,11 @@ int main(int argc, char* argv[])
autoapp::ui::SettingsWindow settingsWindow(configuration);
settingsWindow.setWindowFlags(Qt::WindowStaysOnTopHint);

autoapp::configuration::RecentAddressesList recentAddressesList(5);
recentAddressesList.read();

aasdk::tcp::TCPWrapper tcpWrapper;
autoapp::ui::ConnectDialog connectDialog(ioService, tcpWrapper);
autoapp::ui::ConnectDialog connectDialog(ioService, tcpWrapper, recentAddressesList);
connectDialog.setWindowFlags(Qt::WindowStaysOnTopHint);

QObject::connect(&mainWindow, &autoapp::ui::MainWindow::exit, []() { std::exit(0); });
Expand Down

0 comments on commit f01f057

Please sign in to comment.