mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-28 23:44:32 +00:00
Several torrent addition dialog fixes (Save path and label combo boxes)
This commit is contained in:
parent
7998395532
commit
214bb13843
@ -45,6 +45,7 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
|
|||||||
connect(torrentContentList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayContentListMenu(const QPoint&)));
|
connect(torrentContentList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayContentListMenu(const QPoint&)));
|
||||||
connect(selectAllButton, SIGNAL(clicked()), PropListModel, SLOT(selectAll()));
|
connect(selectAllButton, SIGNAL(clicked()), PropListModel, SLOT(selectAll()));
|
||||||
connect(selectNoneButton, SIGNAL(clicked()), PropListModel, SLOT(selectNone()));
|
connect(selectNoneButton, SIGNAL(clicked()), PropListModel, SLOT(selectNone()));
|
||||||
|
connect(comboLabel, SIGNAL(editTextChanged(QString)), this, SLOT(resetComboLabelIndex(QString)));
|
||||||
connect(comboLabel, SIGNAL(editTextChanged(QString)), this, SLOT(updateLabelInSavePath(QString)));
|
connect(comboLabel, SIGNAL(editTextChanged(QString)), this, SLOT(updateLabelInSavePath(QString)));
|
||||||
connect(comboLabel, SIGNAL(currentIndexChanged(QString)), this, SLOT(updateLabelInSavePath(QString)));
|
connect(comboLabel, SIGNAL(currentIndexChanged(QString)), this, SLOT(updateLabelInSavePath(QString)));
|
||||||
// Remember columns width
|
// Remember columns width
|
||||||
@ -52,21 +53,23 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
|
|||||||
//torrentContentList->header()->setResizeMode(0, QHeaderView::Stretch);
|
//torrentContentList->header()->setResizeMode(0, QHeaderView::Stretch);
|
||||||
defaultSavePath = Preferences::getSavePath();
|
defaultSavePath = Preferences::getSavePath();
|
||||||
appendLabelToSavePath = Preferences::appendTorrentLabel();
|
appendLabelToSavePath = Preferences::appendTorrentLabel();
|
||||||
QString display_path = defaultSavePath;
|
QString display_path = defaultSavePath.replace("\\", "/");
|
||||||
if(!display_path.endsWith("/") && !display_path.endsWith("\\"))
|
if(!display_path.endsWith("/"))
|
||||||
display_path += "/";
|
display_path += "/";
|
||||||
|
path_history << 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->addItem(display_path);
|
savePathTxt->addItem(display_path);
|
||||||
// Load save path history
|
// Load save path history
|
||||||
const QStringList path_history = getSavePathHistory();
|
QStringList raw_path_history = getSavePathHistory();
|
||||||
foreach(const QString &sp, path_history) {
|
foreach(const QString &sp, raw_path_history) {
|
||||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||||
if(sp.compare(display_path, Qt::CaseInsensitive) != 0) {
|
if(sp.compare(display_path, Qt::CaseInsensitive) != 0) {
|
||||||
#else
|
#else
|
||||||
if(sp.compare(display_path, Qt::CaseSensitive) != 0) {
|
if(sp.compare(display_path, Qt::CaseSensitive) != 0) {
|
||||||
#endif
|
#endif
|
||||||
|
path_history << sp;
|
||||||
QString dsp = sp;
|
QString dsp = sp;
|
||||||
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||||
dsp = dsp.replace("/", "\\");
|
dsp = dsp.replace("/", "\\");
|
||||||
@ -165,6 +168,7 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
|
|||||||
savePathTxt->setEditText(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>"));
|
||||||
|
connect(savePathTxt, SIGNAL(editTextChanged(QString)), this, SLOT(updateSavePathCurrentText(QString)));
|
||||||
// Update display
|
// Update display
|
||||||
updateDiskSpaceLabels();
|
updateDiskSpaceLabels();
|
||||||
// Load custom labels
|
// Load custom labels
|
||||||
@ -222,10 +226,10 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
|
|||||||
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->setEditText(save_path + root_folder + QDir::separator());
|
savePathTxt->setEditText(save_path + root_folder);
|
||||||
// Update other combo items
|
// Update other combo items
|
||||||
for(int i=0; i<savePathTxt->count(); ++i) {
|
for(int i=0; i<savePathTxt->count(); ++i) {
|
||||||
savePathTxt->setItemText(i, savePathTxt->itemText(i) + root_folder + QDir::separator());
|
savePathTxt->setItemText(i, savePathTxt->itemText(i) + root_folder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(nbFiles == 1) {
|
if(nbFiles == 1) {
|
||||||
@ -263,6 +267,7 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
connect(savePathTxt, SIGNAL(editTextChanged(QString)), this, SLOT(updateDiskSpaceLabels()));
|
connect(savePathTxt, SIGNAL(editTextChanged(QString)), this, SLOT(updateDiskSpaceLabels()));
|
||||||
|
connect(savePathTxt, SIGNAL(editTextChanged(QString)), this, SLOT(updateSavePathCurrentText(QString)));
|
||||||
updateDiskSpaceLabels();
|
updateDiskSpaceLabels();
|
||||||
// Load custom labels
|
// Load custom labels
|
||||||
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||||
@ -457,22 +462,42 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
|
|||||||
|
|
||||||
void torrentAdditionDialog::on_browseButton_clicked(){
|
void torrentAdditionDialog::on_browseButton_clicked(){
|
||||||
QString new_path;
|
QString new_path;
|
||||||
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) {
|
if(!is_magnet && t->num_files() == 1) {
|
||||||
new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), save_path);
|
new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), savePathTxt->currentText());
|
||||||
} else {
|
} else {
|
||||||
const QDir saveDir(save_path);
|
QString root_folder;
|
||||||
if(!save_path.isEmpty() && saveDir.exists()){
|
QString truncated_path = getCurrentTruncatedSavePath(&root_folder);
|
||||||
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), saveDir.absolutePath());
|
if(!truncated_path.isEmpty() && QDir(truncated_path).exists()){
|
||||||
|
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), truncated_path);
|
||||||
}else{
|
}else{
|
||||||
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
||||||
}
|
}
|
||||||
|
if(!new_path.isEmpty()) {
|
||||||
|
QStringList path_parts = new_path.replace("\\", "/").split("/");
|
||||||
|
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
|
||||||
|
if(!root_folder.isEmpty())
|
||||||
|
path_parts << root_folder;
|
||||||
|
// Construct new_path
|
||||||
|
new_path = path_parts.join(QDir::separator());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(!new_path.isEmpty()){
|
if(!new_path.isEmpty()) {
|
||||||
|
// Check if this new path already exists in the list
|
||||||
|
QString new_truncated_path = getTruncatedSavePath(new_path);
|
||||||
|
#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
|
||||||
|
const int cur_index = path_history.indexOf(QRegExp(new_truncated_path, Qt::CaseInsensitive));
|
||||||
|
#else
|
||||||
|
const int cur_index = path_history.indexOf(QRegExp(new_truncated_path, Qt::CaseSensitive));
|
||||||
|
#endif
|
||||||
|
if(cur_index >= 0) {
|
||||||
|
savePathTxt->setCurrentIndex(cur_index);
|
||||||
|
}
|
||||||
#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
|
||||||
@ -513,13 +538,6 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
|
|||||||
save_path = parts.join("/");
|
save_path = parts.join("/");
|
||||||
}
|
}
|
||||||
QDir savePath(save_path);
|
QDir savePath(save_path);
|
||||||
// Check if savePath exists
|
|
||||||
if(!savePath.exists()){
|
|
||||||
if(!savePath.mkpath(savePath.path())){
|
|
||||||
QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const QString ¤t_label = comboLabel->currentText().trimmed();
|
const QString ¤t_label = comboLabel->currentText().trimmed();
|
||||||
if (!current_label.isEmpty() && !misc::isValidFileSystemName(current_label)) {
|
if (!current_label.isEmpty() && !misc::isValidFileSystemName(current_label)) {
|
||||||
QMessageBox::warning(this, tr("Invalid label name"), tr("Please don't use any special characters in the label name."));
|
QMessageBox::warning(this, tr("Invalid label name"), tr("Please don't use any special characters in the label name."));
|
||||||
@ -568,6 +586,15 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
|
|||||||
QMessageBox::warning(0, tr("Invalid file selection"), tr("You must select at least one file in the torrent"));
|
QMessageBox::warning(0, tr("Invalid file selection"), tr("You must select at least one file in the torrent"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Save path history
|
||||||
|
saveTruncatedPathHistory();
|
||||||
|
// Check if savePath exists
|
||||||
|
if(!savePath.exists()){
|
||||||
|
if(!savePath.mkpath(savePath.path())){
|
||||||
|
QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
// save filtered files
|
// save filtered files
|
||||||
if(!is_magnet && t->num_files() > 1)
|
if(!is_magnet && t->num_files() > 1)
|
||||||
savePiecesPriorities();
|
savePiecesPriorities();
|
||||||
@ -581,36 +608,74 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
|
|||||||
h.pause();
|
h.pause();
|
||||||
emit torrentPaused(h);
|
emit torrentPaused(h);
|
||||||
}
|
}
|
||||||
// Save path history
|
|
||||||
saveTruncatedPathHistory();
|
|
||||||
// Close the dialog
|
// Close the dialog
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void torrentAdditionDialog::resetComboLabelIndex(QString text) {
|
||||||
|
// Select first index
|
||||||
|
if(text != comboLabel->itemText(comboLabel->currentIndex())) {
|
||||||
|
comboLabel->setItemText(0, text);
|
||||||
|
comboLabel->setCurrentIndex(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void torrentAdditionDialog::updateLabelInSavePath(QString label) {
|
void torrentAdditionDialog::updateLabelInSavePath(QString label) {
|
||||||
if(appendLabelToSavePath) {
|
if(appendLabelToSavePath) {
|
||||||
|
// Update Label in combobox
|
||||||
|
savePathTxt->setItemText(0, misc::updateLabelInSavePath(defaultSavePath, savePathTxt->itemText(0), old_label, label));
|
||||||
|
// update edit text
|
||||||
savePathTxt->setEditText(misc::updateLabelInSavePath(defaultSavePath, savePathTxt->currentText(), 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
|
void torrentAdditionDialog::updateSavePathCurrentText(QString path) {
|
||||||
QString torrentAdditionDialog::getCurrentTruncatedSavePath() const {
|
savePathTxt->setItemText(savePathTxt->currentIndex(), path);
|
||||||
QStringList parts = savePathTxt->currentText().replace("\\", "/").split("/");
|
path_history.replace(savePathTxt->currentIndex(), getCurrentTruncatedSavePath());
|
||||||
if(parts.last().isEmpty())
|
QString root_folder_or_file_name = "";
|
||||||
parts.removeLast();
|
getCurrentTruncatedSavePath(&root_folder_or_file_name);
|
||||||
// Remove last part
|
// Update other combo items
|
||||||
parts.removeLast();
|
for(int i=0; i<savePathTxt->count(); ++i) {
|
||||||
if(appendLabelToSavePath) {
|
if(i == savePathTxt->currentIndex()) continue;
|
||||||
// Remove label
|
QString item_path = path_history.at(i);
|
||||||
if(parts.last() == comboLabel->currentText())
|
if(item_path.isEmpty()) continue;
|
||||||
parts.removeLast();
|
// Append label
|
||||||
|
if(i == 0 && appendLabelToSavePath && QDir(item_path) == QDir(defaultSavePath) && !comboLabel->currentText().isEmpty())
|
||||||
|
item_path += comboLabel->currentText() + "/";
|
||||||
|
// Append root_folder or filename
|
||||||
|
if(!root_folder_or_file_name.isEmpty())
|
||||||
|
item_path += root_folder_or_file_name;
|
||||||
|
#if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
||||||
|
item_path = item_path.replace("/", "\\");
|
||||||
|
#endif
|
||||||
|
savePathTxt->setItemText(i, item_path);
|
||||||
}
|
}
|
||||||
const QString truncated_path = parts.join("/")+"/";
|
}
|
||||||
|
|
||||||
|
QString torrentAdditionDialog::getCurrentTruncatedSavePath(QString* root_folder_or_file_name) const {
|
||||||
|
QString save_path = savePathTxt->currentText();
|
||||||
|
return getTruncatedSavePath(save_path, root_folder_or_file_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get current save path without the torrent root folder nor the label label
|
||||||
|
QString torrentAdditionDialog::getTruncatedSavePath(QString save_path, QString* root_folder_or_file_name) const {
|
||||||
|
// Expand and clean path (~, .., .)
|
||||||
|
save_path = misc::expandPath(save_path);
|
||||||
|
QStringList parts = save_path.replace("\\", "/").split("/");
|
||||||
|
// Remove torrent root folder
|
||||||
|
if(!QDir(save_path).exists() || (!is_magnet && t->num_files() == 1)) {
|
||||||
|
QString tmp = parts.takeLast();
|
||||||
|
if(root_folder_or_file_name)
|
||||||
|
*root_folder_or_file_name = tmp;
|
||||||
|
}
|
||||||
|
// Remove label
|
||||||
|
if(appendLabelToSavePath && savePathTxt->currentIndex() == 0 && parts.last() == comboLabel->currentText()) {
|
||||||
|
parts.removeLast();
|
||||||
|
}
|
||||||
|
QString truncated_path = parts.join("/");
|
||||||
|
if(!truncated_path.endsWith("/"))
|
||||||
|
truncated_path += "/";
|
||||||
qDebug("Truncated save path: %s", qPrintable(truncated_path));
|
qDebug("Truncated save path: %s", qPrintable(truncated_path));
|
||||||
return truncated_path;
|
return truncated_path;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,8 @@ 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;
|
QString getCurrentTruncatedSavePath(QString* root_folder_or_file_name = 0) const;
|
||||||
|
QString getTruncatedSavePath(QString save_path, QString* root_folder_or_file_name = 0) const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void displayContentListMenu(const QPoint&);
|
void displayContentListMenu(const QPoint&);
|
||||||
@ -84,6 +85,8 @@ public slots:
|
|||||||
void saveTruncatedPathHistory();
|
void saveTruncatedPathHistory();
|
||||||
QStringList getSavePathHistory() const;
|
QStringList getSavePathHistory() const;
|
||||||
void updateLabelInSavePath(QString label);
|
void updateLabelInSavePath(QString label);
|
||||||
|
void updateSavePathCurrentText(QString path);
|
||||||
|
void resetComboLabelIndex(QString text);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void torrentPaused(QTorrentHandle &h);
|
void torrentPaused(QTorrentHandle &h);
|
||||||
@ -104,6 +107,7 @@ private:
|
|||||||
QStringList files_path;
|
QStringList files_path;
|
||||||
bool is_magnet;
|
bool is_magnet;
|
||||||
int hidden_height;
|
int hidden_height;
|
||||||
|
QStringList path_history;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user