mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-03 06:02:29 -06:00
Change project directory structure.
Change project directory structure according to application structure. Change 'nox' configuration option to something more meaningful 'nogui'. Rename 'Icons' folder to 'icons' (similar to other folders). Partially add 'nowebui' option support. Remove QConf project file.
This commit is contained in:
248
src/gui/properties/downloadedpiecesbar.cpp
Normal file
248
src/gui/properties/downloadedpiecesbar.cpp
Normal file
@@ -0,0 +1,248 @@
|
||||
/*
|
||||
* 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 "downloadedpiecesbar.h"
|
||||
|
||||
//#include <QDebug>
|
||||
|
||||
DownloadedPiecesBar::DownloadedPiecesBar(QWidget *parent): QWidget(parent)
|
||||
{
|
||||
setFixedHeight(BAR_HEIGHT);
|
||||
|
||||
bg_color = 0xffffff;
|
||||
border_color = palette().color(QPalette::Dark).rgb();
|
||||
piece_color = 0x0000ff;
|
||||
piece_color_dl = 0x00d000;
|
||||
|
||||
updatePieceColors();
|
||||
}
|
||||
|
||||
std::vector<float> DownloadedPiecesBar::bitfieldToFloatVector(const libtorrent::bitfield &vecin, int reqSize)
|
||||
{
|
||||
std::vector<float> result(reqSize, 0.0);
|
||||
|
||||
if (vecin.empty())
|
||||
return result;
|
||||
|
||||
const float ratio = vecin.size() / (float)reqSize;
|
||||
|
||||
// simple linear transformation algorithm
|
||||
// for example:
|
||||
// image.x(0) = pieces.x(0.0 >= x < 1.7)
|
||||
// image.x(1) = pieces.x(1.7 >= x < 3.4)
|
||||
|
||||
for (int x = 0; x < reqSize; ++x) {
|
||||
|
||||
// don't use previously calculated value "ratio" here!!!
|
||||
// float cannot save irrational number like 7/9, if this number will be rounded up by std::ceil
|
||||
// give you x2 == pieces.size(), and index out of range: pieces[x2]
|
||||
// this code is safe, so keep that in mind when you try optimize more.
|
||||
// tested with size = 3000000ul
|
||||
|
||||
// R - real
|
||||
const float fromR = (x * vecin.size()) / (float)reqSize;
|
||||
const float toR = ((x + 1) * vecin.size()) / (float)reqSize;
|
||||
|
||||
// C - integer
|
||||
int fromC = fromR;// std::floor not needed
|
||||
int toC = std::ceil(toR);
|
||||
|
||||
// position in pieces table
|
||||
// libtorrent::bitfield::m_size is unsigned int(31 bits), so qlonglong is not needed
|
||||
// tested with size = 3000000ul
|
||||
int x2 = fromC;
|
||||
|
||||
// little speed up for really big pieces table, 10K+ size
|
||||
const int toCMinusOne = toC - 1;
|
||||
|
||||
// value in returned vector
|
||||
float value = 0;
|
||||
|
||||
// case when calculated range is (15.2 >= x < 15.7)
|
||||
if (x2 == toCMinusOne) {
|
||||
if (vecin[x2]) {
|
||||
value += toR - fromR;
|
||||
}
|
||||
++x2;
|
||||
}
|
||||
// case when (15.2 >= x < 17.8)
|
||||
else {
|
||||
// subcase (15.2 >= x < 16)
|
||||
if (x2 != fromR) {
|
||||
if (vecin[x2]) {
|
||||
value += 1.0 - (fromR - fromC);
|
||||
}
|
||||
++x2;
|
||||
}
|
||||
|
||||
// subcase (16 >= x < 17)
|
||||
for (; x2 < toCMinusOne; ++x2) {
|
||||
if (vecin[x2]) {
|
||||
value += 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
// subcase (17 >= x < 17.8)
|
||||
if (x2 == toCMinusOne) {
|
||||
if (vecin[x2]) {
|
||||
value += 1.0 - (toC - toR);
|
||||
}
|
||||
++x2;
|
||||
}
|
||||
}
|
||||
|
||||
// normalization <0, 1>
|
||||
value /= ratio;
|
||||
|
||||
// float precision sometimes gives > 1, because in not possible to store irrational numbers
|
||||
value = qMin(value, (float)1.0);
|
||||
|
||||
result[x] = value;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int DownloadedPiecesBar::mixTwoColors(int &rgb1, int &rgb2, float ratio)
|
||||
{
|
||||
int r1 = qRed(rgb1);
|
||||
int g1 = qGreen(rgb1);
|
||||
int b1 = qBlue(rgb1);
|
||||
|
||||
int r2 = qRed(rgb2);
|
||||
int g2 = qGreen(rgb2);
|
||||
int b2 = qBlue(rgb2);
|
||||
|
||||
float ratio_n = 1.0 - ratio;
|
||||
int r = (r1 * ratio_n) + (r2 * ratio);
|
||||
int g = (g1 * ratio_n) + (g2 * ratio);
|
||||
int b = (b1 * ratio_n) + (b2 * ratio);
|
||||
|
||||
return qRgb(r, g, b);
|
||||
}
|
||||
|
||||
void DownloadedPiecesBar::updateImage()
|
||||
{
|
||||
// qDebug() << "updateImage";
|
||||
QImage image2(width() - 2, 1, QImage::Format_RGB888);
|
||||
|
||||
if (pieces.empty()) {
|
||||
image2.fill(0xffffff);
|
||||
image = image2;
|
||||
update();
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<float> scaled_pieces = bitfieldToFloatVector(pieces, image2.width());
|
||||
std::vector<float> scaled_pieces_dl = bitfieldToFloatVector(pieces_dl, image2.width());
|
||||
|
||||
// filling image
|
||||
for (unsigned int x = 0; x < scaled_pieces.size(); ++x)
|
||||
{
|
||||
float pieces2_val = scaled_pieces.at(x);
|
||||
float pieces2_val_dl = scaled_pieces_dl.at(x);
|
||||
if (pieces2_val_dl != 0)
|
||||
{
|
||||
float fill_ratio = pieces2_val + pieces2_val_dl;
|
||||
float ratio = pieces2_val_dl / fill_ratio;
|
||||
|
||||
int mixedColor = mixTwoColors(piece_color, piece_color_dl, ratio);
|
||||
mixedColor = mixTwoColors(bg_color, mixedColor, fill_ratio);
|
||||
|
||||
image2.setPixel(x, 0, mixedColor);
|
||||
}
|
||||
else
|
||||
{
|
||||
image2.setPixel(x, 0, piece_colors[pieces2_val * 255]);
|
||||
}
|
||||
}
|
||||
image = image2;
|
||||
}
|
||||
|
||||
void DownloadedPiecesBar::setProgress(const libtorrent::bitfield &bf, const libtorrent::bitfield &bf_dl)
|
||||
{
|
||||
pieces = libtorrent::bitfield(bf);
|
||||
pieces_dl = libtorrent::bitfield(bf_dl);
|
||||
|
||||
updateImage();
|
||||
update();
|
||||
}
|
||||
|
||||
void DownloadedPiecesBar::updatePieceColors()
|
||||
{
|
||||
piece_colors = std::vector<int>(256);
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
float ratio = (i / 255.0);
|
||||
piece_colors[i] = mixTwoColors(bg_color, piece_color, ratio);
|
||||
}
|
||||
}
|
||||
|
||||
void DownloadedPiecesBar::clear()
|
||||
{
|
||||
image = QImage();
|
||||
update();
|
||||
}
|
||||
|
||||
void DownloadedPiecesBar::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
QRect imageRect(1, 1, width() - 2, height() - 2);
|
||||
if (image.isNull())
|
||||
{
|
||||
painter.setBrush(Qt::white);
|
||||
painter.drawRect(imageRect);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (image.width() != imageRect.width())
|
||||
updateImage();
|
||||
painter.drawImage(imageRect, image);
|
||||
}
|
||||
QPainterPath border;
|
||||
border.addRect(0, 0, width() - 1, height() - 1);
|
||||
|
||||
painter.setPen(border_color);
|
||||
painter.drawPath(border);
|
||||
}
|
||||
|
||||
void DownloadedPiecesBar::setColors(int background, int border, int complete, int incomplete)
|
||||
{
|
||||
bg_color = background;
|
||||
border_color = border;
|
||||
piece_color = complete;
|
||||
piece_color_dl = incomplete;
|
||||
|
||||
updatePieceColors();
|
||||
updateImage();
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
87
src/gui/properties/downloadedpiecesbar.h
Normal file
87
src/gui/properties/downloadedpiecesbar.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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 <QImage>
|
||||
#include <cmath>
|
||||
#include <libtorrent/bitfield.hpp>
|
||||
|
||||
#define BAR_HEIGHT 18
|
||||
|
||||
class DownloadedPiecesBar: public QWidget {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(DownloadedPiecesBar)
|
||||
|
||||
private:
|
||||
QImage image;
|
||||
|
||||
// I used values, bacause it should be possible to change colors in runtime
|
||||
|
||||
// background color
|
||||
int bg_color;
|
||||
// border color
|
||||
int border_color;
|
||||
// complete piece color
|
||||
int piece_color;
|
||||
// incomplete piece color
|
||||
int piece_color_dl;
|
||||
// buffered 256 levels gradient from bg_color to piece_color
|
||||
std::vector<int> piece_colors;
|
||||
|
||||
// last used bitfields, uses to better resize redraw
|
||||
// TODO: make a diff pieces to new pieces and update only changed pixels, speedup when update > 20x faster
|
||||
libtorrent::bitfield pieces;
|
||||
libtorrent::bitfield pieces_dl;
|
||||
|
||||
// scale bitfield vector to float vector
|
||||
std::vector<float> bitfieldToFloatVector(const libtorrent::bitfield &vecin, int reqSize);
|
||||
// mix two colors by light model, ratio <0, 1>
|
||||
int mixTwoColors(int &rgb1, int &rgb2, float ratio);
|
||||
// draw new image and replace actual image
|
||||
void updateImage();
|
||||
|
||||
public:
|
||||
DownloadedPiecesBar(QWidget *parent);
|
||||
|
||||
void setProgress(const libtorrent::bitfield &bf, const libtorrent::bitfield &bf_dl);
|
||||
void updatePieceColors();
|
||||
void clear();
|
||||
|
||||
void setColors(int background, int border, int complete, int incomplete);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
};
|
||||
|
||||
#endif // DOWNLOADEDPIECESBAR_H
|
||||
109
src/gui/properties/peer.ui
Normal file
109
src/gui/properties/peer.ui
Normal file
@@ -0,0 +1,109 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>addPeerDialog</class>
|
||||
<widget class="QDialog" name="addPeerDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>112</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Peer addition</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>IP</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineIP"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Port</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinPort">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>60</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>70</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1000</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>65535</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>6881</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
105
src/gui/properties/peeraddition.h
Normal file
105
src/gui/properties/peeraddition.h
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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 <QHostAddress>
|
||||
#include "ui_peer.h"
|
||||
|
||||
#include <libtorrent/socket.hpp>
|
||||
#include <libtorrent/address.hpp>
|
||||
|
||||
#include <boost/version.hpp>
|
||||
#if BOOST_VERSION < 103500
|
||||
#include <libtorrent/asio/ip/tcp.hpp>
|
||||
#else
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#endif
|
||||
|
||||
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 {
|
||||
QHostAddress ip(lineIP->text());
|
||||
if (!ip.isNull()) {
|
||||
// QHostAddress::toString() cleans up the IP for libtorrent
|
||||
return ip.toString();
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
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) {
|
||||
QString ip = dlg.getIP();
|
||||
boost::system::error_code ec;
|
||||
libtorrent::address addr = libtorrent::address::from_string(qPrintable(ip), ec);
|
||||
if (ec) {
|
||||
qDebug("Unable to parse the provided IP: %s", qPrintable(ip));
|
||||
return ep;
|
||||
}
|
||||
qDebug("Provided IP is correct");
|
||||
ep = libtorrent::asio::ip::tcp::endpoint(addr, dlg.getPort());
|
||||
}
|
||||
return ep;
|
||||
}
|
||||
|
||||
|
||||
protected slots:
|
||||
void validateInput() {
|
||||
if (getIP().isEmpty()) {
|
||||
QMessageBox::warning(this, tr("Invalid IP"),
|
||||
tr("The IP you provided is invalid."),
|
||||
QMessageBox::Ok);
|
||||
} else {
|
||||
accept();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // PEERADDITION_H
|
||||
87
src/gui/properties/peerlistdelegate.h
Normal file
87
src/gui/properties/peerlistdelegate.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
class PeerListDelegate: public QItemDelegate {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum PeerListColumns {COUNTRY, IP, PORT, CONNECTION, FLAGS, CLIENT, PROGRESS, DOWN_SPEED, UP_SPEED,
|
||||
TOT_DOWN, TOT_UP, RELEVANCE, IP_HIDDEN, COL_COUNT};
|
||||
|
||||
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);
|
||||
qreal 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:
|
||||
case RELEVANCE:{
|
||||
QItemDelegate::drawBackground(painter, opt, index);
|
||||
qreal progress = index.data().toDouble();
|
||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, misc::accurateDoubleToString(progress*100.0, 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
|
||||
64
src/gui/properties/peerlistsortmodel.h
Normal file
64
src/gui/properties/peerlistsortmodel.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt4 and libtorrent.
|
||||
* Copyright (C) 2013 Nick Tiskov
|
||||
*
|
||||
* 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 : daymansmail@gmail.com
|
||||
*/
|
||||
|
||||
#ifndef PEERLISTSORTMODEL_H
|
||||
#define PEERLISTSORTMODEL_H
|
||||
|
||||
#include <QStringList>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include "peerlistdelegate.h"
|
||||
|
||||
class PeerListSortModel : public QSortFilterProxyModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PeerListSortModel(QObject *parent = 0) : QSortFilterProxyModel(parent) {}
|
||||
|
||||
protected:
|
||||
bool lessThan(const QModelIndex &left, const QModelIndex &right) const {
|
||||
if (sortColumn() == PeerListDelegate::IP || sortColumn() == PeerListDelegate::CLIENT) {
|
||||
QVariant vL = sourceModel()->data(left);
|
||||
QVariant vR = sourceModel()->data(right);
|
||||
if (!(vL.isValid() && vR.isValid()))
|
||||
return QSortFilterProxyModel::lessThan(left, right);
|
||||
Q_ASSERT(vL.isValid());
|
||||
Q_ASSERT(vR.isValid());
|
||||
|
||||
bool res = false;
|
||||
if (misc::naturalSort(vL.toString(), vR.toString(), res))
|
||||
return res;
|
||||
|
||||
return QSortFilterProxyModel::lessThan(left, right);
|
||||
}
|
||||
return QSortFilterProxyModel::lessThan(left, right);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // PEERLISTSORTMODEL_H
|
||||
616
src/gui/properties/peerlistwidget.cpp
Normal file
616
src/gui/properties/peerlistwidget.cpp
Normal file
@@ -0,0 +1,616 @@
|
||||
/*
|
||||
* 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 "peerlistsortmodel.h"
|
||||
#include "reverseresolution.h"
|
||||
#include "preferences.h"
|
||||
#include "propertieswidget.h"
|
||||
#include "geoipmanager.h"
|
||||
#include "peeraddition.h"
|
||||
#include "speedlimitdlg.h"
|
||||
#include "iconprovider.h"
|
||||
#include "qtorrenthandle.h"
|
||||
#include "logger.h"
|
||||
#include <QStandardItemModel>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QSet>
|
||||
#include <QHeaderView>
|
||||
#include <QMenu>
|
||||
#include <QClipboard>
|
||||
#include <vector>
|
||||
#include <libtorrent/peer_info.hpp>
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
PeerListWidget::PeerListWidget(PropertiesWidget *parent):
|
||||
QTreeView(parent), m_properties(parent), m_displayFlags(false)
|
||||
{
|
||||
// Load settings
|
||||
loadSettings();
|
||||
// Visual settings
|
||||
setUniformRowHeights(true);
|
||||
setRootIsDecorated(false);
|
||||
setItemsExpandable(false);
|
||||
setAllColumnsShowFocus(true);
|
||||
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
// List Model
|
||||
m_listModel = new QStandardItemModel(0, PeerListDelegate::COL_COUNT);
|
||||
m_listModel->setHeaderData(PeerListDelegate::COUNTRY, Qt::Horizontal, QVariant()); // Country flag column
|
||||
m_listModel->setHeaderData(PeerListDelegate::IP, Qt::Horizontal, tr("IP"));
|
||||
m_listModel->setHeaderData(PeerListDelegate::PORT, Qt::Horizontal, tr("Port"));
|
||||
m_listModel->setHeaderData(PeerListDelegate::FLAGS, Qt::Horizontal, tr("Flags"));
|
||||
m_listModel->setHeaderData(PeerListDelegate::CONNECTION, Qt::Horizontal, tr("Connection"));
|
||||
m_listModel->setHeaderData(PeerListDelegate::CLIENT, Qt::Horizontal, tr("Client", "i.e.: Client application"));
|
||||
m_listModel->setHeaderData(PeerListDelegate::PROGRESS, Qt::Horizontal, tr("Progress", "i.e: % downloaded"));
|
||||
m_listModel->setHeaderData(PeerListDelegate::DOWN_SPEED, Qt::Horizontal, tr("Down Speed", "i.e: Download speed"));
|
||||
m_listModel->setHeaderData(PeerListDelegate::UP_SPEED, Qt::Horizontal, tr("Up Speed", "i.e: Upload speed"));
|
||||
m_listModel->setHeaderData(PeerListDelegate::TOT_DOWN, Qt::Horizontal, tr("Downloaded", "i.e: total data downloaded"));
|
||||
m_listModel->setHeaderData(PeerListDelegate::TOT_UP, Qt::Horizontal, tr("Uploaded", "i.e: total data uploaded"));
|
||||
m_listModel->setHeaderData(PeerListDelegate::RELEVANCE, Qt::Horizontal, tr("Relevance", "i.e: How relevant this peer is to us. How many pieces it has that we don't."));
|
||||
// Proxy model to support sorting without actually altering the underlying model
|
||||
m_proxyModel = new PeerListSortModel();
|
||||
m_proxyModel->setDynamicSortFilter(true);
|
||||
m_proxyModel->setSourceModel(m_listModel);
|
||||
m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
setModel(m_proxyModel);
|
||||
//Explicitly set the column visibility. When columns are added/removed
|
||||
//between versions this prevents some of them being hidden due to
|
||||
//incorrect restoreState() being used.
|
||||
for (unsigned int i=0; i<PeerListDelegate::IP_HIDDEN; i++)
|
||||
showColumn(i);
|
||||
hideColumn(PeerListDelegate::IP_HIDDEN);
|
||||
hideColumn(PeerListDelegate::COL_COUNT);
|
||||
if (!Preferences::instance()->resolvePeerCountries())
|
||||
hideColumn(PeerListDelegate::COUNTRY);
|
||||
//To also migitate the above issue, we have to resize each column when
|
||||
//its size is 0, because explicitely 'showing' the column isn't enough
|
||||
//in the above scenario.
|
||||
for (unsigned int i=0; i<PeerListDelegate::IP_HIDDEN; i++)
|
||||
if (!columnWidth(i))
|
||||
resizeColumnToContents(i);
|
||||
// Context menu
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showPeerListMenu(QPoint)));
|
||||
// List delegate
|
||||
m_listDelegate = new PeerListDelegate(this);
|
||||
setItemDelegate(m_listDelegate);
|
||||
// Enable sorting
|
||||
setSortingEnabled(true);
|
||||
// IP to Hostname resolver
|
||||
updatePeerHostNameResolutionState();
|
||||
// SIGNAL/SLOT
|
||||
connect(header(), SIGNAL(sectionClicked(int)), SLOT(handleSortColumnChanged(int)));
|
||||
handleSortColumnChanged(header()->sortIndicatorSection());
|
||||
}
|
||||
|
||||
PeerListWidget::~PeerListWidget()
|
||||
{
|
||||
saveSettings();
|
||||
delete m_proxyModel;
|
||||
delete m_listModel;
|
||||
delete m_listDelegate;
|
||||
if (m_resolver)
|
||||
delete m_resolver;
|
||||
}
|
||||
|
||||
void PeerListWidget::updatePeerHostNameResolutionState()
|
||||
{
|
||||
if (Preferences::instance()->resolvePeerHostNames()) {
|
||||
if (!m_resolver) {
|
||||
m_resolver = new ReverseResolution(this);
|
||||
connect(m_resolver, SIGNAL(ip_resolved(QString,QString)), SLOT(handleResolved(QString,QString)));
|
||||
loadPeers(m_properties->getCurrentTorrent(), true);
|
||||
}
|
||||
} else {
|
||||
if (m_resolver)
|
||||
delete m_resolver;
|
||||
}
|
||||
}
|
||||
|
||||
void PeerListWidget::updatePeerCountryResolutionState()
|
||||
{
|
||||
if (Preferences::instance()->resolvePeerCountries() != m_displayFlags) {
|
||||
m_displayFlags = !m_displayFlags;
|
||||
if (m_displayFlags)
|
||||
loadPeers(m_properties->getCurrentTorrent());
|
||||
}
|
||||
}
|
||||
|
||||
void PeerListWidget::showPeerListMenu(const QPoint&)
|
||||
{
|
||||
QMenu menu;
|
||||
bool empty_menu = true;
|
||||
QTorrentHandle h = m_properties->getCurrentTorrent();
|
||||
if (!h.is_valid()) return;
|
||||
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||||
QStringList selectedPeerIPs;
|
||||
QStringList selectedPeerIPPort;
|
||||
foreach (const QModelIndex &index, selectedIndexes) {
|
||||
int row = m_proxyModel->mapToSource(index).row();
|
||||
QString myip = m_listModel->data(m_listModel->index(row, PeerListDelegate::IP_HIDDEN)).toString();
|
||||
QString myport = m_listModel->data(m_listModel->index(row, PeerListDelegate::PORT)).toString();
|
||||
selectedPeerIPs << myip;
|
||||
selectedPeerIPPort << myip + ":" + myport;
|
||||
}
|
||||
// Add Peer Action
|
||||
QAction *addPeerAct = 0;
|
||||
if (!h.is_queued() && !h.is_checking()) {
|
||||
addPeerAct = menu.addAction(IconProvider::instance()->getIcon("user-group-new"), tr("Add a new peer..."));
|
||||
empty_menu = false;
|
||||
}
|
||||
// Per Peer Speed limiting actions
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
QAction *upLimitAct = 0;
|
||||
QAction *dlLimitAct = 0;
|
||||
#endif
|
||||
QAction *banAct = 0;
|
||||
QAction *copyPeerAct = 0;
|
||||
if (!selectedPeerIPs.isEmpty()) {
|
||||
copyPeerAct = menu.addAction(IconProvider::instance()->getIcon("edit-copy"), tr("Copy selected"));
|
||||
menu.addSeparator();
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
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();
|
||||
#endif
|
||||
banAct = menu.addAction(IconProvider::instance()->getIcon("user-group-delete"), tr("Ban peer permanently"));
|
||||
empty_menu = false;
|
||||
}
|
||||
if (empty_menu) return;
|
||||
QAction *act = menu.exec(QCursor::pos());
|
||||
if (act == 0) return;
|
||||
if (act == addPeerAct) {
|
||||
boost::asio::ip::tcp::endpoint ep = PeerAdditionDlg::askForPeerEndpoint();
|
||||
if (ep != boost::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 LIBTORRENT_VERSION_NUM < 10000
|
||||
if (act == upLimitAct) {
|
||||
limitUpRateSelectedPeers(selectedPeerIPs);
|
||||
return;
|
||||
}
|
||||
if (act == dlLimitAct) {
|
||||
limitDlRateSelectedPeers(selectedPeerIPs);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (act == banAct) {
|
||||
banSelectedPeers(selectedPeerIPs);
|
||||
return;
|
||||
}
|
||||
if (act == copyPeerAct) {
|
||||
#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
|
||||
QApplication::clipboard()->setText(selectedPeerIPPort.join("\r\n"));
|
||||
#else
|
||||
QApplication::clipboard()->setText(selectedPeerIPPort.join("\n"));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void PeerListWidget::banSelectedPeers(const 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());
|
||||
Logger::instance()->addMessage(tr("Manually banning peer %1...").arg(ip));
|
||||
QBtSession::instance()->banIP(ip);
|
||||
}
|
||||
// Refresh list
|
||||
loadPeers(m_properties->getCurrentTorrent());
|
||||
}
|
||||
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
void PeerListWidget::limitUpRateSelectedPeers(const QStringList& peer_ips)
|
||||
{
|
||||
if (peer_ips.empty())
|
||||
return;
|
||||
QTorrentHandle h = m_properties->getCurrentTorrent();
|
||||
if (!h.is_valid())
|
||||
return;
|
||||
|
||||
bool ok = false;
|
||||
int cur_limit = -1;
|
||||
boost::asio::ip::tcp::endpoint first_ep = m_peerEndpoints.value(peer_ips.first(),
|
||||
boost::asio::ip::tcp::endpoint());
|
||||
if (first_ep != boost::asio::ip::tcp::endpoint())
|
||||
cur_limit = h.get_peer_upload_limit(first_ep);
|
||||
long limit = SpeedLimitDialog::askSpeedLimit(&ok,
|
||||
tr("Upload rate limiting"),
|
||||
cur_limit,
|
||||
Preferences::instance()->getGlobalUploadLimit()*1024.);
|
||||
if (!ok)
|
||||
return;
|
||||
|
||||
foreach (const QString &ip, peer_ips) {
|
||||
boost::asio::ip::tcp::endpoint ep = m_peerEndpoints.value(ip, boost::asio::ip::tcp::endpoint());
|
||||
if (ep != boost::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(const QStringList& peer_ips)
|
||||
{
|
||||
QTorrentHandle h = m_properties->getCurrentTorrent();
|
||||
if (!h.is_valid())
|
||||
return;
|
||||
bool ok = false;
|
||||
int cur_limit = -1;
|
||||
boost::asio::ip::tcp::endpoint first_ep = m_peerEndpoints.value(peer_ips.first(),
|
||||
boost::asio::ip::tcp::endpoint());
|
||||
if (first_ep != boost::asio::ip::tcp::endpoint())
|
||||
cur_limit = h.get_peer_download_limit(first_ep);
|
||||
long limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Download rate limiting"), cur_limit, Preferences::instance()->getGlobalDownloadLimit()*1024.);
|
||||
if (!ok)
|
||||
return;
|
||||
|
||||
foreach (const QString &ip, peer_ips) {
|
||||
boost::asio::ip::tcp::endpoint ep = m_peerEndpoints.value(ip, boost::asio::ip::tcp::endpoint());
|
||||
if (ep != boost::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...");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void PeerListWidget::clear() {
|
||||
qDebug("clearing peer list");
|
||||
m_peerItems.clear();
|
||||
m_peerEndpoints.clear();
|
||||
m_missingFlags.clear();
|
||||
int nbrows = m_listModel->rowCount();
|
||||
if (nbrows > 0) {
|
||||
qDebug("Cleared %d peers", nbrows);
|
||||
m_listModel->removeRows(0, nbrows);
|
||||
}
|
||||
}
|
||||
|
||||
void PeerListWidget::loadSettings() {
|
||||
header()->restoreState(Preferences::instance()->getPeerListState());
|
||||
}
|
||||
|
||||
void PeerListWidget::saveSettings() const {
|
||||
Preferences::instance()->setPeerListState(header()->saveState());
|
||||
}
|
||||
|
||||
void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_resolution) {
|
||||
if (!h.is_valid())
|
||||
return;
|
||||
boost::system::error_code ec;
|
||||
libtorrent::torrent_status status = h.status(torrent_handle::query_pieces);
|
||||
std::vector<peer_info> peers;
|
||||
h.get_peer_info(peers);
|
||||
QSet<QString> old_peers_set = m_peerItems.keys().toSet();
|
||||
|
||||
std::vector<peer_info>::const_iterator itr = peers.begin();
|
||||
std::vector<peer_info>::const_iterator itrend = peers.end();
|
||||
for ( ; itr != itrend; ++itr) {
|
||||
peer_info peer = *itr;
|
||||
std::string ip_str = peer.ip.address().to_string(ec);
|
||||
if (ec || ip_str.empty())
|
||||
continue;
|
||||
QString peer_ip = misc::toQString(ip_str);
|
||||
if (m_peerItems.contains(peer_ip)) {
|
||||
// Update existing peer
|
||||
updatePeer(peer_ip, status, peer);
|
||||
old_peers_set.remove(peer_ip);
|
||||
if (force_hostname_resolution && m_resolver) {
|
||||
m_resolver->resolve(peer_ip);
|
||||
}
|
||||
} else {
|
||||
// Add new peer
|
||||
m_peerItems[peer_ip] = addPeer(peer_ip, status, peer);
|
||||
m_peerEndpoints[peer_ip] = peer.ip;
|
||||
// Resolve peer host name is asked
|
||||
if (m_resolver)
|
||||
m_resolver->resolve(peer_ip);
|
||||
}
|
||||
}
|
||||
// Delete peers that are gone
|
||||
QSetIterator<QString> it(old_peers_set);
|
||||
while(it.hasNext()) {
|
||||
const QString& ip = it.next();
|
||||
m_missingFlags.remove(ip);
|
||||
m_peerEndpoints.remove(ip);
|
||||
QStandardItem *item = m_peerItems.take(ip);
|
||||
m_listModel->removeRow(item->row());
|
||||
}
|
||||
}
|
||||
|
||||
QStandardItem* PeerListWidget::addPeer(const QString& ip, const libtorrent::torrent_status &status, const peer_info& peer) {
|
||||
int row = m_listModel->rowCount();
|
||||
// Adding Peer to peer list
|
||||
m_listModel->insertRow(row);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::IP), ip);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::IP), ip, Qt::ToolTipRole);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::PORT), peer.ip.port());
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::IP_HIDDEN), ip);
|
||||
if (m_displayFlags) {
|
||||
const QIcon ico = GeoIPManager::CountryISOCodeToIcon(peer.country);
|
||||
if (!ico.isNull()) {
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::COUNTRY), ico, Qt::DecorationRole);
|
||||
const QString country_name = GeoIPManager::CountryISOCodeToName(peer.country);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::COUNTRY), country_name, Qt::ToolTipRole);
|
||||
} else {
|
||||
m_missingFlags.insert(ip);
|
||||
}
|
||||
}
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::CONNECTION), getConnectionString(peer));
|
||||
QString flags, tooltip;
|
||||
getFlags(peer, flags, tooltip);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), flags);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), tooltip, Qt::ToolTipRole);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::CLIENT), misc::toQStringU(peer.client));
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::PROGRESS), peer.progress);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payload_down_speed);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payload_up_speed);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_DOWN), (qulonglong)peer.total_download);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_UP), (qulonglong)peer.total_upload);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::RELEVANCE), getPeerRelevance(status, peer));
|
||||
return m_listModel->item(row, PeerListDelegate::IP);
|
||||
}
|
||||
|
||||
void PeerListWidget::updatePeer(const QString& ip, const libtorrent::torrent_status &status, const peer_info& peer) {
|
||||
QStandardItem *item = m_peerItems.value(ip);
|
||||
int row = item->row();
|
||||
if (m_displayFlags) {
|
||||
const QIcon ico = GeoIPManager::CountryISOCodeToIcon(peer.country);
|
||||
if (!ico.isNull()) {
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::COUNTRY), ico, Qt::DecorationRole);
|
||||
const QString country_name = GeoIPManager::CountryISOCodeToName(peer.country);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::COUNTRY), country_name, Qt::ToolTipRole);
|
||||
m_missingFlags.remove(ip);
|
||||
}
|
||||
}
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::CONNECTION), getConnectionString(peer));
|
||||
QString flags, tooltip;
|
||||
getFlags(peer, flags, tooltip);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::PORT), peer.ip.port());
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), flags);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::FLAGS), tooltip, Qt::ToolTipRole);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::CLIENT), misc::toQStringU(peer.client));
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::PROGRESS), peer.progress);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::DOWN_SPEED), peer.payload_down_speed);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payload_up_speed);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_DOWN), (qulonglong)peer.total_download);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_UP), (qulonglong)peer.total_upload);
|
||||
m_listModel->setData(m_listModel->index(row, PeerListDelegate::RELEVANCE), getPeerRelevance(status, peer));
|
||||
}
|
||||
|
||||
void PeerListWidget::handleResolved(const QString &ip, const QString &hostname) {
|
||||
QStandardItem *item = m_peerItems.value(ip, 0);
|
||||
if (item) {
|
||||
qDebug("Resolved %s -> %s", qPrintable(ip), qPrintable(hostname));
|
||||
item->setData(hostname, Qt::DisplayRole);
|
||||
}
|
||||
}
|
||||
|
||||
void PeerListWidget::handleSortColumnChanged(int col)
|
||||
{
|
||||
if (col == PeerListDelegate::COUNTRY) {
|
||||
qDebug("Sorting by decoration");
|
||||
m_proxyModel->setSortRole(Qt::ToolTipRole);
|
||||
} else {
|
||||
m_proxyModel->setSortRole(Qt::DisplayRole);
|
||||
}
|
||||
}
|
||||
|
||||
QString PeerListWidget::getConnectionString(const peer_info& peer)
|
||||
{
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
if (peer.connection_type & peer_info::bittorrent_utp) {
|
||||
#else
|
||||
if (peer.flags & peer_info::utp_socket) {
|
||||
#endif
|
||||
return QString::fromUtf8("μTP");
|
||||
}
|
||||
|
||||
QString connection;
|
||||
switch(peer.connection_type) {
|
||||
case peer_info::http_seed:
|
||||
case peer_info::web_seed:
|
||||
connection = "Web";
|
||||
break;
|
||||
default:
|
||||
connection = "BT";
|
||||
break;
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
void PeerListWidget::getFlags(const peer_info& peer, QString& flags, QString& tooltip)
|
||||
{
|
||||
if (peer.flags & peer_info::interesting) {
|
||||
//d = Your client wants to download, but peer doesn't want to send (interested and choked)
|
||||
if (peer.flags & peer_info::remote_choked) {
|
||||
flags += "d ";
|
||||
tooltip += tr("interested(local) and choked(peer)");
|
||||
tooltip += ", ";
|
||||
}
|
||||
else {
|
||||
//D = Currently downloading (interested and not choked)
|
||||
flags += "D ";
|
||||
tooltip += tr("interested(local) and unchoked(peer)");
|
||||
tooltip += ", ";
|
||||
}
|
||||
}
|
||||
|
||||
if (peer.flags & peer_info::remote_interested) {
|
||||
//u = Peer wants your client to upload, but your client doesn't want to (interested and choked)
|
||||
if (peer.flags & peer_info::choked) {
|
||||
flags += "u ";
|
||||
tooltip += tr("interested(peer) and choked(local)");
|
||||
tooltip += ", ";
|
||||
}
|
||||
else {
|
||||
//U = Currently uploading (interested and not choked)
|
||||
flags += "U ";
|
||||
tooltip += tr("interested(peer) and unchoked(local)");
|
||||
tooltip += ", ";
|
||||
}
|
||||
}
|
||||
|
||||
//O = Optimistic unchoke
|
||||
if (peer.flags & peer_info::optimistic_unchoke) {
|
||||
flags += "O ";
|
||||
tooltip += tr("optimistic unchoke");
|
||||
tooltip += ", ";
|
||||
}
|
||||
|
||||
//S = Peer is snubbed
|
||||
if (peer.flags & peer_info::snubbed) {
|
||||
flags += "S ";
|
||||
tooltip += tr("peer snubbed");
|
||||
tooltip += ", ";
|
||||
}
|
||||
|
||||
//I = Peer is an incoming connection
|
||||
if ((peer.flags & peer_info::local_connection) == 0 ) {
|
||||
flags += "I ";
|
||||
tooltip += tr("incoming connection");
|
||||
tooltip += ", ";
|
||||
}
|
||||
|
||||
//K = Peer is unchoking your client, but your client is not interested
|
||||
if (((peer.flags & peer_info::remote_choked) == 0) && ((peer.flags & peer_info::interesting) == 0)) {
|
||||
flags += "K ";
|
||||
tooltip += tr("not interested(local) and unchoked(peer)");
|
||||
tooltip += ", ";
|
||||
}
|
||||
|
||||
//? = Your client unchoked the peer but the peer is not interested
|
||||
if (((peer.flags & peer_info::choked) == 0) && ((peer.flags & peer_info::remote_interested) == 0)) {
|
||||
flags += "? ";
|
||||
tooltip += tr("not interested(peer) and unchoked(local)");
|
||||
tooltip += ", ";
|
||||
}
|
||||
|
||||
//X = Peer was included in peerlists obtained through Peer Exchange (PEX)
|
||||
if (peer.source & peer_info::pex) {
|
||||
flags += "X ";
|
||||
tooltip += tr("peer from PEX");
|
||||
tooltip += ", ";
|
||||
}
|
||||
|
||||
//H = Peer was obtained through DHT
|
||||
if (peer.source & peer_info::dht) {
|
||||
flags += "H ";
|
||||
tooltip += tr("peer from DHT");
|
||||
tooltip += ", ";
|
||||
}
|
||||
|
||||
//E = Peer is using Protocol Encryption (all traffic)
|
||||
if (peer.flags & peer_info::rc4_encrypted) {
|
||||
flags += "E ";
|
||||
tooltip += tr("encrypted traffic");
|
||||
tooltip += ", ";
|
||||
}
|
||||
|
||||
//e = Peer is using Protocol Encryption (handshake)
|
||||
if (peer.flags & peer_info::plaintext_encrypted) {
|
||||
flags += "e ";
|
||||
tooltip += tr("encrypted handshake");
|
||||
tooltip += ", ";
|
||||
}
|
||||
|
||||
//P = Peer is using uTorrent uTP
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
if (peer.connection_type & peer_info::bittorrent_utp) {
|
||||
#else
|
||||
if (peer.flags & peer_info::utp_socket) {
|
||||
#endif
|
||||
flags += "P ";
|
||||
tooltip += QString::fromUtf8("μTP");
|
||||
tooltip += ", ";
|
||||
}
|
||||
|
||||
//L = Peer is local
|
||||
if (peer.source & peer_info::lsd) {
|
||||
flags += "L";
|
||||
tooltip += tr("peer from LSD");
|
||||
}
|
||||
|
||||
flags = flags.trimmed();
|
||||
tooltip = tooltip.trimmed();
|
||||
if (tooltip.endsWith(',', Qt::CaseInsensitive))
|
||||
tooltip.chop(1);
|
||||
}
|
||||
|
||||
double PeerListWidget::getPeerRelevance(const torrent_status& status, const libtorrent::peer_info &peer)
|
||||
{
|
||||
int localMissing = 0;
|
||||
int remoteHaves = 0;
|
||||
libtorrent::bitfield local = status.pieces;
|
||||
libtorrent::bitfield remote = peer.pieces;
|
||||
|
||||
for (int i=0; i<local.size(); ++i) {
|
||||
if (!local[i]) {
|
||||
++localMissing;
|
||||
if (remote[i])
|
||||
++remoteHaves;
|
||||
}
|
||||
}
|
||||
|
||||
if (localMissing == 0)
|
||||
return 0.0;
|
||||
|
||||
return (double)remoteHaves/localMissing;
|
||||
}
|
||||
111
src/gui/properties/peerlistwidget.h
Normal file
111
src/gui/properties/peerlistwidget.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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 <libtorrent/version.hpp>
|
||||
|
||||
class PeerListDelegate;
|
||||
class PeerListSortModel;
|
||||
class ReverseResolution;
|
||||
class PropertiesWidget;
|
||||
class QTorrentHandle;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QSortFilterProxyModel;
|
||||
class QStandardItem;
|
||||
class QStandardItemModel;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
struct peer_info;
|
||||
struct torrent_status;
|
||||
}
|
||||
|
||||
#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(const QString& ip, const libtorrent::torrent_status &status, const libtorrent::peer_info& peer);
|
||||
void updatePeer(const QString& ip, const libtorrent::torrent_status &status, const libtorrent::peer_info& peer);
|
||||
void handleResolved(const QString &ip, const QString &hostname);
|
||||
void updatePeerHostNameResolutionState();
|
||||
void updatePeerCountryResolutionState();
|
||||
void clear();
|
||||
|
||||
protected slots:
|
||||
void loadSettings();
|
||||
void saveSettings() const;
|
||||
void showPeerListMenu(const QPoint&);
|
||||
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
void limitUpRateSelectedPeers(const QStringList& peer_ips);
|
||||
void limitDlRateSelectedPeers(const QStringList& peer_ips);
|
||||
#endif
|
||||
|
||||
void banSelectedPeers(const QStringList& peer_ips);
|
||||
void handleSortColumnChanged(int col);
|
||||
|
||||
private:
|
||||
static QString getConnectionString(const libtorrent::peer_info &peer);
|
||||
static void getFlags(const libtorrent::peer_info& peer, QString& flags, QString& tooltip);
|
||||
double getPeerRelevance(const libtorrent::torrent_status &status, const libtorrent::peer_info &peer);
|
||||
|
||||
private:
|
||||
QStandardItemModel *m_listModel;
|
||||
PeerListDelegate *m_listDelegate;
|
||||
PeerListSortModel *m_proxyModel;
|
||||
QHash<QString, QStandardItem*> m_peerItems;
|
||||
QHash<QString, boost::asio::ip::tcp::endpoint> m_peerEndpoints;
|
||||
QSet<QString> m_missingFlags;
|
||||
QPointer<ReverseResolution> m_resolver;
|
||||
PropertiesWidget *m_properties;
|
||||
bool m_displayFlags;
|
||||
};
|
||||
|
||||
#endif // PEERLISTWIDGET_H
|
||||
238
src/gui/properties/pieceavailabilitybar.cpp
Normal file
238
src/gui/properties/pieceavailabilitybar.cpp
Normal file
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* 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 "pieceavailabilitybar.h"
|
||||
|
||||
//#include <QDebug>
|
||||
|
||||
PieceAvailabilityBar::PieceAvailabilityBar(QWidget *parent) :
|
||||
QWidget(parent)
|
||||
{
|
||||
setFixedHeight(BAR_HEIGHT);
|
||||
|
||||
bg_color = 0xffffff;
|
||||
border_color = palette().color(QPalette::Dark).rgb();
|
||||
piece_color = 0x0000ff;
|
||||
|
||||
updatePieceColors();
|
||||
}
|
||||
|
||||
std::vector<float> PieceAvailabilityBar::intToFloatVector(const std::vector<int> &vecin, int reqSize)
|
||||
{
|
||||
std::vector<float> result(reqSize, 0.0);
|
||||
|
||||
if (vecin.empty())
|
||||
return result;
|
||||
|
||||
const float ratio = vecin.size() / (float)reqSize;
|
||||
|
||||
const int maxElement = *std::max_element(vecin.begin(), vecin.end());
|
||||
|
||||
// qMax bacause in normalization we don't want divide by 0
|
||||
// if maxElement == 0 check will be disabled please enable this line:
|
||||
// const int maxElement = qMax(*std::max_element(avail.begin(), avail.end()), 1);
|
||||
|
||||
if (maxElement == 0)
|
||||
return result;
|
||||
|
||||
// simple linear transformation algorithm
|
||||
// for example:
|
||||
// image.x(0) = pieces.x(0.0 >= x < 1.7)
|
||||
// image.x(1) = pieces.x(1.7 >= x < 3.4)
|
||||
|
||||
for (int x = 0; x < reqSize; ++x) {
|
||||
|
||||
// don't use previously calculated value "ratio" here!!!
|
||||
// float cannot save irrational number like 7/9, if this number will be rounded up by std::ceil
|
||||
// give you x2 == pieces.size(), and index out of range: pieces[x2]
|
||||
// this code is safe, so keep that in mind when you try optimize more.
|
||||
// tested with size = 3000000ul
|
||||
|
||||
// R - real
|
||||
const float fromR = (x * vecin.size()) / (float)reqSize;
|
||||
const float toR = ((x + 1) * vecin.size()) / (float)reqSize;
|
||||
|
||||
// C - integer
|
||||
int fromC = fromR;// std::floor not needed
|
||||
int toC = std::ceil(toR);
|
||||
|
||||
// position in pieces table
|
||||
// libtorrent::bitfield::m_size is unsigned int(31 bits), so qlonglong is not needed
|
||||
// tested with size = 3000000ul
|
||||
int x2 = fromC;
|
||||
|
||||
// little speed up for really big pieces table, 10K+ size
|
||||
const int toCMinusOne = toC - 1;
|
||||
|
||||
// value in returned vector
|
||||
float value = 0;
|
||||
|
||||
// case when calculated range is (15.2 >= x < 15.7)
|
||||
if (x2 == toCMinusOne) {
|
||||
if (vecin[x2]) {
|
||||
value += (toR - fromR) * vecin[x2];
|
||||
}
|
||||
++x2;
|
||||
}
|
||||
// case when (15.2 >= x < 17.8)
|
||||
else {
|
||||
// subcase (15.2 >= x < 16)
|
||||
if (x2 != fromR) {
|
||||
if (vecin[x2]) {
|
||||
value += (1.0 - (fromR - fromC)) * vecin[x2];
|
||||
}
|
||||
++x2;
|
||||
}
|
||||
|
||||
// subcase (16 >= x < 17)
|
||||
for (; x2 < toCMinusOne; ++x2) {
|
||||
if (vecin[x2]) {
|
||||
value += vecin[x2];
|
||||
}
|
||||
}
|
||||
|
||||
// subcase (17 >= x < 17.8)
|
||||
if (x2 == toCMinusOne) {
|
||||
if (vecin[x2]) {
|
||||
value += (1.0 - (toC - toR)) * vecin[x2];
|
||||
}
|
||||
++x2;
|
||||
}
|
||||
}
|
||||
|
||||
// normalization <0, 1>
|
||||
value /= ratio * maxElement;
|
||||
|
||||
// float precision sometimes gives > 1, because in not possible to store irrational numbers
|
||||
value = qMin(value, (float)1.0);
|
||||
|
||||
result[x] = value;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int PieceAvailabilityBar::mixTwoColors(int &rgb1, int &rgb2, float ratio)
|
||||
{
|
||||
int r1 = qRed(rgb1);
|
||||
int g1 = qGreen(rgb1);
|
||||
int b1 = qBlue(rgb1);
|
||||
|
||||
int r2 = qRed(rgb2);
|
||||
int g2 = qGreen(rgb2);
|
||||
int b2 = qBlue(rgb2);
|
||||
|
||||
float ratio_n = 1.0 - ratio;
|
||||
int r = (r1 * ratio_n) + (r2 * ratio);
|
||||
int g = (g1 * ratio_n) + (g2 * ratio);
|
||||
int b = (b1 * ratio_n) + (b2 * ratio);
|
||||
|
||||
return qRgb(r, g, b);
|
||||
}
|
||||
|
||||
void PieceAvailabilityBar::updateImage()
|
||||
{
|
||||
// qDebug() << "updateImageAv";
|
||||
QImage image2(width() - 2, 1, QImage::Format_RGB888);
|
||||
|
||||
if (pieces.empty()) {
|
||||
image2.fill(0xffffff);
|
||||
image = image2;
|
||||
update();
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<float> scaled_pieces = intToFloatVector(pieces, image2.width());
|
||||
|
||||
// filling image
|
||||
for (unsigned int x = 0; x < scaled_pieces.size(); ++x)
|
||||
{
|
||||
float pieces2_val = scaled_pieces.at(x);
|
||||
image2.setPixel(x, 0, piece_colors[pieces2_val * 255]);
|
||||
}
|
||||
image = image2;
|
||||
}
|
||||
|
||||
void PieceAvailabilityBar::setAvailability(const std::vector<int>& avail)
|
||||
{
|
||||
pieces = std::vector<int>(avail);
|
||||
|
||||
updateImage();
|
||||
update();
|
||||
}
|
||||
|
||||
void PieceAvailabilityBar::updatePieceColors()
|
||||
{
|
||||
piece_colors = std::vector<int>(256);
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
float ratio = (i / 255.0);
|
||||
piece_colors[i] = mixTwoColors(bg_color, piece_color, ratio);
|
||||
}
|
||||
}
|
||||
|
||||
void PieceAvailabilityBar::clear()
|
||||
{
|
||||
image = QImage();
|
||||
update();
|
||||
}
|
||||
|
||||
void PieceAvailabilityBar::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
QRect imageRect(1, 1, width() - 2, height() - 2);
|
||||
if (image.isNull())
|
||||
{
|
||||
painter.setBrush(Qt::white);
|
||||
painter.drawRect(imageRect);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (image.width() != imageRect.width())
|
||||
updateImage();
|
||||
painter.drawImage(imageRect, image);
|
||||
}
|
||||
QPainterPath border;
|
||||
border.addRect(0, 0, width() - 1, height() - 1);
|
||||
|
||||
painter.setPen(border_color);
|
||||
painter.drawPath(border);
|
||||
}
|
||||
|
||||
void PieceAvailabilityBar::setColors(int background, int border, int available)
|
||||
{
|
||||
bg_color = background;
|
||||
border_color = border;
|
||||
piece_color = available;
|
||||
|
||||
updatePieceColors();
|
||||
updateImage();
|
||||
update();
|
||||
}
|
||||
|
||||
86
src/gui/properties/pieceavailabilitybar.h
Normal file
86
src/gui/properties/pieceavailabilitybar.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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 <QImage>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
#define BAR_HEIGHT 18
|
||||
|
||||
class PieceAvailabilityBar: public QWidget {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(PieceAvailabilityBar)
|
||||
|
||||
private:
|
||||
QImage image;
|
||||
|
||||
// I used values, bacause it should be possible to change colors in runtime
|
||||
|
||||
// background color
|
||||
int bg_color;
|
||||
// border color
|
||||
int border_color;
|
||||
// complete piece color
|
||||
int piece_color;
|
||||
// buffered 256 levels gradient from bg_color to piece_color
|
||||
std::vector<int> piece_colors;
|
||||
|
||||
// last used int vector, uses to better resize redraw
|
||||
// TODO: make a diff pieces to new pieces and update only changed pixels, speedup when update > 20x faster
|
||||
std::vector<int> pieces;
|
||||
|
||||
// scale int vector to float vector
|
||||
std::vector<float> intToFloatVector(const std::vector<int> &vecin, int reqSize);
|
||||
|
||||
// mix two colors by light model, ratio <0, 1>
|
||||
int mixTwoColors(int &rgb1, int &rgb2, float ratio);
|
||||
// draw new image and replace actual image
|
||||
void updateImage();
|
||||
|
||||
public:
|
||||
PieceAvailabilityBar(QWidget *parent);
|
||||
|
||||
void setAvailability(const std::vector<int>& avail);
|
||||
void updatePieceColors();
|
||||
void clear();
|
||||
|
||||
void setColors(int background, int border, int available);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *);
|
||||
|
||||
};
|
||||
|
||||
#endif // PIECEAVAILABILITYBAR_H
|
||||
24
src/gui/properties/properties.pri
Normal file
24
src/gui/properties/properties.pri
Normal file
@@ -0,0 +1,24 @@
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
FORMS += $$PWD/propertieswidget.ui \
|
||||
$$PWD/trackersadditiondlg.ui \
|
||||
$$PWD/peer.ui
|
||||
|
||||
HEADERS += $$PWD/propertieswidget.h \
|
||||
$$PWD/peerlistwidget.h \
|
||||
$$PWD/proplistdelegate.h \
|
||||
$$PWD/trackerlist.h \
|
||||
$$PWD/downloadedpiecesbar.h \
|
||||
$$PWD/peerlistdelegate.h \
|
||||
$$PWD/peerlistsortmodel.h \
|
||||
$$PWD/peeraddition.h \
|
||||
$$PWD/trackersadditiondlg.h \
|
||||
$$PWD/pieceavailabilitybar.h \
|
||||
$$PWD/proptabbar.h
|
||||
|
||||
SOURCES += $$PWD/propertieswidget.cpp \
|
||||
$$PWD/peerlistwidget.cpp \
|
||||
$$PWD/trackerlist.cpp \
|
||||
$$PWD/proptabbar.cpp \
|
||||
$$PWD/downloadedpiecesbar.cpp \
|
||||
$$PWD/pieceavailabilitybar.cpp
|
||||
851
src/gui/properties/propertieswidget.cpp
Normal file
851
src/gui/properties/propertieswidget.cpp
Normal file
@@ -0,0 +1,851 @@
|
||||
/*
|
||||
* 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 <QDebug>
|
||||
#include <QTimer>
|
||||
#include <QListWidgetItem>
|
||||
#include <QVBoxLayout>
|
||||
#include <QStackedWidget>
|
||||
#include <QSplitter>
|
||||
#include <QHeaderView>
|
||||
#include <QAction>
|
||||
#include <QMessageBox>
|
||||
#include <QMenu>
|
||||
#include <QFileDialog>
|
||||
#include <QDesktopServices>
|
||||
#include <libtorrent/version.hpp>
|
||||
#include "propertieswidget.h"
|
||||
#include "transferlistwidget.h"
|
||||
#include "torrentpersistentdata.h"
|
||||
#include "qbtsession.h"
|
||||
#include "proplistdelegate.h"
|
||||
#include "torrentcontentfiltermodel.h"
|
||||
#include "torrentcontentmodel.h"
|
||||
#include "peerlistwidget.h"
|
||||
#include "trackerlist.h"
|
||||
#include "mainwindow.h"
|
||||
#include "downloadedpiecesbar.h"
|
||||
#include "pieceavailabilitybar.h"
|
||||
#include "preferences.h"
|
||||
#include "proptabbar.h"
|
||||
#include "iconprovider.h"
|
||||
#include "lineedit.h"
|
||||
#include "fs_utils.h"
|
||||
#include "autoexpandabledialog.h"
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, TransferListWidget *transferList):
|
||||
QWidget(parent), transferList(transferList), main_window(main_window) {
|
||||
setupUi(this);
|
||||
|
||||
// Icons
|
||||
trackerUpButton->setIcon(IconProvider::instance()->getIcon("go-up"));
|
||||
trackerDownButton->setIcon(IconProvider::instance()->getIcon("go-down"));
|
||||
|
||||
state = VISIBLE;
|
||||
|
||||
// Set Properties list model
|
||||
PropListModel = new TorrentContentFilterModel();
|
||||
filesList->setModel(PropListModel);
|
||||
PropDelegate = new PropListDelegate(this);
|
||||
filesList->setItemDelegate(PropDelegate);
|
||||
filesList->setSortingEnabled(true);
|
||||
// Torrent content filtering
|
||||
m_contentFilerLine = new LineEdit(this);
|
||||
m_contentFilerLine->setPlaceholderText(tr("Filter files..."));
|
||||
connect(m_contentFilerLine, SIGNAL(textChanged(QString)), this, SLOT(filterText(QString)));
|
||||
contentFilterLayout->insertWidget(4, m_contentFilerLine);
|
||||
|
||||
// SIGNAL/SLOTS
|
||||
connect(filesList, SIGNAL(clicked(const QModelIndex&)), filesList, SLOT(edit(const QModelIndex&)));
|
||||
connect(selectAllButton, SIGNAL(clicked()), PropListModel, SLOT(selectAll()));
|
||||
connect(selectNoneButton, SIGNAL(clicked()), PropListModel, SLOT(selectNone()));
|
||||
connect(filesList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFilesListMenu(const QPoint&)));
|
||||
connect(filesList, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(openDoubleClickedFile(const QModelIndex &)));
|
||||
connect(PropListModel, SIGNAL(filteredFilesChanged()), this, SLOT(filteredFilesChanged()));
|
||||
connect(listWebSeeds, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayWebSeedListMenu(const QPoint&)));
|
||||
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(QBtSession::instance(), SIGNAL(savePathChanged(QTorrentHandle)), this, SLOT(updateSavePath(QTorrentHandle)));
|
||||
connect(QBtSession::instance(), SIGNAL(metadataReceived(QTorrentHandle)), this, SLOT(updateTorrentInfos(QTorrentHandle)));
|
||||
connect(filesList->header(), SIGNAL(sectionMoved(int, int, int)), this, SLOT(saveSettings()));
|
||||
connect(filesList->header(), SIGNAL(sectionResized(int, int, int)), this, SLOT(saveSettings()));
|
||||
connect(filesList->header(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), this, SLOT(saveSettings()));
|
||||
|
||||
// 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);
|
||||
connect(trackerUpButton, SIGNAL(clicked()), trackerList, SLOT(moveSelectionUp()));
|
||||
connect(trackerDownButton, SIGNAL(clicked()), trackerList, SLOT(moveSelectionDown()));
|
||||
horizontalLayout_trackers->insertWidget(0, trackerList);
|
||||
connect(trackerList->header(), SIGNAL(sectionMoved(int, int, int)), trackerList, SLOT(saveSettings()));
|
||||
connect(trackerList->header(), SIGNAL(sectionResized(int, int, int)), trackerList, SLOT(saveSettings()));
|
||||
connect(trackerList->header(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), trackerList, SLOT(saveSettings()));
|
||||
// Peers list
|
||||
peersList = new PeerListWidget(this);
|
||||
peerpage_layout->addWidget(peersList);
|
||||
connect(peersList->header(), SIGNAL(sectionMoved(int, int, int)), peersList, SLOT(saveSettings()));
|
||||
connect(peersList->header(), SIGNAL(sectionResized(int, int, int)), peersList, SLOT(saveSettings()));
|
||||
connect(peersList->header(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), peersList, SLOT(saveSettings()));
|
||||
// Tab bar
|
||||
m_tabBar = new PropTabBar();
|
||||
verticalLayout->addLayout(m_tabBar);
|
||||
connect(m_tabBar, SIGNAL(tabChanged(int)), stackedProperties, SLOT(setCurrentIndex(int)));
|
||||
connect(m_tabBar, SIGNAL(tabChanged(int)), this, SLOT(saveSettings()));
|
||||
connect(m_tabBar, SIGNAL(visibilityToggled(bool)), SLOT(setVisibility(bool)));
|
||||
connect(m_tabBar, SIGNAL(visibilityToggled(bool)), this, SLOT(saveSettings()));
|
||||
// Dynamic data refresher
|
||||
refreshTimer = new QTimer(this);
|
||||
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(loadDynamicData()));
|
||||
refreshTimer->start(3000); // 3sec
|
||||
editHotkeyFile = new QShortcut(QKeySequence("F2"), filesList, 0, 0, Qt::WidgetShortcut);
|
||||
connect(editHotkeyFile, SIGNAL(activated()), SLOT(renameSelectedFile()));
|
||||
editHotkeyWeb = new QShortcut(QKeySequence("F2"), listWebSeeds, 0, 0, Qt::WidgetShortcut);
|
||||
connect(editHotkeyWeb, SIGNAL(activated()), SLOT(editWebSeed()));
|
||||
connect(listWebSeeds, SIGNAL(doubleClicked(QModelIndex)), SLOT(editWebSeed()));
|
||||
deleteHotkeyWeb = new QShortcut(QKeySequence(QKeySequence::Delete), listWebSeeds, 0, 0, Qt::WidgetShortcut);
|
||||
connect(deleteHotkeyWeb, SIGNAL(activated()), SLOT(deleteSelectedUrlSeeds()));
|
||||
}
|
||||
|
||||
PropertiesWidget::~PropertiesWidget() {
|
||||
qDebug() << Q_FUNC_INFO << "ENTER";
|
||||
delete refreshTimer;
|
||||
delete trackerList;
|
||||
delete peersList;
|
||||
delete downloaded_pieces;
|
||||
delete pieces_availability;
|
||||
delete PropListModel;
|
||||
delete PropDelegate;
|
||||
delete m_tabBar;
|
||||
delete editHotkeyFile;
|
||||
delete editHotkeyWeb;
|
||||
delete deleteHotkeyWeb;
|
||||
qDebug() << Q_FUNC_INFO << "EXIT";
|
||||
}
|
||||
|
||||
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::setVisibility(bool visible) {
|
||||
if (!visible && state == VISIBLE) {
|
||||
QSplitter *hSplitter = static_cast<QSplitter*>(parentWidget());
|
||||
stackedProperties->setVisible(false);
|
||||
slideSizes = hSplitter->sizes();
|
||||
hSplitter->handle(1)->setVisible(false);
|
||||
hSplitter->handle(1)->setDisabled(true);
|
||||
QList<int> sizes = QList<int>() << hSplitter->geometry().height()-30 << 30;
|
||||
hSplitter->setSizes(sizes);
|
||||
state = REDUCED;
|
||||
return;
|
||||
}
|
||||
|
||||
if (visible && 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();
|
||||
pieceSize_lbl->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();
|
||||
m_contentFilerLine->clear();
|
||||
PropListModel->model()->clear();
|
||||
showPiecesAvailability(false);
|
||||
showPiecesDownloaded(false);
|
||||
}
|
||||
|
||||
QTorrentHandle PropertiesWidget::getCurrentTorrent() const {
|
||||
return h;
|
||||
}
|
||||
|
||||
void PropertiesWidget::updateSavePath(const QTorrentHandle& _h) {
|
||||
if (h.is_valid() && h == _h) {
|
||||
save_path->setText(fsutils::toNativePath(h.save_path_parsed()));
|
||||
}
|
||||
}
|
||||
|
||||
void PropertiesWidget::updateTorrentInfos(const QTorrentHandle& _h) {
|
||||
if (h.is_valid() && h == _h) {
|
||||
loadTorrentInfos(h);
|
||||
}
|
||||
}
|
||||
|
||||
void PropertiesWidget::loadTorrentInfos(const QTorrentHandle& _h)
|
||||
{
|
||||
clear();
|
||||
h = _h;
|
||||
if (!h.is_valid())
|
||||
return;
|
||||
|
||||
try {
|
||||
// Save path
|
||||
updateSavePath(h);
|
||||
// Hash
|
||||
hash_lbl->setText(h.hash());
|
||||
PropListModel->model()->clear();
|
||||
if (h.has_metadata()) {
|
||||
// Creation date
|
||||
lbl_creationDate->setText(h.creation_date());
|
||||
// Piece size
|
||||
pieceSize_lbl->setText(misc::friendlyUnit(h.piece_length()));
|
||||
// Comment
|
||||
comment_text->setHtml(misc::parseHtmlLinks(h.comment()));
|
||||
// URL seeds
|
||||
loadUrlSeeds();
|
||||
// List files in torrent
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
PropListModel->model()->setupModelData(h.get_torrent_info());
|
||||
#else
|
||||
PropListModel->model()->setupModelData(*h.torrent_file());
|
||||
#endif
|
||||
filesList->setExpanded(PropListModel->index(0, 0), true);
|
||||
// Load file priorities
|
||||
PropListModel->model()->updateFilesPriorities(h.file_priorities());
|
||||
}
|
||||
} catch(const invalid_handle& e) { }
|
||||
// Load dynamic data
|
||||
loadDynamicData();
|
||||
}
|
||||
|
||||
void PropertiesWidget::readSettings() {
|
||||
const Preferences* const pref = Preferences::instance();
|
||||
// Restore splitter sizes
|
||||
QStringList sizes_str = pref->getPropSplitterSizes().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);
|
||||
}
|
||||
const int current_tab = pref->getPropCurTab();
|
||||
const bool visible = pref->getPropVisible();
|
||||
// the following will call saveSettings but shouldn't change any state
|
||||
if (!filesList->header()->restoreState(pref->getPropFileListState())) {
|
||||
filesList->header()->resizeSection(0, 400); //Default
|
||||
}
|
||||
m_tabBar->setCurrentIndex(current_tab);
|
||||
if (!visible) {
|
||||
setVisibility(false);
|
||||
}
|
||||
}
|
||||
|
||||
void PropertiesWidget::saveSettings() {
|
||||
Preferences* const pref = Preferences::instance();
|
||||
pref->setPropVisible(state==VISIBLE);
|
||||
// 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) {
|
||||
pref->setPropSplitterSizes(QString::number(sizes.first())+','+QString::number(sizes.last()));
|
||||
}
|
||||
pref->setPropFileListState(filesList->header()->saveState());
|
||||
// Remember current tab
|
||||
pref->setPropCurTab(m_tabBar->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() == PropTabBar::MAIN_TAB) {
|
||||
libtorrent::torrent_status status = h.status(torrent_handle::query_accurate_download_counters
|
||||
| torrent_handle::query_distributed_copies
|
||||
| torrent_handle::query_pieces);
|
||||
|
||||
wasted->setText(misc::friendlyUnit(status.total_failed_bytes+status.total_redundant_bytes));
|
||||
upTotal->setText(misc::friendlyUnit(status.all_time_upload) + " ("+misc::friendlyUnit(status.total_payload_upload)+" "+tr("this session")+")");
|
||||
dlTotal->setText(misc::friendlyUnit(status.all_time_download) + " ("+misc::friendlyUnit(status.total_payload_download)+" "+tr("this session")+")");
|
||||
lbl_uplimit->setText(h.upload_limit() <= 0 ? QString::fromUtf8("∞") : misc::friendlyUnit(h.upload_limit())+tr("/s", "/second (i.e. per second)"));
|
||||
lbl_dllimit->setText(h.download_limit() <= 0 ? QString::fromUtf8("∞") : misc::friendlyUnit(h.download_limit())+tr("/s", "/second (i.e. per second)"));
|
||||
QString elapsed_txt = misc::userFriendlyDuration(status.active_time);
|
||||
if (h.is_seed(status)) {
|
||||
elapsed_txt += " ("+tr("Seeded for %1", "e.g. Seeded for 3m10s").arg(misc::userFriendlyDuration(status.seeding_time))+")";
|
||||
}
|
||||
lbl_elapsed->setText(elapsed_txt);
|
||||
if (status.connections_limit > 0)
|
||||
lbl_connections->setText(QString::number(status.num_connections)+" ("+tr("%1 max", "e.g. 10 max").arg(QString::number(status.connections_limit))+")");
|
||||
else
|
||||
lbl_connections->setText(QString::number(status.num_connections));
|
||||
// Update next announce time
|
||||
reannounce_lbl->setText(misc::userFriendlyDuration(status.next_announce.total_seconds()));
|
||||
// Update ratio info
|
||||
const qreal ratio = QBtSession::instance()->getRealRatio(status);
|
||||
shareRatio->setText(ratio > QBtSession::MAX_RATIO ? QString::fromUtf8("∞") : misc::accurateDoubleToString(ratio, 2));
|
||||
if (!h.is_seed(status) && status.has_metadata) {
|
||||
showPiecesDownloaded(true);
|
||||
// Downloaded pieces
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
bitfield bf(h.get_torrent_info().num_pieces(), 0);
|
||||
#else
|
||||
bitfield bf(h.torrent_file()->num_pieces(), 0);
|
||||
#endif
|
||||
h.downloading_pieces(bf);
|
||||
downloaded_pieces->setProgress(status.pieces, bf);
|
||||
// Pieces availability
|
||||
if (!h.is_paused(status) && !h.is_queued(status) && !h.is_checking(status)) {
|
||||
showPiecesAvailability(true);
|
||||
std::vector<int> avail;
|
||||
h.piece_availability(avail);
|
||||
pieces_availability->setAvailability(avail);
|
||||
avail_average_lbl->setText(misc::accurateDoubleToString(status.distributed_copies, 3));
|
||||
} else {
|
||||
showPiecesAvailability(false);
|
||||
}
|
||||
// Progress
|
||||
qreal progress = h.progress(status)*100.;
|
||||
progress_lbl->setText(misc::accurateDoubleToString(progress, 1)+"%");
|
||||
} else {
|
||||
showPiecesAvailability(false);
|
||||
showPiecesDownloaded(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (stackedProperties->currentIndex() == PropTabBar::TRACKERS_TAB) {
|
||||
// Trackers
|
||||
trackerList->loadTrackers();
|
||||
return;
|
||||
}
|
||||
if (stackedProperties->currentIndex() == PropTabBar::PEERS_TAB) {
|
||||
// Load peers
|
||||
peersList->loadPeers(h);
|
||||
return;
|
||||
}
|
||||
if (stackedProperties->currentIndex() == PropTabBar::FILES_TAB) {
|
||||
libtorrent::torrent_status status = h.status(torrent_handle::query_accurate_download_counters
|
||||
| torrent_handle::query_distributed_copies
|
||||
| torrent_handle::query_pieces);
|
||||
// Files progress
|
||||
if (h.is_valid() && status.has_metadata) {
|
||||
qDebug("Updating priorities in files tab");
|
||||
filesList->setUpdatesEnabled(false);
|
||||
std::vector<size_type> fp;
|
||||
h.file_progress(fp);
|
||||
PropListModel->model()->updateFilesProgress(fp);
|
||||
// XXX: We don't update file priorities regularly for performance
|
||||
// reasons. This means that priorities will not be updated if
|
||||
// set from the Web UI.
|
||||
// PropListModel->model()->updateFilesPriorities(h.file_priorities());
|
||||
filesList->setUpdatesEnabled(true);
|
||||
}
|
||||
}
|
||||
} catch(const invalid_handle& e) {
|
||||
qWarning() << "Caught exception in PropertiesWidget::loadDynamicData(): " << misc::toQStringU(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void PropertiesWidget::openDoubleClickedFile(const QModelIndex &index) {
|
||||
if (!index.isValid()) return;
|
||||
if (!h.is_valid() || !h.has_metadata()) return;
|
||||
if (PropListModel->itemType(index) == TorrentContentModelItem::FileType)
|
||||
openFile(index);
|
||||
else
|
||||
openFolder(index, false);
|
||||
}
|
||||
|
||||
void PropertiesWidget::openFile(const QModelIndex &index) {
|
||||
int i = PropListModel->getFileIndex(index);
|
||||
const QDir saveDir(h.save_path());
|
||||
const QString filename = h.filepath_at(i);
|
||||
const QString file_path = fsutils::expandPath(saveDir.absoluteFilePath(filename));
|
||||
qDebug("Trying to open file at %s", qPrintable(file_path));
|
||||
// Flush data
|
||||
h.flush_cache();
|
||||
if (QFile::exists(file_path)) {
|
||||
if (file_path.startsWith("//"))
|
||||
QDesktopServices::openUrl(fsutils::toNativePath("file:" + file_path));
|
||||
else
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(file_path));
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(this, tr("I/O Error"), tr("This file does not exist yet."));
|
||||
}
|
||||
}
|
||||
|
||||
void PropertiesWidget::openFolder(const QModelIndex &index, bool containing_folder) {
|
||||
QString absolute_path;
|
||||
// FOLDER
|
||||
if (PropListModel->itemType(index) == TorrentContentModelItem::FolderType) {
|
||||
// Generate relative path to selected 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);
|
||||
}
|
||||
if (path_items.isEmpty())
|
||||
return;
|
||||
#if !(defined(Q_OS_WIN) || (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)))
|
||||
if (containing_folder)
|
||||
path_items.removeLast();
|
||||
#endif
|
||||
const QDir saveDir(h.save_path());
|
||||
const QString relative_path = path_items.join("/");
|
||||
absolute_path = fsutils::expandPath(saveDir.absoluteFilePath(relative_path));
|
||||
}
|
||||
else {
|
||||
int i = PropListModel->getFileIndex(index);
|
||||
const QDir saveDir(h.save_path());
|
||||
const QString relative_path = h.filepath_at(i);
|
||||
absolute_path = fsutils::expandPath(saveDir.absoluteFilePath(relative_path));
|
||||
|
||||
#if !(defined(Q_OS_WIN) || (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)))
|
||||
if (containing_folder)
|
||||
absolute_path = fsutils::folderName(absolute_path);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Flush data
|
||||
h.flush_cache();
|
||||
if (!QFile::exists(absolute_path))
|
||||
return;
|
||||
qDebug("Trying to open folder at %s", qPrintable(absolute_path));
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
if (containing_folder) {
|
||||
// Syntax is: explorer /select, "C:\Folder1\Folder2\file_to_select"
|
||||
// Dir separators MUST be win-style slashes
|
||||
QProcess::startDetached("explorer.exe", QStringList() << "/select," << fsutils::toNativePath(absolute_path));
|
||||
} else {
|
||||
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
|
||||
if (containing_folder) {
|
||||
QProcess proc;
|
||||
QString output;
|
||||
proc.start("xdg-mime", QStringList() << "query" << "default" << "inode/directory");
|
||||
proc.waitForFinished();
|
||||
output = proc.readLine().simplified();
|
||||
if (output == "dolphin.desktop")
|
||||
proc.startDetached("dolphin", QStringList() << "--select" << fsutils::toNativePath(absolute_path));
|
||||
else if (output == "nautilus-folder-handler.desktop")
|
||||
proc.startDetached("nautilus", QStringList() << "--no-desktop" << fsutils::toNativePath(absolute_path));
|
||||
else if (output == "kfmclient_dir.desktop")
|
||||
proc.startDetached("konqueror", QStringList() << "--select" << fsutils::toNativePath(absolute_path));
|
||||
else
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(absolute_path).absolutePath()));
|
||||
} else {
|
||||
#endif
|
||||
if (QFile::exists(absolute_path)) {
|
||||
// Hack to access samba shares with QDesktopServices::openUrl
|
||||
if (absolute_path.startsWith("//"))
|
||||
QDesktopServices::openUrl(fsutils::toNativePath("file:" + absolute_path));
|
||||
else
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(absolute_path));
|
||||
} else {
|
||||
QMessageBox::warning(this, tr("I/O Error"), tr("This folder does not exist yet."));
|
||||
}
|
||||
#if defined(Q_OS_WIN) || (defined(Q_OS_UNIX) && !defined(Q_OS_MAC))
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void PropertiesWidget::displayFilesListMenu(const QPoint&) {
|
||||
if (!h.is_valid())
|
||||
return;
|
||||
QModelIndexList selectedRows = filesList->selectionModel()->selectedRows(0);
|
||||
if (selectedRows.empty())
|
||||
return;
|
||||
QMenu myFilesLlistMenu;
|
||||
QAction *actOpen = 0;
|
||||
QAction *actOpenContainingFolder = 0;
|
||||
QAction *actRename = 0;
|
||||
if (selectedRows.size() == 1) {
|
||||
actOpen = myFilesLlistMenu.addAction(IconProvider::instance()->getIcon("folder-documents"), tr("Open"));
|
||||
actOpenContainingFolder = myFilesLlistMenu.addAction(IconProvider::instance()->getIcon("inode-directory"), tr("Open Containing Folder"));
|
||||
actRename = myFilesLlistMenu.addAction(IconProvider::instance()->getIcon("edit-rename"), tr("Rename..."));
|
||||
myFilesLlistMenu.addSeparator();
|
||||
}
|
||||
QMenu subMenu;
|
||||
if (!h.status(0x0).is_seeding) {
|
||||
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());
|
||||
// The selected torrent might have dissapeared during exec()
|
||||
// from the current view thus leaving invalid indices.
|
||||
const QModelIndex index = *(selectedRows.begin());
|
||||
if (!index.isValid())
|
||||
return;
|
||||
if (act) {
|
||||
if (act == actOpen)
|
||||
openDoubleClickedFile(index);
|
||||
else if (act == actOpenContainingFolder)
|
||||
openFolder(index, true);
|
||||
else if (act == actRename)
|
||||
renameSelectedFile();
|
||||
else {
|
||||
int prio = prio::NORMAL;
|
||||
if (act == actionHigh)
|
||||
prio = prio::HIGH;
|
||||
else if (act == actionMaximum)
|
||||
prio = prio::MAXIMUM;
|
||||
else if (act == actionNot_downloaded)
|
||||
prio = 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::displayWebSeedListMenu(const QPoint&) {
|
||||
if (!h.is_valid())
|
||||
return;
|
||||
QMenu seedMenu;
|
||||
QModelIndexList rows = listWebSeeds->selectionModel()->selectedRows();
|
||||
QAction *actAdd = seedMenu.addAction(IconProvider::instance()->getIcon("list-add"), tr("New Web seed"));
|
||||
QAction *actDel = 0;
|
||||
QAction *actCpy = 0;
|
||||
QAction *actEdit = 0;
|
||||
|
||||
if (rows.size()) {
|
||||
actDel = seedMenu.addAction(IconProvider::instance()->getIcon("list-remove"), tr("Remove Web seed"));
|
||||
seedMenu.addSeparator();
|
||||
actCpy = seedMenu.addAction(IconProvider::instance()->getIcon("edit-copy"), tr("Copy Web seed URL"));
|
||||
actEdit = seedMenu.addAction(IconProvider::instance()->getIcon("edit-rename"), tr("Edit Web seed URL"));
|
||||
}
|
||||
|
||||
const QAction *act = seedMenu.exec(QCursor::pos());
|
||||
if (act) {
|
||||
if (act == actAdd)
|
||||
askWebSeed();
|
||||
else if (act == actDel)
|
||||
deleteSelectedUrlSeeds();
|
||||
else if (act == actCpy)
|
||||
copySelectedWebSeedsToClipboard();
|
||||
else if (act == actEdit)
|
||||
editWebSeed();
|
||||
}
|
||||
}
|
||||
|
||||
void PropertiesWidget::renameSelectedFile() {
|
||||
const QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(0);
|
||||
if (selectedIndexes.size() != 1)
|
||||
return;
|
||||
const QModelIndex index = selectedIndexes.first();
|
||||
if (!index.isValid())
|
||||
return;
|
||||
// Ask for new name
|
||||
bool ok;
|
||||
QString new_name_last = AutoExpandableDialog::getText(this, tr("Rename the file"),
|
||||
tr("New name:"), QLineEdit::Normal,
|
||||
index.data().toString(), &ok).trimmed();
|
||||
if (ok && !new_name_last.isEmpty()) {
|
||||
if (!fsutils::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->itemType(index) == TorrentContentModelItem::FileType) {
|
||||
// File renaming
|
||||
const int file_index = PropListModel->getFileIndex(index);
|
||||
if (!h.is_valid() || !h.has_metadata()) return;
|
||||
QString old_name = h.filepath_at(file_index);
|
||||
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 = fsutils::expandPath(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_OS_UNIX) || defined(Q_WS_QWS)
|
||||
if (h.filepath_at(i).compare(new_name, Qt::CaseSensitive) == 0) {
|
||||
#else
|
||||
if (h.filepath_at(i).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()+"/"+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 = h.filepath_at(i);
|
||||
#if defined(Q_OS_UNIX) || 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 = h.filepath_at(i);
|
||||
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 = fsutils::expandPath(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(!QDir().rmpath(old_folder.absolutePath()) && timeout > 0) {
|
||||
// XXX: We should not sleep here (freezes the UI for 1 second)
|
||||
misc::msleep(100);
|
||||
--timeout;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PropertiesWidget::askWebSeed() {
|
||||
bool ok;
|
||||
// Ask user for a new url seed
|
||||
const QString url_seed = AutoExpandableDialog::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, "qBittorrent",
|
||||
tr("This url seed is already in the list."),
|
||||
QMessageBox::Ok);
|
||||
return;
|
||||
}
|
||||
if (h.is_valid())
|
||||
h.add_url_seed(url_seed);
|
||||
// Refresh the seeds list
|
||||
loadUrlSeeds();
|
||||
}
|
||||
|
||||
void PropertiesWidget::deleteSelectedUrlSeeds() {
|
||||
const QList<QListWidgetItem *> selectedItems = listWebSeeds->selectedItems();
|
||||
if (selectedItems.isEmpty())
|
||||
return;
|
||||
bool change = false;
|
||||
foreach (const QListWidgetItem *item, selectedItems) {
|
||||
QString url_seed = item->text();
|
||||
try {
|
||||
h.remove_url_seed(url_seed);
|
||||
change = true;
|
||||
} catch (invalid_handle&) {}
|
||||
}
|
||||
if (change) {
|
||||
// Refresh list
|
||||
loadUrlSeeds();
|
||||
}
|
||||
}
|
||||
|
||||
void PropertiesWidget::copySelectedWebSeedsToClipboard() const {
|
||||
const QList<QListWidgetItem *> selected_items = listWebSeeds->selectedItems();
|
||||
if (selected_items.isEmpty())
|
||||
return;
|
||||
|
||||
QStringList urls_to_copy;
|
||||
foreach (QListWidgetItem *item, selected_items)
|
||||
urls_to_copy << item->text();
|
||||
|
||||
QApplication::clipboard()->setText(urls_to_copy.join("\n"));
|
||||
}
|
||||
|
||||
void PropertiesWidget::editWebSeed() {
|
||||
const QList<QListWidgetItem *> selected_items = listWebSeeds->selectedItems();
|
||||
if (selected_items.size() != 1)
|
||||
return;
|
||||
|
||||
const QListWidgetItem *selected_item = selected_items.last();
|
||||
const QString old_seed = selected_item->text();
|
||||
bool result;
|
||||
const QString new_seed = AutoExpandableDialog::getText(this, tr("Web seed editing"),
|
||||
tr("Web seed URL:"), QLineEdit::Normal,
|
||||
old_seed, &result);
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
if (!listWebSeeds->findItems(new_seed, Qt::MatchFixedString).empty()) {
|
||||
QMessageBox::warning(this, tr("qBittorrent"),
|
||||
tr("This url seed is already in the list."),
|
||||
QMessageBox::Ok);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
h.remove_url_seed(old_seed);
|
||||
h.add_url_seed(new_seed);
|
||||
loadUrlSeeds();
|
||||
} catch (invalid_handle&) {}
|
||||
}
|
||||
|
||||
bool PropertiesWidget::applyPriorities() {
|
||||
qDebug("Saving files priorities");
|
||||
const std::vector<int> priorities = PropListModel->model()->getFilesPriorities();
|
||||
// Save first/last piece first option state
|
||||
bool first_last_piece_first = h.first_last_piece_first();
|
||||
// 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::filteredFilesChanged() {
|
||||
if (h.is_valid()) {
|
||||
applyPriorities();
|
||||
}
|
||||
}
|
||||
|
||||
void PropertiesWidget::filterText(const QString& filter) {
|
||||
PropListModel->setFilterFixedString(filter);
|
||||
if (filter.isEmpty()) {
|
||||
filesList->collapseAll();
|
||||
filesList->expand(PropListModel->index(0, 0));
|
||||
}
|
||||
else
|
||||
filesList->expandAll();
|
||||
}
|
||||
128
src/gui/properties/propertieswidget.h
Normal file
128
src/gui/properties/propertieswidget.h
Normal 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 PROPERTIESWIDGET_H
|
||||
#define PROPERTIESWIDGET_H
|
||||
|
||||
#include <QShortcut>
|
||||
#include <QWidget>
|
||||
#include "ui_propertieswidget.h"
|
||||
#include "qtorrenthandle.h"
|
||||
|
||||
|
||||
class TransferListWidget;
|
||||
class TorrentContentFilterModel;
|
||||
class PropListDelegate;
|
||||
class torrent_file;
|
||||
class PeerListWidget;
|
||||
class TrackerList;
|
||||
class MainWindow;
|
||||
class DownloadedPiecesBar;
|
||||
class PieceAvailabilityBar;
|
||||
class PropTabBar;
|
||||
class LineEdit;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAction;
|
||||
class QTimer;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class PropertiesWidget : public QWidget, private Ui::PropertiesWidget {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(PropertiesWidget)
|
||||
|
||||
public:
|
||||
enum SlideState {REDUCED, VISIBLE};
|
||||
|
||||
public:
|
||||
PropertiesWidget(QWidget *parent, MainWindow* main_window, TransferListWidget *transferList);
|
||||
~PropertiesWidget();
|
||||
QTorrentHandle getCurrentTorrent() 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(const QTorrentHandle &h);
|
||||
void updateTorrentInfos(const QTorrentHandle &h);
|
||||
void loadUrlSeeds();
|
||||
void askWebSeed();
|
||||
void deleteSelectedUrlSeeds();
|
||||
void copySelectedWebSeedsToClipboard() const;
|
||||
void editWebSeed();
|
||||
void displayFilesListMenu(const QPoint& pos);
|
||||
void displayWebSeedListMenu(const QPoint& pos);
|
||||
void filteredFilesChanged();
|
||||
void showPiecesDownloaded(bool show);
|
||||
void showPiecesAvailability(bool show);
|
||||
void renameSelectedFile();
|
||||
|
||||
public slots:
|
||||
void setVisibility(bool visible);
|
||||
void loadDynamicData();
|
||||
void clear();
|
||||
void readSettings();
|
||||
void saveSettings();
|
||||
void reloadPreferences();
|
||||
void openDoubleClickedFile(const QModelIndex &);
|
||||
void updateSavePath(const QTorrentHandle& h);
|
||||
|
||||
private:
|
||||
void openFile(const QModelIndex &index);
|
||||
void openFolder(const QModelIndex &index, bool containing_folder);
|
||||
|
||||
private:
|
||||
TransferListWidget *transferList;
|
||||
MainWindow *main_window;
|
||||
QTorrentHandle h;
|
||||
QTimer *refreshTimer;
|
||||
SlideState state;
|
||||
TorrentContentFilterModel *PropListModel;
|
||||
PropListDelegate *PropDelegate;
|
||||
PeerListWidget *peersList;
|
||||
TrackerList *trackerList;
|
||||
QList<int> slideSizes;
|
||||
DownloadedPiecesBar *downloaded_pieces;
|
||||
PieceAvailabilityBar *pieces_availability;
|
||||
PropTabBar *m_tabBar;
|
||||
LineEdit *m_contentFilerLine;
|
||||
QShortcut *editHotkeyFile;
|
||||
QShortcut *editHotkeyWeb;
|
||||
QShortcut *deleteHotkeyWeb;
|
||||
|
||||
private slots:
|
||||
void filterText(const QString& filter);
|
||||
};
|
||||
|
||||
#endif // PROPERTIESWIDGET_H
|
||||
765
src/gui/properties/propertieswidget.ui
Normal file
765
src/gui/properties/propertieswidget.ui
Normal file
@@ -0,0 +1,765 @@
|
||||
<?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>551</width>
|
||||
<height>452</height>
|
||||
</rect>
|
||||
</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>549</width>
|
||||
<height>447</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 extracomment="Time (duration) the torrent is active (not paused)">Time active:</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>
|
||||
<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="label_3">
|
||||
<property name="text">
|
||||
<string>Piece size:</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_7">
|
||||
<item>
|
||||
<widget class="QLabel" name="pieceSize_lbl">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">piece size</string>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_8">
|
||||
<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="4" 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="4" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QTextBrowser" name="comment_text">
|
||||
<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>
|
||||
</widget>
|
||||
</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>
|
||||
</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">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_4">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="contentFilterLayout">
|
||||
<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 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>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_11">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Torrent content:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="TorrentContentTreeView" 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>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>TorrentContentTreeView</class>
|
||||
<extends>QTreeView</extends>
|
||||
<header location="global">torrentcontenttreeview.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
198
src/gui/properties/proplistdelegate.h
Normal file
198
src/gui/properties/proplistdelegate.h
Normal file
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* 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_OS_WIN
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
|
||||
#include <QPlastiqueStyle>
|
||||
#else
|
||||
#include <QProxyStyle>
|
||||
#endif
|
||||
#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:{
|
||||
if (index.data().toDouble() >= 0) {
|
||||
QStyleOptionProgressBarV2 newopt;
|
||||
qreal progress = index.data().toDouble()*100.;
|
||||
newopt.rect = opt.rect;
|
||||
newopt.text = misc::accurateDoubleToString(progress, 1) + "%";
|
||||
newopt.progress = (int)progress;
|
||||
newopt.maximum = 100;
|
||||
newopt.minimum = 0;
|
||||
newopt.state |= QStyle::State_Enabled;
|
||||
newopt.textVisible = true;
|
||||
#ifndef Q_OS_WIN
|
||||
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
|
||||
#else
|
||||
// XXX: To avoid having the progress text on the right of the bar
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
|
||||
QPlastiqueStyle st;
|
||||
#else
|
||||
QProxyStyle st("fusion");
|
||||
#endif
|
||||
st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0);
|
||||
#endif
|
||||
} else {
|
||||
// Do not display anything if the file is disabled (progress == -1)
|
||||
QItemDelegate::drawBackground(painter, opt, index);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PRIORITY: {
|
||||
QItemDelegate::drawBackground(painter, opt, index);
|
||||
QString text = "";
|
||||
switch(index.data().toInt()) {
|
||||
case -1:
|
||||
text = tr("Mixed", "Mixed (priorities");
|
||||
break;
|
||||
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();
|
||||
}
|
||||
|
||||
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() || !h.has_metadata() || h.status(0x0).is_seeding)
|
||||
return 0;
|
||||
}
|
||||
if (index.data().toInt() <= 0) {
|
||||
// IGNORED or MIXED
|
||||
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
|
||||
109
src/gui/properties/proptabbar.cpp
Normal file
109
src/gui/properties/proptabbar.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt4 and libtorrent.
|
||||
* Copyright (C) 2010 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 <QButtonGroup>
|
||||
#include <QPushButton>
|
||||
#include <QSpacerItem>
|
||||
#include <QKeySequence>
|
||||
|
||||
#include "proptabbar.h"
|
||||
#include "iconprovider.h"
|
||||
|
||||
PropTabBar::PropTabBar(QWidget *parent) :
|
||||
QHBoxLayout(parent), m_currentIndex(-1)
|
||||
{
|
||||
setSpacing(2);
|
||||
m_btnGroup = new QButtonGroup(this);
|
||||
// General tab
|
||||
QPushButton *main_infos_button = new QPushButton(IconProvider::instance()->getIcon("document-properties"), tr("General"), parent);
|
||||
main_infos_button->setShortcut(QKeySequence(QString::fromUtf8("Alt+P")));
|
||||
addWidget(main_infos_button);
|
||||
m_btnGroup->addButton(main_infos_button, MAIN_TAB);
|
||||
// Trackers tab
|
||||
QPushButton *trackers_button = new QPushButton(IconProvider::instance()->getIcon("network-server"), tr("Trackers"), parent);
|
||||
addWidget(trackers_button);
|
||||
m_btnGroup->addButton(trackers_button, TRACKERS_TAB);
|
||||
// Peers tab
|
||||
QPushButton *peers_button = new QPushButton(IconProvider::instance()->getIcon("edit-find-user"), tr("Peers"), parent);
|
||||
addWidget(peers_button);
|
||||
m_btnGroup->addButton(peers_button, PEERS_TAB);
|
||||
// URL seeds tab
|
||||
QPushButton *urlseeds_button = new QPushButton(IconProvider::instance()->getIcon("network-server"), tr("HTTP Sources"), parent);
|
||||
addWidget(urlseeds_button);
|
||||
m_btnGroup->addButton(urlseeds_button, URLSEEDS_TAB);
|
||||
// Files tab
|
||||
QPushButton *files_button = new QPushButton(IconProvider::instance()->getIcon("inode-directory"), tr("Content"), parent);
|
||||
addWidget(files_button);
|
||||
m_btnGroup->addButton(files_button, FILES_TAB);
|
||||
// Spacer
|
||||
addItem(new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
|
||||
// SIGNAL/SLOT
|
||||
connect(m_btnGroup, SIGNAL(buttonClicked(int)), SLOT(setCurrentIndex(int)));
|
||||
// Disable buttons focus
|
||||
foreach (QAbstractButton *btn, m_btnGroup->buttons()) {
|
||||
btn->setFocusPolicy(Qt::NoFocus);
|
||||
}
|
||||
}
|
||||
|
||||
PropTabBar::~PropTabBar() {
|
||||
delete m_btnGroup;
|
||||
}
|
||||
|
||||
int PropTabBar::currentIndex() const
|
||||
{
|
||||
return m_currentIndex;
|
||||
}
|
||||
|
||||
void PropTabBar::setCurrentIndex(int index)
|
||||
{
|
||||
if (index >= m_btnGroup->buttons().size())
|
||||
index = 0;
|
||||
// If asked to hide or if the currently selected tab is clicked
|
||||
if (index < 0 || m_currentIndex == index) {
|
||||
if (m_currentIndex >= 0) {
|
||||
m_btnGroup->button(m_currentIndex)->setDown(false);
|
||||
m_currentIndex = -1;
|
||||
emit visibilityToggled(false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Unselect previous tab
|
||||
if (m_currentIndex >= 0) {
|
||||
m_btnGroup->button(m_currentIndex)->setDown(false);
|
||||
} else {
|
||||
// Nothing was selected, show!
|
||||
emit visibilityToggled(true);
|
||||
}
|
||||
// Select the new button
|
||||
m_btnGroup->button(index)->setDown(true);
|
||||
m_currentIndex = index;
|
||||
// Emit the signal
|
||||
emit tabChanged(index);
|
||||
}
|
||||
66
src/gui/properties/proptabbar.h
Normal file
66
src/gui/properties/proptabbar.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt4 and libtorrent.
|
||||
* Copyright (C) 2010 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 PROPTABBAR_H
|
||||
#define PROPTABBAR_H
|
||||
|
||||
#include <QHBoxLayout>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QButtonGroup;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class PropTabBar : public QHBoxLayout
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(PropTabBar)
|
||||
|
||||
public:
|
||||
enum PropertyTab {MAIN_TAB, TRACKERS_TAB, PEERS_TAB, URLSEEDS_TAB, FILES_TAB};
|
||||
|
||||
public:
|
||||
explicit PropTabBar(QWidget *parent = 0);
|
||||
~PropTabBar();
|
||||
int currentIndex() const;
|
||||
|
||||
signals:
|
||||
void tabChanged(int index);
|
||||
void visibilityToggled(bool visible);
|
||||
|
||||
public slots:
|
||||
void setCurrentIndex(int index);
|
||||
|
||||
private:
|
||||
QButtonGroup *m_btnGroup;
|
||||
int m_currentIndex;
|
||||
|
||||
};
|
||||
|
||||
#endif // PROPTABBAR_H
|
||||
512
src/gui/properties/trackerlist.cpp
Normal file
512
src/gui/properties/trackerlist.cpp
Normal file
@@ -0,0 +1,512 @@
|
||||
/*
|
||||
* 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 <QDebug>
|
||||
#include <QUrl>
|
||||
#include <libtorrent/version.hpp>
|
||||
#include <libtorrent/peer_info.hpp>
|
||||
#include "trackerlist.h"
|
||||
#include "propertieswidget.h"
|
||||
#include "trackersadditiondlg.h"
|
||||
#include "iconprovider.h"
|
||||
#include "qbtsession.h"
|
||||
#include "preferences.h"
|
||||
#include "misc.h"
|
||||
#include "autoexpandabledialog.h"
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
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 << "#";
|
||||
header << tr("URL");
|
||||
header << tr("Status");
|
||||
header << tr("Peers");
|
||||
header << tr("Message");
|
||||
setHeaderItem(new QTreeWidgetItem(header));
|
||||
dht_item = new QTreeWidgetItem(QStringList() << "" << "** [DHT] **");
|
||||
insertTopLevelItem(0, dht_item);
|
||||
setRowColor(0, QColor("grey"));
|
||||
pex_item = new QTreeWidgetItem(QStringList() << "" << "** [PeX] **");
|
||||
insertTopLevelItem(1, pex_item);
|
||||
setRowColor(1, QColor("grey"));
|
||||
lsd_item = new QTreeWidgetItem(QStringList() << "" << "** [LSD] **");
|
||||
insertTopLevelItem(2, lsd_item);
|
||||
setRowColor(2, QColor("grey"));
|
||||
editHotkey = new QShortcut(QKeySequence("F2"), this, SLOT(editSelectedTracker()), 0, Qt::WidgetShortcut);
|
||||
connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(editSelectedTracker()));
|
||||
deleteHotkey = new QShortcut(QKeySequence(QKeySequence::Delete), this, SLOT(deleteSelectedTrackers()), 0, Qt::WidgetShortcut);
|
||||
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
TrackerList::~TrackerList() {
|
||||
delete editHotkey;
|
||||
delete deleteHotkey;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
QList<QTreeWidgetItem*> TrackerList::getSelectedTrackerItems() const {
|
||||
const QList<QTreeWidgetItem*> selected_items = selectedItems();
|
||||
QList<QTreeWidgetItem*> selected_trackers;
|
||||
foreach (QTreeWidgetItem *item, selected_items) {
|
||||
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() {
|
||||
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
|
||||
if (!h.is_paused())
|
||||
h.force_reannounce();
|
||||
loadTrackers();
|
||||
}
|
||||
|
||||
void TrackerList::moveSelectionDown() {
|
||||
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
|
||||
if (!h.is_paused())
|
||||
h.force_reannounce();
|
||||
loadTrackers();
|
||||
}
|
||||
|
||||
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) {
|
||||
QString working = tr("Working");
|
||||
QString disabled = tr("Disabled");
|
||||
|
||||
// load DHT information
|
||||
if (QBtSession::instance()->isDHTEnabled() && !h.priv())
|
||||
dht_item->setText(COL_STATUS, working);
|
||||
else
|
||||
dht_item->setText(COL_STATUS, disabled);
|
||||
|
||||
// Load PeX Information
|
||||
if (QBtSession::instance()->isPexEnabled() && !h.priv())
|
||||
pex_item->setText(COL_STATUS, working);
|
||||
else
|
||||
pex_item->setText(COL_STATUS, disabled);
|
||||
|
||||
// Load LSD Information
|
||||
if (QBtSession::instance()->isLSDEnabled() && !h.priv())
|
||||
lsd_item->setText(COL_STATUS, working);
|
||||
else
|
||||
lsd_item->setText(COL_STATUS, disabled);
|
||||
|
||||
if (h.priv()) {
|
||||
QString privateMsg = tr("This torrent is private");
|
||||
dht_item->setText(COL_MSG, privateMsg);
|
||||
pex_item->setText(COL_MSG, privateMsg);
|
||||
lsd_item->setText(COL_MSG, privateMsg);
|
||||
}
|
||||
|
||||
// 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 = peers.begin();
|
||||
std::vector<peer_info>::iterator end = peers.end();
|
||||
for ( ; it != 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;
|
||||
}
|
||||
dht_item->setText(COL_PEERS, QString::number(nb_dht));
|
||||
pex_item->setText(COL_PEERS, QString::number(nb_pex));
|
||||
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 = QBtSession::instance()->getTrackersInfo(h.hash());
|
||||
QStringList old_trackers_urls = tracker_items.keys();
|
||||
const std::vector<announce_entry> trackers = h.trackers();
|
||||
std::vector<announce_entry>::const_iterator it = trackers.begin();
|
||||
std::vector<announce_entry>::const_iterator end = trackers.end();
|
||||
for ( ; it != 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);
|
||||
}
|
||||
item->setText(COL_TIER, QString::number(it->tier));
|
||||
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
|
||||
QString error_message = data.last_message.trimmed();
|
||||
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, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
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()) {
|
||||
for (int i=0; i<trackers.count(); i++) {
|
||||
const QString& tracker = trackers[i];
|
||||
if (tracker.trimmed().isEmpty()) continue;
|
||||
announce_entry url(tracker.toStdString());
|
||||
url.tier = (topLevelItemCount() - NB_STICKY_ITEM) + i;
|
||||
h.add_tracker(url);
|
||||
}
|
||||
// Reannounce to new trackers
|
||||
if (!h.is_paused())
|
||||
h.force_reannounce();
|
||||
// Reload tracker list
|
||||
loadTrackers();
|
||||
}
|
||||
}
|
||||
|
||||
void TrackerList::copyTrackerUrl() {
|
||||
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
|
||||
if (selected_items.isEmpty()) return;
|
||||
QStringList urls_to_copy;
|
||||
foreach (QTreeWidgetItem *item, selected_items) {
|
||||
QString tracker_url = item->data(COL_URL, Qt::DisplayRole).toString();
|
||||
qDebug() << QString("Copy: ") + tracker_url;
|
||||
urls_to_copy << tracker_url;
|
||||
}
|
||||
QApplication::clipboard()->setText(urls_to_copy.join("\n"));
|
||||
}
|
||||
|
||||
|
||||
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> remaining_trackers;
|
||||
std::vector<announce_entry> trackers = h.trackers();
|
||||
|
||||
std::vector<announce_entry>::iterator it = trackers.begin();
|
||||
std::vector<announce_entry>::iterator itend = trackers.end();
|
||||
for ( ; it != itend; ++it) {
|
||||
if (!urls_to_remove.contains(misc::toQString((*it).url))) {
|
||||
remaining_trackers.push_back(*it);
|
||||
}
|
||||
}
|
||||
h.replace_trackers(remaining_trackers);
|
||||
if (!h.is_paused())
|
||||
h.force_reannounce();
|
||||
// Reload Trackers
|
||||
loadTrackers();
|
||||
}
|
||||
|
||||
void TrackerList::editSelectedTracker() {
|
||||
try {
|
||||
QTorrentHandle h = properties->getCurrentTorrent();
|
||||
|
||||
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
|
||||
if (selected_items.isEmpty())
|
||||
return;
|
||||
// During multi-select only process item selected last
|
||||
QUrl tracker_url = selected_items.last()->text(COL_URL);
|
||||
|
||||
bool ok;
|
||||
QUrl new_tracker_url = AutoExpandableDialog::getText(this, tr("Tracker editing"), tr("Tracker URL:"),
|
||||
QLineEdit::Normal, tracker_url.toString(), &ok).trimmed();
|
||||
if (!ok)
|
||||
return;
|
||||
|
||||
if (!new_tracker_url.isValid()) {
|
||||
QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL entered is invalid."));
|
||||
return;
|
||||
}
|
||||
if (new_tracker_url == tracker_url)
|
||||
return;
|
||||
|
||||
std::vector<announce_entry> trackers = h.trackers();
|
||||
std::vector<announce_entry>::iterator it = trackers.begin();
|
||||
std::vector<announce_entry>::iterator itend = trackers.end();
|
||||
bool match = false;
|
||||
|
||||
for ( ; it != itend; ++it) {
|
||||
if (new_tracker_url == QUrl(misc::toQString(it->url))) {
|
||||
QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL already exists."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (tracker_url == QUrl(misc::toQString(it->url)) && !match) {
|
||||
announce_entry new_entry(new_tracker_url.toString().toStdString());
|
||||
new_entry.tier = it->tier;
|
||||
match = true;
|
||||
*it = new_entry;
|
||||
}
|
||||
}
|
||||
|
||||
h.replace_trackers(trackers);
|
||||
if (!h.is_paused()) {
|
||||
h.force_reannounce();
|
||||
h.force_dht_announce();
|
||||
}
|
||||
} catch(invalid_handle&) {
|
||||
return;
|
||||
}
|
||||
|
||||
loadTrackers();
|
||||
}
|
||||
|
||||
#if LIBTORRENT_VERSION_NUM >= 10000
|
||||
void TrackerList::reannounceSelected() {
|
||||
try {
|
||||
QTorrentHandle h = properties->getCurrentTorrent();
|
||||
|
||||
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
|
||||
if (selected_items.isEmpty())
|
||||
return;
|
||||
|
||||
std::vector<announce_entry> trackers = h.trackers();
|
||||
for (size_t i = 0; i < trackers.size(); ++i) {
|
||||
foreach (QTreeWidgetItem* w, selected_items) {
|
||||
if (w->text(COL_URL) == misc::toQString(trackers[i].url)) {
|
||||
h.force_reannounce(0, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch(invalid_handle&) {
|
||||
return;
|
||||
}
|
||||
|
||||
loadTrackers();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void TrackerList::showTrackerListMenu(QPoint) {
|
||||
QTorrentHandle h = properties->getCurrentTorrent();
|
||||
if (!h.is_valid()) return;
|
||||
//QList<QTreeWidgetItem*> selected_items = getSelectedTrackerItems();
|
||||
QMenu menu;
|
||||
// Add actions
|
||||
QAction *addAct = menu.addAction(IconProvider::instance()->getIcon("list-add"), tr("Add a new tracker..."));
|
||||
QAction *copyAct = 0;
|
||||
QAction *delAct = 0;
|
||||
QAction *editAct = 0;
|
||||
if (!getSelectedTrackerItems().isEmpty()) {
|
||||
delAct = menu.addAction(IconProvider::instance()->getIcon("list-remove"), tr("Remove tracker"));
|
||||
copyAct = menu.addAction(IconProvider::instance()->getIcon("edit-copy"), tr("Copy tracker url"));
|
||||
editAct = menu.addAction(IconProvider::instance()->getIcon("edit-rename"),tr("Edit selected tracker URL"));
|
||||
}
|
||||
#if LIBTORRENT_VERSION_NUM >= 10000
|
||||
QAction *reannounceSelAct = NULL;
|
||||
#endif
|
||||
QAction *reannounceAct = NULL;
|
||||
if (!h.is_paused()) {
|
||||
#if LIBTORRENT_VERSION_NUM >= 10000
|
||||
reannounceSelAct = menu.addAction(IconProvider::instance()->getIcon("view-refresh"), tr("Force reannounce to selected trackers"));
|
||||
#endif
|
||||
menu.addSeparator();
|
||||
reannounceAct = menu.addAction(IconProvider::instance()->getIcon("view-refresh"), tr("Force reannounce to all trackers"));
|
||||
}
|
||||
QAction *act = menu.exec(QCursor::pos());
|
||||
if (act == 0) return;
|
||||
if (act == addAct) {
|
||||
askForTrackers();
|
||||
return;
|
||||
}
|
||||
if (act == copyAct) {
|
||||
copyTrackerUrl();
|
||||
return;
|
||||
}
|
||||
if (act == delAct) {
|
||||
deleteSelectedTrackers();
|
||||
return;
|
||||
}
|
||||
#if LIBTORRENT_VERSION_NUM >= 10000
|
||||
if (act == reannounceSelAct) {
|
||||
reannounceSelected();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (act == reannounceAct) {
|
||||
properties->getCurrentTorrent().force_reannounce();
|
||||
return;
|
||||
}
|
||||
if (act == editAct) {
|
||||
editSelectedTracker();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void TrackerList::loadSettings() {
|
||||
if (!header()->restoreState(Preferences::instance()->getPropTrackerListState())) {
|
||||
setColumnWidth(0, 30);
|
||||
setColumnWidth(1, 300);
|
||||
}
|
||||
}
|
||||
|
||||
void TrackerList::saveSettings() const {
|
||||
Preferences::instance()->setPropTrackerListState(header()->saveState());
|
||||
}
|
||||
88
src/gui/properties/trackerlist.h
Normal file
88
src/gui/properties/trackerlist.h
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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 <QShortcut>
|
||||
#include <QTreeWidget>
|
||||
#include <QList>
|
||||
#include <QClipboard>
|
||||
|
||||
#include <libtorrent/version.hpp>
|
||||
#include "qtorrenthandle.h"
|
||||
#include "propertieswidget.h"
|
||||
|
||||
enum TrackerListColumn {COL_TIER, COL_URL, COL_STATUS, COL_PEERS, COL_MSG};
|
||||
#define NB_STICKY_ITEM 3
|
||||
|
||||
class TrackerList: public QTreeWidget {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(TrackerList)
|
||||
|
||||
private:
|
||||
PropertiesWidget *properties;
|
||||
QHash<QString, QTreeWidgetItem*> tracker_items;
|
||||
QTreeWidgetItem* dht_item;
|
||||
QTreeWidgetItem* pex_item;
|
||||
QTreeWidgetItem* lsd_item;
|
||||
QShortcut *editHotkey;
|
||||
QShortcut *deleteHotkey;
|
||||
|
||||
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 copyTrackerUrl();
|
||||
#if LIBTORRENT_VERSION_NUM >= 10000
|
||||
void reannounceSelected();
|
||||
#endif
|
||||
void deleteSelectedTrackers();
|
||||
void editSelectedTracker();
|
||||
void showTrackerListMenu(QPoint);
|
||||
void loadSettings();
|
||||
void saveSettings() const;
|
||||
|
||||
};
|
||||
|
||||
#endif // TRACKERLIST_H
|
||||
149
src/gui/properties/trackersadditiondlg.h
Normal file
149
src/gui/properties/trackersadditiondlg.h
Normal file
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* 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 "iconprovider.h"
|
||||
#include "misc.h"
|
||||
#include "ui_trackersadditiondlg.h"
|
||||
#include "downloadthread.h"
|
||||
#include "qtorrenthandle.h"
|
||||
#include "fs_utils.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);
|
||||
// Icons
|
||||
uTorrentListButton->setIcon(IconProvider::instance()->getIcon("download"));
|
||||
}
|
||||
|
||||
~TrackersAdditionDlg() {}
|
||||
|
||||
QStringList newTrackers() const {
|
||||
return trackers_list->toPlainText().trimmed().split("\n");
|
||||
}
|
||||
|
||||
public slots:
|
||||
void on_uTorrentListButton_clicked() {
|
||||
uTorrentListButton->setEnabled(false);
|
||||
DownloadThread *d = new DownloadThread(this);
|
||||
connect(d, SIGNAL(downloadFinished(QString,QString)), SLOT(parseUTorrentList(QString,QString)));
|
||||
connect(d, SIGNAL(downloadFailure(QString,QString)), SLOT(getTrackerError(QString,QString)));
|
||||
//Just to show that it takes times
|
||||
setCursor(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);
|
||||
setCursor(Qt::ArrowCursor);
|
||||
uTorrentListButton->setEnabled(true);
|
||||
sender()->deleteLater();
|
||||
fsutils::forceRemove(path);
|
||||
return;
|
||||
}
|
||||
QList<QUrl> existingTrackers;
|
||||
// Load from torrent handle
|
||||
std::vector<libtorrent::announce_entry> tor_trackers = h.trackers();
|
||||
|
||||
std::vector<libtorrent::announce_entry>::iterator itr = tor_trackers.begin();
|
||||
std::vector<libtorrent::announce_entry>::iterator itrend = tor_trackers.end();
|
||||
while(itr != itrend) {
|
||||
existingTrackers << QUrl(misc::toQString(itr->url));
|
||||
++itr;
|
||||
}
|
||||
// Load from current user list
|
||||
QStringList tmp = trackers_list->toPlainText().split("\n");
|
||||
foreach (const 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()) {
|
||||
const 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();
|
||||
fsutils::forceRemove(path);
|
||||
//To restore the cursor ...
|
||||
setCursor(Qt::ArrowCursor);
|
||||
uTorrentListButton->setEnabled(true);
|
||||
// Display information message if necessary
|
||||
if (nb == 0) {
|
||||
QMessageBox::information(this, tr("No change"), tr("No additional trackers were found."), QMessageBox::Ok);
|
||||
}
|
||||
sender()->deleteLater();
|
||||
}
|
||||
|
||||
void getTrackerError(const QString&, const QString &error) {
|
||||
//To restore the cursor ...
|
||||
setCursor(Qt::ArrowCursor);
|
||||
uTorrentListButton->setEnabled(true);
|
||||
QMessageBox::warning(this, tr("Download error"), tr("The trackers list could not be downloaded, reason: %1").arg(error), QMessageBox::Ok);
|
||||
sender()->deleteLater();
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
static QStringList askForTrackers(QTorrentHandle h) {
|
||||
QStringList trackers;
|
||||
TrackersAdditionDlg dlg(h);
|
||||
if (dlg.exec() == QDialog::Accepted) {
|
||||
return dlg.newTrackers();
|
||||
}
|
||||
return trackers;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
121
src/gui/properties/trackersadditiondlg.ui
Normal file
121
src/gui/properties/trackersadditiondlg.ui
Normal file
@@ -0,0 +1,121 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TrackersAdditionDlg</class>
|
||||
<widget class="QDialog" name="TrackersAdditionDlg">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>367</width>
|
||||
<height>274</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Trackers addition dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>List of trackers to add (one per line):</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="trackers_list">
|
||||
<property name="lineWrapMode">
|
||||
<enum>QTextEdit::NoWrap</enum>
|
||||
</property>
|
||||
<property name="html">
|
||||
<string notr="true"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;">
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans'; font-size:10pt;"></p></body></html></string>
|
||||
</property>
|
||||
<property name="acceptRichText">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>µTorrent compatible list URL:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="list_url"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="uTorrentListButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>31</width>
|
||||
<height>31</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>31</width>
|
||||
<height>31</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>TrackersAdditionDlg</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>TrackersAdditionDlg</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user