Index: code/branches/notifications/src/modules/notifications/CMakeLists.txt
===================================================================
--- code/branches/notifications/src/modules/notifications/CMakeLists.txt	(revision 7362)
+++ code/branches/notifications/src/modules/notifications/CMakeLists.txt	(revision 7395)
@@ -13,4 +13,5 @@
   TOLUA_FILES
     NotificationManager.h
+    NotificationQueue.h
   PCH_FILE
     NotificationsPrecompiledHeaders.h
Index: code/branches/notifications/src/modules/notifications/NotificationManager.cc
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationManager.cc	(revision 7362)
+++ code/branches/notifications/src/modules/notifications/NotificationManager.cc	(revision 7395)
@@ -28,5 +28,5 @@
 
 /**
-    @file
+    @file NotificationManager.cc
     @brief Implementation of the NotificationManager class.
 */
@@ -43,4 +43,6 @@
 #include "NotificationQueue.h"
 
+#include "ToluaBindNotifications.h"
+
 namespace orxonox
 {
@@ -49,4 +51,7 @@
     const std::string NotificationManager::NONE("none");
 
+    // Register tolua_open function when loading the library.
+    DeclareToluaInterface(Notifications);
+
     ManageScopedSingleton(NotificationManager, ScopeID::Graphics, false);
 
@@ -65,12 +70,6 @@
 
         ModifyConsoleCommand("enterEditMode").setObject(this);
-
-        if(GameMode::showsGraphics())
-        {
-            GUIManager::getInstance().loadGUI("NotificationLayer");
-
-            // Create first queue:
-            this->queues_.push_back(new NotificationQueue("all"));
-        }
+        
+        COUT(3) << "NotificatioManager created." << std::endl;
     }
 
@@ -82,10 +81,19 @@
     {
         ModifyConsoleCommand("enterEditMode").setObject(NULL);
+
+        for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
+            it->second->destroy();
+        
+        COUT(3) << "NotificationManager destroyed." << std::endl;
     }
 
     void NotificationManager::preDestroy(void)
     {
-        for(std::vector<NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); it++)
-            (*it)->destroy();
+        for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); )
+        {
+            NotificationQueue* queue = (*it).second;
+            it++;
+            queue->destroy();
+        }
         this->queues_.clear();
     }
@@ -101,17 +109,16 @@
     bool NotificationManager::registerNotification(Notification* notification)
     {
-
-        if(notification == NULL) //!< A NULL-Notification cannot be registered.
+        if(notification == NULL) // A NULL-Notification cannot be registered.
             return false;
 
         std::time_t time = std::time(0); //TODO: Doesn't this expire? //!< Get current time.
 
-        this->allNotificationsList_.insert(std::pair<std::time_t,Notification*>(time,notification));
-
-        if(notification->getSender() == NONE) // If the sender has no specific name, then the Notification is only added to the list of all Notifications.
+        this->allNotificationsList_.insert(std::pair<std::time_t, Notification*>(time, notification));
+
+        if(notification->getSender() == NotificationManager::NONE) // If the sender has no specific name, then the Notification is only added to the list of all Notifications.
             return true;
 
         bool all = false;
-        if(notification->getSender() == ALL) // If all are the sender, then the Notifications is added to every NotificationListener.
+        if(notification->getSender() == NotificationManager::ALL) // If all are the sender, then the Notifications is added to every NotificationListener.
             all = true;
 
@@ -119,8 +126,12 @@
         for(std::map<NotificationListener*,int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) // Iterate through all listeners.
         {
-            std::set<std::string> set = it->first->getTargetsSet();
-            if(all || set.find(notification->getSender()) != set.end() || set.find(ALL) != set.end()) //TODO: Make sure this works.
+            std::set<std::string, NotificationListenerStringCompare> set = it->first->getTargetsSet();
+            bool bAll = set.find(NotificationManager::ALL) != set.end();
+            if(all || bAll || set.find(notification->getSender()) != set.end()) //TODO: Make sure this works.
             {
-                this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); // Insert the Notification in the Notifications list of the current NotificationListener.
+                if(!bAll)
+                {
+                    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);
@@ -132,5 +143,5 @@
         }
 
-        COUT(4) << "Notification registered with the NotificationManager." << std::endl;
+        COUT(4) << "Notification (&" << notification << ") registered with the NotificationManager." << std::endl;
 
         return true;
@@ -154,13 +165,5 @@
             this->listenerCounter_[notification] = this->listenerCounter_[notification] - 1;
 
-        // If the Notification is no longer present in any of the NotificationListeners it can be removed from the map of all Notifications and be destroyed.
-        if(this->listenerCounter_[notification] == (unsigned int) 0)
-        {
-            this->removeNotification(notification, this->allNotificationsList_);
-            this->listenerCounter_.erase(notification);
-            notification->destroy();
-        }
-
-        COUT(4) << "Notification unregistered with the NotificationManager." << std::endl;
+        COUT(4) << "Notification (&" << notification << ")unregistered with the NotificationManager from listener (&" << listener << ")" << std::endl;
     }
 
