mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-02 09:55:55 +00:00
Allow to edit tracker URI
This commit is contained in:
parent
6f46c60360
commit
cd830768d6
@ -2,7 +2,8 @@ INCLUDEPATH += $$PWD
|
|||||||
|
|
||||||
FORMS += $$PWD/propertieswidget.ui \
|
FORMS += $$PWD/propertieswidget.ui \
|
||||||
$$PWD/trackersadditiondlg.ui \
|
$$PWD/trackersadditiondlg.ui \
|
||||||
$$PWD/peer.ui
|
$$PWD/peer.ui \
|
||||||
|
$$PWD/trackereditdlg.ui
|
||||||
|
|
||||||
HEADERS += $$PWD/propertieswidget.h \
|
HEADERS += $$PWD/propertieswidget.h \
|
||||||
$$PWD/peerlistwidget.h \
|
$$PWD/peerlistwidget.h \
|
||||||
@ -13,7 +14,8 @@ HEADERS += $$PWD/propertieswidget.h \
|
|||||||
$$PWD/peeraddition.h \
|
$$PWD/peeraddition.h \
|
||||||
$$PWD/trackersadditiondlg.h \
|
$$PWD/trackersadditiondlg.h \
|
||||||
$$PWD/pieceavailabilitybar.h \
|
$$PWD/pieceavailabilitybar.h \
|
||||||
$$PWD/proptabbar.h
|
$$PWD/proptabbar.h \
|
||||||
|
$$PWD/trackereditdlg.h
|
||||||
|
|
||||||
SOURCES += $$PWD/propertieswidget.cpp \
|
SOURCES += $$PWD/propertieswidget.cpp \
|
||||||
$$PWD/peerlistwidget.cpp \
|
$$PWD/peerlistwidget.cpp \
|
||||||
|
121
src/properties/trackereditdlg.h
Normal file
121
src/properties/trackereditdlg.h
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* 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 TRACKEREDITDLG_H
|
||||||
|
#define TRACKEREDITDLG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <Qstring>
|
||||||
|
#include "ui_trackereditdlg.h"
|
||||||
|
#include "qtorrenthandle.h"
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
|
using namespace libtorrent;
|
||||||
|
|
||||||
|
class TrackerEditDlg : public QDialog, private Ui::TrackerEditDlg {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTorrentHandle h;
|
||||||
|
QString m_tracker_URI;
|
||||||
|
|
||||||
|
public:
|
||||||
|
TrackerEditDlg(QTorrentHandle h, QString tracker_URI, QWidget *parent=0) : QDialog(parent), h(h) {
|
||||||
|
setupUi(this);
|
||||||
|
this->m_tracker_URI = tracker_URI.trimmed();
|
||||||
|
this->tracker_URI_edit->setText(m_tracker_URI);
|
||||||
|
connect(this->button_OK,SIGNAL(clicked()),this,SLOT(TrackerEditDlg::on_button_OK_clicked()));
|
||||||
|
connect(this->button_Cancel,SIGNAL(clicked()),this,SLOT(TrackerEditDlg::on_button_Cancel_clicked()));
|
||||||
|
}
|
||||||
|
|
||||||
|
~TrackerEditDlg() {}
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void on_button_OK_clicked() {
|
||||||
|
if (replaceTracker())
|
||||||
|
emit TrackerEditDlg::accept();
|
||||||
|
else
|
||||||
|
emit TrackerEditDlg::reject();
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_button_Cancel_clicked() {
|
||||||
|
emit TrackerEditDlg::reject();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool replaceTracker() {
|
||||||
|
if (!h.is_valid()) return false;
|
||||||
|
|
||||||
|
QString new_URI = this->tracker_URI_edit->text().trimmed();
|
||||||
|
if (new_URI.isEmpty()
|
||||||
|
|| new_URI == this->m_tracker_URI) return false;
|
||||||
|
|
||||||
|
std::vector<announce_entry> trackers = h.trackers();
|
||||||
|
if (trackers.empty()) return false;
|
||||||
|
|
||||||
|
std::vector<announce_entry> new_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_URI == misc::toQString((*it).url))
|
||||||
|
return false; // Tracker already exists; silently ignoring
|
||||||
|
|
||||||
|
announce_entry URI(*it);
|
||||||
|
|
||||||
|
if (this->m_tracker_URI == misc::toQString((*it).url) && !match) {
|
||||||
|
announce_entry temp_URI(new_URI.toStdString());
|
||||||
|
URI = temp_URI;
|
||||||
|
URI.tier = (*it).tier;
|
||||||
|
match = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
new_trackers.push_back(URI);
|
||||||
|
}
|
||||||
|
if (match == false) return false; // Found no tracker to replace
|
||||||
|
|
||||||
|
h.replace_trackers(new_trackers);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
static bool editSelectedTracker(QTorrentHandle h, QString tracker_URI) {
|
||||||
|
TrackerEditDlg dlg(h,tracker_URI);
|
||||||
|
if (dlg.exec() != QDialog::Accepted) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
62
src/properties/trackereditdlg.ui
Normal file
62
src/properties/trackereditdlg.ui
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>TrackerEditDlg</class>
|
||||||
|
<widget class="QDialog" name="TrackerEditDlg">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>370</width>
|
||||||
|
<height>88</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Edit Tracker Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Tracker URI:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="tracker_URI_edit"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="button_OK">
|
||||||
|
<property name="text">
|
||||||
|
<string>OK</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="button_Cancel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Cancel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
@ -40,6 +40,7 @@
|
|||||||
#include "trackerlist.h"
|
#include "trackerlist.h"
|
||||||
#include "propertieswidget.h"
|
#include "propertieswidget.h"
|
||||||
#include "trackersadditiondlg.h"
|
#include "trackersadditiondlg.h"
|
||||||
|
#include "trackereditdlg.h"
|
||||||
#include "iconprovider.h"
|
#include "iconprovider.h"
|
||||||
#include "qbtsession.h"
|
#include "qbtsession.h"
|
||||||
#include "qinisettings.h"
|
#include "qinisettings.h"
|
||||||
@ -343,6 +344,21 @@ void TrackerList::deleteSelectedTrackers() {
|
|||||||
loadTrackers();
|
loadTrackers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TrackerList::editSelectedTracker() {
|
||||||
|
QTorrentHandle h = properties->getCurrentTorrent();
|
||||||
|
if (!h.is_valid()) return;
|
||||||
|
|
||||||
|
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
|
||||||
|
if (selected_items.isEmpty()) return;
|
||||||
|
// During multi-select only process item selected last
|
||||||
|
QString tracker_URI = selected_items.last()->data(COL_URL, Qt::DisplayRole).toString();
|
||||||
|
if (!TrackerEditDlg::editSelectedTracker(h,tracker_URI))
|
||||||
|
return;
|
||||||
|
|
||||||
|
h.force_reannounce();
|
||||||
|
loadTrackers();
|
||||||
|
}
|
||||||
|
|
||||||
void TrackerList::showTrackerListMenu(QPoint) {
|
void TrackerList::showTrackerListMenu(QPoint) {
|
||||||
QTorrentHandle h = properties->getCurrentTorrent();
|
QTorrentHandle h = properties->getCurrentTorrent();
|
||||||
if (!h.is_valid()) return;
|
if (!h.is_valid()) return;
|
||||||
@ -352,8 +368,10 @@ void TrackerList::showTrackerListMenu(QPoint) {
|
|||||||
QAction *addAct = menu.addAction(IconProvider::instance()->getIcon("list-add"), tr("Add a new tracker..."));
|
QAction *addAct = menu.addAction(IconProvider::instance()->getIcon("list-add"), tr("Add a new tracker..."));
|
||||||
QAction *copyAct = menu.addAction(IconProvider::instance()->getIcon("edit-copy"), tr("Copy tracker url"));
|
QAction *copyAct = menu.addAction(IconProvider::instance()->getIcon("edit-copy"), tr("Copy tracker url"));
|
||||||
QAction *delAct = 0;
|
QAction *delAct = 0;
|
||||||
|
QAction *editAct = 0;
|
||||||
if (!getSelectedTrackerItems().isEmpty()) {
|
if (!getSelectedTrackerItems().isEmpty()) {
|
||||||
delAct = menu.addAction(IconProvider::instance()->getIcon("list-remove"), tr("Remove tracker"));
|
delAct = menu.addAction(IconProvider::instance()->getIcon("list-remove"), tr("Remove tracker"));
|
||||||
|
editAct = menu.addAction(IconProvider::instance()->getIcon("edit-rename"),tr("Edit selected tracker URI"));
|
||||||
}
|
}
|
||||||
QAction *act = menu.exec(QCursor::pos());
|
QAction *act = menu.exec(QCursor::pos());
|
||||||
if (act == 0) return;
|
if (act == 0) return;
|
||||||
@ -369,6 +387,10 @@ void TrackerList::showTrackerListMenu(QPoint) {
|
|||||||
deleteSelectedTrackers();
|
deleteSelectedTrackers();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (act == editAct) {
|
||||||
|
editSelectedTracker();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackerList::loadSettings() {
|
void TrackerList::loadSettings() {
|
||||||
|
@ -72,6 +72,7 @@ public slots:
|
|||||||
void askForTrackers();
|
void askForTrackers();
|
||||||
void copyTrackerUrl();
|
void copyTrackerUrl();
|
||||||
void deleteSelectedTrackers();
|
void deleteSelectedTrackers();
|
||||||
|
void editSelectedTracker();
|
||||||
void showTrackerListMenu(QPoint);
|
void showTrackerListMenu(QPoint);
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
void saveSettings() const;
|
void saveSettings() const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user