diff options
Diffstat (limited to 'indra/newview/llfloaterforgetuser.cpp')
-rw-r--r-- | indra/newview/llfloaterforgetuser.cpp | 298 |
1 files changed, 246 insertions, 52 deletions
diff --git a/indra/newview/llfloaterforgetuser.cpp b/indra/newview/llfloaterforgetuser.cpp index 5659cb2f79..97b022699f 100644 --- a/indra/newview/llfloaterforgetuser.cpp +++ b/indra/newview/llfloaterforgetuser.cpp @@ -29,11 +29,15 @@ #include "llfloaterforgetuser.h" +#include "llappviewer.h" #include "llcheckboxctrl.h" #include "llfavoritesbar.h" +#include "llnotificationsutil.h" #include "llpanellogin.h" // for helper function getUserName() and to repopulate list if nessesary #include "llscrolllistctrl.h" #include "llsecapi.h" +#include "llstartup.h" +#include "llviewercontrol.h" #include "llviewernetwork.h" @@ -54,52 +58,69 @@ LLFloaterForgetUser::~LLFloaterForgetUser() BOOL LLFloaterForgetUser::postBuild() { - // Note, storage works per grid, watever is selected currently in login screen or logged in. - // Since login screen can change grid, store the value. - mGrid = LLGridManager::getInstance()->getGrid(); + mScrollList = getChild<LLScrollListCtrl>("user_list"); - LLScrollListCtrl *scroll_list = getChild<LLScrollListCtrl>("user_list"); - if (gSecAPIHandler->hasCredentialMap("login_list", mGrid)) - { - LLSecAPIHandler::credential_map_t credencials; - gSecAPIHandler->loadCredentialMap("login_list", mGrid, credencials); - LLSecAPIHandler::credential_map_t::iterator cr_iter = credencials.begin(); - LLSecAPIHandler::credential_map_t::iterator cr_end = credencials.end(); - while (cr_iter != cr_end) + bool show_grid_marks = gSavedSettings.getBOOL("ForceShowGrid"); + show_grid_marks |= !LLGridManager::getInstance()->isInProductionGrid(); + + std::map<std::string, std::string> known_grids = LLGridManager::getInstance()->getKnownGrids(); + + if (!show_grid_marks) + { + // Figure out if there are records for more than one grid in storage + for (std::map<std::string, std::string>::iterator grid_iter = known_grids.begin(); + grid_iter != known_grids.end(); + grid_iter++) { - if (cr_iter->second.notNull()) // basic safety + if (!grid_iter->first.empty() + && grid_iter->first != MAINGRID) // a workaround since 'mIsInProductionGrid' might not be set { - LLScrollListItem::Params item_params; - item_params.value(cr_iter->first); - item_params.columns.add() - .value(LLPanelLogin::getUserName(cr_iter->second)) - .column("user") - .font(LLFontGL::getFontSansSerifSmall()); - scroll_list->addRow(item_params, ADD_BOTTOM); + if (!gSecAPIHandler->emptyCredentialMap("login_list", grid_iter->first)) + { + show_grid_marks = true; + break; + } + + // "Legacy" viewer support + LLPointer<LLCredential> cred = gSecAPIHandler->loadCredential(grid_iter->first); + if (cred.notNull()) + { + const LLSD &ident = cred->getIdentifier(); + if (ident.isMap() && ident.has("type")) + { + show_grid_marks = true; + break; + } + } } - cr_iter++; } - scroll_list->selectFirstItem(); + } + + mUserGridsCount.clear(); + if (!show_grid_marks) + { + // just load maingrid + loadGridToList(MAINGRID, false); } else { - LLPointer<LLCredential> cred = gSecAPIHandler->loadCredential(mGrid); - if (cred.notNull()) + for (std::map<std::string, std::string>::iterator grid_iter = known_grids.begin(); + grid_iter != known_grids.end(); + grid_iter++) { - LLScrollListItem::Params item_params; - item_params.value(cred->userID()); - item_params.columns.add() - .value(LLPanelLogin::getUserName(cred)) - .column("user") - .font(LLFontGL::getFontSansSerifSmall()); - scroll_list->addRow(item_params, ADD_BOTTOM); - scroll_list->selectFirstItem(); + if (!grid_iter->first.empty()) + { + loadGridToList(grid_iter->first, true); + } } } - bool enable_button = scroll_list->getFirstSelectedIndex() != -1; - getChild<LLView>("delete_data")->setEnabled(enable_button); + mScrollList->selectFirstItem(); + bool enable_button = mScrollList->getFirstSelectedIndex() != -1; + LLCheckBoxCtrl *chk_box = getChild<LLCheckBoxCtrl>("delete_data"); + chk_box->setEnabled(enable_button); + chk_box->set(FALSE); LLButton *button = getChild<LLButton>("forget"); button->setEnabled(enable_button); button->setCommitCallback(boost::bind(&LLFloaterForgetUser::onForgetClicked, this)); @@ -109,36 +130,88 @@ BOOL LLFloaterForgetUser::postBuild() void LLFloaterForgetUser::onForgetClicked() { - mLoginPanelDirty = true; LLScrollListCtrl *scroll_list = getChild<LLScrollListCtrl>("user_list"); - std::string user_key = scroll_list->getSelectedValue(); + LLSD user_data = scroll_list->getSelectedValue(); + const std::string user_id = user_data["user_id"]; - // remove creds - gSecAPIHandler->removeFromCredentialMap("login_list", mGrid, user_key); + LLCheckBoxCtrl *chk_box = getChild<LLCheckBoxCtrl>("delete_data"); + BOOL delete_data = chk_box->getValue(); - LLPointer<LLCredential> cred = gSecAPIHandler->loadCredential(mGrid); - if (cred.notNull() && cred->userID() == user_key) + if (delete_data && mUserGridsCount[user_id] > 1) { - gSecAPIHandler->deleteCredential(cred); + // more than 1 grid uses this id + LLNotificationsUtil::add("LoginRemoveMultiGridUserData", LLSD(), LLSD(), boost::bind(&LLFloaterForgetUser::onConfirmForget, this, _1, _2)); + return; } - // Clean data - LLCheckBoxCtrl *chk_box = getChild<LLCheckBoxCtrl>("delete_data"); - BOOL delete_data = chk_box->getValue(); - if (delete_data) + processForgetUser(); +} + +bool LLFloaterForgetUser::onConfirmForget(const LLSD& notification, const LLSD& response) +{ + S32 option = LLNotificationsUtil::getSelectedOption(notification, response); + if (option == 0) { - // key is edentical to one we use for name of user's folder - std::string user_path = gDirUtilp->getOSUserAppDir() + gDirUtilp->getDirDelimiter() + user_key; - gDirUtilp->deleteDirAndContents(user_path); + processForgetUser(); + } + return false; +} - // Clean favorites, label is edentical to username - LLFavoritesOrderStorage::removeFavoritesRecordOfUser(scroll_list->getSelectedItemLabel(), mGrid); +// static +bool LLFloaterForgetUser::onConfirmLogout(const LLSD& notification, const LLSD& response, const std::string &fav_id, const std::string &grid) +{ + S32 option = LLNotificationsUtil::getSelectedOption(notification, response); + if (option == 0) + { + // Remove creds + gSecAPIHandler->removeFromCredentialMap("login_list", grid, LLStartUp::getUserId()); - // Note: we do not clean user-related files from cache because there are id dependent (inventory) - // files and cache has separate cleaning mechanism either way. - // Also this only cleans user from current grid, not all of them. + LLPointer<LLCredential> cred = gSecAPIHandler->loadCredential(grid); + if (cred.notNull() && cred->userID() == LLStartUp::getUserId()) + { + gSecAPIHandler->deleteCredential(cred); + } + + // Clean favorites + LLFavoritesOrderStorage::removeFavoritesRecordOfUser(fav_id, grid); + + // mark data for removal + LLAppViewer::instance()->purgeUserDataOnExit(); + LLAppViewer::instance()->requestQuit(); } + return false; +} + +void LLFloaterForgetUser::processForgetUser() +{ + LLScrollListCtrl *scroll_list = getChild<LLScrollListCtrl>("user_list"); + LLCheckBoxCtrl *chk_box = getChild<LLCheckBoxCtrl>("delete_data"); + BOOL delete_data = chk_box->getValue(); + LLSD user_data = scroll_list->getSelectedValue(); + const std::string user_id = user_data["user_id"]; + const std::string grid = user_data["grid"]; + const std::string user_name = user_data["label"]; // for favorites + if (delete_data && user_id == LLStartUp::getUserId() && LLStartUp::getStartupState() > STATE_LOGIN_WAIT) + { + // we can't delete data for user that is currently logged in + // we need to pass grid because we are deleting data universal to grids, but specific grid's user + LLNotificationsUtil::add("LoginCantRemoveCurUsername", LLSD(), LLSD(), boost::bind(onConfirmLogout, _1, _2, user_name, grid)); + return; + } + + // key is used for name of user's folder and in credencials + // user_name is edentical to favorite's username + forgetUser(user_id, user_name, grid, delete_data); + mLoginPanelDirty = true; + if (delete_data) + { + mUserGridsCount[user_id] = 0; //no data left to care about + } + else + { + mUserGridsCount[user_id]--; + } // Update UI scroll_list->deleteSelectedItems(); @@ -151,4 +224,125 @@ void LLFloaterForgetUser::onForgetClicked() } } +//static +void LLFloaterForgetUser::forgetUser(const std::string &userid, const std::string &fav_id, const std::string &grid, bool delete_data) +{ + // Remove creds + gSecAPIHandler->removeFromCredentialMap("login_list", grid, userid); + + LLPointer<LLCredential> cred = gSecAPIHandler->loadCredential(grid); + if (cred.notNull() && cred->userID() == userid) + { + gSecAPIHandler->deleteCredential(cred); + } + + // Clean data + if (delete_data) + { + std::string user_path = gDirUtilp->getOSUserAppDir() + gDirUtilp->getDirDelimiter() + userid; + gDirUtilp->deleteDirAndContents(user_path); + + // Clean favorites + LLFavoritesOrderStorage::removeFavoritesRecordOfUser(fav_id, grid); + + // Note: we do not clean user-related files from cache because there are id dependent (inventory) + // files and cache has separate cleaning mechanism either way. + // Also this only cleans user from current grid, not all of them. + } +} + +void LLFloaterForgetUser::loadGridToList(const std::string &grid, bool show_grid_name) +{ + std::string grid_label; + if (show_grid_name) + { + grid_label = LLGridManager::getInstance()->getGridId(grid); //login id (shortened label) + } + if (gSecAPIHandler->hasCredentialMap("login_list", grid)) + { + LLSecAPIHandler::credential_map_t credencials; + gSecAPIHandler->loadCredentialMap("login_list", grid, credencials); + + LLSecAPIHandler::credential_map_t::iterator cr_iter = credencials.begin(); + LLSecAPIHandler::credential_map_t::iterator cr_end = credencials.end(); + while (cr_iter != cr_end) + { + if (cr_iter->second.notNull()) // basic safety + { + std::string user_label = LLPanelLogin::getUserName(cr_iter->second); + LLSD user_data; + user_data["user_id"] = cr_iter->first; + user_data["label"] = user_label; + user_data["grid"] = grid; + + if (show_grid_name) + { + user_label += " (" + grid_label + ")"; + } + + LLScrollListItem::Params item_params; + item_params.value(user_data); + item_params.columns.add() + .value(user_label) + .column("user") + .font(LLFontGL::getFontSansSerifSmall()); + mScrollList->addRow(item_params, ADD_BOTTOM); + + // Add one to grid count + std::map<std::string, S32>::iterator found = mUserGridsCount.find(cr_iter->first); + if (found != mUserGridsCount.end()) + { + found->second++; + } + else + { + mUserGridsCount[cr_iter->first] = 1; + } + } + cr_iter++; + } + } + else + { + // "Legacy" viewer support + LLPointer<LLCredential> cred = gSecAPIHandler->loadCredential(grid); + if (cred.notNull()) + { + const LLSD &ident = cred->getIdentifier(); + if (ident.isMap() && ident.has("type")) + { + std::string user_label = LLPanelLogin::getUserName(cred); + LLSD user_data; + user_data["user_id"] = cred->userID(); + user_data["label"] = user_label; + user_data["grid"] = grid; + + if (show_grid_name) + { + user_label += " (" + grid_label + ")"; + } + + LLScrollListItem::Params item_params; + item_params.value(user_data); + item_params.columns.add() + .value(user_label) + .column("user") + .font(LLFontGL::getFontSansSerifSmall()); + mScrollList->addRow(item_params, ADD_BOTTOM); + + // Add one to grid count + std::map<std::string, S32>::iterator found = mUserGridsCount.find(cred->userID()); + if (found != mUserGridsCount.end()) + { + found->second++; + } + else + { + mUserGridsCount[cred->userID()] = 1; + } + } + } + } +} + |