Index: code/branches/presentation3/src/modules/questsystem/notifications/NotificationManager.cc
===================================================================
--- code/branches/presentation3/src/modules/questsystem/notifications/NotificationManager.cc	(revision 6912)
+++ code/branches/presentation3/src/modules/questsystem/notifications/NotificationManager.cc	(revision 6944)
@@ -66,4 +66,5 @@
     NotificationManager::~NotificationManager()
     {
+        
     }
 
@@ -101,10 +102,52 @@
                 this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationListener.
                 it->first->update(notification, time); //!< Update the listener.
+                std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(notification);
+                if(counterIt == this->listenerCounter_.end())
+                    this->listenerCounter_[notification] = 1;
+                else
+                    this->listenerCounter_[notification] = counterIt->second + 1;
             }
         }
 
-        COUT(3) << "Notification registered with the NotificationManager." << std::endl;
+        COUT(4) << "Notification registered with the NotificationManager." << std::endl;
 
         return true;
+    }
+
+    /**
+    @brief
+        Unregisters a Notification within the NotificationManager.
+    */
+    void NotificationManager::unregisterNotification(Notification* notification, NotificationListener* listener)
+    {
+        assert(notification);
+        assert(listener);
+
+        if(this->removeNotification(notification, *(this->notificationLists_.find(this->listenerList_.find(listener)->second)->second)))
+            this->listenerCounter_[notification] = this->listenerCounter_[notification] - 1;
+        if(this->listenerCounter_[notification] == (unsigned int) 0)
+        {
+            this->removeNotification(notification, this->allNotificationsList_);
+            notification->destroy();
+        }
+
+        COUT(4) << "Notification unregistered with the NotificationManager." << std::endl;
+    }
+
+    /**
+    @brief
+        Helper method that removes an input notification form an input map.
+    */
+    bool NotificationManager::removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map)
+    {
+        for(std::multimap<std::time_t, Notification*>::iterator it = map.begin(); it != map.end(); it++)
+        {
+            if(it->second == notification)
+            {
+                map.erase(it);
+                return true;
+            }
+        }
+        return false;
     }
 
@@ -130,5 +173,5 @@
         {
             this->notificationLists_[index] = &this->allNotificationsList_;
-            COUT(3) << "NotificationListener registered with the NotificationManager." << std::endl;
+            COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl;
             return true;
         }
@@ -142,5 +185,10 @@
             if(set.find(it->second->getSender()) != set.end()) //!< Checks whether the overlay has the sender of the current notification as target.
             {
-                map.insert(std::pair<std::time_t,Notification*>(it->first, it->second));
+                map.insert(std::pair<std::time_t, Notification*>(it->first, it->second));
+                std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(it->second);
+                if(counterIt == this->listenerCounter_.end())
+                    this->listenerCounter_[it->second] = 1;
+                else
+                    this->listenerCounter_[it->second] = counterIt->second + 1;
             }
         }
@@ -148,7 +196,33 @@
         listener->update(); //!< Update the listener.
 
-        COUT(3) << "NotificationListener registered with the NotificationManager." << std::endl;
+        COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl;
 
         return true;
+    }
+
+    /**
+    @brief
+        Unregisters a NotificationListener withing the NotificationManager.
+    */
+    void NotificationManager::unregisterListener(NotificationListener* listener)
+    {
+        assert(listener);
+
+        int identifier = this->listenerList_.find(listener)->second;
+        std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(identifier)->second;
+        
+        // Make sure all Notifications are removed.
+        std::multimap<std::time_t, Notification*>::iterator it = map->begin();
+        while(it != map->end())
+        {
+            this->unregisterNotification(it->second, listener);
+            it = map->begin();
+        }
+
+        this->listenerList_.erase(listener);
+        this->notificationLists_.erase(identifier);
+        delete map;
+
+        COUT(4) << "NotificationListener unregistered with the NotificationManager." << std::endl;
     }
 
