Commit 98e1fddc authored by Harald Sitter's avatar Harald Sitter 🏳️‍🌈
Browse files

always try to notify on device appearance

since a hotfix that changed when exactly devices appear the
notifications have been broken as they'd never get emitted when the
failed property was already true when the deviceAdded signal fired (i.e.
pretty much always unless the state changed while the system was
running)

to fix this always try to notify on devices when they appear. if they
aren't failing we aren't raising notifications anyway
parent eada1e17
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
// SPDX-FileCopyrightText: 2020 Harald Sitter <sitter@kde.org>
// SPDX-FileCopyrightText: 2020-2021 Harald Sitter <sitter@kde.org>
#include "smartnotifier.h"
......@@ -58,15 +58,30 @@ SMARTNotifier::SMARTNotifier(SMARTMonitor *monitor, QObject *parent)
: QObject(parent)
{
connect(monitor, &SMARTMonitor::deviceAdded, this, [this](const Device *device) {
connect(device, &Device::failedChanged, this, [this, device] {
if (device->failed() && !device->ignore()) {
new FailureNotification(device, this); // auto-deletes
// once displayed we'll not want to trigger any more notifications
device->disconnect(this);
}
});
connect(device, &Device::failedChanged, this, &SMARTNotifier::onMaybeFailed);
// The device may already be in failure state. Make sure we display it if applicable.
maybeFailed(device);
});
// upon removal the devices are deleted which takes care of disconnecting
}
void SMARTNotifier::onMaybeFailed()
{
maybeFailed(qobject_cast<Device *>(sender()));
}
void SMARTNotifier::maybeFailed(const Device *device)
{
Q_ASSERT(device);
// We notify on instabilities in the hopes that there won't be false positives.
// Might need revisiting.
if (!device->failed() || device->ignore()) {
return;
}
new FailureNotification(device, this); // auto-deletes
// once displayed we'll not want to trigger any more notifications
device->disconnect(this);
}
#include "smartnotifier.moc"
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
// SPDX-FileCopyrightText: 2020 Harald Sitter <sitter@kde.org>
// SPDX-FileCopyrightText: 2020-2021 Harald Sitter <sitter@kde.org>
#pragma once
......@@ -13,4 +13,10 @@ class SMARTNotifier : public QObject
Q_OBJECT
public:
SMARTNotifier(SMARTMonitor *monitor, QObject *parent = nullptr);
private Q_SLOTS:
void onMaybeFailed();
private:
void maybeFailed(const Device *device);
};
Supports Markdown
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