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 "lluictrlfactory.h"
00046 #include "llviewerwindow.h"
00047
00048 class LLPanelGroupInvite::impl
00049 {
00050 public:
00051 impl(const LLUUID& group_id);
00052 ~impl();
00053
00054 void addUsers(const std::vector<std::string>& names,
00055 const std::vector<LLUUID>& agent_ids);
00056 void submitInvitations();
00057 void addRoleNames(LLGroupMgrGroupData* gdatap);
00058 void handleRemove();
00059 void handleSelection();
00060
00061 static void callbackClickCancel(void* userdata);
00062 static void callbackClickOK(void* userdata);
00063 static void callbackClickAdd(void* userdata);
00064 static void callbackClickRemove(void* userdata);
00065 static void callbackSelect(LLUICtrl* ctrl, void* userdata);
00066 static void callbackAddUsers(const std::vector<std::string>& names,
00067 const std::vector<LLUUID>& agent_ids,
00068 void* user_data);
00069 static void inviteOwnerCallback(S32 option, void* userdata);
00070
00071 public:
00072 LLUUID mGroupID;
00073
00074 LLString mLoadingText;
00075 LLNameListCtrl *mInvitees;
00076 LLComboBox *mRoleNames;
00077 LLButton *mOKButton;
00078 LLButton *mRemoveButton;
00079 LLTextBox *mGroupName;
00080 LLString mOwnerWarning;
00081 bool mConfirmedOwnerInvite;
00082
00083 void (*mCloseCallback)(void* data);
00084
00085 void* mCloseCallbackUserData;
00086 };
00087
00088
00089 LLPanelGroupInvite::impl::impl(const LLUUID& group_id):
00090 mGroupID( group_id ),
00091 mLoadingText (),
00092 mInvitees ( NULL ),
00093 mRoleNames( NULL ),
00094 mOKButton ( NULL ),
00095 mRemoveButton( NULL ),
00096 mGroupName( NULL ),
00097 mConfirmedOwnerInvite( false ),
00098 mCloseCallback( NULL ),
00099 mCloseCallbackUserData( NULL )
00100 {
00101 }
00102
00103 LLPanelGroupInvite::impl::~impl()
00104 {
00105 }
00106
00107 void LLPanelGroupInvite::impl::addUsers(const std::vector<std::string>& names,
00108 const std::vector<LLUUID>& agent_ids)
00109 {
00110 std::string name;
00111 LLUUID id;
00112
00113 for (S32 i = 0; i < (S32)names.size(); i++)
00114 {
00115 name = names[i];
00116 id = agent_ids[i];
00117
00118
00119 bool already_in_list = false;
00120 std::vector<LLScrollListItem*> items = mInvitees->getAllData();
00121 for (std::vector<LLScrollListItem*>::iterator iter = items.begin();
00122 iter != items.end(); ++iter)
00123 {
00124 LLScrollListItem* item = *iter;
00125 if (item->getUUID() == id)
00126 {
00127 already_in_list = true;
00128 break;
00129 }
00130 }
00131 if (already_in_list)
00132 {
00133 continue;
00134 }
00135
00136
00137 LLSD row;
00138 row["id"] = id;
00139 row["columns"][0]["value"] = name;
00140
00141 mInvitees->addElement(row);
00142 }
00143 }
00144
00145 void LLPanelGroupInvite::impl::submitInvitations()
00146 {
00147 std::map<LLUUID, LLUUID> role_member_pairs;
00148
00149 LLGroupMgrGroupData* gdatap = LLGroupMgr::getInstance()->getGroupData(mGroupID);
00150
00151
00152 LLUUID role_id = LLUUID::null;
00153
00154 if (mRoleNames)
00155 {
00156 role_id = mRoleNames->getCurrentID();
00157
00158
00159 if ((role_id == gdatap->mOwnerRole) && (!mConfirmedOwnerInvite))
00160 {
00161 LLString::format_map_t args;
00162 args["[MESSAGE]"] = mOwnerWarning;
00163 gViewerWindow->alertXml("GenericAlertYesCancel", args, inviteOwnerCallback, this);
00164 return;
00165 }
00166 }
00167
00168
00169 std::vector<LLScrollListItem*> items = mInvitees->getAllData();
00170 for (std::vector<LLScrollListItem*>::iterator iter = items.begin();
00171 iter != items.end(); ++iter)
00172 {
00173 LLScrollListItem* item = *iter;
00174 role_member_pairs[item->getUUID()] = role_id;
00175 }
00176
00177 LLGroupMgr::getInstance()->sendGroupMemberInvites(mGroupID, role_member_pairs);
00178
00179
00180 (*mCloseCallback)(mCloseCallbackUserData);
00181 }
00182
00183
00184 void LLPanelGroupInvite::impl::inviteOwnerCallback(S32 option, void* userdata)
00185 {
00186 LLPanelGroupInvite::impl* self = (LLPanelGroupInvite::impl*)userdata;
00187 if (!self) return;
00188
00189 switch(option)
00190 {
00191 case 0:
00192
00193 self->mConfirmedOwnerInvite = true;
00194 self->submitInvitations();
00195 break;
00196 case 1:
00197
00198 default:
00199 break;
00200 }
00201 }
00202
00203
00204
00205 void LLPanelGroupInvite::impl::addRoleNames(LLGroupMgrGroupData* gdatap)
00206 {
00207 LLGroupMgrGroupData::member_list_t::iterator agent_iter =
00208 gdatap->mMembers.find(gAgent.getID());
00209
00210
00211 if ( agent_iter != gdatap->mMembers.end() )
00212 {
00213 LLGroupMemberData* member_data = (*agent_iter).second;
00214
00215
00216
00217
00218 if ( member_data && mRoleNames)
00219 {
00220
00221
00222
00223
00224
00225
00226
00227 bool is_owner = member_data->isInRole(gdatap->mOwnerRole);
00228 bool can_assign_any = gAgent.hasPowerInGroup(mGroupID,
00229 GP_ROLE_ASSIGN_MEMBER);
00230 bool can_assign_limited = gAgent.hasPowerInGroup(mGroupID,
00231 GP_ROLE_ASSIGN_MEMBER_LIMITED);
00232
00233 LLGroupMgrGroupData::role_list_t::iterator rit = gdatap->mRoles.begin();
00234 LLGroupMgrGroupData::role_list_t::iterator end = gdatap->mRoles.end();
00235
00236
00237 for ( ; rit != end; ++rit)
00238 {
00239 LLUUID role_id = (*rit).first;
00240 LLRoleData rd;
00241 if ( gdatap->getRoleData(role_id,rd) )
00242 {
00243
00244 if ( is_owner
00245
00246 || (can_assign_any && role_id != gdatap->mOwnerRole)
00247
00248 || (can_assign_limited && member_data->isInRole(role_id))
00249
00250 || role_id == LLUUID::null )
00251 {
00252 mRoleNames->add(rd.mRoleName,
00253 role_id,
00254 ADD_BOTTOM);
00255 }
00256 }
00257 }
00258 }
00259 }
00260 }
00261
00262
00263 void LLPanelGroupInvite::impl::callbackClickAdd(void* userdata)
00264 {
00265 LLPanelGroupInvite* panelp = (LLPanelGroupInvite*) userdata;
00266
00267 if ( panelp )
00268 {
00269
00270
00271
00272
00273
00274
00275 LLFloater* parentp;
00276
00277 parentp = gFloaterView->getParentFloater(panelp);
00278 parentp->addDependentFloater(LLFloaterAvatarPicker::show(callbackAddUsers,
00279 panelp->mImplementation,
00280 TRUE));
00281 }
00282 }
00283
00284
00285 void LLPanelGroupInvite::impl::callbackClickRemove(void* userdata)
00286 {
00287 impl* selfp = (impl*) userdata;
00288
00289 if ( selfp ) selfp->handleRemove();
00290 }
00291
00292 void LLPanelGroupInvite::impl::handleRemove()
00293 {
00294
00295 std::vector<LLScrollListItem*> selection =
00296 mInvitees->getAllSelected();
00297 if (selection.empty()) return;
00298
00299
00300 mInvitees->deleteSelectedItems();
00301 mRemoveButton->setEnabled(FALSE);
00302 }
00303
00304
00305 void LLPanelGroupInvite::impl::callbackSelect(
00306 LLUICtrl* ctrl, void* userdata)
00307 {
00308 impl* selfp = (impl*) userdata;
00309 if ( selfp ) selfp->handleSelection();
00310 }
00311
00312 void LLPanelGroupInvite::impl::handleSelection()
00313 {
00314
00315 std::vector<LLScrollListItem*> selection =
00316 mInvitees->getAllSelected();
00317 if (selection.empty())
00318 {
00319 mRemoveButton->setEnabled(FALSE);
00320 }
00321 else
00322 {
00323 mRemoveButton->setEnabled(TRUE);
00324 }
00325 }
00326
00327 void LLPanelGroupInvite::impl::callbackClickCancel(void* userdata)
00328 {
00329 impl* selfp = (impl*) userdata;
00330
00331 if ( selfp )
00332 {
00333 (*(selfp->mCloseCallback))(selfp->mCloseCallbackUserData);
00334 }
00335 }
00336
00337 void LLPanelGroupInvite::impl::callbackClickOK(void* userdata)
00338 {
00339 impl* selfp = (impl*) userdata;
00340
00341 if ( selfp ) selfp->submitInvitations();
00342 }
00343
00344
00345 void LLPanelGroupInvite::impl::callbackAddUsers(const std::vector<std::string>& names,
00346 const std::vector<LLUUID>& ids,
00347 void* user_data)
00348 {
00349 impl* selfp = (impl*) user_data;
00350
00351 if ( selfp) selfp->addUsers(names, ids);
00352 }
00353
00354 LLPanelGroupInvite::LLPanelGroupInvite(const std::string& name,
00355 const LLUUID& group_id)
00356 : LLPanel(name)
00357 {
00358 mImplementation = new impl(group_id);
00359 mPendingUpdate = FALSE;
00360 mStoreSelected = LLUUID::null;
00361
00362 std::string panel_def_file;
00363
00364
00365 LLUICtrlFactory::getInstance()->buildPanel(this, "panel_group_invite.xml", &getFactoryMap());
00366 }
00367
00368 LLPanelGroupInvite::~LLPanelGroupInvite()
00369 {
00370 delete mImplementation;
00371 }
00372
00373 void LLPanelGroupInvite::setCloseCallback(void (*close_callback)(void*),
00374 void* data)
00375 {
00376 mImplementation->mCloseCallback = close_callback;
00377 mImplementation->mCloseCallbackUserData = data;
00378 }
00379
00380 void LLPanelGroupInvite::clear()
00381 {
00382 mStoreSelected = LLUUID::null;
00383 mImplementation->mInvitees->deleteAllItems();
00384 mImplementation->mRoleNames->clear();
00385 mImplementation->mRoleNames->removeall();
00386 mImplementation->mOKButton->setEnabled(FALSE);
00387 }
00388
00389 void LLPanelGroupInvite::addUsers(std::vector<LLUUID>& agent_ids)
00390 {
00391 std::vector<std::string> names;
00392 for (S32 i = 0; i < (S32)agent_ids.size(); i++)
00393 {
00394 LLUUID agent_id = agent_ids[i];
00395 LLViewerObject* dest = gObjectList.findObject(agent_id);
00396 if(dest && dest->isAvatar())
00397 {
00398 LLString fullname;
00399 LLString::format_map_t args;
00400 LLNameValue* nvfirst = dest->getNVPair("FirstName");
00401 LLNameValue* nvlast = dest->getNVPair("LastName");
00402 if(nvfirst && nvlast)
00403 {
00404 args["[FIRST]"] = nvfirst->getString();
00405 args["[LAST]"] = nvlast->getString();
00406 fullname = nvfirst->getString();
00407 fullname += " ";
00408 fullname += nvlast->getString();
00409 }
00410 if (!fullname.empty())
00411 {
00412 names.push_back(fullname);
00413 }
00414 else
00415 {
00416 llwarns << "llPanelGroupInvite: Selected avatar has no name: " << dest->getID() << llendl;
00417 names.push_back("(Unknown)");
00418 }
00419 }
00420 }
00421 mImplementation->addUsers(names, agent_ids);
00422 }
00423
00424 void LLPanelGroupInvite::draw()
00425 {
00426 LLPanel::draw();
00427 if (mPendingUpdate)
00428 {
00429 updateLists();
00430 }
00431 }
00432
00433 void LLPanelGroupInvite::update()
00434 {
00435 mPendingUpdate = FALSE;
00436 if (mImplementation->mGroupName)
00437 {
00438 mImplementation->mGroupName->setText(mImplementation->mLoadingText);
00439 }
00440 if ( mImplementation->mRoleNames )
00441 {
00442 mStoreSelected = mImplementation->mRoleNames->getCurrentID();
00443 mImplementation->mRoleNames->clear();
00444 mImplementation->mRoleNames->removeall();
00445 mImplementation->mRoleNames->add(mImplementation->mLoadingText, LLUUID::null, ADD_BOTTOM);
00446 mImplementation->mRoleNames->setCurrentByID(LLUUID::null);
00447 }
00448
00449 updateLists();
00450 }
00451
00452 void LLPanelGroupInvite::updateLists()
00453 {
00454 LLGroupMgrGroupData* gdatap = LLGroupMgr::getInstance()->getGroupData(mImplementation->mGroupID);
00455 bool waiting = false;
00456
00457 if (gdatap)
00458 {
00459 if (gdatap->isGroupPropertiesDataComplete())
00460 {
00461 if (mImplementation->mGroupName)
00462 {
00463 mImplementation->mGroupName->setText(gdatap->mName);
00464 }
00465 }
00466 else
00467 {
00468 waiting = true;
00469 }
00470 if (gdatap->isRoleDataComplete() && gdatap->isMemberDataComplete())
00471 {
00472 if ( mImplementation->mRoleNames )
00473 {
00474 mImplementation->mRoleNames->clear();
00475 mImplementation->mRoleNames->removeall();
00476
00477
00478 mImplementation->addRoleNames(gdatap);
00479 mImplementation->mRoleNames->setCurrentByID(mStoreSelected);
00480 }
00481 }
00482 else
00483 {
00484 waiting = true;
00485 }
00486 }
00487 else
00488 {
00489 waiting = true;
00490 }
00491
00492 if (waiting)
00493 {
00494 if (!mPendingUpdate)
00495 {
00496 LLGroupMgr::getInstance()->sendGroupPropertiesRequest(mImplementation->mGroupID);
00497 LLGroupMgr::getInstance()->sendGroupMembersRequest(mImplementation->mGroupID);
00498 LLGroupMgr::getInstance()->sendGroupRoleDataRequest(mImplementation->mGroupID);
00499 }
00500 mPendingUpdate = TRUE;
00501 }
00502 else
00503 {
00504 mPendingUpdate = FALSE;
00505 if (mImplementation->mOKButton && mImplementation->mRoleNames->getItemCount())
00506 {
00507 mImplementation->mOKButton->setEnabled(TRUE);
00508 }
00509 }
00510 }
00511
00512 BOOL LLPanelGroupInvite::postBuild()
00513 {
00514 BOOL recurse = TRUE;
00515
00516 mImplementation->mLoadingText = getString("loading");
00517 mImplementation->mRoleNames = getChild<LLComboBox>("role_name",
00518 recurse);
00519 mImplementation->mGroupName = getChild<LLTextBox>("group_name_text", recurse);
00520 mImplementation->mInvitees =
00521 getChild<LLNameListCtrl>("invitee_list", recurse);
00522 if ( mImplementation->mInvitees )
00523 {
00524 mImplementation->mInvitees->setCallbackUserData(mImplementation);
00525 mImplementation->mInvitees->setCommitOnSelectionChange(TRUE);
00526 mImplementation->mInvitees->setCommitCallback(impl::callbackSelect);
00527 }
00528
00529 LLButton* button = getChild<LLButton>("add_button", recurse);
00530 if ( button )
00531 {
00532
00533
00534 button->setClickedCallback(impl::callbackClickAdd);
00535 button->setCallbackUserData(this);
00536 }
00537
00538 mImplementation->mRemoveButton =
00539 getChild<LLButton>("remove_button", recurse);
00540 if ( mImplementation->mRemoveButton )
00541 {
00542 mImplementation->mRemoveButton->
00543 setClickedCallback(impl::callbackClickRemove);
00544 mImplementation->mRemoveButton->setCallbackUserData(mImplementation);
00545 mImplementation->mRemoveButton->setEnabled(FALSE);
00546 }
00547
00548 mImplementation->mOKButton =
00549 getChild<LLButton>("ok_button", recurse);
00550 if ( mImplementation->mOKButton )
00551 {
00552 mImplementation->mOKButton->
00553 setClickedCallback(impl::callbackClickOK);
00554 mImplementation->mOKButton->setCallbackUserData(mImplementation);
00555 mImplementation->mOKButton->setEnabled(FALSE);
00556 }
00557
00558 button = getChild<LLButton>("cancel_button", recurse);
00559 if ( button )
00560 {
00561 button->setClickedCallback(impl::callbackClickCancel);
00562 button->setCallbackUserData(mImplementation);
00563 }
00564
00565 mImplementation->mOwnerWarning = getString("confirm_invite_owner_str");
00566
00567 update();
00568
00569 return (mImplementation->mRoleNames &&
00570 mImplementation->mInvitees &&
00571 mImplementation->mRemoveButton);
00572 }