fix: properly map progress range
- doument PCRE used for URL compacting Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
parent
9d2f0e4dc8
commit
f1028fa66d
@ -61,13 +61,23 @@ QString truncateUrlHumanFriendly(QUrl &url, int max_len, bool hard_limit = false
|
|||||||
if (str_url.length() <= max_len)
|
if (str_url.length() <= max_len)
|
||||||
return str_url;
|
return str_url;
|
||||||
|
|
||||||
QRegularExpression re(R"(^([\w]+:\/\/)([\w._-]+\/)([\w._-]+\/).*(\/[^]+[^]+)$)");
|
/* this is a PCRE regular expression that splits a URL (given by the display rules above) into 5 capture groups
|
||||||
|
* the scheme (ie https://) is group 1
|
||||||
|
* the host (with trailing /) is group 2
|
||||||
|
* the first part of the path (with trailing /) is group 3
|
||||||
|
* the last part of the path (with leading /) is group 5
|
||||||
|
* the remainder of the URL is in the .* and in group 4
|
||||||
|
*
|
||||||
|
* See: https://regex101.com/r/inHkek/1
|
||||||
|
* for an interactive breakdown
|
||||||
|
*/
|
||||||
|
QRegularExpression re(R"(^([\w]+:\/\/)([\w._-]+\/)([\w._-]+\/)(.*)(\/[^]+[^]+)$)");
|
||||||
|
|
||||||
auto url_compact = QString(str_url);
|
auto url_compact = QString(str_url);
|
||||||
url_compact.replace(re, "\\1\\2\\3...\\4");
|
url_compact.replace(re, "\\1\\2\\3...\\5");
|
||||||
if (url_compact.length() >= max_len) {
|
if (url_compact.length() >= max_len) {
|
||||||
auto url_compact = QString(str_url);
|
url_compact = QString(str_url);
|
||||||
url_compact.replace(re, "\\1\\2...\\4");
|
url_compact.replace(re, "\\1\\2...\\5");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -120,7 +130,7 @@ void Download::addValidator(Validator* v)
|
|||||||
|
|
||||||
void Download::executeTask()
|
void Download::executeTask()
|
||||||
{
|
{
|
||||||
setStatus(tr("Downloading %1").arg(truncateUrlHumanFriendly(m_url, 60)));
|
setStatus(tr("Downloading %1").arg(truncateUrlHumanFriendly(m_url, 100)));
|
||||||
|
|
||||||
if (getState() == Task::State::AbortedByUser) {
|
if (getState() == Task::State::AbortedByUser) {
|
||||||
qCWarning(DownloadLogC) << getUid().toString() << "Attempt to start an aborted Download:" << m_url.toString();
|
qCWarning(DownloadLogC) << getUid().toString() << "Attempt to start an aborted Download:" << m_url.toString();
|
||||||
|
@ -28,12 +28,7 @@ void ConcurrentTask::addTask(Task::Ptr task)
|
|||||||
|
|
||||||
void ConcurrentTask::executeTask()
|
void ConcurrentTask::executeTask()
|
||||||
{
|
{
|
||||||
// Start the least amount of tasks needed, but at least one
|
// Start One task, startNext hadels starting the up to the m_total_max_size
|
||||||
// int num_starts = qMax(1, qMin(m_total_max_size, m_queue.size()));
|
|
||||||
// for (int i = 0; i < num_starts; i++) {
|
|
||||||
// QMetaObject::invokeMethod(this, &ConcurrentTask::startNext, Qt::QueuedConnection);
|
|
||||||
// }
|
|
||||||
// Start One task, startNext hadles starting the up to the m_total_max_size
|
|
||||||
// while tracking the number currently being done
|
// while tracking the number currently being done
|
||||||
QMetaObject::invokeMethod(this, &ConcurrentTask::startNext, Qt::QueuedConnection);
|
QMetaObject::invokeMethod(this, &ConcurrentTask::startNext, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
@ -45,21 +45,18 @@
|
|||||||
#include "ui/widgets/SubTaskProgressBar.h"
|
#include "ui/widgets/SubTaskProgressBar.h"
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
// map a value in a numaric range of an arbatray type to between 0 and INT_MAX
|
||||||
int map_int_range(T value)
|
// for getting the best percision out of the qt progress bar
|
||||||
|
template<typename T, typename = typename std::enable_if<std::is_arithmetic<T>::value, T>::type>
|
||||||
|
std::tuple<int, int> map_int_zero_max(T current, T range_max, T range_min)
|
||||||
{
|
{
|
||||||
// auto type_min = std::numeric_limits<T>::min();
|
int int_max = std::numeric_limits<int>::max();
|
||||||
auto type_min = 0;
|
|
||||||
auto type_max = std::numeric_limits<T>::max();
|
|
||||||
|
|
||||||
// auto int_min = std::numeric_limits<int>::min();
|
auto type_range = range_max - range_min;
|
||||||
auto int_min = 0;
|
double percentage = static_cast<double>(current - range_min) / static_cast<double>(type_range);
|
||||||
auto int_max = std::numeric_limits<int>::max();
|
int mapped_current = percentage * int_max;
|
||||||
|
|
||||||
auto type_range = type_max - type_min;
|
return {mapped_current, int_max};
|
||||||
auto int_range = int_max - int_min;
|
|
||||||
|
|
||||||
return static_cast<int>((value - type_min) * int_range / type_range + int_min);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -100,14 +97,21 @@ void ProgressDialog::updateSize()
|
|||||||
{
|
{
|
||||||
QSize lastSize = this->size();
|
QSize lastSize = this->size();
|
||||||
QSize qSize = QSize(480, minimumSizeHint().height());
|
QSize qSize = QSize(480, minimumSizeHint().height());
|
||||||
|
|
||||||
|
// if the current window is too small
|
||||||
|
if ((lastSize != qSize) && (lastSize.height() < qSize.height()))
|
||||||
|
{
|
||||||
resize(qSize);
|
resize(qSize);
|
||||||
setFixedSize(qSize);
|
|
||||||
// keep the dialog in the center after a resize
|
// keep the dialog in the center after a resize
|
||||||
if (lastSize != qSize)
|
|
||||||
this->move(
|
this->move(
|
||||||
this->parentWidget()->x() + (this->parentWidget()->width() - this->width()) / 2,
|
this->parentWidget()->x() + (this->parentWidget()->width() - this->width()) / 2,
|
||||||
this->parentWidget()->y() + (this->parentWidget()->height() - this->height()) / 2
|
this->parentWidget()->y() + (this->parentWidget()->height() - this->height()) / 2
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
setMinimumSize(qSize);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ProgressDialog::execWithTask(Task* task)
|
int ProgressDialog::execWithTask(Task* task)
|
||||||
@ -147,9 +151,6 @@ int ProgressDialog::execWithTask(Task* task)
|
|||||||
changeProgress(task->getProgress(), task->getTotalProgress());
|
changeProgress(task->getProgress(), task->getTotalProgress());
|
||||||
}
|
}
|
||||||
|
|
||||||
// auto size_hint = ui->verticalLayout->sizeHint();
|
|
||||||
// resize(size_hint.width(), size_hint.height());
|
|
||||||
|
|
||||||
return QDialog::exec();
|
return QDialog::exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,26 +210,31 @@ void ProgressDialog::addTaskProgress(TaskStepProgress* progress)
|
|||||||
{
|
{
|
||||||
SubTaskProgressBar* task_bar = new SubTaskProgressBar(this);
|
SubTaskProgressBar* task_bar = new SubTaskProgressBar(this);
|
||||||
taskProgress.insert(progress->uid, task_bar);
|
taskProgress.insert(progress->uid, task_bar);
|
||||||
ui->taskProgressLayout->insertWidget(0, task_bar);
|
ui->taskProgressLayout->addWidget(task_bar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressDialog::changeStepProgress(TaskStepProgressList task_progress)
|
void ProgressDialog::changeStepProgress(TaskStepProgressList task_progress)
|
||||||
{
|
{
|
||||||
m_is_multi_step = true;
|
m_is_multi_step = true;
|
||||||
|
if(ui->taskProgressScrollArea->isHidden()) {
|
||||||
ui->taskProgressScrollArea->setHidden(false);
|
ui->taskProgressScrollArea->setHidden(false);
|
||||||
|
updateSize();
|
||||||
|
}
|
||||||
|
|
||||||
for (auto tp : task_progress) {
|
for (auto tp : task_progress) {
|
||||||
if (!taskProgress.contains(tp->uid))
|
if (!taskProgress.contains(tp->uid))
|
||||||
addTaskProgress(tp.get());
|
addTaskProgress(tp.get());
|
||||||
auto task_bar = taskProgress.value(tp->uid);
|
auto task_bar = taskProgress.value(tp->uid);
|
||||||
|
|
||||||
if (tp->total < 0) {
|
|
||||||
|
auto const [mapped_current, mapped_total] = map_int_zero_max<qint64>(tp->current, tp->total, 0);
|
||||||
|
if (tp->total <= 0) {
|
||||||
task_bar->setRange(0, 0);
|
task_bar->setRange(0, 0);
|
||||||
} else {
|
} else {
|
||||||
task_bar->setRange(0, map_int_range<qint64>(tp->total));
|
task_bar->setRange(0, mapped_total);
|
||||||
}
|
}
|
||||||
|
|
||||||
task_bar->setValue(map_int_range<qint64>(tp->current));
|
task_bar->setValue(mapped_current);
|
||||||
task_bar->setStatus(tp->status);
|
task_bar->setStatus(tp->status);
|
||||||
task_bar->setDetails(tp->details);
|
task_bar->setDetails(tp->details);
|
||||||
|
|
||||||
@ -237,8 +243,6 @@ void ProgressDialog::changeStepProgress(TaskStepProgressList task_progress)
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressDialog::changeProgress(qint64 current, qint64 total)
|
void ProgressDialog::changeProgress(qint64 current, qint64 total)
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>600</width>
|
<width>480</width>
|
||||||
<height>260</height>
|
<height>210</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -18,19 +18,16 @@
|
|||||||
</property>
|
</property>
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>600</width>
|
<width>480</width>
|
||||||
<height>260</height>
|
<height>210</height>
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>600</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Please wait...</string>
|
<string>Please wait...</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="sizeGripEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0">
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
|
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
|
||||||
@ -112,8 +109,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>584</width>
|
<width>464</width>
|
||||||
<height>146</height>
|
<height>96</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="taskProgressLayout">
|
<layout class="QVBoxLayout" name="taskProgressLayout">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user