00001
00032
00033
00034
00035
00036
00037
00038 #include "llviewerprecompiledheaders.h"
00039
00040 #include "llfloaterpreference.h"
00041
00042 #include "llbutton.h"
00043 #include "llcheckboxctrl.h"
00044 #include "lldir.h"
00045 #include "llfocusmgr.h"
00046 #include "llscrollbar.h"
00047 #include "llspinctrl.h"
00048 #include "message.h"
00049
00050 #include "llfloaterabout.h"
00051 #include "llpanelnetwork.h"
00052 #include "llpanelaudioprefs.h"
00053 #include "llpaneldisplay.h"
00054 #include "llpaneldebug.h"
00055 #include "llpanelgeneral.h"
00056 #include "llpanelinput.h"
00057 #include "llpanelLCD.h"
00058 #include "llpanelmsgs.h"
00059 #include "llpanelweb.h"
00060 #include "llpaneldatabase.h"
00061 #include "llprefschat.h"
00062 #include "llprefsvoice.h"
00063 #include "llprefsim.h"
00064 #include "llresizehandle.h"
00065 #include "llresmgr.h"
00066 #include "llassetstorage.h"
00067 #include "llagent.h"
00068 #include "llviewercontrol.h"
00069 #include "llviewernetwork.h"
00070 #include "llvieweruictrlfactory.h"
00071 #include "llviewerwindow.h"
00072 #include "llkeyboard.h"
00073 #include "llscrollcontainer.h"
00074
00075
00076 const S32 PREF_BORDER = 4;
00077 const S32 PREF_PAD = 5;
00078 const S32 PREF_BUTTON_WIDTH = 70;
00079 const S32 PREF_CATEGORY_WIDTH = 150;
00080
00081 const S32 PREF_FLOATER_MIN_HEIGHT = 2 * SCROLLBAR_SIZE + 2 * LLPANEL_BORDER_WIDTH + 96;
00082
00083 LLFloaterPreference* LLFloaterPreference::sInstance = NULL;
00084
00085 #if LL_WINDOWS
00086
00087 #ifndef LL_LOGITECH_LCD_H
00088 #include "lllogitechlcd.h"
00089 #endif
00090 extern llLCD *gLcdScreen;
00091 #endif
00092
00093
00094 S32 pref_min_width()
00095 {
00096 return
00097 2 * PREF_BORDER +
00098 2 * PREF_BUTTON_WIDTH +
00099 PREF_PAD + RESIZE_HANDLE_WIDTH +
00100 PREF_CATEGORY_WIDTH +
00101 PREF_PAD;
00102 }
00103
00104 S32 pref_min_height()
00105 {
00106 return
00107 2 * PREF_BORDER +
00108 3*(BTN_HEIGHT + PREF_PAD) +
00109 PREF_FLOATER_MIN_HEIGHT;
00110 }
00111
00112
00113 LLPreferenceCore::LLPreferenceCore(LLTabContainerCommon* tab_container, LLButton * default_btn) :
00114 mTabContainer(tab_container),
00115 mGeneralPanel(NULL),
00116 mInputPanel(NULL),
00117 mNetworkPanel(NULL),
00118 mDisplayPanel(NULL),
00119 mDisplayPanel2(NULL),
00120 mAudioPanel(NULL),
00121 mMsgPanel(NULL),
00122 mLCDPanel(NULL)
00123 {
00124 mGeneralPanel = new LLPanelGeneral();
00125 mTabContainer->addTabPanel(mGeneralPanel, mGeneralPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
00126 mGeneralPanel->setDefaultBtn(default_btn);
00127
00128 mInputPanel = new LLPanelInput();
00129 mTabContainer->addTabPanel(mInputPanel, mInputPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
00130 mInputPanel->setDefaultBtn(default_btn);
00131
00132 mNetworkPanel = new LLPanelNetwork();
00133 mTabContainer->addTabPanel(mNetworkPanel, mNetworkPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
00134 mNetworkPanel->setDefaultBtn(default_btn);
00135
00136 #if LL_LIBXUL_ENABLED
00137 mWebPanel = new LLPanelWeb();
00138 mTabContainer->addTabPanel(mWebPanel, mWebPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
00139 mWebPanel->setDefaultBtn(default_btn);
00140 #endif
00141
00142 mDisplayPanel = new LLPanelDisplay();
00143 mTabContainer->addTabPanel(mDisplayPanel, mDisplayPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
00144 mDisplayPanel->setDefaultBtn(default_btn);
00145
00146 mDisplayPanel3 = new LLPanelDisplay3();
00147 mTabContainer->addTabPanel(mDisplayPanel3, mDisplayPanel3->getLabel(), FALSE, onTabChanged, mTabContainer);
00148 mDisplayPanel3->setDefaultBtn(default_btn);
00149
00150 mDisplayPanel2 = new LLPanelDisplay2();
00151 mTabContainer->addTabPanel(mDisplayPanel2, mDisplayPanel2->getLabel(), FALSE, onTabChanged, mTabContainer);
00152 mDisplayPanel2->setDefaultBtn(default_btn);
00153
00154 mAudioPanel = new LLPanelAudioPrefs();
00155 mTabContainer->addTabPanel(mAudioPanel, mAudioPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
00156 mAudioPanel->setDefaultBtn(default_btn);
00157
00158 mPrefsChat = new LLPrefsChat();
00159 mTabContainer->addTabPanel(mPrefsChat->getPanel(), mPrefsChat->getPanel()->getLabel(), FALSE, onTabChanged, mTabContainer);
00160 mPrefsChat->getPanel()->setDefaultBtn(default_btn);
00161
00162 mPrefsVoice = new LLPrefsVoice();
00163 mTabContainer->addTabPanel(mPrefsVoice, mPrefsVoice->getLabel(), FALSE, onTabChanged, mTabContainer);
00164 mPrefsVoice->setDefaultBtn(default_btn);
00165
00166 mPrefsIM = new LLPrefsIM();
00167 mTabContainer->addTabPanel(mPrefsIM->getPanel(), mPrefsIM->getPanel()->getLabel(), FALSE, onTabChanged, mTabContainer);
00168 mPrefsIM->getPanel()->setDefaultBtn(default_btn);
00169
00170 #if LL_WINDOWS && LL_LCD_COMPILE
00171
00172
00173 if (gLcdScreen->Enabled())
00174 {
00175 mLCDPanel = new LLPanelLCD();
00176 mTabContainer->addTabPanel(mLCDPanel, mLCDPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
00177 mLCDPanel->setDefaultBtn(default_btn);
00178 }
00179
00180 #else
00181 mLCDPanel = NULL;
00182 #endif
00183
00184 mMsgPanel = new LLPanelMsgs();
00185 mTabContainer->addTabPanel(mMsgPanel, mMsgPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
00186 mMsgPanel->setDefaultBtn(default_btn);
00187
00188 mDBPanel = new LLPanelDatabase();
00189 mTabContainer->addTabPanel(mDBPanel, mDBPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
00190 mDBPanel->setDefaultBtn(default_btn);
00191
00192 mTabContainer->selectTab(gSavedSettings.getS32("LastPrefTab"));
00193 }
00194
00195 LLPreferenceCore::~LLPreferenceCore()
00196 {
00197 if (mGeneralPanel)
00198 {
00199 delete mGeneralPanel;
00200 mGeneralPanel = NULL;
00201 }
00202 if (mInputPanel)
00203 {
00204 delete mInputPanel;
00205 mInputPanel = NULL;
00206 }
00207 if (mNetworkPanel)
00208 {
00209 delete mNetworkPanel;
00210 mNetworkPanel = NULL;
00211 }
00212 if (mDisplayPanel)
00213 {
00214 delete mDisplayPanel;
00215 mDisplayPanel = NULL;
00216 }
00217 if (mDisplayPanel2)
00218 {
00219 delete mDisplayPanel2;
00220 mDisplayPanel2 = NULL;
00221 }
00222 if (mDisplayPanel3)
00223 {
00224 delete mDisplayPanel3;
00225 mDisplayPanel3 = NULL;
00226 }
00227 if (mAudioPanel)
00228 {
00229 delete mAudioPanel;
00230 mAudioPanel = NULL;
00231 }
00232 if (mPrefsChat)
00233 {
00234 delete mPrefsChat;
00235 mPrefsChat = NULL;
00236 }
00237 if (mPrefsIM)
00238 {
00239 delete mPrefsIM;
00240 mPrefsIM = NULL;
00241 }
00242 if (mMsgPanel)
00243 {
00244 delete mMsgPanel;
00245 mMsgPanel = NULL;
00246 }
00247 #if LL_LIBXUL_ENABLED
00248 if (mWebPanel)
00249 {
00250 delete mWebPanel;
00251 mWebPanel = NULL;
00252 }
00253 #endif
00254 }
00255
00256
00257 void LLPreferenceCore::apply()
00258 {
00259 mGeneralPanel->apply();
00260 mInputPanel->apply();
00261 mNetworkPanel->apply();
00262 mDisplayPanel->apply();
00263 mDisplayPanel2->apply();
00264 mDisplayPanel3->apply();
00265 mPrefsChat->apply();
00266 mPrefsVoice->apply();
00267 mPrefsIM->apply();
00268 mMsgPanel->apply();
00269 mDBPanel->apply();
00270 #if LL_WINDOWS && LL_LCD_COMPILE
00271
00272 if (gLcdScreen->Enabled())
00273 {
00274 mLCDPanel->apply();
00275 }
00276 #endif
00277
00278 }
00279
00280
00281 void LLPreferenceCore::cancel()
00282 {
00283 mGeneralPanel->cancel();
00284 mInputPanel->cancel();
00285 mNetworkPanel->cancel();
00286 mDisplayPanel->cancel();
00287 mDisplayPanel2->cancel();
00288 mDisplayPanel3->cancel();
00289 mAudioPanel->cancel();
00290 mPrefsChat->cancel();
00291 mPrefsVoice->cancel();
00292 mPrefsIM->cancel();
00293 mMsgPanel->cancel();
00294 mDBPanel->cancel();
00295 #if LL_WINDOWS && LL_LCD_COMPILE
00296
00297 if (gLcdScreen->Enabled())
00298 {
00299 mLCDPanel->cancel();
00300 }
00301 #endif
00302
00303 }
00304
00305
00306 void LLPreferenceCore::onTabChanged(void* user_data, bool from_click)
00307 {
00308 LLTabContainerCommon* self = (LLTabContainerCommon*)user_data;
00309
00310 gSavedSettings.setS32("LastPrefTab", self->getCurrentPanelIndex());
00311 }
00312
00313
00314 void LLPreferenceCore::setPersonalInfo(
00315 const char* visibility,
00316 BOOL im_via_email,
00317 const char* email)
00318 {
00319 mPrefsIM->setPersonalInfo(visibility, im_via_email, email);
00320 }
00321
00323
00324
00325 LLFloaterPreference::LLFloaterPreference()
00326 {
00327 gUICtrlFactory->buildFloater(this, "floater_preferences.xml");
00328 }
00329
00330 BOOL LLFloaterPreference::postBuild()
00331 {
00332 requires("About...", WIDGET_TYPE_BUTTON);
00333 requires("OK", WIDGET_TYPE_BUTTON);
00334 requires("Cancel", WIDGET_TYPE_BUTTON);
00335 requires("Apply", WIDGET_TYPE_BUTTON);
00336 requires("pref core", WIDGET_TYPE_TAB_CONTAINER);
00337
00338 if (!checkRequirements())
00339 {
00340 return FALSE;
00341 }
00342
00343 mAboutBtn = LLUICtrlFactory::getButtonByName(this, "About...");
00344 mAboutBtn->setClickedCallback(onClickAbout, this);
00345
00346 mApplyBtn = LLUICtrlFactory::getButtonByName(this, "Apply");
00347 mApplyBtn->setClickedCallback(onBtnApply, this);
00348
00349 mCancelBtn = LLUICtrlFactory::getButtonByName(this, "Cancel");
00350 mCancelBtn->setClickedCallback(onBtnCancel, this);
00351
00352 mOKBtn = LLUICtrlFactory::getButtonByName(this, "OK");
00353 mOKBtn->setClickedCallback(onBtnOK, this);
00354
00355 mPreferenceCore = new LLPreferenceCore(
00356 LLUICtrlFactory::getTabContainerByName(this, "pref core"),
00357 static_cast<LLButton *>(getChildByName("OK"))
00358 );
00359
00360 sInstance = this;
00361
00362 return TRUE;
00363 }
00364
00365
00366 LLFloaterPreference::~LLFloaterPreference()
00367 {
00368 sInstance = NULL;
00369 delete mPreferenceCore;
00370 }
00371
00372
00373 void LLFloaterPreference::draw()
00374 {
00375 if( getVisible() )
00376 {
00377 LLFloater::draw();
00378 }
00379 }
00380
00381
00382 void LLFloaterPreference::apply()
00383 {
00384 this->mPreferenceCore->apply();
00385 }
00386
00387
00388 void LLFloaterPreference::cancel()
00389 {
00390 this->mPreferenceCore->cancel();
00391 }
00392
00393
00394
00395 void LLFloaterPreference::show(void*)
00396 {
00397 if (!sInstance)
00398 {
00399 new LLFloaterPreference();
00400 sInstance->center();
00401 }
00402
00403 sInstance->open();
00404
00405 if(!gAgent.getID().isNull())
00406 {
00407
00408 gMessageSystem->newMessageFast(_PREHASH_UserInfoRequest);
00409 gMessageSystem->nextBlockFast(_PREHASH_AgentData);
00410 gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
00411 gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
00412 gAgent.sendReliableMessage();
00413 }
00414 }
00415
00416
00417
00418 void LLFloaterPreference::onClickAbout(void*)
00419 {
00420 LLFloaterAbout::show(NULL);
00421 }
00422
00423
00424
00425 void LLFloaterPreference::onBtnOK( void* userdata )
00426 {
00427 LLFloaterPreference *fp =(LLFloaterPreference *)userdata;
00428
00429 if (fp->hasFocus())
00430 {
00431 LLUICtrl* cur_focus = gFocusMgr.getKeyboardFocus();
00432 if (cur_focus->acceptsTextInput())
00433 {
00434 cur_focus->onCommit();
00435 }
00436 }
00437
00438 if (fp->canClose())
00439 {
00440 fp->apply();
00441 fp->close(false);
00442
00443 gSavedSettings.saveToFile( gSettingsFileName, TRUE );
00444
00445 std::string crash_settings_filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, CRASH_SETTINGS_FILE);
00446
00447 gCrashSettings.saveToFile(crash_settings_filename.c_str(), FALSE);
00448 }
00449 else
00450 {
00451
00452 llinfos << "Can't close preferences!" << llendl;
00453 }
00454 }
00455
00456
00457
00458 void LLFloaterPreference::onBtnApply( void* userdata )
00459 {
00460 LLFloaterPreference *fp =(LLFloaterPreference *)userdata;
00461 if (fp->hasFocus())
00462 {
00463 LLUICtrl* cur_focus = gFocusMgr.getKeyboardFocus();
00464 if (cur_focus->acceptsTextInput())
00465 {
00466 cur_focus->onCommit();
00467 }
00468 }
00469 fp->apply();
00470 }
00471
00472
00473
00474 void LLFloaterPreference::onBtnCancel( void* userdata )
00475 {
00476 LLFloaterPreference *fp =(LLFloaterPreference *)userdata;
00477 if (fp->hasFocus())
00478 {
00479 LLUICtrl* cur_focus = gFocusMgr.getKeyboardFocus();
00480 if (cur_focus->acceptsTextInput())
00481 {
00482 cur_focus->onCommit();
00483 }
00484 }
00485 fp->cancel();
00486 fp->close();
00487 }
00488
00489
00490
00491 void LLFloaterPreference::updateUserInfo(
00492 const char* visibility,
00493 BOOL im_via_email,
00494 const char* email)
00495 {
00496 if(sInstance && sInstance->mPreferenceCore)
00497 {
00498 sInstance->mPreferenceCore->setPersonalInfo(
00499 visibility, im_via_email, email);
00500 }
00501 }