llfloaterproperties.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 #include "llfloaterproperties.h"
00034 
00035 #include <algorithm>
00036 #include <functional>
00037 #include "llcachename.h"
00038 #include "lldbstrings.h"
00039 #include "llinventory.h"
00040 
00041 #include "llagent.h"
00042 #include "llbutton.h"
00043 #include "llcheckboxctrl.h"
00044 #include "llfloateravatarinfo.h"
00045 #include "llfloatergroupinfo.h"
00046 #include "llinventorymodel.h"
00047 #include "lllineeditor.h"
00048 #include "llradiogroup.h"
00049 #include "llresmgr.h"
00050 #include "roles_constants.h"
00051 #include "llselectmgr.h"
00052 #include "lltextbox.h"
00053 #include "lluiconstants.h"
00054 #include "llviewerinventory.h"
00055 #include "llviewerobjectlist.h"
00056 #include "llviewerregion.h"
00057 #include "llviewercontrol.h"
00058 
00059 #include "lluictrlfactory.h"
00060 
00061 
00062 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00063 // Class LLPropertiesObserver
00064 //
00065 // helper class to watch the inventory. 
00066 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00067 
00068 // Ugh. This can't be a singleton because it needs to remove itself
00069 //  from the inventory observer list when destroyed, which could
00070 //  happen after gInventory has already been destroyed if a singleton.
00071 // Instead, do our own ref counting and create / destroy it as needed
00072 class LLPropertiesObserver : public LLInventoryObserver
00073 {
00074 public:
00075         LLPropertiesObserver()
00076         {
00077                 gInventory.addObserver(this);
00078         }
00079         virtual ~LLPropertiesObserver()
00080         {
00081                 gInventory.removeObserver(this);
00082         }
00083         virtual void changed(U32 mask);
00084 };
00085 
00086 void LLPropertiesObserver::changed(U32 mask)
00087 {
00088         // if there's a change we're interested in.
00089         if((mask & (LLInventoryObserver::LABEL | LLInventoryObserver::INTERNAL | LLInventoryObserver::REMOVE)) != 0)
00090         {
00091                 LLFloaterProperties::dirtyAll();
00092         }
00093 }
00094 
00095 
00096 
00100 
00101 // static
00102 LLFloaterProperties::instance_map LLFloaterProperties::sInstances;
00103 LLPropertiesObserver* LLFloaterProperties::sPropertiesObserver = NULL;
00104 S32 LLFloaterProperties::sPropertiesObserverCount = 0;
00105 
00106 // static
00107 LLFloaterProperties* LLFloaterProperties::find(const LLUUID& item_id,
00108                                                                                            const LLUUID& object_id)
00109 {
00110         // for simplicity's sake, we key the properties window with a
00111         // single uuid. However, the items are keyed by item and object
00112         // (obj == null -> agent inventory). So, we xor the two ids, and
00113         // use that as a lookup key
00114         instance_map::iterator it = sInstances.find(item_id ^ object_id);
00115         if(it != sInstances.end())
00116         {
00117                 return (*it).second;
00118         }
00119         return NULL;
00120 }
00121 
00122 // static
00123 LLFloaterProperties* LLFloaterProperties::show(const LLUUID& item_id,
00124                                                                                            const LLUUID& object_id)
00125 {
00126         LLFloaterProperties* instance = find(item_id, object_id);
00127         if(instance)
00128         {
00129                 if (LLFloater::getFloaterHost() && LLFloater::getFloaterHost() != instance->getHost())
00130                 {
00131                         // this properties window is being opened in a new context
00132                         // needs to be rehosted
00133                         LLFloater::getFloaterHost()->addFloater(instance, TRUE);
00134                 }
00135 
00136                 instance->refresh();
00137                 instance->open();               /* Flawfinder: ignore */
00138         }
00139         return instance;
00140 }
00141 
00142 void LLFloaterProperties::dirtyAll()
00143 {
00144         // ...this is more clear. Possibly more correct, because the
00145         // refresh method may delete the object.
00146         for(instance_map::iterator it = sInstances.begin(); it!=sInstances.end(); )
00147         {
00148                 (*it++).second->dirty();
00149         }
00150 }
00151 
00152 // Default constructor
00153 LLFloaterProperties::LLFloaterProperties(const std::string& name, const LLRect& rect, const std::string& title, const LLUUID& item_id, const LLUUID& object_id) :
00154         LLFloater(name, rect, title),
00155         mItemID(item_id),
00156         mObjectID(object_id),
00157         mDirty(TRUE)
00158 {
00159         LLUICtrlFactory::getInstance()->buildFloater(this,"floater_inventory_item_properties.xml");
00160 
00161         if (!sPropertiesObserver)
00162         {
00163                 sPropertiesObserver = new LLPropertiesObserver;
00164         }
00165         sPropertiesObserverCount++;
00166         
00167         // add the object to the static structure
00168         LLUUID key = mItemID ^ mObjectID;
00169         sInstances.insert(instance_map::value_type(key, this));
00170         // build the UI
00171         // item name & description
00172         childSetPrevalidate("LabelItemName",&LLLineEditor::prevalidatePrintableNotPipe);
00173         childSetCommitCallback("LabelItemName",onCommitName,this);
00174         childSetPrevalidate("LabelItemDesc",&LLLineEditor::prevalidatePrintableNotPipe);
00175         childSetCommitCallback("LabelItemDesc", onCommitDescription, this);
00176         // Creator information
00177         childSetAction("BtnCreator",onClickCreator,this);
00178         // owner information
00179         childSetAction("BtnOwner",onClickOwner,this);
00180         // acquired date
00181         // owner permissions
00182         // Permissions debug text
00183         // group permissions
00184         childSetCommitCallback("CheckShareWithGroup",&onCommitPermissions, this);
00185         // everyone permissions
00186         childSetCommitCallback("CheckEveryoneCopy",&onCommitPermissions, this);
00187         // next owner permissions
00188         childSetCommitCallback("CheckNextOwnerModify",&onCommitPermissions, this);
00189         childSetCommitCallback("CheckNextOwnerCopy",&onCommitPermissions, this);
00190         childSetCommitCallback("CheckNextOwnerTransfer",&onCommitPermissions, this);
00191         // Mark for sale or not, and sale info
00192         childSetCommitCallback("CheckPurchase",&onCommitSaleInfo, this);
00193         childSetCommitCallback("RadioSaleType",&onCommitSaleType, this);
00194         // "Price" label for edit
00195         childSetCommitCallback("EditPrice",&onCommitSaleInfo, this);
00196         // The UI has been built, now fill in all the values
00197         refresh();
00198 }
00199 
00200 // Destroys the object
00201 LLFloaterProperties::~LLFloaterProperties()
00202 {
00203         // clean up the static data.
00204         instance_map::iterator it = sInstances.find(mItemID ^ mObjectID);
00205         if(it != sInstances.end())
00206         {
00207                 sInstances.erase(it);
00208         }
00209         sPropertiesObserverCount--;
00210         if (!sPropertiesObserverCount)
00211         {
00212                 delete sPropertiesObserver;
00213                 sPropertiesObserver = NULL;
00214         }
00215 }
00216 
00217 void LLFloaterProperties::refresh()
00218 {
00219         LLInventoryItem* item = findItem();
00220         if(item)
00221         {
00222                 refreshFromItem(item);
00223         }
00224         else
00225         {
00226                 //RN: it is possible that the container object is in the middle of an inventory refresh
00227                 // causing findItem() to fail, so just temporarily disable everything
00228                 
00229                 mDirty = TRUE;
00230 
00231                 const char* enableNames[]={
00232                         "LabelItemName",
00233                         "LabelItemDesc",
00234                         "LabelCreatorName",
00235                         "BtnCreator",
00236                         "LabelOwnerName",
00237                         "BtnOwner",
00238                         "CheckOwnerModify",
00239                         "CheckOwnerCopy",
00240                         "CheckOwnerTransfer",
00241                         "CheckShareWithGroup",
00242                         "CheckEveryoneCopy",
00243                         "CheckNextOwnerModify",
00244                         "CheckNextOwnerCopy",
00245                         "CheckNextOwnerTransfer",
00246                         "CheckPurchase",
00247                         "RadioSaleType",
00248                         "EditPrice"
00249                 };
00250                 for(size_t t=0; t<sizeof(enableNames)/sizeof(char*); ++t)
00251                 {
00252                         childSetEnabled(enableNames[t],false);
00253                 }
00254                 const char* hideNames[]={
00255                         "BaseMaskDebug",
00256                         "OwnerMaskDebug",
00257                         "GroupMaskDebug",
00258                         "EveryoneMaskDebug",
00259                         "NextMaskDebug"
00260                 };
00261                 for(size_t t=0; t<sizeof(hideNames)/sizeof(char*); ++t)
00262                 {
00263                         childSetVisible(hideNames[t],false);
00264                 }
00265         }
00266 }
00267 
00268 void LLFloaterProperties::draw()
00269 {
00270         if (mDirty)
00271         {
00272                 // RN: clear dirty first because refresh can set dirty to TRUE
00273                 mDirty = FALSE;
00274                 refresh();
00275         }
00276 
00277         LLFloater::draw();
00278 }
00279 
00280 void LLFloaterProperties::refreshFromItem(LLInventoryItem* item)
00281 {
00283         // PERMISSIONS LOOKUP //
00285 
00286         // do not enable the UI for incomplete items.
00287         LLViewerInventoryItem* i = (LLViewerInventoryItem*)item;
00288         BOOL is_complete = i->isComplete();
00289 
00290         const LLPermissions& perm = item->getPermissions();
00291         BOOL can_agent_manipulate = gAgent.allowOperation(PERM_OWNER, perm, 
00292                                                                                                 GP_OBJECT_MANIPULATE);
00293         BOOL can_agent_sell = gAgent.allowOperation(PERM_OWNER, perm, 
00294                                                                                                 GP_OBJECT_SET_SALE);
00295 
00296         // You need permission to modify the object to modify an inventory
00297         // item in it.
00298         LLViewerObject* object = NULL;
00299         if(!mObjectID.isNull()) object = gObjectList.findObject(mObjectID);
00300         BOOL is_obj_modify = TRUE;
00301         if(object)
00302         {
00303                 is_obj_modify = object->permOwnerModify();
00304         }
00305 
00307         // ITEM NAME & DESC //
00309         BOOL is_modifiable = gAgent.allowOperation(PERM_MODIFY, perm,
00310                                                                                                 GP_OBJECT_MANIPULATE)
00311                                                         && is_obj_modify && is_complete;
00312 
00313         childSetEnabled("LabelItemNameTitle",TRUE);
00314         childSetEnabled("LabelItemName",is_modifiable);
00315         childSetText("LabelItemName",item->getName());
00316         childSetEnabled("LabelItemDescTitle",TRUE);
00317         childSetEnabled("LabelItemDesc",is_modifiable);
00318         childSetVisible("IconLocked",!is_modifiable);
00319         childSetText("LabelItemDesc",item->getDescription());
00320 
00322         // CREATOR NAME //
00324         if(!gCacheName) return;
00325         if(!gAgent.getRegion()) return;
00326 
00327         if (item->getCreatorUUID().notNull())
00328         {
00329                 std::string name;
00330                 gCacheName->getFullName(item->getCreatorUUID(), name);
00331                 childSetEnabled("BtnCreator",TRUE);
00332                 childSetEnabled("LabelCreatorTitle",TRUE);
00333                 childSetEnabled("LabelCreatorName",TRUE);
00334                 childSetText("LabelCreatorName",name);
00335         }
00336         else
00337         {
00338                 childSetEnabled("BtnCreator",FALSE);
00339                 childSetEnabled("LabelCreatorTitle",FALSE);
00340                 childSetEnabled("LabelCreatorName",FALSE);
00341                 childSetText("LabelCreatorName",getString("unknown"));
00342         }
00343 
00345         // OWNER NAME //
00347         if(perm.isOwned())
00348         {
00349                 LLString name;
00350                 if (perm.isGroupOwned())
00351                 {
00352                         gCacheName->getGroupName(perm.getGroup(), name);
00353                 }
00354                 else
00355                 {
00356                         gCacheName->getFullName(perm.getOwner(), name);
00357                 }
00358                 childSetEnabled("BtnOwner",TRUE);
00359                 childSetEnabled("LabelOwnerTitle",TRUE);
00360                 childSetEnabled("LabelOwnerName",TRUE);
00361                 childSetText("LabelOwnerName",name);
00362         }
00363         else
00364         {
00365                 childSetEnabled("BtnOwner",FALSE);
00366                 childSetEnabled("LabelOwnerTitle",FALSE);
00367                 childSetEnabled("LabelOwnerName",FALSE);
00368                 childSetText("LabelOwnerName",getString("public"));
00369         }
00370         
00372         // ACQUIRE DATE //
00374 
00375         // *TODO: Localize / translate this
00376         time_t time_utc = (time_t)item->getCreationDate();
00377         if (0 == time_utc)
00378         {
00379                 childSetText("LabelAcquiredDate",getString("unknown"));
00380         }
00381         else
00382         {
00383                 childSetText("LabelAcquiredDate", LLString(ctime(&time_utc)) );
00384         }
00385 
00387         // OWNER PERMISSIONS //
00389         if(can_agent_manipulate)
00390         {
00391                 childSetText("OwnerLabel",getString("you_can"));
00392         }
00393         else
00394         {
00395                 childSetText("OwnerLabel",getString("owner_can"));
00396         }
00397 
00398         U32 base_mask           = perm.getMaskBase();
00399         U32 owner_mask          = perm.getMaskOwner();
00400         U32 group_mask          = perm.getMaskGroup();
00401         U32 everyone_mask       = perm.getMaskEveryone();
00402         U32 next_owner_mask     = perm.getMaskNextOwner();
00403 
00404         childSetEnabled("OwnerLabel",TRUE);
00405         childSetEnabled("CheckOwnerModify",FALSE);
00406         childSetValue("CheckOwnerModify",LLSD((BOOL)(owner_mask & PERM_MODIFY)));
00407         childSetEnabled("CheckOwnerCopy",FALSE);
00408         childSetValue("CheckOwnerCopy",LLSD((BOOL)(owner_mask & PERM_COPY)));
00409         childSetEnabled("CheckOwnerTransfer",FALSE);
00410         childSetValue("CheckOwnerTransfer",LLSD((BOOL)(owner_mask & PERM_TRANSFER)));
00411 
00413         // DEBUG PERMISSIONS //
00415 
00416         if( gSavedSettings.getBOOL("DebugPermissions") )
00417         {
00418                 BOOL slam_perm                  = FALSE;
00419                 BOOL overwrite_group    = FALSE;
00420                 BOOL overwrite_everyone = FALSE;
00421 
00422                 if (item->getType() == LLAssetType::AT_OBJECT)
00423                 {
00424                         U32 flags = item->getFlags();
00425                         slam_perm                       = flags & LLInventoryItem::II_FLAGS_OBJECT_SLAM_PERM;
00426                         overwrite_everyone      = flags & LLInventoryItem::II_FLAGS_OBJECT_PERM_OVERWRITE_EVERYONE;
00427                         overwrite_group         = flags & LLInventoryItem::II_FLAGS_OBJECT_PERM_OVERWRITE_GROUP;
00428                 }
00429                 
00430                 std::string perm_string;
00431 
00432                 perm_string = "B: ";
00433                 perm_string += mask_to_string(base_mask);
00434                 childSetText("BaseMaskDebug",perm_string);
00435                 childSetVisible("BaseMaskDebug",TRUE);
00436                 
00437                 perm_string = "O: ";
00438                 perm_string += mask_to_string(owner_mask);
00439                 childSetText("OwnerMaskDebug",perm_string);
00440                 childSetVisible("OwnerMaskDebug",TRUE);
00441                 
00442                 perm_string = "G";
00443                 perm_string += overwrite_group ? "*: " : ": ";
00444                 perm_string += mask_to_string(group_mask);
00445                 childSetText("GroupMaskDebug",perm_string);
00446                 childSetVisible("GroupMaskDebug",TRUE);
00447                 
00448                 perm_string = "E";
00449                 perm_string += overwrite_everyone ? "*: " : ": ";
00450                 perm_string += mask_to_string(everyone_mask);
00451                 childSetText("EveryoneMaskDebug",perm_string);
00452                 childSetVisible("EveryoneMaskDebug",TRUE);
00453                 
00454                 perm_string = "N";
00455                 perm_string += slam_perm ? "*: " : ": ";
00456                 perm_string += mask_to_string(next_owner_mask);
00457                 childSetText("NextMaskDebug",perm_string);
00458                 childSetVisible("NextMaskDebug",TRUE);
00459         }
00460         else
00461         {
00462                 childSetVisible("BaseMaskDebug",FALSE);
00463                 childSetVisible("OwnerMaskDebug",FALSE);
00464                 childSetVisible("GroupMaskDebug",FALSE);
00465                 childSetVisible("EveryoneMaskDebug",FALSE);
00466                 childSetVisible("NextMaskDebug",FALSE);
00467         }
00468 
00470         // SHARING //
00472 
00473         // Check for ability to change values.
00474         if (is_obj_modify && can_agent_manipulate)
00475         {
00476                 childSetEnabled("CheckShareWithGroup",TRUE);
00477                 childSetEnabled("CheckEveryoneCopy",(owner_mask & PERM_COPY) && (owner_mask & PERM_TRANSFER));
00478         }
00479         else
00480         {
00481                 childSetEnabled("CheckShareWithGroup",FALSE);
00482                 childSetEnabled("CheckEveryoneCopy",FALSE);
00483         }
00484 
00485         // Set values.
00486         BOOL is_group_copy = (group_mask & PERM_COPY) ? TRUE : FALSE;
00487         BOOL is_group_modify = (group_mask & PERM_MODIFY) ? TRUE : FALSE;
00488         BOOL is_group_move = (group_mask & PERM_MOVE) ? TRUE : FALSE;
00489 
00490         if (is_group_copy && is_group_modify && is_group_move)
00491         {
00492                 childSetValue("CheckShareWithGroup",LLSD((BOOL)TRUE));
00493 
00494                 LLCheckBoxCtrl* ctl = getChild<LLCheckBoxCtrl>("CheckShareWithGroup");
00495                 if(ctl)
00496                 {
00497                         ctl->setTentative(FALSE);
00498                 }
00499         }
00500         else if (!is_group_copy && !is_group_modify && !is_group_move)
00501         {
00502                 childSetValue("CheckShareWithGroup",LLSD((BOOL)FALSE));
00503                 LLCheckBoxCtrl* ctl = getChild<LLCheckBoxCtrl>("CheckShareWithGroup");
00504                 if(ctl)
00505                 {
00506                         ctl->setTentative(FALSE);
00507                 }
00508         }
00509         else
00510         {
00511                 LLCheckBoxCtrl* ctl = getChild<LLCheckBoxCtrl>("CheckShareWithGroup");
00512                 if(ctl)
00513                 {
00514                         ctl->setTentative(TRUE);
00515                         ctl->set(TRUE);
00516                 }
00517         }
00518         
00519         childSetValue("CheckEveryoneCopy",LLSD((BOOL)(everyone_mask & PERM_COPY)));
00520 
00522         // SALE INFO //
00524 
00525         const LLSaleInfo& sale_info = item->getSaleInfo();
00526         BOOL is_for_sale = sale_info.isForSale();
00527         // Check for ability to change values.
00528         if (is_obj_modify && can_agent_sell 
00529                 && gAgent.allowOperation(PERM_TRANSFER, perm, GP_OBJECT_MANIPULATE))
00530         {
00531                 childSetEnabled("SaleLabel",is_complete);
00532                 childSetEnabled("CheckPurchase",is_complete);
00533 
00534                 childSetEnabled("NextOwnerLabel",TRUE);
00535                 childSetEnabled("CheckNextOwnerModify",base_mask & PERM_MODIFY);
00536                 childSetEnabled("CheckNextOwnerCopy",base_mask & PERM_COPY);
00537                 childSetEnabled("CheckNextOwnerTransfer",next_owner_mask & PERM_COPY);
00538 
00539                 childSetEnabled("RadioSaleType",is_complete && is_for_sale);
00540                 childSetEnabled("TextPrice",is_complete && is_for_sale);
00541                 childSetEnabled("EditPrice",is_complete && is_for_sale);
00542         }
00543         else
00544         {
00545                 childSetEnabled("SaleLabel",FALSE);
00546                 childSetEnabled("CheckPurchase",FALSE);
00547 
00548                 childSetEnabled("NextOwnerLabel",FALSE);
00549                 childSetEnabled("CheckNextOwnerModify",FALSE);
00550                 childSetEnabled("CheckNextOwnerCopy",FALSE);
00551                 childSetEnabled("CheckNextOwnerTransfer",FALSE);
00552 
00553                 childSetEnabled("RadioSaleType",FALSE);
00554                 childSetEnabled("TextPrice",FALSE);
00555                 childSetEnabled("EditPrice",FALSE);
00556         }
00557 
00558         // Set values.
00559         childSetValue("CheckPurchase", is_for_sale);
00560         childSetValue("CheckNextOwnerModify",LLSD(BOOL(next_owner_mask & PERM_MODIFY)));
00561         childSetValue("CheckNextOwnerCopy",LLSD(BOOL(next_owner_mask & PERM_COPY)));
00562         childSetValue("CheckNextOwnerTransfer",LLSD(BOOL(next_owner_mask & PERM_TRANSFER)));
00563 
00564         LLRadioGroup* radioSaleType = getChild<LLRadioGroup>("RadioSaleType");
00565         if (is_for_sale)
00566         {
00567                 radioSaleType->setSelectedIndex((S32)sale_info.getSaleType() - 1);
00568                 S32 numerical_price;
00569                 numerical_price = sale_info.getSalePrice();
00570                 childSetText("EditPrice",llformat("%d",numerical_price));
00571         }
00572         else
00573         {
00574                 radioSaleType->setSelectedIndex(-1);
00575                 childSetText("EditPrice",llformat("%d",0));
00576         }
00577 }
00578 
00579 // static
00580 void LLFloaterProperties::onClickCreator(void* data)
00581 {
00582         LLFloaterProperties* self = (LLFloaterProperties*)data;
00583         if(!self) return;
00584         LLInventoryItem* item = self->findItem();
00585         if(!item) return;
00586         if(!item->getCreatorUUID().isNull())
00587         {
00588                 LLFloaterAvatarInfo::showFromObject(item->getCreatorUUID());
00589         }
00590 }
00591 
00592 // static
00593 void LLFloaterProperties::onClickOwner(void* data)
00594 {
00595         LLFloaterProperties* self = (LLFloaterProperties*)data;
00596         if(!self) return;
00597         LLInventoryItem* item = self->findItem();
00598         if(!item) return;
00599         if(item->getPermissions().isGroupOwned())
00600         {
00601                 LLFloaterGroupInfo::showFromUUID(item->getPermissions().getGroup());
00602         }
00603         else
00604         {
00605                 if(!item->getPermissions().getOwner().isNull())
00606                 {
00607                         LLFloaterAvatarInfo::showFromObject(item->getPermissions().getOwner());
00608                 }
00609         }
00610 }
00611 
00612 // static
00613 void LLFloaterProperties::onCommitName(LLUICtrl* ctrl, void* data)
00614 {
00615         //llinfos << "LLFloaterProperties::onCommitName()" << llendl;
00616         LLFloaterProperties* self = (LLFloaterProperties*)data;
00617         if(!self)
00618         {
00619                 return;
00620         }
00621         LLViewerInventoryItem* item = (LLViewerInventoryItem*)self->findItem();
00622         if(!item)
00623         {
00624                 return;
00625         }
00626         LLLineEditor* labelItemName = self->getChild<LLLineEditor>("LabelItemName");
00627 
00628         if(labelItemName&&
00629            (item->getName() != labelItemName->getText()) && 
00630            (gAgent.allowOperation(PERM_MODIFY, item->getPermissions(), GP_OBJECT_MANIPULATE)) )
00631         {
00632                 LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
00633                 new_item->rename(labelItemName->getText());
00634                 if(self->mObjectID.isNull())
00635                 {
00636                         new_item->updateServer(FALSE);
00637                         gInventory.updateItem(new_item);
00638                         gInventory.notifyObservers();
00639                 }
00640                 else
00641                 {
00642                         LLViewerObject* object = gObjectList.findObject(self->mObjectID);
00643                         if(object)
00644                         {
00645                                 object->updateInventory(
00646                                         new_item,
00647                                         TASK_INVENTORY_ITEM_KEY,
00648                                         false);
00649                         }
00650                 }
00651         }
00652 }
00653 
00654 // static
00655 void LLFloaterProperties::onCommitDescription(LLUICtrl* ctrl, void* data)
00656 {
00657         //llinfos << "LLFloaterProperties::onCommitDescription()" << llendl;
00658         LLFloaterProperties* self = (LLFloaterProperties*)data;
00659         if(!self) return;
00660         LLViewerInventoryItem* item = (LLViewerInventoryItem*)self->findItem();
00661         if(!item) return;
00662 
00663         LLLineEditor* labelItemDesc = self->getChild<LLLineEditor>("LabelItemDesc");
00664         if(!labelItemDesc)
00665         {
00666                 return;
00667         }
00668         if((item->getDescription() != labelItemDesc->getText()) && 
00669            (gAgent.allowOperation(PERM_MODIFY, item->getPermissions(), GP_OBJECT_MANIPULATE)))
00670         {
00671                 LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
00672 
00673                 new_item->setDescription(labelItemDesc->getText());
00674                 if(self->mObjectID.isNull())
00675                 {
00676                         new_item->updateServer(FALSE);
00677                         gInventory.updateItem(new_item);
00678                         gInventory.notifyObservers();
00679                 }
00680                 else
00681                 {
00682                         LLViewerObject* object = gObjectList.findObject(self->mObjectID);
00683                         if(object)
00684                         {
00685                                 object->updateInventory(
00686                                         new_item,
00687                                         TASK_INVENTORY_ITEM_KEY,
00688                                         false);
00689                         }
00690                 }
00691         }
00692 }
00693 
00694 // static
00695 void LLFloaterProperties::onCommitPermissions(LLUICtrl* ctrl, void* data)
00696 {
00697         //llinfos << "LLFloaterProperties::onCommitPermissions()" << llendl;
00698         LLFloaterProperties* self = (LLFloaterProperties*)data;
00699         if(!self) return;
00700         LLViewerInventoryItem* item = (LLViewerInventoryItem*)self->findItem();
00701         if(!item) return;
00702         LLPermissions perm(item->getPermissions());
00703 
00704 
00705         LLCheckBoxCtrl* CheckShareWithGroup = self->getChild<LLCheckBoxCtrl>("CheckShareWithGroup");
00706 
00707         if(CheckShareWithGroup)
00708         {
00709                 perm.setGroupBits(gAgent.getID(), gAgent.getGroupID(),
00710                                                 CheckShareWithGroup->get(),
00711                                                 PERM_MODIFY | PERM_MOVE | PERM_COPY);
00712         }
00713         LLCheckBoxCtrl* CheckEveryoneCopy = self->getChild<LLCheckBoxCtrl>("CheckEveryoneCopy");
00714         if(CheckEveryoneCopy)
00715         {
00716                 perm.setEveryoneBits(gAgent.getID(), gAgent.getGroupID(),
00717                                                  CheckEveryoneCopy->get(), PERM_COPY);
00718         }
00719 
00720         LLCheckBoxCtrl* CheckNextOwnerModify = self->getChild<LLCheckBoxCtrl>("CheckNextOwnerModify");
00721         if(CheckNextOwnerModify)
00722         {
00723                 perm.setNextOwnerBits(gAgent.getID(), gAgent.getGroupID(),
00724                                                         CheckNextOwnerModify->get(), PERM_MODIFY);
00725         }
00726         LLCheckBoxCtrl* CheckNextOwnerCopy = self->getChild<LLCheckBoxCtrl>("CheckNextOwnerCopy");
00727         if(CheckNextOwnerCopy)
00728         {
00729                 perm.setNextOwnerBits(gAgent.getID(), gAgent.getGroupID(),
00730                                                         CheckNextOwnerCopy->get(), PERM_COPY);
00731         }
00732         LLCheckBoxCtrl* CheckNextOwnerTransfer = self->getChild<LLCheckBoxCtrl>("CheckNextOwnerTransfer");
00733         if(CheckNextOwnerTransfer)
00734         {
00735                 perm.setNextOwnerBits(gAgent.getID(), gAgent.getGroupID(),
00736                                                         CheckNextOwnerTransfer->get(), PERM_TRANSFER);
00737         }
00738         if(perm != item->getPermissions()
00739                 && item->isComplete())
00740         {
00741                 LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
00742                 new_item->setPermissions(perm);
00743                 U32 flags = new_item->getFlags();
00744                 // If next owner permissions have changed (and this is an object)
00745                 // then set the slam permissions flag so that they are applied on rez.
00746                 if((perm.getMaskNextOwner()!=item->getPermissions().getMaskNextOwner())
00747                    && (item->getType() == LLAssetType::AT_OBJECT))
00748                 {
00749                         flags |= LLInventoryItem::II_FLAGS_OBJECT_SLAM_PERM;
00750                 }
00751                 // If everyone permissions have changed (and this is an object)
00752                 // then set the overwrite everyone permissions flag so they
00753                 // are applied on rez.
00754                 if ((perm.getMaskEveryone()!=item->getPermissions().getMaskEveryone())
00755                         && (item->getType() == LLAssetType::AT_OBJECT))
00756                 {
00757                         flags |= LLInventoryItem::II_FLAGS_OBJECT_PERM_OVERWRITE_EVERYONE;
00758                 }
00759                 // If group permissions have changed (and this is an object)
00760                 // then set the overwrite group permissions flag so they
00761                 // are applied on rez.
00762                 if ((perm.getMaskGroup()!=item->getPermissions().getMaskGroup())
00763                         && (item->getType() == LLAssetType::AT_OBJECT))
00764                 {
00765                         flags |= LLInventoryItem::II_FLAGS_OBJECT_PERM_OVERWRITE_GROUP;
00766                 }
00767                 new_item->setFlags(flags);
00768                 if(self->mObjectID.isNull())
00769                 {
00770                         new_item->updateServer(FALSE);
00771                         gInventory.updateItem(new_item);
00772                         gInventory.notifyObservers();
00773                 }
00774                 else
00775                 {
00776                         LLViewerObject* object = gObjectList.findObject(self->mObjectID);
00777                         if(object)
00778                         {
00779                                 object->updateInventory(
00780                                         new_item,
00781                                         TASK_INVENTORY_ITEM_KEY,
00782                                         false);
00783                         }
00784                 }
00785         }
00786         else
00787         {
00788                 // need to make sure we don't just follow the click
00789                 self->refresh();
00790         }
00791 }
00792 
00793 // static
00794 void LLFloaterProperties::onCommitSaleInfo(LLUICtrl* ctrl, void* data)
00795 {
00796         //llinfos << "LLFloaterProperties::onCommitSaleInfo()" << llendl;
00797         LLFloaterProperties* self = (LLFloaterProperties*)data;
00798         if(!self) return;
00799         self->updateSaleInfo();
00800 }
00801 
00802 // static
00803 void LLFloaterProperties::onCommitSaleType(LLUICtrl* ctrl, void* data)
00804 {
00805         //llinfos << "LLFloaterProperties::onCommitSaleType()" << llendl;
00806         LLFloaterProperties* self = (LLFloaterProperties*)data;
00807         if(!self) return;
00808         self->updateSaleInfo();
00809 }
00810 
00811 void LLFloaterProperties::updateSaleInfo()
00812 {
00813         LLViewerInventoryItem* item = (LLViewerInventoryItem*)findItem();
00814         if(!item) return;
00815         LLSaleInfo sale_info(item->getSaleInfo());
00816         if(!gAgent.allowOperation(PERM_TRANSFER, item->getPermissions(), GP_OBJECT_SET_SALE))
00817         {
00818                 childSetValue("CheckPurchase",LLSD((BOOL)FALSE));
00819         }
00820 
00821         if((BOOL)childGetValue("CheckPurchase"))
00822         {
00823                 // turn on sale info
00824                 LLSaleInfo::EForSale sale_type = LLSaleInfo::FS_COPY;
00825         
00826                 LLRadioGroup* RadioSaleType = getChild<LLRadioGroup>("RadioSaleType");
00827                 if(RadioSaleType)
00828                 {
00829                         switch (RadioSaleType->getSelectedIndex())
00830                         {
00831                         case 0:
00832                                 sale_type = LLSaleInfo::FS_ORIGINAL;
00833                                 break;
00834                         case 1:
00835                                 sale_type = LLSaleInfo::FS_COPY;
00836                                 break;
00837                         case 2:
00838                                 sale_type = LLSaleInfo::FS_CONTENTS;
00839                                 break;
00840                         default:
00841                                 sale_type = LLSaleInfo::FS_COPY;
00842                                 break;
00843                         }
00844                 }
00845 
00846                 if (sale_type == LLSaleInfo::FS_COPY 
00847                         && !gAgent.allowOperation(PERM_COPY, item->getPermissions(), 
00848                                                                           GP_OBJECT_SET_SALE))
00849                 {
00850                         sale_type = LLSaleInfo::FS_ORIGINAL;
00851                 }
00852 
00853                 LLLineEditor* EditPrice = getChild<LLLineEditor>("EditPrice");
00854                 
00855                 S32 price = -1;
00856                 if(EditPrice)
00857                 {
00858                         price = atoi(EditPrice->getText().c_str());
00859                 }
00860                 // Invalid data - turn off the sale
00861                 if (price < 0)
00862                 {
00863                         sale_type = LLSaleInfo::FS_NOT;
00864                         price = 0;
00865                 }
00866 
00867                 sale_info.setSaleType(sale_type);
00868                 sale_info.setSalePrice(price);
00869         }
00870         else
00871         {
00872                 sale_info.setSaleType(LLSaleInfo::FS_NOT);
00873         }
00874         if(sale_info != item->getSaleInfo()
00875                 && item->isComplete())
00876         {
00877                 LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
00878 
00879                 // Force an update on the sale price.
00880                 U32 flags = new_item->getFlags();
00881                 flags |= LLInventoryItem::II_FLAGS_OBJECT_SLAM_SALE;
00882                 new_item->setFlags(flags);
00883 
00884                 new_item->setSaleInfo(sale_info);
00885                 if(mObjectID.isNull())
00886                 {
00887                         // This is in the agent's inventory.
00888                         new_item->updateServer(FALSE);
00889                         gInventory.updateItem(new_item);
00890                         gInventory.notifyObservers();
00891                 }
00892                 else
00893                 {
00894                         // This is in an object's contents.
00895                         LLViewerObject* object = gObjectList.findObject(mObjectID);
00896                         if(object)
00897                         {
00898                                 object->updateInventory(
00899                                         new_item,
00900                                         TASK_INVENTORY_ITEM_KEY,
00901                                         false);
00902                         }
00903                 }
00904         }
00905         else
00906         {
00907                 // need to make sure we don't just follow the click
00908                 refresh();
00909         }
00910 }
00911 
00912 LLInventoryItem* LLFloaterProperties::findItem() const
00913 {
00914         LLInventoryItem* item = NULL;
00915         if(mObjectID.isNull())
00916         {
00917                 // it is in agent inventory
00918                 item = gInventory.getItem(mItemID);
00919         }
00920         else
00921         {
00922                 LLViewerObject* object = gObjectList.findObject(mObjectID);
00923                 if(object)
00924                 {
00925                         item = (LLInventoryItem*)object->getInventoryObject(mItemID);
00926                 }
00927         }
00928         return item;
00929 }
00930 
00931 void LLFloaterProperties::closeByID(const LLUUID& item_id, const LLUUID &object_id)
00932 {
00933         LLFloaterProperties* floaterp = find(item_id, object_id);
00934 
00935         if (floaterp)
00936         {
00937                 floaterp->close();
00938         }
00939 }
00940 
00944 
00945 LLMultiProperties::LLMultiProperties(const LLRect &rect) : LLMultiFloater("Properties", rect)
00946 {
00947 }
00948 

Generated on Fri May 16 08:33:29 2008 for SecondLife by  doxygen 1.5.5