Merge lp:~renatofilho/indicator-datetime/hide-non-selected-sources into lp:indicator-datetime

Proposed by Renato Araujo Oliveira Filho
Status: Merged
Approved by: Charles Kerr
Approved revision: 452
Merged at revision: 454
Proposed branch: lp:~renatofilho/indicator-datetime/hide-non-selected-sources
Merge into: lp:indicator-datetime
Diff against target: 147 lines (+127/-0)
3 files modified
src/engine-eds.cpp (+5/-0)
tests/test-eds-ics-non-selected-source.cpp (+94/-0)
tests/test-eds-ics-non-selected-source.ics.in (+28/-0)
To merge this branch: bzr merge lp:~renatofilho/indicator-datetime/hide-non-selected-sources
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+297350@code.launchpad.net

Commit message

Does not show events from non selected sources.

Description of the change

How to test:

1 - Add your google account to calendar app
2 - Make sure to sync your calendar events
3 - Check if the next 4 events appear on the indicator
4 - Go to calendar app "calendars" page and unselect your google calendar
5 - Make sure that the events get removed from indicator

To post a comment you must log in.
Revision history for this message
Charles Kerr (charlesk) wrote :

Looks okay to me, but a couple of caveats:

1. Most important, agree with what you said in IRC about adding integration tests

2. I haven't done manual testing with this

3. If there's a bug associated with this MR, it should be linked

452. By Renato Araujo Oliveira Filho

Implemented unit test.

