~ubuntu-filemanager-dev/ubuntu-filemanager-app/nemo-qml-plugins-packaging

« back to all changes in this revision

Viewing changes to alarms/src/alarmsbackendmodel.cpp

  • Committer: Timo Jyrinki
  • Date: 2013-03-20 15:03:31 UTC
  • Revision ID: timo.jyrinki@canonical.com-20130320150331-aggtqfb7cufdiuzc
ImportĀ upstreamĀ 0.3.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 Jolla Ltd.
 
3
 * Contact: John Brooks <john.brooks@jollamobile.com>
 
4
 *
 
5
 * You may use this file under the terms of the BSD license as follows:
 
6
 *
 
7
 * "Redistribution and use in source and binary forms, with or without
 
8
 * modification, are permitted provided that the following conditions are
 
9
 * met:
 
10
 *   * Redistributions of source code must retain the above copyright
 
11
 *     notice, this list of conditions and the following disclaimer.
 
12
 *   * Redistributions in binary form must reproduce the above copyright
 
13
 *     notice, this list of conditions and the following disclaimer in
 
14
 *     the documentation and/or other materials provided with the
 
15
 *     distribution.
 
16
 *   * Neither the name of Nemo Mobile nor the names of its contributors
 
17
 *     may be used to endorse or promote products derived from this
 
18
 *     software without specific prior written permission.
 
19
 *
 
20
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
21
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
22
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
23
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
24
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
25
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
26
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
27
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
28
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
29
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
30
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
 
31
 */
 
32
 
 
33
#include "alarmsbackendmodel.h"
 
34
#include "alarmsbackendmodel_p.h"
 
35
#include "alarmobject.h"
 
36
 
 
37
AlarmsBackendModel::AlarmsBackendModel(QObject *parent)
 
38
    : QAbstractListModel(parent)
 
39
{
 
40
    QHash<int,QByteArray> roles;
 
41
    roles[Qt::DisplayRole] = "title";
 
42
    roles[AlarmObjectRole] = "alarm";
 
43
    roles[EnabledRole] = "enabled";
 
44
    roles[HourRole] = "hour";
 
45
    roles[MinuteRole] = "minute";
 
46
    roles[WeekDaysRole] = "daysOfWeek";
 
47
    setRoleNames(roles);
 
48
 
 
49
    priv = new AlarmsBackendModelPriv(this);
 
50
}
 
51
 
 
52
AlarmsBackendModel::~AlarmsBackendModel()
 
53
{
 
54
}
 
55
 
 
56
AlarmObject *AlarmsBackendModel::createAlarm()
 
57
{
 
58
    AlarmObject *alarm = new AlarmObject(this);
 
59
    connect(alarm, SIGNAL(updated()), priv, SLOT(alarmUpdated()));
 
60
    connect(alarm, SIGNAL(deleted()), priv, SLOT(alarmDeleted()));
 
61
    return alarm;
 
62
}
 
63
 
 
64
bool AlarmsBackendModel::isPopulated() const
 
65
{
 
66
    return priv->populated;
 
67
}
 
68
 
 
69
int AlarmsBackendModel::rowCount(const QModelIndex &parent) const
 
70
{
 
71
    if (parent.isValid())
 
72
        return 0;
 
73
    return priv->alarms.size();
 
74
}
 
75
 
 
76
QVariant AlarmsBackendModel::data(const QModelIndex &index, int role) const
 
77
{
 
78
    if (!index.isValid() || index.row() < 0 || index.row() >= priv->alarms.size())
 
79
        return QVariant();
 
80
 
 
81
    AlarmObject *alarm = priv->alarms[index.row()];
 
82
 
 
83
    switch (role) {
 
84
        case Qt::DisplayRole: return alarm->title();
 
85
        case AlarmObjectRole: return QVariant::fromValue<QObject*>(alarm);
 
86
        case EnabledRole: return alarm->isEnabled();
 
87
        case HourRole: return alarm->hour();
 
88
        case MinuteRole: return alarm->minute();
 
89
        case WeekDaysRole: return alarm->daysOfWeek();
 
90
    }
 
91
 
 
92
    return QVariant();
 
93
}
 
94