diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2014-08-08 15:31:49 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2014-08-08 15:31:49 -0500 |
commit | 9cc6380c1cb0c4e96a893a1b9d2720d2ed3181bd (patch) | |
tree | c4998c28ec72c215ccb8bff40ef5851e826358ac /src | |
parent | 91c7ce04f148bbeed31ac65d41a6e20b2c080014 (diff) | |
download | ayatana-indicator-datetime-9cc6380c1cb0c4e96a893a1b9d2720d2ed3181bd.tar.gz ayatana-indicator-datetime-9cc6380c1cb0c4e96a893a1b9d2720d2ed3181bd.tar.bz2 ayatana-indicator-datetime-9cc6380c1cb0c4e96a893a1b9d2720d2ed3181bd.zip |
in notifications, don't ask the notification server for its capabilities until we need them.
Diffstat (limited to 'src')
-rw-r--r-- | src/notifications.cpp | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/src/notifications.cpp b/src/notifications.cpp index b19fa48..18f15d9 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -120,21 +120,6 @@ public: { if (!notify_init(app_name.c_str())) g_critical("Unable to initialize libnotify!"); - - // put the server capabilities into m_caps - auto caps_gl = notify_get_server_caps(); - std::string caps_str; - for(auto l=caps_gl; l!=nullptr; l=l->next) - { - m_caps.insert((const char*)l->data); - - caps_str += (const char*) l->data;; - if (l->next != nullptr) - caps_str += ", "; - } - - g_debug("%s notify_get_server() returned [%s]", G_STRFUNC, caps_str.c_str()); - g_list_free_full(caps_gl, g_free); } ~Impl() @@ -151,7 +136,7 @@ public: bool supports_actions() const { - return m_caps.count("actions") != 0; + return server_caps().count("actions") != 0; } void close_all () @@ -255,6 +240,28 @@ public: private: + const std::set<std::string>& server_caps() const + { + if (G_UNLIKELY(m_lazy_caps.empty())) + { + auto caps_gl = notify_get_server_caps(); + std::string caps_str; + for(auto l=caps_gl; l!=nullptr; l=l->next) + { + m_lazy_caps.insert((const char*)l->data); + + caps_str += (const char*) l->data;; + if (l->next != nullptr) + caps_str += ", "; + } + + g_debug("%s notify_get_server() returned [%s]", G_STRFUNC, caps_str.c_str()); + g_list_free_full(caps_gl, g_free); + } + + return m_lazy_caps; + } + static void on_notification_clicked (NotifyNotification * nn, char * action, gpointer) @@ -303,8 +310,9 @@ private: // key-to-data std::map<int,notification_data> m_notifications; - // server capabilities - std::set<std::string> m_caps; + // server capabilities. + // as the name indicates, don't use this directly: use server_caps() instead + mutable std::set<std::string> m_lazy_caps; static constexpr char const * HINT_TIMEOUT {"x-canonical-snap-decisions-timeout"}; }; |