diff --git a/Changelog b/Changelog index a68b6cf02..7387497ac 100644 --- a/Changelog +++ b/Changelog @@ -4,7 +4,7 @@ - FEATURE: Disk cache size can be set from preferences - FEATURE: Peer Exchange (PeX) can be disabled from preferences - FEATURE: Append !.qB extension to incomplete files option (libtorrent >= v0.15 only) - - FEATURE: Torrent files can be renamed + - FEATURE: Torrent files/folders can be renamed * Thu Dec 10 2009 - Christophe Dumez - v2.0.0 - FEATURE: Added program option to disable splash screen diff --git a/src/propertieswidget.cpp b/src/propertieswidget.cpp index 5dd6e4244..db003186a 100644 --- a/src/propertieswidget.cpp +++ b/src/propertieswidget.cpp @@ -479,7 +479,7 @@ void PropertiesWidget::displayFilesListMenu(const QPoint&){ QMenu myFilesLlistMenu; QModelIndexList selectedRows = filesList->selectionModel()->selectedRows(0); QAction *actRename = 0; - if(selectedRows.size() == 1 && PropListModel->getType(selectedRows.first())==TFILE) { + if(selectedRows.size() == 1) { actRename = myFilesLlistMenu.addAction(QIcon(QString::fromUtf8(":/Icons/oxygen/edit_clear.png")), tr("Rename...")); myFilesLlistMenu.addSeparator(); } @@ -500,43 +500,70 @@ void PropertiesWidget::displayFilesListMenu(const QPoint&){ void PropertiesWidget::renameSelectedFile() { QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(0); Q_ASSERT(selectedIndexes.size() == 1); + QModelIndex index = selectedIndexes.first(); // Ask for new name bool ok; QString new_name_last = QInputDialog::getText(this, tr("Rename torrent file"), - tr("New name:"), QLineEdit::Normal, - selectedIndexes.first().data().toString(), &ok); + tr("New name:"), QLineEdit::Normal, + index.data().toString(), &ok); if (ok && !new_name_last.isEmpty()) { - int file_index = PropListModel->getFileIndex(selectedIndexes.first()); - if(!h.is_valid() || !h.has_metadata()) return; - QString old_name = misc::toQString(h.get_torrent_info().file_at(file_index).path.string()); - if(old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB")) { - new_name_last += ".!qB"; - } - QStringList path_items = old_name.split(QDir::separator()); - path_items.removeLast(); - path_items << new_name_last; - QString new_name = path_items.join(QDir::separator()); - if(old_name == new_name) { - qDebug("Name did not change"); - return; - } - // Check if that name is already used - for(int i=0; igetType(index)==TFILE) { + // File renaming + int file_index = PropListModel->getFileIndex(index); + if(!h.is_valid() || !h.has_metadata()) return; + QString old_name = misc::toQString(h.get_torrent_info().file_at(file_index).path.string()); + if(old_name.endsWith(".!qB") && !new_name_last.endsWith(".!qB")) { + new_name_last += ".!qB"; + } + QStringList path_items = old_name.split(QDir::separator()); + path_items.removeLast(); + path_items << new_name_last; + QString new_name = path_items.join(QDir::separator()); + if(old_name == new_name) { + qDebug("Name did not change"); return; } + // Check if that name is already used + for(int i=0; isetData(index, new_name_last); + } else { + // Folder renaming + QStringList path_items; + path_items << index.data().toString(); + QModelIndex parent = PropListModel->parent(index); + while(parent.isValid()) { + path_items.prepend(parent.data().toString()); + parent = PropListModel->parent(parent); + } + QString old_path = path_items.join(QDir::separator()); + path_items.removeLast(); + path_items << new_name_last; + QString new_path = path_items.join(QDir::separator()); + // XXX: Check for overwriting + // Replace path in all files + for(int i=0; isetData(index, new_name_last); } - qDebug("Renaming %s to %s", old_name.toLocal8Bit().data(), new_name.toLocal8Bit().data()); - h.rename_file(file_index, new_name); - // Rename if torrent files model too - if(new_name_last.endsWith(".!qB")) - new_name_last.chop(4); - PropListModel->setData(selectedIndexes.first(), new_name_last); } } diff --git a/src/torrentfilesmodel.h b/src/torrentfilesmodel.h index 5ebbf9b7d..0e42983d0 100644 --- a/src/torrentfilesmodel.h +++ b/src/torrentfilesmodel.h @@ -329,7 +329,7 @@ public: void updateFilesPriorities(std::vector fprio) { for(unsigned int i=0; isetPriority(fprio[i]); } emit layoutChanged(); @@ -338,7 +338,7 @@ public: std::vector getFilesPriorities(unsigned int nbFiles) const { std::vector prio; for(unsigned int i=0; igetPriority()); + //qDebug("Called getFilesPriorities: %d", files_index[i]->getPriority()); prio.push_back(files_index[i]->getPriority()); } return prio;