Merge lp:~rpadovani/ubuntu-calendar-app/1231136 into lp:ubuntu-calendar-app

Proposed by Riccardo Padovani
Status: Merged
Approved by: Alan Pope 🍺🐧🐱 πŸ¦„
Approved revision: 136
Merged at revision: 155
Proposed branch: lp:~rpadovani/ubuntu-calendar-app/1231136
Merge into: lp:ubuntu-calendar-app
Diff against target: 224 lines (+159/-9)
3 files modified
NewEvent.qml (+13/-6)
calendar-app.desktop (+1/-1)
calendar.qml (+145/-2)
To merge this branch: bzr merge lp:~rpadovani/ubuntu-calendar-app/1231136
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Mihir Soni Approve
Charles Kerr (community) Approve
Ted Gould (community) Approve
Review via email: mp+188002@code.launchpad.net

Commit message

Fixed #1231136, add support for Arguments

Description of the change

Added support for three arguments:
--newevent, to open new event popup

If --newevent is set:
 --starttime, to set start time of new event
 --endtime, to set end time of new event. It has to be > of start time. If start time is not set, it's ignored

If --newevent is not set:
 --starttime, to open calendar in a precise day
 --endtime, to choose the view

If endtime - starttime > month, year view is open
If entdime - starttime > week, month view is open
If endtime - starttime > day, week view is open

--endtime and --starttime accept integer value of the number of seconds since UNIX epoch in the UTC timezone.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ted Gould (ted) wrote :

Hello Riccardo,

Thanks for working on this! The big issue I see is that the calendar app itself needs to be the one to parse the URL, we don't do that externally. So the exec line needs to look something like:

Exec=qmlscene /usr/share/calendar-app/calendar.qml %u

So then the URL will get passed onto the application. The QUrl() branch provides some functions for dealing with URLs that should make this a bit easier.

Ted

review: Needs Fixing
Revision history for this message
David Planella (dpm) wrote :

Ted, could you point us to the QUrl() branch? Where does that live?

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ted Gould (ted) wrote :

Here are the docs on QUrl:

http://qt-project.org/doc/qt-5.0/qtcore/qurl.html

What you need your exec line to look like is something like this:

Exec=qmlscene /usr/share/calendar-app/calendar.qml %u

Then the actual call will be:

qmlscene /usr/share/calendar-app/calendar.qml calendar:///?starttime=20130913

So the only argument will be the URL itself, you can then use QUrl to help break that down into the values you need.

Revision history for this message
Riccardo Padovani (rpadovani) wrote :

I implemented it, but due to bug #1231558 we have to pass args before command:
qmlscene calendar:///?starttime=1234567889 /usr/share/calendar-app/calendar.qml

I implemented starttime and endtime with value as number of seconds since UNIX epoch in the UTC timezone.

https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1231558

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ted Gould (ted) wrote :

The desktop file and arguments comments look correct.

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

I see that this MP is blocked awaiting my review.

The approach looks sane and the coding is fine; I'm happy enough to Approve on that level.

From an indicator-datetime perspective, I don't have much of substance to add to this review. The indicator doesn't know or care what the contents of the calendar:/// url are as long as it can be fetched from EDS and dispatched via url-dispatcher.

review: Approve
Revision history for this message
Mihir Soni (mihirsoni) wrote :

Riccardo , can you remove the changes in manifest.json , I don't know why everybody is facing this issue.

Revision history for this message
Mihir Soni (mihirsoni) wrote :

Thank you Riccardo ,

it looks fine to me

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
136. By Riccardo Padovani

