Browse Source

- Torrents can be renamed in transfer list

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
7bac95c9ad
  1. 1
      Changelog
  2. 7
      src/qtorrenthandle.cpp
  3. 4
      src/torrentfilesmodel.h
  4. 17
      src/torrentpersistentdata.h
  5. 22
      src/transferlistwidget.cpp
  6. 1
      src/transferlistwidget.h

1
Changelog

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
- FEATURE: uTorrent compatible tracker list support (use torrentz.com url as a default)
- FEATURE: Better proxy support and preferences remodeling
- FEATURE: qBittorrent can identify itself as uTorrent or Vuze (Any version)
- FEATURE: Torrents can be renamed in transfer list
- COSMETIC: Use checkboxes to filter torrent content instead of comboboxes
- COSMETIC: Use alternating row colors in transfer list (set in program preferences)
- COSMETIC: Added a spin box to speed limiting dialog for manual input

7
src/qtorrenthandle.cpp

@ -36,6 +36,7 @@ @@ -36,6 +36,7 @@
#include <math.h>
#include "misc.h"
#include "qtorrenthandle.h"
#include "torrentpersistentdata.h"
#include <libtorrent/magnet_uri.hpp>
#include <libtorrent/torrent_info.hpp>
@ -62,7 +63,11 @@ QString QTorrentHandle::hash() const { @@ -62,7 +63,11 @@ QString QTorrentHandle::hash() const {
QString QTorrentHandle::name() const {
Q_ASSERT(h.is_valid());
return misc::toQString(h.name());
QString name = TorrentPersistentData::getName(hash());
if(name.isEmpty()) {
name = misc::toQString(h.name());
}
return name;
}
QString QTorrentHandle::creation_date() const {

4
src/torrentfilesmodel.h

@ -506,7 +506,7 @@ public: @@ -506,7 +506,7 @@ public:
return;
}
// Create parent folder
QString root_name = misc::toQString(t.file_at(0).path.string()).split('/').first();
QString root_name = misc::toQString(t.file_at(0).path.string()).split(QDir::separator()).first();
TreeItem *current_parent = new TreeItem(root_name, parent);
//parent->appendChild(current_parent);
TreeItem *root_folder = current_parent;
@ -518,7 +518,7 @@ public: @@ -518,7 +518,7 @@ public:
current_parent = root_folder;
QString path = QDir::cleanPath(misc::toQString(fi->path.string()));
// Iterate of parts of the path to create necessary folders
QStringList pathFolders = path.split('/');
QStringList pathFolders = path.split(QDir::separator());
Q_ASSERT(pathFolders.size() >= 2);
QString fileName = pathFolders.takeLast();
QString currentFolderName = pathFolders.takeFirst();

17
src/torrentpersistentdata.h

@ -257,6 +257,16 @@ public: @@ -257,6 +257,16 @@ public:
settings.setValue("torrents", all_data);
}
static void saveName(QString hash, QString name) {
Q_ASSERT(!hash.isEmpty());
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
QHash<QString, QVariant> data = all_data[hash].toHash();
data["name"] = name;
all_data[hash] = data;
settings.setValue("torrents", all_data);
}
static void savePriority(QTorrentHandle h) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
@ -291,6 +301,13 @@ public: @@ -291,6 +301,13 @@ public:
return data.value("label", "").toString();
}
static QString getName(QString hash) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
QHash<QString, QVariant> data = all_data[hash].toHash();
return data.value("name", "").toString();
}
static int getPriority(QString hash) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();

22
src/transferlistwidget.cpp

@ -866,6 +866,24 @@ void TransferListWidget::askNewLabelForSelection() { @@ -866,6 +866,24 @@ void TransferListWidget::askNewLabelForSelection() {
}
}
void TransferListWidget::renameSelectedTorrent() {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
if(selectedIndexes.size() != 1) return;
if(!selectedIndexes.first().isValid()) return;
QString hash = getHashFromRow(mapToSource(selectedIndexes.first()).row());
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(!h.is_valid()) return;
// Ask for a new Name
bool ok;
QString name = QInputDialog::getText(this, tr("Rename"), tr("New name:"), QLineEdit::Normal, h.name(), &ok);
if (ok && !name.isEmpty()) {
// Remember the name
TorrentPersistentData::saveName(hash, name);
// Visually change the name
proxyModel->setData(selectedIndexes.first(), name);
}
}
void TransferListWidget::setSelectionLabel(QString label) {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
foreach(const QModelIndex &index, selectedIndexes) {
@ -917,6 +935,8 @@ void TransferListWidget::displayListMenu(const QPoint&) { @@ -917,6 +935,8 @@ void TransferListWidget::displayListMenu(const QPoint&) {
QAction actionSuper_seeding_mode(tr("Super seeding mode"), 0);
connect(&actionSuper_seeding_mode, SIGNAL(triggered()), this, SLOT(toggleSelectedTorrentsSuperSeeding()));
#endif
QAction actionRename(QIcon(QString::fromUtf8(":/Icons/oxygen/edit_clear.png")), tr("Rename..."), 0);
connect(&actionRename, SIGNAL(triggered()), this, SLOT(renameSelectedTorrent()));
QAction actionSequential_download(tr("Download in sequential order"), 0);
connect(&actionSequential_download, SIGNAL(triggered()), this, SLOT(toggleSelectedTorrentsSequentialDownload()));
QAction actionFirstLastPiece_prio(tr("Download first and last piece first"), 0);
@ -993,6 +1013,8 @@ void TransferListWidget::displayListMenu(const QPoint&) { @@ -993,6 +1013,8 @@ void TransferListWidget::displayListMenu(const QPoint&) {
listMenu.addSeparator();
listMenu.addAction(&actionDelete);
listMenu.addSeparator();
if(selectedIndexes.size() == 1)
listMenu.addAction(&actionRename);
// Label Menu
QStringList customLabels = getCustomLabels();
QList<QAction*> labelActions;

1
src/transferlistwidget.h

@ -117,6 +117,7 @@ public slots: @@ -117,6 +117,7 @@ public slots:
void applyLabelFilter(QString label);
void previewFile(QString filePath);
void removeLabelFromRows(QString label);
void renameSelectedTorrent();
signals:
void currentTorrentChanged(QTorrentHandle &h);

Loading…
Cancel
Save