mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-24 18:26:11 +03:00
Follow project coding style. Issue #2192.
This commit is contained in:
parent
d45aff9169
commit
38455af791
2 changed files with 559 additions and 549 deletions
|
@ -51,15 +51,15 @@
|
|||
|
||||
using namespace libtorrent;
|
||||
|
||||
AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::AddNewTorrentDialog),
|
||||
m_contentModel(0),
|
||||
m_contentDelegate(0),
|
||||
m_isMagnet(false),
|
||||
m_hasMetadata(false),
|
||||
m_hasRenamedFile(false),
|
||||
m_oldIndex(0)
|
||||
AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::AddNewTorrentDialog)
|
||||
, m_contentModel(0)
|
||||
, m_contentDelegate(0)
|
||||
, m_isMagnet(false)
|
||||
, m_hasMetadata(false)
|
||||
, m_hasRenamedFile(false)
|
||||
, m_oldIndex(0)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
@ -77,9 +77,8 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) :
|
|||
// Load labels
|
||||
const QStringList customLabels = pref->getTorrentLabels();
|
||||
ui->label_combo->addItem("");
|
||||
foreach (const QString& label, customLabels) {
|
||||
foreach (const QString& label, customLabels)
|
||||
ui->label_combo->addItem(label);
|
||||
}
|
||||
ui->label_combo->model()->sort(0);
|
||||
ui->content_tree->header()->setSortIndicator(0, Qt::AscendingOrder);
|
||||
loadState();
|
||||
|
@ -140,7 +139,8 @@ void AddNewTorrentDialog::showMagnet(const QString& link, QWidget *parent)
|
|||
delete dlg;
|
||||
}
|
||||
|
||||
void AddNewTorrentDialog::showEvent(QShowEvent *event) {
|
||||
void AddNewTorrentDialog::showEvent(QShowEvent *event)
|
||||
{
|
||||
QDialog::showEvent(event);
|
||||
Preferences* const pref = Preferences::instance();
|
||||
if (!pref->additionDialogFront())
|
||||
|
@ -159,16 +159,18 @@ void AddNewTorrentDialog::showAdvancedSettings(bool show)
|
|||
if (m_hasMetadata && (m_torrentInfo->num_files() > 1)) {
|
||||
ui->content_tree->setVisible(true);
|
||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
ui->content_tree->setVisible(false);
|
||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
}
|
||||
static_cast<QVBoxLayout*>(layout())->insertWidget(layout()->indexOf(ui->never_show_cb)+1, ui->adv_button);
|
||||
} else {
|
||||
static_cast<QVBoxLayout*>(layout())->insertWidget(layout()->indexOf(ui->never_show_cb) + 1, ui->adv_button);
|
||||
}
|
||||
else {
|
||||
ui->adv_button->setText(QString::fromUtf8("▼"));
|
||||
ui->settings_group->setVisible(false);
|
||||
ui->info_group->setVisible(false);
|
||||
ui->buttonsHLayout->insertWidget(0, layout()->takeAt(layout()->indexOf(ui->never_show_cb)+1)->widget());
|
||||
ui->buttonsHLayout->insertWidget(0, layout()->takeAt(layout()->indexOf(ui->never_show_cb) + 1)->widget());
|
||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
}
|
||||
relayout();
|
||||
|
@ -216,7 +218,7 @@ bool AddNewTorrentDialog::loadTorrent(const QString& torrent_path, const QString
|
|||
|
||||
bool AddNewTorrentDialog::loadMagnet(const QString &magnet_uri)
|
||||
{
|
||||
connect(QBtSession::instance(), SIGNAL(metadataReceivedHidden(const QTorrentHandle&)), SLOT(updateMetadata(const QTorrentHandle&)));
|
||||
connect(QBtSession::instance(), SIGNAL(metadataReceivedHidden(const QTorrentHandle &)), SLOT(updateMetadata(const QTorrentHandle &)));
|
||||
m_isMagnet = true;
|
||||
m_url = magnet_uri;
|
||||
m_hash = misc::magnetUriToHash(m_url);
|
||||
|
@ -273,22 +275,22 @@ void AddNewTorrentDialog::saveSavePathHistory() const
|
|||
int AddNewTorrentDialog::indexOfSavePath(const QString &save_path)
|
||||
{
|
||||
QDir saveDir(save_path);
|
||||
for(int i=0; i<ui->save_path_combo->count()-1; ++i) {
|
||||
for(int i = 0; i<ui->save_path_combo->count() - 1; ++i)
|
||||
if (QDir(ui->save_path_combo->itemData(i).toString()) == saveDir)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void AddNewTorrentDialog::updateFileNameInSavePaths(const QString &new_filename)
|
||||
{
|
||||
for(int i=0; i<ui->save_path_combo->count()-1; ++i) {
|
||||
for(int i = 0; i<ui->save_path_combo->count() - 1; ++i) {
|
||||
const QDir folder(ui->save_path_combo->itemData(i).toString());
|
||||
ui->save_path_combo->setItemText(i, fsutils::toNativePath(folder.absoluteFilePath(new_filename)));
|
||||
}
|
||||
}
|
||||
|
||||
void AddNewTorrentDialog::updateDiskSpaceLabel() {
|
||||
void AddNewTorrentDialog::updateDiskSpaceLabel()
|
||||
{
|
||||
// Determine torrent size
|
||||
qulonglong torrent_size = 0;
|
||||
|
||||
|
@ -296,11 +298,11 @@ void AddNewTorrentDialog::updateDiskSpaceLabel() {
|
|||
if (m_contentModel) {
|
||||
const std::vector<int> priorities = m_contentModel->model()->getFilesPriorities();
|
||||
Q_ASSERT(priorities.size() == (uint) m_torrentInfo->num_files());
|
||||
for (uint i=0; i<priorities.size(); ++i) {
|
||||
for (uint i = 0; i<priorities.size(); ++i)
|
||||
if (priorities[i] > 0)
|
||||
torrent_size += m_torrentInfo->files().file_size(i);
|
||||
}
|
||||
} else {
|
||||
else {
|
||||
torrent_size = m_torrentInfo->total_size();
|
||||
}
|
||||
}
|
||||
|
@ -339,7 +341,8 @@ void AddNewTorrentDialog::browseButton_clicked()
|
|||
new_path = fsutils::branchPath(new_path, &new_filename);
|
||||
qDebug() << "new_path: " << new_path;
|
||||
qDebug() << "new_filename: " << new_filename;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (!cur_save_path.isEmpty() && QDir(cur_save_path).exists())
|
||||
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), cur_save_path);
|
||||
else
|
||||
|
@ -347,8 +350,9 @@ void AddNewTorrentDialog::browseButton_clicked()
|
|||
}
|
||||
if (!new_path.isEmpty()) {
|
||||
const int existing_index = indexOfSavePath(new_path);
|
||||
if (existing_index >= 0)
|
||||
if (existing_index >= 0) {
|
||||
ui->save_path_combo->setCurrentIndex(existing_index);
|
||||
}
|
||||
else {
|
||||
// New path, prepend to combo box
|
||||
if (!new_filename.isEmpty())
|
||||
|
@ -365,7 +369,8 @@ void AddNewTorrentDialog::browseButton_clicked()
|
|||
}
|
||||
|
||||
onSavePathChanged(0);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// Restore index
|
||||
ui->save_path_combo->setCurrentIndex(m_oldIndex);
|
||||
}
|
||||
|
@ -419,7 +424,7 @@ void AddNewTorrentDialog::renameSelectedFile()
|
|||
new_name = fsutils::expandPath(new_name);
|
||||
qDebug("New name: %s", qPrintable(new_name));
|
||||
// Check if that name is already used
|
||||
for (int i=0; i<m_torrentInfo->num_files(); ++i) {
|
||||
for (int i = 0; i<m_torrentInfo->num_files(); ++i) {
|
||||
if (i == file_index) continue;
|
||||
if (fsutils::sameFileNames(m_filesPath.at(i), new_name)) {
|
||||
// Display error message
|
||||
|
@ -435,7 +440,8 @@ void AddNewTorrentDialog::renameSelectedFile()
|
|||
m_hasRenamedFile = true;
|
||||
// Rename in torrent files model too
|
||||
m_contentModel->setData(index, new_name_last);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// Folder renaming
|
||||
QStringList path_items;
|
||||
path_items << index.data().toString();
|
||||
|
@ -450,7 +456,7 @@ void AddNewTorrentDialog::renameSelectedFile()
|
|||
QString new_path = path_items.join("/");
|
||||
if (!new_path.endsWith("/")) new_path += "/";
|
||||
// Check for overwriting
|
||||
for (int i=0; i<m_torrentInfo->num_files(); ++i) {
|
||||
for (int i = 0; i<m_torrentInfo->num_files(); ++i) {
|
||||
const QString ¤t_name = m_filesPath.at(i);
|
||||
#if defined(Q_OS_UNIX) || defined(Q_WS_QWS)
|
||||
if (current_name.startsWith(new_path, Qt::CaseSensitive)) {
|
||||
|
@ -464,7 +470,7 @@ void AddNewTorrentDialog::renameSelectedFile()
|
|||
}
|
||||
}
|
||||
// Replace path in all files
|
||||
for (int i=0; i<m_torrentInfo->num_files(); ++i) {
|
||||
for (int i = 0; i<m_torrentInfo->num_files(); ++i) {
|
||||
const QString ¤t_name = m_filesPath.at(i);
|
||||
if (current_name.startsWith(old_path)) {
|
||||
QString new_name = current_name;
|
||||
|
@ -490,7 +496,8 @@ void AddNewTorrentDialog::setdialogPosition()
|
|||
int y = Preferences::instance()->getAddNewTorrentDialogPos();
|
||||
if (y >= 0) {
|
||||
center.setY(y);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
center.ry() -= 120;
|
||||
if (center.y() < 0)
|
||||
center.setY(0);
|
||||
|
@ -503,13 +510,13 @@ void AddNewTorrentDialog::loadSavePathHistory()
|
|||
QDir default_save_path(Preferences::instance()->getSavePath());
|
||||
// Load save path history
|
||||
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)
|
||||
ui->save_path_combo->addItem(fsutils::toNativePath(sp), sp);
|
||||
}
|
||||
}
|
||||
|
||||
void AddNewTorrentDialog::displayContentTreeMenu(const QPoint&) {
|
||||
void AddNewTorrentDialog::displayContentTreeMenu(const QPoint&)
|
||||
{
|
||||
QMenu myFilesLlistMenu;
|
||||
const QModelIndexList selectedRows = ui->content_tree->selectionModel()->selectedRows(0);
|
||||
QAction *actRename = 0;
|
||||
|
@ -529,18 +536,19 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint&) {
|
|||
if (act) {
|
||||
if (act == actRename) {
|
||||
renameSelectedFile();
|
||||
} else {
|
||||
int prio = prio::NORMAL;
|
||||
if (act == ui->actionHigh)
|
||||
prio = prio::HIGH;
|
||||
}
|
||||
else {
|
||||
if (act == ui->actionMaximum) {
|
||||
int prio = prio::NORMAL;
|
||||
if (act == ui->actionHigh) {
|
||||
prio = prio::HIGH;
|
||||
}
|
||||
else {
|
||||
if (act == ui->actionMaximum)
|
||||
prio = prio::MAXIMUM;
|
||||
} else {
|
||||
else
|
||||
if (act == ui->actionNot_downloaded)
|
||||
prio = prio::IGNORED;
|
||||
}
|
||||
}
|
||||
qDebug("Setting files priority");
|
||||
foreach (const QModelIndex &index, selectedRows) {
|
||||
qDebug("Setting priority(%d) for file at row %d", prio, index.row());
|
||||
|
@ -553,16 +561,15 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint&) {
|
|||
void AddNewTorrentDialog::accept()
|
||||
{
|
||||
if (m_isMagnet)
|
||||
disconnect(this, SLOT(updateMetadata(const QTorrentHandle&)));
|
||||
disconnect(this, SLOT(updateMetadata(const QTorrentHandle &)));
|
||||
|
||||
Preferences* const pref = Preferences::instance();
|
||||
// Save Temporary data about torrent
|
||||
QString save_path = ui->save_path_combo->itemData(ui->save_path_combo->currentIndex()).toString();
|
||||
TorrentTempData::setSavePath(m_hash, save_path);
|
||||
if (ui->skip_check_cb->isChecked()) {
|
||||
if (ui->skip_check_cb->isChecked())
|
||||
// TODO: Check if destination actually exists
|
||||
TorrentTempData::setSeedingMode(m_hash, true);
|
||||
}
|
||||
|
||||
// Label
|
||||
const QString label = ui->label_combo->currentText();
|
||||
|
@ -595,21 +602,23 @@ void AddNewTorrentDialog::accept()
|
|||
QDialog::accept();
|
||||
}
|
||||
|
||||
void AddNewTorrentDialog::reject() {
|
||||
void AddNewTorrentDialog::reject()
|
||||
{
|
||||
if (m_isMagnet) {
|
||||
disconnect(this, SLOT(updateMetadata(const QTorrentHandle&)));
|
||||
disconnect(this, SLOT(updateMetadata(const QTorrentHandle &)));
|
||||
setMetadataProgressIndicator(false);
|
||||
QBtSession::instance()->deleteTorrent(m_hash, true);
|
||||
}
|
||||
QDialog::reject();
|
||||
}
|
||||
|
||||
void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) {
|
||||
void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h)
|
||||
{
|
||||
try {
|
||||
if (h.hash() != m_hash)
|
||||
return;
|
||||
|
||||
disconnect(this, SLOT(updateMetadata(const QTorrentHandle&)));
|
||||
disconnect(this, SLOT(updateMetadata(const QTorrentHandle &)));
|
||||
Q_ASSERT(h.has_metadata());
|
||||
|
||||
#if LIBTORRENT_VERSION_NUM < 10000
|
||||
|
@ -632,14 +641,16 @@ void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) {
|
|||
}
|
||||
}
|
||||
|
||||
void AddNewTorrentDialog::setMetadataProgressIndicator(bool visibleIndicator, const QString &labelText) {
|
||||
void AddNewTorrentDialog::setMetadataProgressIndicator(bool visibleIndicator, const QString &labelText)
|
||||
{
|
||||
// Always show info label when waiting for metadata
|
||||
ui->lblMetaLoading->setVisible(true);
|
||||
ui->lblMetaLoading->setText(labelText);
|
||||
ui->progMetaLoading->setVisible(visibleIndicator);
|
||||
}
|
||||
|
||||
void AddNewTorrentDialog::setupTreeview() {
|
||||
void AddNewTorrentDialog::setupTreeview()
|
||||
{
|
||||
if (!m_hasMetadata) {
|
||||
ui->comment_lbl->setText(tr("Not Available", "This comment is unavailable"));
|
||||
ui->date_lbl->setText(tr("Not Available", "This date is unavailable"));
|
||||
|
@ -656,9 +667,8 @@ void AddNewTorrentDialog::setupTreeview() {
|
|||
file_storage const& fs = m_torrentInfo->files();
|
||||
|
||||
// Populate m_filesList
|
||||
for (int i = 0; i < fs.num_files(); ++i) {
|
||||
for (int i = 0; i < fs.num_files(); ++i)
|
||||
m_filesPath << misc::toQStringU(fs.file_path(i));
|
||||
}
|
||||
|
||||
// Prepare content tree
|
||||
if (fs.num_files() > 1) {
|
||||
|
@ -668,8 +678,8 @@ void AddNewTorrentDialog::setupTreeview() {
|
|||
ui->content_tree->hideColumn(PROGRESS);
|
||||
m_contentDelegate = new PropListDelegate();
|
||||
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(customContextMenuRequested(const QPoint&)), this, SLOT(displayContentTreeMenu(const QPoint&)));
|
||||
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 &)));
|
||||
|
||||
// List files in torrent
|
||||
m_contentModel->model()->setupModelData(*m_torrentInfo);
|
||||
|
@ -678,14 +688,14 @@ void AddNewTorrentDialog::setupTreeview() {
|
|||
|
||||
// Expand root folder
|
||||
ui->content_tree->setExpanded(m_contentModel->index(0, 0), true);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// Update save paths (append file name to them)
|
||||
QString single_file_relpath = misc::toQStringU(fs.file_path(0));
|
||||
for (int i=0; i<ui->save_path_combo->count()-1; ++i) {
|
||||
for (int i = 0; i<ui->save_path_combo->count() - 1; ++i)
|
||||
ui->save_path_combo->setItemText(i, fsutils::toNativePath(QDir(ui->save_path_combo->itemText(i)).absoluteFilePath(single_file_relpath)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateDiskSpaceLabel();
|
||||
showAdvancedSettings(Preferences::instance()->getAddNewTorrentDialogExpanded());
|
||||
|
|
|
@ -40,14 +40,14 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class AddNewTorrentDialog;
|
||||
class AddNewTorrentDialog;
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class TorrentContentFilterModel;
|
||||
class PropListDelegate;
|
||||
|
||||
class AddNewTorrentDialog : public QDialog
|
||||
class AddNewTorrentDialog: public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
|
Loading…
Reference in a new issue