Merge lp:~charlesk/indicator-datetime/lp-1293646 into lp:indicator-datetime/14.04

Proposed by Charles Kerr
Status: Merged
Approved by: Ted Gould
Approved revision: 325
Merged at revision: 329
Proposed branch: lp:~charlesk/indicator-datetime/lp-1293646
Merge into: lp:indicator-datetime/14.04
Diff against target: 122 lines (+33/-15)
4 files modified
src/actions.cpp (+4/-1)
src/menu.cpp (+17/-8)
src/planner-upcoming.cpp (+2/-2)
tests/test-actions.cpp (+10/-4)
To merge this branch: bzr merge lp:~charlesk/indicator-datetime/lp-1293646
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Ted Gould (community) Approve
Review via email: mp+212056@code.launchpad.net

Commit message

When clicking onto a different calendar date on the Desktop, show the events for that calendar day starting at the beginning of the day, rather than the current time of day.

Description of the change

When clicking onto a different calendar date on the Desktop, show the events for that calendar day starting at the beginning of the day, rather than the current time of day.

The usual case is on desktop (and /only/ case on phone) is that we're looking at the current date and want to see "the next five calendar events, if any."

However on the Desktop when the user clicks onto a different calendar date, show the next five calendar events starting from the beginning of that clicked day.

To post a comment you must log in.
Revision history for this message
Ted Gould (ted) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
326. By Charles Kerr

sync unit tests with r325

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
327. By Charles Kerr

