Skip to content

Commit

Permalink
Changes: Reverting part of the system notification fix. Disk space no…
Browse files Browse the repository at this point in the history
…tifications are not system notifications.

RevBy: TrustMe
  • Loading branch information
Vesa Halttunen committed Jul 7, 2011
1 parent f0d4e6c commit a4f4d2a
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 16 deletions.
26 changes: 22 additions & 4 deletions src/systemui/diskspacenotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,25 @@
#include <MNotification>
#include "diskspacenotifier.h"

DiskSpaceNotifier::DiskSpaceNotifier(QObject *parent) : QObject(parent)
DiskSpaceNotifier::DiskSpaceNotifier(QObject *parent) : QObject(parent),
notification(NULL)
{
QDBusConnection::systemBus().connect(QString(), "/com/nokia/diskmonitor/signal", "com.nokia.diskmonitor.signal", "disk_space_change_ind", this, SLOT(handleDiskSpaceChange(QString, int)));

// Destroy any previous disk space notifications
foreach (MNotification *notification, MNotification::notifications()) {
if (notification->eventType() == "x-nokia.system-memusage") {
notification->remove();
}
delete notification;
}
}

DiskSpaceNotifier::~DiskSpaceNotifier()
{
if (notification != NULL) {
delete notification;
}
}

void DiskSpaceNotifier::handleDiskSpaceChange(const QString &path, int percentage)
Expand All @@ -49,10 +61,16 @@ void DiskSpaceNotifier::handleDiskSpaceChange(const QString &path, int percentag
}

if (notificationShouldBeVisible) {
if (notification != NULL) {
// Destroy any previous notification
notification->remove();
delete notification;
}

// Show a notification
//% "Getting low with storage. Please check."
MNotification notification("x-nokia.system-memusage", "", qtTrId("qtn_memu_memlow_notification_src"));
notification.setAction(MRemoteAction("com.nokia.DuiControlPanel", "/", "com.nokia.DuiControlPanelIf", "appletPage", QList<QVariant>() << "Mass Storage Usage"));
notification.publish();
notification = new MNotification("x-nokia.system-memusage", "", qtTrId("qtn_memu_memlow_notification_src"));
notification->setAction(MRemoteAction("com.nokia.DuiControlPanel", "/", "com.nokia.DuiControlPanelIf", "appletPage", QList<QVariant>() << "Mass Storage Usage"));
notification->publish();
}
}
5 changes: 5 additions & 0 deletions src/systemui/diskspacenotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <QMap>
#include <QPair>

class MNotification;

/*!
* Disk space notifier sends disk space notifications when the disk is full.
*/
Expand Down Expand Up @@ -55,6 +57,9 @@ private slots:
//! Notifications sent for each path. The first bool in the pair is whether the threshold notification was sent, second whether the 100% notification was sent.
QMap<QString, QPair<bool, bool> > notificationsSentForPath;

//! The disk space notification
MNotification *notification;

#ifdef UNIT_TEST
friend class Ut_DiskSpaceNotifier;
#endif
Expand Down
91 changes: 79 additions & 12 deletions tests/ut_diskspacenotifier/ut_diskspacenotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,50 @@ bool QDBusConnection::connect(const QString &service, const QString &path, const
return true;
}

int mNotificationsPublished = 0;
int mNotificationsCreated = 0;
MNotification::MNotification(const QString &, const QString &, const QString &)
{
mNotificationsCreated++;
}

int mNotificationsDestroyed = 0;
MNotification::~MNotification()
{
mNotificationsDestroyed++;
}

void MNotification::setAction(const MRemoteAction &)
{
}

int mNotificationsRemoved = 0;
bool MNotification::remove()
{
mNotificationsRemoved++;
return true;
}

bool MNotification::publish()
{
mNotificationsPublished++;
return true;
}

QString mNotificationEventType;
QString MNotification::eventType() const
{
return mNotificationEventType;
}

int mNotificationNotificationsCount = 0;
QList<MNotification *> MNotification::notifications()
{
QList<MNotification *> notifications;
for (int i = 0; i < mNotificationNotificationsCount; i++) {
notifications << new MNotification("", "", "");
}
return notifications;
}

void Ut_DiskSpaceNotifier::initTestCase()
{
}
Expand All @@ -69,7 +106,10 @@ void Ut_DiskSpaceNotifier::cleanup()
qDBusConnectionConnectName.clear();
qDBusConnectionConnectReceiver = NULL;
qDBusConnectionConnectSlot.clear();
mNotificationsPublished = 0;
mNotificationsCreated = 0;
mNotificationsDestroyed = 0;
mNotificationsRemoved = 0;
mNotificationNotificationsCount = 0;
}

