Started properties refactoring

This commit is contained in:
Christophe Dumez
2010-10-22 17:49:55 +00:00
parent c73243b0d2
commit 0a510db95e
15 changed files with 21 additions and 13 deletions

View File

@@ -0,0 +1,141 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef DOWNLOADEDPIECESBAR_H
#define DOWNLOADEDPIECESBAR_H
#include <QWidget>
#include <QPainter>
#include <QList>
#include <QPixmap>
#include <libtorrent/bitfield.hpp>
#include <math.h>
using namespace libtorrent;
#define BAR_HEIGHT 18
class DownloadedPiecesBar: public QWidget {
Q_OBJECT
private:
QPixmap pixmap;
public:
DownloadedPiecesBar(QWidget *parent): QWidget(parent) {
setFixedHeight(BAR_HEIGHT);
}
void setProgress(const bitfield &pieces, const bitfield &downloading_pieces) {
if(pieces.empty()) {
// Empty bar
QPixmap pix = QPixmap(1, 1);
pix.fill();
pixmap = pix;
} else {
const qulonglong nb_pieces = pieces.size();
// Reduce the number of pieces before creating the pixmap
// otherwise it can crash when there are too many pieces
const uint w = width();
if(nb_pieces > w) {
const uint ratio = floor(nb_pieces/(double)w);
bitfield scaled_pieces(ceil(nb_pieces/(double)ratio), false);
bitfield scaled_downloading(ceil(nb_pieces/(double)ratio), false);
uint scaled_index = 0;
for(qulonglong i=0; i<nb_pieces; i+= ratio) {
bool have = true;
for(qulonglong j=i; j<qMin(i+ratio, nb_pieces); ++j) {
if(!pieces[i]) { have = false; break; }
}
if(have) {
scaled_pieces.set_bit(scaled_index);
} else {
bool downloading = false;
for(qulonglong j=i; j<qMin(i+ratio, nb_pieces); ++j) {
if(downloading_pieces[i]) { downloading = true; break; }
}
if(downloading)
scaled_downloading.set_bit(scaled_index);
}
++scaled_index;
}
QPixmap pix = QPixmap(scaled_pieces.size(), 1);
//pix.fill();
QPainter painter(&pix);
for(uint i=0; i<scaled_pieces.size(); ++i) {
if(scaled_pieces[i]) {
painter.setPen(Qt::blue);
} else {
if(scaled_downloading[i]) {
painter.setPen(Qt::yellow);
} else {
painter.setPen(Qt::white);
}
}
painter.drawPoint(i,0);
}
pixmap = pix;
} else {
QPixmap pix = QPixmap(pieces.size(), 1);
//pix.fill();
QPainter painter(&pix);
for(uint i=0; i<pieces.size(); ++i) {
if(pieces[i]) {
painter.setPen(Qt::blue);
} else {
if(downloading_pieces[i]) {
painter.setPen(Qt::yellow);
} else {
painter.setPen(Qt::white);
}
}
painter.drawPoint(i,0);
}
pixmap = pix;
}
}
update();
}
void clear() {
pixmap = QPixmap();
update();
}
protected:
void paintEvent(QPaintEvent *) {
if(pixmap.isNull()) return;
QPainter painter(this);
painter.drawPixmap(rect(), pixmap);
}
};
#endif // DOWNLOADEDPIECESBAR_H

View File

@@ -0,0 +1,109 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef PEERADDITION_H
#define PEERADDITION_H
#include <QDialog>
#include <QRegExp>
#include <QMessageBox>
#include "ui_peer.h"
#include <libtorrent/session.hpp>
#include <boost/version.hpp>
#if BOOST_VERSION < 103500
#include <libtorrent/asio/ip/tcp.hpp>
#else
#include <boost/asio/ip/tcp.hpp>
#endif
using namespace libtorrent;
class PeerAdditionDlg: public QDialog, private Ui::addPeerDialog {
Q_OBJECT
public:
PeerAdditionDlg(QWidget *parent=0): QDialog(parent) {
setupUi(this);
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(validateInput()));
}
~PeerAdditionDlg(){}
QString getIP() const {
return lineIP->text();
}
unsigned short getPort() const {
return spinPort->value();
}
static libtorrent::asio::ip::tcp::endpoint askForPeerEndpoint() {
libtorrent::asio::ip::tcp::endpoint ep;
PeerAdditionDlg dlg;
if(dlg.exec() == QDialog::Accepted) {
const QRegExp is_ipv6(QString::fromUtf8("[0-9a-f]{4}(:[0-9a-f]{4}){7}"), Qt::CaseInsensitive, QRegExp::RegExp);
const QRegExp is_ipv4(QString::fromUtf8("(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))(\\.(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))){3}"), Qt::CaseInsensitive, QRegExp::RegExp);
QString IP = dlg.getIP();
if(is_ipv4.exactMatch(IP)) {
// IPv4
ep = libtorrent::asio::ip::tcp::endpoint(libtorrent::asio::ip::address_v4::from_string(IP.toLocal8Bit().data()), dlg.getPort());
} else {
// IPv6
ep = libtorrent::asio::ip::tcp::endpoint(libtorrent::asio::ip::address_v6::from_string(IP.toLocal8Bit().data()), dlg.getPort());
}
}
return ep;
}
protected slots:
void validateInput() {
const QRegExp is_ipv6(QString::fromUtf8("[0-9a-f]{4}(:[0-9a-f]{4}){7}"), Qt::CaseInsensitive, QRegExp::RegExp);
const QRegExp is_ipv4(QString::fromUtf8("(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))(\\.(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))){3}"), Qt::CaseInsensitive, QRegExp::RegExp);
QString IP = getIP();
if(is_ipv4.exactMatch(IP)) {
qDebug("Detected IPv4 address: %s", IP.toLocal8Bit().data());
accept();
} else {
if(is_ipv6.exactMatch(IP)) {
qDebug("Detected IPv6 address: %s", IP.toLocal8Bit().data());
accept();
} else {
QMessageBox::warning(this, tr("Invalid IP"),
tr("The IP you provided is invalid."),
QMessageBox::Ok);
}
}
}
};
#endif // PEERADDITION_H

View File

@@ -0,0 +1,84 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef PEERLISTDELEGATE_H
#define PEERLISTDELEGATE_H
#include <QItemDelegate>
#include <QPainter>
#include "misc.h"
enum PeerListColumns {IP, CLIENT, PROGRESS, DOWN_SPEED, UP_SPEED, TOT_DOWN, TOT_UP, IP_HIDDEN};
class PeerListDelegate: public QItemDelegate {
Q_OBJECT
public:
PeerListDelegate(QObject *parent) : QItemDelegate(parent){}
~PeerListDelegate(){}
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{
painter->save();
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
switch(index.column()){
case TOT_DOWN:
case TOT_UP:
QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, option.rect, misc::friendlyUnit(index.data().toLongLong()));
break;
case DOWN_SPEED:
case UP_SPEED:{
QItemDelegate::drawBackground(painter, opt, index);
double speed = index.data().toDouble();
if (speed > 0.0)
QItemDelegate::drawDisplay(painter, opt, opt.rect, misc::friendlyUnit(speed)+tr("/s", "/second (i.e. per second)"));
break;
}
case PROGRESS:{
QItemDelegate::drawBackground(painter, opt, index);
double progress = index.data().toDouble();
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::number(progress*100., 'f', 1)+"%");
break;
}
default:
QItemDelegate::paint(painter, option, index);
}
painter->restore();
}
QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const {
// No editor here
return 0;
}
};
#endif // PEERLISTDELEGATE_H

View File

