Skip to content

Commit

Permalink
Implement tracker list in the side panel. Closes #170.
Browse files Browse the repository at this point in the history
  • Loading branch information
sledgehammer999 committed Mar 28, 2015
1 parent 36d2bee commit f0d5ce4
Show file tree
Hide file tree
Showing 15 changed files with 391 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/core/qtlibtorrent/qbtsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,7 @@ void QBtSession::loadTorrentTempData(QTorrentHandle &h, QString savePath, bool m

void QBtSession::mergeTorrents(QTorrentHandle& h_ex, const QString& magnet_uri)
{
QString hash = h_ex.hash();
QList<QUrl> new_trackers = misc::magnetUriToTrackers(magnet_uri);
bool trackers_added = false;
foreach (const QUrl& new_tracker, new_trackers) {
Expand All @@ -1293,6 +1294,7 @@ void QBtSession::mergeTorrents(QTorrentHandle& h_ex, const QString& magnet_uri)
if (!found) {
h_ex.add_tracker(announce_entry(new_tracker.toString().toStdString()));
trackers_added = true;
emit trackerAdded(new_tracker.toString(), hash);
}
}
if (trackers_added)
Expand All @@ -1302,6 +1304,7 @@ void QBtSession::mergeTorrents(QTorrentHandle& h_ex, const QString& magnet_uri)
void QBtSession::mergeTorrents(QTorrentHandle &h_ex, boost::intrusive_ptr<torrent_info> t) {
// Check if the torrent contains trackers or url seeds we don't know about
// and add them
QString hash = h_ex.hash();
if (!h_ex.is_valid()) return;
std::vector<announce_entry> existing_trackers = h_ex.trackers();
std::vector<announce_entry> new_trackers = t->trackers();
Expand All @@ -1320,6 +1323,7 @@ void QBtSession::mergeTorrents(QTorrentHandle &h_ex, boost::intrusive_ptr<torren
if (!found) {
h_ex.add_tracker(announce_entry(new_tracker_url));
trackers_added = true;
emit trackerAdded(new_tracker_url.c_str(), hash);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/core/qtlibtorrent/qbtsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ private slots:
void metadataReceivedHidden(const QTorrentHandle &h);
void stateUpdate(const std::vector<libtorrent::torrent_status> &statuses);
void statsReceived(const libtorrent::stats_alert&);
void trackerAdded(const QString &tracker, const QString &hash);

private:
// Bittorrent
Expand Down
5 changes: 5 additions & 0 deletions src/core/qtlibtorrent/torrentmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ QVariant TorrentModelItem::data(int column, int role) const
}
}

QTorrentHandle TorrentModelItem::torrentHandle() const
{
return m_torrent;
}

// TORRENT MODEL

TorrentModel::TorrentModel(QObject *parent) :
Expand Down
1 change: 1 addition & 0 deletions src/core/qtlibtorrent/torrentmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class TorrentModelItem : public QObject {
bool setData(int column, const QVariant &value, int role = Qt::DisplayRole);
inline QString const& hash() const { return m_hash; }
State state() const;
QTorrentHandle torrentHandle() const;

signals:
void labelChanged(QString previous, QString current);
Expand Down
3 changes: 3 additions & 0 deletions src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ MainWindow::MainWindow(QWidget *parent)
connect(search_filter, SIGNAL(textChanged(QString)), transferList, SLOT(applyNameFilter(QString)));
connect(hSplitter, SIGNAL(splitterMoved(int, int)), this, SLOT(writeSettings()));
connect(vSplitter, SIGNAL(splitterMoved(int, int)), this, SLOT(writeSettings()));
connect(properties, SIGNAL(trackerAdded(const QString&, const QString&)), transferListFilters, SLOT(addTracker(const QString&, const QString&)));
connect(properties, SIGNAL(trackerRemoved(const QString&, const QString&)), transferListFilters, SLOT(removeTracker(const QString&, const QString&)));
connect(QBtSession::instance(), SIGNAL(trackerAdded(const QString&, const QString&)), transferListFilters, SLOT(addTracker(const QString&, const QString&)));

vboxLayout->addWidget(tabs);

Expand Down
2 changes: 2 additions & 0 deletions src/gui/properties/propertieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow* main_window, Tra
trackerList = new TrackerList(this);
connect(trackerUpButton, SIGNAL(clicked()), trackerList, SLOT(moveSelectionUp()));
connect(trackerDownButton, SIGNAL(clicked()), trackerList, SLOT(moveSelectionDown()));
connect(trackerList, SIGNAL(trackerAdded(const QString&, const QString&)), this, SIGNAL(trackerAdded(const QString&, const QString&)));
connect(trackerList, SIGNAL(trackerRemoved(const QString&, const QString&)), this, SIGNAL(trackerRemoved(const QString&, const QString&)));
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()));
Expand Down
4 changes: 4 additions & 0 deletions src/gui/properties/propertieswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class PropertiesWidget : public QWidget, private Ui::PropertiesWidget {
PeerListWidget* getPeerList() const { return peersList; }
QTreeView* getFilesList() const { return filesList; }

signals:
void trackerAdded(const QString &tracker, const QString &hash);
void trackerRemoved(const QString &tracker, const QString &hash);

protected:
QPushButton* getButtonFromIndex(int index);
bool applyPriorities();
Expand Down
12 changes: 12 additions & 0 deletions src/gui/properties/trackerlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,19 @@ void TrackerList::loadTrackers() {
void TrackerList::askForTrackers() {
QTorrentHandle h = properties->getCurrentTorrent();
if (!h.is_valid()) return;
QString hash = h.hash();
QStringList trackers = TrackersAdditionDlg::askForTrackers(h);
if (!trackers.empty()) {
if (h.trackers().empty())
emit trackerRemoved("", hash);

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);
emit trackerAdded(tracker, hash);
}
// Reannounce to new trackers
if (!h.is_paused())
Expand Down Expand Up @@ -336,6 +341,7 @@ void TrackerList::deleteSelectedTrackers() {
clear();
return;
}
QString hash = h.hash();
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
if (selected_items.isEmpty()) return;
QStringList urls_to_remove;
Expand All @@ -344,6 +350,7 @@ void TrackerList::deleteSelectedTrackers() {
urls_to_remove << tracker_url;
tracker_items.remove(tracker_url);
delete item;
emit trackerRemoved(tracker_url, hash);
}
// Iterate of trackers and remove selected ones
std::vector<announce_entry> remaining_trackers;
Expand All @@ -357,6 +364,8 @@ void TrackerList::deleteSelectedTrackers() {
}
}
h.replace_trackers(remaining_trackers);
if (remaining_trackers.empty())
emit trackerAdded("", hash);
if (!h.is_paused())
h.force_reannounce();
// Reload Trackers
Expand All @@ -366,6 +375,7 @@ void TrackerList::deleteSelectedTrackers() {
void TrackerList::editSelectedTracker() {
try {
QTorrentHandle h = properties->getCurrentTorrent();
QString hash = h.hash();

QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
if (selected_items.isEmpty())
Expand Down Expand Up @@ -402,6 +412,8 @@ void TrackerList::editSelectedTracker() {
new_entry.tier = it->tier;
match = true;
*it = new_entry;
emit trackerRemoved(tracker_url.toString(), hash);
emit trackerAdded(new_tracker_url.toString(), hash);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/gui/properties/trackerlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class TrackerList: public QTreeWidget {
TrackerList(PropertiesWidget *properties);
~TrackerList();

signals:
void trackerAdded(const QString &tracker, const QString &hash);
void trackerRemoved(const QString &tracker, const QString &hash);

protected:
QList<QTreeWidgetItem*> getSelectedTrackerItems() const;

Expand Down
Loading

0 comments on commit f0d5ce4

Please sign in to comment.