@@ -175,5 +178,4 @@
         Returns true if successful.
     */
-    //TODO: Needed?
     bool NotificationManager::removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map)
     {
@@ -206,23 +208,24 @@
         this->listenerList_[listener] = index; // Add the NotificationListener to the list of listeners.
 
-        std::set<std::string> set = listener->getTargetsSet(); //TODO: Does this work?
+        std::set<std::string, NotificationListenerStringCompare> set = listener->getTargetsSet();
 
         // If all senders are the target of the listener, then the list of notification for that specific listener is te same as the list of all Notifications.
-        if(set.find(ALL) != set.end())
-        {
+        bool bAll = set.find(NotificationManager::ALL) != set.end();
+        std::multimap<std::time_t, Notification*> map;
+        if(bAll)
             this->notificationLists_[index] = &this->allNotificationsList_;
-            COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl;
-            return true;
-        }
-
-        this->notificationLists_[index] = new std::multimap<std::time_t,Notification*>;
-        std::multimap<std::time_t,Notification*> map = *this->notificationLists_[index];
+        else
+        {
+            this->notificationLists_[index] = new std::multimap<std::time_t, Notification*>;
+            map = *this->notificationLists_[index];
+        }
 
         // Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationListener.
-        for(std::multimap<std::time_t,Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
-        {
-            if(set.find(it->second->getSender()) != set.end()) // Checks whether the overlay has the sender of the current notification as target.
+        for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
+        {
+            if(bAll || set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current notification as target.
             {
-                map.insert(std::pair<std::time_t, Notification*>(it->first, it->second));
+                if(!bAll)
+                    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())
@@ -288,24 +291,46 @@
             return false;
 
-        std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // The Notifications for the input NotificationListener.
-
-        if(notifications == NULL) // Returns NULL, if there are no Notifications.
-            return true;
+        std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // The Notifications for the input NotificationListener.
+
+        if(notifications == NULL) // Returns false, if there are no Notifications.
+            return false;
 
         std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest;
         itLowest = notifications->lower_bound(timeFrameStart);
-        itHighest = notifications->upper_bound(timeFrameStart);
+        itHighest = notifications->upper_bound(timeFrameEnd);
 
         for(it = itLowest; it != itHighest; it++) // Iterate through the Notifications from the start of the time Frame to the end of it.
-        {
-            map->insert(std::pair<std::time_t,Notification*>(it->first,it->second)); // Add the found Notifications to the map.
-        }
+            map->insert(std::pair<std::time_t, Notification*>(it->first,it->second)); // Add the found Notifications to the map.
 
         return true;
     }
 
-    void NotificationManager::createQueue(const std::string& name, const std::string& targets, unsigned int size, unsigned int displayTime)
-    {
-        this->queues_.push_back(new NotificationQueue(name, targets, size, displayTime));
+    void NotificationManager::loadQueues(void)
+    {
+        new NotificationQueue("all");
+    }
+
+    void NotificationManager::createQueue(const std::string& name)
+    {
+        new NotificationQueue(name);
+    }
+
+    NotificationQueue* NotificationManager::getQueue(const std::string & name)
+    {
+        std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.find(name);
+        if(it == this->queues_.end())
+            return NULL;
+
+        return (*it).second;
+    }
+
+    bool NotificationManager::registerQueue(NotificationQueue* queue)
+    {
+        return this->queues_.insert(std::pair<const std::string, NotificationQueue*>(queue->getName(), queue)).second;
+    }
+    
+    void NotificationManager::unregisterQueue(NotificationQueue* queue)
+    {
+        this->queues_.erase(queue->getName());
     }
 
Index: code/branches/notifications/src/modules/notifications/NotificationManager.h
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationManager.h	(revision 7362)
+++ code/branches/notifications/src/modules/notifications/NotificationManager.h	(revision 7395)
@@ -28,5 +28,5 @@
 
 /**
-    @file
+    @file NotificationManager.h
     @brief Definition of the NotificationManager class.
 */
@@ -40,5 +40,4 @@
 #include <map>
 #include <string>
-#include <vector>
 
 #include "util/Singleton.h"
@@ -55,5 +54,5 @@
         Damian 'Mozork' Frick
     */
-    class _NotificationsExport NotificationManager  // tolua_export
+    class _NotificationsExport NotificationManager // tolua_export
         : public Singleton<NotificationManager>, public OrxonoxClass
     { // tolua_export
@@ -75,5 +74,5 @@
             void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager.
 
-            bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationListener in a specified timeframe.
+            bool getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationListener in a specified timeframe.
 
             /**
@@ -84,21 +83,29 @@
             @return Returns true if successful.
             */
-            bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, int timeDelay)
+            bool getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay)
                 { return this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); }
 
             void enterEditMode(void);
 
-            void createQueue(const std::string& name, const std::string& targets, unsigned int size, unsigned int displayTime); // tolua_export
+            // tolua_begin
+            void loadQueues(void);
+            
+            void createQueue(const std::string& name);
+            orxonox::NotificationQueue* getQueue(const std::string & name);
+            // tolua_end
+
+            bool registerQueue(NotificationQueue* queue);
+            void unregisterQueue(NotificationQueue* queue);
 
         private:
             static NotificationManager* singletonPtr_s;
 
-            std::vector<NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager.
+            std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager.
 
             int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.
 
-            std::multimap<std::time_t,Notification*> allNotificationsList_; //!< Container where all notifications are stored.
-            std::map<NotificationListener*,int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier.
-            std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored.
+            std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all notifications are stored.
+            std::map<NotificationListener*, int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier.
+            std::map<int,std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored.
             std::map<Notification*, unsigned int> listenerCounter_; //!< A container to store the number of NotificationListeners a Notification is registered with.
 
Index: code/branches/notifications/src/modules/notifications/NotificationQueue.cc
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationQueue.cc	(revision 7362)
+++ code/branches/notifications/src/modules/notifications/NotificationQueue.cc	(revision 7395)
@@ -35,4 +35,5 @@
 
 #include <map>
+#include <sstream>
 
 #include "core/CoreIncludes.h"
@@ -62,8 +63,23 @@
         this->setDisplayTime(displayTime);
 
+        bool queueRegistered = NotificationManager::getInstance().registerQueue(this);
+        this->registered_ = true;
+        if(!queueRegistered)
+        {
+            this->registered_ = false;
+            COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl;
+            return;
+        }
+
         this->create();
-
-        NotificationManager::getInstance().registerListener(this);
-        this->registered_ = true;
+        
+        bool listenerRegistered = NotificationManager::getInstance().registerListener(this);
+        if(!listenerRegistered)
+        {
+            this->registered_ = false;
+            NotificationManager::getInstance().unregisterQueue(this);
+            COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl;
+            return;
+        }
 
         COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl;
@@ -77,8 +93,12 @@
     {
         this->targets_.clear();
-        this->clear();
 
         if(this->registered_)
+        {
+            this->clear();
+            
             NotificationManager::getInstance().unregisterListener(this);
+            NotificationManager::getInstance().unregisterQueue(this);
+        }
     }
 
@@ -100,5 +120,5 @@
     void NotificationQueue::create(void)
     {
-        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");
+        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() +  "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");
     }
 
@@ -144,13 +164,15 @@
         }
 
-        if(notifications->empty())
-            return;
-
-        for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) // Add all Notifications.
-            this->push(it->second, it->first);
+        if(!notifications->empty())
+        {
+            for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) // Add all Notifications.
+            {
+                this->push(it->second, it->first);
+            }
+        }
 
         delete notifications;
 
