Browse Source

- New peers can manually be added to a torrent

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
94f3323270
  1. 1
      Changelog
  2. BIN
      src/Icons/oxygen/add_peer.png
  3. 1
      src/icons.qrc
  4. 109
      src/peer.ui
  5. 111
      src/peeraddition.h
  6. 26
      src/peerlistwidget.cpp
  7. 1
      src/peerlistwidget.h
  8. 10
      src/qtorrenthandle.cpp
  9. 2
      src/qtorrenthandle.h
  10. 6
      src/src.pro

1
Changelog

@ -22,6 +22,7 @@
- FEATURE: Make sure torrent files are always sorted by name - FEATURE: Make sure torrent files are always sorted by name
- FEATURE: Seeds and Peers columns are now sortable - FEATURE: Seeds and Peers columns are now sortable
- FEATURE: Torrents can be rechecked from Web UI (Stephanos Antaris) - FEATURE: Torrents can be rechecked from Web UI (Stephanos Antaris)
- FEATURE: New peers can manually be added to the torrents
- COSMETIC: Merged download / upload lists - COSMETIC: Merged download / upload lists
- COSMETIC: Torrents can be filtered based on their status - COSMETIC: Torrents can be filtered based on their status
- COSMETIC: Torrent properties are now displayed in main window - COSMETIC: Torrent properties are now displayed in main window

BIN
src/Icons/oxygen/add_peer.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 644 B

1
src/icons.qrc

@ -142,5 +142,6 @@
<file>Icons/oxygen/unsubscribe.png</file> <file>Icons/oxygen/unsubscribe.png</file>
<file>Icons/oxygen/draw-rectangle.png</file> <file>Icons/oxygen/draw-rectangle.png</file>
<file>Icons/oxygen/subscribe16.png</file> <file>Icons/oxygen/subscribe16.png</file>
<file>Icons/oxygen/add_peer.png</file>
</qresource> </qresource>
</RCC> </RCC>

109
src/peer.ui

@ -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>

111
src/peeraddition.h

@ -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 PEERADDITION_H
#define PEERADDITION_H
#include <QDialog>
#include <QRegExp>
#include <QMessageBox>
#include "ui_peer.h"
#include <boost/asio/ip/tcp.hpp>
class PeerAdditionDlg: public QDialog, private Ui::addPeerDialog {
Q_OBJECT
private:
bool valid;
public:
PeerAdditionDlg(QWidget *parent=0): QDialog(parent), valid(false) {
setupUi(this);
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(validateInput()));
}
~PeerAdditionDlg(){}
QString getIP() const {
return lineIP->text();
}
unsigned short getPort() const {
return spinPort->value();
}
bool isValid() const {
return valid;
}
static boost::asio::ip::tcp::endpoint askForPeerEndpoint() {
boost::asio::ip::tcp::endpoint ep;
PeerAdditionDlg dlg;
dlg.exec();
if(dlg.isValid()) {
const QRegExp is_ipv6(QString::fromUtf8("[0-9a-f]{4}(:[0-9a-f]{4}){7}"), Qt::CaseInsensitive, QRegExp::RegExp);
const QRegExp is_ipv4(QString::fromUtf8("(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))(\\.(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))){3}"), Qt::CaseInsensitive, QRegExp::RegExp);
QString IP = dlg.getIP();
if(is_ipv4.exactMatch(IP)) {
// IPv4
ep = boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v4::from_string(IP.toLocal8Bit().data()), dlg.getPort());
} else {
// IPv6
ep = boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v6::from_string(IP.toLocal8Bit().data()), dlg.getPort());
}
}
return ep;
}
protected slots:
void validateInput() {
const QRegExp is_ipv6(QString::fromUtf8("[0-9a-f]{4}(:[0-9a-f]{4}){7}"), Qt::CaseInsensitive, QRegExp::RegExp);
const QRegExp is_ipv4(QString::fromUtf8("(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))(\\.(([0-1]?[0-9]?[0-9])|(2[0-4][0-9])|(25[0-5]))){3}"), Qt::CaseInsensitive, QRegExp::RegExp);
QString IP = getIP();
if(is_ipv4.exactMatch(IP)) {
qDebug("Detected IPv4 address: %s", IP.toLocal8Bit().data());
valid = true;
accept();
} else {
if(is_ipv6.exactMatch(IP)) {
qDebug("Detected IPv6 address: %s", IP.toLocal8Bit().data());
valid = true;
accept();
} else {
QMessageBox::warning(this, tr("Invalid IP"),
tr("The IP you provided is invalid."),
QMessageBox::Ok);
}
}
}
};
#endif // PEERADDITION_H

26
src/peerlistwidget.cpp

