Browse Source

Merge pull request #6217

51fc672 [Qt] disconnect peers from peers tab via context menu (Philip Kaufmann)
0.13
Wladimir J. van der Laan 9 years ago
parent
commit
c57e12aeef
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 13
      src/qt/guiutil.cpp
  2. 10
      src/qt/guiutil.h
  3. 34
      src/qt/rpcconsole.cpp
  4. 6
      src/qt/rpcconsole.h

13
src/qt/guiutil.cpp

@ -265,6 +265,19 @@ void copyEntryData(QAbstractItemView *view, int column, int role)
} }
} }
QString getEntryData(QAbstractItemView *view, int column, int role)
{
if(!view || !view->selectionModel())
return QString();
QModelIndexList selection = view->selectionModel()->selectedRows(column);
if(!selection.isEmpty()) {
// Return first item
return (selection.at(0).data(role).toString());
}
return QString();
}
QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir,
const QString &filter, const QString &filter,
QString *selectedSuffixOut) QString *selectedSuffixOut)

10
src/qt/guiutil.h

@ -64,6 +64,14 @@ namespace GUIUtil
*/ */
void copyEntryData(QAbstractItemView *view, int column, int role=Qt::EditRole); void copyEntryData(QAbstractItemView *view, int column, int role=Qt::EditRole);
/** Return a field of the currently selected entry as a QString. Does nothing if nothing
is selected.
@param[in] column Data column to extract from the model
@param[in] role Data role to extract from the model
@see TransactionView::copyLabel, TransactionView::copyAmount, TransactionView::copyAddress
*/
QString getEntryData(QAbstractItemView *view, int column, int role);
void setClipboard(const QString& str); void setClipboard(const QString& str);
/** Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix /** Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix
@ -205,7 +213,7 @@ namespace GUIUtil
#else #else
typedef QProgressBar ProgressBar; typedef QProgressBar ProgressBar;
#endif #endif
} // namespace GUIUtil } // namespace GUIUtil
#endif // BITCOIN_QT_GUIUTIL_H #endif // BITCOIN_QT_GUIUTIL_H

34
src/qt/rpcconsole.cpp

@ -25,6 +25,7 @@
#endif #endif
#include <QKeyEvent> #include <QKeyEvent>
#include <QMenu>
#include <QScrollBar> #include <QScrollBar>
#include <QThread> #include <QThread>
#include <QTime> #include <QTime>
@ -205,7 +206,8 @@ RPCConsole::RPCConsole(QWidget *parent) :
ui(new Ui::RPCConsole), ui(new Ui::RPCConsole),
clientModel(0), clientModel(0),
historyPtr(0), historyPtr(0),
cachedNodeid(-1) cachedNodeid(-1),
contextMenu(0)
{ {
ui->setupUi(this); ui->setupUi(this);
GUIUtil::restoreWindowGeometry("nRPCConsoleWindow", this->size(), this); GUIUtil::restoreWindowGeometry("nRPCConsoleWindow", this->size(), this);
@ -305,10 +307,22 @@ void RPCConsole::setClientModel(ClientModel *model)
ui->peerWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); ui->peerWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->peerWidget->setSelectionBehavior(QAbstractItemView::SelectRows); ui->peerWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->peerWidget->setSelectionMode(QAbstractItemView::SingleSelection); ui->peerWidget->setSelectionMode(QAbstractItemView::SingleSelection);
ui->peerWidget->setContextMenuPolicy(Qt::CustomContextMenu);
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);
// create context menu actions
QAction* disconnectAction = new QAction(tr("&Disconnect Node"), this);
// create context menu
contextMenu = new QMenu();
contextMenu->addAction(disconnectAction);
// context menu signals
connect(ui->peerWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showMenu(const QPoint&)));
connect(disconnectAction, SIGNAL(triggered()), this, SLOT(disconnectSelectedNode()));
// connect the peerWidget selection model to our peerSelected() handler // connect the peerWidget selection model to our peerSelected() handler
connect(ui->peerWidget->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), connect(ui->peerWidget->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
this, SLOT(peerSelected(const QItemSelection &, const QItemSelection &))); this, SLOT(peerSelected(const QItemSelection &, const QItemSelection &)));
@ -659,3 +673,21 @@ void RPCConsole::hideEvent(QHideEvent *event)
// stop PeerTableModel auto refresh // stop PeerTableModel auto refresh
clientModel->getPeerTableModel()->stopAutoRefresh(); clientModel->getPeerTableModel()->stopAutoRefresh();
} }
void RPCConsole::showMenu(const QPoint& point)
{
QModelIndex index = ui->peerWidget->indexAt(point);
if (index.isValid())
contextMenu->exec(QCursor::pos());
}
void RPCConsole::disconnectSelectedNode()
{
// Get currently selected peer address
QString strNode = GUIUtil::getEntryData(ui->peerWidget, 0, PeerTableModel::Address);
// Find the node, disconnect it and clear the selected node
if (CNode *bannedNode = FindNode(strNode.toStdString())) {
bannedNode->CloseSocketDisconnect();
ui->peerWidget->selectionModel()->clearSelection();
}
}

6
src/qt/rpcconsole.h

@ -19,6 +19,7 @@ namespace Ui {
} }
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QMenu;
class QItemSelection; class QItemSelection;
QT_END_NAMESPACE QT_END_NAMESPACE
@ -57,6 +58,8 @@ private slots:
void resizeEvent(QResizeEvent *event); void resizeEvent(QResizeEvent *event);
void showEvent(QShowEvent *event); void showEvent(QShowEvent *event);
void hideEvent(QHideEvent *event); void hideEvent(QHideEvent *event);
/** Show custom context menu on Peers tab */
void showMenu(const QPoint& point);
public slots: public slots:
void clear(); void clear();
@ -73,6 +76,8 @@ public slots:
void peerSelected(const QItemSelection &selected, const QItemSelection &deselected); void peerSelected(const QItemSelection &selected, const QItemSelection &deselected);
/** Handle updated peer information */ /** Handle updated peer information */
void peerLayoutChanged(); void peerLayoutChanged();
/** Disconnect a selected node on the Peers tab */
void disconnectSelectedNode();
signals: signals:
// For RPC command executor // For RPC command executor
@ -98,6 +103,7 @@ private:
QStringList history; QStringList history;
int historyPtr; int historyPtr;
NodeId cachedNodeid; NodeId cachedNodeid;
QMenu *contextMenu;
}; };
#endif // BITCOIN_QT_RPCCONSOLE_H #endif // BITCOIN_QT_RPCCONSOLE_H

Loading…
Cancel
Save