~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to tests/system/qmlorganizer/organizer.qml

  • Committer: chris.gagnon
  • Date: 2013-12-10 23:09:37 UTC
  • Revision ID: chris.gagnon@canonical.com-20131210230937-2akf1ft1edcttk87
first post

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the examples of the Qt Mobility Components.
 
7
**
 
8
** $QT_BEGIN_LICENSE:BSD$
 
9
** You may use this file under the terms of the BSD license as follows:
 
10
**
 
11
** "Redistribution and use in source and binary forms, with or without
 
12
** modification, are permitted provided that the following conditions are
 
13
** met:
 
14
**   * Redistributions of source code must retain the above copyright
 
15
**     notice, this list of conditions and the following disclaimer.
 
16
**   * Redistributions in binary form must reproduce the above copyright
 
17
**     notice, this list of conditions and the following disclaimer in
 
18
**     the documentation and/or other materials provided with the
 
19
**     distribution.
 
20
**   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
 
21
**     of its contributors may be used to endorse or promote products derived
 
22
**     from this software without specific prior written permission.
 
23
**
 
24
**
 
25
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
26
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
27
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
28
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
29
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
30
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
31
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
32
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
33
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
34
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
35
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
 
36
**
 
37
** $QT_END_LICENSE$
 
38
**
 
39
****************************************************************************/
 
40
 
 
41
import QtQuick 2.0
 
42
import QtOrganizer 5.0
 
43
import "contents"
 
