llpanelgroupinvite.cpp

Go to the documentation of this file.
00001 
00031 #include "llviewerprecompiledheaders.h"
00032 
00033 #include "llpanelgroupinvite.h"
00034 
00035 #include "llagent.h"
00036 #include "llfloateravatarpicker.h"
00037 #include "llbutton.h"
00038 #include "llcombobox.h"
00039 #include "llgroupmgr.h"
00040 #include "llnamelistctrl.h"
00041 #include "llspinctrl.h"
00042 #include "lltextbox.h"
00043 #include "llviewerobject.h"
00044 #include "llviewerobjectlist.h"
00045 #include "llvieweruictrlfactory.h"
00046 
00047 class LLPanelGroupInvite::impl
00048 {
00049 public:
00050         impl(const LLUUID& group_id);
00051         ~impl();
00052 
00053         void addUsers(const std::vector<std::string>& names,
00054                                   const std::vector<LLUUID>& agent_ids);
00055         void submitInvitations();
00056         void addRoleNames(LLGroupMgrGroupData* gdatap);
00057         void handleRemove();
00058         void handleSelection();
00059 
00060         static void callbackClickCancel(void* userdata);
00061         static void callbackClickOK(void* userdata);
00062         static void callbackClickAdd(void* userdata);
00063         static void callbackClickRemove(void* userdata);
00064         static void callbackSelect(LLUICtrl* ctrl, void* userdata);
00065         static void callbackAddUsers(const std::vector<std::string>& names,
00066                                                                  const std::vector<LLUUID>& agent_ids,
00067                                                                  void* user_data);
00068 
00069 public:
00070         LLUUID mGroupID;
00071 
00072         LLString                mLoadingText;
00073         LLNameListCtrl  *mInvitees;
00074         LLComboBox      *mRoleNames;
00075         LLButton                *mOKButton;
00076         LLButton                *mRemoveButton;
00077         LLTextBox               *mGroupName;
00078 
00079         void (*mCloseCallback)(void* data);
00080 
00081         void* mCloseCallbackUserData;
00082 };
00083 
00084 
00085 LLPanelGroupInvite::impl::impl(const LLUUID& group_id)
00086 {
00087         mGroupID = group_id;
00088 
00089         mInvitees  = NULL;
00090         mRoleNames = NULL;
00091         mRemoveButton = NULL;
00092 
00093         mCloseCallback = NULL;
00094         mCloseCallbackUserData = NULL;
00095 }
00096 
00097 LLPanelGroupInvite::impl::~impl()
00098 {
00099 }
00100 
00101 void LLPanelGroupInvite::impl::addUsers(const std::vector<std::string>& names,
00102                                                                                 const std::vector<LLUUID>& agent_ids)
00103 {
00104         std::string name;
00105         LLUUID id;
00106 
00107         for (S32 i = 0; i < (S32)names.size(); i++)
00108         {
00109                 name = names[i];
00110                 id = agent_ids[i];
00111 
00112                 // Make sure this agent isn't already in the list.
00113                 bool already_in_list = false;
00114                 std::vector<LLScrollListItem*> items = mInvitees->getAllData();
00115                 for (std::vector<LLScrollListItem*>::iterator iter = items.begin();
00116                          iter != items.end(); ++iter)
00117                 {
00118                         LLScrollListItem* item = *iter;
00119                         if (item->getUUID() == id)
00120                         {
00121                                 already_in_list = true;
00122                                 break;
00123                         }
00124                 }
00125                 if (already_in_list)
00126                 {
00127                         continue;
00128                 }
00129 
00130                 //add the name to the names list
00131                 LLSD row;
00132                 row["id"] = id;
00133                 row["columns"][0]["value"] = name;
00134 
00135                 mInvitees->addElement(row);
00136         }
00137 }
00138 
00139 void LLPanelGroupInvite::impl::submitInvitations()
00140 {
00141         std::map<LLUUID, LLUUID> role_member_pairs;
00142 
00143         // Default to everyone role.
00144         LLUUID role_id = LLUUID::null;
00145 
00146         if (mRoleNames)
00147         {
00148                 role_id = mRoleNames->getCurrentID();
00149         }
00150 
00151         //loop over the users
00152         std::vector<LLScrollListItem*> items = mInvitees->getAllData();
00153         for (std::vector<LLScrollListItem*>::iterator iter = items.begin();
00154                  iter != items.end(); ++iter)
00155         {
00156                 LLScrollListItem* item = *iter;
00157                 role_member_pairs[item->getUUID()] = role_id;
00158         }
00159 
00160         gGroupMgr->sendGroupMemberInvites(mGroupID, role_member_pairs);
00161 
00162         //then close
00163         (*mCloseCallback)(mCloseCallbackUserData);
00164 }
00165 
00166 void LLPanelGroupInvite::impl::addRoleNames(LLGroupMgrGroupData* gdatap)
00167 {
00168         LLGroupMgrGroupData::member_iter agent_iter =
00169                 gdatap->mMembers.find(gAgent.getID());
00170 
00171         //get the member data for the agent if it exists
00172         if ( agent_iter != gdatap->mMembers.end() )
00173         {
00174                 LLGroupMemberData* member_data = (*agent_iter).second;
00175 
00176                 //loop over the agent's roles in the group
00177                 //then add those roles to the list of roles that the agent
00178                 //can invite people to be
00179                 if ( member_data && mRoleNames)
00180                 {
00181                         //if the user is the owner then we add
00182                         //all of the roles in the group
00183                         //else if they have the add to roles power
00184                         //we add every role but owner,
00185                         //else if they have the limited add to roles power
00186                         //we add every role the user is in
00187                         //else we just add to everyone
00188                         bool is_owner   = member_data->isInRole(gdatap->mOwnerRole);
00189                         bool can_assign_any = gAgent.hasPowerInGroup(mGroupID,
00190                                                                                                  GP_ROLE_ASSIGN_MEMBER);
00191                         bool can_assign_limited = gAgent.hasPowerInGroup(mGroupID,
00192                                                                                                  GP_ROLE_ASSIGN_MEMBER_LIMITED);
00193 
00194                         LLGroupMgrGroupData::role_iter rit = gdatap->mRoles.begin();
00195                         LLGroupMgrGroupData::role_iter end = gdatap->mRoles.end();
00196 
00197                         //populate the role list
00198                         for ( ; rit != end; ++rit)
00199                         {
00200                                 LLUUID role_id = (*rit).first;
00201                                 LLRoleData rd;
00202                                 if ( gdatap->getRoleData(role_id,rd) )
00203                                 {
00204                                         // Owners can add any role.
00205                                         if ( is_owner 
00206                                                 // Even 'can_assign_any' can't add owner role.
00207                                                  || (can_assign_any && role_id != gdatap->mOwnerRole)
00208                                                 // Add all roles user is in
00209                                                  || (can_assign_limited && member_data->isInRole(role_id))
00210                                                 // Everyone role.
00211                                                  || role_id == LLUUID::null )
00212                                         {
00213                                                         mRoleNames->add(rd.mRoleName,
00214                                                                                         role_id,
00215                                                                                         ADD_BOTTOM);
00216                                         }
00217                                 }
00218                         }
00219                 }//end if member data is not null
00220         }//end if agent is in the group
00221 }
00222 
00223 //static
00224 void LLPanelGroupInvite::impl::callbackClickAdd(void* userdata)
00225 {
00226         LLPanelGroupInvite* panelp = (LLPanelGroupInvite*) userdata;
00227 
00228         if ( panelp )
00229         {
00230                 //Right now this is hard coded with some knowledge that it is part
00231                 //of a floater since the avatar picker needs to be added as a dependent
00232                 //floater to the parent floater.
00233                 //Soon the avatar picker will be embedded into this panel
00234                 //instead of being it's own separate floater.  But that is next week.
00235                 //This will do for now. -jwolk May 10, 2006
00236                 LLFloater* parentp;
00237 
00238                 parentp = gFloaterView->getParentFloater(panelp);
00239                 parentp->addDependentFloater(LLFloaterAvatarPicker::show(callbackAddUsers,
00240                                                                                                                                  panelp->mImplementation,
00241                                                                                                                                  TRUE));
00242         }
00243 }
00244 
00245 //static
00246 void LLPanelGroupInvite::impl::callbackClickRemove(void* userdata)
00247 {
00248         impl* selfp = (impl*) userdata;
00249 
00250         if ( selfp ) selfp->handleRemove();
00251 }
00252 
00253 void LLPanelGroupInvite::impl::handleRemove()
00254 {
00255         // Check if there is anything selected.
00256         std::vector<LLScrollListItem*> selection = 
00257                         mInvitees->getAllSelected();
00258         if (selection.empty()) return;
00259 
00260         // Remove all selected invitees.
00261         mInvitees->deleteSelectedItems();
00262         mRemoveButton->setEnabled(FALSE);
00263 }
00264 
00265 // static
00266 void LLPanelGroupInvite::impl::callbackSelect(
00267                                                                         LLUICtrl* ctrl, void* userdata)
00268 {
00269         impl* selfp = (impl*) userdata;
00270         if ( selfp ) selfp->handleSelection();
00271 }
00272 
00273 void LLPanelGroupInvite::impl::handleSelection()
00274 {
00275         // Check if there is anything selected.
00276         std::vector<LLScrollListItem*> selection = 
00277                         mInvitees->getAllSelected();
00278         if (selection.empty())
00279         {
00280                 mRemoveButton->setEnabled(FALSE);
00281         }
00282         else
00283         {
00284                 mRemoveButton->setEnabled(TRUE);
00285         }
00286 }
00287 
00288 void LLPanelGroupInvite::impl::callbackClickCancel(void* userdata)
00289 {
00290         impl* selfp = (impl*) userdata;
00291 
00292         if ( selfp ) 
00293         {
00294                 (*(selfp->mCloseCallback))(selfp->mCloseCallbackUserData);
00295         }
00296 }
00297 
00298 void LLPanelGroupInvite::impl::callbackClickOK(void* userdata)
00299 {
00300         impl* selfp = (impl*) userdata;
00301 
00302         if ( selfp ) selfp->submitInvitations();
00303 }
00304 
00305 //static
00306 void LLPanelGroupInvite::impl::callbackAddUsers(const std::vector<std::string>& names,
00307                                                                                                 const std::vector<LLUUID>& ids,
00308                                                                                                 void* user_data)
00309 {
00310         impl* selfp = (impl*) user_data;
00311 
00312         if ( selfp) selfp->addUsers(names, ids);
00313 }
00314 
00315 LLPanelGroupInvite::LLPanelGroupInvite(const std::string& name,
00316                                                                            const LLUUID& group_id)
00317         : LLPanel(name)
00318 {
00319         mImplementation = new impl(group_id);
00320         mPendingUpdate = FALSE;
00321         mStoreSelected = LLUUID::null;
00322 
00323         std::string panel_def_file;
00324 
00325         // Pass on construction of this panel to the control factory.
00326         gUICtrlFactory->buildPanel(this, "panel_group_invite.xml", &getFactoryMap());
00327 }
00328 
00329 LLPanelGroupInvite::~LLPanelGroupInvite()
00330 {
00331         delete mImplementation;
00332 }
00333 
00334 void LLPanelGroupInvite::setCloseCallback(void (*close_callback)(void*),
00335                                                                                   void* data)
00336 {
00337         mImplementation->mCloseCallback         = close_callback;
00338         mImplementation->mCloseCallbackUserData = data;
00339 }
00340 
00341 void LLPanelGroupInvite::clear()
00342 {
00343         mStoreSelected = LLUUID::null;
00344         mImplementation->mInvitees->deleteAllItems();
00345         mImplementation->mRoleNames->clear();
00346         mImplementation->mRoleNames->removeall();
00347         mImplementation->mOKButton->setEnabled(FALSE);
00348 }
00349 
00350 void LLPanelGroupInvite::addUsers(std::vector<LLUUID>& agent_ids)
00351 {
00352         std::vector<std::string> names;
00353         for (S32 i = 0; i < (S32)agent_ids.size(); i++)
00354         {
00355                 LLUUID agent_id = agent_ids[i];
00356                 LLViewerObject* dest = gObjectList.findObject(agent_id);
00357                 if(dest && dest->isAvatar())
00358                 {
00359                         LLString fullname;
00360                         LLString::format_map_t args;
00361                         LLNameValue* nvfirst = dest->getNVPair("FirstName");
00362                         LLNameValue* nvlast = dest->getNVPair("LastName");
00363                         if(nvfirst && nvlast)
00364                         {
00365                                 args["[FIRST]"] = nvfirst->getString();
00366                                 args["[LAST]"] = nvlast->getString();
00367                                 fullname = nvfirst->getString();
00368                                 fullname += " ";
00369                                 fullname += nvlast->getString();
00370                         }
00371                         if (!fullname.empty())
00372                         {
00373                                 names.push_back(fullname);
00374                         } 
00375                         else 
00376                         {
00377                                 llwarns << "llPanelGroupInvite: Selected avatar has no name: " << dest->getID() << llendl;
00378                                 names.push_back("(Unknown)");
00379                         }
00380                 }
00381         }
00382         mImplementation->addUsers(names, agent_ids);
00383 }
00384 
00385 void LLPanelGroupInvite::draw()
00386 {
00387         LLPanel::draw();
00388         if (mPendingUpdate)
00389         {
00390                 updateLists();
00391         }
00392 }
00393  
00394 void LLPanelGroupInvite::update()
00395 {
00396         mPendingUpdate = FALSE;
00397         if (mImplementation->mGroupName) 
00398         {
00399                 mImplementation->mGroupName->setText(mImplementation->mLoadingText);
00400         }
00401         if ( mImplementation->mRoleNames ) 
00402         {
00403                 mStoreSelected = mImplementation->mRoleNames->getCurrentID();
00404                 mImplementation->mRoleNames->clear();
00405                 mImplementation->mRoleNames->removeall();
00406                 mImplementation->mRoleNames->add(mImplementation->mLoadingText, LLUUID::null, ADD_BOTTOM);
00407                 mImplementation->mRoleNames->setCurrentByID(LLUUID::null);
00408         }
00409 
00410         updateLists();
00411 }
00412 
00413 void LLPanelGroupInvite::updateLists()
00414 {
00415         LLGroupMgrGroupData* gdatap = gGroupMgr->getGroupData(mImplementation->mGroupID);
00416         BOOL waiting = FALSE;
00417 
00418         if (gdatap) 
00419         {
00420                 if (gdatap->isGroupPropertiesDataComplete()) 
00421                 {
00422                         if (mImplementation->mGroupName) 
00423                         {
00424                                 mImplementation->mGroupName->setText(gdatap->mName);
00425                         }
00426                 } 
00427                 else 
00428                 {
00429                         waiting = TRUE;
00430                 }
00431                 if (gdatap->isRoleDataComplete() && gdatap->isMemberDataComplete()) 
00432                 {
00433                         if ( mImplementation->mRoleNames )
00434                         {
00435                                 mImplementation->mRoleNames->clear();
00436                                 mImplementation->mRoleNames->removeall();
00437 
00438                                 //add the role names and select the everybody role by default
00439                                 mImplementation->addRoleNames(gdatap);
00440                                 mImplementation->mRoleNames->setCurrentByID(mStoreSelected);
00441                         }
00442                 } 
00443                 else 
00444                 {
00445                         waiting = TRUE;
00446                 }
00447         } 
00448         else 
00449         {
00450                 waiting = TRUE;
00451         }
00452 
00453         if (waiting) 
00454         {
00455                 if (!mPendingUpdate) 
00456                 {
00457                         gGroupMgr->sendGroupPropertiesRequest(mImplementation->mGroupID);
00458                         gGroupMgr->sendGroupMembersRequest(mImplementation->mGroupID);
00459                         gGroupMgr->sendGroupRoleDataRequest(mImplementation->mGroupID);
00460                 }
00461                 mPendingUpdate = TRUE;
00462         } 
00463         else
00464         {
00465                 mPendingUpdate = FALSE;
00466                 if (mImplementation->mOKButton && mImplementation->mRoleNames->getItemCount()) 
00467                 {
00468                         mImplementation->mOKButton->setEnabled(TRUE);
00469                 }
00470         }
00471 }
00472 
00473 BOOL LLPanelGroupInvite::postBuild()
00474 {
00475         BOOL recurse = TRUE;
00476 
00477         mImplementation->mLoadingText = childGetText("loading");
00478         mImplementation->mRoleNames = (LLComboBox*) getChildByName("role_name",
00479                                                                                                                            recurse);
00480         mImplementation->mGroupName = (LLTextBox*) getChildByName("group_name_text", recurse);
00481         mImplementation->mInvitees = 
00482                 (LLNameListCtrl*) getChildByName("invitee_list", recurse);
00483         if ( mImplementation->mInvitees )
00484         {
00485                 mImplementation->mInvitees->setCallbackUserData(mImplementation);
00486                 mImplementation->mInvitees->setCommitOnSelectionChange(TRUE);
00487                 mImplementation->mInvitees->setCommitCallback(impl::callbackSelect);
00488         }
00489 
00490         LLButton* button = (LLButton*) getChildByName("add_button", recurse);
00491         if ( button )
00492         {
00493                 // default to opening avatarpicker automatically
00494                 // (*impl::callbackClickAdd)((void*)this);
00495                 button->setClickedCallback(impl::callbackClickAdd);
00496                 button->setCallbackUserData(this);
00497         }
00498 
00499         mImplementation->mRemoveButton = 
00500                         (LLButton*) getChildByName("remove_button", recurse);
00501         if ( mImplementation->mRemoveButton )
00502         {
00503                 mImplementation->mRemoveButton->
00504                                 setClickedCallback(impl::callbackClickRemove);
00505                 mImplementation->mRemoveButton->setCallbackUserData(mImplementation);
00506                 mImplementation->mRemoveButton->setEnabled(FALSE);
00507         }
00508 
00509         mImplementation->mOKButton = 
00510                 (LLButton*) getChildByName("ok_button", recurse);
00511         if ( mImplementation->mOKButton )
00512         {
00513                 mImplementation->mOKButton->
00514                                 setClickedCallback(impl::callbackClickOK);
00515                 mImplementation->mOKButton->setCallbackUserData(mImplementation);
00516                 mImplementation->mOKButton->setEnabled(FALSE);
00517         }
00518 
00519         button = (LLButton*) getChildByName("cancel_button", recurse);
00520         if ( button )
00521         {
00522                 button->setClickedCallback(impl::callbackClickCancel);
00523                 button->setCallbackUserData(mImplementation);
00524         }
00525 
00526         update();
00527         
00528         return (mImplementation->mRoleNames &&
00529                         mImplementation->mInvitees &&
00530                         mImplementation->mRemoveButton);
00531 }

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