llfloaterobjectiminfo.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /**
  2. * @file llfloaterobjectiminfo.cpp
  3. * @brief A floater with information about an object that sent an IM.
  4. *
  5. * $LicenseInfo:firstyear=2007&license=viewergpl$
  6. *
  7. * Copyright (c) 2007-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llfloaterobjectiminfo.h"
  34. #include "llcachename.h"
  35. #include "llfloater.h"
  36. #include "llsdutil.h"
  37. #include "lluictrlfactory.h"
  38. #include "llagent.h"
  39. #include "llcommandhandler.h"
  40. #include "llfloateravatarinfo.h"
  41. #include "llfloatergroupinfo.h"
  42. #include "llfloatermute.h"
  43. #include "llmutelist.h"
  44. //MK
  45. #include "mkrlinterface.h"
  46. //mk
  47. #include "llurldispatcher.h"
  48. #include "llviewercontrol.h"
  49. ////////////////////////////////////////////////////////////////////////////
  50. // LLFloaterObjectIMInfo
  51. class LLFloaterObjectIMInfo : public LLFloater,
  52. public LLFloaterSingleton<LLFloaterObjectIMInfo>
  53. {
  54. friend class LLUISingleton<LLFloaterObjectIMInfo,
  55. VisibilityPolicy<LLFloater> >;
  56. public:
  57. bool postBuild();
  58. void update(const LLUUID& id, const std::string& name,
  59. const std::string& slurl, const LLUUID& owner,
  60. bool owner_is_group);
  61. private:
  62. // Open only via LLFloaterSingleton interface, i.e. showInstance() or
  63. // toggleInstance().
  64. LLFloaterObjectIMInfo(const LLSD&);
  65. // UI Handlers
  66. static void onClickMap(void* data);
  67. static void onClickOwner(void* data);
  68. static void onClickMuteOwner(void* data);
  69. static void onClickMuteObject(void* data);
  70. static void onClickMuteByName(void* data);
  71. // Name cache callbacks
  72. static void nameCallback(const LLUUID& id, const std::string& full_name,
  73. bool is_group, LLFloaterObjectIMInfo* self);
  74. static void onAvatarNameCache(const LLUUID& agent_id,
  75. const LLAvatarName& av_name,
  76. LLFloaterObjectIMInfo* self);
  77. private:
  78. LLUUID mObjectID;
  79. LLUUID mOwnerID;
  80. std::string mObjectName;
  81. std::string mSlurl;
  82. std::string mOwnerName;
  83. bool mOwnerIsGroup;
  84. };
  85. LLFloaterObjectIMInfo::LLFloaterObjectIMInfo(const LLSD&)
  86. : mOwnerIsGroup(false)
  87. {
  88. LLUICtrlFactory::getInstance()->buildFloater(this,
  89. "floater_object_im_info.xml");
  90. if (getRect().mLeft == 0 && getRect().mBottom == 0)
  91. {
  92. center();
  93. }
  94. }
  95. bool LLFloaterObjectIMInfo::postBuild()
  96. {
  97. childSetAction("MuteOwner", onClickMuteOwner, this);
  98. childSetAction("MuteObject", onClickMuteObject, this);
  99. childSetAction("MuteByName", onClickMuteByName, this);
  100. childSetActionTextbox("OwnerName", onClickOwner, this);
  101. childSetActionTextbox("Slurl", onClickMap, this);
  102. return true;
  103. }
  104. void LLFloaterObjectIMInfo::update(const LLUUID& object_id,
  105. const std::string& name,
  106. const std::string& slurl,
  107. const LLUUID& owner_id, bool owner_is_group)
  108. {
  109. // When talking to an old region we do not have a slurl. The object Id is
  110. // not really the object Id either but we do not use it so who cares.
  111. bool have_slurl = !slurl.empty();
  112. childSetVisible("Unknown_Slurl", !have_slurl);
  113. childSetVisible("Slurl", have_slurl);
  114. childSetText("ObjectName", name);
  115. childSetText("Slurl", slurl);
  116. bool my_object = owner_id == gAgentID;
  117. childSetEnabled("MuteOwner", !my_object);
  118. childSetEnabled("MuteObject", !my_object);
  119. childSetEnabled("MuteByName", !my_object);
  120. mObjectID = object_id;
  121. mObjectName = name;
  122. mSlurl = slurl;
  123. mOwnerName.clear();
  124. mOwnerID = owner_id;
  125. mOwnerIsGroup = owner_is_group;
  126. if (owner_is_group)
  127. {
  128. if (gCacheNamep)
  129. {
  130. gCacheNamep->get(owner_id, true,
  131. boost::bind(&LLFloaterObjectIMInfo::nameCallback,
  132. _1, _2, _3, this));
  133. }
  134. }
  135. else
  136. {
  137. LLAvatarName av_name;
  138. if (LLAvatarNameCache::get(owner_id, &av_name))
  139. {
  140. if (LLAvatarNameCache::useDisplayNames())
  141. {
  142. mOwnerName = av_name.getNames();
  143. }
  144. else
  145. {
  146. mOwnerName = av_name.getLegacyName();
  147. }
  148. }
  149. else
  150. {
  151. LLAvatarNameCache::get(owner_id,
  152. boost::bind(&LLFloaterObjectIMInfo::onAvatarNameCache,
  153. _1, _2, this));
  154. }
  155. }
  156. childSetText("OwnerName", mOwnerName);
  157. }
  158. //static
  159. void LLFloaterObjectIMInfo::nameCallback(const LLUUID& id,
  160. const std::string& full_name,
  161. bool is_group,
  162. LLFloaterObjectIMInfo* self)
  163. {
  164. if (self == findInstance())
  165. {
  166. self->mOwnerName = full_name;
  167. self->childSetText("OwnerName", full_name);
  168. }
  169. }
  170. //static
  171. void LLFloaterObjectIMInfo::onAvatarNameCache(const LLUUID& agent_id,
  172. const LLAvatarName& av_name,
  173. LLFloaterObjectIMInfo* self)
  174. {
  175. if (self != findInstance()) return; // Stale callback, instance closed.
  176. if (LLAvatarNameCache::useDisplayNames())
  177. {
  178. self->mOwnerName = av_name.getNames();
  179. }
  180. else
  181. {
  182. self->mOwnerName = av_name.getLegacyName();
  183. }
  184. self->childSetText("OwnerName", self->mOwnerName);
  185. }
  186. //static
  187. void LLFloaterObjectIMInfo::onClickMap(void* data)
  188. {
  189. LLFloaterObjectIMInfo* self = (LLFloaterObjectIMInfo*)data;
  190. std::ostringstream link;
  191. link << "secondlife://" << self->mSlurl;
  192. class LLMediaCtrl* web = NULL;
  193. LLURLDispatcher::dispatch(link.str(), "clicked", web, true);
  194. }
  195. //static
  196. void LLFloaterObjectIMInfo::onClickOwner(void* data)
  197. {
  198. LLFloaterObjectIMInfo* self = (LLFloaterObjectIMInfo*)data;
  199. if (self->mOwnerIsGroup)
  200. {
  201. LLFloaterGroupInfo::showFromUUID(self->mOwnerID);
  202. }
  203. //MK
  204. else if (self->mOwnerID == gAgentID || !gRLenabled ||
  205. !gRLInterface.mContainsShownames)
  206. //mk
  207. {
  208. LLFloaterAvatarInfo::showFromObject(self->mOwnerID);
  209. }
  210. }
  211. //static
  212. void LLFloaterObjectIMInfo::onClickMuteOwner(void* data)
  213. {
  214. LLFloaterObjectIMInfo* self = (LLFloaterObjectIMInfo*)data;
  215. LLMute::EType mute_type = self->mOwnerIsGroup ? LLMute::GROUP
  216. : LLMute::AGENT;
  217. LLMute mute(self->mOwnerID, self->mOwnerName, mute_type);
  218. if (LLMuteList::add(mute))
  219. {
  220. LLFloaterMute::selectMute(mute.mID);
  221. }
  222. self->close();
  223. }
  224. //static
  225. void LLFloaterObjectIMInfo::onClickMuteObject(void* data)
  226. {
  227. LLFloaterObjectIMInfo* self = (LLFloaterObjectIMInfo*)data;
  228. LLMute mute(self->mObjectID, self->mObjectName, LLMute::OBJECT);
  229. if (LLMuteList::add(mute))
  230. {
  231. LLFloaterMute::selectMute(mute.mID);
  232. }
  233. self->close();
  234. }
  235. //static
  236. void LLFloaterObjectIMInfo::onClickMuteByName(void* data)
  237. {
  238. LLFloaterObjectIMInfo* self = (LLFloaterObjectIMInfo*)data;
  239. LLMute mute(LLUUID::null, self->mObjectName, LLMute::BY_NAME);
  240. if (LLMuteList::add(mute))
  241. {
  242. LLFloaterMute::showInstance();
  243. }
  244. self->close();
  245. }
  246. ////////////////////////////////////////////////////////////////////////////
  247. // LLObjectIMInfo
  248. //static
  249. void LLObjectIMInfo::show(const LLUUID& object_id, const std::string& name,
  250. const std::string& location, const LLUUID& owner_id,
  251. bool owner_is_group)
  252. {
  253. LLFloaterObjectIMInfo* floaterp = LLFloaterObjectIMInfo::showInstance();
  254. floaterp->update(object_id, name, location, owner_id, owner_is_group);
  255. }
  256. ////////////////////////////////////////////////////////////////////////////
  257. // LLObjectIMInfoHandler
  258. // E.g. secondlife:///app/objectim/9426adfc-9c17-8765-5f09-fdf19957d003
  259. // ?owner=a112d245-9095-4e9c-ace4-ffa31717f934&groupowned=true
  260. // &slurl=ahern/123/123/123&name=Object
  261. class LLObjectIMInfoHandler final : public LLCommandHandler
  262. {
  263. public:
  264. LLObjectIMInfoHandler()
  265. : LLCommandHandler("objectim", UNTRUSTED_THROTTLE)
  266. {
  267. }
  268. bool handle(const LLSD& tokens, const LLSD& query_map,
  269. LLMediaCtrl*) override
  270. {
  271. LLUUID task_id = tokens[0].asUUID();
  272. std::string name = query_map["name"].asString();
  273. std::string slurl = query_map["slurl"].asString();
  274. LLUUID owner = query_map["owner"].asUUID();
  275. bool group_owned = query_map.has("groupowned");
  276. LLObjectIMInfo::show(task_id, name, slurl, owner, group_owned);
  277. return true;
  278. }
  279. };
  280. // Creating the object registers with the dispatcher.
  281. LLObjectIMInfoHandler gObjectIMHandler;