Fixed newEvent

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NewEvent.qml'
2--- NewEvent.qml 2013-10-15 15:01:07 +0000
3+++ NewEvent.qml 2013-10-16 14:15:26 +0000
4@@ -10,17 +10,24 @@
5 id: root
6
7 property var date: new Date();
8- property var startDate: date
9- property var endDate: date
10+ property var startDate;
11+ property var endDate;
12+
13 property alias scrollY: flickable.contentY
14
15 Component.onCompleted: {
16+ // If startDate is setted by argument we have to not change it
17+ if (typeof(startDate) === 'undefined')
18+ startDate = new Date(date)
19+
20+ // If endDate is setted by argument we have to not change it
21+ if (typeof(endDate) === 'undefined') {
22+ endDate = new Date(date)
23+ endDate.setMinutes( endDate.getMinutes() + 10)
24+ }
25+
26 internal.eventModel = GlobalModel.gloablModel();
27
28- startDate = new Date(date)
29- endDate = new Date(date)
30- endDate.setMinutes( endDate.getMinutes() + 10)
31-
32 startTime.text = Qt.formatDateTime(startDate, "dd MMM yyyy hh:mm");
33 endTime.text = Qt.formatDateTime(endDate, "dd MMM yyyy hh:mm");
34 }
35
36=== modified file 'calendar-app.desktop'
37--- calendar-app.desktop 2013-06-12 15:23:13 +0000
38+++ calendar-app.desktop 2013-10-16 14:15:26 +0000
39@@ -3,7 +3,7 @@
40 Version=1.0
41 Type=Application
42 Terminal=false
43-Exec=qmlscene /usr/share/calendar-app/calendar.qml
44+Exec=qmlscene %u /usr/share/calendar-app/calendar.qml
45 Icon=/usr/share/calendar-app/calendar64.png
46 Name=Calendar
47 X-Ubuntu-Touch=true
48
49=== modified file 'calendar.qml'
50--- calendar.qml 2013-10-15 15:01:07 +0000
51+++ calendar.qml 2013-10-16 14:15:26 +0000
52@@ -8,6 +8,46 @@
53 MainView {
54 id: mainView
55
56+ // Argument during startup
57+ Arguments {
58+ id: args;
59+
60+ // Example of argument: calendar:///new-event
61+
62+ // IMPORTANT
63+ // Due to bug #1231558 you have to pass arguments BEFORE app:
64+ // qmlscene calendar:///new-event calendar.qml
65+
66+ 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");
67+ //defaultArgument.required: false;
68+ defaultArgument.valueNames: ["URL"]
69+
70+ /* ARGUMENTS on startup
71+ * (no one is required)
72+ *
73+ * Create a new event
74+ * Keyword: newevent
75+ *
76+ * Create a new event. If starttime or endtime are set they are used to set start and end time of the new event.
77+ * It accepts no value.
78+ *
79+ *
80+ * Choose the view
81+ * Keyword: starttime
82+ *
83+ * If newevent has been called, starttime is the start time of event. Otherwise is the day on which app is focused on startup.
84+ * It accepts an integer value of the number of seconds since UNIX epoch in the UTC timezone.
85+ * 0 means today.
86+ *
87+ * Keyword: endtime
88+ *
89+ * If newevent is set it's the end time of the event, has to be > of starttime.
90+ * If newevent isn't set and startime is set, its value is used to choose the right view.
91+ * If neither of precendet flags are set, endtime is ignored.
92+ * It accepts an integer value of the number of seconds since UNIX epoch in the UTC timezone.
93+ */
94+ }
95+
96 objectName: "calendar"
97 applicationName: "com.ubuntu.calendar"
98
99@@ -30,6 +70,11 @@
100 property var currentDay: DateExt.today();
101 property var globalModel;
102
103+ // Arguments on startup
104+ property bool newevent: false;
105+ property int starttime: -1;
106+ property int endtime: -1;
107+
108 onCurrentDayChanged: {
109 if( monthView.currentMonth !== undefined && !monthView.currentMonth.isSameDay(currentDay))
110 monthView.currentMonth = currentDay.midnight();
111@@ -51,13 +96,111 @@
112 }
113
114 function newEvent() {
115- PopupUtils.open(newEventComponent, tabPage, {"defaultDate": currentDay})
116+ var startDate = new Date();
117+ var endDate = new Date();
118+ var startTime;
119+ var endTime;
120+
121+ if (starttime === 0) { // startime 0 means now
122+ if (endtime !== -1) { // If also endtime has been invoked
123+ endTime = parseInt(endtime);
124+ if (endTime > startDate) // If endtime is after startime
125+ endDate = new Date(endTime);
126+ }
127+ }
128+ else if (starttime !== -1) { // If starttime has been invoked
129+ startTime = parseInt(starttime);
130+ startDate = new Date(startTime);
131+ if (endtime !== -1) { // If --endtime has been invoked
132+ endTime = parseInt(endtime);
133+ if (endTime > startDate)
134+ endDate = new Date(endTime);
135+ }
136+ }
137+ pageStack.push(Qt.resolvedUrl("NewEvent.qml"),{"startDate": startDate, "endDate": endDate});
138+ }
139+
140+ // This function calculate the difference between --endtime and --starttime and choose the better view
141+ function calculateDifferenceStarttimeEndtime(startTime, endTime) {
142+ var minute = 60 * 1000;
143+ var hour = 60 * minute;
144+ var day = 24 * hour;
145+ var month = 30 * day;
146+
147+ var difference = endTime - startTime;
148+
149+ if (difference > month)
150+ return 0; // Year view
151+ else if (difference > 7 * day)
152+ return 1; // Month view}
153+ else if (difference > day)
154+ return 2; // Week view
155+ else
156+ return 3; // Day view
157+ }
158+
159+ // This function parse the argument
160+ function parseArguments(url) {
161+ var newevenpattern= new RegExp ("newevent");
162+ var starttimepattern = new RegExp ("starttime=\\d+");
163+ var endtimepattern = new RegExp ("endtime=\\d+");
164+
165+ newevent = newevenpattern.test(url);
166+
167+ if (starttimepattern.test(url))
168+ starttime = url.match(/starttime=(\d+)/)[0].replace("starttime=", '');
169+
170+ if (endtimepattern.test(url))
171+ endtime = url.match(/endtime=(\d+)/)[0].replace("endtime=", '');
172+
173 }
174
175 Component.onCompleted: {
176+ // If an url has been set
177+ if (args.defaultArgument.at(0)) {
178+ parseArguments(args.defaultArgument.at(0))
179+ tabPage.currentDay = new Date()
180+ // If newevent has been called on startup
181+ if (newevent) {
182+ timer.running = true;
183+ }
184+ else if (starttime !== -1) { // If no newevent has been setted, but starttime
185+ var startTime = parseInt(starttime);
186+ tabPage.currentDay = new Date(startTime);
187+
188+ // If also endtime has been settend
189+ if (endtime !== -1) {
190+ var endTime = parseInt(endtime);
191+ tabs.selectedTabIndex = calculateDifferenceStarttimeEndtime(startTime, endTime);
192+ }
193+ else {
194+ // If no endtime has been setted, open the starttime date in day view
195+ tabs.selectedTabIndex = 3;
196+ }
197+ } // End of else if (starttime)
198+ else {
199+ // Due to bug #1231558 {if (args.defaultArgument.at(0))} is always true
200+ // After the fix we can delete this else
201+ tabs.selectedTabIndex= 1;
202+ }
203+ } // End of if about args.values
204+ else {
205+ tabs.selectedTabIndex= 1;
206+ }
207+
208 globalModel = GlobalModel.gloablModel();
209 setStartEndDateToModel();
210- tabs.selectedTabIndex = 1;
211+ } // End of Component.onCompleted:
212+
213+ // This is for wait that the app is load when newEvent is invoked by argument
214+ Timer {
215+ id: timer
216+ interval: 200;
217+ running: false;
218+ repeat: false
219+ onTriggered: {
220+ tabPage.newEvent();
221+ }
222 }
223
224 ToolbarItems {

Subscribers

People subscribed via source and target branches

to status/vote changes: