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 10 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) @@ -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,
const QString &filter,
QString *selectedSuffixOut)

10
src/qt/guiutil.h

@ -64,6 +64,14 @@ namespace GUIUtil @@ -64,6 +64,14 @@ namespace GUIUtil
*/
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);
/** Get save filename, mimics QFileDialog::getSaveFileName, except that it appends a default suffix
@ -205,7 +213,7 @@ namespace GUIUtil @@ -205,7 +213,7 @@ namespace GUIUtil
#else
typedef QProgressBar ProgressBar;
#endif
} // namespace GUIUtil
#endif // BITCOIN_QT_GUIUTIL_H

34
src/qt/rpcconsole.cpp

@ -25,6 +25,7 @@ @@ -25,6 +25,7 @@
#endif
#include <QKeyEvent>
#include <QMenu>
#include <QScrollBar>
#include <QThread>
#include <QTime>
@ -205,7 +206,8 @@ RPCConsole::RPCConsole(QWidget *parent) : @@ -205,7 +206,8 @@ RPCConsole::RPCConsole(QWidget *parent) :
ui(new Ui::RPCConsole),
clientModel(0),
historyPtr(0),
cachedNodeid(-1)
cachedNodeid(-1),
contextMenu(0)
{
ui->setupUi(this);
GUIUtil::restoreWindowGeometry("nRPCConsoleWindow", this->size(), this);
@ -305,10 +307,22 @@ void RPCConsole::setClientModel(ClientModel *model) @@ -305,10 +307,22 @@ void RPCConsole::setClientModel(ClientModel *model)
ui->peerWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->peerWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->peerWidget->setSelectionMode(QAbstractItemView::SingleSelection);
ui->peerWidget->setContextMenuPolicy(Qt::CustomContextMenu);
ui->peerWidget->setColumnWidth(PeerTableModel::Address, ADDRESS_COLUMN_WIDTH);
ui->peerWidget->setColumnWidth(PeerTableModel::Subversion, SUBVERSION_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(ui->peerWidget->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
this, SLOT(peerSelected(const QItemSelection &, const QItemSelection &)));
@ -659,3 +673,21 @@ void RPCConsole::hideEvent(QHideEvent *event) @@ -659,3 +673,21 @@ void RPCConsole::hideEvent(QHideEvent *event)
// stop PeerTableModel auto refresh
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 { @@ -19,6 +19,7 @@ namespace Ui {
}
QT_BEGIN_NAMESPACE
class QMenu;
class QItemSelection;
QT_END_NAMESPACE
@ -57,6 +58,8 @@ private slots: @@ -57,6 +58,8 @@ private slots:
void resizeEvent(QResizeEvent *event);
void showEvent(QShowEvent *event);
void hideEvent(QHideEvent *event);
/** Show custom context menu on Peers tab */
void showMenu(const QPoint& point);
public slots:
void clear();
@ -73,6 +76,8 @@ public slots: @@ -73,6 +76,8 @@ public slots:
void peerSelected(const QItemSelection &selected, const QItemSelection &deselected);
/** Handle updated peer information */
void peerLayoutChanged();
/** Disconnect a selected node on the Peers tab */
void disconnectSelectedNode();
signals:
// For RPC command executor
@ -98,6 +103,7 @@ private: @@ -98,6 +103,7 @@ private:
QStringList history;
int historyPtr;
NodeId cachedNodeid;
QMenu *contextMenu;
};
#endif // BITCOIN_QT_RPCCONSOLE_H

Loading…
Cancel
Save