FIRE-11224: Introduce FSRegistrarUtils class to be able to run enabled checks from LLUI and disable context menu items in scroll lists and text areas

master
Ansariel 2013-08-06 15:03:24 +02:00
parent 7b7b8195e9
commit ab5afa556f
9 changed files with 209 additions and 7 deletions

View File

@ -33,6 +33,8 @@ include_directories(SYSTEM
)
set(llui_SOURCE_FILES
fsregistrarutils.cpp
llaccordionctrl.cpp
llaccordionctrltab.cpp
llbadge.cpp
@ -137,6 +139,8 @@ set(llui_SOURCE_FILES
set(llui_HEADER_FILES
CMakeLists.txt
fsregistrarutils.h
llaccordionctrl.h
llaccordionctrltab.h
llbadge.h

View File

@ -0,0 +1,45 @@
/**
* @file fsregistrarutils.cpp
* @brief Utility class to allow registrars access information from dependent projects
*
* $LicenseInfo:firstyear=2013&license=viewerlgpl$
* Phoenix Firestorm Viewer Source Code
* Copyright (c) 2013 Ansariel Hiller @ Second Life
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* The Phoenix Firestorm Project, Inc., 1831 Oakwood Drive, Fairmont, Minnesota 56031-3225 USA
* http://www.firestormviewer.org
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "fsregistrarutils.h"
FSRegistrarUtils::FSRegistrarUtils() :
mEnableCheckFunction(NULL)
{
}
bool FSRegistrarUtils::checkIsEnabled(const LLUUID& av_id, EFSRegistrarFunctionActionType action)
{
if (mEnableCheckFunction)
{
return mEnableCheckFunction(av_id, action);
}
return false;
}
FSRegistrarUtils gFSRegistrarUtils;

View File

@ -0,0 +1,62 @@
/**
* @file fsregistrarutils.h
* @brief Utility class to allow registrars access information from dependent projects
*
* $LicenseInfo:firstyear=2013&license=viewerlgpl$
* Phoenix Firestorm Viewer Source Code
* Copyright (c) 2013 Ansariel Hiller @ Second Life
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* The Phoenix Firestorm Project, Inc., 1831 Oakwood Drive, Fairmont, Minnesota 56031-3225 USA
* http://www.firestormviewer.org
* $/LicenseInfo$
*/
#ifndef FS_REGISTRARUTILS_H
#define FS_REGISTRARUTILS_H
enum EFSRegistrarFunctionActionType
{
FS_RGSTR_ACT_ADD_FRIEND,
FS_RGSTR_ACT_SEND_IM,
FS_RGSTR_ACT_ZOOM_IN,
FS_RGSTR_ACT_OFFER_TELEPORT,
FS_RGSTR_ACT_SHOW_PROFILE,
FS_RGSTR_ACT_TRACK_AVATAR,
FS_RGSTR_ACT_TELEPORT_TO
};
class FSRegistrarUtils
{
public:
FSRegistrarUtils::FSRegistrarUtils();
FSRegistrarUtils::~FSRegistrarUtils() { };
typedef boost::function<bool(const LLUUID&, EFSRegistrarFunctionActionType)> enable_check_function_t;
void setEnableCheckFunction(const enable_check_function_t& func)
{
mEnableCheckFunction = func;
}
bool checkIsEnabled(const LLUUID& av_id, EFSRegistrarFunctionActionType action);
private:
enable_check_function_t mEnableCheckFunction;
};
extern FSRegistrarUtils gFSRegistrarUtils;
#endif // FS_REGISTRARUTILS_H

View File

@ -61,6 +61,8 @@
#include <boost/bind.hpp>
#include "fsregistrarutils.h"
static LLDefaultChildRegistry::Register<LLScrollListCtrl> r("scroll_list");
// local structures & classes.
@ -1914,6 +1916,17 @@ BOOL LLScrollListCtrl::handleRightMouseDown(S32 x, S32 y, MASK mask)
registrar.add("FS.TrackAvatar", boost::bind(&LLUrlAction::executeSLURL, "secondlife:///app/firestorm/" + id + "/track"));
// </FS:Ansariel> Additional convenience options
// <FS:Ansariel> Add enable checks for menu items
LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registrar;
enable_registrar.add("Url.EnableShowProfile", boost::bind(&FSRegistrarUtils::checkIsEnabled, gFSRegistrarUtils, uuid, FS_RGSTR_ACT_SHOW_PROFILE));
enable_registrar.add("Url.EnableAddFriend", boost::bind(&FSRegistrarUtils::checkIsEnabled, gFSRegistrarUtils, uuid, FS_RGSTR_ACT_ADD_FRIEND));
enable_registrar.add("Url.EnableSendIM", boost::bind(&FSRegistrarUtils::checkIsEnabled, gFSRegistrarUtils, uuid, FS_RGSTR_ACT_SEND_IM));
enable_registrar.add("FS.EnableZoomIn", boost::bind(&FSRegistrarUtils::checkIsEnabled, gFSRegistrarUtils, uuid, FS_RGSTR_ACT_ZOOM_IN));
enable_registrar.add("FS.EnableOfferTeleport", boost::bind(&FSRegistrarUtils::checkIsEnabled, gFSRegistrarUtils, uuid, FS_RGSTR_ACT_OFFER_TELEPORT));
enable_registrar.add("FS.EnableTrackAvatar", boost::bind(&FSRegistrarUtils::checkIsEnabled, gFSRegistrarUtils, uuid, FS_RGSTR_ACT_TRACK_AVATAR));
enable_registrar.add("FS.EnableTeleportToTarget", boost::bind(&FSRegistrarUtils::checkIsEnabled, gFSRegistrarUtils, uuid, FS_RGSTR_ACT_TELEPORT_TO));
// </FS:Ansariel>
// create the context menu from the XUI file and display it
std::string menu_name = is_group ? "menu_url_group.xml" : "menu_url_agent.xml";
delete mPopupMenu;

View File

@ -44,6 +44,8 @@
#include "llwindow.h"
#include <boost/bind.hpp>
#include "fsregistrarutils.h"
const F32 CURSOR_FLASH_DELAY = 1.0f; // in seconds
const S32 CURSOR_THICKNESS = 2;
const F32 TRIPLE_CLICK_INTERVAL = 0.3f; // delay between double and triple click.
@ -2010,11 +2012,23 @@ void LLTextBase::createUrlContextMenu(S32 x, S32 y, const std::string &in_url)
registrar.add("Url.SendIM", boost::bind(&LLUrlAction::sendIM, url)); // <FS:CR>
// <FS:Ansariel> Additional convenience options
std::string target_id = LLUrlAction::extractUuidFromSlurl(url).asString();
registrar.add("FS.ZoomIn", boost::bind(&LLUrlAction::executeSLURL, "secondlife:///app/firestorm/" + target_id + "/zoom"));
registrar.add("FS.TeleportToTarget", boost::bind(&LLUrlAction::executeSLURL, "secondlife:///app/firestorm/" + target_id + "/teleportto"));
registrar.add("FS.OfferTeleport", boost::bind(&LLUrlAction::executeSLURL, "secondlife:///app/firestorm/" + target_id + "/offerteleport"));
registrar.add("FS.TrackAvatar", boost::bind(&LLUrlAction::executeSLURL, "secondlife:///app/firestorm/" + target_id + "/track"));
std::string target_id_str = LLUrlAction::extractUuidFromSlurl(url).asString();
registrar.add("FS.ZoomIn", boost::bind(&LLUrlAction::executeSLURL, "secondlife:///app/firestorm/" + target_id_str + "/zoom"));
registrar.add("FS.TeleportToTarget", boost::bind(&LLUrlAction::executeSLURL, "secondlife:///app/firestorm/" + target_id_str + "/teleportto"));
registrar.add("FS.OfferTeleport", boost::bind(&LLUrlAction::executeSLURL, "secondlife:///app/firestorm/" + target_id_str + "/offerteleport"));
registrar.add("FS.TrackAvatar", boost::bind(&LLUrlAction::executeSLURL, "secondlife:///app/firestorm/" + target_id_str + "/track"));
// </FS:Ansariel>
// <FS:Ansariel> Add enable checks for menu items
LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registrar;
LLUUID target_id(target_id_str);
enable_registrar.add("Url.EnableShowProfile", boost::bind(&FSRegistrarUtils::checkIsEnabled, gFSRegistrarUtils, target_id, FS_RGSTR_ACT_SHOW_PROFILE));
enable_registrar.add("Url.EnableAddFriend", boost::bind(&FSRegistrarUtils::checkIsEnabled, gFSRegistrarUtils, target_id, FS_RGSTR_ACT_ADD_FRIEND));
enable_registrar.add("Url.EnableSendIM", boost::bind(&FSRegistrarUtils::checkIsEnabled, gFSRegistrarUtils, target_id, FS_RGSTR_ACT_SEND_IM));
enable_registrar.add("FS.EnableZoomIn", boost::bind(&FSRegistrarUtils::checkIsEnabled, gFSRegistrarUtils, target_id, FS_RGSTR_ACT_ZOOM_IN));
enable_registrar.add("FS.EnableOfferTeleport", boost::bind(&FSRegistrarUtils::checkIsEnabled, gFSRegistrarUtils, target_id, FS_RGSTR_ACT_OFFER_TELEPORT));
enable_registrar.add("FS.EnableTrackAvatar", boost::bind(&FSRegistrarUtils::checkIsEnabled, gFSRegistrarUtils, target_id, FS_RGSTR_ACT_TRACK_AVATAR));
enable_registrar.add("FS.EnableTeleportToTarget", boost::bind(&FSRegistrarUtils::checkIsEnabled, gFSRegistrarUtils, target_id, FS_RGSTR_ACT_TELEPORT_TO));
// </FS:Ansariel>
// create and return the context menu from the XUI file

View File

@ -28,17 +28,21 @@
#include "llviewerprecompiledheaders.h"
#include "fscommon.h"
#include "fsradar.h"
#include "llagent.h"
#include "llavataractions.h"
#include "llavatarnamecache.h"
#include "llfloatersidepanelcontainer.h"
#include "llnotificationmanager.h"
#include "llinventorymodel.h"
#include "llnotificationmanager.h"
#include "llnotificationsutil.h" // <FS:CR> reportToNearbyChat
#include "llpanel.h"
#include "lltooldraganddrop.h"
#include "llviewerinventory.h"
#include "llviewernetwork.h"
#include "llviewerregion.h"
#include "llnotificationsutil.h" // <FS:CR> reportToNearbyChat
#include "rlvactions.h"
#include "rlvhandler.h"
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
@ -51,6 +55,7 @@ static const std::string LL_PRODUCTENGINE = "ProductEngine";
static const std::string LL_SCOUT = "Scout";
static const std::string LL_TESTER = "Tester";
S32 FSCommon::sObjectAddMsg = 0;
void reportToNearbyChat(const std::string& message)
@ -283,3 +288,41 @@ bool FSCommon::isLinden(const LLUUID& av_id)
last_name == LL_SCOUT ||
last_name == LL_TESTER);
}
bool FSCommon::checkIsActionEnabled(const LLUUID& av_id, EFSRegistrarFunctionActionType action)
{
bool isSelf = (av_id == gAgentID);
if (action == FS_RGSTR_ACT_ADD_FRIEND)
{
return (!isSelf && !LLAvatarActions::isFriend(av_id));
}
else if (action == FS_RGSTR_ACT_SEND_IM)
{
return (!isSelf && RlvActions::canStartIM(av_id));
}
else if (action == FS_RGSTR_ACT_ZOOM_IN)
{
return (!isSelf && LLAvatarActions::canZoomIn(av_id));
}
else if (action == FS_RGSTR_ACT_OFFER_TELEPORT)
{
return (!isSelf && LLAvatarActions::canOfferTeleport(av_id));
}
else if (action == FS_RGSTR_ACT_SHOW_PROFILE)
{
return (isSelf || !gRlvHandler.hasBehaviour(RLV_BHVR_SHOWNAMES));
}
else if (action == FS_RGSTR_ACT_TRACK_AVATAR)
{
return (!isSelf && FSRadar::getInstance()->getEntry(av_id) != NULL);
}
else if (action == FS_RGSTR_ACT_TELEPORT_TO)
{
return (!isSelf && FSRadar::getInstance()->getEntry(av_id) != NULL);
}
return false;
}

View File

@ -28,6 +28,7 @@
#ifndef FS_COMMON_H
#define FS_COMMON_H
#include "fsregistrarutils.h"
#include "llchat.h"
#include "llpanelpeople.h"
#include "llviewerobject.h"
@ -73,6 +74,8 @@ namespace FSCommon
* keep track of ObjectAdd messages sent to the similular.
*/
extern S32 sObjectAddMsg;
bool checkIsActionEnabled(const LLUUID& av_id, EFSRegistrarFunctionActionType);
};
#endif // FS_COMMON_H

