~pkunal-parmar/ubuntu-calendar-app/ICalImport

400.1.1 by mihirsoni-123
Added copyright header comments in all the pages
1
/*
400.1.2 by mihirsoni-123
updated copyright year
2
 * Copyright (C) 2013-2014 Canonical Ltd
400.1.1 by mihirsoni-123
Added copyright header comments in all the pages
3
 *
4
 * This file is part of Ubuntu Calendar App
5
 *
6
 * Ubuntu Calendar App is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License version 3 as
8
 * published by the Free Software Foundation.
9
 *
10
 * Ubuntu Calendar App is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
279.1.1 by Kunal Parmar
Agenda view created
18
import QtQuick 2.0
19
import Ubuntu.Components 0.1
20
import QtOrganizer 5.0
21
22
import "dateExt.js" as DateExt
23
24
Page{
25
    id: root
26
    objectName: "AgendaView"
27
28
    property var currentDay: new Date()
29
416.1.1 by Kunal Parmar
Agenda view to dayView
30
    signal dateSelected(var date);
31
279.1.1 by Kunal Parmar
Agenda view created
32
    Keys.forwardTo: [eventList]
33
279.1.2 by Kunal Parmar
review comment
34
    function goToBeginning() {
35
        eventList.positionViewAtBeginning();
36
    }
37
415.1.2 by twstddev
Change according to the 'Needs fixing'
38
    function hasEnabledCalendars() {
39
        var enabled_calendars = eventListModel.getCollections().filter( function( item ) {
40
            return item.extendedMetaData( "collection-selected" );
41
        } );
42
43
        return !!enabled_calendars.length;
44
    }
45
279.1.1 by Kunal Parmar
Agenda view created
46
    EventListModel {
212.4.25 by Kunal Parmar
merge from trunk
47
        id: eventListModel
279.1.1 by Kunal Parmar
Agenda view created
48
        startPeriod: currentDay.midnight();
49
        endPeriod: currentDay.addDays(30).endOfDay()
212.4.25 by Kunal Parmar
merge from trunk
50
        filter: eventModel.filter
311.1.1 by Kunal Parmar
Setting sort order
51
311.1.7 by Kunal Parmar
Formatting corrected
52
        sortOrders: [
53
            SortOrder{
54
                blankPolicy: SortOrder.BlanksFirst
55
                detail: Detail.EventTime
56
                field: EventTime.FieldStartDateTime
57
                direction: Qt.AscendingOrder
58
            }
59
        ]
279.1.1 by Kunal Parmar
Agenda view created
60
    }
61
62
    ActivityIndicator {
63
        visible: running
212.4.25 by Kunal Parmar
merge from trunk
64
        running: eventListModel.isLoading
279.1.1 by Kunal Parmar
Agenda view created
65
        anchors.centerIn: parent
66
        z:2
67
    }
68
415.1.2 by twstddev
Change according to the 'Needs fixing'
69
    Label {
415.1.3 by twstddev
Change button label and label component behaviour
70
        id: noEventsOrCalendarsLabel
71
        text: {
72
            var default_title = i18n.tr( "No upcoming events" );
73
74
            if ( !root.hasEnabledCalendars() ) {
75
                default_title = i18n.tr("You have no calendars enabled")
76
            }
77
78
            return default_title;
79
        }
80
        visible: !root.hasEnabledCalendars() || !eventListModel.itemCount
279.1.1 by Kunal Parmar
Agenda view created
81
        anchors.centerIn: parent
82
    }
83
415.1.1 by twstddev
A fix for bug #1359323
84
    Button {
415.1.3 by twstddev
Change button label and label component behaviour
85
        text: i18n.tr( "Enbale calendars" )
415.1.2 by twstddev
Change according to the 'Needs fixing'
86
        visible: !root.hasEnabledCalendars()
415.1.3 by twstddev
Change button label and label component behaviour
87
        anchors.top: noEventsOrCalendarsLabel.bottom
88
        anchors.horizontalCenter: noEventsOrCalendarsLabel.horizontalCenter
415.1.4 by twstddev
Replace hardcoded margin value with responsive unit
89
        anchors.topMargin: units.gu( 1.5 )
415.1.1 by twstddev
A fix for bug #1359323
90
        color: UbuntuColors.orange
91
92
        onClicked: {
93
            pageStack.push(Qt.resolvedUrl("CalendarChoicePopup.qml"),{"model":eventModel});
94
            pageStack.currentPage.collectionUpdated.connect(eventModel.delayedApplyFilter);
95
        }
96
    }
97
279.1.1 by Kunal Parmar
Agenda view created
98
    ListView{
99
        id: eventList
212.4.25 by Kunal Parmar
merge from trunk
100
        model: eventListModel
279.1.1 by Kunal Parmar
Agenda view created
101
        anchors.fill: parent
212.4.25 by Kunal Parmar
merge from trunk
102
        visible: eventListModel.itemCount > 0
279.1.1 by Kunal Parmar
Agenda view created
103
104
        delegate: listDelegate
105
    }
106
107
    Scrollbar{
108
        flickableItem: eventList
109
        align: Qt.AlignTrailing
110
    }
111
112
    Component{
113
        id: listDelegate
114
115
        Item {
116
            id: root
212.4.25 by Kunal Parmar
merge from trunk
117
            property var event: eventListModel.items[index];
279.1.1 by Kunal Parmar
Agenda view created
118
119
            width: parent.width
120
            height: container.height
121
122
            onEventChanged: {
123
                setDetails();
124
            }
125
126
            function setDetails() {
127
                if(event === null || event === undefined) {
128
                    return;
129
                }
130
131
                headerContainer.visible = false;
132
                if( index == 0 ) {
133
                    headerContainer.visible = true;
134
                } else {
212.4.25 by Kunal Parmar
merge from trunk
135
                    var prevEvent = eventListModel.items[index-1];
279.1.1 by Kunal Parmar
Agenda view created
136
                    if( prevEvent.startDateTime.midnight() < event.startDateTime.midnight()) {
137
                        headerContainer.visible = true;
138
                    }
139
                }
140
141
                // TRANSLATORS: this is a time formatting string,
142
                // see http://qt-project.org/doc/qt-5/qml-qtqml-date.html#details for valid expressions
143
                var timeFormat = i18n.tr("hh:mm");
144
                var dateFormat = i18n.tr("dddd , d MMMM");
145
                var date = event.startDateTime.toLocaleString(Qt.locale(),dateFormat);
146
                var startTime = event.startDateTime.toLocaleTimeString(Qt.locale(), timeFormat)
147
                var endTime = event.endDateTime.toLocaleTimeString(Qt.locale(), timeFormat)
148
317.1.1 by Anthony Wong
Fix typos in translator comment
149
                // TRANSLATORS: the first argument (%1) refers to a start time for an event,
150
                // while the second one (%2) refers to the end time
279.1.1 by Kunal Parmar
Agenda view created
151
                var timeString = i18n.tr("%1 - %2").arg(startTime).arg(endTime)
152
153
                header.text = date
154
                timeLabel.text = timeString
155
156
                if( event.displayLabel) {
157
                    titleLabel.text = event.displayLabel;
158
                }
159
            }
160
161
            Column {
162
                id: container
163
164
                width: parent.width
165
                height: detailsContainer.height + headerContainer.height +
166
                        (headerContainer.visible ? units.gu(2) : units.gu(0.5))
167
168
                spacing: headerContainer.visible ? units.gu(1) : 0
169
170
                anchors.top: parent.top
171
                anchors.topMargin: headerContainer.visible ? units.gu(1.5) : units.gu(1)
172
173
                DayHeaderBackground{
174
                    id: headerContainer
175
                    height: visible ? header.height + units.gu(1) : 0
176
                    width: parent.width
177
                    Label{
178
                        id: header
179
                        width: parent.height
180
                        anchors.verticalCenter: parent.verticalCenter
181
                        anchors.left: parent.left
182
                        anchors.leftMargin: units.gu(1)
183
                        color: "white"
184
                    }
416.1.1 by Kunal Parmar
Agenda view to dayView
185
186
                    MouseArea{
187
                        anchors.fill: parent
188
                        onClicked: {
189
                            dateSelected(event.startDateTime);
190
                        }
191
                    }
279.1.1 by Kunal Parmar
Agenda view created
192
                }
193
194
                UbuntuShape{
195
                    id: detailsContainer
422.4.1 by twstddev
A fix for bug #1360314
196
                    color: backgroundColor
197
279.1.1 by Kunal Parmar
Agenda view created
198
                    anchors.horizontalCenter: parent.horizontalCenter
199
                    width: parent.width - units.gu(4)
200
                    height: detailsColumn.height + units.gu(1)
201
422.4.2 by twstddev
Refactor highlight functionality to a state and pressed/release signals
202
                    states: [
203
                        State {
204
                            name: "selected"
205
206
                            PropertyChanges {
207
                                target: detailsContainer
208
                                color: UbuntuColors.orange
209
                            }
210
211
                            PropertyChanges {
212
                                target: timeLabel
213
                                color: "white"
214
                            }
215
                        }
216
217
                    ]
422.4.1 by twstddev
A fix for bug #1360314
218
422.4.3 by twstddev
Add animation to color change
219
                    Behavior on color {
220
                        ColorAnimation {
221
                            duration: 50
222
                        }
223
                    }
224
279.1.1 by Kunal Parmar
Agenda view created
225
                    Column{
226
                        id: detailsColumn
227
228
                        anchors.left: parent.left
229
                        anchors.right: parent.right
230
                        anchors.top: parent.top
231
                        anchors.margins: units.gu(0.5)
232
233
                        spacing: units.gu(0.5)
234
235
                        Row{
236
                            width: parent.width
237
                            Label{
238
                                id: timeLabel
239
                                color:"gray"
240
                                width: parent.width - rect.width
241
                            }
242
                            Rectangle{
243
                                id:rect
244
                                width: units.gu(1)
245
                                radius: width/2
246
                                height: width
247
                                color: "#715772"
248
                            }
249
                        }
250
                        Label{
251
                            id: titleLabel
252
                            color:"black"
253
                            wrapMode: Text.WrapAtWordBoundaryOrAnywhere
254
                            width: parent.width
422.4.3 by twstddev
Add animation to color change
255
256
                            Behavior on color {
257
                                ColorAnimation {
258
                                    duration: 50
259
                                }
260
                            }
279.1.1 by Kunal Parmar
Agenda view created
261
                        }
262
                    }
263
264
                    MouseArea{
265
                        anchors.fill: parent
266
                        onClicked: {
422.4.2 by twstddev
Refactor highlight functionality to a state and pressed/release signals
267
                            pageStack.push(Qt.resolvedUrl("EventDetails.qml"), {"event":event,"model":eventListModel});
268
                        }
269
270
                        onPressed: {
271
                            parent.state = "selected"
272
                        }
273
274
                        onReleased: {
275
                            parent.state = ""
279.1.1 by Kunal Parmar
Agenda view created
276
                        }
277
                    }
278
                }
279
            }
280
        }
281
    }
282
}