From 1875846326efe7b96c32e14b3564284f2ca70b81 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 18 Oct 2010 19:23:39 +0000 Subject: [PATCH] Improved "Set Location" and "Change save path" dialogs --- src/propertieswidget.cpp | 26 +++++++++++++------------- src/transferlistwidget.cpp | 27 ++++++++++++++------------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/propertieswidget.cpp b/src/propertieswidget.cpp index 27f2bbc86..9cd801f4d 100644 --- a/src/propertieswidget.cpp +++ b/src/propertieswidget.cpp @@ -776,12 +776,16 @@ void PropertiesWidget::renameSelectedFile() { if(h.has_metadata() && h.num_files() == 1) { new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), h.firstFileSavePath()); } else { - const QDir saveDir(h.save_path()); - if(saveDir.exists()){ - new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), h.save_path()); - }else{ - new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath()); - } + const QDir saveDir(TorrentPersistentData::getSavePath(h.hash())); + QFileDialog dlg(this, tr("Choose save path"), saveDir.absolutePath()); + dlg.setConfirmOverwrite(false); + dlg.setFileMode(QFileDialog::Directory); + dlg.setOption(QFileDialog::ShowDirsOnly, true); + dlg.setFilter(QDir::AllDirs); + dlg.setAcceptMode(QFileDialog::AcceptSave); + dlg.setNameFilterDetailsVisible(false); + if(dlg.exec()) + new_path = dlg.selectedFiles().first(); } if(!new_path.isEmpty()){ // Check if savePath exists @@ -793,15 +797,11 @@ void PropertiesWidget::renameSelectedFile() { save_path_dir = parts.join("/"); } QDir savePath(misc::expandPath(save_path_dir)); - if(!savePath.exists()){ - if(!savePath.mkpath(savePath.absolutePath())){ - QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path")); - return; - } - } // Actually move storage - if(!BTSession->useTemporaryFolder() || h.is_seed()) + if(!BTSession->useTemporaryFolder() || h.is_seed()) { + if(!savePath.exists()) savePath.mkpath(savePath.absolutePath()); h.move_storage(savePath.absolutePath()); + } // Update save_path in dialog QString display_path; if(h.has_metadata() && h.num_files() == 1) { diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index 3116d2664..7101b2789 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -654,25 +654,26 @@ void TransferListWidget::setSelectedTorrentsLocation() { if(hashes.isEmpty()) return; QString dir; const QDir saveDir(TorrentPersistentData::getSavePath(hashes.first())); - qDebug("Torrent save path is %s", qPrintable(saveDir.absolutePath())); - if(saveDir.exists()){ - dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), saveDir.path()); - }else{ - dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath()); - } - if(!dir.isNull()){ + qDebug("Old save path is %s", qPrintable(saveDir.absolutePath())); + QFileDialog dlg(this, tr("Choose save path"), saveDir.absolutePath()); + dlg.setConfirmOverwrite(false); + dlg.setFileMode(QFileDialog::Directory); + dlg.setOption(QFileDialog::ShowDirsOnly, true); + dlg.setFilter(QDir::AllDirs); + dlg.setAcceptMode(QFileDialog::AcceptSave); + dlg.setNameFilterDetailsVisible(false); + if(dlg.exec()) + dir = dlg.selectedFiles().first(); + if(!dir.isNull()) { + qDebug("New path is %s", qPrintable(dir)); // Check if savePath exists QDir savePath(misc::expandPath(dir)); - if(!savePath.exists()){ - if(!savePath.mkpath(savePath.absolutePath())){ - QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path")); - return; - } - } + qDebug("New path after clean up is %s", qPrintable(savePath.absolutePath())); foreach(const QString & hash, hashes) { // Actually move storage QTorrentHandle h = BTSession->getTorrentHandle(hash); if(!BTSession->useTemporaryFolder() || h.is_seed()) { + if(!savePath.exists()) savePath.mkpath(savePath.absolutePath()); h.move_storage(savePath.absolutePath()); } else { TorrentPersistentData::saveSavePath(h.hash(), savePath.absolutePath());