summaryrefslogtreecommitdiff
path: root/indra/newview/llfloateravatarrendersettings.cpp
blob: 2bae7d63aaac2d894ef51e444794da344311f1af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/**
 * @file llfloateravatarrendersettings.cpp
 * @brief Shows the list of avatars with non-default rendering settings
 *
 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
 * Second Life Viewer Source Code
 * Copyright (C) 2017, Linden Research, Inc.
 *
 * 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
 *
 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 * $/LicenseInfo$
 */
#include "llviewerprecompiledheaders.h"

#include "llfloateravatarrendersettings.h"

#include "llavatarnamecache.h"
#include "llfloateravatarpicker.h"
#include "llfiltereditor.h"
#include "llfloaterreg.h"
#include "llnamelistctrl.h"
#include "llmenugl.h"
#include "lltrans.h"
#include "llviewerobjectlist.h"
#include "llvoavatar.h"

class LLSettingsContextMenu : public LLListContextMenu

{
public:
    LLSettingsContextMenu(LLFloaterAvatarRenderSettings* floater_settings)
        :   mFloaterSettings(floater_settings)
    {}
protected:
    LLContextMenu* createMenu()
    {
        LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar;
        LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registrar;
        registrar.add("Settings.SetRendering", boost::bind(&LLFloaterAvatarRenderSettings::onCustomAction, mFloaterSettings, _2, mUUIDs.front()));
        enable_registrar.add("Settings.IsSelected", boost::bind(&LLFloaterAvatarRenderSettings::isActionChecked, mFloaterSettings, _2, mUUIDs.front()));
        LLContextMenu* menu = createFromFile("menu_avatar_rendering_settings.xml");

        return menu;
    }

    LLFloaterAvatarRenderSettings* mFloaterSettings;
};

class LLAvatarRenderMuteListObserver : public LLMuteListObserver
{
    /* virtual */ void onChange()  { LLFloaterAvatarRenderSettings::setNeedsUpdate();}
};

static LLAvatarRenderMuteListObserver sAvatarRenderMuteListObserver;

LLFloaterAvatarRenderSettings::LLFloaterAvatarRenderSettings(const LLSD& key)
:   LLFloater(key),
	mAvatarSettingsList(NULL),
	mNeedsUpdate(false)
{
    mContextMenu = new LLSettingsContextMenu(this);
    LLRenderMuteList::getInstance()->addObserver(&sAvatarRenderMuteListObserver);
    mCommitCallbackRegistrar.add("Settings.AddNewEntry", boost::bind(&LLFloaterAvatarRenderSettings::onClickAdd, this, _2));
}

LLFloaterAvatarRenderSettings::~LLFloaterAvatarRenderSettings()
{
    delete mContextMenu;
    LLRenderMuteList::getInstance()->removeObserver(&sAvatarRenderMuteListObserver);
}

BOOL LLFloaterAvatarRenderSettings::postBuild()
{
    LLFloater::postBuild();
    mAvatarSettingsList = getChild<LLNameListCtrl>("render_settings_list");
    mAvatarSettingsList->setRightMouseDownCallback(boost::bind(&LLFloaterAvatarRenderSettings::onAvatarListRightClick, this, _1, _2, _3));
    this->setVisibleCallback(boost::bind(&LLFloaterAvatarRenderSettings::removePicker, this));
    getChild<LLFilterEditor>("people_filter_input")->setCommitCallback(boost::bind(&LLFloaterAvatarRenderSettings::onFilterEdit, this, _2));

	return TRUE;
}

void LLFloaterAvatarRenderSettings::removePicker()
{
    if(mPicker.get())
    {
        mPicker.get()->closeFloater();
    }
}

void LLFloaterAvatarRenderSettings::draw()
{
    if(mNeedsUpdate)
    {
        updateList();
        mNeedsUpdate = false;
    }

    LLFloater::draw();
}

void LLFloaterAvatarRenderSettings::onAvatarListRightClick(LLUICtrl* ctrl, S32 x, S32 y)
{
    LLNameListCtrl* list = dynamic_cast<LLNameListCtrl*>(ctrl);
    if (!list) return;
    list->selectItemAt(x, y, MASK_NONE);
    uuid_vec_t selected_uuids;

    if(list->getCurrentID().notNull())
    {
        selected_uuids.push_back(list->getCurrentID());
        mContextMenu->show(ctrl, selected_uuids, x, y);
    }
}

void LLFloaterAvatarRenderSettings::onOpen(const LLSD& key)
{
    updateList();
}

void LLFloaterAvatarRenderSettings::updateList()
{
    mAvatarSettingsList->deleteAllItems();
    LLAvatarName av_name;
    LLNameListCtrl::NameItem item_params;
    for (std::map<LLUUID, S32>::iterator iter = LLRenderMuteList::getInstance()->sVisuallyMuteSettingsMap.begin(); iter != LLRenderMuteList::getInstance()->sVisuallyMuteSettingsMap.end(); iter++)
    {
        item_params.value = iter->first;
        LLAvatarNameCache::get(iter->first, &av_name);
        if(!isHiddenRow(av_name.getCompleteName()))
        {
            item_params.columns.add().value(av_name.getCompleteName()).column("name");
            std::string setting = getString(iter->second == 1 ? "av_never_render" : "av_always_render");
            item_params.columns.add().value(setting).column("setting");
            std::string timestamp = createTimestamp(LLRenderMuteList::getInstance()->getVisualMuteDate(iter->first));
            item_params.columns.add().value(timestamp).column("timestamp");
            mAvatarSettingsList->addNameItemRow(item_params);
        }
    }
}

