diff options
Diffstat (limited to 'linden/indra/newview/floaterlogin.cpp')
-rw-r--r-- | linden/indra/newview/floaterlogin.cpp | 723 |
1 files changed, 723 insertions, 0 deletions
diff --git a/linden/indra/newview/floaterlogin.cpp b/linden/indra/newview/floaterlogin.cpp new file mode 100644 index 0000000..f1afc53 --- /dev/null +++ b/linden/indra/newview/floaterlogin.cpp | |||
@@ -0,0 +1,723 @@ | |||
1 | /* | ||
2 | * floaterlogin.cpp (floatergridmanager.cpp pls) | ||
3 | * This is Meerkats grid manager, and I accidentally finished it with the wrong name :) | ||
4 | * -Patrick Sapinski (Monday, August 17, 2009) | ||
5 | */ | ||
6 | |||
7 | #include "llviewerprecompiledheaders.h" | ||
8 | |||
9 | #include <boost/algorithm/string.hpp> | ||
10 | #include "llviewercontrol.h" | ||
11 | #include "llviewerbuild.h" | ||
12 | #include "llcombobox.h" | ||
13 | #include "llscrolllistctrl.h" | ||
14 | #include "llmd5.h" | ||
15 | #include "llurlsimstring.h" | ||
16 | #include "lluictrlfactory.h" | ||
17 | #include "floaterlogin.h" | ||
18 | #include "hippoGridManager.h" | ||
19 | #include "llviewernetwork.h" | ||
20 | #include "llpanellogin.h" | ||
21 | |||
22 | #define PASSWORD_FILLER "123456789!123456" | ||
23 | |||
24 | LoginFloater* LoginFloater::sInstance = NULL; | ||
25 | LoginController* LoginFloater::sController = NULL; | ||
26 | bool LoginFloater::sIsInitialLogin; | ||
27 | std::string LoginFloater::sGrid; | ||
28 | |||
29 | LoginFloater::LoginFloater() | ||
30 | : LLFloater("floater_login") | ||
31 | { | ||
32 | |||
33 | mState = NORMAL; | ||
34 | LLUICtrlFactory::getInstance()->buildFloater(this, "floater_login.xml"); | ||
35 | |||
36 | |||
37 | llwarns << "LoginFloater called" << llendl; | ||
38 | |||
39 | |||
40 | // configure the floater interface for non-initial login | ||
41 | setCanMinimize(!sIsInitialLogin); | ||
42 | setCanClose(!sIsInitialLogin); | ||
43 | setCanDrag(!sIsInitialLogin); | ||
44 | childSetVisible("server_combo", sIsInitialLogin); | ||
45 | |||
46 | if(!sIsInitialLogin) | ||
47 | { | ||
48 | LLButton* quit_btn = getChild<LLButton>("quit_btn"); | ||
49 | quit_btn->setLabel(std::string("Cancel")); | ||
50 | setTitle(std::string("Grid Manager")); | ||
51 | } | ||
52 | |||
53 | center(); | ||
54 | LLLineEditor* edit = getChild<LLLineEditor>("avatar_password_edit"); | ||
55 | if (edit) edit->setDrawAsterixes(TRUE); | ||
56 | LLComboBox* combo = getChild<LLComboBox>("start_location_combo"); | ||
57 | combo->setAllowTextEntry(TRUE, 128, FALSE); | ||
58 | |||
59 | BOOL login_last = gSavedSettings.getBOOL("LoginLastLocation"); | ||
60 | std::string sim_string = LLURLSimString::sInstance.mSimString; | ||
61 | if (!sim_string.empty()) | ||
62 | { | ||
63 | // Replace "<Type region name>" with this region name | ||
64 | combo->remove(2); | ||
65 | combo->add( sim_string ); | ||
66 | combo->setTextEntry(sim_string); | ||
67 | combo->setCurrentByIndex( 2 ); | ||
68 | } | ||
69 | else if (login_last) | ||
70 | { | ||
71 | combo->setCurrentByIndex( 1 ); | ||
72 | } | ||
73 | else | ||
74 | { | ||
75 | combo->setCurrentByIndex( 0 ); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | |||
80 | LoginFloater::~LoginFloater() | ||
81 | { | ||
82 | LoginFloater::sController = NULL; | ||
83 | LoginFloater::sInstance = NULL; | ||
84 | } | ||
85 | |||
86 | void LoginFloater::close() | ||
87 | { | ||
88 | if(sInstance) | ||
89 | { | ||
90 | delete sInstance; | ||
91 | sInstance = NULL; | ||
92 | } | ||
93 | } | ||
94 | |||
95 | BOOL LoginFloater::postBuild() | ||
96 | { | ||
97 | requires<LLScrollListCtrl>("grid_selector"); | ||
98 | requires<LLLineEditor>("gridnick"); | ||
99 | requires<LLLineEditor>("gridname"); | ||
100 | requires<LLLineEditor>("loginuri"); | ||
101 | requires<LLLineEditor>("loginpage"); | ||
102 | requires<LLLineEditor>("helperuri"); | ||
103 | requires<LLLineEditor>("website"); | ||
104 | requires<LLLineEditor>("support"); | ||
105 | requires<LLLineEditor>("register"); | ||
106 | requires<LLLineEditor>("password"); | ||
107 | requires<LLLineEditor>("first_name"); | ||
108 | requires<LLLineEditor>("last_name"); | ||
109 | requires<LLLineEditor>("avatar_password"); | ||
110 | //requires<LLLineEditor>("search"); | ||
111 | requires<LLButton>("btn_delete"); | ||
112 | requires<LLButton>("btn_add"); | ||
113 | requires<LLButton>("btn_copy"); | ||
114 | requires<LLButton>("set_default"); | ||
115 | requires<LLButton>("btn_gridinfo"); | ||
116 | requires<LLButton>("btn_help_render_compat"); | ||
117 | if (!checkRequirements()) return false; | ||
118 | LLLineEditor* password_edit = getChild<LLLineEditor>("avatar_password"); | ||
119 | if (password_edit) password_edit->setDrawAsterixes(TRUE); | ||
120 | |||
121 | childSetAction("btn_delete", onClickDelete, this); | ||
122 | childSetAction("btn_add", onClickAdd, this); | ||
123 | childSetAction("btn_copy", onClickCopy, this); | ||
124 | childSetAction("btn_ok", onClickOk, this); | ||
125 | childSetAction("btn_apply", onClickApply, this); | ||
126 | // childSetAction("set_default", onClickDefault, this); | ||
127 | childSetAction("btn_cancel", onClickCancel, this); | ||
128 | childSetAction("btn_gridinfo", onClickGridInfo, this); | ||
129 | // childSetAction("btn_help_render_compat", onClickHelpRenderCompat, this); | ||
130 | |||
131 | childSetCommitCallback("grid_selector", onSelectGrid, this); | ||
132 | //KOW childSetCommitCallback("platform", onSelectPlatform, this); | ||
133 | |||
134 | // !!!### server_choice_combo->setFocusLostCallback(onServerComboLostFocus); | ||
135 | |||
136 | //KOW update(); | ||
137 | return TRUE; | ||
138 | } | ||
139 | |||
140 | void LoginFloater::refresh_grids() | ||
141 | { | ||
142 | const std::string &defaultGrid = gHippoGridManager->getDefaultGridNick(); | ||
143 | LLScrollListCtrl *grids = sInstance->getChild<LLScrollListCtrl>("grid_selector"); | ||
144 | S32 selectIndex = -1, i = 0; | ||
145 | grids->deleteAllItems(); | ||
146 | if (defaultGrid != "") { | ||
147 | LLSD value; | ||
148 | value["id"] = defaultGrid; | ||
149 | value["columns"][0]["column"] = "grid"; | ||
150 | value["columns"][0]["value"] = defaultGrid; | ||
151 | grids->addElement(value); | ||
152 | selectIndex = i++; | ||
153 | } | ||
154 | |||
155 | HippoGridManager::GridIterator it, end = gHippoGridManager->endGrid(); | ||
156 | for (it = gHippoGridManager->beginGrid(); it != end; ++it) { | ||
157 | const std::string &grid = it->second->getGridNick(); | ||
158 | if (grid != defaultGrid) { | ||
159 | LLSD value; | ||
160 | value["id"] = grid; | ||
161 | value["columns"][0]["column"] = "grid"; | ||
162 | value["columns"][0]["value"] = grid; | ||
163 | grids->addElement(value); | ||
164 | |||
165 | if (grid == sInstance->mCurGrid) selectIndex = i; | ||
166 | i++; | ||
167 | } | ||
168 | } | ||
169 | if ((sInstance->mState == ADD_NEW) || (sInstance->mState == ADD_COPY)) { | ||
170 | grids->addElement("<new>"); | ||
171 | selectIndex = i++; | ||
172 | } | ||
173 | if (selectIndex >= 0) { | ||
174 | //grids->setCurrentByIndex(selectIndex); | ||
175 | } else { | ||
176 | //grids->setLabel(LLStringExplicit("")); // LLComboBox::removeall() does not clear the label | ||
177 | } | ||
178 | |||
179 | // sInstance->childSetTextArg("default_grid", "[DEFAULT]", (defaultGrid != "")? defaultGrid: " "); | ||
180 | |||
181 | sInstance->childSetEnabled("btn_delete", (selectIndex >= 0)); | ||
182 | sInstance->childSetEnabled("btn_copy", (sInstance->mState == NORMAL) && (selectIndex >= 0)); | ||
183 | // sInstance->childSetEnabled("set_default", (sInstance->mState == NORMAL) && (selectIndex > 0)); | ||
184 | sInstance->childSetEnabled("gridnick", (sInstance->mState == ADD_NEW) || (sInstance->mState == ADD_COPY)); | ||
185 | |||
186 | if (sInstance->mState == NORMAL) { | ||
187 | HippoGridInfo *gridInfo = gHippoGridManager->getGrid(sInstance->mCurGrid); | ||
188 | if (gridInfo) { | ||
189 | sInstance->childSetText("gridnick", gridInfo->getGridNick()); | ||
190 | //sInstance->childSetText("grid_name", gridInfo->getGridName()); | ||
191 | sInstance->childSetText("loginuri", gridInfo->getLoginUri()); | ||
192 | sInstance->childSetText("loginpage", gridInfo->getLoginPage()); | ||
193 | sInstance->childSetText("helperuri", gridInfo->getHelperUri()); | ||
194 | sInstance->childSetText("website", gridInfo->getWebSite()); | ||
195 | sInstance->childSetText("support", gridInfo->getSupportUrl()); | ||
196 | sInstance->childSetText("register", gridInfo->getRegisterUrl()); | ||
197 | sInstance->childSetText("password", gridInfo->getPasswordUrl()); | ||
198 | |||
199 | // sInstance->childSetText("first_name", gridInfo->getFirstName()); | ||
200 | // sInstance->childSetText("last_name", gridInfo->getLastName()); | ||
201 | // if(gridInfo->getAvatarPassword().length() == 32) | ||
202 | // sInstance->childSetText("avatar_password", std::string(PASSWORD_FILLER)); | ||
203 | // else if(gridInfo->getPasswordUrl().empty()) | ||
204 | // sInstance->childSetText("avatar_password", std::string("")); | ||
205 | |||
206 | // if (gridInfo->getPlatform() == HippoGridInfo::PLATFORM_SECONDLIFE) { | ||
207 | // //childSetEnabled("search", false); | ||
208 | // //childSetText("search", LLStringExplicit("")); | ||
209 | // childSetEnabled("render_compat", false); | ||
210 | // childSetValue("render_compat", false); | ||
211 | // } else { | ||
212 | // //childSetEnabled("search", true); | ||
213 | // //childSetText("search", gridInfo->getSearchUrl()); | ||
214 | // childSetEnabled("render_compat", true); | ||
215 | // childSetValue("render_compat", gridInfo->isRenderCompat()); | ||
216 | // } | ||
217 | |||
218 | } else { | ||
219 | std::string empty = ""; | ||
220 | sInstance->childSetText("gridnick", empty); | ||
221 | sInstance->childSetText("gridname", empty); | ||
222 | sInstance->childSetText("loginuri", empty); | ||
223 | sInstance->childSetText("loginpage", empty); | ||
224 | sInstance->childSetText("helperuri", empty); | ||
225 | sInstance->childSetText("website", empty); | ||
226 | // sInstance->childSetText("first_name", empty); | ||
227 | // sInstance->childSetText("last_name", empty); | ||
228 | // sInstance->childSetText("avatar_password", empty); | ||
229 | } | ||
230 | } else if (sInstance->mState == ADD_NEW) { | ||
231 | llwarns << "ADD_NEW" << llendl; | ||
232 | std::string required = "<required>"; | ||
233 | std::string empty = ""; | ||
234 | sInstance->childSetText("gridnick", required); | ||
235 | sInstance->childSetText("gridname", empty); | ||
236 | sInstance->childSetText("loginuri", required); | ||
237 | sInstance->childSetText("loginpage", empty); | ||
238 | sInstance->childSetText("helperuri", empty); | ||
239 | sInstance->childSetText("website", empty); | ||
240 | sInstance->childSetText("support", empty); | ||
241 | sInstance->childSetText("register", empty); | ||
242 | sInstance->childSetText("password", empty); | ||
243 | // sInstance->childSetText("first_name", empty); | ||
244 | // sInstance->childSetText("last_name", empty); | ||
245 | // sInstance->childSetText("avatar_password", empty); | ||
246 | //childSetEnabled("search", true); | ||
247 | //childSetText("search", empty); | ||
248 | } else if (sInstance->mState == ADD_COPY) { | ||
249 | llwarns << "ADD_COPY" << llendl; | ||
250 | sInstance->childSetText("gridnick", LLStringExplicit("<required>")); | ||
251 | } else { | ||
252 | llwarns << "Illegal state " << sInstance->mState << '.' << llendl; | ||
253 | } | ||
254 | return; | ||
255 | } | ||
256 | |||
257 | void LoginFloater::update() | ||
258 | { | ||
259 | mState = NORMAL; | ||
260 | mCurGrid = gHippoGridManager->getCurrentGridNick(); | ||
261 | refresh_grids(); | ||
262 | //KOW gHippoLimits->setLimits(); | ||
263 | } | ||
264 | |||
265 | void LoginFloater::applyChanges() | ||
266 | { | ||
267 | HippoGridInfo *gridInfo = gHippoGridManager->getGrid(mCurGrid); | ||
268 | if (gridInfo) | ||
269 | { | ||
270 | if (gridInfo->getGridNick() == childGetValue("gridnick").asString()) | ||
271 | { | ||
272 | gridInfo->setGridName(childGetValue("gridname")); | ||
273 | gridInfo->setLoginUri(childGetValue("loginuri")); | ||
274 | gridInfo->setLoginPage(childGetValue("loginpage")); | ||
275 | gridInfo->setHelperUri(childGetValue("helperuri")); | ||
276 | gridInfo->setWebSite(childGetValue("website")); | ||
277 | gridInfo->setSupportUrl(childGetValue("support")); | ||
278 | gridInfo->setRegisterUrl(childGetValue("register")); | ||
279 | gridInfo->setPasswordUrl(childGetValue("password")); | ||
280 | //gridInfo->setSearchUrl(childGetValue("search")); | ||
281 | gridInfo->setRenderCompat(childGetValue("render_compat")); | ||
282 | |||
283 | // gridInfo->setFirstName(childGetValue("first_name")); | ||
284 | // gridInfo->setLastName(childGetValue("last_name")); | ||
285 | // if(childGetValue("avatar_password").asString().empty()) | ||
286 | // gridInfo->setAvatarPassword(std::string("")); | ||
287 | // else if(childGetValue("avatar_password").asString() != std::string(PASSWORD_FILLER)) | ||
288 | // { | ||
289 | // // store account authentication data | ||
290 | // std::string auth_password = childGetValue("avatar_password"); | ||
291 | // std::string hashed_password; | ||
292 | // hashPassword(auth_password, hashed_password); | ||
293 | // gridInfo->setAvatarPassword(hashed_password); | ||
294 | // } | ||
295 | |||
296 | //this bug was a feature -Patrick Sapinski (Friday, August 21, 2009) | ||
297 | //LLPanelLogin::setFields(gridInfo->getFirstName(), gridInfo->getLastName(), | ||
298 | // gridInfo->getAvatarPassword(), true); | ||
299 | } | ||
300 | else | ||
301 | { | ||
302 | llwarns << "Grid nickname mismatch, ignoring changes." << llendl; | ||
303 | } | ||
304 | } | ||
305 | } | ||
306 | |||
307 | |||
308 | bool LoginFloater::createNewGrid() | ||
309 | { | ||
310 | // check nickname | ||
311 | std::string gridnick = childGetValue("gridnick"); | ||
312 | if (gridnick == "<required>") gridnick = ""; | ||
313 | if (gridnick == "") { | ||
314 | //KOW gViewerWindow->alertXml("GridsNoNick"); | ||
315 | return false; | ||
316 | } | ||
317 | if (gHippoGridManager->getGrid(gridnick)) { | ||
318 | LLStringUtil::format_map_t args; | ||
319 | args["[NAME]"] = gridnick; | ||
320 | //KOW gViewerWindow->alertXml("GridExists", args); | ||
321 | return false; | ||
322 | } | ||
323 | |||
324 | // check login URI | ||
325 | std::string loginuri = childGetValue("loginuri"); | ||
326 | if ((loginuri == "") || (loginuri == "<required>")) { | ||
327 | LLStringUtil::format_map_t args; | ||
328 | args["[NAME]"] = gridnick; | ||
329 | //KOW gViewerWindow->alertXml("GridsNoLoginUri", args); | ||
330 | return false; | ||
331 | } | ||
332 | |||
333 | // create new grid | ||
334 | HippoGridInfo *grid = new HippoGridInfo(gridnick); | ||
335 | grid->setGridName(childGetValue("gridname")); | ||
336 | grid->setLoginUri(loginuri); | ||
337 | grid->setLoginPage(childGetValue("loginpage")); | ||
338 | grid->setHelperUri(childGetValue("helperuri")); | ||
339 | grid->setWebSite(childGetValue("website")); | ||
340 | grid->setSupportUrl(childGetValue("support")); | ||
341 | grid->setRegisterUrl(childGetValue("register")); | ||
342 | grid->setPasswordUrl(childGetValue("password")); | ||
343 | //grid->setSearchUrl(childGetValue("search")); | ||
344 | grid->setRenderCompat(childGetValue("render_compat")); | ||
345 | gHippoGridManager->addGrid(grid); | ||
346 | |||
347 | // grid->setFirstName(childGetValue("first_name")); | ||
348 | // grid->setLastName(childGetValue("last_name")); | ||
349 | // if(childGetValue("avatar_password").asString().empty()) | ||
350 | // grid->setAvatarPassword(std::string("")); | ||
351 | // else | ||
352 | // { | ||
353 | // std::string hashed_password; | ||
354 | // hashPassword(childGetValue("avatar_password"), hashed_password); | ||
355 | // grid->setAvatarPassword(hashed_password); | ||
356 | // } | ||
357 | |||
358 | mCurGrid = gridnick; | ||
359 | return true; | ||
360 | } | ||
361 | |||
362 | void LoginFloater::retrieveGridInfo() | ||
363 | { | ||
364 | std::string loginuri = childGetValue("loginuri"); | ||
365 | if ((loginuri == "") || (loginuri == "<required>")) { | ||
366 | //KOW gViewerWindow->alertXml("GridInfoNoLoginUri"); | ||
367 | return; | ||
368 | } | ||
369 | |||
370 | HippoGridInfo *grid = 0; | ||
371 | bool cleanupGrid = false; | ||
372 | if (mState == NORMAL) { | ||
373 | grid = gHippoGridManager->getGrid(mCurGrid); | ||
374 | } else if ((mState == ADD_NEW) || (mState == ADD_COPY)) { | ||
375 | grid = new HippoGridInfo(""); | ||
376 | cleanupGrid = true; | ||
377 | } else { | ||
378 | llerrs << "Illegal state " << mState << '.' << llendl; | ||
379 | return; | ||
380 | } | ||
381 | if (!grid) { | ||
382 | llerrs << "Internal error retrieving grid info." << llendl; | ||
383 | return; | ||
384 | } | ||
385 | |||
386 | grid->setLoginUri(loginuri); | ||
387 | if (grid->retrieveGridInfo()) { | ||
388 | if (grid->getGridNick() != "") childSetText("gridnick", grid->getGridNick()); | ||
389 | if (grid->getGridName() != "") childSetText("gridname", grid->getGridName()); | ||
390 | if (grid->getLoginUri() != "") childSetText("loginuri", grid->getLoginUri()); | ||
391 | if (grid->getLoginPage() != "") childSetText("loginpage", grid->getLoginPage()); | ||
392 | if (grid->getHelperUri() != "") childSetText("helperuri", grid->getHelperUri()); | ||
393 | if (grid->getWebSite() != "") childSetText("website", grid->getWebSite()); | ||
394 | if (grid->getSupportUrl() != "") childSetText("support", grid->getSupportUrl()); | ||
395 | if (grid->getRegisterUrl() != "") childSetText("register", grid->getRegisterUrl()); | ||
396 | if (grid->getPasswordUrl() != "") childSetText("password", grid->getPasswordUrl()); | ||
397 | //if (grid->getSearchUrl() != "") childSetText("search", grid->getSearchUrl()); | ||
398 | } else { | ||
399 | //KOW gViewerWindow->alertXml("GridInfoError"); | ||
400 | } | ||
401 | |||
402 | if (cleanupGrid) delete grid; | ||
403 | } | ||
404 | |||
405 | void LoginFloater::apply() | ||
406 | { | ||
407 | if (mState == NORMAL) { | ||
408 | applyChanges(); | ||
409 | } else if ((mState == ADD_NEW) || (mState == ADD_COPY)) { | ||
410 | if (!createNewGrid()) return; | ||
411 | } else { | ||
412 | llwarns << "Illegal state " << mState << '.' << llendl; | ||
413 | return; | ||
414 | } | ||
415 | //gHippoGridManager->setCurrentGrid(mCurGrid); | ||
416 | //gHippoGridManager->setDefaultGrid(mCurGrid); | ||
417 | //LLPanelLogin::refreshLoginPage(); | ||
418 | gHippoGridManager->saveFile(); | ||
419 | LLPanelLogin::addServer(LLViewerLogin::getInstance()->getGridLabel()); | ||
420 | } | ||
421 | |||
422 | void LoginFloater::setDefault() | ||
423 | { | ||
424 | if (mState == NORMAL) { | ||
425 | applyChanges(); | ||
426 | } else if ((mState == ADD_NEW) || (mState == ADD_COPY)) { | ||
427 | if (!createNewGrid()) return; | ||
428 | } else { | ||
429 | llwarns << "Illegal state " << mState << '.' << llendl; | ||
430 | return; | ||
431 | } | ||
432 | gHippoGridManager->setCurrentGrid(mCurGrid); | ||
433 | gHippoGridManager->setDefaultGrid(mCurGrid); | ||
434 | gHippoGridManager->saveFile(); | ||
435 | LLPanelLogin::addServer(LLViewerLogin::getInstance()->getGridLabel()); | ||
436 | } | ||
437 | |||
438 | void LoginFloater::cancel() | ||
439 | { | ||
440 | gHippoGridManager->discardAndReload(); | ||
441 | update(); | ||
442 | } | ||
443 | |||
444 | void LoginFloater::onSelectGrid(LLUICtrl* ctrl, void *data) | ||
445 | { | ||
446 | LoginFloater* self = (LoginFloater*)data; | ||
447 | if (self->mState == NORMAL) { | ||
448 | self->applyChanges(); | ||
449 | } else if ((self->mState == ADD_NEW) || (self->mState == ADD_COPY)) { | ||
450 | if (self->createNewGrid()) { | ||
451 | self->mState = NORMAL; | ||
452 | } else { | ||
453 | //LLScrollListCtrl *grids = self->getChild<LLScrollListCtrl>("grid_selector"); | ||
454 | //grids->setCurrentByIndex(grids->getItemCount() - 1); | ||
455 | return; | ||
456 | } | ||
457 | } else { | ||
458 | llwarns << "Illegal state " << self->mState << '.' << llendl; | ||
459 | return; | ||
460 | } | ||
461 | self->mCurGrid = ctrl->getValue().asString(); | ||
462 | self->refresh_grids(); | ||
463 | } | ||
464 | |||
465 | //static | ||
466 | void LoginFloater::onClickDelete(void *data) | ||
467 | { | ||
468 | llwarns << "onclickdelete" << llendl; | ||
469 | LoginFloater* self = (LoginFloater*)data; | ||
470 | if (self->mState == NORMAL) | ||
471 | gHippoGridManager->deleteGrid(self->mCurGrid); | ||
472 | self->update(); | ||
473 | } | ||
474 | |||
475 | //static | ||
476 | void LoginFloater::onClickAdd(void *data) | ||
477 | { | ||
478 | llwarns << "add" << llendl; | ||
479 | LoginFloater* self = (LoginFloater*)data; | ||
480 | self->mState = ADD_NEW; | ||
481 | self->refresh_grids(); | ||
482 | } | ||
483 | |||
484 | |||
485 | //static | ||
486 | void LoginFloater::onClickCopy(void *data) | ||
487 | { | ||
488 | llwarns << "copy" << llendl; | ||
489 | LoginFloater* self = (LoginFloater*)data; | ||
490 | self->mState = ADD_COPY; | ||
491 | self->refresh_grids(); | ||
492 | } | ||
493 | |||
494 | // static | ||
495 | void LoginFloater::onClickOk(void* data) | ||
496 | { | ||
497 | if(NULL==sInstance) | ||
498 | return; | ||
499 | |||
500 | sInstance->apply(); | ||
501 | sInstance->close(); | ||
502 | } | ||
503 | |||
504 | //static | ||
505 | void LoginFloater::onClickApply(void *data) | ||
506 | { | ||
507 | if(NULL==sInstance) | ||
508 | return; | ||
509 | |||
510 | sInstance->apply(); | ||
511 | refresh_grids(); | ||
512 | } | ||
513 | |||
514 | //static | ||
515 | void LoginFloater::onClickDefault(void *data) | ||
516 | { | ||
517 | sInstance->setDefault(); | ||
518 | sInstance->refresh_grids(); | ||
519 | } | ||
520 | |||
521 | //static | ||
522 | void LoginFloater::onClickGridInfo(void *data) | ||
523 | { | ||
524 | //HippoPanelGrids* self = (HippoPanelGrids*)data; | ||
525 | sInstance->retrieveGridInfo(); | ||
526 | } | ||
527 | |||
528 | //static | ||
529 | void LoginFloater::onClickCancel(void *data) | ||
530 | { | ||
531 | sInstance->cancel(); | ||
532 | } | ||
533 | |||
534 | void LoginFloater::setAlwaysRefresh(bool refresh) | ||
535 | { | ||
536 | // wargames 2: dead code, LLPanelLogin compatibility | ||
537 | return; | ||
538 | } | ||
539 | |||
540 | void LoginFloater::refreshLocation( bool force_visible ) | ||
541 | { | ||
542 | |||
543 | llwarns << "refreshLocation called" << llendl; | ||
544 | |||
545 | if (!sInstance) return; | ||
546 | |||
547 | LLComboBox* combo = sInstance->getChild<LLComboBox>("start_location_combo"); | ||
548 | |||
549 | if (LLURLSimString::parse()) | ||
550 | { | ||
551 | combo->setCurrentByIndex( 3 ); // BUG? Maybe 2? | ||
552 | combo->setTextEntry(LLURLSimString::sInstance.mSimString); | ||
553 | } | ||
554 | else | ||
555 | { | ||
556 | BOOL login_last = gSavedSettings.getBOOL("LoginLastLocation"); | ||
557 | combo->setCurrentByIndex( login_last ? 1 : 0 ); | ||
558 | } | ||
559 | |||
560 | BOOL show_start = TRUE; | ||
561 | |||
562 | if ( ! force_visible ) | ||
563 | show_start = gSavedSettings.getBOOL("ShowStartLocation"); | ||
564 | |||
565 | sInstance->childSetVisible("start_location_combo", show_start); | ||
566 | sInstance->childSetVisible("start_location_text", show_start); | ||
567 | sInstance->childSetVisible("server_combo", TRUE); | ||
568 | } | ||
569 | |||
570 | void LoginFloater::newShow(const std::string &grid, bool initialLogin) | ||
571 | { | ||
572 | |||
573 | llwarns << "newShow called" << llendl; | ||
574 | if(NULL==sInstance) | ||
575 | { | ||
576 | LoginFloater::sGrid = grid; | ||
577 | LoginFloater::sIsInitialLogin = initialLogin; | ||
578 | sInstance = new LoginFloater(); | ||
579 | |||
580 | llwarns << "sInstance assigned. sInstance=" << sInstance << llendl; | ||
581 | } | ||
582 | |||
583 | llwarns << "newshow called" << llendl; | ||
584 | sInstance->mCurGrid = gHippoGridManager->getCurrentGridNick(); | ||
585 | refresh_grids(); | ||
586 | |||
587 | sInstance->open(); /*Flawfinder: ignore*/ | ||
588 | // we're important | ||
589 | //sInstance->setFrontmost(TRUE); | ||
590 | //sInstance->setFocus(TRUE); | ||
591 | |||
592 | } | ||
593 | |||
594 | void LoginFloater::show(const LLRect &rect, BOOL show_server, | ||
595 | void (*callback)(S32 option, void* user_data), | ||
596 | void* callback_data) | ||
597 | { | ||
598 | // we don't need a grid passed in because this is old-style login | ||
599 | std::string grid = ""; | ||
600 | newShow(grid, TRUE); | ||
601 | } | ||
602 | |||
603 | void LoginFloater::setFocus(BOOL b) | ||
604 | { | ||
605 | if(b != hasFocus()) | ||
606 | { | ||
607 | if(b) | ||
608 | { | ||
609 | LoginFloater::giveFocus(); | ||
610 | } | ||
611 | else | ||
612 | { | ||
613 | LLPanel::setFocus(b); | ||
614 | } | ||
615 | } | ||
616 | } | ||
617 | |||
618 | void LoginFloater::giveFocus() | ||
619 | { | ||
620 | LLScrollListCtrl *combo = NULL; | ||
621 | |||
622 | if(NULL==sInstance) | ||
623 | { | ||
624 | llwarns << "giveFocus has no LoginFloater instance. sInstance=" << sInstance << llendl; | ||
625 | return; | ||
626 | } | ||
627 | |||
628 | // for our combo box approach, selecting the combo box is almost always | ||
629 | // the right thing to do on the floater receiving focus | ||
630 | combo = sInstance->getChild<LLScrollListCtrl>("grid_selector"); | ||
631 | combo->setFocus(TRUE); | ||
632 | } | ||
633 | |||
634 | BOOL LoginFloater::isGridComboDirty() | ||
635 | { | ||
636 | BOOL user_picked = FALSE; | ||
637 | if (!sInstance) | ||
638 | { | ||
639 | llwarns << "Attempted getServer with no login view shown" << llendl; | ||
640 | } | ||
641 | else | ||
642 | { | ||
643 | LLComboBox* combo = sInstance->getChild<LLComboBox>("server_combo"); | ||
644 | user_picked = combo->isDirty(); | ||
645 | } | ||
646 | return user_picked; | ||
647 | } | ||
648 | |||
649 | void LoginFloater::getLocation(std::string &location) | ||
650 | { | ||
651 | if (!sInstance) | ||
652 | { | ||
653 | llwarns << "Attempted getLocation with no login view shown" << llendl; | ||
654 | return; | ||
655 | } | ||
656 | |||
657 | LLComboBox* combo = sInstance->getChild<LLComboBox>("start_location_combo"); | ||
658 | location = combo->getValue().asString(); | ||
659 | } | ||
660 | |||
661 | std::string& LoginFloater::getPassword() | ||
662 | { | ||
663 | return mMungedPassword; | ||
664 | } | ||
665 | |||
666 | void LoginFloater::setPassword(std::string &password) | ||
667 | { | ||
668 | mMungedPassword = password; | ||
669 | } | ||
670 | |||
671 | bool LoginFloater::isSamePassword(std::string &password) | ||
672 | { | ||
673 | return mMungedPassword == password; | ||
674 | } | ||
675 | |||
676 | void LoginFloater::addServer(const std::string& server, S32 domain_name) | ||
677 | { | ||
678 | if (!sInstance) | ||
679 | { | ||
680 | llwarns << "Attempted addServer with no login view shown" << llendl; | ||
681 | return; | ||
682 | } | ||
683 | |||
684 | LLComboBox* combo = sInstance->getChild<LLComboBox>("server_combo"); | ||
685 | combo->add(server, LLSD(domain_name) ); | ||
686 | combo->setCurrentByIndex(0); | ||
687 | } | ||
688 | |||
689 | void LoginFloater::cancel_old() | ||
690 | { | ||
691 | if(NULL==sInstance) | ||
692 | return; | ||
693 | |||
694 | if(sInstance->sIsInitialLogin) | ||
695 | { | ||
696 | // send a callback that indicates we're quitting or closing | ||
697 | if(sInstance->mCallback) | ||
698 | sInstance->mCallback(LOGIN_OPTION_QUIT, sInstance->mCallbackData); | ||
699 | return; | ||
700 | } | ||
701 | |||
702 | sInstance->close(); | ||
703 | } | ||
704 | |||
705 | void LoginFloater::hashPassword(const std::string& password, std::string& hashedPassword) | ||
706 | { | ||
707 | // Max "actual" password length is 16 characters. | ||
708 | // Hex digests are always 32 characters. | ||
709 | if (password.length() == 32) | ||
710 | { | ||
711 | hashedPassword = password; | ||
712 | } | ||
713 | else | ||
714 | { | ||
715 | // this is a normal text password | ||
716 | LLMD5 pass((unsigned char *)password.c_str()); | ||
717 | char munged_password[MD5HEX_STR_SIZE]; | ||
718 | pass.hex_digest(munged_password); | ||
719 | hashedPassword = munged_password; | ||
720 | } | ||
721 | |||
722 | } | ||
723 | |||