From df650bec0f1c634ee773c150b451c3bdd8ed4e65 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 6 Mar 2014 17:54:57 -0600 Subject: =?UTF-8?q?In=20the=20Desktop=20profile,=20don't=20show=20the=20'A?= =?UTF-8?q?dd=20Event=E2=80=A6'=20button=20if=20evolution=20can't=20be=20l?= =?UTF-8?q?aunched.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/datetime/actions-live.h | 1 + include/datetime/actions.h | 1 + src/actions-live.cpp | 24 +++++++++++++++++++ src/menu.cpp | 19 ++++++++------- tests/actions-mock.h | 5 ++++ tests/test-menus.cpp | 52 +++++++++++++++++++++++++++-------------- 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 ccc7fcf..8fce6ad 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 +{ + bool inited = false; + bool have_evolution = false; + + if (G_UNLIKELY(!inited)) + { + inited = true; + + auto all = g_app_info_get_all_for_type ("text/calendar"); + for(auto l=all; !have_evolution && l!=nullptr; l=l->next) + { + auto app_info = static_cast(l->data); + + if (!g_strcmp0("evolution", g_app_info_get_executable(app_info))) + have_evolution = true; + } + + g_list_free_full(all, (GDestroyNotify)g_object_unref); + } + + return have_evolution; +} + void LiveActions::open_planner() { execute_command("evolution -c calendar"); diff --git a/src/menu.cpp b/src/menu.cpp index 797757f..f88c290 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -302,7 +302,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)); @@ -319,13 +319,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 73d6036..452cbfc 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& appointments) + const std::vector& appointments, + bool can_open_planner) { // try adding a few appointments and see if the menu updates itself m_state->planner->upcoming.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 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); + 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(§ion); // try adding a few appointments and see if the menu updates itself @@ -302,15 +309,15 @@ private: 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); + EXPECT_EQ(n_add_event_buttons + 2, g_menu_model_get_n_items(section)); + InspectAppointmentMenuItems(section, 0, appointments, can_open_planner); g_clear_object(§ion); // 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(§ion); // 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 = m_menu_factory->buildMenu(Menu::Desktop); + InspectAppointments(menu->menu_model(), menu->profile()); } TEST_F(MenuFixture, Locations) -- cgit v1.2.3 From 01dca64fc75b6bff4494f1886f2397f6fd0ad8d1 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 13 Mar 2014 17:00:19 -0500 Subject: test for evolution with g_app_info_get_id() rather than g_app_info_get_name() --- src/actions-live.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/actions-live.cpp b/src/actions-live.cpp index f8ef4e8..51d96c6 100644 --- a/src/actions-live.cpp +++ b/src/actions-live.cpp @@ -76,26 +76,26 @@ void LiveActions::open_desktop_settings() bool LiveActions::can_open_planner() const { - bool inited = false; - bool have_evolution = false; + 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_evolution && l!=nullptr; l=l->next) + for(auto l=all; !have_calendar && l!=nullptr; l=l->next) { auto app_info = static_cast(l->data); - if (!g_strcmp0("evolution", g_app_info_get_executable(app_info))) - have_evolution = true; + 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_evolution; + return have_calendar; } void LiveActions::open_planner() -- cgit v1.2.3