View File

@ -225,6 +225,7 @@
#include "streamtitledisplay.h"
#include "fscommon.h"
#include "tea.h"
#include "fsregistrarutils.h"
//
// exported globals
@ -1740,6 +1741,9 @@ LLWorld::getInstance()->addRegion(gFirstSimHandle, gFirstSim, first_sim_size_x,
llinfos << "Radar initialized" << llendl;
// </FS:Ansariel>
// <FS:Ansariel> Register check function for registrar enable checks
gFSRegistrarUtils.setEnableCheckFunction(boost::bind(&FSCommon::checkIsActionEnabled, _1, _2));
// <FS:Techwolf Lupindo> fsdata support
FSData::instance().addAgents();
// </FS:Techwolf Lupindo>

View File

@ -11,6 +11,8 @@
function="Url.Execute" /> -->
<menu_item_call.on_click
function="Url.ShowProfile" />
<menu_item_call.on_enable
function="Url.EnableShowProfile" />
</menu_item_call>
<menu_item_call
label="Send IM..."
@ -18,6 +20,8 @@
name="send_im">
<menu_item_call.on_click
function="Url.SendIM" />
<menu_item_call.on_enable
function="Url.EnableSendIM" />
</menu_item_call>
<menu_item_call
label="Add Friend..."
@ -25,6 +29,8 @@
name="add_friend">
<menu_item_call.on_click
function="Url.AddFriend" />
<menu_item_call.on_enable
function="Url.EnableAddFriend" />
</menu_item_call>
<menu_item_call
label="Zoom at Resident"
@ -32,6 +38,8 @@
name="zoom_agent">
<menu_item_call.on_click
function="FS.ZoomIn" />
<menu_item_call.on_enable
function="FS.EnableZoomIn" />
</menu_item_call>
<menu_item_call
label="Teleport to Resident"
@ -39,6 +47,8 @@
name="teleportto_agent">
<menu_item_call.on_click
function="FS.TeleportToTarget" />
<menu_item_call.on_enable
function="FS.EnableTeleportToTarget" />
</menu_item_call>
<menu_item_call
label="Offer Teleport"
@ -46,6 +56,8 @@
name="offer_teleport">
<menu_item_call.on_click
function="FS.OfferTeleport" />
<menu_item_call.on_enable
function="FS.EnableOfferTeleport" />
</menu_item_call>
<menu_item_call
label="Track Resident"
@ -53,6 +65,8 @@
name="track_agent">
<menu_item_call.on_click
function="FS.TrackAvatar" />
<menu_item_call.on_enable
function="FS.EnableTrackAvatar" />
</menu_item_call>
<menu_item_separator
layout="topleft" />