From a9c75a31013b8b26ce9756b6ec5bc738f527630f Mon Sep 17 00:00:00 2001 From: Bryan Biedenkapp Date: Mon, 23 Dec 2024 13:35:25 -0500 Subject: [PATCH] correct issue with peer list data not properly committing; --- src/tged/TGEditPeerListWnd.h | 39 +++++++++++++++++++++++------------- src/tged/TGListWnd.h | 16 +++++++-------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/tged/TGEditPeerListWnd.h b/src/tged/TGEditPeerListWnd.h index b7d984d1..6b8314b4 100644 --- a/src/tged/TGEditPeerListWnd.h +++ b/src/tged/TGEditPeerListWnd.h @@ -219,12 +219,18 @@ private: */ void addEntry() { + LogMessage(LOG_HOST, "Adding %s peer ID %s from TG %s (%u)", m_title.c_str(), m_entry.getText().c_str(), + m_rule.name().c_str(), m_rule.source().tgId()); + if (m_entry.getText() == "") { - m_listBox.insert(std::to_string(0U)); + peerList.push_back(0U); } else { - m_listBox.insert(m_entry.getText()); + uint32_t peerId = ::atoi(m_entry.getText().c_str()); + peerList.push_back(peerId); } + loadList(); + //setFocusWidget(&m_listBox); redraw(); } @@ -238,9 +244,20 @@ private: size_t curItem = m_listBox.currentItem(); auto item = m_listBox.getItem(curItem); - LogMessage(LOG_HOST, "Removing %s peer ID %s from TG %s (%u)", m_title.c_str(), item.getText().c_str(), - m_rule.name().c_str(), m_rule.source().tgId()); - m_listBox.remove(curItem); + if (item.getText() != "") { + uint32_t peerId = ::atoi(item.getText().c_str()); + for (std::vector::iterator it = peerList.begin(); it != peerList.end(); it++) { + auto entry = *it; + if (entry == peerId) { + LogMessage(LOG_HOST, "Removing %s peer ID %s from TG %s (%u)", m_title.c_str(), item.getText().c_str(), + m_rule.name().c_str(), m_rule.source().tgId()); + peerList.erase(it); + break; + } + } + } + + loadList(); //setFocusWidget(&m_listBox); redraw(); @@ -283,15 +300,9 @@ private: return; } - peerList.clear(); - for (uint32_t i = 0U; i < m_listBox.getCount(); i++) { - auto item = m_listBox.getItem(i + 1U); - if (item.getText() != "") { - uint32_t peerId = ::atoi(item.getText().c_str()); - LogMessage(LOG_HOST, "%s peer ID %s for TG %s (%u)", m_title.c_str(), item.getText().c_str(), - m_rule.name().c_str(), m_rule.source().tgId()); - peerList.push_back(peerId); - } + for (auto entry : peerList) { + LogMessage(LOG_HOST, "%s peer ID %u for TG %s (%u)", m_title.c_str(), entry, + m_rule.name().c_str(), m_rule.source().tgId()); } CloseWndBase::onClose(e); diff --git a/src/tged/TGListWnd.h b/src/tged/TGListWnd.h index 0efb3e5b..3a315cdc 100644 --- a/src/tged/TGListWnd.h +++ b/src/tged/TGListWnd.h @@ -322,14 +322,14 @@ private: // Use box-drawing characters to draw a border constexpr std::array box_char {{ - static_cast(0x2554), - static_cast(0x2550), - static_cast(0x2557), - static_cast(0x2551), - static_cast(0x2551), - static_cast(0x255A), - static_cast(0x2550), - static_cast(0x255D) + static_cast(0x2554), // ╔ + static_cast(0x2550), // ═ + static_cast(0x2557), // ╗ + static_cast(0x2551), // ║ + static_cast(0x2551), // ║ + static_cast(0x255A), // ╚ + static_cast(0x2550), // ═ + static_cast(0x255D) // ╝ }}; drawGenericBox(this, box, box_char);