@@ -0,0 +1,402 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#include "peerlistwidget.h"
#include "peerlistdelegate.h"
#include "reverseresolution.h"
#include "preferences.h"
#include "propertieswidget.h"
#include "geoip.h"
#include "peeraddition.h"
#include "speedlimitdlg.h"
#include <QStandardItemModel>
#include <QSortFilterProxyModel>
#include <QSet>
#include <QHeaderView>
#include <QMenu>
#include <QClipboard>
#include <vector>
#include "qinisettings.h"
PeerListWidget::PeerListWidget(PropertiesWidget *parent): properties(parent), display_flags(false) {
// Visual settings
setRootIsDecorated(false);
setItemsExpandable(false);
setAllColumnsShowFocus(true);
setSelectionMode(QAbstractItemView::ExtendedSelection);
// List Model
listModel = new QStandardItemModel(0, 8);
listModel->setHeaderData(IP, Qt::Horizontal, tr("IP"));
listModel->setHeaderData(CLIENT, Qt::Horizontal, tr("Client", "i.e.: Client application"));
listModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress", "i.e: % downloaded"));
listModel->setHeaderData(DOWN_SPEED, Qt::Horizontal, tr("Down Speed", "i.e: Download speed"));
listModel->setHeaderData(UP_SPEED, Qt::Horizontal, tr("Up Speed", "i.e: Upload speed"));
listModel->setHeaderData(TOT_DOWN, Qt::Horizontal, tr("Downloaded", "i.e: total data downloaded"));
listModel->setHeaderData(TOT_UP, Qt::Horizontal, tr("Uploaded", "i.e: total data uploaded"));
// Proxy model to support sorting without actually altering the underlying model
proxyModel = new QSortFilterProxyModel();
proxyModel->setDynamicSortFilter(true);
proxyModel->setSourceModel(listModel);
setModel(proxyModel);
hideColumn(IP_HIDDEN);
// Context menu
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showPeerListMenu(QPoint)));
// List delegate
listDelegate = new PeerListDelegate(this);
setItemDelegate(listDelegate);
// Enable sorting
setSortingEnabled(true);
// Load settings
loadSettings();
// IP to Hostname resolver
updatePeerHostNameResolutionState();
}
PeerListWidget::~PeerListWidget() {
saveSettings();
delete proxyModel;
delete listModel;
delete listDelegate;
if(resolver)
delete resolver;
}
void PeerListWidget::updatePeerHostNameResolutionState() {
if(Preferences::resolvePeerHostNames()) {
if(!resolver) {
resolver = new ReverseResolution(this);
connect(resolver, SIGNAL(ip_resolved(QString,QString)), this, SLOT(handleResolved(QString,QString)));
resolver->start();
loadPeers(properties->getCurrentTorrent(), true);
}
} else {
if(resolver)
resolver->asyncDelete();
}
}
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::showPeerListMenu(QPoint) {
QMenu menu;
bool empty_menu = true;
QTorrentHandle h = properties->getCurrentTorrent();
if(!h.is_valid()) return;
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QStringList selectedPeerIPs;
foreach(const QModelIndex &index, selectedIndexes) {
int row = proxyModel->mapToSource(index).row();
QString myip = listModel->data(listModel->index(row, IP_HIDDEN)).toString();
selectedPeerIPs << myip;
}
// Add Peer Action
QAction *addPeerAct = 0;
if(!h.is_queued() && !h.is_checking()) {
addPeerAct = menu.addAction(QIcon(":/Icons/oxygen/user-group-new.png"), tr("Add a new peer..."));
empty_menu = false;
}
// Per Peer Speed limiting actions
QAction *upLimitAct = 0;
QAction *dlLimitAct = 0;
QAction *banAct = 0;
QAction *copyIPAct = 0;
if(!selectedPeerIPs.isEmpty()) {
copyIPAct = menu.addAction(QIcon(":/Icons/oxygen/edit-copy.png"), tr("Copy IP"));
menu.addSeparator();
dlLimitAct = menu.addAction(QIcon(":/Icons/skin/download.png"), tr("Limit download rate..."));
upLimitAct = menu.addAction(QIcon(":/Icons/skin/seeding.png"), tr("Limit upload rate..."));
menu.addSeparator();
banAct = menu.addAction(QIcon(":/Icons/oxygen/user-group-delete.png"), tr("Ban peer permanently"));
empty_menu = false;
}
if(empty_menu) return;
QAction *act = menu.exec(QCursor::pos());
if(act == 0) return;
if(act == addPeerAct) {
libtorrent::asio::ip::tcp::endpoint ep = PeerAdditionDlg::askForPeerEndpoint();
if(ep != libtorrent::asio::ip::tcp::endpoint()) {
try {
h.connect_peer(ep);
QMessageBox::information(0, tr("Peer addition"), tr("The peer was added to this torrent."));
} catch(std::exception) {
QMessageBox::critical(0, tr("Peer addition"), tr("The peer could not be added to this torrent."));
}
} else {
qDebug("No peer was added");
}
return;
}
if(act == upLimitAct) {
limitUpRateSelectedPeers(selectedPeerIPs);
return;
}
if(act == dlLimitAct) {
limitDlRateSelectedPeers(selectedPeerIPs);
return;
}
if(act == banAct) {
banSelectedPeers(selectedPeerIPs);
return;
}
if(act == copyIPAct) {
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
QApplication::clipboard()->setText(selectedPeerIPs.join("\r\n"));
#else
QApplication::clipboard()->setText(selectedPeerIPs.join("\n"));
#endif
}
}
void PeerListWidget::banSelectedPeers(QStringList peer_ips) {
// Confirm first
int ret = QMessageBox::question(this, tr("Are you sure? -- qBittorrent"), tr("Are you sure you want to ban permanently the selected peers?"),
tr("&Yes"), tr("&No"),
QString(), 0, 1);
if(ret) return;
foreach(const QString &ip, peer_ips) {
qDebug("Banning peer %s...", ip.toLocal8Bit().data());
properties->getBTSession()->addConsoleMessage(tr("Manually banning peer %1...").arg(ip));
properties->getBTSession()->banIP(ip);
}
// Refresh list
loadPeers(properties->getCurrentTorrent());
}
void PeerListWidget::limitUpRateSelectedPeers(QStringList peer_ips) {
QTorrentHandle h = properties->getCurrentTorrent();
if(!h.is_valid()) return;
bool ok=false;
long limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Upload rate limiting"), -1, Preferences::getGlobalUploadLimit()*1024.);
if(!ok) return;
foreach(const QString &ip, peer_ips) {
libtorrent::asio::ip::tcp::endpoint ep = peerEndpoints.value(ip, libtorrent::asio::ip::tcp::endpoint());
if(ep != libtorrent::asio::ip::tcp::endpoint()) {
qDebug("Settings Upload limit of %.1f Kb/s to peer %s", limit/1024., ip.toLocal8Bit().data());
try {
h.set_peer_upload_limit(ep, limit);
}catch(std::exception) {
std::cerr << "Impossible to apply upload limit to peer" << std::endl;
}
} else {
qDebug("The selected peer no longer exists...");
}
}
}
void PeerListWidget::limitDlRateSelectedPeers(QStringList peer_ips) {
QTorrentHandle h = properties->getCurrentTorrent();
if(!h.is_valid()) return;
bool ok=false;
long limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Download rate limiting"), -1, Preferences::getGlobalDownloadLimit()*1024.);
if(!ok) return;
foreach(const QString &ip, peer_ips) {
libtorrent::asio::ip::tcp::endpoint ep = peerEndpoints.value(ip, libtorrent::asio::ip::tcp::endpoint());
if(ep != libtorrent::asio::ip::tcp::endpoint()) {
qDebug("Settings Download limit of %.1f Kb/s to peer %s", limit/1024., ip.toLocal8Bit().data());
try {
h.set_peer_download_limit(ep, limit);
}catch(std::exception) {
std::cerr << "Impossible to apply download limit to peer" << std::endl;
}
} else {
qDebug("The selected peer no longer exists...");
}
}
}
void PeerListWidget::clear() {
qDebug("clearing peer list");
peerItems.clear();
peerEndpoints.clear();
missingFlags.clear();
int nbrows = listModel->rowCount();
if(nbrows > 0) {
qDebug("Cleared %d peers", nbrows);
listModel->removeRows(0, nbrows);
}
}
void PeerListWidget::loadSettings() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QList<int> contentColsWidths = misc::intListfromStringList(settings.value(QString::fromUtf8("TorrentProperties/Peers/peersColsWidth")).toStringList());
if(!contentColsWidths.empty()) {
for(int i=0; i<contentColsWidths.size(); ++i) {
setColumnWidth(i, contentColsWidths.at(i));
}
}
// Load sorted column
QString sortedCol = settings.value(QString::fromUtf8("TorrentProperties/Peers/PeerListSortedCol"), QString()).toString();
if(!sortedCol.isEmpty()) {
Qt::SortOrder sortOrder;
if(sortedCol.endsWith(QString::fromUtf8("d")))
sortOrder = Qt::DescendingOrder;
else
sortOrder = Qt::AscendingOrder;
sortedCol.chop(1);
int index = sortedCol.toInt();
sortByColumn(index, sortOrder);
}
}
void PeerListWidget::saveSettings() const {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QStringList contentColsWidths;
for(int i=0; i<listModel->columnCount(); ++i) {
contentColsWidths << QString::number(columnWidth(i));
}
settings.setValue(QString::fromUtf8("TorrentProperties/Peers/peersColsWidth"), contentColsWidths);
// Save sorted column
Qt::SortOrder sortOrder = header()->sortIndicatorOrder();
QString sortOrderLetter;
if(sortOrder == Qt::AscendingOrder)
sortOrderLetter = QString::fromUtf8("a");
else
sortOrderLetter = QString::fromUtf8("d");
int index = header()->sortIndicatorSection();
settings.setValue(QString::fromUtf8("TorrentProperties/Peers/PeerListSortedCol"), QVariant(QString::number(index)+sortOrderLetter));
}
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);
std::vector<peer_info>::iterator itr;
QSet<QString> old_peers_set = peerItems.keys().toSet();
for(itr = peers.begin(); itr != peers.end(); itr++) {
peer_info peer = *itr;
QString peer_ip = misc::toQString(peer.ip.address().to_string());
if(peerItems.contains(peer_ip)) {
// Update existing peer
updatePeer(peer_ip, peer);
old_peers_set.remove(peer_ip);
if(force_hostname_resolution) {
if(resolver) {
QString host = resolver->getHostFromCache(peer.ip);
if(host.isNull()) {
resolver->resolve(peer.ip);
} else {
qDebug("Got peer IP from cache");
handleResolved(peer_ip, host);
}
}
}
} else {
// Add new peer
peerItems[peer_ip] = addPeer(peer_ip, peer);
peerEndpoints[peer_ip] = peer.ip;
}
}
// Delete peers that are gone
QSetIterator<QString> it(old_peers_set);
while(it.hasNext()) {
QString ip = it.next();
missingFlags.remove(ip);
peerEndpoints.remove(ip);
QStandardItem *item = peerItems.take(ip);
listModel->removeRow(item->row());
}
}
QStandardItem* PeerListWidget::addPeer(QString ip, peer_info peer) {
int row = listModel->rowCount();
// Adding Peer to peer list
listModel->insertRow(row);
QString host;
if(resolver) {
host = resolver->getHostFromCache(peer.ip);
}
if(host.isNull())
listModel->setData(listModel->index(row, IP), ip);
else
listModel->setData(listModel->index(row, IP), host);
listModel->setData(listModel->index(row, IP_HIDDEN), ip);
// Resolve peer host name is asked
if(resolver && host.isNull())
resolver->resolve(peer.ip);
if(display_flags) {
QString country_name;
const QIcon ico = GeoIP::CountryISOCodeToIcon(peer.country, country_name);
if(!ico.isNull()) {
listModel->setData(listModel->index(row, IP), ico, Qt::DecorationRole);
Q_ASSERT(!country_name.isEmpty());
listModel->setData(listModel->index(row, IP), country_name, Qt::ToolTipRole);
} else {
missingFlags.insert(ip);
}
}
listModel->setData(listModel->index(row, CLIENT), misc::toQStringU(peer.client));
listModel->setData(listModel->index(row, PROGRESS), peer.progress);
listModel->setData(listModel->index(row, DOWN_SPEED), peer.payload_down_speed);
listModel->setData(listModel->index(row, UP_SPEED), peer.payload_up_speed);
listModel->setData(listModel->index(row, TOT_DOWN), (qulonglong)peer.total_download);
listModel->setData(listModel->index(row, TOT_UP), (qulonglong)peer.total_upload);
return listModel->item(row, IP);
}
void PeerListWidget::updatePeer(QString ip, peer_info peer) {
QStandardItem *item = peerItems.value(ip);
int row = item->row();
if(display_flags) {
QString country_name;
const QIcon ico = GeoIP::CountryISOCodeToIcon(peer.country, country_name);
if(!ico.isNull()) {
listModel->setData(listModel->index(row, IP), ico, Qt::DecorationRole);
Q_ASSERT(!country_name.isEmpty());
listModel->setData(listModel->index(row, IP), country_name, Qt::ToolTipRole);
missingFlags.remove(ip);
}
}
listModel->setData(listModel->index(row, CLIENT), misc::toQStringU(peer.client));
listModel->setData(listModel->index(row, PROGRESS), peer.progress);
listModel->setData(listModel->index(row, DOWN_SPEED), peer.payload_down_speed);
listModel->setData(listModel->index(row, UP_SPEED), peer.payload_up_speed);
listModel->setData(listModel->index(row, TOT_DOWN), (qulonglong)peer.total_download);
listModel->setData(listModel->index(row, TOT_UP), (qulonglong)peer.total_upload);
}
void PeerListWidget::handleResolved(QString ip, QString hostname) {
QStandardItem *item = peerItems.value(ip, 0);
if(item) {
qDebug("Resolved %s -> %s", qPrintable(ip), qPrintable(hostname));
item->setData(hostname);
//listModel->setData(listModel->index(item->row(), IP), hostname);
}
}

