~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
 */
455.3.1 by Mihir Soni
Removed duplicate header section from views and added common header
18
import QtQuick 2.3
422.5.1 by Akiva Avraham
Upgraded component library imports
19
import Ubuntu.Components 1.1
20
import Ubuntu.Components.Popups 1.0
212.4.23 by Kunal Parmar
review comment
21
import QtOrganizer 5.0
238.1.18 by Kunal Parmar
reverted un-necessary changes
22
import Ubuntu.SyncMonitor 0.1
12.2.5 by Kunal Parmar
Resolving the layout issue, temp commit for merging latest trunk code
23
72.2.22 by Kunal Parmar
temp merge
24
import "dateExt.js" as DateExt
25
1 by Michael Hall
Initial code template
26
MainView {
3 by Frank Mertens
Initial code for the month view. Also bootstrapped a small extension library for JS::Date.
27
    id: mainView
275.1.1 by Kunal Parmar
New Header transition
28
    useDeprecatedToolbar: false
246.1.1 by David Planella
Workaround for bug 1308343 to show the app's name in the title bar on the desktop
29
246.1.2 by David Planella
Fixed the comment for the app's title workaround
30
    // Work-around until this branch lands:
455.3.1 by Mihir Soni
Removed duplicate header section from views and added common header
31
    // https://code.launchpad.net/~tpeeters/ubuntu-ui-toolkit/optIn-tabsDrawer/+merge/212496
212.4.16 by Kunal Parmar
temp commit
32
    //property bool windowActive: typeof window != 'undefined'
33
    //onWindowActiveChanged: window.title = i18n.tr("Calendar")
246.1.1 by David Planella
Workaround for bug 1308343 to show the app's name in the title bar on the desktop
34
122.2.6 by Riccardo Padovani
Updated with last indication
35
    // Argument during startup
122.2.1 by Riccardo Padovani
Add support for Arguments
36
    Arguments {
37
        id: args;
38
122.2.6 by Riccardo Padovani
Updated with last indication
39
        // Example of argument: calendar:///new-event
40
41
        // IMPORTANT
42
        // Due to bug #1231558 you have to pass arguments BEFORE app:
43
        // qmlscene calendar:///new-event calendar.qml
44
277.2.1 by Riccardo Padovani
Started to work on support to launch the app on an event page
45
        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");
122.2.6 by Riccardo Padovani
Updated with last indication
46
        //defaultArgument.required: false;
47
        defaultArgument.valueNames: ["URL"]
48
49
        /* ARGUMENTS on startup
50
         * (no one is required)
51
         *
52
         * Create a new event
53
         * Keyword: newevent
54
         *
55
         * Create a new event. If starttime or endtime are set they are used to set start and end time of the new event.
56
         * It accepts no value.
57
         *
58
         *
59
         * Choose the view
60
         * Keyword: starttime
61
         *
62
         * If newevent has been called, starttime is the start time of event. Otherwise is the day on which app is focused on startup.
63
         * It accepts an integer value of the number of seconds since UNIX epoch in the UTC timezone.
64
         * 0 means today.
65
         *
66
         * Keyword: endtime
67
         *
68
         * If newevent is set it's the end time of the event, has to be > of starttime.
69
         * If newevent isn't set and startime is set, its value is used to choose the right view.
70
         * If neither of precendet flags are set, endtime is ignored.
71
         * It accepts an integer value of the number of seconds since UNIX epoch in the UTC timezone.
277.2.1 by Riccardo Padovani
Started to work on support to launch the app on an event page
72
         *
73
         *
74
         * Open an existing event
75
         * Keyword: eventid (provisional)
76
         *
77
         * It takes a id of an event and open that event on full page
122.2.1 by Riccardo Padovani
Add support for Arguments
78
         */
277.2.3 by Riccardo Padovani
Working implementation following Kunal guidelines
79
        Argument {
80
            name: "eventid"
81
            required: false
82
            valueNames: ["EVENT_ID"]
83
        }
122.2.1 by Riccardo Padovani
Add support for Arguments
84
    }
85
8.2.1 by Zoltán Balogh
fix desktop file name and add application name property
86
    objectName: "calendar"
137.1.1 by Sergio Schvezov
Fixing namespace issues and adding calendar apparmor profile
87
    applicationName: "com.ubuntu.calendar"
8.2.1 by Zoltán Balogh
fix desktop file name and add application name property
88
224.1.1 by Marcin Lesniowski
fix #1297463, simply changed default window size
89
    width: units.gu(100)
3 by Frank Mertens
Initial code for the month view. Also bootstrapped a small extension library for JS::Date.
90
    height: units.gu(80)
183.1.1 by Kunal Parmar
Key Navigation implemented
91
    focus: true
234.1.4 by Kunal Parmar
Merge from trunk
92
    Keys.forwardTo: [pageStack.currentPage]
4.2.8 by Frank Mertens
Allow to select the current month with the tab bar.
93
279.2.1 by Alan Pope
start moving to new colours
94
    headerColor: "#E8E8E8"
95
    backgroundColor: "#f5f5f5"
96
    footerColor: "#ECECEC"
110.1.12 by Kunal Parmar
MainView anchoring to keyboard
97
    anchorToKeyboard: true
96.2.5 by Kunal Parmar
Theme and some other modification
98
238.1.18 by Kunal Parmar
reverted un-necessary changes
99
    SyncMonitor {
100
        id: syncMonitor
101
    }
253.5.1 by Renato Araujo Oliveira Filho
Integrated with SyncMonitor.
102
12.2.1 by Kunal Parmar
Details view changed to use DataService, pagestack used to push Details View
103
    PageStack {
104
        id: pageStack
12.2.6 by Kunal Parmar
Layout issue due to new page stack change resolved
105
234.1.1 by Kunal Parmar
Unnecessary Top Page removed
106
        Component.onCompleted: push(tabs)
72.2.1 by Kunal Parmar
minor modification in dayview
107
234.1.4 by Kunal Parmar
Merge from trunk
108
        // This is for wait that the app is load when newEvent is invoked by argument
109
        Timer {
110
            id: timer
111
            interval: 200; running: false; repeat: false
112
            onTriggered: {
113
                tabs.newEvent();
114
            }
115
        }
116
212.4.28 by Kunal Parmar
Timer approach
117
        Timer {
118
            id: applyFilterTimer
119
            interval: 200; running: false; repeat: false
120
            onTriggered: {
121
                eventModel.applyFilterFinal();
122
            }
123
        }
124
354.1.1 by Kunal Parmar
intersaction filter used
125
        UnionFilter {
126
            id: itemTypeFilter
127
            DetailFieldFilter{
128
                id: eventFilter
129
                detail: Detail.ItemType;
130
                field: Type.FieldType
131
                value: Type.Event
132
                matchFlags: Filter.MatchExactly
133
            }
212.4.28 by Kunal Parmar
Timer approach
134
354.1.1 by Kunal Parmar
intersaction filter used
135
            DetailFieldFilter{
136
                id: eventOccurenceFilter
137
                detail: Detail.ItemType;
138
                field: Type.FieldType
139
                value: Type.EventOccurrence
140
                matchFlags: Filter.MatchExactly
141
            }
212.4.28 by Kunal Parmar
Timer approach
142
        }
143
144
        CollectionFilter{
145
            id: collectionFilter
146
        }
147
234.1.4 by Kunal Parmar
Merge from trunk
148
        EventListModel{
149
            id: eventModel
212.4.26 by Kunal Parmar
merge from trunk
150
212.4.12 by Kunal Parmar
review comment addressed
151
            autoUpdate: true
152
            startPeriod: tabs.currentDay
153
            endPeriod: tabs.currentDay
154
354.1.1 by Kunal Parmar
intersaction filter used
155
            filter: IntersectionFilter {
156
                filters: [ collectionFilter, itemTypeFilter]
212.4.28 by Kunal Parmar
Timer approach
157
            }
158
159
            function delayedApplyFilter() {
160
                applyFilterTimer.restart();
161
            }
162
163
            function applyFilterFinal() {
212.4.12 by Kunal Parmar
review comment addressed
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);
170
                    }
171
                }
212.4.28 by Kunal Parmar
Timer approach
172
                collectionFilter.ids = collectionIds;
212.4.12 by Kunal Parmar
review comment addressed
173
            }
