llprefsvoice.cpp

Go to the documentation of this file.
00001 
00033 #include "llviewerprecompiledheaders.h"
00034 
00035 #include "llprefsvoice.h"
00036 
00037 #include "llcheckboxctrl.h"
00038 #include "llcombobox.h"
00039 
00040 #include "llviewercontrol.h"
00041 #include "llvieweruictrlfactory.h"
00042 
00043 #include "llmodaldialog.h"
00044 #include "llkeyboard.h"
00045 #include "llfocusmgr.h"
00046 #include "llfloatervoicewizard.h"
00047 
00048 #include "viewer.h"
00049 
00050 #include "llvoiceclient.h"
00051 
00052 class LLVoiceHotkeySelectDialog : public LLModalDialog
00053 {
00054 private:
00055         LLPrefsVoiceLogic       *mParent;
00056         LLFloater                       *mOldFrontmost;
00057 
00058 public:
00059         LLVoiceHotkeySelectDialog( LLPrefsVoiceLogic *parent )
00060                 : LLModalDialog( "", 240, 100 ),
00061                   mParent( parent )
00062         {
00063                 mOldFrontmost = gFloaterView->getFrontmost();
00064 
00065                 gUICtrlFactory->buildFloater(this, "floater_select_key.xml");
00066                 
00067                 childSetAction("Cancel", LLVoiceHotkeySelectDialog::onCancel, this );
00068                 childSetFocus("Cancel");
00069         }
00070 
00071         /*virtual*/ void setFocus( BOOL b )
00072         {
00073                 LLFloater::setFocus(b);
00074                 
00075                 // This forces keyboard processing to happen at the raw key level instead of going through handleUnicodeChar.
00076                 gFocusMgr.removeKeyboardFocusWithoutCallback(gFocusMgr.getKeyboardFocus());
00077         }
00078 
00079         static void onCancel( void* userdata );
00080 
00081         BOOL handleKey(KEY key, MASK mask, BOOL called_from_parent );
00082 
00083 };
00084 
00085 LLPrefsVoiceLogic::LLPrefsVoiceLogic(LLPanel* panelp) : 
00086         mPanel(panelp)
00087 {
00088         init();
00089 }
00090  
00091 void LLPrefsVoiceLogic::init()
00092 {
00093         mEnableVoice = gSavedSettings.getBOOL("EnableVoiceChat");
00094 
00095         mVoiceCallsFriendsOnly = gSavedSettings.getBOOL("VoiceCallsFriendsOnly");
00096         mEnablePushToTalk = gSavedSettings.getBOOL("EnablePushToTalk");
00097         mModifier = gSavedSettings.getString("PushToTalkButton");
00098         mPushToTalkToggle = gSavedSettings.getBOOL("PushToTalkToggle");
00099         mEarLocation = gSavedSettings.getS32("VoiceEarLocation");
00100 
00101         mCtrlEarLocation = LLUICtrlFactory::getSelectionInterfaceByName(mPanel, "ear_location");
00102         mCtrlEarLocation->selectByValue(LLSD(gSavedSettings.getS32("VoiceEarLocation")));
00103         mPanel->childSetCommitCallback("ear_location", onEarLocationCommit, this );
00104 
00105         mPanel->childSetAction("launch_voice_wizard_button", onClickLaunchWizard, this);
00106         mPanel->childSetAction("set_voice_hotkey_button", onClickSetKey, this);
00107         mPanel->childSetAction("set_voice_middlemouse_button", onClickSetMiddleMouse, this);
00108 
00109         refresh();
00110         mEatNextSetKeyClick = FALSE;
00111 }
00112 
00113 void LLPrefsVoiceLogic::refresh()
00114 {
00115         mPanel->childSetVisible("voice_unavailable", gDisableVoice);
00116         mPanel->childSetVisible("enable_voice_check", !gDisableVoice);
00117         mPanel->childSetEnabled("enable_voice_check", !gDisableVoice);
00118         
00119         bool enable = !gDisableVoice && gSavedSettings.getBOOL("EnableVoiceChat");
00120         
00121         mPanel->childSetEnabled("push_to_talk_check", enable);
00122         mPanel->childSetEnabled("push_to_talk_label", enable);
00123         mPanel->childSetEnabled("voice_call_friends_only_check", enable);
00124         mPanel->childSetEnabled("push_to_talk_toggle_check", enable /*&& gSavedSettings.getBOOL("EnablePushToTalk")*/);
00125         mPanel->childSetEnabled("ear_location", enable);
00126         mPanel->childSetEnabled("set_voice_hotkey_button", enable /*&& gSavedSettings.getBOOL("EnablePushToTalk")*/);
00127         mPanel->childSetEnabled("set_voice_middlemouse_button", enable /*&& gSavedSettings.getBOOL("EnablePushToTalk")*/);
00128 }
00129 
00130 void LLPrefsVoiceLogic::cancel()
00131 {
00132         gSavedSettings.setBOOL("EnableVoiceChat", mEnableVoice);
00133         gSavedSettings.setBOOL("VoiceCallsFriendsOnly", mVoiceCallsFriendsOnly);
00134         gSavedSettings.setBOOL("EnablePushToTalk", mEnablePushToTalk );
00135         gSavedSettings.setString("PushToTalkButton", mModifier);
00136         gSavedSettings.setBOOL("PushToTalkToggle", mPushToTalkToggle );
00137         gSavedSettings.setS32("VoiceEarLocation", mEarLocation);
00138 }
00139 
00140 void LLPrefsVoiceLogic::apply()
00141 {
00142 }
00143 
00144 //static 
00145 void LLPrefsVoiceLogic::onEarLocationCommit(LLUICtrl* ctrl, void* user_data)
00146 {
00147         LLCtrlSelectionInterface* interfacep = ctrl->getSelectionInterface();
00148         if (interfacep)
00149         {
00150                 gSavedSettings.setS32("VoiceEarLocation", interfacep->getSimpleSelectedValue().asInteger());
00151         }
00152 }
00153 
00154 //static
00155 void LLPrefsVoiceLogic::onClickLaunchWizard(void* user_data)
00156 {
00157         LLFloaterVoiceWizard::showInstance();
00158 }
00159 
00160 // static
00161 void LLPrefsVoiceLogic::onClickSetKey(void* user_data)
00162 {
00163         LLPrefsVoiceLogic* self=(LLPrefsVoiceLogic*)user_data;  
00164         if(self->mEatNextSetKeyClick)
00165         {
00166                 self->mEatNextSetKeyClick = false;
00167         }
00168         else
00169         {
00170                 LLVoiceHotkeySelectDialog* dialog = new LLVoiceHotkeySelectDialog( self );
00171                 dialog->startModal();
00172                 // dialog will delete itself
00173         }
00174 }
00175 
00176 
00177 // static
00178 void LLPrefsVoiceLogic::onClickSetMiddleMouse(void* user_data)
00179 {
00180 //      LLPrefsVoiceLogic* self=(LLPrefsVoiceLogic*)user_data;
00181         
00182         gSavedSettings.setString("PushToTalkButton", "MiddleMouse");
00183 }
00184 
00185 void LLPrefsVoiceLogic::setKey(KEY key, MASK mask)
00186 {
00187         std::string keystring = LLKeyboard::stringFromKey(key);
00188         gSavedSettings.setString("PushToTalkButton", keystring);
00189         
00190         if(key == ' ')
00191         {
00192                 // This will cause the select dialog to immediately reopen.
00193                 // Eat the next click event.
00194                 mEatNextSetKeyClick = TRUE;
00195         }
00196 }
00197 
00198 void LLVoiceHotkeySelectDialog::onCancel( void* userdata )
00199 {
00200         LLVoiceHotkeySelectDialog* self = (LLVoiceHotkeySelectDialog*) userdata;
00201         self->close(); // destroys this object
00202         self->mOldFrontmost->setFrontmost(TRUE);
00203 }
00204 
00205 BOOL LLVoiceHotkeySelectDialog::handleKey(KEY key, MASK mask, BOOL called_from_parent )
00206 {
00207         BOOL result = TRUE;
00208         
00209         // Suck up all keystokes except CTRL-Q.
00210         BOOL is_quit = ('Q' == key) && (MASK_CONTROL == mask);
00211         if(is_quit)
00212         {
00213                 result = FALSE;
00214         }
00215         else
00216         {
00217                 mParent->setKey(key, mask);
00218         }
00219 
00220         close(); // destroys this object
00221         mOldFrontmost->setFrontmost(TRUE);
00222         
00223         return result;
00224 }
00225 
00226 //---------------------------------------------------------------------------
00227 
00228 
00229 LLPrefsVoice::LLPrefsVoice()
00230 :       LLPanel("Voice Chat Panel")
00231 { 
00232         gUICtrlFactory->buildPanel(this, "panel_preferences_voice.xml");
00233         mLogic = new LLPrefsVoiceLogic(this);
00234         childSetAction("device_settings_btn", onClickDeviceSettingsBtn, this);
00235 
00236         // create floater immediately and keep it hidden
00237         // since it stores preference state for audio devices
00238         mDeviceSettings = LLFloaterDeviceSettings::getInstance();
00239 }
00240 
00241 LLPrefsVoice::~LLPrefsVoice()
00242 {
00243         delete mLogic;
00244 }
00245 
00246 void LLPrefsVoice::draw()
00247 {
00248         bool enable = !gDisableVoice && gSavedSettings.getBOOL("EnableVoiceChat");
00249         childSetEnabled("device_settings_btn", enable);
00250 
00251         mLogic->refresh();
00252         mDeviceSettings->refresh();
00253         LLPanel::draw();
00254 }
00255 
00256 void LLPrefsVoice::apply()
00257 {
00258         mLogic->apply();
00259         mDeviceSettings->apply();
00260 }
00261 
00262 void LLPrefsVoice::cancel()
00263 {
00264         mLogic->cancel();
00265         mDeviceSettings->cancel();
00266 }
00267 
00268 //static 
00269 void LLPrefsVoice::onClickDeviceSettingsBtn(void* user_data)
00270 {
00271         LLPrefsVoice* prefs = (LLPrefsVoice*)user_data;
00272         prefs->mDeviceSettings->open();
00273         LLFloater* parent_floater = gFloaterView->getParentFloater(prefs);
00274         if (parent_floater)
00275         {
00276                 parent_floater->addDependentFloater(prefs->mDeviceSettings, FALSE);
00277         }
00278 }

Generated on Thu Jul 1 06:09:01 2010 for Second Life Viewer by  doxygen 1.4.7