llfloaterinspect.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 #include "llfloateravatarinfo.h"
00034 #include "llfloaterinspect.h"
00035 #include "llfloatertools.h"
00036 #include "llcachename.h"
00037 #include "llscrolllistctrl.h"
00038 #include "llselectmgr.h"
00039 #include "lltoolcomp.h"
00040 #include "lltoolmgr.h"
00041 #include "llviewercontrol.h"
00042 #include "llviewerobject.h"
00043 #include "llvieweruictrlfactory.h"
00044 
00045 LLFloaterInspect* LLFloaterInspect::sInstance = NULL;
00046 
00047 LLFloaterInspect::LLFloaterInspect(void) :
00048         LLFloater("Inspect Object"),
00049         mDirty(FALSE)
00050 {
00051         sInstance = this;
00052         gUICtrlFactory->buildFloater(this, "floater_inspect.xml");
00053 }
00054 
00055 LLFloaterInspect::~LLFloaterInspect(void)
00056 {
00057         if(!gFloaterTools->getVisible())
00058         {
00059                 if(gToolMgr->getBaseTool() == gToolInspect)
00060                 {
00061                         gToolMgr->clearTransientTool();
00062                 }
00063                 // Switch back to basic toolset
00064                 gToolMgr->setCurrentToolset(gBasicToolset);     
00065         }
00066         else
00067         {
00068                 gFloaterTools->setFocus(TRUE);
00069         }
00070         sInstance = NULL;
00071 }
00072 
00073 BOOL LLFloaterInspect::isVisible()
00074 {
00075         return (!!sInstance);
00076 }
00077 
00078 void LLFloaterInspect::show(void* ignored)
00079 {
00080         // setForceSelection ensures that the pie menu does not deselect things when it 
00081         // looses the focus (this can happen with "select own objects only" enabled
00082         // VWR-1471
00083         BOOL forcesel = gSelectMgr->setForceSelection(TRUE);
00084 
00085         if (!sInstance) // first use
00086         {
00087                 sInstance = new LLFloaterInspect;
00088         }
00089 
00090         sInstance->open();
00091         gToolMgr->setTransientTool(gToolInspect);
00092         gSelectMgr->setForceSelection(forcesel);        // restore previouis value
00093 
00094         sInstance->mObjectSelection = gSelectMgr->getSelection();
00095         sInstance->refresh();
00096 }
00097 
00098 void LLFloaterInspect::onClickCreatorProfile(void* ctrl)
00099 {
00100         if(sInstance->mObjectList->getAllSelected().size() == 0)
00101         {
00102                 return;
00103         }
00104         LLScrollListItem* first_selected =
00105                 sInstance->mObjectList->getFirstSelected();
00106 
00107         if (first_selected)
00108         {
00109                 struct f : public LLSelectedNodeFunctor
00110                 {
00111                         LLUUID obj_id;
00112                         f(const LLUUID& id) : obj_id(id) {}
00113                         virtual bool apply(LLSelectNode* node)
00114                         {
00115                                 return (obj_id == node->getObject()->getID());
00116                         }
00117                 } func(first_selected->getUUID());
00118                 LLSelectNode* node = sInstance->mObjectSelection->getFirstNode(&func);
00119                 if(node)
00120                 {
00121                         LLFloaterAvatarInfo::showFromDirectory(node->mPermissions->getCreator());
00122                 }
00123         }
00124 }
00125 
00126 void LLFloaterInspect::onClickOwnerProfile(void* ctrl)
00127 {
00128         if(sInstance->mObjectList->getAllSelected().size() == 0) return;
00129         LLScrollListItem* first_selected =
00130                 sInstance->mObjectList->getFirstSelected();
00131 
00132         if (first_selected)
00133         {
00134                 LLUUID selected_id = first_selected->getUUID();
00135                 struct f : public LLSelectedNodeFunctor
00136                 {
00137                         LLUUID obj_id;
00138                         f(const LLUUID& id) : obj_id(id) {}
00139                         virtual bool apply(LLSelectNode* node)
00140                         {
00141                                 return (obj_id == node->getObject()->getID());
00142                         }
00143                 } func(selected_id);
00144                 LLSelectNode* node = sInstance->mObjectSelection->getFirstNode(&func);
00145                 if(node)
00146                 {
00147                         const LLUUID& owner_id = node->mPermissions->getOwner();
00148                         LLFloaterAvatarInfo::showFromDirectory(owner_id);
00149                 }
00150         }
00151 }
00152 
00153 BOOL LLFloaterInspect::postBuild()
00154 {
00155         mObjectList = LLUICtrlFactory::getScrollListByName(this, "object_list");
00156         childSetAction("button owner",onClickOwnerProfile, this);
00157         childSetAction("button creator",onClickCreatorProfile, this);
00158         childSetCommitCallback("object_list", onSelectObject);
00159         return TRUE;
00160 }
00161 
00162 void LLFloaterInspect::onSelectObject(LLUICtrl* ctrl, void* user_data)
00163 {
00164         if(LLFloaterInspect::getSelectedUUID() != LLUUID::null)
00165         {
00166                 sInstance->childSetEnabled("button owner", true);
00167                 sInstance->childSetEnabled("button creator", true);
00168         }
00169 }
00170 
00171 LLUUID LLFloaterInspect::getSelectedUUID()
00172 {
00173         if(sInstance)
00174         {
00175                 if(sInstance->mObjectList->getAllSelected().size() > 0)
00176                 {
00177                         LLScrollListItem* first_selected =
00178                                 sInstance->mObjectList->getFirstSelected();
00179                         if (first_selected)
00180                         {
00181                                 return first_selected->getUUID();
00182                         }
00183                 }
00184         }
00185         return LLUUID::null;
00186 }
00187 
00188 void LLFloaterInspect::refresh()
00189 {
00190         LLUUID creator_id;
00191         LLString creator_name;
00192         S32 pos = mObjectList->getScrollPos();
00193         childSetEnabled("button owner", false);
00194         childSetEnabled("button creator", false);
00195         LLUUID selected_uuid;
00196         S32 selected_index = mObjectList->getFirstSelectedIndex();
00197         if(selected_index > -1)
00198         {
00199                 LLScrollListItem* first_selected =
00200                         mObjectList->getFirstSelected();
00201                 if (first_selected)
00202                 {
00203                         selected_uuid = first_selected->getUUID();
00204                 }
00205         }
00206         mObjectList->operateOnAll(LLScrollListCtrl::OP_DELETE);
00207         //List all transient objects, then all linked objects
00208 
00209         for (LLObjectSelection::iterator iter = mObjectSelection->begin();
00210                  iter != mObjectSelection->end(); iter++)
00211         {
00212                 LLSelectNode* obj = *iter;
00213                 LLSD row;
00214                 char owner_first_name[MAX_STRING], owner_last_name[MAX_STRING];
00215                 char creator_first_name[MAX_STRING], creator_last_name[MAX_STRING];
00216                 char time[MAX_STRING];
00217                 std::ostringstream owner_name, creator_name, date;
00218                 time_t timestamp = (time_t) (obj->mCreationDate/1000000);
00219                 LLString::copy(time, ctime(&timestamp), MAX_STRING);
00220                 time[24] = '\0';
00221                 date << obj->mCreationDate;
00222                 gCacheName->getName(obj->mPermissions->getOwner(), owner_first_name, owner_last_name);
00223                 owner_name << owner_first_name << " " << owner_last_name;
00224                 gCacheName->getName(obj->mPermissions->getCreator(), creator_first_name, creator_last_name);
00225                 creator_name << creator_first_name << " " << creator_last_name;
00226                 row["id"] = obj->getObject()->getID();
00227                 row["columns"][0]["column"] = "object_name";
00228                 row["columns"][0]["type"] = "text";
00229                 // make sure we're either at the top of the link chain
00230                 // or top of the editable chain, for attachments
00231                 if(!(obj->getObject()->isRoot() || obj->getObject()->isRootEdit()))
00232                 {
00233                         row["columns"][0]["value"] = LLString("   ") + obj->mName;
00234                 }
00235                 else
00236                 {
00237                         row["columns"][0]["value"] = obj->mName;
00238                 }
00239                 row["columns"][1]["column"] = "owner_name";
00240                 row["columns"][1]["type"] = "text";
00241                 row["columns"][1]["value"] = owner_name.str().c_str();
00242                 row["columns"][2]["column"] = "creator_name";
00243                 row["columns"][2]["type"] = "text";
00244                 row["columns"][2]["value"] = creator_name.str().c_str();
00245                 row["columns"][3]["column"] = "creation_date";
00246                 row["columns"][3]["type"] = "text";
00247                 row["columns"][3]["value"] = time;
00248                 mObjectList->addElement(row, ADD_TOP);
00249         }
00250         if(selected_index > -1 && mObjectList->getItemIndex(selected_uuid) == selected_index)
00251         {
00252                 mObjectList->selectNthItem(selected_index);
00253         }
00254         else
00255         {
00256                 mObjectList->selectNthItem(0);
00257         }
00258         onSelectObject(this, NULL);
00259         mObjectList->setScrollPos(pos);
00260 }
00261 
00262 void LLFloaterInspect::onFocusReceived()
00263 {
00264         gToolMgr->setTransientTool(gToolInspect);
00265 }
00266 
00267 void LLFloaterInspect::dirty()
00268 {
00269         if(sInstance)
00270         {
00271                 sInstance->setDirty();
00272         }
00273 }
00274 
00275 void LLFloaterInspect::draw()
00276 {
00277         if (mDirty)
00278         {
00279                 refresh();
00280                 mDirty = FALSE;
00281         }
00282 
00283         LLFloater::draw();
00284 }

Generated on Thu Jul 1 06:08:34 2010 for Second Life Viewer by  doxygen 1.4.7