aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-08-01 11:42:43 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-08-01 11:42:43 -0500
commit6da58726eb18e7205845ec1af4cb43d08d988e31 (patch)
tree88ffdb6f7938c2726efd068b092e849a7787e5c3
parent03e9b9479840493bb1edb17ccb42c175a4b2163e (diff)
downloadayatana-indicator-datetime-6da58726eb18e7205845ec1af4cb43d08d988e31.tar.gz
ayatana-indicator-datetime-6da58726eb18e7205845ec1af4cb43d08d988e31.tar.bz2
ayatana-indicator-datetime-6da58726eb18e7205845ec1af4cb43d08d988e31.zip
refactor changes based on Antti's feedback
-rw-r--r--include/notifications/CMakeLists.txt2
-rw-r--r--src/notifications.cpp27
2 files changed, 14 insertions, 15 deletions
diff --git a/include/notifications/CMakeLists.txt b/include/notifications/CMakeLists.txt
index 139597f..e69de29 100644
--- a/include/notifications/CMakeLists.txt
+++ b/include/notifications/CMakeLists.txt
@@ -1,2 +0,0 @@
-
-
diff --git a/src/notifications.cpp b/src/notifications.cpp
index da7351b..dfb1dc6 100644
--- a/src/notifications.cpp
+++ b/src/notifications.cpp
@@ -156,14 +156,14 @@ public:
void close_all ()
{
- // close() removes the item from m_notifications,
- // so increment the iterator before it gets invalidated
- for (auto it=m_notifications.begin(), e=m_notifications.end(); it!=e; )
- {
- const int key = it->first;
- ++it;
- close (key);
- }
+ // call close() on all our keys
+
+ std::set<int> keys;
+ for (const auto& it : m_notifications)
+ keys.insert (it.first);
+
+ for (const int key : keys)
+ close (key);
}
void close (int key)
@@ -171,15 +171,16 @@ public:
auto it = m_notifications.find(key);
if (it != m_notifications.end())
{
- // tell the server to close, call the close() callback,
- // and immediately forget about the nn.
+ // tell the server to close the notification
GError * error = nullptr;
if (!notify_notification_close (it->second.nn.get(), &error))
{
g_warning ("Unable to close notification %d: %s", key, error->message);
g_error_free (error);
}
- on_closed (key);
+
+ // call the user callback and remove it from our bookkeeping
+ remove_closed_notification (key);
}
}
@@ -270,10 +271,10 @@ private:
{
const GQuark q = notification_key_quark();
const gpointer gkey = g_object_get_qdata(G_OBJECT(nn), q);
- static_cast<Impl*>(gself)->on_closed(GPOINTER_TO_INT(gkey));
+ static_cast<Impl*>(gself)->remove_closed_notification(GPOINTER_TO_INT(gkey));
}
- void on_closed (int key)
+ void remove_closed_notification (int key)
{
auto it = m_notifications.find(key);
g_return_if_fail (it != m_notifications.end());