PageRenderTime 44ms CodeModel.GetById 30ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llpanelsnapshotoptions.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 120 lines | 73 code | 18 blank | 29 comment | 1 complexity | a041d8a0d4fb83134dfb10e447b89fe0 MD5 | raw file
  1/** 
  2 * @file llpanelsnapshotoptions.cpp
  3 * @brief Snapshot posting options panel.
  4 *
  5 * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2011, 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 "lleconomy.h"
 30#include "llpanel.h"
 31#include "llsidetraypanelcontainer.h"
 32
 33#include "llfloatersnapshot.h" // FIXME: create a snapshot model
 34
 35/**
 36 * Provides several ways to save a snapshot.
 37 */
 38class LLPanelSnapshotOptions
 39:	public LLPanel
 40,	public LLEconomyObserver
 41{
 42	LOG_CLASS(LLPanelSnapshotOptions);
 43
 44public:
 45	LLPanelSnapshotOptions();
 46	~LLPanelSnapshotOptions();
 47	/*virtual*/ void onOpen(const LLSD& key);
 48	/*virtual*/ void onEconomyDataChange() { updateUploadCost(); }
 49
 50private:
 51	void updateUploadCost();
 52	void openPanel(const std::string& panel_name);
 53	void onSaveToProfile();
 54	void onSaveToEmail();
 55	void onSaveToInventory();
 56	void onSaveToComputer();
 57};
 58
 59static LLRegisterPanelClassWrapper<LLPanelSnapshotOptions> panel_class("llpanelsnapshotoptions");
 60
 61LLPanelSnapshotOptions::LLPanelSnapshotOptions()
 62{
 63	mCommitCallbackRegistrar.add("Snapshot.SaveToProfile",		boost::bind(&LLPanelSnapshotOptions::onSaveToProfile,	this));
 64	mCommitCallbackRegistrar.add("Snapshot.SaveToEmail",		boost::bind(&LLPanelSnapshotOptions::onSaveToEmail,		this));
 65	mCommitCallbackRegistrar.add("Snapshot.SaveToInventory",	boost::bind(&LLPanelSnapshotOptions::onSaveToInventory,	this));
 66	mCommitCallbackRegistrar.add("Snapshot.SaveToComputer",		boost::bind(&LLPanelSnapshotOptions::onSaveToComputer,	this));
 67
 68	LLGlobalEconomy::Singleton::getInstance()->addObserver(this);
 69}
 70
 71LLPanelSnapshotOptions::~LLPanelSnapshotOptions()
 72{
 73	LLGlobalEconomy::Singleton::getInstance()->removeObserver(this);
 74}
 75
 76// virtual
 77void LLPanelSnapshotOptions::onOpen(const LLSD& key)
 78{
 79	updateUploadCost();
 80}
 81
 82void LLPanelSnapshotOptions::updateUploadCost()
 83{
 84	S32 upload_cost = LLGlobalEconomy::Singleton::getInstance()->getPriceUpload();
 85	getChild<LLUICtrl>("save_to_inventory_btn")->setLabelArg("[AMOUNT]", llformat("%d", upload_cost));
 86}
 87
 88void LLPanelSnapshotOptions::openPanel(const std::string& panel_name)
 89{
 90	LLSideTrayPanelContainer* parent = dynamic_cast<LLSideTrayPanelContainer*>(getParent());
 91	if (!parent)
 92	{
 93		llwarns << "Cannot find panel container" << llendl;
 94		return;
 95	}
 96
 97	parent->openPanel(panel_name);
 98	parent->getCurrentPanel()->onOpen(LLSD());
 99	LLFloaterSnapshot::postPanelSwitch();
100}
101
102void LLPanelSnapshotOptions::onSaveToProfile()
103{
104	openPanel("panel_snapshot_profile");
105}
106
107void LLPanelSnapshotOptions::onSaveToEmail()
108{
109	openPanel("panel_snapshot_postcard");
110}
111
112void LLPanelSnapshotOptions::onSaveToInventory()
113{
114	openPanel("panel_snapshot_inventory");
115}
116
117void LLPanelSnapshotOptions::onSaveToComputer()
118{
119	openPanel("panel_snapshot_local");
120}