diff options
Diffstat (limited to 'src/menu.cpp')
-rw-r--r-- | src/menu.cpp | 84 |
1 files changed, 60 insertions, 24 deletions
diff --git a/src/menu.cpp b/src/menu.cpp index 4ed0a03..bdf92c3 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -35,6 +35,33 @@ 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; +} + +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" @@ -43,9 +70,9 @@ class MenuImpl: public Menu protected: MenuImpl(const Menu::Profile profile_in, const std::string& name_in, - std::shared_ptr<State>& state, + std::shared_ptr<const State>& state, std::shared_ptr<Actions>& actions, - std::shared_ptr<Formatter> formatter): + std::shared_ptr<const Formatter> formatter): Menu(profile_in, name_in), m_state(state), m_actions(actions), @@ -60,12 +87,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 @@ -80,7 +107,7 @@ protected: m_state->planner->upcoming.changed().connect([this](const std::vector<Appointment>&){ 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 }); @@ -106,9 +133,9 @@ protected: g_action_group_change_action_state(action_group, action_name.c_str(), state); } - std::shared_ptr<State> m_state; + std::shared_ptr<const State> m_state; std::shared_ptr<Actions> m_actions; - std::shared_ptr<Formatter> m_formatter; + std::shared_ptr<const Formatter> m_formatter; GMenu* m_submenu = nullptr; GVariant* get_serialized_alarm_icon() @@ -281,7 +308,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); @@ -296,10 +323,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, @@ -318,7 +345,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); @@ -330,6 +357,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); } @@ -347,7 +383,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"); @@ -417,10 +453,10 @@ class DesktopBaseMenu: public MenuImpl protected: DesktopBaseMenu(Menu::Profile profile_, const std::string& name_, - std::shared_ptr<State>& state_, + std::shared_ptr<const State>& state_, std::shared_ptr<Actions>& actions_): MenuImpl(profile_, name_, state_, actions_, - std::shared_ptr<Formatter>(new DesktopFormatter(state_->clock, state_->settings))) + std::shared_ptr<const Formatter>(new DesktopFormatter(state_->clock, state_->settings))) { update_header(); } @@ -444,14 +480,14 @@ protected: class DesktopMenu: public DesktopBaseMenu { public: - DesktopMenu(std::shared_ptr<State>& state_, std::shared_ptr<Actions>& actions_): + DesktopMenu(std::shared_ptr<const State>& state_, std::shared_ptr<Actions>& actions_): DesktopBaseMenu(Desktop,"desktop", state_, actions_) {} }; class DesktopGreeterMenu: public DesktopBaseMenu { public: - DesktopGreeterMenu(std::shared_ptr<State>& state_, std::shared_ptr<Actions>& actions_): + DesktopGreeterMenu(std::shared_ptr<const State>& state_, std::shared_ptr<Actions>& actions_): DesktopBaseMenu(DesktopGreeter,"desktop_greeter", state_, actions_) {} }; @@ -460,7 +496,7 @@ class PhoneBaseMenu: public MenuImpl protected: PhoneBaseMenu(Menu::Profile profile_, const std::string& name_, - std::shared_ptr<State>& state_, + std::shared_ptr<const State>& state_, std::shared_ptr<Actions>& actions_): MenuImpl(profile_, name_, state_, actions_, std::shared_ptr<Formatter>(new PhoneFormatter(state_->clock))) @@ -501,7 +537,7 @@ protected: class PhoneMenu: public PhoneBaseMenu { public: - PhoneMenu(std::shared_ptr<State>& state_, + PhoneMenu(std::shared_ptr<const State>& state_, std::shared_ptr<Actions>& actions_): PhoneBaseMenu(Phone, "phone", state_, actions_) {} }; @@ -509,7 +545,7 @@ public: class PhoneGreeterMenu: public PhoneBaseMenu { public: - PhoneGreeterMenu(std::shared_ptr<State>& state_, + PhoneGreeterMenu(std::shared_ptr<const State>& state_, std::shared_ptr<Actions>& actions_): PhoneBaseMenu(PhoneGreeter, "phone_greeter", state_, actions_) {} }; @@ -518,8 +554,8 @@ public: ***** ****/ -MenuFactory::MenuFactory(std::shared_ptr<Actions>& actions_, - std::shared_ptr<State>& state_): +MenuFactory::MenuFactory(const std::shared_ptr<Actions>& actions_, + const std::shared_ptr<const State>& state_): m_actions(actions_), m_state(state_) { |