Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[lipstick] Remove more unnecessary notification categories. JB#39340
  • Loading branch information
Bea Lam committed Aug 18, 2020
1 parent 175f60d commit 1f064a5
Show file tree
Hide file tree
Showing 24 changed files with 80 additions and 112 deletions.
4 changes: 0 additions & 4 deletions src/notificationcategories/device.added.conf

This file was deleted.

4 changes: 0 additions & 4 deletions src/notificationcategories/device.error.conf

This file was deleted.

4 changes: 0 additions & 4 deletions src/notificationcategories/device.removed.conf

This file was deleted.

3 changes: 0 additions & 3 deletions src/notificationcategories/network.error.conf

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions src/notificationcategories/x-nemo.battery.enterpsm.conf

This file was deleted.

3 changes: 0 additions & 3 deletions src/notificationcategories/x-nemo.battery.exitpsm.conf

This file was deleted.

5 changes: 0 additions & 5 deletions src/notificationcategories/x-nemo.battery.lowbattery.conf

This file was deleted.

4 changes: 0 additions & 4 deletions src/notificationcategories/x-nemo.battery.notenoughpower.conf

This file was deleted.

4 changes: 0 additions & 4 deletions src/notificationcategories/x-nemo.battery.recharge.conf

This file was deleted.

4 changes: 0 additions & 4 deletions src/notificationcategories/x-nemo.battery.removecharger.conf

This file was deleted.

4 changes: 0 additions & 4 deletions src/notificationcategories/x-nemo.battery.shutdown.conf

This file was deleted.

4 changes: 0 additions & 4 deletions src/notificationcategories/x-nemo.battery.temperature.conf

This file was deleted.

3 changes: 0 additions & 3 deletions src/notificationcategories/x-nemo.device.locked.conf

This file was deleted.

3 changes: 0 additions & 3 deletions src/notificationcategories/x-nemo.general.warning.conf

This file was deleted.

51 changes: 34 additions & 17 deletions src/notifications/batterynotifier.cpp
Expand Up @@ -396,45 +396,55 @@ void BatteryNotifier::sendNotification(BatteryNotifier::NotificationType type)
static const struct NotificationInfo {
QString category;
QString message;
QString feedback;
QString icon;
} description[] = {
{"x-nemo.battery", // NotificationCharging
//% "Charging"
qtTrId("qtn_ener_charging"),
"",
""},
{"x-nemo.battery.chargingcomplete", // NotificationChargingComplete
{"", // NotificationChargingComplete
//% "Charging complete"
qtTrId("qtn_ener_charcomp"),
""},
{"x-nemo.battery.removecharger", // NotificationRemoveCharger
"",
"icon-system-charging"},
{"", // NotificationRemoveCharger
//% "Disconnect charger from power supply to save energy"
qtTrId("qtn_ener_remcha"),
""},
{"x-nemo.battery.chargingnotstarted", // NotificationChargingNotStarted
"",
"icon-system-charging"},
{"", // NotificationChargingNotStarted
//% "Charging not started. Replace charger."
qtTrId("qtn_ener_repcharger"),
""},
{"x-nemo.battery.recharge", // NotificationRechargeBattery
"general_warning",
"icon-system-battery"},
{"", // NotificationRechargeBattery
//% "Recharge battery"
qtTrId("qtn_ener_rebatt"),
""},
{"x-nemo.battery.enterpsm", // NotificationEnteringPSM
"battery_empty",
"icon-system-battery"},
{"", // NotificationEnteringPSM
//% "Entering power save mode"
qtTrId("qtn_ener_ent_psnote"),
""},
{"x-nemo.battery.exitpsm", // NotificationExitingPSM
"battery_low",
"icon-system-battery"},
{"", // NotificationExitingPSM
//% "Exiting power save mode"
qtTrId("qtn_ener_exit_psnote"),
""},
{"x-nemo.battery.lowbattery", // NotificationLowBattery
"",
"icon-system-battery"},
{"", // NotificationLowBattery
//: Shown when the battery is low. %1 = current battery level as a percentage
//% "Low battery: %1%"
qtTrId("qtn_ener_lowbatt_with_percentage"),
""},
{"x-nemo.battery.notenoughpower", // NotificationNotEnoughPower
"battery_low",
"icon-system-battery"},
{"", // NotificationNotEnoughPower
//% "Not enough power to charge"
qtTrId("qtn_ener_nopowcharge"),
"icon-m-energy-management-insufficient-power"}
"",
"icon-system-battery"}
};
Q_ASSERT(type < sizeof(description) / sizeof(description[0]));
NotificationInfo const &info = description[type];
Expand All @@ -457,8 +467,15 @@ void BatteryNotifier::sendNotification(BatteryNotifier::NotificationType type)

