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

This commit is contained in:
Christophe Dumez 2010-06-27 16:30:37 +00:00
parent 67f41ad991
commit ca762139f6
4 changed files with 555 additions and 471 deletions

View file

@ -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

View file

@ -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);
@ -66,15 +84,15 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
#endif #endif
// Set Add button as default // Set Add button as default
OkButton->setDefault(true); OkButton->setDefault(true);
} }
torrentAdditionDialog::~torrentAdditionDialog() { torrentAdditionDialog::~torrentAdditionDialog() {
saveSettings(); saveSettings();
delete PropDelegate; delete PropDelegate;
delete PropListModel; delete PropListModel;
} }
void torrentAdditionDialog::readSettings() { void torrentAdditionDialog::readSettings() {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
// Restore size and position // Restore size and position
resize(settings.value(QString::fromUtf8("TorrentAdditionDlg/size"), size()).toSize()); resize(settings.value(QString::fromUtf8("TorrentAdditionDlg/size"), size()).toSize());
@ -88,9 +106,9 @@ void torrentAdditionDialog::readSettings() {
torrentContentList->setColumnWidth(i, contentColsWidths.at(i)); torrentContentList->setColumnWidth(i, contentColsWidths.at(i));
} }
} }
} }
void torrentAdditionDialog::saveSettings() { void torrentAdditionDialog::saveSettings() {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
if(!is_magnet && t.get() && t->is_valid() && t->num_files() > 1) { if(!is_magnet && t.get() && t->is_valid() && t->num_files() > 1) {
QStringList contentColsWidths; QStringList contentColsWidths;
@ -103,15 +121,15 @@ void torrentAdditionDialog::saveSettings() {
settings.setValue("TorrentAdditionDlg/size", size()+QSize(0, hidden_height)); settings.setValue("TorrentAdditionDlg/size", size()+QSize(0, hidden_height));
qDebug("pos: (%d, %d)", pos().x(), pos().y()); qDebug("pos: (%d, %d)", pos().x(), pos().y());
settings.setValue("TorrentAdditionDlg/pos", pos()); settings.setValue("TorrentAdditionDlg/pos", pos());
} }
void torrentAdditionDialog::renameTorrentNameInModel(QString file_path) { void torrentAdditionDialog::renameTorrentNameInModel(QString file_path) {
file_path = file_path.replace("\\", "/"); file_path = file_path.replace("\\", "/");
// Rename in torrent files model too // Rename in torrent files model too
PropListModel->setData(PropListModel->index(0, 0), file_path.split("/", QString::SkipEmptyParts).last()); PropListModel->setData(PropListModel->index(0, 0), file_path.split("/", QString::SkipEmptyParts).last());
} }
void torrentAdditionDialog::hideTorrentContent() { void torrentAdditionDialog::hideTorrentContent() {
// Disable useless widgets // Disable useless widgets
hidden_height += torrentContentList->height(); hidden_height += torrentContentList->height();
torrentContentList->setVisible(false); torrentContentList->setVisible(false);
@ -124,9 +142,9 @@ void torrentAdditionDialog::hideTorrentContent() {
// Resize main window // Resize main window
setMinimumSize(0, 0); setMinimumSize(0, 0);
resize(width(), height()-hidden_height); resize(width(), height()-hidden_height);
} }
void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) { void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) {
show(); show();
is_magnet = true; is_magnet = true;
this->from_url = magnet_uri; this->from_url = magnet_uri;
@ -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
@ -159,9 +177,9 @@ void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) {
} }
// No need to display torrent content // No need to display torrent content
hideTorrentContent(); hideTorrentContent();
} }
void torrentAdditionDialog::showLoad(QString filePath, QString from_url) { void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
is_magnet = false; is_magnet = false;
if(!QFile::exists(filePath)) { if(!QFile::exists(filePath)) {
close(); close();
@ -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"));
@ -250,9 +276,9 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
show(); show();
if(t->num_files() <= 1) if(t->num_files() <= 1)
hideTorrentContent(); hideTorrentContent();
} }
void torrentAdditionDialog::displayContentListMenu(const QPoint&) { void torrentAdditionDialog::displayContentListMenu(const QPoint&) {
QMenu myFilesLlistMenu; QMenu myFilesLlistMenu;
const QModelIndexList &selectedRows = torrentContentList->selectionModel()->selectedRows(0); const QModelIndexList &selectedRows = torrentContentList->selectionModel()->selectedRows(0);
QAction *actRename = 0; QAction *actRename = 0;
@ -287,9 +313,9 @@ void torrentAdditionDialog::displayContentListMenu(const QPoint&) {
} }
} }
} }
} }
void torrentAdditionDialog::renameSelectedFile() { void torrentAdditionDialog::renameSelectedFile() {
const QModelIndexList &selectedIndexes = torrentContentList->selectionModel()->selectedRows(0); const QModelIndexList &selectedIndexes = torrentContentList->selectionModel()->selectedRows(0);
Q_ASSERT(selectedIndexes.size() == 1); Q_ASSERT(selectedIndexes.size() == 1);
const QModelIndex &index = selectedIndexes.first(); const QModelIndex &index = selectedIndexes.first();
@ -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();
}

View file

@ -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);

View file

@ -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">