void Ut_DiskSpaceNotifier::testSystemBusConnection()
Expand All @@ -88,13 +128,14 @@ void Ut_DiskSpaceNotifier::testNotifications_data()
QTest::addColumn<int>("diskSpaceChangePercentage1");
QTest::addColumn<QString>("diskSpaceChangePath2");
QTest::addColumn<int>("diskSpaceChangePercentage2");
QTest::addColumn<int>("notificationsPublished");

QTest::newRow("Disk space of / reached threshold but not 100%") << "/" << 90 << "/" << 99 << 1;
QTest::newRow("Disk space of / reached threshold and then 100%") << "/" << 90 << "/" << 100 << 2;
QTest::newRow("Disk space of / reached 100% twice") << "/" << 100 << "/" << 100 << 1;
QTest::newRow("Disk space of / and /home reached threshold") << "/" << 90 << "/home" << 90 << 2;
QTest::newRow("Disk space of /home and /home/user/MyDocs reached 100%") << "/home" << 100 << "/home/user/MyDocs" << 100 << 2;
QTest::addColumn<int>("notificationsCreated");
QTest::addColumn<int>("notificationsDestroyed");

QTest::newRow("Disk space of / reached threshold but not 100%") << "/" << 90 << "/" << 99 << 1 << 0;
QTest::newRow("Disk space of / reached threshold and then 100%") << "/" << 90 << "/" << 100 << 2 << 1;
QTest::newRow("Disk space of / reached 100% twice") << "/" << 100 << "/" << 100 << 1 << 0;
QTest::newRow("Disk space of / and /home reached threshold") << "/" << 90 << "/home" << 90 << 2 << 1;
QTest::newRow("Disk space of /home and /home/user/MyDocs reached 100%") << "/home" << 100 << "/home/user/MyDocs" << 100 << 2 << 1;
}

void Ut_DiskSpaceNotifier::testNotifications()
Expand All @@ -103,12 +144,36 @@ void Ut_DiskSpaceNotifier::testNotifications()
QFETCH(int, diskSpaceChangePercentage1);
QFETCH(QString, diskSpaceChangePath2);
QFETCH(int, diskSpaceChangePercentage2);
QFETCH(int, notificationsPublished);
QFETCH(int, notificationsCreated);
QFETCH(int, notificationsDestroyed);

m_subject->handleDiskSpaceChange(diskSpaceChangePath1, diskSpaceChangePercentage1);
m_subject->handleDiskSpaceChange(diskSpaceChangePath2, diskSpaceChangePercentage2);

QCOMPARE(mNotificationsPublished, notificationsPublished);
QCOMPARE(mNotificationsCreated, notificationsCreated);
QCOMPARE(mNotificationsRemoved, notificationsDestroyed);
QCOMPARE(mNotificationsDestroyed, notificationsDestroyed);
}

void Ut_DiskSpaceNotifier::testConstruction()
{
delete m_subject;

// Check that the constructor destroys only any previous notifications of type x-nokia.system-memusage
mNotificationNotificationsCount = 5;
m_subject = new DiskSpaceNotifier();
QCOMPARE(mNotificationsCreated, mNotificationNotificationsCount);
QCOMPARE(mNotificationsRemoved, 0);
QCOMPARE(mNotificationsDestroyed, mNotificationNotificationsCount);
delete m_subject;

mNotificationsCreated = 0;
mNotificationsDestroyed = 0;
mNotificationEventType = "x-nokia.system-memusage";
m_subject = new DiskSpaceNotifier();
QCOMPARE(mNotificationsCreated, mNotificationNotificationsCount);
QCOMPARE(mNotificationsRemoved, mNotificationNotificationsCount);
QCOMPARE(mNotificationsDestroyed, mNotificationNotificationsCount);
}

void Ut_DiskSpaceNotifier::testDestruction()
Expand All @@ -117,6 +182,8 @@ void Ut_DiskSpaceNotifier::testDestruction()

delete m_subject;
m_subject = NULL;

QCOMPARE(mNotificationsDestroyed, mNotificationsCreated);
}

QTEST_APPLESS_MAIN(Ut_DiskSpaceNotifier)
1 change: 1 addition & 0 deletions tests/ut_diskspacenotifier/ut_diskspacenotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private slots:
void testSystemBusConnection();
void testNotifications_data();
void testNotifications();
void testConstruction();
void testDestruction();

private:
Expand Down

0 comments on commit a4f4d2a

Please sign in to comment.