Files
qt5-legatus-legacy/Lts/Plugins/TakeHomePackageManager/OldTHP/Common/tpm_process_dialog.cpp
T
2026-08-13 18:33:10 +02:00

67 lines
1.9 KiB
C++
Executable File

#include "tpm_process_dialog.h"
#include "ui_tpm_process_dialog.h"
namespace TakeHomePackageManager
{
ProcessOverlay::ProcessOverlay(QWidget *parent)
: QWidget(parent)
, m_ui(new Ui::ProcessOverlay)
{
m_ui->setupUi(this);
connect(m_ui->pbCancel, &QPushButton::clicked,
this, [this]()
{
m_ui->pbCancel->setEnabled(false);
emit signalCancel();
});
}
ProcessOverlay::~ProcessOverlay()
{
delete m_ui;
}
void ProcessOverlay::setCancelEnabled(bool enabled)
{
m_ui->pbCancel->setEnabled(enabled);
}
void ProcessOverlay::setStatus(const QString &text, qint64 totalFiles, qint64 curFile, qint64 totalSize, qint64 curPos, const QString &curName)
{
if (!text.isEmpty()) // only set new text if not empty (we dont want to send the text on every update..
m_ui->lblStatus->setText(text);
if (!curName.isEmpty()) // only set new text if not empty (we dont want to send the text on every update..
m_ui->lblFilename->setText(curName);
double progressBytes = (totalSize == 0) ? (double)0 : ((double)curPos / (double)totalSize);
double progressFiles = (((double)curFile - 1) / (double)totalFiles);
double progressTotal = progressFiles + (progressBytes / (double)totalFiles);
progressBytes = qRound(progressBytes * 100);
progressFiles = qRound(progressFiles * 100);
progressTotal = qRound(progressTotal * 100);
m_ui->pbarFiles->setValue(progressFiles);
m_ui->pbarBytes->setValue(progressBytes);
m_ui->pbarProgress->setValue(progressTotal);
QLocale l;
if (curFile == 0)
m_ui->lblFiles->setText(QStringLiteral(" - "));
else
m_ui->lblFiles->setText(QStringLiteral("%1 / %2").arg(l.toString(curFile)).arg(l.toString(totalFiles)));
if (curPos == 0)
m_ui->lblBytes->setText(QStringLiteral(" - "));
else
m_ui->lblBytes->setText(QStringLiteral("%1 / %2").arg(l.toString(curPos)).arg(l.toString(totalSize)));
}
} // namespace TakehomePackageManager