From 5c10a24923f39d1828af2b4b65f4724e8c82cc22 Mon Sep 17 00:00:00 2001 From: Eugene Shalygin Date: Tue, 22 Mar 2016 19:41:43 +0100 Subject: [PATCH] Add availability column to torrent properties window --- src/base/unicodestrings.h | 1 + src/gui/addnewtorrentdialog.cpp | 1 + src/gui/properties/propertieswidget.cpp | 1 + src/gui/properties/proplistdelegate.cpp | 14 ++++++++++++++ src/gui/properties/proplistdelegate.h | 4 +++- src/gui/torrentcontentmodel.cpp | 2 +- 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/base/unicodestrings.h b/src/base/unicodestrings.h index 33e164ddb..88ffe7782 100644 --- a/src/base/unicodestrings.h +++ b/src/base/unicodestrings.h @@ -39,6 +39,7 @@ const char C_NON_BREAKING_SPACE[] = " "; const char C_UP[] = "▲"; const char C_DOWN[] = "▼"; const char C_COPYRIGHT[] = "©"; +const char C_THIN_SPACE[] = " "; const char C_UTP[] = "μTP"; const char C_LOCALE_ENGLISH[] = "English"; const char C_LOCALE_ENGLISH_AUSTRALIA[] = "English(Australia)"; diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index 5bbac7bb4..bbdb6901c 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -737,6 +737,7 @@ void AddNewTorrentDialog::setupTreeview() // Hide useless columns after loading the header state ui->contentTreeView->hideColumn(PROGRESS); ui->contentTreeView->hideColumn(REMAINING); + ui->contentTreeView->hideColumn(AVAILABILITY); // Expand root folder ui->contentTreeView->setExpanded(m_contentModel->index(0, 0), true); diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index 77466c748..5df08d842 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -493,6 +493,7 @@ void PropertiesWidget::loadDynamicData() qDebug("Updating priorities in files tab"); m_ui->filesList->setUpdatesEnabled(false); PropListModel->model()->updateFilesProgress(m_torrent->filesProgress()); + PropListModel->model()->updateFilesAvailability(m_torrent->availableFileFractions()); // XXX: We don't update file priorities regularly for performance // reasons. This means that priorities will not be updated if // set from the Web UI. diff --git a/src/gui/properties/proplistdelegate.cpp b/src/gui/properties/proplistdelegate.cpp index 2c845ba6f..b1b1b3645 100644 --- a/src/gui/properties/proplistdelegate.cpp +++ b/src/gui/properties/proplistdelegate.cpp @@ -42,6 +42,7 @@ #include #endif +#include "base/unicodestrings.h" #include "base/utils/misc.h" #include "base/utils/string.h" #include "propertieswidget.h" @@ -131,6 +132,19 @@ void PropListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti QItemDelegate::drawDisplay(painter, opt, option.rect, text); } break; + case AVAILABILITY: { + const qreal availability = index.data().toDouble(); + if (availability < 0) { + QItemDelegate::drawDisplay(painter, opt, option.rect, tr("N/A")); + } + else { + const QString value = (availability >= 1.0) + ? QLatin1String("100") + : Utils::String::fromDouble(availability * 100., 1); + QItemDelegate::drawDisplay(painter, opt, option.rect, value + C_THIN_SPACE + QLatin1Char('%')); + } + } + break; default: QItemDelegate::paint(painter, option, index); break; diff --git a/src/gui/properties/proplistdelegate.h b/src/gui/properties/proplistdelegate.h index 2d5e41335..ed9035349 100644 --- a/src/gui/properties/proplistdelegate.h +++ b/src/gui/properties/proplistdelegate.h @@ -46,7 +46,8 @@ enum PropColumn PCSIZE, PROGRESS, PRIORITY, - REMAINING + REMAINING, + AVAILABILITY }; class PropListDelegate: public QItemDelegate @@ -72,3 +73,4 @@ private: }; #endif + diff --git a/src/gui/torrentcontentmodel.cpp b/src/gui/torrentcontentmodel.cpp index 53a0a4705..ace9868a8 100644 --- a/src/gui/torrentcontentmodel.cpp +++ b/src/gui/torrentcontentmodel.cpp @@ -56,7 +56,7 @@ namespace TorrentContentModel::TorrentContentModel(QObject *parent) : QAbstractItemModel(parent) - , m_rootItem(new TorrentContentModelFolder(QList({ tr("Name"), tr("Size"), tr("Progress"), tr("Download Priority"), tr("Remaining") }))) + , m_rootItem(new TorrentContentModelFolder(QList({ tr("Name"), tr("Size"), tr("Progress"), tr("Download Priority"), tr("Remaining"), tr("Availability") }))) { }