@ -34,10 +34,12 @@
#include "preferences.h" #include "preferences.h"
#include "propertieswidget.h" #include "propertieswidget.h"
#include "geoip.h" #include "geoip.h"
#include "peeraddition.h"
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QSet> #include <QSet>
#include <QSettings> #include <QSettings>
#include <QMenu>
#include <vector> #include <vector>
PeerListWidget::PeerListWidget(PropertiesWidget *parent): properties(parent), display_flags(false) { PeerListWidget::PeerListWidget(PropertiesWidget *parent): properties(parent), display_flags(false) {
@ -59,6 +61,9 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent): properties(parent), di
proxyModel->setDynamicSortFilter(true); proxyModel->setDynamicSortFilter(true);
proxyModel->setSourceModel(listModel); proxyModel->setSourceModel(listModel);
setModel(proxyModel); setModel(proxyModel);
// Context menu
setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showPeerListMenu(QPoint)));
// List delegate // List delegate
listDelegate = new PeerListDelegate(this); listDelegate = new PeerListDelegate(this);
setItemDelegate(listDelegate); setItemDelegate(listDelegate);
@ -104,6 +109,27 @@ void PeerListWidget::updatePeerCountryResolutionState() {
} }
} }
void PeerListWidget::showPeerListMenu(QPoint) {
QMenu menu;
QTorrentHandle h = properties->getCurrentTorrent();
if(!h.is_valid()) return;
QAction *addPeerAct = 0;
if(!h.is_queued() && !h.is_checking()) {
addPeerAct = menu.addAction(QIcon(":/Icons/oxygen/add_peer.png"), "Add a new peer");
}
QAction *act = menu.exec(QCursor::pos());
if(act == addPeerAct) {
boost::asio::ip::tcp::endpoint ep = PeerAdditionDlg::askForPeerEndpoint();
if(ep != boost::asio::ip::tcp::endpoint()) {
h.connect_peer(ep);
QMessageBox::information(0, tr("Peer addition"), tr("The peer was added to this torrent."));
} else {
qDebug("No peer was added");
}
return;
}
}
void PeerListWidget::clear() { void PeerListWidget::clear() {
qDebug("clearing peer list"); qDebug("clearing peer list");
peerItems.clear(); peerItems.clear();

1
src/peerlistwidget.h

@ -74,6 +74,7 @@ public slots:
protected slots: protected slots:
void loadSettings(); void loadSettings();
void saveSettings() const; void saveSettings() const;
void showPeerListMenu(QPoint);
}; };
#endif // PEERLISTWIDGET_H #endif // PEERLISTWIDGET_H

10
src/qtorrenthandle.cpp

@ -290,6 +290,11 @@ void QTorrentHandle::file_progress(std::vector<size_type>& fp) {
return h.file_progress(fp); return h.file_progress(fp);
} }
bool QTorrentHandle::is_checking() const {
Q_ASSERT(h.is_valid());
return h.status().state == torrent_status::checking_files || h.status().state == torrent_status::checking_resume_data;
}
size_type QTorrentHandle::all_time_download() { size_type QTorrentHandle::all_time_download() {
Q_ASSERT(h.is_valid()); Q_ASSERT(h.is_valid());
return h.status().all_time_download; return h.status().all_time_download;
@ -498,6 +503,11 @@ void QTorrentHandle::resolve_countries(bool r) {
h.resolve_countries(r); h.resolve_countries(r);
} }
void QTorrentHandle::connect_peer(asio::ip::tcp::endpoint const& adr, int source) const {
Q_ASSERT(h.is_valid());
h.connect_peer(adr, source);
}
// //
// Operators // Operators
// //

2
src/qtorrenthandle.h

@ -109,6 +109,7 @@ class QTorrentHandle {
QStringList files_path() const; QStringList files_path() const;
int num_uploads() const; int num_uploads() const;
bool is_seed() const; bool is_seed() const;
bool is_checking() const;
bool is_auto_managed() const; bool is_auto_managed() const;
qlonglong active_time() const; qlonglong active_time() const;
qlonglong seeding_time() const; qlonglong seeding_time() const;
@ -145,6 +146,7 @@ class QTorrentHandle {
void move_storage(QString path) const; void move_storage(QString path) const;
void super_seeding(bool on) const; void super_seeding(bool on) const;
void resolve_countries(bool r); void resolve_countries(bool r);
void connect_peer(asio::ip::tcp::endpoint const& adr, int source = 0) const;
// //
// Operators // Operators

6
src/src.pro

@ -191,7 +191,8 @@ HEADERS += GUI.h \
peerlistdelegate.h \ peerlistdelegate.h \
reverseresolution.h \ reverseresolution.h \
preferences.h \ preferences.h \
geoip.h geoip.h \
peeraddition.h
FORMS += MainWindow.ui \ FORMS += MainWindow.ui \
options.ui \ options.ui \
about.ui \ about.ui \
@ -208,7 +209,8 @@ FORMS += MainWindow.ui \
trackersAdd.ui \ trackersAdd.ui \
console.ui \ console.ui \
FeedDownloader.ui \ FeedDownloader.ui \
propertiesWidget.ui propertiesWidget.ui \
peer.ui
SOURCES += GUI.cpp \ SOURCES += GUI.cpp \
main.cpp \ main.cpp \
options_imp.cpp \ options_imp.cpp \

Loading…
Cancel
Save