-        COUT(4) << "NotificationQueue '" << this->getName() << "' updated." << std::endl;
+        COUT(3) << "NotificationQueue '" << this->getName() << "' updated." << std::endl; //TODO: Level 4.
     }
 
@@ -167,5 +189,5 @@
         this->push(notification, time);
 
-        COUT(4) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl;
+        COUT(3) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl; //TODO: Level 4.
     }
 
@@ -253,5 +275,4 @@
     bool NotificationQueue::setName(const std::string& name)
     {
-        //TODO: Test uniqueness of name.
         this->name_ = name;
         return true;
@@ -268,4 +289,7 @@
     void NotificationQueue::setMaxSize(unsigned int size)
     {
+        if(this->maxSize_ == size)
+            return;
+        
         this->maxSize_ = size;
         this->sizeChanged();
@@ -292,6 +316,11 @@
     void NotificationQueue::setDisplayTime(unsigned int time)
     {
+        if(this->displayTime_ == time)
+            return;
+
         this->displayTime_ = time;
-        this->update();
+
+        if(this->registered_)
+            this->update();
     }
 
@@ -299,28 +328,21 @@
     @brief
         Produces all targets concatinated as string, with kommas (',') as seperators.
-    @param string
-        Pointer to a string which will be used by the method to fill with the concatination of the targets.
-    @return
-        Returns true if successful.
-    */
-    bool NotificationQueue::getTargets(std::string* string) const
-    {
-        if(string == NULL)
-        {
-            COUT(4) << "Input string must have memory allocated." << std::endl;
-            return false;
-        }
-        string->clear();
+    @return
+        Returns the targets as a string.
+    */
+    const std::string& NotificationQueue::getTargets(void) const
+    {
+        std::stringstream stream;
         bool first = true;
-        for(std::set<std::string>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++) // Iterate through the set of targets.
+        for(std::set<std::string, NotificationListenerStringCompare>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++) // Iterate through the set of targets.
         {
             if(!first)
-                *string += ',';
+                stream << ',';
             else
                 first = false;
-            *string += *it;
-        }
-
-        return true;
+            stream << *it;
+        }
+
+        return *(new std::string(stream.str()));
     }
 
@@ -352,4 +374,10 @@
         }
 
+        if(this->registered_)
+        {
+            NotificationManager::getInstance().unregisterListener(this);
+            NotificationManager::getInstance().registerListener(this);
+        }
+
         return true;
     }
