llfloatervoicewizard.cpp

Go to the documentation of this file.
00001 
00033 #include "llviewerprecompiledheaders.h"
00034 
00035 #include "llfloatervoicewizard.h"
00036 
00037 #include "llagent.h"
00038 #include "llbutton.h"
00039 #include "llcombobox.h"
00040 #include "llfocusmgr.h"
00041 #include "lliconctrl.h"
00042 #include "llprefsvoice.h"
00043 #include "llsliderctrl.h"
00044 #include "llviewercontrol.h"
00045 #include "llvieweruictrlfactory.h"
00046 #include "llvoiceclient.h"
00047 #include "llimpanel.h"
00048 
00049 LLFloaterVoiceWizard::LLFloaterVoiceWizard(const LLSD& seed) : LLFloater("floater_voice_wizard"), mDevicePanel(NULL)
00050 {
00051         mFactoryMap["device_settings"] = LLCallbackMap(createPanelDeviceSettings, this);
00052         // do not automatically open singleton floaters (as result of getInstance())
00053         BOOL no_open = FALSE;
00054         gUICtrlFactory->buildFloater(this, "floater_voice_wizard.xml", &mFactoryMap, no_open);
00055 
00056         mLogic = new LLPrefsVoiceLogic(this);
00057         center();
00058 }
00059 
00060 LLFloaterVoiceWizard::~LLFloaterVoiceWizard()
00061 {
00062         delete mLogic;
00063         mLogic = NULL;
00064 }
00065 
00066 BOOL LLFloaterVoiceWizard::postBuild()
00067 {
00068         childSetAction("next_btn", onClickNext, this);
00069         childSetAction("back_btn", onClickBack, this);
00070         childSetAction("ok_btn", onClickOK, this);
00071         childSetAction("cancel_btn", onClickCancel, this);
00072 
00073         childSetCommitCallback("voice_enable", onCommitVoiceEnable, this);
00074 
00075         return TRUE;
00076 }
00077 
00078 void LLFloaterVoiceWizard::draw()
00079 {
00080         mLogic->refresh();
00081         if (mDevicePanel)
00082         {
00083                 mDevicePanel->refresh();
00084         }
00085 
00086         LLTabContainerCommon* tabs = LLUICtrlFactory::getTabContainerByName(this, "wizard_tabs");
00087 
00088         if (tabs)
00089         {
00090                 // if on first tab, disable back button, etc
00091                 if (tabs->getCurrentPanelIndex() == 0)
00092                 {
00093                         if (gSavedSettings.getBOOL("EnableVoiceChat"))
00094                         {
00095                                 childSetEnabled("next_btn", TRUE);
00096                                 setDefaultBtn(gUICtrlFactory->getButtonByName(this, "next_btn"));
00097                         }
00098                         else
00099                         {
00100                                 childSetEnabled("next_btn", FALSE);
00101                                 setDefaultBtn(gUICtrlFactory->getButtonByName(this, "ok_btn"));
00102                         }
00103                         childSetEnabled("back_btn", FALSE);
00104                 }
00105                 else
00106                 {
00107                         // if on any tab but the last, enable the next button
00108                         if (tabs->getCurrentPanelIndex() < tabs->getTabCount() - 1)
00109                         {
00110                                 childSetEnabled("next_btn", TRUE);
00111                                 setDefaultBtn(gUICtrlFactory->getButtonByName(this, "next_btn"));
00112                         }
00113                         else
00114                         {
00115                                 childSetEnabled("next_btn", FALSE);
00116                                 setDefaultBtn(gUICtrlFactory->getButtonByName(this, "ok_btn"));
00117                         }
00118                         childSetEnabled("back_btn", TRUE);
00119                 }
00120         }
00121 
00122         // because we can simultaneously change voice settings from the preferences UI
00123         // we need to stay in sync
00124         childSetValue("voice_enable", gSavedSettings.getBOOL("EnableVoiceChat") ? "1" : "0");
00125 
00126         // show appropriate text on first tab
00127         childSetVisible("voice_intro_text3", !gSavedSettings.getBOOL("EnableVoiceChat"));
00128         childSetVisible("voice_intro_text4", gSavedSettings.getBOOL("EnableVoiceChat"));
00129 
00130         LLFloater::draw();
00131 }
00132 
00133 void LLFloaterVoiceWizard::onOpen()
00134 {
00135         if(mDevicePanel)
00136         {
00137                 mDevicePanel->onOpen();
00138         }
00139 
00140         LLFloater::onOpen();
00141 }
00142 
00143 void LLFloaterVoiceWizard::onClose(bool app_quitting)
00144 {
00145         if(mDevicePanel)
00146         {
00147                 mDevicePanel->onClose(app_quitting);
00148         }
00149 
00150         LLFloater::onClose(app_quitting);
00151 }
00152 
00153 
00154 // static
00155 void LLFloaterVoiceWizard::onClickNext(void *user_data)
00156 {
00157         LLTabContainerCommon* tabs = LLUICtrlFactory::getTabContainerByName((LLFloater*)user_data, "wizard_tabs");
00158         if (tabs)
00159         {
00160                 tabs->selectNextTab();
00161         }
00162 }
00163 
00164 // static
00165 void LLFloaterVoiceWizard::onClickBack(void *user_data)
00166 {
00167         LLTabContainerCommon* tabs = LLUICtrlFactory::getTabContainerByName((LLFloater*)user_data, "wizard_tabs");
00168         if (tabs)
00169         {
00170                 tabs->selectPrevTab();
00171         }
00172 }
00173 
00174 // static
00175 void LLFloaterVoiceWizard::onClickOK(void *user_data)
00176 {
00177         LLFloaterVoiceWizard* self = (LLFloaterVoiceWizard*)user_data;
00178 
00179         // propagate tuning mic volume to actual mic volume
00180         self->mLogic->apply();
00181         if (self->mDevicePanel)
00182         {
00183                 self->mDevicePanel->apply();
00184         }
00185         self->close();
00186 }
00187 
00188 // static
00189 void LLFloaterVoiceWizard::onClickCancel(void *user_data)
00190 {
00191         LLFloaterVoiceWizard* self = (LLFloaterVoiceWizard*)user_data;
00192         
00193         self->mLogic->cancel();
00194         if (self->mDevicePanel)
00195         {
00196                 self->mDevicePanel->cancel();
00197         }
00198         self->close();
00199 }
00200 
00201 // static
00202 void LLFloaterVoiceWizard::onCommitVoiceEnable(LLUICtrl* ctrl, void* user_data)
00203 {
00204         gSavedSettings.setBOOL("EnableVoiceChat", ctrl->getValue().asInteger());
00205 }
00206 
00207 // static
00208 void* LLFloaterVoiceWizard::createPanelDeviceSettings(void* user_data)
00209 {
00210         LLFloaterVoiceWizard* floaterp = (LLFloaterVoiceWizard*)user_data;
00211         floaterp->mDevicePanel = new LLPanelDeviceSettings();
00212         return floaterp->mDevicePanel;
00213 }
00214 
00215 
00216 //
00217 // LLPanelDeviceSettings
00218 //
00219 
00220 LLPanelDeviceSettings::LLPanelDeviceSettings()
00221 {
00222         mCtrlInputDevices = NULL;
00223         mCtrlOutputDevices = NULL;
00224         mInputDevice = gSavedSettings.getString("VoiceInputAudioDevice");
00225         mOutputDevice = gSavedSettings.getString("VoiceOutputAudioDevice");
00226         mDevicesUpdated = FALSE;
00227 
00228         // grab "live" mic volume level
00229         mMicVolume = gSavedSettings.getF32("AudioLevelMic");
00230 
00231         // ask for new device enumeration
00232         // now do this in onOpen() instead...
00233         //gVoiceClient->refreshDeviceLists();
00234 }
00235 
00236 LLPanelDeviceSettings::~LLPanelDeviceSettings()
00237 {
00238 }
00239 
00240 BOOL LLPanelDeviceSettings::postBuild()
00241 {
00242         LLSlider* volume_slider = gUICtrlFactory->getSliderBarByName(this, "mic_volume_slider");
00243         if (volume_slider)
00244         {
00245                 // set mic volume tuning slider based on last mic volume setting
00246                 volume_slider->setValue(mMicVolume);
00247         }
00248 
00249         return TRUE;
00250 }
00251 
00252 void LLPanelDeviceSettings::draw()
00253 {
00254         // let user know that volume indicator is not yet available
00255         childSetVisible("wait_text", !gVoiceClient->inTuningMode());
00256 
00257         LLPanel::draw();
00258 
00259         F32 voice_power = gVoiceClient->tuningGetEnergy();
00260         S32 discrete_power = 0;
00261 
00262         if (!gVoiceClient->inTuningMode())
00263         {
00264                 discrete_power = 0;
00265         }
00266         else
00267         {
00268                 discrete_power = llmin(4, llfloor((voice_power / LLVoiceClient::OVERDRIVEN_POWER_LEVEL) * 4.f));
00269         }
00270         
00271         if (gVoiceClient->inTuningMode())
00272         {
00273                 const S32 GAP = 5;
00274                 S32 cur_x = 100;
00275                 S32 cur_y = 15;
00276 
00277                 for(S32 power_bar_idx = 0; power_bar_idx < 5; power_bar_idx++)
00278                 {
00279                         if (power_bar_idx < discrete_power)
00280                         {
00281                                 LLColor4 color = (power_bar_idx >= 3) ? gSavedSettings.getColor4("OverdrivenColor") : gSavedSettings.getColor4("SpeakingColor");
00282                                 gl_rect_2d(cur_x, cur_y + 20, cur_x + 20, cur_y, color, TRUE);
00283                         }
00284                         gl_rect_2d(cur_x, cur_y + 20, cur_x + 20, cur_y, LLColor4::grey, FALSE);
00285                         cur_x += 20 + GAP;
00286                 }
00287         }
00288 }
00289 
00290 void LLPanelDeviceSettings::apply()
00291 {
00292         std::string s;
00293         if(mCtrlInputDevices)
00294         {
00295                 s = mCtrlInputDevices->getSimple();
00296                 gSavedSettings.setString("VoiceInputAudioDevice", s);
00297         }
00298 
00299         if(mCtrlOutputDevices)
00300         {
00301                 s = mCtrlOutputDevices->getSimple();
00302                 gSavedSettings.setString("VoiceOutputAudioDevice", s);
00303         }
00304 
00305         // assume we are being destroyed by closing our embedding window
00306         gSavedSettings.setF32("AudioLevelMic", mMicVolume);
00307 }
00308 
00309 void LLPanelDeviceSettings::cancel()
00310 {
00311         gSavedSettings.setString("VoiceInputAudioDevice", mInputDevice);
00312         gSavedSettings.setString("VoiceOutputAudioDevice", mOutputDevice);
00313 
00314         if(mCtrlInputDevices)
00315                 mCtrlInputDevices->setSimple(mInputDevice);
00316 
00317         if(mCtrlOutputDevices)
00318                 mCtrlOutputDevices->setSimple(mOutputDevice);
00319 }
00320 
00321 void LLPanelDeviceSettings::refresh()
00322 {
00323         //grab current volume
00324         LLSlider* volume_slider = gUICtrlFactory->getSliderBarByName(this, "mic_volume_slider");
00325         if (volume_slider)
00326         {
00327                 // set mic volume tuning slider based on last mic volume setting
00328                 mMicVolume = (F32)volume_slider->getValue().asReal();
00329                 gVoiceClient->tuningSetMicVolume(mMicVolume);
00330         }
00331 
00332         // Fill in popup menus
00333         mCtrlInputDevices = LLUICtrlFactory::getComboBoxByName(this, "voice_input_device");
00334         mCtrlOutputDevices = LLUICtrlFactory::getComboBoxByName(this, "voice_output_device");
00335 
00336         if(!gVoiceClient->deviceSettingsAvailable())
00337         {
00338                 // The combo boxes are disabled, since we can't get the device settings from the daemon just now.
00339                 // Put the currently set default (ONLY) in the box, and select it.
00340                 if(mCtrlInputDevices)
00341                 {
00342                         mCtrlInputDevices->removeall();
00343                         mCtrlInputDevices->add( mInputDevice, ADD_BOTTOM );
00344                         mCtrlInputDevices->setSimple(mInputDevice);
00345                 }
00346                 if(mCtrlOutputDevices)
00347                 {
00348                         mCtrlOutputDevices->removeall();
00349                         mCtrlOutputDevices->add( mOutputDevice, ADD_BOTTOM );
00350                         mCtrlOutputDevices->setSimple(mOutputDevice);
00351                 }
00352         }
00353         else if (!mDevicesUpdated)
00354         {
00355                 LLVoiceClient::deviceList *devices;
00356                 
00357                 LLVoiceClient::deviceList::iterator iter;
00358                 
00359                 if(mCtrlInputDevices)
00360                 {
00361                         mCtrlInputDevices->removeall();
00362                         mCtrlInputDevices->add( childGetText("default_text"), ADD_BOTTOM );
00363 
00364                         devices = gVoiceClient->getCaptureDevices();
00365                         for(iter=devices->begin(); iter != devices->end(); iter++)
00366                         {
00367                                 mCtrlInputDevices->add( *iter, ADD_BOTTOM );
00368                         }
00369 
00370                         if(!mCtrlInputDevices->setSimple(mInputDevice))
00371                         {
00372                                 mCtrlInputDevices->setSimple(childGetText("default_text"));
00373                         }
00374                 }
00375                 
00376                 if(mCtrlOutputDevices)
00377                 {
00378                         mCtrlOutputDevices->removeall();
00379                         mCtrlOutputDevices->add( childGetText("default_text"), ADD_BOTTOM );
00380 
00381                         devices = gVoiceClient->getRenderDevices();
00382                         for(iter=devices->begin(); iter != devices->end(); iter++)
00383                         {
00384                                 mCtrlOutputDevices->add( *iter, ADD_BOTTOM );
00385                         }
00386 
00387                         if(!mCtrlOutputDevices->setSimple(mOutputDevice))
00388                         {
00389                                 mCtrlOutputDevices->setSimple(childGetText("default_text"));
00390                         }
00391                 }
00392                 mDevicesUpdated = TRUE;
00393         }       
00394 }
00395 
00396 void LLPanelDeviceSettings::onOpen()
00397 {
00398         mDevicesUpdated = FALSE;
00399 
00400         // ask for new device enumeration
00401         gVoiceClient->refreshDeviceLists();
00402 
00403         // put voice client in "tuning" mode
00404         gVoiceClient->tuningStart();
00405 }
00406 
00407 void LLPanelDeviceSettings::onClose(bool app_quitting)
00408 {
00409         gVoiceClient->tuningStop();
00410 }
00411 
00412 //
00413 // LLFloaterDeviceSettings
00414 //
00415 
00416 LLFloaterDeviceSettings::LLFloaterDeviceSettings(const LLSD& seed) : LLFloater("floater_device_settings"), mDevicePanel(NULL)
00417 {
00418         mFactoryMap["device_settings"] = LLCallbackMap(createPanelDeviceSettings, this);
00419         // do not automatically open singleton floaters (as result of getInstance())
00420         BOOL no_open = FALSE;
00421         gUICtrlFactory->buildFloater(this, "floater_device_settings.xml", &mFactoryMap, no_open);
00422         center();
00423 }
00424 
00425 void LLFloaterDeviceSettings::onOpen()
00426 {
00427         if(mDevicePanel)
00428         {
00429                 mDevicePanel->onOpen();
00430         }
00431 
00432         LLFloater::onOpen();
00433 }
00434 
00435 void LLFloaterDeviceSettings::onClose(bool app_quitting)
00436 {
00437         if(mDevicePanel)
00438         {
00439                 mDevicePanel->onClose(app_quitting);
00440         }
00441 
00442         setVisible(FALSE);
00443 }
00444 
00445 void LLFloaterDeviceSettings::apply()
00446 {
00447         if (mDevicePanel)
00448         {
00449                 mDevicePanel->apply();
00450         }
00451 }
00452 
00453 void LLFloaterDeviceSettings::cancel()
00454 {
00455         if (mDevicePanel)
00456         {
00457                 mDevicePanel->cancel();
00458         }
00459 }
00460 
00461 void LLFloaterDeviceSettings::draw()
00462 {
00463         if (mDevicePanel)
00464         {
00465                 mDevicePanel->refresh();
00466         }
00467         LLFloater::draw();
00468 }
00469 
00470 // static
00471 void* LLFloaterDeviceSettings::createPanelDeviceSettings(void* user_data)
00472 {
00473         LLFloaterDeviceSettings* floaterp = (LLFloaterDeviceSettings*)user_data;
00474         floaterp->mDevicePanel = new LLPanelDeviceSettings();
00475         return floaterp->mDevicePanel;
00476 }

Generated on Thu Jul 1 06:08:36 2010 for Second Life Viewer by  doxygen 1.4.7