mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
FEATURE: Remember previous save paths in torrent addition dialog (closes #579305)
This commit is contained in:
parent
67f41ad991
commit
ca762139f6
4 changed files with 555 additions and 471 deletions
|
@ -1,5 +1,6 @@
|
|||
* Unreleased - Christophe Dumez <chris@qbittorrent.org> - v2.3.0
|
||||
- FEATURE: Simplified torrent root folder renaming/truncating (< v2.3.0 is no longer forward compatible)
|
||||
- FEATURE: Remember previous save paths in torrent addition dialog
|
||||
- FEATURE: Max number of half-open connections can now be edited
|
||||
- FEATURE: Added support for strict super seeding
|
||||
- FEATURE: The user can force listening on a particular network interface
|
||||
|
|
|
@ -53,10 +53,28 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
|
|||
defaultSavePath = Preferences::getSavePath();
|
||||
appendLabelToSavePath = Preferences::appendTorrentLabel();
|
||||
QString display_path = defaultSavePath;
|
||||
if(!display_path.endsWith("/") && !display_path.endsWith("\\"))
|
||||
display_path += "/";
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
display_path = display_path.replace("/", "\\");
|
||||
#endif
|
||||
savePathTxt->setText(display_path);
|
||||
savePathTxt->addItem(display_path);
|
||||
// Load save path history
|
||||
const QStringList path_history = getSavePathHistory();
|
||||
foreach(const QString &sp, path_history) {
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
if(sp.compare(display_path, Qt::CaseInsensitive) != 0) {
|
||||
#else
|
||||
if(sp.compare(display_path, Qt::CaseSensitive) != 0) {
|
||||
#endif
|
||||
QString dsp = sp;
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
dsp = dsp.replace("/", "\\");
|
||||
#endif
|
||||
savePathTxt->addItem(dsp);
|
||||
}
|
||||
}
|
||||
|
||||
if(Preferences::addTorrentsInPause()) {
|
||||
addInPause->setChecked(true);
|
||||
//addInPause->setEnabled(false);
|
||||
|
@ -141,10 +159,10 @@ void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) {
|
|||
if(fileName.isEmpty()) {
|
||||
fileName = tr("Magnet Link");
|
||||
} else {
|
||||
QString save_path = savePathTxt->text();
|
||||
QString save_path = savePathTxt->currentText();
|
||||
if(!save_path.endsWith(QDir::separator()))
|
||||
save_path += QDir::separator();
|
||||
savePathTxt->setText(save_path + fileName);
|
||||
savePathTxt->setEditText(save_path + fileName);
|
||||
}
|
||||
fileNameLbl->setText(QString::fromUtf8("<center><b>")+fileName+QString::fromUtf8("</b></center>"));
|
||||
// Update display
|
||||
|
@ -193,10 +211,10 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
|
|||
}
|
||||
if(nbFiles == 1) {
|
||||
// Update properties model whenever the file path is edited
|
||||
connect(savePathTxt, SIGNAL(textChanged(QString)), this, SLOT(renameTorrentNameInModel(QString)));
|
||||
connect(savePathTxt, SIGNAL(editTextChanged(QString)), this, SLOT(renameTorrentNameInModel(QString)));
|
||||
}
|
||||
QString root_folder = misc::truncateRootFolder(t);
|
||||
QString save_path = savePathTxt->text();
|
||||
QString save_path = savePathTxt->currentText();
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
save_path = save_path.replace("/", "\\");
|
||||
#endif
|
||||
|
@ -204,7 +222,11 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
|
|||
save_path += QDir::separator();
|
||||
// If the torrent has a root folder, append it to the save path
|
||||
if(!root_folder.isEmpty()) {
|
||||
savePathTxt->setText(save_path + root_folder + QDir::separator());
|
||||
savePathTxt->setEditText(save_path + root_folder + QDir::separator());
|
||||
// Update other combo items
|
||||
for(int i=0; i<savePathTxt->count(); ++i) {
|
||||
savePathTxt->setItemText(i, savePathTxt->itemText(i) + root_folder + QDir::separator());
|
||||
}
|
||||
}
|
||||
if(nbFiles == 1) {
|
||||
// single file torrent
|
||||
|
@ -212,7 +234,11 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
|
|||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
single_file_relpath = single_file_relpath.replace("/", "\\");
|
||||
#endif
|
||||
savePathTxt->setText(save_path+single_file_relpath);
|
||||
savePathTxt->setEditText(save_path + single_file_relpath);
|
||||
// Update other combo items
|
||||
for(int i=0; i<savePathTxt->count(); ++i) {
|
||||
savePathTxt->setItemText(i, savePathTxt->itemText(i) + single_file_relpath);
|
||||
}
|
||||
}
|
||||
// Setting file name
|
||||
fileName = misc::toQStringU(t->name());
|
||||
|
@ -236,7 +262,7 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
|
|||
files_path << misc::toQStringU(t->file_at(i).path.string());
|
||||
}
|
||||
}
|
||||
connect(savePathTxt, SIGNAL(textChanged(QString)), this, SLOT(updateDiskSpaceLabels()));
|
||||
connect(savePathTxt, SIGNAL(editTextChanged(QString)), this, SLOT(updateDiskSpaceLabels()));
|
||||
updateDiskSpaceLabels();
|
||||
// Load custom labels
|
||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||
|
@ -389,7 +415,8 @@ void torrentAdditionDialog::renameSelectedFile() {
|
|||
}
|
||||
|
||||
void torrentAdditionDialog::updateDiskSpaceLabels() {
|
||||
const long long available = misc::freeDiskSpaceOnPath(misc::expandPath(savePathTxt->text()));
|
||||
qDebug("Updating disk space label...");
|
||||
const long long available = misc::freeDiskSpaceOnPath(misc::expandPath(savePathTxt->currentText()));
|
||||
lbl_disk_space->setText(misc::friendlyUnit(available));
|
||||
if(!is_magnet) {
|
||||
// Determine torrent size
|
||||
|
@ -425,7 +452,7 @@ void torrentAdditionDialog::renameSelectedFile() {
|
|||
|
||||
void torrentAdditionDialog::on_browseButton_clicked(){
|
||||
QString new_path;
|
||||
QString save_path = savePathTxt->text();
|
||||
QString save_path = savePathTxt->currentText();
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
save_path = save_path.replace("\\", "/");
|
||||
#endif
|
||||
|
@ -444,7 +471,7 @@ void torrentAdditionDialog::renameSelectedFile() {
|
|||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
new_path = new_path.replace("/", "\\");
|
||||
#endif
|
||||
savePathTxt->setText(new_path);
|
||||
savePathTxt->setEditText(new_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -463,22 +490,22 @@ void torrentAdditionDialog::renameSelectedFile() {
|
|||
}
|
||||
|
||||
void torrentAdditionDialog::on_OkButton_clicked(){
|
||||
if(savePathTxt->text().trimmed().isEmpty()){
|
||||
if(savePathTxt->currentText().trimmed().isEmpty()){
|
||||
QMessageBox::critical(0, tr("Empty save path"), tr("Please enter a save path"));
|
||||
return;
|
||||
}
|
||||
QString save_path = savePathTxt->text();
|
||||
QString save_path = savePathTxt->currentText();
|
||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||
save_path = save_path.replace("\\", "/");
|
||||
#endif
|
||||
save_path = misc::expandPath(save_path);
|
||||
if(!is_magnet && t->num_files() == 1) {
|
||||
// Remove file name
|
||||
QStringList parts = save_path.split("/", QString::SkipEmptyParts);
|
||||
QStringList parts = save_path.split("/");
|
||||
const QString single_file_name = parts.takeLast();
|
||||
Q_ASSERT(files_path.isEmpty());
|
||||
files_path << single_file_name;
|
||||
save_path = "/"+parts.join("/");
|
||||
save_path = parts.join("/");
|
||||
}
|
||||
QDir savePath(save_path);
|
||||
// Check if savePath exists
|
||||
|
@ -523,7 +550,7 @@ void torrentAdditionDialog::renameSelectedFile() {
|
|||
// Skip file checking and directly start seeding
|
||||
if(addInSeed->isChecked()) {
|
||||
// Check if local file(s) actually exist
|
||||
if(is_magnet || QFile::exists(savePathTxt->text())) {
|
||||
if(is_magnet || QFile::exists(savePathTxt->currentText())) {
|
||||
TorrentTempData::setSeedingMode(hash, true);
|
||||
} else {
|
||||
QMessageBox::warning(0, tr("Seeding mode error"), tr("You chose to skip file checking. However, local files do not seem to exist in the current destionation folder. Please disable this feature or update the save path."));
|
||||
|
@ -549,12 +576,61 @@ void torrentAdditionDialog::renameSelectedFile() {
|
|||
h.pause();
|
||||
emit torrentPaused(h);
|
||||
}
|
||||
// Save path history
|
||||
saveTruncatedPathHistory();
|
||||
// Close the dialog
|
||||
close();
|
||||
}
|
||||
|
||||
void torrentAdditionDialog::updateLabelInSavePath(QString label) {
|
||||
if(appendLabelToSavePath) {
|
||||
savePathTxt->setText(misc::updateLabelInSavePath(defaultSavePath, savePathTxt->text(), old_label, label));
|
||||
savePathTxt->setEditText(misc::updateLabelInSavePath(defaultSavePath, savePathTxt->currentText(), old_label, label));
|
||||
// Update other combo items
|
||||
for(int i=0; i<savePathTxt->count(); ++i) {
|
||||
savePathTxt->setItemText(i, misc::updateLabelInSavePath(defaultSavePath, savePathTxt->itemText(i), old_label, label));
|
||||
}
|
||||
old_label = label;
|
||||
}
|
||||
}
|
||||
|
||||
// Get current save path without last part and without label
|
||||
QString torrentAdditionDialog::getCurrentTruncatedSavePath() const {
|
||||
QStringList parts = savePathTxt->currentText().replace("\\", "/").split("/");
|
||||
if(parts.last().isEmpty())
|
||||
parts.removeLast();
|
||||
// Remove last part
|
||||
parts.removeLast();
|
||||
if(appendLabelToSavePath) {
|
||||
// Remove label
|
||||
if(parts.last() == comboLabel->currentText())
|
||||
parts.removeLast();
|
||||
}
|
||||
const QString truncated_path = parts.join("/")+"/";
|
||||
qDebug("Truncated save path: %s", qPrintable(truncated_path));
|
||||
return truncated_path;
|
||||
}
|
||||
|
||||
void torrentAdditionDialog::saveTruncatedPathHistory() {
|
||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||
const QString current_save_path = getCurrentTruncatedSavePath();
|
||||
// Get current history
|
||||
QStringList history = settings.value("TorrentAdditionDlg/save_path_history").toStringList();
|
||||
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
|
||||
if(!history.contains(current_save_path, Qt::CaseSensitive)) {
|
||||
#else
|
||||
if(!history.contains(current_save_path, Qt::CaseInsensitive)) {
|
||||
#endif
|
||||
// Add save path to history
|
||||
history << current_save_path;
|
||||
// Limit list size
|
||||
if(history.size() > 8)
|
||||
history.removeFirst();
|
||||
// Save history
|
||||
settings.setValue("TorrentAdditionDlg/save_path_history", history);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList torrentAdditionDialog::getSavePathHistory() const {
|
||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||
return settings.value("TorrentAdditionDlg/save_path_history").toStringList();
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ public:
|
|||
void saveSettings();
|
||||
void showLoadMagnetURI(QString magnet_uri);
|
||||
void showLoad(QString filePath, QString from_url=QString::null);
|
||||
QString getCurrentTruncatedSavePath() const;
|
||||
|
||||
public slots:
|
||||
void displayContentListMenu(const QPoint&);
|
||||
|
@ -80,6 +81,8 @@ public slots:
|
|||
void on_OkButton_clicked();
|
||||
void renameTorrentNameInModel(QString file_path);
|
||||
void hideTorrentContent();
|
||||
void saveTruncatedPathHistory();
|
||||
QStringList getSavePathHistory() const;
|
||||
|
||||
public slots:
|
||||
void updateLabelInSavePath(QString label);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>585</width>
|
||||
<width>560</width>
|
||||
<height>517</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -29,20 +29,14 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="savePathLbl">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>50</weight>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save path:</string>
|
||||
|
@ -50,7 +44,17 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="savePathTxt"/>
|
||||
<widget class="QComboBox" name="savePathTxt">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="browseButton">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue