Skip to content
Snippets Groups Projects
llfloaterpreference.cpp 107 KiB
Newer Older
Graham Linden's avatar
Graham Linden committed
                                                            || sim_access == SIM_ACCESS_ADULT);
Graham Linden's avatar
Graham Linden committed
    getChild<LLIconCtrl>("rating_icon_adult")->setVisible(sim_access == SIM_ACCESS_ADULT);
std::string get_category_path(LLUUID cat_id)
{
    LLViewerInventoryCategory* cat = gInventory.getCategory(cat_id);
    std::string localized_cat_name;
    if (!LLTrans::findString(localized_cat_name, "InvFolder " + cat->getName()))
    {
        localized_cat_name = cat->getName();
    }

        return get_category_path(cat->getParentUUID()) + " > " + localized_cat_name;
        return localized_cat_name;
    }
}

std::string get_category_path(LLFolderType::EType cat_type)
{
    LLUUID cat_id = gInventory.findUserDefinedCategoryUUIDForType(cat_type);
    return get_category_path(cat_id);
}

void LLFloaterPreference::onChangeModelFolder()
{
    if (gInventory.isInventoryUsable())
    {
        getChild<LLTextBox>("upload_models")->setText(get_category_path(LLFolderType::FT_OBJECT));
    }
}

void LLFloaterPreference::onChangeTextureFolder()
{
    if (gInventory.isInventoryUsable())
    {
        getChild<LLTextBox>("upload_textures")->setText(get_category_path(LLFolderType::FT_TEXTURE));
    }
}

void LLFloaterPreference::onChangeSoundFolder()
{
    if (gInventory.isInventoryUsable())
    {
        getChild<LLTextBox>("upload_sounds")->setText(get_category_path(LLFolderType::FT_SOUND));
    }
}

