~acerisara/ubuntu-calendar-app/failing-tests

« back to all changes in this revision

Viewing changes to calendar.qml

  • Committer: Tarmac
  • Author(s): Riccardo Padovani
  • Date: 2013-10-16 16:51:57 UTC
  • mfrom: (122.2.14 1231136)
  • Revision ID: tarmac-20131016165157-l8ipxrxxzw4hty6r
Fixed #1231136, add support for Arguments. Fixes: https://bugs.launchpad.net/bugs/1231136.

Approved by Ubuntu Phone Apps Jenkins Bot, Mihir Soni, Charles Kerr, Ted Gould.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
MainView {
9
9
    id: mainView
10
10
 
 
11
    // Argument during startup
 
12
    Arguments {
 
13
        id: args;
 
14
 
 
15
        // Example of argument: calendar:///new-event
 
16
 
 
17
        // IMPORTANT
 
18
        // Due to bug #1231558 you have to pass arguments BEFORE app:
 
19
        // qmlscene calendar:///new-event calendar.qml
 
20
 
 
21
        defaultArgument.help: i18n.tr("Calendar app accept three arguments: --starttime, --endtime and --newevet. They will be managed by system. See the source for a full comment about them");
 
22
        //defaultArgument.required: false;
 
23
        defaultArgument.valueNames: ["URL"]
 
24
 
 
25
        /* ARGUMENTS on startup
 
26
         * (no one is required)
 
27
         *
 
28
         * Create a new event
 
29
         * Keyword: newevent
 
30
         *
 
31
         * Create a new event. If starttime or endtime are set they are used to set start and end time of the new event.
 
32
         * It accepts no value.
 
33
         *
 
34
         *
 
35
         * Choose the view
 
36
         * Keyword: starttime
 
37
         *
 
38
         * If newevent has been called, starttime is the start time of event. Otherwise is the day on which app is focused on startup.
 
39
         * It accepts an integer value of the number of seconds since UNIX epoch in the UTC timezone.
 
40
         * 0 means today.
 
41
         *
 
42
         * Keyword: endtime
 
43
         *
 
44
         * If newevent is set it's the end time of the event, has to be > of starttime.
 
45
         * If newevent isn't set and startime is set, its value is used to choose the right view.
 
46
         * If neither of precendet flags are set, endtime is ignored.
 
47
         * It accepts an integer value of the number of seconds since UNIX epoch in the UTC timezone.
 
48
         */
 
49
    }
 
50
 
11
51
    objectName: "calendar"
12
52
    applicationName: "com.ubuntu.calendar"
13
53
 
30
70
            property var currentDay: DateExt.today();
31
71
            property var globalModel;
32
72
 
 
73
            // Arguments on startup
 
74
            property bool newevent: false;
 
75
            property int starttime: -1;
 
76
            property int endtime: -1;
 
77
 
33
78
            onCurrentDayChanged: {
34
79
                if( monthView.currentMonth !== undefined && !monthView.currentMonth.isSameDay(currentDay))
35
80
                    monthView.currentMonth = currentDay.midnight();
51
96
            }
52
97
 
53
98
            function newEvent() {
54
 
                 PopupUtils.open(newEventComponent, tabPage, {"defaultDate": currentDay})
 
99
                var startDate = new Date();
 
100
                var endDate = new Date();
 
101
                var startTime;
 
102
                var endTime;
 
103
 
 
104
                if (starttime === 0) { // startime 0 means now
 
105
                    if (endtime !== -1) { // If also endtime has been invoked
 
106
                        endTime = parseInt(endtime);
 
107
                        if (endTime > startDate) // If endtime is after startime
 
108
                            endDate = new Date(endTime);
 
109
                    }
 
110
                }
 
111
                else if (starttime !== -1) { // If starttime has been invoked
 
112
                    startTime = parseInt(starttime);
 
113
                    startDate = new Date(startTime);
 
114
                    if (endtime !== -1) { // If --endtime has been invoked
 
115
                        endTime = parseInt(endtime);
 
116
                        if (endTime > startDate)
 
117
                            endDate = new Date(endTime);
 
118
                    }
 
119
                }
 
120
                pageStack.push(Qt.resolvedUrl("NewEvent.qml"),{"startDate": startDate, "endDate": endDate});
 
121
            }
 
122
 
 
123
            // This function calculate the difference between --endtime and --starttime and choose the better view
 
124
            function calculateDifferenceStarttimeEndtime(startTime, endTime) {
 
125
                var minute = 60 * 1000;
 
126
                var hour = 60 * minute;
 
127
                var day = 24 * hour;
 
128
                var month = 30 * day;
 
129
 
 
130
                var difference = endTime - startTime;
 
131
 
 
132
                if (difference > month)
 
133
                    return 0;   // Year view
 
134
                else if (difference > 7 * day)
 
135
                    return 1;   // Month view}
 
136
                else if (difference > day)
 
137
                    return 2;   // Week view
 
138
                else
 
139
                    return 3;   // Day view
 
140
            }
 
141
 
 
142
            // This function parse the argument
 
143
            function parseArguments(url) {
 
144
                var newevenpattern= new RegExp ("newevent");
 
145
                var starttimepattern = new RegExp ("starttime=\\d+");
 
146
                var endtimepattern = new RegExp ("endtime=\\d+");
 
147
 
 
148
                newevent = newevenpattern.test(url);
 
149
 
 
150
                if (starttimepattern.test(url))
 
151
                    starttime = url.match(/starttime=(\d+)/)[0].replace("starttime=", '');
 
152
 
 
153
                if (endtimepattern.test(url))
 
154
                    endtime = url.match(/endtime=(\d+)/)[0].replace("endtime=", '');
 
155
 
55
156
            }
56
157
 
57
158
            Component.onCompleted: {
 
159
                // If an url has been set
 
160
                if (args.defaultArgument.at(0)) {
 
161
                    parseArguments(args.defaultArgument.at(0))
 
162
                    tabPage.currentDay = new Date()
 
163
                    // If newevent has been called on startup
 
164
                    if (newevent) {
 
165
                        timer.running = true;
 
166
                    }
 
167
                    else if (starttime !== -1) { // If no newevent has been setted, but starttime
 
168
                        var startTime = parseInt(starttime);
 
169
                        tabPage.currentDay = new Date(startTime);
 
170
 
 
171
                        // If also endtime has been settend
 
172
                        if (endtime !== -1) {
 
173
                            var endTime = parseInt(endtime);
 
174
                            tabs.selectedTabIndex = calculateDifferenceStarttimeEndtime(startTime, endTime);
 
175
                        }
 
176
                        else {
 
177
                            // If no endtime has been setted, open the starttime date in day view
 
178
                            tabs.selectedTabIndex = 3;
 
179
                        }
 
180
                    } // End of else if (starttime)
 
181
                    else {
 
182
                        // Due to bug #1231558 {if (args.defaultArgument.at(0))} is always true
 
183
                        // After the fix we can delete this else
 
184
                        tabs.selectedTabIndex= 1;
 
185
                    }
 
186
                } // End of if about args.values
 
187
                else {
 
188
                    tabs.selectedTabIndex= 1;
 
189
                }
 
190
 
58
191
                globalModel = GlobalModel.gloablModel();
59
192
                setStartEndDateToModel();
60
 
                tabs.selectedTabIndex = 1;
 
193
            } // End of Component.onCompleted:
 
194
 
 
195
            // This is for wait that the app is load when newEvent is invoked by argument
 
196
            Timer {
 
197
                id: timer
 
198
                interval: 200;
 
199
                running: false;
 
200
                repeat: false
 
201
                onTriggered: {
 
202
                    tabPage.newEvent();
 
203
                }
61
204
            }
62
205
 
63
206
            ToolbarItems {