From 33425752728cef43c566a2ace5a54a3a31f6b36f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 2 Feb 2014 15:29:29 -0600 Subject: copyediting: use 'nullptr' instead of 'NULL' in c++ source --- 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 91f7dd2..b3dcc53 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -270,7 +270,7 @@ private: // add calendar if (show_calendar) { - item = g_menu_item_new ("[calendar]", NULL); + item = g_menu_item_new ("[calendar]", nullptr); 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", -- cgit v1.2.3 From c4e010f1cd307a5919cace98f82941a57bc91573 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 3 Feb 2014 00:05:42 -0600 Subject: update the header state when the planner's appointments change --- src/menu.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/menu.cpp') diff --git a/src/menu.cpp b/src/menu.cpp index b3dcc53..5d97859 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -108,6 +108,7 @@ protected: update_section(Appointments); // showing events got toggled }); m_state->planner->upcoming.changed().connect([this](const std::vector&){ + update_header(); // show an 'alarm' icon if there are upcoming alarms update_section(Appointments); // "upcoming" is the list of Appointments we show }); m_state->clock->date_changed.connect([this](){ -- cgit v1.2.3 From 2893b128d4aa61f9c55f2916350c898b1fa4a477 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 3 Feb 2014 21:34:40 -0600 Subject: when displaying alarms, use the 'alarm-clock' key matching the icon in ubuntu-mobile-icons --- CMakeLists.txt | 3 +-- debian/control | 1 - src/menu.cpp | 69 +++++++--------------------------------------------------- 3 files changed, 9 insertions(+), 64 deletions(-) (limited to 'src/menu.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index 53a3f7e..ab8cca4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,8 +40,7 @@ pkg_check_modules (SERVICE_DEPS REQUIRED libedataserver-1.2>=3.5 libnotify>=0.7.6 url-dispatcher-1>=1 - properties-cpp>=0.0.1 - json-glib-1.0>=0.16.2) + properties-cpp>=0.0.1) include_directories (SYSTEM ${SERVICE_DEPS_INCLUDE_DIRS}) pkg_check_modules (PANEL_DEPS diff --git a/debian/control b/debian/control index 175684f..54d265d 100644 --- a/debian/control +++ b/debian/control @@ -22,7 +22,6 @@ Build-Depends: cmake, libical-dev (>= 1.0), libgtk-3-dev (>= 3.1.4), libcairo2-dev (>= 1.10), - libjson-glib-dev, libpolkit-gobject-1-dev, libedataserver1.2-dev (>= 3.5), libgconf2-dev (>= 2.31), diff --git a/src/menu.cpp b/src/menu.cpp index 5d97859..7f41b22 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -22,8 +22,6 @@ #include #include -#include - #include #include @@ -62,7 +60,7 @@ GMenuModel* Menu::menu_model() ****/ -#define FALLBACK_ALARM_CLOCK_ICON_NAME "clock" +#define ALARM_ICON_NAME "alarm-clock" #define CALENDAR_ICON_NAME "calendar" class MenuImpl: public Menu @@ -78,9 +76,6 @@ 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() { return m_serialized_alarm_icon; } - -private: - - /* try to get the clock app's filename from click. (/$pkgdir/$icon) */ - static GVariant* create_alarm_icon() + GVariant* get_serialized_alarm_icon() { - 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) + if (G_UNLIKELY(m_serialized_alarm_icon == nullptr)) { - 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); - } - - if (icon_filename != nullptr) - { - GFile* file = g_file_new_for_path(icon_filename); - GIcon* icon = g_file_icon_new(file); - - serialized = g_icon_serialize(icon); - - g_object_unref(icon); - g_object_unref(file); - 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); + auto i = g_themed_icon_new_with_default_fallbacks(ALARM_ICON_NAME); + m_serialized_alarm_icon = g_icon_serialize(i); g_object_unref(i); } - return serialized; + return m_serialized_alarm_icon; } +private: + GVariant* get_serialized_calendar_icon() { if (G_UNLIKELY(m_serialized_calendar_icon == nullptr)) -- cgit v1.2.3 From a75d4006a59c6e58e14d21fa6820a86f52d113cd Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 5 Feb 2014 16:57:10 -0600 Subject: remove upcoming events from the menu once they're no longer upcoming. --- src/menu.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/menu.cpp') diff --git a/src/menu.cpp b/src/menu.cpp index 7f41b22..50a0087 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -239,16 +239,23 @@ private: { int n = 0; const int MAX_APPTS = 5; + const auto now = m_state->clock->localtime(); std::set added; for (const auto& appt : m_state->planner->upcoming.get()) { + // don't show too many if (n++ >= MAX_APPTS) break; + // don't show duplicates if (added.count(appt.uid)) continue; + // don't show appointments that have already started + if ((appt.begin Date: Wed, 5 Feb 2014 18:09:49 -0600 Subject: another pass at removing alarms from the menu once they're no longer upcoming. This version fixes the header's icon as well. --- include/datetime/date-time.h | 3 +++ src/date-time.cpp | 18 ++++++++++++++++++ src/menu.cpp | 37 ++++++++++++++++++++++++++++--------- 3 files changed, 49 insertions(+), 9 deletions(-) (limited to 'src/menu.cpp') diff --git a/include/datetime/date-time.h b/include/datetime/date-time.h index 2ad7856..b054a1f 100644 --- a/include/datetime/date-time.h +++ b/include/datetime/date-time.h @@ -41,6 +41,7 @@ public: DateTime& operator=(GDateTime* in); DateTime& operator=(const DateTime& in); DateTime to_timezone(const std::string& zone) const; + DateTime add_full(int years, int months, int days, int hours, int minutes, double seconds) const; void reset(GDateTime* in=nullptr); GDateTime* get() const; @@ -48,9 +49,11 @@ public: std::string format(const std::string& fmt) const; int day_of_month() const; + double seconds() const; int64_t to_unix() const; bool operator<(const DateTime& that) const; + bool operator<=(const DateTime& that) const; bool operator!=(const DateTime& that) const; bool operator==(const DateTime& that) const; diff --git a/src/date-time.cpp b/src/date-time.cpp index a634c5e..e6d99cd 100644 --- a/src/date-time.cpp +++ b/src/date-time.cpp @@ -69,6 +69,14 @@ DateTime DateTime::to_timezone(const std::string& zone) const return dt; } +DateTime DateTime::add_full(int years, int months, int days, int hours, int minutes, double seconds) const +{ + auto gdt = g_date_time_add_full(get(), years, months, days, hours, minutes, seconds); + DateTime dt(gdt); + g_date_time_unref(gdt); + return dt; +} + GDateTime* DateTime::get() const { g_assert(m_dt); @@ -88,6 +96,11 @@ int DateTime::day_of_month() const return g_date_time_get_day_of_month(get()); } +double DateTime::seconds() const +{ + return g_date_time_get_seconds(get()); +} + int64_t DateTime::to_unix() const { return g_date_time_to_unix(get()); @@ -112,6 +125,11 @@ bool DateTime::operator<(const DateTime& that) const return g_date_time_compare(get(), that.get()) < 0; } +bool DateTime::operator<=(const DateTime& that) const +{ + return g_date_time_compare(get(), that.get()) <= 0; +} + bool DateTime::operator!=(const DateTime& that) const { // return true if this isn't set, or if it's not equal diff --git a/src/menu.cpp b/src/menu.cpp index 50a0087..b2562db 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -25,6 +25,8 @@ #include #include +#include + namespace unity { namespace indicator { namespace datetime { @@ -103,13 +105,15 @@ protected: update_section(Appointments); // showing events got toggled }); m_state->planner->upcoming.changed().connect([this](const std::vector&){ - update_header(); // show an 'alarm' icon if there are upcoming alarms - update_section(Appointments); // "upcoming" is the list of Appointments we show + update_upcoming(); // our m_upcoming is planner->upcoming() filtered by time }); 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 }); + m_state->clock->minute_changed.connect([this](){ + update_upcoming(); // our m_upcoming is planner->upcoming() filtered by time + }); m_state->locations->locations.changed().connect([this](const std::vector&) { update_section(Locations); // "locations" is the list of Locations we show }); @@ -132,6 +136,24 @@ protected: g_action_group_change_action_state(action_group, action_name.c_str(), state); } + void update_upcoming() + { + const auto now = m_state->clock->localtime(); + const auto next_minute = now.add_full(0,0,0,0,1,-now.seconds()); + + std::vector upcoming; + for(const auto& a : m_state->planner->upcoming.get()) + if (next_minute <= a.begin) + upcoming.push_back(a); + + if (m_upcoming != upcoming) + { + m_upcoming.swap(upcoming); + update_header(); // show an 'alarm' icon if there are upcoming alarms + update_section(Appointments); // "upcoming" is the list of Appointments we show + } + } + std::shared_ptr m_state; std::shared_ptr m_actions; std::shared_ptr m_formatter; @@ -149,6 +171,8 @@ protected: return m_serialized_alarm_icon; } + std::vector m_upcoming; + private: GVariant* get_serialized_calendar_icon() @@ -239,10 +263,9 @@ private: { int n = 0; const int MAX_APPTS = 5; - const auto now = m_state->clock->localtime(); std::set added; - for (const auto& appt : m_state->planner->upcoming.get()) + for (const auto& appt : m_upcoming) { // don't show too many if (n++ >= MAX_APPTS) @@ -252,10 +275,6 @@ private: if (added.count(appt.uid)) continue; - // don't show appointments that have already started - if ((appt.beginplanner->upcoming.get()) + for(const auto& appointment : m_upcoming) if((has_alarms = appointment.has_alarms)) break; -- cgit v1.2.3