void LLFloaterPreference::onChangeAnimationFolder()
{
    if (gInventory.isInventoryUsable())
    {
        getChild<LLTextBox>("upload_animation")->setText(get_category_path(LLFolderType::FT_ANIMATION));
// FIXME: this will stop you from spawning the sidetray from preferences dialog on login screen
// but the UI for this will still be enabled
void LLFloaterPreference::onClickBlockList()
{
Graham Linden's avatar
Graham Linden committed
    LLFloaterSidePanelContainer::showPanel("people", "panel_people",
        LLSD().with("people_panel_tab_name", "blocked_panel"));
void LLFloaterPreference::onClickProxySettings()
Graham Linden's avatar
Graham Linden committed
    LLFloaterReg::showInstance("prefs_proxy");
Vadim ProductEngine's avatar
Vadim ProductEngine committed
void LLFloaterPreference::onClickTranslationSettings()
Graham Linden's avatar
Graham Linden committed
    LLFloaterReg::showInstance("prefs_translation");
Graham Linden's avatar
Graham Linden committed
    LLFloaterReg::showInstance("prefs_autoreplace");
    LLFloaterReg::showInstance("prefs_spellchecker");
void LLFloaterPreference::onClickRenderExceptions()
{
    LLFloaterReg::showInstance("avatar_render_settings");
}

void LLFloaterPreference::onClickAdvanced()
{
Graham Linden's avatar
Graham Linden committed
    LLFloaterReg::showInstance("prefs_graphics_advanced");
Graham Linden's avatar
Graham Linden committed
    LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
    for (child_list_t::const_iterator iter = tabcontainer->getChildList()->begin();
         iter != tabcontainer->getChildList()->end(); ++iter)
    {
        LLView* view = *iter;
        LLPanelPreferenceGraphics* panel = dynamic_cast<LLPanelPreferenceGraphics*>(view);
        if (panel)
        {
            panel->resetDirtyChilds();
        }
    }
void LLFloaterPreference::onClickActionChange()
Graham Linden's avatar
Graham Linden committed
    mClickActionDirty = true;
void LLFloaterPreference::onClickPermsDefault()
{
Graham Linden's avatar
Graham Linden committed
    LLFloaterReg::showInstance("perms_default");
void LLFloaterPreference::onDeleteTranscripts()
{
Graham Linden's avatar
Graham Linden committed
    LLSD args;
    args["FOLDER"] = gDirUtilp->getUserName();
Graham Linden's avatar
Graham Linden committed
    LLNotificationsUtil::add("PreferenceChatDeleteTranscripts", args, LLSD(), boost::bind(&LLFloaterPreference::onDeleteTranscriptsResponse, this, _1, _2));
}

void LLFloaterPreference::onDeleteTranscriptsResponse(const LLSD& notification, const LLSD& response)
{
Graham Linden's avatar
Graham Linden committed
    if (0 == LLNotificationsUtil::getSelectedOption(notification, response))
    {
        LLLogChat::deleteTranscripts();
        updateDeleteTranscriptsButton();
    }
Graham Linden's avatar
Graham Linden committed
    LLButton * delete_transcripts_buttonp = getChild<LLButton>("delete_transcripts");
Graham Linden's avatar
Graham Linden committed
    if (!delete_transcripts_buttonp->getEnabled())
    {
        delete_transcripts_buttonp->setEnabled(true);
    }
void LLFloaterPreference::updateClickActionSettings()
{
Graham Linden's avatar
Graham Linden committed
    const int single_clk_action = getChild<LLComboBox>("single_click_action_combo")->getValue().asInteger();
    const int double_clk_action = getChild<LLComboBox>("double_click_action_combo")->getValue().asInteger();
Graham Linden's avatar
Graham Linden committed
    gSavedSettings.setBOOL("ClickToWalk",           single_clk_action == 1);
    gSavedSettings.setBOOL("DoubleClickAutoPilot",  double_clk_action == 1);
    gSavedSettings.setBOOL("DoubleClickTeleport",   double_clk_action == 2);
void LLFloaterPreference::updateClickActionControls()
Graham Linden's avatar
Graham Linden committed
    const bool click_to_walk = gSavedSettings.getBOOL("ClickToWalk");
    const bool dbl_click_to_walk = gSavedSettings.getBOOL("DoubleClickAutoPilot");
    const bool dbl_click_to_teleport = gSavedSettings.getBOOL("DoubleClickTeleport");
Graham Linden's avatar
Graham Linden committed
    getChild<LLComboBox>("single_click_action_combo")->setValue((int)click_to_walk);
    getChild<LLComboBox>("double_click_action_combo")->setValue(dbl_click_to_teleport ? 2 : (int)dbl_click_to_walk);
void LLFloaterPreference::applyUIColor(LLUICtrl* ctrl, const LLSD& param)
{
Graham Linden's avatar
Graham Linden committed
    LLUIColorTable::instance().setColor(param.asString(), LLColor4(ctrl->getValue()));
}

void LLFloaterPreference::getUIColor(LLUICtrl* ctrl, const LLSD& param)
{
Graham Linden's avatar
Graham Linden committed
    LLColorSwatchCtrl* color_swatch = (LLColorSwatchCtrl*) ctrl;
    color_swatch->setOriginal(LLUIColorTable::instance().getColor(param.asString()));
void LLFloaterPreference::setCacheLocation(const LLStringExplicit& location)
{
Graham Linden's avatar
Graham Linden committed
    LLUICtrl* cache_location_editor = getChild<LLUICtrl>("cache_location");
    cache_location_editor->setValue(location);
    cache_location_editor->setToolTip(location);
void LLFloaterPreference::selectPanel(const LLSD& name)
{
Graham Linden's avatar
Graham Linden committed
    LLTabContainer * tab_containerp = getChild<LLTabContainer>("pref core");
    LLPanel * panel = tab_containerp->getPanelByName(name);
    if (NULL != panel)
    {
        tab_containerp->selectTabPanel(panel);
    }
}

void LLFloaterPreference::selectPrivacyPanel()
{
Graham Linden's avatar
Graham Linden committed
    selectPanel("im");
}

void LLFloaterPreference::selectChatPanel()
{
Graham Linden's avatar
Graham Linden committed
    selectPanel("chat");
Graham Linden's avatar
Graham Linden committed
    getChild<LLButton>("clear_log")->setEnabled(LLConversationLog::instance().getConversations().size() > 0);
Graham Linden's avatar
Graham Linden committed
    // set 'enable' property for 'Delete transcripts...' button
    updateDeleteTranscriptsButton();
void LLFloaterPreference::saveCameraPreset(std::string& preset)
{
Graham Linden's avatar
Graham Linden committed
    mSavedCameraPreset = preset;
void LLFloaterPreference::saveGraphicsPreset(std::string& preset)
{
Graham Linden's avatar
Graham Linden committed
    mSavedGraphicsPreset = preset;
//------------------------------Updater---------------------------------------

static bool handleBandwidthChanged(const LLSD& newvalue)
{
Graham Linden's avatar
Graham Linden committed
    gViewerThrottle.setMaxBandwidth((F32) newvalue.asReal());
    return true;
Graham Linden's avatar
Graham Linden committed
    typedef boost::function<bool(const LLSD&)> callback_t;
Graham Linden's avatar
Graham Linden committed
    Updater(callback_t cb, F32 period)
    :LLEventTimer(period),
     mCallback(cb)
    {
        mEventTimer.stop();
    }
Graham Linden's avatar
Graham Linden committed
    virtual ~Updater(){}
Graham Linden's avatar
Graham Linden committed
    void update(const LLSD& new_value)
    {
        mNewValue = new_value;
        mEventTimer.start();
    }
Graham Linden's avatar
Graham Linden committed
    BOOL tick()
    {
        mCallback(mNewValue);
        mEventTimer.stop();
Graham Linden's avatar
Graham Linden committed
        return FALSE;
    }
Graham Linden's avatar
Graham Linden committed
    LLSD mNewValue;
    callback_t mCallback;
//----------------------------------------------------------------------------
static LLPanelInjector<LLPanelPreference> t_places("panel_preference");
LLPanelPreference::LLPanelPreference()
Graham Linden's avatar
Graham Linden committed
    mCommitCallbackRegistrar.add("Pref.setControlFalse",    boost::bind(&LLPanelPreference::setControlFalse,this, _2));
    mCommitCallbackRegistrar.add("Pref.updateMediaAutoPlayCheckbox",    boost::bind(&LLPanelPreference::updateMediaAutoPlayCheckbox, this, _1));
    mCommitCallbackRegistrar.add("Pref.PrefDelete", boost::bind(&LLPanelPreference::deletePreset, this, _2));
    mCommitCallbackRegistrar.add("Pref.PrefSave",   boost::bind(&LLPanelPreference::savePreset, this, _2));
    mCommitCallbackRegistrar.add("Pref.PrefLoad",   boost::bind(&LLPanelPreference::loadPreset, this, _2));
//virtual
BOOL LLPanelPreference::postBuild()
{
Graham Linden's avatar
Graham Linden committed
    ////////////////////// PanelGeneral ///////////////////
    if (hasChild("display_names_check", TRUE))
    {
        BOOL use_people_api = gSavedSettings.getBOOL("UsePeopleAPI");
        LLCheckBoxCtrl* ctrl_display_name = getChild<LLCheckBoxCtrl>("display_names_check");
        ctrl_display_name->setEnabled(use_people_api);
        if (!use_people_api)
        {
            ctrl_display_name->setValue(FALSE);
        }
    }

    ////////////////////// PanelVoice ///////////////////
    if (hasChild("voice_unavailable", TRUE))
    {
        BOOL voice_disabled = gSavedSettings.getBOOL("CmdLineDisableVoice");
        getChildView("voice_unavailable")->setVisible( voice_disabled);
        getChildView("enable_voice_check")->setVisible( !voice_disabled);
    }
    
    //////////////////////PanelSkins ///////////////////
    
    if (hasChild("skin_selection", TRUE))
    {
        LLFloaterPreference::refreshSkin(this);

        // if skin is set to a skin that no longer exists (silver) set back to default
        if (getChild<LLRadioGroup>("skin_selection")->getSelectedIndex() < 0)
        {
            gSavedSettings.setString("SkinCurrent", "default");
            LLFloaterPreference::refreshSkin(this);
        }

    }

    //////////////////////PanelPrivacy ///////////////////
    if (hasChild("media_enabled", TRUE))
    {
        bool media_enabled = gSavedSettings.getBOOL("AudioStreamingMedia");
        
        getChild<LLCheckBoxCtrl>("media_enabled")->set(media_enabled);
        getChild<LLCheckBoxCtrl>("autoplay_enabled")->setEnabled(media_enabled);
    }
    if (hasChild("music_enabled", TRUE))
    {
        getChild<LLCheckBoxCtrl>("music_enabled")->set(gSavedSettings.getBOOL("AudioStreamingMusic"));
    }
    if (hasChild("voice_call_friends_only_check", TRUE))
    {
        getChild<LLCheckBoxCtrl>("voice_call_friends_only_check")->setCommitCallback(boost::bind(&showFriendsOnlyWarning, _1, _2));
    }
    if (hasChild("allow_multiple_viewer_check", TRUE))
    {
        getChild<LLCheckBoxCtrl>("allow_multiple_viewer_check")->setCommitCallback(boost::bind(&showMultipleViewersWarning, _1, _2));
    }
    if (hasChild("favorites_on_login_check", TRUE))
    {
        getChild<LLCheckBoxCtrl>("favorites_on_login_check")->setCommitCallback(boost::bind(&handleFavoritesOnLoginChanged, _1, _2));
        bool show_favorites_at_login = LLPanelLogin::getShowFavorites();
        getChild<LLCheckBoxCtrl>("favorites_on_login_check")->setValue(show_favorites_at_login);
    }
    if (hasChild("mute_chb_label", TRUE))
    {
        getChild<LLTextBox>("mute_chb_label")->setShowCursorHand(false);
        getChild<LLTextBox>("mute_chb_label")->setClickedCallback(boost::bind(&toggleMuteWhenMinimized));
    }

    //////////////////////PanelAdvanced ///////////////////
    if (hasChild("modifier_combo", TRUE))
    {
        //localizing if push2talk button is set to middle mouse
        if (MIDDLE_MOUSE_CV == getChild<LLUICtrl>("modifier_combo")->getValue().asString())
        {
            getChild<LLUICtrl>("modifier_combo")->setValue(getString("middle_mouse"));
        }
    }

    //////////////////////PanelSetup ///////////////////
    if (hasChild("max_bandwidth"), TRUE)
    {
        mBandWidthUpdater = new LLPanelPreference::Updater(boost::bind(&handleBandwidthChanged, _1), BANDWIDTH_UPDATER_TIMEOUT);
        gSavedSettings.getControl("ThrottleBandwidthKBPS")->getSignal()->connect(boost::bind(&LLPanelPreference::Updater::update, mBandWidthUpdater, _2));
    }
Graham Linden's avatar
Graham Linden committed
    LLRadioGroup* ext_browser_settings = getChild<LLRadioGroup>("preferred_browser_behavior");
    if (ext_browser_settings)
    {
        // turn off ability to set external/internal browser
        ext_browser_settings->setSelectedByValue(LLWeb::BROWSER_EXTERNAL_ONLY, true);
        ext_browser_settings->setEnabled(false);
    }
Graham Linden's avatar
Graham Linden committed
    apply();
    return true;
Graham Linden's avatar
Graham Linden committed
    if (mBandWidthUpdater)
    {
        delete mBandWidthUpdater;
    }
void LLPanelPreference::apply()
Graham Linden's avatar
Graham Linden committed
    // no-op
Graham Linden's avatar
Graham Linden committed
    LLFloater* advanced = LLFloaterReg::findTypedInstance<LLFloater>("prefs_graphics_advanced");

    // Save the value of all controls in the hierarchy
    mSavedValues.clear();
    std::list<LLView*> view_stack;
    view_stack.push_back(this);
    if (advanced)
    {
        view_stack.push_back(advanced);
    }
    while(!view_stack.empty())
    {
        // Process view on top of the stack
        LLView* curview = view_stack.front();
        view_stack.pop_front();

        LLColorSwatchCtrl* color_swatch = dynamic_cast<LLColorSwatchCtrl *>(curview);
        if (color_swatch)
        {
            mSavedColors[color_swatch->getName()] = color_swatch->get();
        }
        else
        {
            LLUICtrl* ctrl = dynamic_cast<LLUICtrl*>(curview);
            if (ctrl)
            {
                LLControlVariable* control = ctrl->getControlVariable();
                if (control)
                {
                    mSavedValues[control] = control->getValue();
                }
            }
        }
            
        // Push children onto the end of the work stack
        for (child_list_t::const_iterator iter = curview->getChildList()->begin();
             iter != curview->getChildList()->end(); ++iter)
        {
            view_stack.push_back(*iter);
        }
    }   
James Cook's avatar
James Cook committed

void LLPanelPreference::showMultipleViewersWarning(LLUICtrl* checkbox, const LLSD& value)
{
    if (checkbox && checkbox->getValue())
    {
        LLNotificationsUtil::add("AllowMultipleViewers");
    }
}

void LLPanelPreference::showFriendsOnlyWarning(LLUICtrl* checkbox, const LLSD& value)
{
Graham Linden's avatar
Graham Linden committed
    if (checkbox && checkbox->getValue())
    {
        LLNotificationsUtil::add("FriendsAndGroupsOnly");
    }
void LLPanelPreference::handleFavoritesOnLoginChanged(LLUICtrl* checkbox, const LLSD& value)
Graham Linden's avatar
Graham Linden committed
    if (checkbox)
    {
        LLFavoritesOrderStorage::instance().showFavoritesOnLoginChanged(checkbox->getValue().asBoolean());
        if(checkbox->getValue())
        {
            LLNotificationsUtil::add("FavoritesOnLogin");
        }
    }
void LLPanelPreference::toggleMuteWhenMinimized()
{
Graham Linden's avatar
Graham Linden committed
    std::string mute("MuteWhenMinimized");
    gSavedSettings.setBOOL(mute, !gSavedSettings.getBOOL(mute));
void LLPanelPreference::cancel()
James Cook's avatar
James Cook committed
{
Graham Linden's avatar
Graham Linden committed
    for (control_values_map_t::iterator iter =  mSavedValues.begin();
         iter !=  mSavedValues.end(); ++iter)
    {
        LLControlVariable* control = iter->first;
        LLSD ctrl_value = iter->second;
Graham Linden's avatar
Graham Linden committed
        if((control->getName() == "InstantMessageLogPath") && (ctrl_value.asString() == ""))
        {
            continue;
        }
Graham Linden's avatar
Graham Linden committed
        control->set(ctrl_value);
    }
Graham Linden's avatar
Graham Linden committed
    for (string_color_map_t::iterator iter = mSavedColors.begin();
         iter != mSavedColors.end(); ++iter)
    {
        LLColorSwatchCtrl* color_swatch = findChild<LLColorSwatchCtrl>(iter->first);
        if (color_swatch)
        {
            color_swatch->set(iter->second);
            color_swatch->onCommit();
        }
    }
James Cook's avatar
James Cook committed
}
void LLPanelPreference::setControlFalse(const LLSD& user_data)
Graham Linden's avatar
Graham Linden committed
    std::string control_name = user_data.asString();
    LLControlVariable* control = findControl(control_name);
    
    if (control)
        control->set(LLSD(FALSE));
}

void LLPanelPreference::updateMediaAutoPlayCheckbox(LLUICtrl* ctrl)
{
Graham Linden's avatar
Graham Linden committed
    std::string name = ctrl->getName();
Graham Linden's avatar
Graham Linden committed
    // Disable "Allow Media to auto play" only when both
    // "Streaming Music" and "Media" are unchecked. STORM-513.
    if ((name == "enable_music") || (name == "enable_media"))
    {
        bool music_enabled = getChild<LLCheckBoxCtrl>("enable_music")->get();
        bool media_enabled = getChild<LLCheckBoxCtrl>("enable_media")->get();
Graham Linden's avatar
Graham Linden committed
        getChild<LLCheckBoxCtrl>("media_auto_play_btn")->setEnabled(music_enabled || media_enabled);
    }
void LLPanelPreference::deletePreset(const LLSD& user_data)
Graham Linden's avatar
Graham Linden committed
    std::string subdirectory = user_data.asString();
    LLFloaterReg::hideInstance("load_pref_preset", subdirectory);
    LLFloaterReg::hideInstance("save_pref_preset", subdirectory);
    LLFloaterReg::showInstance("delete_pref_preset", subdirectory);
void LLPanelPreference::savePreset(const LLSD& user_data)
Graham Linden's avatar
Graham Linden committed
    std::string subdirectory = user_data.asString();
    LLFloaterReg::hideInstance("delete_pref_preset", subdirectory);
    LLFloaterReg::hideInstance("load_pref_preset", subdirectory);
    LLFloaterReg::showInstance("save_pref_preset", subdirectory);
void LLPanelPreference::loadPreset(const LLSD& user_data)
Graham Linden's avatar
Graham Linden committed
    std::string subdirectory = user_data.asString();
    LLFloaterReg::hideInstance("delete_pref_preset", subdirectory);
    LLFloaterReg::hideInstance("save_pref_preset", subdirectory);
    LLFloaterReg::showInstance("load_pref_preset", subdirectory);
void LLPanelPreference::setHardwareDefaults()
{
}

class LLPanelPreferencePrivacy : public LLPanelPreference
{
public:
Graham Linden's avatar
Graham Linden committed
    LLPanelPreferencePrivacy()
    {
        mAccountIndependentSettings.push_back("VoiceCallsFriendsOnly");
        mAccountIndependentSettings.push_back("AutoDisengageMic");
    }

    /*virtual*/ void saveSettings()
    {
        LLPanelPreference::saveSettings();

        // Don't save (=erase from the saved values map) per-account privacy settings
        // if we're not logged in, otherwise they will be reset to defaults on log off.
        if (LLStartUp::getStartupState() != STATE_STARTED)
        {
            // Erase only common settings, assuming there are no color settings on Privacy page.
            for (control_values_map_t::iterator it = mSavedValues.begin(); it != mSavedValues.end(); )
            {
                const std::string setting = it->first->getName();
                if (find(mAccountIndependentSettings.begin(),
                    mAccountIndependentSettings.end(), setting) == mAccountIndependentSettings.end())
                {
                    mSavedValues.erase(it++);
                }
                else
                {
                    ++it;
                }
            }
        }
    }
Graham Linden's avatar
Graham Linden committed
    std::list<std::string> mAccountIndependentSettings;
static LLPanelInjector<LLPanelPreferenceGraphics> t_pref_graph("panel_preference_graphics");
static LLPanelInjector<LLPanelPreferencePrivacy> t_pref_privacy("panel_preference_privacy");
static LLPanelInjector<LLPanelPreferenceView> t_pref_view("panel_preference_view");

BOOL LLPanelPreferenceView::postBuild()
{
Graham Linden's avatar
Graham Linden committed
    setPresetText();
Graham Linden's avatar
Graham Linden committed
    LLPresetsManager* presetsMgr = LLPresetsManager::getInstance();
    if (presetsMgr)
    {
        presetsMgr->setPresetListChangeCameraCallback(boost::bind(&LLPanelPreferenceView::onPresetsListChangeCamera, this));
        presetsMgr->createMissingDefault(PRESETS_CAMERA); // a no-op after the first time, but that's ok
    }
Graham Linden's avatar
Graham Linden committed
    return LLPanelPreference::postBuild();
}

void LLPanelPreferenceView::onPresetsListChangeCamera()
{
Graham Linden's avatar
Graham Linden committed
    LLPresetsManager* presetsMgr = LLPresetsManager::getInstance();
    if (presetsMgr)
    {
        presetsMgr->setCameraDirty(false);
    }
Graham Linden's avatar
Graham Linden committed
    setPresetText();
Graham Linden's avatar
Graham Linden committed
    LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
    if (instance && !gSavedSettings.getString("PresetCameraActive").empty())
    {
        instance->saveSettings(); //make cancel work correctly after changing the preset
    }
}

void LLPanelPreferenceView::draw()
{
Graham Linden's avatar
Graham Linden committed
    setPresetText();
    LLPanelPreference::draw();
}

void LLPanelPreferenceView::setPresetText()
{
Graham Linden's avatar
Graham Linden committed
    LLTextBox* preset_text = getChild<LLTextBox>("preset_camera_text");

    std::string preset_camera_active = gSavedSettings.getString("PresetCameraActive");

    if (!preset_camera_active.empty() && preset_camera_active != preset_text->getText())
    {
        LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
        if (instance)
        {
            instance->saveCameraPreset(preset_camera_active);
        }
    }

    LLPresetsManager* presetsMgr = LLPresetsManager::getInstance();
    if (presetsMgr)
    {
        if (presetsMgr->isCameraDirty() && !preset_camera_active.empty())
        {
            preset_camera_active.clear();
        }
    }

    if (!preset_camera_active.empty())
    {
        if (preset_camera_active == PRESETS_DEFAULT)
        {
            preset_camera_active = LLTrans::getString(PRESETS_DEFAULT);
        }
        preset_text->setText(preset_camera_active);
    }
    else
    {
        preset_text->setText(LLTrans::getString("none_paren_cap"));
    }
Graham Linden's avatar
Graham Linden committed
    LLFloaterReg::showInstance("prefs_graphics_advanced");
    LLFloaterReg::hideInstance("prefs_graphics_advanced");
Graham Linden's avatar
Graham Linden committed
    resetDirtyChilds();
    setPresetText();
Graham Linden's avatar
Graham Linden committed
    LLPresetsManager* presetsMgr = LLPresetsManager::getInstance();
    presetsMgr->setPresetListChangeCallback(boost::bind(&LLPanelPreferenceGraphics::onPresetsListChange, this));
    presetsMgr->createMissingDefault(PRESETS_GRAPHIC); // a no-op after the first time, but that's ok
Graham Linden's avatar
Graham Linden committed
    return LLPanelPreference::postBuild();
Graham Linden's avatar
Graham Linden committed
    setPresetText();
    LLPanelPreference::draw();
void LLPanelPreferenceGraphics::onPresetsListChange()
{
Graham Linden's avatar
Graham Linden committed
    resetDirtyChilds();
    setPresetText();
Graham Linden's avatar
Graham Linden committed
    LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
    if (instance && !gSavedSettings.getString("PresetGraphicActive").empty())
    {
        instance->saveSettings(); //make cancel work correctly after changing the preset
    }
void LLPanelPreferenceGraphics::setPresetText()
Graham Linden's avatar
Graham Linden committed
    LLTextBox* preset_text = getChild<LLTextBox>("preset_text");

    std::string preset_graphic_active = gSavedSettings.getString("PresetGraphicActive");

    if (!preset_graphic_active.empty() && preset_graphic_active != preset_text->getText())
    {
        LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
        if (instance)
        {
            instance->saveGraphicsPreset(preset_graphic_active);
        }
    }

    if (hasDirtyChilds() && !preset_graphic_active.empty())
    {
        gSavedSettings.setString("PresetGraphicActive", "");
        preset_graphic_active.clear();
        // This doesn't seem to cause an infinite recursion.  This trigger is needed to cause the pulldown
        // panel to update.
        LLPresetsManager::getInstance()->triggerChangeSignal();
    }

    if (!preset_graphic_active.empty())
    {
        if (preset_graphic_active == PRESETS_DEFAULT)
        {
            preset_graphic_active = LLTrans::getString(PRESETS_DEFAULT);
        }
        preset_text->setText(preset_graphic_active);
    }
    else
    {
        preset_text->setText(LLTrans::getString("none_paren_cap"));
    }

    preset_text->resetDirty();
bool LLPanelPreferenceGraphics::hasDirtyChilds()
{
Graham Linden's avatar
Graham Linden committed
    LLFloater* advanced = LLFloaterReg::findTypedInstance<LLFloater>("prefs_graphics_advanced");
    std::list<LLView*> view_stack;
    view_stack.push_back(this);
    if (advanced)
    {
        view_stack.push_back(advanced);
    }
    while(!view_stack.empty())
    {
        // Process view on top of the stack
        LLView* curview = view_stack.front();
        view_stack.pop_front();

        LLUICtrl* ctrl = dynamic_cast<LLUICtrl*>(curview);
        if (ctrl)
        {
            if (ctrl->isDirty())
            {
                LLControlVariable* control = ctrl->getControlVariable();
                if (control)
                {
                    std::string control_name = control->getName();
                    if (!control_name.empty())
                    {
                        return true;
                    }
                }
            }
        }
        // Push children onto the end of the work stack
        for (child_list_t::const_iterator iter = curview->getChildList()->begin();
             iter != curview->getChildList()->end(); ++iter)
        {
            view_stack.push_back(*iter);
        }
    }

    return false;
Graham Linden's avatar
Graham Linden committed
    LLFloater* advanced = LLFloaterReg::findTypedInstance<LLFloater>("prefs_graphics_advanced");
    std::list<LLView*> view_stack;
    view_stack.push_back(this);
    if (advanced)
    {
        view_stack.push_back(advanced);
    }
    while(!view_stack.empty())
    {
        // Process view on top of the stack
        LLView* curview = view_stack.front();
        view_stack.pop_front();

        LLUICtrl* ctrl = dynamic_cast<LLUICtrl*>(curview);
        if (ctrl)
        {
            ctrl->resetDirty();
        }
        // Push children onto the end of the work stack
        for (child_list_t::const_iterator iter = curview->getChildList()->begin();
             iter != curview->getChildList()->end(); ++iter)
        {
            view_stack.push_back(*iter);
        }
    }   
Graham Linden's avatar
Graham Linden committed
    LLPanelPreference::cancel();
Graham Linden's avatar
Graham Linden committed
    resetDirtyChilds();
    std::string preset_graphic_active = gSavedSettings.getString("PresetGraphicActive");
    if (preset_graphic_active.empty())
    {
        LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
        if (instance)
        {
            //don't restore previous preset after closing Preferences
            instance->saveGraphicsPreset(preset_graphic_active);
        }
    }
    LLPanelPreference::saveSettings();
}
void LLPanelPreferenceGraphics::setHardwareDefaults()
{
Graham Linden's avatar
Graham Linden committed
    resetDirtyChilds();
LLFloaterPreferenceGraphicsAdvanced::LLFloaterPreferenceGraphicsAdvanced(const LLSD& key)
Graham Linden's avatar
Graham Linden committed
    : LLFloater(key)
Graham Linden's avatar
Graham Linden committed
    mCommitCallbackRegistrar.add("Pref.VertexShaderEnable",     boost::bind(&LLFloaterPreferenceGraphicsAdvanced::onVertexShaderEnable, this));
    mCommitCallbackRegistrar.add("Pref.UpdateIndirectMaxNonImpostors", boost::bind(&LLFloaterPreferenceGraphicsAdvanced::updateMaxNonImpostors,this));
    mCommitCallbackRegistrar.add("Pref.UpdateIndirectMaxComplexity",   boost::bind(&LLFloaterPreferenceGraphicsAdvanced::updateMaxComplexity,this));
}

LLFloaterPreferenceGraphicsAdvanced::~LLFloaterPreferenceGraphicsAdvanced()
{
}

LLFloaterPreferenceProxy::LLFloaterPreferenceProxy(const LLSD& key)
Graham Linden's avatar
Graham Linden committed
    : LLFloater(key),
      mSocksSettingsDirty(false)
Graham Linden's avatar
Graham Linden committed
    mCommitCallbackRegistrar.add("Proxy.OK",                boost::bind(&LLFloaterPreferenceProxy::onBtnOk, this));
    mCommitCallbackRegistrar.add("Proxy.Cancel",            boost::bind(&LLFloaterPreferenceProxy::onBtnCancel, this));
    mCommitCallbackRegistrar.add("Proxy.Change",            boost::bind(&LLFloaterPreferenceProxy::onChangeSocksSettings, this));
BOOL LLFloaterPreferenceGraphicsAdvanced::postBuild()
{
    // Don't do this on Mac as their braindead GL versioning
    // sets this when 8x and 16x are indeed available
    //
#if !LL_DARWIN
    if (gGLManager.mIsIntel || gGLManager.mGLVersion < 3.f)
    { //remove FSAA settings above "4x"
        LLComboBox* combo = getChild<LLComboBox>("fsaa");
        combo->remove("8x");
        combo->remove("16x");
    }
#endif

    return TRUE;
}

void LLFloaterPreferenceGraphicsAdvanced::onOpen(const LLSD& key)
{
    refresh();
}

void LLFloaterPreferenceGraphicsAdvanced::onClickCloseBtn(bool app_quitting)
{
Graham Linden's avatar
Graham Linden committed
    LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
    if (instance)
    {
        instance->cancel();
    }
LLFloaterPreferenceProxy::~LLFloaterPreferenceProxy()
{
}

BOOL LLFloaterPreferenceProxy::postBuild()
{
Graham Linden's avatar
Graham Linden committed
    LLRadioGroup* socksAuth = getChild<LLRadioGroup>("socks5_auth_type");
    if (!socksAuth)
    {
        return FALSE;
    }
    if (socksAuth->getSelectedValue().asString() == "None")
    {
        getChild<LLLineEditor>("socks5_username")->setEnabled(false);
        getChild<LLLineEditor>("socks5_password")->setEnabled(false);
    }
    else
    {
        // Populate the SOCKS 5 credential fields with protected values.
        LLPointer<LLCredential> socks_cred = gSecAPIHandler->loadCredential("SOCKS5");
        getChild<LLLineEditor>("socks5_username")->setValue(socks_cred->getIdentifier()["username"].asString());
        getChild<LLLineEditor>("socks5_password")->setValue(socks_cred->getAuthenticator()["creds"].asString());
    }

    return TRUE;
}

void LLFloaterPreferenceProxy::onOpen(const LLSD& key)
{
Graham Linden's avatar
Graham Linden committed
    saveSettings();
}

void LLFloaterPreferenceProxy::onClose(bool app_quitting)
{
Graham Linden's avatar
Graham Linden committed
    if(app_quitting)
    {
        cancel();
    }
Graham Linden's avatar
Graham Linden committed
    if (mSocksSettingsDirty)
    {
Graham Linden's avatar
Graham Linden committed
        // If the user plays with the Socks proxy settings after login, it's only fair we let them know
        // it will not be updated until next restart.
        if (LLStartUp::getStartupState()>STATE_LOGIN_WAIT)
        {
            LLNotifications::instance().add("ChangeProxySettings", LLSD(), LLSD());
            mSocksSettingsDirty = false; // we have notified the user now be quiet again
        }
    }
}

void LLFloaterPreferenceProxy::saveSettings()
{
Graham Linden's avatar
Graham Linden committed
    // Save the value of all controls in the hierarchy
    mSavedValues.clear();
    std::list<LLView*> view_stack;
    view_stack.push_back(this);
    while(!view_stack.empty())
    {
        // Process view on top of the stack
        LLView* curview = view_stack.front();
        view_stack.pop_front();

        LLUICtrl* ctrl = dynamic_cast<LLUICtrl*>(curview);
        if (ctrl)
        {
            LLControlVariable* control = ctrl->getControlVariable();
            if (control)
            {
                mSavedValues[control] = control->getValue();
            }
        }

        // Push children onto the end of the work stack
        for (child_list_t::const_iterator iter = curview->getChildList()->begin();
                iter != curview->getChildList()->end(); ++iter)
        {
            view_stack.push_back(*iter);
        }
    }
}

void LLFloaterPreferenceProxy::onBtnOk()
{
Graham Linden's avatar
Graham Linden committed
    // commit any outstanding text entry
    if (hasFocus())
    {
        LLUICtrl* cur_focus = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
        if (cur_focus && cur_focus->acceptsTextInput())
        {
            cur_focus->onCommit();
        }
    }

    // Save SOCKS proxy credentials securely if password auth is enabled
    LLRadioGroup* socksAuth = getChild<LLRadioGroup>("socks5_auth_type");
    if (socksAuth->getSelectedValue().asString() == "UserPass")
    {
        LLSD socks_id = LLSD::emptyMap();
        socks_id["type"] = "SOCKS5";
        socks_id["username"] = getChild<LLLineEditor>("socks5_username")->getValue().asString();

        LLSD socks_authenticator = LLSD::emptyMap();
        socks_authenticator["type"] = "SOCKS5";
        socks_authenticator["creds"] = getChild<LLLineEditor>("socks5_password")->getValue().asString();