~nskaggs/ubuntu-ui-toolkit/sphinx-autopilot-emulator

« back to all changes in this revision

Viewing changes to tests/resources/alarm/Alarms.qml

  • Committer: Tarmac
  • Author(s): Zsombor Egri
  • Date: 2013-08-23 09:05:49 UTC
  • mfrom: (699.2.5 alarm-testapp)
  • Revision ID: tarmac-20130823090549-nutyfyu0g5qo4wfo
AlarmModel got a role named model to solve ambiguous role accessing situations. Test application added.

Approved by Christian Dywan, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2012 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser 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
 
 
17
import QtQuick 2.0
 
18
import Ubuntu.Components 0.1
 
19
import Ubuntu.Components.ListItems 0.1
 
20
import Ubuntu.Components.Popups 0.1
 
21
 
 
22
MainView {
 
23
    id: mainView
 
24
    width: units.gu(40)
 
25
    height: units.gu(71)
 
26
    objectName: "mainView"
 
27
 
 
28
    AlarmModel{
 
29
        id: alarmModel
 
30
    }
 
31
 
 
32
    Alarm {
 
33
        id: alarm
 
34
    }
 
35
 
 
36
    Column {
 
37
        id: layout
 
38
        anchors {
 
39
            left: parent.left
 
40
            top: parent.top
 
41
            right: parent.right
 
42
        }
 
43
        height: childrenRect.height
 
44
 
 
45
        Standard {
 
46
            text: "Label"
 
47
            control: TextField {
 
48
                id: message
 
49
                objectName: "alarm_message"
 
50
                text: alarm.message
 
51
            }
 
52
        }
 
53
        Standard {
 
54
            text: "Date"
 
55
            control: TextField {
 
56
                id: date
 
57
                objectName: "alarm_date"
 
58
                text: alarm.date.toString()
 
59
            }
 
60
        }
 
61
        Standard {
 
62
            text: "Enabled"
 
63
            control: Switch {
 
64
                id: enabled
 
65
                objectName: "alarm_enabled"
 
66
                checked: alarm.enabled
 
67
                onCheckedChanged: {
 
68
                    if (checked != alarm.enabled)
 
69
                        alarm.enabled = checked;
 
70
                }
 
71
            }
 
72
        }
 
73
        ValueSelector {
 
74
            id: recurence
 
75
            text: "Recurence"
 
76
            values: ["OneTime", "Daily", "Weekly"]
 
77
            selectedIndex: {
 
78
                if (alarm.type == Alarm.OneTime)
 
79
                    return 0;
 
80
                else if (alarm.type == Alarm.Repeating) {
 
81
                    if (alarm.daysOfWeek === Alarm.Daily)
 
82
                        return 1;
 
83
                    else
 
84
                        return 2;
 
85
                }
 
86
            }
 
87
            onSelectedIndexChanged: {
 
88
                switch (selectedIndex) {
 
89
                case 0:
 
90
                    alarm.type = Alarm.OneTime;
 
91
                    break;
 
92
                case 1:
 
93
                    alarm.type = Alarm.Repeating;
 
94
                    alarm.daysOfWeek = Alarm.Daily;
 
95
                    break;
 
96
                case 2:
 
97
                    alarm.type = Alarm.Repeating;
 
98
                    break;
 
99
                }
 
100
            }
 
101
        }
 
102
 
 
103
        MultiValue {
 
104
            id: days
 
105
            text: "Occurence"
 
106
            values: getValues()
 
107
            visible: recurence.selectedIndex == 2
 
108
            onClicked: {
 
109
                PopupUtils.open(Qt.resolvedUrl("AlarmDays.qml"), days, {"alarm": alarm});
 
110
            }
 
111
            function getValues() {
 
112
                var v = [];
 
113
                if (alarm.daysOfWeek & Alarm.Monday) v.push("Monday");
 
114
                if (alarm.daysOfWeek & Alarm.Tuesday) v.push("Tuesday");
 
115
                if (alarm.daysOfWeek & Alarm.Wednesday) v.push("Wednesday");
 
116
                if (alarm.daysOfWeek & Alarm.Thursday) v.push("Thursday");
 
117
                if (alarm.daysOfWeek & Alarm.Friday) v.push("Friday");
 
118
                if (alarm.daysOfWeek & Alarm.Saturday) v.push("Saturday");
 
119
                if (alarm.daysOfWeek & Alarm.Sunday) v.push("Sunday");
 
120
                return v;
 
121
            }
 
122
        }
 
123
 
 
124
        Standard {
 
125
            text: "Save result="+alarm.error
 
126
            control: Button {
 
127
                text: "Save"
 
128
                onClicked: {
 
129
                    alarm.message = message.text
 
130
                    alarm.date = new Date(date.text)
 
131
                    alarm.save();
 
132
                    if (alarm.error == Alarm.NoError) alarm.reset();
 
133
                }
 
134
            }
 
135
        }
 
136
        ThinDivider{}
 
137
    }
 
138
 
 
139
    ListView {
 
140
        id: alarmList
 
141
        anchors {
 
142
            fill: parent
 
143
            topMargin: layout.height
 
144
        }
 
145
        clip: true
 
146
        model: alarmModel
 
147
        delegate: Standard {
 
148
            text: message
 
149
            removable: true
 
150
            control: Switch {
 
151
                checked: model.enabled
 
152
                onCheckedChanged: {
 
153
                    if (checked != model.enabled) {
 
154
                        model.enabled = checked;
 
155
                        model.save();
 
156
                    }
 
157
                }
 
158
            }
 
159
            onItemRemoved: {
 
160
                var data = alarmModel.get(index);
 
161
                data.cancel();
 
162
            }
 
163
            onClicked: {
 
164
                var data = alarmModel.get(index);
 
165
                alarm.message = data.message;
 
166
                alarm.date = data.date;
 
167
                alarm.type = data.type;
 
168
                alarm.daysOfWeek = data.daysOfWeek;
 
169
                alarm.enabled = data.enabled;
 
170
            }
 
171
        }
 
172
    }
 
173
}