mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-30 16:34:16 +00:00
Merge pull request #260 from sledgehammer999/add_new_torrent_layout
Improve usability of 'Add new torrent' dialog. Implements issue #225.
This commit is contained in:
commit
d45aff9169
@ -58,7 +58,8 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) :
|
|||||||
m_contentDelegate(0),
|
m_contentDelegate(0),
|
||||||
m_isMagnet(false),
|
m_isMagnet(false),
|
||||||
m_hasMetadata(false),
|
m_hasMetadata(false),
|
||||||
m_hasRenamedFile(false)
|
m_hasRenamedFile(false),
|
||||||
|
m_oldIndex(0)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
@ -69,9 +70,8 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) :
|
|||||||
ui->start_torrent_cb->setChecked(!pref->addTorrentsInPause());
|
ui->start_torrent_cb->setChecked(!pref->addTorrentsInPause());
|
||||||
ui->save_path_combo->addItem(fsutils::toNativePath(pref->getSavePath()), pref->getSavePath());
|
ui->save_path_combo->addItem(fsutils::toNativePath(pref->getSavePath()), pref->getSavePath());
|
||||||
loadSavePathHistory();
|
loadSavePathHistory();
|
||||||
ui->save_path_combo->insertSeparator(ui->save_path_combo->count());
|
|
||||||
ui->save_path_combo->addItem(tr("Other...", "Other save path..."));
|
|
||||||
connect(ui->save_path_combo, SIGNAL(currentIndexChanged(int)), SLOT(onSavePathChanged(int)));
|
connect(ui->save_path_combo, SIGNAL(currentIndexChanged(int)), SLOT(onSavePathChanged(int)));
|
||||||
|
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
|
||||||
|
|
||||||
// Load labels
|
// Load labels
|
||||||
@ -316,58 +316,61 @@ void AddNewTorrentDialog::updateDiskSpaceLabel() {
|
|||||||
|
|
||||||
void AddNewTorrentDialog::onSavePathChanged(int index)
|
void AddNewTorrentDialog::onSavePathChanged(int index)
|
||||||
{
|
{
|
||||||
static int old_index = 0;
|
|
||||||
Preferences* const pref = Preferences::instance();
|
|
||||||
|
|
||||||
if (index == (ui->save_path_combo->count() - 1)) {
|
|
||||||
disconnect(ui->save_path_combo, SIGNAL(currentIndexChanged(int)), this, SLOT(onSavePathChanged(int)));
|
|
||||||
// User is asking for a new save path
|
|
||||||
QString cur_save_path = ui->save_path_combo->itemText(old_index);
|
|
||||||
QString new_path, old_filename, new_filename;
|
|
||||||
|
|
||||||
if (m_torrentInfo && m_torrentInfo->num_files() == 1) {
|
|
||||||
old_filename = fsutils::fileName(cur_save_path);
|
|
||||||
new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), cur_save_path, QString(), 0, QFileDialog::DontConfirmOverwrite);
|
|
||||||
if (!new_path.isEmpty())
|
|
||||||
new_path = fsutils::branchPath(new_path, &new_filename);
|
|
||||||
qDebug() << "new_path: " << new_path;
|
|
||||||
qDebug() << "new_filename: " << new_filename;
|
|
||||||
} else {
|
|
||||||
if (!cur_save_path.isEmpty() && QDir(cur_save_path).exists())
|
|
||||||
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), cur_save_path);
|
|
||||||
else
|
|
||||||
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
|
||||||
}
|
|
||||||
if (!new_path.isEmpty()) {
|
|
||||||
const int existing_index = indexOfSavePath(new_path);
|
|
||||||
if (existing_index >= 0)
|
|
||||||
ui->save_path_combo->setCurrentIndex(existing_index);
|
|
||||||
else {
|
|
||||||
// New path, prepend to combo box
|
|
||||||
if (!new_filename.isEmpty())
|
|
||||||
ui->save_path_combo->insertItem(0, fsutils::toNativePath(QDir(new_path).absoluteFilePath(new_filename)), new_path);
|
|
||||||
else
|
|
||||||
ui->save_path_combo->insertItem(0, fsutils::toNativePath(new_path), new_path);
|
|
||||||
ui->save_path_combo->setCurrentIndex(0);
|
|
||||||
}
|
|
||||||
// Update file name in all save_paths
|
|
||||||
if (!new_filename.isEmpty() && !fsutils::sameFileNames(old_filename, new_filename)) {
|
|
||||||
m_hasRenamedFile = true;
|
|
||||||
m_filesPath[0] = new_filename;
|
|
||||||
updateFileNameInSavePaths(new_filename);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Restore index
|
|
||||||
ui->save_path_combo->setCurrentIndex(old_index);
|
|
||||||
}
|
|
||||||
connect(ui->save_path_combo, SIGNAL(currentIndexChanged(int)), SLOT(onSavePathChanged(int)));
|
|
||||||
}
|
|
||||||
// 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()) != pref->getSavePath());
|
ui->default_save_path_cb->setVisible(QDir(ui->save_path_combo->itemData(ui->save_path_combo->currentIndex()).toString()) != QDir(Preferences::instance()->getSavePath()));
|
||||||
relayout();
|
relayout();
|
||||||
|
|
||||||
// Remember index
|
// Remember index
|
||||||
old_index = ui->save_path_combo->currentIndex();
|
m_oldIndex = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddNewTorrentDialog::browseButton_clicked()
|
||||||
|
{
|
||||||
|
disconnect(ui->save_path_combo, 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 && m_torrentInfo->num_files() == 1) {
|
||||||
|
old_filename = fsutils::fileName(cur_save_path);
|
||||||
|
new_path = QFileDialog::getSaveFileName(this, tr("Choose save path"), cur_save_path, QString(), 0, QFileDialog::DontConfirmOverwrite);
|
||||||
|
if (!new_path.isEmpty())
|
||||||
|
new_path = fsutils::branchPath(new_path, &new_filename);
|
||||||
|
qDebug() << "new_path: " << new_path;
|
||||||
|
qDebug() << "new_filename: " << new_filename;
|
||||||
|
} else {
|
||||||
|
if (!cur_save_path.isEmpty() && QDir(cur_save_path).exists())
|
||||||
|
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), cur_save_path);
|
||||||
|
else
|
||||||
|
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
||||||
|
}
|
||||||
|
if (!new_path.isEmpty()) {
|
||||||
|
const int existing_index = indexOfSavePath(new_path);
|
||||||
|
if (existing_index >= 0)
|
||||||
|
ui->save_path_combo->setCurrentIndex(existing_index);
|
||||||
|
else {
|
||||||
|
// New path, prepend to combo box
|
||||||
|
if (!new_filename.isEmpty())
|
||||||
|
ui->save_path_combo->insertItem(0, fsutils::toNativePath(QDir(new_path).absoluteFilePath(new_filename)), new_path);
|
||||||
|
else
|
||||||
|
ui->save_path_combo->insertItem(0, fsutils::toNativePath(new_path), new_path);
|
||||||
|
ui->save_path_combo->setCurrentIndex(0);
|
||||||
|
}
|
||||||
|
// Update file name in all save_paths
|
||||||
|
if (!new_filename.isEmpty() && !fsutils::sameFileNames(old_filename, new_filename)) {
|
||||||
|
m_hasRenamedFile = true;
|
||||||
|
m_filesPath[0] = new_filename;
|
||||||
|
updateFileNameInSavePaths(new_filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
onSavePathChanged(0);
|
||||||
|
} else {
|
||||||
|
// Restore index
|
||||||
|
ui->save_path_combo->setCurrentIndex(m_oldIndex);
|
||||||
|
}
|
||||||
|
connect(ui->save_path_combo, SIGNAL(currentIndexChanged(int)), SLOT(onSavePathChanged(int)));
|
||||||
|
|
||||||
updateDiskSpaceLabel();
|
updateDiskSpaceLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +69,7 @@ private slots:
|
|||||||
void renameSelectedFile();
|
void renameSelectedFile();
|
||||||
void setdialogPosition();
|
void setdialogPosition();
|
||||||
void updateMetadata(const QTorrentHandle& h);
|
void updateMetadata(const QTorrentHandle& h);
|
||||||
|
void browseButton_clicked();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
virtual void accept();
|
virtual void accept();
|
||||||
@ -101,6 +102,7 @@ private:
|
|||||||
bool m_hasRenamedFile;
|
bool m_hasRenamedFile;
|
||||||
QShortcut *editHotkey;
|
QShortcut *editHotkey;
|
||||||
QByteArray m_headerState;
|
QByteArray m_headerState;
|
||||||
|
int m_oldIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ADDNEWTORRENTDIALOG_H
|
#endif // ADDNEWTORRENTDIALOG_H
|
||||||
|
@ -30,14 +30,31 @@
|
|||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QComboBox" name="save_path_combo">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<property name="sizePolicy">
|
<item>
|
||||||
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
|
<widget class="QComboBox" name="save_path_combo">
|
||||||
<horstretch>0</horstretch>
|
<property name="sizePolicy">
|
||||||
<verstretch>0</verstretch>
|
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
|
||||||
</sizepolicy>
|
<horstretch>0</horstretch>
|
||||||
</property>
|
<verstretch>0</verstretch>
|
||||||
</widget>
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="browse_button">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Browse...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="default_save_path_cb">
|
<widget class="QCheckBox" name="default_save_path_cb">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user