PageRenderTime 52ms CodeModel.GetById 14ms app.highlight 31ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llui/llfloaterreglistener.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 156 lines | 100 code | 10 blank | 46 comment | 5 complexity | a2f429cc9763073181dc4f23acc0d90e MD5 | raw file
  1/**
  2 * @file   llfloaterreglistener.cpp
  3 * @author Nat Goodspeed
  4 * @date   2009-08-12
  5 * @brief  Implementation for llfloaterreglistener.
  6 * 
  7 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28
 29// Precompiled header
 30#include "linden_common.h"
 31// associated header
 32#include "llfloaterreglistener.h"
 33// STL headers
 34// std headers
 35// external library headers
 36// other Linden headers
 37#include "llfloaterreg.h"
 38#include "llfloater.h"
 39#include "llbutton.h"
 40
 41LLFloaterRegListener::LLFloaterRegListener():
 42    LLEventAPI("LLFloaterReg",
 43               "LLFloaterReg listener to (e.g.) show/hide LLFloater instances")
 44{
 45    add("getBuildMap",
 46        "Return on [\"reply\"] data about all registered LLFloaterReg floater names",
 47        &LLFloaterRegListener::getBuildMap,
 48        LLSD().with("reply", LLSD()));
 49    LLSD requiredName;
 50    requiredName["name"] = LLSD();
 51    add("showInstance",
 52        "Ask to display the floater specified in [\"name\"]",
 53        &LLFloaterRegListener::showInstance,
 54        requiredName);
 55    add("hideInstance",
 56        "Ask to hide the floater specified in [\"name\"]",
 57        &LLFloaterRegListener::hideInstance,
 58        requiredName);
 59    add("toggleInstance",
 60        "Ask to toggle the state of the floater specified in [\"name\"]",
 61        &LLFloaterRegListener::toggleInstance,
 62        requiredName);
 63    add("instanceVisible",
 64        "Return on [\"reply\"] an event whose [\"visible\"] indicates the visibility "
 65        "of the floater specified in [\"name\"]",
 66        &LLFloaterRegListener::instanceVisible,
 67        requiredName);
 68    LLSD requiredNameButton;
 69    requiredNameButton["name"] = LLSD();
 70    requiredNameButton["button"] = LLSD();
 71    add("clickButton",
 72        "Simulate clicking the named [\"button\"] in the visible floater named in [\"name\"]",
 73        &LLFloaterRegListener::clickButton,
 74        requiredNameButton);
 75}
 76
 77void LLFloaterRegListener::getBuildMap(const LLSD& event) const
 78{
 79    LLSD reply;
 80    // Build an LLSD map that mirrors sBuildMap. Since we have no good way to
 81    // represent a C++ callable in LLSD, the only part of BuildData we can
 82    // store is the filename. For each LLSD map entry, it would be more
 83    // extensible to store a nested LLSD map containing a single key "file" --
 84    // but we don't bother, simply storing the string filename instead.
 85    for (LLFloaterReg::build_map_t::const_iterator mi(LLFloaterReg::sBuildMap.begin()),
 86                                                   mend(LLFloaterReg::sBuildMap.end());
 87         mi != mend; ++mi)
 88    {
 89        reply[mi->first] = mi->second.mFile;
 90    }
 91    // Send the reply to the LLEventPump named in event["reply"].
 92    sendReply(reply, event);
 93}
 94
 95void LLFloaterRegListener::showInstance(const LLSD& event) const
 96{
 97    LLFloaterReg::showInstance(event["name"], event["key"], event["focus"]);
 98}
 99
100void LLFloaterRegListener::hideInstance(const LLSD& event) const
101{
102    LLFloaterReg::hideInstance(event["name"], event["key"]);
103}
104
105void LLFloaterRegListener::toggleInstance(const LLSD& event) const
106{
107    LLFloaterReg::toggleInstance(event["name"], event["key"]);
108}
109
110void LLFloaterRegListener::instanceVisible(const LLSD& event) const
111{
112    sendReply(LLSDMap("visible", LLFloaterReg::instanceVisible(event["name"], event["key"])),
113              event);
114}
115
116void LLFloaterRegListener::clickButton(const LLSD& event) const
117{
118    // If the caller requests a reply, build the reply.
119    LLReqID reqID(event);
120    LLSD reply(reqID.makeResponse());
121
122    LLFloater* floater = LLFloaterReg::findInstance(event["name"], event["key"]);
123    if (! LLFloater::isShown(floater))
124    {
125        reply["type"]  = "LLFloater";
126        reply["name"]  = event["name"];
127        reply["key"]   = event["key"];
128        reply["error"] = floater? "!isShown()" : "NULL";
129    }
130    else
131    {
132        // Here 'floater' points to an LLFloater instance with the specified
133        // name and key which isShown().
134        LLButton* button = floater->findChild<LLButton>(event["button"]);
135        if (! LLButton::isAvailable(button))
136        {
137            reply["type"]  = "LLButton";
138            reply["name"]  = event["button"];
139            reply["error"] = button? "!isAvailable()" : "NULL";
140        }
141        else
142        {
143            // Here 'button' points to an isAvailable() LLButton child of
144            // 'floater' with the specified button name. Pretend to click it.
145            button->onCommit();
146            // Leave reply["error"] isUndefined(): no error, i.e. success.
147        }
148    }
149
150    // Send a reply only if caller asked for a reply.
151    LLSD replyPump(event["reply"]);
152    if (replyPump.isString())       // isUndefined() if absent
153    {
154        LLEventPumps::instance().obtain(replyPump).post(reply);
155    }
156}