Merge lp:~zsombi/ubuntu-ui-toolkit/alarm-sound-update-fix into lp:ubuntu-ui-toolkit/staging

Proposed by Zsombor Egri
Status: Merged
Approved by: Zsombor Egri
Approved revision: 1234
Merged at revision: 1239
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/alarm-sound-update-fix
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 206 lines (+113/-4)
6 files modified
modules/Ubuntu/Components/plugin/adapters/alarmsadapter_organizer.cpp (+79/-3)
modules/Ubuntu/Components/plugin/adapters/alarmsadapter_p.h (+3/-1)
modules/Ubuntu/Components/plugin/alarmmanager_p.cpp (+8/-0)
modules/Ubuntu/Components/plugin/alarmmanager_p.h (+2/-0)
modules/Ubuntu/Components/plugin/alarmmanager_p_p.h (+4/-0)
tests/unit/tst_alarms/tst_alarms.cpp (+17/-0)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/alarm-sound-update-fix
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Cris Dywan Approve
Nekhelesh Ramananthan Pending
Review via email: mp+233340@code.launchpad.net

Commit message

Organizer audible reminder wasn't updated when Alarm sound changed.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) wrote :

I like.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/Ubuntu/Components/plugin/adapters/alarmsadapter_organizer.cpp'
2--- modules/Ubuntu/Components/plugin/adapters/alarmsadapter_organizer.cpp 2014-08-22 14:48:56 +0000
3+++ modules/Ubuntu/Components/plugin/adapters/alarmsadapter_organizer.cpp 2014-09-04 13:47:23 +0000
4@@ -203,6 +203,15 @@
5 // save the sound as description as the audible reminder may be off
6 if (alarm.changes && AlarmData::Sound) {
7 event.setDescription(alarm.sound.toString());
8+ // update audible reminder as well if alarm is enabled
9+ if (alarm.enabled) {
10+ QOrganizerItemAudibleReminder audible = event.detail(QOrganizerItemDetail::TypeAudibleReminder);
11+ // remove the previous data, otherwise we will have two melodies
12+ event.removeDetail(&audible);
13+ // update sound and save
14+ audible.setDataUrl(alarm.sound);
15+ event.saveDetail(&audible);
16+ }
17 }
18
19 // set repeating, reset recurrence no matter if we had it or not
20@@ -221,7 +230,7 @@
21 rule.setFrequency(QOrganizerRecurrenceRule::Daily);
22 } else if (alarm.days) {
23 rule.setFrequency(QOrganizerRecurrenceRule::Weekly);
24- rule.setDaysOfWeek(daysToSet(alarm));
25+ rule.setDaysOfWeek(daysToSet(alarm.days));
26 }
27 event.setRecurrenceRule(rule);
28 break;
29@@ -274,11 +283,11 @@
30 return UCAlarm::NoError;
31 }
32
33-QSet<Qt::DayOfWeek> AlarmsAdapter::daysToSet(const AlarmData &alarm) const
34+QSet<Qt::DayOfWeek> AlarmsAdapter::daysToSet(int days) const
35 {
36 QSet<Qt::DayOfWeek> result;
37 for (Qt::DayOfWeek day = Qt::Monday; day <= Qt::Sunday; day = static_cast<Qt::DayOfWeek>(static_cast<int>(day) + 1)) {
38- if (alarm.days & (1 << (static_cast<int>(day) - 1)))
39+ if (days & (1 << (static_cast<int>(day) - 1)))
40 result << day;
41 }
42 return result;
43@@ -298,6 +307,73 @@
44 /*-----------------------------------------------------------------------------
45 * Abstract methods
46 */
47+bool AlarmsAdapter::verifyChange(const QVariant &cookie, AlarmData::Change change, const QVariant &value)
48+{
49+ QOrganizerItemId id = cookie.value<QOrganizerItemId>();
50+ QOrganizerTodo todo = static_cast<QOrganizerTodo>(manager->item(id));
51+ if (todo.isEmpty()) {
52+ return false;
53+ }
54+
55+ switch (change) {
56+ case AlarmData::Enabled:
57+ {
58+ QOrganizerItemVisualReminder visual = todo.detail(QOrganizerItemDetail::TypeVisualReminder);
59+ QOrganizerItemAudibleReminder audible = todo.detail(QOrganizerItemDetail::TypeAudibleReminder);
60+ return (visual.isEmpty() && audible.isEmpty()) == value.toBool();
61+ }
62+ case AlarmData::Date:
63+ {
64+ return todo.startDateTime() == value.toDateTime();
65+ }
66+ case AlarmData::Message:
67+ {
68+ return todo.displayLabel() == value.toString();
69+ }
70+ case AlarmData::Sound:
71+ {
72+ // it is enough to check teh audible presence, as they are added/removed in pair with visual reminder
73+ QOrganizerItemAudibleReminder audible = todo.detail(QOrganizerItemDetail::TypeAudibleReminder);
74+ bool result = todo.description() == value.toString();
75+ if (result && !audible.isEmpty()) {
76+ // check whether the reminder has the same sound
77+ result = audible.dataUrl().toString() == value.toString();
78+ }
79+ return result;
80+ }
81+ case AlarmData::Type:
82+ {
83+ QOrganizerRecurrenceRule rule = todo.recurrenceRule();
84+ QOrganizerRecurrenceRule::Frequency frequency = rule.frequency();
85+ UCAlarm::AlarmType type = static_cast<UCAlarm::AlarmType>(value.toInt());
86+ return (type == UCAlarm::OneTime && frequency == QOrganizerRecurrenceRule::Invalid) ||
87+ (type == UCAlarm::Repeating &&
88+ (frequency == QOrganizerRecurrenceRule::Daily ||
89+ frequency == QOrganizerRecurrenceRule::Weekly));
90+ }
91+ case AlarmData::Days:
92+ {
93+ // this only checks the days set
94+ QOrganizerRecurrenceRule rule = todo.recurrenceRule();
95+ QOrganizerRecurrenceRule::Frequency frequency = rule.frequency();
96+ if (frequency == QOrganizerRecurrenceRule::Invalid) {
97+ return false;
98+ }
99+ int days = value.toInt();
100+ if (days == UCAlarm::Daily && frequency == QOrganizerRecurrenceRule::Daily) {
101+ return true;
102+ }
103+ if (frequency == QOrganizerRecurrenceRule::Weekly) {
104+ return rule.daysOfWeek() == daysToSet(days);
105+ }
106+ return false;
107+ }
108+ default:
109+ return false;
110+ break;
111+ }
112+}
113+
114 bool AlarmsAdapter::fetchAlarms()
115 {
116 if (fetchRequest) {
117
118=== modified file 'modules/Ubuntu/Components/plugin/adapters/alarmsadapter_p.h'
119--- modules/Ubuntu/Components/plugin/adapters/alarmsadapter_p.h 2014-08-22 13:01:29 +0000
120+++ modules/Ubuntu/Components/plugin/adapters/alarmsadapter_p.h 2014-09-04 13:47:23 +0000
121@@ -86,9 +86,11 @@
122
123 void organizerEventFromAlarmData(const AlarmData &alarm, QOrganizerTodo &event);
124 int alarmDataFromOrganizerEvent(const QOrganizerTodo &event, AlarmData &alarm);
125- QSet<Qt::DayOfWeek> daysToSet(const AlarmData &alarm) const;
126+ QSet<Qt::DayOfWeek> daysToSet(int days) const;
127 void daysFromSet(AlarmData &alarm, QSet<Qt::DayOfWeek> set);
128
129+ bool verifyChange(const QVariant &cookie, AlarmData::Change change, const QVariant &value);
130+
131 public Q_SLOTS:
132 bool fetchAlarms();
133 void updateAlarms(QList<QOrganizerItemId> list);
134
135=== modified file 'modules/Ubuntu/Components/plugin/alarmmanager_p.cpp'
136--- modules/Ubuntu/Components/plugin/alarmmanager_p.cpp 2014-08-22 11:03:40 +0000
137+++ modules/Ubuntu/Components/plugin/alarmmanager_p.cpp 2014-09-04 13:47:23 +0000
138@@ -59,4 +59,12 @@
139 return d->alarmList;
140 }
141
142+bool AlarmManager::verifyChange(UCAlarm *alarm, AlarmData::Change change, const QVariant &newData)
143+{
144+ Q_D(AlarmManager);
145+ UCAlarmPrivate *pAlarm = UCAlarmPrivate::get(alarm);
146+ return d->verifyChange(pAlarm->rawData.cookie, change, newData);
147+}
148+
149+
150 #include "moc_alarmmanager_p.cpp"
151
152=== modified file 'modules/Ubuntu/Components/plugin/alarmmanager_p.h'
153--- modules/Ubuntu/Components/plugin/alarmmanager_p.h 2014-08-22 11:03:40 +0000
154+++ modules/Ubuntu/Components/plugin/alarmmanager_p.h 2014-09-04 13:47:23 +0000
155@@ -159,6 +159,8 @@
156
157 AlarmList alarms() const;
158
159+ bool verifyChange(UCAlarm *alarm, AlarmData::Change change, const QVariant &newData);
160+
161 Q_SIGNALS:
162 void alarmsChanged();
163 void alarmsUpdated(const QList<QVariant> &cookies);
164
165=== modified file 'modules/Ubuntu/Components/plugin/alarmmanager_p_p.h'
166--- modules/Ubuntu/Components/plugin/alarmmanager_p_p.h 2014-08-22 11:03:40 +0000
167+++ modules/Ubuntu/Components/plugin/alarmmanager_p_p.h 2014-09-04 13:47:23 +0000
168@@ -43,6 +43,10 @@
169 bool completed:1;
170
171 virtual bool fetchAlarms() = 0;
172+
173+ // function to verify whether the given alarm property has a given value set
174+ // used for testing purposes
175+ virtual bool verifyChange(const QVariant &cookie, AlarmData::Change change, const QVariant &value) = 0;
176 };
177
178 AlarmManagerPrivate * createAlarmsAdapter(AlarmManager *alarms);
179
180=== modified file 'tests/unit/tst_alarms/tst_alarms.cpp'
181--- tests/unit/tst_alarms/tst_alarms.cpp 2014-08-22 13:01:29 +0000
182+++ tests/unit/tst_alarms/tst_alarms.cpp 2014-09-04 13:47:23 +0000
183@@ -563,6 +563,23 @@
184 QVERIFY(data.cookie.isValid());
185 QCOMPARE(data.enabled, false);
186 }
187+
188+ void test_change_alarm_sound()
189+ {
190+ UCAlarm alarm(QDateTime::currentDateTime(), UCAlarm::AutoDetect, "test_change_alarm_fields_sound");
191+ alarm.save();
192+ waitForRequest(&alarm);
193+ QVERIFY(containsAlarm(&alarm));
194+
195+ // do the change
196+ alarm.setSound(QUrl("file:///usr/share/sounds/ubuntu/ringtones/Celestial.ogg"));
197+ alarm.save();
198+ waitForRequest(&alarm);
199+ QVERIFY(containsAlarm(&alarm));
200+
201+ //verify whether we have the desired change
202+ QVERIFY(AlarmManager::instance().verifyChange(&alarm, AlarmData::Sound, QVariant::fromValue(alarm.sound())));
203+ }
204 };
205
206 QTEST_MAIN(tst_UCAlarms)

Subscribers

People subscribed via source and target branches