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 "llvieweruictrlfactory.h"
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 class LLPropertiesObserver : public LLInventoryObserver
00069 {
00070 public:
00071         LLPropertiesObserver() {}
00072         virtual ~LLPropertiesObserver() {}
00073         virtual void changed(U32 mask);
00074 };
00075 
00076 LLPropertiesObserver* gPropertiesObserver = NULL;
00077 void LLPropertiesObserver::changed(U32 mask)
00078 {
00079         
00080         if((mask & (LLInventoryObserver::LABEL | LLInventoryObserver::INTERNAL | LLInventoryObserver::REMOVE)) != 0)
00081         {
00082                 LLFloaterProperties::dirtyAll();
00083         }
00084 }
00085 
00086 
00087 
00091 
00092 LLFloaterProperties::instance_map LLFloaterProperties::sInstances;
00093 
00094 
00095 LLFloaterProperties* LLFloaterProperties::find(const LLUUID& item_id,
00096                                                                                            const LLUUID& object_id)
00097 {
00098         
00099         
00100         
00101         
00102         instance_map::iterator it = sInstances.find(item_id ^ object_id);
00103         if(it != sInstances.end())
00104         {
00105                 return (*it).second;
00106         }
00107         return NULL;
00108 }
00109 
00110 
00111 LLFloaterProperties* LLFloaterProperties::show(const LLUUID& item_id,
00112                                                                                            const LLUUID& object_id)
00113 {
00114         LLFloaterProperties* instance = find(item_id, object_id);
00115         if(instance)
00116         {
00117                 if (LLFloater::getFloaterHost() && LLFloater::getFloaterHost() != instance->getHost())
00118                 {
00119                         
00120                         
00121                         LLFloater::getFloaterHost()->addFloater(instance, TRUE);
00122                 }
00123 
00124                 instance->refresh();
00125                 instance->open();               
00126         }
00127         return instance;
00128 }
00129 
00130 void LLFloaterProperties::dirtyAll()
00131 {
00132         
00133         
00134         for(instance_map::iterator it = sInstances.begin(); it!=sInstances.end(); )
00135         {
00136                 (*it++).second->dirty();
00137         }
00138 }
00139 
00140 
00141 LLFloaterProperties::LLFloaterProperties(const std::string& name, const LLRect& rect, const std::string& title, const LLUUID& item_id, const LLUUID& object_id) :
00142         LLFloater(name, rect, title),
00143         mItemID(item_id),
00144         mObjectID(object_id),
00145         mDirty(TRUE)
00146 {
00147         gUICtrlFactory->buildFloater(this,"floater_inventory_item_properties.xml");
00148 
00149         
00150         if(!gPropertiesObserver)
00151         {
00152                 gPropertiesObserver = new LLPropertiesObserver;
00153                 gInventory.addObserver(gPropertiesObserver);
00154         }
00155         
00156         LLUUID key = mItemID ^ mObjectID;
00157         sInstances.insert(instance_map::value_type(key, this));
00158         
00159         
00160         childSetPrevalidate("LabelItemName",&LLLineEditor::prevalidatePrintableNotPipe);
00161         childSetCommitCallback("LabelItemName",onCommitName,this);
00162         childSetPrevalidate("LabelItemDesc",&LLLineEditor::prevalidatePrintableNotPipe);
00163         childSetCommitCallback("LabelItemDesc", onCommitDescription, this);
00164         
00165         childSetAction("BtnCreator",onClickCreator,this);
00166         
00167         childSetAction("BtnOwner",onClickOwner,this);
00168         
00169         
00170         
00171         
00172         childSetCommitCallback("CheckShareWithGroup",&onCommitPermissions, this);
00173         
00174         childSetCommitCallback("CheckEveryoneCopy",&onCommitPermissions, this);
00175         
00176         childSetCommitCallback("CheckNextOwnerModify",&onCommitPermissions, this);
00177         childSetCommitCallback("CheckNextOwnerCopy",&onCommitPermissions, this);
00178         childSetCommitCallback("CheckNextOwnerTransfer",&onCommitPermissions, this);
00179         
00180         childSetCommitCallback("CheckPurchase",&onCommitSaleInfo, this);
00181         childSetCommitCallback("RadioSaleType",&onCommitSaleType, this);
00182         
00183         childSetCommitCallback("EditPrice",&onCommitSaleInfo, this);
00184         
00185         refresh();
00186 }
00187 
00188 
00189 LLFloaterProperties::~LLFloaterProperties()
00190 {
00191         
00192         instance_map::iterator it = sInstances.find(mItemID ^ mObjectID);
00193         if(it != sInstances.end())
00194         {
00195                 sInstances.erase(it);
00196         }
00197 }
00198 
00199 void LLFloaterProperties::refresh()
00200 {
00201         LLInventoryItem* item = findItem();
00202         if(item)
00203         {
00204                 refreshFromItem(item);
00205         }
00206         else
00207         {
00208                 
00209                 
00210                 
00211                 mDirty = TRUE;
00212 
00213                 const char* enableNames[]={
00214                         "LabelItemName",
00215                         "LabelItemDesc",
00216                         "LabelCreatorName",
00217                         "BtnCreator",
00218                         "LabelOwnerName",
00219                         "BtnOwner",
00220                         "CheckOwnerModify",
00221                         "CheckOwnerCopy",
00222                         "CheckOwnerTransfer",
00223                         "CheckShareWithGroup",
00224                         "CheckEveryoneCopy",
00225                         "CheckNextOwnerModify",
00226                         "CheckNextOwnerCopy",
00227                         "CheckNextOwnerTransfer",
00228                         "CheckPurchase",
00229                         "RadioSaleType",
00230                         "EditPrice"
00231                 };
00232                 for(size_t t=0; t<sizeof(enableNames)/sizeof(char*); ++t)
00233                 {
00234                         childSetEnabled(enableNames[t],false);
00235                 }
00236                 const char* hideNames[]={
00237                         "BaseMaskDebug",
00238                         "OwnerMaskDebug",
00239                         "GroupMaskDebug",
00240                         "EveryoneMaskDebug",
00241                         "NextMaskDebug"
00242                 };
00243                 for(size_t t=0; t<sizeof(hideNames)/sizeof(char*); ++t)
00244                 {
00245                         childSetVisible(hideNames[t],false);
00246                 }
00247         }
00248 }
00249 
00250 void LLFloaterProperties::draw()
00251 {
00252         if (mDirty)
00253         {
00254                 
00255                 mDirty = FALSE;
00256                 refresh();
00257         }
00258 
00259         LLFloater::draw();
00260 }
00261 
00262 void LLFloaterProperties::refreshFromItem(LLInventoryItem* item)
00263 {
00265         
00267 
00268         
00269         LLViewerInventoryItem* i = (LLViewerInventoryItem*)item;
00270         BOOL is_complete = i->isComplete();
00271 
00272         const LLPermissions& perm = item->getPermissions();
00273         BOOL can_agent_manipulate = gAgent.allowOperation(PERM_OWNER, perm, 
00274                                                                                                 GP_OBJECT_MANIPULATE);
00275         BOOL can_agent_sell = gAgent.allowOperation(PERM_OWNER, perm, 
00276                                                                                                 GP_OBJECT_SET_SALE);
00277 
00278         
00279         
00280         LLViewerObject* object = NULL;
00281         if(!mObjectID.isNull()) object = gObjectList.findObject(mObjectID);
00282         BOOL is_obj_modify = TRUE;
00283         if(object)
00284         {
00285                 is_obj_modify = object->permOwnerModify();
00286         }
00287 
00289         
00291         BOOL is_modifiable = gAgent.allowOperation(PERM_MODIFY, perm,
00292                                                                                                 GP_OBJECT_MANIPULATE)
00293                                                         && is_obj_modify && is_complete;
00294 
00295         childSetEnabled("LabelItemNameTitle",TRUE);
00296         childSetEnabled("LabelItemName",is_modifiable);
00297         childSetText("LabelItemName",item->getName());
00298         childSetEnabled("LabelItemDescTitle",TRUE);
00299         childSetEnabled("LabelItemDesc",is_modifiable);
00300         childSetVisible("IconLocked",!is_modifiable);
00301         childSetText("LabelItemDesc",item->getDescription());
00302 
00304         
00306         char first_name[DB_FIRST_NAME_BUF_SIZE];                
00307         char last_name[DB_LAST_NAME_BUF_SIZE];          
00308         if(!gCacheName) return;
00309         if(!gAgent.getRegion()) return;
00310 
00311         if (item->getCreatorUUID().notNull())
00312         {
00313                 gCacheName->getName(item->getCreatorUUID(), first_name, last_name);
00314                 LLString name(first_name);
00315                 name.append(1, ' ');
00316                 name.append(last_name);
00317 
00318                 childSetEnabled("BtnCreator",TRUE);
00319                 childSetEnabled("LabelCreatorTitle",TRUE);
00320                 childSetEnabled("LabelCreatorName",TRUE);
00321                 childSetText("LabelCreatorName",name);
00322         }
00323         else
00324         {
00325                 childSetEnabled("BtnCreator",FALSE);
00326                 childSetEnabled("LabelCreatorTitle",FALSE);
00327                 childSetEnabled("LabelCreatorName",FALSE);
00328                 childSetText("LabelCreatorName",childGetText("unknown"));
00329         }
00330 
00332         
00334         if(perm.isOwned())
00335         {
00336                 LLString name;
00337                 if (perm.isGroupOwned())
00338                 {
00339                         char group_name[DB_GROUP_NAME_BUF_SIZE];                
00340                         gCacheName->getGroupName(perm.getGroup(), group_name);
00341                         name.assign(group_name);
00342                 }
00343                 else
00344                 {
00345                         gCacheName->getName(perm.getOwner(), first_name, last_name);
00346                         name.assign(first_name);
00347                         name.append(1, ' ');
00348                         name.append(last_name);
00349                 }
00350                 childSetEnabled("BtnOwner",TRUE);
00351                 childSetEnabled("LabelOwnerTitle",TRUE);
00352                 childSetEnabled("LabelOwnerName",TRUE);
00353                 childSetText("LabelOwnerName",name);
00354         }
00355         else
00356         {
00357                 childSetEnabled("BtnOwner",FALSE);
00358                 childSetEnabled("LabelOwnerTitle",FALSE);
00359                 childSetEnabled("LabelOwnerName",FALSE);
00360                 childSetText("LabelOwnerName",childGetText("public"));
00361         }
00362         
00364         
00366 
00367         
00368         time_t time_utc = (time_t)item->getCreationDate();
00369         if (0 == time_utc)
00370         {
00371                 childSetText("LabelAcquiredDate",childGetText("unknown"));
00372         }
00373         else
00374         {
00375                 childSetText("LabelAcquiredDate", LLString(ctime(&time_utc)) );
00376         }
00377 
00379         
00381         if(can_agent_manipulate)
00382         {
00383                 childSetText("OwnerLabel",childGetText("you_can"));
00384         }
00385         else
00386         {
00387                 childSetText("OwnerLabel",childGetText("owner_can"));
00388         }
00389 
00390         U32 base_mask           = perm.getMaskBase();
00391         U32 owner_mask          = perm.getMaskOwner();
00392         U32 group_mask          = perm.getMaskGroup();
00393         U32 everyone_mask       = perm.getMaskEveryone();
00394         U32 next_owner_mask     = perm.getMaskNextOwner();
00395 
00396         childSetEnabled("OwnerLabel",TRUE);
00397         childSetEnabled("CheckOwnerModify",FALSE);
00398         childSetValue("CheckOwnerModify",LLSD((BOOL)(owner_mask & PERM_MODIFY)));
00399         childSetEnabled("CheckOwnerCopy",FALSE);
00400         childSetValue("CheckOwnerCopy",LLSD((BOOL)(owner_mask & PERM_COPY)));
00401         childSetEnabled("CheckOwnerTransfer",FALSE);
00402         childSetValue("CheckOwnerTransfer",LLSD((BOOL)(owner_mask & PERM_TRANSFER)));
00403 
00405         
00407 
00408         if( gSavedSettings.getBOOL("DebugPermissions") )
00409         {
00410                 BOOL slam_perm                  = FALSE;
00411                 BOOL overwrite_group    = FALSE;
00412                 BOOL overwrite_everyone = FALSE;
00413 
00414                 if (item->getType() == LLAssetType::AT_OBJECT)
00415                 {
00416                         U32 flags = item->getFlags();
00417                         slam_perm                       = flags & LLInventoryItem::II_FLAGS_OBJECT_SLAM_PERM;
00418                         overwrite_everyone      = flags & LLInventoryItem::II_FLAGS_OBJECT_PERM_OVERWRITE_EVERYONE;
00419                         overwrite_group         = flags & LLInventoryItem::II_FLAGS_OBJECT_PERM_OVERWRITE_GROUP;
00420                 }
00421                 
00422                 std::string perm_string;
00423 
00424                 perm_string = "B: ";
00425                 perm_string += mask_to_string(base_mask);
00426                 childSetText("BaseMaskDebug",perm_string);
00427                 childSetVisible("BaseMaskDebug",TRUE);
00428                 
00429                 perm_string = "O: ";
00430                 perm_string += mask_to_string(owner_mask);
00431                 childSetText("OwnerMaskDebug",perm_string);
00432                 childSetVisible("OwnerMaskDebug",TRUE);
00433                 
00434                 perm_string = "G";
00435                 perm_string += overwrite_group ? "*: " : ": ";
00436                 perm_string += perm_string += mask_to_string(group_mask);
00437                 childSetText("GroupMaskDebug",perm_string);
00438                 childSetVisible("GroupMaskDebug",TRUE);
00439                 
00440                 perm_string = "E";
00441                 perm_string += overwrite_everyone ? "*: " : ": ";
00442                 perm_string += mask_to_string(everyone_mask);
00443                 childSetText("EveryoneMaskDebug",perm_string);
00444                 childSetVisible("EveryoneMaskDebug",TRUE);
00445                 
00446                 perm_string = "N";
00447                 perm_string += slam_perm ? "*: " : ": ";
00448                 perm_string += mask_to_string(next_owner_mask);
00449                 childSetText("NextMaskDebug",perm_string);
00450                 childSetVisible("NextMaskDebug",TRUE);
00451         }
00452         else
00453         {
00454                 childSetVisible("BaseMaskDebug",FALSE);
00455                 childSetVisible("OwnerMaskDebug",FALSE);
00456                 childSetVisible("GroupMaskDebug",FALSE);
00457                 childSetVisible("EveryoneMaskDebug",FALSE);
00458                 childSetVisible("NextMaskDebug",FALSE);
00459         }
00460 
00462         
00464 
00465         
00466         if (is_obj_modify && can_agent_manipulate)
00467         {
00468                 childSetEnabled("CheckShareWithGroup",TRUE);
00469                 childSetEnabled("CheckEveryoneCopy",(owner_mask & PERM_COPY) && (owner_mask & PERM_TRANSFER));
00470         }
00471         else
00472         {
00473                 childSetEnabled("CheckShareWithGroup",FALSE);
00474                 childSetEnabled("CheckEveryoneCopy",FALSE);
00475         }
00476 
00477         
00478         BOOL is_group_copy = (group_mask & PERM_COPY) ? TRUE : FALSE;
00479         BOOL is_group_modify = (group_mask & PERM_MODIFY) ? TRUE : FALSE;
00480         BOOL is_group_move = (group_mask & PERM_MOVE) ? TRUE : FALSE;
00481 
00482         if (is_group_copy && is_group_modify && is_group_move)
00483         {
00484                 childSetValue("CheckShareWithGroup",LLSD((BOOL)TRUE));
00485 
00486                 LLCheckBoxCtrl* ctl = LLUICtrlFactory::getCheckBoxByName(this,"CheckShareWithGroup");
00487                 if(ctl)
00488                 {
00489                         ctl->setTentative(FALSE);
00490                 }
00491         }
00492         else if (!is_group_copy && !is_group_modify && !is_group_move)
00493         {
00494                 childSetValue("CheckShareWithGroup",LLSD((BOOL)FALSE));
00495                 LLCheckBoxCtrl* ctl = LLUICtrlFactory::getCheckBoxByName(this,"CheckShareWithGroup");
00496                 if(ctl)
00497                 {
00498                         ctl->setTentative(FALSE);
00499                 }
00500         }
00501         else
00502         {
00503                 LLCheckBoxCtrl* ctl = LLUICtrlFactory::getCheckBoxByName(this,"CheckShareWithGroup");
00504                 if(ctl)
00505                 {
00506                         ctl->setTentative(TRUE);
00507                         ctl->set(TRUE);
00508                 }
00509         }
00510         
00511         childSetValue("CheckEveryoneCopy",LLSD((BOOL)(everyone_mask & PERM_COPY)));
00512 
00514         
00516 
00517         const LLSaleInfo& sale_info = item->getSaleInfo();
00518         BOOL is_for_sale = sale_info.isForSale();
00519         
00520         if (is_obj_modify && can_agent_sell 
00521                 && gAgent.allowOperation(PERM_TRANSFER, perm, GP_OBJECT_MANIPULATE))
00522         {
00523                 childSetEnabled("SaleLabel",is_complete);
00524                 childSetEnabled("CheckPurchase",is_complete);
00525 
00526                 childSetEnabled("NextOwnerLabel",TRUE);
00527                 childSetEnabled("CheckNextOwnerModify",base_mask & PERM_MODIFY);
00528                 childSetEnabled("CheckNextOwnerCopy",base_mask & PERM_COPY);
00529                 childSetEnabled("CheckNextOwnerTransfer",next_owner_mask & PERM_COPY);
00530 
00531                 childSetEnabled("RadioSaleType",is_complete && is_for_sale);
00532                 childSetEnabled("TextPrice",is_complete && is_for_sale);
00533                 childSetEnabled("EditPrice",is_complete && is_for_sale);
00534         }
00535         else
00536         {
00537                 childSetEnabled("SaleLabel",FALSE);
00538                 childSetEnabled("CheckPurchase",FALSE);
00539 
00540                 childSetEnabled("NextOwnerLabel",FALSE);
00541                 childSetEnabled("CheckNextOwnerModify",FALSE);
00542                 childSetEnabled("CheckNextOwnerCopy",FALSE);
00543                 childSetEnabled("CheckNextOwnerTransfer",FALSE);
00544 
00545                 childSetEnabled("RadioSaleType",FALSE);
00546                 childSetEnabled("TextPrice",FALSE);
00547                 childSetEnabled("EditPrice",FALSE);
00548         }
00549 
00550         
00551         childSetValue("CheckPurchase", is_for_sale);
00552         childSetValue("CheckNextOwnerModify",LLSD(BOOL(next_owner_mask & PERM_MODIFY)));
00553         childSetValue("CheckNextOwnerCopy",LLSD(BOOL(next_owner_mask & PERM_COPY)));
00554         childSetValue("CheckNextOwnerTransfer",LLSD(BOOL(next_owner_mask & PERM_TRANSFER)));
00555 
00556         LLRadioGroup* radioSaleType = LLUICtrlFactory::getRadioGroupByName(this,"RadioSaleType");
00557         if (is_for_sale)
00558         {
00559                 radioSaleType->setSelectedIndex((S32)sale_info.getSaleType() - 1);
00560                 S32 numerical_price;
00561                 numerical_price = sale_info.getSalePrice();
00562                 childSetText("EditPrice",llformat("%d",numerical_price));
00563         }
00564         else
00565         {
00566                 radioSaleType->setSelectedIndex(-1);
00567                 childSetText("EditPrice",llformat("%d",0));
00568         }
00569 }
00570 
00571 
00572 void LLFloaterProperties::onClickCreator(void* data)
00573 {
00574         LLFloaterProperties* self = (LLFloaterProperties*)data;
00575         if(!self) return;
00576         LLInventoryItem* item = self->findItem();
00577         if(!item) return;
00578         if(!item->getCreatorUUID().isNull())
00579         {
00580                 LLFloaterAvatarInfo::showFromObject(item->getCreatorUUID());
00581         }
00582 }
00583 
00584 
00585 void LLFloaterProperties::onClickOwner(void* data)
00586 {
00587         LLFloaterProperties* self = (LLFloaterProperties*)data;
00588         if(!self) return;
00589         LLInventoryItem* item = self->findItem();
00590         if(!item) return;
00591         if(item->getPermissions().isGroupOwned())
00592         {
00593                 LLFloaterGroupInfo::showFromUUID(item->getPermissions().getGroup());
00594         }
00595         else
00596         {
00597                 if(!item->getPermissions().getOwner().isNull())
00598                 {
00599                         LLFloaterAvatarInfo::showFromObject(item->getPermissions().getOwner());
00600                 }
00601         }
00602 }
00603 
00604 
00605 void LLFloaterProperties::onCommitName(LLUICtrl* ctrl, void* data)
00606 {
00607         
00608         LLFloaterProperties* self = (LLFloaterProperties*)data;
00609         if(!self)
00610         {
00611                 return;
00612         }
00613         LLViewerInventoryItem* item = (LLViewerInventoryItem*)self->findItem();
00614         if(!item)
00615         {
00616                 return;
00617         }
00618         LLLineEditor* labelItemName = LLUICtrlFactory::getLineEditorByName(self,"LabelItemName");
00619 
00620         if(labelItemName&&
00621            (item->getName() != labelItemName->getText()) && 
00622            (gAgent.allowOperation(PERM_MODIFY, item->getPermissions(), GP_OBJECT_MANIPULATE)) )
00623         {
00624                 LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
00625                 new_item->rename(labelItemName->getText());
00626                 if(self->mObjectID.isNull())
00627                 {
00628                         new_item->updateServer(FALSE);
00629                         gInventory.updateItem(new_item);
00630                         gInventory.notifyObservers();
00631                 }
00632                 else
00633                 {
00634                         LLViewerObject* object = gObjectList.findObject(self->mObjectID);
00635                         if(object)
00636                         {
00637                                 object->updateInventory(
00638                                         new_item,
00639                                         TASK_INVENTORY_ITEM_KEY,
00640                                         false);
00641                         }
00642                 }
00643         }
00644 }
00645 
00646 
00647 void LLFloaterProperties::onCommitDescription(LLUICtrl* ctrl, void* data)
00648 {
00649         
00650         LLFloaterProperties* self = (LLFloaterProperties*)data;
00651         if(!self) return;
00652         LLViewerInventoryItem* item = (LLViewerInventoryItem*)self->findItem();
00653         if(!item) return;
00654 
00655         LLLineEditor* labelItemDesc = LLUICtrlFactory::getLineEditorByName(self,"LabelItemDesc");
00656         if(!labelItemDesc)
00657         {
00658                 return;
00659         }
00660         if((item->getDescription() != labelItemDesc->getText()) && 
00661            (gAgent.allowOperation(PERM_MODIFY, item->getPermissions(), GP_OBJECT_MANIPULATE)))
00662         {
00663                 LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
00664 
00665                 new_item->setDescription(labelItemDesc->getText());
00666                 if(self->mObjectID.isNull())
00667                 {
00668                         new_item->updateServer(FALSE);
00669                         gInventory.updateItem(new_item);
00670                         gInventory.notifyObservers();
00671                 }
00672                 else
00673                 {
00674                         LLViewerObject* object = gObjectList.findObject(self->mObjectID);
00675                         if(object)
00676                         {
00677                                 object->updateInventory(
00678                                         new_item,
00679                                         TASK_INVENTORY_ITEM_KEY,
00680                                         false);
00681                         }
00682                 }
00683         }
00684 }
00685 
00686 
00687 void LLFloaterProperties::onCommitPermissions(LLUICtrl* ctrl, void* data)
00688 {
00689         
00690         LLFloaterProperties* self = (LLFloaterProperties*)data;
00691         if(!self) return;
00692         LLViewerInventoryItem* item = (LLViewerInventoryItem*)self->findItem();
00693         if(!item) return;
00694         LLPermissions perm(item->getPermissions());
00695 
00696 
00697         LLCheckBoxCtrl* CheckShareWithGroup = LLUICtrlFactory::getCheckBoxByName(self,"CheckShareWithGroup");
00698 
00699         if(CheckShareWithGroup)
00700         {
00701                 perm.setGroupBits(gAgent.getID(), gAgent.getGroupID(),
00702                                                 CheckShareWithGroup->get(),
00703                                                 PERM_MODIFY | PERM_MOVE | PERM_COPY);
00704         }
00705         LLCheckBoxCtrl* CheckEveryoneCopy = LLUICtrlFactory::getCheckBoxByName(self,"CheckEveryoneCopy");
00706         if(CheckEveryoneCopy)
00707         {
00708                 perm.setEveryoneBits(gAgent.getID(), gAgent.getGroupID(),
00709                                                  CheckEveryoneCopy->get(), PERM_COPY);
00710         }
00711 
00712         LLCheckBoxCtrl* CheckNextOwnerModify = LLUICtrlFactory::getCheckBoxByName(self,"CheckNextOwnerModify");
00713         if(CheckNextOwnerModify)
00714         {
00715                 perm.setNextOwnerBits(gAgent.getID(), gAgent.getGroupID(),
00716                                                         CheckNextOwnerModify->get(), PERM_MODIFY);
00717         }
00718         LLCheckBoxCtrl* CheckNextOwnerCopy = LLUICtrlFactory::getCheckBoxByName(self,"CheckNextOwnerCopy");
00719         if(CheckNextOwnerCopy)
00720         {
00721                 perm.setNextOwnerBits(gAgent.getID(), gAgent.getGroupID(),
00722                                                         CheckNextOwnerCopy->get(), PERM_COPY);
00723         }
00724         LLCheckBoxCtrl* CheckNextOwnerTransfer = LLUICtrlFactory::getCheckBoxByName(self,"CheckNextOwnerTransfer");
00725         if(CheckNextOwnerTransfer)
00726         {
00727                 perm.setNextOwnerBits(gAgent.getID(), gAgent.getGroupID(),
00728                                                         CheckNextOwnerTransfer->get(), PERM_TRANSFER);
00729         }
00730         if(perm != item->getPermissions()
00731                 && item->isComplete())
00732         {
00733                 LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
00734                 new_item->setPermissions(perm);
00735                 U32 flags = new_item->getFlags();
00736                 
00737                 
00738                 if((perm.getMaskNextOwner()!=item->getPermissions().getMaskNextOwner())
00739                    && (item->getType() == LLAssetType::AT_OBJECT))
00740                 {
00741                         flags |= LLInventoryItem::II_FLAGS_OBJECT_SLAM_PERM;
00742                 }
00743                 
00744                 
00745                 
00746                 if ((perm.getMaskEveryone()!=item->getPermissions().getMaskEveryone())
00747                         && (item->getType() == LLAssetType::AT_OBJECT))
00748                 {
00749                         flags |= LLInventoryItem::II_FLAGS_OBJECT_PERM_OVERWRITE_EVERYONE;
00750                 }
00751                 
00752                 
00753                 
00754                 if ((perm.getMaskGroup()!=item->getPermissions().getMaskGroup())
00755                         && (item->getType() == LLAssetType::AT_OBJECT))
00756                 {
00757                         flags |= LLInventoryItem::II_FLAGS_OBJECT_PERM_OVERWRITE_GROUP;
00758                 }
00759                 new_item->setFlags(flags);
00760                 if(self->mObjectID.isNull())
00761                 {
00762                         new_item->updateServer(FALSE);
00763                         gInventory.updateItem(new_item);
00764                         gInventory.notifyObservers();
00765                 }
00766                 else
00767                 {
00768                         LLViewerObject* object = gObjectList.findObject(self->mObjectID);
00769                         if(object)
00770                         {
00771                                 object->updateInventory(
00772                                         new_item,
00773                                         TASK_INVENTORY_ITEM_KEY,
00774                                         false);
00775                         }
00776                 }
00777         }
00778         else
00779         {
00780                 
00781                 self->refresh();
00782         }
00783 }
00784 
00785 
00786 void LLFloaterProperties::onCommitSaleInfo(LLUICtrl* ctrl, void* data)
00787 {
00788         
00789         LLFloaterProperties* self = (LLFloaterProperties*)data;
00790         if(!self) return;
00791         self->updateSaleInfo();
00792 }
00793 
00794 
00795 void LLFloaterProperties::onCommitSaleType(LLUICtrl* ctrl, void* data)
00796 {
00797         
00798         LLFloaterProperties* self = (LLFloaterProperties*)data;
00799         if(!self) return;
00800         self->updateSaleInfo();
00801 }
00802 
00803 void LLFloaterProperties::updateSaleInfo()
00804 {
00805         LLViewerInventoryItem* item = (LLViewerInventoryItem*)findItem();
00806         if(!item) return;
00807         LLSaleInfo sale_info(item->getSaleInfo());
00808         if(!gAgent.allowOperation(PERM_TRANSFER, item->getPermissions(), GP_OBJECT_SET_SALE))
00809         {
00810                 childSetValue("CheckPurchase",LLSD((BOOL)FALSE));
00811         }
00812 
00813         if((BOOL)childGetValue("CheckPurchase"))
00814         {
00815                 
00816                 LLSaleInfo::EForSale sale_type = LLSaleInfo::FS_COPY;
00817         
00818                 LLRadioGroup* RadioSaleType = LLUICtrlFactory::getRadioGroupByName(this,"RadioSaleType");
00819                 if(RadioSaleType)
00820                 {
00821                         switch (RadioSaleType->getSelectedIndex())
00822                         {
00823                         case 0:
00824                                 sale_type = LLSaleInfo::FS_ORIGINAL;
00825                                 break;
00826                         case 1:
00827                                 sale_type = LLSaleInfo::FS_COPY;
00828                                 break;
00829                         case 2:
00830                                 sale_type = LLSaleInfo::FS_CONTENTS;
00831                                 break;
00832                         default:
00833                                 sale_type = LLSaleInfo::FS_COPY;
00834                                 break;
00835                         }
00836                 }
00837 
00838                 if (sale_type == LLSaleInfo::FS_COPY 
00839                         && !gAgent.allowOperation(PERM_COPY, item->getPermissions(), 
00840                                                                           GP_OBJECT_SET_SALE))
00841                 {
00842                         sale_type = LLSaleInfo::FS_ORIGINAL;
00843                 }
00844 
00845                 LLLineEditor* EditPrice = LLUICtrlFactory::getLineEditorByName(this,"EditPrice");
00846                 
00847                 S32 price = -1;
00848                 if(EditPrice)
00849                 {
00850                         price = atoi(EditPrice->getText().c_str());
00851                 }
00852                 
00853                 if (price < 0)
00854                 {
00855                         sale_type = LLSaleInfo::FS_NOT;
00856                         price = 0;
00857                 }
00858 
00859                 sale_info.setSaleType(sale_type);
00860                 sale_info.setSalePrice(price);
00861         }
00862         else
00863         {
00864                 sale_info.setSaleType(LLSaleInfo::FS_NOT);
00865         }
00866         if(sale_info != item->getSaleInfo()
00867                 && item->isComplete())
00868         {
00869                 LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
00870                 new_item->setSaleInfo(sale_info);
00871                 if(mObjectID.isNull())
00872                 {
00873                         
00874                         new_item->updateServer(FALSE);
00875                         gInventory.updateItem(new_item);
00876                         gInventory.notifyObservers();
00877                 }
00878                 else
00879                 {
00880                         
00881                         LLViewerObject* object = gObjectList.findObject(mObjectID);
00882                         if(object)
00883                         {
00884                                 object->updateInventory(
00885                                         new_item,
00886                                         TASK_INVENTORY_ITEM_KEY,
00887                                         false);
00888                         }
00889                 }
00890         }
00891         else
00892         {
00893                 
00894                 refresh();
00895         }
00896 }
00897 
00898 LLInventoryItem* LLFloaterProperties::findItem() const
00899 {
00900         LLInventoryItem* item = NULL;
00901         if(mObjectID.isNull())
00902         {
00903                 
00904                 item = gInventory.getItem(mItemID);
00905         }
00906         else
00907         {
00908                 LLViewerObject* object = gObjectList.findObject(mObjectID);
00909                 if(object)
00910                 {
00911                         item = (LLInventoryItem*)object->getInventoryObject(mItemID);
00912                 }
00913         }
00914         return item;
00915 }
00916 
00917 void LLFloaterProperties::closeByID(const LLUUID& item_id, const LLUUID &object_id)
00918 {
00919         LLFloaterProperties* floaterp = find(item_id, object_id);
00920 
00921         if (floaterp)
00922         {
00923                 floaterp->close();
00924         }
00925 }
00926 
00930 
00931 LLMultiProperties::LLMultiProperties(const LLRect &rect) : LLMultiFloater("Properties", rect)
00932 {
00933 }
00934