312.5.6
by Charles Kerr
decouple the planner's states; need three separate sets: upcoming-now (for alarms in the current time), upcoming-calendar (to show events coming from the selected calendar date), and calendar-month (all the appointments in the month displayed in the menu). |
1 |
/*
|
2 |
* Copyright 2014 Canonical Ltd.
|
|
3 |
*
|
|
4 |
* This program is free software: you can redistribute it and/or modify it
|
|
5 |
* under the terms of the GNU General Public License version 3, as published
|
|
6 |
* by the Free Software Foundation.
|
|
7 |
*
|
|
8 |
* This program is distributed in the hope that it will be useful, but
|
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranties of
|
|
10 |
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
|
|
11 |
* PURPOSE. See the GNU General Public License for more details.
|
|
12 |
*
|
|
13 |
* You should have received a copy of the GNU General Public License along
|
|
14 |
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
15 |
*
|
|
16 |
* Authors:
|
|
17 |
* Charles Kerr <charles.kerr@canonical.com>
|
|
18 |
*/
|
|
19 |
||
20 |
#include <datetime/planner-range.h> |
|
21 |
||
22 |
namespace unity { |
|
23 |
namespace indicator { |
|
24 |
namespace datetime { |
|
25 |
||
26 |
/***
|
|
27 |
****
|
|
28 |
***/
|
|
29 |
||
312.6.1
by Charles Kerr
don't connect to EDS when running in the greeter. |
30 |
SimpleRangePlanner::SimpleRangePlanner(const std::shared_ptr<Engine>& engine, |
375.3.4
by Charles Kerr
in SimpleRangePlanner, re-query the engine for appointments when the local timezone changes. |
31 |
const std::shared_ptr<Timezone>& timezone): |
312.6.1
by Charles Kerr
don't connect to EDS when running in the greeter. |
32 |
m_engine(engine), |
33 |
m_timezone(timezone), |
|
312.5.6
by Charles Kerr
decouple the planner's states; need three separate sets: upcoming-now (for alarms in the current time), upcoming-calendar (to show events coming from the selected calendar date), and calendar-month (all the appointments in the month displayed in the menu). |
34 |
m_range(std::pair<DateTime,DateTime>(DateTime::NowLocal(), DateTime::NowLocal())) |
35 |
{
|
|
312.6.1
by Charles Kerr
don't connect to EDS when running in the greeter. |
36 |
engine->changed().connect([this](){ |
340.3.2
by Charles Kerr
hw alarms |
37 |
g_debug("RangePlanner %p rebuilding soon because Engine %p emitted 'changed' signal", this, m_engine.get()); |
312.6.1
by Charles Kerr
don't connect to EDS when running in the greeter. |
38 |
rebuild_soon(); |
39 |
});
|
|
40 |
||
375.3.4
by Charles Kerr
in SimpleRangePlanner, re-query the engine for appointments when the local timezone changes. |
41 |
m_timezone->timezone.changed().connect([this](const std::string& s){ |
42 |
g_debug("RangePlanner %p rebuilding soon because the timezone changed to '%s'", this, s.c_str()); |
|
43 |
rebuild_soon(); |
|
44 |
});
|
|
45 |
||
312.5.6
by Charles Kerr
decouple the planner's states; need three separate sets: upcoming-now (for alarms in the current time), upcoming-calendar (to show events coming from the selected calendar date), and calendar-month (all the appointments in the month displayed in the menu). |
46 |
range().changed().connect([this](const std::pair<DateTime,DateTime>&){ |
47 |
g_debug("rebuilding because the date range changed"); |
|
48 |
rebuild_soon(); |
|
49 |
});
|
|
50 |
}
|
|
51 |
||
312.6.1
by Charles Kerr
don't connect to EDS when running in the greeter. |
52 |
SimpleRangePlanner::~SimpleRangePlanner() |
312.5.6
by Charles Kerr
decouple the planner's states; need three separate sets: upcoming-now (for alarms in the current time), upcoming-calendar (to show events coming from the selected calendar date), and calendar-month (all the appointments in the month displayed in the menu). |
53 |
{
|
54 |
if (m_rebuild_tag) |
|
55 |
g_source_remove(m_rebuild_tag); |
|
56 |
}
|
|
57 |
||
312.6.1
by Charles Kerr
don't connect to EDS when running in the greeter. |
58 |
/***
|
59 |
****
|
|
60 |
***/
|
|
61 |
||
62 |
void SimpleRangePlanner::rebuild_now() |
|
63 |
{
|
|
64 |
const auto& r = range().get(); |
|
65 |
||
66 |
auto on_appointments_fetched = [this](const std::vector<Appointment>& a){ |
|
67 |
g_debug("RangePlanner %p got %zu appointments", this, a.size()); |
|
68 |
appointments().set(a); |
|
69 |
};
|
|
70 |
||
71 |
m_engine->get_appointments(r.first, r.second, *m_timezone.get(), on_appointments_fetched); |
|
72 |
}
|
|
73 |
||
74 |
void SimpleRangePlanner::rebuild_soon() |
|
312.5.6
by Charles Kerr
decouple the planner's states; need three separate sets: upcoming-now (for alarms in the current time), upcoming-calendar (to show events coming from the selected calendar date), and calendar-month (all the appointments in the month displayed in the menu). |
75 |
{
|
76 |
static const int ARBITRARY_BATCH_MSEC = 200; |
|
77 |
||
78 |
if (m_rebuild_tag == 0) |
|
79 |
m_rebuild_tag = g_timeout_add(ARBITRARY_BATCH_MSEC, rebuild_now_static, this); |
|
80 |
}
|
|
81 |
||
312.6.1
by Charles Kerr
don't connect to EDS when running in the greeter. |
82 |
gboolean SimpleRangePlanner::rebuild_now_static(gpointer gself) |
312.5.6
by Charles Kerr
decouple the planner's states; need three separate sets: upcoming-now (for alarms in the current time), upcoming-calendar (to show events coming from the selected calendar date), and calendar-month (all the appointments in the month displayed in the menu). |
83 |
{
|
312.6.1
by Charles Kerr
don't connect to EDS when running in the greeter. |
84 |
auto self = static_cast<SimpleRangePlanner*>(gself); |
312.5.6
by Charles Kerr
decouple the planner's states; need three separate sets: upcoming-now (for alarms in the current time), upcoming-calendar (to show events coming from the selected calendar date), and calendar-month (all the appointments in the month displayed in the menu). |
85 |
self->m_rebuild_tag = 0; |
86 |
self->rebuild_now(); |
|
87 |
return G_SOURCE_REMOVE; |
|
88 |
}
|
|
89 |
||
312.6.1
by Charles Kerr
don't connect to EDS when running in the greeter. |
90 |
/***
|
91 |
****
|
|
92 |
***/
|
|
93 |
||
94 |
core::Property<std::vector<Appointment>>& SimpleRangePlanner::appointments() |
|
95 |
{
|
|
96 |
return m_appointments; |
|
97 |
}
|
|
98 |
||
99 |
core::Property<std::pair<DateTime,DateTime>>& SimpleRangePlanner::range() |
|
312.5.6
by Charles Kerr
decouple the planner's states; need three separate sets: upcoming-now (for alarms in the current time), upcoming-calendar (to show events coming from the selected calendar date), and calendar-month (all the appointments in the month displayed in the menu). |
100 |
{
|
101 |
return m_range; |
|
102 |
}
|
|
103 |
||
104 |
/***
|
|
105 |
****
|
|
106 |
***/
|
|
107 |
||
108 |
} // namespace datetime |
|
109 |
} // namespace indicator |
|
110 |
} // namespace unity |