[Qt] bantable overhaul

- some code cleanups
- fix date formatting
- reduce header includes
This commit is contained in:
Jonas Schnelli 2015-06-21 10:44:48 +02:00
parent f0bcbc4c8a
commit 53caec66cc
4 changed files with 17 additions and 14 deletions

View File

@ -8,7 +8,6 @@
#include "guiconstants.h" #include "guiconstants.h"
#include "guiutil.h" #include "guiutil.h"
#include "net.h"
#include "sync.h" #include "sync.h"
#include "utiltime.h" #include "utiltime.h"
@ -41,15 +40,16 @@ public:
cachedBanlist.reserve(banMap.size()); cachedBanlist.reserve(banMap.size());
#endif #endif
std::map<CSubNet, int64_t>::iterator iter; std::map<CSubNet, int64_t>::iterator iter;
for (iter = banMap.begin(); iter != banMap.end(); ++iter) { foreach (const PAIRTYPE(CSubNet, int64_t)& banentry, banMap)
{
CCombinedBan banEntry; CCombinedBan banEntry;
banEntry.subnet = iter->first; banEntry.subnet = banentry.first;
banEntry.bantil = iter->second; banEntry.bantil = banentry.second;
cachedBanlist.append(banEntry); cachedBanlist.append(banEntry);
} }
} }
int size() int size() const
{ {
return cachedBanlist.size(); return cachedBanlist.size();
} }
@ -120,7 +120,7 @@ QVariant BanTableModel::data(const QModelIndex &index, int role) const
case Bantime: case Bantime:
QDateTime date = QDateTime::fromMSecsSinceEpoch(0); QDateTime date = QDateTime::fromMSecsSinceEpoch(0);
date = date.addSecs(rec->bantil); date = date.addSecs(rec->bantil);
return date.toString(Qt::SystemLocaleShortDate); return date.toString(Qt::SystemLocaleLongDate);
} }
} else if (role == Qt::TextAlignmentRole) { } else if (role == Qt::TextAlignmentRole) {
if (index.column() == Bantime) if (index.column() == Bantime)

View File

@ -5,7 +5,6 @@
#ifndef BITCOIN_QT_BANTABLEMODEL_H #ifndef BITCOIN_QT_BANTABLEMODEL_H
#define BITCOIN_QT_BANTABLEMODEL_H #define BITCOIN_QT_BANTABLEMODEL_H
#include "main.h"
#include "net.h" #include "net.h"
#include <QAbstractTableModel> #include <QAbstractTableModel>

View File

@ -356,10 +356,10 @@ void RPCConsole::setClientModel(ClientModel *model)
// create context menu actions // create context menu actions
QAction* disconnectAction = new QAction(tr("&Disconnect Node"), this); QAction* disconnectAction = new QAction(tr("&Disconnect Node"), this);
QAction* banAction1h = new QAction(tr("&Ban Node for 1 hour"), this); QAction* banAction1h = new QAction(tr("&Ban Node for") + " " + tr("&1 hour"), this);
QAction* banAction24h = new QAction(tr("&Ban Node for 24 hours"), this); QAction* banAction24h = new QAction(tr("&Ban Node for") + " " + tr("&24 hours"), this);
QAction* banAction7d = new QAction(tr("&Ban Node for 7 days"), this); QAction* banAction7d = new QAction(tr("&Ban Node for") + " " + tr("&7 days"), this);
QAction* banAction365d = new QAction(tr("&Ban Node for 1 year"), this); QAction* banAction365d = new QAction(tr("&Ban Node for") + " " + tr("&1 year"), this);
// create context menu // create context menu
peersTableContextMenu = new QMenu(); peersTableContextMenu = new QMenu();
@ -798,7 +798,8 @@ void RPCConsole::banSelectedNode(int bantime)
SplitHostPort(nStr, port, addr); SplitHostPort(nStr, port, addr);
CNode::Ban(CNetAddr(addr), bantime); CNode::Ban(CNetAddr(addr), bantime);
bannedNode->CloseSocketDisconnect(); bannedNode->fDisconnect = true;
clearSelectedNode(); clearSelectedNode();
ui->banlistWidget->setVisible(true); ui->banlistWidget->setVisible(true);
ui->banHeading->setVisible(true); ui->banHeading->setVisible(true);
@ -830,6 +831,9 @@ void RPCConsole::clearSelectedNode()
void RPCConsole::showOrHideBanTableIfRequired() void RPCConsole::showOrHideBanTableIfRequired()
{ {
if (!clientModel)
return;
bool visible = clientModel->getBanTableModel()->shouldShow(); bool visible = clientModel->getBanTableModel()->shouldShow();
ui->banlistWidget->setVisible(visible); ui->banlistWidget->setVisible(visible);
ui->banHeading->setVisible(visible); ui->banHeading->setVisible(visible);

View File

@ -108,8 +108,8 @@ private:
ADDRESS_COLUMN_WIDTH = 200, ADDRESS_COLUMN_WIDTH = 200,
SUBVERSION_COLUMN_WIDTH = 100, SUBVERSION_COLUMN_WIDTH = 100,
PING_COLUMN_WIDTH = 80, PING_COLUMN_WIDTH = 80,
BANSUBNET_COLUMN_WIDTH = 300, BANSUBNET_COLUMN_WIDTH = 250,
BANTIME_COLUMN_WIDTH = 150 BANTIME_COLUMN_WIDTH = 200
}; };