44
 
 
45
Rectangle {
 
46
         id: calendar
 
47
         width: 400
 
48
         height: 640
 
49
         property date currentDate:new Date()
 
50
         property int year:currentDate.getFullYear()
 
51
         property int month:currentDate.getMonth()
 
52
         property int day:currentDate.getDate()
 
53
         property int hour:currentDate.getHours()
 
54
         property int weekDay:currentDate.getDay()
 
55
         property string status:currentDate.toDateString()
 
56
         property string preState: "MonthView"
 
57
         property alias storageLocationModel: storageLocationModel
 
58
         property alias contentArea : contentArea
 
59
 
 
60
        color: "#343434";
 
61
        Image { source: "contents/images/stripes.png"; fillMode: Image.Tile; anchors.fill: parent; opacity: 1 }
 
62
 
 
63
        state: "MonthView";
 
64
 
 
65
        CollectionFilter {
 
66
            id: modelCollectionFilter
 
67
            ids: {
 
68
                var idList = [];
 
69
                var list = organizer.collections;
 
70
                for (var i = 0; i< list.length; i++) {
 
71
                    idList.push(list[i].collectionId);
 
72
                }
 
73
                return idList;
 
74
            }
 
75
        }
 
76
 
 
77
        DetailFieldFilter {
 
78
            id: todoFilter
 
79
            detail: Detail.ItemType
 
80
            field: Type.FieldType
 
81
            value: Type.Todo
 
82
        }
 
83
 
 
84
        IntersectionFilter {
 
85
            id: intersectionFilter
 
86
            filters: [modelCollectionFilter]
 
87
        }
 
88
 
 
89
        SystemPalette { id: activePalette }
 
90
        property OrganizerModel organizer:OrganizerModel{
 
91
            id: organizer
 
92
            manager:"qtorganizer:jsondb:id=qml"
 
93
            //manager:"qtorganizer:memory:id=qml"
 
94
            startPeriod:'2009-01-01'
 
95
            endPeriod:'2012-12-31'
 
96
            autoUpdate:true
 
97
            filter: intersectionFilter
 
98
            Component.onCompleted : {
 
99
                if (managerName == "memory")
 
100
                    organizer.importItems(Qt.resolvedUrl("contents/test.ics"));
 
101
            }
 
102
            onItemsFetched: {
 
103
                // this is for occurrenceDialog
 
104
                console.log("QML --- ITEMS FETCHED" + fetchedItems[0].displayLabel + fetchedItems[0].itemStartTime);
 
105
                if (fetchedItems.length == 1) {
 
106
                    detailsView.isNewItem = false;
 
107
                    detailsView.item = fetchedItems[0];
 
108
                    calendar.state = "DetailsView";
 
109
                }
 
110
            }
 
111
        }
 
112
 
 
113
        ListModel {
 
114
            id: storageLocationModel
 
115
            ListElement{name: "UserDataStorage"}
 
116
            ListElement{name: "SystemStorage"}
 
117
        }
 
118
 
 
119
        InfoBar {
 
120
            id: infoBar;
 
121
            anchors {
 
122
                left: parent.left; right: parent.right; top: parent.top
 
123
            }
 
124
            height: 20
 
125
        }
 
126
 
 
127
        MenuBar {
 
128
            id: menuBar;
 
129
            anchors {
 
130
                left: parent.left; right: parent.right; top: infoBar.bottom
 
131
            }
 
132
            height: 35; opacity: 0.9
 
133
            info: organizer.error + "\nTotal:" + organizer.itemCount
 
134
        }
 
135
 
 
136
        StatusBar {
 
137
            id: statusBar; status:calendar.status; width: parent.width; height: 35; opacity: 0.9; anchors.bottom: calendar.bottom
 
138
            onLeftClicked: {
 
139
                if (calendar.state == "MonthView") {
 
140
                    calendar.currentDate = new Date(calendar.year, calendar.month - 1, calendar.day);
 
141
                } else if (calendar.state == "WeekView") {
 
142
                    calendar.currentDate = new Date(calendar.year, calendar.month , calendar.day - 7);
 
143
                } else if (calendar.state == "DayView" || calendar.state == "TimelineView") {
 
144
                    calendar.currentDate = new Date(calendar.year, calendar.month , calendar.day - 1);
 
145
                }
 
146
 
 
147
            }
 
148
 
 
149
            //rightClick
 
150
            onRightClicked: {
 
151
                if (calendar.state == "MonthView") {
 
152
                    calendar.currentDate = new Date(calendar.year, calendar.month + 1, calendar.day);
 
153
                } else if (calendar.state == "WeekView") {
 
154
                    calendar.currentDate = new Date(calendar.year, calendar.month , calendar.day + 7);
 
155
                } else if (calendar.state == "DayView" || calendar.state == "TimelineView") {
 
156
                    calendar.currentDate = new Date(calendar.year, calendar.month , calendar.day + 1);
 
157
                }
 
158
            }
 
159
 
 
160
            //add new item clicked
 
161
            onAddClicked : {
 
162
                calendar.preState = calendar.state;
 
163
                if (calendar.state == "SettingsView" && settingsView.state == "CollectionManagerView") {
 
164
                    settingsView.collectionManagerView.addCollection();
 
165
                } else {
 
166
                    calendar.state = "AddNewItemSelectView";
 
167
                }
 
168
            }
 
169
        }
 
170
 
 
171
        states: [
 
172
            State {name: "MonthView"; PropertyChanges { target: monthView; opacity: 1; }},
 
173
            State {name: "TimelineView"; PropertyChanges { target: timelineView; opacity: 1; }},
 
174
            State {name: "WeekView"; PropertyChanges { target: weekView; opacity: 1; }},
 
175
            State {name: "DayView"; PropertyChanges { target: dayView; opacity: 1; }},
 
176
            State {name: "AgenderView"; PropertyChanges { target: agenderView; opacity: 1; }},
 
177
            State {
 
178
                name: "DetailsView";
 
179
                PropertyChanges { target: detailsView; opacity: 1;}
 
180
                PropertyChanges { target: statusBar; opacity: 0; }
 
181
            },
 
182
            State {name: "AddNewItemSelectView"; PropertyChanges { target: addNewItemview; opacity: 0.8; }},
 
183
            State {name: "OccurrenceDialogView"; PropertyChanges { target: occurrenceDialog; opacity: 0.8; }},
 
184
            State {name: "TodoView"; PropertyChanges { target: todoView; opacity: 1; }},
 
185
            State {name: "AttendeeDetailsView"; PropertyChanges { target: attendeeDetailsView; opacity: 1; }},
 
186
            State {name: "SettingsView"; PropertyChanges { target: settingsView; opacity: 1; }}
 
187
        ]
 
188
        transitions: [
 
189
            Transition {
 
190
                NumberAnimation {
 
191
                    properties: "opacity"
 
192
                    easing.type: "Linear"
 
193
                    duration: 10
 
194
                }
 
195
            }
 
196
        ]
 
197
 
 
198
        // some views are based on certain filters
 
199
        onStateChanged: {
 
200
            if (state == "TodoView") {
 
201
                intersectionFilter.filters = [todoFilter, modelCollectionFilter];
 
202
            } else if (intersectionFilter.filters.length != 1) {
 
203
                // No need to change the filter if filter is the same
 
204
                // (Currently changing the filter triggers also a full update.)
 
205
                intersectionFilter.filters = [modelCollectionFilter];
 
206
            }
 
207
        }
 
208
 
 
209
        Item {
 
210
            id: contentArea;
 
211
            anchors.top: menuBar.bottom;
 
212
            anchors.left: calendar.left;
 
213
            anchors.right: calendar.right;
 
214
            anchors.bottom: (statusBar.opacity != 0) ? statusBar.top : statusBar.bottom;
 
215
 
 
216
            MonthView {
 
217
                id: monthView;
 
218
                width: calendar.width;
 
219
                height: calendar.height - menuBar.height - statusBar.height;
 
220
                opacity: 0;
 
221
                month:calendar.month
 
222
                year:calendar.year
 
223
                anchors.fill: contentArea;
 
224
            }
 
225
            TimelineView {
 
226
                id: timelineView;
 
227
                width: calendar.width;
 
228
                height: calendar.height - menuBar.height - statusBar.height;
 
229
                opacity: 0;
 
230
                anchors.fill: contentArea;
 
231
            }
 
232
            WeekView {
 
233
                id: weekView;
 
234
                width: calendar.width;
 
235
                height: calendar.height - menuBar.height - statusBar.height;
 
236
                opacity: 0;
 
237
                anchors.fill: contentArea;
 
238
            }
 
239
            DayView {
 
240
                id: dayView;
 
241
                width: calendar.width;
 
242
                height: calendar.height - menuBar.height - statusBar.height;
 
243
                opacity: 0;
 
244
                anchors.fill: contentArea;
 
245
            }
 
246
 
 
247
            AgenderView {
 
248
                id: agenderView;
 
249
                width: calendar.width;
 
250
                height: calendar.height - menuBar.height - statusBar.height;
 
251
                opacity: 0;
 
252
                anchors.fill: contentArea;
 
253
            }
 
254
            DetailsView {
 
255
                id: detailsView;
 
256
                width: calendar.width;
 
257
                height: calendar.height - menuBar.height - statusBar.height;
 
258
                opacity: 0;
 
259
                anchors.fill: contentArea;
 
260
            }
 
261
            SelectionView {
 
262
                id: addNewItemview;
 
263
                title: "Select type:"
 
264
 
 
265
                model: VisualItemModel {
 
266
                    Button {
 
267
                        text: "New event"
 
268
                        width: addNewItemview.width / 2
 
269
                        onClicked: {
 
270
                            detailsView.isNewItem = true;
 
271
                            detailsView.item = createEmptyItem(Type.Event);
 
272
                            detailsView.item.displayLabel = "Event"+(organizer.itemCount+1)
 
273
                            calendar.state = "DetailsView";
 
274
                        }
 
275
                    }
 
276
                    Button {
 
277
                        text: "New todo-item"
 
278
                        width: addNewItemview.width / 2
 
279
                        onClicked: {
 
280
                            detailsView.isNewItem = true;
 
281
                            detailsView.item = createEmptyItem(Type.Todo);
 
282
                            detailsView.item.displayLabel = "Todo"+(organizer.itemCount+1)
 
283
                            calendar.state = "DetailsView";
 
284
                        }
 
285
                    }
 
286
                    Button {
 
287
                        text: "Cancel"
 
288
                        width: addNewItemview.width / 2
 
289
                        onClicked: {
 
290
                            calendar.state = calendar.preState;
 
291
                        }
 
292
                    }
 
293
 
 
294
                }
 
295
            }
 
296
            SelectionView {
 
297
                id: occurrenceDialog;
 
298
                //title: "This is a recurring item. Open this instance or whole series?"
 
299
                title: "Recurring item"
 
300
 
 
301
                model: VisualItemModel {
 
302
                    Button {
 
303
                        text: "Open this instance"
 
304
                        width: addNewItemview.width / 2
 
305
                        onClicked: {
 
306
                            calendar.state = "DetailsView";
 
307
                        }
 
308
                    }
 
309
                    Button {
 
310
                        text: "Open whole series"
 
311
                        width: addNewItemview.width / 2
 
312
                        onClicked: {
 
313
                            var parentDetail = detailsView.item.detail(Detail.Parent);
 
314
                            organizer.fetchItems([parentDetail.parentId]);
 
315
                        }
 
316
                    }
 
317
                }
 
318
            }
 
319
            TodoView {
 
320
                id: todoView;
 
321
            }
 
322
            AttendeeDetailsView {
 
323
                id: attendeeDetailsView;
 
324
            }
 
325
            SettingsView {
 
326
                id: settingsView;
 
327
            }
 
328
        }
 
329
 
 
330
        function createEmptyItem(type)
 
331
        {
 
332
            if (type == Type.Event) {
 
333
                return Qt.createQmlObject("import QtOrganizer 5.0; Event { }", organizer);
 
334
            } else if (type == Type.Todo) {
 
335
                return Qt.createQmlObject("import QtOrganizer 5.0; Todo { }", organizer);
 
336
    //        } else if (type == Type.EventOccurrence) {
 
337
    //            return Qt.createQmlObject("import QtOrganizer 5.0; EventOccurrence { }", organizer);
 
338
    //        } else if (type == Type.TodoOccurrence) {
 
339
    //            return Qt.createQmlObject("import QtOrganizer 5.0; TodoOccurrence { }", organizer);
 
340
            } else {
 
341
                return Qt.createQmlObject("import QtOrganizer 5.0; Event { }", organizer);
 
342
            }
 
343
        }
 
344
}