diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 06432d317..74ca2e424 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -1645,7 +1645,6 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { qDebug("Moving storage to %s", qPrintable(new_save_path)); QDir().mkpath(new_save_path); h.move_storage(new_save_path); - emit savePathChanged(h); } } @@ -1658,8 +1657,8 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { QString new_save_path = misc::updateLabelInSavePath(defaultSavePath, old_save_path, "", label); if(old_save_path != new_save_path) { // Move storage + QDir().mkpath(new_save_path); h.move_storage(new_save_path); - emit savePathChanged(h); } } @@ -1950,8 +1949,11 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { } else if (storage_moved_alert* p = dynamic_cast(a.get())) { QTorrentHandle h(p->handle); - if(h.is_valid()) + if(h.is_valid()) { + TorrentPersistentData::saveSavePath(h.hash(), QString(p->path.c_str())); + emit savePathChanged(h); h.force_recheck(); //XXX: Required by libtorrent for now + } } else if (metadata_received_alert* p = dynamic_cast(a.get())) { QTorrentHandle h(p->handle); @@ -2177,14 +2179,11 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { if(savePath.isEmpty()) { savePath = defaultSavePath; } - if(appendLabelToSavePath && savePath.startsWith(defaultSavePath)) { + if(appendLabelToSavePath) { qDebug("appendLabelToSavePath is true"); const QString &label = TorrentTempData::getLabel(hash); if(!label.isEmpty()) { - const QDir save_dir(savePath); - if(save_dir.dirName() != label) { - savePath = save_dir.absoluteFilePath(label); - } + savePath = misc::updateLabelInSavePath(defaultSavePath, savePath, "", label); } } qDebug("getSavePath, got save_path from temp data: %s", qPrintable(savePath)); @@ -2207,10 +2206,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { if(!fromScanDir && appendLabelToSavePath) { const QString &label = TorrentPersistentData::getLabel(hash); if(!label.isEmpty()) { - QDir save_dir(savePath); - if(save_dir.dirName() != label) { - savePath = save_dir.absoluteFilePath(label); - } + savePath = misc::updateLabelInSavePath(defaultSavePath, savePath, "", label); } } if(append_root_folder && !root_folder.isEmpty()) { diff --git a/src/misc.cpp b/src/misc.cpp index c9d5fedfa..e88fc1458 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -258,12 +258,15 @@ QString misc::updateLabelInSavePath(const QString& defaultSavePath, QString save path_parts << new_label; } else { if(old_label.isEmpty() || path_parts.first() != old_label) { - path_parts.prepend(new_label); + if(path_parts.first() != new_label) + path_parts.prepend(new_label); } else { - if(new_label.isEmpty()) + if(new_label.isEmpty()) { path_parts.removeAt(0); - else - path_parts.replace(0, new_label); + } else { + if(path_parts.first() != new_label) + path_parts.replace(0, new_label); + } } } new_save_path = defaultSavePath; diff --git a/src/torrentadditiondlg.h b/src/torrentadditiondlg.h index 3fd8aa70e..907d78e4c 100644 --- a/src/torrentadditiondlg.h +++ b/src/torrentadditiondlg.h @@ -66,6 +66,9 @@ private: QString hash; QString filePath; QString from_url; + QString defaultSavePath; + QString old_label; + bool appendLabelToSavePath; TorrentFilesModel *PropListModel; PropListDelegate *PropDelegate; unsigned int nbFiles; @@ -74,7 +77,7 @@ private: bool is_magnet; public: - torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession) : QDialog((QWidget*)parent) { + torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession) : QDialog((QWidget*)parent), old_label("") { setupUi(this); setAttribute(Qt::WA_DeleteOnClose); connect(this, SIGNAL(torrentPaused(QTorrentHandle&)), parent->getTransferList(), SLOT(pauseTorrent(QTorrentHandle&))); @@ -89,10 +92,14 @@ public: connect(torrentContentList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayContentListMenu(const QPoint&))); connect(collapseAllButton, SIGNAL(clicked()), torrentContentList, SLOT(collapseAll())); connect(expandAllButton, SIGNAL(clicked()), torrentContentList, SLOT(expandAll())); + connect(comboLabel, SIGNAL(editTextChanged(QString)), this, SLOT(updateLabelInSavePath(QString))); + connect(comboLabel, SIGNAL(currentIndexChanged(QString)), this, SLOT(updateLabelInSavePath(QString))); // Remember columns width readSettings(); //torrentContentList->header()->setResizeMode(0, QHeaderView::Stretch); - savePathTxt->setText(Preferences::getSavePath()); + defaultSavePath = Preferences::getSavePath(); + appendLabelToSavePath = Preferences::appendTorrentLabel(); + savePathTxt->setText(defaultSavePath); if(Preferences::addTorrentsInPause()) { addInPause->setChecked(true); //addInPause->setEnabled(false); @@ -295,8 +302,8 @@ public slots: // Ask for new name bool ok; const QString &new_name_last = QInputDialog::getText(this, tr("Rename the file"), - tr("New name:"), QLineEdit::Normal, - index.data().toString(), &ok); + tr("New name:"), QLineEdit::Normal, + index.data().toString(), &ok); if (ok && !new_name_last.isEmpty()) { if(!misc::isValidFileSystemName(new_name_last)) { QMessageBox::warning(this, tr("The file could not be renamed"), @@ -516,6 +523,14 @@ public slots: close(); } + public slots: + void updateLabelInSavePath(QString label) { + if(appendLabelToSavePath) { + savePathTxt->setText(misc::updateLabelInSavePath(defaultSavePath, savePathTxt->text(), old_label, label)); + old_label = label; + } + } + signals: void torrentPaused(QTorrentHandle &h); };