Commit c8965364 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Notifier: Use the notification frequency also for unattended updates

Makes it so unattended updates can also be contained.
parent e9bd8a08
Pipeline #222062 passed with stage
in 1 minute and 25 seconds
......@@ -62,14 +62,24 @@ SimpleKCM {
}
QQC2.ComboBox {
Kirigami.FormData.label: i18nc("@title:group", "Notification frequency:")
model: [
Kirigami.FormData.label: kcm.updatesSettings.useUnattendedUpdates ? i18nc("@title:group", "Update frequency:") : i18nc("@title:group", "Notification frequency:")
readonly property var updatesFrequencyModel: [
i18nc("@item:inlistbox", "Daily"),
i18nc("@item:inlistbox", "Weekly"),
i18nc("@item:inlistbox", "Monthly"),
i18nc("@item:inlistbox", "Never")
]
// Same as updatesFrequencyModel but without "Never"
readonly property var unattendedUpdatesFrequencyModel: [
updatesFrequencyModel[0],
updatesFrequencyModel[1],
updatesFrequencyModel[2],
]
model: kcm.updatesSettings.useUnattendedUpdates ? unattendedUpdatesFrequencyModel : updatesFrequencyModel
readonly property var options: [
60 * 60 * 24,
60 * 60 * 24 * 7,
......
......@@ -100,24 +100,36 @@ void DiscoverNotifier::showDiscoverUpdates(const QString &xdgActivationToken)
}
}
void DiscoverNotifier::showUpdatesNotification()
bool DiscoverNotifier::notifyAboutUpdates() const
{
if (m_updatesAvailableNotification) {
m_updatesAvailableNotification->close();
}
if (state() != NormalUpdates && state() != SecurityUpdates) {
// it's not very helpful to notify that everything is in order
return;
return false;
}
if (m_settings->requiredNotificationInterval() < 0) {
return;
return false;
}
// To configure to a random value, execute:
// kwriteconfig5 --file PlasmaDiscoverUpdates --group Global --key RequiredNotificationInterval 3600
const QDateTime timeSinceLastRefresh = m_settings->lastNotificationTime().addSecs(m_settings->requiredNotificationInterval());
if (!timeSinceLastRefresh.isValid() || timeSinceLastRefresh > QDateTime::currentDateTimeUtc()) {
return false;
}
m_settings->setLastNotificationTime(QDateTime::currentDateTimeUtc());
m_settings->save();
return true;
}
void DiscoverNotifier::showUpdatesNotification()
{
if (m_updatesAvailableNotification) {
m_updatesAvailableNotification->close();
}
if (!notifyAboutUpdates()) {
return;
}
......@@ -135,8 +147,6 @@ void DiscoverNotifier::showUpdatesNotification()
connect(m_updatesAvailableNotification, QOverload<unsigned int>::of(&KNotification::activated), this, [this] {
showDiscoverUpdates(m_updatesAvailableNotification->xdgActivationToken());
});
m_settings->setLastNotificationTime(QDateTime::currentDateTimeUtc());
m_settings->save();
}
void DiscoverNotifier::updateStatusNotifier()
......@@ -178,6 +188,11 @@ static bool isConnectionAdequate()
void DiscoverNotifier::refreshUnattended()
{
m_settings->read();
if (!notifyAboutUpdates()) {
return;
}
const auto enabled = m_settings->useUnattendedUpdates()
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
&& m_manager->isOnline() && isConnectionAdequate(m_manager->defaultConfiguration());
......
......@@ -92,6 +92,8 @@ private:
void updateStatusNotifier();
void refreshUnattended();
bool notifyAboutUpdates() const;
QList<BackendNotifierModule *> m_backends;
QTimer m_timer;
bool m_hasSecurityUpdates = false;
......
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