View File

@@ -0,0 +1,91 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef PEERLISTWIDGET_H
#define PEERLISTWIDGET_H
#include <QTreeView>
#include <QHash>
#include <QPointer>
#include <QSet>
#include "qtorrenthandle.h"
#include "misc.h"
class QStandardItemModel;
class QStandardItem;
class QSortFilterProxyModel;
class PeerListDelegate;
class ReverseResolution;
class PropertiesWidget;
#include <boost/version.hpp>
#if BOOST_VERSION < 103500
#include <libtorrent/asio/ip/tcp.hpp>
#else
#include <boost/asio/ip/tcp.hpp>
#endif
class PeerListWidget : public QTreeView {
Q_OBJECT
public:
PeerListWidget(PropertiesWidget *parent);
~PeerListWidget();
public slots:
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:
void loadSettings();
void saveSettings() const;
void showPeerListMenu(QPoint);
void limitUpRateSelectedPeers(QStringList peer_ips);
void limitDlRateSelectedPeers(QStringList peer_ips);
void banSelectedPeers(QStringList peer_ips);
private:
QStandardItemModel *listModel;
PeerListDelegate *listDelegate;
QSortFilterProxyModel * proxyModel;
QHash<QString, QStandardItem*> peerItems;
QHash<QString, libtorrent::asio::ip::tcp::endpoint> peerEndpoints;
QSet<QString> missingFlags;
QPointer<ReverseResolution> resolver;
PropertiesWidget* properties;
bool display_flags;
};
#endif // PEERLISTWIDGET_H

View File

@@ -0,0 +1,128 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef PIECEAVAILABILITYBAR_H
#define PIECEAVAILABILITYBAR_H
#include <QWidget>
#include <QPainter>
#include <QPixmap>
#include <QColor>
#include <numeric>
#include <math.h>
#define BAR_HEIGHT 18
class PieceAvailabilityBar: public QWidget {
Q_OBJECT
private:
QPixmap pixmap;
public:
PieceAvailabilityBar(QWidget *parent): QWidget(parent) {
setFixedHeight(BAR_HEIGHT);
}
void setAvailability(const std::vector<int>& avail) {
double average = 0;
if(avail.empty()) {
// Empty bar
QPixmap pix = QPixmap(1, 1);
pix.fill();
pixmap = pix;
} else {
// Look for maximum value
const qulonglong nb_pieces = avail.size();
average = std::accumulate(avail.begin(), avail.end(), 0)/(double)nb_pieces;
// Reduce the number of pieces before creating the pixmap
// otherwise it can crash when there are too many pieces
const uint w = width();
if(nb_pieces > w) {
const qulonglong ratio = floor(nb_pieces/(double)w);
std::vector<int> scaled_avail;
scaled_avail.reserve(ceil(nb_pieces/(double)ratio));
for(qulonglong i=0; i<nb_pieces; i+= ratio) {
/*qulonglong j = i;
qulonglong sum = avail[i];
for(j=i+1; j<qMin(i+ratio, nb_pieces); ++j) {
sum += avail[j];
}
scaled_avail.push_back(sum/(qMin(ratio, nb_pieces-i)));*/
// XXX: Do not compute the average to save cpu
scaled_avail.push_back(avail[i]);
}
QPixmap pix = QPixmap(scaled_avail.size(), 1);
//pix.fill();
QPainter painter(&pix);
for(qulonglong i=0; i < scaled_avail.size(); ++i) {
painter.setPen(getPieceColor(scaled_avail[i], average));
painter.drawPoint(i,0);
}
pixmap = pix;
} else {
QPixmap pix = QPixmap(nb_pieces, 1);
//pix.fill();
QPainter painter(&pix);
for(qulonglong i=0; i < nb_pieces; ++i) {
painter.setPen(getPieceColor(avail[i], average));
painter.drawPoint(i,0);
}
pixmap = pix;
}
}
update();
}
void clear() {
pixmap = QPixmap();
update();
}
protected:
void paintEvent(QPaintEvent *) {
if(pixmap.isNull()) return;
QPainter painter(this);
painter.drawPixmap(rect(), pixmap);
}
QColor getPieceColor(int avail, double average) {
if(!avail) return Qt::white;
//qDebug("avail: %d/%d", avail, max_avail);
double fraction = 100.*average/avail;
if(fraction < 100)
fraction *= 0.8;
else
fraction *= 1.2;
return QColor(Qt::blue).lighter(fraction);
}
};
#endif // PIECEAVAILABILITYBAR_H

View File

@@ -0,0 +1,20 @@
INCLUDEPATH += $$PWD
!contains(DEFINES, DISABLE_GUI) {
FORMS += $$PWD/propertieswidget.ui
HEADERS += $$PWD/propertieswidget.h \
$$PWD/peerlistwidget.h \
$$PWD/proplistdelegate.h \
$$PWD/trackerlist.h \
$$PWD/downloadedpiecesbar.h \
$$PWD/peerlistdelegate.h \
$$PWD/peeraddition.h \
$$PWD/trackersadditiondlg.h \
$$PWD/pieceavailabilitybar.h
SOURCES += $$PWD/propertieswidget.cpp \
$$PWD/peerlistwidget.cpp \
$$PWD/trackerlist.cpp
}

View File

