Follow project coding style. Issue #2192.

This commit is contained in:
sledgehammer999 2015-02-01 01:27:51 +02:00
commit 38455af791
2 changed files with 559 additions and 549 deletions

View file

@ -51,15 +51,15 @@
using namespace libtorrent; using namespace libtorrent;
AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) : AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent)
QDialog(parent), : QDialog(parent)
ui(new Ui::AddNewTorrentDialog), , ui(new Ui::AddNewTorrentDialog)
m_contentModel(0), , m_contentModel(0)
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) , m_oldIndex(0)
{ {
ui->setupUi(this); ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
@ -77,9 +77,8 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) :
// Load labels // Load labels
const QStringList customLabels = pref->getTorrentLabels(); const QStringList customLabels = pref->getTorrentLabels();
ui->label_combo->addItem(""); ui->label_combo->addItem("");
foreach (const QString& label, customLabels) { foreach (const QString& label, customLabels)
ui->label_combo->addItem(label); ui->label_combo->addItem(label);
}
ui->label_combo->model()->sort(0); ui->label_combo->model()->sort(0);
ui->content_tree->header()->setSortIndicator(0, Qt::AscendingOrder); ui->content_tree->header()->setSortIndicator(0, Qt::AscendingOrder);
loadState(); loadState();
@ -140,7 +139,8 @@ void AddNewTorrentDialog::showMagnet(const QString& link, QWidget *parent)
delete dlg; delete dlg;
} }
void AddNewTorrentDialog::showEvent(QShowEvent *event) { void AddNewTorrentDialog::showEvent(QShowEvent *event)
{
QDialog::showEvent(event); QDialog::showEvent(event);
Preferences* const pref = Preferences::instance(); Preferences* const pref = Preferences::instance();
if (!pref->additionDialogFront()) if (!pref->additionDialogFront())
@ -159,12 +159,14 @@ void AddNewTorrentDialog::showAdvancedSettings(bool show)
if (m_hasMetadata && (m_torrentInfo->num_files() > 1)) { if (m_hasMetadata && (m_torrentInfo->num_files() > 1)) {
ui->content_tree->setVisible(true); ui->content_tree->setVisible(true);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
} else { }
else {
ui->content_tree->setVisible(false); ui->content_tree->setVisible(false);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
} }
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 {
ui->adv_button->setText(QString::fromUtf8("")); ui->adv_button->setText(QString::fromUtf8(""));
ui->settings_group->setVisible(false); ui->settings_group->setVisible(false);
ui->info_group->setVisible(false); ui->info_group->setVisible(false);
@ -273,10 +275,9 @@ 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()-1; ++i) { for(int i = 0; i<ui->save_path_combo->count() - 1; ++i)
if (QDir(ui->save_path_combo->itemData(i).toString()) == saveDir) if (QDir(ui->save_path_combo->itemData(i).toString()) == saveDir)
return i; return i;
}
return -1; return -1;
} }
@ -288,7 +289,8 @@ void AddNewTorrentDialog::updateFileNameInSavePaths(const QString &new_filename)
} }
} }
void AddNewTorrentDialog::updateDiskSpaceLabel() { void AddNewTorrentDialog::updateDiskSpaceLabel()
{
// Determine torrent size // Determine torrent size
qulonglong torrent_size = 0; qulonglong torrent_size = 0;
@ -296,11 +298,11 @@ void AddNewTorrentDialog::updateDiskSpaceLabel() {
if (m_contentModel) { if (m_contentModel) {
const std::vector<int> priorities = m_contentModel->model()->getFilesPriorities(); const std::vector<int> priorities = m_contentModel->model()->getFilesPriorities();
Q_ASSERT(priorities.size() == (uint) m_torrentInfo->num_files()); 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) if (priorities[i] > 0)
torrent_size += m_torrentInfo->files().file_size(i); torrent_size += m_torrentInfo->files().file_size(i);
} }
} else { else {
torrent_size = m_torrentInfo->total_size(); torrent_size = m_torrentInfo->total_size();
} }
} }
@ -339,7 +341,8 @@ void AddNewTorrentDialog::browseButton_clicked()
new_path = fsutils::branchPath(new_path, &new_filename); new_path = fsutils::branchPath(new_path, &new_filename);
qDebug() << "new_path: " << new_path; qDebug() << "new_path: " << new_path;
qDebug() << "new_filename: " << new_filename; qDebug() << "new_filename: " << new_filename;
} else { }
else {
if (!cur_save_path.isEmpty() && QDir(cur_save_path).exists()) if (!cur_save_path.isEmpty() && QDir(cur_save_path).exists())
new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), cur_save_path); new_path = QFileDialog::getExistingDirectory(this, tr("Choose save path"), cur_save_path);
else else
@ -347,8 +350,9 @@ void AddNewTorrentDialog::browseButton_clicked()
} }
if (!new_path.isEmpty()) { if (!new_path.isEmpty()) {
const int existing_index = indexOfSavePath(new_path); const int existing_index = indexOfSavePath(new_path);
if (existing_index >= 0) if (existing_index >= 0) {
ui->save_path_combo->setCurrentIndex(existing_index); 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()) if (!new_filename.isEmpty())
@ -365,7 +369,8 @@ void AddNewTorrentDialog::browseButton_clicked()
} }
onSavePathChanged(0); onSavePathChanged(0);
} else { }
else {
// Restore index // Restore index
ui->save_path_combo->setCurrentIndex(m_oldIndex); ui->save_path_combo->setCurrentIndex(m_oldIndex);
} }
@ -435,7 +440,8 @@ void AddNewTorrentDialog::renameSelectedFile()
m_hasRenamedFile = true; m_hasRenamedFile = true;
// Rename in torrent files model too // Rename in torrent files model too
m_contentModel->setData(index, new_name_last); m_contentModel->setData(index, new_name_last);
} else { }
else {
// Folder renaming // Folder renaming
QStringList path_items; QStringList path_items;
path_items << index.data().toString(); path_items << index.data().toString();
@ -490,7 +496,8 @@ void AddNewTorrentDialog::setdialogPosition()
int y = Preferences::instance()->getAddNewTorrentDialogPos(); int y = Preferences::instance()->getAddNewTorrentDialogPos();
if (y >= 0) { if (y >= 0) {
center.setY(y); center.setY(y);
} else { }
else {
center.ry() -= 120; center.ry() -= 120;
if (center.y() < 0) if (center.y() < 0)
center.setY(0); center.setY(0);
@ -503,13 +510,13 @@ void AddNewTorrentDialog::loadSavePathHistory()
QDir default_save_path(Preferences::instance()->getSavePath()); QDir default_save_path(Preferences::instance()->getSavePath());
// Load save path history // Load save path history
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(fsutils::toNativePath(sp), sp); ui->save_path_combo->addItem(fsutils::toNativePath(sp), sp);
} }
}
void AddNewTorrentDialog::displayContentTreeMenu(const QPoint&) { 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;
@ -529,18 +536,19 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint&) {
if (act) { if (act) {
if (act == actRename) { if (act == actRename) {
renameSelectedFile(); renameSelectedFile();
} else { }
int prio = prio::NORMAL;
if (act == ui->actionHigh)
prio = prio::HIGH;
else { else {
if (act == ui->actionMaximum) { int prio = prio::NORMAL;
if (act == ui->actionHigh) {
prio = prio::HIGH;
}
else {
if (act == ui->actionMaximum)
prio = prio::MAXIMUM; prio = prio::MAXIMUM;
} else { else
if (act == ui->actionNot_downloaded) if (act == ui->actionNot_downloaded)
prio = prio::IGNORED; prio = prio::IGNORED;
} }
}
qDebug("Setting files priority"); qDebug("Setting files priority");
foreach (const QModelIndex &index, selectedRows) { foreach (const QModelIndex &index, selectedRows) {
qDebug("Setting priority(%d) for file at row %d", prio, index.row()); qDebug("Setting priority(%d) for file at row %d", prio, index.row());
@ -559,10 +567,9 @@ void AddNewTorrentDialog::accept()
// Save Temporary data about torrent // Save Temporary data about torrent
QString save_path = ui->save_path_combo->itemData(ui->save_path_combo->currentIndex()).toString(); QString save_path = ui->save_path_combo->itemData(ui->save_path_combo->currentIndex()).toString();
TorrentTempData::setSavePath(m_hash, save_path); TorrentTempData::setSavePath(m_hash, save_path);
if (ui->skip_check_cb->isChecked()) { if (ui->skip_check_cb->isChecked())
// TODO: Check if destination actually exists // TODO: Check if destination actually exists
TorrentTempData::setSeedingMode(m_hash, true); TorrentTempData::setSeedingMode(m_hash, true);
}
// Label // Label
const QString label = ui->label_combo->currentText(); const QString label = ui->label_combo->currentText();
@ -595,7 +602,8 @@ void AddNewTorrentDialog::accept()
QDialog::accept(); QDialog::accept();
} }
void AddNewTorrentDialog::reject() { void AddNewTorrentDialog::reject()
{
if (m_isMagnet) { if (m_isMagnet) {
disconnect(this, SLOT(updateMetadata(const QTorrentHandle &))); disconnect(this, SLOT(updateMetadata(const QTorrentHandle &)));
setMetadataProgressIndicator(false); setMetadataProgressIndicator(false);
@ -604,7 +612,8 @@ void AddNewTorrentDialog::reject() {
QDialog::reject(); QDialog::reject();
} }
void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h) { void AddNewTorrentDialog::updateMetadata(const QTorrentHandle &h)
{
try { try {
if (h.hash() != m_hash) if (h.hash() != m_hash)
return; return;
@ -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 // Always show info label when waiting for metadata
ui->lblMetaLoading->setVisible(true); ui->lblMetaLoading->setVisible(true);
ui->lblMetaLoading->setText(labelText); ui->lblMetaLoading->setText(labelText);
ui->progMetaLoading->setVisible(visibleIndicator); ui->progMetaLoading->setVisible(visibleIndicator);
} }
void AddNewTorrentDialog::setupTreeview() { void AddNewTorrentDialog::setupTreeview()
{
if (!m_hasMetadata) { if (!m_hasMetadata) {
ui->comment_lbl->setText(tr("Not Available", "This comment is unavailable")); ui->comment_lbl->setText(tr("Not Available", "This comment is unavailable"));
ui->date_lbl->setText(tr("Not Available", "This date 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(); file_storage const& fs = m_torrentInfo->files();
// Populate m_filesList // 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)); m_filesPath << misc::toQStringU(fs.file_path(i));
}
// Prepare content tree // Prepare content tree
if (fs.num_files() > 1) { if (fs.num_files() > 1) {
@ -678,14 +688,14 @@ void AddNewTorrentDialog::setupTreeview() {
// 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 { }
else {
// Update save paths (append file name to them) // Update save paths (append file name to them)
QString single_file_relpath = misc::toQStringU(fs.file_path(0)); 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))); ui->save_path_combo->setItemText(i, fsutils::toNativePath(QDir(ui->save_path_combo->itemText(i)).absoluteFilePath(single_file_relpath)));
} }
} }
}
updateDiskSpaceLabel(); updateDiskSpaceLabel();
showAdvancedSettings(Preferences::instance()->getAddNewTorrentDialogExpanded()); showAdvancedSettings(Preferences::instance()->getAddNewTorrentDialogExpanded());