/indra/newview/llpanelmarketplaceinboxinventory.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 329 lines · 216 code · 67 blank · 46 comment · 22 complexity · f768d0f86a25909b722d490b6ac09002 MD5 · raw file

  1. /**
  2. * @file llpanelmarketplaceinboxinventory.cpp
  3. * @brief LLInboxInventoryPanel class definition
  4. *
  5. * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llpanelmarketplaceinboxinventory.h"
  28. #include "llfolderview.h"
  29. #include "llfoldervieweventlistener.h"
  30. #include "llinventorybridge.h"
  31. #include "llinventoryfunctions.h"
  32. #include "llpanellandmarks.h"
  33. #include "llplacesinventorybridge.h"
  34. #include "llviewerfoldertype.h"
  35. #define DEBUGGING_FRESHNESS 0
  36. //
  37. // statics
  38. //
  39. static LLDefaultChildRegistry::Register<LLInboxInventoryPanel> r1("inbox_inventory_panel");
  40. static LLDefaultChildRegistry::Register<LLInboxFolderViewFolder> r2("inbox_folder_view_folder");
  41. static LLDefaultChildRegistry::Register<LLInboxFolderViewItem> r3("inbox_folder_view_item");
  42. //
  43. // LLInboxInventoryPanel Implementation
  44. //
  45. LLInboxInventoryPanel::LLInboxInventoryPanel(const LLInboxInventoryPanel::Params& p)
  46. : LLInventoryPanel(p)
  47. {
  48. }
  49. LLInboxInventoryPanel::~LLInboxInventoryPanel()
  50. {
  51. }
  52. // virtual
  53. void LLInboxInventoryPanel::buildFolderView(const LLInventoryPanel::Params& params)
  54. {
  55. // Determine the root folder in case specified, and
  56. // build the views starting with that folder.
  57. LLUUID root_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_INBOX, false, false);
  58. // leslie -- temporary HACK to work around sim not creating inbox with proper system folder type
  59. if (root_id.isNull())
  60. {
  61. std::string start_folder_name(params.start_folder());
  62. LLInventoryModel::cat_array_t* cats;
  63. LLInventoryModel::item_array_t* items;
  64. gInventory.getDirectDescendentsOf(gInventory.getRootFolderID(), cats, items);
  65. if (cats)
  66. {
  67. for (LLInventoryModel::cat_array_t::const_iterator cat_it = cats->begin(); cat_it != cats->end(); ++cat_it)
  68. {
  69. LLInventoryCategory* cat = *cat_it;
  70. if (cat->getName() == start_folder_name)
  71. {
  72. root_id = cat->getUUID();
  73. break;
  74. }
  75. }
  76. }
  77. if (root_id == LLUUID::null)
  78. {
  79. llwarns << "No category found that matches inbox inventory panel start_folder: " << start_folder_name << llendl;
  80. }
  81. }
  82. // leslie -- end temporary HACK
  83. if (root_id == LLUUID::null)
  84. {
  85. llwarns << "Inbox inventory panel has no root folder!" << llendl;
  86. root_id = LLUUID::generateNewID();
  87. }
  88. LLInvFVBridge* new_listener = mInvFVBridgeBuilder->createBridge(LLAssetType::AT_CATEGORY,
  89. LLAssetType::AT_CATEGORY,
  90. LLInventoryType::IT_CATEGORY,
  91. this,
  92. NULL,
  93. root_id);
  94. mFolderRoot = createFolderView(new_listener, params.use_label_suffix());
  95. }
  96. LLFolderViewFolder * LLInboxInventoryPanel::createFolderViewFolder(LLInvFVBridge * bridge)
  97. {
  98. LLInboxFolderViewFolder::Params params;
  99. params.name = bridge->getDisplayName();
  100. params.icon = bridge->getIcon();
  101. params.icon_open = bridge->getOpenIcon();
  102. if (mShowItemLinkOverlays) // if false, then links show up just like normal items
  103. {
  104. params.icon_overlay = LLUI::getUIImage("Inv_Link");
  105. }
  106. params.root = mFolderRoot;
  107. params.listener = bridge;
  108. params.tool_tip = params.name;
  109. return LLUICtrlFactory::create<LLInboxFolderViewFolder>(params);
  110. }
  111. LLFolderViewItem * LLInboxInventoryPanel::createFolderViewItem(LLInvFVBridge * bridge)
  112. {
  113. LLInboxFolderViewItem::Params params;
  114. params.name = bridge->getDisplayName();
  115. params.icon = bridge->getIcon();
  116. params.icon_open = bridge->getOpenIcon();
  117. if (mShowItemLinkOverlays) // if false, then links show up just like normal items
  118. {
  119. params.icon_overlay = LLUI::getUIImage("Inv_Link");
  120. }
  121. params.creation_date = bridge->getCreationDate();
  122. params.root = mFolderRoot;
  123. params.listener = bridge;
  124. params.rect = LLRect (0, 0, 0, 0);
  125. params.tool_tip = params.name;
  126. return LLUICtrlFactory::create<LLInboxFolderViewItem>(params);
  127. }
  128. //
  129. // LLInboxFolderViewFolder Implementation
  130. //
  131. LLInboxFolderViewFolder::LLInboxFolderViewFolder(const Params& p)
  132. : LLFolderViewFolder(p)
  133. , LLBadgeOwner(getHandle())
  134. , mFresh(false)
  135. {
  136. #if SUPPORTING_FRESH_ITEM_COUNT
  137. initBadgeParams(p.new_badge());
  138. #endif
  139. }
  140. // virtual
  141. void LLInboxFolderViewFolder::draw()
  142. {
  143. #if SUPPORTING_FRESH_ITEM_COUNT
  144. if (!badgeHasParent())
  145. {
  146. addBadgeToParentPanel();
  147. }
  148. setBadgeVisibility(mFresh);
  149. #endif
  150. LLFolderViewFolder::draw();
  151. }
  152. void LLInboxFolderViewFolder::selectItem()
  153. {
  154. deFreshify();
  155. LLFolderViewFolder::selectItem();
  156. }
  157. void LLInboxFolderViewFolder::toggleOpen()
  158. {
  159. deFreshify();
  160. LLFolderViewFolder::toggleOpen();
  161. }
  162. void LLInboxFolderViewFolder::computeFreshness()
  163. {
  164. const U32 last_expansion_utc = gSavedPerAccountSettings.getU32("LastInventoryInboxActivity");
  165. if (last_expansion_utc > 0)
  166. {
  167. mFresh = (mCreationDate > last_expansion_utc);
  168. #if DEBUGGING_FRESHNESS
  169. if (mFresh)
  170. {
  171. llinfos << "Item is fresh! -- creation " << mCreationDate << ", saved_freshness_date " << last_expansion_utc << llendl;
  172. }
  173. #endif
  174. }
  175. else
  176. {
  177. mFresh = true;
  178. }
  179. }
  180. void LLInboxFolderViewFolder::deFreshify()
  181. {
  182. mFresh = false;
  183. gSavedPerAccountSettings.setU32("LastInventoryInboxActivity", time_corrected());
  184. }
  185. void LLInboxFolderViewFolder::setCreationDate(time_t creation_date_utc)
  186. {
  187. mCreationDate = creation_date_utc;
  188. if (mParentFolder == mRoot)
  189. {
  190. computeFreshness();
  191. }
  192. }
  193. //
  194. // LLInboxFolderViewItem Implementation
  195. //
  196. LLInboxFolderViewItem::LLInboxFolderViewItem(const Params& p)
  197. : LLFolderViewItem(p)
  198. , LLBadgeOwner(getHandle())
  199. , mFresh(false)
  200. {
  201. #if SUPPORTING_FRESH_ITEM_COUNT
  202. initBadgeParams(p.new_badge());
  203. #endif
  204. }
  205. BOOL LLInboxFolderViewItem::addToFolder(LLFolderViewFolder* folder, LLFolderView* root)
  206. {
  207. BOOL retval = LLFolderViewItem::addToFolder(folder, root);
  208. #if SUPPORTING_FRESH_ITEM_COUNT
  209. // Compute freshness if our parent is the root folder for the inbox
  210. if (mParentFolder == mRoot)
  211. {
  212. computeFreshness();
  213. }
  214. #endif
  215. return retval;
  216. }
  217. BOOL LLInboxFolderViewItem::handleDoubleClick(S32 x, S32 y, MASK mask)
  218. {
  219. deFreshify();
  220. return LLFolderViewItem::handleDoubleClick(x, y, mask);
  221. }
  222. // virtual
  223. void LLInboxFolderViewItem::draw()
  224. {
  225. #if SUPPORTING_FRESH_ITEM_COUNT
  226. if (!badgeHasParent())
  227. {
  228. addBadgeToParentPanel();
  229. }
  230. setBadgeVisibility(mFresh);
  231. #endif
  232. LLFolderViewItem::draw();
  233. }
  234. void LLInboxFolderViewItem::selectItem()
  235. {
  236. deFreshify();
  237. LLFolderViewItem::selectItem();
  238. }
  239. void LLInboxFolderViewItem::computeFreshness()
  240. {
  241. const U32 last_expansion_utc = gSavedPerAccountSettings.getU32("LastInventoryInboxActivity");
  242. if (last_expansion_utc > 0)
  243. {
  244. mFresh = (mCreationDate > last_expansion_utc);
  245. #if DEBUGGING_FRESHNESS
  246. if (mFresh)
  247. {
  248. llinfos << "Item is fresh! -- creation " << mCreationDate << ", saved_freshness_date " << last_expansion_utc << llendl;
  249. }
  250. #endif
  251. }
  252. else
  253. {
  254. mFresh = true;
  255. }
  256. }
  257. void LLInboxFolderViewItem::deFreshify()
  258. {
  259. mFresh = false;
  260. gSavedPerAccountSettings.setU32("LastInventoryInboxActivity", time_corrected());
  261. }
  262. // eof