Skip to content

Commit

Permalink
Implement selection of recent address
Browse files Browse the repository at this point in the history
  • Loading branch information
f1xpl committed Mar 25, 2018
1 parent f01f057 commit 9db15b9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/f1x/openauto/autoapp/UI/ConnectDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private slots:
void onConnectButtonClicked();
void onConnectionFailed(const QString& message);
void onConnectionSucceed(aasdk::tcp::ITCPEndpoint::SocketPointer socket, const std::string& ipAddress);
void onRecentAddressClicked(const QModelIndex& index);

private:
void insertIpAddress(const std::string& ipAddress);
Expand Down
7 changes: 5 additions & 2 deletions src/autoapp/Configuration/RecentAddressesList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ void RecentAddressesList::read()

void RecentAddressesList::insertAddress(const std::string& address)
{
list_.push_front(address);
this->save();
if(std::find(list_.begin(), list_.end(), address) != list_.end())
{
list_.push_front(address);
this->save();
}
}

RecentAddressesList::RecentAddresses RecentAddressesList::getList() const
Expand Down
11 changes: 11 additions & 0 deletions src/autoapp/UI/ConnectDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,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(ui_->listViewRecent, &QListView::clicked, this, &ConnectDialog::onRecentAddressClicked);
connect(this, &ConnectDialog::connectionSucceed, this, &ConnectDialog::onConnectionSucceed);
connect(this, &ConnectDialog::connectionFailed, this, &ConnectDialog::onConnectionFailed);

Expand Down Expand Up @@ -81,6 +82,16 @@ void ConnectDialog::onConnectionFailed(const QString& message)
errorMessage.exec();
}

void ConnectDialog::onRecentAddressClicked(const QModelIndex& index)
{
const auto& recentAddressesList = recentAddressesList_.getList();

if(static_cast<size_t>(index.row()) <= recentAddressesList.size())
{
ui_->lineEditIPAddress->setText(QString::fromStdString(recentAddressesList.at(index.row())));
}
}

void ConnectDialog::setControlsEnabledStatus(bool status)
{
ui_->pushButtonConnect->setVisible(status);
Expand Down
3 changes: 3 additions & 0 deletions src/autoapp/UI/connectdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
<height>141</height>
</rect>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
</widget>
</widget>
<widget class="QLabel" name="labelHeadUnitServerInfo">
Expand Down

0 comments on commit 9db15b9

Please sign in to comment.