mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2026-01-31 05:19:47 +00:00
feat: use singleton connection to systemstats
it has been found in #174, that if there are multiple instances of widget, it keeps subscribing on all sources, because of how dbus interface works. In order to hande it, all subscriptions are now kept from singleton with tracking active clients
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include <QObject>
|
||||
#include <QSet>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace KSysGuard::SystemStats
|
||||
{
|
||||
@@ -34,12 +35,26 @@ class AWDataEngineAggregator : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AWDataEngineAggregator(QObject *_parent = nullptr);
|
||||
~AWDataEngineAggregator() override;
|
||||
|
||||
AWDataEngineAggregator(AWDataEngineAggregator &) = delete;
|
||||
void operator=(const AWDataEngineAggregator &) = delete;
|
||||
|
||||
[[nodiscard]] static AWDataEngineAggregator *instance(QObject *_client)
|
||||
{
|
||||
static auto instance = loadInstance();
|
||||
instance->registerClient(_client);
|
||||
return instance.get();
|
||||
};
|
||||
|
||||
void connectSources();
|
||||
void disconnectSources();
|
||||
void dropSourceForClient(QObject *_client, const QString &_source);
|
||||
[[nodiscard]] inline bool isSubscriptionUnused(const QString &_source) const;
|
||||
[[nodiscard]] static bool isValidSensor(const KSysGuard::SensorInfo &_sensor);
|
||||
void loadSources();
|
||||
void registerClient(QObject *_client);
|
||||
void unregisterClient(QObject *_client);
|
||||
|
||||
signals:
|
||||
void dataUpdated(const QHash<QString, KSysGuard::SensorInfo> &_sensors, const KSysGuard::SensorDataList &_data);
|
||||
@@ -52,7 +67,18 @@ public slots:
|
||||
void updateData(const KSysGuard::SensorDataList &_data);
|
||||
void updateSensors(const QHash<QString, KSysGuard::SensorInfo> &_sensors);
|
||||
|
||||
protected:
|
||||
explicit AWDataEngineAggregator(QObject *_parent = nullptr);
|
||||
|
||||
[[nodiscard]] static std::unique_ptr<AWDataEngineAggregator> loadInstance()
|
||||
{
|
||||
auto instance = new AWDataEngineAggregator();
|
||||
return std::unique_ptr<AWDataEngineAggregator>(instance);
|
||||
};
|
||||
|
||||
private:
|
||||
QSet<QObject *> m_clients;
|
||||
QHash<QString, QSet<QObject *>> m_droppedBy;
|
||||
KSysGuard::SystemStats::DBusInterface *m_interface = nullptr;
|
||||
QHash<QString, KSysGuard::SensorInfo> m_sensors;
|
||||
QSet<QString> m_subscribed;
|
||||
|
||||
Reference in New Issue
Block a user