aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/datetime/actions-live.h1
-rw-r--r--include/datetime/actions.h1
-rw-r--r--src/actions-live.cpp24
-rw-r--r--src/menu.cpp19
-rw-r--r--tests/actions-mock.h5
-rw-r--r--tests/test-menus.cpp52
6 files changed, 76 insertions, 26 deletions
diff --git a/include/datetime/actions-live.h b/include/datetime/actions-live.h
index 3607836..a24b844 100644
--- a/include/datetime/actions-live.h
+++ b/include/datetime/actions-live.h
@@ -42,6 +42,7 @@ public:
void open_desktop_settings();
void open_phone_settings();
void open_phone_clock_app();
+ bool can_open_planner() const;
void open_planner();
void open_planner_at(const DateTime&);
void open_appointment(const std::string& uid);
diff --git a/include/datetime/actions.h b/include/datetime/actions.h
index 99e78f5..2c4217c 100644
--- a/include/datetime/actions.h
+++ b/include/datetime/actions.h
@@ -45,6 +45,7 @@ public:
virtual void open_desktop_settings() =0;
virtual void open_phone_settings() =0;
virtual void open_phone_clock_app() =0;
+ virtual bool can_open_planner() const = 0;
virtual void open_planner() =0;
virtual void open_planner_at(const DateTime&) =0;
virtual void open_appointment(const std::string& uid) =0;
diff --git a/src/actions-live.cpp b/src/actions-live.cpp
index c179274..97b12db 100644
--- a/src/actions-live.cpp
+++ b/src/actions-live.cpp
@@ -74,6 +74,30 @@ void LiveActions::open_desktop_settings()
g_free (path);
}
+bool LiveActions::can_open_planner() const
+{
+ static bool inited = false;
+ static bool have_calendar = false;
+
+ if (G_UNLIKELY(!inited))
+ {
+ inited = true;
+
+ auto all = g_app_info_get_all_for_type ("text/calendar");
+ for(auto l=all; !have_calendar && l!=nullptr; l=l->next)
+ {
+ auto app_info = static_cast<GAppInfo*>(l->data);
+
+ if (!g_strcmp0("evolution.desktop", g_app_info_get_id(app_info)))
+ have_calendar = true;
+ }
+
+ g_list_free_full(all, (GDestroyNotify)g_object_unref);
+ }
+
+ return have_calendar;
+}
+
void LiveActions::open_planner()
{
execute_command("evolution -c calendar");
diff --git a/src/menu.cpp b/src/menu.cpp
index d6abd27..90ef41f 100644
--- a/src/menu.cpp
+++ b/src/menu.cpp
@@ -308,7 +308,7 @@ private:
g_menu_item_set_action_and_target_value (menu_item,
"indicator.activate-appointment",
g_variant_new_string (appt.uid.c_str()));
- else
+ else if (m_actions->can_open_planner())
g_menu_item_set_action_and_target_value (menu_item,
"indicator.activate-planner",
g_variant_new_int64 (unix_time));
@@ -325,13 +325,16 @@ private:
{
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);
+ if (m_actions->can_open_planner())
+ {
+ // 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);
+ }
}
else if (profile==Phone)
{
diff --git a/tests/actions-mock.h b/tests/actions-mock.h
index da93cb9..ebd8a4d 100644
--- a/tests/actions-mock.h
+++ b/tests/actions-mock.h
@@ -49,6 +49,8 @@ public:
void open_phone_clock_app() { m_history.push_back(OpenPhoneClockApp); }
+ bool can_open_planner() const { return m_can_open_planner; }
+
void open_planner() { m_history.push_back(OpenPlanner); }
void open_planner_at(const DateTime& date_time_) {
@@ -67,7 +69,10 @@ public:
m_url = url_;
}
+ void set_can_open_planner(bool b) { m_can_open_planner = b; }
+
private:
+ bool m_can_open_planner = true;
std::string m_url;
std::string m_zone;
std::string m_name;
diff --git a/tests/test-menus.cpp b/tests/test-menus.cpp
index 61d1295..29d86b3 100644
--- a/tests/test-menus.cpp
+++ b/tests/test-menus.cpp
@@ -252,7 +252,8 @@ private:
void InspectAppointmentMenuItems(GMenuModel* section,
int first_appt_index,
- const std::vector<Appointment>& appointments)
+ const std::vector<Appointment>& appointments,
+ bool can_open_planner)
{
// try adding a few appointments and see if the menu updates itself
m_state->calendar_upcoming->appointments().set(appointments);
@@ -260,7 +261,8 @@ private:
//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));
+ const int n_add_event_buttons = can_open_planner ? 1 : 0;
+ EXPECT_EQ(n_add_event_buttons + appointments.size(), g_menu_model_get_n_items(section));
for (int i=0, n=appointments.size(); i<n; i++)
InspectAppointmentMenuItem(section, first_appt_index+i, appointments[i]);
@@ -269,8 +271,10 @@ private:
//g_clear_object(&submenu);
}
- void InspectDesktopAppointments(GMenuModel* menu_model)
+ void InspectDesktopAppointments(GMenuModel* menu_model, bool can_open_planner)
{
+ const int n_add_event_buttons = can_open_planner ? 1 : 0;
+
// get the Appointments section
auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU);
@@ -281,20 +285,23 @@ private:
EXPECT_EQ(0, g_menu_model_get_n_items(section));
g_clear_object(&section);
- // when "show_events" is true,
- // there should be an "add event" button even if there aren't any appointments
std::vector<Appointment> appointments;
m_state->settings->show_events.set(true);
m_state->calendar_upcoming->appointments().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);
+ EXPECT_EQ(n_add_event_buttons, g_menu_model_get_n_items(section));
+ if (can_open_planner)
+ {
+ // when "show_events" is true,
+ // there should be an "add event" button even if there aren't any appointments
+ 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(&section);
// try adding a few appointments and see if the menu updates itself
@@ -302,15 +309,15 @@ private:
m_state->calendar_upcoming->appointments().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);
+ EXPECT_EQ(n_add_event_buttons + 2, g_menu_model_get_n_items(section));
+ InspectAppointmentMenuItems(section, 0, appointments, can_open_planner);
g_clear_object(&section);
// cleanup
g_clear_object(&submenu);
}
- void InspectPhoneAppointments(GMenuModel* menu_model)
+ void InspectPhoneAppointments(GMenuModel* menu_model, bool can_open_planner)
{
auto submenu = g_menu_model_get_item_link(menu_model, 0, G_MENU_LINK_SUBMENU);
@@ -336,7 +343,7 @@ private:
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);
+ InspectAppointmentMenuItems(section, 1, appointments, can_open_planner);
g_clear_object(&section);
// cleanup
@@ -347,10 +354,12 @@ protected:
void InspectAppointments(GMenuModel* menu_model, Menu::Profile profile)
{
+ const auto can_open_planner = m_actions->can_open_planner();
+
switch (profile)
{
case Menu::Desktop:
- InspectDesktopAppointments(menu_model);
+ InspectDesktopAppointments(menu_model, can_open_planner);
break;
case Menu::DesktopGreeter:
@@ -358,7 +367,7 @@ protected:
break;
case Menu::Phone:
- InspectPhoneAppointments(menu_model);
+ InspectPhoneAppointments(menu_model, can_open_planner);
break;
case Menu::PhoneGreeter:
@@ -507,6 +516,13 @@ TEST_F(MenuFixture, Appointments)
{
for(auto& menu : m_menus)
InspectAppointments(menu->menu_model(), menu->profile());
+
+ // toggle can_open_planner() and test the desktop again
+ // to confirm that the "Add Event…" menuitem appears iff
+ // there's a calendar available user-agent
+ m_mock_actions->set_can_open_planner (!m_actions->can_open_planner());
+ std::shared_ptr<Menu> menu = m_menu_factory->buildMenu(Menu::Desktop);
+ InspectAppointments(menu->menu_model(), menu->profile());
}
TEST_F(MenuFixture, Locations)