mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-09 14:27:56 +00:00
fixup! Use QInputDilog for tracker editing
This commit is contained in:
parent
4cb783d5bf
commit
a7a4557b29
@ -346,59 +346,61 @@ void TrackerList::deleteSelectedTrackers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TrackerList::editSelectedTracker() {
|
void TrackerList::editSelectedTracker() {
|
||||||
QTorrentHandle h = properties->getCurrentTorrent();
|
try {
|
||||||
if (!h.is_valid())
|
QTorrentHandle h = properties->getCurrentTorrent();
|
||||||
return;
|
|
||||||
|
|
||||||
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
|
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
|
||||||
if (selected_items.isEmpty()) return;
|
if (selected_items.isEmpty())
|
||||||
// During multi-select only process item selected last
|
return;
|
||||||
QUrl tracker_url = selected_items.last()->text(COL_URL);
|
// During multi-select only process item selected last
|
||||||
|
QUrl tracker_url = selected_items.last()->text(COL_URL);
|
||||||
|
|
||||||
QInputDialog editDlg(this);
|
QInputDialog editDlg(this);
|
||||||
editDlg.setInputMode(QInputDialog::TextInput);
|
editDlg.setInputMode(QInputDialog::TextInput);
|
||||||
editDlg.setLabelText(tr("Tracker URL:"));
|
editDlg.setLabelText(tr("Tracker URL:"));
|
||||||
editDlg.setWindowTitle(tr("Edit Tracker Dialog"));
|
editDlg.setWindowTitle(tr("Tracker editing"));
|
||||||
editDlg.setTextValue(tracker_url.toString());
|
editDlg.setTextValue(tracker_url.toString());
|
||||||
QSize dlgSize = editDlg.size();
|
QSize dlgSize = editDlg.size();
|
||||||
dlgSize.setWidth(350);
|
dlgSize.setWidth(350);
|
||||||
editDlg.resize(dlgSize);
|
editDlg.resize(dlgSize);
|
||||||
|
|
||||||
bool dlgResult = editDlg.exec();
|
if(!editDlg.exec())
|
||||||
if(!dlgResult)
|
return;
|
||||||
return;
|
|
||||||
|
|
||||||
if (!h.is_valid())
|
QUrl new_tracker_url = editDlg.textValue().trimmed();
|
||||||
return;
|
if (!new_tracker_url.isValid()) {
|
||||||
|
QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL entered is invalid."));
|
||||||
QUrl new_tracker_url = editDlg.textValue().trimmed();
|
return;
|
||||||
if (new_tracker_url.isEmpty() || !new_tracker_url.isValid() || new_tracker_url == tracker_url)
|
|
||||||
return;
|
|
||||||
|
|
||||||
std::vector<announce_entry> trackers = h.trackers();
|
|
||||||
if (trackers.empty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
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)))
|
|
||||||
return; // Tracker already exists; silently ignoring
|
|
||||||
|
|
||||||
if (tracker_url == QUrl(misc::toQString(it->url)) && !match) {
|
|
||||||
announce_entry temp_URI(new_tracker_url.toString().toStdString());
|
|
||||||
temp_URI.tier = it->tier;
|
|
||||||
match = true;
|
|
||||||
*it = temp_URI;
|
|
||||||
}
|
}
|
||||||
}
|
else if (new_tracker_url == tracker_url)
|
||||||
if (!match)
|
return;
|
||||||
return; // Found no tracker to replace
|
|
||||||
|
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);
|
||||||
|
h.force_reannounce();
|
||||||
|
h.force_dht_announce();
|
||||||
|
} catch(invalid_handle&) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
h.replace_trackers(trackers);
|
|
||||||
h.force_reannounce();
|
|
||||||
loadTrackers();
|
loadTrackers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user