~saviq/unity-api/add-shell-notifications-api

« back to all changes in this revision

Viewing changes to test/mocks/plugins/Unity/Notifications/Mocks/mocksource.cpp

  • Committer: Michał Sawicz
  • Date: 2013-05-13 15:27:42 UTC
  • Revision ID: michal.sawicz@canonical.com-20130513152742-dciqjztw8pnqc8lk
add mock Notifications implementation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authors:
 
17
 *      Michał Sawicz <michal.sawicz@canonical.com>
 
18
 */
 
19
 
 
20
 
 
21
#include <Mocks/mocksource.h>
 
22
 
 
23
#include <Mocks/mockmodel.h>
 
24
#include <Mocks/mocknotification.h>
 
25
 
 
26
#include <unity/shell/notifications/notification.h>
 
27
 
 
28
using namespace unity::shell::notifications;
 
29
 
 
30
MockSource::MockSource(QObject *parent)
 
31
    : SourceInterface(parent)
 
32
    , m_model(0)
 
33
{
 
34
}
 
35
 
 
36
ModelInterface*
 
37
MockSource::model() const
 
38
{
 
39
    return m_model;
 
40
}
 
41
 
 
42
void
 
43
MockSource::setModel(ModelInterface* model)
 
44
{
 
45
    MockModel* mockModel = qobject_cast<MockModel*>(model);
 
46
    if (m_model != mockModel) {
 
47
        m_model = mockModel;
 
48
        Q_EMIT modelChanged(m_model);
 
49
    }
 
50
}
 
51
 
 
52
void
 
53
MockSource::send(QVariantMap data)
 
54
{
 
55
    MockNotification* notification = new MockNotification(this);
 
56
    notification->m_data = data;
 
57
 
 
58
    connect(notification, SIGNAL(completed()), SLOT(onCompleted()));
 
59
 
 
60
    if(m_model) {
 
61
        m_model->add(notification);
 
62
    }
 
63
}
 
64
 
 
65
void
 
66
MockSource::onCompleted()
 
67
{
 
68
    sender()->deleteLater();
 
69
}