sync with trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/actions.cpp'
2--- src/actions.cpp 2014-03-10 02:08:47 +0000
3+++ src/actions.cpp 2014-03-21 18:46:08 +0000
4@@ -129,7 +129,10 @@
5
6 g_return_if_fail(t != 0);
7
8- static_cast<Actions*>(gself)->set_calendar_date(DateTime(t));
9+ // the client gave us a date; remove the HMS component from the resulting DateTime
10+ auto dt = DateTime(t);
11+ dt = dt.add_full (0, 0, 0, -dt.hour(), -dt.minute(), -dt.seconds());
12+ static_cast<Actions*>(gself)->set_calendar_date(dt);
13 }
14
15 GVariant* create_default_header_state()
16
17=== modified file 'src/menu.cpp'
18--- src/menu.cpp 2014-03-10 03:32:19 +0000
19+++ src/menu.cpp 2014-03-21 18:46:08 +0000
20@@ -104,6 +104,9 @@
21 m_state->settings->show_events.changed().connect([this](bool){
22 update_section(Appointments); // showing events got toggled
23 });
24+ m_state->calendar_upcoming->date().changed().connect([this](const DateTime&){
25+ update_upcoming(); // our m_upcoming is planner->upcoming() filtered by time
26+ });
27 m_state->calendar_upcoming->appointments().changed().connect([this](const std::vector<Appointment>&){
28 update_upcoming(); // our m_upcoming is planner->upcoming() filtered by time
29 });
30@@ -138,18 +141,24 @@
31
32 void update_upcoming()
33 {
34- // show upcoming appointments that occur after "calendar_next_minute",
35- // where that is the wallclock time on the specified calendar day
36+ // The usual case is on desktop (and /only/ case on phone)
37+ // is that we're looking at the current date and want to see
38+ // "the next five calendar events, if any."
39+ //
40+ // However on the Desktop when the user clicks onto a different
41+ // calendar date, show the next five calendar events starting
42+ // from the beginning of that clicked day.
43+ DateTime begin;
44+ const auto now = m_state->clock->localtime();
45 const auto calendar_day = m_state->calendar_month->month().get();
46- const auto now = m_state->clock->localtime();
47- int y, m, d;
48- calendar_day.ymd(y, m, d);
49- const auto calendar_now = DateTime::Local(y, m, d, now.hour(), now.minute(), now.seconds());
50- const auto calendar_next_minute = calendar_now.add_full(0, 0, 0, 0, 1, -now.seconds());
51+ if ((profile() == Desktop) && !DateTime::is_same_day(now, calendar_day))
52+ begin = calendar_day.add_full (0, 0, 0, -calendar_day.hour(), -calendar_day.minute(), -calendar_day.seconds());
53+ else
54+ begin = now.add_full (0, 0, 0, 0, 0, -now.seconds());
55
56 std::vector<Appointment> upcoming;
57 for(const auto& a : m_state->calendar_upcoming->appointments().get())
58- if (calendar_next_minute <= a.begin)
59+ if (begin <= a.begin)
60 upcoming.push_back(a);
61
62 if (m_upcoming != upcoming)
63
64=== modified file 'src/planner-upcoming.cpp'
65--- src/planner-upcoming.cpp 2014-03-10 02:08:47 +0000
66+++ src/planner-upcoming.cpp 2014-03-21 18:46:08 +0000
67@@ -33,8 +33,8 @@
68 {
69 date().changed().connect([this](const DateTime& dt){
70 // set the range to the upcoming month
71- const auto b = dt.add_full(0, 0, -1, 0, 0, 0);
72- const auto e = dt.add_full(0, 1, 0, 0, 0, 0);
73+ const auto b = dt.add_full(0, 0, -1, -dt.hour(), -dt.minute(), -dt.seconds());
74+ const auto e = b.add_full(0, 1, 0, 0, 0, 0);
75 g_debug("%p setting date range to [%s..%s]", this, b.format("%F %T").c_str(), e.format("%F %T").c_str());
76 m_range_planner->range().set(std::pair<DateTime,DateTime>(b,e));
77 });
78
79=== modified file 'tests/test-actions.cpp'
80--- tests/test-actions.cpp 2014-03-10 02:08:47 +0000
81+++ tests/test-actions.cpp 2014-03-21 18:46:08 +0000
82@@ -153,7 +153,7 @@
83 EXPECT_NE (now, m_state->calendar_month->month().get());
84 auto v = g_variant_new_int64(now.to_unix());
85 g_action_group_activate_action (action_group, action_name, v);
86- EXPECT_EQ (now, m_state->calendar_month->month().get());
87+ EXPECT_TRUE(DateTime::is_same_day (now, m_state->calendar_month->month().get()));
88 }
89
90 TEST_F(ActionsFixture, ActivatingTheCalendarResetsItsDate)
91@@ -171,22 +171,28 @@
92 const auto now = m_state->clock->localtime();
93 auto next_week = g_date_time_add_weeks(now.get(), 1);
94 const auto next_week_unix = g_date_time_to_unix(next_week);
95- g_date_time_unref(next_week);
96 g_action_group_activate_action (action_group, "calendar", g_variant_new_int64(next_week_unix));
97
98 // confirm the planner and calendar action state moved a week into the future
99 // but that m_state->clock is unchanged
100- EXPECT_EQ(next_week_unix, m_state->calendar_month->month().get().to_unix());
101+ auto expected = g_date_time_add_full (next_week, 0, 0, 0, -g_date_time_get_hour(next_week),
102+ -g_date_time_get_minute(next_week),
103+ -g_date_time_get_seconds(next_week));
104+ const auto expected_unix = g_date_time_to_unix(expected);
105+ EXPECT_EQ(expected_unix, m_state->calendar_month->month().get().to_unix());
106 EXPECT_EQ(now, m_state->clock->localtime());
107 auto calendar_state = g_action_group_get_action_state(action_group, "calendar");
108 EXPECT_TRUE(calendar_state != nullptr);
109 EXPECT_TRUE(g_variant_is_of_type(calendar_state, G_VARIANT_TYPE_DICTIONARY));
110 auto v = g_variant_lookup_value(calendar_state, "calendar-day", G_VARIANT_TYPE_INT64);
111 EXPECT_TRUE(v != nullptr);
112- EXPECT_EQ(next_week_unix, g_variant_get_int64(v));
113+ EXPECT_EQ(expected_unix, g_variant_get_int64(v));
114 g_clear_pointer(&v, g_variant_unref);
115 g_clear_pointer(&calendar_state, g_variant_unref);
116
117+ g_date_time_unref(expected);
118+ g_date_time_unref(next_week);
119+
120 ///
121 /// Now the actual test.
122 /// We set the state of 'calendar-active' to true, which should reset the calendar date.

Subscribers

People subscribed via source and target branches