|
|
@ -69,7 +69,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) |
|
|
|
setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
|
|
setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
|
|
header()->setStretchLastSection(false); |
|
|
|
header()->setStretchLastSection(false); |
|
|
|
// List Model
|
|
|
|
// List Model
|
|
|
|
m_listModel = new QStandardItemModel(0, PeerListDelegate::COL_COUNT); |
|
|
|
m_listModel = new QStandardItemModel(0, PeerListDelegate::COL_COUNT, this); |
|
|
|
m_listModel->setHeaderData(PeerListDelegate::COUNTRY, Qt::Horizontal, tr("Country")); // Country flag column
|
|
|
|
m_listModel->setHeaderData(PeerListDelegate::COUNTRY, Qt::Horizontal, tr("Country")); // Country flag column
|
|
|
|
m_listModel->setHeaderData(PeerListDelegate::IP, Qt::Horizontal, tr("IP")); |
|
|
|
m_listModel->setHeaderData(PeerListDelegate::IP, Qt::Horizontal, tr("IP")); |
|
|
|
m_listModel->setHeaderData(PeerListDelegate::PORT, Qt::Horizontal, tr("Port")); |
|
|
|
m_listModel->setHeaderData(PeerListDelegate::PORT, Qt::Horizontal, tr("Port")); |
|
|
@ -92,7 +92,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) |
|
|
|
m_listModel->setHeaderData(PeerListDelegate::TOT_UP, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole); |
|
|
|
m_listModel->setHeaderData(PeerListDelegate::TOT_UP, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole); |
|
|
|
m_listModel->setHeaderData(PeerListDelegate::RELEVANCE, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole); |
|
|
|
m_listModel->setHeaderData(PeerListDelegate::RELEVANCE, Qt::Horizontal, QVariant(Qt::AlignRight | Qt::AlignVCenter), Qt::TextAlignmentRole); |
|
|
|
// Proxy model to support sorting without actually altering the underlying model
|
|
|
|
// Proxy model to support sorting without actually altering the underlying model
|
|
|
|
m_proxyModel = new PeerListSortModel(); |
|
|
|
m_proxyModel = new PeerListSortModel(this); |
|
|
|
m_proxyModel->setDynamicSortFilter(true); |
|
|
|
m_proxyModel->setDynamicSortFilter(true); |
|
|
|
m_proxyModel->setSourceModel(m_listModel); |
|
|
|
m_proxyModel->setSourceModel(m_listModel); |
|
|
|
m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); |
|
|
|
m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); |
|
|
@ -102,7 +102,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) |
|
|
|
m_resolveCountries = Preferences::instance()->resolvePeerCountries(); |
|
|
|
m_resolveCountries = Preferences::instance()->resolvePeerCountries(); |
|
|
|
if (!m_resolveCountries) |
|
|
|
if (!m_resolveCountries) |
|
|
|
hideColumn(PeerListDelegate::COUNTRY); |
|
|
|
hideColumn(PeerListDelegate::COUNTRY); |
|
|
|
//Ensure that at least one column is visible at all times
|
|
|
|
// Ensure that at least one column is visible at all times
|
|
|
|
bool atLeastOne = false; |
|
|
|
bool atLeastOne = false; |
|
|
|
for (unsigned int i = 0; i < PeerListDelegate::IP_HIDDEN; i++) { |
|
|
|
for (unsigned int i = 0; i < PeerListDelegate::IP_HIDDEN; i++) { |
|
|
|
if (!isColumnHidden(i)) { |
|
|
|
if (!isColumnHidden(i)) { |
|
|
@ -112,9 +112,9 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) |
|
|
|
} |
|
|
|
} |
|
|
|
if (!atLeastOne) |
|
|
|
if (!atLeastOne) |
|
|
|
setColumnHidden(PeerListDelegate::IP, false); |
|
|
|
setColumnHidden(PeerListDelegate::IP, false); |
|
|
|
//To also mitigate the above issue, we have to resize each column when
|
|
|
|
// To also mitigate the above issue, we have to resize each column when
|
|
|
|
//its size is 0, because explicitly 'showing' the column isn't enough
|
|
|
|
// its size is 0, because explicitly 'showing' the column isn't enough
|
|
|
|
//in the above scenario.
|
|
|
|
// in the above scenario.
|
|
|
|
for (unsigned int i = 0; i < PeerListDelegate::IP_HIDDEN; i++) |
|
|
|
for (unsigned int i = 0; i < PeerListDelegate::IP_HIDDEN; i++) |
|
|
|
if ((columnWidth(i) <= 0) && !isColumnHidden(i)) |
|
|
|
if ((columnWidth(i) <= 0) && !isColumnHidden(i)) |
|
|
|
resizeColumnToContents(i); |
|
|
|
resizeColumnToContents(i); |
|
|
@ -130,7 +130,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) |
|
|
|
updatePeerHostNameResolutionState(); |
|
|
|
updatePeerHostNameResolutionState(); |
|
|
|
// SIGNAL/SLOT
|
|
|
|
// SIGNAL/SLOT
|
|
|
|
header()->setContextMenuPolicy(Qt::CustomContextMenu); |
|
|
|
header()->setContextMenuPolicy(Qt::CustomContextMenu); |
|
|
|
connect(header(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(displayToggleColumnsMenu(const QPoint &))); |
|
|
|
connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayToggleColumnsMenu(const QPoint&))); |
|
|
|
connect(header(), SIGNAL(sectionClicked(int)), SLOT(handleSortColumnChanged(int))); |
|
|
|
connect(header(), SIGNAL(sectionClicked(int)), SLOT(handleSortColumnChanged(int))); |
|
|
|
handleSortColumnChanged(header()->sortIndicatorSection()); |
|
|
|
handleSortColumnChanged(header()->sortIndicatorSection()); |
|
|
|
m_copyHotkey = new QShortcut(QKeySequence::Copy, this, SLOT(copySelectedPeers()), 0, Qt::WidgetShortcut); |
|
|
|
m_copyHotkey = new QShortcut(QKeySequence::Copy, this, SLOT(copySelectedPeers()), 0, Qt::WidgetShortcut); |
|
|
@ -146,19 +146,15 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent) |
|
|
|
PeerListWidget::~PeerListWidget() |
|
|
|
PeerListWidget::~PeerListWidget() |
|
|
|
{ |
|
|
|
{ |
|
|
|
saveSettings(); |
|
|
|
saveSettings(); |
|
|
|
delete m_proxyModel; |
|
|
|
|
|
|
|
delete m_listModel; |
|
|
|
|
|
|
|
delete m_listDelegate; |
|
|
|
|
|
|
|
if (m_resolver) |
|
|
|
if (m_resolver) |
|
|
|
delete m_resolver; |
|
|
|
delete m_resolver; |
|
|
|
delete m_copyHotkey; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PeerListWidget::displayToggleColumnsMenu(const QPoint&) |
|
|
|
void PeerListWidget::displayToggleColumnsMenu(const QPoint &) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QMenu hideshowColumn(this); |
|
|
|
QMenu hideshowColumn(this); |
|
|
|
hideshowColumn.setTitle(tr("Column visibility")); |
|
|
|
hideshowColumn.setTitle(tr("Column visibility")); |
|
|
|
QList<QAction*> actions; |
|
|
|
QList<QAction *> actions; |
|
|
|
for (int i = 0; i < PeerListDelegate::IP_HIDDEN; ++i) { |
|
|
|
for (int i = 0; i < PeerListDelegate::IP_HIDDEN; ++i) { |
|
|
|
if ((i == PeerListDelegate::COUNTRY) && !Preferences::instance()->resolvePeerCountries()) { |
|
|
|
if ((i == PeerListDelegate::COUNTRY) && !Preferences::instance()->resolvePeerCountries()) { |
|
|
|
actions.append(nullptr); // keep the index in sync
|
|
|
|
actions.append(nullptr); // keep the index in sync
|
|
|
@ -199,7 +195,7 @@ void PeerListWidget::updatePeerHostNameResolutionState() |
|
|
|
if (Preferences::instance()->resolvePeerHostNames()) { |
|
|
|
if (Preferences::instance()->resolvePeerHostNames()) { |
|
|
|
if (!m_resolver) { |
|
|
|
if (!m_resolver) { |
|
|
|
m_resolver = new Net::ReverseResolution(this); |
|
|
|
m_resolver = new Net::ReverseResolution(this); |
|
|
|
connect(m_resolver, SIGNAL(ipResolved(QString, QString)), SLOT(handleResolved(QString, QString))); |
|
|
|
connect(m_resolver, SIGNAL(ipResolved(QString,QString)), SLOT(handleResolved(QString,QString))); |
|
|
|
loadPeers(m_properties->getCurrentTorrent(), true); |
|
|
|
loadPeers(m_properties->getCurrentTorrent(), true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -224,7 +220,7 @@ void PeerListWidget::updatePeerCountryResolutionState() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PeerListWidget::showPeerListMenu(const QPoint&) |
|
|
|
void PeerListWidget::showPeerListMenu(const QPoint &) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QMenu menu; |
|
|
|
QMenu menu; |
|
|
|
bool emptyMenu = true; |
|
|
|
bool emptyMenu = true; |
|
|
@ -368,7 +364,7 @@ void PeerListWidget::loadPeers(BitTorrent::TorrentHandle *const torrent, bool fo |
|
|
|
// Delete peers that are gone
|
|
|
|
// Delete peers that are gone
|
|
|
|
QSetIterator<QString> it(oldeersSet); |
|
|
|
QSetIterator<QString> it(oldeersSet); |
|
|
|
while (it.hasNext()) { |
|
|
|
while (it.hasNext()) { |
|
|
|
const QString& ip = it.next(); |
|
|
|
const QString &ip = it.next(); |
|
|
|
m_missingFlags.remove(ip); |
|
|
|
m_missingFlags.remove(ip); |
|
|
|
m_peerAddresses.remove(ip); |
|
|
|
m_peerAddresses.remove(ip); |
|
|
|
QStandardItem *item = m_peerItems.take(ip); |
|
|
|
QStandardItem *item = m_peerItems.take(ip); |
|
|
@ -376,7 +372,7 @@ void PeerListWidget::loadPeers(BitTorrent::TorrentHandle *const torrent, bool fo |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QStandardItem* PeerListWidget::addPeer(const QString& ip, BitTorrent::TorrentHandle *const torrent, const BitTorrent::PeerInfo &peer) |
|
|
|
QStandardItem *PeerListWidget::addPeer(const QString &ip, BitTorrent::TorrentHandle *const torrent, const BitTorrent::PeerInfo &peer) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int row = m_listModel->rowCount(); |
|
|
|
int row = m_listModel->rowCount(); |
|
|
|
// Adding Peer to peer list
|
|
|
|
// Adding Peer to peer list
|
|
|
@ -466,7 +462,7 @@ void PeerListWidget::wheelEvent(QWheelEvent *event) |
|
|
|
{ |
|
|
|
{ |
|
|
|
event->accept(); |
|
|
|
event->accept(); |
|
|
|
|
|
|
|
|
|
|
|
if(event->modifiers() & Qt::ShiftModifier) { |
|
|
|
if (event->modifiers() & Qt::ShiftModifier) { |
|
|
|
// Shift + scroll = horizontal scroll
|
|
|
|
// Shift + scroll = horizontal scroll
|
|
|
|
QWheelEvent scrollHEvent(event->pos(), event->globalPos(), event->delta(), event->buttons(), event->modifiers(), Qt::Horizontal); |
|
|
|
QWheelEvent scrollHEvent(event->pos(), event->globalPos(), event->delta(), event->buttons(), event->modifiers(), Qt::Horizontal); |
|
|
|
QTreeView::wheelEvent(&scrollHEvent); |
|
|
|
QTreeView::wheelEvent(&scrollHEvent); |
|
|
|