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 "lluictrlfactory.h"
00042 
00043 #include "llmodaldialog.h"
00044 #include "llkeyboard.h"
00045 #include "llfocusmgr.h"
00046 #include "llfloatervoicedevicesettings.h"
00047 
00048 #include "llappviewer.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                 LLUICtrlFactory::getInstance()->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                 if (b)
00077                 {
00078                         gFocusMgr.setKeystrokesOnly(TRUE);
00079                 }
00080         }
00081 
00082         static void onCancel( void* userdata );
00083 
00084         BOOL handleKeyHere(KEY key, MASK mask);
00085 
00086 };
00087 
00088 LLPrefsVoiceLogic::LLPrefsVoiceLogic(LLPanel* panelp) : 
00089         mPanel(panelp)
00090 {
00091         init();
00092 }
00093  
00094 void LLPrefsVoiceLogic::init()
00095 {
00096         mEnableVoice = gSavedSettings.getBOOL("EnableVoiceChat");
00097 
00098         mVoiceCallsFriendsOnly = gSavedSettings.getBOOL("VoiceCallsFriendsOnly");
00099 //      mEnablePushToTalk = gSavedSettings.getBOOL("EnablePushToTalk");
00100         mModifier = gSavedSettings.getString("PushToTalkButton");
00101         mPushToTalkToggle = gSavedSettings.getBOOL("PushToTalkToggle");
00102         mEarLocation = gSavedSettings.getS32("VoiceEarLocation");
00103 
00104         LLUICtrl* ear_location = mPanel->getChild<LLUICtrl>("ear_location");
00105         mCtrlEarLocation = ear_location->getSelectionInterface();
00106         if (mCtrlEarLocation)
00107         {
00108                 mCtrlEarLocation->selectByValue(LLSD(gSavedSettings.getS32("VoiceEarLocation")));
00109         }
00110         mPanel->childSetCommitCallback("ear_location", onEarLocationCommit, this );
00111 
00112         mPanel->childSetAction("set_voice_hotkey_button", onClickSetKey, this);
00113         mPanel->childSetAction("set_voice_middlemouse_button", onClickSetMiddleMouse, this);
00114 
00115         refresh();
00116         mEatNextSetKeyClick = FALSE;
00117 }
00118 
00119 void LLPrefsVoiceLogic::refresh()
00120 {
00121     BOOL voiceDisabled = gSavedSettings.getBOOL("CmdLineDisableVoice");
00122         mPanel->childSetVisible("voice_unavailable", voiceDisabled);
00123         mPanel->childSetVisible("enable_voice_check", !voiceDisabled);
00124         mPanel->childSetEnabled("enable_voice_check", !voiceDisabled);
00125         
00126         bool enable = !voiceDisabled && gSavedSettings.getBOOL("EnableVoiceChat");
00127         
00128         mPanel->childSetEnabled("friends_only_check", enable);
00129         mPanel->childSetEnabled("push_to_talk_check", enable);
00130         mPanel->childSetEnabled("push_to_talk_label", enable);
00131         mPanel->childSetEnabled("voice_call_friends_only_check", enable);
00132         mPanel->childSetEnabled("push_to_talk_toggle_check", enable);
00133         mPanel->childSetEnabled("ear_location", enable);
00134         mPanel->childSetEnabled("set_voice_hotkey_button", enable);
00135         mPanel->childSetEnabled("set_voice_middlemouse_button", enable);
00136 }
00137 
00138 void LLPrefsVoiceLogic::cancel()
00139 {
00140         gSavedSettings.setBOOL("EnableVoiceChat", mEnableVoice);
00141         gSavedSettings.setBOOL("VoiceCallsFriendsOnly", mVoiceCallsFriendsOnly);
00142 //      gSavedSettings.setBOOL("EnablePushToTalk", mEnablePushToTalk );
00143         gSavedSettings.setString("PushToTalkButton", mModifier);
00144         gSavedSettings.setBOOL("PushToTalkToggle", mPushToTalkToggle );
00145         gSavedSettings.setS32("VoiceEarLocation", mEarLocation);
00146 }
00147 
00148 void LLPrefsVoiceLogic::apply()
00149 {
00150 }
00151 
00152 //static 
00153 void LLPrefsVoiceLogic::onEarLocationCommit(LLUICtrl* ctrl, void* user_data)
00154 {
00155         LLCtrlSelectionInterface* interfacep = ctrl->getSelectionInterface();
00156         if (interfacep)
00157         {
00158                 gSavedSettings.setS32("VoiceEarLocation", interfacep->getSelectedValue().asInteger());
00159         }
00160 }
00161 
00162 // static
00163 void LLPrefsVoiceLogic::onClickSetKey(void* user_data)
00164 {
00165         LLPrefsVoiceLogic* self=(LLPrefsVoiceLogic*)user_data;  
00166         if(self->mEatNextSetKeyClick)
00167         {
00168                 self->mEatNextSetKeyClick = false;
00169         }
00170         else
00171         {
00172                 LLVoiceHotkeySelectDialog* dialog = new LLVoiceHotkeySelectDialog( self );
00173                 dialog->startModal();
00174                 // dialog will delete itself
00175         }
00176 }
00177 
00178 
00179 // static
00180 void LLPrefsVoiceLogic::onClickSetMiddleMouse(void* user_data)
00181 {
00182 //      LLPrefsVoiceLogic* self=(LLPrefsVoiceLogic*)user_data;
00183         
00184         gSavedSettings.setString("PushToTalkButton", "MiddleMouse");
00185 }
00186 
00187 void LLPrefsVoiceLogic::setKey(KEY key, MASK mask)
00188 {
00189         std::string keystring = LLKeyboard::stringFromKey(key);
00190         gSavedSettings.setString("PushToTalkButton", keystring);
00191         
00192         if(key == ' ')
00193         {
00194                 // This will cause the select dialog to immediately reopen.
00195                 // Eat the next click event.
00196                 mEatNextSetKeyClick = TRUE;
00197         }
00198 }
00199 
00200 void LLVoiceHotkeySelectDialog::onCancel( void* userdata )
00201 {
00202         LLVoiceHotkeySelectDialog* self = (LLVoiceHotkeySelectDialog*) userdata;
00203         self->close(); // destroys this object
00204         self->mOldFrontmost->setFrontmost(TRUE);
00205 }
00206 
00207 BOOL LLVoiceHotkeySelectDialog::handleKeyHere(KEY key, MASK mask)
00208 {
00209         BOOL result = TRUE;
00210         
00211         // Suck up all keystokes except CTRL-Q.
00212         BOOL is_quit = ('Q' == key) && (MASK_CONTROL == mask);
00213         if(is_quit)
00214         {
00215                 result = FALSE;
00216         }
00217         else
00218         {
00219                 mParent->setKey(key, mask);
00220         }
00221 
00222         close(); // destroys this object
00223         mOldFrontmost->setFrontmost(TRUE);
00224         
00225         return result;
00226 }
00227 
00228 //---------------------------------------------------------------------------
00229 
00230 
00231 LLPrefsVoice::LLPrefsVoice()
00232 :       LLPanel("Voice Chat Panel")
00233 { 
00234         LLUICtrlFactory::getInstance()->buildPanel(this, "panel_preferences_voice.xml");
00235         mLogic = new LLPrefsVoiceLogic(this);
00236         childSetAction("device_settings_btn", onClickVoiceDeviceSettingsBtn, this);
00237 
00238         // create floater immediately and keep it hidden
00239         // since it stores preference state for audio devices
00240         mVoiceDeviceSettings = LLFloaterVoiceDeviceSettings::getInstance();
00241 }
00242 
00243 LLPrefsVoice::~LLPrefsVoice()
00244 {
00245         delete mLogic;
00246 }
00247 
00248 void LLPrefsVoice::draw()
00249 {
00250         bool enable = !gSavedSettings.getBOOL("CmdLineDisableVoice")
00251                   && gSavedSettings.getBOOL("EnableVoiceChat");
00252         childSetEnabled("device_settings_btn", enable);
00253 
00254         mLogic->refresh();
00255         mVoiceDeviceSettings->refresh();
00256         LLPanel::draw();
00257 }
00258 
00259 void LLPrefsVoice::apply()
00260 {
00261         mLogic->apply();
00262         mVoiceDeviceSettings->apply();
00263 }
00264 
00265 void LLPrefsVoice::cancel()
00266 {
00267         mLogic->cancel();
00268         mVoiceDeviceSettings->cancel();
00269 }
00270 
00271 //static 
00272 void LLPrefsVoice::onClickVoiceDeviceSettingsBtn(void* user_data)
00273 {
00274         LLPrefsVoice* prefs = (LLPrefsVoice*)user_data;
00275         prefs->mVoiceDeviceSettings->open();
00276         LLFloater* parent_floater = gFloaterView->getParentFloater(prefs);
00277         if (parent_floater)
00278         {
00279                 parent_floater->addDependentFloater(prefs->mVoiceDeviceSettings, FALSE);
00280         }
00281 }

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