@@ -0,0 +1,843 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#include <QTimer>
#include <QListWidgetItem>
#include <QVBoxLayout>
#include <QStackedWidget>
#include <QSplitter>
#include <QHeaderView>
#include <QAction>
#include <QMessageBox>
#include <QMenu>
#include <QFileDialog>
#include <QDesktopServices>
#include <QInputDialog>
#include <libtorrent/version.hpp>
#include "propertieswidget.h"
#include "transferlistwidget.h"
#include "torrentpersistentdata.h"
#include "qbtsession.h"
#include "proplistdelegate.h"
#include "torrentfilesmodel.h"
#include "peerlistwidget.h"
#include "trackerlist.h"
#include "GUI.h"
#include "downloadedpiecesbar.h"
#include "pieceavailabilitybar.h"
#include "qinisettings.h"
#ifdef Q_WS_MAC
#define DEFAULT_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px; margin-left: 8px; margin-right: 8px;}"
#define SELECTED_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px;background-color: rgb(255, 208, 105); margin-left: 8px; margin-right: 8px;}"
#else
#define DEFAULT_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px; margin-left: 3px; margin-right: 3px;}"
#define SELECTED_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px;background-color: rgb(255, 208, 105); margin-left: 3px; margin-right: 3px;}"
#endif
PropertiesWidget::PropertiesWidget(QWidget *parent, GUI* main_window, TransferListWidget *transferList, QBtSession* BTSession):
QWidget(parent), transferList(transferList), main_window(main_window), BTSession(BTSession) {
setupUi(this);
state = VISIBLE;
setEnabled(false);
// Buttons stylesheet
trackers_button->setStyleSheet(DEFAULT_BUTTON_CSS);
peers_button->setStyleSheet(DEFAULT_BUTTON_CSS);
url_seeds_button->setStyleSheet(DEFAULT_BUTTON_CSS);
files_button->setStyleSheet(DEFAULT_BUTTON_CSS);
main_infos_button->setStyleSheet(DEFAULT_BUTTON_CSS);
main_infos_button->setShortcut(QKeySequence(QString::fromUtf8("Alt+P")));
// Set Properties list model
PropListModel = new TorrentFilesModel();
filesList->setModel(PropListModel);
PropDelegate = new PropListDelegate(this);
filesList->setItemDelegate(PropDelegate);
// SIGNAL/SLOTS
connect(filesList, SIGNAL(clicked(const QModelIndex&)), filesList, SLOT(edit(const QModelIndex&)));
connect(selectAllButton, SIGNAL(clicked()), this, SLOT(selectAllFiles()));
connect(selectNoneButton, SIGNAL(clicked()), this, SLOT(selectNoneFiles()));
connect(filesList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFilesListMenu(const QPoint&)));
connect(filesList, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(openDoubleClickedFile(QModelIndex)));
connect(PropListModel, SIGNAL(filteredFilesChanged()), this, SLOT(filteredFilesChanged()));
connect(addWS_button, SIGNAL(clicked()), this, SLOT(askWebSeed()));
connect(deleteWS_button, SIGNAL(clicked()), this, SLOT(deleteSelectedUrlSeeds()));
connect(transferList, SIGNAL(currentTorrentChanged(QTorrentHandle&)), this, SLOT(loadTorrentInfos(QTorrentHandle &)));
connect(PropDelegate, SIGNAL(filteredFilesChanged()), this, SLOT(filteredFilesChanged()));
connect(stackedProperties, SIGNAL(currentChanged(int)), this, SLOT(loadDynamicData()));
connect(BTSession, SIGNAL(savePathChanged(QTorrentHandle&)), this, SLOT(updateSavePath(QTorrentHandle&)));
connect(BTSession, SIGNAL(metadataReceived(QTorrentHandle&)), this, SLOT(updateTorrentInfos(QTorrentHandle&)));
// Downloaded pieces progress bar
downloaded_pieces = new DownloadedPiecesBar(this);
ProgressHLayout->insertWidget(1, downloaded_pieces);
// Pieces availability bar
pieces_availability = new PieceAvailabilityBar(this);
ProgressHLayout_2->insertWidget(1, pieces_availability);
// Tracker list
trackerList = new TrackerList(this);
#if LIBTORRENT_VERSION_MINOR > 14
trackerUpButton->setVisible(false);
trackerDownButton->setVisible(false);
#else
connect(trackerUpButton, SIGNAL(clicked()), trackerList, SLOT(moveSelectionUp()));
connect(trackerDownButton, SIGNAL(clicked()), trackerList, SLOT(moveSelectionDown()));
#endif
horizontalLayout_trackers->insertWidget(0, trackerList);
// Peers list
peersList = new PeerListWidget(this);
peerpage_layout->addWidget(peersList);
// Dynamic data refresher
refreshTimer = new QTimer(this);
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(loadDynamicData()));
refreshTimer->start(3000); // 3sec
}
PropertiesWidget::~PropertiesWidget() {
delete refreshTimer;
delete trackerList;
delete peersList;
delete downloaded_pieces;
delete pieces_availability;
delete PropListModel;
delete PropDelegate;
}
void PropertiesWidget::showPiecesAvailability(bool show) {
avail_pieces_lbl->setVisible(show);
pieces_availability->setVisible(show);
avail_average_lbl->setVisible(show);
if(show || (!show && !downloaded_pieces->isVisible()))
line_2->setVisible(show);
}
void PropertiesWidget::showPiecesDownloaded(bool show) {
downloaded_pieces_lbl->setVisible(show);
downloaded_pieces->setVisible(show);
progress_lbl->setVisible(show);
if(show || (!show && !pieces_availability->isVisible()))
line_2->setVisible(show);
}
void PropertiesWidget::reduce() {
if(state == VISIBLE) {
QSplitter *hSplitter = static_cast<QSplitter*>(parentWidget());
slideSizes = hSplitter->sizes();
stackedProperties->setVisible(false);
QList<int> sizes;
sizes << hSplitter->geometry().height()-30 << 30;
hSplitter->setSizes(sizes);
hSplitter->handle(1)->setVisible(false);
hSplitter->handle(1)->setDisabled(true);
state = REDUCED;
}
}
void PropertiesWidget::slide() {
if(state == REDUCED) {
stackedProperties->setVisible(true);
QSplitter *hSplitter = static_cast<QSplitter*>(parentWidget());
hSplitter->handle(1)->setDisabled(false);
hSplitter->handle(1)->setVisible(true);
hSplitter->setSizes(slideSizes);
state = VISIBLE;
// Force refresh
loadDynamicData();
}
}
void PropertiesWidget::clear() {
qDebug("Clearing torrent properties");
save_path->clear();
lbl_creationDate->clear();
hash_lbl->clear();
comment_text->clear();
progress_lbl->clear();
trackerList->clear();
downloaded_pieces->clear();
pieces_availability->clear();
avail_average_lbl->clear();
wasted->clear();
upTotal->clear();
dlTotal->clear();
peersList->clear();
lbl_uplimit->clear();
lbl_dllimit->clear();
lbl_elapsed->clear();
lbl_connections->clear();
reannounce_lbl->clear();
shareRatio->clear();
listWebSeeds->clear();
PropListModel->clear();
showPiecesAvailability(false);
showPiecesDownloaded(false);
setEnabled(false);
}
QTorrentHandle PropertiesWidget::getCurrentTorrent() const {
return h;
}
QBtSession* PropertiesWidget::getBTSession() const {
return BTSession;
}
void PropertiesWidget::updateSavePath(QTorrentHandle& _h) {
if(h.is_valid() && h == _h) {
QString p;
if(h.has_metadata() && h.num_files() == 1) {
p = h.firstFileSavePath();
} else {
p = TorrentPersistentData::getSavePath(h.hash());
if(p.isEmpty())
p = h.save_path();
}
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
p = p.replace("/", "\\");
#endif
save_path->setText(p);
}
}
void PropertiesWidget::updateTorrentInfos(QTorrentHandle& _h) {
if(h.is_valid() && h == _h) {
loadTorrentInfos(h);
}
}
void PropertiesWidget::loadTorrentInfos(QTorrentHandle &_h) {
clear();
h = _h;
if(!h.is_valid()) {
clear();
return;
}
setEnabled(true);
try {
// Save path
updateSavePath(h);
changeSavePathButton->setEnabled(h.has_metadata());
// Creation date
lbl_creationDate->setText(h.creation_date());
// Hash
hash_lbl->setText(h.hash());
// Comment
comment_text->setHtml(h.comment());
// URL seeds
loadUrlSeeds();
// List files in torrent
PropListModel->clear();
PropListModel->setupModelData(h.get_torrent_info());
// Expand first item if possible
filesList->expand(PropListModel->index(0, 0));
} catch(invalid_handle e) {
}
// Load dynamic data
loadDynamicData();
}
void PropertiesWidget::readSettings() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QList<int> contentColsWidths = misc::intListfromStringList(settings.value(QString::fromUtf8("TorrentProperties/filesColsWidth")).toStringList());
if(contentColsWidths.empty()) {
filesList->header()->resizeSection(0, 300);
} else {
for(int i=0; i<contentColsWidths.size(); ++i) {
filesList->setColumnWidth(i, contentColsWidths.at(i));
}
}
// Restore splitter sizes
QStringList sizes_str = settings.value(QString::fromUtf8("TorrentProperties/SplitterSizes"), QString()).toString().split(",");
if(sizes_str.size() == 2) {
slideSizes << sizes_str.first().toInt();
slideSizes << sizes_str.last().toInt();
QSplitter *hSplitter = static_cast<QSplitter*>(parentWidget());
hSplitter->setSizes(slideSizes);
}
if(!settings.value("TorrentProperties/Visible", false).toBool()) {
reduce();
}
const int current_tab = settings.value("TorrentProperties/CurrentTab", MAIN_TAB).toInt();
stackedProperties->setCurrentIndex(current_tab);
if(state != REDUCED)
getButtonFromIndex(current_tab)->setStyleSheet(SELECTED_BUTTON_CSS);
}
void PropertiesWidget::saveSettings() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
settings.setValue("TorrentProperties/Visible", state==VISIBLE);
QStringList contentColsWidths;
for(int i=0; i<PropListModel->columnCount(); ++i) {
contentColsWidths << QString::number(filesList->columnWidth(i));
}
settings.setValue(QString::fromUtf8("TorrentProperties/filesColsWidth"), contentColsWidths);
// Splitter sizes
QSplitter *hSplitter = static_cast<QSplitter*>(parentWidget());
QList<int> sizes;
if(state == VISIBLE)
sizes = hSplitter->sizes();
else
sizes = slideSizes;
qDebug("Sizes: %d", sizes.size());
if(sizes.size() == 2) {
settings.setValue(QString::fromUtf8("TorrentProperties/SplitterSizes"), QVariant(QString::number(sizes.first())+','+QString::number(sizes.last())));
}
// Remember current tab
settings.setValue("TorrentProperties/CurrentTab", stackedProperties->currentIndex());
}
void PropertiesWidget::reloadPreferences() {
// Take program preferences into consideration
peersList->updatePeerHostNameResolutionState();
peersList->updatePeerCountryResolutionState();
}
void PropertiesWidget::loadDynamicData() {
// Refresh only if the torrent handle is valid and if visible
if(!h.is_valid() || main_window->getCurrentTabWidget() != transferList || state != VISIBLE) return;
try {
// Transfer infos
if(stackedProperties->currentIndex() == MAIN_TAB) {
wasted->setText(misc::friendlyUnit(h.total_failed_bytes()+h.total_redundant_bytes()));
upTotal->setText(misc::friendlyUnit(h.all_time_upload()) + " ("+misc::friendlyUnit(h.total_payload_upload())+" "+tr("this session")+")");
dlTotal->setText(misc::friendlyUnit(h.all_time_download()) + " ("+misc::friendlyUnit(h.total_payload_download())+" "+tr("this session")+")");
if(h.upload_limit() <= 0)
lbl_uplimit->setText(QString::fromUtf8(""));
else
lbl_uplimit->setText(misc::friendlyUnit(h.upload_limit())+tr("/s", "/second (i.e. per second)"));
if(h.download_limit() <= 0)
lbl_dllimit->setText(QString::fromUtf8(""));
else
lbl_dllimit->setText(misc::friendlyUnit(h.download_limit())+tr("/s", "/second (i.e. per second)"));
QString elapsed_txt = misc::userFriendlyDuration(h.active_time());
if(h.is_seed()) {
elapsed_txt += " ("+tr("Seeded for %1", "e.g. Seeded for 3m10s").arg(misc::userFriendlyDuration(h.seeding_time()))+")";
}
lbl_elapsed->setText(elapsed_txt);
if(h.connections_limit() > 0)
lbl_connections->setText(QString::number(h.num_connections())+" ("+tr("%1 max", "e.g. 10 max").arg(QString::number(h.connections_limit()))+")");
else
lbl_connections->setText(QString::number(h.num_connections()));
// Update next announce time
reannounce_lbl->setText(h.next_announce());
// Update ratio info
const double ratio = BTSession->getRealRatio(h.hash());
if(ratio > 100.)
shareRatio->setText(QString::fromUtf8(""));
else
shareRatio->setText(QString(QByteArray::number(ratio, 'f', 2)));
if(!h.is_seed()) {
showPiecesDownloaded(true);
// Downloaded pieces
bitfield bf(h.get_torrent_info().num_pieces(), 0);
h.downloading_pieces(bf);
downloaded_pieces->setProgress(h.pieces(), bf);
// Pieces availability
if(h.has_metadata() && !h.is_paused() && !h.is_queued() && !h.is_checking()) {
showPiecesAvailability(true);
std::vector<int> avail;
h.piece_availability(avail);
pieces_availability->setAvailability(avail);
avail_average_lbl->setText(QString::number(h.status().distributed_copies, 'f', 1));
} else {
showPiecesAvailability(false);
}
// Progress
progress_lbl->setText(QString::number(h.progress()*100., 'f', 1)+"%");
} else {
showPiecesAvailability(false);
showPiecesDownloaded(false);
}
return;
}
if(stackedProperties->currentIndex() == TRACKERS_TAB) {
// Trackers
trackerList->loadTrackers();
return;
}
if(stackedProperties->currentIndex() == PEERS_TAB) {
// Load peers
peersList->loadPeers(h);
return;
}
if(stackedProperties->currentIndex() == FILES_TAB) {
// Files progress
if(h.is_valid() && h.has_metadata()) {
if(PropListModel->rowCount() == 0) {
PropListModel->setupModelData(h.get_torrent_info());
// Expand first item if possible
filesList->expand(PropListModel->index(0, 0));
}
qDebug("Updating priorities in files tab");
std::vector<size_type> fp;
h.file_progress(fp);
PropListModel->updateFilesPriorities(h.file_priorities());
PropListModel->updateFilesProgress(fp);
}
}
} catch(invalid_handle e) {}
}
void PropertiesWidget::selectAllFiles() {
// Update torrent properties
std::vector<int> prio = h.file_priorities();
for(std::vector<int>::iterator it = prio.begin(); it != prio.end(); it++) {
if(*it == IGNORED) {
*it = NORMAL;
}
}
h.prioritize_files(prio);
// Update model
PropListModel->selectAll();
}
void PropertiesWidget::selectNoneFiles() {
// Update torrent properties
std::vector<int> prio;
prio.assign(h.num_files(), IGNORED);
h.prioritize_files(prio);
// Update model
PropListModel->selectNone();
}
void PropertiesWidget::loadUrlSeeds(){
listWebSeeds->clear();
qDebug("Loading URL seeds");
const QStringList hc_seeds = h.url_seeds();
// Add url seeds
foreach(const QString &hc_seed, hc_seeds){
qDebug("Loading URL seed: %s", qPrintable(hc_seed));
new QListWidgetItem(hc_seed, listWebSeeds);
}
}
/* Tab buttons */
QPushButton* PropertiesWidget::getButtonFromIndex(int index) {
switch(index) {
case TRACKERS_TAB:
return trackers_button;
case PEERS_TAB:
return peers_button;
case URLSEEDS_TAB:
return url_seeds_button;
case FILES_TAB:
return files_button;
default:
return main_infos_button;
}
}
void PropertiesWidget::on_main_infos_button_clicked() {
if(state == VISIBLE && stackedProperties->currentIndex() == MAIN_TAB) {
reduce();
main_infos_button->setStyleSheet(DEFAULT_BUTTON_CSS);
} else {
slide();
getButtonFromIndex(stackedProperties->currentIndex())->setStyleSheet(DEFAULT_BUTTON_CSS);
stackedProperties->setCurrentIndex(MAIN_TAB);
main_infos_button->setStyleSheet(SELECTED_BUTTON_CSS);
}
}
void PropertiesWidget::on_trackers_button_clicked() {
if(state == VISIBLE && stackedProperties->currentIndex() == TRACKERS_TAB) {
reduce();
} else {
trackers_button->setStyleSheet(DEFAULT_BUTTON_CSS);
slide();
getButtonFromIndex(stackedProperties->currentIndex())->setStyleSheet(DEFAULT_BUTTON_CSS);
stackedProperties->setCurrentIndex(TRACKERS_TAB);
trackers_button->setStyleSheet(SELECTED_BUTTON_CSS);
}
}
void PropertiesWidget::on_peers_button_clicked() {
if(state == VISIBLE && stackedProperties->currentIndex() == PEERS_TAB) {
reduce();
peers_button->setStyleSheet(DEFAULT_BUTTON_CSS);
} else {
slide();
getButtonFromIndex(stackedProperties->currentIndex())->setStyleSheet(DEFAULT_BUTTON_CSS);
stackedProperties->setCurrentIndex(PEERS_TAB);
peers_button->setStyleSheet(SELECTED_BUTTON_CSS);
}
}
void PropertiesWidget::on_url_seeds_button_clicked() {
if(state == VISIBLE && stackedProperties->currentIndex() == URLSEEDS_TAB) {
reduce();
url_seeds_button->setStyleSheet(DEFAULT_BUTTON_CSS);
} else {
slide();
getButtonFromIndex(stackedProperties->currentIndex())->setStyleSheet(DEFAULT_BUTTON_CSS);
stackedProperties->setCurrentIndex(URLSEEDS_TAB);
url_seeds_button->setStyleSheet(SELECTED_BUTTON_CSS);
}
}
void PropertiesWidget::on_files_button_clicked() {
if(state == VISIBLE && stackedProperties->currentIndex() == FILES_TAB) {
reduce();
files_button->setStyleSheet(DEFAULT_BUTTON_CSS);
} else {
slide();
getButtonFromIndex(stackedProperties->currentIndex())->setStyleSheet(DEFAULT_BUTTON_CSS);
stackedProperties->setCurrentIndex(FILES_TAB);
files_button->setStyleSheet(SELECTED_BUTTON_CSS);
}
}
void PropertiesWidget::openDoubleClickedFile(QModelIndex index) {
if(!index.isValid()) return;
if(!h.is_valid() || !h.has_metadata()) return;
if(PropListModel->getType(index) == TFILE) {
int i = PropListModel->getFileIndex(index);
const QDir saveDir(h.save_path());
const QString filename = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename));
qDebug("Trying to open file at %s", qPrintable(file_path));
#if LIBTORRENT_VERSION_MINOR > 14
// Flush data
h.flush_cache();
#endif
if(QFile::exists(file_path)) {
#ifdef Q_WS_WIN
QDesktopServices::openUrl(QUrl("file:///"+file_path));
#else
QDesktopServices::openUrl(QUrl("file://"+file_path));
#endif
} else {
QMessageBox::warning(this, tr("I/O Error"), tr("This file does not exist yet."));
}
} else {
// FOLDER
QStringList path_items;
path_items << index.data().toString();
QModelIndex parent = PropListModel->parent(index);
while(parent.isValid()) {
path_items.prepend(parent.data().toString());
parent = PropListModel->parent(parent);
}
const QDir saveDir(h.save_path());
const QString filename = path_items.join(QDir::separator());
const QString file_path = QDir::cleanPath(saveDir.absoluteFilePath(filename));
qDebug("Trying to open folder at %s", qPrintable(file_path));
#if LIBTORRENT_VERSION_MINOR > 14
// Flush data
h.flush_cache();
#endif
if(QFile::exists(file_path)) {
#ifdef Q_WS_WIN
QDesktopServices::openUrl(QUrl("file:///"+file_path));
#else
QDesktopServices::openUrl(QUrl("file://"+file_path));
#endif
} else {
QMessageBox::warning(this, tr("I/O Error"), tr("This folder does not exist yet."));
}
}
}
void PropertiesWidget::displayFilesListMenu(const QPoint&){
QMenu myFilesLlistMenu;
QModelIndexList selectedRows = filesList->selectionModel()->selectedRows(0);
QAction *actRename = 0;
if(selectedRows.size() == 1) {
actRename = myFilesLlistMenu.addAction(QIcon(QString::fromUtf8(":/Icons/oxygen/edit_clear.png")), tr("Rename..."));
myFilesLlistMenu.addSeparator();
}
QMenu subMenu;
subMenu.setTitle(tr("Priority"));
subMenu.addAction(actionNot_downloaded);
subMenu.addAction(actionNormal);
subMenu.addAction(actionHigh);
subMenu.addAction(actionMaximum);
myFilesLlistMenu.addMenu(&subMenu);
// Call menu
const QAction *act = myFilesLlistMenu.exec(QCursor::pos());
if(act) {
if(act == actRename) {
renameSelectedFile();
} else {
int prio = 1;
if(act == actionHigh) {
prio = HIGH;
} else {
if(act == actionMaximum) {
prio = MAXIMUM;
} else {
if(act == actionNot_downloaded) {
prio = IGNORED;
}
}
}
qDebug("Setting files priority");
foreach(QModelIndex index, selectedRows) {
qDebug("Setting priority(%d) for file at row %d", prio, index.row());
PropListModel->setData(PropListModel->index(index.row(), PRIORITY, index.parent()), prio);
}
// Save changes
filteredFilesChanged();
}
}
}
void PropertiesWidget::renameSelectedFile() {
const QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(0);
Q_ASSERT(selectedIndexes.size() == 1);
const QModelIndex index = selectedIndexes.first();
// Ask for new name
bool ok;
QString new_name_last = QInputDialog::getText(this, tr("Rename the file"),
tr("New name:"), QLineEdit::Normal,
index.data().toString(), &ok);
if (ok && !new_name_last.isEmpty()) {
if(!misc::isValidFileSystemName(new_name_last)) {
QMessageBox::warning(this, tr("The file could not be renamed"),
tr("This file name contains forbidden characters, please choose a different one."),
QMessageBox::Ok);
return;
}
if(PropListModel->getType(index)==TFILE) {
// File renaming
const int file_index = PropListModel->getFileIndex(index);
if(!h.is_valid() || !h.has_metadata()) return;
QString old_name = misc::toQStringU(h.get_torrent_info().file_at(file_index).path.string());
old_name = old_name.replace("\\", "/");
if(old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB")) {
new_name_last += ".!qB";
}
QStringList path_items = old_name.split("/");
path_items.removeLast();
path_items << new_name_last;
QString new_name = path_items.join("/");
if(old_name == new_name) {
qDebug("Name did not change");
return;
}
new_name = QDir::cleanPath(new_name);
// Check if that name is already used
for(int i=0; i<h.num_files(); ++i) {
if(i == file_index) continue;
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if(misc::toQStringU(h.get_torrent_info().file_at(i).path.string()).compare(new_name, Qt::CaseSensitive) == 0) {
#else
if(misc::toQStringU(h.get_torrent_info().file_at(i).path.string()).compare(new_name, Qt::CaseInsensitive) == 0) {
#endif
// Display error message
QMessageBox::warning(this, tr("The file could not be renamed"),
tr("This name is already in use in this folder. Please use a different name."),
QMessageBox::Ok);
return;
}
}
const bool force_recheck = QFile::exists(h.save_path()+QDir::separator()+new_name);
qDebug("Renaming %s to %s", qPrintable(old_name), qPrintable(new_name));
h.rename_file(file_index, new_name);
// Force recheck
if(force_recheck) h.force_recheck();
// Rename if torrent files model too
if(new_name_last.endsWith(".!qB"))
new_name_last.chop(4);
PropListModel->setData(index, new_name_last);
} else {
// Folder renaming
QStringList path_items;
path_items << index.data().toString();
QModelIndex parent = PropListModel->parent(index);
while(parent.isValid()) {
path_items.prepend(parent.data().toString());
parent = PropListModel->parent(parent);
}
const QString old_path = path_items.join("/");
path_items.removeLast();
path_items << new_name_last;
QString new_path = path_items.join("/");
if(!new_path.endsWith("/")) new_path += "/";
// Check for overwriting
const int num_files = h.num_files();
for(int i=0; i<num_files; ++i) {
const QString current_name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if(current_name.startsWith(new_path, Qt::CaseSensitive)) {
#else
if(current_name.startsWith(new_path, Qt::CaseInsensitive)) {
#endif
QMessageBox::warning(this, tr("The folder could not be renamed"),
tr("This name is already in use in this folder. Please use a different name."),
QMessageBox::Ok);
return;
}
}
bool force_recheck = false;
// Replace path in all files
for(int i=0; i<num_files; ++i) {
const QString current_name = misc::toQStringU(h.get_torrent_info().file_at(i).path.string());
if(current_name.startsWith(old_path)) {
QString new_name = current_name;
new_name.replace(0, old_path.length(), new_path);
if(!force_recheck && QDir(h.save_path()).exists(new_name))
force_recheck = true;
new_name = QDir::cleanPath(new_name);
qDebug("Rename %s to %s", qPrintable(current_name), qPrintable(new_name));
h.rename_file(i, new_name);
}
}
// Force recheck
if(force_recheck) h.force_recheck();
// Rename folder in torrent files model too
PropListModel->setData(index, new_name_last);
// Remove old folder
const QDir old_folder(h.save_path()+"/"+old_path);
int timeout = 10;
while(!misc::removeEmptyTree(old_folder.absolutePath()) && timeout > 0) {
SleeperThread::msleep(100);
--timeout;
}
}
}
}
void PropertiesWidget::askWebSeed(){
bool ok;
// Ask user for a new url seed
const QString url_seed = QInputDialog::getText(this, tr("New url seed", "New HTTP source"),
tr("New url seed:"), QLineEdit::Normal,
QString::fromUtf8("http://www."), &ok);
if(!ok) return;
qDebug("Adding %s web seed", qPrintable(url_seed));
if(!listWebSeeds->findItems(url_seed, Qt::MatchFixedString).empty()) {
QMessageBox::warning(this, tr("qBittorrent"),
tr("This url seed is already in the list."),
QMessageBox::Ok);
return;
}
h.add_url_seed(url_seed);
// Refresh the seeds list
loadUrlSeeds();
}
void PropertiesWidget::deleteSelectedUrlSeeds(){
const QList<QListWidgetItem *> selectedItems = listWebSeeds->selectedItems();
bool change = false;
foreach(const QListWidgetItem *item, selectedItems){
QString url_seed = item->text();
h.remove_url_seed(url_seed);
change = true;
}
if(change){
// Refresh list
loadUrlSeeds();
}
}
bool PropertiesWidget::applyPriorities() {
qDebug("Saving pieces priorities");
const std::vector<int> priorities = PropListModel->getFilesPriorities(h.get_torrent_info().num_files());
bool first_last_piece_first = false;
// Save first/last piece first option state
if(h.first_last_piece_first())
first_last_piece_first = true;
// Prioritize the files
qDebug("prioritize files: %d", priorities[0]);
h.prioritize_files(priorities);
// Restore first/last piece first option if necessary
if(first_last_piece_first)
h.prioritize_first_last_piece(true);
return true;
}
void PropertiesWidget::on_changeSavePathButton_clicked() {
if(!h.is_valid()) return;
QString new_path;
if(h.has_metadata() && h.num_files() == 1) {
new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), h.firstFileSavePath());
} else {
const QDir saveDir(TorrentPersistentData::getSavePath(h.hash()));
QFileDialog dlg(this, tr("Choose save path"), saveDir.absolutePath());
dlg.setConfirmOverwrite(false);
dlg.setFileMode(QFileDialog::Directory);
dlg.setOption(QFileDialog::ShowDirsOnly, true);
dlg.setFilter(QDir::AllDirs);
dlg.setAcceptMode(QFileDialog::AcceptSave);
dlg.setNameFilterDetailsVisible(false);
if(dlg.exec())
new_path = dlg.selectedFiles().first();
}
if(!new_path.isEmpty()){
// Check if savePath exists
QString save_path_dir = new_path.replace("\\", "/");
QString new_file_name;
if(h.has_metadata() && h.num_files() == 1) {
QStringList parts = save_path_dir.split("/");
new_file_name = parts.takeLast(); // Skip file name
save_path_dir = parts.join("/");
}
QDir savePath(misc::expandPath(save_path_dir));
// Actually move storage
if(!BTSession->useTemporaryFolder() || h.is_seed()) {
if(!savePath.exists()) savePath.mkpath(savePath.absolutePath());
h.move_storage(savePath.absolutePath());
}
// Update save_path in dialog
QString display_path;
if(h.has_metadata() && h.num_files() == 1) {
// Rename the file
Q_ASSERT(!new_file_name.isEmpty());
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
if(h.file_at(0).compare(new_file_name, Qt::CaseInsensitive) != 0) {
#else
if(h.file_at(0).compare(new_file_name, Qt::CaseSensitive) != 0) {
#endif
qDebug("Renaming single file to %s", qPrintable(new_file_name));
h.rename_file(0, new_file_name);
// Also rename it in the files list model
PropListModel->setData(PropListModel->index(0, 0), new_file_name);
}
display_path = h.firstFileSavePath();
} else {
display_path = savePath.absolutePath();
}
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
display_path = display_path.replace("/", "\\");
#endif
save_path->setText(display_path);
}
}
void PropertiesWidget::filteredFilesChanged() {
if(h.is_valid()) {
applyPriorities();
}
}

View File

@@ -0,0 +1,119 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef PROPERTIESWIDGET_H
#define PROPERTIESWIDGET_H
#include <QWidget>
#include "ui_propertieswidget.h"
#include "qtorrenthandle.h"
class TransferListWidget;
class QTimer;
class QBtSession;
class TorrentFilesModel;
class PropListDelegate;
class QAction;
class torrent_file;
class PeerListWidget;
class TrackerList;
class GUI;
class DownloadedPiecesBar;
class PieceAvailabilityBar;
enum Tab {MAIN_TAB, TRACKERS_TAB, PEERS_TAB, URLSEEDS_TAB, FILES_TAB};
enum SlideState {REDUCED, VISIBLE};
class PropertiesWidget : public QWidget, private Ui::PropertiesWidget {
Q_OBJECT
private:
TransferListWidget *transferList;
GUI *main_window;
QTorrentHandle h;
QTimer *refreshTimer;
QBtSession* BTSession;
SlideState state;
TorrentFilesModel *PropListModel;
PropListDelegate *PropDelegate;
PeerListWidget *peersList;
TrackerList *trackerList;
QList<int> slideSizes;
DownloadedPiecesBar *downloaded_pieces;
PieceAvailabilityBar *pieces_availability;
public:
PropertiesWidget(QWidget *parent, GUI* main_window, TransferListWidget *transferList, QBtSession* BTSession);
~PropertiesWidget();
QTorrentHandle getCurrentTorrent() const;
QBtSession* getBTSession() const;
TrackerList* getTrackerList() const { return trackerList; }
PeerListWidget* getPeerList() const { return peersList; }
QTreeView* getFilesList() const { return filesList; }
protected:
QPushButton* getButtonFromIndex(int index);
bool applyPriorities();
protected slots:
void loadTorrentInfos(QTorrentHandle &h);
void updateTorrentInfos(QTorrentHandle &h);
void loadUrlSeeds();
void on_main_infos_button_clicked();
void on_trackers_button_clicked();
void on_peers_button_clicked();
void on_url_seeds_button_clicked();
void on_files_button_clicked();
void askWebSeed();
void deleteSelectedUrlSeeds();
void displayFilesListMenu(const QPoint& pos);
void on_changeSavePathButton_clicked();
void filteredFilesChanged();
void showPiecesDownloaded(bool show);
void showPiecesAvailability(bool show);
void renameSelectedFile();
void selectAllFiles();
void selectNoneFiles();
public slots:
void loadDynamicData();
void reduce();
void slide();
void clear();
void readSettings();
void saveSettings();
void reloadPreferences();
void openDoubleClickedFile(QModelIndex);
void updateSavePath(QTorrentHandle& h);
};
#endif // PROPERTIESWIDGET_H

View File

@@ -0,0 +1,949 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PropertiesWidget</class>
<widget class="QWidget" name="PropertiesWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>540</width>
<height>329</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="windowTitle">
<string notr="true">Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QStackedWidget" name="stackedProperties">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_7">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>522</width>
<height>351</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="ProgressHLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QLabel" name="downloaded_pieces_lbl">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Downloaded:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="progress_lbl">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string notr="true">0.0%</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="ProgressHLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QLabel" name="avail_pieces_lbl">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Availability:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="avail_average_lbl">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string notr="true">0.0</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Transfer</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Uploaded:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="upTotal">
<property name="text">
<string notr="true">0 Kb</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label">
<property name="text">
<string>UP limit:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="lbl_uplimit">
<property name="text">
<string notr="true">∞</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QLabel" name="lbl_ratio">
<property name="text">
<string>Share ratio:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="6">
<widget class="QLabel" name="shareRatio">
<property name="text">
<string notr="true">1.0</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Downloaded:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="dlTotal">
<property name="text">
<string notr="true">0 Kb</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>DL limit:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="lbl_dllimit">
<property name="text">
<string notr="true">∞</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Connections:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="6">
<widget class="QLabel" name="lbl_connections">
<property name="text">
<string notr="true">0</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Wasted:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="wasted">
<property name="text">
<string notr="true">0 kb</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Time elapsed:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLabel" name="lbl_elapsed">
<property name="text">
<string notr="true">∞</string>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Reannounce in:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="6">
<widget class="QLabel" name="reannounce_lbl">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupTorrentInfos">
<property name="title">
<string>Information</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="savePath_lbl">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Save path:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="save_path">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">path</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="changeSavePathButton">
<property name="maximumSize">
<size>
<width>22</width>
<height>15</height>
</size>
</property>
<property name="text">
<string notr="true">...</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>14</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Created on:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="lbl_creationDate">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">date</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>14</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="hash_lbl2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Torrent hash:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="hash_lbl">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">hash</string>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>14</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="comment_lbl2">
<property name="text">
<string>Comment:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QTextBrowser" name="comment_text">
<property name="html">
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:8pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="openLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_trackers">
<layout class="QHBoxLayout" name="horizontalLayout_trackers">
<item>
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="trackerUpButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>31</horstretch>
<verstretch>27</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>31</width>
<height>27</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>31</width>
<height>27</height>
</size>
</property>
<property name="text">
<string notr="true"/>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/uparrow.png</normaloff>:/Icons/uparrow.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>28</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="trackerDownButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>31</horstretch>
<verstretch>27</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>31</width>
<height>27</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>31</width>
<height>27</height>
</size>
</property>
<property name="text">
<string notr="true"/>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/downarrow.png</normaloff>:/Icons/downarrow.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_5">
<layout class="QVBoxLayout" name="peerpage_layout"/>
</widget>
<widget class="QWidget" name="page_3">
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QListWidget" name="listWebSeeds"/>
</item>
<item>
<layout class="QHBoxLayout" name="_19">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="deleteWS_button">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/oxygen/list-remove.png</normaloff>:/Icons/oxygen/list-remove.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="addWS_button">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/oxygen/list-add.png</normaloff>:/Icons/oxygen/list-add.png</iconset>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_4">
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QTreeView" name="filesList">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::AllEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="allColumnsShowFocus">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="_6">
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="selectAllButton">
<property name="text">
<string>Select All</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="selectNoneButton">
<property name="text">
<string>Select None</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QPushButton" name="main_infos_button">
<property name="text">
<string>General</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/oxygen/help-about.png</normaloff>:/Icons/oxygen/help-about.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="trackers_button">
<property name="text">
<string>Trackers</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/oxygen/network-server.png</normaloff>:/Icons/oxygen/network-server.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="peers_button">
<property name="minimumSize">
<size>
<width>0</width>
<height>24</height>
</size>
</property>
<property name="text">
<string>Peers</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/oxygen/peer.png</normaloff>:/Icons/oxygen/peer.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="url_seeds_button">
<property name="text">
<string>URL seeds</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/oxygen/urlseed.png</normaloff>:/Icons/oxygen/urlseed.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="files_button">
<property name="text">
<string>Files</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/Icons/oxygen/folder.png</normaloff>:/Icons/oxygen/folder.png</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
<action name="actionNormal">
<property name="text">
<string>Normal</string>
</property>
</action>
<action name="actionHigh">
<property name="text">
<string>High</string>
</property>
</action>
<action name="actionMaximum">
<property name="text">
<string>Maximum</string>
</property>
</action>
<action name="actionNot_downloaded">
<property name="text">
<string>Do not download</string>
</property>
<property name="toolTip">
<string>Do not download</string>
</property>
</action>
</widget>
<resources>
<include location="../icons.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -0,0 +1,191 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef PROPLISTDELEGATE_H
#define PROPLISTDELEGATE_H
#include <QItemDelegate>
#include <QStyleOptionProgressBarV2>
#include <QStyleOptionViewItemV2>
#include <QStyleOptionComboBox>
#include <QComboBox>
#include <QModelIndex>
#include <QPainter>
#include <QProgressBar>
#include <QApplication>
#include "misc.h"
#include "propertieswidget.h"
#ifdef Q_WS_WIN
#include <QPlastiqueStyle>
#endif
// Defines for properties list columns
enum PropColumn {NAME, PCSIZE, PROGRESS, PRIORITY};
class PropListDelegate: public QItemDelegate {
Q_OBJECT
private:
PropertiesWidget *properties;
signals:
void filteredFilesChanged() const;
public:
PropListDelegate(PropertiesWidget* properties=0, QObject *parent=0) : QItemDelegate(parent), properties(properties){
}
~PropListDelegate(){}
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{
painter->save();
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
switch(index.column()){
case PCSIZE:
QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, option.rect, misc::friendlyUnit(index.data().toLongLong()));
break;
case PROGRESS:{
QStyleOptionProgressBarV2 newopt;
float progress = index.data().toDouble()*100.;
newopt.rect = opt.rect;
newopt.text = QString(QByteArray::number(progress, 'f', 1))+QString::fromUtf8("%");
newopt.progress = (int)progress;
newopt.maximum = 100;
newopt.minimum = 0;
newopt.state |= QStyle::State_Enabled;
newopt.textVisible = true;
#ifndef Q_WS_WIN
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
#else
// XXX: To avoid having the progress text on the right of the bar
QPlastiqueStyle st;
st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0);
#endif
break;
}
case PRIORITY: {
QItemDelegate::drawBackground(painter, opt, index);
QString text = "";
switch(index.data().toInt()) {
case 0:
text = tr("Not downloaded");
break;
case 2:
text = tr("High", "High (priority)");
break;
case 7:
text = tr("Maximum", "Maximum (priority)");
break;
default:
text = tr("Normal", "Normal (priority)");
break;
}
QItemDelegate::drawDisplay(painter, opt, option.rect, text);
break;
}
default:
QItemDelegate::paint(painter, option, index);
break;
}
painter->restore();
}
QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const{
QVariant value = index.data(Qt::FontRole);
QFont fnt = value.isValid() ? qvariant_cast<QFont>(value) : option.font;
QFontMetrics fontMetrics(fnt);
const QString text = index.data(Qt::DisplayRole).toString();
QRect textRect = QRect(0, 0, 0, fontMetrics.lineSpacing() * (text.count(QLatin1Char('\n')) + 1));
textRect.setHeight(textRect.height()+4);
return textRect.size();
}
void setEditorData(QWidget *editor, const QModelIndex &index) const {
QComboBox *combobox = static_cast<QComboBox*>(editor);
// Set combobox index
switch(index.data().toInt()) {
case 2:
combobox->setCurrentIndex(1);
break;
case 7:
combobox->setCurrentIndex(2);
break;
default:
combobox->setCurrentIndex(0);
break;
}
}
QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &index) const {
if(index.column() != PRIORITY) return 0;
if(properties) {
QTorrentHandle h = properties->getCurrentTorrent();
if(!h.is_valid() || static_cast<torrent_handle>(h).is_seed() || !h.has_metadata()) return 0;
}
if(index.data().toInt() == 0) {
// IGNORED
return 0;
}
QComboBox* editor = new QComboBox(parent);
editor->setFocusPolicy(Qt::StrongFocus);
editor->addItem(tr("Normal", "Normal (priority)"));
editor->addItem(tr("High", "High (priority)"));
editor->addItem(tr("Maximum", "Maximum (priority)"));
return editor;
}
public slots:
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
QComboBox *combobox = static_cast<QComboBox*>(editor);
int value = combobox->currentIndex();
qDebug("PropListDelegate: setModelData(%d)", value);
switch(value) {
case 1:
model->setData(index, 2); // HIGH
break;
case 2:
model->setData(index, 7); // MAX
break;
default:
model->setData(index, 1); // NORMAL
}
emit filteredFilesChanged();
}
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const {
qDebug("UpdateEditor Geometry called");
editor->setGeometry(option.rect);
}
};
#endif

