00001
00032 #include "llviewerprecompiledheaders.h"
00033
00034 #include "llfloatermute.h"
00035
00036 #include "llfontgl.h"
00037 #include "llrect.h"
00038 #include "llerror.h"
00039 #include "llstring.h"
00040 #include "message.h"
00041
00042
00043 #include "llagent.h"
00044 #include "llfloateravatarpicker.h"
00045 #include "llbutton.h"
00046 #include "lllineeditor.h"
00047 #include "llmutelist.h"
00048 #include "llresizehandle.h"
00049 #include "llscrolllistctrl.h"
00050 #include "lltextbox.h"
00051 #include "llviewertexteditor.h"
00052 #include "llviewerwindow.h"
00053 #include "lluictrlfactory.h"
00054 #include "llfocusmgr.h"
00055
00056
00057
00058
00059 const char FLOATER_TITLE[] = "Muted Residents & Objects";
00060 const F32 INSTANT_MSG_SIZE = 8.0f;
00061 const LLColor4 INSTANT_MSG_COLOR(1, 1, 1, 1);
00062 const LLColor4 MUTED_MSG_COLOR(0.5f, 0.5f, 0.5f, 1.f);
00063
00064 const S32 LINE = 16;
00065 const S32 LEFT = 2;
00066 const S32 VPAD = 4;
00067 const S32 HPAD = 4;
00068
00069
00070
00071
00072
00073 class LLFloaterMuteObjectUI : public LLFloater
00074 {
00075 public:
00076 typedef void(*callback_t)(const LLString&, void*);
00077
00078 static LLFloaterMuteObjectUI* show(callback_t callback,
00079 void* userdata);
00080 virtual BOOL postBuild();
00081
00082 protected:
00083 LLFloaterMuteObjectUI();
00084 virtual ~LLFloaterMuteObjectUI();
00085 virtual BOOL handleKeyHere(KEY key, MASK mask);
00086
00087 private:
00088
00089 static void onBtnOk(void *data);
00090 static void onBtnCancel(void *data);
00091
00092 void (*mCallback)(const LLString& objectName,
00093 void* userdata);
00094 void* mCallbackUserData;
00095
00096 static LLFloaterMuteObjectUI* sInstance;
00097 };
00098
00099 LLFloaterMuteObjectUI* LLFloaterMuteObjectUI::sInstance = NULL;
00100
00101 LLFloaterMuteObjectUI::LLFloaterMuteObjectUI()
00102 : LLFloater("Mute object by name"),
00103 mCallback(NULL),
00104 mCallbackUserData(NULL)
00105 {
00106 LLUICtrlFactory::getInstance()->buildFloater(this, "floater_mute_object.xml", NULL);
00107 }
00108
00109
00110 LLFloaterMuteObjectUI::~LLFloaterMuteObjectUI()
00111 {
00112 gFocusMgr.releaseFocusIfNeeded( this );
00113 sInstance = NULL;
00114 }
00115
00116 LLFloaterMuteObjectUI* LLFloaterMuteObjectUI::show(callback_t callback,
00117 void* userdata)
00118 {
00119 const bool firstInstantiation = (sInstance == NULL);
00120 if (firstInstantiation)
00121 {
00122 sInstance = new LLFloaterMuteObjectUI;
00123 }
00124 sInstance->mCallback = callback;
00125 sInstance->mCallbackUserData = userdata;
00126
00127 sInstance->open();
00128 if (firstInstantiation)
00129 {
00130 sInstance->center();
00131 }
00132
00133 return sInstance;
00134 }
00135
00136
00137 BOOL LLFloaterMuteObjectUI::postBuild()
00138 {
00139 childSetAction("OK", onBtnOk, this);
00140 childSetAction("Cancel", onBtnCancel, this);
00141 return TRUE;
00142 }
00143
00144 void LLFloaterMuteObjectUI::onBtnOk(void* userdata)
00145 {
00146 LLFloaterMuteObjectUI* self = (LLFloaterMuteObjectUI*)userdata;
00147 if (!self) return;
00148
00149 if (self->mCallback)
00150 {
00151 const LLString& text = self->childGetValue("object_name").asString();
00152 self->mCallback(text,self->mCallbackUserData);
00153 }
00154 self->close();
00155 }
00156
00157 void LLFloaterMuteObjectUI::onBtnCancel(void* userdata)
00158 {
00159 LLFloaterMuteObjectUI* self = (LLFloaterMuteObjectUI*)userdata;
00160 if (!self) return;
00161
00162 self->close();
00163 }
00164
00165 BOOL LLFloaterMuteObjectUI::handleKeyHere(KEY key, MASK mask)
00166 {
00167 if (key == KEY_RETURN && mask == MASK_NONE)
00168 {
00169 onBtnOk(this);
00170 return TRUE;
00171 }
00172 else if (key == KEY_ESCAPE && mask == MASK_NONE)
00173 {
00174 onBtnCancel(this);
00175 return TRUE;
00176 }
00177
00178 return LLFloater::handleKeyHere(key, mask);
00179 }
00180
00181
00182
00183
00184
00185
00186
00187
00188 LLFloaterMute::LLFloaterMute(const LLSD& seed)
00189 : LLFloater("mute floater", "FloaterMuteRect3", FLOATER_TITLE,
00190 RESIZE_YES, 220, 140, DRAG_ON_TOP, MINIMIZE_YES, CLOSE_YES)
00191 {
00192
00193 LLUICtrlFactory::getInstance()->buildFloater(this, "floater_mute.xml", NULL, FALSE);
00194 }
00195
00196
00197 void LLFloaterMute::onChange()
00198 {
00199 refreshMuteList();
00200 }
00201
00202 BOOL LLFloaterMute::postBuild()
00203 {
00204 childSetCommitCallback("mutes", onSelectName, this);
00205 childSetAction("Mute resident...", onClickPick, this);
00206 childSetAction("Mute object by name...", onClickMuteByName, this);
00207 childSetAction("Unmute", onClickRemove, this);
00208
00209 mMuteList = getChild<LLScrollListCtrl>("mutes");
00210 mMuteList->setCommitOnSelectionChange(TRUE);
00211
00212 LLMuteList::getInstance()->addObserver(this);
00213
00214 refreshMuteList();
00215
00216 return TRUE;
00217 }
00218
00219
00220
00221
00222 LLFloaterMute::~LLFloaterMute()
00223 {
00224 }
00225
00226
00227
00228
00229 void LLFloaterMute::refreshMuteList()
00230 {
00231 mMuteList->deleteAllItems();
00232
00233 std::vector<LLMute> mutes = LLMuteList::getInstance()->getMutes();
00234 std::vector<LLMute>::iterator it;
00235 for (it = mutes.begin(); it != mutes.end(); ++it)
00236 {
00237 LLString display_name = it->getDisplayName();
00238 mMuteList->addStringUUIDItem(display_name, it->mID);
00239 }
00240
00241 updateButtons();
00242 }
00243
00244 void LLFloaterMute::selectMute(const LLUUID& mute_id)
00245 {
00246 mMuteList->selectByID(mute_id);
00247 updateButtons();
00248 }
00249
00250
00251
00252
00253 void LLFloaterMute::updateButtons()
00254 {
00255 if (mMuteList->getFirstSelected())
00256 {
00257 childSetEnabled("Unmute", TRUE);
00258 }
00259 else
00260 {
00261 childSetEnabled("Unmute", FALSE);
00262 }
00263 }
00264
00265
00266
00267
00268 void LLFloaterMute::onSelectName(LLUICtrl *caller, void *data)
00269 {
00270 LLFloaterMute *floater = (LLFloaterMute*)data;
00271
00272 floater->updateButtons();
00273 }
00274
00275
00276
00277
00278 void LLFloaterMute::onClickRemove(void *data)
00279 {
00280 LLFloaterMute* floater = (LLFloaterMute *)data;
00281
00282 LLString name = floater->mMuteList->getSelectedItemLabel();
00283 LLUUID id = floater->mMuteList->getStringUUIDSelectedItem();
00284 LLMute mute(id);
00285 mute.setFromDisplayName(name);
00286
00287
00288 S32 last_selected = floater->mMuteList->getFirstSelectedIndex();
00289 if (LLMuteList::getInstance()->remove(mute))
00290 {
00291
00292
00293 if (last_selected == floater->mMuteList->getItemCount())
00294 {
00295
00296 floater->mMuteList->selectNthItem(last_selected - 1);
00297 }
00298 else
00299 {
00300
00301 floater->mMuteList->selectNthItem(last_selected);
00302 }
00303 }
00304 floater->updateButtons();
00305 }
00306
00307
00308
00309
00310 void LLFloaterMute::onClickPick(void *data)
00311 {
00312 LLFloaterMute* floaterp = (LLFloaterMute*)data;
00313 const BOOL allow_multiple = FALSE;
00314 const BOOL close_on_select = TRUE;
00315 LLFloaterAvatarPicker* picker = LLFloaterAvatarPicker::show(onPickUser, data, allow_multiple, close_on_select);
00316 floaterp->addDependentFloater(picker);
00317 }
00318
00319
00320
00321
00322 void LLFloaterMute::onPickUser(const std::vector<std::string>& names, const std::vector<LLUUID>& ids, void* user_data)
00323 {
00324 LLFloaterMute* floaterp = (LLFloaterMute*)user_data;
00325 if (!floaterp) return;
00326 if (names.empty() || ids.empty()) return;
00327
00328 LLMute mute(ids[0], names[0], LLMute::AGENT);
00329 LLMuteList::getInstance()->add(mute);
00330 floaterp->updateButtons();
00331 }
00332
00333
00334 void LLFloaterMute::onClickMuteByName(void* data)
00335 {
00336 LLFloaterMuteObjectUI* picker = LLFloaterMuteObjectUI::show(callbackMuteByName,data);
00337 assert(picker);
00338
00339 LLFloaterMute* floaterp = (LLFloaterMute*)data;
00340 floaterp->addDependentFloater(picker);
00341 }
00342
00343 void LLFloaterMute::callbackMuteByName(const LLString& text, void* data)
00344 {
00345 if (text.empty()) return;
00346
00347 LLMute mute(LLUUID::null, text, LLMute::BY_NAME);
00348 BOOL success = LLMuteList::getInstance()->add(mute);
00349 if (!success)
00350 {
00351 gViewerWindow->alertXml("MuteByNameFailed");
00352 }
00353 }