Browse Source

Add tooltip for the peers' flags. Closes #1068.

adaptive-webui-19844
sledgehammer999 11 years ago
parent
commit
7345a64696
  1. 96
      src/properties/peerlistwidget.cpp
  2. 2
      src/properties/peerlistwidget.h

96
src/properties/peerlistwidget.cpp

@ -379,7 +379,10 @@ QStandardItem* PeerListWidget::addPeer(const QString& ip, const peer_info& peer)
} }
} }
m_listModel->setData(m_listModel->index(row, PeerListDelegate::CONNECTION), getConnectionString(peer.connection_type)); m_listModel->setData(m_listModel->index(row, PeerListDelegate::CONNECTION), getConnectionString(peer.connection_type));
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), getFlags(peer)); QString flags, tooltip;
getFlags(peer, flags, tooltip);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), flags);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), tooltip, Qt::ToolTipRole);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::CLIENT), misc::toQStringU(peer.client)); m_listModel->setData(m_listModel->index(row, PeerListDelegate::CLIENT), misc::toQStringU(peer.client));
m_listModel->setData(m_listModel->index(row, PeerListDelegate::PROGRESS), peer.progress); m_listModel->setData(m_listModel->index(row, PeerListDelegate::PROGRESS), peer.progress);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payload_down_speed); m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payload_down_speed);
@ -402,7 +405,10 @@ void PeerListWidget::updatePeer(const QString& ip, const peer_info& peer) {
} }
} }
m_listModel->setData(m_listModel->index(row, PeerListDelegate::CONNECTION), getConnectionString(peer.connection_type)); m_listModel->setData(m_listModel->index(row, PeerListDelegate::CONNECTION), getConnectionString(peer.connection_type));
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), getFlags(peer)); QString flags, tooltip;
getFlags(peer, flags, tooltip);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), flags);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), tooltip, Qt::ToolTipRole);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::CLIENT), misc::toQStringU(peer.client)); m_listModel->setData(m_listModel->index(row, PeerListDelegate::CLIENT), misc::toQStringU(peer.client));
m_listModel->setData(m_listModel->index(row, PeerListDelegate::PROGRESS), peer.progress); m_listModel->setData(m_listModel->index(row, PeerListDelegate::PROGRESS), peer.progress);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payload_down_speed); m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payload_down_speed);
@ -447,68 +453,116 @@ QString PeerListWidget::getConnectionString(int connection_type)
return connection; return connection;
} }
QString PeerListWidget::getFlags(const peer_info& peer) void PeerListWidget::getFlags(const peer_info& peer, QString& flags, QString& tooltip)
{ {
QString flags;
if (peer.flags & peer_info::interesting) { if (peer.flags & peer_info::interesting) {
//d = Your client wants to download, but peer doesn't want to send (interested and choked) //d = Your client wants to download, but peer doesn't want to send (interested and choked)
if (peer.flags & peer_info::remote_choked) if (peer.flags & peer_info::remote_choked) {
flags += "d "; flags += "d ";
else //D = Currently downloading (interested and not choked) tooltip += tr("interested(local) and choked(peer)");
tooltip += ", ";
}
else {
//D = Currently downloading (interested and not choked)
flags += "D "; flags += "D ";
tooltip += tr("interested(local) and unchoked(peer)");
tooltip += ", ";
}
} }
if (peer.flags & peer_info::remote_interested) { if (peer.flags & peer_info::remote_interested) {
//u = Peer wants your client to upload, but your client doesn't want to (interested and choked) //u = Peer wants your client to upload, but your client doesn't want to (interested and choked)
if (peer.flags & peer_info::choked) if (peer.flags & peer_info::choked) {
flags += "u "; flags += "u ";
else //U = Currently uploading (interested and not choked) tooltip += tr("interested(peer) and choked(local)");
tooltip += ", ";
}
else {
//U = Currently uploading (interested and not choked)
flags += "U "; flags += "U ";
tooltip += tr("interested(peer) and unchoked(local)");
tooltip += ", ";
}
} }
//O = Optimistic unchoke //O = Optimistic unchoke
if (peer.flags & peer_info::optimistic_unchoke) if (peer.flags & peer_info::optimistic_unchoke) {
flags += "O "; flags += "O ";
tooltip += tr("optimistic unchoke");
tooltip += ", ";
}
//S = Peer is snubbed //S = Peer is snubbed
if (peer.flags & peer_info::snubbed) if (peer.flags & peer_info::snubbed) {
flags += "S "; flags += "S ";
tooltip += tr("peer snubbed");
tooltip += ", ";
}
//I = Peer is an incoming connection //I = Peer is an incoming connection
if ((peer.flags & peer_info::local_connection) == 0 ) if ((peer.flags & peer_info::local_connection) == 0 ) {
flags += "I "; flags += "I ";
tooltip += tr("incoming connection");
tooltip += ", ";
}
//K = Peer is unchoking your client, but your client is not interested //K = Peer is unchoking your client, but your client is not interested
if (((peer.flags & peer_info::remote_choked) == 0) && ((peer.flags & peer_info::interesting) == 0)) if (((peer.flags & peer_info::remote_choked) == 0) && ((peer.flags & peer_info::interesting) == 0)) {
flags += "K "; flags += "K ";
tooltip += tr("not interested(local) and unchoked(peer)");
tooltip += ", ";
}
//? = Your client unchoked the peer but the peer is not interested //? = Your client unchoked the peer but the peer is not interested
if (((peer.flags & peer_info::choked) == 0) && ((peer.flags & peer_info::remote_interested) == 0)) if (((peer.flags & peer_info::choked) == 0) && ((peer.flags & peer_info::remote_interested) == 0)) {
flags += "? "; flags += "? ";
tooltip += tr("not interested(peer) and unchoked(local)");
tooltip += ", ";
}
//X = Peer was included in peerlists obtained through Peer Exchange (PEX) //X = Peer was included in peerlists obtained through Peer Exchange (PEX)
if (peer.source & peer_info::pex) if (peer.source & peer_info::pex) {
flags += "X "; flags += "X ";
tooltip += tr("peer from PEX");
tooltip += ", ";
}
//H = Peer was obtained through DHT //H = Peer was obtained through DHT
if (peer.source & peer_info::dht) if (peer.source & peer_info::dht) {
flags += "H "; flags += "H ";
tooltip += tr("peer from PEX");
tooltip += ", ";
}
//E = Peer is using Protocol Encryption (all traffic) //E = Peer is using Protocol Encryption (all traffic)
if (peer.flags & peer_info::rc4_encrypted) if (peer.flags & peer_info::rc4_encrypted) {
flags += "E "; flags += "E ";
tooltip += tr("encrypted traffic");
tooltip += ", ";
}
//e = Peer is using Protocol Encryption (handshake) //e = Peer is using Protocol Encryption (handshake)
if (peer.flags & peer_info::plaintext_encrypted) if (peer.flags & peer_info::plaintext_encrypted) {
flags += "e "; flags += "e ";
tooltip += tr("encrypted handshake");
tooltip += ", ";
}
//P = Peer is using uTorrent uTP //P = Peer is using uTorrent uTP
if (peer.connection_type & peer_info::bittorrent_utp) if (peer.connection_type & peer_info::bittorrent_utp) {
flags += "P "; flags += "P ";
tooltip += QString::fromUtf8("μTP");
tooltip += ", ";
}
//L = Peer is local //L = Peer is local
if (peer.source & peer_info::lsd) if (peer.source & peer_info::lsd) {
flags += "L "; flags += "L";
tooltip += tr("peer from LSD");
}
return flags.trimmed(); flags = flags.trimmed();
tooltip = tooltip.trimmed();
if (tooltip.endsWith(',', Qt::CaseInsensitive))
tooltip.chop(1);
} }

2
src/properties/peerlistwidget.h

@ -84,7 +84,7 @@ protected slots:
private: private:
static QString getConnectionString(int connection_type); static QString getConnectionString(int connection_type);
static QString getFlags(const libtorrent::peer_info& peer); static void getFlags(const libtorrent::peer_info& peer, QString& flags, QString& tooltip);
private: private:
QStandardItemModel *m_listModel; QStandardItemModel *m_listModel;

Loading…
Cancel
Save