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:
sledgehammer999 2016-03-18 00:54:10 +02:00
parent 7794502324
commit 2bb76bf781
2 changed files with 27 additions and 22 deletions

View File

@ -501,6 +501,10 @@ void AddNewTorrentDialog::renameSelectedFile()
path_items.removeLast(); path_items.removeLast();
path_items << new_name_last; path_items << new_name_last;
QString new_path = path_items.join("/"); 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 += "/"; if (!new_path.endsWith("/")) new_path += "/";
// Check for overwriting // Check for overwriting
for (int i = 0; i < m_torrentInfo.filesCount(); ++i) { for (int i = 0; i < m_torrentInfo.filesCount(); ++i) {

View File

@ -36,7 +36,6 @@
#include <QSplitter> #include <QSplitter>
#include <QHeaderView> #include <QHeaderView>
#include <QAction> #include <QAction>
#include <QMessageBox>
#include <QMenu> #include <QMenu>
#include <QFileDialog> #include <QFileDialog>
#include <QBitArray> #include <QBitArray>
@ -54,6 +53,7 @@
#include "speedwidget.h" #include "speedwidget.h"
#include "trackerlist.h" #include "trackerlist.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "messageboxraised.h"
#include "downloadedpiecesbar.h" #include "downloadedpiecesbar.h"
#include "pieceavailabilitybar.h" #include "pieceavailabilitybar.h"
#include "proptabbar.h" #include "proptabbar.h"
@ -657,7 +657,7 @@ void PropertiesWidget::renameSelectedFile() {
index.data().toString(), &ok).trimmed(); index.data().toString(), &ok).trimmed();
if (ok && !new_name_last.isEmpty()) { if (ok && !new_name_last.isEmpty()) {
if (!Utils::Fs::isValidFileSystemName(new_name_last)) { 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."), tr("This file name contains forbidden characters, please choose a different one."),
QMessageBox::Ok); QMessageBox::Ok);
return; return;
@ -674,25 +674,22 @@ void PropertiesWidget::renameSelectedFile() {
path_items.removeLast(); path_items.removeLast();
path_items << new_name_last; path_items << new_name_last;
QString new_name = path_items.join("/"); QString new_name = path_items.join("/");
if (old_name == new_name) { if (Utils::Fs::sameFileNames(old_name, new_name)) {
qDebug("Name did not change"); qDebug("Name did not change");
return; return;
} }
new_name = Utils::Fs::expandPath(new_name); new_name = Utils::Fs::expandPath(new_name);
qDebug("New name: %s", qPrintable(new_name));
// Check if that name is already used // Check if that name is already used
for (int i = 0; i < m_torrent->filesCount(); ++i) { for (int i = 0; i < m_torrent->filesCount(); ++i) {
if (i == file_index) continue; if (i == file_index) continue;
#if defined(Q_OS_UNIX) || defined(Q_WS_QWS) if (Utils::Fs::sameFileNames(m_torrent->filePath(i), new_name)) {
if (m_torrent->filePath(i).compare(new_name, Qt::CaseSensitive) == 0) { // Display error message
#else MessageBoxRaised::warning(this, tr("The file could not be renamed"),
if (m_torrent->filePath(i).compare(new_name, Qt::CaseInsensitive) == 0) { tr("This name is already in use in this folder. Please use a different name."),
#endif QMessageBox::Ok);
// Display error message return;
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."),
QMessageBox::Ok);
return;
}
} }
const bool force_recheck = QFile::exists(m_torrent->savePath(true) + "/" + new_name); const bool force_recheck = QFile::exists(m_torrent->savePath(true) + "/" + new_name);
qDebug("Renaming %s to %s", qPrintable(old_name), qPrintable(new_name)); qDebug("Renaming %s to %s", qPrintable(old_name), qPrintable(new_name));
@ -703,7 +700,8 @@ void PropertiesWidget::renameSelectedFile() {
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();
@ -716,11 +714,14 @@ void PropertiesWidget::renameSelectedFile() {
path_items.removeLast(); path_items.removeLast();
path_items << new_name_last; path_items << new_name_last;
QString new_path = path_items.join("/"); 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 += "/"; if (!new_path.endsWith("/")) new_path += "/";
// Check for overwriting // Check for overwriting
const int num_files = m_torrent->filesCount(); for (int i = 0; i < m_torrent->filesCount(); ++i) {
for (int i=0; i<num_files; ++i) { const QString &current_name = m_torrent->filePath(i);
const QString current_name = m_torrent->filePath(i);
#if defined(Q_OS_UNIX) || defined(Q_WS_QWS) #if defined(Q_OS_UNIX) || defined(Q_WS_QWS)
if (current_name.startsWith(new_path, Qt::CaseSensitive)) { if (current_name.startsWith(new_path, Qt::CaseSensitive)) {
#else #else
@ -734,7 +735,7 @@ void PropertiesWidget::renameSelectedFile() {
} }
bool force_recheck = false; bool force_recheck = false;
// Replace path in all files // 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); const QString current_name = m_torrent->filePath(i);
if (current_name.startsWith(old_path)) { if (current_name.startsWith(old_path)) {
QString new_name = current_name; QString new_name = current_name;