Revision history for this message
Charles Kerr (charlesk) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/engine-eds.cpp'
2--- src/engine-eds.cpp 2016-05-14 02:07:10 +0000
3+++ src/engine-eds.cpp 2016-06-21 21:40:23 +0000
4@@ -120,6 +120,11 @@
5
6 auto& source = kv.first;
7 auto extension = e_source_get_extension(source, E_SOURCE_EXTENSION_CALENDAR);
8+ // check source is selected
9+ if (!e_source_selectable_get_selected(E_SOURCE_SELECTABLE(extension))) {
10+ g_debug("Soure is not selected, ignore it: %s", e_source_get_display_name(source));
11+ continue;
12+ }
13 const auto color = e_source_selectable_get_color(E_SOURCE_SELECTABLE(extension));
14
15 e_cal_client_generate_instances(
16
17=== added file 'tests/test-eds-ics-non-selected-source.cpp'
18--- tests/test-eds-ics-non-selected-source.cpp 1970-01-01 00:00:00 +0000
19+++ tests/test-eds-ics-non-selected-source.cpp 2016-06-21 21:40:23 +0000
20@@ -0,0 +1,94 @@
21+/*
22+ * Copyright 2015 Canonical Ltd.
23+ *
24+ * This program is free software: you can redistribute it and/or modify it
25+ * under the terms of the GNU General Public License version 3, as published
26+ * by the Free Software Foundation.
27+ *
28+ * This program is distributed in the hope that it will be useful, but
29+ * WITHOUT ANY WARRANTY; without even the implied warranties of
30+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
31+ * PURPOSE. See the GNU General Public License for more details.
32+ *
33+ * You should have received a copy of the GNU General Public License along
34+ * with this program. If not, see <http://www.gnu.org/licenses/>.
35+ *
36+ * Authors:
37+ * Renato Araujo Oliveira Filh <renato.filho@canonical.com>
38+ */
39+
40+#include <algorithm>
41+
42+#include <datetime/engine-eds.h>
43+#include <datetime/myself.h>
44+#include <datetime/planner-range.h>
45+
46+#include <libedataserver/libedataserver.h>
47+
48+#include <gtest/gtest.h>
49+
50+#include "glib-fixture.h"
51+#include "timezone-mock.h"
52+
53+using namespace unity::indicator::datetime;
54+using VAlarmFixture = GlibFixture;
55+
56+/***
57+****
58+***/
59+
60+TEST_F(VAlarmFixture, NonSelectedSources)
61+{
62+ // start the EDS engine
63+ auto engine = std::make_shared<EdsEngine>(std::make_shared<Myself>());
64+
65+ // we need a consistent timezone for the planner and our local DateTimes
66+ constexpr char const * zone_str {"America/Chicago"};
67+ auto tz = std::make_shared<MockTimezone>(zone_str);
68+ auto gtz = g_time_zone_new(zone_str);
69+
70+ // make a planner that looks at the first half of 2015 in EDS
71+ auto planner = std::make_shared<SimpleRangePlanner>(engine, tz);
72+ const DateTime range_begin {gtz, 2015,1, 1, 0, 0, 0.0};
73+ const DateTime range_end {gtz, 2015,6,31,23,59,59.5};
74+ planner->range().set(std::make_pair(range_begin, range_end));
75+
76+ // give EDS a moment to load
77+ if (planner->appointments().get().empty()) {
78+ g_message("waiting a moment for EDS to load...");
79+ auto on_appointments_changed = [this](const std::vector<Appointment>& appointments){
80+ g_message("ah, they loaded");
81+ if (!appointments.empty())
82+ g_main_loop_quit(loop);
83+ };
84+ core::ScopedConnection conn(planner->appointments().changed().connect(on_appointments_changed));
85+ constexpr int max_wait_sec = 10;
86+ wait_msec(max_wait_sec * G_TIME_SPAN_MILLISECOND);
87+ }
88+
89+ // appointmes are visible
90+ auto appts = planner->appointments().get();
91+ EXPECT_TRUE(appts.size() > 0);
92+
93+ // Unselect all sources
94+ auto registry = e_source_registry_new_sync(NULL, NULL);
95+ auto sources = e_source_registry_list_sources(registry, E_SOURCE_EXTENSION_TASK_LIST);
96+ for (auto l=sources; l!=nullptr; l=l->next) {
97+ auto source = static_cast<ESource*>(l->data);
98+ auto extension = e_source_get_extension(source, E_SOURCE_EXTENSION_CALENDAR);
99+ e_source_selectable_set_selected(E_SOURCE_SELECTABLE(extension), FALSE);
100+ e_source_write_sync(source, NULL, NULL);
101+ }
102+
103+ g_list_free_full(sources, g_object_unref);
104+ g_object_unref(registry);
105+
106+ // give some time to planner update
107+ wait_msec(5 * G_TIME_SPAN_MILLISECOND);
108+
109+ // the planner should be empty at this point
110+ appts = planner->appointments().get();
111+ EXPECT_TRUE(appts.size() == 0);
112+ // cleanup
113+ g_time_zone_unref(gtz);
114+}
115
116=== added file 'tests/test-eds-ics-non-selected-source.ics.in'
117--- tests/test-eds-ics-non-selected-source.ics.in 1970-01-01 00:00:00 +0000
118+++ tests/test-eds-ics-non-selected-source.ics.in 2016-06-21 21:40:23 +0000
119@@ -0,0 +1,28 @@
120+BEGIN:VCALENDAR
121+CALSCALE:GREGORIAN
122+PRODID:-//Ximian//NONSGML Evolution Calendar//EN
123+VERSION:2.0
124+X-EVOLUTION-DATA-REVISION:2015-05-07T21:14:49.315443Z(0)
125+BEGIN:VTODO
126+UID:20150507T211449Z-4262-32011-1418-1@ubuntu-phablet
127+DTSTAMP:20150508T211449Z
128+DTSTART:20150508T164000
129+RRULE:FREQ=WEEKLY;BYDAY=FR
130+SUMMARY:Alarm
131+CATEGORIES:x-canonical-alarm
132+CREATED:20150507T211449Z
133+LAST-MODIFIED:20150507T211449Z
134+BEGIN:VALARM
135+X-EVOLUTION-ALARM-UID:20150507T211449Z-4262-32011-1418-2@ubuntu-phablet
136+ACTION:AUDIO
137+ATTACH:file://@ALARM_DEFAULT_SOUND@
138+TRIGGER;VALUE=DURATION;RELATED=START:PT0S
139+END:VALARM
140+BEGIN:VALARM
141+X-EVOLUTION-ALARM-UID:20150507T211449Z-4262-32011-1418-3@ubuntu-phablet
142+ACTION:DISPLAY
143+DESCRIPTION:Alarm
144+TRIGGER;VALUE=DURATION;RELATED=START:PT0S
145+END:VALARM
146+END:VTODO
147+END:VCALENDAR

Subscribers

People subscribed via source and target branches