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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
/**
* @file llpanelblockedlist.cpp
* @brief Container for blocked Residents & Objects list
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, 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 "llpanelblockedlist.h"
// library include
#include "llavatarname.h"
#include "llfiltereditor.h"
#include "llfloater.h"
#include "llfloaterreg.h"
#include "llnotificationsutil.h"
#include "llscrolllistctrl.h"
#include "llmenubutton.h"
// project include
#include "llavatarlistitem.h"
#include "llblocklist.h"
#include "llblockedlistitem.h"
#include "llfloateravatarpicker.h"
#include "llfloatersidepanelcontainer.h"
#include "llinventorylistitem.h"
#include "llinventorymodel.h"
#include "llsidetraypanelcontainer.h"
#include "llviewercontrol.h"
static LLPanelInjector<LLPanelBlockedList> t_panel_blocked_list("panel_block_list_sidetray");
//
// Constants
//
const std::string BLOCKED_PARAM_NAME = "blocked_to_select";
//-----------------------------------------------------------------------------
// LLPanelBlockedList()
//-----------------------------------------------------------------------------
LLPanelBlockedList::LLPanelBlockedList()
: LLPanel()
{
mCommitCallbackRegistrar.add("Block.Action", { boost::bind(&LLPanelBlockedList::onCustomAction, this, _2), cb_info::UNTRUSTED_BLOCK });
mEnableCallbackRegistrar.add("Block.Check", boost::bind(&LLPanelBlockedList::isActionChecked, this, _2));
}
void LLPanelBlockedList::removePicker()
{
if(mPicker.get())
{
mPicker.get()->closeFloater();
}
}
bool LLPanelBlockedList::postBuild()
{
mBlockedList = getChild<LLBlockList>("blocked");
mBlockedList->setCommitOnSelectionChange(true);
this->setVisibleCallback(boost::bind(&LLPanelBlockedList::removePicker, this));
switch (gSavedSettings.getU32("BlockPeopleSortOrder"))
{
case E_SORT_BY_NAME:
mBlockedList->sortByName();
break;
case E_SORT_BY_TYPE:
mBlockedList->sortByType();
break;
default:
LL_WARNS() << "Unrecognized sort order for blocked list" << LL_ENDL;
break;
}
mBlockedGearBtn = getChild<LLMenuButton>("blocked_gear_btn");
// Use the context menu of the Block list for the Block tab gear menu.
LLToggleableMenu* blocked_gear_menu = mBlockedList->getContextMenu();
if (blocked_gear_menu)
{
mBlockedGearBtn->setMenu(blocked_gear_menu, LLMenuButton::MP_BOTTOM_LEFT);
}
mUnblockBtn = getChild<LLButton>("unblock_btn");
mUnblockBtn->setCommitCallback(boost::bind(&LLPanelBlockedList::unblockItem, this));
getChild<LLFilterEditor>("blocked_filter_input")->setCommitCallback(boost::bind(&LLPanelBlockedList::onFilterEdit, this, _2));
mBlockLimitText = getChild<LLUICtrl>("block_limit");
return LLPanel::postBuild();
}
void LLPanelBlockedList::draw()
{
updateButtons();
LLPanel::draw();
}
void LLPanelBlockedList::onOpen(const LLSD& key)
{
if (key.has(BLOCKED_PARAM_NAME) && key[BLOCKED_PARAM_NAME].asUUID().notNull())
{
selectBlocked(key[BLOCKED_PARAM_NAME].asUUID());
}
}
void LLPanelBlockedList::selectBlocked(const LLUUID& mute_id)
{
mBlockedList->resetSelection();
mBlockedList->selectItemByUUID(mute_id);
}
void LLPanelBlockedList::showPanelAndSelect(const LLUUID& idToSelect)
{
LLFloaterSidePanelContainer::showPanel("people", "panel_people",
LLSD().with("people_panel_tab_name", "blocked_panel").with(BLOCKED_PARAM_NAME, idToSelect));
}
//////////////////////////////////////////////////////////////////////////
// Private Section
//////////////////////////////////////////////////////////////////////////
void LLPanelBlockedList::updateButtons()
{
bool hasSelected = NULL != mBlockedList->getSelectedItem();
mUnblockBtn->setEnabled(hasSelected);
mBlockedGearBtn->setEnabled(hasSelected);
static LLCachedControl<S32> mute_list_limit(gSavedSettings, "MuteListLimit");
mBlockLimitText->setTextArg("[COUNT]", llformat("%d", mBlockedList->getMuteListSize()));
mBlockLimitText->setTextArg("[LIMIT]", llformat("%d", mute_list_limit()));
}
void LLPanelBlockedList::unblockItem()
{
LLBlockedListItem* item = mBlockedList->getBlockedItem();
if (item)
{
LLMute mute(item->getUUID(), item->getName());
LLMuteList::instance().remove(mute);
}
}
void LLPanelBlockedList::onCustomAction(const LLSD& userdata)
{
const std::string command_name = userdata.asString();
if ("block_obj_by_name" == command_name)
{
blockObjectByName();
}
else if ("block_res_by_name" == command_name)
{
blockResidentByName();
}
else if ("sort_by_name" == command_name)
{
mBlockedList->sortByName();
gSavedSettings.setU32("BlockPeopleSortOrder", E_SORT_BY_NAME);
}
else if ("sort_by_type" == command_name)
{
mBlockedList->sortByType();
gSavedSettings.setU32("BlockPeopleSortOrder", E_SORT_BY_TYPE);
}
}
bool LLPanelBlockedList::isActionChecked(const LLSD& userdata)
{
std::string item = userdata.asString();
U32 sort_order = gSavedSettings.getU32("BlockPeopleSortOrder");
if ("sort_by_name" == item)
{
return E_SORT_BY_NAME == sort_order;
}
else if ("sort_by_type" == item)
{
return E_SORT_BY_TYPE == sort_order;
}
return false;
}
void LLPanelBlockedList::blockResidentByName()
{
const bool allow_multiple = false;
const bool close_on_select = true;
LLView * button = findChild<LLButton>("plus_btn", true);
LLFloater* root_floater = gFloaterView->getParentFloater(this);
LLFloaterAvatarPicker * picker = LLFloaterAvatarPicker::show(boost::bind(&LLPanelBlockedList::callbackBlockPicked, this, _1, _2),
allow_multiple, close_on_select, false, root_floater->getName(), button);
if (root_floater)
{
root_floater->addDependentFloater(picker);
}
mPicker = picker->getHandle();
}
void LLPanelBlockedList::blockObjectByName()
{
LLFloaterGetBlockedObjectName::show(&LLPanelBlockedList::callbackBlockByName);
}
void LLPanelBlockedList::onFilterEdit(const std::string& search_string)
{
std::string filter = search_string;
LLStringUtil::trimHead(filter);
mBlockedList->setNameFilter(filter);
}
void LLPanelBlockedList::callbackBlockPicked(const uuid_vec_t& ids, const std::vector<LLAvatarName> names)
{
if (names.empty() || ids.empty()) return;
LLMute mute(ids[0], names[0].getUserName(), LLMute::AGENT);
LLMuteList::getInstance()->add(mute);
showPanelAndSelect(mute.mID);
}
//static
void LLPanelBlockedList::callbackBlockByName(const std::string& text)
{
if (text.empty()) return;
LLMute mute(LLUUID::null, text, LLMute::BY_NAME);
bool success = LLMuteList::getInstance()->add(mute);
if (!success)
{
LLNotificationsUtil::add("MuteByNameFailed");
}
}
//////////////////////////////////////////////////////////////////////////
// LLFloaterGetBlockedObjectName
//////////////////////////////////////////////////////////////////////////
// Constructor/Destructor
LLFloaterGetBlockedObjectName::LLFloaterGetBlockedObjectName(const LLSD& key)
: LLFloater(key)
, mGetObjectNameCallback(NULL)
{
}
// Destroys the object
LLFloaterGetBlockedObjectName::~LLFloaterGetBlockedObjectName()
{
gFocusMgr.releaseFocusIfNeeded( this );
}
bool LLFloaterGetBlockedObjectName::postBuild()
{
getChild<LLButton>("OK")-> setCommitCallback(boost::bind(&LLFloaterGetBlockedObjectName::applyBlocking, this));
getChild<LLButton>("Cancel")-> setCommitCallback(boost::bind(&LLFloaterGetBlockedObjectName::cancelBlocking, this));
center();
return LLFloater::postBuild();
}
bool LLFloaterGetBlockedObjectName::handleKeyHere(KEY key, MASK mask)
{
if (key == KEY_RETURN && mask == MASK_NONE)
{
applyBlocking();
return true;
}
else if (key == KEY_ESCAPE && mask == MASK_NONE)
{
cancelBlocking();
return true;
}
return LLFloater::handleKeyHere(key, mask);
}
// static
LLFloaterGetBlockedObjectName* LLFloaterGetBlockedObjectName::show(get_object_name_callback_t callback)
{
LLFloaterGetBlockedObjectName* floater = LLFloaterReg::showTypedInstance<LLFloaterGetBlockedObjectName>("mute_object_by_name");
floater->mGetObjectNameCallback = callback;
// *TODO: mantipov: should LLFloaterGetBlockedObjectName be closed when panel is closed?
// old Floater dependency is not enable in panel
// addDependentFloater(floater);
return floater;
}
//////////////////////////////////////////////////////////////////////////
// Private Section
void LLFloaterGetBlockedObjectName::applyBlocking()
{
if (mGetObjectNameCallback)
{
const std::string& text = getChild<LLUICtrl>("object_name")->getValue().asString();
mGetObjectNameCallback(text);
}
closeFloater();
}
void LLFloaterGetBlockedObjectName::cancelBlocking()
{
closeFloater();
}
//EOF
|