View File

@@ -0,0 +1,391 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#include <QTreeWidgetItem>
#include <QStringList>
#include <QMenu>
#include <QHash>
#include <QAction>
#include <QColor>
#include <libtorrent/version.hpp>
#include "trackerlist.h"
#include "propertieswidget.h"
#include "trackersadditiondlg.h"
#include "misc.h"
#include "qbtsession.h"
#include "qinisettings.h"
TrackerList::TrackerList(PropertiesWidget *properties): QTreeWidget(), properties(properties) {
// Graphical settings
setRootIsDecorated(false);
setAllColumnsShowFocus(true);
setItemsExpandable(false);
setSelectionMode(QAbstractItemView::ExtendedSelection);
// Context menu
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showTrackerListMenu(QPoint)));
// Set header
QStringList header;
header << tr("URL");
header << tr("Status");
header << tr("Peers");
header << tr("Message");
setHeaderItem(new QTreeWidgetItem(header));
dht_item = new QTreeWidgetItem(QStringList("** "+tr("[DHT]")+" **"));
insertTopLevelItem(0, dht_item);
setRowColor(0, QColor("grey"));
pex_item = new QTreeWidgetItem(QStringList("** "+tr("[PeX]")+" **"));
insertTopLevelItem(1, pex_item);
setRowColor(1, QColor("grey"));
lsd_item = new QTreeWidgetItem(QStringList("** "+tr("[LSD]")+" **"));
insertTopLevelItem(2, lsd_item);
setRowColor(2, QColor("grey"));
loadSettings();
}
TrackerList::~TrackerList() {
saveSettings();
}
QList<QTreeWidgetItem*> TrackerList::getSelectedTrackerItems() const {
QList<QTreeWidgetItem*> selected_items = selectedItems();
QList<QTreeWidgetItem*> selected_trackers;
foreach(QTreeWidgetItem *item, selectedItems()) {
if(indexOfTopLevelItem(item) >= NB_STICKY_ITEM) { // Ignore STICKY ITEMS
selected_trackers << item;
}
}
return selected_trackers;
}
void TrackerList::setRowColor(int row, QColor color) {
unsigned int nbColumns = columnCount();
QTreeWidgetItem *item = topLevelItem(row);
for(unsigned int i=0; i<nbColumns; ++i) {
item->setData(i, Qt::ForegroundRole, color);
}
}
void TrackerList::moveSelectionUp() {
#if LIBTORRENT_VERSION_MINOR < 15
QTorrentHandle h = properties->getCurrentTorrent();
if(!h.is_valid()) {
clear();
return;
}
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
if(selected_items.isEmpty()) return;
bool change = false;
foreach(QTreeWidgetItem *item, selected_items){
int index = indexOfTopLevelItem(item);
if(index > NB_STICKY_ITEM) {
insertTopLevelItem(index-1, takeTopLevelItem(index));
change = true;
}
}
if(!change) return;
// Restore selection
QItemSelectionModel *selection = selectionModel();
foreach(QTreeWidgetItem *item, selected_items) {
selection->select(indexFromItem(item), QItemSelectionModel::Rows|QItemSelectionModel::Select);
}
setSelectionModel(selection);
// Update torrent trackers
std::vector<announce_entry> trackers;
for(int i=NB_STICKY_ITEM; i<topLevelItemCount(); ++i) {
QString tracker_url = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString();
announce_entry e(tracker_url.toStdString());
e.tier = i-NB_STICKY_ITEM;
trackers.push_back(e);
}
h.replace_trackers(trackers);
// Reannounce
h.force_reannounce();
#endif
}
void TrackerList::moveSelectionDown() {
#if LIBTORRENT_VERSION_MINOR < 15
QTorrentHandle h = properties->getCurrentTorrent();
if(!h.is_valid()) {
clear();
return;
}
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
if(selected_items.isEmpty()) return;
bool change = false;
for(int i=selectedItems().size()-1; i>= 0; --i) {
int index = indexOfTopLevelItem(selected_items.at(i));
if(index < topLevelItemCount()-1) {
insertTopLevelItem(index+1, takeTopLevelItem(index));
change = true;
}
}
if(!change) return;
// Restore selection
QItemSelectionModel *selection = selectionModel();
foreach(QTreeWidgetItem *item, selected_items) {
selection->select(indexFromItem(item), QItemSelectionModel::Rows|QItemSelectionModel::Select);
}
setSelectionModel(selection);
// Update torrent trackers
std::vector<announce_entry> trackers;
for(int i=NB_STICKY_ITEM; i<topLevelItemCount(); ++i) {
QString tracker_url = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString();
announce_entry e(tracker_url.toStdString());
e.tier = i-NB_STICKY_ITEM;
trackers.push_back(e);
}
h.replace_trackers(trackers);
// Reannounce
h.force_reannounce();
#endif
}
void TrackerList::clear() {
qDeleteAll(tracker_items.values());
tracker_items.clear();
dht_item->setText(COL_PEERS, "");
dht_item->setText(COL_STATUS, "");
dht_item->setText(COL_MSG, "");
pex_item->setText(COL_PEERS, "");
pex_item->setText(COL_STATUS, "");
pex_item->setText(COL_MSG, "");
lsd_item->setText(COL_PEERS, "");
lsd_item->setText(COL_STATUS, "");
lsd_item->setText(COL_MSG, "");
}
void TrackerList::loadStickyItems(const QTorrentHandle &h) {
// XXX: libtorrent should provide this info...
// Count peers from DHT, LSD, PeX
uint nb_dht=0, nb_lsd=0, nb_pex=0;
std::vector<peer_info> peers;
h.get_peer_info(peers);
std::vector<peer_info>::iterator it;
for(it=peers.begin(); it!=peers.end(); it++) {
if(it->source & peer_info::dht)
++nb_dht;
if(it->source & peer_info::lsd)
++nb_lsd;
if(it->source & peer_info::pex)
++nb_pex;
}
// load DHT information
if(properties->getBTSession()->isDHTEnabled() && h.has_metadata() && !h.priv()) {
dht_item->setText(COL_STATUS, tr("Working"));
} else {
dht_item->setText(COL_STATUS, tr("Disabled"));
}
dht_item->setText(COL_PEERS, QString::number(nb_dht));
if(h.has_metadata() && h.priv()) {
dht_item->setText(COL_MSG, tr("This torrent is private"));
}
// Load PeX Information
if(properties->getBTSession()->isPexEnabled())
pex_item->setText(COL_STATUS, tr("Working"));
else
pex_item->setText(COL_STATUS, tr("Disabled"));
pex_item->setText(COL_PEERS, QString::number(nb_pex));
// Load LSD Information
if(properties->getBTSession()->isLSDEnabled())
lsd_item->setText(COL_STATUS, tr("Working"));
else
lsd_item->setText(COL_STATUS, tr("Disabled"));
lsd_item->setText(COL_PEERS, QString::number(nb_lsd));
}
void TrackerList::loadTrackers() {
// Load trackers from torrent handle
QTorrentHandle h = properties->getCurrentTorrent();
if(!h.is_valid()) return;
loadStickyItems(h);
// Load actual trackers information
QHash<QString, TrackerInfos> trackers_data = properties->getBTSession()->getTrackersInfo(h.hash());
QStringList old_trackers_urls = tracker_items.keys();
const std::vector<announce_entry> trackers = h.trackers();
for(std::vector<announce_entry>::const_iterator it = trackers.begin(); it != trackers.end(); it++) {
QString tracker_url = misc::toQString(it->url);
QTreeWidgetItem *item = tracker_items.value(tracker_url, 0);
if(!item) {
item = new QTreeWidgetItem();
item->setText(COL_URL, tracker_url);
addTopLevelItem(item);
tracker_items[tracker_url] = item;
} else {
old_trackers_urls.removeOne(tracker_url);
}
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
QString error_message = data.last_message.trimmed();
#if LIBTORRENT_VERSION_MINOR > 14
if(it->verified) {
item->setText(COL_STATUS, tr("Working"));
item->setText(COL_MSG, "");
} else {
if(it->updating && it->fails == 0) {
item->setText(COL_STATUS, tr("Updating..."));
item->setText(COL_MSG, "");
} else {
if(it->fails > 0) {
item->setText(COL_STATUS, tr("Not working"));
item->setText(COL_MSG, error_message);
} else {
item->setText(COL_STATUS, tr("Not contacted yet"));
item->setText(COL_MSG, "");
}
}
}
#else
if(data.verified) {
item->setText(COL_STATUS, tr("Working"));
item->setText(COL_MSG, "");
} else {
if(data.fail_count > 0) {
item->setText(COL_STATUS, tr("Not working"));
item->setText(COL_MSG, error_message);
} else {
item->setText(COL_STATUS, tr("Not contacted yet"));
item->setText(COL_MSG, "");
}
}
#endif
item->setText(COL_PEERS, QString::number(trackers_data.value(tracker_url, TrackerInfos(tracker_url)).num_peers));
}
// Remove old trackers
foreach(const QString &tracker, old_trackers_urls) {
delete tracker_items.take(tracker);
}
}
// Ask the user for new trackers and add them to the torrent
void TrackerList::askForTrackers(){
QTorrentHandle h = properties->getCurrentTorrent();
if(!h.is_valid()) return;
QStringList trackers = TrackersAdditionDlg::askForTrackers(h);
if(!trackers.empty()) {
foreach(const QString& tracker, trackers) {
announce_entry url(tracker.toStdString());
url.tier = 0;
h.add_tracker(url);
}
// Reannounce to new trackers
h.force_reannounce();
// Reload tracker list
loadTrackers();
// XXX: I don't think this is necessary now
//BTSession->saveTrackerFile(h.hash());
}
}
void TrackerList::deleteSelectedTrackers(){
QTorrentHandle h = properties->getCurrentTorrent();
if(!h.is_valid()) {
clear();
return;
}
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
if(selected_items.isEmpty()) return;
QStringList urls_to_remove;
foreach(QTreeWidgetItem *item, selected_items){
QString tracker_url = item->data(COL_URL, Qt::DisplayRole).toString();
urls_to_remove << tracker_url;
tracker_items.remove(tracker_url);
delete item;
}
// Iterate of trackers and remove selected ones
std::vector<announce_entry> trackers = h.trackers();
std::vector<announce_entry>::iterator it = trackers.begin();
while(it != trackers.end()) {
int index = urls_to_remove.indexOf(misc::toQString((*it).url));
if(index >= 0) {
trackers.erase(it);
urls_to_remove.removeAt(index);
} else {
it++;
}
}
h.replace_trackers(trackers);
h.force_reannounce();
// Reload Trackers
loadTrackers();
//XXX: I don't think this is necessary
//BTSession->saveTrackerFile(h.hash());
}
void TrackerList::showTrackerListMenu(QPoint) {
QTorrentHandle h = properties->getCurrentTorrent();
if(!h.is_valid() || !h.has_metadata()) return;
//QList<QTreeWidgetItem*> selected_items = getSelectedTrackerItems();
QMenu menu;
// Add actions
QAction *addAct = menu.addAction(QIcon(":/Icons/oxygen/list-add.png"), tr("Add a new tracker..."));
QAction *delAct = 0;
if(!getSelectedTrackerItems().isEmpty()) {
delAct = menu.addAction(QIcon(":/Icons/oxygen/list-remove.png"), tr("Remove tracker"));
}
menu.addSeparator();
QAction *reannounceAct = menu.addAction(QIcon(":/Icons/oxygen/run-build.png"), tr("Force reannounce"));
QAction *act = menu.exec(QCursor::pos());
if(act == 0) return;
if(act == addAct) {
askForTrackers();
return;
}
if(act == delAct) {
deleteSelectedTrackers();
return;
}
if(act == reannounceAct) {
properties->getCurrentTorrent().force_reannounce();
return;
}
}
void TrackerList::loadSettings() {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QList<int> contentColsWidths = misc::intListfromStringList(settings.value(QString::fromUtf8("TorrentProperties/Trackers/trackersColsWidth")).toStringList());
if(!contentColsWidths.empty()) {
for(int i=0; i<contentColsWidths.size(); ++i) {
setColumnWidth(i, contentColsWidths.at(i));
}
} else {
setColumnWidth(0, 300);
}
}
void TrackerList::saveSettings() const {
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QStringList contentColsWidths;
for(int i=0; i<columnCount(); ++i) {
contentColsWidths << QString::number(columnWidth(i));
}
settings.setValue(QString::fromUtf8("TorrentProperties/Trackers/trackersColsWidth"), contentColsWidths);
}

