- Torrents can be renamed in transfer list

This commit is contained in:
Christophe Dumez 2010-01-01 13:25:59 +00:00
parent add2475700
commit 7bac95c9ad
6 changed files with 49 additions and 3 deletions

View file

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

View file

@ -36,6 +36,7 @@
#include <math.h> #include <math.h>
#include "misc.h" #include "misc.h"
#include "qtorrenthandle.h" #include "qtorrenthandle.h"
#include "torrentpersistentdata.h"
#include <libtorrent/magnet_uri.hpp> #include <libtorrent/magnet_uri.hpp>
#include <libtorrent/torrent_info.hpp> #include <libtorrent/torrent_info.hpp>
@ -62,7 +63,11 @@ QString QTorrentHandle::hash() const {
QString QTorrentHandle::name() const { QString QTorrentHandle::name() const {
Q_ASSERT(h.is_valid()); 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 { QString QTorrentHandle::creation_date() const {

View file

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

View file

@ -257,6 +257,16 @@ public:
settings.setValue("torrents", all_data); 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) { static void savePriority(QTorrentHandle h) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
@ -291,6 +301,13 @@ public:
return data.value("label", "").toString(); 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) { static int getPriority(QString hash) {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash(); QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();

View file

@ -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) { void TransferListWidget::setSelectionLabel(QString label) {
QModelIndexList selectedIndexes = selectionModel()->selectedRows(); QModelIndexList selectedIndexes = selectionModel()->selectedRows();
foreach(const QModelIndex &index, selectedIndexes) { foreach(const QModelIndex &index, selectedIndexes) {
@ -917,6 +935,8 @@ void TransferListWidget::displayListMenu(const QPoint&) {
QAction actionSuper_seeding_mode(tr("Super seeding mode"), 0); QAction actionSuper_seeding_mode(tr("Super seeding mode"), 0);
connect(&actionSuper_seeding_mode, SIGNAL(triggered()), this, SLOT(toggleSelectedTorrentsSuperSeeding())); connect(&actionSuper_seeding_mode, SIGNAL(triggered()), this, SLOT(toggleSelectedTorrentsSuperSeeding()));
#endif #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); QAction actionSequential_download(tr("Download in sequential order"), 0);
connect(&actionSequential_download, SIGNAL(triggered()), this, SLOT(toggleSelectedTorrentsSequentialDownload())); connect(&actionSequential_download, SIGNAL(triggered()), this, SLOT(toggleSelectedTorrentsSequentialDownload()));
QAction actionFirstLastPiece_prio(tr("Download first and last piece first"), 0); QAction actionFirstLastPiece_prio(tr("Download first and last piece first"), 0);
@ -993,6 +1013,8 @@ void TransferListWidget::displayListMenu(const QPoint&) {
listMenu.addSeparator(); listMenu.addSeparator();
listMenu.addAction(&actionDelete); listMenu.addAction(&actionDelete);
listMenu.addSeparator(); listMenu.addSeparator();
if(selectedIndexes.size() == 1)
listMenu.addAction(&actionRename);
// Label Menu // Label Menu
QStringList customLabels = getCustomLabels(); QStringList customLabels = getCustomLabels();
QList<QAction*> labelActions; QList<QAction*> labelActions;

View file

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