Browse Source

Fix "Append Label to Save path" on Windows

adaptive-webui-19844
Christophe Dumez 14 years ago
parent
commit
d9e15e40f4
  1. 8
      src/misc.cpp
  2. 2
      src/misc.h
  3. 15
      src/torrentadditiondlg.cpp

8
src/misc.cpp

@ -422,13 +422,17 @@ void misc::chmod644(const QDir& folder) { @@ -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;

2
src/misc.h

@ -128,7 +128,7 @@ public: @@ -128,7 +128,7 @@ public:
static QString truncateRootFolder(boost::intrusive_ptr<libtorrent::torrent_info> 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);

15
src/torrentadditiondlg.cpp

@ -504,10 +504,22 @@ void torrentAdditionDialog::updateDiskSpaceLabels() { @@ -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(){ @@ -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

Loading…
Cancel
Save