Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7399


Ignore:
Timestamp:
Sep 10, 2010, 11:17:02 PM (9 years ago)
Author:
dafrick
Message:

Some cleanup and documenting.
After some more extensive testing it seems to work, the code looks ok as well…

Location:
code/branches/notifications
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/notifications/data/gui/scripts/NotificationLayer.lua

    r7398 r7399  
    88P.sampleWindow = nil
    99
     10-- Loads the queues from the NotificationManager and creates the sample window, that is used to measure the width various strings need.
    1011function P.onLoad()
    1112    orxonox.NotificationManager:getInstance():loadQueues()
     
    1314end
    1415
     16-- Creates a queue in the GUI.
    1517function P.createQueue(name, size)
    1618    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
    1719    local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name)
    18     queue:setProperty("BackgroundColor", "00FFFFFF")
     20    queue:setProperty("BackgroundColor", "00FFFFFF") -- Set background to be fully transparent.
    1921    root:addChildWindow(queue)
    2022
     
    3133
    3234    P.queueList[name] = queueTuple -- name access
    33     P.setVisible(queueTuple, false)
    34 end
    35 
    36 function P.removeQueue(name)
    37     local queue = P.queueList[name]
     35    P.setVisible(queueTuple, false) -- Set the queue to invisible as long as there are no notifications in it.
     36end
     37
     38-- Removes a queue from the GUI.
     39function P.removeQueue(queueName)
     40    local queue = P.queueList[queueName]
    3841
    3942    if queue ~= nil then
    4043        winMgr:destroyWindow(queue.window)
    4144    end
    42     P.queueList[name] = nil
    43 end
    44 
     45    P.queueList[queueName] = nil
     46end
     47
     48-- Pushes an input notification to the input queue.
    4549function P.pushNotification(queueName, notification)
    4650    local queue = P.queueList[queueName]
    4751    if queue == nil then
    48         cout(0, "0Queue is nil! " .. queueName)
    4952        return
    5053    end
    5154    item = CEGUI.createListboxTextItem(notification)
    5255    local listbox = CEGUI.toListbox(queue.window)
     56    -- Add the item to the top of the listbox.
    5357    if listbox:getItemCount() == 0 then
    5458        listbox:addItem(item)
     
    5761    end
    5862
     63    -- If the queue has been invisible, set it to visible.
    5964    if queue.visible == false then
    6065        P.setVisible(queue, true)
     
    6267end
    6368
     69-- Pops the least recently added notification from the queue.
    6470function P.popNotification(queueName)
    6571    local queue = P.queueList[queueName]
    6672    if queue == nil then
    67         cout(0, "1Queue is nil! " .. queueName)
    6873        return
    6974    end
    7075    local listbox = CEGUI.toListbox(queue.window)
     76    -- Removes the item from the bottom of the listbox.
    7177    listbox:removeItem(listbox:getListboxItemFromIndex(listbox:getItemCount()-1))
    7278
     79    -- Sets the queue to invisible if there are no more notifications in it.
    7380    if listbox:getItemCount() == 0 then
    7481        P.setVisible(queue, false)
     
    7683end
    7784
     85-- Removes a notification at a given index from the queue.
    7886function P.removeNotification(queueName, index)
    7987    local queue = P.queueList[queueName]
    8088    if queue == nil then
    81         cout(0, "2Queue is nil! " .. queueName)
    8289        return
    8390    end
    8491    local listbox = CEGUI.toListbox(queue.window)
     92    -- Removes the item.
    8593    listbox:removeItem(listbox:getListboxItemFromIndex(tonumber(index)))
    8694
     95    -- Sets the queue to invisible if there are no more notifications in it.
    8796    if listbox:getItemCount() == 0 then
    8897        P.setVisible(queue, false)
     
    9099end
    91100
    92 function P.clearQueue(name)
    93     local queue = P.queueList[name]
    94     if queue == nil then
    95         cout(0, "3Queue is nil! " .. name)
     101-- Clears the queue. Removes all notifications from it.
     102function P.clearQueue(queueName)
     103    local queue = P.queueList[queueName]
     104    if queue == nil then
    96105        return
    97106    end
     
    99108    CEGUI.toListbox(queue.window):resetList()
    100109
     110    -- Sets the queue to invisible.
    101111    P.setVisible(queue, false)
    102112end
    103113
    104 function P.changeSize(name, size)
    105     local queue = P.queueList[name]
    106     if queue == nil then
    107         cout(0, "5Queue is nil! " .. name)
    108         return
    109     end
    110     queue.window:setHeight(CEGUI.UDim(0, P.queueHeightHelper(queue.window, size)))
    111 end
    112 
     114-- Sets the visibility of the queue.
    113115function P.setVisible(queue, visible)
    114116    if queue == nil then
    115         cout(0, "6Queue is nil! " .. queue.name)
    116117        return
    117118    end
     
    120121end
    121122
     123-- Enter the edit mode of the notification layer.
    122124function P.enterEditMode()
    123125    P.editMode = true
     
    139141    vertOffset = 0
    140142    horzOffset = 0
     143    -- Line to be able to create a new queue.
    141144    local newQueueTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueTitle")
    142145    newQueueTitle:setText("Create a new NotificationQueue:")
     
    165168
    166169    horzOffset = 0
     170    -- Button to leave the edit mode.
    167171    local leave = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/ControlWindow/LeaveEditModeButton")
    168172    leave:setText("leave Edit Mode")
     
    180184        if v ~= nil then
    181185            local queue = P.queueList[k]
    182             root:removeChildWindow(queue.window)
    183            
    184             local window = P.createQueueEditFrame(queue.name)
    185             window:setArea(queue.window:getArea())
    186            
    187             queue.edit = window
     186            -- Remove the window that displays the queue from the root window such that it is no longer displayed.
     187            root:removeChildWindow(v.window)
     188
     189            -- Create the frame window, with options to edit the queue, that is displayed instead of the queue.
     190            local window = P.createQueueEditFrame(v.name)
     191            window:setArea(v.window:getArea()) -- Set the frame window size and position to the same as the queue.
     192
     193            v.edit = window
    188194        end
    189195    end
    190196end
    191197
    192 function P.createQueueEditFrame(name)
     198-- Helper function. Creates a frame for the input queue.
     199function P.createQueueEditFrame(queueName)
    193200    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
    194     window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/" .. name)
     201
     202    window = winMgr:createWindow("MenuWidgets/FrameWindow", "orxonox/NotificationLayer/Root/EditMode/" .. queueName)
    195203    local frame = tolua.cast(window, "CEGUI::FrameWindow")
    196204    frame:setCloseButtonEnabled(true)
    197205    orxonox.GUIManager:subscribeEventHelper(frame, "CloseClicked", P.name .. ".closeQueue_clicked")
    198     frame:setText("NotificationQueue \"" .. name .. "\"")
     206    frame:setText("NotificationQueue \"" .. queueName .. "\"")
    199207    root:addChildWindow(window)
    200     local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/ScrollingPane")
     208    local pane = winMgr:createWindow("MenuWidgets/ScrollablePane", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/ScrollingPane")
    201209    pane:setSize(CEGUI.UVector2(CEGUI.UDim(1,-20), CEGUI.UDim(1,-30)))
    202210    pane:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 10), CEGUI.UDim(0, 26)))
     
    206214    local vertOffset = 0
    207215
    208     local targetsTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/TargetsTitle")
     216    -- The line that lets you edit the targets of the queue.
     217    local targetsTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/TargetsTitle")
    209218    targetsTitle:setText("Targets:")
    210219    local size = getMinTextSize(targetsTitle)
     
    214223    pane:addChildWindow(targetsTitle)
    215224    horzOffset = horzOffset + size[2] + 5
    216     local targets = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/Targets")
     225    local targets = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets")
    217226    targets:setProperty("ReadOnly", "set:False")
    218     local targetsText = orxonox.NotificationManager:getInstance():getQueue(name):getTargets()
     227    local targetsText = orxonox.NotificationManager:getInstance():getQueue(queueName):getTargets()
    219228    targets:setText(targetsText)
    220229    P.sampleWindow:setText(targetsText)
     
    224233    horzOffset = horzOffset + size[2]*2+20 + 5
    225234    pane:addChildWindow(targets)
    226     local save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/Targets/Save")
     235    local save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Targets/Save")
    227236    save:setText("save")
    228237    P.sampleWindow:setText("save")
     
    237246
    238247    horzOffset = 0
    239     local sizeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/SizeTitle")
     248    -- The line that lets you edit the size of the queue.
     249    local sizeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/SizeTitle")
    240250    sizeTitle:setText("Size:")
    241251    size = getMinTextSize(sizeTitle)
     
    244254    pane:addChildWindow(sizeTitle)
    245255    horzOffset = horzOffset + size[2] + 5
    246     local queueSize = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/Size")
     256    local queueSize = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size")
    247257    queueSize:setProperty("ReadOnly", "set:False")
    248     local maxSize = orxonox.NotificationManager:getInstance():getQueue(name):getMaxSize()
     258    local maxSize = orxonox.NotificationManager:getInstance():getQueue(queueName):getMaxSize()
    249259    queueSize:setText(maxSize)
    250260    P.sampleWindow:setText(maxSize)
     
    254264    horzOffset = horzOffset + size[2]*2+20 + 5
    255265    pane:addChildWindow(queueSize)
    256     save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/Size/Save")
     266    save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/Size/Save")
    257267    save:setText("save")
    258268    P.sampleWindow:setText("save")
     
    267277
    268278    horzOffset = 0
    269     local displayTimeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/DisplayTimeTitle")
     279    -- The line that lets you edit the display time of the queue.
     280    local displayTimeTitle = winMgr:createWindow("MenuWidgets/StaticText", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTimeTitle")
    270281    displayTimeTitle:setText("Display time:")
    271282    size = getMinTextSize(displayTimeTitle)
     
    274285    pane:addChildWindow(displayTimeTitle)
    275286    horzOffset = horzOffset + size[2] + 5
    276     local displayTime = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/DisplayTime")
     287    local displayTime = winMgr:createWindow("MenuWidgets/Editbox", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime")
    277288    displayTime:setProperty("ReadOnly", "set:False")
    278     local time = orxonox.NotificationManager:getInstance():getQueue(name):getDisplayTime()
     289    local time = orxonox.NotificationManager:getInstance():getQueue(queueName):getDisplayTime()
    279290    displayTime:setText(time)
    280291    P.sampleWindow:setText(time)
     
    284295    horzOffset = horzOffset + size[2]*2+20 + 5
    285296    pane:addChildWindow(displayTime)
    286     save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. name .. "/DisplayTime/Save")
     297    save = winMgr:createWindow("MenuWidgets/Button", "orxonox/NotificationLayer/Root/EditMode/" .. queueName .. "/DisplayTime/Save")
    287298    save:setText("save")
    288299    P.sampleWindow:setText("save")
     
    299310end
    300311
     312-- Leave the edit mode.
    301313function P.leaveEditMode()
    302314    P.editMode = false
     
    306318    for k,v in pairs(P.queueList) do
    307319        if v ~= nil then
     320            -- Add the queue window to the root window to have it displayed again.
    308321            root:addChildWindow(v.window)
     322            -- Set the size and position of the queue window to the size and position of the queue edit frame.
    309323            v.window:setArea(v.edit:getArea())
     324            -- Destroy the edit frame.
    310325            winMgr:destroyWindow(v.edit)
    311326            v.edit = nil
     
    317332end
    318333
     334-- Is called after the sheet has been hidden.
    319335function P.afterHide()
     336    -- If we leave the edit mode we show the sheet again.
    320337    if P.editMode then
    321338        P.leaveEditMode()
     
    324341end
    325342
     343-- If the button to save the targets of a queue has been clicked.
    326344function P. saveTargets_clicked(e)
    327345    local we = CEGUI.toWindowEventArgs(e)
     
    337355
    338356    local queue = orxonox.NotificationManager:getInstance():getQueue(queueName)
     357    -- Set the new targets.
    339358    queue:setTargets(window:getText())
    340359    local targets = queue:getTargets()
     
    343362    P.sampleWindow:setText(targets)
    344363    local size = getMinTextSize(P.sampleWindow)
     364    -- Adjust the width of the targets field.
    345365    window:setWidth(CEGUI.UDim(0, size[2]*2+20))
     366    -- Adjust the position of the save button after the targets field.
    346367    save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1)))
    347368end
    348369
     370-- If the button to save the size if a queue has been clicked.
    349371function P. saveSize_clicked(e)
    350372    local we = CEGUI.toWindowEventArgs(e)
     
    360382
    361383    local queue = orxonox.NotificationManager:getInstance():getQueue(queueName)
     384    -- Set the new size.
    362385    queue:setMaxSize(tonumber(window:getText()))
    363386    local maxSize = queue:getMaxSize()
     
    366389    P.sampleWindow:setText(maxSize)
    367390    local size = getMinTextSize(P.sampleWindow)
     391    -- Adjust the width of the size field.
    368392    window:setWidth(CEGUI.UDim(0, size[2]*2+20))
     393    -- Adjust the position of the save button after the size field.
    369394    save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1)))
    370395end
    371396
     397-- If the button to save the display time if a queue has been clicked.
    372398function P. saveDisplayTime_clicked(e)
    373399    local we = CEGUI.toWindowEventArgs(e)
     
    383409
    384410    local queue = orxonox.NotificationManager:getInstance():getQueue(queueName)
     411    -- Set the new display time.
    385412    queue:setDisplayTime(tonumber(window:getText()))
    386413    local time = queue:getDisplayTime()
     
    389416    P.sampleWindow:setText(time)
    390417    local size = getMinTextSize(P.sampleWindow)
     418    -- Adjust the width of the display time field.
    391419    window:setWidth(CEGUI.UDim(0, size[2]*2+20))
     420    -- Adjust the position of the save button after the display time field.
    392421    save:setXPosition(CEGUI.UDim(0, save:getXPosition():asAbsolute(1)-width+window:getWidth():asAbsolute(1)))
    393422end
    394423
     424-- if the button to create a new queue has been clicked.
    395425function P.createNewQueue_clicked(e)
    396426    local window = winMgr:getWindow("orxonox/NotificationLayer/Root/EditMode/ControlWindow/NewQueueName")
    397427    local name = window:getText()
     428    -- Creates the new queue.
    398429    orxonox.NotificationManager:getInstance():createQueue(name)
    399430
    400431    local queue = P.queueList[name]
    401432    if queue == nil then
    402         cout(0, "7Queue is nil! " .. name)
    403         return
    404     end
    405    
     433        return
     434    end
     435
     436    -- Create the frame that represents the queue in edit mode, since that's what we're in.
    406437    local frame = P.createQueueEditFrame(name)
    407438    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
     439    -- Remove the queue window from the root window, since we're in edit mode.
    408440    root:removeChildWindow(queue.window)
     441    -- Set the frame window size and position to that of the queue window.
    409442    frame:setArea(queue.window:getArea())
    410443    queue.edit = frame
    411    
     444
     445    -- Reset the text to create a new queue.
    412446    window:setText("")
    413447end
    414448
     449-- If the button to leave the edit mode has been clicked.
    415450function P.leaveEditMode_clicked(e)
    416451    hideMenuSheet(P.name)
    417452end
    418453
     454-- If the button to close the queue has been clicked.
    419455function P.closeQueue_clicked(e)
    420456    local we = CEGUI.toWindowEventArgs(e)
     
    425461    local queueName = string.sub(nameStr, 10, string.len(nameStr))
    426462
     463    -- Destroy the frame window,
    427464    winMgr:destroyWindow(P.queueList[queueName].edit)
    428465    P.queueList[queueName].edit = nil
     466    -- Destroy the queue.
    429467    orxonox.NotificationManager:getInstance():getQueue(queueName):destroy()
    430468end
    431469
     470-- Helper function. Returns height a queue needs to have to display 'size' items.
    432471function P.queueHeightHelper(queue, size)
    433472    local listbox = CEGUI.toListbox(queue)
  • code/branches/notifications/src/modules/notifications/NotificationManager.cc

    r7398 r7399  
    3939#include "core/LuaState.h"
    4040#include "util/ScopedSingletonManager.h"
     41
    4142#include "interfaces/NotificationListener.h"
     43
    4244#include "Notification.h"
    4345#include "NotificationQueue.h"
     
    5658    ManageScopedSingleton(NotificationManager, ScopeID::Graphics, false);
    5759
    58     //TODO: Make work.
    5960    SetConsoleCommand("enterEditMode", &NotificationManager::enterEditMode);
    6061
     
    7071
    7172        ModifyConsoleCommand("enterEditMode").setObject(this);
    72        
     73
    7374        COUT(3) << "NotificatioManager created." << std::endl;
    7475    }
     
    8283        ModifyConsoleCommand("enterEditMode").setObject(NULL);
    8384
     85        //  Destroys all Notifications that have been registered with the NotificationManager.
    8486        for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
    8587            it->second->destroy();
    86        
     88
    8789        COUT(3) << "NotificationManager destroyed." << std::endl;
    8890    }
    8991
     92    /**
     93    @brief
     94        Is called before the object is destroyed.
     95    */
    9096    void NotificationManager::preDestroy(void)
    9197    {
     98        // Destroys all NotificationQueues that have been registered with the NotificationManager.
    9299        for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); )
    93100        {
     
    109116    bool NotificationManager::registerNotification(Notification* notification)
    110117    {
    111         if(notification == NULL) // A NULL-Notification cannot be registered.
    112             return false;
     118        assert(notification);
    113119
    114120        std::time_t time = std::time(0); //TODO: Doesn't this expire? //!< Get current time.
    115121
     122        // Add the Notification to the list that holds all Notifications.
    116123        this->allNotificationsList_.insert(std::pair<std::time_t, Notification*>(time, notification));
    117124
     
    123130            all = true;
    124131
    125         // Insert the notification in all listeners that have its sender as target.
    126         for(std::map<NotificationListener*,int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) // Iterate through all listeners.
     132        // Insert the Notification in all NotificationListeners that have its sender as target.
     133        for(std::map<NotificationListener*, unsigned int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) // Iterate through all NotificationListeners.
    127134        {
    128135            std::set<std::string, NotificationListenerStringCompare> set = it->first->getTargetsSet();
    129136            bool bAll = set.find(NotificationManager::ALL) != set.end();
    130             if(all || bAll || set.find(notification->getSender()) != set.end()) //TODO: Make sure this works.
     137            // If either the Notification has as sender 'all', the NotificationListener displays all Notifications or the NotificationListener has the sender of the Notification as target.
     138            if(all || bAll || set.find(notification->getSender()) != set.end())
    131139            {
    132140                if(!bAll)
    133                 {
    134                     this->notificationLists_[it->second]->insert(std::pair<std::time_t, Notification*>(time, notification)); // Insert the Notification in the Notifications list of the current NotificationListener.
    135                 }
    136                 it->first->update(notification, time); // Update the listener.
    137                 std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(notification);
    138                 if(counterIt == this->listenerCounter_.end())
    139                     this->listenerCounter_[notification] = 1;
    140                 else
    141                     this->listenerCounter_[notification] = counterIt->second + 1;
     141                    this->notificationLists_[it->second]->insert(std::pair<std::time_t, Notification*>(time, notification)); // Insert the Notification in the notifications list of the current NotificationListener.
     142                it->first->update(notification, time); // Update the NotificationListener.
    142143            }
    143144        }
     
    150151    /**
    151152    @brief
    152         Unregisters a Notification within the NotificationManager.
     153        Unregisters a Notification within the NotificationManager for a given NotificationListener.
    153154    @param notification
    154155        A pointer to the Notification to be unregistered.
     
    161162        assert(listener);
    162163
    163         // If the Notification was removed from the list of Notifications of the input NotificationListener, the counter for the Notification of the number of NotificationListeners it is present in is decremented.
    164         if(this->removeNotification(notification, *(this->notificationLists_.find(this->listenerList_.find(listener)->second)->second)))
    165             this->listenerCounter_[notification] = this->listenerCounter_[notification] - 1;
     164        // Remove the Notification from the list of Notifications of the input NotificationListener.
     165        this->removeNotification(notification, *(this->notificationLists_.find(this->listenerList_.find(listener)->second)->second));
    166166
    167167        COUT(4) << "Notification (&" << notification << ") unregistered with the NotificationManager from listener (&" << listener << ")" << std::endl;
     
    170170    /**
    171171    @brief
    172         Helper method that removes an input notification form an input map.
     172        Helper method that removes an input Notification form an input map.
    173173    @param notification
    174         A pointer to the notification to be removed.
     174        A pointer to the Notification to be removed.
    175175    @param map
    176         The map the notification should be removed from.
     176        The map the Notification should be removed from.
    177177    @return
    178178        Returns true if successful.
     
    199199        The NotificationListener to be registered.
    200200    @return
    201         Returns true if successful.
     201        Returns true if successful.  Fales if the NotificationListener is already registered.
    202202    */
    203203    bool NotificationManager::registerListener(NotificationListener* listener)
    204204    {
     205        assert(listener);
     206
     207        // If the NotificationListener is already registered.
     208        if(this->listenerList_.find(listener) != this->listenerList_.end())
     209            return false;
     210
    205211        this->highestIndex_ += 1;
    206         int index = this->highestIndex_;
    207 
    208         this->listenerList_[listener] = index; // Add the NotificationListener to the list of listeners.
     212        unsigned int index = this->highestIndex_; // An identifier that identifies each registered NotificationListener uniquely.
     213
     214        this->listenerList_[listener] = index; // Add the NotificationListener to the list of NotificationListeners.
    209215
    210216        std::set<std::string, NotificationListenerStringCompare> set = listener->getTargetsSet();
    211217
    212         // 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.
     218        // If all senders are the target of the NotificationListener, then the list of Notifications for that specific NotificationListener is the same as the list of all Notifications.
    213219        bool bAll = set.find(NotificationManager::ALL) != set.end();
    214220        std::multimap<std::time_t, Notification*>* map;
    215221        if(bAll)
    216222            this->notificationLists_[index] = &this->allNotificationsList_;
     223        // Else a new list (resp. multimap) is created and added to the list of Notification lists for NotificationListeners.
    217224        else
    218225        {
     
    224231        for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
    225232        {
    226             if(bAll || set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current notification as target.
    227             {
    228                 if(!bAll)
    229                     map->insert(std::pair<std::time_t, Notification*>(it->first, it->second));
    230                 std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(it->second);
    231                 if(counterIt == this->listenerCounter_.end())
    232                     this->listenerCounter_[it->second] = 1;
    233                 else
    234                     this->listenerCounter_[it->second] = counterIt->second + 1;
    235             }
     233            if(!bAll && set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current Notification as target.
     234                map->insert(std::pair<std::time_t, Notification*>(it->first, it->second));
    236235        }
    237236
     
    245244    /**
    246245    @brief
    247         Unregisters a NotificationListener withing the NotificationManager.
     246        Unregisters a NotificationListener within the NotificationManager.
     247    @param listener
     248        The NotificationListener to be unregistered.
    248249    */
    249250    void NotificationManager::unregisterListener(NotificationListener* listener)
     
    251252        assert(listener);
    252253
    253         int identifier = this->listenerList_.find(listener)->second;
     254        //TODO: Make unsigned int.
     255        unsigned int identifier = this->listenerList_.find(listener)->second;
    254256        std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(identifier)->second;
    255257
    256         // If the map is not the map of all notifications, make sure all Notifications are removed and delete it.
     258        // If the map is not the map of all Notifications, make sure all Notifications are unregistered.
    257259        std::multimap<std::time_t, Notification*>::iterator it = map->begin();
    258260        if(map != &this->allNotificationsList_)
     
    266268        }
    267269
     270        // Remove the NotificationListener from the list of NotificationListeners.
    268271        this->listenerList_.erase(listener);
     272        // Remove the Notifications list that was associated with the input NotificationListener.
    269273        this->notificationLists_.erase(identifier);
    270274
     
    274278    /**
    275279    @brief
    276         Fetches the Notifications for a specific NotificationListener in a specified timeframe.
     280        Fetches the Notifications for a specific NotificationListener in a specified timeframe and stores them in the input map.
    277281    @param listener
    278282        The NotificationListener the Notifications are fetched for.
    279283    @param map
    280         A multimap, in which the notifications are stored.
     284        A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
    281285    @param timeFrameStart
    282286        The start time of the timeframe.
     
    286290        Returns true if successful.
    287291    */
    288     bool NotificationManager::getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
    289     {
    290         if(listener == NULL || map == NULL)
    291             return false;
    292 
    293         std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // The Notifications for the input NotificationListener.
    294 
    295         if(notifications == NULL) // Returns false, if there are no Notifications.
    296             return false;
     292    void NotificationManager::getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
     293    {
     294        assert(listener);
     295        assert(map);
     296
     297        std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // All the Notifications for the input NotificationListener.
    297298
    298299        std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest;
     300        // Iterators pointing to the bounds specified by the specified start and end times of the time frame.
    299301        itLowest = notifications->lower_bound(timeFrameStart);
    300302        itHighest = notifications->upper_bound(timeFrameEnd);
    301303
    302         for(it = itLowest; it != itHighest; it++) // Iterate through the Notifications from the start of the time Frame to the end of it.
    303             map->insert(std::pair<std::time_t, Notification*>(it->first,it->second)); // Add the found Notifications to the map.
    304 
    305         return true;
    306     }
    307 
    308     void NotificationManager::loadQueues(void)
    309     {
    310         new NotificationQueue("all");
    311     }
    312 
    313     void NotificationManager::createQueue(const std::string& name)
    314     {
    315         new NotificationQueue(name);
    316     }
    317 
    318     NotificationQueue* NotificationManager::getQueue(const std::string & name)
    319     {
    320         std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.find(name);
    321         if(it == this->queues_.end())
    322             return NULL;
    323 
    324         return (*it).second;
    325     }
    326 
    327     bool NotificationManager::registerQueue(NotificationQueue* queue)
    328     {
    329         return this->queues_.insert(std::pair<const std::string, NotificationQueue*>(queue->getName(), queue)).second;
    330     }
    331    
    332     void NotificationManager::unregisterQueue(NotificationQueue* queue)
    333     {
    334         this->queues_.erase(queue->getName());
    335     }
    336 
     304        for(it = itLowest; it != itHighest; it++) // Iterate through the Notifications from the start of the time frame to the end of it.
     305            map->insert(std::pair<std::time_t, Notification*>(it->first, it->second)); // Add the found Notifications to the map.
     306    }
     307
     308    /**
     309    @brief
     310        Enters the edit mode of the NotificationLayer.
     311    */
    337312    void NotificationManager::enterEditMode(void)
    338313    {
     
    342317    }
    343318
     319    /**
     320    @brief
     321        Registers a NotificationQueue.
     322        This makes sure that the NotificationQueue can be attained through lua by name. It also makes sure that the NotificationQueue is destroyed upon destruction of the NotificationManager.
     323    @param queue
     324        A pointer to the NotificationQueue to be registered.
     325    @return
     326        Returns true if successful. If e.g. the a NotificationQueue with that name already exists this returns false.
     327    */
     328    bool NotificationManager::registerQueue(NotificationQueue* queue)
     329    {
     330        return this->queues_.insert(std::pair<const std::string, NotificationQueue*>(queue->getName(), queue)).second;
     331    }
     332
     333    /**
     334    @brief
     335        Unregisters a NotificationQueue.
     336    @param queue
     337        A pointer to the NotificationQueue to be unregistered.
     338    */
     339    void NotificationManager::unregisterQueue(NotificationQueue* queue)
     340    {
     341        this->queues_.erase(queue->getName());
     342    }
     343
     344    /**
     345    @brief
     346        Loads all the NotificationQueues that should exist.
     347    */
     348    void NotificationManager::loadQueues(void)
     349    {
     350        new NotificationQueue("all");
     351    }
     352
     353    /**
     354    @brief
     355        Creates a new NotificationQueue.
     356        This is used in lua.
     357    @param name
     358        The name of the new NotificationQueue.
     359    */
     360    void NotificationManager::createQueue(const std::string& name)
     361    {
     362        new NotificationQueue(name);
     363    }
     364
     365    /**
     366    @brief
     367        Get the NotificationQueue with the input name.
     368    @param name
     369        The name of the NotificationQueue.
     370    @return
     371        Returns a pointer to the NotificationQueue with the input name. Returns NULL if no NotificationQueue with such a name exists.
     372    */
     373    NotificationQueue* NotificationManager::getQueue(const std::string & name)
     374    {
     375        std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.find(name);
     376        // Returns NULL if no such NotificationQueue exists.
     377        if(it == this->queues_.end())
     378            return NULL;
     379
     380        return (*it).second;
     381    }
     382
    344383}
  • code/branches/notifications/src/modules/notifications/NotificationManager.h

    r7395 r7399  
    6262            virtual ~NotificationManager();
    6363
    64             virtual void preDestroy(void);
     64            virtual void preDestroy(void); //!< Is called before the object is destroyed.
    6565
    6666            static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export
     
    7070
    7171            bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
    72             void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager.
     72            void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager for a given NotificationListener.
    7373            bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager.
    7474            void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager.
    7575
    76             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.
     76            void getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Fetches the Notifications for a specific NotificationListener in a specified timeframe and stores them in the input map.
    7777
    7878            /**
    79             @brief Fetches the Notifications for a specific NotificationListener starting at a specified timespan before now.
     79            @brief Fetches the Notifications for a specific NotificationListener in a timeframe from now-timeDelay to now and stores them in the input map.
    8080            @param listener The NotificationListener the Notifications are fetched for.
    81             @param map A multimap, in which the notifications are stored.
     81            @param map A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
    8282            @param timeDelay The timespan.
    8383            @return Returns true if successful.
    8484            */
    85             bool getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay)
    86                 { return this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); }
     85            void getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay)
     86                { this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); }
    8787
    88             void enterEditMode(void);
     88            void enterEditMode(void); //!< Enters the edit mode of the NotificationLayer.
     89
     90            bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue.
     91            void unregisterQueue(NotificationQueue* queue); //!< Unregisters a NotificationQueue.
    8992
    9093            // tolua_begin
    91             void loadQueues(void);
    92            
    93             void createQueue(const std::string& name);
    94             orxonox::NotificationQueue* getQueue(const std::string & name);
     94            void loadQueues(void); //!< Loads all the NotificationQueues that should exist.
     95            void createQueue(const std::string& name); //!< Creates a new NotificationQueue.
     96            orxonox::NotificationQueue* getQueue(const std::string & name); //!< Get the NotificationQueue with the input name.
    9597            // tolua_end
    96 
    97             bool registerQueue(NotificationQueue* queue);
    98             void unregisterQueue(NotificationQueue* queue);
    9998
    10099        private:
    101100            static NotificationManager* singletonPtr_s;
    102101
     102            unsigned int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.
     103
     104            std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all Notifications are stored.
     105            std::map<NotificationListener*, unsigned int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier.
     106            std::map<int,std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored.
     107
    103108            std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager.
    104109
    105             int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.
    106 
    107             std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all notifications are stored.
    108             std::map<NotificationListener*, int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier.
    109             std::map<int,std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored.
    110             std::map<Notification*, unsigned int> listenerCounter_; //!< A container to store the number of NotificationListeners a Notification is registered with.
    111 
    112             bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input notification form an input map.
     110            bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input Notification form an input map.
    113111
    114112    }; // tolua_export
  • code/branches/notifications/src/modules/notifications/NotificationQueue.cc

    r7398 r7399  
    4141#include "core/LuaState.h"
    4242#include "util/Convert.h"
     43#include "util/SubString.h"
     44
    4345#include "Notification.h"
    4446
     
    4951    @brief
    5052        Constructor. Creates and initializes the object.
     53    @param name
     54        The name of the new NotificationQueue.
     55    @param senders
     56        The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays.
     57        The senders need to be seperated by commas.
     58    @param size
     59        The size (the maximum number of displayed Notifications) of this NotificationQueue.
     60    @param displayTime
     61        The time during which a Notification is (at most) displayed.
    5162    */
    5263    NotificationQueue::NotificationQueue(const std::string& name, const std::string& senders, unsigned int size, unsigned int displayTime)
     
    5667        RegisterRootObject(NotificationQueue);
    5768
    58         this->initialize();
    59 
     69        // Initialize.
     70        this->size_ = 0;
     71        this->tickTime_ = 0.0;
     72
     73        // Sets the input values.
    6074        this->setTargets(senders);
    6175        this->name_ = name;
     
    6377        this->setDisplayTime(displayTime);
    6478
     79        //TODO: Destroy if registration fails?
     80
     81        // Register the NotificationQueue with the NotificationManager.
    6582        bool queueRegistered = NotificationManager::getInstance().registerQueue(this);
    6683        this->registered_ = true;
    67         if(!queueRegistered)
     84        if(!queueRegistered) // If the registration has failed.
    6885        {
    6986            this->registered_ = false;
     
    7289        }
    7390
    74         this->create();
    75        
     91        this->create(); // Creates the NotificationQueue in lua.
     92
     93        // register the NotificationQueue as NotificationListener with the NotificationManager.
    7694        bool listenerRegistered = NotificationManager::getInstance().registerListener(this);
    77         if(!listenerRegistered)
     95        if(!listenerRegistered) // If the registration has failed.
    7896        {
    7997            this->registered_ = false;
     98            // Remove the NotificationQueue in lua.
     99            GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() +  "\")");
    80100            NotificationManager::getInstance().unregisterQueue(this);
    81101            COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl;
     
    94114        this->targets_.clear();
    95115
    96         if(this->registered_)
     116        if(this->registered_) // If the
    97117        {
    98118            this->clear();
    99            
     119
     120            // Unregister with the NotificationManager.
    100121            NotificationManager::getInstance().unregisterListener(this);
    101122            NotificationManager::getInstance().unregisterQueue(this);
    102123
     124            // Remove the NotificationQueue in lua.
    103125            GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() +  "\")");
    104126        }
    105     }
    106 
    107     /**
    108     @brief
    109         Initializes the object.
    110         Registers the object, initializes variables, sets default values and registers the queue with the NotificationManager.
    111     */
    112     void NotificationQueue::initialize(void)
    113     {
    114         this->size_ = 0;
    115         this->tickTime_ = 0.0;
    116127    }
    117128
     
    139150
    140151            std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator it = this->ordering_.begin();
    141             while(it != this->ordering_.upper_bound(&this->timeLimit_)) // Iterate through all elements whose creation time is smaller than the current time minus the display time.
     152            // Iterate through all elements whose creation time is smaller than the current time minus the display time.
     153            while(it != this->ordering_.upper_bound(&this->timeLimit_))
    142154            {
    143155                NotificationContainer* temp = *it;
    144156                it++;
    145                 this->remove(temp);
     157                this->remove(temp); // Remove the Notifications that have expired.
    146158            }
    147159
     
    160172
    161173        std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t, Notification*>;
    162         if(!NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_)) // Get the Notifications sent in the interval form now to minus the display time.
    163         {
    164             COUT(1) << "NotificationQueue update failed due to undetermined cause." << std::endl;
    165             return;
    166         }
     174        // Get the Notifications sent in the interval from now to now minus the display time.
     175        NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_);
    167176
    168177        if(!notifications->empty())
    169178        {
    170             for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) // Add all Notifications.
    171             {
     179            // Add all Notifications.
     180            for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++)
    172181                this->push(it->second, it->first);
    173             }
    174182        }
    175183
    176184        delete notifications;
    177185
    178         COUT(3) << "NotificationQueue '" << this->getName() << "' updated." << std::endl; //TODO: Level 4.
     186        COUT(4) << "NotificationQueue '" << this->getName() << "' updated." << std::endl;
    179187    }
    180188
     
    191199        this->push(notification, time);
    192200
    193         COUT(3) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl; //TODO: Level 4.
    194     }
    195 
    196     /**
    197     @brief
    198         Adds a Notification to the NotificationQueue.
     201        COUT(4) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl;
     202    }
     203
     204    /**
     205    @brief
     206        Adds (pushes) a Notification to the NotificationQueue.
    199207        It inserts it into the storage containers, creates a corresponding container and pushes the Notification message to the GUI.
    200208    @param notification
    201         The Notification.
     209        The Notification to be pushed.
    202210    @param time
    203         The time.
     211        The time when the Notification has been sent.
    204212    */
    205213    void NotificationQueue::push(Notification* notification, const std::time_t & time)
     
    216224
    217225        this->ordering_.insert(container);
     226        // Insert the Notification at the begin of the list (vector, actually).
    218227        this->notifications_.insert(this->notifications_.begin(), container);
    219228
     229        // Push the Notification to the GUI.
    220230        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
    221231    }
     
    223233    /**
    224234    @brief
    225         Removes the least recently added Notification form the NotificationQueue.
     235        Removes (pops) the least recently added Notification form the NotificationQueue.
    226236    */
    227237    void NotificationQueue::pop(void)
     
    230240        this->ordering_.erase(container);
    231241        this->notifications_.pop_back();
     242
    232243        this->size_--;
     244
    233245        delete container;
     246
     247        // Pops the Notification from the GUI.
    234248        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")");
    235249    }
     
    237251    /**
    238252    @brief
    239         Removes the Notification that is stored in the input container.
     253        Removes the Notification that is stored in the input NotificationContainer.
    240254    @param container
    241255        The NotificationContainer with the Notification to be removed.
     
    244258    {
    245259        std::vector<NotificationContainer*>::iterator it = std::find(this->notifications_.begin(), this->notifications_.end(), container);
     260        // Get the index at which the Notification is.
    246261        std::vector<NotificationContainer*>::difference_type index = it - this->notifications_.begin ();
    247262        this->ordering_.erase(container);
    248263        this->notifications_.erase(it);
     264
    249265        this->size_--;
     266
    250267        delete container;
     268
     269        // Removes the Notification from the GUI.
    251270        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
    252271    }
     
    254273    /**
    255274    @brief
    256         Clears the queue by removing all Notifications.
     275        Clears the NotificationQueue by removing all NotificationContainers.
    257276    */
    258277    void NotificationQueue::clear(void)
    259278    {
    260279        this->ordering_.clear();
     280        // Delete all NotificationContainers in the list.
    261281        for(std::vector<NotificationContainer*>::iterator it = this->notifications_.begin(); it != this->notifications_.end(); it++)
    262282            delete *it;
    263283
    264284        this->notifications_.clear();
     285
    265286        this->size_ = 0;
     287
     288        // Clear the NotificationQueue in the GUI.
    266289        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");
    267290    }
     
    272295    @param name
    273296        The name to be set.
    274     @return
    275         returns true if successful.
    276     */
    277     bool NotificationQueue::setName(const std::string& name)
     297    */
     298    void NotificationQueue::setName(const std::string& name)
    278299    {
    279300        this->name_ = name;
    280         return true;
    281301    }
    282302
     
    286306    @param size
    287307        The size to be set.
    288     @return
    289         Returns true if successful.
    290308    */
    291309    void NotificationQueue::setMaxSize(unsigned int size)
     
    293311        if(this->maxSize_ == size)
    294312            return;
    295        
     313
    296314        this->maxSize_ = size;
    297         this->sizeChanged();
    298     }
    299 
    300     /**
    301     @brief
    302         Adjusts the NotificationQueue, when the maximum size has changed.
    303     */
    304     void NotificationQueue::sizeChanged(void)
    305     {
    306         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeSize(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getSize()) + ")");
    307         this->update();
     315
     316        if(this->registered_)
     317            this->update();
    308318    }
    309319
     
    329339    /**
    330340    @brief
    331         Produces all targets concatinated as string, with kommas (',') as seperators.
     341        Produces all targets of the NotificationQueue concatinated as string, with kommas (',') as seperators.
    332342    @return
    333343        Returns the targets as a string.
     
    337347        std::stringstream stream;
    338348        bool first = true;
    339         for(std::set<std::string, NotificationListenerStringCompare>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++) // Iterate through the set of targets.
     349        // Iterate through the set of targets.
     350        for(std::set<std::string, NotificationListenerStringCompare>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++)
    340351        {
    341352            if(!first)
    342                 stream << ',';
     353                stream << ", ";
    343354            else
    344355                first = false;
     
    351362    /**
    352363    @brief
    353         Sets the targets of the queue.
     364        Sets the targets of the NotificationQueue.
    354365        The targets are the senders whose Notifications are displayed in this queue.
    355366    @param targets
    356367        Accepts a string of targets, each seperated by commas (','), spaces are ignored.
    357     @return
    358         Returns true if successful.
    359     */
    360     bool NotificationQueue::setTargets(const std::string & targets)
     368    */
     369    void NotificationQueue::setTargets(const std::string & targets)
    361370    {
    362371        this->targets_.clear();
    363372
    364         //TODO: Do with SubString.
    365         std::string* pTemp;
    366         unsigned int index = 0;
    367         while(index < targets.size()) // Go through the string, character by character until the end is reached.
    368         {
    369             pTemp = new std::string();
    370             while(index < targets.size() && targets[index] != ',' && targets[index] != ' ')
    371             {
    372                 *pTemp += targets[index];
    373                 index++;
    374             }
    375             index++;
    376             this->targets_.insert(*pTemp);
    377         }
     373        SubString string = SubString(targets, ",", " ", false);
     374        for(unsigned int i = 0; i < string.size(); i++)
     375            this->targets_.insert(string[i]);
    378376
    379377        if(this->registered_)
     
    382380            NotificationManager::getInstance().registerListener(this);
    383381        }
    384 
    385         return true;
    386382    }
    387383
  • code/branches/notifications/src/modules/notifications/NotificationQueue.h

    r7398 r7399  
    4343
    4444#include "tools/interfaces/Tickable.h"
     45
    4546#include "interfaces/NotificationListener.h"
    4647#include "NotificationManager.h"
     
    7677            virtual ~NotificationQueue();
    7778
     79            /**
     80            @brief Destroys the NotificationQueue.
     81                   Used in lua.
     82            */
    7883            void destroy(void) { this->OrxonoxClass::destroy(); } // tolua_export
    7984
    8085            virtual void tick(float dt); //!< To update from time to time.
    8186
    82             void update(void); //!< Updates the queue.
    83             void update(Notification* notification, const std::time_t & time); //!< Adds a Notification to the queue.
     87            void update(void); //!< Updates the NotificationQueue.
     88            void update(Notification* notification, const std::time_t & time); //!< Updates the NotificationQueue by adding an new Notification.
    8489
    8590            // tolua_begin
     
    110115            /**
    111116            @brief Returns the current number of Notifications displayed.
    112             @return Returns the size of the queue.
     117            @return Returns the size of the NotificationQueue.
    113118            */
    114119            inline unsigned int getSize() const
     
    116121
    117122            /**
    118             @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue.
    119             @return Retuns a set of string holding the different targets.
     123            @brief Returns the targets of this NotificationQueue, reps. the senders which Notifications are displayed in this NotificationQueue.
     124            @return Returns a set of strings holding the different targets.
    120125            */
    121126            inline const std::set<std::string, NotificationListenerStringCompare> & getTargetsSet()
     
    123128
    124129            // tolua_begin
    125             bool setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue.
     130            void setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue.
    126131            const std::string& getTargets(void) const; //!< Returns a string consisting of the concatination of the targets.
    127132            // tolua_end
     
    137142            unsigned int displayTime_; //!< The time a Notification is displayed.
    138143
    139             std::set<std::string, NotificationListenerStringCompare> targets_; //!< The targets the Queue displays Notifications of.
     144            bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
    140145
    141             std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered. //TODO: Would set work as well?
     146            std::set<std::string, NotificationListenerStringCompare> targets_; //!< The targets the NotificationQueue displays Notifications of.
     147
     148            std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered.
    142149            std::vector<NotificationContainer*> notifications_; //!< The NotificationContainers in the order they were added to the NotificationQueue.
    143150
     
    145152            NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
    146153
    147             bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
    148 
    149             void initialize(void); //!< Initializes the object.
    150154            void create(void); //!< Creates the NotificationQueue in lua.
    151155
    152             bool setName(const std::string& name); //!< Sets the name of the NotificationQueue.
     156            void setName(const std::string& name); //!< Sets the name of the NotificationQueue.
    153157
    154             void sizeChanged(void); //!< Adjusts the NotificationQueue, when the maximum size has changed.
     158            void push(Notification* notification, const std::time_t & time); //!< Adds (pushes) a Notification to the NotificationQueue.
     159            void pop(void); //!< Removes (pops) the least recently added Notification form the NotificationQueue.
     160            void remove(NotificationContainer* container); //!< Removes the Notification that is stored in the input NotificationContainer.
    155161
    156             void push(Notification* notification, const std::time_t & time); //!< Add a Notification to the NotificationQueue.
    157             void pop(void); //!< Removes the least recently added Notification form the NotificationQueue.
    158             void remove(NotificationContainer* container); //!< Removes the Notification that is stored in the input container.
    159 
    160             void clear(void); //!< Clears the queue by removing all Notifications.
     162            void clear(void); //!< Clears the NotificationQueue by removing all NotificationContainers.
    161163
    162164    }; // tolua_export
Note: See TracChangeset for help on using the changeset viewer.