Browse Source

fixup! Use QInputDilog for tracker editing

adaptive-webui-19844
Nick Tiskov 12 years ago
parent
commit
a7a4557b29
  1. 42
      src/properties/trackerlist.cpp

42
src/properties/trackerlist.cpp

@ -346,59 +346,61 @@ void TrackerList::deleteSelectedTrackers() {
} }
void TrackerList::editSelectedTracker() { void TrackerList::editSelectedTracker() {
try {
QTorrentHandle h = properties->getCurrentTorrent(); QTorrentHandle h = properties->getCurrentTorrent();
if (!h.is_valid())
return;
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems(); QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
if (selected_items.isEmpty()) return; if (selected_items.isEmpty())
return;
// During multi-select only process item selected last // During multi-select only process item selected last
QUrl tracker_url = selected_items.last()->text(COL_URL); 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;
if (!h.is_valid())
return; return;
QUrl new_tracker_url = editDlg.textValue().trimmed(); QUrl new_tracker_url = editDlg.textValue().trimmed();
if (new_tracker_url.isEmpty() || !new_tracker_url.isValid() || new_tracker_url == tracker_url) if (!new_tracker_url.isValid()) {
QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL entered is invalid."));
return; return;
}
std::vector<announce_entry> trackers = h.trackers(); else if (new_tracker_url == tracker_url)
if (trackers.empty())
return; return;
std::vector<announce_entry> trackers = h.trackers();
std::vector<announce_entry>::iterator it = trackers.begin(); std::vector<announce_entry>::iterator it = trackers.begin();
std::vector<announce_entry>::iterator itend = trackers.end(); std::vector<announce_entry>::iterator itend = trackers.end();
bool match = false; bool match = false;
for ( ; it != itend; ++it) { for ( ; it != itend; ++it) {
if (new_tracker_url == QUrl(misc::toQString(it->url))) if (new_tracker_url == QUrl(misc::toQString(it->url))) {
return; // Tracker already exists; silently ignoring QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL already exists."));
return;
}
if (tracker_url == QUrl(misc::toQString(it->url)) && !match) { if (tracker_url == QUrl(misc::toQString(it->url)) && !match) {
announce_entry temp_URI(new_tracker_url.toString().toStdString()); announce_entry new_entry(new_tracker_url.toString().toStdString());
temp_URI.tier = it->tier; new_entry.tier = it->tier;
match = true; match = true;
*it = temp_URI; *it = new_entry;
} }
} }
if (!match)
return; // Found no tracker to replace
h.replace_trackers(trackers); h.replace_trackers(trackers);
h.force_reannounce(); h.force_reannounce();
h.force_dht_announce();
} catch(invalid_handle&) {
return;
}
loadTrackers(); loadTrackers();
} }

Loading…
Cancel
Save