/* * @file llfloatermediafilter.cpp * @brief Stupid floater for listing junk * @author Cinder Biscuits * * Permission is hereby granted, free of charge, to any person or organization * obtaining a copy of the software and accompanying documentation covered by * this license (the "Software") to use, reproduce, display, distribute, * execute, and transmit the Software, and to prepare derivative works of the * Software, and to permit third-parties to whom the Software is furnished to * do so, all subject to the following: * * The copyright notices in the Software and this entire statement, including * the above license grant, this restriction and the following disclaimer, * must be included in all copies of the Software, in whole or in part, and * all derivative works of the Software, unless such copies or derivative * works are solely in the form of machine-executable object code generated by * a source language processor. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * */ #include "llviewerprecompiledheaders.h" #include "llfloatermediafilter.h" #include "llnotificationsutil.h" #include "llscrolllistctrl.h" #include "llscrolllistitem.h" #include "lltrans.h" #include "lluictrlfactory.h" bool handle_add_callback(const LLSD& notification, const LLSD& response); // TODO: Maybe add removal confirmation? //bool handle_remove_callback(const LLSD& notification, const LLSD& response); LLFloaterMediaFilter::LLFloaterMediaFilter(const LLSD& key) : LLFloater(key) { mCommitCallbackRegistrar.add("MediaFilter.CommitAction", boost::bind(&LLFloaterMediaFilter::onCommitAction, this, _2)); mMediaListConnection = LLMediaFilter::getInstance()->setMediaListUpdateCallback(boost::bind(&LLFloaterMediaFilter::updateLists, this, _1)); LLUICtrlFactory::getInstance()->buildFloater(this, "floater_media_lists.xml", NULL, false); } LLFloaterMediaFilter::~LLFloaterMediaFilter() { if (mMediaListConnection.connected()) mMediaListConnection.disconnect(); } BOOL LLFloaterMediaFilter::postBuild() { mWhitelist = getChild("whitelist"); mBlacklist = getChild("blacklist"); updateLists(LLMediaFilter::WHITELIST); updateLists(LLMediaFilter::BLACKLIST); return TRUE; } void LLFloaterMediaFilter::updateLists(LLMediaFilter::EMediaList list) { if (list == LLMediaFilter::WHITELIST) { LLMediaFilter::string_list_t list = LLMediaFilter::getInstance()->getWhiteList(); mWhitelist->clearRows(); for (LLMediaFilter::string_list_t::const_iterator itr = list.begin(); itr != list.end(); ++itr) { LLSD element; element["columns"][0]["column"] = "list"; element["columns"][0]["value"] = (*itr); mWhitelist->addElement(element); } } if (list == LLMediaFilter::BLACKLIST) { LLMediaFilter::string_list_t list = LLMediaFilter::getInstance()->getBlackList(); mBlacklist->clearRows(); for (LLMediaFilter::string_list_t::const_iterator itr = list.begin(); itr != list.end(); ++itr) { LLSD element; element["columns"][0]["column"] = "list"; element["columns"][0]["value"] = (*itr); mBlacklist->addElement(element); } } } void LLFloaterMediaFilter::onCommitAction(const LLSD& userdata) { std::string chosen_item = userdata.asString(); if (chosen_item == "AddToWhitelist") { LLSD payload, args; args["LIST"] = LLTrans::getString("MediaFilterWhitelist"); payload = true; LLNotificationsUtil::add("AddToMediaList", args, payload, &handle_add_callback); } else if (chosen_item == "AddToBlacklist") { LLSD payload, args; args["LIST"] = LLTrans::getString("MediaFilterBlacklist"); payload = false; LLNotificationsUtil::add("AddToMediaList", args, payload, &handle_add_callback); } else if (chosen_item == "RemoveFromWhitelist") { std::vector selected = mWhitelist->getAllSelected(); if (!selected.empty()) { LLMediaFilter::string_vec_t domains; for (std::vector::iterator itr = selected.begin(); itr != selected.end(); ++itr) { domains.push_back((*itr)->getColumn(0)->getValue().asString()); } LLMediaFilter::getInstance()->removeFromMediaList(domains, LLMediaFilter::WHITELIST); } } else if (chosen_item == "RemoveFromBlacklist") { std::vector selected = mBlacklist->getAllSelected(); if (!selected.empty()) { LLMediaFilter::string_vec_t domains; for (std::vector::iterator itr = selected.begin(); itr != selected.end(); ++itr) { domains.push_back((*itr)->getColumn(0)->getValue().asString()); } LLMediaFilter::getInstance()->removeFromMediaList(domains, LLMediaFilter::BLACKLIST); } } } bool handle_add_callback(const LLSD& notification, const LLSD& response) { S32 option = LLNotificationsUtil::getSelectedOption(notification, response); if (option == 0) { std::string url = response["url"].asString(); if (notification["payload"].asBoolean()) LLMediaFilter::getInstance()->addToMediaList(url, LLMediaFilter::WHITELIST); else LLMediaFilter::getInstance()->addToMediaList(url, LLMediaFilter::BLACKLIST); } return false; }