llfloaterexperienceprofile.cpp 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  1. /**
  2. * @file llfloaterexperienceprofile.cpp
  3. * @brief llfloaterexperienceprofile and related class definitions
  4. *
  5. * $LicenseInfo:firstyear=2013&license=viewergpl$
  6. *
  7. * Copyright (c) 2013, 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 "llfloaterexperienceprofile.h"
  34. #include "llbutton.h"
  35. #include "llcachename.h"
  36. #include "llcheckboxctrl.h"
  37. #include "llcombobox.h"
  38. #include "llevents.h"
  39. #include "llexperiencecache.h"
  40. #include "lllineeditor.h"
  41. #include "llnotifications.h"
  42. #include "llsdserialize.h"
  43. #include "lltabcontainer.h"
  44. #include "lltextbox.h"
  45. #include "lltexteditor.h"
  46. #include "lltrans.h"
  47. #include "lluictrlfactory.h"
  48. #include "llagent.h"
  49. #include "llappviewer.h"
  50. #include "llcommandhandler.h"
  51. #include "llexperiencelog.h" // For PUMP_EXPERIENCE
  52. #include "llfloateravatarinfo.h"
  53. #include "llfloatergroups.h"
  54. #include "llfloatergroupinfo.h"
  55. #include "llfloaterreporter.h"
  56. #include "llmediactrl.h"
  57. //MK
  58. #include "mkrlinterface.h"
  59. //mk
  60. #include "llslurl.h"
  61. #include "llurldispatcher.h"
  62. #include "lltexturectrl.h"
  63. #include "llviewerregion.h"
  64. #include "llviewerwindow.h" // For gViewerWindowp
  65. #include "llweb.h"
  66. //static
  67. LLFloaterExperienceProfile::instances_map_t LLFloaterExperienceProfile::sInstances;
  68. // Command handler
  69. class LLExperienceHandler final : public LLCommandHandler
  70. {
  71. public:
  72. LLExperienceHandler()
  73. : LLCommandHandler("experience", UNTRUSTED_THROTTLE)
  74. {
  75. }
  76. bool handle(const LLSD& params, const LLSD&, LLMediaCtrl*) override
  77. {
  78. if (params.size() != 2 || params[1].asString() != "profile")
  79. {
  80. return false;
  81. }
  82. LLExperienceCache* exp = LLExperienceCache::getInstance();
  83. exp->get(params[0].asUUID(),
  84. boost::bind(&LLExperienceHandler::experienceCallback, this,
  85. _1));
  86. return true;
  87. }
  88. void experienceCallback(const LLSD& exp_details)
  89. {
  90. if (!exp_details.has(LLExperienceCache::MISSING))
  91. {
  92. LLUUID id = exp_details[LLExperienceCache::EXPERIENCE_ID].asUUID();
  93. if (id.notNull())
  94. {
  95. LLFloaterExperienceProfile::show(id);
  96. }
  97. }
  98. }
  99. };
  100. LLExperienceHandler gExperienceHandler;
  101. // LLFloaterExperienceProfile class
  102. //static
  103. LLFloaterExperienceProfile* LLFloaterExperienceProfile::show(const LLUUID& id)
  104. {
  105. LLFloaterExperienceProfile* self = NULL;
  106. instances_map_t::iterator it = sInstances.find(id);
  107. if (it == sInstances.end())
  108. {
  109. self = new LLFloaterExperienceProfile(id);
  110. }
  111. else
  112. {
  113. self = it->second;
  114. }
  115. if (self)
  116. {
  117. self->open();
  118. self->setFocus(true);
  119. }
  120. return self;
  121. }
  122. LLFloaterExperienceProfile::LLFloaterExperienceProfile(const LLUUID& exp_id)
  123. : LLFloater(exp_id.asString()),
  124. mExperienceId(exp_id),
  125. mSaveCompleteAction(NOTHING),
  126. mDirty(false),
  127. mForceClose(false)
  128. {
  129. sInstances[exp_id] = this;
  130. LLUICtrlFactory::getInstance()->buildFloater(this,
  131. "floater_experienceprofile.xml");
  132. }
  133. LLFloaterExperienceProfile::~LLFloaterExperienceProfile()
  134. {
  135. sInstances.erase(mExperienceId);
  136. }
  137. bool LLFloaterExperienceProfile::postBuild()
  138. {
  139. mEditBtn = getChild<LLButton>("edit_btn");
  140. mEditBtn->setClickedCallback(onClickEdit, this);
  141. mEditBtn->setVisible(false);
  142. mAllowBtn = getChild<LLButton>("allow_btn");
  143. mAllowBtn->setClickedCallback(onClickAllow, this);
  144. mForgetBtn = getChild<LLButton>("forget_btn");
  145. mForgetBtn->setClickedCallback(onClickForget, this);
  146. mBlockBtn = getChild<LLButton>("block_btn");
  147. mBlockBtn->setClickedCallback(onClickBlock, this);
  148. childSetAction("cancel_btn", onClickCancel, this);
  149. mSaveBtn = getChild<LLButton>("save_btn");
  150. mSaveBtn->setClickedCallback(onClickSave, this);
  151. childSetAction("location_btn", onClickLocation, this);
  152. childSetAction("clear_btn", onClickClear, this);
  153. LLColor4 links_color = LLTextEditor::getLinksColor();
  154. mOwnerText = getChild<LLTextBox>("OwnerText");
  155. mOwnerText->setClickedCallback(onOwnerProfile, this);
  156. mOwnerText->setColor(links_color);
  157. mGroupBtn = getChild<LLButton>("group_btn");
  158. mGroupBtn->setClickedCallback(onPickGroup, this);
  159. mGroupText = getChild<LLTextBox>("GroupText");
  160. mGroupText->setClickedCallback(onShowGroupInfo, this);
  161. mGroupText->setColor(links_color);
  162. mEditGroupText = getChild<LLTextBox>("edit_GroupText");
  163. mEditGroupText->setClickedCallback(onShowGroupInfo, this);
  164. mEditGroupText->setColor(links_color);
  165. childSetAction("report_btn", onReportExperience, this);
  166. mExperienceDescEditor = getChild<LLTextEditor>("edit_experience_description");
  167. mExperienceDescEditor->setKeystrokeCallback(onTextKeystroke, this);
  168. mExperienceDescEditor->setCommitOnFocusLost(true);
  169. mRatingCombo = getChild<LLComboBox>("edit_ContentRatingText");
  170. mRatingCombo->setCommitCallback(onFieldChanged);
  171. mRatingCombo->setCallbackUserData(this);
  172. mRatingText = getChild<LLTextBox>("ContentRatingText");
  173. mMarketplaceText = getChild<LLTextBox>("marketplace");
  174. mMarketplaceText->setClickedCallback(onOpenMarketplaceURL, this);
  175. mMarketplaceText->setColor(links_color);
  176. mMarketplaceEditor = getChild<LLLineEditor>("edit_marketplace");
  177. mMarketplaceEditor->setKeystrokeCallback(onLineKeystroke);
  178. mMarketplaceEditor->setCallbackUserData(this);
  179. mExperienceTitleText = getChild<LLTextBox>("experience_title");
  180. mExperienceTitleText->setClickedCallback(onClickExperienceTitle, this);
  181. mExperienceTitleEditor = getChild<LLLineEditor>("edit_experience_title");
  182. mExperienceTitleEditor->setKeystrokeCallback(onLineKeystroke);
  183. mExperienceTitleEditor->setCallbackUserData(this);
  184. mEnableCheck = getChild<LLCheckBoxCtrl>("edit_enable_btn");
  185. mEnableCheck->setCommitCallback(onFieldChanged);
  186. mEnableCheck->setCallbackUserData(this);
  187. mPrivateCheck = getChild<LLCheckBoxCtrl>("edit_private_btn");
  188. mPrivateCheck->setCommitCallback(onFieldChanged);
  189. mPrivateCheck->setCallbackUserData(this);
  190. mLogoTexture = getChild<LLTextureCtrl>("logo");
  191. mLogoTexture->setFallbackImageName("default_land_picture.j2c");
  192. mEditLogoTexture = getChild<LLTextureCtrl>("edit_logo");
  193. mEditLogoTexture->setCommitCallback(onFieldChanged);
  194. mEditLogoTexture->setCallbackUserData(this);
  195. mEditLogoTexture->setFallbackImageName("default_land_picture.j2c");
  196. mLocationText = getChild<LLTextBox>("LocationTextText");
  197. mLocationText->setClickedCallback(onShowLocation, this);
  198. mLocationText->setColor(links_color);
  199. mEditLocationText = getChild<LLTextBox>("edit_LocationTextText");
  200. mEditLocationText->setClickedCallback(onShowLocation, this);
  201. mEditLocationText->setColor(links_color);
  202. if (mExperienceId.notNull())
  203. {
  204. LLExperienceCache* expcache = LLExperienceCache::getInstance();
  205. expcache->fetch(mExperienceId, true);
  206. expcache->get(mExperienceId,
  207. boost::bind(&LLFloaterExperienceProfile::experienceCallback,
  208. getDerivedHandle<LLFloaterExperienceProfile>(),
  209. _1));
  210. if (gAgent.hasRegionCapability("IsExperienceAdmin"))
  211. {
  212. expcache->getExperienceAdmin(mExperienceId,
  213. boost::bind(&LLFloaterExperienceProfile::experienceIsAdmin,
  214. getDerivedHandle<LLFloaterExperienceProfile>(),
  215. _1));
  216. }
  217. }
  218. LLEventPump& pump = gEventPumps.obtain(PUMP_EXPERIENCE);
  219. pump.listen(mExperienceId.asString() + "-profile",
  220. boost::bind(&LLFloaterExperienceProfile::experiencePermission,
  221. getDerivedHandle<LLFloaterExperienceProfile>(this),
  222. _1));
  223. return true;
  224. }
  225. void LLFloaterExperienceProfile::experienceCallback(LLHandle<LLFloaterExperienceProfile> handle,
  226. const LLSD& experience)
  227. {
  228. LLFloaterExperienceProfile* self = handle.get();
  229. if (self)
  230. {
  231. self->refreshExperience(experience);
  232. }
  233. }
  234. bool LLFloaterExperienceProfile::experiencePermission(LLHandle<LLFloaterExperienceProfile> handle,
  235. const LLSD& permission)
  236. {
  237. LLFloaterExperienceProfile* self = handle.get();
  238. if (self)
  239. {
  240. self->updatePermission(permission);
  241. }
  242. return false;
  243. }
  244. void LLFloaterExperienceProfile::setPermission(const char* perm)
  245. {
  246. if (gAgent.hasRegionCapability("ExperiencePreferences"))
  247. {
  248. LLExperienceCache* exp = LLExperienceCache::getInstance();
  249. exp->setExperiencePermission(mExperienceId, perm,
  250. boost::bind(&LLFloaterExperienceProfile::experiencePermissionResults,
  251. mExperienceId, _1));
  252. }
  253. }
  254. bool LLFloaterExperienceProfile::setMaturityString(S32 maturity)
  255. {
  256. std::string access;
  257. if (maturity <= (S32)SIM_ACCESS_PG)
  258. {
  259. access = LLTrans::getString("SIM_ACCESS_PG");
  260. mRatingCombo->setCurrentByIndex(2);
  261. }
  262. else if (maturity <= (S32)SIM_ACCESS_MATURE)
  263. {
  264. access = LLTrans::getString("SIM_ACCESS_MATURE");
  265. mRatingCombo->setCurrentByIndex(1);
  266. }
  267. else if (maturity <= (S32)SIM_ACCESS_ADULT)
  268. {
  269. access = LLTrans::getString("SIM_ACCESS_ADULT");
  270. mRatingCombo->setCurrentByIndex(0);
  271. }
  272. else
  273. {
  274. return false;
  275. }
  276. mRatingText->setText(access);
  277. return true;
  278. }
  279. void LLFloaterExperienceProfile::refreshExperience(const LLSD& experience)
  280. {
  281. mExperienceDetails = experience;
  282. mPackage = experience;
  283. LLPanel* imagePanel = getChild<LLPanel>("image_panel");
  284. LLPanel* locationPanel = getChild<LLPanel>("location panel");
  285. LLPanel* marketplacePanel = getChild<LLPanel>("marketplace panel");
  286. LLPanel* groupPanel = getChild<LLPanel>("group_panel");
  287. imagePanel->setVisible(false);
  288. locationPanel->setVisible(false);
  289. marketplacePanel->setVisible(false);
  290. mExperienceTitleText->setText(experience[LLExperienceCache::NAME].asString());
  291. LLSLURL exp_slurl("experience",
  292. experience[LLExperienceCache::EXPERIENCE_ID], "profile");
  293. mExperienceSLURL = exp_slurl.getSLURLString();
  294. mExperienceTitleEditor->setText(experience[LLExperienceCache::NAME].asString());
  295. std::string value = experience[LLExperienceCache::DESCRIPTION].asString();
  296. getChild<LLTextEditor>("experience_description")->setText(value);
  297. mExperienceDescEditor->setText(value);
  298. mLocationSLURL = experience[LLExperienceCache::SLURL].asString();
  299. //MK
  300. if (gRLenabled && gRLInterface.mContainsShowloc)
  301. {
  302. mLocationSLURL.clear();
  303. }
  304. //mk
  305. bool has_slurl = mLocationSLURL.length() > 0;
  306. locationPanel->setVisible(has_slurl);
  307. if (has_slurl)
  308. {
  309. std::string loc_str;
  310. // Depending on the experience, experience[LLExperienceCache::SLURL]
  311. // can be either an actual SLURL, or a region name followed with
  312. // coordinates between parenthesis... Let's convert it into an actual
  313. // SLURL, always.
  314. size_t i = mLocationSLURL.find('(');
  315. if (i != std::string::npos)
  316. {
  317. llwarns << "Invalid SLURL (apparently got a region name and position instead): "
  318. << mLocationSLURL << " - Converting to valid SLURL..."
  319. << llendl;
  320. std::string region = mLocationSLURL.substr(0, i);
  321. LLStringUtil::trimTail(region); // Remove any trailing space
  322. std::string loc = mLocationSLURL.substr(i + 1,
  323. mLocationSLURL.find(')'));
  324. LLStringUtil::trimHead(loc); // Remove any leading space
  325. LLStringUtil::trimTail(loc); // Remove any trailing space
  326. S32 x, y, z;
  327. S32 matched = sscanf(loc.c_str(), "%i,%i,%i", &x, &y, &z);
  328. if (matched != 3)
  329. {
  330. llwarns << "... no valid position found, using center sim..."
  331. << llendl;
  332. // Use the center sim instead...
  333. x = y = 128;
  334. z = 0;
  335. }
  336. LLVector3 pos = LLVector3(x, y, z);
  337. LLSLURL loc_slurl(region, pos);
  338. mLocationSLURL = loc_slurl.getSLURLString();
  339. loc_str = loc_slurl.getLocationString();
  340. llinfos << "... converted to SLURL: " << mLocationSLURL << llendl;
  341. }
  342. else
  343. {
  344. LLSLURL loc_slurl(mLocationSLURL);
  345. mLocationSLURL = loc_slurl.getSLURLString();
  346. loc_str = loc_slurl.getLocationString();
  347. }
  348. mLocationText->setText(loc_str);
  349. mEditLocationText->setText(loc_str);
  350. }
  351. else
  352. {
  353. mLocationSLURL.clear();
  354. mLocationText->setText("");
  355. mEditLocationText->setText("");
  356. }
  357. setMaturityString(experience[LLExperienceCache::MATURITY].asInteger());
  358. LLUUID id = experience[LLExperienceCache::AGENT_ID].asUUID();
  359. setOwnerId(id, this);
  360. id = experience[LLExperienceCache::GROUP_ID].asUUID();
  361. groupPanel->setVisible(!id.isNull());
  362. setEditGroup(id, this);
  363. mGroupBtn->setEnabled(experience[LLExperienceCache::AGENT_ID].asUUID() == gAgentID);
  364. S32 properties = mExperienceDetails[LLExperienceCache::PROPERTIES].asInteger();
  365. mEnableCheck->set(!(properties & LLExperienceCache::PROPERTY_DISABLED));
  366. mPrivateCheck->set(properties & LLExperienceCache::PROPERTY_PRIVATE);
  367. LLTextBox* child = getChild<LLTextBox>("grid_wide");
  368. child->setVisible(true);
  369. if (properties & LLExperienceCache::PROPERTY_GRID)
  370. {
  371. child->setText(LLTrans::getString("Grid-Scope"));
  372. }
  373. else
  374. {
  375. child->setText(LLTrans::getString("Land-Scope"));
  376. }
  377. if (properties & LLExperienceCache::PROPERTY_PRIVILEGED)
  378. {
  379. child = getChild<LLTextBox>("privileged");
  380. child->setVisible(true);
  381. }
  382. else if (gAgent.hasRegionCapability("ExperiencePreferences"))
  383. {
  384. LLExperienceCache* exp = LLExperienceCache::getInstance();
  385. exp->getExperiencePermission(mExperienceId,
  386. boost::bind(&LLFloaterExperienceProfile::experiencePermissionResults,
  387. mExperienceId, _1));
  388. }
  389. value = experience[LLExperienceCache::METADATA].asString();
  390. if (value.empty())
  391. {
  392. return;
  393. }
  394. LLPointer<LLSDParser> parser = new LLSDXMLParser();
  395. LLSD data;
  396. std::istringstream is(value);
  397. if (LLSDParser::PARSE_FAILURE != parser->parse(is, data, value.size()))
  398. {
  399. mMarketplaceURL.clear();
  400. if (data.has("marketplace"))
  401. {
  402. mMarketplaceURL = data["marketplace"].asString();
  403. }
  404. mMarketplaceEditor->setText(mMarketplaceURL);
  405. mMarketplaceText->setText(mMarketplaceURL);
  406. marketplacePanel->setVisible(!mMarketplaceURL.empty());
  407. if (data.has("logo"))
  408. {
  409. LLUUID id = data["logo"].asUUID();
  410. mLogoTexture->setImageAssetID(id);
  411. mEditLogoTexture->setImageAssetID(id);
  412. imagePanel->setVisible(id.notNull());
  413. }
  414. }
  415. else
  416. {
  417. marketplacePanel->setVisible(false);
  418. imagePanel->setVisible(false);
  419. }
  420. mDirty = false;
  421. mForceClose = false;
  422. mSaveBtn->setEnabled(mDirty);
  423. }
  424. void LLFloaterExperienceProfile::setPreferences(const LLSD& content)
  425. {
  426. S32 properties = mExperienceDetails[LLExperienceCache::PROPERTIES].asInteger();
  427. if (properties & LLExperienceCache::PROPERTY_PRIVILEGED)
  428. {
  429. return;
  430. }
  431. const LLSD& experiences = content["experiences"];
  432. const LLSD& blocked = content["blocked"];
  433. for (LLSD::array_const_iterator it = experiences.beginArray(),
  434. end = experiences.endArray();
  435. it != end; ++it)
  436. {
  437. if (it->asUUID() == mExperienceId)
  438. {
  439. experienceAllowed();
  440. return;
  441. }
  442. }
  443. for (LLSD::array_const_iterator it = blocked.beginArray(),
  444. end = blocked.endArray();
  445. it != end; ++it)
  446. {
  447. if (it->asUUID() == mExperienceId)
  448. {
  449. experienceBlocked();
  450. return;
  451. }
  452. }
  453. experienceForgotten();
  454. }
  455. bool LLFloaterExperienceProfile::canClose()
  456. {
  457. if (mForceClose || !mDirty)
  458. {
  459. return true;
  460. }
  461. else
  462. {
  463. // Bring up view-modal dialog: Save changes? Yes, No, Cancel
  464. gNotifications.add("SaveChanges", LLSD(), LLSD(),
  465. boost::bind(&LLFloaterExperienceProfile::handleSaveChangesDialog,
  466. this, _1, _2, CLOSE));
  467. return false;
  468. }
  469. }
  470. bool LLFloaterExperienceProfile::handleSaveChangesDialog(const LLSD& notification,
  471. const LLSD& response,
  472. PostSaveAction action)
  473. {
  474. S32 option = LLNotification::getSelectedOption(notification, response);
  475. switch (option)
  476. {
  477. case 0: // "Yes"
  478. // close after saving
  479. doSave(action);
  480. break;
  481. case 1: // "No"
  482. if (action != NOTHING)
  483. {
  484. mForceClose = true;
  485. if (action==CLOSE)
  486. {
  487. close();
  488. }
  489. else
  490. {
  491. changeToView();
  492. }
  493. }
  494. break;
  495. case 2: // "Cancel"
  496. default:
  497. // If we were quitting, we didn't really mean it.
  498. gAppViewerp->abortQuit();
  499. }
  500. return false;
  501. }
  502. void LLFloaterExperienceProfile::doSave(S32 success_action)
  503. {
  504. mSaveCompleteAction = success_action;
  505. if (gAgent.hasRegionCapability("UpdateExperience"))
  506. {
  507. LLExperienceCache* exp = LLExperienceCache::getInstance();
  508. exp->updateExperience(mPackage,
  509. boost::bind(&LLFloaterExperienceProfile::experienceUpdateResult,
  510. getDerivedHandle<LLFloaterExperienceProfile>(),
  511. _1));
  512. }
  513. }
  514. void LLFloaterExperienceProfile::onSaveComplete(const LLSD& content)
  515. {
  516. LLUUID id = getExperienceId();
  517. if (content.has("removed"))
  518. {
  519. const LLSD& removed = content["removed"];
  520. for (LLSD::map_const_iterator it = removed.beginMap(),
  521. end = removed.endMap();
  522. it != end; ++it)
  523. {
  524. const std::string& field = it->first;
  525. if (field == LLExperienceCache::EXPERIENCE_ID)
  526. {
  527. // this message should be removed by the experience api
  528. continue;
  529. }
  530. const LLSD& data = it->second;
  531. std::string error_tag = data["error_tag"].asString() +
  532. "ExperienceProfileMessage";
  533. LLSD fields;
  534. if (gNotifications.getTemplate(error_tag))
  535. {
  536. fields["FIELD"] = field;
  537. fields["EXTRA_INFO"] = data["extra_info"];
  538. gNotifications.add(error_tag, fields);
  539. }
  540. else
  541. {
  542. fields["MESSAGE"] = data["en"];
  543. gNotifications.add("GenericAlert", fields);
  544. }
  545. }
  546. }
  547. if (!content.has("experience_keys"))
  548. {
  549. llwarns << "Call done with bad content" << llendl;
  550. return;
  551. }
  552. const LLSD& experiences = content["experience_keys"];
  553. LLSD::array_const_iterator it = experiences.beginArray();
  554. if (it == experiences.endArray())
  555. {
  556. llwarns << "Call done with empty content" << llendl;
  557. return;
  558. }
  559. if (!it->has(LLExperienceCache::EXPERIENCE_ID) ||
  560. ((*it)[LLExperienceCache::EXPERIENCE_ID].asUUID() != id))
  561. {
  562. llwarns << "Call done with unexpected experience id" << llendl;
  563. return;
  564. }
  565. refreshExperience(*it);
  566. LLExperienceCache* expcache = LLExperienceCache::getInstance();
  567. expcache->insert(*it);
  568. expcache->fetch(id, true);
  569. if (mSaveCompleteAction == VIEW)
  570. {
  571. LLTabContainer* tabs = getChild<LLTabContainer>("tab_container");
  572. tabs->selectTabByName("panel_experience_info");
  573. }
  574. else if (mSaveCompleteAction == CLOSE)
  575. {
  576. close();
  577. }
  578. }
  579. void LLFloaterExperienceProfile::changeToView()
  580. {
  581. if (mForceClose || !mDirty)
  582. {
  583. refreshExperience(mExperienceDetails);
  584. LLTabContainer* tabs = getChild<LLTabContainer>("tab_container");
  585. tabs->selectTabByName("panel_experience_info");
  586. }
  587. else
  588. {
  589. // Bring up view-modal dialog: Save changes? Yes, No, Cancel
  590. gNotifications.add("SaveChanges", LLSD(), LLSD(),
  591. boost::bind(&LLFloaterExperienceProfile::handleSaveChangesDialog,
  592. this, _1, _2, VIEW));
  593. }
  594. }
  595. void LLFloaterExperienceProfile::updatePermission(const LLSD& permission)
  596. {
  597. if (permission.has("experience"))
  598. {
  599. if (permission["experience"].asUUID() != mExperienceId)
  600. {
  601. return;
  602. }
  603. std::string str = permission[mExperienceId.asString()]["permission"].asString();
  604. if (str == "Allow")
  605. {
  606. experienceAllowed();
  607. }
  608. else if (str == "Block")
  609. {
  610. experienceBlocked();
  611. }
  612. else if (str == "Forget")
  613. {
  614. experienceForgotten();
  615. }
  616. }
  617. else
  618. {
  619. setPreferences(permission);
  620. }
  621. }
  622. void LLFloaterExperienceProfile::experienceAllowed()
  623. {
  624. mAllowBtn->setEnabled(false);
  625. mForgetBtn->setEnabled(true);
  626. mBlockBtn->setEnabled(true);
  627. }
  628. void LLFloaterExperienceProfile::experienceForgotten()
  629. {
  630. mAllowBtn->setEnabled(true);
  631. mForgetBtn->setEnabled(false);
  632. mBlockBtn->setEnabled(true);
  633. }
  634. void LLFloaterExperienceProfile::experienceBlocked()
  635. {
  636. mAllowBtn->setEnabled(true);
  637. mForgetBtn->setEnabled(true);
  638. mBlockBtn->setEnabled(false);
  639. }
  640. void LLFloaterExperienceProfile::onClose(bool app_quitting)
  641. {
  642. LLEventPump& pump = gEventPumps.obtain(PUMP_EXPERIENCE);
  643. pump.stopListening(mExperienceId.asString() + "-profile");
  644. LLFloater::onClose(app_quitting);
  645. }
  646. void LLFloaterExperienceProfile::updatePackage()
  647. {
  648. mPackage[LLExperienceCache::NAME] = mExperienceTitleEditor->getText();
  649. mPackage[LLExperienceCache::DESCRIPTION] = mExperienceDescEditor->getText();
  650. if (mLocationSLURL.empty())
  651. {
  652. mPackage[LLExperienceCache::SLURL] = LLStringUtil::null;
  653. }
  654. else
  655. {
  656. mPackage[LLExperienceCache::SLURL] = mLocationSLURL;
  657. }
  658. mPackage[LLExperienceCache::MATURITY] = mRatingCombo->getSelectedValue().asInteger();
  659. LLSD metadata;
  660. metadata["marketplace"] = mMarketplaceEditor->getText();
  661. metadata["logo"] = mEditLogoTexture->getImageAssetID();
  662. LLPointer<LLSDXMLFormatter> formatter = new LLSDXMLFormatter();
  663. std::ostringstream os;
  664. if (formatter->format(metadata, os))
  665. {
  666. mPackage[LLExperienceCache::METADATA] = os.str();
  667. }
  668. S32 properties = mPackage[LLExperienceCache::PROPERTIES].asInteger();
  669. if (mEnableCheck->get())
  670. {
  671. properties &= ~LLExperienceCache::PROPERTY_DISABLED;
  672. }
  673. else
  674. {
  675. properties |= LLExperienceCache::PROPERTY_DISABLED;
  676. }
  677. if (mPrivateCheck->get())
  678. {
  679. properties |= LLExperienceCache::PROPERTY_PRIVATE;
  680. }
  681. else
  682. {
  683. properties &= ~LLExperienceCache::PROPERTY_PRIVATE;
  684. }
  685. mPackage[LLExperienceCache::PROPERTIES] = properties;
  686. }
  687. //static
  688. LLUUID LLFloaterExperienceProfile::getInstanceId(LLFloaterExperienceProfile* instance)
  689. {
  690. for (instances_map_t::const_iterator it = sInstances.begin(),
  691. end = sInstances.end();
  692. it != end; ++it)
  693. {
  694. if (it->second == instance)
  695. {
  696. return it->first;
  697. }
  698. }
  699. return LLUUID::null;
  700. }
  701. //static
  702. void LLFloaterExperienceProfile::nameCallback(const LLUUID& id,
  703. const std::string& name,
  704. bool is_group,
  705. LLFloaterExperienceProfile* self)
  706. {
  707. if (self && getInstanceId(self).notNull())
  708. {
  709. if (is_group)
  710. {
  711. if (id == self->mGroupId)
  712. {
  713. self->mGroupText->setText(name);
  714. self->mEditGroupText->setText(name);
  715. }
  716. }
  717. else if (id == self->mOwnerId)
  718. {
  719. self->mOwnerText->setText(name);
  720. }
  721. }
  722. }
  723. //static
  724. void LLFloaterExperienceProfile::setOwnerId(LLUUID agent_id, void* data)
  725. {
  726. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  727. if (self && getInstanceId(self).notNull())
  728. {
  729. self->mOwnerId = agent_id;
  730. std::string value;
  731. if (agent_id.notNull() && gCacheNamep)
  732. {
  733. if (!gCacheNamep->getFullName(agent_id, value))
  734. {
  735. gCacheNamep->get(agent_id, false,
  736. boost::bind(&LLFloaterExperienceProfile::nameCallback,
  737. _1, _2, _3, self));
  738. }
  739. }
  740. self->mOwnerText->setText(value);
  741. }
  742. }
  743. //static
  744. void LLFloaterExperienceProfile::setEditGroup(LLUUID group_id, void* data)
  745. {
  746. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  747. if (self && getInstanceId(self).notNull())
  748. {
  749. self->mGroupId = group_id;
  750. std::string value;
  751. if (group_id.notNull() && gCacheNamep)
  752. {
  753. if (!gCacheNamep->getGroupName(group_id, value))
  754. {
  755. gCacheNamep->get(group_id, true,
  756. boost::bind(&LLFloaterExperienceProfile::nameCallback,
  757. _1, _2, _3, self));
  758. }
  759. }
  760. self->mGroupText->setText(value);
  761. self->mEditGroupText->setText(value);
  762. self->mPackage[LLExperienceCache::GROUP_ID] = group_id;
  763. onFieldChanged(NULL, data);
  764. }
  765. }
  766. //static
  767. void LLFloaterExperienceProfile::onClickEdit(void* data)
  768. {
  769. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  770. if (self)
  771. {
  772. LLTabContainer* tabs = self->getChild<LLTabContainer>("tab_container");
  773. tabs->selectTabByName("edit_panel_experience_info");
  774. }
  775. }
  776. //static
  777. void LLFloaterExperienceProfile::onClickCancel(void* data)
  778. {
  779. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  780. if (self)
  781. {
  782. self->changeToView();
  783. }
  784. }
  785. //static
  786. void LLFloaterExperienceProfile::onClickSave(void* data)
  787. {
  788. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  789. if (self)
  790. {
  791. self->doSave(NOTHING);
  792. }
  793. }
  794. //static
  795. void LLFloaterExperienceProfile::onClickAllow(void* data)
  796. {
  797. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  798. if (self)
  799. {
  800. self->setPermission("Allow");
  801. }
  802. }
  803. //static
  804. void LLFloaterExperienceProfile::onClickBlock(void* data)
  805. {
  806. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  807. if (self)
  808. {
  809. self->setPermission("Block");
  810. }
  811. }
  812. //static
  813. void LLFloaterExperienceProfile::onClickForget(void* data)
  814. {
  815. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  816. if (self && gAgent.hasRegionCapability("ExperiencePreferences"))
  817. {
  818. LLExperienceCache* exp = LLExperienceCache::getInstance();
  819. exp->forgetExperiencePermission(self->mExperienceId,
  820. boost::bind(&LLFloaterExperienceProfile::experiencePermissionResults,
  821. self->mExperienceId, _1));
  822. }
  823. }
  824. //static
  825. void LLFloaterExperienceProfile::onLineKeystroke(LLLineEditor*, void* data)
  826. {
  827. onFieldChanged(NULL, data);
  828. }
  829. //static
  830. void LLFloaterExperienceProfile::onTextKeystroke(LLTextEditor*, void* data)
  831. {
  832. onFieldChanged(NULL, data);
  833. }
  834. //static
  835. void LLFloaterExperienceProfile::onFieldChanged(LLUICtrl*, void* data)
  836. {
  837. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  838. if (self)
  839. {
  840. self->updatePackage();
  841. if (!self->mEditBtn->getVisible())
  842. {
  843. return;
  844. }
  845. LLSD::map_const_iterator st = self->mExperienceDetails.beginMap();
  846. LLSD::map_const_iterator dt = self->mPackage.beginMap();
  847. self->mDirty = false;
  848. while (!self->mDirty && st != self->mExperienceDetails.endMap() &&
  849. dt != self->mPackage.endMap())
  850. {
  851. self->mDirty = st->first != dt->first ||
  852. st->second.asString() != dt->second.asString();
  853. ++st;
  854. ++dt;
  855. }
  856. if (!self->mDirty &&
  857. (st != self->mExperienceDetails.endMap() ||
  858. dt != self->mPackage.endMap()))
  859. {
  860. self->mDirty = true;
  861. }
  862. self->mSaveBtn->setEnabled(self->mDirty);
  863. }
  864. }
  865. //static
  866. void LLFloaterExperienceProfile::onClickLocation(void* data)
  867. {
  868. //MK
  869. if (gRLenabled && gRLInterface.mContainsShowloc)
  870. {
  871. return;
  872. }
  873. //mk
  874. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  875. if (self)
  876. {
  877. LLViewerRegion* region = gAgent.getRegion();
  878. if (region)
  879. {
  880. LLSLURL loc_slurl(region->getName(), gAgent.getPositionGlobal());
  881. self->mLocationSLURL = loc_slurl.getSLURLString();
  882. self->mEditLocationText->setText(loc_slurl.getLocationString());
  883. onFieldChanged(NULL, self);
  884. }
  885. }
  886. }
  887. //static
  888. void LLFloaterExperienceProfile::onClickClear(void* data)
  889. {
  890. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  891. if (self)
  892. {
  893. self->mEditLocationText->setText("");
  894. self->mLocationSLURL.clear();
  895. onFieldChanged(NULL, self);
  896. }
  897. }
  898. //static
  899. void LLFloaterExperienceProfile::onPickGroup(void* data)
  900. {
  901. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  902. if (self && gFloaterViewp)
  903. {
  904. LLFloaterGroupPicker* widget= LLFloaterGroupPicker::show(setEditGroup,
  905. self);
  906. LLFloater* parentp = gFloaterViewp->getParentFloater(self);
  907. if (widget && parentp)
  908. {
  909. LLRect new_rect = gFloaterViewp->findNeighboringPosition(parentp,
  910. widget);
  911. widget->setOrigin(new_rect.mLeft, new_rect.mBottom);
  912. parentp->addDependentFloater(widget);
  913. }
  914. }
  915. }
  916. //static
  917. void LLFloaterExperienceProfile::onClickExperienceTitle(void* data)
  918. {
  919. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  920. if (self && !self->mExperienceSLURL.empty())
  921. {
  922. gWindowp->copyTextToClipboard(utf8str_to_wstring(self->mExperienceSLURL));
  923. gNotifications.add("SLURLCopiedtoClipboard");
  924. }
  925. }
  926. //static
  927. void LLFloaterExperienceProfile::onOwnerProfile(void* data)
  928. {
  929. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  930. if (self && self->mOwnerId.notNull())
  931. {
  932. LLFloaterAvatarInfo::show(self->mOwnerId);
  933. }
  934. }
  935. //static
  936. void LLFloaterExperienceProfile::onShowGroupInfo(void* data)
  937. {
  938. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  939. if (self && self->mGroupId.notNull())
  940. {
  941. LLFloaterGroupInfo::showFromUUID(self->mGroupId);
  942. }
  943. }
  944. //static
  945. void LLFloaterExperienceProfile::onShowLocation(void* data)
  946. {
  947. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  948. if (self && !self->mLocationSLURL.empty())
  949. {
  950. LLMediaCtrl* web = NULL;
  951. LLURLDispatcher::dispatch(self->mLocationSLURL, "clicked", web, true);
  952. }
  953. }
  954. //static
  955. void LLFloaterExperienceProfile::onOpenMarketplaceURL(void* data)
  956. {
  957. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  958. if (self && !self->mMarketplaceURL.empty())
  959. {
  960. LLWeb::loadURL(self->mMarketplaceURL);
  961. }
  962. }
  963. //static
  964. void LLFloaterExperienceProfile::onReportExperience(void* data)
  965. {
  966. LLFloaterExperienceProfile* self = (LLFloaterExperienceProfile*)data;
  967. if (self)
  968. {
  969. LLFloaterReporter::showFromExperience(self->mExperienceId);
  970. }
  971. }
  972. //static
  973. bool LLFloaterExperienceProfile::hasPermission(const LLSD& content,
  974. const std::string& name,
  975. const LLUUID& test)
  976. {
  977. if (!content.has(name)) return false;
  978. const LLSD& list = content[name];
  979. for (LLSD::array_const_iterator it = list.beginArray(),
  980. end = list.endArray();
  981. it != end; ++it)
  982. {
  983. if (it->asUUID() == test)
  984. {
  985. return true;
  986. }
  987. }
  988. return false;
  989. }
  990. //static
  991. void LLFloaterExperienceProfile::experiencePermissionResults(LLUUID exp_id,
  992. LLSD result)
  993. {
  994. std::string permission;
  995. if (hasPermission(result, "experiences", exp_id))
  996. {
  997. permission = "Allow";
  998. }
  999. else if (hasPermission(result, "blocked", exp_id))
  1000. {
  1001. permission = "Block";
  1002. }
  1003. else
  1004. {
  1005. permission = "Forget";
  1006. }
  1007. LLSD experience;
  1008. experience["permission"] = permission;
  1009. LLSD message;
  1010. message["experience"] = exp_id;
  1011. message[exp_id.asString()] = experience;
  1012. gEventPumps.obtain(PUMP_EXPERIENCE).post(message);
  1013. }
  1014. //static
  1015. void LLFloaterExperienceProfile::experienceIsAdmin(LLHandle<LLFloaterExperienceProfile> handle,
  1016. const LLSD& result)
  1017. {
  1018. LLFloaterExperienceProfile* self = handle.get();
  1019. if (self && result["status"].asBoolean() &&
  1020. gAgent.hasRegionCapability("UpdateExperience"))
  1021. {
  1022. self->mEditBtn->setVisible(true);
  1023. }
  1024. }
  1025. //static
  1026. void LLFloaterExperienceProfile::experienceUpdateResult(LLHandle<LLFloaterExperienceProfile> handle,
  1027. const LLSD& result)
  1028. {
  1029. LLFloaterExperienceProfile* self = handle.get();
  1030. if (self)
  1031. {
  1032. self->onSaveComplete(result);
  1033. }
  1034. }