llfloaterpreference.cpp

Go to the documentation of this file.
00001 
00032 /*
00033  * App-wide preferences.  Note that these are not per-user,
00034  * because we need to load many preferences before we have
00035  * a login name.
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 "llcommandhandler.h"
00051 #include "llfloaterabout.h"
00052 #include "llfloaterpreference.h"
00053 #include "llpanelnetwork.h"
00054 #include "llpanelaudioprefs.h"
00055 #include "llpaneldisplay.h"
00056 #include "llpaneldebug.h"
00057 #include "llpanelgeneral.h"
00058 #include "llpanelinput.h"
00059 #include "llpanellogin.h"
00060 #include "llpanelLCD.h"
00061 #include "llpanelmsgs.h"
00062 #include "llpanelweb.h"
00063 #include "llprefschat.h"
00064 #include "llprefsvoice.h"
00065 #include "llprefsim.h"
00066 #include "llresizehandle.h"
00067 #include "llresmgr.h"
00068 #include "llassetstorage.h"
00069 #include "llagent.h"
00070 #include "llviewercontrol.h"
00071 #include "llviewernetwork.h"
00072 #include "lluictrlfactory.h"
00073 #include "llviewerwindow.h"
00074 #include "llkeyboard.h"
00075 #include "llscrollcontainer.h"
00076 #include "llfloaterhardwaresettings.h"
00077 
00078 #if LL_WINDOWS
00079 // for Logitech LCD keyboards / speakers
00080 #ifndef LL_LOGITECH_LCD_H
00081 #include "lllogitechlcd.h"
00082 #endif
00083 extern LLLCD    *gLcdScreen; 
00084 #endif
00085 
00086 const S32 PREF_BORDER = 4;
00087 const S32 PREF_PAD = 5;
00088 const S32 PREF_BUTTON_WIDTH = 70;
00089 const S32 PREF_CATEGORY_WIDTH = 150;
00090 
00091 const S32 PREF_FLOATER_MIN_HEIGHT = 2 * SCROLLBAR_SIZE + 2 * LLPANEL_BORDER_WIDTH + 96;
00092 
00093 LLFloaterPreference* LLFloaterPreference::sInstance = NULL;
00094 
00095 
00096 class LLPreferencesHandler : public LLCommandHandler
00097 {
00098 public:
00099         // don't allow from external browsers
00100         LLPreferencesHandler() : LLCommandHandler("preferences", false) { }
00101         bool handle(const LLSD& tokens, const LLSD& queryMap)
00102         {
00103                 LLFloaterPreference::show(NULL);
00104                 return true;
00105         }
00106 };
00107 
00108 LLPreferencesHandler gPreferencesHandler;
00109 
00110 
00111 // Must be done at run time, not compile time. JC
00112 S32 pref_min_width()
00113 {
00114         return  
00115         2 * PREF_BORDER + 
00116         2 * PREF_BUTTON_WIDTH + 
00117         PREF_PAD + RESIZE_HANDLE_WIDTH +
00118         PREF_CATEGORY_WIDTH +
00119         PREF_PAD;
00120 }
00121 
00122 S32 pref_min_height()
00123 {
00124         return
00125         2 * PREF_BORDER +
00126         3*(BTN_HEIGHT + PREF_PAD) +
00127         PREF_FLOATER_MIN_HEIGHT;
00128 }
00129 
00130 
00131 LLPreferenceCore::LLPreferenceCore(LLTabContainer* tab_container, LLButton * default_btn) :
00132         mTabContainer(tab_container),
00133         mGeneralPanel(NULL),
00134         mInputPanel(NULL),
00135         mNetworkPanel(NULL),
00136         mDisplayPanel(NULL),
00137         mAudioPanel(NULL),
00138         mMsgPanel(NULL),
00139         mLCDPanel(NULL)
00140 {
00141         mGeneralPanel = new LLPanelGeneral();
00142         mTabContainer->addTabPanel(mGeneralPanel, mGeneralPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
00143         mGeneralPanel->setDefaultBtn(default_btn);
00144 
00145         mInputPanel = new LLPanelInput();
00146         mTabContainer->addTabPanel(mInputPanel, mInputPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
00147         mInputPanel->setDefaultBtn(default_btn);
00148 
00149         mNetworkPanel = new LLPanelNetwork();
00150         mTabContainer->addTabPanel(mNetworkPanel, mNetworkPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
00151         mNetworkPanel->setDefaultBtn(default_btn);
00152 
00153         mWebPanel = new LLPanelWeb();
00154         mTabContainer->addTabPanel(mWebPanel, mWebPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
00155         mWebPanel->setDefaultBtn(default_btn);
00156 
00157         mDisplayPanel = new LLPanelDisplay();
00158         mTabContainer->addTabPanel(mDisplayPanel, mDisplayPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
00159         mDisplayPanel->setDefaultBtn(default_btn);
00160 
00161         mAudioPanel = new LLPanelAudioPrefs();
00162         mTabContainer->addTabPanel(mAudioPanel, mAudioPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
00163         mAudioPanel->setDefaultBtn(default_btn);
00164 
00165         mPrefsChat = new LLPrefsChat();
00166         mTabContainer->addTabPanel(mPrefsChat->getPanel(), mPrefsChat->getPanel()->getLabel(), FALSE, onTabChanged, mTabContainer);
00167         mPrefsChat->getPanel()->setDefaultBtn(default_btn);
00168 
00169         mPrefsVoice = new LLPrefsVoice();
00170         mTabContainer->addTabPanel(mPrefsVoice, mPrefsVoice->getLabel(), FALSE, onTabChanged, mTabContainer);
00171         mPrefsVoice->setDefaultBtn(default_btn);
00172 
00173         mPrefsIM = new LLPrefsIM();
00174         mTabContainer->addTabPanel(mPrefsIM->getPanel(), mPrefsIM->getPanel()->getLabel(), FALSE, onTabChanged, mTabContainer);
00175         mPrefsIM->getPanel()->setDefaultBtn(default_btn);
00176 
00177 #if LL_WINDOWS && LL_LCD_COMPILE
00178 
00179         // only add this option if we actually have a logitech keyboard / speaker set
00180         if (gLcdScreen->Enabled())
00181         {
00182                 mLCDPanel = new LLPanelLCD();
00183                 mTabContainer->addTabPanel(mLCDPanel, mLCDPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
00184                 mLCDPanel->setDefaultBtn(default_btn);
00185         }
00186 
00187 #else
00188         mLCDPanel = NULL;
00189 #endif
00190 
00191         mMsgPanel = new LLPanelMsgs();
00192         mTabContainer->addTabPanel(mMsgPanel, mMsgPanel->getLabel(), FALSE, onTabChanged, mTabContainer);
00193         mMsgPanel->setDefaultBtn(default_btn);
00194 
00195         if (!mTabContainer->selectTab(gSavedSettings.getS32("LastPrefTab")))
00196         {
00197                 mTabContainer->selectFirstTab();
00198         }
00199 }
00200 
00201 LLPreferenceCore::~LLPreferenceCore()
00202 {
00203         if (mGeneralPanel)
00204         {
00205                 delete mGeneralPanel;
00206                 mGeneralPanel = NULL;
00207         }
00208         if (mInputPanel)
00209         {
00210                 delete mInputPanel;
00211                 mInputPanel = NULL;
00212         }
00213         if (mNetworkPanel)
00214         {
00215                 delete mNetworkPanel;
00216                 mNetworkPanel = NULL;
00217         }
00218         if (mDisplayPanel)
00219         {
00220                 delete mDisplayPanel;
00221                 mDisplayPanel = NULL;
00222         }
00223 
00224         if (mAudioPanel)
00225         {
00226                 delete mAudioPanel;
00227                 mAudioPanel = NULL;
00228         }
00229         if (mPrefsChat)
00230         {
00231                 delete mPrefsChat;
00232                 mPrefsChat = NULL;
00233         }
00234         if (mPrefsIM)
00235         {
00236                 delete mPrefsIM;
00237                 mPrefsIM = NULL;
00238         }
00239         if (mMsgPanel)
00240         {
00241                 delete mMsgPanel;
00242                 mMsgPanel = NULL;
00243         }
00244         if (mWebPanel)
00245         {
00246                 delete mWebPanel;
00247                 mWebPanel = NULL;
00248         }
00249 }
00250 
00251 
00252 void LLPreferenceCore::apply()
00253 {
00254         mGeneralPanel->apply();
00255         mInputPanel->apply();
00256         mNetworkPanel->apply();
00257         mDisplayPanel->apply();
00258         mPrefsChat->apply();
00259         mPrefsVoice->apply();
00260         mPrefsIM->apply();
00261         mMsgPanel->apply();
00262 
00263         // hardware menu apply
00264         LLFloaterHardwareSettings::instance()->apply();
00265 
00266         mWebPanel->apply();
00267 #if LL_WINDOWS && LL_LCD_COMPILE
00268         // only add this option if we actually have a logitech keyboard / speaker set
00269         if (gLcdScreen->Enabled())
00270         {
00271                 mLCDPanel->apply();
00272         }
00273 #endif
00274 //      mWebPanel->apply();
00275 }
00276 
00277 
00278 void LLPreferenceCore::cancel()
00279 {
00280         mGeneralPanel->cancel();
00281         mInputPanel->cancel();
00282         mNetworkPanel->cancel();
00283         mDisplayPanel->cancel();
00284         mAudioPanel->cancel();
00285         mPrefsChat->cancel();
00286         mPrefsVoice->cancel();
00287         mPrefsIM->cancel();
00288         mMsgPanel->cancel();
00289 
00290         // cancel hardware menu
00291         LLFloaterHardwareSettings::instance()->cancel();
00292 
00293         mWebPanel->cancel();
00294 #if LL_WINDOWS && LL_LCD_COMPILE
00295         // only add this option if we actually have a logitech keyboard / speaker set
00296         if (gLcdScreen->Enabled())
00297         {
00298                 mLCDPanel->cancel();
00299         }
00300 #endif
00301 //      mWebPanel->cancel();
00302 }
00303 
00304 // static
00305 void LLPreferenceCore::onTabChanged(void* user_data, bool from_click)
00306 {
00307         LLTabContainer* self = (LLTabContainer*)user_data;
00308 
00309         gSavedSettings.setS32("LastPrefTab", self->getCurrentPanelIndex());
00310 }
00311 
00312 
00313 void LLPreferenceCore::setPersonalInfo(
00314         const char* visibility,
00315         BOOL im_via_email,
00316         const char* email)
00317 {
00318         mPrefsIM->setPersonalInfo(visibility, im_via_email, email);
00319 }
00320 
00321 void LLPreferenceCore::refreshEnabledGraphics()
00322 {
00323         LLFloaterHardwareSettings::instance()->refreshEnabledState();
00324         mDisplayPanel->refreshEnabledState();
00325 }
00326 
00328 // LLFloaterPreference
00329 
00330 LLFloaterPreference::LLFloaterPreference()
00331 {
00332         LLUICtrlFactory::getInstance()->buildFloater(this, "floater_preferences.xml");
00333 }
00334 
00335 BOOL LLFloaterPreference::postBuild()
00336 {
00337         requires<LLButton>("About...");
00338         requires<LLButton>("OK");
00339         requires<LLButton>("Cancel");
00340         requires<LLButton>("Apply");
00341         requires<LLTabContainer>("pref core");
00342 
00343         if (!checkRequirements())
00344         {
00345                 return FALSE;
00346         }
00347 
00348         mAboutBtn = getChild<LLButton>("About...");
00349         mAboutBtn->setClickedCallback(onClickAbout, this);
00350         
00351         mApplyBtn = getChild<LLButton>("Apply");
00352         mApplyBtn->setClickedCallback(onBtnApply, this);
00353                 
00354         mCancelBtn = getChild<LLButton>("Cancel");
00355         mCancelBtn->setClickedCallback(onBtnCancel, this);
00356 
00357         mOKBtn = getChild<LLButton>("OK");
00358         mOKBtn->setClickedCallback(onBtnOK, this);
00359                         
00360         mPreferenceCore = new LLPreferenceCore(
00361                 getChild<LLTabContainer>("pref core"),
00362                 getChild<LLButton>("OK")
00363                 );
00364         
00365         sInstance = this;
00366 
00367         return TRUE;
00368 }
00369 
00370 
00371 LLFloaterPreference::~LLFloaterPreference()
00372 {
00373         sInstance = NULL;
00374         delete mPreferenceCore;
00375 }
00376 
00377 void LLFloaterPreference::apply()
00378 {
00379         this->mPreferenceCore->apply();
00380 }
00381 
00382 
00383 void LLFloaterPreference::cancel()
00384 {
00385         this->mPreferenceCore->cancel();
00386 }
00387 
00388 
00389 // static
00390 void LLFloaterPreference::show(void*)
00391 {
00392         if (!sInstance)
00393         {
00394                 new LLFloaterPreference();
00395                 sInstance->center();
00396         }
00397 
00398         sInstance->open();              /* Flawfinder: ignore */
00399 
00400         if(!gAgent.getID().isNull())
00401         {
00402                 // we're logged in, so we can get this info.
00403                 gMessageSystem->newMessageFast(_PREHASH_UserInfoRequest);
00404                 gMessageSystem->nextBlockFast(_PREHASH_AgentData);
00405                 gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
00406                 gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
00407                 gAgent.sendReliableMessage();
00408         }
00409 
00410         LLPanelLogin::setAlwaysRefresh(true);
00411 }
00412 
00413 
00414 // static
00415 void LLFloaterPreference::onClickAbout(void*)
00416 {
00417         LLFloaterAbout::show(NULL);
00418 }
00419 
00420 
00421 // static 
00422 void LLFloaterPreference::onBtnOK( void* userdata )
00423 {
00424         LLPanelLogin::refreshLocation( false );
00425 
00426         LLFloaterPreference *fp =(LLFloaterPreference *)userdata;
00427         // commit any outstanding text entry
00428         if (fp->hasFocus())
00429         {
00430                 LLUICtrl* cur_focus = gFocusMgr.getKeyboardFocus();
00431                 if (cur_focus->acceptsTextInput())
00432                 {
00433                         cur_focus->onCommit();
00434                 }
00435         }
00436 
00437         if (fp->canClose())
00438         {
00439                 fp->apply();
00440                 fp->close(false);
00441 
00442                 gSavedSettings.saveToFile( gSavedSettings.getString("ClientSettingsFile"), TRUE );
00443                 
00444                 std::string crash_settings_filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, CRASH_SETTINGS_FILE);
00445                 // save all settings, even if equals defaults
00446                 gCrashSettings.saveToFile(crash_settings_filename.c_str(), FALSE);
00447         }
00448         else
00449         {
00450                 // Show beep, pop up dialog, etc.
00451                 llinfos << "Can't close preferences!" << llendl;
00452         }
00453 }
00454 
00455 
00456 // static 
00457 void LLFloaterPreference::onBtnApply( void* userdata )
00458 {
00459         LLFloaterPreference *fp =(LLFloaterPreference *)userdata;
00460         if (fp->hasFocus())
00461         {
00462                 LLUICtrl* cur_focus = gFocusMgr.getKeyboardFocus();
00463                 if (cur_focus->acceptsTextInput())
00464                 {
00465                         cur_focus->onCommit();
00466                 }
00467         }
00468         fp->apply();
00469 
00470         LLPanelLogin::refreshLocation( false );
00471 }
00472 
00473 
00474 void LLFloaterPreference::onClose(bool app_quitting)
00475 {
00476         LLPanelLogin::setAlwaysRefresh(false);
00477         LLFloater::onClose(app_quitting);
00478 }
00479 
00480 
00481 // static 
00482 void LLFloaterPreference::onBtnCancel( void* userdata )
00483 {
00484         LLFloaterPreference *fp =(LLFloaterPreference *)userdata;
00485         if (fp->hasFocus())
00486         {
00487                 LLUICtrl* cur_focus = gFocusMgr.getKeyboardFocus();
00488                 if (cur_focus->acceptsTextInput())
00489                 {
00490                         cur_focus->onCommit();
00491                 }
00492         }
00493         fp->cancel();
00494         fp->close();
00495 }
00496 
00497 
00498 // static
00499 void LLFloaterPreference::updateUserInfo(
00500         const char* visibility,
00501         BOOL im_via_email,
00502         const char* email)
00503 {
00504         if(sInstance && sInstance->mPreferenceCore)
00505         {
00506                 sInstance->mPreferenceCore->setPersonalInfo(
00507                         visibility, im_via_email, email);
00508         }
00509 }
00510 
00511 void LLFloaterPreference::refreshEnabledGraphics()
00512 {
00513         sInstance->mPreferenceCore->refreshEnabledGraphics();
00514 }

Generated on Fri May 16 08:33:29 2008 for SecondLife by  doxygen 1.5.5