mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-21 08:09:35 +08:00
Don't display warning when folder named stayed the same.
Copy some code from AddNewTorrent dialog and beautify a bit. Closes #4970.
This commit is contained in:
parent
7794502324
commit
2bb76bf781
@ -501,6 +501,10 @@ void AddNewTorrentDialog::renameSelectedFile()
|
||||
path_items.removeLast();
|
||||
path_items << new_name_last;
|
||||
QString new_path = path_items.join("/");
|
||||
if (Utils::Fs::sameFileNames(old_path, new_path)) {
|
||||
qDebug("Name did not change");
|
||||
return;
|
||||
}
|
||||
if (!new_path.endsWith("/")) new_path += "/";
|
||||
// Check for overwriting
|
||||
for (int i = 0; i < m_torrentInfo.filesCount(); ++i) {
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include <QSplitter>
|
||||
#include <QHeaderView>
|
||||
#include <QAction>
|
||||
#include <QMessageBox>
|
||||
#include <QMenu>
|
||||
#include <QFileDialog>
|
||||
#include <QBitArray>
|
||||
@ -54,6 +53,7 @@
|
||||
#include "speedwidget.h"
|
||||
#include "trackerlist.h"
|
||||
#include "mainwindow.h"
|
||||
#include "messageboxraised.h"
|
||||
#include "downloadedpiecesbar.h"
|
||||
#include "pieceavailabilitybar.h"
|
||||
#include "proptabbar.h"
|
||||
@ -657,7 +657,7 @@ void PropertiesWidget::renameSelectedFile() {
|
||||
index.data().toString(), &ok).trimmed();
|
||||
if (ok && !new_name_last.isEmpty()) {
|
||||
if (!Utils::Fs::isValidFileSystemName(new_name_last)) {
|
||||
QMessageBox::warning(this, tr("The file could not be renamed"),
|
||||
MessageBoxRaised::warning(this, tr("The file could not be renamed"),
|
||||
tr("This file name contains forbidden characters, please choose a different one."),
|
||||
QMessageBox::Ok);
|
||||
return;
|
||||
@ -674,21 +674,18 @@ void PropertiesWidget::renameSelectedFile() {
|
||||
path_items.removeLast();
|
||||
path_items << new_name_last;
|
||||
QString new_name = path_items.join("/");
|
||||
if (old_name == new_name) {
|
||||
if (Utils::Fs::sameFileNames(old_name, new_name)) {
|
||||
qDebug("Name did not change");
|
||||
return;
|
||||
}
|
||||
new_name = Utils::Fs::expandPath(new_name);
|
||||
qDebug("New name: %s", qPrintable(new_name));
|
||||
// Check if that name is already used
|
||||
for (int i = 0; i < m_torrent->filesCount(); ++i) {
|
||||
if (i == file_index) continue;
|
||||
#if defined(Q_OS_UNIX) || defined(Q_WS_QWS)
|
||||
if (m_torrent->filePath(i).compare(new_name, Qt::CaseSensitive) == 0) {
|
||||
#else
|
||||
if (m_torrent->filePath(i).compare(new_name, Qt::CaseInsensitive) == 0) {
|
||||
#endif
|
||||
if (Utils::Fs::sameFileNames(m_torrent->filePath(i), new_name)) {
|
||||
// Display error message
|
||||
QMessageBox::warning(this, tr("The file could not be renamed"),
|
||||
MessageBoxRaised::warning(this, tr("The file could not be renamed"),
|
||||
tr("This name is already in use in this folder. Please use a different name."),
|
||||
QMessageBox::Ok);
|
||||
return;
|
||||
@ -703,7 +700,8 @@ void PropertiesWidget::renameSelectedFile() {
|
||||
if (new_name_last.endsWith(".!qB"))
|
||||
new_name_last.chop(4);
|
||||
PropListModel->setData(index, new_name_last);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// Folder renaming
|
||||
QStringList path_items;
|
||||
path_items << index.data().toString();
|
||||
@ -716,11 +714,14 @@ void PropertiesWidget::renameSelectedFile() {
|
||||
path_items.removeLast();
|
||||
path_items << new_name_last;
|
||||
QString new_path = path_items.join("/");
|
||||
if (Utils::Fs::sameFileNames(old_path, new_path)) {
|
||||
qDebug("Name did not change");
|
||||
return;
|
||||
}
|
||||
if (!new_path.endsWith("/")) new_path += "/";
|
||||
// Check for overwriting
|
||||
const int num_files = m_torrent->filesCount();
|
||||
for (int i=0; i<num_files; ++i) {
|
||||
const QString current_name = m_torrent->filePath(i);
|
||||
for (int i = 0; i < m_torrent->filesCount(); ++i) {
|
||||
const QString ¤t_name = m_torrent->filePath(i);
|
||||
#if defined(Q_OS_UNIX) || defined(Q_WS_QWS)
|
||||
if (current_name.startsWith(new_path, Qt::CaseSensitive)) {
|
||||
#else
|
||||
@ -734,7 +735,7 @@ void PropertiesWidget::renameSelectedFile() {
|
||||
}
|
||||
bool force_recheck = false;
|
||||
// Replace path in all files
|
||||
for (int i=0; i<num_files; ++i) {
|
||||
for (int i = 0; i < m_torrent->filesCount(); ++i) {
|
||||
const QString current_name = m_torrent->filePath(i);
|
||||
if (current_name.startsWith(old_path)) {
|
||||
QString new_name = current_name;
|
||||
|
Loading…
Reference in New Issue
Block a user