Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[lipstick] Only play notification feedbacks when the associated previ…
…ews are shown
  • Loading branch information
Vesa Halttunen committed Aug 26, 2013
1 parent 5955059 commit bc0c66a
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 47 deletions.
3 changes: 1 addition & 2 deletions src/homeapplication.cpp
Expand Up @@ -82,8 +82,7 @@ HomeApplication::HomeApplication(int &argc, char **argv, const QString &qmlPath)

// Initialize the notification manager
NotificationManager::instance();
new NotificationPreviewPresenter(this);
new NotificationFeedbackPlayer(this);
new NotificationFeedbackPlayer(new NotificationPreviewPresenter(this));

// Create screen lock logic - not parented to "this" since destruction happens too late in that case
screenLock = new ScreenLock;
Expand Down
12 changes: 7 additions & 5 deletions src/notifications/notificationfeedbackplayer.cpp
Expand Up @@ -15,9 +15,10 @@

#include <NgfClient>
#include <QWaylandSurface>
#include "lipstickcompositor.h"
#include "notificationmanager.h"
#include "notificationpreviewpresenter.h"
#include "notificationfeedbackplayer.h"
#include "lipstickcompositor.h"

enum PreviewMode {
AllNotificationsEnabled = 0,
Expand All @@ -26,11 +27,12 @@ enum PreviewMode {
AllNotificationsDisabled
};

NotificationFeedbackPlayer::NotificationFeedbackPlayer(QObject *parent) :
QObject(parent),
ngfClient(new Ngf::Client(this))
NotificationFeedbackPlayer::NotificationFeedbackPlayer(NotificationPreviewPresenter *notificationPreviewPresenter) :
QObject(notificationPreviewPresenter),
ngfClient(new Ngf::Client(this)),
notificationPreviewPresenter(notificationPreviewPresenter)
{
connect(NotificationManager::instance(), SIGNAL(notificationModified(uint)), this, SLOT(addNotification(uint)));
connect(notificationPreviewPresenter, SIGNAL(notificationPresented(uint)), this, SLOT(addNotification(uint)));
connect(NotificationManager::instance(), SIGNAL(notificationRemoved(uint)), this, SLOT(removeNotification(uint)));

QTimer::singleShot(0, this, SLOT(init()));
Expand Down
6 changes: 5 additions & 1 deletion src/notifications/notificationfeedbackplayer.h
Expand Up @@ -20,6 +20,7 @@
#include <QHash>

class LipstickNotification;
class NotificationPreviewPresenter;
namespace Ngf {
class Client;
}
Expand All @@ -34,7 +35,7 @@ class NotificationFeedbackPlayer : public QObject
Q_OBJECT

public:
explicit NotificationFeedbackPlayer(QObject *parent = 0);
explicit NotificationFeedbackPlayer(NotificationPreviewPresenter *notificationPreviewPresenter = 0);

private slots:
//! Initializes the feedback player
Expand Down Expand Up @@ -64,6 +65,9 @@ private slots:
//! A mapping between notification IDs and NGF play IDs.
QHash<LipstickNotification *, uint> idToEventId;

//! The notification preview presenter this feedback player is synced to
NotificationPreviewPresenter *notificationPreviewPresenter;

#ifdef UNIT_TEST
friend class Ut_NotificationFeedbackPlayer;
#endif
Expand Down
10 changes: 8 additions & 2 deletions src/notifications/notificationpreviewpresenter.cpp
Expand Up @@ -63,9 +63,11 @@ void NotificationPreviewPresenter::showNextNotification()

setCurrentNotification(0);
} else {
LipstickNotification *notification = notificationQueue.takeFirst();

if (locks->getState(MeeGo::QmLocks::TouchAndKeyboard) == MeeGo::QmLocks::Locked && displayState->get() == MeeGo::QmDisplayState::Off) {
// Screen locked and off: don't show the notification but just remove it from the queue
notificationQueue.removeFirst();
emit notificationPresented(notification->property("id").toUInt());

setCurrentNotification(0);

Expand All @@ -77,7 +79,9 @@ void NotificationPreviewPresenter::showNextNotification()
window->show();
}

setCurrentNotification(notificationQueue.takeFirst());
emit notificationPresented(notification->property("id").toUInt());

setCurrentNotification(notification);
}
}
}
Expand Down Expand Up @@ -105,6 +109,8 @@ void NotificationPreviewPresenter::updateNotification(uint id)
}
} else {
// Remove updated notification only from the queue so that a currently visible notification won't suddenly disappear
emit notificationPresented(id);

removeNotification(id, true);

if (currentNotification != notification && notification->hints().value(NotificationManager::HINT_URGENCY).toInt() >= 2) {
Expand Down
3 changes: 3 additions & 0 deletions src/notifications/notificationpreviewpresenter.h
Expand Up @@ -65,6 +65,9 @@ class LIPSTICK_EXPORT NotificationPreviewPresenter : public QObject
//! Sent when the notification to be shown has changed.
void notificationChanged();

//! Sent when a notification is considered presented by the presenter
void notificationPresented(uint id);

public slots:
/*!
* Shows the next notification to be shown, if any. If the notification
Expand Down
83 changes: 83 additions & 0 deletions tests/stubs/notificationpreviewpresenter_stub.h
@@ -0,0 +1,83 @@
#ifndef NOTIFICATIONPREVIEWPRESENTER_STUB
#define NOTIFICATIONPREVIEWPRESENTER_STUB

#include "notificationpreviewpresenter.h"
#include <stubbase.h>


// 1. DECLARE STUB
// FIXME - stubgen is not yet finished
class NotificationPreviewPresenterStub : public StubBase {
public:
virtual void NotificationPreviewPresenterConstructor(QObject *parent);
virtual void NotificationPreviewPresenterDestructor();
virtual LipstickNotification * notification() const;
virtual void showNextNotification();
virtual void updateNotification(uint id);
virtual void removeNotification(uint id, bool onlyFromQueue);
};

// 2. IMPLEMENT STUB
void NotificationPreviewPresenterStub::NotificationPreviewPresenterConstructor(QObject *parent) {
Q_UNUSED(parent);

}
void NotificationPreviewPresenterStub::NotificationPreviewPresenterDestructor() {

}
LipstickNotification * NotificationPreviewPresenterStub::notification() const {
stubMethodEntered("notification");
return stubReturnValue<LipstickNotification *>("notification");
}

void NotificationPreviewPresenterStub::showNextNotification() {
stubMethodEntered("showNextNotification");
}

void NotificationPreviewPresenterStub::updateNotification(uint id) {
QList<ParameterBase*> params;
params.append( new Parameter<uint >(id));
stubMethodEntered("updateNotification",params);
}

void NotificationPreviewPresenterStub::removeNotification(uint id, bool onlyFromQueue) {
QList<ParameterBase*> params;
params.append( new Parameter<uint >(id));
params.append( new Parameter<bool >(onlyFromQueue));
stubMethodEntered("removeNotification",params);
}



// 3. CREATE A STUB INSTANCE
NotificationPreviewPresenterStub gDefaultNotificationPreviewPresenterStub;
NotificationPreviewPresenterStub* gNotificationPreviewPresenterStub = &gDefaultNotificationPreviewPresenterStub;


// 4. CREATE A PROXY WHICH CALLS THE STUB
NotificationPreviewPresenter::NotificationPreviewPresenter(QObject *parent) {
gNotificationPreviewPresenterStub->NotificationPreviewPresenterConstructor(parent);
}

NotificationPreviewPresenter::~NotificationPreviewPresenter() {
gNotificationPreviewPresenterStub->NotificationPreviewPresenterDestructor();
}

LipstickNotification * NotificationPreviewPresenter::notification() const {
return gNotificationPreviewPresenterStub->notification();
}

void NotificationPreviewPresenter::showNextNotification() {
gNotificationPreviewPresenterStub->showNextNotification();
}

void NotificationPreviewPresenter::updateNotification(uint id) {
gNotificationPreviewPresenterStub->updateNotification(id);
}

void NotificationPreviewPresenter::removeNotification(uint id, bool onlyFromQueue) {
gNotificationPreviewPresenterStub->removeNotification(id, onlyFromQueue);
}


#endif
Expand Up @@ -16,6 +16,7 @@
#include <QtTest/QtTest>
#include "notificationmanager.h"
#include "notificationfeedbackplayer.h"
#include "notificationpreviewpresenter_stub.h"
#include "lipstickcompositor_stub.h"
#include "ngfclient_stub.h"
#include "ut_notificationfeedbackplayer.h"
Expand Down Expand Up @@ -87,6 +88,7 @@ LipstickNotification *createNotification(uint id, int urgency = 0)
hints.insert(NotificationManager::HINT_URGENCY, urgency);
notification->setHints(hints);
notificationManagerNotification.insert(id, notification);
gNotificationPreviewPresenterStub->stubSetReturnValue("notification", notification);
return notification;
}

Expand All @@ -113,14 +115,17 @@ void Ut_NotificationFeedbackPlayer::initTestCase()

void Ut_NotificationFeedbackPlayer::init()
{
player = new NotificationFeedbackPlayer;
presenter = new NotificationPreviewPresenter();
player = new NotificationFeedbackPlayer(presenter);
}

void Ut_NotificationFeedbackPlayer::cleanup()
{
delete player;
delete presenter;

gClientStub->stubReset();
gNotificationPreviewPresenterStub->stubReset();
}

void Ut_NotificationFeedbackPlayer::testAddAndRemoveNotification()
Expand Down Expand Up @@ -181,7 +186,7 @@ void Ut_NotificationFeedbackPlayer::testUpdateNotificationIsNotPossibleAfterRest

// Create a notification
createNotification(1);
player = new NotificationFeedbackPlayer;
player = new NotificationFeedbackPlayer(presenter);

// Update the notification
player->addNotification(1);
Expand Down
Expand Up @@ -19,6 +19,7 @@
#include <QObject>

class NotificationFeedbackPlayer;
class NotificationPreviewPresenter;

class Ut_NotificationFeedbackPlayer : public QObject
{
Expand All @@ -42,6 +43,7 @@ private slots:

private:
NotificationFeedbackPlayer *player;
NotificationPreviewPresenter *presenter;
};

#endif // UT_NOTIFICATIONFEEDBACKPLAYER_H_
Expand Up @@ -8,6 +8,7 @@ DEFINES += QT_COMPOSITOR_QUICK
HEADERS += \
ut_notificationfeedbackplayer.h \
$$NOTIFICATIONSRCDIR/notificationfeedbackplayer.h \
$$NOTIFICATIONSRCDIR/notificationpreviewpresenter.h \
$$NOTIFICATIONSRCDIR/notificationmanager.h \
$$NOTIFICATIONSRCDIR/lipsticknotification.h \
$$COMPOSITORSRCDIR/lipstickcompositor.h \
Expand Down

0 comments on commit bc0c66a

Please sign in to comment.