Skip to content

Commit

Permalink
implementing #27
Browse files Browse the repository at this point in the history
  • Loading branch information
aliakseis committed Mar 13, 2022
1 parent 3ecf47d commit 5b5e44d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -33,7 +33,7 @@ set(CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
)

project(${PROJECT_NAME} VERSION 0.1.1.16)
project(${PROJECT_NAME} VERSION 0.1.1.17)
message("Building ${PROJECT_NAME} version ${PROJECT_VERSION}")

###################################################
Expand Down
17 changes: 17 additions & 0 deletions src/common/utilities/utils.cpp
Expand Up @@ -223,6 +223,23 @@ QString SizeToString(quint64 size, int precision, int fieldWidth)
return QStringLiteral("%1 GB").arg(sizef, fieldWidth, 'f', precision);
}

QString EstimatedTimeToString(double time)
{
if (time >= 99.5 * 3600)
{
return QObject::tr("%1 days").arg(time / (3600 * 24), 0, 'f', 0);
}
if (time >= 99.5 * 60)
{
return QObject::tr("%1 hours").arg(time / 3600, 0, 'f', 0);
}
if (time >= 99.5)
{
return QObject::tr("%1 minutes").arg(time / 60, 0, 'f', 0);
}
return QObject::tr("%1 seconds").arg(time, 0, 'f', 0);
}

QString ProgressString(double progress)
{
// We don't want to display 100% unless the torrent is really complete
Expand Down
1 change: 1 addition & 0 deletions src/common/utilities/utils.h
Expand Up @@ -63,6 +63,7 @@ QStringList ParseUrls(const QString& data);
bool DeserializeObject(QXmlStreamReader* stream, QObject* object, const QString& name = QString());
void SerializeObject(QXmlStreamWriter* stream, QObject* object, const QString& name);
QString SizeToString(quint64 size, int precision = 2, int fieldWidth = 0);
QString EstimatedTimeToString(double time);
QString ProgressString(double progress);

// correct QString args handling
Expand Down
54 changes: 35 additions & 19 deletions src/logic/downloadcollectionmodel.cpp
Expand Up @@ -250,28 +250,53 @@ QVariant DownloadCollectionModel::data(const QModelIndex& index, int role /* = Q
return int(Qt::AlignLeft | Qt::AlignVCenter);
}

auto* item = static_cast<TreeItem*>(index.internalPointer());
if (!item)
{
return {};
}

const int l_colunm = index.column();

if (role == Qt::ToolTipRole)
{
if (l_colunm == eDC_Status)
switch (l_colunm)
{
auto* l_item = static_cast<TreeItem*>(index.internalPointer());
if (l_item && l_item->getStatus() == ItemDC::eERROR)
case eDC_Status:
if (item->getStatus() == ItemDC::eERROR)
{
QString errorDescr = l_item->errorDescription();
if (!DownloadType::isTorrentDownload(l_item->downloadType()))
QString errorDescr = item->errorDescription();
if (!DownloadType::isTorrentDownload(item->downloadType()))
{
QString tooltipText = ::Tr::Tr(
utilities::ErrorCode::instance().getDescription(l_item->getErrorCode()));
utilities::ErrorCode::instance().getDescription(item->getErrorCode()));
if (!errorDescr.isEmpty())
{
tooltipText += '\n' + errorDescr;
}
return tooltipText;
}
return (!errorDescr.isEmpty() ? tr("Error: ") + errorDescr : QString());
if (!errorDescr.isEmpty())
{
return tr("Error: ") + errorDescr;
}
}
break;
case eDC_percentDownl:
if (item->getStatus() == ItemDC::eDOWNLOADING)
{
const float speed = item->getSpeed();
if (speed > std::numeric_limits<float>::epsilon())
{
const auto remaining = (item->size() - item->sizeCurrDownl()) / speed / 1024.;
if (remaining > 0)
{
return tr("Estimated remaining time: %1").arg(utilities::EstimatedTimeToString(remaining));
}
}
}
break;
default:
return {};
}
return {};
Expand All @@ -282,25 +307,16 @@ QVariant DownloadCollectionModel::data(const QModelIndex& index, int role /* = Q
// https://personal.sron.nl/~pault/#sec:qualitative
static const QRgb palette[]
= { 0x332288, 0x88CCEE, 0x44AA99, 0x117733, 0x999933, 0xDDCC77, 0xCC6677, 0x882255, 0xAA4499 };
if (auto* item = static_cast<TreeItem*>(index.internalPointer()))
{
const int colorIdx = item->getStatus();
if (colorIdx >= 0 && colorIdx < sizeof(palette) / sizeof(palette[0]))
return QBrush(palette[colorIdx]);
}
const int colorIdx = item->getStatus();
if (colorIdx >= 0 && colorIdx < sizeof(palette) / sizeof(palette[0]))
return QBrush(palette[colorIdx]);
}

if (role != Qt::DisplayRole)
{
return {};
}

auto* item = static_cast<TreeItem*>(index.internalPointer());
if (!item)
{
return {};
}

switch (l_colunm)
{
case eDC_ID:
Expand Down

0 comments on commit 5b5e44d

Please sign in to comment.