Browse Source

- Remove old folders after renaming

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
7d66c07cef
  1. 13
      src/misc.h
  2. 14
      src/propertieswidget.cpp
  3. 3
      src/torrentfilesmodel.h

13
src/misc.h

@ -269,6 +269,19 @@ public: @@ -269,6 +269,19 @@ public:
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) {
QString hash = "";
QRegExp regHex("urn:btih:([0-9A-Za-z]+)");

14
src/propertieswidget.cpp

@ -557,8 +557,9 @@ void PropertiesWidget::renameSelectedFile() { @@ -557,8 +557,9 @@ void PropertiesWidget::renameSelectedFile() {
path_items.removeLast();
path_items << new_name_last;
QString new_path = path_items.join(QDir::separator());
// XXX: Check for overwriting
for(int i=0; i<h.num_files(); ++i) {
// Check for overwriting
int num_files = h.num_files();
for(int i=0; i<num_files; ++i) {
QString current_name = misc::toQString(h.get_torrent_info().file_at(i).path.string());
#ifdef Q_WS_WIN
if(current_name.contains(new_path, Qt::CaseInsensitive)) {
@ -572,7 +573,7 @@ void PropertiesWidget::renameSelectedFile() { @@ -572,7 +573,7 @@ void PropertiesWidget::renameSelectedFile() {
}
}
// Replace path in all 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 new_name = current_name.replace(old_path, new_path);
qDebug("Rename %s to %s", current_name.toLocal8Bit().data(), new_name.toLocal8Bit().data());
@ -580,6 +581,13 @@ void PropertiesWidget::renameSelectedFile() { @@ -580,6 +581,13 @@ void PropertiesWidget::renameSelectedFile() {
}
// 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;
}
}
}
}

3
src/torrentfilesmodel.h

@ -492,7 +492,8 @@ public: @@ -492,7 +492,8 @@ public:
return;
}
// 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);
TreeItem *root_folder = current_parent;

Loading…
Cancel
Save