mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-15 01:33:07 -07:00
- Remove old folders after renaming
This commit is contained in:
parent
28ecb2fe1d
commit
7d66c07cef
3 changed files with 181 additions and 159 deletions
13
src/misc.h
13
src/misc.h
|
@ -269,6 +269,19 @@ public:
|
||||||
list.insert(i, value);
|
list.insert(i, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool removeEmptyTree(QString path) {
|
||||||
|
QDir dir(path);
|
||||||
|
foreach(QString child, dir.entryList(QDir::AllDirs)) {
|
||||||
|
if(child == "." || child == "..") continue;
|
||||||
|
return removeEmptyTree(dir.absoluteFilePath(child));
|
||||||
|
}
|
||||||
|
QString dir_name = dir.dirName();
|
||||||
|
if(dir.cdUp()) {
|
||||||
|
return dir.rmdir(dir_name);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static QString magnetUriToHash(QString magnet_uri) {
|
static QString magnetUriToHash(QString magnet_uri) {
|
||||||
QString hash = "";
|
QString hash = "";
|
||||||
QRegExp regHex("urn:btih:([0-9A-Za-z]+)");
|
QRegExp regHex("urn:btih:([0-9A-Za-z]+)");
|
||||||
|
|
|
@ -529,181 +529,189 @@ void PropertiesWidget::renameSelectedFile() {
|
||||||
#ifdef Q_WS_WIN
|
#ifdef Q_WS_WIN
|
||||||
if(misc::toQString(h.get_torrent_info().file_at(i).path.string()).compare(new_name, Qt::CaseInsensitive) == 0) {
|
if(misc::toQString(h.get_torrent_info().file_at(i).path.string()).compare(new_name, Qt::CaseInsensitive) == 0) {
|
||||||
#else
|
#else
|
||||||
if(misc::toQString(h.get_torrent_info().file_at(i).path.string()).compare(new_name, Qt::CaseSensitive) == 0) {
|
if(misc::toQString(h.get_torrent_info().file_at(i).path.string()).compare(new_name, Qt::CaseSensitive) == 0) {
|
||||||
#endif
|
#endif
|
||||||
// Display error message
|
// Display error message
|
||||||
QMessageBox::warning(this, tr("The file could not be renamed"),
|
QMessageBox::warning(this, tr("The file could not be renamed"),
|
||||||
tr("This name is already in use in this folder. Please use a different name."),
|
tr("This name is already in use in this folder. Please use a different name."),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
qDebug("Renaming %s to %s", old_name.toLocal8Bit().data(), new_name.toLocal8Bit().data());
|
||||||
qDebug("Renaming %s to %s", old_name.toLocal8Bit().data(), new_name.toLocal8Bit().data());
|
h.rename_file(file_index, new_name);
|
||||||
h.rename_file(file_index, new_name);
|
// Rename if torrent files model too
|
||||||
// Rename if torrent files model too
|
if(new_name_last.endsWith(".!qB"))
|
||||||
if(new_name_last.endsWith(".!qB"))
|
new_name_last.chop(4);
|
||||||
new_name_last.chop(4);
|
PropListModel->setData(index, new_name_last);
|
||||||
PropListModel->setData(index, new_name_last);
|
} else {
|
||||||
} else {
|
// Folder renaming
|
||||||
// Folder renaming
|
QStringList path_items;
|
||||||
QStringList path_items;
|
path_items << index.data().toString();
|
||||||
path_items << index.data().toString();
|
QModelIndex parent = PropListModel->parent(index);
|
||||||
QModelIndex parent = PropListModel->parent(index);
|
while(parent.isValid()) {
|
||||||
while(parent.isValid()) {
|
path_items.prepend(parent.data().toString());
|
||||||
path_items.prepend(parent.data().toString());
|
parent = PropListModel->parent(parent);
|
||||||
parent = PropListModel->parent(parent);
|
}
|
||||||
}
|
QString old_path = path_items.join(QDir::separator());
|
||||||
QString old_path = path_items.join(QDir::separator());
|
path_items.removeLast();
|
||||||
path_items.removeLast();
|
path_items << new_name_last;
|
||||||
path_items << new_name_last;
|
QString new_path = path_items.join(QDir::separator());
|
||||||
QString new_path = path_items.join(QDir::separator());
|
// Check for overwriting
|
||||||
// XXX: Check for overwriting
|
int num_files = h.num_files();
|
||||||
for(int i=0; i<h.num_files(); ++i) {
|
for(int i=0; i<num_files; ++i) {
|
||||||
QString current_name = misc::toQString(h.get_torrent_info().file_at(i).path.string());
|
QString current_name = misc::toQString(h.get_torrent_info().file_at(i).path.string());
|
||||||
#ifdef Q_WS_WIN
|
#ifdef Q_WS_WIN
|
||||||
if(current_name.contains(new_path, Qt::CaseInsensitive)) {
|
if(current_name.contains(new_path, Qt::CaseInsensitive)) {
|
||||||
#else
|
#else
|
||||||
if(current_name.contains(new_path, Qt::CaseSensitive)) {
|
if(current_name.contains(new_path, Qt::CaseSensitive)) {
|
||||||
#endif
|
#endif
|
||||||
QMessageBox::warning(this, tr("The folder could not be renamed"),
|
QMessageBox::warning(this, tr("The folder could not be renamed"),
|
||||||
tr("This name is already in use in this folder. Please use a different name."),
|
tr("This name is already in use in this folder. Please use a different name."),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Replace path in all files
|
||||||
|
for(int i=0; i<num_files; ++i) {
|
||||||
|
QString current_name = misc::toQString(h.get_torrent_info().file_at(i).path.string());
|
||||||
|
QString new_name = current_name.replace(old_path, new_path);
|
||||||
|
qDebug("Rename %s to %s", current_name.toLocal8Bit().data(), new_name.toLocal8Bit().data());
|
||||||
|
h.rename_file(i, new_name);
|
||||||
|
}
|
||||||
|
// Rename folder in torrent files model too
|
||||||
|
PropListModel->setData(index, new_name_last);
|
||||||
|
// Remove old folder
|
||||||
|
QDir old_folder(h.save_path()+QDir::separator()+old_path);
|
||||||
|
int timeout = 10;
|
||||||
|
while(!misc::removeEmptyTree(old_folder.absolutePath()) && timeout > 0) {
|
||||||
|
SleeperThread::msleep(100);
|
||||||
|
--timeout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Replace path in all files
|
}
|
||||||
for(int i=0; i<h.num_files(); ++i) {
|
|
||||||
QString current_name = misc::toQString(h.get_torrent_info().file_at(i).path.string());
|
void PropertiesWidget::ignoreSelection(){
|
||||||
QString new_name = current_name.replace(old_path, new_path);
|
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(PRIORITY);
|
||||||
qDebug("Rename %s to %s", current_name.toLocal8Bit().data(), new_name.toLocal8Bit().data());
|
foreach(const QModelIndex &index, selectedIndexes){
|
||||||
h.rename_file(i, new_name);
|
if(PropListModel->data(index) != QVariant(IGNORED)){
|
||||||
|
PropListModel->setData(index, QVariant(IGNORED));
|
||||||
|
filteredFilesChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Rename folder in torrent files model too
|
|
||||||
PropListModel->setData(index, new_name_last);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PropertiesWidget::ignoreSelection(){
|
void PropertiesWidget::normalSelection(){
|
||||||
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(PRIORITY);
|
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(PRIORITY);
|
||||||
foreach(const QModelIndex &index, selectedIndexes){
|
foreach(const QModelIndex &index, selectedIndexes){
|
||||||
if(PropListModel->data(index) != QVariant(IGNORED)){
|
if(PropListModel->data(index) != QVariant(NORMAL)){
|
||||||
PropListModel->setData(index, QVariant(IGNORED));
|
PropListModel->setData(index, QVariant(NORMAL));
|
||||||
filteredFilesChanged();
|
filteredFilesChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PropertiesWidget::normalSelection(){
|
void PropertiesWidget::highSelection(){
|
||||||
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(PRIORITY);
|
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(PRIORITY);
|
||||||
foreach(const QModelIndex &index, selectedIndexes){
|
foreach(const QModelIndex &index, selectedIndexes){
|
||||||
if(PropListModel->data(index) != QVariant(NORMAL)){
|
if(PropListModel->data(index) != QVariant(HIGH)){
|
||||||
PropListModel->setData(index, QVariant(NORMAL));
|
PropListModel->setData(index, QVariant(HIGH));
|
||||||
filteredFilesChanged();
|
filteredFilesChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PropertiesWidget::highSelection(){
|
void PropertiesWidget::maximumSelection(){
|
||||||
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(PRIORITY);
|
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(PRIORITY);
|
||||||
foreach(const QModelIndex &index, selectedIndexes){
|
foreach(const QModelIndex &index, selectedIndexes){
|
||||||
if(PropListModel->data(index) != QVariant(HIGH)){
|
if(PropListModel->data(index) != QVariant(MAXIMUM)){
|
||||||
PropListModel->setData(index, QVariant(HIGH));
|
PropListModel->setData(index, QVariant(MAXIMUM));
|
||||||
filteredFilesChanged();
|
filteredFilesChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PropertiesWidget::maximumSelection(){
|
void PropertiesWidget::askWebSeed(){
|
||||||
QModelIndexList selectedIndexes = filesList->selectionModel()->selectedRows(PRIORITY);
|
bool ok;
|
||||||
foreach(const QModelIndex &index, selectedIndexes){
|
// Ask user for a new url seed
|
||||||
if(PropListModel->data(index) != QVariant(MAXIMUM)){
|
QString url_seed = QInputDialog::getText(this, tr("New url seed", "New HTTP source"),
|
||||||
PropListModel->setData(index, QVariant(MAXIMUM));
|
tr("New url seed:"), QLineEdit::Normal,
|
||||||
filteredFilesChanged();
|
QString::fromUtf8("http://www."), &ok);
|
||||||
}
|
if(!ok) return;
|
||||||
}
|
qDebug("Adding %s web seed", url_seed.toLocal8Bit().data());
|
||||||
}
|
if(!listWebSeeds->findItems(url_seed, Qt::MatchFixedString).empty()) {
|
||||||
|
QMessageBox::warning(this, tr("qBittorrent"),
|
||||||
void PropertiesWidget::askWebSeed(){
|
tr("This url seed is already in the list."),
|
||||||
bool ok;
|
QMessageBox::Ok);
|
||||||
// Ask user for a new url seed
|
|
||||||
QString url_seed = QInputDialog::getText(this, tr("New url seed", "New HTTP source"),
|
|
||||||
tr("New url seed:"), QLineEdit::Normal,
|
|
||||||
QString::fromUtf8("http://www."), &ok);
|
|
||||||
if(!ok) return;
|
|
||||||
qDebug("Adding %s web seed", url_seed.toLocal8Bit().data());
|
|
||||||
if(!listWebSeeds->findItems(url_seed, Qt::MatchFixedString).empty()) {
|
|
||||||
QMessageBox::warning(this, tr("qBittorrent"),
|
|
||||||
tr("This url seed is already in the list."),
|
|
||||||
QMessageBox::Ok);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
h.add_url_seed(url_seed);
|
|
||||||
// Refresh the seeds list
|
|
||||||
loadUrlSeeds();
|
|
||||||
}
|
|
||||||
|
|
||||||
void PropertiesWidget::deleteSelectedUrlSeeds(){
|
|
||||||
QList<QListWidgetItem *> selectedItems = listWebSeeds->selectedItems();
|
|
||||||
bool change = false;
|
|
||||||
foreach(QListWidgetItem *item, selectedItems){
|
|
||||||
QString url_seed = item->text();
|
|
||||||
h.remove_url_seed(url_seed);
|
|
||||||
change = true;
|
|
||||||
}
|
|
||||||
if(change){
|
|
||||||
// Refresh list
|
|
||||||
loadUrlSeeds();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PropertiesWidget::applyPriorities() {
|
|
||||||
qDebug("Saving pieces priorities");
|
|
||||||
std::vector<int> priorities = PropListModel->getFilesPriorities(h.get_torrent_info().num_files());
|
|
||||||
bool first_last_piece_first = false;
|
|
||||||
// Save first/last piece first option state
|
|
||||||
if(h.first_last_piece_first())
|
|
||||||
first_last_piece_first = true;
|
|
||||||
// Prioritize the files
|
|
||||||
qDebug("prioritize files: %d", priorities[0]);
|
|
||||||
h.prioritize_files(priorities);
|
|
||||||
// Restore first/last piece first option if necessary
|
|
||||||
if(first_last_piece_first)
|
|
||||||
h.prioritize_first_last_piece(true);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void PropertiesWidget::on_changeSavePathButton_clicked() {
|
|
||||||
if(!h.is_valid()) return;
|
|
||||||
QString dir;
|
|
||||||
QDir saveDir(h.save_path());
|
|
||||||
if(saveDir.exists()){
|
|
||||||
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), h.save_path());
|
|
||||||
}else{
|
|
||||||
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
|
||||||
}
|
|
||||||
if(!dir.isNull()){
|
|
||||||
// Check if savePath exists
|
|
||||||
QDir savePath(dir);
|
|
||||||
if(!savePath.exists()){
|
|
||||||
if(!savePath.mkpath(savePath.path())){
|
|
||||||
QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
h.add_url_seed(url_seed);
|
||||||
|
// Refresh the seeds list
|
||||||
|
loadUrlSeeds();
|
||||||
}
|
}
|
||||||
// Save savepath
|
|
||||||
TorrentPersistentData::saveSavePath(h.hash(), savePath.path());
|
|
||||||
// Actually move storage
|
|
||||||
if(!BTSession->useTemporaryFolder() || h.is_seed())
|
|
||||||
h.move_storage(savePath.path());
|
|
||||||
// Update save_path in dialog
|
|
||||||
save_path->setText(savePath.path());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PropertiesWidget::filteredFilesChanged() {
|
void PropertiesWidget::deleteSelectedUrlSeeds(){
|
||||||
if(h.is_valid()) {
|
QList<QListWidgetItem *> selectedItems = listWebSeeds->selectedItems();
|
||||||
applyPriorities();
|
bool change = false;
|
||||||
}
|
foreach(QListWidgetItem *item, selectedItems){
|
||||||
}
|
QString url_seed = item->text();
|
||||||
|
h.remove_url_seed(url_seed);
|
||||||
|
change = true;
|
||||||
|
}
|
||||||
|
if(change){
|
||||||
|
// Refresh list
|
||||||
|
loadUrlSeeds();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PropertiesWidget::applyPriorities() {
|
||||||
|
qDebug("Saving pieces priorities");
|
||||||
|
std::vector<int> priorities = PropListModel->getFilesPriorities(h.get_torrent_info().num_files());
|
||||||
|
bool first_last_piece_first = false;
|
||||||
|
// Save first/last piece first option state
|
||||||
|
if(h.first_last_piece_first())
|
||||||
|
first_last_piece_first = true;
|
||||||
|
// Prioritize the files
|
||||||
|
qDebug("prioritize files: %d", priorities[0]);
|
||||||
|
h.prioritize_files(priorities);
|
||||||
|
// Restore first/last piece first option if necessary
|
||||||
|
if(first_last_piece_first)
|
||||||
|
h.prioritize_first_last_piece(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PropertiesWidget::on_changeSavePathButton_clicked() {
|
||||||
|
if(!h.is_valid()) return;
|
||||||
|
QString dir;
|
||||||
|
QDir saveDir(h.save_path());
|
||||||
|
if(saveDir.exists()){
|
||||||
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), h.save_path());
|
||||||
|
}else{
|
||||||
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
||||||
|
}
|
||||||
|
if(!dir.isNull()){
|
||||||
|
// Check if savePath exists
|
||||||
|
QDir savePath(dir);
|
||||||
|
if(!savePath.exists()){
|
||||||
|
if(!savePath.mkpath(savePath.path())){
|
||||||
|
QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Save savepath
|
||||||
|
TorrentPersistentData::saveSavePath(h.hash(), savePath.path());
|
||||||
|
// Actually move storage
|
||||||
|
if(!BTSession->useTemporaryFolder() || h.is_seed())
|
||||||
|
h.move_storage(savePath.path());
|
||||||
|
// Update save_path in dialog
|
||||||
|
save_path->setText(savePath.path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PropertiesWidget::filteredFilesChanged() {
|
||||||
|
if(h.is_valid()) {
|
||||||
|
applyPriorities();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -492,7 +492,8 @@ public:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Create parent folder
|
// Create parent folder
|
||||||
TreeItem *current_parent = new TreeItem(misc::toQString(t.name()), parent);
|
QString root_name = misc::toQString(t.file_at(0).path.string()).split('/').first();
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue