diff --git a/Changelog b/Changelog index 389693f83..d2468e1e5 100644 --- a/Changelog +++ b/Changelog @@ -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 diff --git a/src/qtorrenthandle.cpp b/src/qtorrenthandle.cpp index cf5542d87..dac74e39b 100644 --- a/src/qtorrenthandle.cpp +++ b/src/qtorrenthandle.cpp @@ -36,6 +36,7 @@ #include #include "misc.h" #include "qtorrenthandle.h" +#include "torrentpersistentdata.h" #include #include @@ -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 { diff --git a/src/torrentfilesmodel.h b/src/torrentfilesmodel.h index 78f8fc45b..ebf27a928 100644 --- a/src/torrentfilesmodel.h +++ b/src/torrentfilesmodel.h @@ -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: 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(); diff --git a/src/torrentpersistentdata.h b/src/torrentpersistentdata.h index dd7a0dfae..04ab9ca0e 100644 --- a/src/torrentpersistentdata.h +++ b/src/torrentpersistentdata.h @@ -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 all_data = settings.value("torrents", QHash()).toHash(); + QHash 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 all_data = settings.value("torrents", QHash()).toHash(); @@ -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 all_data = settings.value("torrents", QHash()).toHash(); + QHash 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 all_data = settings.value("torrents", QHash()).toHash(); diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index 5b711f916..7342bbb8f 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -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&) { 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&) { listMenu.addSeparator(); listMenu.addAction(&actionDelete); listMenu.addSeparator(); + if(selectedIndexes.size() == 1) + listMenu.addAction(&actionRename); // Label Menu QStringList customLabels = getCustomLabels(); QList labelActions; diff --git a/src/transferlistwidget.h b/src/transferlistwidget.h index 51f92a59e..2fe1c5550 100644 --- a/src/transferlistwidget.h +++ b/src/transferlistwidget.h @@ -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);