File indexing completed on 2024-05-12 05:37:17
0001 /* 0002 SPDX-FileCopyrightText: 2008 Rob Scheepmaker <r.scheepmaker@student.utwente.nl> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #pragma once 0008 0009 #include <QList> 0010 0011 #include <Plasma5Support/DataContainer> 0012 #include <Plasma5Support/DataEngine> 0013 0014 #include "jobsmodel.h" 0015 0016 namespace NotificationManager 0017 { 0018 class Job; 0019 } 0020 0021 namespace Plasma5Support 0022 { 0023 class Service; 0024 } // namespace Plasma5Support 0025 0026 class KuiserverEngine : public Plasma5Support::DataEngine 0027 { 0028 Q_OBJECT 0029 0030 public: 0031 KuiserverEngine(QObject *parent); 0032 ~KuiserverEngine() override; 0033 0034 void init(); 0035 0036 Plasma5Support::Service *serviceForSource(const QString &source) override; 0037 0038 static QString sourceName(NotificationManager::Job *job); 0039 static uint jobId(const QString &sourceName); 0040 0041 private: 0042 template<typename T, typename signal> 0043 void connectJobField(NotificationManager::Job *job, T (NotificationManager::Job::*getter)() const, signal changeSignal, const QString &targetFieldName) 0044 { 0045 // Set value initially in case we missed the first change 0046 const QString source = sourceName(job); 0047 setData(source, targetFieldName, ((job)->*getter)()); 0048 // and then listen for changes 0049 connect(job, changeSignal, this, [=, this] { 0050 setData(source, targetFieldName, ((job)->*getter)()); 0051 }); 0052 } 0053 0054 void updateDescriptionField(NotificationManager::Job *job, 0055 int number, 0056 QString (NotificationManager::Job::*labelGetter)() const, 0057 QString (NotificationManager::Job::*valueGetter)() const); 0058 0059 void updateUnit(NotificationManager::Job *job, 0060 int number, 0061 const QString &unit, 0062 qulonglong (NotificationManager::Job::*processedGetter)() const, 0063 qulonglong (NotificationManager::Job::*totalGetter)() const); 0064 0065 void registerJob(NotificationManager::Job *job); 0066 void removeJob(NotificationManager::Job *job); 0067 0068 static QString speedString(qulonglong speed); 0069 0070 void updateState(NotificationManager::Job *job); 0071 void updateSpeed(NotificationManager::Job *job); 0072 void updateEta(NotificationManager::Job *job); 0073 0074 NotificationManager::JobsModel::Ptr m_jobsModel; 0075 0076 QList<NotificationManager::Job *> m_jobs; 0077 };