mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-01 13:18:06 -06:00
Implement tracker list in the side panel. Closes #170.
This commit is contained in:
@@ -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()));
|
||||
|
||||
@@ -69,6 +69,10 @@ public:
|
||||
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();
|
||||
|
||||
@@ -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())
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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
|
||||
@@ -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())
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,10 @@ public:
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user