mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-26 19:26:59 +03:00
Make AddNewTorrentDialog behavior uniform
This commit is contained in:
parent
654c8edc6b
commit
a96cabfe73
3 changed files with 46 additions and 83 deletions
|
@ -69,9 +69,9 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent)
|
||||||
|
|
||||||
Preferences* const pref = Preferences::instance();
|
Preferences* const pref = Preferences::instance();
|
||||||
ui->start_torrent_cb->setChecked(!pref->addTorrentsInPause());
|
ui->start_torrent_cb->setChecked(!pref->addTorrentsInPause());
|
||||||
ui->save_path_combo->addItem(Utils::Fs::toNativePath(pref->getSavePath()), pref->getSavePath());
|
ui->savePathComboBox->addItem(Utils::Fs::toNativePath(pref->getSavePath()), pref->getSavePath());
|
||||||
loadSavePathHistory();
|
loadSavePathHistory();
|
||||||
connect(ui->save_path_combo, SIGNAL(currentIndexChanged(int)), SLOT(onSavePathChanged(int)));
|
connect(ui->savePathComboBox, SIGNAL(currentIndexChanged(int)), SLOT(onSavePathChanged(int)));
|
||||||
connect(ui->browse_button, SIGNAL(clicked()), SLOT(browseButton_clicked()));
|
connect(ui->browse_button, SIGNAL(clicked()), SLOT(browseButton_clicked()));
|
||||||
ui->default_save_path_cb->setVisible(false); // Default path is selected by default
|
ui->default_save_path_cb->setVisible(false); // Default path is selected by default
|
||||||
|
|
||||||
|
@ -272,12 +272,7 @@ void AddNewTorrentDialog::showAdvancedSettings(bool show)
|
||||||
ui->adv_button->setText(QString::fromUtf8(C_UP));
|
ui->adv_button->setText(QString::fromUtf8(C_UP));
|
||||||
ui->settings_group->setVisible(true);
|
ui->settings_group->setVisible(true);
|
||||||
ui->infoGroup->setVisible(true);
|
ui->infoGroup->setVisible(true);
|
||||||
if (m_hasMetadata && (m_torrentInfo.filesCount() > 1)) {
|
ui->content_tree->setVisible(m_hasMetadata);
|
||||||
ui->content_tree->setVisible(true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ui->content_tree->setVisible(false);
|
|
||||||
}
|
|
||||||
static_cast<QVBoxLayout*>(layout())->insertWidget(layout()->indexOf(ui->never_show_cb) + 1, ui->adv_button);
|
static_cast<QVBoxLayout*>(layout())->insertWidget(layout()->indexOf(ui->never_show_cb) + 1, ui->adv_button);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -292,7 +287,7 @@ void AddNewTorrentDialog::showAdvancedSettings(bool show)
|
||||||
|
|
||||||
void AddNewTorrentDialog::saveSavePathHistory() const
|
void AddNewTorrentDialog::saveSavePathHistory() const
|
||||||
{
|
{
|
||||||
QDir selected_save_path(ui->save_path_combo->itemData(ui->save_path_combo->currentIndex()).toString());
|
QDir selected_save_path(ui->savePathComboBox->itemData(ui->savePathComboBox->currentIndex()).toString());
|
||||||
Preferences* const pref = Preferences::instance();
|
Preferences* const pref = Preferences::instance();
|
||||||
// Get current history
|
// Get current history
|
||||||
QStringList history = pref->getAddNewTorrentDialogPathHistory();
|
QStringList history = pref->getAddNewTorrentDialogPathHistory();
|
||||||
|
@ -314,20 +309,12 @@ void AddNewTorrentDialog::saveSavePathHistory() const
|
||||||
int AddNewTorrentDialog::indexOfSavePath(const QString &save_path)
|
int AddNewTorrentDialog::indexOfSavePath(const QString &save_path)
|
||||||
{
|
{
|
||||||
QDir saveDir(save_path);
|
QDir saveDir(save_path);
|
||||||
for(int i = 0; i < ui->save_path_combo->count(); ++i)
|
for (int i = 0; i < ui->savePathComboBox->count(); ++i)
|
||||||
if (QDir(ui->save_path_combo->itemData(i).toString()) == saveDir)
|
if (QDir(ui->savePathComboBox->itemData(i).toString()) == saveDir)
|
||||||
return i;
|
return i;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddNewTorrentDialog::updateFileNameInSavePaths(const QString &new_filename)
|
|
||||||
{
|
|
||||||
for(int i = 0; i < ui->save_path_combo->count(); ++i) {
|
|
||||||
const QDir folder(ui->save_path_combo->itemData(i).toString());
|
|
||||||
ui->save_path_combo->setItemText(i, Utils::Fs::toNativePath(folder.absoluteFilePath(new_filename)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AddNewTorrentDialog::updateDiskSpaceLabel()
|
void AddNewTorrentDialog::updateDiskSpaceLabel()
|
||||||
{
|
{
|
||||||
// Determine torrent size
|
// Determine torrent size
|
||||||
|
@ -349,8 +336,8 @@ void AddNewTorrentDialog::updateDiskSpaceLabel()
|
||||||
QString size_string = torrent_size ? Utils::Misc::friendlyUnit(torrent_size) : QString(tr("Not Available", "This size is unavailable."));
|
QString size_string = torrent_size ? Utils::Misc::friendlyUnit(torrent_size) : QString(tr("Not Available", "This size is unavailable."));
|
||||||
size_string += " (";
|
size_string += " (";
|
||||||
size_string += tr("Free space on disk: %1").arg(Utils::Misc::friendlyUnit(Utils::Fs::freeDiskSpaceOnPath(
|
size_string += tr("Free space on disk: %1").arg(Utils::Misc::friendlyUnit(Utils::Fs::freeDiskSpaceOnPath(
|
||||||
ui->save_path_combo->itemData(
|
ui->savePathComboBox->itemData(
|
||||||
ui->save_path_combo->currentIndex()).toString())));
|
ui->savePathComboBox->currentIndex()).toString())));
|
||||||
size_string += ")";
|
size_string += ")";
|
||||||
ui->size_lbl->setText(size_string);
|
ui->size_lbl->setText(size_string);
|
||||||
}
|
}
|
||||||
|
@ -359,7 +346,7 @@ void AddNewTorrentDialog::onSavePathChanged(int index)
|
||||||
{
|
{
|
||||||
// Toggle default save path setting checkbox visibility
|
// Toggle default save path setting checkbox visibility
|
||||||
ui->default_save_path_cb->setChecked(false);
|
ui->default_save_path_cb->setChecked(false);
|
||||||
ui->default_save_path_cb->setVisible(QDir(ui->save_path_combo->itemData(ui->save_path_combo->currentIndex()).toString()) != QDir(Preferences::instance()->getSavePath()));
|
ui->default_save_path_cb->setVisible(QDir(ui->savePathComboBox->itemData(ui->savePathComboBox->currentIndex()).toString()) != QDir(Preferences::instance()->getSavePath()));
|
||||||
|
|
||||||
// Remember index
|
// Remember index
|
||||||
m_oldIndex = index;
|
m_oldIndex = index;
|
||||||
|
@ -369,51 +356,36 @@ void AddNewTorrentDialog::onSavePathChanged(int index)
|
||||||
|
|
||||||
void AddNewTorrentDialog::browseButton_clicked()
|
void AddNewTorrentDialog::browseButton_clicked()
|
||||||
{
|
{
|
||||||
disconnect(ui->save_path_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(onSavePathChanged(int)));
|
disconnect(ui->savePathComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onSavePathChanged(int)));
|
||||||
// User is asking for a new save path
|
|
||||||
QString cur_save_path = ui->save_path_combo->itemText(m_oldIndex);
|
|
||||||
QString new_path, old_filename, new_filename;
|
|
||||||
|
|
||||||
if (m_torrentInfo.isValid() && (m_torrentInfo.filesCount() == 1)) {
|
// User is asking for a new save path
|
||||||
old_filename = Utils::Fs::fileName(cur_save_path);
|
QString curSavePath = ui->savePathComboBox->itemText(m_oldIndex);
|
||||||
new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), cur_save_path, QString(), 0, QFileDialog::DontConfirmOverwrite);
|
QString newPath;
|
||||||
if (!new_path.isEmpty())
|
|
||||||
new_path = Utils::Fs::branchPath(new_path, &new_filename);
|
if (!curSavePath.isEmpty() && QDir(curSavePath).exists())
|
||||||
qDebug() << "new_path: " << new_path;
|
newPath = QFileDialog::getExistingDirectory(this, tr("Choose save path"), curSavePath);
|
||||||
qDebug() << "new_filename: " << new_filename;
|
else
|
||||||
}
|
newPath = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
||||||
else {
|
|
||||||
if (!cur_save_path.isEmpty() && QDir(cur_save_path).exists())
|
if (!newPath.isEmpty()) {
|
||||||
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), cur_save_path);
|
const int existingIndex = indexOfSavePath(newPath);
|
||||||
else
|
if (existingIndex >= 0) {
|
||||||
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
ui->savePathComboBox->setCurrentIndex(existingIndex);
|
||||||
}
|
|
||||||
if (!new_path.isEmpty()) {
|
|
||||||
const int existing_index = indexOfSavePath(new_path);
|
|
||||||
if (existing_index >= 0) {
|
|
||||||
ui->save_path_combo->setCurrentIndex(existing_index);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// New path, prepend to combo box
|
// New path, prepend to combo box
|
||||||
if (!new_filename.isEmpty())
|
ui->savePathComboBox->insertItem(0, Utils::Fs::toNativePath(newPath), newPath);
|
||||||
ui->save_path_combo->insertItem(0, Utils::Fs::toNativePath(QDir(new_path).absoluteFilePath(new_filename)), new_path);
|
ui->savePathComboBox->setCurrentIndex(0);
|
||||||
else
|
|
||||||
ui->save_path_combo->insertItem(0, Utils::Fs::toNativePath(new_path), new_path);
|
|
||||||
ui->save_path_combo->setCurrentIndex(0);
|
|
||||||
}
|
|
||||||
// Update file name in all save_paths
|
|
||||||
if (!new_filename.isEmpty() && !Utils::Fs::sameFileNames(old_filename, new_filename)) {
|
|
||||||
m_torrentInfo.renameFile(0, new_filename);
|
|
||||||
updateFileNameInSavePaths(new_filename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onSavePathChanged(0);
|
onSavePathChanged(0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Restore index
|
// Restore index
|
||||||
ui->save_path_combo->setCurrentIndex(m_oldIndex);
|
ui->savePathComboBox->setCurrentIndex(m_oldIndex);
|
||||||
}
|
}
|
||||||
connect(ui->save_path_combo, SIGNAL(currentIndexChanged(int)), SLOT(onSavePathChanged(int)));
|
|
||||||
|
connect(ui->savePathComboBox, SIGNAL(currentIndexChanged(int)), SLOT(onSavePathChanged(int)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddNewTorrentDialog::renameSelectedFile()
|
void AddNewTorrentDialog::renameSelectedFile()
|
||||||
|
@ -537,7 +509,7 @@ void AddNewTorrentDialog::loadSavePathHistory()
|
||||||
QStringList raw_path_history = Preferences::instance()->getAddNewTorrentDialogPathHistory();
|
QStringList raw_path_history = Preferences::instance()->getAddNewTorrentDialogPathHistory();
|
||||||
foreach (const QString &sp, raw_path_history)
|
foreach (const QString &sp, raw_path_history)
|
||||||
if (QDir(sp) != default_save_path)
|
if (QDir(sp) != default_save_path)
|
||||||
ui->save_path_combo->addItem(Utils::Fs::toNativePath(sp), sp);
|
ui->savePathComboBox->addItem(Utils::Fs::toNativePath(sp), sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddNewTorrentDialog::displayContentTreeMenu(const QPoint&)
|
void AddNewTorrentDialog::displayContentTreeMenu(const QPoint&)
|
||||||
|
@ -545,7 +517,7 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint&)
|
||||||
QMenu myFilesLlistMenu;
|
QMenu myFilesLlistMenu;
|
||||||
const QModelIndexList selectedRows = ui->content_tree->selectionModel()->selectedRows(0);
|
const QModelIndexList selectedRows = ui->content_tree->selectionModel()->selectedRows(0);
|
||||||
QAction *actRename = 0;
|
QAction *actRename = 0;
|
||||||
if ((selectedRows.size() == 1) && (m_torrentInfo.filesCount() > 1)) {
|
if (selectedRows.size() == 1) {
|
||||||
actRename = myFilesLlistMenu.addAction(GuiIconProvider::instance()->getIcon("edit-rename"), tr("Rename..."));
|
actRename = myFilesLlistMenu.addAction(GuiIconProvider::instance()->getIcon("edit-rename"), tr("Rename..."));
|
||||||
myFilesLlistMenu.addSeparator();
|
myFilesLlistMenu.addSeparator();
|
||||||
}
|
}
|
||||||
|
@ -607,7 +579,7 @@ void AddNewTorrentDialog::accept()
|
||||||
saveSavePathHistory();
|
saveSavePathHistory();
|
||||||
pref->useAdditionDialog(!ui->never_show_cb->isChecked());
|
pref->useAdditionDialog(!ui->never_show_cb->isChecked());
|
||||||
|
|
||||||
QString savePath = ui->save_path_combo->itemData(ui->save_path_combo->currentIndex()).toString();
|
QString savePath = ui->savePathComboBox->itemData(ui->savePathComboBox->currentIndex()).toString();
|
||||||
if (ui->default_save_path_cb->isChecked()) {
|
if (ui->default_save_path_cb->isChecked()) {
|
||||||
pref->setSavePath(savePath);
|
pref->setSavePath(savePath);
|
||||||
pref->apply();
|
pref->apply();
|
||||||
|
@ -682,30 +654,22 @@ void AddNewTorrentDialog::setupTreeview()
|
||||||
ui->date_lbl->setText(!m_torrentInfo.creationDate().isNull() ? m_torrentInfo.creationDate().toString(Qt::DefaultLocaleShortDate) : tr("Not available"));
|
ui->date_lbl->setText(!m_torrentInfo.creationDate().isNull() ? m_torrentInfo.creationDate().toString(Qt::DefaultLocaleShortDate) : tr("Not available"));
|
||||||
|
|
||||||
// Prepare content tree
|
// Prepare content tree
|
||||||
if (m_torrentInfo.filesCount() > 1) {
|
m_contentModel = new TorrentContentFilterModel(this);
|
||||||
m_contentModel = new TorrentContentFilterModel(this);
|
connect(m_contentModel->model(), SIGNAL(filteredFilesChanged()), SLOT(updateDiskSpaceLabel()));
|
||||||
connect(m_contentModel->model(), SIGNAL(filteredFilesChanged()), SLOT(updateDiskSpaceLabel()));
|
ui->content_tree->setModel(m_contentModel);
|
||||||
ui->content_tree->setModel(m_contentModel);
|
ui->content_tree->hideColumn(PROGRESS);
|
||||||
ui->content_tree->hideColumn(PROGRESS);
|
m_contentDelegate = new PropListDelegate();
|
||||||
m_contentDelegate = new PropListDelegate();
|
ui->content_tree->setItemDelegate(m_contentDelegate);
|
||||||
ui->content_tree->setItemDelegate(m_contentDelegate);
|
connect(ui->content_tree, SIGNAL(clicked(const QModelIndex &)), ui->content_tree, SLOT(edit(const QModelIndex &)));
|
||||||
connect(ui->content_tree, SIGNAL(clicked(const QModelIndex &)), ui->content_tree, SLOT(edit(const QModelIndex &)));
|
connect(ui->content_tree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(displayContentTreeMenu(const QPoint &)));
|
||||||
connect(ui->content_tree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(displayContentTreeMenu(const QPoint &)));
|
|
||||||
|
|
||||||
// List files in torrent
|
// List files in torrent
|
||||||
m_contentModel->model()->setupModelData(m_torrentInfo);
|
m_contentModel->model()->setupModelData(m_torrentInfo);
|
||||||
if (!m_headerState.isEmpty())
|
if (!m_headerState.isEmpty())
|
||||||
ui->content_tree->header()->restoreState(m_headerState);
|
ui->content_tree->header()->restoreState(m_headerState);
|
||||||
|
|
||||||
// Expand root folder
|
// Expand root folder
|
||||||
ui->content_tree->setExpanded(m_contentModel->index(0, 0), true);
|
ui->content_tree->setExpanded(m_contentModel->index(0, 0), true);
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Update save paths (append file name to them)
|
|
||||||
QString single_file_relpath = m_torrentInfo.filePath(0);
|
|
||||||
for (int i = 0; i < ui->save_path_combo->count(); ++i)
|
|
||||||
ui->save_path_combo->setItemText(i, Utils::Fs::toNativePath(QDir(ui->save_path_combo->itemText(i)).absoluteFilePath(single_file_relpath)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDiskSpaceLabel();
|
updateDiskSpaceLabel();
|
||||||
|
|
|
@ -87,7 +87,6 @@ private:
|
||||||
void loadSavePathHistory();
|
void loadSavePathHistory();
|
||||||
void saveSavePathHistory() const;
|
void saveSavePathHistory() const;
|
||||||
int indexOfSavePath(const QString& save_path);
|
int indexOfSavePath(const QString& save_path);
|
||||||
void updateFileNameInSavePaths(const QString& new_filename);
|
|
||||||
void loadState();
|
void loadState();
|
||||||
void saveState();
|
void saveState();
|
||||||
void setMetadataProgressIndicator(bool visibleIndicator, const QString &labelText = QString());
|
void setMetadataProgressIndicator(bool visibleIndicator, const QString &labelText = QString());
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QComboBox" name="save_path_combo">
|
<widget class="QComboBox" name="savePathComboBox">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
|
|
Loading…
Reference in a new issue