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
2
import Ubuntu.Components 0.1
3
import Ubuntu.Components.Popups 0.1
23
5
import "dateExt.js" as DateExt
27
useDeprecatedToolbar: false
29
// Work-around until this branch lands:
30
// https://code.launchpad.net/~tpeeters/ubuntu-ui-toolkit/optIn-tabsDrawer/+merge/212496
31
//property bool windowActive: typeof window != 'undefined'
32
//onWindowActiveChanged: window.title = i18n.tr("Calendar")
34
// Argument during startup
38
// Example of argument: calendar:///new-event
41
// Due to bug #1231558 you have to pass arguments BEFORE app:
42
// qmlscene calendar:///new-event calendar.qml
44
defaultArgument.help: i18n.tr("Calendar app accept four arguments: --starttime, --endtime, --newevent and --eventid. They will be managed by system. See the source for a full comment about them");
45
//defaultArgument.required: false;
46
defaultArgument.valueNames: ["URL"]
48
/* ARGUMENTS on startup
49
* (no one is required)
54
* Create a new event. If starttime or endtime are set they are used to set start and end time of the new event.
55
* It accepts no value.
61
* If newevent has been called, starttime is the start time of event. Otherwise is the day on which app is focused on startup.
62
* It accepts an integer value of the number of seconds since UNIX epoch in the UTC timezone.
67
* If newevent is set it's the end time of the event, has to be > of starttime.
68
* If newevent isn't set and startime is set, its value is used to choose the right view.
69
* If neither of precendet flags are set, endtime is ignored.
70
* It accepts an integer value of the number of seconds since UNIX epoch in the UTC timezone.
73
* Open an existing event
74
* Keyword: eventid (provisional)
76
* It takes a id of an event and open that event on full page
81
valueNames: ["EVENT_ID"]
85
10
objectName: "calendar"
86
applicationName: "com.ubuntu.calendar"
11
applicationName: "calendar-app"
89
14
height: units.gu(80)
91
Keys.forwardTo: [pageStack.currentPage]
93
headerColor: "#E8E8E8"
94
backgroundColor: "#f5f5f5"
95
footerColor: "#ECECEC"
96
anchorToKeyboard: true
16
headerColor: "#266249"
17
backgroundColor: "#478158"
18
footerColor: "#478158"
102
Component.onCompleted: push(tabs)
104
// This is for wait that the app is load when newEvent is invoked by argument
107
interval: 200; running: false; repeat: false
115
interval: 200; running: false; repeat: false
117
eventModel.applyFilterFinal();
125
detail: Detail.ItemType;
126
field: Type.FieldType
128
matchFlags: Filter.MatchExactly
132
id: eventOccurenceFilter
133
detail: Detail.ItemType;
134
field: Type.FieldType
135
value: Type.EventOccurrence
136
matchFlags: Filter.MatchExactly
148
startPeriod: tabs.currentDay
149
endPeriod: tabs.currentDay
151
filter: IntersectionFilter {
152
filters: [ collectionFilter, itemTypeFilter]
155
function delayedApplyFilter() {
156
applyFilterTimer.restart();
159
function applyFilterFinal() {
160
var collectionIds = [];
161
var collections = eventModel.getCollections();
162
for(var i=0; i < collections.length ; ++i) {
163
var collection = collections[i]
164
if(collection.extendedMetaData("collection-selected") === true) {
165
collectionIds.push(collection.collectionId);
168
collectionFilter.ids = collectionIds;
171
Component.onCompleted: {
172
delayedApplyFilter();
174
if (args.values.eventid) {
176
eventModel.onItemsFetched.connect( function(id,fetchedItems) {
177
if( requestId === id && fetchedItems.length > 0 ) {
178
var event = fetchedItems[0];
179
pageStack.push(Qt.resolvedUrl("EventDetails.qml"),{"event":event,"model": eventModel});
182
requestId = eventModel.fetchItems([args.values.eventid]);
189
Keys.forwardTo: [tabs.currentPage.item]
23
Component.onCompleted: push(tabPage)
191
28
property var currentDay: DateExt.today();
193
// Arguments on startup
194
property bool newevent: false;
195
property int starttime: -1;
196
property int endtime: -1;
198
selectedTabIndex: weekTab.index
30
onCurrentDayChanged: {
31
if( monthView.currentMonth !== undefined && !monthView.currentMonth.isSameDay(currentDay))
32
monthView.currentMonth = currentDay.midnight();
34
if( !dayView.currentDay.isSameDay(currentDay))
35
dayView.currentDay = currentDay
37
if( !weekView.dayStart.isSameDay(currentDay))
38
weekView.dayStart = currentDay
200
41
function newEvent() {
201
var startDate = new Date();
202
var endDate = new Date();
206
if (starttime === 0) { // startime 0 means now
207
if (endtime !== -1) { // If also endtime has been invoked
208
endTime = parseInt(endtime);
209
if (endTime > startDate) // If endtime is after startime
210
endDate = new Date(endTime);
213
else if (starttime !== -1) { // If starttime has been invoked
214
startTime = parseInt(starttime);
215
startDate = new Date(startTime);
216
if (endtime !== -1) { // If --endtime has been invoked
217
endTime = parseInt(endtime);
218
if (endTime > startDate)
219
endDate = new Date(endTime);
222
//pageStack.push(Qt.resolvedUrl("NewEvent.qml"),{"startDate": startDate, "endDate": endDate, //"model":eventModel});
225
// This function calculate the difference between --endtime and --starttime and choose the better view
226
function calculateDifferenceStarttimeEndtime(startTime, endTime) {
227
var minute = 60 * 1000;
228
var hour = 60 * minute;
230
var month = 30 * day;
232
var difference = endTime - startTime;
234
if (difference > month)
235
return yearTab.index; // Year view
236
else if (difference > 7 * day)
237
return monthTab.index; // Month view}
238
else if (difference > day)
239
return weekTab.index; // Week view
241
return dayTab.index; // Day view
244
// This function parse the argument
245
function parseArguments(url) {
246
var newevenpattern= new RegExp ("newevent");
247
var starttimepattern = new RegExp ("starttime=\\d+");
248
var endtimepattern = new RegExp ("endtime=\\d+");
250
newevent = newevenpattern.test(url);
252
if (starttimepattern.test(url))
253
starttime = url.match(/starttime=(\d+)/)[0].replace("starttime=", '');
255
if (endtimepattern.test(url))
256
endtime = url.match(/endtime=(\d+)/)[0].replace("endtime=", '');
42
PopupUtils.open(newEventComponent, tabPage, {"defaultDate": currentDay})
259
45
Component.onCompleted: {
260
// If an url has been set
261
if (args.defaultArgument.at(0)) {
262
parseArguments(args.defaultArgument.at(0))
263
tabs.currentDay = new Date()
264
// If newevent has been called on startup
266
timer.running = true;
268
else if (starttime !== -1) { // If no newevent has been setted, but starttime
269
var startTime = parseInt(starttime);
270
tabs.currentDay = new Date(startTime);
272
// If also endtime has been settend
273
if (endtime !== -1) {
274
var endTime = parseInt(endtime);
275
tabs.selectedTabIndex = calculateDifferenceStarttimeEndtime(startTime, endTime);
278
// If no endtime has been setted, open the starttime date in day view
279
tabs.selectedTabIndex = dayTab.index;
281
} // End of else if (starttime)
283
// Due to bug #1231558 {if (args.defaultArgument.at(0))} is always true
284
// After the fix we can delete this else
285
tabs.selectedTabIndex = weekTab.index;
287
} // End of if about args.values
289
tabs.selectedTabIndex = weekTab.index;
291
} // End of Component.onCompleted:
294
id: commonHeaderActions
298
if( event.modifiers & Qt.ControlModifier) {
299
var currentTab = tabs.selectedTabIndex;
301
if( currentTab >= tabs.tabChildren.length){
304
tabs.selectedTabIndex = currentTab;
308
Keys.onBacktabPressed: {
309
if( event.modifiers & Qt.ControlModifier) {
310
var currentTab = tabs.selectedTabIndex;
313
currentTab = tabs.tabChildren.length -1;
315
tabs.selectedTabIndex = currentTab;
321
objectName: "yearTab"
322
title: i18n.tr("Year")
325
objectName: "yearViewLoader"
326
source: tabs.selectedTab == yearTab ? Qt.resolvedUrl("YearView.qml"):""
328
item.currentYear = tabs.currentDay.getFullYear();
334
bottom: parent.bottom
338
target: yearViewLoader.item
340
var now = DateExt.today();
341
if( date.getMonth() === now.getMonth()
342
&& date.getFullYear() === now.getFullYear()) {
343
tabs.currentDay = now;
345
tabs.currentDay = date.midnight();
347
tabs.selectedTabIndex = monthTab.index;
355
objectName: "monthTab"
356
title: i18n.tr("Month")
359
objectName: "monthViewLoader"
360
source: tabs.selectedTab == monthTab ? Qt.resolvedUrl("MonthView.qml"):""
362
item.currentMonth = tabs.currentDay.midnight();
368
bottom: parent.bottom
372
target: monthViewLoader.item
374
tabs.currentDay = date;
375
tabs.selectedTabIndex = dayTab.index;
383
objectName: "weekTab"
384
title: i18n.tr("Week")
387
objectName: "weekViewLoader"
388
source: tabs.selectedTab == weekTab ? Qt.resolvedUrl("WeekView.qml"):""
390
item.isCurrentPage= Qt.binding(function() { return tabs.selectedTab == weekTab })
391
item.dayStart = tabs.currentDay;
397
bottom: parent.bottom
401
target: weekViewLoader.item
403
tabs.currentDay = weekViewLoader.item.dayStart;
407
tabs.currentDay = date;
408
tabs.selectedTabIndex = dayTab.index;
417
title: i18n.tr("Day")
420
objectName: "dayViewLoader"
421
source: tabs.selectedTab == dayTab ? Qt.resolvedUrl("DayView.qml"):""
423
item.isCurrentPage= Qt.binding(function() { return tabs.selectedTab == dayTab })
424
item.currentDay = tabs.currentDay;
430
bottom: parent.bottom
434
target: dayViewLoader.item
435
onCurrentDayChanged: {
436
tabs.currentDay = dayViewLoader.item.currentDay;
440
tabs.currentDay = date;
448
objectName: "agendaTab"
449
title: i18n.tr("Agenda")
452
objectName: "agendaViewLoader"
453
source: tabs.selectedTab == agendaTab ? Qt.resolvedUrl("AgendaView.qml"):""
458
bottom: parent.bottom
462
target: agendaViewLoader.item
464
tabs.currentDay = date;
465
tabs.selectedTabIndex = dayTab.index;
46
tabs.selectedTabIndex= 1;
53
objectName: "neweventbutton"
55
iconSource: Qt.resolvedUrl("avatar.png")
56
text: i18n.tr("New Event")
57
onTriggered: tabPage.newEvent()
61
objectName: "todaybutton"
63
iconSource: Qt.resolvedUrl("avatar.png");
64
text: i18n.tr("Today");
66
tabPage.currentDay = (new Date()).midnight();
75
title: i18n.tr("Year")
81
tabs.selectedTabIndex = 1
82
var now = DateExt.today();
83
if( date.getMonth() === now.getMonth()
84
&& date.getFullYear() === now.getFullYear()) {
85
monthView.currentMonth = now
87
monthView.currentMonth = date.midnight();
95
title: i18n.tr("Month")
102
tabs.selectedTabIndex = 3
103
tabPage.currentDay = date;
108
title: i18n.tr("Week")
117
tabPage.currentDay = dayStart;
124
title: i18n.tr("Day")
132
onCurrentDayChanged: {
133
tabPage.currentDay = currentDay;
141
id: newEventComponent