Changeset View
Changeset View
Standalone View
Standalone View
src/qt/bantablemodel.cpp
// Copyright (c) 2011-2016 The Bitcoin Core developers | // Copyright (c) 2011-2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "bantablemodel.h" | #include "bantablemodel.h" | ||||
#include "clientmodel.h" | #include "clientmodel.h" | ||||
#include "guiconstants.h" | #include "guiconstants.h" | ||||
#include "guiutil.h" | #include "guiutil.h" | ||||
#include "interface/node.h" | |||||
#include "sync.h" | #include "sync.h" | ||||
#include "utiltime.h" | #include "utiltime.h" | ||||
#include <QDebug> | #include <QDebug> | ||||
#include <QList> | #include <QList> | ||||
bool BannedNodeLessThan::operator()(const CCombinedBan &left, | bool BannedNodeLessThan::operator()(const CCombinedBan &left, | ||||
const CCombinedBan &right) const { | const CCombinedBan &right) const { | ||||
Show All 19 Lines | public: | ||||
/** Local cache of peer information */ | /** Local cache of peer information */ | ||||
QList<CCombinedBan> cachedBanlist; | QList<CCombinedBan> cachedBanlist; | ||||
/** Column to sort nodes by */ | /** Column to sort nodes by */ | ||||
int sortColumn; | int sortColumn; | ||||
/** Order (ascending or descending) to sort nodes by */ | /** Order (ascending or descending) to sort nodes by */ | ||||
Qt::SortOrder sortOrder; | Qt::SortOrder sortOrder; | ||||
/** Pull a full list of banned nodes from CNode into our cache */ | /** Pull a full list of banned nodes from CNode into our cache */ | ||||
void refreshBanlist() { | void refreshBanlist(interface::Node &node) { | ||||
banmap_t banMap; | banmap_t banMap; | ||||
if (g_connman) g_connman->GetBanned(banMap); | node.getBanned(banMap); | ||||
cachedBanlist.clear(); | cachedBanlist.clear(); | ||||
cachedBanlist.reserve(banMap.size()); | cachedBanlist.reserve(banMap.size()); | ||||
for (const auto &entry : banMap) { | for (const auto &entry : banMap) { | ||||
CCombinedBan banEntry; | CCombinedBan banEntry; | ||||
banEntry.subnet = entry.first; | banEntry.subnet = entry.first; | ||||
banEntry.banEntry = entry.second; | banEntry.banEntry = entry.second; | ||||
cachedBanlist.append(banEntry); | cachedBanlist.append(banEntry); | ||||
Show All 10 Lines | public: | ||||
CCombinedBan *index(int idx) { | CCombinedBan *index(int idx) { | ||||
if (idx >= 0 && idx < cachedBanlist.size()) return &cachedBanlist[idx]; | if (idx >= 0 && idx < cachedBanlist.size()) return &cachedBanlist[idx]; | ||||
return 0; | return 0; | ||||
} | } | ||||
}; | }; | ||||
BanTableModel::BanTableModel(ClientModel *parent) | BanTableModel::BanTableModel(interface::Node &node, ClientModel *parent) | ||||
: QAbstractTableModel(parent), clientModel(parent) { | : QAbstractTableModel(parent), m_node(node), clientModel(parent) { | ||||
columns << tr("IP/Netmask") << tr("Banned Until"); | columns << tr("IP/Netmask") << tr("Banned Until"); | ||||
priv.reset(new BanTablePriv()); | priv.reset(new BanTablePriv()); | ||||
// default to unsorted | // default to unsorted | ||||
priv->sortColumn = -1; | priv->sortColumn = -1; | ||||
// load initial data | // load initial data | ||||
refresh(); | refresh(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | QModelIndex BanTableModel::index(int row, int column, | ||||
CCombinedBan *data = priv->index(row); | CCombinedBan *data = priv->index(row); | ||||
if (data) return createIndex(row, column, data); | if (data) return createIndex(row, column, data); | ||||
return QModelIndex(); | return QModelIndex(); | ||||
} | } | ||||
void BanTableModel::refresh() { | void BanTableModel::refresh() { | ||||
Q_EMIT layoutAboutToBeChanged(); | Q_EMIT layoutAboutToBeChanged(); | ||||
priv->refreshBanlist(); | priv->refreshBanlist(m_node); | ||||
Q_EMIT layoutChanged(); | Q_EMIT layoutChanged(); | ||||
} | } | ||||
void BanTableModel::sort(int column, Qt::SortOrder order) { | void BanTableModel::sort(int column, Qt::SortOrder order) { | ||||
priv->sortColumn = column; | priv->sortColumn = column; | ||||
priv->sortOrder = order; | priv->sortOrder = order; | ||||
refresh(); | refresh(); | ||||
} | } | ||||
bool BanTableModel::shouldShow() { | bool BanTableModel::shouldShow() { | ||||
return priv->size() > 0; | return priv->size() > 0; | ||||
} | } |