From ad204df1a9077327ab1142fbc9bf41369c1a73d1 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Sat, 20 Jun 2015 20:27:03 +0200 Subject: [Qt] add banlist table below peers table --- src/qt/bantablemodel.cpp | 192 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 src/qt/bantablemodel.cpp (limited to 'src/qt/bantablemodel.cpp') diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp new file mode 100644 index 000000000..3b71769ef --- /dev/null +++ b/src/qt/bantablemodel.cpp @@ -0,0 +1,192 @@ +// Copyright (c) 2011-2015 The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "bantablemodel.h" + +#include "clientmodel.h" +#include "guiconstants.h" +#include "guiutil.h" + +#include "net.h" +#include "sync.h" +#include "utiltime.h" + +#include +#include +#include + +#include +#include + +// private implementation +class BanTablePriv +{ +public: + /** Local cache of peer information */ + QList cachedBanlist; + /** Column to sort nodes by */ + int sortColumn; + /** Order (ascending or descending) to sort nodes by */ + Qt::SortOrder sortOrder; + + /** Pull a full list of banned nodes from CNode into our cache */ + void refreshBanlist() + { + std::map banMap; + CNode::GetBanned(banMap); + + cachedBanlist.clear(); +#if QT_VERSION >= 0x040700 + cachedBanlist.reserve(banMap.size()); +#endif + std::map::iterator iter; + for (iter = banMap.begin(); iter != banMap.end(); ++iter) { + CCombinedBan banEntry; + banEntry.subnet = iter->first; + banEntry.bantil = iter->second; + cachedBanlist.append(banEntry); + } + } + + int size() + { + return cachedBanlist.size(); + } + + CCombinedBan *index(int idx) + { + if(idx >= 0 && idx < cachedBanlist.size()) { + return &cachedBanlist[idx]; + } else { + return 0; + } + } +}; + +BanTableModel::BanTableModel(ClientModel *parent) : + QAbstractTableModel(parent), + clientModel(parent), + timer(0) +{ + columns << tr("IP/Netmask") << tr("Banned Until"); + priv = new BanTablePriv(); + // default to unsorted + priv->sortColumn = -1; + + // set up timer for auto refresh + timer = new QTimer(); + connect(timer, SIGNAL(timeout()), SLOT(refresh())); + timer->setInterval(MODEL_UPDATE_DELAY); + + // load initial data + refresh(); +} + +void BanTableModel::startAutoRefresh() +{ + timer->start(); +} + +void BanTableModel::stopAutoRefresh() +{ + timer->stop(); +} + +int BanTableModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return priv->size(); +} + +int BanTableModel::columnCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + return columns.length();; +} + +QVariant BanTableModel::data(const QModelIndex &index, int role) const +{ + if(!index.isValid()) + return QVariant(); + + CCombinedBan *rec = static_cast(index.internalPointer()); + + if (role == Qt::DisplayRole) { + switch(index.column()) + { + case Address: + return QString::fromStdString(rec->subnet.ToString()); + case Bantime: + //show time in users local timezone, not 64bit compatible! + //TODO find a way to support 64bit timestamps + boost::posix_time::ptime pt1 = boost::posix_time::from_time_t(rec->bantil); + boost::posix_time::ptime pt2 = boost::date_time::c_local_adjustor::utc_to_local(pt1); + std::stringstream ss; + ss << pt2; + return QString::fromStdString(ss.str()); + } + } else if (role == Qt::TextAlignmentRole) { + if (index.column() == Bantime) + return (int)(Qt::AlignRight | Qt::AlignVCenter); + } + + return QVariant(); +} + +QVariant BanTableModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if(orientation == Qt::Horizontal) + { + if(role == Qt::DisplayRole && section < columns.size()) + { + return columns[section]; + } + } + return QVariant(); +} + +Qt::ItemFlags BanTableModel::flags(const QModelIndex &index) const +{ + if(!index.isValid()) + return 0; + + Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled; + return retval; +} + +QModelIndex BanTableModel::index(int row, int column, const QModelIndex &parent) const +{ + Q_UNUSED(parent); + CCombinedBan *data = priv->index(row); + + if (data) + { + return createIndex(row, column, data); + } + else + { + return QModelIndex(); + } +} + +void BanTableModel::refresh() +{ + emit layoutAboutToBeChanged(); + priv->refreshBanlist(); + emit layoutChanged(); +} + +void BanTableModel::sort(int column, Qt::SortOrder order) +{ + priv->sortColumn = column; + priv->sortOrder = order; + refresh(); +} + +bool BanTableModel::shouldShow() +{ + if (priv->size() > 0) + return true; + return false; +} \ No newline at end of file -- cgit v1.2.3 From f0bcbc4c8a9918e5d240ba2736286cede76155f5 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Sun, 21 Jun 2015 10:25:00 +0200 Subject: [Qt] bantable fix timestamp 64bit issue --- src/qt/bantablemodel.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/qt/bantablemodel.cpp') diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp index 3b71769ef..615574cca 100644 --- a/src/qt/bantablemodel.cpp +++ b/src/qt/bantablemodel.cpp @@ -118,13 +118,9 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const case Address: return QString::fromStdString(rec->subnet.ToString()); case Bantime: - //show time in users local timezone, not 64bit compatible! - //TODO find a way to support 64bit timestamps - boost::posix_time::ptime pt1 = boost::posix_time::from_time_t(rec->bantil); - boost::posix_time::ptime pt2 = boost::date_time::c_local_adjustor::utc_to_local(pt1); - std::stringstream ss; - ss << pt2; - return QString::fromStdString(ss.str()); + QDateTime date = QDateTime::fromMSecsSinceEpoch(0); + date = date.addSecs(rec->bantil); + return date.toString(Qt::SystemLocaleShortDate); } } else if (role == Qt::TextAlignmentRole) { if (index.column() == Bantime) -- cgit v1.2.3 From 53caec66cc43e1f16ba26e16147b77f5cfba22bb Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Sun, 21 Jun 2015 10:44:48 +0200 Subject: [Qt] bantable overhaul - some code cleanups - fix date formatting - reduce header includes --- src/qt/bantablemodel.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/qt/bantablemodel.cpp') diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp index 615574cca..b4b100bf5 100644 --- a/src/qt/bantablemodel.cpp +++ b/src/qt/bantablemodel.cpp @@ -8,7 +8,6 @@ #include "guiconstants.h" #include "guiutil.h" -#include "net.h" #include "sync.h" #include "utiltime.h" @@ -41,15 +40,16 @@ public: cachedBanlist.reserve(banMap.size()); #endif std::map::iterator iter; - for (iter = banMap.begin(); iter != banMap.end(); ++iter) { + foreach (const PAIRTYPE(CSubNet, int64_t)& banentry, banMap) + { CCombinedBan banEntry; - banEntry.subnet = iter->first; - banEntry.bantil = iter->second; + banEntry.subnet = banentry.first; + banEntry.bantil = banentry.second; cachedBanlist.append(banEntry); } } - int size() + int size() const { return cachedBanlist.size(); } @@ -120,7 +120,7 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const case Bantime: QDateTime date = QDateTime::fromMSecsSinceEpoch(0); date = date.addSecs(rec->bantil); - return date.toString(Qt::SystemLocaleShortDate); + return date.toString(Qt::SystemLocaleLongDate); } } else if (role == Qt::TextAlignmentRole) { if (index.column() == Bantime) -- cgit v1.2.3 From 9e521c173586257f57764b479beb5923c33ed0eb Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Tue, 23 Jun 2015 21:10:42 +0200 Subject: [Qt] polish ban table --- src/qt/bantablemodel.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'src/qt/bantablemodel.cpp') diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp index b4b100bf5..1ef120ccf 100644 --- a/src/qt/bantablemodel.cpp +++ b/src/qt/bantablemodel.cpp @@ -56,11 +56,10 @@ public: CCombinedBan *index(int idx) { - if(idx >= 0 && idx < cachedBanlist.size()) { + if (idx >= 0 && idx < cachedBanlist.size()) return &cachedBanlist[idx]; - } else { - return 0; - } + + return 0; } }; @@ -124,7 +123,7 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const } } else if (role == Qt::TextAlignmentRole) { if (index.column() == Bantime) - return (int)(Qt::AlignRight | Qt::AlignVCenter); + return (QVariant)(Qt::AlignRight | Qt::AlignVCenter); } return QVariant(); @@ -157,13 +156,8 @@ QModelIndex BanTableModel::index(int row, int column, const QModelIndex &parent) CCombinedBan *data = priv->index(row); if (data) - { return createIndex(row, column, data); - } - else - { - return QModelIndex(); - } + return QModelIndex(); } void BanTableModel::refresh() -- cgit v1.2.3 From 43c1f5b8d7accc158dfd6b270cb9bfd0cd900a3e Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Fri, 26 Jun 2015 10:21:13 +0200 Subject: [Qt] remove unused timer-code from banlistmodel.cpp --- src/qt/bantablemodel.cpp | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'src/qt/bantablemodel.cpp') diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp index 1ef120ccf..ee40cdbf5 100644 --- a/src/qt/bantablemodel.cpp +++ b/src/qt/bantablemodel.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include @@ -65,33 +64,17 @@ public: BanTableModel::BanTableModel(ClientModel *parent) : QAbstractTableModel(parent), - clientModel(parent), - timer(0) + clientModel(parent) { columns << tr("IP/Netmask") << tr("Banned Until"); priv = new BanTablePriv(); // default to unsorted priv->sortColumn = -1; - // set up timer for auto refresh - timer = new QTimer(); - connect(timer, SIGNAL(timeout()), SLOT(refresh())); - timer->setInterval(MODEL_UPDATE_DELAY); - // load initial data refresh(); } -void BanTableModel::startAutoRefresh() -{ - timer->start(); -} - -void BanTableModel::stopAutoRefresh() -{ - timer->stop(); -} - int BanTableModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); -- cgit v1.2.3 From 51654deff2661732c5e2a2aa8ac1f632f5880f45 Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Fri, 26 Jun 2015 14:55:52 +0200 Subject: [Qt] bantable polish - add missing NULL pointer checks - add better comments and reorder some code in rpcconsole.cpp - remove unneeded leftovers in bantable.cpp - update bantable column sizes to prevent cutting of banned until --- src/qt/bantablemodel.cpp | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/qt/bantablemodel.cpp') diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp index ee40cdbf5..6074cd2f0 100644 --- a/src/qt/bantablemodel.cpp +++ b/src/qt/bantablemodel.cpp @@ -14,8 +14,6 @@ #include #include -#include -#include // private implementation class BanTablePriv @@ -38,7 +36,6 @@ public: #if QT_VERSION >= 0x040700 cachedBanlist.reserve(banMap.size()); #endif - std::map::iterator iter; foreach (const PAIRTYPE(CSubNet, int64_t)& banentry, banMap) { CCombinedBan banEntry; @@ -104,9 +101,6 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const date = date.addSecs(rec->bantil); return date.toString(Qt::SystemLocaleLongDate); } - } else if (role == Qt::TextAlignmentRole) { - if (index.column() == Bantime) - return (QVariant)(Qt::AlignRight | Qt::AlignVCenter); } return QVariant(); -- cgit v1.2.3 From 65abe91ce4c3c9b26afa5d1af38bd1bfe81546c4 Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Fri, 26 Jun 2015 14:58:15 +0200 Subject: [Qt] add sorting for bantable --- src/qt/bantablemodel.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/qt/bantablemodel.cpp') diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp index 6074cd2f0..04840b052 100644 --- a/src/qt/bantablemodel.cpp +++ b/src/qt/bantablemodel.cpp @@ -14,6 +14,24 @@ #include #include +bool BannedNodeLessThan::operator()(const CCombinedBan& left, const CCombinedBan& right) const +{ + const CCombinedBan* pLeft = &left; + const CCombinedBan* pRight = &right; + + if (order == Qt::DescendingOrder) + std::swap(pLeft, pRight); + + switch(column) + { + case BanTableModel::Address: + return pLeft->subnet.ToString().compare(pRight->subnet.ToString()) < 0; + case BanTableModel::Bantime: + return pLeft->bantil < pRight->bantil; + } + + return false; +} // private implementation class BanTablePriv @@ -43,6 +61,10 @@ public: banEntry.bantil = banentry.second; cachedBanlist.append(banEntry); } + + if (sortColumn >= 0) + // sort cachedBanlist (use stable sort to prevent rows jumping around unneceesarily) + qStableSort(cachedBanlist.begin(), cachedBanlist.end(), BannedNodeLessThan(sortColumn, sortOrder)); } int size() const -- cgit v1.2.3 From b1189cfa105da414d8645f7284c16a443a710cfe Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Fri, 3 Jul 2015 08:35:14 +0200 Subject: [Qt] adapt QT ban option to banlist.dat changes --- src/qt/bantablemodel.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/qt/bantablemodel.cpp') diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp index 04840b052..42542371e 100644 --- a/src/qt/bantablemodel.cpp +++ b/src/qt/bantablemodel.cpp @@ -27,7 +27,7 @@ bool BannedNodeLessThan::operator()(const CCombinedBan& left, const CCombinedBan case BanTableModel::Address: return pLeft->subnet.ToString().compare(pRight->subnet.ToString()) < 0; case BanTableModel::Bantime: - return pLeft->bantil < pRight->bantil; + return pLeft->banEntry.nBanUntil < pRight->banEntry.nBanUntil; } return false; @@ -47,18 +47,18 @@ public: /** Pull a full list of banned nodes from CNode into our cache */ void refreshBanlist() { - std::map banMap; + banmap_t banMap; CNode::GetBanned(banMap); cachedBanlist.clear(); #if QT_VERSION >= 0x040700 cachedBanlist.reserve(banMap.size()); #endif - foreach (const PAIRTYPE(CSubNet, int64_t)& banentry, banMap) + foreach (const PAIRTYPE(CSubNet, CBanEntry)& banentry, banMap) { CCombinedBan banEntry; banEntry.subnet = banentry.first; - banEntry.bantil = banentry.second; + banEntry.banEntry = banentry.second; cachedBanlist.append(banEntry); } @@ -120,7 +120,7 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const return QString::fromStdString(rec->subnet.ToString()); case Bantime: QDateTime date = QDateTime::fromMSecsSinceEpoch(0); - date = date.addSecs(rec->bantil); + date = date.addSecs(rec->banEntry.nBanUntil); return date.toString(Qt::SystemLocaleLongDate); } } -- cgit v1.2.3 From 7f90ea78cb68c60408df85d5c653257dbc9160fe Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Wed, 29 Jul 2015 14:34:14 +0200 Subject: [QA] adabt QT_NO_KEYWORDS for QT ban implementation --- src/qt/bantablemodel.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/qt/bantablemodel.cpp') diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp index 42542371e..33792af5b 100644 --- a/src/qt/bantablemodel.cpp +++ b/src/qt/bantablemodel.cpp @@ -54,11 +54,11 @@ public: #if QT_VERSION >= 0x040700 cachedBanlist.reserve(banMap.size()); #endif - foreach (const PAIRTYPE(CSubNet, CBanEntry)& banentry, banMap) + for (banmap_t::iterator it = banMap.begin(); it != banMap.end(); it++) { CCombinedBan banEntry; - banEntry.subnet = banentry.first; - banEntry.banEntry = banentry.second; + banEntry.subnet = (*it).first; + banEntry.banEntry = (*it).second; cachedBanlist.append(banEntry); } @@ -161,9 +161,9 @@ QModelIndex BanTableModel::index(int row, int column, const QModelIndex &parent) void BanTableModel::refresh() { - emit layoutAboutToBeChanged(); + Q_EMIT layoutAboutToBeChanged(); priv->refreshBanlist(); - emit layoutChanged(); + Q_EMIT layoutChanged(); } void BanTableModel::sort(int column, Qt::SortOrder order) -- cgit v1.2.3 From a5a0831458d8290c1e7591cf32a529669b613d86 Mon Sep 17 00:00:00 2001 From: 21E14 <21xe14@gmail.com> Date: Tue, 29 Dec 2015 22:42:27 -0500 Subject: Double semicolon cleanup. --- src/qt/bantablemodel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/qt/bantablemodel.cpp') diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp index 33792af5b..d95106b5a 100644 --- a/src/qt/bantablemodel.cpp +++ b/src/qt/bantablemodel.cpp @@ -103,7 +103,7 @@ int BanTableModel::rowCount(const QModelIndex &parent) const int BanTableModel::columnCount(const QModelIndex &parent) const { Q_UNUSED(parent); - return columns.length();; + return columns.length(); } QVariant BanTableModel::data(const QModelIndex &index, int role) const @@ -178,4 +178,4 @@ bool BanTableModel::shouldShow() if (priv->size() > 0) return true; return false; -} \ No newline at end of file +} -- cgit v1.2.3 From a0f3d3cdad630103d919a4ec802c413b87fa1f1a Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Sat, 16 Apr 2016 17:43:11 -0400 Subject: net: move ban and addrman functions into CConnman --- src/qt/bantablemodel.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/qt/bantablemodel.cpp') diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp index d95106b5a..6e11e2390 100644 --- a/src/qt/bantablemodel.cpp +++ b/src/qt/bantablemodel.cpp @@ -48,7 +48,8 @@ public: void refreshBanlist() { banmap_t banMap; - CNode::GetBanned(banMap); + if(g_connman) + g_connman->GetBanned(banMap); cachedBanlist.clear(); #if QT_VERSION >= 0x040700 -- cgit v1.2.3 From 47db07537746940ee7dd0739a8c73e328837813f Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Fri, 18 Nov 2016 15:47:20 +0100 Subject: qt: Plug many memory leaks None of these are very serious, and are leaks in objects that are created at most one time. In most cases this means properly using the QObject parent hierarchy, except for BanTablePriv/PeerTablePriv which are not QObject, so use a std::unique_ptr instead. --- src/qt/bantablemodel.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/qt/bantablemodel.cpp') diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp index 6e11e2390..fe53d89ba 100644 --- a/src/qt/bantablemodel.cpp +++ b/src/qt/bantablemodel.cpp @@ -87,7 +87,7 @@ BanTableModel::BanTableModel(ClientModel *parent) : clientModel(parent) { columns << tr("IP/Netmask") << tr("Banned Until"); - priv = new BanTablePriv(); + priv.reset(new BanTablePriv()); // default to unsorted priv->sortColumn = -1; @@ -95,6 +95,11 @@ BanTableModel::BanTableModel(ClientModel *parent) : refresh(); } +BanTableModel::~BanTableModel() +{ + // Intentionally left empty +} + int BanTableModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); -- cgit v1.2.3 From 27765b6403cece54320374b37afb01a0cfe571c3 Mon Sep 17 00:00:00 2001 From: isle2983 Date: Sat, 31 Dec 2016 11:01:21 -0700 Subject: Increment MIT Licence copyright header year on files modified in 2016 Edited via: $ contrib/devtools/copyright_header.py update . --- src/qt/bantablemodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/qt/bantablemodel.cpp') diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp index fe53d89ba..00a915dd8 100644 --- a/src/qt/bantablemodel.cpp +++ b/src/qt/bantablemodel.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2011-2015 The Bitcoin Core developers +// Copyright (c) 2011-2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -- cgit v1.2.3 From cc16d99f1dc8305b1b255f1cc0f2b1516aa77ed0 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Wed, 18 Jan 2017 16:15:37 +0100 Subject: [trivial] Fix typos in comments --- src/qt/bantablemodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/qt/bantablemodel.cpp') diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp index 00a915dd8..4b34e73eb 100644 --- a/src/qt/bantablemodel.cpp +++ b/src/qt/bantablemodel.cpp @@ -64,7 +64,7 @@ public: } if (sortColumn >= 0) - // sort cachedBanlist (use stable sort to prevent rows jumping around unneceesarily) + // sort cachedBanlist (use stable sort to prevent rows jumping around unnecessarily) qStableSort(cachedBanlist.begin(), cachedBanlist.end(), BannedNodeLessThan(sortColumn, sortOrder)); } -- cgit v1.2.3