From ee64bb2698adfe27e55615a8856b0e2c78ad8469 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 14 Jan 2014 23:07:10 -0600 Subject: Function: add fully-tested ActionGroups, per-profile Menus, state object. Form: Add code annotations/comments. Remove dead code. Use Mir style guide. Todo: GSettings toggles, sync with new dbus-test-runner API, get GNOME Panel building again --- src/menu.cpp | 518 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 518 insertions(+) create mode 100644 src/menu.cpp (limited to 'src/menu.cpp') diff --git a/src/menu.cpp b/src/menu.cpp new file mode 100644 index 0000000..76306cc --- /dev/null +++ b/src/menu.cpp @@ -0,0 +1,518 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/**** +***** +****/ + +#define ALARM_CLOCK_ICON_NAME "alarm-clock" +#define CALENDAR_ICON_NAME "calendar" + +class MenuImpl: public Menu +{ +protected: + MenuImpl(const Menu::Profile profile_in, + const std::string& name_in, + std::shared_ptr& state, + std::shared_ptr& actions, + std::shared_ptr formatter): + Menu(profile_in, name_in), + m_state(state), + m_actions(actions), + m_formatter(formatter) + { + // initialize the menu + create_gmenu(); + for (int i=0; iheader.changed().connect([this](const std::string&){ + update_header(); + }); + m_formatter->headerFormat.changed().connect([this](const std::string&){ + update_section(Locations); // need to update x-canonical-time-format + }); + m_formatter->relativeFormatChanged.connect([this](){ + update_section(Appointments); // uses formatter.getRelativeFormat() + update_section(Locations); // uses formatter.getRelativeFormat() + }); + m_state->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){ + update_section(Appointments); // showing events got toggled + }); + m_state->planner->upcoming.changed().connect([this](const std::vector&){ + update_section(Appointments); // "upcoming" is the list of Appointments we show + }); + m_state->clock->dateChanged.connect([this](){ + update_section(Calendar); // need to update the Date menuitem + update_section(Locations); // locations' relative time may have changed + }); + m_state->locations->locations.changed().connect([this](const std::vector&) { + update_section(Locations); // "locations" is the list of Locations we show + }); + } + + virtual ~MenuImpl() + { + g_clear_object(&m_menu); + g_clear_pointer(&m_serialized_alarm_icon, g_variant_unref); + g_clear_pointer(&m_serialized_calendar_icon, g_variant_unref); + } + + virtual GVariant* create_header_state() =0; + + void update_header() + { + auto action_group = m_actions->action_group(); + auto action_name = name() + "-header"; + auto state = create_header_state(); + g_action_group_change_action_state(action_group, action_name.c_str(), state); + } + + std::shared_ptr m_state; + std::shared_ptr m_actions; + std::shared_ptr m_formatter; + GMenu* m_submenu = nullptr; + + GVariant* get_serialized_alarm_icon() + { + if (G_UNLIKELY(m_serialized_alarm_icon == nullptr)) + { + auto i = g_themed_icon_new_with_default_fallbacks(ALARM_CLOCK_ICON_NAME); + m_serialized_alarm_icon = g_icon_serialize(i); + g_object_unref(i); + } + + return m_serialized_alarm_icon; + } + +private: + + GVariant* get_serialized_calendar_icon() + { + if (G_UNLIKELY(m_serialized_calendar_icon == nullptr)) + { + auto i = g_themed_icon_new_with_default_fallbacks(CALENDAR_ICON_NAME); + m_serialized_calendar_icon = g_icon_serialize(i); + g_object_unref(i); + } + + return m_serialized_calendar_icon; + } + + void create_gmenu() + { + g_assert(m_submenu == nullptr); + + m_submenu = g_menu_new(); + + // build placeholders for the sections + for(int i=0; iclock->localtime().format(_("%A, %e %B %Y")); + auto item = g_menu_item_new (label.c_str(), nullptr); + auto v = get_serialized_calendar_icon(); + g_menu_item_set_attribute_value (item, G_MENU_ATTRIBUTE_ICON, v); + if (allow_activation) + { + v = g_variant_new_int64(0); + const char* action = "indicator.activate-planner"; + g_menu_item_set_action_and_target_value (item, action, v); + } + g_menu_append_item(menu, item); + g_object_unref(item); + + // add calendar + if (show_calendar) + { + item = g_menu_item_new ("[calendar]", NULL); + v = g_variant_new_int64(0); + g_menu_item_set_action_and_target_value (item, "indicator.calendar", v); + g_menu_item_set_attribute (item, "x-canonical-type", + "s", "com.canonical.indicator.calendar"); + if (allow_activation) + { + g_menu_item_set_attribute (item, "activation-action", + "s", "indicator.activate-planner"); + } + g_menu_append_item (menu, item); + g_object_unref (item); + } + + return G_MENU_MODEL(menu); + } + + void add_appointments(GMenu* menu, Profile profile) + { + int n = 0; + const int MAX_APPTS = 5; + std::set added; + + for (const auto& appt : m_state->planner->upcoming.get()) + { + if (n++ >= MAX_APPTS) + break; + + if (added.count(appt.uid)) + continue; + + added.insert(appt.uid); + + GDateTime* begin = appt.begin(); + GDateTime* end = appt.end(); + auto fmt = m_formatter->getRelativeFormat(begin, end); + auto unix_time = g_date_time_to_unix(begin); + + auto menu_item = g_menu_item_new (appt.summary.c_str(), nullptr); + g_menu_item_set_attribute (menu_item, "x-canonical-time", "x", unix_time); + g_menu_item_set_attribute (menu_item, "x-canonical-time-format", "s", fmt.c_str()); + + if (appt.has_alarms) + { + g_menu_item_set_attribute (menu_item, "x-canonical-type", "s", "com.canonical.indicator.alarm"); + g_menu_item_set_attribute_value(menu_item, G_MENU_ATTRIBUTE_ICON, get_serialized_alarm_icon()); + } + else + { + g_menu_item_set_attribute (menu_item, "x-canonical-type", "s", "com.canonical.indicator.appointment"); + + if (!appt.color.empty()) + g_menu_item_set_attribute (menu_item, "x-canonical-color", "s", appt.color.c_str()); + } + + if (profile == Phone) + g_menu_item_set_action_and_target_value (menu_item, + "indicator.activate-appointment", + g_variant_new_string (appt.uid.c_str())); + else + g_menu_item_set_action_and_target_value (menu_item, + "indicator.activate-planner", + g_variant_new_int64 (unix_time)); + g_menu_append_item (menu, menu_item); + g_object_unref (menu_item); + } + } + + GMenuModel* create_appointments_section(Profile profile) + { + auto menu = g_menu_new(); + + if (((profile==Phone) || (profile==Desktop)) && m_state->show_events.get()) + { + add_appointments (menu, profile); + + // add the 'Add Event…' menuitem + auto menu_item = g_menu_item_new(_("Add Event…"), nullptr); + const gchar* action_name = "indicator.activate_planner"; + auto v = g_variant_new_int64(0); + g_menu_item_set_action_and_target_value(menu_item, action_name, v); + g_menu_append_item(menu, menu_item); + g_object_unref(menu_item); + } + + return G_MENU_MODEL(menu); + } + + GMenuModel* create_locations_section(Profile profile) + { + GMenu* menu = g_menu_new(); + + if (profile == Desktop) + { + const auto now = m_state->clock->localtime(); + + for(const auto& location : m_state->locations->locations.get()) + { + const auto& zone = location.zone(); + const auto& name = location.name(); + const auto zone_now = now.to_timezone(zone); + const auto fmt = m_formatter->getRelativeFormat(zone_now.get()); + auto detailed_action = g_strdup_printf("indicator.set-location::%s %s", zone.c_str(), name.c_str()); + auto i = g_menu_item_new (name.c_str(), detailed_action); + g_menu_item_set_attribute(i, "x-canonical-type", "s", "com.canonical.indicator.location"); + g_menu_item_set_attribute(i, "x-canonical-timezone", "s", zone.c_str()); + g_menu_item_set_attribute(i, "x-canonical-time-format", "s", fmt.c_str()); + g_menu_append_item (menu, i); + g_object_unref(i); + g_free(detailed_action); + } + } + + return G_MENU_MODEL(menu); + } + + GMenuModel* create_settings_section(Profile profile) + { + auto menu = g_menu_new(); + + if (profile == Desktop) + { + g_menu_append (menu, _("Date & Time Settings…"), "indicator.activate-desktop-settings"); + } + else if (profile == Phone) + { + g_menu_append (menu, _("Time & Date settings…"), "indicator.activate-phone-settings"); + } + + return G_MENU_MODEL (menu); + } + + void update_section(Section section) + { + GMenuModel * model; + const auto p = profile(); + + switch (section) + { + case Calendar: model = create_calendar_section(p); break; + case Appointments: model = create_appointments_section(p); break; + case Locations: model = create_locations_section(p); break; + case Settings: model = create_settings_section(p); break; + default: g_warn_if_reached(); + } + + if (model) + { + g_menu_remove(m_submenu, section); + g_menu_insert_section(m_submenu, section, nullptr, model); + g_object_unref(model); + } + } + +//private: + GVariant * m_serialized_alarm_icon = nullptr; + GVariant * m_serialized_calendar_icon = nullptr; + +}; // class MenuImpl + + + +/*** +**** +***/ + +class DesktopBaseMenu: public MenuImpl +{ +protected: + DesktopBaseMenu(Menu::Profile profile_, + const std::string& name_, + std::shared_ptr& state_, + std::shared_ptr& actions_): + MenuImpl(profile_, name_, state_, actions_, + std::shared_ptr(new DesktopFormatter(state_->clock))) + { + update_header(); + } + + GVariant* create_header_state() + { + const auto visible = m_state->show_clock.get(); + const auto title = _("Date and Time"); + auto label = g_variant_new_string(m_formatter->header.get().c_str()); + + GVariantBuilder b; + g_variant_builder_init(&b, G_VARIANT_TYPE_VARDICT); + g_variant_builder_add(&b, "{sv}", "accessible-desc", label); + g_variant_builder_add(&b, "{sv}", "label", label); + g_variant_builder_add(&b, "{sv}", "title", g_variant_new_string(title)); + g_variant_builder_add(&b, "{sv}", "visible", g_variant_new_boolean(visible)); + return g_variant_builder_end(&b); + } +}; + +class DesktopMenu: public DesktopBaseMenu +{ +public: + DesktopMenu(std::shared_ptr& state_, std::shared_ptr& actions_): + DesktopBaseMenu(Desktop,"desktop", state_, actions_) {} +}; + +class DesktopGreeterMenu: public DesktopBaseMenu +{ +public: + DesktopGreeterMenu(std::shared_ptr& state_, std::shared_ptr& actions_): + DesktopBaseMenu(DesktopGreeter,"desktop-greeter", state_, actions_) {} +}; + +class PhoneBaseMenu: public MenuImpl +{ +protected: + PhoneBaseMenu(Menu::Profile profile_, + const std::string& name_, + std::shared_ptr& state_, + std::shared_ptr& actions_): + MenuImpl(profile_, name_, state_, actions_, + std::shared_ptr(new PhoneFormatter(state_->clock))) + { + update_header(); + } + + GVariant* create_header_state() + { + // are there alarms? + bool has_alarms = false; + for(const auto& appointment : m_state->planner->upcoming.get()) + if((has_alarms = appointment.has_alarms)) + break; + + GVariantBuilder b; + g_variant_builder_init(&b, G_VARIANT_TYPE_VARDICT); + g_variant_builder_add(&b, "{sv}", "title", g_variant_new_string (_("Upcoming"))); + g_variant_builder_add(&b, "{sv}", "visible", g_variant_new_boolean (TRUE)); + if (has_alarms) + { + auto label = m_formatter->header.get(); + auto a11y = g_strdup_printf(_("%s (has alarms)"), label.c_str()); + g_variant_builder_add(&b, "{sv}", "label", g_variant_new_string(label.c_str())); + g_variant_builder_add(&b, "{sv}", "accessible-desc", g_variant_new_take_string(a11y)); + g_variant_builder_add(&b, "{sv}", "icon", get_serialized_alarm_icon()); + } + else + { + auto v = g_variant_new_string(m_formatter->header.get().c_str()); + g_variant_builder_add(&b, "{sv}", "label", v); + g_variant_builder_add(&b, "{sv}", "accessible-desc", v); + } + return g_variant_builder_end (&b); + } +}; + +class PhoneMenu: public PhoneBaseMenu +{ +public: + PhoneMenu(std::shared_ptr& state_, + std::shared_ptr& actions_): + PhoneBaseMenu(Phone, "phone", state_, actions_) {} +}; + +class PhoneGreeterMenu: public PhoneBaseMenu +{ +public: + PhoneGreeterMenu(std::shared_ptr& state_, + std::shared_ptr& actions_): + PhoneBaseMenu(PhoneGreeter, "phone-greeter", state_, actions_) {} +}; + +/**** +***** +****/ + +MenuFactory::MenuFactory(std::shared_ptr& actions_, + std::shared_ptr& state_): + m_actions(actions_), + m_state(state_) +{ +} + +std::shared_ptr +MenuFactory::buildMenu(Menu::Profile profile) +{ + std::shared_ptr menu; + m_state->show_clock.set (true); // FIXME + + //std::shared_ptr 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; + + default: + g_warn_if_reached(); + break; + } + + return menu; +} + +/**** +***** +****/ + +} // namespace datetime +} // namespace indicator +} // namespace unity -- cgit v1.2.3 From a2b5c79157fa8db36d94786de1b86b756308912d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 16 Jan 2014 16:45:40 -0600 Subject: Plug the Settings object into the State container s.t. menus and actions can update themselves when the user's settings change. --- include/datetime/state.h | 14 +++++++------- src/actions.cpp | 4 ++-- src/menu.cpp | 20 +++++--------------- tests/test-menus.cc | 4 ++-- 4 files changed, 16 insertions(+), 26 deletions(-) (limited to 'src/menu.cpp') 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 -#include -#include #include +#include +#include +#include #include @@ -47,18 +48,17 @@ namespace datetime { * @see Clock * @see Planner * @see Locations + * @see Settings */ struct State { - std::shared_ptr timezones; std::shared_ptr clock; - std::shared_ptr planner; std::shared_ptr locations; + std::shared_ptr planner; + std::shared_ptr settings; + std::shared_ptr timezones; - core::Property show_events; - core::Property show_clock; core::Property calendar_day; - core::Property 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) 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&){ @@ -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_, std::shared_ptr& actions_): MenuImpl(profile_, name_, state_, actions_, - std::shared_ptr(new DesktopFormatter(state_->clock))) + std::shared_ptr(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 MenuFactory::buildMenu(Menu::Profile profile) { std::shared_ptr menu; - m_state->show_clock.set (true); // FIXME - - //std::shared_ptr 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 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); -- cgit v1.2.3 From 6e447b7bdb1273048dbaf9ead0eea629e73042e3 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 08:08:44 -0600 Subject: plug in the greeter menus --- src/exporter.cpp | 4 +++- src/main.cpp | 3 ++- src/menu.cpp | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'src/menu.cpp') diff --git a/src/exporter.cpp b/src/exporter.cpp index aa021f3..8103b5b 100644 --- a/src/exporter.cpp +++ b/src/exporter.cpp @@ -85,13 +85,15 @@ Exporter::on_bus_acquired(GDBusConnection* connection, const gchar* /*name*/) { const auto path = std::string(BUS_PATH) + "/" + menu->name(); const auto id = g_dbus_connection_export_menu_model(m_dbus_connection, path.c_str(), menu->menu_model(), &error); +g_message ("path %s id %d", path.c_str(), (int)id); if (id) { m_exported_menu_ids.insert(id); } else { - g_warning("cannot export %s menu: %s", menu->name().c_str(), error->message); + if (error != nullptr) + g_warning("cannot export %s menu: %s", menu->name().c_str(), error->message); g_clear_error(&error); } } diff --git a/src/main.cpp b/src/main.cpp index 50d5241..2c4f160 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,7 +54,8 @@ main(int /*argc*/, char** /*argv*/) // create the menus std::vector> menus; - menus.push_back(factory.buildMenu(Menu::Desktop)); + for(int i=0, n=Menu::NUM_PROFILES; i& state_, std::shared_ptr& actions_): - DesktopBaseMenu(DesktopGreeter,"desktop-greeter", state_, actions_) {} + DesktopBaseMenu(DesktopGreeter,"desktop_greeter", state_, actions_) {} }; class PhoneBaseMenu: public MenuImpl @@ -454,7 +454,7 @@ class PhoneGreeterMenu: public PhoneBaseMenu public: PhoneGreeterMenu(std::shared_ptr& state_, std::shared_ptr& actions_): - PhoneBaseMenu(PhoneGreeter, "phone-greeter", state_, actions_) {} + PhoneBaseMenu(PhoneGreeter, "phone_greeter", state_, actions_) {} }; /**** -- cgit v1.2.3 From 56e036200e389f74064836ea2e3254a8b9bc267f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 08:35:54 -0600 Subject: the clock icon should match the one used by the clock app, so use click to ask the clock app which icon it's using --- src/exporter.cpp | 1 - src/menu.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 54 insertions(+), 9 deletions(-) (limited to 'src/menu.cpp') diff --git a/src/exporter.cpp b/src/exporter.cpp index 8103b5b..86e3670 100644 --- a/src/exporter.cpp +++ b/src/exporter.cpp @@ -85,7 +85,6 @@ Exporter::on_bus_acquired(GDBusConnection* connection, const gchar* /*name*/) { const auto path = std::string(BUS_PATH) + "/" + menu->name(); const auto id = g_dbus_connection_export_menu_model(m_dbus_connection, path.c_str(), menu->menu_model(), &error); -g_message ("path %s id %d", path.c_str(), (int)id); if (id) { m_exported_menu_ids.insert(id); diff --git a/src/menu.cpp b/src/menu.cpp index 43e07ae..5b19d92 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include #include @@ -53,6 +55,9 @@ protected: m_actions(actions), m_formatter(formatter) { + // preload the alarm icon from click + m_serialized_alarm_icon = create_alarm_icon(); + // initialize the menu create_gmenu(); for (int i=0; i m_formatter; GMenu* m_submenu = nullptr; - GVariant* get_serialized_alarm_icon() + GVariant* get_serialized_alarm_icon() { return m_serialized_alarm_icon; } + +private: + + /* try to get the clock app's filename from click. (/$pkgdir/$icon) */ + static GVariant* create_alarm_icon() { - if (G_UNLIKELY(m_serialized_alarm_icon == nullptr)) + GVariant* serialized = nullptr; + gchar* icon_filename = nullptr; + gchar* standard_error = nullptr; + gchar* pkgdir = nullptr; + + g_spawn_command_line_sync("click pkgdir com.ubuntu.clock", &pkgdir, &standard_error, nullptr, nullptr); + g_clear_pointer(&standard_error, g_free); + if (pkgdir != nullptr) { - auto i = g_themed_icon_new_with_default_fallbacks(ALARM_CLOCK_ICON_NAME); - m_serialized_alarm_icon = g_icon_serialize(i); - g_object_unref(i); + gchar* manifest = nullptr; + g_strstrip(pkgdir); + g_spawn_command_line_sync("click info com.ubuntu.clock", &manifest, &standard_error, nullptr, nullptr); + g_clear_pointer(&standard_error, g_free); + if (manifest != nullptr) + { + JsonParser* parser = json_parser_new(); + if (json_parser_load_from_data(parser, manifest, -1, nullptr)) + { + JsonNode* root = json_parser_get_root(parser); /* transfer-none */ + if ((root != nullptr) && (JSON_NODE_TYPE(root) == JSON_NODE_OBJECT)) + { + JsonObject* o = json_node_get_object(root); /* transfer-none */ + const gchar* icon_name = json_object_get_string_member(o, "icon"); + if (icon_name != nullptr) + icon_filename = g_build_filename(pkgdir, icon_name, nullptr); + } + } + g_object_unref(parser); + g_free(manifest); + } + g_free(pkgdir); } - return m_serialized_alarm_icon; - } + if (icon_filename != nullptr) + { + GFile* file = g_file_new_for_path(icon_filename); + GIcon* icon = g_file_icon_new(file); -private: + serialized = g_icon_serialize(icon); + + g_object_unref(icon); + g_object_unref(file); + g_free(icon_filename); + } + + return serialized; + } GVariant* get_serialized_calendar_icon() { -- cgit v1.2.3 From b4a6c506a38e5e9d364a3909eb4aeeed91ed36c8 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 09:53:27 -0600 Subject: copyediting: omit unnecessary #includes --- src/menu.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/menu.cpp') diff --git a/src/menu.cpp b/src/menu.cpp index 5b19d92..503d47c 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -19,12 +19,8 @@ #include -#include #include -#include -#include #include -#include #include -- cgit v1.2.3 From 47ab9adad438b137b5e7e9b33ce503e184e019f8 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 09:57:52 -0600 Subject: follow-up to r326, if we can't get the alarm icon from click, use a sane fallback icon --- src/menu.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/menu.cpp') diff --git a/src/menu.cpp b/src/menu.cpp index 503d47c..9e76d4b 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -35,7 +35,7 @@ namespace datetime { ***** ****/ -#define ALARM_CLOCK_ICON_NAME "alarm-clock" +#define FALLBACK_ALARM_CLOCK_ICON_NAME "clock" #define CALENDAR_ICON_NAME "calendar" class MenuImpl: public Menu @@ -163,8 +163,15 @@ private: g_free(icon_filename); } + if (serialized == nullptr) + { + auto i = g_themed_icon_new_with_default_fallbacks(FALLBACK_ALARM_CLOCK_ICON_NAME); + serialized = g_icon_serialize(i); + g_object_unref(i); + } + return serialized; - } + } GVariant* get_serialized_calendar_icon() { -- cgit v1.2.3 From e57a2e9b860db9776d94356a6fc38e193c801f65 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 28 Jan 2014 11:50:50 -0600 Subject: silence compiler warning --- src/menu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/menu.cpp') diff --git a/src/menu.cpp b/src/menu.cpp index 9e76d4b..390a06f 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -381,7 +381,7 @@ private: case Appointments: model = create_appointments_section(p); break; case Locations: model = create_locations_section(p); break; case Settings: model = create_settings_section(p); break; - default: g_warn_if_reached(); + default: model = nullptr; g_warn_if_reached(); } if (model) -- cgit v1.2.3 From f07f97ef53522abdce52cf3c7b583c0d6d47aa40 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 29 Jan 2014 12:50:59 -0600 Subject: sync with lp:~larsu/indicator-datetime/reset-date and add corresponding unit tests. --- src/actions.cpp | 20 ++++++++++++++++--- src/menu.cpp | 2 ++ tests/test-actions.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 3 deletions(-) (limited to 'src/menu.cpp') diff --git a/src/actions.cpp b/src/actions.cpp index a6a7c0b..acf8fd4 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -108,9 +108,22 @@ void on_set_location(GSimpleAction * /*action*/, g_free(zone); } -static void on_calendar_activated(GSimpleAction * /*action*/, - GVariant * state, - gpointer gself) +void on_calendar_active_changed(GSimpleAction * /*action*/, + GVariant * state, + gpointer gself) +{ + // reset the date when the menu is shown + if (g_variant_get_boolean(state)) + { + auto self = static_cast(gself); + + self->set_calendar_date(self->state()->clock->localtime()); + } +} + +void on_calendar_activated(GSimpleAction * /*action*/, + GVariant * state, + gpointer gself) { const time_t t = g_variant_get_int64(state); @@ -175,6 +188,7 @@ Actions::Actions(const std::shared_ptr& state): { "activate-phone-clock-app", on_phone_clock_activated }, { "activate-appointment", on_activate_appointment, "s", nullptr }, { "activate-planner", on_activate_planner, "x", nullptr }, + { "calendar-active", nullptr, nullptr, "false", on_calendar_active_changed }, { "set-location", on_set_location, "s" } }; diff --git a/src/menu.cpp b/src/menu.cpp index 390a06f..b0ba79d 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -204,6 +204,8 @@ private: auto header = g_menu_item_new(nullptr, detailed_action.c_str()); g_menu_item_set_attribute(header, "x-canonical-type", "s", "com.canonical.indicator.root"); + g_menu_item_set_attribute(header, "submenu-action", "s", + "indicator.calendar-active"); g_menu_item_set_submenu(header, G_MENU_MODEL(m_submenu)); g_object_unref(m_submenu); diff --git a/tests/test-actions.cpp b/tests/test-actions.cpp index c30d1fb..1865cfd 100644 --- a/tests/test-actions.cpp +++ b/tests/test-actions.cpp @@ -156,6 +156,60 @@ TEST_F(ActionsFixture, SetCalendarDate) EXPECT_EQ (now, m_state->planner->time.get()); } +TEST_F(ActionsFixture, ActivatingTheCalendarResetsItsDate) +{ + // Confirm that the GActions exist + auto action_group = m_actions->action_group(); + EXPECT_TRUE(g_action_group_has_action(action_group, "calendar")); + EXPECT_TRUE(g_action_group_has_action(action_group, "calendar-active")); + + /// + /// Prerequisite for the test: move calendar-date away from today + /// + + // move calendar-date a week into the future... + 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_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->planner->time.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)); + g_clear_pointer(&v, g_variant_unref); + g_clear_pointer(&calendar_state, g_variant_unref); + + /// + /// Now the actual test. + /// We set the state of 'calendar-active' to true, which should reset the calendar date. + /// This is so the calendar always starts on today's date when the indicator's menu is pulled down. + /// + + // change the state... + g_action_group_change_action_state(action_group, "calendar-active", g_variant_new_boolean(true)); + + // confirm the planner and calendar action state were reset back to m_state->clock's time + EXPECT_EQ(now.to_unix(), m_state->planner->time.get().to_unix()); + EXPECT_EQ(now, m_state->clock->localtime()); + 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)); + v = g_variant_lookup_value(calendar_state, "calendar-day", G_VARIANT_TYPE_INT64); + EXPECT_TRUE(v != nullptr); + EXPECT_EQ(now.to_unix(), g_variant_get_int64(v)); + g_clear_pointer(&v, g_variant_unref); + g_clear_pointer(&calendar_state, g_variant_unref); + +} + + TEST_F(ActionsFixture, OpenAppointment) { Appointment appt; -- cgit v1.2.3 From 6b2c01ed6063bd7fd12e192668b738a075dc3a24 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 29 Jan 2014 16:10:50 -0600 Subject: fix instant calendar toggle issue reported in testing by seb128; add a test for this regression --- src/menu.cpp | 7 +++++-- tests/test-menus.cpp | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src/menu.cpp') diff --git a/src/menu.cpp b/src/menu.cpp index b0ba79d..40a94fa 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -74,6 +74,9 @@ protected: update_header(); // update header's label update_section(Locations); // locations' relative time may have changed }); + m_state->settings->show_calendar.changed().connect([this](bool){ + update_section(Calendar); + }); m_state->settings->show_events.changed().connect([this](bool){ update_section(Appointments); // showing events got toggled }); @@ -219,8 +222,8 @@ private: { const bool allow_activation = (profile == Desktop) || (profile == Phone); - const bool show_calendar = (profile == Desktop) - || (profile == DesktopGreeter); + const bool show_calendar = m_state->settings->show_calendar.get() && + ((profile == Desktop) || (profile == DesktopGreeter)); auto menu = g_menu_new(); // add a menuitem that shows the current date diff --git a/tests/test-menus.cpp b/tests/test-menus.cpp index fe1e86e..27248ad 100644 --- a/tests/test-menus.cpp +++ b/tests/test-menus.cpp @@ -93,7 +93,8 @@ protected: { gchar* str = nullptr; const auto actions_expected = (profile == Menu::Desktop) || (profile == Menu::Phone); - const auto calendar_expected = (profile == Menu::Desktop) || (profile == Menu::DesktopGreeter); + const auto calendar_expected = ((profile == Menu::Desktop) || (profile == Menu::DesktopGreeter)) + && (m_state->settings->show_calendar.get()); // get the calendar section auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU); @@ -377,6 +378,11 @@ TEST_F(MenuFixture, Sections) TEST_F(MenuFixture, Calendar) { + m_state->settings->show_calendar.set(true); + for(auto& menu : m_menus) + InspectCalendar(menu->menu_model(), menu->profile()); + + m_state->settings->show_calendar.set(false); for(auto& menu : m_menus) InspectCalendar(menu->menu_model(), menu->profile()); } -- cgit v1.2.3 From 131f7512975e3e0e1363cb787834abee5b79b4e5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 29 Jan 2014 16:26:25 -0600 Subject: fix disabled 'Add Event…' menuitem issue reported in testing by seb128; add a test for this regression MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/menu.cpp | 2 +- tests/test-menus.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'src/menu.cpp') diff --git a/src/menu.cpp b/src/menu.cpp index 40a94fa..44da7b7 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -321,7 +321,7 @@ private: // add the 'Add Event…' menuitem auto menu_item = g_menu_item_new(_("Add Event…"), nullptr); - const gchar* action_name = "indicator.activate_planner"; + const gchar* action_name = "indicator.activate-planner"; auto v = g_variant_new_int64(0); g_menu_item_set_action_and_target_value(menu_item, action_name, v); g_menu_append_item(menu, menu_item); diff --git a/tests/test-menus.cpp b/tests/test-menus.cpp index 27248ad..e9dd7df 100644 --- a/tests/test-menus.cpp +++ b/tests/test-menus.cpp @@ -182,6 +182,14 @@ protected: section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION); int expected_n = appointments_expected ? 1 : 0; EXPECT_EQ(expected_n, g_menu_model_get_n_items(section)); + if (appointments_expected) + { + gchar* action = nullptr; + EXPECT_TRUE(g_menu_model_get_item_attribute(section, 0, G_MENU_ATTRIBUTE_ACTION, "s", &action)); + EXPECT_STREQ("indicator.activate-planner", action); + EXPECT_TRUE(g_action_group_has_action(m_actions->action_group(), "activate-planner")); + g_free(action); + } g_clear_object(§ion); // try adding a few appointments and see if the menu updates itself -- cgit v1.2.3 From 9752ca1cd3e75e1245ebb8dcb4719503e332a352 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 10:57:19 -0600 Subject: fix 'clock app' menuitem on phone profile reported by seb128 and update the corresponding unit tests --- src/menu.cpp | 17 +++- tests/test-menus.cpp | 242 +++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 188 insertions(+), 71 deletions(-) (limited to 'src/menu.cpp') diff --git a/src/menu.cpp b/src/menu.cpp index 44da7b7..d0756cc 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -293,10 +293,10 @@ private: else { g_menu_item_set_attribute (menu_item, "x-canonical-type", "s", "com.canonical.indicator.appointment"); - - if (!appt.color.empty()) - g_menu_item_set_attribute (menu_item, "x-canonical-color", "s", appt.color.c_str()); } + + if (!appt.color.empty()) + g_menu_item_set_attribute (menu_item, "x-canonical-color", "s", appt.color.c_str()); if (profile == Phone) g_menu_item_set_action_and_target_value (menu_item, @@ -315,7 +315,7 @@ private: { auto menu = g_menu_new(); - if (((profile==Phone) || (profile==Desktop)) && m_state->settings->show_events.get()) + if ((profile==Desktop) && m_state->settings->show_events.get()) { add_appointments (menu, profile); @@ -327,6 +327,15 @@ private: g_menu_append_item(menu, menu_item); g_object_unref(menu_item); } + else if (profile==Phone) + { + auto menu_item = g_menu_item_new (_("Clock"), "indicator.activate-phone-clock-app"); + g_menu_item_set_attribute_value (menu_item, G_MENU_ATTRIBUTE_ICON, get_serialized_alarm_icon()); + g_menu_append_item (menu, menu_item); + g_object_unref (menu_item); + + add_appointments (menu, profile); + } return G_MENU_MODEL(menu); } diff --git a/tests/test-menus.cpp b/tests/test-menus.cpp index e9dd7df..73d6036 100644 --- a/tests/test-menus.cpp +++ b/tests/test-menus.cpp @@ -158,42 +158,20 @@ protected: g_object_unref(submenu); } - void InspectAppointments(GMenuModel* menu_model, Menu::Profile profile) - { - const bool appointments_expected = (profile == Menu::Desktop) - || (profile == Menu::Phone); +private: + void InspectEmptySection(GMenuModel* menu_model, Menu::Section section) + { // get the Appointments section auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU); + auto menu_section = g_menu_model_get_item_link(submenu, section, G_MENU_LINK_SECTION); + EXPECT_EQ(0, g_menu_model_get_n_items(menu_section)); + g_clear_object(&menu_section); + g_clear_object(&submenu); + } - // there shouldn't be any menuitems when "show events" is 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)); - g_clear_object(§ion); - - // when "show_events" is true, - // there should be an "add event" button even if there aren't any appointments - std::vector appointments; - 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); - int expected_n = appointments_expected ? 1 : 0; - EXPECT_EQ(expected_n, g_menu_model_get_n_items(section)); - if (appointments_expected) - { - gchar* action = nullptr; - EXPECT_TRUE(g_menu_model_get_item_attribute(section, 0, G_MENU_ATTRIBUTE_ACTION, "s", &action)); - EXPECT_STREQ("indicator.activate-planner", action); - EXPECT_TRUE(g_action_group_has_action(m_actions->action_group(), "activate-planner")); - g_free(action); - } - g_clear_object(§ion); - - // try adding a few appointments and see if the menu updates itself - + std::vector build_some_appointments() + { const auto now = m_state->clock->localtime(); auto gdt_tomorrow = g_date_time_add_days(now.get(), 1); const auto tomorrow = DateTime(gdt_tomorrow); @@ -206,7 +184,6 @@ protected: a1.uid = "example"; a1.has_alarms = true; a1.begin = a1.end = tomorrow; - appointments.push_back(a1); Appointment a2; // a non-alarm appointment a2.color = "green"; @@ -215,52 +192,183 @@ protected: a2.uid = "monkey"; a2.has_alarms = false; a2.begin = a2.end = tomorrow; - appointments.push_back(a2); - m_state->planner->upcoming.set(appointments); - wait_msec(); // wait a moment for the menu to update + return std::vector({a1, a2}); + } - section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION); - expected_n = appointments_expected ? 3 : 0; - EXPECT_EQ(expected_n, g_menu_model_get_n_items(section)); - if (appointments_expected) + void InspectAppointmentMenuItem(GMenuModel* section, + int index, + const Appointment& appt) + { + // confirm it has the right x-canonical-type + gchar * str = nullptr; + g_menu_model_get_item_attribute(section, index, "x-canonical-type", "s", &str); + if (appt.has_alarms) + EXPECT_STREQ("com.canonical.indicator.alarm", str); + else + EXPECT_STREQ("com.canonical.indicator.appointment", str); + g_clear_pointer(&str, g_free); + + // confirm it has a nonempty x-canonical-time-format + g_menu_model_get_item_attribute(section, index, "x-canonical-time-format", "s", &str); + EXPECT_TRUE(str && *str); + g_clear_pointer(&str, g_free); + + // confirm the color hint, if it exists, + // is in the x-canonical-color attribute + if (appt.color.empty()) { - gchar * str = nullptr; + EXPECT_FALSE(g_menu_model_get_item_attribute(section, + index, + "x-canonical-color", + "s", + &str)); + } + else + { + EXPECT_TRUE(g_menu_model_get_item_attribute(section, + index, + "x-canonical-color", + "s", + &str)); + EXPECT_EQ(appt.color, str); + } + g_clear_pointer(&str, g_free); - // test the alarm - // - confirm it has an x-canonical-type of "alarm" - g_menu_model_get_item_attribute(section, 0, "x-canonical-type", "s", &str); - EXPECT_STREQ("com.canonical.indicator.alarm", str); - g_clear_pointer(&str, g_free); - // - confirm it has a nonempty x-canonical-time-format - g_menu_model_get_item_attribute(section, 0, "x-canonical-time-format", "s", &str); - EXPECT_TRUE(str && *str); - g_clear_pointer(&str, g_free); - // - confirm it has a serialized icon attribute - auto v = g_menu_model_get_item_attribute_value(section, 0, G_MENU_ATTRIBUTE_ICON, nullptr); + // confirm that alarms have an icon + if (appt.has_alarms) + { + auto v = g_menu_model_get_item_attribute_value(section, + index, + G_MENU_ATTRIBUTE_ICON, + nullptr); EXPECT_TRUE(v != nullptr); auto icon = g_icon_deserialize(v); EXPECT_TRUE(icon != nullptr); g_clear_object(&icon); g_clear_pointer(&v, g_variant_unref); - - // test the appointment - // - confirm it has an x-canonical-type of "appointment" - g_menu_model_get_item_attribute(section, 1, "x-canonical-type", "s", &str); - EXPECT_STREQ("com.canonical.indicator.appointment", str); - g_clear_pointer(&str, g_free); - // - confirm it has a nonempty x-canonical-time-format - g_menu_model_get_item_attribute(section, 0, "x-canonical-time-format", "s", &str); - EXPECT_TRUE(str && *str); - g_clear_pointer(&str, g_free); - // - confirm its color matches the one we fed the appointments vector - g_menu_model_get_item_attribute(section, 1, "x-canonical-color", "s", &str); - EXPECT_EQ(a2.color, str); - g_clear_pointer(&str, g_free); } + } + + void InspectAppointmentMenuItems(GMenuModel* section, + int first_appt_index, + const std::vector& appointments) + { + // try adding a few appointments and see if the menu updates itself + m_state->planner->upcoming.set(appointments); + wait_msec(); // wait a moment for the menu to update + + //auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU); + //auto section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION); + EXPECT_EQ(appointments.size()+1, g_menu_model_get_n_items(section)); + + for (int i=0, n=appointments.size(); isettings->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)); g_clear_object(§ion); - g_object_unref(submenu); + // when "show_events" is true, + // there should be an "add event" button even if there aren't any appointments + std::vector appointments; + 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); + EXPECT_EQ(1, g_menu_model_get_n_items(section)); + gchar* action = nullptr; + EXPECT_TRUE(g_menu_model_get_item_attribute(section, 0, G_MENU_ATTRIBUTE_ACTION, "s", &action)); + const char* expected_action = "activate-planner"; + EXPECT_EQ(std::string("indicator.")+expected_action, action); + EXPECT_TRUE(g_action_group_has_action(m_actions->action_group(), expected_action)); + g_free(action); + g_clear_object(§ion); + + // try adding a few appointments and see if the menu updates itself + appointments = build_some_appointments(); + m_state->planner->upcoming.set(appointments); + wait_msec(); // wait a moment for the menu to update + section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION); + EXPECT_EQ(3, g_menu_model_get_n_items(section)); + InspectAppointmentMenuItems(section, 0, appointments); + g_clear_object(§ion); + + // cleanup + g_clear_object(&submenu); + } + + void InspectPhoneAppointments(GMenuModel* menu_model) + { + auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU); + + // clear all the appointments + std::vector appointments; + m_state->planner->upcoming.set(appointments); + wait_msec(); // wait a moment for the menu to update + + // check that there's a "clock app" menuitem even when there are no appointments + auto section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION); + const char* expected_action = "activate-phone-clock-app"; + EXPECT_EQ(1, g_menu_model_get_n_items(section)); + gchar* action = nullptr; + EXPECT_TRUE(g_menu_model_get_item_attribute(section, 0, G_MENU_ATTRIBUTE_ACTION, "s", &action)); + EXPECT_EQ(std::string("indicator.")+expected_action, action); + EXPECT_TRUE(g_action_group_has_action(m_actions->action_group(), expected_action)); + g_free(action); + g_clear_object(§ion); + + // add some appointments and test them + appointments = build_some_appointments(); + m_state->planner->upcoming.set(appointments); + wait_msec(); // wait a moment for the menu to update + section = g_menu_model_get_item_link(submenu, Menu::Appointments, G_MENU_LINK_SECTION); + EXPECT_EQ(3, g_menu_model_get_n_items(section)); + InspectAppointmentMenuItems(section, 1, appointments); + g_clear_object(§ion); + + // cleanup + g_clear_object(&submenu); + } + +protected: + + void InspectAppointments(GMenuModel* menu_model, Menu::Profile profile) + { + switch (profile) + { + case Menu::Desktop: + InspectDesktopAppointments(menu_model); + break; + + case Menu::DesktopGreeter: + InspectEmptySection(menu_model, Menu::Appointments); + break; + + case Menu::Phone: + InspectPhoneAppointments(menu_model); + break; + + case Menu::PhoneGreeter: + InspectEmptySection(menu_model, Menu::Appointments); + break; + + default: + g_warn_if_reached(); + break; + } } void CompareLocationsTo(GMenuModel* menu_model, const std::vector& locations) -- cgit v1.2.3 From d2caa37e18191c31d866dd3042b676c135bae50d Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 12:45:50 -0600 Subject: as per review, don't inline getters --- include/datetime/actions.h | 4 ++-- include/datetime/locations.h | 4 ++-- include/datetime/menu.h | 8 ++++---- src/actions.cpp | 11 +++++++++++ src/locations.cpp | 10 ++++++++++ src/menu.cpp | 26 ++++++++++++++++++++++++++ 6 files changed, 55 insertions(+), 8 deletions(-) (limited to 'src/menu.cpp') diff --git a/include/datetime/actions.h b/include/datetime/actions.h index 3686b95..6817b4c 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -50,8 +50,8 @@ public: virtual void open_appointment(const std::string& uid) =0; virtual void set_location(const std::string& zone, const std::string& name)=0; void set_calendar_date(const DateTime&); - GActionGroup* action_group() { return G_ACTION_GROUP(m_actions); } - std::shared_ptr state() { return m_state; } + GActionGroup* action_group(); + std::shared_ptr state(); protected: Actions(const std::shared_ptr& state); diff --git a/include/datetime/locations.h b/include/datetime/locations.h index ee67615..fc776bb 100644 --- a/include/datetime/locations.h +++ b/include/datetime/locations.h @@ -39,9 +39,9 @@ namespace datetime { class Location { public: - const std::string& zone() const { return m_zone; } + const std::string& zone() const; - const std::string& name() const { return m_name; } + const std::string& name() const; bool operator== (const Location& that) const { diff --git a/include/datetime/menu.h b/include/datetime/menu.h index fcd709f..f097b02 100644 --- a/include/datetime/menu.h +++ b/include/datetime/menu.h @@ -43,9 +43,9 @@ class Menu public: enum Profile { Desktop, DesktopGreeter, Phone, PhoneGreeter, NUM_PROFILES }; enum Section { Calendar, Appointments, Locations, Settings, NUM_SECTIONS }; - const std::string& name() const { return m_name; } - Profile profile() const { return m_profile; } - GMenuModel* menu_model() { return G_MENU_MODEL(m_menu); } + const std::string& name() const; + Profile profile() const; + GMenuModel* menu_model(); protected: Menu (Profile profile_in, const std::string& name_in): m_profile(profile_in), m_name(name_in) {} @@ -72,7 +72,7 @@ class MenuFactory public: MenuFactory (std::shared_ptr& actions, std::shared_ptr& state); std::shared_ptr buildMenu(Menu::Profile profile); - std::shared_ptr state() { return m_state; } + std::shared_ptr state(); private: std::shared_ptr m_actions; diff --git a/src/actions.cpp b/src/actions.cpp index acf8fd4..6ee3896 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -249,6 +249,17 @@ void Actions::set_calendar_date(const DateTime& date) m_state->planner->time.set(date); } +GActionGroup* Actions::action_group() +{ + return G_ACTION_GROUP(m_actions); +} + +std::shared_ptr Actions::state() +{ + return m_state; +} + + } // namespace datetime } // namespace indicator diff --git a/src/locations.cpp b/src/locations.cpp index d6ab73a..8d1a086 100644 --- a/src/locations.cpp +++ b/src/locations.cpp @@ -25,6 +25,16 @@ namespace unity { namespace indicator { namespace datetime { +const std::string& Location::zone() const +{ + return m_zone; +} + +const std::string& Location::name() const +{ + return m_name; +} + Location::Location(const std::string& zone_, const std::string& name_): m_zone(zone_), m_name(name_) diff --git a/src/menu.cpp b/src/menu.cpp index d0756cc..4bb4fb6 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -35,6 +35,27 @@ namespace datetime { ***** ****/ +const std::string& Menu::name() const +{ + return m_name; +} + +Menu::Profile Menu::profile() const +{ + return m_profile; +} + +GMenuModel* Menu::menu_model() +{ + return G_MENU_MODEL(m_menu); +} + + +/**** +***** +****/ + + #define FALLBACK_ALARM_CLOCK_ICON_NAME "clock" #define CALENDAR_ICON_NAME "calendar" @@ -531,6 +552,11 @@ MenuFactory::MenuFactory(std::shared_ptr& actions_, { } +std::shared_ptr MenuFactory::state() +{ + return m_state; +} + std::shared_ptr MenuFactory::buildMenu(Menu::Profile profile) { -- cgit v1.2.3 From cc2ad2ad457313cb87e4483bf0278f670a5a5cea Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 13:00:22 -0600 Subject: as per review, don't inline unless there are performance issues --- include/datetime/actions-live.h | 2 +- include/datetime/appointment.h | 12 +--------- include/datetime/date-time.h | 6 ++--- include/datetime/locations.h | 12 ++-------- include/datetime/menu.h | 2 +- include/datetime/timezone-file.h | 6 ++--- include/datetime/timezone.h | 1 - src/CMakeLists.txt | 1 + src/actions-live.cpp | 5 +++++ src/appointment.cpp | 48 ++++++++++++++++++++++++++++++++++++++++ src/date-time.cpp | 17 ++++++++++++++ src/locations.cpp | 8 +++++++ src/menu.cpp | 6 +++++ src/timezone-file.cpp | 14 ++++++++++++ 14 files changed, 110 insertions(+), 30 deletions(-) create mode 100644 src/appointment.cpp (limited to 'src/menu.cpp') diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h index 949222d..3607836 100644 --- a/include/datetime/actions-live.h +++ b/include/datetime/actions-live.h @@ -36,7 +36,7 @@ namespace datetime { class LiveActions: public Actions { public: - LiveActions(const std::shared_ptr& state_in): Actions(state_in) {} + LiveActions(const std::shared_ptr& state_in); ~LiveActions() =default; void open_desktop_settings(); diff --git a/include/datetime/appointment.h b/include/datetime/appointment.h index e034c08..a5283c9 100644 --- a/include/datetime/appointment.h +++ b/include/datetime/appointment.h @@ -45,17 +45,7 @@ public: DateTime begin; DateTime end; - bool operator== (const Appointment& that) const - { - return (color==that.color) && - (summary==that.summary) && - (url==that.url) && - (uid==that.uid) && - (is_event==that.is_event) && - (has_alarms==that.has_alarms) && - (begin==that.begin) && - (end==that.end); - } + bool operator== (const Appointment& that) const; }; } // namespace datetime diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h index c2429eb..2ad7856 100644 --- a/include/datetime/date-time.h +++ b/include/datetime/date-time.h @@ -37,9 +37,9 @@ class DateTime public: static DateTime NowLocal(); explicit DateTime(time_t t); - explicit DateTime(GDateTime* in=nullptr) {reset(in);} - DateTime& operator=(GDateTime* in) {reset(in); return *this;} - DateTime& operator=(const DateTime& in) {m_dt=in.m_dt; return *this; } + explicit DateTime(GDateTime* in=nullptr); + DateTime& operator=(GDateTime* in); + DateTime& operator=(const DateTime& in); DateTime to_timezone(const std::string& zone) const; void reset(GDateTime* in=nullptr); diff --git a/include/datetime/locations.h b/include/datetime/locations.h index fc776bb..b840436 100644 --- a/include/datetime/locations.h +++ b/include/datetime/locations.h @@ -39,18 +39,10 @@ namespace datetime { class Location { public: + Location (const std::string& zone, const std::string& name); const std::string& zone() const; - const std::string& name() const; - - bool operator== (const Location& that) const - { - return (name() == that.name()) && - (zone() == that.zone()) && - (m_offset == that.m_offset); - } - - Location (const std::string& zone, const std::string& name); + bool operator== (const Location& that) const; private: diff --git a/include/datetime/menu.h b/include/datetime/menu.h index f097b02..526cd9f 100644 --- a/include/datetime/menu.h +++ b/include/datetime/menu.h @@ -48,7 +48,7 @@ public: GMenuModel* menu_model(); protected: - Menu (Profile profile_in, const std::string& name_in): m_profile(profile_in), m_name(name_in) {} + Menu (Profile profile_in, const std::string& name_in); virtual ~Menu() =default; GMenu* m_menu = nullptr; diff --git a/include/datetime/timezone-file.h b/include/datetime/timezone-file.h index 7f47df6..d77aaae 100644 --- a/include/datetime/timezone-file.h +++ b/include/datetime/timezone-file.h @@ -37,9 +37,9 @@ namespace datetime { class FileTimezone: public Timezone { public: - FileTimezone() {} - FileTimezone(const std::string& filename) { setFilename(filename); } - ~FileTimezone() {clear();} + FileTimezone(); + FileTimezone(const std::string& filename); + ~FileTimezone(); private: void setFilename(const std::string& filename); diff --git a/include/datetime/timezone.h b/include/datetime/timezone.h index ffa5a84..7d2ace8 100644 --- a/include/datetime/timezone.h +++ b/include/datetime/timezone.h @@ -35,7 +35,6 @@ protected: Timezone() =default; public: - //virtual ~Timezone() {} core::Property timezone; }; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eb716d4..d5236ad 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,6 +15,7 @@ endif () add_library (${SERVICE_LIB} STATIC actions.cpp actions-live.cpp + appointment.cpp clock.cpp clock-live.cpp date-time.cpp diff --git a/src/actions-live.cpp b/src/actions-live.cpp index afd83f4..c0fd8ff 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -31,6 +31,11 @@ namespace datetime { **** ***/ +LiveActions::LiveActions(const std::shared_ptr& state_in): + Actions(state_in) +{ +} + void LiveActions::execute_command(const std::string& cmdstr) { const auto cmd = cmdstr.c_str(); diff --git a/src/appointment.cpp b/src/appointment.cpp new file mode 100644 index 0000000..6e742c3 --- /dev/null +++ b/src/appointment.cpp @@ -0,0 +1,48 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/**** +***** +****/ + +bool Appointment::operator==(const Appointment& that) const +{ + return (color==that.color) + && (summary==that.summary) + && (url==that.url) + && (uid==that.uid) + && (is_event==that.is_event) + && (has_alarms==that.has_alarms) + && (begin==that.begin) + && (end==that.end); +} + +/**** +***** +****/ + +} // namespace datetime +} // namespace indicator +} // namespace unity diff --git a/src/date-time.cpp b/src/date-time.cpp index 40c638f..a634c5e 100644 --- a/src/date-time.cpp +++ b/src/date-time.cpp @@ -27,6 +27,23 @@ namespace datetime { **** ***/ +DateTime::DateTime(GDateTime* gdt) +{ + reset(gdt); +} + +DateTime& DateTime::operator=(GDateTime* gdt) +{ + reset(gdt); + return *this; +} + +DateTime& DateTime::operator=(const DateTime& that) +{ + m_dt = that.m_dt; + return *this; +} + DateTime::DateTime(time_t t) { GDateTime * gdt = g_date_time_new_from_unix_local(t); diff --git a/src/locations.cpp b/src/locations.cpp index 8d1a086..c59f988 100644 --- a/src/locations.cpp +++ b/src/locations.cpp @@ -35,6 +35,14 @@ const std::string& Location::name() const return m_name; } +bool Location::operator== (const Location& that) const +{ + return (m_name == that.m_name) + && (m_zone == that.m_zone) + && (m_offset == that.m_offset); +} + + Location::Location(const std::string& zone_, const std::string& name_): m_zone(zone_), m_name(name_) diff --git a/src/menu.cpp b/src/menu.cpp index 4bb4fb6..b263520 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -35,6 +35,12 @@ namespace datetime { ***** ****/ +Menu::Menu (Profile profile_in, const std::string& name_in): + m_profile(profile_in), + m_name(name_in) +{ +} + const std::string& Menu::name() const { return m_name; diff --git a/src/timezone-file.cpp b/src/timezone-file.cpp index 3a0c240..76737b4 100644 --- a/src/timezone-file.cpp +++ b/src/timezone-file.cpp @@ -23,6 +23,20 @@ namespace unity { namespace indicator { namespace datetime { +FileTimezone::FileTimezone() +{ +} + +FileTimezone::FileTimezone(const std::string& filename) +{ + setFilename(filename); +} + +FileTimezone::~FileTimezone() +{ + clear(); +} + void FileTimezone::clear() { -- cgit v1.2.3 From b56293e7b4fb4b253da17119ad153990744dac3b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 13:17:11 -0600 Subject: as per review, constify getters where possible. This isn't always possible due to system APIs asking for non-const pointers. --- include/datetime/actions.h | 2 +- include/datetime/menu.h | 1 - src/actions.cpp | 6 +++--- src/menu.cpp | 5 ----- 4 files changed, 4 insertions(+), 10 deletions(-) (limited to 'src/menu.cpp') diff --git a/include/datetime/actions.h b/include/datetime/actions.h index 6817b4c..99e78f5 100644 --- a/include/datetime/actions.h +++ b/include/datetime/actions.h @@ -51,7 +51,7 @@ public: virtual void set_location(const std::string& zone, const std::string& name)=0; void set_calendar_date(const DateTime&); GActionGroup* action_group(); - std::shared_ptr state(); + const std::shared_ptr state() const; protected: Actions(const std::shared_ptr& state); diff --git a/include/datetime/menu.h b/include/datetime/menu.h index 526cd9f..5821e33 100644 --- a/include/datetime/menu.h +++ b/include/datetime/menu.h @@ -72,7 +72,6 @@ class MenuFactory public: MenuFactory (std::shared_ptr& actions, std::shared_ptr& state); std::shared_ptr buildMenu(Menu::Profile profile); - std::shared_ptr state(); private: std::shared_ptr m_actions; diff --git a/src/actions.cpp b/src/actions.cpp index 6ee3896..cdeb77f 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -65,7 +65,7 @@ void on_activate_appointment(GSimpleAction * /*action*/, g_return_if_fail(uid && *uid); // find url of the upcoming appointment with this uid - for (auto& appt : self->state()->planner->upcoming.get()) + for (const auto& appt : self->state()->planner->upcoming.get()) { if (appt.uid == uid) { @@ -146,7 +146,7 @@ GVariant* create_default_header_state() GVariant* create_calendar_state(const std::shared_ptr& state) { gboolean days[32] = { 0 }; - for(const auto& appt : state->planner->thisMonth.get()) + for (const auto& appt : state->planner->thisMonth.get()) days[appt.begin.day_of_month()] = true; GVariantBuilder day_builder; @@ -254,7 +254,7 @@ GActionGroup* Actions::action_group() return G_ACTION_GROUP(m_actions); } -std::shared_ptr Actions::state() +const std::shared_ptr Actions::state() const { return m_state; } diff --git a/src/menu.cpp b/src/menu.cpp index b263520..696ed2b 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -558,11 +558,6 @@ MenuFactory::MenuFactory(std::shared_ptr& actions_, { } -std::shared_ptr MenuFactory::state() -{ - return m_state; -} - std::shared_ptr MenuFactory::buildMenu(Menu::Profile profile) { -- cgit v1.2.3 From 0f384f4c9607b785d7df4da8566fe2b869ef11e4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 13:28:48 -0600 Subject: as per review, there were a few places that accidentally passed a shared_ptr& instead of a const shared_ptr& --- include/datetime/exporter.h | 4 ++-- include/datetime/menu.h | 2 +- src/exporter.cpp | 4 ++-- src/menu.cpp | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/menu.cpp') diff --git a/include/datetime/exporter.h b/include/datetime/exporter.h index a32b941..c228cc1 100644 --- a/include/datetime/exporter.h +++ b/include/datetime/exporter.h @@ -45,8 +45,8 @@ public: core::Signal<> name_lost; - void publish(std::shared_ptr& actions, - std::vector>& menus); + void publish(const std::shared_ptr& actions, + const std::vector>& menus); private: static void on_bus_acquired(GDBusConnection*, const gchar *name, gpointer gthis); diff --git a/include/datetime/menu.h b/include/datetime/menu.h index 5821e33..a95be10 100644 --- a/include/datetime/menu.h +++ b/include/datetime/menu.h @@ -70,7 +70,7 @@ private: class MenuFactory { public: - MenuFactory (std::shared_ptr& actions, std::shared_ptr& state); + MenuFactory (const std::shared_ptr& actions, const std::shared_ptr& state); std::shared_ptr buildMenu(Menu::Profile profile); private: diff --git a/src/exporter.cpp b/src/exporter.cpp index 86e3670..ccd6e5c 100644 --- a/src/exporter.cpp +++ b/src/exporter.cpp @@ -120,8 +120,8 @@ Exporter::on_name_lost(GDBusConnection* /*connection*/, const gchar* /*name*/) ***/ void -Exporter::publish(std::shared_ptr& actions, - std::vector>& menus) +Exporter::publish(const std::shared_ptr& actions, + const std::vector>& menus) { m_actions = actions; m_menus = menus; diff --git a/src/menu.cpp b/src/menu.cpp index 696ed2b..42265c9 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -551,8 +551,8 @@ public: ***** ****/ -MenuFactory::MenuFactory(std::shared_ptr& actions_, - std::shared_ptr& state_): +MenuFactory::MenuFactory(const std::shared_ptr& actions_, + const std::shared_ptr& state_): m_actions(actions_), m_state(state_) { -- cgit v1.2.3 From 197309468247c893bdaa37ef47a98db695b2ea78 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 13:44:12 -0600 Subject: following on the review comment covered in the last commit, use shared_ptr instead of shared_ptr where possible. --- include/datetime/clock.h | 2 +- include/datetime/formatter.h | 8 ++++---- include/datetime/locations-settings.h | 8 ++++---- include/datetime/menu.h | 4 ++-- include/datetime/timezones-live.h | 4 ++-- src/clock-live.cpp | 6 +++--- src/formatter-desktop.cpp | 4 ++-- src/formatter.cpp | 6 +++--- src/locations-settings.cpp | 4 ++-- src/menu.cpp | 24 ++++++++++++------------ src/timezones-live.cpp | 3 ++- 11 files changed, 37 insertions(+), 36 deletions(-) (limited to 'src/menu.cpp') diff --git a/include/datetime/clock.h b/include/datetime/clock.h index b3e3538..4a9db8f 100644 --- a/include/datetime/clock.h +++ b/include/datetime/clock.h @@ -79,7 +79,7 @@ class Timezones; class LiveClock: public Clock { public: - LiveClock (const std::shared_ptr& zones); + LiveClock (const std::shared_ptr& zones); virtual ~LiveClock(); virtual DateTime localtime() const; diff --git a/include/datetime/formatter.h b/include/datetime/formatter.h index 3de109e..f323858 100644 --- a/include/datetime/formatter.h +++ b/include/datetime/formatter.h @@ -86,7 +86,7 @@ public: std::string getRelativeFormat(GDateTime* then, GDateTime* then_end=nullptr) const; protected: - Formatter(const std::shared_ptr&); + Formatter(const std::shared_ptr&); virtual ~Formatter(); static const char* getDefaultHeaderTimeFormat(bool twelvehour, bool show_seconds); @@ -107,10 +107,10 @@ private: class DesktopFormatter: public Formatter { public: - DesktopFormatter(const std::shared_ptr&, const std::shared_ptr&); + DesktopFormatter(const std::shared_ptr&, const std::shared_ptr&); private: - std::shared_ptr m_settings; + std::shared_ptr m_settings; void rebuildHeaderFormat(); const gchar* getFullTimeFormatString() const; @@ -126,7 +126,7 @@ private: class PhoneFormatter: public Formatter { public: - PhoneFormatter(const std::shared_ptr& clock): Formatter(clock) { + PhoneFormatter(const std::shared_ptr& clock): Formatter(clock) { headerFormat.set(getDefaultHeaderTimeFormat(is_locale_12h(), false)); } }; diff --git a/include/datetime/locations-settings.h b/include/datetime/locations-settings.h index d01cbb5..8757f43 100644 --- a/include/datetime/locations-settings.h +++ b/include/datetime/locations-settings.h @@ -39,12 +39,12 @@ public: * @param[in] settings the #Settings whose locations property is to be used * @param[in] timezones the #Timezones to always show first in the list */ - SettingsLocations (const std::shared_ptr& settings, - const std::shared_ptr& timezones); + SettingsLocations (const std::shared_ptr& settings, + const std::shared_ptr& timezones); private: - std::shared_ptr m_settings; - std::shared_ptr m_timezones; + std::shared_ptr m_settings; + std::shared_ptr m_timezones; void reload(); }; diff --git a/include/datetime/menu.h b/include/datetime/menu.h index a95be10..7b351c3 100644 --- a/include/datetime/menu.h +++ b/include/datetime/menu.h @@ -70,12 +70,12 @@ private: class MenuFactory { public: - MenuFactory (const std::shared_ptr& actions, const std::shared_ptr& state); + MenuFactory (const std::shared_ptr& actions, const std::shared_ptr& state); std::shared_ptr buildMenu(Menu::Profile profile); private: std::shared_ptr m_actions; - std::shared_ptr m_state; + std::shared_ptr m_state; }; } // namespace datetime diff --git a/include/datetime/timezones-live.h b/include/datetime/timezones-live.h index 286c967..ca4ef31 100644 --- a/include/datetime/timezones-live.h +++ b/include/datetime/timezones-live.h @@ -38,14 +38,14 @@ namespace datetime { class LiveTimezones: public Timezones { public: - LiveTimezones(std::shared_ptr& settings, const std::string& filename); + LiveTimezones(const std::shared_ptr& settings, const std::string& filename); private: void update_geolocation(); void update_timezones(); FileTimezone m_file; - std::shared_ptr m_settings; + std::shared_ptr m_settings; std::shared_ptr m_geo; }; diff --git a/src/clock-live.cpp b/src/clock-live.cpp index 69ebda7..7c9db40 100644 --- a/src/clock-live.cpp +++ b/src/clock-live.cpp @@ -59,7 +59,7 @@ class LiveClock::Impl { public: - Impl(LiveClock& owner, const std::shared_ptr& tzd): + Impl(LiveClock& owner, const std::shared_ptr& tzd): m_owner(owner), m_timezones(tzd) { @@ -135,13 +135,13 @@ protected: LiveClock& m_owner; GTimeZone* m_timezone = nullptr; - std::shared_ptr m_timezones; + std::shared_ptr m_timezones; DateTime m_prev_datetime; unsigned int m_timer = 0; }; -LiveClock::LiveClock(const std::shared_ptr& tzd): +LiveClock::LiveClock(const std::shared_ptr& tzd): p(new Impl(*this, tzd)) { } diff --git a/src/formatter-desktop.cpp b/src/formatter-desktop.cpp index d542ec4..9a098c6 100644 --- a/src/formatter-desktop.cpp +++ b/src/formatter-desktop.cpp @@ -64,8 +64,8 @@ std::string joinDateAndTimeFormatStrings(const char* date_string, **** ***/ -DesktopFormatter::DesktopFormatter(const std::shared_ptr& clock_in, - const std::shared_ptr& settings_in): +DesktopFormatter::DesktopFormatter(const std::shared_ptr& clock_in, + const std::shared_ptr& settings_in): Formatter(clock_in), m_settings(settings_in) { diff --git a/src/formatter.cpp b/src/formatter.cpp index a15c7f8..638eac4 100644 --- a/src/formatter.cpp +++ b/src/formatter.cpp @@ -118,7 +118,7 @@ class Formatter::Impl { public: - Impl(Formatter* owner, const std::shared_ptr& clock): + Impl(Formatter* owner, const std::shared_ptr& clock): m_owner(owner), m_clock(clock) { @@ -208,14 +208,14 @@ private: guint m_relative_timer = 0; public: - std::shared_ptr m_clock; + std::shared_ptr m_clock; }; /*** **** ***/ -Formatter::Formatter(const std::shared_ptr& clock): +Formatter::Formatter(const std::shared_ptr& clock): p(new Formatter::Impl(this, clock)) { } diff --git a/src/locations-settings.cpp b/src/locations-settings.cpp index 9b90bc0..ef3085f 100644 --- a/src/locations-settings.cpp +++ b/src/locations-settings.cpp @@ -29,8 +29,8 @@ namespace unity { namespace indicator { namespace datetime { -SettingsLocations::SettingsLocations(const std::shared_ptr& settings, - const std::shared_ptr& timezones): +SettingsLocations::SettingsLocations(const std::shared_ptr& settings, + const std::shared_ptr& timezones): m_settings(settings), m_timezones(timezones) { diff --git a/src/menu.cpp b/src/menu.cpp index 42265c9..e92d398 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -70,9 +70,9 @@ class MenuImpl: public Menu protected: MenuImpl(const Menu::Profile profile_in, const std::string& name_in, - std::shared_ptr& state, + std::shared_ptr& state, std::shared_ptr& actions, - std::shared_ptr formatter): + std::shared_ptr formatter): Menu(profile_in, name_in), m_state(state), m_actions(actions), @@ -136,9 +136,9 @@ protected: g_action_group_change_action_state(action_group, action_name.c_str(), state); } - std::shared_ptr m_state; + std::shared_ptr m_state; std::shared_ptr m_actions; - std::shared_ptr m_formatter; + std::shared_ptr m_formatter; GMenu* m_submenu = nullptr; GVariant* get_serialized_alarm_icon() { return m_serialized_alarm_icon; } @@ -450,10 +450,10 @@ class DesktopBaseMenu: public MenuImpl protected: DesktopBaseMenu(Menu::Profile profile_, const std::string& name_, - std::shared_ptr& state_, + std::shared_ptr& state_, std::shared_ptr& actions_): MenuImpl(profile_, name_, state_, actions_, - std::shared_ptr(new DesktopFormatter(state_->clock, state_->settings))) + std::shared_ptr(new DesktopFormatter(state_->clock, state_->settings))) { update_header(); } @@ -477,14 +477,14 @@ protected: class DesktopMenu: public DesktopBaseMenu { public: - DesktopMenu(std::shared_ptr& state_, std::shared_ptr& actions_): + DesktopMenu(std::shared_ptr& state_, std::shared_ptr& actions_): DesktopBaseMenu(Desktop,"desktop", state_, actions_) {} }; class DesktopGreeterMenu: public DesktopBaseMenu { public: - DesktopGreeterMenu(std::shared_ptr& state_, std::shared_ptr& actions_): + DesktopGreeterMenu(std::shared_ptr& state_, std::shared_ptr& actions_): DesktopBaseMenu(DesktopGreeter,"desktop_greeter", state_, actions_) {} }; @@ -493,7 +493,7 @@ class PhoneBaseMenu: public MenuImpl protected: PhoneBaseMenu(Menu::Profile profile_, const std::string& name_, - std::shared_ptr& state_, + std::shared_ptr& state_, std::shared_ptr& actions_): MenuImpl(profile_, name_, state_, actions_, std::shared_ptr(new PhoneFormatter(state_->clock))) @@ -534,7 +534,7 @@ protected: class PhoneMenu: public PhoneBaseMenu { public: - PhoneMenu(std::shared_ptr& state_, + PhoneMenu(std::shared_ptr& state_, std::shared_ptr& actions_): PhoneBaseMenu(Phone, "phone", state_, actions_) {} }; @@ -542,7 +542,7 @@ public: class PhoneGreeterMenu: public PhoneBaseMenu { public: - PhoneGreeterMenu(std::shared_ptr& state_, + PhoneGreeterMenu(std::shared_ptr& state_, std::shared_ptr& actions_): PhoneBaseMenu(PhoneGreeter, "phone_greeter", state_, actions_) {} }; @@ -552,7 +552,7 @@ public: ****/ MenuFactory::MenuFactory(const std::shared_ptr& actions_, - const std::shared_ptr& state_): + const std::shared_ptr& state_): m_actions(actions_), m_state(state_) { diff --git a/src/timezones-live.cpp b/src/timezones-live.cpp index baac05d..4902b76 100644 --- a/src/timezones-live.cpp +++ b/src/timezones-live.cpp @@ -25,7 +25,8 @@ namespace unity { namespace indicator { namespace datetime { -LiveTimezones::LiveTimezones(std::shared_ptr& settings, const std::string& filename): +LiveTimezones::LiveTimezones(const std::shared_ptr& settings, + const std::string& filename): m_file(filename), m_settings(settings) { -- cgit v1.2.3 From a7a09a5ca5012fb1c48f259d2587542316e7349b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 30 Jan 2014 18:33:14 -0600 Subject: copyediting: as per review, use name_of_thing() instead of get_name_of_thing() or getNameOfThing() --- include/datetime/clock-mock.h | 4 ++-- include/datetime/clock.h | 10 +++++----- include/datetime/formatter.h | 12 ++++++------ include/datetime/planner.h | 6 +++--- src/actions.cpp | 4 ++-- src/clock-live.cpp | 6 +++--- src/clock.cpp | 22 +++++++++++----------- src/formatter-desktop.cpp | 4 ++-- src/formatter.cpp | 12 ++++++------ src/menu.cpp | 14 +++++++------- src/planner-eds.cpp | 2 +- tests/test-clock.cpp | 8 ++++---- tests/test-formatter.cpp | 10 +++++----- tests/test-live-actions.cpp | 4 ++-- tests/test-planner.cpp | 6 +++--- 15 files changed, 62 insertions(+), 62 deletions(-) (limited to 'src/menu.cpp') diff --git a/include/datetime/clock-mock.h b/include/datetime/clock-mock.h index 27926ff..fb9b52f 100644 --- a/include/datetime/clock-mock.h +++ b/include/datetime/clock-mock.h @@ -45,9 +45,9 @@ public: const auto old = m_localtime; m_localtime = dt; if (!DateTime::is_same_minute(old, m_localtime)) - minuteChanged(); + minute_changed(); if (!DateTime::is_same_day(old, m_localtime)) - dateChanged(); + date_changed(); } private: diff --git a/include/datetime/clock.h b/include/datetime/clock.h index 4a9db8f..1d488d1 100644 --- a/include/datetime/clock.h +++ b/include/datetime/clock.h @@ -43,20 +43,20 @@ public: virtual DateTime localtime() const =0; /** \brief A signal which fires when the clock's minute changes */ - core::Signal<> minuteChanged; + core::Signal<> minute_changed; /** \brief A signal which fires when the clock's date changes */ - core::Signal<> dateChanged; + core::Signal<> date_changed; protected: Clock(); - /** \brief Compares old and new times, emits minuteChanged() or dateChanged() signals if appropriate */ + /** \brief Compares old and new times, emits minute_changed() or date_changed() signals if appropriate */ void maybe_emit (const DateTime& a, const DateTime& b); private: - static void onSystemBusReady(GObject*, GAsyncResult*, gpointer); - static void onPrepareForSleep(GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar*, GVariant*, gpointer); + static void on_system_bus_ready(GObject*, GAsyncResult*, gpointer); + static void on_prepare_for_sleep(GDBusConnection*, const gchar*, const gchar*, const gchar*, const gchar*, GVariant*, gpointer); GCancellable * m_cancellable = nullptr; GDBusConnection * m_system_bus = nullptr; diff --git a/include/datetime/formatter.h b/include/datetime/formatter.h index f323858..0d695e2 100644 --- a/include/datetime/formatter.h +++ b/include/datetime/formatter.h @@ -69,27 +69,27 @@ class Formatter public: /** \brief The time format string for the menu header */ - core::Property headerFormat; + core::Property header_format; - /** \brief The time string for the menu header. (eg, the headerFormat + the clock's time */ + /** \brief The time string for the menu header. (eg, the header_format + the clock's time */ core::Property header; /** \brief Signal to denote when the relativeFormat has changed. When this is emitted, clients will want to rebuild their menuitems that contain relative time strings (ie, the Appointments and Locations menuitems) */ - core::Signal<> relativeFormatChanged; + core::Signal<> relative_format_changed; /** \brief Generate a relative time format for some time (or time range) from the current clock's value. For example, a full-day interval starting at the end of the current clock's day yields "Tomorrow" */ - std::string getRelativeFormat(GDateTime* then, GDateTime* then_end=nullptr) const; + std::string relative_format(GDateTime* then, GDateTime* then_end=nullptr) const; protected: Formatter(const std::shared_ptr&); virtual ~Formatter(); - static const char* getDefaultHeaderTimeFormat(bool twelvehour, bool show_seconds); + static const char* default_header_time_format(bool twelvehour, bool show_seconds); private: @@ -127,7 +127,7 @@ class PhoneFormatter: public Formatter { public: PhoneFormatter(const std::shared_ptr& clock): Formatter(clock) { - headerFormat.set(getDefaultHeaderTimeFormat(is_locale_12h(), false)); + header_format.set(default_header_time_format(is_locale_12h(), false)); } }; diff --git a/include/datetime/planner.h b/include/datetime/planner.h index a8f9941..376a31f 100644 --- a/include/datetime/planner.h +++ b/include/datetime/planner.h @@ -43,9 +43,9 @@ public: virtual ~Planner() =default; /** - * \brief Timestamp used to determine the appointments in the `upcoming' and `thisMonth' properties. + * \brief Timestamp used to determine the appointments in the `upcoming' and `this_month' properties. * Setting this value will cause the planner to re-query its backend and - * update the `upcoming' and `thisMonth' properties. + * update the `upcoming' and `this_month' properties. */ core::Property time; @@ -57,7 +57,7 @@ public: /** * \brief The appointments that occur in the same month as the time property */ - core::Property> thisMonth; + core::Property> this_month; protected: Planner() =default; diff --git a/src/actions.cpp b/src/actions.cpp index cdeb77f..d6fa698 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -146,7 +146,7 @@ GVariant* create_default_header_state() GVariant* create_calendar_state(const std::shared_ptr& state) { gboolean days[32] = { 0 }; - for (const auto& appt : state->planner->thisMonth.get()) + for (const auto& appt : state->planner->this_month.get()) days[appt.begin.day_of_month()] = true; GVariantBuilder day_builder; @@ -222,7 +222,7 @@ Actions::Actions(const std::shared_ptr& state): m_state->planner->time.changed().connect([this](const DateTime&){ update_calendar_state(); }); - m_state->planner->thisMonth.changed().connect([this](const std::vector&){ + m_state->planner->this_month.changed().connect([this](const std::vector&){ update_calendar_state(); }); m_state->settings->show_week_numbers.changed().connect([this](bool){ diff --git a/src/clock-live.cpp b/src/clock-live.cpp index 7c9db40..21a18a3 100644 --- a/src/clock-live.cpp +++ b/src/clock-live.cpp @@ -95,7 +95,7 @@ private: { g_clear_pointer(&m_timezone, g_time_zone_unref); m_timezone = g_time_zone_new(str.c_str()); - m_owner.minuteChanged(); + m_owner.minute_changed(); } /*** @@ -109,9 +109,9 @@ private: // maybe emit change signals const auto now = localtime(); if (!DateTime::is_same_minute(m_prev_datetime, now)) - m_owner.minuteChanged(); + m_owner.minute_changed(); if (!DateTime::is_same_day(m_prev_datetime, now)) - m_owner.dateChanged(); + m_owner.date_changed(); // queue up a timer to fire at the next minute m_prev_datetime = now; diff --git a/src/clock.cpp b/src/clock.cpp index d5293cc..f41a0cc 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -33,7 +33,7 @@ namespace datetime { Clock::Clock(): m_cancellable(g_cancellable_new()) { - g_bus_get(G_BUS_TYPE_SYSTEM, m_cancellable, onSystemBusReady, this); + g_bus_get(G_BUS_TYPE_SYSTEM, m_cancellable, on_system_bus_ready, this); } Clock::~Clock() @@ -48,7 +48,7 @@ Clock::~Clock() } void -Clock::onSystemBusReady(GObject*, GAsyncResult * res, gpointer gself) +Clock::on_system_bus_ready(GObject*, GAsyncResult * res, gpointer gself) { GDBusConnection * system_bus; @@ -66,22 +66,22 @@ Clock::onSystemBusReady(GObject*, GAsyncResult * res, gpointer gself) "/org/freedesktop/login1", // object path nullptr, // arg0 G_DBUS_SIGNAL_FLAGS_NONE, - onPrepareForSleep, + on_prepare_for_sleep, self, nullptr); } } void -Clock::onPrepareForSleep(GDBusConnection* /*connection*/, - const gchar* /*sender_name*/, - const gchar* /*object_path*/, - const gchar* /*interface_name*/, - const gchar* /*signal_name*/, - GVariant* /*parameters*/, - gpointer gself) +Clock::on_prepare_for_sleep(GDBusConnection* /*connection*/, + const gchar* /*sender_name*/, + const gchar* /*object_path*/, + const gchar* /*interface_name*/, + const gchar* /*signal_name*/, + GVariant* /*parameters*/, + gpointer gself) { - static_cast(gself)->minuteChanged(); + static_cast(gself)->minute_changed(); } /*** diff --git a/src/formatter-desktop.cpp b/src/formatter-desktop.cpp index 9a098c6..336d2d3 100644 --- a/src/formatter-desktop.cpp +++ b/src/formatter-desktop.cpp @@ -81,7 +81,7 @@ DesktopFormatter::DesktopFormatter(const std::shared_ptr& clock_ void DesktopFormatter::rebuildHeaderFormat() { - headerFormat.set(getHeaderLabelFormatString()); + header_format.set(getHeaderLabelFormatString()); } std::string DesktopFormatter::getHeaderLabelFormatString() const @@ -126,7 +126,7 @@ const gchar* DesktopFormatter::getFullTimeFormatString() const break; } - return getDefaultHeaderTimeFormat(twelvehour, show_seconds); + return default_header_time_format(twelvehour, show_seconds); } const gchar* DesktopFormatter::getDateFormat(bool show_day, bool show_date, bool show_year) const diff --git a/src/formatter.cpp b/src/formatter.cpp index 638eac4..9aa9bbb 100644 --- a/src/formatter.cpp +++ b/src/formatter.cpp @@ -122,8 +122,8 @@ public: m_owner(owner), m_clock(clock) { - m_owner->headerFormat.changed().connect([this](const std::string& /*fmt*/){update_header();}); - m_clock->minuteChanged.connect([this](){update_header();}); + m_owner->header_format.changed().connect([this](const std::string& /*fmt*/){update_header();}); + m_clock->minute_changed.connect([this](){update_header();}); update_header(); restartRelativeTimer(); @@ -149,7 +149,7 @@ private: void update_header() { // update the header property - const auto fmt = m_owner->headerFormat.get(); + const auto fmt = m_owner->header_format.get(); const auto str = m_clock->localtime().format(fmt); m_owner->header.set(str); @@ -197,7 +197,7 @@ private: static gboolean onRelativeTimer(gpointer gself) { auto self = static_cast(gself); - self->m_owner->relativeFormatChanged(); + self->m_owner->relative_format_changed(); self->restartRelativeTimer(); return G_SOURCE_REMOVE; } @@ -225,7 +225,7 @@ Formatter::~Formatter() } const char* -Formatter::getDefaultHeaderTimeFormat(bool twelvehour, bool show_seconds) +Formatter::default_header_time_format(bool twelvehour, bool show_seconds) { const char* fmt; @@ -250,7 +250,7 @@ Formatter::getDefaultHeaderTimeFormat(bool twelvehour, bool show_seconds) ***/ std::string -Formatter::getRelativeFormat(GDateTime* then_begin, GDateTime* then_end) const +Formatter::relative_format(GDateTime* then_begin, GDateTime* then_end) const { auto cstr = generate_full_format_string_at_time (p->m_clock->localtime().get(), then_begin, then_end); const std::string ret = cstr; diff --git a/src/menu.cpp b/src/menu.cpp index e92d398..91f7dd2 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -90,12 +90,12 @@ protected: m_formatter->header.changed().connect([this](const std::string&){ update_header(); }); - m_formatter->headerFormat.changed().connect([this](const std::string&){ + m_formatter->header_format.changed().connect([this](const std::string&){ update_section(Locations); // need to update x-canonical-time-format }); - m_formatter->relativeFormatChanged.connect([this](){ - update_section(Appointments); // uses formatter.getRelativeFormat() - update_section(Locations); // uses formatter.getRelativeFormat() + m_formatter->relative_format_changed.connect([this](){ + update_section(Appointments); // uses formatter.relative_format() + update_section(Locations); // uses formatter.relative_format() }); m_state->settings->show_clock.changed().connect([this](bool){ update_header(); // update header's label @@ -110,7 +110,7 @@ protected: m_state->planner->upcoming.changed().connect([this](const std::vector&){ update_section(Appointments); // "upcoming" is the list of Appointments we show }); - m_state->clock->dateChanged.connect([this](){ + m_state->clock->date_changed.connect([this](){ update_section(Calendar); // need to update the Date menuitem update_section(Locations); // locations' relative time may have changed }); @@ -305,7 +305,7 @@ private: GDateTime* begin = appt.begin(); GDateTime* end = appt.end(); - auto fmt = m_formatter->getRelativeFormat(begin, end); + auto fmt = m_formatter->relative_format(begin, end); auto unix_time = g_date_time_to_unix(begin); auto menu_item = g_menu_item_new (appt.summary.c_str(), nullptr); @@ -380,7 +380,7 @@ private: const auto& zone = location.zone(); const auto& name = location.name(); const auto zone_now = now.to_timezone(zone); - const auto fmt = m_formatter->getRelativeFormat(zone_now.get()); + const auto fmt = m_formatter->relative_format(zone_now.get()); auto detailed_action = g_strdup_printf("indicator.set-location::%s %s", zone.c_str(), name.c_str()); auto i = g_menu_item_new (name.c_str(), detailed_action); g_menu_item_set_attribute(i, "x-canonical-type", "s", "com.canonical.indicator.location"); diff --git a/src/planner-eds.cpp b/src/planner-eds.cpp index 98cfe0a..cb42d6e 100644 --- a/src/planner-eds.cpp +++ b/src/planner-eds.cpp @@ -227,7 +227,7 @@ private: { getAppointments(begin, end, [this](const std::vector& appointments) { g_debug("got %d appointments in this calendar month", (int)appointments.size()); - m_owner.thisMonth.set(appointments); + m_owner.this_month.set(appointments); }); } g_clear_pointer(&begin, g_date_time_unref); diff --git a/tests/test-clock.cpp b/tests/test-clock.cpp index 4271374..4287e1c 100644 --- a/tests/test-clock.cpp +++ b/tests/test-clock.cpp @@ -54,12 +54,12 @@ TEST_F(ClockFixture, MinuteChangedSignalShouldTriggerOncePerMinute) LiveClock clock(zones); wait_msec(500); // wait for the bus to set up - // count how many times clock.minuteChanged() is emitted over the next minute + // count how many times clock.minute_changed() is emitted over the next minute const DateTime now = clock.localtime(); const auto gnow = now.get(); auto gthen = g_date_time_add_minutes(gnow, 1); int count = 0; - clock.minuteChanged.connect([&count](){count++;}); + clock.minute_changed.connect([&count](){count++;}); const auto msec = g_date_time_difference(gthen,gnow) / 1000; wait_msec(msec); EXPECT_EQ(1, count); @@ -95,7 +95,7 @@ TEST_F(ClockFixture, TimezoneChangeTriggersSkew) g_time_zone_unref(tz_nyc); /// change the timezones! - clock.minuteChanged.connect([this](){ + clock.minute_changed.connect([this](){ g_main_loop_quit(loop); }); g_idle_add([](gpointer gs){ @@ -124,7 +124,7 @@ TEST_F(ClockFixture, SleepTriggersSkew) wait_msec(500); // wait for the bus to set up bool skewed = false; - clock.minuteChanged.connect([&skewed, this](){ + clock.minute_changed.connect([&skewed, this](){ skewed = true; g_main_loop_quit(loop); return G_SOURCE_REMOVE; diff --git a/tests/test-formatter.cpp b/tests/test-formatter.cpp index 9950453..01df4f2 100644 --- a/tests/test-formatter.cpp +++ b/tests/test-formatter.cpp @@ -97,7 +97,7 @@ TEST_F(FormatterFixture, TestPhoneHeader) if(Set24hLocale()) { PhoneFormatter formatter(clock); - EXPECT_EQ(std::string("%H:%M"), formatter.headerFormat.get()); + EXPECT_EQ(std::string("%H:%M"), formatter.header_format.get()); EXPECT_EQ(std::string("18:30"), formatter.header.get()); } @@ -105,7 +105,7 @@ TEST_F(FormatterFixture, TestPhoneHeader) if(Set12hLocale()) { PhoneFormatter formatter(clock); - EXPECT_EQ(std::string("%l:%M %p"), formatter.headerFormat.get()); + EXPECT_EQ(std::string("%l:%M %p"), formatter.header_format.get()); EXPECT_EQ(std::string(" 6:30 PM"), formatter.header.get()); } } @@ -156,7 +156,7 @@ TEST_F(FormatterFixture, TestDesktopHeader) m_settings->show_date.set(test_case.show_date); m_settings->show_year.set(test_case.show_year); - ASSERT_STREQ(test_case.expected_format_string, f.headerFormat.get().c_str()); + ASSERT_STREQ(test_case.expected_format_string, f.header_format.get().c_str()); } } } @@ -196,7 +196,7 @@ TEST_F(FormatterFixture, TestUpcomingTimes) std::shared_ptr clock (new MockClock(DateTime(test_case.now))); DesktopFormatter f(clock, m_settings); - const auto fmt = f.getRelativeFormat(test_case.then); + const auto fmt = f.relative_format(test_case.then); ASSERT_EQ(test_case.expected_format_string, fmt); g_clear_pointer(&test_case.now, g_date_time_unref); @@ -239,7 +239,7 @@ TEST_F(FormatterFixture, TestEventTimes) std::shared_ptr clock(new MockClock(DateTime(test_case.now))); DesktopFormatter f(clock, m_settings); - const auto fmt = f.getRelativeFormat(test_case.then, test_case.then_end); + const auto fmt = f.relative_format(test_case.then, test_case.then_end); ASSERT_STREQ(test_case.expected_format_string, fmt.c_str()); g_clear_pointer(&test_case.now, g_date_time_unref); diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp index 562b358..eab8596 100644 --- a/tests/test-live-actions.cpp +++ b/tests/test-live-actions.cpp @@ -356,11 +356,11 @@ TEST_F(LiveActionsFixture, CalendarState) a2.begin = next_begin; a2.end = next_end; - m_state->planner->thisMonth.set(std::vector({a1, a2})); + m_state->planner->this_month.set(std::vector({a1, a2})); /// /// Now test the calendar state again. - /// The thisMonth field should now contain the appointments we just added. + /// The this_month field should now contain the appointments we just added. /// calendar_state = g_action_group_get_action_state (action_group, "calendar"); diff --git a/tests/test-planner.cpp b/tests/test-planner.cpp index 3072aea..b476ee8 100644 --- a/tests/test-planner.cpp +++ b/tests/test-planner.cpp @@ -47,9 +47,9 @@ TEST_F(PlannerFixture, EDS) planner.time.set(DateTime(now)); wait_msec(2500); - std::vector thisMonth = planner.thisMonth.get(); - std::cerr << thisMonth.size() << " appointments this month" << std::endl; - for(const auto& a : thisMonth) + std::vector this_month = planner.this_month.get(); + std::cerr << this_month.size() << " appointments this month" << std::endl; + for(const auto& a : this_month) std::cerr << a.summary << std::endl; } -- cgit v1.2.3