diff --git a/include/f1x/openauto/autoapp/UI/ConnectDialog.hpp b/include/f1x/openauto/autoapp/UI/ConnectDialog.hpp index 5395befc..dcb33263 100644 --- a/include/f1x/openauto/autoapp/UI/ConnectDialog.hpp +++ b/include/f1x/openauto/autoapp/UI/ConnectDialog.hpp @@ -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_; }; } diff --git a/src/autoapp/UI/ConnectDialog.cpp b/src/autoapp/UI/ConnectDialog.cpp index 1a510cd6..5e43c171 100644 --- a/src/autoapp/UI/ConnectDialog.cpp +++ b/src/autoapp/UI/ConnectDialog.cpp @@ -19,6 +19,7 @@ ConnectDialog::ConnectDialog(boost::asio::io_service& ioService, aasdk::tcp::ITC , ui_(new Ui::ConnectDialog) { qRegisterMetaType("aasdk::tcp::ITCPEndpoint::SocketPointer"); + qRegisterMetaType("std::string"); ui_->setupUi(this); connect(ui_->pushButtonCancel, &QPushButton::clicked, this, &ConnectDialog::close); @@ -26,8 +27,8 @@ ConnectDialog::ConnectDialog(boost::asio::io_service& ioService, aasdk::tcp::ITC 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() @@ -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) { @@ -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); @@ -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(); diff --git a/src/autoapp/autoapp.cpp b/src/autoapp/autoapp.cpp index 81fe3cd7..4d0d846d 100644 --- a/src/autoapp/autoapp.cpp +++ b/src/autoapp/autoapp.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -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); });