/* Add fresh notification item */
QVariantHash hints;
hints.insert(LipstickNotification::HINT_CATEGORY, info.category);
if (!info.category.isEmpty()) {
hints.insert(LipstickNotification::HINT_CATEGORY, info.category);
}
if (!info.feedback.isEmpty()) {
hints.insert(LipstickNotification::HINT_FEEDBACK, info.feedback);
}
hints.insert(LipstickNotification::HINT_VISIBILITY, QLatin1String("public"));
hints.insert(LipstickNotification::HINT_URGENCY, LipstickNotification::Critical);
hints.insert(LipstickNotification::HINT_TRANSIENT, true);
QueuedNotification queuedNotification;
queuedNotification.m_type = type;
queuedNotification.m_id = m_notificationManager->Notify(m_notificationManager->systemApplicationName(),
Expand Down
15 changes: 10 additions & 5 deletions src/notifications/thermalnotifier.cpp
Expand Up @@ -32,15 +32,15 @@ void ThermalNotifier::applyThermalState(DeviceState::Thermal::ThermalState state
switch (state) {
case DeviceState::Thermal::Warning:
//% "Device is getting hot. Close all apps."
createAndPublishNotification("x-nemo.battery.temperature", qtTrId("qtn_shut_high_temp_warning"));
publishTemperatureNotification(qtTrId("qtn_shut_high_temp_warning"));
break;
case DeviceState::Thermal::Alert:
//% "Device is overheating. turn it off."
createAndPublishNotification("x-nemo.battery.temperature", qtTrId("qtn_shut_high_temp_alert"));
publishTemperatureNotification(qtTrId("qtn_shut_high_temp_alert"));
break;
case DeviceState::Thermal::LowTemperatureWarning:
//% "Low temperature warning"
createAndPublishNotification("x-nemo.battery.temperature", qtTrId("qtn_shut_low_temp_warning"));
publishTemperatureNotification(qtTrId("qtn_shut_low_temp_warning"));
break;
default:
break;
Expand All @@ -61,11 +61,16 @@ void ThermalNotifier::applyDisplayState(DeviceState::DisplayStateMonitor::Displa
}
}

void ThermalNotifier::createAndPublishNotification(const QString &category, const QString &body)
void ThermalNotifier::publishTemperatureNotification(const QString &body)
{
NotificationManager *manager = NotificationManager::instance();

QVariantHash hints;
hints.insert(LipstickNotification::HINT_CATEGORY, category);
hints.insert(LipstickNotification::HINT_APP_ICON, "icon-system-warning");
hints.insert(LipstickNotification::HINT_URGENCY, LipstickNotification::Critical);
hints.insert(LipstickNotification::HINT_TRANSIENT, true);
hints.insert(LipstickNotification::HINT_FEEDBACK, "general_warning");

manager->Notify(manager->systemApplicationName(),
0,
QString(),
Expand Down
15 changes: 7 additions & 8 deletions src/notifications/thermalnotifier.h
Expand Up @@ -24,6 +24,13 @@ class ThermalNotifier : public QObject
public:
explicit ThermalNotifier(QObject *parent = 0);

/*!
* Shows a system notification.
*
* \param body the body text of the notification
*/
static void publishTemperatureNotification(const QString &body);

private slots:
/*!
* Reacts to thermal state changes by showing the
Expand All @@ -42,14 +49,6 @@ private slots:
void applyDisplayState(DeviceState::DisplayStateMonitor::DisplayState state);

private:
/*!
* Shows a system notification.
*
* \param category the category of the notification
* \param body the body text of the notification
*/
void createAndPublishNotification(const QString &category, const QString &body);

//! For getting the thermal state
DeviceState::Thermal *m_thermalState;

Expand Down
17 changes: 11 additions & 6 deletions src/shutdownscreen.cpp
Expand Up @@ -23,6 +23,7 @@
#include "utilities/closeeventeater.h"
#include "notifications/notificationmanager.h"
#include "notifications/lipsticknotification.h"
#include "notifications/thermalnotifier.h"
#include "homeapplication.h"
#include "shutdownscreen.h"
#include "lipstickqmlpath.h"
Expand Down Expand Up @@ -82,17 +83,17 @@ void ShutdownScreen::applySystemState(DeviceState::DeviceState::StateIndication

case DeviceState::DeviceState::ThermalStateFatal:
//% "Temperature too high. Device shutting down."
createAndPublishNotification("x-nemo.battery.temperature", qtTrId("qtn_shut_high_temp"));
ThermalNotifier::publishTemperatureNotification(qtTrId("qtn_shut_high_temp"));
break;

case DeviceState::DeviceState::ShutdownDeniedUSB:
//% "USB cable plugged in. Unplug the USB cable to shutdown."
createAndPublishNotification("device.added", qtTrId("qtn_shut_unplug_usb"));
publishNotification("icon-system-usb", "accessory_connected", qtTrId("qtn_shut_unplug_usb"));
break;

case DeviceState::DeviceState::BatteryStateEmpty:
//% "Battery empty. Device shutting down."
createAndPublishNotification("x-nemo.battery.shutdown", qtTrId("qtn_shut_batt_empty"));
publishNotification("icon-system-battery", "battery_empty", qtTrId("qtn_shut_batt_empty"));
break;

case DeviceState::DeviceState::Reboot:
Expand Down Expand Up @@ -129,11 +130,15 @@ void ShutdownScreen::setUser(uint uid)
m_user = uid;
}

void ShutdownScreen::createAndPublishNotification(const QString &category, const QString &body)
void ShutdownScreen::publishNotification(const QString &icon, const QString &feedback, const QString &body)
{
NotificationManager *manager = NotificationManager::instance();
QVariantHash hints;
hints.insert(LipstickNotification::HINT_CATEGORY, category);
hints.insert(LipstickNotification::HINT_APP_ICON, icon);
hints.insert(LipstickNotification::HINT_URGENCY, LipstickNotification::Critical);
hints.insert(LipstickNotification::HINT_TRANSIENT, true);
hints.insert(LipstickNotification::HINT_FEEDBACK, feedback);

NotificationManager *manager = NotificationManager::instance();
manager->Notify(manager->systemApplicationName(), 0, QString(), QString(), body, QStringList(), hints, -1);
}

Expand Down
5 changes: 3 additions & 2 deletions src/shutdownscreen.h
Expand Up @@ -79,10 +79,11 @@ private slots:
/*!
* Shows a system notification.
*
* \param category the category of the notification
* \param icon the icon of the notification
* \param feedback the feedback of the notification
* \param body the body text of the notification
*/
void createAndPublishNotification(const QString &category, const QString &body);
void publishNotification(const QString &icon, const QString &feedback, const QString &body);

//! The volume control window
HomeWindow *m_window;
Expand Down
11 changes: 4 additions & 7 deletions tests/ut_shutdownscreen/ut_shutdownscreen.cpp
Expand Up @@ -85,7 +85,7 @@ void Ut_ShutdownScreen::cleanup()

void Ut_ShutdownScreen::testConnections()
{
QCOMPARE(disconnect(shutdownScreen->m_systemState, SIGNAL(systemStateChanged(DeviceState::DeviceState::StateIndication)), shutdownScreen, SLOT(applySystemState(DeviceState::DeviceState::StateIndication))), true);
QCOMPARE(disconnect(shutdownScreen->m_systemState, &DeviceState::DeviceState::systemStateChanged, shutdownScreen, &ShutdownScreen::applySystemState), true);
}

void Ut_ShutdownScreen::testSystemState()
Expand All @@ -94,22 +94,19 @@ void Ut_ShutdownScreen::testSystemState()
shutdownScreen->applySystemState(DeviceState::DeviceState::ThermalStateFatal);
QCOMPARE(qQuickViews.count(), 0);
QCOMPARE(gNotificationManagerStub->stubCallCount("Notify"), 1);
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QVariantHash>(6).value(LipstickNotification::HINT_CATEGORY).toString(), QString("x-nemo.battery.temperature"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QVariantHash>(6).value(LipstickNotification::HINT_PREVIEW_BODY).toString(), qtTrId("qtn_shut_high_temp"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(4), qtTrId("qtn_shut_high_temp"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString());

shutdownScreen->applySystemState(DeviceState::DeviceState::ShutdownDeniedUSB);
QCOMPARE(qQuickViews.count(), 0);
QCOMPARE(gNotificationManagerStub->stubCallCount("Notify"), 2);
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QVariantHash>(6).value(LipstickNotification::HINT_CATEGORY).toString(), QString("device.added"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QVariantHash>(6).value(LipstickNotification::HINT_PREVIEW_BODY).toString(), qtTrId("qtn_shut_unplug_usb"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(4), qtTrId("qtn_shut_unplug_usb"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString());

shutdownScreen->applySystemState(DeviceState::DeviceState::BatteryStateEmpty);
QCOMPARE(qQuickViews.count(), 0);
QCOMPARE(gNotificationManagerStub->stubCallCount("Notify"), 3);
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QVariantHash>(6).value(LipstickNotification::HINT_CATEGORY).toString(), QString("x-nemo.battery.shutdown"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QVariantHash>(6).value(LipstickNotification::HINT_PREVIEW_BODY).toString(), qtTrId("qtn_shut_batt_empty"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(4), qtTrId("qtn_shut_batt_empty"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString());

shutdownScreen->applySystemState(DeviceState::DeviceState::Shutdown);
Expand Down
8 changes: 8 additions & 0 deletions tests/ut_shutdownscreen/ut_shutdownscreen.pro
Expand Up @@ -10,22 +10,30 @@ PKGCONFIG += dsme_dbus_if thermalmanager_dbus_if usb_moded sailfishusermanager
SOURCES += \
$$SRCDIR/shutdownscreen.cpp \
$$NOTIFICATIONSRCDIR/lipsticknotification.cpp \
$$NOTIFICATIONSRCDIR/thermalnotifier.cpp \
$$STUBSDIR/stubbase.cpp \
$$STUBSDIR/homewindow.cpp \
$$STUBSDIR/homeapplication.cpp \
$$DEVICESTATE/devicestate.cpp \
$$DEVICESTATE/displaystate.cpp \
$$DEVICESTATE/thermal.cpp \
$$DEVICESTATE/ipcinterface.cpp \
ut_shutdownscreen.cpp

HEADERS += \
$$SRCDIR/shutdownscreen.h \
$$NOTIFICATIONSRCDIR/notificationmanager.h \
$$NOTIFICATIONSRCDIR/lipsticknotification.h \
$$NOTIFICATIONSRCDIR/thermalnotifier.h \
$$UTILITYSRCDIR/closeeventeater.h \
$$SRCDIR/homeapplication.h \
$$SRCDIR/homewindow.h \
$$DEVICESTATE/devicestate.h \
$$DEVICESTATE/devicestate_p.h \
$$DEVICESTATE/displaystate.h \
$$DEVICESTATE/displaystate_p.h \
$$DEVICESTATE/thermal.h \
$$DEVICESTATE/thermal_p.h \
$$DEVICESTATE/ipcinterface_p.h \
$$STUBSDIR/nemo-devicelock/devicelock.h \
ut_shutdownscreen.h
9 changes: 3 additions & 6 deletions tests/ut_thermalnotifier/ut_thermalnotifier.cpp
Expand Up @@ -71,20 +71,17 @@ void Ut_ThermalNotifier::testThermalState()
{
thermalNotifier->applyThermalState(DeviceState::Thermal::Warning);
QCOMPARE(gNotificationManagerStub->stubCallCount("Notify"), 1);
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QVariantHash>(6).value(LipstickNotification::HINT_CATEGORY).toString(), QString("x-nemo.battery.temperature"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QVariantHash>(6).value(LipstickNotification::HINT_PREVIEW_BODY).toString(), qtTrId("qtn_shut_high_temp_warning"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(4), qtTrId("qtn_shut_high_temp_warning"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString());

thermalNotifier->applyThermalState(DeviceState::Thermal::Alert);
QCOMPARE(gNotificationManagerStub->stubCallCount("Notify"), 2);
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QVariantHash>(6).value(LipstickNotification::HINT_CATEGORY).toString(), QString("x-nemo.battery.temperature"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QVariantHash>(6).value(LipstickNotification::HINT_PREVIEW_BODY).toString(), qtTrId("qtn_shut_high_temp_alert"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(4), qtTrId("qtn_shut_high_temp_alert"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString());

thermalNotifier->applyThermalState(DeviceState::Thermal::LowTemperatureWarning);
QCOMPARE(gNotificationManagerStub->stubCallCount("Notify"), 3);
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QVariantHash>(6).value(LipstickNotification::HINT_CATEGORY).toString(), QString("x-nemo.battery.temperature"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QVariantHash>(6).value(LipstickNotification::HINT_PREVIEW_BODY).toString(), qtTrId("qtn_shut_low_temp_warning"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(4), qtTrId("qtn_shut_low_temp_warning"));
QCOMPARE(gNotificationManagerStub->stubLastCallTo("Notify").parameter<QString>(2), QString());
}

Expand Down

0 comments on commit 1f064a5

Please sign in to comment.