From f09e561c4181f4c03a496f70c1f6cecc0f838419 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 20 Mar 2014 16:17:37 -0500 Subject: 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. --- src/actions.cpp | 5 ++++- src/menu.cpp | 25 +++++++++++++++++-------- src/planner-upcoming.cpp | 4 ++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/actions.cpp b/src/actions.cpp index c9c6286..87adb96 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -129,7 +129,10 @@ void on_calendar_activated(GSimpleAction * /*action*/, g_return_if_fail(t != 0); - static_cast(gself)->set_calendar_date(DateTime(t)); + // the client gave us a date; remove the HMS component from the resulting DateTime + auto dt = DateTime(t); + dt = dt.add_full (0, 0, 0, -dt.hour(), -dt.minute(), -dt.seconds()); + static_cast(gself)->set_calendar_date(dt); } GVariant* create_default_header_state() diff --git a/src/menu.cpp b/src/menu.cpp index 90ef41f..2bfc4aa 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -104,6 +104,9 @@ protected: m_state->settings->show_events.changed().connect([this](bool){ update_section(Appointments); // showing events got toggled }); + m_state->calendar_upcoming->date().changed().connect([this](const DateTime&){ + update_upcoming(); // our m_upcoming is planner->upcoming() filtered by time + }); m_state->calendar_upcoming->appointments().changed().connect([this](const std::vector&){ update_upcoming(); // our m_upcoming is planner->upcoming() filtered by time }); @@ -138,18 +141,24 @@ protected: void update_upcoming() { - // show upcoming appointments that occur after "calendar_next_minute", - // where that is the wallclock time on the specified calendar day - const auto calendar_day = m_state->calendar_month->month().get(); + // 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. + DateTime begin; const auto now = m_state->clock->localtime(); - int y, m, d; - calendar_day.ymd(y, m, d); - const auto calendar_now = DateTime::Local(y, m, d, now.hour(), now.minute(), now.seconds()); - const auto calendar_next_minute = calendar_now.add_full(0, 0, 0, 0, 1, -now.seconds()); + const auto calendar_day = m_state->calendar_month->month().get(); + if ((profile() == Desktop) && !DateTime::is_same_day(now, calendar_day)) + begin = calendar_day.add_full (0, 0, 0, -calendar_day.hour(), -calendar_day.minute(), -calendar_day.seconds()); + else + begin = now.add_full (0, 0, 0, 0, 0, -now.seconds()); std::vector upcoming; for(const auto& a : m_state->calendar_upcoming->appointments().get()) - if (calendar_next_minute <= a.begin) + if (begin <= a.begin) upcoming.push_back(a); if (m_upcoming != upcoming) diff --git a/src/planner-upcoming.cpp b/src/planner-upcoming.cpp index 4e5af6f..ed45955 100644 --- a/src/planner-upcoming.cpp +++ b/src/planner-upcoming.cpp @@ -33,8 +33,8 @@ UpcomingPlanner::UpcomingPlanner(const std::shared_ptr& range_plan { date().changed().connect([this](const DateTime& dt){ // set the range to the upcoming month - const auto b = dt.add_full(0, 0, -1, 0, 0, 0); - const auto e = dt.add_full(0, 1, 0, 0, 0, 0); + const auto b = dt.add_full(0, 0, -1, -dt.hour(), -dt.minute(), -dt.seconds()); + const auto e = b.add_full(0, 1, 0, 0, 0, 0); g_debug("%p setting date range to [%s..%s]", this, b.format("%F %T").c_str(), e.format("%F %T").c_str()); m_range_planner->range().set(std::pair(b,e)); }); -- cgit v1.2.3 From 43196aeedad8604615de338f32d596e9a47fc51b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 20 Mar 2014 17:13:23 -0500 Subject: sync unit tests with r325 --- tests/test-actions.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/test-actions.cpp b/tests/test-actions.cpp index 5d1efd5..d838a52 100644 --- a/tests/test-actions.cpp +++ b/tests/test-actions.cpp @@ -153,7 +153,7 @@ TEST_F(ActionsFixture, SetCalendarDate) EXPECT_NE (now, m_state->calendar_month->month().get()); auto v = g_variant_new_int64(now.to_unix()); g_action_group_activate_action (action_group, action_name, v); - EXPECT_EQ (now, m_state->calendar_month->month().get()); + EXPECT_TRUE(DateTime::is_same_day (now, m_state->calendar_month->month().get())); } TEST_F(ActionsFixture, ActivatingTheCalendarResetsItsDate) @@ -171,22 +171,28 @@ TEST_F(ActionsFixture, ActivatingTheCalendarResetsItsDate) const auto now = m_state->clock->localtime(); auto next_week = g_date_time_add_weeks(now.get(), 1); const auto next_week_unix = g_date_time_to_unix(next_week); - g_date_time_unref(next_week); g_action_group_activate_action (action_group, "calendar", g_variant_new_int64(next_week_unix)); // confirm the planner and calendar action state moved a week into the future // but that m_state->clock is unchanged - EXPECT_EQ(next_week_unix, m_state->calendar_month->month().get().to_unix()); + auto expected = g_date_time_add_full (next_week, 0, 0, 0, -g_date_time_get_hour(next_week), + -g_date_time_get_minute(next_week), + -g_date_time_get_seconds(next_week)); + const auto expected_unix = g_date_time_to_unix(expected); + EXPECT_EQ(expected_unix, m_state->calendar_month->month().get().to_unix()); EXPECT_EQ(now, m_state->clock->localtime()); auto calendar_state = g_action_group_get_action_state(action_group, "calendar"); EXPECT_TRUE(calendar_state != nullptr); EXPECT_TRUE(g_variant_is_of_type(calendar_state, G_VARIANT_TYPE_DICTIONARY)); auto v = g_variant_lookup_value(calendar_state, "calendar-day", G_VARIANT_TYPE_INT64); EXPECT_TRUE(v != nullptr); - EXPECT_EQ(next_week_unix, g_variant_get_int64(v)); + EXPECT_EQ(expected_unix, g_variant_get_int64(v)); g_clear_pointer(&v, g_variant_unref); g_clear_pointer(&calendar_state, g_variant_unref); + g_date_time_unref(expected); + g_date_time_unref(next_week); + /// /// Now the actual test. /// We set the state of 'calendar-active' to true, which should reset the calendar date. -- cgit v1.2.3