void LLFloaterAvatarRenderSettings::onFilterEdit(const std::string& search_string)
{
    std::string filter_upper = search_string;
    LLStringUtil::toUpper(filter_upper);
    if (mNameFilter != filter_upper)
    {
        mNameFilter = filter_upper;
        mNeedsUpdate = true;
    }
}

bool LLFloaterAvatarRenderSettings::isHiddenRow(const std::string& av_name)
{
    if (mNameFilter.empty()) return false;
    std::string upper_name = av_name;
    LLStringUtil::toUpper(upper_name);
    return std::string::npos == upper_name.find(mNameFilter);
}

static LLVOAvatar* find_avatar(const LLUUID& id)
{
    LLViewerObject *obj = gObjectList.findObject(id);
    while (obj && obj->isAttachment())
    {
        obj = (LLViewerObject *)obj->getParent();
    }

    if (obj && obj->isAvatar())
    {
        return (LLVOAvatar*)obj;
    }
    else
    {
        return NULL;
    }
}


void LLFloaterAvatarRenderSettings::onCustomAction (const LLSD& userdata, const LLUUID& av_id)
{
    const std::string command_name = userdata.asString();

    S32 new_setting = 0;
    if ("default" == command_name)
    {
        new_setting = S32(LLVOAvatar::AV_RENDER_NORMALLY);
    }
    else if ("never" == command_name)
    {
        new_setting = S32(LLVOAvatar::AV_DO_NOT_RENDER);
    }
    else if ("always" == command_name)
    {
        new_setting = S32(LLVOAvatar::AV_ALWAYS_RENDER);
    }

    setAvatarRenderSetting(av_id, new_setting);
}


bool LLFloaterAvatarRenderSettings::isActionChecked(const LLSD& userdata, const LLUUID& av_id)
{
    const std::string command_name = userdata.asString();

    S32 visual_setting = LLRenderMuteList::getInstance()->getSavedVisualMuteSetting(av_id);
    if ("default" == command_name)
    {
        return (visual_setting == S32(LLVOAvatar::AV_RENDER_NORMALLY));
    }
    else if ("never" == command_name)
    {
        return (visual_setting == S32(LLVOAvatar::AV_DO_NOT_RENDER));
    }
    else if ("always" == command_name)
    {
        return (visual_setting == S32(LLVOAvatar::AV_ALWAYS_RENDER));
    }
    return false;
}

void LLFloaterAvatarRenderSettings::setNeedsUpdate()
{
    LLFloaterAvatarRenderSettings* instance = LLFloaterReg::getTypedInstance<LLFloaterAvatarRenderSettings>("avatar_render_settings");
    if(!instance) return;
    instance->mNeedsUpdate = true;
}

void LLFloaterAvatarRenderSettings::onClickAdd(const LLSD& userdata)
{
    const std::string command_name = userdata.asString();
    S32 visual_setting = 0;
    if ("never" == command_name)
    {
        visual_setting = S32(LLVOAvatar::AV_DO_NOT_RENDER);
    }
    else if ("always" == command_name)
    {
        visual_setting = S32(LLVOAvatar::AV_ALWAYS_RENDER);
    }

    LLView * button = findChild<LLButton>("plus_btn", TRUE);
    LLFloater* root_floater = gFloaterView->getParentFloater(this);
    LLFloaterAvatarPicker * picker = LLFloaterAvatarPicker::show(boost::bind(&LLFloaterAvatarRenderSettings::callbackAvatarPicked, this, _1, visual_setting),
                                                                    FALSE, TRUE, FALSE, root_floater->getName(), button);

    if (root_floater)
    {
        root_floater->addDependentFloater(picker);
    }

    mPicker = picker->getHandle();
}

void LLFloaterAvatarRenderSettings::callbackAvatarPicked(const uuid_vec_t& ids, S32 visual_setting)
{
    if (ids.empty()) return;
    setAvatarRenderSetting(ids[0], visual_setting);
}

void LLFloaterAvatarRenderSettings::setAvatarRenderSetting(const LLUUID& av_id, S32 new_setting)
{
    LLVOAvatar *avatarp = find_avatar(av_id);
    if (avatarp)
    {
        avatarp->setVisualMuteSettings(LLVOAvatar::VisualMuteSettings(new_setting));
    }
    else
    {
        LLRenderMuteList::getInstance()->saveVisualMuteSetting(av_id, new_setting);
    }
}

BOOL LLFloaterAvatarRenderSettings::handleKeyHere(KEY key, MASK mask )
{
    BOOL handled = FALSE;

    if (KEY_DELETE == key)
    {
        setAvatarRenderSetting(mAvatarSettingsList->getCurrentID(), (S32)LLVOAvatar::AV_RENDER_NORMALLY);
        handled = TRUE;
    }
    return handled;
}

std::string LLFloaterAvatarRenderSettings::createTimestamp(S32 datetime)
{
    std::string timeStr;
    LLSD substitution;
    substitution["datetime"] = datetime;

    timeStr = "["+LLTrans::getString ("TimeMonth")+"]/["
                 +LLTrans::getString ("TimeDay")+"]/["
                 +LLTrans::getString ("TimeYear")+"]";

    LLStringUtil::format (timeStr, substitution);
    return timeStr;
}