Browse Source

Reuse code in AddNewTorrentDialog. #894.

adaptive-webui-19844
sledgehammer999 11 years ago
parent
commit
202006bdd1
  1. 138
      src/addnewtorrentdialog.cpp
  2. 1
      src/addnewtorrentdialog.h

138
src/addnewtorrentdialog.cpp

@ -206,51 +206,7 @@ bool AddNewTorrentDialog::loadTorrent(const QString& torrent_path, const QString @@ -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; 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)));
}
}
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) { @@ -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; 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)));
}
}
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 @@ -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; 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)));
}
}
QIniSettings settings;
showAdvancedSettings(settings.value("AddNewTorrentDialog/expanded").toBool());
// Set dialog position
setdialogPosition();
}

1
src/addnewtorrentdialog.h

@ -84,6 +84,7 @@ private: @@ -84,6 +84,7 @@ private:
void loadState();
void saveState();
void setMetadataProgressIndicator(bool visibleIndicator, const QString &labelText = QString());
void setupTreeview();
private:
Ui::AddNewTorrentDialog *ui;

Loading…
Cancel
Save