Browse Source

[Qt] banlist, UI optimizing and better signal handling

0.13
Jonas Schnelli 10 years ago
parent
commit
6135309816
  1. 1
      src/qt/clientmodel.cpp
  2. 1
      src/qt/clientmodel.h
  3. 8
      src/qt/forms/rpcconsole.ui
  4. 32
      src/qt/rpcconsole.cpp
  5. 7
      src/qt/rpcconsole.h
  6. 1
      src/rpcnet.cpp

1
src/qt/clientmodel.cpp

@ -217,6 +217,7 @@ QString ClientModel::formatClientStartupTime() const
void ClientModel::updateBanlist() void ClientModel::updateBanlist()
{ {
banTableModel->refresh(); banTableModel->refresh();
emit banListChanged();
} }
// Handlers for core signals // Handlers for core signals

1
src/qt/clientmodel.h

@ -91,6 +91,7 @@ Q_SIGNALS:
void numBlocksChanged(int count, const QDateTime& blockDate); void numBlocksChanged(int count, const QDateTime& blockDate);
void alertsChanged(const QString &warnings); void alertsChanged(const QString &warnings);
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut); void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);
void banListChanged();
//! Fired when a message should be reported to the user //! Fired when a message should be reported to the user
void message(const QString &title, const QString &message, unsigned int style); void message(const QString &title, const QString &message, unsigned int style);

8
src/qt/forms/rpcconsole.ui

@ -752,7 +752,7 @@
</property> </property>
<property name="font"> <property name="font">
<font> <font>
<pointsize>14</pointsize> <pointsize>12</pointsize>
</font> </font>
</property> </property>
<property name="cursor"> <property name="cursor">
@ -780,12 +780,6 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="horizontalScrollBarPolicy"> <property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum> <enum>Qt::ScrollBarAsNeeded</enum>
</property> </property>

32
src/qt/rpcconsole.cpp

