From d53a422354cbe27b0e0b3faa07be80b3c5df0896 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Fri, 9 Jul 2010 03:07:25 -0700 Subject: Use cancel-apply-ok for the grid manager, fixed those weird refresh bugs, re-added notfications for errors --- linden/indra/newview/floatergridmanager.cpp | 217 +++++++++++---------- linden/indra/newview/floatergridmanager.h | 6 + linden/indra/newview/hippoGridManager.cpp | 194 ++++++++++++------ .../default/xui/en-us/floater_grid_manager.xml | 12 +- .../skins/default/xui/en-us/notifications.xml | 41 ++++ 5 files changed, 305 insertions(+), 165 deletions(-) (limited to 'linden') diff --git a/linden/indra/newview/floatergridmanager.cpp b/linden/indra/newview/floatergridmanager.cpp index efd02ca..1ca7ae3 100644 --- a/linden/indra/newview/floatergridmanager.cpp +++ b/linden/indra/newview/floatergridmanager.cpp @@ -53,32 +53,6 @@ FloaterGridManager::~FloaterGridManager() BOOL FloaterGridManager::postBuild() { - /*requires("grid_selector"); - requires("gridnick"); - requires("gridname"); - requires("loginuri"); - requires("loginpage"); - requires("helperuri"); - requires("website"); - requires("support"); - requires("register"); - requires("password"); - requires("first_name"); - requires("last_name"); - requires("avatar_password"); - //requires("search"); - requires("btn_delete"); - requires("btn_add"); - requires("btn_copy"); - requires("set_default"); - requires("btn_gridinfo");*/ - //requires("btn_help_render_compat"); - - /*if (!checkRequirements()) - { - return false; - }*/ - LLLineEditor* password_edit = getChild("avatar_password"); if (password_edit) { @@ -105,49 +79,120 @@ BOOL FloaterGridManager::postBuild() return TRUE; } +void FloaterGridManager::clearInfo() +{ + //getChild("grid_selector")->clear(); + //getChild("gridnick")->clear(); + //getChild("gridname")->clear(); + //getChild("loginuri")->clear(); + getChild("loginpage")->clear(); + getChild("helperuri")->clear(); + getChild("website")->clear(); + getChild("support")->clear(); + getChild("register")->clear(); + getChild("password")->clear(); + //getChild("first_name")->clear(); + //getChild("last_name")->clear(); + //getChild("avatar_password")->clear(); + //getChild("search")->clear(); + //getChild("btn_delete"); + //getChild("btn_add") + //getChild("btn_copy"); + //getChild("set_default")->setEnabled(FALSE); + getChild("btn_gridinfo")->setEnabled(TRUE); + //getChild("btn_clear"); + //getChild("btn_help_render_compat")->setEnabled(FALSE); +} + +void FloaterGridManager::draw() +{ + refresh(); + + LLFloater::draw(); +} + +void FloaterGridManager::refresh() +{ + //TODO: these should just be set in a prompt + bool can_edit = (!getChild("gridnick")->getText().empty() && + !getChild("loginuri")->getText().empty() && + getChild("gridnick")->getText() != "" && + getChild("loginuri")->getText() != ""); + + //getChild("gridname"); + getChild("loginpage")->setEnabled(can_edit); + getChild("helperuri")->setEnabled(can_edit); + getChild("website")->setEnabled(can_edit); + getChild("support")->setEnabled(can_edit); + getChild("register")->setEnabled(can_edit); + getChild("password")->setEnabled(can_edit); + //getChild("first_name")->setEnabled(can_edit); + //getChild("last_name")->setEnabled(can_edit); + //getChild("avatar_password")->setEnabled(can_edit); + //getChild("search")->setEnabled(can_edit); + getChild("btn_delete")->setEnabled(can_edit); + //getChild("btn_add") + //getChild("btn_copy")->setEnabled(can_edit); + //getChild("set_default")->setEnabled(can_dit); + getChild("btn_gridinfo")->setEnabled(can_edit); + getChild("btn_clear")->setEnabled(can_edit); + //getChild("btn_help_render_compat")->setEnabled(can_edit); +} + void FloaterGridManager::refreshGrids() { - const std::string &defaultGrid = gHippoGridManager->getDefaultGridNick(); LLScrollListCtrl *grids = FloaterGridManager::getInstance()->getChild("grid_selector"); - grids->deleteAllItems(); + std::string lastSelectedItem; + LLSD element; - S32 selectIndex = -1; - S32 i = 0; - if (defaultGrid != "") + if (grids->getFirstSelected()) { - LLSD value; - value["id"] = defaultGrid; - value["columns"][0]["column"] = "grid"; - value["columns"][0]["value"] = defaultGrid; - grids->addElement(value); - selectIndex = i++; + lastSelectedItem = grids->getFirstSelected()->getValue().asString(); } - - HippoGridManager::GridIterator it = gHippoGridManager->beginGrid(); - HippoGridManager::GridIterator end = gHippoGridManager->endGrid(); - for (it; it != end; ++it) + + grids->deleteAllItems(); + + for (HippoGridManager::GridIterator it = gHippoGridManager->beginGrid(); it != gHippoGridManager->endGrid(); ++it) { - const std::string &grid = it->second->getGridNick(); - if (grid != defaultGrid) + std::string grid_nick = it->second->getGridNick(); + // There's no reason why empty grids nicks should be in this list, ugh + if (!grid_nick.empty() && grid_nick != gHippoGridManager->getCurrentGridNick()) { - LLSD value; - value["id"] = grid; - value["columns"][0]["column"] = "grid"; - value["columns"][0]["value"] = grid; - grids->addElement(value); - - if (grid == FloaterGridManager::getInstance()->getCurGrid()) - { - selectIndex = i; - } - i++; + element["id"] = grid_nick; + element["columns"][0]["column"] = "grid"; + element["columns"][0]["type"] = "text"; + element["columns"][0]["value"] = grid_nick; + grids->addElement(element, ADD_BOTTOM); } } + // Setting the default needs to be rethought. + // Right now, we just use the last-selected grid, + // but leaving this as the current behavior for now + if (!gHippoGridManager->getCurrentGridNick().empty()) + { + element["id"] = gHippoGridManager->getCurrentGridNick(); + element["columns"][0]["column"] = "grid"; + element["columns"][0]["type"] = "text"; + element["columns"][0]["font-style"] = "BOLD"; + element["columns"][0]["value"] = gHippoGridManager->getCurrentGridNick(); + grids->addElement(element, ADD_TOP); + } + + // Reselect the item if we had one selected + if (lastSelectedItem.empty()) + { + grids->selectItemByLabel(gHippoGridManager->getCurrentGridNick()); + } + else + { + grids->selectItemByLabel(lastSelectedItem); + } + + // TODO: get rid of all this state junk if ((FloaterGridManager::getInstance()->getState() == ADD_NEW) || (FloaterGridManager::getInstance()->getState() == ADD_COPY)) { - grids->addElement(""); - selectIndex = i++; + grids->addElement("", ADD_BOTTOM); } //if (selectIndex >= 0) @@ -161,9 +206,10 @@ void FloaterGridManager::refreshGrids() // FloaterGridManager::getInstance()->childSetTextArg("default_grid", "[DEFAULT]", (defaultGrid != "")? defaultGrid: " "); - FloaterGridManager::getInstance()->childSetEnabled("btn_delete", (selectIndex >= 0)); - FloaterGridManager::getInstance()->childSetEnabled("btn_copy", (FloaterGridManager::getInstance()->getState() == NORMAL) && (selectIndex >= 0)); - // FloaterGridManager::getInstance()->childSetEnabled("set_default", (FloaterGridManager::getInstance()->getState() == NORMAL) && (selectIndex > 0)); + FloaterGridManager::getInstance()->childSetEnabled("btn_delete", grids->getItemCount() > 0); + + FloaterGridManager::getInstance()->childSetEnabled("btn_copy", (FloaterGridManager::getInstance()->getState() == NORMAL) && (grids->getItemCount() > 0)); + // FloaterGridManager::getInstance()->childSetEnabled("set_default", (FloaterGridManager::getInstance()->getState() == NORMAL) && (grids->getItemCount() > 0)); FloaterGridManager::getInstance()->childSetEnabled("gridnick", (FloaterGridManager::getInstance()->getState() == ADD_NEW) || (FloaterGridManager::getInstance()->getState() == ADD_COPY)); if (FloaterGridManager::getInstance()->getState() == NORMAL) @@ -309,15 +355,15 @@ bool FloaterGridManager::createNewGrid() if (gridnick.empty()) { - //KOW gViewerWindow->alertXml("GridsNoNick"); + LLNotifications::instance().add("GridsNoNick"); return false; } if (gHippoGridManager->getGrid(gridnick)) { - //LLStringUtil::format_map_t args; - //args["[NAME]"] = gridnick; - //KOW gViewerWindow->alertXml("GridExists", args); + LLSD args; + args["[NAME]"] = gridnick; + LLNotifications::instance().add("GridExists", args); return false; } @@ -325,9 +371,9 @@ bool FloaterGridManager::createNewGrid() std::string loginuri = childGetValue("loginuri"); if ((loginuri.empty()) || (loginuri == "")) { - //LLStringUtil::format_map_t args; - //args["[NAME]"] = gridnick; - //KOW gViewerWindow->alertXml("GridsNoLoginUri", args); + LLSD args; + args["[NAME]"] = gridnick; + LLNotifications::instance().add("GridsNoLoginUri", args); return false; } @@ -365,7 +411,7 @@ void FloaterGridManager::retrieveGridInfo() std::string loginuri = childGetValue("loginuri"); if ((loginuri == "") || (loginuri == "")) { - //KOW gViewerWindow->alertXml("GridInfoNoLoginUri"); + LLNotifications::instance().add("GridInfoNoLoginUri"); return; } @@ -408,7 +454,7 @@ void FloaterGridManager::retrieveGridInfo() } else { - //KOW gViewerWindow->alertXml("GridInfoError"); + LLNotifications::instance().add("GridInfoError"); } if (cleanupGrid) delete grid; @@ -533,8 +579,7 @@ void FloaterGridManager::onClickApply(void* data) // static void FloaterGridManager::onClickClear(void* data) { - gHippoGridManager->discardAndReload(); - FloaterGridManager::getInstance()->update(); + FloaterGridManager::getInstance()->clearInfo(); } //static @@ -595,38 +640,6 @@ void FloaterGridManager::onClickCancel(void* data) //FloaterGridManager::getInstance()->childSetVisible("server_combo", TRUE); //} -//void FloaterGridManager::newShow(const std::string &grid, bool initialLogin) -//{ -// llinfos << "newShow called" << llendl; -// /*if (!FloaterGridManager::getInstance()) -// { -// FloaterGridManager::sGrid = grid; -// FloaterGridManager::sIsInitialLogin = initialLogin; -// FloaterGridManager::getInstance() = new FloaterGridManager(); -// -// llinfos << "FloaterGridManager::getInstance() assigned. FloaterGridManager::getInstance()=" << FloaterGridManager::getInstance() << llendl; -// }*/ -// -// llinfos << "newshow called" << llendl; -// FloaterGridManager::getInstance()->setCurGrid(gHippoGridManager->getCurrentGridNick()); -// refreshGrids(); -// -// FloaterGridManager::getInstance()->open(); -// // we're important -// //FloaterGridManager::getInstance()->setFrontmost(TRUE); -// //FloaterGridManager::getInstance()->setFocus(TRUE); -// -//} - -//void FloaterGridManager::show(const LLRect &rect, BOOL show_server, -// void (*callback)(S32 option, void* user_data), -// void* callback_data) -//{ -// // we don't need a grid passed in because this is old-style login -// std::string grid = ""; -// newShow(grid, TRUE); -//} - //void FloaterGridManager::setFocus(BOOL b) //{ // if(b != hasFocus()) diff --git a/linden/indra/newview/floatergridmanager.h b/linden/indra/newview/floatergridmanager.h index 16720bd..55517f5 100644 --- a/linden/indra/newview/floatergridmanager.h +++ b/linden/indra/newview/floatergridmanager.h @@ -30,6 +30,12 @@ public: //void setDefault(); void cancel(); + void clearInfo(); + + virtual void draw(); + + void refresh(); + // new-style login methods virtual std::string& getPassword(); virtual void setPassword(std::string &password); diff --git a/linden/indra/newview/hippoGridManager.cpp b/linden/indra/newview/hippoGridManager.cpp index e89e3ff..c9f2549 100644 --- a/linden/indra/newview/hippoGridManager.cpp +++ b/linden/indra/newview/hippoGridManager.cpp @@ -1,4 +1,4 @@ - +// Ported to Imprudence from the Hippo OpenSim Viewer by Jacek Antonelli #include "llviewerprecompiledheaders.h" @@ -173,11 +173,16 @@ void HippoGridInfo::setPlatform(const std::string &platform) for (unsigned i=0; imXmlState) { - - case XML_GRIDNICK: { + switch (self->mXmlState) + { + case XML_GRIDNICK: + { if (self->mGridNick == "") self->mGridNick.assign(s, len); self->mGridNick = sanitizeGridNick(self->mGridNick); break; } - case XML_PLATFORM: { + case XML_PLATFORM: + { std::string platform(s, len); self->setPlatform(platform); break; } - case XML_LOGINURI: { + case XML_LOGINURI: + { std::string loginuri(s, len); self->mLoginUri = sanitizeUri( loginuri ); break; } - case XML_HELPERURI: { + case XML_HELPERURI: + { std::string helperuri(s, len); self->mHelperUri = sanitizeUri( helperuri ); break; } - case XML_SEARCH: { + case XML_SEARCH: + { //self->mSearchUrl.assign(s, len); //sanitizeQueryUrl(mSearchUrl); break; @@ -426,7 +457,8 @@ bool HippoGridInfo::retrieveGridInfo() XML_SetElementHandler(parser, onXmlElementStart, onXmlElementEnd); XML_SetCharacterDataHandler(parser, onXmlCharacterData); mXmlState = XML_VOID; - if (!XML_Parse(parser, reply.data(), reply.size(), TRUE)) { + if (!XML_Parse(parser, reply.data(), reply.size(), TRUE)) + { llwarns << "XML Parse Error: " << XML_ErrorString(XML_GetErrorCode(parser)) << llendl; success = false; } @@ -477,7 +509,8 @@ void HippoGridInfo::formatFee(std::string &fee, int cost, bool showFree) const // static const char *HippoGridInfo::getPlatformString(Platform platform) { - static const char *platformStrings[PLATFORM_LAST] = { + static const char *platformStrings[PLATFORM_LAST] = + { "Other", "OpenSim", "SecondLife" }; @@ -492,11 +525,15 @@ std::string HippoGridInfo::sanitizeGridNick(std::string &gridnick) { std::string tmp; int size = gridnick.size(); - for (int i=0; i::iterator it, end = mGridInfo.end(); - for (it=mGridInfo.begin(); it != end; ++it) { + for (it=mGridInfo.begin(); it != end; ++it) + { delete it->second; } mGridInfo.clear(); @@ -589,9 +629,12 @@ HippoGridInfo* HippoGridManager::getGrid(const std::string &grid) const { std::map::const_iterator it; it = mGridInfo.find(grid); - if (it != mGridInfo.end()) { + if (it != mGridInfo.end()) + { return it->second; - } else { + } + else + { return 0; } } @@ -606,9 +649,12 @@ HippoGridInfo* HippoGridManager::getConnectedGrid() const HippoGridInfo* HippoGridManager::getCurrentGrid() const { HippoGridInfo *grid = getGrid(mCurrentGrid); - if (grid) { + if (grid) + { return grid; - } else { + } + else + { return &HippoGridInfo::FALLBACK_GRIDINFO; } } @@ -620,6 +666,10 @@ const std::string& HippoGridManager::getDefaultGridNick() const const std::string& HippoGridManager::getCurrentGridNick() const { + if (mCurrentGrid.empty()) + { + return mDefaultGrid; + } return mCurrentGrid; } @@ -633,12 +683,14 @@ void HippoGridManager::addGrid(HippoGridInfo *grid) { if (!grid) return; const std::string &nick = grid->getGridNick(); - if (nick == "") { + if (nick == "") + { llwarns << "Ignoring to try adding grid with empty nick." << llendl; delete grid; return; } - if (mGridInfo.find(nick) != mGridInfo.end()) { + if (mGridInfo.find(nick) != mGridInfo.end()) + { llwarns << "Ignoring to try adding existing grid " << nick << '.' << llendl; delete grid; return; @@ -667,13 +719,20 @@ void HippoGridManager::deleteGrid(const std::string &grid) void HippoGridManager::setDefaultGrid(const std::string &grid) { GridIterator it = mGridInfo.find(grid); - if (it != mGridInfo.end()) { + if (it != mGridInfo.end()) + { mDefaultGrid = grid; - } else if (mGridInfo.find("secondlife") != mGridInfo.end()) { + } + else if (mGridInfo.find("secondlife") != mGridInfo.end()) + { mDefaultGrid = "secondlife"; - } else if (!mGridInfo.empty()) { + } + else if (!mGridInfo.empty()) + { mDefaultGrid = mGridInfo.begin()->first; - } else { + } + else + { mDefaultGrid = ""; } } @@ -682,9 +741,12 @@ void HippoGridManager::setDefaultGrid(const std::string &grid) void HippoGridManager::setCurrentGrid(const std::string &grid) { GridIterator it = mGridInfo.find(grid); - if (it != mGridInfo.end()) { + if (it != mGridInfo.end()) + { mCurrentGrid = grid; - } else if (!mGridInfo.empty()) { + } + else if (!mGridInfo.empty()) + { llwarns << "Unknown grid '" << grid << "'. Setting to default grid." << llendl; mCurrentGrid = mDefaultGrid; } @@ -722,7 +784,8 @@ void HippoGridManager::parseUrl(const char *url, bool mergeIfNewer) // check response, return on error S32 status = response["status"].asInteger(); - if ((status != 200) || !response["body"].isArray()) { + if ((status != 200) || !response["body"].isArray()) + { llinfos << "GridInfo Update failed (" << status << "): " << (response["body"].isString()? response["body"].asString(): "") << llendl; @@ -737,13 +800,15 @@ void HippoGridManager::parseFile(const std::string &fileName, bool mergeIfNewer) { llifstream infile; infile.open(fileName.c_str()); - if(!infile.is_open()) { + if (!infile.is_open()) + { llwarns << "Cannot find grid info file " << fileName << " to load." << llendl; return; } LLSD gridInfo; - if (LLSDSerialize::fromXML(gridInfo, infile) <= 0) { + if (LLSDSerialize::fromXML(gridInfo, infile) <= 0) + { llwarns << "Unable to parse grid info file " << fileName << '.' << llendl; return; } @@ -755,17 +820,21 @@ void HippoGridManager::parseFile(const std::string &fileName, bool mergeIfNewer) void HippoGridManager::parseData(LLSD &gridInfo, bool mergeIfNewer) { - if (mergeIfNewer) { + if (mergeIfNewer) + { LLSD::array_const_iterator it, end = gridInfo.endArray(); - for (it = gridInfo.beginArray(); it != end; ++it) { + for (it = gridInfo.beginArray(); it != end; ++it) + { LLSD gridMap = *it; - if (gridMap.has("default_grids_version")) { + if (gridMap.has("default_grids_version")) + { int version = gridMap["default_grids_version"]; if (version <= mDefaultGridsVersion) return; else break; } } - if (it == end) { + if (it == end) + { llwarns << "Grid data has no version number." << llendl; return; } @@ -774,19 +843,26 @@ void HippoGridManager::parseData(LLSD &gridInfo, bool mergeIfNewer) llinfos << "Loading grid data." << llendl; LLSD::array_const_iterator it, end = gridInfo.endArray(); - for (it = gridInfo.beginArray(); it != end; ++it) { + for (it = gridInfo.beginArray(); it != end; ++it) + { LLSD gridMap = *it; - if (gridMap.has("default_grids_version")) { + if (gridMap.has("default_grids_version")) + { mDefaultGridsVersion = gridMap["default_grids_version"]; - } else if (gridMap.has("gridnick") && gridMap.has("loginuri")) { + } + else if (gridMap.has("gridnick") && gridMap.has("loginuri")) + { std::string gridnick = gridMap["gridnick"]; HippoGridInfo *grid; GridIterator it = mGridInfo.find(gridnick); bool newGrid = (it == mGridInfo.end()); - if (newGrid) { + if (newGrid) + { // create new grid info grid = new HippoGridInfo(gridnick); - } else { + } + else + { // update existing grid info grid = it->second; } @@ -822,7 +898,8 @@ void HippoGridManager::saveFile() // add grids S32 i = 1; GridIterator it, end = mGridInfo.end(); - for (it = mGridInfo.begin(); it != end; ++it, i++) { + for (it = mGridInfo.begin(); it != end; ++it, i++) + { HippoGridInfo *grid = it->second; gridInfo[i]["gridnick"] = grid->getGridNick(); gridInfo[i]["platform"] = HippoGridInfo::getPlatformString(grid->getPlatform()); @@ -846,11 +923,14 @@ void HippoGridManager::saveFile() std::string fileName = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "grid_info.xml"); llofstream file; file.open(fileName.c_str()); - if (file.is_open()) { + if (file.is_open()) + { LLSDSerialize::toPrettyXML(gridInfo, file); file.close(); llinfos << "Saved grids to " << fileName << llendl; - } else { + } + else + { llerrs << "Unable to open grid info file: " << fileName << llendl; } } diff --git a/linden/indra/newview/skins/default/xui/en-us/floater_grid_manager.xml b/linden/indra/newview/skins/default/xui/en-us/floater_grid_manager.xml index df7b2a0..8d3e101 100644 --- a/linden/indra/newview/skins/default/xui/en-us/floater_grid_manager.xml +++ b/linden/indra/newview/skins/default/xui/en-us/floater_grid_manager.xml @@ -14,10 +14,10 @@ - + @@ -122,7 +122,7 @@ halign="center" follows="left|top" scale_image="true" font="SansSerifSmall" mouse_opaque="true" />