277.2.3 by Riccardo Padovani
Working implementation following Kunal guidelines
174
175
            Component.onCompleted: {
212.4.28 by Kunal Parmar
Timer approach
176
                delayedApplyFilter();
177
277.2.3 by Riccardo Padovani
Working implementation following Kunal guidelines
178
                if (args.values.eventid) {
179
                    var requestId = "";
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});
184
                        }
185
                    });
186
                    requestId = eventModel.fetchItems([args.values.eventid]);
187
                }
188
            }
234.1.4 by Kunal Parmar
Merge from trunk
189
        }
190
234.1.1 by Kunal Parmar
Unnecessary Top Page removed
191
        Tabs{
192
            id: tabs
234.1.7 by Kunal Parmar
Loader used to load page
193
            Keys.forwardTo: [tabs.currentPage.item]
72.2.1 by Kunal Parmar
minor modification in dayview
194
72.2.22 by Kunal Parmar
temp merge
195
            property var currentDay: DateExt.today();
124.3.2 by Kunal Parmar
Global model date init
196
122.2.6 by Riccardo Padovani
Updated with last indication
197
            // Arguments on startup
198
            property bool newevent: false;
199
            property int starttime: -1;
200
            property int endtime: -1;
201
249.1.1 by Kunal Parmar
MonthView to default View
202
            selectedTabIndex: monthTab.index
203
72.2.3 by Kunal Parmar
ToolbarActions to ToolbarItems
204
            function newEvent() {
122.2.10 by Riccardo Padovani
Updated to last version
205
                var startDate = new Date();
206
                var endDate = new Date();
122.2.1 by Riccardo Padovani
Add support for Arguments
207
                var startTime;
208
                var endTime;
209
122.2.10 by Riccardo Padovani
Updated to last version
210
                if (starttime === 0) { // startime 0 means now
211
                    if (endtime !== -1) { // If also endtime has been invoked
212
                        endTime = parseInt(endtime);
213
                        if (endTime > startDate) // If endtime is after startime
214
                            endDate = new Date(endTime);
215
                    }
216
                }
217
                else if (starttime !== -1) { // If starttime has been invoked
218
                    startTime = parseInt(starttime);
219
                    startDate = new Date(startTime);
220
                    if (endtime !== -1) { // If --endtime has been invoked
221
                        endTime = parseInt(endtime);
222
                        if (endTime > startDate)
223
                            endDate = new Date(endTime);
224
                    }
225
                }
412.2.6 by Mihir Soni
Fixed AP & Launching issue
226
                //pageStack.push(Qt.resolvedUrl("NewEvent.qml"),{"startDate": startDate, "endDate": endDate, //"model":eventModel});
122.2.1 by Riccardo Padovani
Add support for Arguments
227
            }
228
229
            // This function calculate the difference between --endtime and --starttime and choose the better view
230
            function calculateDifferenceStarttimeEndtime(startTime, endTime) {
231
                var minute = 60 * 1000;
232
                var hour = 60 * minute;
233
                var day = 24 * hour;
234
                var month = 30 * day;
235
236
                var difference = endTime - startTime;
237
238
                if (difference > month)
234.1.1 by Kunal Parmar
Unnecessary Top Page removed
239
                    return yearTab.index;   // Year view
122.2.1 by Riccardo Padovani
Add support for Arguments
240
                else if (difference > 7 * day)
234.1.1 by Kunal Parmar
Unnecessary Top Page removed
241
                    return monthTab.index;   // Month view}
122.2.1 by Riccardo Padovani
Add support for Arguments
242
                else if (difference > day)
234.1.1 by Kunal Parmar
Unnecessary Top Page removed
243
                    return weekTab.index;   // Week view
122.2.1 by Riccardo Padovani
Add support for Arguments
244
                else
234.1.1 by Kunal Parmar
Unnecessary Top Page removed
245
                    return dayTab.index;   // Day view
72.2.3 by Kunal Parmar
ToolbarActions to ToolbarItems
246
            }
247
122.2.6 by Riccardo Padovani
Updated with last indication
248
            // This function parse the argument
249
            function parseArguments(url) {
250
                var newevenpattern= new RegExp ("newevent");
251
                var starttimepattern = new RegExp ("starttime=\\d+");
252
                var endtimepattern = new RegExp ("endtime=\\d+");
253
254
                newevent = newevenpattern.test(url);
255
256
                if (starttimepattern.test(url))
257
                    starttime = url.match(/starttime=(\d+)/)[0].replace("starttime=", '');
258
259
                if (endtimepattern.test(url))
260
                    endtime = url.match(/endtime=(\d+)/)[0].replace("endtime=", '');
261
            }
262
72.2.5 by Kunal Parmar
goto today changed
263
            Component.onCompleted: {
122.2.6 by Riccardo Padovani
Updated with last indication
264
                // If an url has been set
265
                if (args.defaultArgument.at(0)) {
266
                    parseArguments(args.defaultArgument.at(0))
234.1.1 by Kunal Parmar
Unnecessary Top Page removed
267
                    tabs.currentDay = new Date()
122.2.6 by Riccardo Padovani
Updated with last indication
268
                    // If newevent has been called on startup
269
                    if (newevent) {
122.2.12 by Riccardo Padovani
Fixed newEvent argument, thanks to Kunal
270
                        timer.running = true;
122.2.6 by Riccardo Padovani
Updated with last indication
271
                    }
272
                    else if (starttime !== -1) { // If no newevent has been setted, but starttime
273
                        var startTime = parseInt(starttime);
234.1.1 by Kunal Parmar
Unnecessary Top Page removed
274
                        tabs.currentDay = new Date(startTime);
122.2.6 by Riccardo Padovani
Updated with last indication
275
276
                        // If also endtime has been settend
277
                        if (endtime !== -1) {
278
                            var endTime = parseInt(endtime);
279
                            tabs.selectedTabIndex = calculateDifferenceStarttimeEndtime(startTime, endTime);
280
                        }
281
                        else {
282
                            // If no endtime has been setted, open the starttime date in day view
212.1.2 by nskaggs
revert to 211
283
                            tabs.selectedTabIndex = 3;
122.2.6 by Riccardo Padovani
Updated with last indication
284
                        }
285
                    } // End of else if (starttime)
122.2.8 by Riccardo Padovani
Set Month View as startup view
286
                    else {
180.1.1 by nskaggs
Tweak for swipe timing and slower device issues
287
                        // Due to bug #1231558 {if (args.defaultArgument.at(0))} is always true
288
                        // After the fix we can delete this else
212.1.2 by nskaggs
revert to 211
289
                        tabs.selectedTabIndex= 1;
122.2.8 by Riccardo Padovani
Set Month View as startup view
290
                    }
122.2.6 by Riccardo Padovani
Updated with last indication
291
                } // End of if about args.values
122.2.1 by Riccardo Padovani
Add support for Arguments
292
                else {
212.1.2 by nskaggs
revert to 211
293
                    tabs.selectedTabIndex= 1;
122.2.1 by Riccardo Padovani
Add support for Arguments
294
                }
295
            } // End of Component.onCompleted:
72.2.5 by Kunal Parmar
goto today changed
296
455.3.1 by Mihir Soni
Removed duplicate header section from views and added common header
297
            EventActions {
298
                id: commonHeaderActions
69.1.1 by Kunal Parmar
Initial WeekRibbon and WeekView implementation
299
            }
300
183.1.1 by Kunal Parmar
Key Navigation implemented
301
            Keys.onTabPressed: {
302
                if( event.modifiers & Qt.ControlModifier) {
303
                    var currentTab = tabs.selectedTabIndex;
304
                    currentTab ++;
305
                    if( currentTab >= tabs.tabChildren.length){
306
                        currentTab = 0;
307
                    }
308
                    tabs.selectedTabIndex = currentTab;
309
                }
310
            }
311
183.1.4 by Kunal Parmar
YearView jump resolved and backtab implemented
312
            Keys.onBacktabPressed: {
313
                if( event.modifiers & Qt.ControlModifier) {
314
                    var currentTab = tabs.selectedTabIndex;
315
                    currentTab --;
316
                    if( currentTab < 0){
317
                        currentTab = tabs.tabChildren.length -1;
318
                    }
319
                    tabs.selectedTabIndex = currentTab;
320
                }
321
            }
322
234.1.1 by Kunal Parmar
Unnecessary Top Page removed
323
            Tab{
324
                id: yearTab
325
                objectName: "yearTab"
326
                title: i18n.tr("Year")
234.1.7 by Kunal Parmar
Loader used to load page
327
                page: Loader{
328
                    id: yearViewLoader
329
                    objectName: "yearViewLoader"
330
                    source: tabs.selectedTab == yearTab ? Qt.resolvedUrl("YearView.qml"):""
331
                    onLoaded: {
332
                        item.currentYear = tabs.currentDay.getFullYear();
333
                    }
334
335
                    anchors{
336
                        left: parent.left
337
                        right: parent.right
338
                        bottom: parent.bottom
339
                    }
340
341
                    Connections{
342
                        target: yearViewLoader.item
343
                        onMonthSelected: {
344
                            var now = DateExt.today();
345
                            if( date.getMonth() === now.getMonth()
346
                                    && date.getFullYear() === now.getFullYear()) {
347
                                tabs.currentDay = now;
348
                            } else {
349
                                tabs.currentDay = date.midnight();
350
                            }
351
                            tabs.selectedTabIndex = monthTab.index;
72.2.1 by Kunal Parmar
minor modification in dayview
352
                        }
174.1.16 by Kunal Parmar
Connections used
353
                    }
72.2.1 by Kunal Parmar
minor modification in dayview
354
                }
234.1.1 by Kunal Parmar
Unnecessary Top Page removed
355
            }
234.1.5 by Kunal Parmar
merge issue fixed
356
234.1.7 by Kunal Parmar
Loader used to load page
357
            Tab{
234.1.1 by Kunal Parmar
Unnecessary Top Page removed
358
                id: monthTab
359
                objectName: "monthTab"
360
                title: i18n.tr("Month")
234.1.7 by Kunal Parmar
Loader used to load page
361
                page: Loader{
362
                    id: monthViewLoader
363
                    objectName: "monthViewLoader"
364
                    source: tabs.selectedTab == monthTab ? Qt.resolvedUrl("MonthView.qml"):""
365
                    onLoaded: {
366
                        item.currentMonth = tabs.currentDay.midnight();
367
                    }
368
369
                    anchors{
370
                        left: parent.left
371
                        right: parent.right
372
                        bottom: parent.bottom
373
                    }
374
375
                    Connections{
376
                        target: monthViewLoader.item
377
                        onDateSelected: {
378
                            tabs.currentDay = date;
379
                            tabs.selectedTabIndex = dayTab.index;
380
                        }
234.1.1 by Kunal Parmar
Unnecessary Top Page removed
381
                    }
382
                }
383
            }
234.1.5 by Kunal Parmar
merge issue fixed
384
234.1.1 by Kunal Parmar
Unnecessary Top Page removed
385
            Tab{
386
                id: weekTab
387
                objectName: "weekTab"
388
                title: i18n.tr("Week")
234.1.7 by Kunal Parmar
Loader used to load page
389
                page: Loader{
390
                    id: weekViewLoader
391
                    objectName: "weekViewLoader"
392
                    source: tabs.selectedTab == weekTab ? Qt.resolvedUrl("WeekView.qml"):""
393
                    onLoaded: {
394
                        item.isCurrentPage= Qt.binding(function() { return tabs.selectedTab == weekTab })
395
                        item.dayStart = tabs.currentDay;
396
                    }
397
398
                    anchors{
399
                        left: parent.left
400
                        right: parent.right
401
                        bottom: parent.bottom
402
                    }
403
404
                    Connections{
405
                        target: weekViewLoader.item
406
                        onDayStartChanged: {
407
                            tabs.currentDay = weekViewLoader.item.dayStart;
408
                        }
409
410
                        onDateSelected: {
411
                            tabs.currentDay = date;
412
                            tabs.selectedTabIndex = dayTab.index;
413
                        }
234.1.1 by Kunal Parmar
Unnecessary Top Page removed
414
                    }
415
                }
416
            }
417
418
            Tab{
419
                id: dayTab
420
                objectName: "dayTab"
421
                title: i18n.tr("Day")
234.1.7 by Kunal Parmar
Loader used to load page
422
                page: Loader{
423
                    id: dayViewLoader
424
                    objectName: "dayViewLoader"
425
                    source: tabs.selectedTab == dayTab ? Qt.resolvedUrl("DayView.qml"):""
426
                    onLoaded: {
427
                        item.isCurrentPage= Qt.binding(function() { return tabs.selectedTab == dayTab })
428
                        item.currentDay = tabs.currentDay;
429
                    }
430
431
                    anchors{
432
                        left: parent.left
433
                        right: parent.right
434
                        bottom: parent.bottom
435
                    }
436
437
                    Connections{
438
                        target: dayViewLoader.item
439
                        onCurrentDayChanged: {
440
                            tabs.currentDay = dayViewLoader.item.currentDay;
441
                        }
63.1.1 by Kunal Parmar
year view implementation
442
                    }
443
                }
444
            }
279.1.1 by Kunal Parmar
Agenda view created
445
446
            Tab {
447
                id: agendaTab
448
                objectName: "agendaTab"
449
                title: i18n.tr("Agenda")
450
                page: Loader {
451
                    id: agendaViewLoader
452
                    objectName: "agendaViewLoader"
453
                    source: tabs.selectedTab == agendaTab ? Qt.resolvedUrl("AgendaView.qml"):""
454
455
                    onLoaded: {
456
                        item.currentDay = tabs.currentDay;
457
                    }
458
459
                    anchors{
460
                        left: parent.left
461
                        right: parent.right
462
                        bottom: parent.bottom
463
                    }
416.1.1 by Kunal Parmar
Agenda view to dayView
464
465
                    Connections{
466
                        target: agendaViewLoader.item
467
                        onDateSelected: {
468
                            tabs.currentDay = date;
469
                            tabs.selectedTabIndex = dayTab.index;
470
                        }
471
                    }
279.1.1 by Kunal Parmar
Agenda view created
472
                }
473
            }
12.2.4 by Kunal Parmar
Broken layout fixes, due to new pagestack changes
474
        }
475
    }
1 by Michael Hall
Initial code template
476
}