View File

@@ -0,0 +1,78 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef TRACKERLIST_H
#define TRACKERLIST_H
#include <QTreeWidget>
#include <QList>
#include <libtorrent/version.hpp>
#include "qtorrenthandle.h"
#include "propertieswidget.h"
enum TrackerListColumn {COL_URL, COL_STATUS, COL_PEERS, COL_MSG};
#define NB_STICKY_ITEM 3
class TrackerList: public QTreeWidget {
Q_OBJECT
private:
PropertiesWidget *properties;
QHash<QString, QTreeWidgetItem*> tracker_items;
QTreeWidgetItem* dht_item;
QTreeWidgetItem* pex_item;
QTreeWidgetItem* lsd_item;
public:
TrackerList(PropertiesWidget *properties);
~TrackerList();
protected:
QList<QTreeWidgetItem*> getSelectedTrackerItems() const;
public slots:
void setRowColor(int row, QColor color);
void moveSelectionUp();
void moveSelectionDown();
void clear();
void loadStickyItems(const QTorrentHandle &h);
void loadTrackers();
void askForTrackers();
void deleteSelectedTrackers();
void showTrackerListMenu(QPoint);
void loadSettings();
void saveSettings() const;
};
#endif // TRACKERLIST_H

View File

@@ -0,0 +1,137 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef TRACKERSADDITION_H
#define TRACKERSADDITION_H
#include <QDialog>
#include <QStringList>
#include <QMessageBox>
#include <QFile>
#include <QUrl>
#include "misc.h"
#include "ui_trackersadditiondlg.h"
#include "downloadthread.h"
#include "qtorrenthandle.h"
class TrackersAdditionDlg : public QDialog, private Ui::TrackersAdditionDlg{
Q_OBJECT
private:
QTorrentHandle h;
public:
TrackersAdditionDlg(QTorrentHandle h, QWidget *parent=0): QDialog(parent), h(h) {
setupUi(this);
// As a default, use torrentz.com link
list_url->setText("http://www.torrentz.com/announce_"+h.hash());
list_url->setCursorPosition(0);
}
~TrackersAdditionDlg(){}
QStringList newTrackers() const {
return trackers_list->toPlainText().trimmed().split("\n");
}
public slots:
void on_uTorrentListButton_clicked() {
downloadThread *d = new downloadThread(this);
connect(d, SIGNAL(downloadFinished(QString,QString)), this, SLOT(parseUTorrentList(QString,QString)));
connect(d, SIGNAL(downloadFailure(QString,QString)), this, SLOT(getTrackerError(QString,QString)));
//Just to show that it takes times
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
d->downloadUrl("http://www.torrentz.com/announce_"+h.hash());
}
void parseUTorrentList(QString, QString path) {
QFile list_file(path);
if (!list_file.open(QFile::ReadOnly)) {
QMessageBox::warning(this, tr("I/O Error"), tr("Error while trying to open the downloaded file."), QMessageBox::Ok);
return;
}
QList<QUrl> existingTrackers;
// Load from torrent handle
std::vector<announce_entry> tor_trackers = h.trackers();
std::vector<announce_entry>::iterator itr = tor_trackers.begin();
while(itr != tor_trackers.end()) {
existingTrackers << QUrl(misc::toQString(itr->url));
itr++;
}
// Load from current user list
QStringList tmp = trackers_list->toPlainText().split("\n");
foreach(QString user_url_str, tmp) {
QUrl user_url(user_url_str);
if(!existingTrackers.contains(user_url))
existingTrackers << user_url;
}
// Add new trackers to the list
if(!trackers_list->toPlainText().isEmpty() && !trackers_list->toPlainText().endsWith("\n"))
trackers_list->insertPlainText("\n");
int nb = 0;
while (!list_file.atEnd()) {
QByteArray line = list_file.readLine().trimmed();
if(line.isEmpty()) continue;
QUrl url(line);
if (!existingTrackers.contains(url)) {
trackers_list->insertPlainText(line + "\n");
++nb;
}
}
// Clean up
list_file.close();
list_file.remove();
//To restore the cursor ...
QApplication::restoreOverrideCursor();
// Display information message if necessary
if(nb == 0) {
QMessageBox::information(this, tr("No change"), tr("No additional trackers were found."), QMessageBox::Ok);
}
}
void getTrackerError(QString, QString error) {
//To restore the cursor ...
QApplication::restoreOverrideCursor();
QMessageBox::warning(this, tr("Download error"), tr("The trackers list could not be downloaded, reason: %1").arg(error), QMessageBox::Ok);
}
public:
static QStringList askForTrackers(QTorrentHandle h) {
QStringList trackers;
TrackersAdditionDlg dlg(h);
if(dlg.exec() == QDialog::Accepted) {
return dlg.newTrackers();
}
return trackers;
}
};
#endif