Index: code/branches/notifications/src/modules/notifications/NotificationQueue.h
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationQueue.h	(revision 7362)
+++ code/branches/notifications/src/modules/notifications/NotificationQueue.h	(revision 7395)
@@ -46,6 +46,6 @@
 #include "NotificationManager.h"
 
-namespace orxonox
-{
+namespace orxonox // tolua_export
+{ // tolua_export
 
     //! Container to allow easy handling.
@@ -68,6 +68,7 @@
         Damian 'Mozork' Frick
     */
-    class _NotificationsExport NotificationQueue : public Tickable, public NotificationListener
-    {
+    class _NotificationsExport NotificationQueue // tolua_export
+        : public Tickable, public NotificationListener
+    { // tolua_export
 
         public:
@@ -80,4 +81,5 @@
             void update(Notification* notification, const std::time_t & time); //!< Adds a Notification to the queue.
 
+            // tolua_begin
             /**
             @brief Get the name of the NotificationQueue.
@@ -87,4 +89,5 @@
                 { return this->name_; }
 
+            void setMaxSize(unsigned int size); //!< Sets the maximum number of displayed Notifications.
             /**
             @brief Returns the maximum number of Notifications displayed.
@@ -93,4 +96,14 @@
             inline unsigned int getMaxSize() const
                 { return this->maxSize_; }
+
+            void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed.
+            /**
+            @brief Returns the time interval the Notification is displayed.
+            @return Returns the display time.
+            */
+            inline float getDisplayTime() const
+                { return this->displayTime_; }
+            // tolua_end
+
             /**
             @brief Returns the current number of Notifications displayed.
@@ -99,10 +112,4 @@
             inline unsigned int getSize() const
                 { return this->size_; }
-            /**
-            @brief Returns the time interval the Notification is displayed.
-            @return Returns the display time.
-            */
-            inline float getDisplayTime() const
-                { return this->displayTime_; }
 
             /**
@@ -110,7 +117,11 @@
             @return Retuns a set of string holding the different targets.
             */
-            inline const std::set<std::string> & getTargetsSet()
+            inline const std::set<std::string, NotificationListenerStringCompare> & getTargetsSet()
                 { return this->targets_; }
-            bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets.
+
+            // tolua_begin
+            bool setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue.
+            const std::string& getTargets(void) const; //!< Returns a string consisting of the concatination of the targets.
+            // tolua_end
 
         private:
@@ -124,5 +135,5 @@
             unsigned int displayTime_; //!< The time a Notification is displayed.
 
-            std::set<std::string> targets_; //!< The targets the Queue displays Notifications of.
+            std::set<std::string, NotificationListenerStringCompare> targets_; //!< The targets the Queue displays Notifications of.
 
             std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered. //TODO: Would set work as well?
@@ -139,9 +150,4 @@
             bool setName(const std::string& name); //!< Sets the name of the NotificationQueue.
 
-            void setMaxSize(unsigned int size); //!< Sets the maximum number of displayed Notifications.
-            void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed.
-
-            bool setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue.
-
             void sizeChanged(void); //!< Adjusts the NotificationQueue, when the maximum size has changed.
 
@@ -152,7 +158,7 @@
             void clear(void); //!< Clears the queue by removing all Notifications.
 
-    };
+    }; // tolua_export
 
-}
+} // tolua_export
 
 #endif /* _NotificationOverlay_H__ */
