summaryrefslogtreecommitdiff
path: root/indra/newview/llpreviewnotecard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llpreviewnotecard.cpp')
-rwxr-xr-x[-rw-r--r--]indra/newview/llpreviewnotecard.cpp225
1 files changed, 158 insertions, 67 deletions
diff --git a/indra/newview/llpreviewnotecard.cpp b/indra/newview/llpreviewnotecard.cpp
index ab9cfbf850..1308d1e9a7 100644..100755
--- a/indra/newview/llpreviewnotecard.cpp
+++ b/indra/newview/llpreviewnotecard.cpp
@@ -2,31 +2,25 @@
* @file llpreviewnotecard.cpp
* @brief Implementation of the notecard editor
*
- * $LicenseInfo:firstyear=2002&license=viewergpl$
- *
- * Copyright (c) 2002-2009, Linden Research, Inc.
- *
+ * $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ * Copyright (C) 2010, Linden Research, Inc.
*
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
*
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -38,12 +32,14 @@
#include "llagent.h"
#include "llassetuploadresponders.h"
+#include "lldraghandle.h"
#include "llviewerwindow.h"
#include "llbutton.h"
#include "llfloaterreg.h"
+#include "llinventorydefines.h"
#include "llinventorymodel.h"
#include "lllineeditor.h"
-#include "llnotify.h"
+#include "llnotificationsutil.h"
#include "llresmgr.h"
#include "roles_constants.h"
#include "llscrollbar.h"
@@ -55,7 +51,6 @@
#include "llviewerobjectlist.h"
#include "llviewerregion.h"
#include "lldir.h"
-//#include "llfloaterchat.h"
#include "llviewerstats.h"
#include "llviewercontrol.h" // gSavedSettings
#include "llappviewer.h" // app_abort_quit()
@@ -75,7 +70,6 @@ LLPreviewNotecard::LLPreviewNotecard(const LLSD& key) //const LLUUID& item_id,
{
mAssetID = item->getAssetUUID();
}
- //Called from floater reg: LLUICtrlFactory::getInstance()->buildFloater(this,"floater_preview_notecard.xml", FALSE);
}
LLPreviewNotecard::~LLPreviewNotecard()
@@ -89,14 +83,20 @@ BOOL LLPreviewNotecard::postBuild()
ed->makePristine();
childSetAction("Save", onClickSave, this);
- childSetVisible("lock", FALSE);
+ getChildView("lock")->setVisible( FALSE);
+
+ childSetAction("Delete", onClickDelete, this);
+ getChildView("Delete")->setEnabled(false);
const LLInventoryItem* item = getItem();
childSetCommitCallback("desc", LLPreview::onText, this);
if (item)
- childSetText("desc", item->getDescription());
- childSetPrevalidate("desc", &LLLineEditor::prevalidatePrintableNotPipe);
+ {
+ getChild<LLUICtrl>("desc")->setValue(item->getDescription());
+ getChildView("Delete")->setEnabled(true);
+ }
+ getChild<LLLineEditor>("desc")->setPrevalidate(&LLTextValidate::validateASCIIPrintableNoPipe);
return LLPreview::postBuild();
}
@@ -112,10 +112,10 @@ void LLPreviewNotecard::setEnabled( BOOL enabled )
LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor");
- childSetEnabled("Notecard Editor", enabled);
- childSetVisible("lock", !enabled);
- childSetEnabled("desc", enabled);
- childSetEnabled("Save", enabled && editor && (!editor->isPristine()));
+ getChildView("Notecard Editor")->setEnabled(enabled);
+ getChildView("lock")->setVisible( !enabled);
+ getChildView("desc")->setEnabled(enabled);
+ getChildView("Save")->setEnabled(enabled && editor && (!editor->isPristine()));
}
@@ -124,7 +124,7 @@ void LLPreviewNotecard::draw()
LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor");
BOOL changed = !editor->isPristine();
- childSetEnabled("Save", changed && getEnabled());
+ getChildView("Save")->setEnabled(changed && getEnabled());
LLPreview::draw();
}
@@ -153,7 +153,7 @@ BOOL LLPreviewNotecard::canClose()
else
{
// Bring up view-modal dialog: Save changes? Yes, No, Cancel
- LLNotifications::instance().add("SaveChanges", LLSD(), LLSD(), boost::bind(&LLPreviewNotecard::handleSaveChangesDialog,this, _1, _2));
+ LLNotificationsUtil::add("SaveChanges", LLSD(), LLSD(), boost::bind(&LLPreviewNotecard::handleSaveChangesDialog,this, _1, _2));
return FALSE;
}
@@ -185,10 +185,24 @@ void LLPreviewNotecard::refreshFromInventory(const LLUUID& new_item_id)
mItemUUID = new_item_id;
setKey(LLSD(new_item_id));
}
- lldebugs << "LLPreviewNotecard::refreshFromInventory()" << llendl;
+ LL_DEBUGS() << "LLPreviewNotecard::refreshFromInventory()" << LL_ENDL;
loadAsset();
}
+void LLPreviewNotecard::updateTitleButtons()
+{
+ LLPreview::updateTitleButtons();
+
+ LLUICtrl* lock_btn = getChild<LLUICtrl>("lock");
+ if(lock_btn->getVisible() && !isMinimized()) // lock button stays visible if floater is minimized.
+ {
+ LLRect lock_rc = lock_btn->getRect();
+ LLRect buttons_rect = getDragHandle()->getButtonsRect();
+ buttons_rect.mLeft = lock_rc.mLeft;
+ getDragHandle()->setButtonsRect(buttons_rect);
+ }
+}
+
void LLPreviewNotecard::loadAsset()
{
// request the asset.
@@ -201,9 +215,12 @@ void LLPreviewNotecard::loadAsset()
if(item)
{
- if (gAgent.allowOperation(PERM_COPY, item->getPermissions(),
- GP_OBJECT_MANIPULATE)
- || gAgent.isGodlike())
+ LLPermissions perm(item->getPermissions());
+ BOOL is_owner = gAgent.allowOperation(PERM_OWNER, perm, GP_OBJECT_MANIPULATE);
+ BOOL allow_copy = gAgent.allowOperation(PERM_COPY, perm, GP_OBJECT_MANIPULATE);
+ BOOL allow_modify = gAgent.allowOperation(PERM_MODIFY, perm, GP_OBJECT_MANIPULATE);
+
+ if (allow_copy || gAgent.isGodlike())
{
mAssetID = item->getAssetUUID();
if(mAssetID.isNull())
@@ -226,7 +243,7 @@ void LLPreviewNotecard::loadAsset()
else
{
// The object that we're trying to look at disappeared, bail.
- llwarns << "Can't find object " << mObjectUUID << " associated with notecard." << llendl;
+ LL_WARNS() << "Can't find object " << mObjectUUID << " associated with notecard." << LL_ENDL;
mAssetID.setNull();
editor->setText(getString("no_object"));
editor->makePristine();
@@ -257,11 +274,16 @@ void LLPreviewNotecard::loadAsset()
editor->setEnabled(FALSE);
mAssetStatus = PREVIEW_ASSET_LOADED;
}
- if(!gAgent.allowOperation(PERM_MODIFY, item->getPermissions(),
- GP_OBJECT_MANIPULATE))
+
+ if(!allow_modify)
{
editor->setEnabled(FALSE);
- childSetVisible("lock", TRUE);
+ getChildView("lock")->setVisible( TRUE);
+ }
+
+ if(allow_modify || is_owner)
+ {
+ getChildView("Delete")->setEnabled(TRUE);
}
}
else
@@ -281,7 +303,7 @@ void LLPreviewNotecard::onLoadComplete(LLVFS *vfs,
LLAssetType::EType type,
void* user_data, S32 status, LLExtStat ext_status)
{
- llinfos << "LLPreviewNotecard::onLoadComplete()" << llendl;
+ LL_INFOS() << "LLPreviewNotecard::onLoadComplete()" << LL_ENDL;
LLUUID* item_id = (LLUUID*)user_data;
LLPreviewNotecard* preview = LLFloaterReg::findTypedInstance<LLPreviewNotecard>("preview_notecard", LLSD(*item_id));
@@ -306,7 +328,7 @@ void LLPreviewNotecard::onLoadComplete(LLVFS *vfs,
{
if( !previewEditor->importBuffer( &buffer[0], file_length+1 ) )
{
- llwarns << "Problem importing notecard" << llendl;
+ LL_WARNS() << "Problem importing notecard" << LL_ENDL;
}
}
else
@@ -325,23 +347,21 @@ void LLPreviewNotecard::onLoadComplete(LLVFS *vfs,
}
else
{
- LLViewerStats::getInstance()->incStat( LLViewerStats::ST_DOWNLOAD_FAILED );
-
if( LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status ||
LL_ERR_FILE_EMPTY == status)
{
- LLNotifications::instance().add("NotecardMissing");
+ LLNotificationsUtil::add("NotecardMissing");
}
else if (LL_ERR_INSUFFICIENT_PERMISSIONS == status)
{
- LLNotifications::instance().add("NotecardNoPermissions");
+ LLNotificationsUtil::add("NotecardNoPermissions");
}
else
{
- LLNotifications::instance().add("UnableToLoadNotecard");
+ LLNotificationsUtil::add("UnableToLoadNotecard");
}
- llwarns << "Problem loading notecard: " << status << llendl;
+ LL_WARNS() << "Problem loading notecard: " << status << LL_ENDL;
preview->mAssetStatus = PREVIEW_ASSET_ERROR;
}
}
@@ -351,7 +371,7 @@ void LLPreviewNotecard::onLoadComplete(LLVFS *vfs,
// static
void LLPreviewNotecard::onClickSave(void* user_data)
{
- //llinfos << "LLPreviewNotecard::onBtnSave()" << llendl;
+ //LL_INFOS() << "LLPreviewNotecard::onBtnSave()" << LL_ENDL;
LLPreviewNotecard* preview = (LLPreviewNotecard*)user_data;
if(preview)
{
@@ -359,6 +379,17 @@ void LLPreviewNotecard::onClickSave(void* user_data)
}
}
+
+// static
+void LLPreviewNotecard::onClickDelete(void* user_data)
+{
+ LLPreviewNotecard* preview = (LLPreviewNotecard*)user_data;
+ if(preview)
+ {
+ preview->deleteNotecard();
+ }
+}
+
struct LLSaveNotecardInfo
{
LLPreviewNotecard* mSelf;
@@ -375,15 +406,14 @@ struct LLSaveNotecardInfo
bool LLPreviewNotecard::saveIfNeeded(LLInventoryItem* copyitem)
{
- if(!gAssetStorage)
+ LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor");
+
+ if(!editor)
{
- llwarns << "Not connected to an asset storage system." << llendl;
+ LL_WARNS() << "Cannot get handle to the notecard editor." << LL_ENDL;
return false;
}
-
- LLViewerTextEditor* editor = getChild<LLViewerTextEditor>("Notecard Editor");
-
if(!editor->isPristine())
{
// We need to update the asset information
@@ -410,8 +440,15 @@ bool LLPreviewNotecard::saveIfNeeded(LLInventoryItem* copyitem)
// save it out to database
if (item)
{
- std::string agent_url = gAgent.getRegion()->getCapability("UpdateNotecardAgentInventory");
- std::string task_url = gAgent.getRegion()->getCapability("UpdateNotecardTaskInventory");
+ const LLViewerRegion* region = gAgent.getRegion();
+ if (!region)
+ {
+ LL_WARNS() << "Not connected to a region, cannot save notecard." << LL_ENDL;
+ return false;
+ }
+ std::string agent_url = region->getCapability("UpdateNotecardAgentInventory");
+ std::string task_url = region->getCapability("UpdateNotecardTaskInventory");
+
if (mObjectUUID.isNull() && !agent_url.empty())
{
// Saving into agent inventory
@@ -419,8 +456,8 @@ bool LLPreviewNotecard::saveIfNeeded(LLInventoryItem* copyitem)
setEnabled(FALSE);
LLSD body;
body["item_id"] = mItemUUID;
- llinfos << "Saving notecard " << mItemUUID
- << " into agent inventory via " << agent_url << llendl;
+ LL_INFOS() << "Saving notecard " << mItemUUID
+ << " into agent inventory via " << agent_url << LL_ENDL;
LLHTTPClient::post(agent_url, body,
new LLUpdateAgentInventoryResponder(body, asset_id, LLAssetType::AT_NOTECARD));
}
@@ -432,8 +469,8 @@ bool LLPreviewNotecard::saveIfNeeded(LLInventoryItem* copyitem)
LLSD body;
body["task_id"] = mObjectUUID;
body["item_id"] = mItemUUID;
- llinfos << "Saving notecard " << mItemUUID << " into task "
- << mObjectUUID << " via " << task_url << llendl;
+ LL_INFOS() << "Saving notecard " << mItemUUID << " into task "
+ << mObjectUUID << " via " << task_url << LL_ENDL;
LLHTTPClient::post(task_url, body,
new LLUpdateTaskInventoryResponder(body, asset_id, LLAssetType::AT_NOTECARD));
}
@@ -445,12 +482,27 @@ bool LLPreviewNotecard::saveIfNeeded(LLInventoryItem* copyitem)
&onSaveComplete,
(void*)info,
FALSE);
+ return true;
+ }
+ else // !gAssetStorage
+ {
+ LL_WARNS() << "Not connected to an asset storage system." << LL_ENDL;
+ return false;
+ }
+ if(mCloseAfterSave)
+ {
+ closeFloater();
}
}
}
return true;
}
+void LLPreviewNotecard::deleteNotecard()
+{
+ LLNotificationsUtil::add("DeleteNotecard", LLSD(), LLSD(), boost::bind(&LLPreviewNotecard::handleConfirmDeleteDialog,this, _1, _2));
+}
+
// static
void LLPreviewNotecard::onSaveComplete(const LLUUID& asset_uuid, void* user_data, S32 status, LLExtStat ext_status) // StoreAssetData callback (fixed)
{
@@ -472,8 +524,8 @@ void LLPreviewNotecard::onSaveComplete(const LLUUID& asset_uuid, void* user_data
}
else
{
- llwarns << "Inventory item for script " << info->mItemUUID
- << " is no longer in agent inventory." << llendl;
+ LL_WARNS() << "Inventory item for script " << info->mItemUUID
+ << " is no longer in agent inventory." << LL_ENDL;
}
}
else
@@ -493,7 +545,7 @@ void LLPreviewNotecard::onSaveComplete(const LLUUID& asset_uuid, void* user_data
}
else
{
- LLNotifications::instance().add("SaveNotecardFailObjectNotFound");
+ LLNotificationsUtil::add("SaveNotecardFailObjectNotFound");
}
}
// Perform item copy to inventory
@@ -516,10 +568,10 @@ void LLPreviewNotecard::onSaveComplete(const LLUUID& asset_uuid, void* user_data
}
else
{
- llwarns << "Problem saving notecard: " << status << llendl;
+ LL_WARNS() << "Problem saving notecard: " << status << LL_ENDL;
LLSD args;
args["REASON"] = std::string(LLAssetStorage::getErrorString(status));
- LLNotifications::instance().add("SaveNotecardFailReason", args);
+ LLNotificationsUtil::add("SaveNotecardFailReason", args);
}
std::string uuid_string;
@@ -532,7 +584,7 @@ void LLPreviewNotecard::onSaveComplete(const LLUUID& asset_uuid, void* user_data
bool LLPreviewNotecard::handleSaveChangesDialog(const LLSD& notification, const LLSD& response)
{
- S32 option = LLNotification::getSelectedOption(notification, response);
+ S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
switch(option)
{
case 0: // "Yes"
@@ -554,4 +606,43 @@ bool LLPreviewNotecard::handleSaveChangesDialog(const LLSD& notification, const
return false;
}
+bool LLPreviewNotecard::handleConfirmDeleteDialog(const LLSD& notification, const LLSD& response)
+{
+ S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+ if (option != 0)
+ {
+ // canceled
+ return false;
+ }
+
+ if (mObjectUUID.isNull())
+ {
+ // move item from agent's inventory into trash
+ LLViewerInventoryItem* item = gInventory.getItem(mItemUUID);
+ if (item != NULL)
+ {
+ const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
+ gInventory.changeItemParent(item, trash_id, FALSE);
+ }
+ }
+ else
+ {
+ // delete item from inventory of in-world object
+ LLViewerObject* object = gObjectList.findObject(mObjectUUID);
+ if(object)
+ {
+ LLViewerInventoryItem* item = dynamic_cast<LLViewerInventoryItem*>(object->getInventoryObject(mItemUUID));
+ if (item != NULL)
+ {
+ object->removeInventory(mItemUUID);
+ }
+ }
+ }
+
+ // close floater, ignore unsaved changes
+ mForceClose = TRUE;
+ closeFloater();
+ return false;
+}
+
// EOF