PageRenderTime 36ms CodeModel.GetById 7ms app.highlight 25ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llpanelmarketplaceinboxinventory.h"
 30
 31#include "llfolderview.h"
 32#include "llfoldervieweventlistener.h"
 33#include "llinventorybridge.h"
 34#include "llinventoryfunctions.h"
 35#include "llpanellandmarks.h"
 36#include "llplacesinventorybridge.h"
 37#include "llviewerfoldertype.h"
 38
 39
 40#define DEBUGGING_FRESHNESS	0
 41
 42//
 43// statics
 44//
 45
 46static LLDefaultChildRegistry::Register<LLInboxInventoryPanel> r1("inbox_inventory_panel");
 47static LLDefaultChildRegistry::Register<LLInboxFolderViewFolder> r2("inbox_folder_view_folder");
 48static LLDefaultChildRegistry::Register<LLInboxFolderViewItem> r3("inbox_folder_view_item");
 49
 50
 51//
 52// LLInboxInventoryPanel Implementation
 53//
 54
 55LLInboxInventoryPanel::LLInboxInventoryPanel(const LLInboxInventoryPanel::Params& p)
 56	: LLInventoryPanel(p)
 57{
 58}
 59
 60LLInboxInventoryPanel::~LLInboxInventoryPanel()
 61{
 62}
 63
 64// virtual
 65void LLInboxInventoryPanel::buildFolderView(const LLInventoryPanel::Params& params)
 66{
 67	// Determine the root folder in case specified, and
 68	// build the views starting with that folder.
 69	
 70	LLUUID root_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_INBOX, false, false);
 71	
 72	// leslie -- temporary HACK to work around sim not creating inbox with proper system folder type
 73	if (root_id.isNull())
 74	{
 75		std::string start_folder_name(params.start_folder());
 76		
 77		LLInventoryModel::cat_array_t* cats;
 78		LLInventoryModel::item_array_t* items;
 79		
 80		gInventory.getDirectDescendentsOf(gInventory.getRootFolderID(), cats, items);
 81		
 82		if (cats)
 83		{
 84			for (LLInventoryModel::cat_array_t::const_iterator cat_it = cats->begin(); cat_it != cats->end(); ++cat_it)
 85			{
 86				LLInventoryCategory* cat = *cat_it;
 87				
 88				if (cat->getName() == start_folder_name)
 89				{
 90					root_id = cat->getUUID();
 91					break;
 92				}
 93			}
 94		}
 95		
 96		if (root_id == LLUUID::null)
 97		{
 98			llwarns << "No category found that matches inbox inventory panel start_folder: " << start_folder_name << llendl;
 99		}
100	}
101	// leslie -- end temporary HACK
102	
103	if (root_id == LLUUID::null)
104	{
105		llwarns << "Inbox inventory panel has no root folder!" << llendl;
106		root_id = LLUUID::generateNewID();
107	}
108	
109	LLInvFVBridge* new_listener = mInvFVBridgeBuilder->createBridge(LLAssetType::AT_CATEGORY,
110																	LLAssetType::AT_CATEGORY,
111																	LLInventoryType::IT_CATEGORY,
112																	this,
113																	NULL,
114																	root_id);
115	
116	mFolderRoot = createFolderView(new_listener, params.use_label_suffix());
117}
118
119LLFolderViewFolder * LLInboxInventoryPanel::createFolderViewFolder(LLInvFVBridge * bridge)
120{
121	LLInboxFolderViewFolder::Params params;
122	
123	params.name = bridge->getDisplayName();
124	params.icon = bridge->getIcon();
125	params.icon_open = bridge->getOpenIcon();
126	
127	if (mShowItemLinkOverlays) // if false, then links show up just like normal items
128	{
129		params.icon_overlay = LLUI::getUIImage("Inv_Link");
130	}
131	
132	params.root = mFolderRoot;
133	params.listener = bridge;
134	params.tool_tip = params.name;
135	
136	return LLUICtrlFactory::create<LLInboxFolderViewFolder>(params);
137}
138
139LLFolderViewItem * LLInboxInventoryPanel::createFolderViewItem(LLInvFVBridge * bridge)
140{
141	LLInboxFolderViewItem::Params params;
142
143	params.name = bridge->getDisplayName();
144	params.icon = bridge->getIcon();
145	params.icon_open = bridge->getOpenIcon();
146
147	if (mShowItemLinkOverlays) // if false, then links show up just like normal items
148	{
149		params.icon_overlay = LLUI::getUIImage("Inv_Link");
150	}
151
152	params.creation_date = bridge->getCreationDate();
153	params.root = mFolderRoot;
154	params.listener = bridge;
155	params.rect = LLRect (0, 0, 0, 0);
156	params.tool_tip = params.name;
157
158	return LLUICtrlFactory::create<LLInboxFolderViewItem>(params);
159}
160
161//
162// LLInboxFolderViewFolder Implementation
163//
164
165LLInboxFolderViewFolder::LLInboxFolderViewFolder(const Params& p)
166	: LLFolderViewFolder(p)
167	, LLBadgeOwner(getHandle())
168	, mFresh(false)
169{
170#if SUPPORTING_FRESH_ITEM_COUNT
171	initBadgeParams(p.new_badge());
172#endif
173}
174
175// virtual
176void LLInboxFolderViewFolder::draw()
177{
178#if SUPPORTING_FRESH_ITEM_COUNT
179	if (!badgeHasParent())
180	{
181		addBadgeToParentPanel();
182	}
183	
184	setBadgeVisibility(mFresh);
185#endif
186
187	LLFolderViewFolder::draw();
188}
189
190void LLInboxFolderViewFolder::selectItem()
191{
192	deFreshify();
193
194	LLFolderViewFolder::selectItem();
195}
196
197void LLInboxFolderViewFolder::toggleOpen()
198{
199	deFreshify();
200
201	LLFolderViewFolder::toggleOpen();
202}
203
204void LLInboxFolderViewFolder::computeFreshness()
205{
206	const U32 last_expansion_utc = gSavedPerAccountSettings.getU32("LastInventoryInboxActivity");
207
208	if (last_expansion_utc > 0)
209	{
210		mFresh = (mCreationDate > last_expansion_utc);
211
212#if DEBUGGING_FRESHNESS
213		if (mFresh)
214		{
215			llinfos << "Item is fresh! -- creation " << mCreationDate << ", saved_freshness_date " << last_expansion_utc << llendl;
216		}
217#endif
218	}
219	else
220	{
221		mFresh = true;
222	}
223}
224
225void LLInboxFolderViewFolder::deFreshify()
226{
227	mFresh = false;
228
229	gSavedPerAccountSettings.setU32("LastInventoryInboxActivity", time_corrected());
230}
231
232void LLInboxFolderViewFolder::setCreationDate(time_t creation_date_utc)
233{ 
234	mCreationDate = creation_date_utc; 
235
236	if (mParentFolder == mRoot)
237	{
238		computeFreshness();
239	}
240}
241
242//
243// LLInboxFolderViewItem Implementation
244//
245
246LLInboxFolderViewItem::LLInboxFolderViewItem(const Params& p)
247	: LLFolderViewItem(p)
248	, LLBadgeOwner(getHandle())
249	, mFresh(false)
250{
251#if SUPPORTING_FRESH_ITEM_COUNT
252	initBadgeParams(p.new_badge());
253#endif
254}
255
256BOOL LLInboxFolderViewItem::addToFolder(LLFolderViewFolder* folder, LLFolderView* root)
257{
258	BOOL retval = LLFolderViewItem::addToFolder(folder, root);
259
260#if SUPPORTING_FRESH_ITEM_COUNT
261	// Compute freshness if our parent is the root folder for the inbox
262	if (mParentFolder == mRoot)
263	{
264		computeFreshness();
265	}
266#endif
267	
268	return retval;
269}
270
271BOOL LLInboxFolderViewItem::handleDoubleClick(S32 x, S32 y, MASK mask)
272{
273	deFreshify();
274	
275	return LLFolderViewItem::handleDoubleClick(x, y, mask);
276}
277
278// virtual
279void LLInboxFolderViewItem::draw()
280{
281#if SUPPORTING_FRESH_ITEM_COUNT
282	if (!badgeHasParent())
283	{
284		addBadgeToParentPanel();
285	}
286
287	setBadgeVisibility(mFresh);
288#endif
289
290	LLFolderViewItem::draw();
291}
292
293void LLInboxFolderViewItem::selectItem()
294{
295	deFreshify();
296
297	LLFolderViewItem::selectItem();
298}
299
300void LLInboxFolderViewItem::computeFreshness()
301{
302	const U32 last_expansion_utc = gSavedPerAccountSettings.getU32("LastInventoryInboxActivity");
303
304	if (last_expansion_utc > 0)
305	{
306		mFresh = (mCreationDate > last_expansion_utc);
307
308#if DEBUGGING_FRESHNESS
309		if (mFresh)
310		{
311			llinfos << "Item is fresh! -- creation " << mCreationDate << ", saved_freshness_date " << last_expansion_utc << llendl;
312		}
313#endif
314	}
315	else
316	{
317		mFresh = true;
318	}
319}
320
321void LLInboxFolderViewItem::deFreshify()
322{
323	mFresh = false;
324
325	gSavedPerAccountSettings.setU32("LastInventoryInboxActivity", time_corrected());
326}
327
328
329// eof