@ -352,7 +352,7 @@ void RPCConsole::setClientModel(ClientModel *model)
ui->peerWidget->setColumnWidth(PeerTableModel::Address, ADDRESS_COLUMN_WIDTH); ui->peerWidget->setColumnWidth(PeerTableModel::Address, ADDRESS_COLUMN_WIDTH);
ui->peerWidget->setColumnWidth(PeerTableModel::Subversion, SUBVERSION_COLUMN_WIDTH); ui->peerWidget->setColumnWidth(PeerTableModel::Subversion, SUBVERSION_COLUMN_WIDTH);
ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH); ui->peerWidget->setColumnWidth(PeerTableModel::Ping, PING_COLUMN_WIDTH);
ui->peerWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); ui->peerWidget->horizontalHeader()->setStretchLastSection(true);
// create context menu actions // create context menu actions
QAction* disconnectAction = new QAction(tr("&Disconnect Node"), this); QAction* disconnectAction = new QAction(tr("&Disconnect Node"), this);
@ -373,8 +373,9 @@ void RPCConsole::setClientModel(ClientModel *model)
connect(ui->peerWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showPeersTableContextMenu(const QPoint&))); connect(ui->peerWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showPeersTableContextMenu(const QPoint&)));
connect(disconnectAction, SIGNAL(triggered()), this, SLOT(disconnectSelectedNode())); connect(disconnectAction, SIGNAL(triggered()), this, SLOT(disconnectSelectedNode()));
//add a signal mapping, use int instead of int64_t for bantime because signalmapper only supports int or objects //add a signal mapping to allow a dynamic argument
//int is sufficient for our case //we need to use int (instead of int64_t) because signal mapper only supports int or objects
//this is okay because max bantime (1 Year) is smaler then int_max
QSignalMapper* signalMapper = new QSignalMapper(this); QSignalMapper* signalMapper = new QSignalMapper(this);
signalMapper->setMapping(banAction1h, 60*60); signalMapper->setMapping(banAction1h, 60*60);
signalMapper->setMapping(banAction24h, 60*60*24); signalMapper->setMapping(banAction24h, 60*60*24);
@ -395,14 +396,14 @@ void RPCConsole::setClientModel(ClientModel *model)
ui->banlistWidget->setModel(model->getBanTableModel()); ui->banlistWidget->setModel(model->getBanTableModel());
ui->banlistWidget->verticalHeader()->hide(); ui->banlistWidget->verticalHeader()->hide();
ui->banlistWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); ui->banlistWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->banlistWidget->setColumnWidth(BanTableModel::Address, ADDRESS_COLUMN_WIDTH); ui->banlistWidget->setColumnWidth(BanTableModel::Address, BANSUBNET_COLUMN_WIDTH);
ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, PING_COLUMN_WIDTH); ui->banlistWidget->setColumnWidth(BanTableModel::Bantime, BANTIME_COLUMN_WIDTH);
ui->banlistWidget->setSelectionBehavior(QAbstractItemView::SelectRows); ui->banlistWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->banlistWidget->setSelectionMode(QAbstractItemView::SingleSelection); ui->banlistWidget->setSelectionMode(QAbstractItemView::SingleSelection);
ui->banlistWidget->setContextMenuPolicy(Qt::CustomContextMenu); ui->banlistWidget->setContextMenuPolicy(Qt::CustomContextMenu);
ui->banlistWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); ui->banlistWidget->horizontalHeader()->setStretchLastSection(true);
// create context menu actions // create banlist context menu actions
QAction* unbanAction = new QAction(tr("&Unban Node"), this); QAction* unbanAction = new QAction(tr("&Unban Node"), this);
banTableContextMenu = new QMenu(); banTableContextMenu = new QMenu();
banTableContextMenu->addAction(unbanAction); banTableContextMenu->addAction(unbanAction);
@ -419,11 +420,8 @@ void RPCConsole::setClientModel(ClientModel *model)
ui->startupTime->setText(model->formatClientStartupTime()); ui->startupTime->setText(model->formatClientStartupTime());
ui->networkName->setText(QString::fromStdString(Params().NetworkIDString())); ui->networkName->setText(QString::fromStdString(Params().NetworkIDString()));
if (!clientModel->getBanTableModel()->shouldShow()) connect(model, SIGNAL(banListChanged()), this, SLOT(showOrHideBanTableIfRequired()));
{ showOrHideBanTableIfRequired();
ui->banlistWidget->hide();
ui->banHeading->hide();
}
} }
} }
@ -810,7 +808,7 @@ void RPCConsole::banSelectedNode(int bantime)
void RPCConsole::unbanSelectedNode() void RPCConsole::unbanSelectedNode()
{ {
// Get currently selected peer address // Get currently selected ban address
QString strNode = GUIUtil::getEntryData(ui->banlistWidget, 0, BanTableModel::Address); QString strNode = GUIUtil::getEntryData(ui->banlistWidget, 0, BanTableModel::Address);
CSubNet possibleSubnet(strNode.toStdString()); CSubNet possibleSubnet(strNode.toStdString());
@ -818,6 +816,7 @@ void RPCConsole::unbanSelectedNode()
{ {
CNode::Unban(possibleSubnet); CNode::Unban(possibleSubnet);
clientModel->updateBanlist(); clientModel->updateBanlist();
showOrHideBanTableIfRequired();
} }
} }
@ -828,3 +827,10 @@ void RPCConsole::clearSelectedNode()
ui->detailWidget->hide(); ui->detailWidget->hide();
ui->peerHeading->setText(tr("Select a peer to view detailed information.")); ui->peerHeading->setText(tr("Select a peer to view detailed information."));
} }
void RPCConsole::showOrHideBanTableIfRequired()
{
bool visible = clientModel->getBanTableModel()->shouldShow();
ui->banlistWidget->setVisible(visible);
ui->banHeading->setVisible(visible);
}

7
src/qt/rpcconsole.h

@ -64,6 +64,8 @@ private Q_SLOTS:
void showPeersTableContextMenu(const QPoint& point); void showPeersTableContextMenu(const QPoint& point);
/** Show custom context menu on Bans tab */ /** Show custom context menu on Bans tab */
void showBanTableContextMenu(const QPoint& point); void showBanTableContextMenu(const QPoint& point);
/** Hides ban table if no bans are present */
void showOrHideBanTableIfRequired();
public Q_SLOTS: public Q_SLOTS:
void clear(); void clear();
@ -105,7 +107,10 @@ 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,
BANTIME_COLUMN_WIDTH = 150
}; };
Ui::RPCConsole *ui; Ui::RPCConsole *ui;

1
src/rpcnet.cpp

@ -580,7 +580,6 @@ UniValue clearbanned(const UniValue& params, bool fHelp)
CNode::ClearBanned(); CNode::ClearBanned();
DumpBanlist(); //store banlist to disk DumpBanlist(); //store banlist to disk
uiInterface.BannedListChanged(); uiInterface.BannedListChanged();
return NullUniValue; return NullUniValue;

Loading…
Cancel
Save