Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit b5910935 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

flatpak: show download speed

Note it needs libflatpak 1.1.3 (1.1.2 is broken, will compile but discover
will crash at boot).

CCBUG: 396349
parent 19eece72
......@@ -12,6 +12,10 @@ set(flatpak-backend_SRCS
add_library(flatpak-backend MODULE ${flatpak-backend_SRCS})
target_link_libraries(flatpak-backend Qt5::Core Qt5::Widgets Qt5::Concurrent KF5::CoreAddons KF5::ConfigCore Discover::Common AppStreamQt PkgConfig::Flatpak)
if (NOT Flatpak_VERSION VERSION_LESS 1.1.2)
target_compile_definitions(flatpak-backend PRIVATE -DFLATPAK_VERBOSE_PROGRESS)
endif()
install(TARGETS flatpak-backend DESTINATION ${PLUGIN_INSTALL_DIR}/discover)
install(FILES flatpak-backend-categories.xml DESTINATION ${DATA_INSTALL_DIR}/libdiscover/categories)
......
......@@ -60,17 +60,13 @@ void FlatpakJobTransaction::start()
// App job will be added every time
m_appJob = new FlatpakTransactionThread(m_app, role());
connect(m_appJob, &FlatpakTransactionThread::finished, this, &FlatpakJobTransaction::finishTransaction);
connect(m_appJob, &FlatpakTransactionThread::progressChanged, this, &FlatpakJobTransaction::onJobProgressChanged);
connect(m_appJob, &FlatpakTransactionThread::progressChanged, this, &FlatpakJobTransaction::setProgress);
connect(m_appJob, &FlatpakTransactionThread::speedChanged, this, &FlatpakJobTransaction::setDownloadSpeed);
connect(m_appJob, &FlatpakTransactionThread::passiveMessage, this, &FlatpakJobTransaction::passiveMessage);
m_appJob->start();
}
void FlatpakJobTransaction::onJobProgressChanged(int progress)
{
setProgress(progress);
}
void FlatpakJobTransaction::finishTransaction()
{
if (m_appJob->result()) {
......
......@@ -44,7 +44,6 @@ public:
void cancel() override;
public Q_SLOTS:
void onJobProgressChanged(int progress);
void finishTransaction();
void start();
......
......@@ -47,8 +47,14 @@ progress_changed_cb (FlatpakTransactionProgress *progress,
{
FlatpakTransactionThread *obj = (FlatpakTransactionThread*) user_data;
qDebug() << "progress" << flatpak_transaction_progress_get_progress(progress);
obj->setProgress(flatpak_transaction_progress_get_progress(progress));
#ifdef FLATPAK_VERBOSE_PROGRESS
guint64 transferred = flatpak_transaction_progress_get_bytes_transferred (progress);
guint64 start_time = flatpak_transaction_progress_get_start_time (progress);
guint64 elapsed_time = (g_get_monotonic_time () - start_time) / G_USEC_PER_SEC;
obj->setSpeed(transferred / elapsed_time);
#endif
}
void
......@@ -67,7 +73,6 @@ new_operation_cb(FlatpakTransaction */*object*/,
FlatpakTransactionThread::FlatpakTransactionThread(FlatpakResource *app, Transaction::Role role)
: QThread()
, m_result(false)
, m_progress(0)
, m_app(app)
, m_role(role)
{
......@@ -151,11 +156,6 @@ FlatpakResource * FlatpakTransactionThread::app() const
return m_app;
}
int FlatpakTransactionThread::progress() const
{
return m_progress;
}
void FlatpakTransactionThread::setProgress(int progress)
{
if (m_progress != progress) {
......@@ -164,6 +164,14 @@ void FlatpakTransactionThread::setProgress(int progress)
}
}
void FlatpakTransactionThread::setSpeed(quint64 speed)
{
if (m_speed != speed) {
m_speed = speed;
Q_EMIT speedChanged(m_speed);
}
}
QString FlatpakTransactionThread::errorMessage() const
{
return m_errorMessage;
......
......@@ -43,21 +43,24 @@ public:
FlatpakResource * app() const;
int progress() const;
int progress() const { return m_progress; }
void setProgress(int progress);
void setSpeed(quint64 speed);
QString errorMessage() const;
bool result() const;
Q_SIGNALS:
void progressChanged(int progress);
void speedChanged(quint64 speed);
void passiveMessage(const QString &msg);
private:
FlatpakTransaction* m_transaction;
bool m_result;
int m_progress;
int m_progress = 0;
quint64 m_speed = 0;
QString m_errorMessage;
GCancellable *m_cancellable;
FlatpakResource *m_app;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment