PageRenderTime 39ms CodeModel.GetById 16ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 0ms

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