Browse Source

FEATURE: Remember previous save paths in torrent addition dialog (closes #579305)

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
ca762139f6
  1. 1
      Changelog
  2. 110
      src/torrentadditiondlg.cpp
  3. 3
      src/torrentadditiondlg.h
  4. 32
      src/ui/torrentadditiondlg.ui

1
Changelog

@ -1,5 +1,6 @@
* Unreleased - Christophe Dumez <chris@qbittorrent.org> - v2.3.0 * 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: 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: Max number of half-open connections can now be edited
- FEATURE: Added support for strict super seeding - FEATURE: Added support for strict super seeding
- FEATURE: The user can force listening on a particular network interface - FEATURE: The user can force listening on a particular network interface

110
src/torrentadditiondlg.cpp

@ -53,10 +53,28 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
defaultSavePath = Preferences::getSavePath(); defaultSavePath = Preferences::getSavePath();
appendLabelToSavePath = Preferences::appendTorrentLabel(); appendLabelToSavePath = Preferences::appendTorrentLabel();
QString display_path = defaultSavePath; QString display_path = defaultSavePath;
if(!display_path.endsWith("/") && !display_path.endsWith("\\"))
display_path += "/";
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
display_path = display_path.replace("/", "\\"); display_path = display_path.replace("/", "\\");
#endif #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()) { if(Preferences::addTorrentsInPause()) {
addInPause->setChecked(true); addInPause->setChecked(true);
//addInPause->setEnabled(false); //addInPause->setEnabled(false);
@ -141,10 +159,10 @@ void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) {
if(fileName.isEmpty()) { if(fileName.isEmpty()) {
fileName = tr("Magnet Link"); fileName = tr("Magnet Link");
} else { } else {
QString save_path = savePathTxt->text(); QString save_path = savePathTxt->currentText();
if(!save_path.endsWith(QDir::separator())) if(!save_path.endsWith(QDir::separator()))
save_path += 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>")); fileNameLbl->setText(QString::fromUtf8("<center><b>")+fileName+QString::fromUtf8("</b></center>"));
// Update display // Update display
@ -193,10 +211,10 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
} }
if(nbFiles == 1) { if(nbFiles == 1) {
// Update properties model whenever the file path is edited // 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 root_folder = misc::truncateRootFolder(t);
QString save_path = savePathTxt->text(); QString save_path = savePathTxt->currentText();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path = save_path.replace("/", "\\"); save_path = save_path.replace("/", "\\");
#endif #endif
@ -204,7 +222,11 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
save_path += QDir::separator(); save_path += QDir::separator();
// If the torrent has a root folder, append it to the save path // If the torrent has a root folder, append it to the save path
if(!root_folder.isEmpty()) { 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) { if(nbFiles == 1) {
// single file torrent // single file torrent
@ -212,7 +234,11 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
single_file_relpath = single_file_relpath.replace("/", "\\"); single_file_relpath = single_file_relpath.replace("/", "\\");
#endif #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 // Setting file name
fileName = misc::toQStringU(t->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()); 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(); updateDiskSpaceLabels();
// Load custom labels // Load custom labels
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
@ -389,7 +415,8 @@ void torrentAdditionDialog::renameSelectedFile() {
} }
void torrentAdditionDialog::updateDiskSpaceLabels() { 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)); lbl_disk_space->setText(misc::friendlyUnit(available));
if(!is_magnet) { if(!is_magnet) {
// Determine torrent size // Determine torrent size
@ -425,7 +452,7 @@ void torrentAdditionDialog::renameSelectedFile() {
void torrentAdditionDialog::on_browseButton_clicked(){ void torrentAdditionDialog::on_browseButton_clicked(){
QString new_path; QString new_path;
QString save_path = savePathTxt->text(); QString save_path = savePathTxt->currentText();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path = save_path.replace("\\", "/"); save_path = save_path.replace("\\", "/");
#endif #endif
@ -444,7 +471,7 @@ void torrentAdditionDialog::renameSelectedFile() {
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
new_path = new_path.replace("/", "\\"); new_path = new_path.replace("/", "\\");
#endif #endif
savePathTxt->setText(new_path); savePathTxt->setEditText(new_path);
} }
} }
@ -463,22 +490,22 @@ void torrentAdditionDialog::renameSelectedFile() {
} }
void torrentAdditionDialog::on_OkButton_clicked(){ 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")); QMessageBox::critical(0, tr("Empty save path"), tr("Please enter a save path"));
return; return;
} }
QString save_path = savePathTxt->text(); QString save_path = savePathTxt->currentText();
#if defined(Q_WS_WIN) || defined(Q_OS_OS2) #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path = save_path.replace("\\", "/"); save_path = save_path.replace("\\", "/");
#endif #endif
save_path = misc::expandPath(save_path); save_path = misc::expandPath(save_path);
if(!is_magnet && t->num_files() == 1) { if(!is_magnet && t->num_files() == 1) {
// Remove file name // Remove file name
QStringList parts = save_path.split("/", QString::SkipEmptyParts); QStringList parts = save_path.split("/");
const QString single_file_name = parts.takeLast(); const QString single_file_name = parts.takeLast();
Q_ASSERT(files_path.isEmpty()); Q_ASSERT(files_path.isEmpty());
files_path << single_file_name; files_path << single_file_name;
save_path = "/"+parts.join("/"); save_path = parts.join("/");
} }
QDir savePath(save_path); QDir savePath(save_path);
// Check if savePath exists // Check if savePath exists
@ -523,7 +550,7 @@ void torrentAdditionDialog::renameSelectedFile() {
// Skip file checking and directly start seeding // Skip file checking and directly start seeding
if(addInSeed->isChecked()) { if(addInSeed->isChecked()) {
// Check if local file(s) actually exist // 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); TorrentTempData::setSeedingMode(hash, true);
} else { } 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.")); 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(); h.pause();
emit torrentPaused(h); emit torrentPaused(h);
} }
// Save path history
saveTruncatedPathHistory();
// Close the dialog
close(); close();
} }
void torrentAdditionDialog::updateLabelInSavePath(QString label) { void torrentAdditionDialog::updateLabelInSavePath(QString label) {
if(appendLabelToSavePath) { 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; 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();
}

3
src/torrentadditiondlg.h

@ -68,6 +68,7 @@ public:
void saveSettings(); void saveSettings();
void showLoadMagnetURI(QString magnet_uri); void showLoadMagnetURI(QString magnet_uri);
void showLoad(QString filePath, QString from_url=QString::null); void showLoad(QString filePath, QString from_url=QString::null);
QString getCurrentTruncatedSavePath() const;
public slots: public slots:
void displayContentListMenu(const QPoint&); void displayContentListMenu(const QPoint&);
@ -80,6 +81,8 @@ public slots:
void on_OkButton_clicked(); void on_OkButton_clicked();
void renameTorrentNameInModel(QString file_path); void renameTorrentNameInModel(QString file_path);
void hideTorrentContent(); void hideTorrentContent();
void saveTruncatedPathHistory();
QStringList getSavePathHistory() const;
public slots: public slots:
void updateLabelInSavePath(QString label); void updateLabelInSavePath(QString label);

32
src/ui/torrentadditiondlg.ui

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>585</width> <width>560</width>
<height>517</height> <height>517</height>
</rect> </rect>
</property> </property>
@ -29,20 +29,14 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="savePathLbl"> <widget class="QLabel" name="savePathLbl">
<property name="font"> <property name="sizePolicy">
<font> <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<weight>50</weight> <horstretch>0</horstretch>
<bold>false</bold> <verstretch>0</verstretch>
</font> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Save path:</string> <string>Save path:</string>
@ -50,7 +44,17 @@
</widget> </widget>
</item> </item>
<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>
<item> <item>
<widget class="QToolButton" name="browseButton"> <widget class="QToolButton" name="browseButton">

Loading…
Cancel
Save