mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-10 14:57:52 +00:00
- Implemented flag display in peer list (has to be enabled in program preferences, connection section)
This commit is contained in:
parent
12106c308e
commit
c5c09b09ee
BIN
src/Icons/flags/argentina.png
Normal file
BIN
src/Icons/flags/argentina.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 308 B |
BIN
src/Icons/flags/canada.png
Normal file
BIN
src/Icons/flags/canada.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 686 B |
BIN
src/Icons/flags/usa.png
Normal file
BIN
src/Icons/flags/usa.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 590 B |
@ -842,6 +842,7 @@ QTorrentHandle bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
|
||||
// Uploads limit per torrent
|
||||
h.set_max_uploads(maxUploadsPerTorrent);
|
||||
// Resolve countries
|
||||
qDebug("AddTorrent: Resolve_countries: %d", (int)resolve_countries);
|
||||
h.resolve_countries(resolve_countries);
|
||||
// Load filtered files
|
||||
loadFilesPriorities(h);
|
||||
|
@ -48,12 +48,14 @@
|
||||
<file>Icons/flags/taiwan.png</file>
|
||||
<file>Icons/flags/sweden.png</file>
|
||||
<file>Icons/flags/spain_catalunya.png</file>
|
||||
<file>Icons/flags/usa.png</file>
|
||||
<file>Icons/flags/romania.png</file>
|
||||
<file>Icons/flags/denmark.png</file>
|
||||
<file>Icons/flags/hungary.png</file>
|
||||
<file>Icons/flags/ukraine.png</file>
|
||||
<file>Icons/flags/turkey.png</file>
|
||||
<file>Icons/flags/greece.png</file>
|
||||
<file>Icons/flags/argentina.png</file>
|
||||
<file>Icons/flags/spain.png</file>
|
||||
<file>Icons/flags/portugal.png</file>
|
||||
<file>Icons/flags/russia.png</file>
|
||||
@ -61,6 +63,7 @@
|
||||
<file>Icons/flags/poland.png</file>
|
||||
<file>Icons/flags/germany.png</file>
|
||||
<file>Icons/flags/bulgaria.png</file>
|
||||
<file>Icons/flags/canada.png</file>
|
||||
<file>Icons/flags/brazil.png</file>
|
||||
<file>Icons/flags/france.png</file>
|
||||
<file>Icons/flags/slovakia.png</file>
|
||||
|
91
src/misc.h
91
src/misc.h
@ -41,6 +41,7 @@
|
||||
#include <QList>
|
||||
#include <QPair>
|
||||
#include <QThread>
|
||||
#include <QIcon>
|
||||
#include <ctime>
|
||||
#include <QDateTime>
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||
@ -48,13 +49,13 @@
|
||||
|
||||
#ifndef Q_WS_WIN
|
||||
#ifdef Q_WS_MAC
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#else
|
||||
#include <sys/vfs.h>
|
||||
#include <sys/vfs.h>
|
||||
#endif
|
||||
#else
|
||||
#include <winbase.h>
|
||||
#include <winbase.h>
|
||||
#endif
|
||||
|
||||
#include <libtorrent/torrent_info.hpp>
|
||||
@ -143,7 +144,7 @@ public:
|
||||
unsigned long long *ret;
|
||||
if (pGetDiskFreeSpaceEx((LPCTSTR)path.ucs2(), &bytesFree, &bytesTotal, NULL)) {
|
||||
tmp = (unsigned long long*)&bytesFree
|
||||
return ret;
|
||||
return ret;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
@ -318,6 +319,86 @@ public:
|
||||
return QDateTime::fromTime_t(mktime(&tm)).toString(Qt::DefaultLocaleLongDate);
|
||||
}
|
||||
|
||||
// TODO: Support more countries
|
||||
// http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm
|
||||
static QIcon CountryISOCodeToIcon(char* iso) {
|
||||
switch(iso[0]) {
|
||||
case 0:
|
||||
case '-':
|
||||
case '!':
|
||||
//qDebug("Not returning any icon because iso is invalid: %s", iso);
|
||||
return QIcon();
|
||||
case 'A':
|
||||
if(iso[1] == 'R') return QIcon(":/Icons/flags/argentina.png");
|
||||
break;
|
||||
case 'B':
|
||||
if(iso[1] == 'R') return QIcon(":/Icons/flags/brazil.png");
|
||||
if(iso[1] == 'G') return QIcon(":/Icons/flags/bulgaria.png");
|
||||
break;
|
||||
case 'C':
|
||||
if(iso[1] == 'A') return QIcon(":/Icons/flags/canada.png");
|
||||
if(iso[1] == 'Z') return QIcon(":/Icons/flags/czech.png");
|
||||
if(iso[1] == 'C') return QIcon(":/Icons/flags/china.png");
|
||||
break;
|
||||
case 'D':
|
||||
if(iso[1] == 'E') return QIcon(":/Icons/flags/germany.png");
|
||||
if(iso[1] == 'K') return QIcon(":/Icons/flags/denmark.png");
|
||||
break;
|
||||
case 'E':
|
||||
if(iso[1] == 'S') return QIcon(":/Icons/flags/spain.png");
|
||||
break;
|
||||
case 'F':
|
||||
if(iso[1] == 'I') return QIcon(":/Icons/flags/finland.png");
|
||||
if(iso[1] == 'R') return QIcon(":/Icons/flags/france.png");
|
||||
break;
|
||||
case 'G':
|
||||
if(iso[1] == 'B') return QIcon(":/Icons/flags/united_kingdom.png");
|
||||
if(iso[1] == 'R') return QIcon(":/Icons/flags/greece.png");
|
||||
break;
|
||||
case 'H':
|
||||
if(iso[1] == 'U') return QIcon(":/Icons/flags/hungary.png");
|
||||
if(iso[1] == 'K') return QIcon(":/Icons/flags/china.png");
|
||||
break;
|
||||
case 'I':
|
||||
if(iso[1] == 'T') return QIcon(":/Icons/flags/italy.png");
|
||||
break;
|
||||
case 'J':
|
||||
if(iso[1] == 'P') return QIcon(":/Icons/flags/japan.png");
|
||||
break;
|
||||
case 'K':
|
||||
if(iso[1] == 'R') return QIcon(":/Icons/flags/south_korea.png");
|
||||
break;
|
||||
case 'N':
|
||||
if(iso[1] == 'L') return QIcon(":/Icons/flags/netherlands.png");
|
||||
if(iso[1] == 'O') return QIcon(":/Icons/flags/norway.png");
|
||||
break;
|
||||
case 'P':
|
||||
if(iso[1] == 'T') return QIcon(":/Icons/flags/portugal.png");
|
||||
if(iso[1] == 'L') return QIcon(":/Icons/flags/poland.png");
|
||||
break;
|
||||
case 'R':
|
||||
if(iso[1] == 'U') return QIcon(":/Icons/flags/russia.png");
|
||||
if(iso[1] == 'O') return QIcon(":/Icons/flags/romania.png");
|
||||
if(iso[1] == 'E') return QIcon(":/Icons/flags/france.png");
|
||||
break;
|
||||
case 'S':
|
||||
if(iso[1] == 'E') return QIcon(":/Icons/flags/sweden.png");
|
||||
if(iso[1] == 'K') return QIcon(":/Icons/flags/slovakia.png");
|
||||
break;
|
||||
case 'T':
|
||||
if(iso[1] == 'W') return QIcon(":/Icons/flags/china.png");
|
||||
if(iso[1] == 'R') return QIcon(":/Icons/flags/turkey.png");
|
||||
break;
|
||||
case 'U':
|
||||
if(iso[1] == 'S') return QIcon(":/Icons/flags/usa.png");
|
||||
if(iso[1] == 'M') return QIcon(":/Icons/flags/usa.png");
|
||||
if(iso[1] == 'A') return QIcon(":/Icons/flags/ukraine.png");
|
||||
break;
|
||||
}
|
||||
qDebug("Unrecognized country code: %s", iso);
|
||||
return QIcon();
|
||||
}
|
||||
|
||||
// Take a number of seconds and return an user-friendly
|
||||
// time duration like "1d 2h 10m".
|
||||
static QString userFriendlyDuration(qlonglong seconds) {
|
||||
|
@ -39,7 +39,7 @@
|
||||
#include <QSettings>
|
||||
#include <vector>
|
||||
|
||||
PeerListWidget::PeerListWidget(PropertiesWidget *parent): properties(parent) {
|
||||
PeerListWidget::PeerListWidget(PropertiesWidget *parent): properties(parent), display_flags(false) {
|
||||
// Visual settings
|
||||
setRootIsDecorated(false);
|
||||
setItemsExpandable(false);
|
||||
@ -84,8 +84,7 @@ void PeerListWidget::updatePeerHostNameResolutionState() {
|
||||
resolver = new ReverseResolution(this);
|
||||
connect(resolver, SIGNAL(ip_resolved(QString,QString)), this, SLOT(handleResolved(QString,QString)));
|
||||
resolver->start();
|
||||
clear();
|
||||
loadPeers(properties->getCurrentTorrent());
|
||||
loadPeers(properties->getCurrentTorrent(), true);
|
||||
}
|
||||
} else {
|
||||
if(resolver)
|
||||
@ -93,9 +92,21 @@ void PeerListWidget::updatePeerHostNameResolutionState() {
|
||||
}
|
||||
}
|
||||
|
||||
void PeerListWidget::updatePeerCountryResolutionState() {
|
||||
if(Preferences::resolvePeerCountries() != display_flags) {
|
||||
display_flags = !display_flags;
|
||||
if(display_flags) {
|
||||
const QTorrentHandle &h = properties->getCurrentTorrent();
|
||||
if(!h.is_valid()) return;
|
||||
loadPeers(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PeerListWidget::clear() {
|
||||
qDebug("clearing peer list");
|
||||
peerItems.clear();
|
||||
missingFlags.clear();
|
||||
int nbrows = listModel->rowCount();
|
||||
if(nbrows > 0) {
|
||||
qDebug("Cleared %d peers", nbrows);
|
||||
@ -122,7 +133,7 @@ void PeerListWidget::saveSettings() const {
|
||||
settings.setValue(QString::fromUtf8("TorrentProperties/Peers/peersColsWidth"), contentColsWidths);
|
||||
}
|
||||
|
||||
void PeerListWidget::loadPeers(const QTorrentHandle &h) {
|
||||
void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_resolution) {
|
||||
if(!h.is_valid()) return;
|
||||
std::vector<peer_info> peers;
|
||||
h.get_peer_info(peers);
|
||||
@ -135,6 +146,10 @@ void PeerListWidget::loadPeers(const QTorrentHandle &h) {
|
||||
// Update existing peer
|
||||
updatePeer(peer_ip, peer);
|
||||
old_peers_set.remove(peer_ip);
|
||||
if(force_hostname_resolution) {
|
||||
if(resolver)
|
||||
resolver->resolve(peer.ip);
|
||||
}
|
||||
} else {
|
||||
// Add new peer
|
||||
peerItems[peer_ip] = addPeer(peer_ip, peer);
|
||||
@ -143,7 +158,9 @@ void PeerListWidget::loadPeers(const QTorrentHandle &h) {
|
||||
// Delete peers that are gone
|
||||
QSetIterator<QString> it(old_peers_set);
|
||||
while(it.hasNext()) {
|
||||
QStandardItem *item = peerItems.take(it.next());
|
||||
QString ip = it.next();
|
||||
missingFlags.remove(ip);
|
||||
QStandardItem *item = peerItems.take(ip);
|
||||
listModel->removeRow(item->row());
|
||||
}
|
||||
}
|
||||
@ -156,6 +173,14 @@ QStandardItem* PeerListWidget::addPeer(QString ip, peer_info peer) {
|
||||
// Resolve peer host name is asked
|
||||
if(resolver)
|
||||
resolver->resolve(peer.ip);
|
||||
if(display_flags) {
|
||||
QIcon ico = misc::CountryISOCodeToIcon(peer.country);
|
||||
if(!ico.isNull()) {
|
||||
listModel->setData(listModel->index(row, IP), ico, Qt::DecorationRole);
|
||||
} else {
|
||||
missingFlags.insert(ip);
|
||||
}
|
||||
}
|
||||
listModel->setData(listModel->index(row, CLIENT), misc::toQString(peer.client));
|
||||
listModel->setData(listModel->index(row, PROGRESS), peer.progress);
|
||||
listModel->setData(listModel->index(row, DOWN_SPEED), peer.payload_down_speed);
|
||||
@ -168,6 +193,13 @@ QStandardItem* PeerListWidget::addPeer(QString ip, peer_info peer) {
|
||||
void PeerListWidget::updatePeer(QString ip, peer_info peer) {
|
||||
QStandardItem *item = peerItems.value(ip);
|
||||
int row = item->row();
|
||||
if(display_flags) {
|
||||
QIcon ico = misc::CountryISOCodeToIcon(peer.country);
|
||||
if(!ico.isNull()) {
|
||||
listModel->setData(listModel->index(row, IP), ico, Qt::DecorationRole);
|
||||
missingFlags.remove(ip);
|
||||
}
|
||||
}
|
||||
listModel->setData(listModel->index(row, CLIENT), misc::toQString(peer.client));
|
||||
listModel->setData(listModel->index(row, PROGRESS), peer.progress);
|
||||
listModel->setData(listModel->index(row, DOWN_SPEED), peer.payload_down_speed);
|
||||
@ -177,11 +209,8 @@ void PeerListWidget::updatePeer(QString ip, peer_info peer) {
|
||||
}
|
||||
|
||||
void PeerListWidget::handleResolved(QString ip, QString hostname) {
|
||||
qDebug("%s was resolved to %s", ip.toLocal8Bit().data(), hostname.toLocal8Bit().data());
|
||||
QStandardItem *item = peerItems.value(ip, 0);
|
||||
if(item) {
|
||||
qDebug("item was updated");
|
||||
//item->setData(hostname);
|
||||
listModel->setData(listModel->indexFromItem(item), hostname);
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include <QTreeView>
|
||||
#include <QHash>
|
||||
#include <QPointer>
|
||||
#include <QSet>
|
||||
#include "qtorrenthandle.h"
|
||||
#include "misc.h"
|
||||
|
||||
@ -52,19 +53,22 @@ private:
|
||||
PeerListDelegate *listDelegate;
|
||||
QSortFilterProxyModel * proxyModel;
|
||||
QHash<QString, QStandardItem*> peerItems;
|
||||
QSet<QString> missingFlags;
|
||||
QPointer<ReverseResolution> resolver;
|
||||
PropertiesWidget* properties;
|
||||
bool display_flags;
|
||||
|
||||
public:
|
||||
PeerListWidget(PropertiesWidget *parent);
|
||||
~PeerListWidget();
|
||||
|
||||
public slots:
|
||||
void loadPeers(const QTorrentHandle &h);
|
||||
void loadPeers(const QTorrentHandle &h, bool force_hostname_resolution=false);
|
||||
QStandardItem* addPeer(QString ip, peer_info peer);
|
||||
void updatePeer(QString ip, peer_info peer);
|
||||
void handleResolved(QString ip, QString hostname);
|
||||
void updatePeerHostNameResolutionState();
|
||||
void updatePeerCountryResolutionState();
|
||||
void clear();
|
||||
|
||||
protected slots:
|
||||
|
@ -267,6 +267,7 @@ void PropertiesWidget::saveSettings() {
|
||||
void PropertiesWidget::reloadPreferences() {
|
||||
// Take program preferences into consideration
|
||||
peersList->updatePeerHostNameResolutionState();
|
||||
peersList->updatePeerCountryResolutionState();
|
||||
}
|
||||
|
||||
void PropertiesWidget::loadDynamicData() {
|
||||
|
Loading…
Reference in New Issue
Block a user