From d9e15e40f46f7010a720e4a6cc9fbeaf47e32624 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sat, 12 Feb 2011 09:50:23 +0000 Subject: [PATCH] Fix "Append Label to Save path" on Windows --- src/misc.cpp | 8 ++++++-- src/misc.h | 2 +- src/torrentadditiondlg.cpp | 15 +++++++++++++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index 39d80f710..eaa41f98e 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -422,13 +422,17 @@ void misc::chmod644(const QDir& folder) { } } -QString misc::updateLabelInSavePath(const QString& defaultSavePath, const QString &save_path, const QString &old_label, const QString &new_label) { +QString misc::updateLabelInSavePath(QString defaultSavePath, QString save_path, const QString &old_label, const QString &new_label) { if(old_label == new_label) return save_path; +#if defined(Q_WS_WIN) || defined(Q_OS_OS2) + defaultSavePath.replace("\\", "/"); + save_path.replace("\\", "/"); +#endif qDebug("UpdateLabelInSavePath(%s, %s, %s)", qPrintable(save_path), qPrintable(old_label), qPrintable(new_label)); if(!save_path.startsWith(defaultSavePath)) return save_path; QString new_save_path = save_path; new_save_path.replace(defaultSavePath, ""); - QStringList path_parts = new_save_path.split(QDir::separator(), QString::SkipEmptyParts); + QStringList path_parts = new_save_path.split("/", QString::SkipEmptyParts); if(path_parts.empty()) { if(!new_label.isEmpty()) path_parts << new_label; diff --git a/src/misc.h b/src/misc.h index 3c8942c40..c06b2a65f 100644 --- a/src/misc.h +++ b/src/misc.h @@ -128,7 +128,7 @@ public: static QString truncateRootFolder(boost::intrusive_ptr t); static QString truncateRootFolder(libtorrent::torrent_handle h); - static QString updateLabelInSavePath(const QString& defaultSavePath, const QString &save_path, const QString &old_label, const QString &new_label); + static QString updateLabelInSavePath(QString defaultSavePath, QString save_path, const QString &old_label, const QString &new_label); static bool sameFiles(const QString &path1, const QString &path2); static bool isUrl(const QString &s); diff --git a/src/torrentadditiondlg.cpp b/src/torrentadditiondlg.cpp index e55d7b820..3acbeb20d 100644 --- a/src/torrentadditiondlg.cpp +++ b/src/torrentadditiondlg.cpp @@ -504,10 +504,22 @@ void torrentAdditionDialog::updateDiskSpaceLabels() { void torrentAdditionDialog::on_browseButton_clicked(){ Q_ASSERT(!is_magnet); QString new_path; + QString root_folder; + const QString label_name = comboLabel->currentText(); if(t->num_files() == 1) { new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), savePathTxt->currentText(), QString(), 0, QFileDialog::DontConfirmOverwrite); + if(!new_path.isEmpty()) { + QStringList path_parts = new_path.replace("\\", "/").split("/"); + const QString filename = path_parts.takeLast(); + // Append label + if(QDir(path_parts.join(QDir::separator())) == QDir(defaultSavePath) && !label_name.isEmpty()) + path_parts << label_name; + // Append file name + path_parts << filename; + // Construct new_path + new_path = path_parts.join(QDir::separator()); + } } else { - QString root_folder; QString truncated_path = getCurrentTruncatedSavePath(&root_folder); if(!truncated_path.isEmpty() && QDir(truncated_path).exists()){ new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), truncated_path); @@ -519,7 +531,6 @@ void torrentAdditionDialog::on_browseButton_clicked(){ if(path_parts.last().isEmpty()) path_parts.removeLast(); // Append label - const QString label_name = comboLabel->currentText(); if(QDir(new_path) == QDir(defaultSavePath) && !label_name.isEmpty()) path_parts << label_name; // Append root folder