aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-01-16 16:45:40 -0600
committerCharles Kerr <charles.kerr@canonical.com>2014-01-16 16:45:40 -0600
commita2b5c79157fa8db36d94786de1b86b756308912d (patch)
tree052475103594dd1b87dcbda97ffed2b8822f2d69
parent9c81a4d60d06b1f33001602cd0cde9844c9233a6 (diff)
downloadayatana-indicator-datetime-a2b5c79157fa8db36d94786de1b86b756308912d.tar.gz
ayatana-indicator-datetime-a2b5c79157fa8db36d94786de1b86b756308912d.tar.bz2
ayatana-indicator-datetime-a2b5c79157fa8db36d94786de1b86b756308912d.zip
Plug the Settings object into the State container s.t. menus and actions can update themselves when the user's settings change.
-rw-r--r--include/datetime/state.h14
-rw-r--r--src/actions.cpp4
-rw-r--r--src/menu.cpp20
-rw-r--r--tests/test-menus.cc4
4 files changed, 16 insertions, 26 deletions
diff --git a/include/datetime/state.h b/include/datetime/state.h
index a82bb4b..e735b6f 100644
--- a/include/datetime/state.h
+++ b/include/datetime/state.h
@@ -21,9 +21,10 @@
#define INDICATOR_DATETIME_STATE_H
#include <datetime/clock.h>
-#include <datetime/timezones.h>
-#include <datetime/planner.h>
#include <datetime/locations.h>
+#include <datetime/planner.h>
+#include <datetime/settings.h>
+#include <datetime/timezones.h>
#include <core/property.h>
@@ -47,18 +48,17 @@ namespace datetime {
* @see Clock
* @see Planner
* @see Locations
+ * @see Settings
*/
struct State
{
- std::shared_ptr<Timezones> timezones;
std::shared_ptr<Clock> clock;
- std::shared_ptr<Planner> planner;
std::shared_ptr<Locations> locations;
+ std::shared_ptr<Planner> planner;
+ std::shared_ptr<Settings> settings;
+ std::shared_ptr<Timezones> timezones;
- core::Property<bool> show_events;
- core::Property<bool> show_clock;
core::Property<DateTime> calendar_day;
- core::Property<bool> show_week_numbers;
};
} // namespace datetime
diff --git a/src/actions.cpp b/src/actions.cpp
index 4efe950..52ee1eb 100644
--- a/src/actions.cpp
+++ b/src/actions.cpp
@@ -154,12 +154,12 @@ GVariant* create_calendar_state(std::shared_ptr<State>& state)
g_variant_builder_add(&dict_builder, "{sv}", key, v);
key = "show-week-numbers";
- v = g_variant_new_boolean(state->show_week_numbers.get());
+ v = g_variant_new_boolean(state->settings->show_week_numbers.get());
g_variant_builder_add(&dict_builder, "{sv}", key, v);
return g_variant_builder_end(&dict_builder);
}
-} // anonymous namespace
+} // unnamed namespace
/***
****
diff --git a/src/menu.cpp b/src/menu.cpp
index 76306cc..c81f185 100644
--- a/src/menu.cpp
+++ b/src/menu.cpp
@@ -69,11 +69,11 @@ protected:
update_section(Appointments); // uses formatter.getRelativeFormat()
update_section(Locations); // uses formatter.getRelativeFormat()
});
- m_state->show_clock.changed().connect([this](bool){
+ m_state->settings->show_clock.changed().connect([this](bool){
update_header(); // update header's label
update_section(Locations); // locations' relative time may have changed
});
- m_state->show_events.changed().connect([this](bool){
+ m_state->settings->show_events.changed().connect([this](bool){
update_section(Appointments); // showing events got toggled
});
m_state->planner->upcoming.changed().connect([this](const std::vector<Appointment>&){
@@ -261,7 +261,7 @@ private:
{
auto menu = g_menu_new();
- if (((profile==Phone) || (profile==Desktop)) && m_state->show_events.get())
+ if (((profile==Phone) || (profile==Desktop)) && m_state->settings->show_events.get())
{
add_appointments (menu, profile);
@@ -363,14 +363,14 @@ protected:
std::shared_ptr<State>& state_,
std::shared_ptr<Actions>& actions_):
MenuImpl(profile_, name_, state_, actions_,
- std::shared_ptr<Formatter>(new DesktopFormatter(state_->clock)))
+ std::shared_ptr<Formatter>(new DesktopFormatter(state_->clock, state_->settings)))
{
update_header();
}
GVariant* create_header_state()
{
- const auto visible = m_state->show_clock.get();
+ const auto visible = m_state->settings->show_clock.get();
const auto title = _("Date and Time");
auto label = g_variant_new_string(m_formatter->header.get().c_str());
@@ -472,32 +472,22 @@ std::shared_ptr<Menu>
MenuFactory::buildMenu(Menu::Profile profile)
{
std::shared_ptr<Menu> menu;
- m_state->show_clock.set (true); // FIXME
-
- //std::shared_ptr<State> state(new State);
- //state->clock = clock;
- //state->planner = planner;
- //state->locations = locations;
switch (profile)
{
case Menu::Desktop:
- m_state->show_events.set(true); // FIXME
menu.reset(new DesktopMenu(m_state, m_actions));
break;
case Menu::DesktopGreeter:
- m_state->show_events.set(true); // FIXME
menu.reset(new DesktopGreeterMenu(m_state, m_actions));
break;
case Menu::Phone:
- m_state->show_events.set(true); // FIXME
menu.reset(new PhoneMenu(m_state, m_actions));
break;
case Menu::PhoneGreeter:
- m_state->show_events.set(false); // FIXME
menu.reset(new PhoneGreeterMenu(m_state, m_actions));
break;
diff --git a/tests/test-menus.cc b/tests/test-menus.cc
index 88e4706..0f86b0d 100644
--- a/tests/test-menus.cc
+++ b/tests/test-menus.cc
@@ -170,7 +170,7 @@ protected:
auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU);
// there shouldn't be any menuitems when "show events" is false
- m_state->show_events.set(false);
+ m_state->settings->show_events.set(false);
wait_msec();
auto section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION);
EXPECT_EQ(0, g_menu_model_get_n_items(section));
@@ -179,7 +179,7 @@ protected:
// when "show_events" is true,
// there should be an "add event" button even if there aren't any appointments
std::vector<Appointment> appointments;
- m_state->show_events.set(true);
+ m_state->settings->show_events.set(true);
m_state->planner->upcoming.set(appointments);
wait_msec();
section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION);