PageRenderTime 15ms CodeModel.GetById 2ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/lldelayedgestureerror.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 121 lines | 72 code | 17 blank | 32 comment | 8 complexity | 20b362da7460c5c7fc4146a38ee9dca6 MD5 | raw file
  1/** 
  2 * @file lldelayedgestureerror.cpp
  3 * @brief Delayed gesture error message -- try to wait until name has been retrieved
  4 * @author Dale Glass
  5 *
  6 * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#include "llviewerprecompiledheaders.h"
 29#include "lldelayedgestureerror.h"
 30
 31#include <list>
 32#include "llnotificationsutil.h"
 33#include "llcallbacklist.h"
 34#include "llinventory.h"
 35#include "llviewerinventory.h"
 36#include "llinventorymodel.h"
 37
 38const F32 MAX_NAME_WAIT_TIME = 5.0f;
 39
 40LLDelayedGestureError::ErrorQueue LLDelayedGestureError::sQueue;
 41
 42//static
 43void LLDelayedGestureError::gestureMissing(const LLUUID &id)
 44{
 45	LLErrorEntry ent("GestureMissing", id);
 46	if ( ! doDialog(ent) )
 47	{
 48		enqueue(ent);
 49	}
 50}
 51
 52//static
 53void LLDelayedGestureError::gestureFailedToLoad(const LLUUID &id)
 54{
 55	LLErrorEntry ent("UnableToLoadGesture", id);
 56
 57	if ( ! doDialog(ent) )
 58	{
 59		enqueue(ent);
 60	}
 61}
 62
 63//static
 64void LLDelayedGestureError::enqueue(const LLErrorEntry &ent)
 65{
 66	if ( sQueue.empty() )
 67	{
 68		gIdleCallbacks.addFunction(onIdle, NULL);
 69	}
 70
 71	sQueue.push_back(ent);
 72}
 73
 74//static 
 75void LLDelayedGestureError::onIdle(void *userdata)
 76{
 77	if ( ! sQueue.empty() )
 78	{
 79		LLErrorEntry ent = sQueue.front();
 80		sQueue.pop_front();
 81
 82		if ( ! doDialog(ent, false ) )
 83		{
 84			enqueue(ent);
 85		}
 86	}
 87	else
 88	{
 89		// Nothing to do anymore
 90		gIdleCallbacks.deleteFunction(onIdle, NULL);
 91	}
 92}
 93
 94//static 
 95bool LLDelayedGestureError::doDialog(const LLErrorEntry &ent, bool uuid_ok)
 96{
 97	LLSD args;
 98	LLInventoryItem *item = gInventory.getItem( ent.mItemID );
 99
100	if ( item )
101	{
102		args["NAME"] = item->getName();
103	}
104	else
105	{
106		if ( uuid_ok || ent.mTimer.getElapsedTimeF32() > MAX_NAME_WAIT_TIME )
107		{
108			args["NAME"] = ent.mItemID.asString();
109		}
110		else
111		{
112			return false;
113		}
114	}
115	 
116
117	LLNotificationsUtil::add(ent.mNotifyName, args);
118
119	return true;
120}
121