From 202006bdd1ccccde8e813fce4cf1df7e5e1d0924 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sun, 2 Feb 2014 19:54:19 +0200 Subject: [PATCH] Reuse code in AddNewTorrentDialog. #894. --- src/addnewtorrentdialog.cpp | 138 +++++++++++++----------------------- src/addnewtorrentdialog.h | 1 + 2 files changed, 50 insertions(+), 89 deletions(-) diff --git a/src/addnewtorrentdialog.cpp b/src/addnewtorrentdialog.cpp index f61375f9d..3580f882c 100644 --- a/src/addnewtorrentdialog.cpp +++ b/src/addnewtorrentdialog.cpp @@ -206,51 +206,7 @@ bool AddNewTorrentDialog::loadTorrent(const QString& torrent_path, const QString return false; } - // Set dialog title - setWindowTitle(misc::toQStringU(m_torrentInfo->name())); - - // Set torrent information - QString comment = misc::toQString(m_torrentInfo->comment()); - ui->comment_lbl->setText(comment.replace('\n', ' ')); - ui->date_lbl->setText(m_torrentInfo->creation_date() ? misc::toQString(*m_torrentInfo->creation_date()) : tr("Not available")); - updateDiskSpaceLabel(); - - file_storage const& fs = m_torrentInfo->files(); - - // Populate m_filesList - 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) { - m_contentModel = new TorrentContentFilterModel(this); - connect(m_contentModel->model(), SIGNAL(filteredFilesChanged()), SLOT(updateDiskSpaceLabel())); - ui->content_tree->setModel(m_contentModel); - 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&))); - - // List files in torrent - m_contentModel->model()->setupModelData(*m_torrentInfo); - - // Expand root folder - ui->content_tree->setExpanded(m_contentModel->index(0, 0), true); - } else { - // Update save paths (append file name to them) - QString single_file_relpath = misc::toQStringU(fs.file_path(0)); - for (int i=0; isave_path_combo->count()-1; ++i) { - ui->save_path_combo->setItemText(i, fsutils::toNativePath(QDir(ui->save_path_combo->itemText(i)).absoluteFilePath(single_file_relpath))); - } - } - - QIniSettings settings; - showAdvancedSettings(settings.value("AddNewTorrentDialog/expanded").toBool()); - // Set dialog position - setdialogPosition(); - + setupTreeview(); return true; } @@ -657,50 +613,7 @@ void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) { setMetadataProgressIndicator(true, tr("Parsing metadata...")); // Update UI - // Set dialog title - setWindowTitle(misc::toQStringU(m_torrentInfo->name())); - - // Set torrent information - QString comment = misc::toQString(m_torrentInfo->comment()); - ui->comment_lbl->setText(comment.replace('\n', ' ')); - ui->date_lbl->setText(m_torrentInfo->creation_date() ? misc::toQString(*m_torrentInfo->creation_date()) : tr("Not available")); - updateDiskSpaceLabel(); - - file_storage const& fs = m_torrentInfo->files(); - - // Populate m_filesList - 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) { - m_contentModel = new TorrentContentFilterModel(this); - connect(m_contentModel->model(), SIGNAL(filteredFilesChanged()), SLOT(updateDiskSpaceLabel())); - ui->content_tree->setModel(m_contentModel); - 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&))); - - // List files in torrent - m_contentModel->model()->setupModelData(*m_torrentInfo); - - // Expand root folder - ui->content_tree->setExpanded(m_contentModel->index(0, 0), true); - } else { - // Update save paths (append file name to them) - QString single_file_relpath = misc::toQStringU(fs.file_path(0)); - for (int i=0; isave_path_combo->count()-1; ++i) { - ui->save_path_combo->setItemText(i, fsutils::toNativePath(QDir(ui->save_path_combo->itemText(i)).absoluteFilePath(single_file_relpath))); - } - } - - QIniSettings settings; - showAdvancedSettings(settings.value("AddNewTorrentDialog/expanded").toBool()); - // Set dialog position - setdialogPosition(); + setupTreeview(); setMetadataProgressIndicator(false, tr("Metadata retrieval complete")); } catch (invalid_handle&) { MessageBoxRaised::critical(0, tr("I/O Error"), ("Unknown error.")); @@ -715,3 +628,50 @@ void AddNewTorrentDialog::setMetadataProgressIndicator(bool visibleIndicator, co ui->lblMetaLoading->setText(labelText); ui->progMetaLoading->setVisible(visibleIndicator); } + +void AddNewTorrentDialog::setupTreeview() { + // Set dialog title + setWindowTitle(misc::toQStringU(m_torrentInfo->name())); + + // Set torrent information + QString comment = misc::toQString(m_torrentInfo->comment()); + ui->comment_lbl->setText(comment.replace('\n', ' ')); + ui->date_lbl->setText(m_torrentInfo->creation_date() ? misc::toQString(*m_torrentInfo->creation_date()) : tr("Not available")); + updateDiskSpaceLabel(); + + file_storage const& fs = m_torrentInfo->files(); + + // Populate m_filesList + 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) { + m_contentModel = new TorrentContentFilterModel(this); + connect(m_contentModel->model(), SIGNAL(filteredFilesChanged()), SLOT(updateDiskSpaceLabel())); + ui->content_tree->setModel(m_contentModel); + 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&))); + + // List files in torrent + m_contentModel->model()->setupModelData(*m_torrentInfo); + + // Expand root folder + ui->content_tree->setExpanded(m_contentModel->index(0, 0), true); + } else { + // Update save paths (append file name to them) + QString single_file_relpath = misc::toQStringU(fs.file_path(0)); + for (int i=0; isave_path_combo->count()-1; ++i) { + ui->save_path_combo->setItemText(i, fsutils::toNativePath(QDir(ui->save_path_combo->itemText(i)).absoluteFilePath(single_file_relpath))); + } + } + + QIniSettings settings; + showAdvancedSettings(settings.value("AddNewTorrentDialog/expanded").toBool()); + // Set dialog position + setdialogPosition(); +} diff --git a/src/addnewtorrentdialog.h b/src/addnewtorrentdialog.h index 1b36ec5a6..96580b846 100644 --- a/src/addnewtorrentdialog.h +++ b/src/addnewtorrentdialog.h @@ -84,6 +84,7 @@ private: void loadState(); void saveState(); void setMetadataProgressIndicator(bool visibleIndicator, const QString &labelText = QString()); + void setupTreeview(); private: Ui::AddNewTorrentDialog *ui;