2
* Copyright (C) 2013-2014 Canonical Ltd
4
* This file is part of Ubuntu Calendar App
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.
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.
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/>.
19
import Ubuntu.Components 1.1
20
import Ubuntu.Components.Popups 1.0
21
import QtOrganizer 5.0
22
import Ubuntu.SyncMonitor 0.1
2
import Ubuntu.Components 0.1
3
import Ubuntu.Components.Popups 0.1
24
5
import "dateExt.js" as DateExt
6
import "GlobalEventModel.js" as GlobalModel
28
useDeprecatedToolbar: false
30
// Work-around until this branch lands:
31
// https://code.launchpad.net/~tpeeters/ubuntu-ui-toolkit/optIn-tabsDrawer/+merge/212496
32
//property bool windowActive: typeof window != 'undefined'
33
//onWindowActiveChanged: window.title = i18n.tr("Calendar")
35
11
// Argument during startup
69
45
* If newevent isn't set and startime is set, its value is used to choose the right view.
70
46
* If neither of precendet flags are set, endtime is ignored.
71
47
* It accepts an integer value of the number of seconds since UNIX epoch in the UTC timezone.
74
* Open an existing event
75
* Keyword: eventid (provisional)
77
* It takes a id of an event and open that event on full page
82
valueNames: ["EVENT_ID"]
86
51
objectName: "calendar"
87
52
applicationName: "com.ubuntu.calendar"
90
55
height: units.gu(80)
92
Keys.forwardTo: [pageStack.currentPage]
94
headerColor: "#E8E8E8"
95
backgroundColor: "#f5f5f5"
96
footerColor: "#ECECEC"
57
headerColor: "#266249"
58
backgroundColor: "#478158"
59
footerColor: "#478158"
97
60
anchorToKeyboard: true
106
Component.onCompleted: push(tabs)
108
// This is for wait that the app is load when newEvent is invoked by argument
111
interval: 200; running: false; repeat: false
119
interval: 200; running: false; repeat: false
121
eventModel.applyFilterFinal();
129
detail: Detail.ItemType;
130
field: Type.FieldType
132
matchFlags: Filter.MatchExactly
136
id: eventOccurenceFilter
137
detail: Detail.ItemType;
138
field: Type.FieldType
139
value: Type.EventOccurrence
140
matchFlags: Filter.MatchExactly
152
startPeriod: tabs.currentDay
153
endPeriod: tabs.currentDay
155
filter: IntersectionFilter {
156
filters: [ collectionFilter, itemTypeFilter]
159
function delayedApplyFilter() {
160
applyFilterTimer.restart();
163
function applyFilterFinal() {
164
var collectionIds = [];
165
var collections = eventModel.getCollections();
166
for(var i=0; i < collections.length ; ++i) {
167
var collection = collections[i]
168
if(collection.extendedMetaData("collection-selected") === true) {
169
collectionIds.push(collection.collectionId);
172
collectionFilter.ids = collectionIds;
175
Component.onCompleted: {
176
delayedApplyFilter();
178
if (args.values.eventid) {
180
eventModel.onItemsFetched.connect( function(id,fetchedItems) {
181
if( requestId === id && fetchedItems.length > 0 ) {
182
var event = fetchedItems[0];
183
pageStack.push(Qt.resolvedUrl("EventDetails.qml"),{"event":event,"model": eventModel});
186
requestId = eventModel.fetchItems([args.values.eventid]);
193
Keys.forwardTo: [tabs.currentPage.item]
65
Component.onCompleted: push(tabPage)
195
70
property var currentDay: DateExt.today();
71
property var globalModel;
197
73
// Arguments on startup
198
74
property bool newevent: false;
199
75
property int starttime: -1;
200
76
property int endtime: -1;
202
selectedTabIndex: monthTab.index
78
onCurrentDayChanged: {
79
if( monthView.currentMonth !== undefined && !monthView.currentMonth.isSameDay(currentDay))
80
monthView.currentMonth = currentDay.midnight();
82
if( !dayView.currentDay.isSameDay(currentDay))
83
dayView.currentDay = currentDay
85
if( !weekView.dayStart.isSameDay(currentDay))
86
weekView.dayStart = currentDay
88
setStartEndDateToModel();
91
function setStartEndDateToModel() {
93
globalModel.startPeriod = new Date(currentDay.getFullYear(),0,1,0,0,0,0);
94
globalModel.endPeriod = new Date(currentDay.getFullYear(),11,31,0,0,0,0);
204
98
function newEvent() {
205
99
var startDate = new Date();
259
153
if (endtimepattern.test(url))
260
154
endtime = url.match(/endtime=(\d+)/)[0].replace("endtime=", '');
263
158
Component.onCompleted: {
264
159
// If an url has been set
265
160
if (args.defaultArgument.at(0)) {
266
161
parseArguments(args.defaultArgument.at(0))
267
tabs.currentDay = new Date()
162
tabPage.currentDay = new Date()
268
163
// If newevent has been called on startup
270
165
timer.running = true;
272
167
else if (starttime !== -1) { // If no newevent has been setted, but starttime
273
168
var startTime = parseInt(starttime);
274
tabs.currentDay = new Date(startTime);
169
tabPage.currentDay = new Date(startTime);
276
171
// If also endtime has been settend
277
172
if (endtime !== -1) {
293
188
tabs.selectedTabIndex= 1;
191
globalModel = GlobalModel.gloablModel();
192
setStartEndDateToModel();
295
193
} // End of Component.onCompleted:
298
id: commonHeaderActions
302
if( event.modifiers & Qt.ControlModifier) {
303
var currentTab = tabs.selectedTabIndex;
305
if( currentTab >= tabs.tabChildren.length){
308
tabs.selectedTabIndex = currentTab;
312
Keys.onBacktabPressed: {
313
if( event.modifiers & Qt.ControlModifier) {
314
var currentTab = tabs.selectedTabIndex;
317
currentTab = tabs.tabChildren.length -1;
319
tabs.selectedTabIndex = currentTab;
325
objectName: "yearTab"
326
title: i18n.tr("Year")
329
objectName: "yearViewLoader"
330
source: tabs.selectedTab == yearTab ? Qt.resolvedUrl("YearView.qml"):""
332
item.currentYear = tabs.currentDay.getFullYear();
338
bottom: parent.bottom
342
target: yearViewLoader.item
344
var now = DateExt.today();
345
if( date.getMonth() === now.getMonth()
346
&& date.getFullYear() === now.getFullYear()) {
347
tabs.currentDay = now;
349
tabs.currentDay = date.midnight();
351
tabs.selectedTabIndex = monthTab.index;
359
objectName: "monthTab"
360
title: i18n.tr("Month")
363
objectName: "monthViewLoader"
364
source: tabs.selectedTab == monthTab ? Qt.resolvedUrl("MonthView.qml"):""
366
item.currentMonth = tabs.currentDay.midnight();
372
bottom: parent.bottom
376
target: monthViewLoader.item
378
tabs.currentDay = date;
379
tabs.selectedTabIndex = dayTab.index;
387
objectName: "weekTab"
388
title: i18n.tr("Week")
391
objectName: "weekViewLoader"
392
source: tabs.selectedTab == weekTab ? Qt.resolvedUrl("WeekView.qml"):""
394
item.isCurrentPage= Qt.binding(function() { return tabs.selectedTab == weekTab })
395
item.dayStart = tabs.currentDay;
401
bottom: parent.bottom
405
target: weekViewLoader.item
407
tabs.currentDay = weekViewLoader.item.dayStart;
411
tabs.currentDay = date;
412
tabs.selectedTabIndex = dayTab.index;
421
title: i18n.tr("Day")
424
objectName: "dayViewLoader"
425
source: tabs.selectedTab == dayTab ? Qt.resolvedUrl("DayView.qml"):""
427
item.isCurrentPage= Qt.binding(function() { return tabs.selectedTab == dayTab })
428
item.currentDay = tabs.currentDay;
434
bottom: parent.bottom
438
target: dayViewLoader.item
439
onCurrentDayChanged: {
440
tabs.currentDay = dayViewLoader.item.currentDay;
444
tabs.currentDay = date;
452
objectName: "agendaTab"
453
title: i18n.tr("Agenda")
456
objectName: "agendaViewLoader"
457
source: tabs.selectedTab == agendaTab ? Qt.resolvedUrl("AgendaView.qml"):""
460
item.currentDay = tabs.currentDay;
466
bottom: parent.bottom
470
target: agendaViewLoader.item
472
tabs.currentDay = date;
473
tabs.selectedTabIndex = dayTab.index;
195
// This is for wait that the app is load when newEvent is invoked by argument
210
objectName: "todaybutton"
212
iconSource: Qt.resolvedUrl("calendar-today.svg");
213
text: i18n.tr("Today");
215
tabPage.currentDay = (new Date()).midnight();
220
objectName: "neweventbutton"
222
iconSource: Qt.resolvedUrl("new-event.svg");
223
text: i18n.tr("New Event");
225
pageStack.push(Qt.resolvedUrl("NewEvent.qml"),{"date":tabPage.currentDay});
234
objectName: "yearTab"
235
title: i18n.tr("Year")
237
objectName: "yearPage"
242
tabs.selectedTabIndex = 1
243
var now = DateExt.today();
244
if( date.getMonth() === now.getMonth()
245
&& date.getFullYear() === now.getFullYear()) {
246
monthView.currentMonth = now
248
monthView.currentMonth = date.midnight();
256
objectName: "monthTab"
257
title: i18n.tr("Month")
264
tabs.selectedTabIndex = 3
265
tabPage.currentDay = date;
270
objectName: "weekTab"
271
title: i18n.tr("Week")
280
tabPage.currentDay = dayStart;
288
title: i18n.tr("Day")
296
onCurrentDayChanged: {
297
tabPage.currentDay = currentDay;