add download progress report

This commit is contained in:
Nova 2025-05-08 02:02:23 +03:30
parent a2c5efc31d
commit 2731e479ce
5 changed files with 68 additions and 16 deletions

View File

@ -10,6 +10,13 @@ namespace NekoGui_network {
QList<QPair<QByteArray, QByteArray>> header;
};
struct DownloadProgressReport
{
QString fileName;
qint64 downloadedSize;
qint64 totalSize;
};
class NetworkRequestHelper : QObject {
Q_OBJECT

View File

@ -2,6 +2,7 @@
#include <QMainWindow>
#include <core/server/gen/libcore.pb.h>
#include <include/global/HTTPRequestHelper.hpp>
#include "include/global/NekoGui.hpp"
#include "include/stats/connections/connectionLister.hpp"
@ -87,8 +88,9 @@ public:
void UpdateConnectionListWithRecreate(const QList<NekoGui_traffic::ConnectionMetadata>& connections);
// TODO maybe use a more generalized way of passing data later, for now we only need it for speedtest data
void UpdateDataView(const libcore::SpeedTestResult& result, const QString& profileName, bool clear);
void UpdateDataView();
void setDownloadReport(const DownloadProgressReport& report, bool show);
signals:
@ -196,6 +198,13 @@ private:
int toolTipID;
//
SpeedWidget *speedChartWidget;
//
// for data view
QString currentSptProfileName;
bool showSpeedtestData = false;
bool showDownloadData = false;
libcore::SpeedTestResult currentTestResult;
DownloadProgressReport currentDownloadReport; // could use a list, but don't think can show more than one anyways
QList<std::shared_ptr<NekoGui::ProxyEntity>> get_now_selected_list();

View File

@ -9,6 +9,7 @@
#include <QApplication>
#include "include/global/NekoGui.hpp"
#include "include/ui/mainwindow.h"
namespace NekoGui_network {
@ -95,9 +96,21 @@ namespace NekoGui_network {
}
MW_show_log(QString("SSL Errors: %1").arg(error_str.join(",")));
});
connect(_reply, &QNetworkReply::downloadProgress, _reply, [&](qint64 bytesReceived, qint64 bytesTotal)
{
runOnUiThread([=]{
GetMainWindow()->setDownloadReport(DownloadProgressReport{fileName, bytesReceived, bytesTotal}, true);
GetMainWindow()->UpdateDataView();
});
});
QEventLoop loop;
connect(_reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
loop.exec();
runOnUiThread([=]
{
GetMainWindow()->setDownloadReport({}, false);
GetMainWindow()->UpdateDataView();
});
if(_reply->error() != QNetworkReply::NetworkError::NoError) {
return _reply->errorString();
}

View File

@ -928,26 +928,45 @@ void MainWindow::neko_set_spmode_vpn(bool enable, bool save) {
if (NekoGui::dataStore->started_id >= 0) neko_start(NekoGui::dataStore->started_id);
}
void MainWindow::UpdateDataView(const libcore::SpeedTestResult& result, const QString& profileName, bool clear)
void MainWindow::UpdateDataView()
{
if (clear)
QString html;
if (showDownloadData)
{
ui->data_view->clear();
return;
qint64 count = 10*currentDownloadReport.downloadedSize / currentDownloadReport.totalSize;
QString progressText;
for (int i = 0; i < 10; i++)
{
if (count--; count >=0) progressText += "#";
else progressText += "-";
}
QString stat = ReadableSize(currentDownloadReport.downloadedSize) + "/" + ReadableSize(currentDownloadReport.totalSize);
html = QString("<p style='text-align:center;margin:0;'>Downloading %1: %2 %3</p>").arg(currentDownloadReport.fileName, stat, progressText);
}
QString html = QString(
if (showSpeedtestData)
{
html += QString(
"<p style='text-align:center;margin:0;'>Running Speedtest: %1</p>"
"<p style='text-align:center; color:#3299FF;margin:0;'>Dl↓ %2</p>"
"<p style='text-align:center; color:#86C43F;margin:0;'>Ul↑ %3</p>"
"<div style='text-align: center;'>"
"<span style='color: #3299FF;'>Dl↓ %2</span> "
"<span style='color: #86C43F;'>Ul↑ %3</span>"
"</div>"
"<p style='text-align:center;margin:0;'>Server: %4, %5</p>"
).arg(profileName,
result.dl_speed().c_str(),
result.ul_speed().c_str(),
result.server_country().c_str(),
result.server_name().c_str());
).arg(currentSptProfileName,
currentTestResult.dl_speed().c_str(),
currentTestResult.ul_speed().c_str(),
currentTestResult.server_country().c_str(),
currentTestResult.server_name().c_str());
}
ui->data_view->setHtml(html);
}
void MainWindow::setDownloadReport(const DownloadProgressReport& report, bool show)
{
showDownloadData = show;
currentDownloadReport = report;
}
void MainWindow::setupConnectionList()
{

View File

@ -247,12 +247,16 @@ void MainWindow::runSpeedTest(const QString& config, bool useDefault, const QStr
}
runOnUiThread([=]
{
UpdateDataView(res.result(), profile->bean->name, false);
showSpeedtestData = true;
currentSptProfileName = profile->bean->name;
currentTestResult = res.result();
UpdateDataView();
});
}
runOnUiThread([=]
{
UpdateDataView({}, {}, true);
showSpeedtestData = false;
UpdateDataView();
});
doneMu->unlock();
delete doneMu;