/indra/newview/llpanelmarketplaceinbox.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 255 lines · 163 code · 54 blank · 38 comment · 20 complexity · e0f35cd409975c8da25562f0714ac2fe MD5 · raw file

  1. /**
  2. * @file llpanelmarketplaceinbox.cpp
  3. * @brief Panel for marketplace inbox
  4. *
  5. * $LicenseInfo:firstyear=2011&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 "llpanelmarketplaceinbox.h"
  28. #include "llpanelmarketplaceinboxinventory.h"
  29. #include "llappviewer.h"
  30. #include "llbutton.h"
  31. #include "llinventorypanel.h"
  32. #include "llfloatersidepanelcontainer.h"
  33. #include "llfolderview.h"
  34. #include "llsidepanelinventory.h"
  35. #include "llviewercontrol.h"
  36. static LLRegisterPanelClassWrapper<LLPanelMarketplaceInbox> t_panel_marketplace_inbox("panel_marketplace_inbox");
  37. const LLPanelMarketplaceInbox::Params& LLPanelMarketplaceInbox::getDefaultParams()
  38. {
  39. return LLUICtrlFactory::getDefaultParams<LLPanelMarketplaceInbox>();
  40. }
  41. // protected
  42. LLPanelMarketplaceInbox::LLPanelMarketplaceInbox(const Params& p)
  43. : LLPanel(p)
  44. , mFreshCountCtrl(NULL)
  45. , mInboxButton(NULL)
  46. , mInventoryPanel(NULL)
  47. {
  48. }
  49. LLPanelMarketplaceInbox::~LLPanelMarketplaceInbox()
  50. {
  51. }
  52. // virtual
  53. BOOL LLPanelMarketplaceInbox::postBuild()
  54. {
  55. LLFocusableElement::setFocusReceivedCallback(boost::bind(&LLPanelMarketplaceInbox::onFocusReceived, this));
  56. mFreshCountCtrl = getChild<LLUICtrl>("inbox_fresh_new_count");
  57. mInboxButton = getChild<LLButton>("inbox_btn");
  58. return TRUE;
  59. }
  60. void LLPanelMarketplaceInbox::onSelectionChange()
  61. {
  62. LLSidepanelInventory* sidepanel_inventory = LLFloaterSidePanelContainer::getPanel<LLSidepanelInventory>("inventory");
  63. sidepanel_inventory->updateVerbs();
  64. }
  65. LLInventoryPanel * LLPanelMarketplaceInbox::setupInventoryPanel()
  66. {
  67. LLView * inbox_inventory_placeholder = getChild<LLView>("inbox_inventory_placeholder");
  68. LLView * inbox_inventory_parent = inbox_inventory_placeholder->getParent();
  69. mInventoryPanel =
  70. LLUICtrlFactory::createFromFile<LLInventoryPanel>("panel_inbox_inventory.xml",
  71. inbox_inventory_parent,
  72. LLInventoryPanel::child_registry_t::instance());
  73. llassert(mInventoryPanel);
  74. // Reshape the inventory to the proper size
  75. LLRect inventory_placeholder_rect = inbox_inventory_placeholder->getRect();
  76. mInventoryPanel->setShape(inventory_placeholder_rect);
  77. // Set the sort order newest to oldest
  78. mInventoryPanel->setSortOrder(LLInventoryFilter::SO_DATE);
  79. mInventoryPanel->getFilter()->markDefault();
  80. // Set selection callback for proper update of inventory status buttons
  81. mInventoryPanel->setSelectCallback(boost::bind(&LLPanelMarketplaceInbox::onSelectionChange, this));
  82. // Set up the note to display when the inbox is empty
  83. mInventoryPanel->getFilter()->setEmptyLookupMessage("InventoryInboxNoItems");
  84. // Hide the placeholder text
  85. inbox_inventory_placeholder->setVisible(FALSE);
  86. return mInventoryPanel;
  87. }
  88. void LLPanelMarketplaceInbox::onFocusReceived()
  89. {
  90. LLSidepanelInventory *sidepanel_inventory = LLFloaterSidePanelContainer::getPanel<LLSidepanelInventory>("inventory");
  91. if (sidepanel_inventory)
  92. {
  93. sidepanel_inventory->clearSelections(true, false);
  94. }
  95. gSavedPerAccountSettings.setU32("LastInventoryInboxActivity", time_corrected());
  96. }
  97. BOOL LLPanelMarketplaceInbox::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop, EDragAndDropType cargo_type, void *cargo_data, EAcceptance *accept, std::string& tooltip_msg)
  98. {
  99. *accept = ACCEPT_NO;
  100. return TRUE;
  101. }
  102. U32 LLPanelMarketplaceInbox::getFreshItemCount() const
  103. {
  104. #if SUPPORTING_FRESH_ITEM_COUNT
  105. //
  106. // NOTE: When turning this on, be sure to test the no inbox/outbox case because this code probably
  107. // will return "2" for the Inventory and LIBRARY top-levels when that happens.
  108. //
  109. U32 fresh_item_count = 0;
  110. if (mInventoryPanel)
  111. {
  112. const LLFolderViewFolder * inbox_folder = mInventoryPanel->getRootFolder();
  113. if (inbox_folder)
  114. {
  115. LLFolderViewFolder::folders_t::const_iterator folders_it = inbox_folder->getFoldersBegin();
  116. LLFolderViewFolder::folders_t::const_iterator folders_end = inbox_folder->getFoldersEnd();
  117. for (; folders_it != folders_end; ++folders_it)
  118. {
  119. const LLFolderViewFolder * folder_view = *folders_it;
  120. const LLInboxFolderViewFolder * inbox_folder_view = dynamic_cast<const LLInboxFolderViewFolder*>(folder_view);
  121. if (inbox_folder_view && inbox_folder_view->isFresh())
  122. {
  123. fresh_item_count++;
  124. }
  125. }
  126. LLFolderViewFolder::items_t::const_iterator items_it = inbox_folder->getItemsBegin();
  127. LLFolderViewFolder::items_t::const_iterator items_end = inbox_folder->getItemsEnd();
  128. for (; items_it != items_end; ++items_it)
  129. {
  130. const LLFolderViewItem * item_view = *items_it;
  131. const LLInboxFolderViewItem * inbox_item_view = dynamic_cast<const LLInboxFolderViewItem*>(item_view);
  132. if (inbox_item_view && inbox_item_view->isFresh())
  133. {
  134. fresh_item_count++;
  135. }
  136. }
  137. }
  138. }
  139. return fresh_item_count;
  140. #else
  141. return getTotalItemCount();
  142. #endif
  143. }
  144. U32 LLPanelMarketplaceInbox::getTotalItemCount() const
  145. {
  146. U32 item_count = 0;
  147. if (mInventoryPanel)
  148. {
  149. const LLFolderViewFolder * inbox_folder = mInventoryPanel->getRootFolder();
  150. if (inbox_folder)
  151. {
  152. item_count += inbox_folder->getFoldersCount();
  153. item_count += inbox_folder->getItemsCount();
  154. }
  155. }
  156. return item_count;
  157. }
  158. std::string LLPanelMarketplaceInbox::getBadgeString() const
  159. {
  160. std::string item_count_str("");
  161. LLPanel *inventory_panel = LLFloaterSidePanelContainer::getPanel("inventory");
  162. // If the inbox is visible, and the side panel is collapsed or expanded and not the inventory panel
  163. if (getParent()->getVisible() && inventory_panel && !inventory_panel->isInVisibleChain())
  164. {
  165. U32 item_count = getFreshItemCount();
  166. if (item_count)
  167. {
  168. item_count_str = llformat("%d", item_count);
  169. }
  170. }
  171. return item_count_str;
  172. }
  173. void LLPanelMarketplaceInbox::draw()
  174. {
  175. U32 item_count = getTotalItemCount();
  176. llassert(mFreshCountCtrl != NULL);
  177. if (item_count > 0)
  178. {
  179. std::string item_count_str = llformat("%d", item_count);
  180. LLStringUtil::format_map_t args;
  181. args["[NUM]"] = item_count_str;
  182. mInboxButton->setLabel(getString("InboxLabelWithArg", args));
  183. #if SUPPORTING_FRESH_ITEM_COUNT
  184. // set green text to fresh item count
  185. U32 fresh_item_count = getFreshItemCount();
  186. mFreshCountCtrl->setVisible((fresh_item_count > 0));
  187. if (fresh_item_count > 0)
  188. {
  189. mFreshCountCtrl->setTextArg("[NUM]", llformat("%d", fresh_item_count));
  190. }
  191. #else
  192. mFreshCountCtrl->setVisible(FALSE);
  193. #endif
  194. }
  195. else
  196. {
  197. mInboxButton->setLabel(getString("InboxLabelNoArg"));
  198. mFreshCountCtrl->setVisible(FALSE);
  199. }
  200. LLPanel::draw();
  201. }