Commit e691df1f authored by LordTermor's avatar LordTermor

Transaction progress is now expored as KDE Plasma job

parent 75577674
......@@ -102,6 +102,7 @@ Pane {
visible: transaction.started
progress: transaction.progress
indeterminate: transaction.indeterminate
infoMessage: transaction.action
}
RowLayout{
......
......@@ -7,6 +7,7 @@ class DesktopProgress: public QQuickItem{
Q_PROPERTY(bool visible READ visible WRITE setShow NOTIFY showChanged)
Q_PROPERTY(double progress READ progress WRITE setProgress NOTIFY progressChanged)
Q_PROPERTY(bool indeterminate READ indeterminate WRITE setIndeterminate NOTIFY indeterminateChanged)
Q_PROPERTY(QString infoMessage READ infoMessage WRITE setInfoMessage NOTIFY infoMessageChanged)
public:
DesktopProgress(QQuickItem* parent = nullptr);
......@@ -15,22 +16,35 @@ public:
bool indeterminate() const;
QString infoMessage() const
{
return m_infoMessage;
}
public Q_SLOTS:
void setShow(bool visible);
void setProgress(double progress);
void setIndeterminate(bool indeterminate);
void setInfoMessage(const QString &infoMessage);
Q_SIGNALS:
void showChanged(bool visible);
void progressChanged(double progress);
void indeterminateChanged(bool indeterminate);
void infoMessageChanged(QString infoMessage);
private:
QString m_kjob;
bool m_show;
double m_progress;
bool m_indeterminate;
QString m_infoMessage;
};
#include "DesktopProgress.h"
#include <QApplication>
#include <QtDBus>
void send_unity_launcher_entry_message(const QVariantMap& message){
QDBusMessage signal = QDBusMessage::createSignal("/",
......@@ -12,6 +13,46 @@ void send_unity_launcher_entry_message(const QVariantMap& message){
QDBusConnection::sessionBus().send(signal);
}
QString kjob_get_job(){
QDBusInterface interface("org.kde.JobViewServer", "/JobViewServer", "org.kde.JobViewServer", QDBusConnection::sessionBus());
if(!interface.isValid()){
return QString();
}
auto message = interface.call("requestView",QApplication::applicationName(),"system-software-install",0);
qDebug()<<message.arguments();
return message.arguments()[0].value<QDBusObjectPath>().path();
}
void kjob_update_progress(const QString& job, uint percent){
if(job.isNull()){
return;
}
QDBusInterface interface("org.kde.JobViewServer", job, "org.kde.JobViewV2", QDBusConnection::sessionBus());
if(interface.isValid())
interface.call("setPercent",percent);
}
void kjob_terminate(const QString& job){
if(job.isNull()){
return;
}
QDBusInterface interface("org.kde.JobViewServer", job, "org.kde.JobViewV2", QDBusConnection::sessionBus());
if(interface.isValid()){
interface.call("terminate","");
}
}
void kjob_update_info(const QString& job, const QString& info){
if(job.isNull()){
return;
}
QDBusInterface interface("org.kde.JobViewServer", job, "org.kde.JobViewV2", QDBusConnection::sessionBus());
if(interface.isValid()){
interface.call("setInfoMessage",info);
}
}
bool DesktopProgress::visible() const
{
......@@ -32,23 +73,34 @@ void DesktopProgress::setShow(bool show)
{
if (m_show == show) {
return;
}
}
m_show = show;
Q_EMIT showChanged(m_show);
if(m_show){
m_kjob = kjob_get_job();
kjob_update_info(m_kjob,m_infoMessage);
kjob_update_progress(m_kjob,uint(m_progress*100));
} else{
kjob_terminate(m_kjob);
}
send_unity_launcher_entry_message({{"progress-visible",show}});
}
void DesktopProgress::setProgress(double progress)
{
qWarning("Floating point comparison needs context sanity check");
if (qFuzzyCompare(m_progress, progress)) {
return;
}
}
m_progress = progress;
Q_EMIT progressChanged(m_progress);
if(!m_kjob.isNull()){
kjob_update_progress(m_kjob,uint(progress*100));
}
send_unity_launcher_entry_message({{"progress",progress}});
}
......@@ -56,11 +108,29 @@ void DesktopProgress::setIndeterminate(bool indeterminate)
{
if (m_indeterminate == indeterminate) {
return;
}
}
m_indeterminate = indeterminate;
Q_EMIT indeterminateChanged(m_indeterminate);
Q_EMIT indeterminateChanged(m_indeterminate);
if(!m_kjob.isNull()){
if(m_indeterminate){
kjob_update_progress(m_kjob,0);
} else {
kjob_update_progress(m_kjob,uint(m_progress*100));
}
}
}
DesktopProgress::DesktopProgress(QQuickItem* parent):QQuickItem(parent){
}
void DesktopProgress::setInfoMessage(const QString& infoMessage)
{
if (m_infoMessage == infoMessage)
return;
m_infoMessage = infoMessage;
kjob_update_info(m_kjob,infoMessage);
Q_EMIT infoMessageChanged(m_infoMessage);
}
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