Browse Source

Allow to copy all peers with a keyboard shortcut

adaptive-webui-19844
ngosang 10 years ago
parent
commit
63ed69789b
  1. 51
      src/gui/properties/peerlistwidget.cpp
  2. 5
      src/gui/properties/peerlistwidget.h

51
src/gui/properties/peerlistwidget.cpp

@ -109,6 +109,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent):
// SIGNAL/SLOT // SIGNAL/SLOT
connect(header(), SIGNAL(sectionClicked(int)), SLOT(handleSortColumnChanged(int))); connect(header(), SIGNAL(sectionClicked(int)), SLOT(handleSortColumnChanged(int)));
handleSortColumnChanged(header()->sortIndicatorSection()); handleSortColumnChanged(header()->sortIndicatorSection());
copyHotkey = new QShortcut(QKeySequence(Qt::ControlModifier + Qt::Key_C), this, SLOT(copySelectedPeers()), 0, Qt::WidgetShortcut);
} }
PeerListWidget::~PeerListWidget() PeerListWidget::~PeerListWidget()
@ -119,6 +120,7 @@ PeerListWidget::~PeerListWidget()
delete m_listDelegate; delete m_listDelegate;
if (m_resolver) if (m_resolver)
delete m_resolver; delete m_resolver;
delete copyHotkey;
} }
void PeerListWidget::updatePeerHostNameResolutionState() void PeerListWidget::updatePeerHostNameResolutionState()
@ -151,19 +153,6 @@ void PeerListWidget::showPeerListMenu(const QPoint&)
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
if (!torrent) return; if (!torrent) return;
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QStringList selectedPeerIPs;
QStringList selectedPeerIPPort;
foreach (const QModelIndex &index, selectedIndexes) {
int row = m_proxyModel->mapToSource(index).row();
QString myip = m_listModel->data(m_listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString();
QString myport = m_listModel->data(m_listModel->index(row, PeerListDelegate::PORT)).toString();
selectedPeerIPs << myip;
if (myip.indexOf(".") == -1) // IPv6
selectedPeerIPPort << "[" + myip + "]:" + myport;
else // IPv4
selectedPeerIPPort << myip + ":" + myport;
}
// Add Peer Action // Add Peer Action
QAction *addPeerAct = 0; QAction *addPeerAct = 0;
if (!torrent->isQueued() && !torrent->isChecking()) { if (!torrent->isQueued() && !torrent->isChecking()) {
@ -172,7 +161,7 @@ void PeerListWidget::showPeerListMenu(const QPoint&)
} }
QAction *banAct = 0; QAction *banAct = 0;
QAction *copyPeerAct = 0; QAction *copyPeerAct = 0;
if (!selectedPeerIPs.isEmpty()) { if (!selectionModel()->selectedRows().isEmpty()) {
copyPeerAct = menu.addAction(GuiIconProvider::instance()->getIcon("edit-copy"), tr("Copy selected")); copyPeerAct = menu.addAction(GuiIconProvider::instance()->getIcon("edit-copy"), tr("Copy selected"));
menu.addSeparator(); menu.addSeparator();
banAct = menu.addAction(GuiIconProvider::instance()->getIcon("user-group-delete"), tr("Ban peer permanently")); banAct = menu.addAction(GuiIconProvider::instance()->getIcon("user-group-delete"), tr("Ban peer permanently"));
@ -201,28 +190,28 @@ void PeerListWidget::showPeerListMenu(const QPoint&)
return; return;
} }
if (act == banAct) { if (act == banAct) {
banSelectedPeers(selectedPeerIPs); banSelectedPeers();
return; return;
} }
if (act == copyPeerAct) { if (act == copyPeerAct) {
#if defined(Q_OS_WIN) || defined(Q_OS_OS2) copySelectedPeers();
QApplication::clipboard()->setText(selectedPeerIPPort.join("\r\n")); return;
#else
QApplication::clipboard()->setText(selectedPeerIPPort.join("\n"));
#endif
} }
} }
void PeerListWidget::banSelectedPeers(const QStringList& peer_ips) void PeerListWidget::banSelectedPeers()
{ {
// Confirm first // Confirm first
int ret = QMessageBox::question(this, tr("Are you sure? -- qBittorrent"), tr("Are you sure you want to ban permanently the selected peers?"), int ret = QMessageBox::question(this, tr("Ban peer permanently"), tr("Are you sure you want to ban permanently the selected peers?"),
tr("&Yes"), tr("&No"), tr("&Yes"), tr("&No"),
QString(), 0, 1); QString(), 0, 1);
if (ret) if (ret)
return; return;
foreach (const QString &ip, peer_ips) { QModelIndexList selectedIndexes = selectionModel()->selectedRows();
foreach (const QModelIndex &index, selectedIndexes) {
int row = m_proxyModel->mapToSource(index).row();
QString ip = m_listModel->data(m_listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString();
qDebug("Banning peer %s...", ip.toLocal8Bit().data()); qDebug("Banning peer %s...", ip.toLocal8Bit().data());
Logger::instance()->addMessage(tr("Manually banning peer %1...").arg(ip)); Logger::instance()->addMessage(tr("Manually banning peer %1...").arg(ip));
BitTorrent::Session::instance()->banIP(ip); BitTorrent::Session::instance()->banIP(ip);
@ -231,6 +220,22 @@ void PeerListWidget::banSelectedPeers(const QStringList& peer_ips)
loadPeers(m_properties->getCurrentTorrent()); loadPeers(m_properties->getCurrentTorrent());
} }
void PeerListWidget::copySelectedPeers()
{
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QStringList selectedPeers;
foreach (const QModelIndex &index, selectedIndexes) {
int row = m_proxyModel->mapToSource(index).row();
QString ip = m_listModel->data(m_listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString();
QString myport = m_listModel->data(m_listModel->index(row, PeerListDelegate::PORT)).toString();
if (ip.indexOf(".") == -1) // IPv6
selectedPeers << "[" + ip + "]:" + myport;
else // IPv4
selectedPeers << ip + ":" + myport;
}
QApplication::clipboard()->setText(selectedPeers.join("\n"));
}
void PeerListWidget::clear() { void PeerListWidget::clear() {
qDebug("clearing peer list"); qDebug("clearing peer list");
m_peerItems.clear(); m_peerItems.clear();

5
src/gui/properties/peerlistwidget.h

@ -35,6 +35,7 @@
#include <QHash> #include <QHash>
#include <QPointer> #include <QPointer>
#include <QSet> #include <QSet>
#include <QShortcut>
namespace Net namespace Net
{ {
@ -80,7 +81,8 @@ protected slots:
void loadSettings(); void loadSettings();
void saveSettings() const; void saveSettings() const;
void showPeerListMenu(const QPoint&); void showPeerListMenu(const QPoint&);
void banSelectedPeers(const QStringList& peer_ips); void banSelectedPeers();
void copySelectedPeers();
void handleSortColumnChanged(int col); void handleSortColumnChanged(int col);
private: private:
@ -97,6 +99,7 @@ private:
QPointer<Net::ReverseResolution> m_resolver; QPointer<Net::ReverseResolution> m_resolver;
PropertiesWidget *m_properties; PropertiesWidget *m_properties;
bool m_displayFlags; bool m_displayFlags;
QShortcut *copyHotkey;
}; };
#endif // PEERLISTWIDGET_H #endif // PEERLISTWIDGET_H

Loading…
Cancel
Save