llpanelexperiencelisteditor.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /**
  2. * @file llpanelexperiencelisteditor.cpp
  3. * @brief Editor for building a list of experiences
  4. *
  5. * $LicenseInfo:firstyear=2014&license=viewergpl$
  6. *
  7. * Copyright (c) 2014, 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 "llpanelexperiencelisteditor.h"
  34. #include "llbutton.h"
  35. #include "llexperiencecache.h"
  36. #include "llscrolllistctrl.h"
  37. #include "lltextbox.h"
  38. #include "lltrans.h"
  39. #include "lluictrlfactory.h"
  40. #include "llagent.h"
  41. #include "llfloaterexperiencepicker.h"
  42. #include "llfloaterexperienceprofile.h"
  43. #include "llviewerregion.h"
  44. LLPanelExperienceListEditor::LLPanelExperienceListEditor()
  45. : mItems(NULL),
  46. mProfile(NULL),
  47. mRemove(NULL),
  48. mReadonly(false),
  49. mDisabled(false),
  50. mListEmpty(true),
  51. mMaxExperienceIDs(0)
  52. {
  53. LLUICtrlFactory::getInstance()->buildPanel(this,
  54. "panel_experience_list_editor.xml");
  55. }
  56. //virtual
  57. LLPanelExperienceListEditor::~LLPanelExperienceListEditor()
  58. {
  59. if (!mPicker.isDead())
  60. {
  61. mPicker.get()->close();
  62. }
  63. }
  64. //virtual
  65. bool LLPanelExperienceListEditor::postBuild()
  66. {
  67. mItemsCount = getChild<LLTextBox>("text_count");
  68. mItems = getChild<LLScrollListCtrl>("experience_list");
  69. mItems->setCommitCallback(checkButtonsEnabled);
  70. mItems->setDoubleClickCallback(onProfile);
  71. mItems->setCallbackUserData(this);
  72. mAdd = getChild<LLButton>("btn_add");
  73. mAdd->setClickedCallback(onAdd, this);
  74. mRemove = getChild<LLButton>("btn_remove");
  75. mRemove->setClickedCallback(onRemove, this);
  76. mProfile = getChild<LLButton>("btn_profile");
  77. mProfile->setClickedCallback(onProfile, this);
  78. checkButtonsEnabled(NULL, this);
  79. return LLPanel::postBuild();
  80. }
  81. void LLPanelExperienceListEditor::addExperience(const LLUUID& id)
  82. {
  83. mExperienceIds.emplace(id);
  84. onItems(mItems, this);
  85. }
  86. void LLPanelExperienceListEditor::addExperienceIds(const uuid_vec_t& ids)
  87. {
  88. #if 0 // Now handled by the callback
  89. mExperienceIds.insert(ids.begin(), ids.end());
  90. onItems(mItems, this);
  91. #endif
  92. if (!mAddedCallback.empty())
  93. {
  94. for (S32 i = 0, count = ids.size(); i < count; ++i)
  95. {
  96. mAddedCallback(ids[i]);
  97. }
  98. }
  99. }
  100. void LLPanelExperienceListEditor::setExperienceIds(const LLSD& experience_ids)
  101. {
  102. mExperienceIds.clear();
  103. for (LLSD::array_const_iterator it = experience_ids.beginArray(),
  104. end = experience_ids.endArray();
  105. it != end; ++it)
  106. {
  107. mExperienceIds.emplace(it->asUUID());
  108. }
  109. onItems(mItems, this);
  110. }
  111. //static
  112. void LLPanelExperienceListEditor::checkButtonsEnabled(LLUICtrl*, void* data)
  113. {
  114. LLPanelExperienceListEditor* self = (LLPanelExperienceListEditor*)data;
  115. if (!self)
  116. {
  117. return;
  118. }
  119. if (self->mDisabled)
  120. {
  121. self->mItems->setEnabled(false);
  122. self->mAdd->setEnabled(false);
  123. self->mRemove->setEnabled(false);
  124. self->mProfile->setEnabled(false);
  125. return;
  126. }
  127. S32 selected = self->mItems->getNumSelected();
  128. bool can_modify = !self->mReadonly;
  129. bool remove_enabled = can_modify && selected > 0;
  130. if (remove_enabled && self->mSticky)
  131. {
  132. std::vector<LLScrollListItem*> items = self->mItems->getAllSelected();
  133. for (std::vector<LLScrollListItem*>::iterator it = items.begin(),
  134. end = items.end();
  135. it != end; ++it)
  136. {
  137. LLScrollListItem* item = *it;
  138. if (item && self->mSticky(item->getValue()))
  139. {
  140. remove_enabled = false;
  141. break;
  142. }
  143. }
  144. }
  145. self->mAdd->setEnabled(can_modify);
  146. self->mRemove->setEnabled(remove_enabled);
  147. self->mProfile->setEnabled(selected == 1);
  148. }
  149. void LLPanelExperienceListEditor::onExperienceDetails(const LLSD& experience)
  150. {
  151. if (mListEmpty)
  152. {
  153. // Remove the dummy, comment entry
  154. mItems->deleteAllItems();
  155. mListEmpty = false;
  156. }
  157. const LLUUID& id = experience[LLExperienceCache::EXPERIENCE_ID];
  158. std::string name = experience[LLExperienceCache::NAME];
  159. if (name.empty())
  160. {
  161. name = LLTrans::getString("ExperienceNameUntitled");
  162. }
  163. LLScrollListItem* item = mItems->getItem(id);
  164. if (item)
  165. {
  166. // Update the existing entry
  167. item->getColumn(0)->setValue(name);
  168. }
  169. else
  170. {
  171. // Create a new entry
  172. LLSD entry;
  173. entry["id"] = id;
  174. LLSD& column_name = entry["columns"][0];
  175. column_name["column"] = "experience_name";
  176. column_name["value"] = name;
  177. mItems->addElement(entry);
  178. }
  179. checkButtonsEnabled(NULL, this);
  180. }
  181. void LLPanelExperienceListEditor::loading()
  182. {
  183. mItems->deleteAllItems();
  184. mItems->addCommentText(getString("loading"));
  185. mListEmpty = true;
  186. }
  187. void LLPanelExperienceListEditor::setDisabled(bool val)
  188. {
  189. mDisabled = val;
  190. setEnabled(!val);
  191. mItems->setEnabled(!val);
  192. checkButtonsEnabled(NULL, this);
  193. }
  194. void LLPanelExperienceListEditor::setReadonly(bool val)
  195. {
  196. mReadonly = val;
  197. checkButtonsEnabled(NULL, this);
  198. }
  199. void LLPanelExperienceListEditor::refreshExperienceCounter()
  200. {
  201. if (mMaxExperienceIDs > 0)
  202. {
  203. LLStringUtil::format_map_t args;
  204. args["[EXPERIENCES]"] = llformat("%d",
  205. mListEmpty ? 0
  206. : mItems->getItemCount());
  207. args["[MAXEXPERIENCES]"] = llformat("%d", mMaxExperienceIDs);
  208. mItemsCount->setText(LLTrans::getString("ExperiencesCounter", args));
  209. }
  210. }
  211. boost::signals2::connection LLPanelExperienceListEditor::setAddedCallback(list_changed_signal_t::slot_type cb)
  212. {
  213. return mAddedCallback.connect(cb);
  214. }
  215. boost::signals2::connection LLPanelExperienceListEditor::setRemovedCallback(list_changed_signal_t::slot_type cb)
  216. {
  217. return mRemovedCallback.connect(cb);
  218. }
  219. //static
  220. void LLPanelExperienceListEditor::onAdd(void* data)
  221. {
  222. LLPanelExperienceListEditor* self = (LLPanelExperienceListEditor*)data;
  223. if (!self || self->mReadonly)
  224. {
  225. return;
  226. }
  227. if (!self->mPicker.isDead())
  228. {
  229. self->mPicker.markDead();
  230. }
  231. self->mKey.generateNewID();
  232. LLFloaterExperiencePicker* picker =
  233. LLFloaterExperiencePicker::show(boost::bind(&LLPanelExperienceListEditor::addExperienceIds,
  234. self, _1),
  235. self->mKey, false, true,
  236. self->mFilters);
  237. self->mPicker = picker->getDerivedHandle<LLFloaterExperiencePicker>();
  238. LLFloater* parent = self->getParentFloater();
  239. if (parent)
  240. {
  241. parent->addDependentFloater(picker);
  242. }
  243. }
  244. //static
  245. void LLPanelExperienceListEditor::onRemove(void* data)
  246. {
  247. LLPanelExperienceListEditor* self = (LLPanelExperienceListEditor*)data;
  248. if (!self || self->mReadonly)
  249. {
  250. return;
  251. }
  252. std::vector<LLScrollListItem*> items = self->mItems->getAllSelected();
  253. for (std::vector<LLScrollListItem*>::iterator it = items.begin(),
  254. end = items.end();
  255. it != end; ++it)
  256. {
  257. LLScrollListItem* item = *it;
  258. if (item)
  259. {
  260. #if 0 // Now handled by the callback
  261. self->mExperienceIds.erase(item->getValue());
  262. #endif
  263. self->mRemovedCallback(item->getValue());
  264. }
  265. }
  266. self->mItems->selectFirstItem();
  267. checkButtonsEnabled(NULL, self);
  268. #if 0 // Now handled by the callback
  269. onItems(self->mItems, self);
  270. #endif
  271. }
  272. //static
  273. void LLPanelExperienceListEditor::onProfile(void* data)
  274. {
  275. LLPanelExperienceListEditor* self = (LLPanelExperienceListEditor*)data;
  276. if (self)
  277. {
  278. LLScrollListItem* item = self->mItems->getFirstSelected();
  279. if (item)
  280. {
  281. LLFloaterExperienceProfile::show(item->getUUID());
  282. }
  283. }
  284. }
  285. //static
  286. void LLPanelExperienceListEditor::onItems(LLUICtrl*, void* data)
  287. {
  288. LLPanelExperienceListEditor* self = (LLPanelExperienceListEditor*)data;
  289. if (!self) return;
  290. if (self->mExperienceIds.empty())
  291. {
  292. self->mItems->deleteAllItems();
  293. self->mItems->addCommentText(self->getString("no_results"));
  294. self->mListEmpty = true;
  295. return;
  296. }
  297. if (self->mListEmpty)
  298. {
  299. self->loading();
  300. }
  301. LLExperienceCache* exp = LLExperienceCache::getInstance();
  302. for (uuid_list_t::iterator it = self->mExperienceIds.begin(),
  303. end = self->mExperienceIds.end();
  304. it != end; ++it)
  305. {
  306. const LLUUID& experience = *it;
  307. exp->get(experience,
  308. boost::bind(&LLPanelExperienceListEditor::experienceDetailsCallback,
  309. self->getDerivedHandle<LLPanelExperienceListEditor>(),
  310. _1));
  311. }
  312. }
  313. //static
  314. void LLPanelExperienceListEditor::experienceDetailsCallback(LLHandle<LLPanelExperienceListEditor> panel,
  315. const LLSD& experience)
  316. {
  317. if (!panel.isDead())
  318. {
  319. panel.get()->onExperienceDetails(experience);
  320. }
  321. }