ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

options.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "gui/browser.h"
00024 #include "gui/themebrowser.h"
00025 #include "gui/message.h"
00026 #include "gui/gui-manager.h"
00027 #include "gui/options.h"
00028 #include "gui/widgets/popup.h"
00029 #include "gui/widgets/tab.h"
00030 #include "gui/ThemeEval.h"
00031 #include "gui/launcher.h"
00032 
00033 #include "common/fs.h"
00034 #include "common/config-manager.h"
00035 #include "common/gui_options.h"
00036 #include "common/rendermode.h"
00037 #include "common/system.h"
00038 #include "common/textconsole.h"
00039 #include "common/translation.h"
00040 #include "common/updates.h"
00041 
00042 #include "audio/mididrv.h"
00043 #include "audio/musicplugin.h"
00044 #include "audio/mixer.h"
00045 //#include "audio/fmopl.h" // ResidualVM removed
00046 #include "widgets/scrollcontainer.h"
00047 #include "widgets/edittext.h"
00048 
00049 #ifdef USE_CLOUD
00050 #ifdef USE_LIBCURL
00051 #include "backends/cloud/cloudmanager.h"
00052 #include "gui/downloaddialog.h"
00053 #include "gui/storagewizarddialog.h"
00054 #endif
00055 
00056 #ifdef USE_SDL_NET
00057 #include "backends/networking/sdl_net/localwebserver.h"
00058 #endif
00059 #endif
00060 
00061 #include "graphics/renderer.h"  // ResidualVM specific
00062 
00063 namespace GUI {
00064 
00065 enum {
00066     kMidiGainChanged        = 'mgch',
00067     kMusicVolumeChanged     = 'muvc',
00068     kSfxVolumeChanged       = 'sfvc',
00069     kMuteAllChanged         = 'mute',
00070     kSubtitleToggle         = 'sttg',
00071     kSubtitleSpeedChanged   = 'stsc',
00072     kSpeechVolumeChanged    = 'vcvc',
00073     kChooseSoundFontCmd     = 'chsf',
00074     kClearSoundFontCmd      = 'clsf',
00075     kChooseSaveDirCmd       = 'chos',
00076     kSavePathClearCmd       = 'clsp',
00077     kChooseThemeDirCmd      = 'chth',
00078     kThemePathClearCmd      = 'clth',
00079     kChooseExtraDirCmd      = 'chex',
00080     kExtraPathClearCmd      = 'clex',
00081     kChoosePluginsDirCmd    = 'chpl',
00082     kChooseThemeCmd         = 'chtf',
00083     kUpdatesCheckCmd        = 'updc',
00084     kKbdMouseSpeedChanged   = 'kmsc',
00085     kJoystickDeadzoneChanged= 'jodc',
00086     kGraphicsTabContainerReflowCmd = 'gtcr',
00087     kFullscreenToggled      = 'oful'  // ResidualVM specific
00088 };
00089 
00090 enum {
00091     kSubtitlesSpeech,
00092     kSubtitlesSubs,
00093     kSubtitlesBoth
00094 };
00095 
00096 #ifdef GUI_ENABLE_KEYSDIALOG
00097 enum {
00098     kChooseKeyMappingCmd    = 'chma'
00099 };
00100 #endif
00101 
00102 #ifdef USE_FLUIDSYNTH
00103 enum {
00104     kFluidSynthSettingsCmd      = 'flst'
00105 };
00106 #endif
00107 
00108 #ifdef USE_CLOUD
00109 enum {
00110     kConfigureStorageCmd = 'cfst',
00111     kRefreshStorageCmd = 'rfst',
00112     kDownloadStorageCmd = 'dlst',
00113     kRunServerCmd = 'rnsv',
00114     kCloudTabContainerReflowCmd = 'ctcr',
00115     kServerPortClearCmd = 'spcl',
00116     kChooseRootDirCmd = 'chrp',
00117     kRootPathClearCmd = 'clrp'
00118 };
00119 #endif
00120 
00121 enum {
00122     kApplyCmd = 'appl'
00123 };
00124 
00125 static const char *savePeriodLabels[] = { _s("Never"), _s("Every 5 mins"), _s("Every 10 mins"), _s("Every 15 mins"), _s("Every 30 mins"), 0 };
00126 static const int savePeriodValues[] = { 0, 5 * 60, 10 * 60, 15 * 60, 30 * 60, -1 };
00127 // The keyboard mouse speed values range from 0 to 7 and correspond to speeds shown in the label
00128 // "10" (value 3) is the default speed corresponding to the speed before introduction of this control
00129 static const char *kbdMouseSpeedLabels[] = { "3", "5", "8", "10", "13", "15", "18", "20", 0 };
00130 
00131 OptionsDialog::OptionsDialog(const Common::String &domain, int x, int y, int w, int h)
00132     : Dialog(x, y, w, h), _domain(domain), _graphicsTabId(-1), _midiTabId(-1), _pathsTabId(-1), _tabWidget(0) {
00133     init();
00134 }
00135 
00136 OptionsDialog::OptionsDialog(const Common::String &domain, const Common::String &name)
00137     : Dialog(name), _domain(domain), _graphicsTabId(-1), _midiTabId(-1), _pathsTabId(-1), _tabWidget(0) {
00138     init();
00139 }
00140 
00141 OptionsDialog::~OptionsDialog() {
00142     delete _subToggleGroup;
00143 }
00144 
00145 void OptionsDialog::init() {
00146     _enableControlSettings = false;
00147     _onscreenCheckbox = 0;
00148     _touchpadCheckbox = 0;
00149     _swapMenuAndBackBtnsCheckbox = 0;
00150     _kbdMouseSpeedDesc = 0;
00151     _kbdMouseSpeedSlider = 0;
00152     _kbdMouseSpeedLabel = 0;
00153     _joystickDeadzoneDesc = 0;
00154     _joystickDeadzoneSlider = 0;
00155     _joystickDeadzoneLabel = 0;
00156     _enableGraphicSettings = false;
00157     _gfxPopUp = 0;
00158     _gfxPopUpDesc = 0;
00159     _renderModePopUp = 0;
00160     _renderModePopUpDesc = 0;
00161     _stretchPopUp = 0;
00162     _stretchPopUpDesc = 0;
00163     _fullscreenCheckbox = 0;
00164     _filteringCheckbox = 0;
00165     _aspectCheckbox = 0;
00166     _enableShaderSettings = false;
00167     _shaderPopUpDesc = 0;
00168     _shaderPopUp = 0;
00169     _vsyncCheckbox = 0;  // ResidualVM specific
00170     _rendererTypePopUpDesc = 0; // ResidualVM specific
00171     _rendererTypePopUp = 0; // ResidualVM specific
00172     _antiAliasPopUpDesc = 0; // ResidualVM specific
00173     _antiAliasPopUp = 0; // ResidualVM specific
00174     _enableAudioSettings = false;
00175     _midiPopUp = 0;
00176     _midiPopUpDesc = 0;
00177     _oplPopUp = 0;
00178     _oplPopUpDesc = 0;
00179     _enableMIDISettings = false;
00180     _gmDevicePopUp = 0;
00181     _gmDevicePopUpDesc = 0;
00182     _soundFont = 0;
00183     _soundFontButton = 0;
00184     _soundFontClearButton = 0;
00185     _multiMidiCheckbox = 0;
00186     _midiGainDesc = 0;
00187     _midiGainSlider = 0;
00188     _midiGainLabel = 0;
00189     _enableMT32Settings = false;
00190     _mt32Checkbox = 0;
00191     _mt32DevicePopUp = 0;
00192     _mt32DevicePopUpDesc = 0;
00193     _enableGSCheckbox = 0;
00194     _enableVolumeSettings = false;
00195     _musicVolumeDesc = 0;
00196     _musicVolumeSlider = 0;
00197     _musicVolumeLabel = 0;
00198     _sfxVolumeDesc = 0;
00199     _sfxVolumeSlider = 0;
00200     _sfxVolumeLabel = 0;
00201     _speechVolumeDesc = 0;
00202     _speechVolumeSlider = 0;
00203     _speechVolumeLabel = 0;
00204     _muteCheckbox = 0;
00205     _enableSubtitleSettings = false;
00206     _subToggleDesc = 0;
00207     _subToggleGroup = 0;
00208     _subToggleSubOnly = 0;
00209     _subToggleSpeechOnly = 0;
00210     _subToggleSubBoth = 0;
00211     _subSpeedDesc = 0;
00212     _subSpeedSlider = 0;
00213     _subSpeedLabel = 0;
00214 
00215     // Retrieve game GUI options
00216     _guioptions.clear();
00217     if (ConfMan.hasKey("guioptions", _domain)) {
00218         _guioptionsString = ConfMan.get("guioptions", _domain);
00219         _guioptions = parseGameGUIOptions(_guioptionsString);
00220     }
00221 }
00222 
00223 void OptionsDialog::build() {
00224     // Retrieve game GUI options
00225     _guioptions.clear();
00226     if (ConfMan.hasKey("guioptions", _domain)) {
00227         _guioptionsString = ConfMan.get("guioptions", _domain);
00228         _guioptions = parseGameGUIOptions(_guioptionsString);
00229     }
00230 
00231     // Control options
00232     if (g_system->hasFeature(OSystem::kFeatureOnScreenControl)) {
00233         if (ConfMan.hasKey("onscreen_control", _domain)) {
00234             bool onscreenState =  g_system->getFeatureState(OSystem::kFeatureOnScreenControl);
00235             if (_onscreenCheckbox != 0)
00236                 _onscreenCheckbox->setState(onscreenState);
00237         }
00238     }
00239     if (g_system->hasFeature(OSystem::kFeatureTouchpadMode)) {
00240         if (ConfMan.hasKey("touchpad_mouse_mode", _domain)) {
00241             bool touchpadState =  g_system->getFeatureState(OSystem::kFeatureTouchpadMode);
00242             if (_touchpadCheckbox != 0)
00243                 _touchpadCheckbox->setState(touchpadState);
00244         }
00245     }
00246     if (g_system->hasFeature(OSystem::kFeatureSwapMenuAndBackButtons)) {
00247         if (ConfMan.hasKey("swap_menu_and_back_buttons", _domain)) {
00248             bool state =  g_system->getFeatureState(OSystem::kFeatureSwapMenuAndBackButtons);
00249             if (_swapMenuAndBackBtnsCheckbox != 0)
00250                 _swapMenuAndBackBtnsCheckbox->setState(state);
00251         }
00252     }
00253     if (g_system->hasFeature(OSystem::kFeatureKbdMouseSpeed)) {
00254         int value = ConfMan.getInt("kbdmouse_speed", _domain);
00255         if (_kbdMouseSpeedSlider && value < ARRAYSIZE(kbdMouseSpeedLabels) - 1 && value >= 0) {
00256             _kbdMouseSpeedSlider->setValue(value);
00257             _kbdMouseSpeedLabel->setLabel(_(kbdMouseSpeedLabels[value]));
00258         }
00259     }
00260     if (g_system->hasFeature(OSystem::kFeatureJoystickDeadzone)) {
00261         int value = ConfMan.getInt("joystick_deadzone", _domain);
00262         if (_joystickDeadzoneSlider != 0) {
00263             _joystickDeadzoneSlider->setValue(value);
00264             _joystickDeadzoneLabel->setValue(value);
00265         }
00266     }
00267 
00268     // Graphic options
00269     if (_fullscreenCheckbox) {
00270 #if 0 // ResidualVM specific
00271         _gfxPopUp->setSelected(0);
00272 
00273         if (ConfMan.hasKey("gfx_mode", _domain)) {
00274             const OSystem::GraphicsMode *gm = g_system->getSupportedGraphicsModes();
00275             Common::String gfxMode(ConfMan.get("gfx_mode", _domain));
00276             int gfxCount = 1;
00277             while (gm->name) {
00278                 gfxCount++;
00279 
00280                 if (scumm_stricmp(gm->name, gfxMode.c_str()) == 0)
00281                     _gfxPopUp->setSelected(gfxCount);
00282 
00283                 gm++;
00284             }
00285         }
00286 
00287         _renderModePopUp->setSelected(0);
00288 
00289         if (ConfMan.hasKey("render_mode", _domain)) {
00290             const Common::RenderModeDescription *p = Common::g_renderModes;
00291             const Common::RenderMode renderMode = Common::parseRenderMode(ConfMan.get("render_mode", _domain));
00292             int sel = 0;
00293             for (int i = 0; p->code; ++p, ++i) {
00294                 if (renderMode == p->id)
00295                     sel = p->id;
00296             }
00297             _renderModePopUp->setSelectedTag(sel);
00298         }
00299 
00300         _stretchPopUp->setSelected(0);
00301 
00302         if (g_system->hasFeature(OSystem::kFeatureStretchMode)) {
00303             if (ConfMan.hasKey("stretch_mode", _domain)) {
00304                 const OSystem::GraphicsMode *sm = g_system->getSupportedStretchModes();
00305                 Common::String stretchMode(ConfMan.get("stretch_mode", _domain));
00306                 int stretchCount = 1;
00307                 while (sm->name) {
00308                     stretchCount++;
00309                     if (scumm_stricmp(sm->name, stretchMode.c_str()) == 0)
00310                         _stretchPopUp->setSelected(stretchCount);
00311                     sm++;
00312                 }
00313             }
00314         } else {
00315             _stretchPopUpDesc->setVisible(false);
00316             _stretchPopUp->setVisible(false);
00317         }
00318 
00319 #endif
00320 #ifdef GUI_ONLY_FULLSCREEN
00321         _fullscreenCheckbox->setState(true);
00322         _fullscreenCheckbox->setEnabled(false);
00323 #else // !GUI_ONLY_FULLSCREEN
00324         // Fullscreen setting
00325         _fullscreenCheckbox->setState(ConfMan.getBool("fullscreen", _domain));
00326 #endif // GUI_ONLY_FULLSCREEN
00327 
00328         // Filtering setting
00329         if (g_system->hasFeature(OSystem::kFeatureFilteringMode))
00330             _filteringCheckbox->setState(ConfMan.getBool("filtering", _domain));
00331         else
00332             _filteringCheckbox->setVisible(false);
00333 
00334         // Aspect ratio setting
00335         if (_guioptions.contains(GUIO_NOASPECT)) { // ResidualVM specific change
00336             _aspectCheckbox->setState(true); // ResidualVM specific change
00337             _aspectCheckbox->setEnabled(false);
00338         } else {
00339             _aspectCheckbox->setEnabled(true);
00340             _aspectCheckbox->setState(ConfMan.getBool("aspect_ratio", _domain));
00341         }
00342 
00343         // ResidualVM specific -- Start
00344         _vsyncCheckbox->setState(ConfMan.getBool("vsync", _domain));
00345 
00346         _rendererTypePopUp->setEnabled(true);
00347         _rendererTypePopUp->setSelectedTag(Graphics::parseRendererTypeCode(ConfMan.get("renderer", _domain)));
00348 
00349         _antiAliasPopUp->setEnabled(true);
00350         if (ConfMan.hasKey("antialiasing", _domain)) {
00351             _antiAliasPopUp->setSelectedTag(ConfMan.getInt("antialiasing", _domain));
00352         } else {
00353             _antiAliasPopUp->setSelectedTag(-1);
00354         }
00355         // ResidualVM specific -- End
00356     }
00357 
00358     // Shader options
00359     if (g_system->hasFeature(OSystem::kFeatureShader)) {
00360         if (_shaderPopUp) {
00361             int value = ConfMan.getInt("shader", _domain);
00362             _shaderPopUp->setSelected(value);
00363         }
00364     }
00365 
00366     // Audio options
00367     if (!loadMusicDeviceSetting(_midiPopUp, "music_driver"))
00368         _midiPopUp->setSelected(0);
00369 
00370 #if 0 // ResidualVM specific
00371     if (_oplPopUp) {
00372         OPL::Config::DriverId id = MAX<OPL::Config::DriverId>(OPL::Config::parse(ConfMan.get("opl_driver", _domain)), 0);
00373         _oplPopUp->setSelectedTag(id);
00374     }
00375 #endif
00376 
00377     if (_multiMidiCheckbox) {
00378         if (!loadMusicDeviceSetting(_gmDevicePopUp, "gm_device"))
00379             _gmDevicePopUp->setSelected(0);
00380 
00381         // Multi midi setting
00382         _multiMidiCheckbox->setState(ConfMan.getBool("multi_midi", _domain));
00383 
00384         Common::String soundFont(ConfMan.get("soundfont", _domain));
00385         if (soundFont.empty() || !ConfMan.hasKey("soundfont", _domain)) {
00386             _soundFont->setLabel(_c("None", "soundfont"));
00387             _soundFontClearButton->setEnabled(false);
00388         } else {
00389             _soundFont->setLabel(soundFont);
00390             _soundFontClearButton->setEnabled(true);
00391         }
00392 
00393         // MIDI gain setting
00394         _midiGainSlider->setValue(ConfMan.getInt("midi_gain", _domain));
00395         _midiGainLabel->setLabel(Common::String::format("%.2f", (double)_midiGainSlider->getValue() / 100.0));
00396     }
00397 
00398     // MT-32 options
00399     if (_mt32DevicePopUp) {
00400         if (!loadMusicDeviceSetting(_mt32DevicePopUp, "mt32_device"))
00401             _mt32DevicePopUp->setSelected(0);
00402 
00403         // Native mt32 setting
00404         _mt32Checkbox->setState(ConfMan.getBool("native_mt32", _domain));
00405 
00406         // GS extensions setting
00407         _enableGSCheckbox->setState(ConfMan.getBool("enable_gs", _domain));
00408     }
00409 
00410     // Volume options
00411     if (_musicVolumeSlider) {
00412         int vol;
00413 
00414         vol = ConfMan.getInt("music_volume", _domain);
00415         _musicVolumeSlider->setValue(vol);
00416         _musicVolumeLabel->setValue(vol);
00417 
00418         vol = ConfMan.getInt("sfx_volume", _domain);
00419         _sfxVolumeSlider->setValue(vol);
00420         _sfxVolumeLabel->setValue(vol);
00421 
00422         vol = ConfMan.getInt("speech_volume", _domain);
00423         _speechVolumeSlider->setValue(vol);
00424         _speechVolumeLabel->setValue(vol);
00425 
00426         bool val = false;
00427         if (ConfMan.hasKey("mute", _domain)) {
00428             val = ConfMan.getBool("mute", _domain);
00429         } else {
00430             ConfMan.setBool("mute", false);
00431         }
00432         _muteCheckbox->setState(val);
00433     }
00434 
00435     // Subtitle options
00436     if (_subToggleGroup) {
00437         int speed;
00438         int sliderMaxValue = _subSpeedSlider->getMaxValue();
00439 
00440         int subMode = getSubtitleMode(ConfMan.getBool("subtitles", _domain), ConfMan.getBool("speech_mute", _domain));
00441         _subToggleGroup->setValue(subMode);
00442 
00443         // Engines that reuse the subtitle speed widget set their own max value.
00444         // Scale the config value accordingly (see addSubtitleControls)
00445         speed = (ConfMan.getInt("talkspeed", _domain) * sliderMaxValue + 255 / 2) / 255;
00446         _subSpeedSlider->setValue(speed);
00447         _subSpeedLabel->setValue(speed);
00448     }
00449 }
00450 
00451 void OptionsDialog::clean() {
00452     delete _subToggleGroup;
00453     while (_firstWidget) {
00454         Widget* w = _firstWidget;
00455         removeWidget(w);
00456         // This is called from rebuild() which may result from handleCommand being called by
00457         // a child widget sendCommand call. In such a case sendCommand is still being executed
00458         // so we should not delete yet the child widget. Thus delay the deletion.
00459         g_gui.addToTrash(w, this);
00460     }
00461     init();
00462 }
00463 
00464 void OptionsDialog::rebuild() {
00465     int currentTab = _tabWidget->getActiveTab();
00466     clean();
00467     build();
00468     reflowLayout();
00469     _tabWidget->setActiveTab(currentTab);
00470     setDefaultFocusedWidget();
00471 }
00472 
00473 void OptionsDialog::open() {
00474     build();
00475 
00476     Dialog::open();
00477 
00478     // Reset result value
00479     setResult(0);
00480 }
00481 
00482 void OptionsDialog::apply() {
00483     bool graphicsModeChanged = false;
00484 
00485     // Graphic options
00486     if (_fullscreenCheckbox) {
00487         if (_enableGraphicSettings) {
00488             if (ConfMan.getBool("filtering", _domain) != _filteringCheckbox->getState())
00489                 graphicsModeChanged = true;
00490             if (ConfMan.getBool("fullscreen", _domain) != _fullscreenCheckbox->getState())
00491                 graphicsModeChanged = true;
00492             if (ConfMan.getBool("aspect_ratio", _domain) != _aspectCheckbox->getState())
00493                 graphicsModeChanged = true;
00494             if (ConfMan.getBool("vsync", _domain) != _vsyncCheckbox->getState()) // ResidualVM specific
00495                 graphicsModeChanged = true; // ResidualVM specific
00496             
00497             ConfMan.setBool("filtering", _filteringCheckbox->getState(), _domain);
00498             ConfMan.setBool("fullscreen", _fullscreenCheckbox->getState(), _domain);
00499             ConfMan.setBool("aspect_ratio", _aspectCheckbox->getState(), _domain);
00500             ConfMan.setBool("vsync", _vsyncCheckbox->getState(), _domain); // ResidualVM specific
00501             
00502 #if 0 // ResidualVM specific
00503             bool isSet = false;
00504 
00505             if ((int32)_gfxPopUp->getSelectedTag() >= 0) {
00506                 const OSystem::GraphicsMode *gm = g_system->getSupportedGraphicsModes();
00507 
00508                 while (gm->name) {
00509                     if (gm->id == (int)_gfxPopUp->getSelectedTag()) {
00510                         if (ConfMan.get("gfx_mode", _domain) != gm->name)
00511                             graphicsModeChanged = true;
00512                         ConfMan.set("gfx_mode", gm->name, _domain);
00513                         isSet = true;
00514                         break;
00515                     }
00516                     gm++;
00517                 }
00518             }
00519             if (!isSet)
00520                 ConfMan.removeKey("gfx_mode", _domain);
00521 
00522             if ((int32)_renderModePopUp->getSelectedTag() >= 0)
00523                 ConfMan.set("render_mode", Common::getRenderModeCode((Common::RenderMode)_renderModePopUp->getSelectedTag()), _domain);
00524 
00525             isSet = false;
00526             if ((int32)_stretchPopUp->getSelectedTag() >= 0) {
00527                 const OSystem::GraphicsMode *sm = g_system->getSupportedStretchModes();
00528                 while (sm->name) {
00529                     if (sm->id == (int)_stretchPopUp->getSelectedTag()) {
00530                         if (ConfMan.get("stretch_mode", _domain) != sm->name)
00531                             graphicsModeChanged = true;
00532                         ConfMan.set("stretch_mode", sm->name, _domain);
00533                         isSet = true;
00534                         break;
00535                     }
00536                     sm++;
00537                 }
00538             }
00539             if (!isSet)
00540                 ConfMan.removeKey("stretch_mode", _domain);
00541 #endif
00542 
00543             // ResidualVM specific -- Start
00544             if (_rendererTypePopUp->getSelectedTag() > 0) {
00545                 Graphics::RendererType selected = (Graphics::RendererType) _rendererTypePopUp->getSelectedTag();
00546                 ConfMan.set("renderer", Graphics::getRendererTypeCode(selected), _domain);
00547             } else {
00548                 ConfMan.removeKey("renderer", _domain);
00549             }
00550 
00551             if (_antiAliasPopUp->getSelectedTag() != (uint32)-1) {
00552                 uint level = _antiAliasPopUp->getSelectedTag();
00553                 ConfMan.setInt("antialiasing", level, _domain);
00554             } else {
00555                 ConfMan.removeKey("antialiasing", _domain);
00556             }
00557             // ResidualVM specific -- End
00558 
00559         } else {
00560             ConfMan.removeKey("fullscreen", _domain);
00561             ConfMan.removeKey("filtering", _domain);
00562             ConfMan.removeKey("aspect_ratio", _domain);
00563 #if 0 // ResidualVM specific
00564             ConfMan.removeKey("gfx_mode", _domain);
00565             ConfMan.removeKey("stretch_mode", _domain);
00566             ConfMan.removeKey("render_mode", _domain);
00567 #endif
00568             ConfMan.removeKey("renderer", _domain); // ResidualVM specific
00569             ConfMan.removeKey("antialiasing", _domain); // ResidualVM specific
00570             ConfMan.removeKey("vsync", _domain); // ResidualVM specific
00571         }
00572     }
00573 
00574     // Setup graphics again if needed
00575     if (_domain == Common::ConfigManager::kApplicationDomain && graphicsModeChanged) {
00576         g_system->beginGFXTransaction();
00577         g_system->setGraphicsMode(ConfMan.get("gfx_mode", _domain).c_str());
00578 
00579         if (ConfMan.hasKey("stretch_mode"))
00580             g_system->setStretchMode(ConfMan.get("stretch_mode", _domain).c_str());
00581         if (ConfMan.hasKey("aspect_ratio"))
00582             g_system->setFeatureState(OSystem::kFeatureAspectRatioCorrection, ConfMan.getBool("aspect_ratio", _domain));
00583         if (ConfMan.hasKey("fullscreen"))
00584             g_system->setFeatureState(OSystem::kFeatureFullscreenMode, ConfMan.getBool("fullscreen", _domain));
00585         if (ConfMan.hasKey("filtering"))
00586             g_system->setFeatureState(OSystem::kFeatureFilteringMode, ConfMan.getBool("filtering", _domain));
00587 
00588         OSystem::TransactionError gfxError = g_system->endGFXTransaction();
00589 
00590         // Since this might change the screen resolution we need to give
00591         // the GUI a chance to update it's internal state. Otherwise we might
00592         // get a crash when the GUI tries to grab the overlay.
00593         //
00594         // This fixes bug #3303501 "Switching from HQ2x->HQ3x crashes ScummVM"
00595         //
00596         // It is important that this is called *before* any of the current
00597         // dialog's widgets are destroyed (for example before
00598         // Dialog::close) is called, to prevent crashes caused by invalid
00599         // widgets being referenced or similar errors.
00600         g_gui.checkScreenChange();
00601 
00602         if (gfxError != OSystem::kTransactionSuccess) {
00603             // Revert ConfMan to what OSystem is using.
00604             Common::String message = _("Failed to apply some of the graphic options changes:");
00605 
00606             if (gfxError & OSystem::kTransactionModeSwitchFailed) {
00607                 const OSystem::GraphicsMode *gm = g_system->getSupportedGraphicsModes();
00608                 while (gm->name) {
00609                     if (gm->id == g_system->getGraphicsMode()) {
00610                         ConfMan.set("gfx_mode", gm->name, _domain);
00611                         break;
00612                     }
00613                     gm++;
00614                 }
00615                 message += "\n";
00616                 message += _("the video mode could not be changed");
00617             }
00618 
00619             if (gfxError & OSystem::kTransactionStretchModeSwitchFailed) {
00620                 const OSystem::GraphicsMode *sm = g_system->getSupportedStretchModes();
00621                 while (sm->name) {
00622                     if (sm->id == g_system->getStretchMode()) {
00623                         ConfMan.set("stretch_mode", sm->name, _domain);
00624                         break;
00625                     }
00626                     sm++;
00627                 }
00628                 message += "\n";
00629                 message += _("the stretch mode could not be changed");
00630             }
00631 
00632             if (gfxError & OSystem::kTransactionAspectRatioFailed) {
00633                 ConfMan.setBool("aspect_ratio", g_system->getFeatureState(OSystem::kFeatureAspectRatioCorrection), _domain);
00634                 message += "\n";
00635                 message += _("the aspect ratio setting could not be changed");
00636             }
00637 
00638             if (gfxError & OSystem::kTransactionFullscreenFailed) {
00639                 ConfMan.setBool("fullscreen", g_system->getFeatureState(OSystem::kFeatureFullscreenMode), _domain);
00640                 message += "\n";
00641                 message += _("the fullscreen setting could not be changed");
00642             }
00643 
00644             if (gfxError & OSystem::kTransactionFilteringFailed) {
00645                 ConfMan.setBool("filtering", g_system->getFeatureState(OSystem::kFeatureFilteringMode), _domain);
00646                 message += "\n";
00647                 message += _("the filtering setting could not be changed");
00648             }
00649 
00650             // And display the error
00651             GUI::MessageDialog dialog(message);
00652             dialog.runModal();
00653         }
00654     }
00655 
00656     // Shader options
00657     if (_enableShaderSettings) {
00658         if (g_system->hasFeature(OSystem::kFeatureShader)) {
00659             if (_shaderPopUp) {
00660                 if (ConfMan.getInt("shader", _domain) != (int32)_shaderPopUp->getSelectedTag()) {
00661                     ConfMan.setInt("shader", _shaderPopUp->getSelectedTag(), _domain);
00662                     g_system->setShader(_shaderPopUp->getSelectedTag());
00663                 }
00664             }
00665         }
00666     }
00667 
00668     // Control options
00669     if (_enableControlSettings) {
00670         if (g_system->hasFeature(OSystem::kFeatureOnScreenControl)) {
00671             if (ConfMan.getBool("onscreen_control", _domain) != _onscreenCheckbox->getState()) {
00672                 g_system->setFeatureState(OSystem::kFeatureOnScreenControl, _onscreenCheckbox->getState());
00673             }
00674         }
00675         if (g_system->hasFeature(OSystem::kFeatureTouchpadMode)) {
00676             if (ConfMan.getBool("touchpad_mouse_mode", _domain) != _touchpadCheckbox->getState()) {
00677                 g_system->setFeatureState(OSystem::kFeatureTouchpadMode, _touchpadCheckbox->getState());
00678             }
00679         }
00680         if (g_system->hasFeature(OSystem::kFeatureSwapMenuAndBackButtons)) {
00681             if (ConfMan.getBool("swap_menu_and_back_buttons", _domain) != _swapMenuAndBackBtnsCheckbox->getState()) {
00682                 g_system->setFeatureState(OSystem::kFeatureSwapMenuAndBackButtons, _swapMenuAndBackBtnsCheckbox->getState());
00683             }
00684         }
00685         if (g_system->hasFeature(OSystem::kFeatureKbdMouseSpeed)) {
00686             if (ConfMan.getInt("kbdmouse_speed", _domain) != _kbdMouseSpeedSlider->getValue()) {
00687                 ConfMan.setInt("kbdmouse_speed", _kbdMouseSpeedSlider->getValue(), _domain);
00688             }
00689         }
00690         if (g_system->hasFeature(OSystem::kFeatureJoystickDeadzone)) {
00691             if (ConfMan.getInt("joystick_deadzone", _domain) != _joystickDeadzoneSlider->getValue()) {
00692                 ConfMan.setInt("joystick_deadzone", _joystickDeadzoneSlider->getValue(), _domain);
00693             }
00694         }
00695     }
00696 
00697     // Volume options
00698     if (_musicVolumeSlider) {
00699         if (_enableVolumeSettings) {
00700             ConfMan.setInt("music_volume", _musicVolumeSlider->getValue(), _domain);
00701             ConfMan.setInt("sfx_volume", _sfxVolumeSlider->getValue(), _domain);
00702             ConfMan.setInt("speech_volume", _speechVolumeSlider->getValue(), _domain);
00703             ConfMan.setBool("mute", _muteCheckbox->getState(), _domain);
00704         } else {
00705             ConfMan.removeKey("music_volume", _domain);
00706             ConfMan.removeKey("sfx_volume", _domain);
00707             ConfMan.removeKey("speech_volume", _domain);
00708             ConfMan.removeKey("mute", _domain);
00709         }
00710     }
00711 
00712     // Audio options
00713     if (_midiPopUp) {
00714         if (_enableAudioSettings) {
00715             saveMusicDeviceSetting(_midiPopUp, "music_driver");
00716         } else {
00717             ConfMan.removeKey("music_driver", _domain);
00718         }
00719     }
00720 
00721 #if 0 // ResidualVM specific
00722     if (_oplPopUp) {
00723         if (_enableAudioSettings) {
00724             const OPL::Config::EmulatorDescription *ed = OPL::Config::findDriver(_oplPopUp->getSelectedTag());
00725 
00726             if (ed)
00727                 ConfMan.set("opl_driver", ed->name, _domain);
00728             else
00729                 ConfMan.removeKey("opl_driver", _domain);
00730         } else {
00731             ConfMan.removeKey("opl_driver", _domain);
00732         }
00733     }
00734 #endif
00735 
00736     // MIDI options
00737     if (_multiMidiCheckbox) {
00738         if (_enableMIDISettings) {
00739             saveMusicDeviceSetting(_gmDevicePopUp, "gm_device");
00740 
00741             ConfMan.setBool("multi_midi", _multiMidiCheckbox->getState(), _domain);
00742             ConfMan.setInt("midi_gain", _midiGainSlider->getValue(), _domain);
00743 
00744             Common::String soundFont(_soundFont->getLabel());
00745             if (!soundFont.empty() && (soundFont != _c("None", "soundfont")))
00746                 ConfMan.set("soundfont", soundFont, _domain);
00747             else
00748                 ConfMan.removeKey("soundfont", _domain);
00749         } else {
00750             ConfMan.removeKey("gm_device", _domain);
00751             ConfMan.removeKey("multi_midi", _domain);
00752             ConfMan.removeKey("midi_gain", _domain);
00753             ConfMan.removeKey("soundfont", _domain);
00754         }
00755     }
00756 
00757     // MT-32 options
00758     if (_mt32DevicePopUp) {
00759         if (_enableMT32Settings) {
00760             saveMusicDeviceSetting(_mt32DevicePopUp, "mt32_device");
00761             ConfMan.setBool("native_mt32", _mt32Checkbox->getState(), _domain);
00762             ConfMan.setBool("enable_gs", _enableGSCheckbox->getState(), _domain);
00763         } else {
00764             ConfMan.removeKey("mt32_device", _domain);
00765             ConfMan.removeKey("native_mt32", _domain);
00766             ConfMan.removeKey("enable_gs", _domain);
00767         }
00768     }
00769 
00770     // Subtitle options
00771     if (_subToggleGroup) {
00772         if (_enableSubtitleSettings) {
00773             bool subtitles, speech_mute;
00774             int talkspeed;
00775             int sliderMaxValue = _subSpeedSlider->getMaxValue();
00776 
00777             switch (_subToggleGroup->getValue()) {
00778                 case kSubtitlesSpeech:
00779                     subtitles = speech_mute = false;
00780                     break;
00781                 case kSubtitlesBoth:
00782                     subtitles = true;
00783                     speech_mute = false;
00784                     break;
00785                 case kSubtitlesSubs:
00786                 default:
00787                     subtitles = speech_mute = true;
00788                     break;
00789             }
00790 
00791             ConfMan.setBool("subtitles", subtitles, _domain);
00792             ConfMan.setBool("speech_mute", speech_mute, _domain);
00793 
00794             // Engines that reuse the subtitle speed widget set their own max value.
00795             // Scale the config value accordingly (see addSubtitleControls)
00796             talkspeed = (_subSpeedSlider->getValue() * 255 + sliderMaxValue / 2) / sliderMaxValue;
00797             ConfMan.setInt("talkspeed", talkspeed, _domain);
00798 
00799         } else {
00800             ConfMan.removeKey("subtitles", _domain);
00801             ConfMan.removeKey("talkspeed", _domain);
00802             ConfMan.removeKey("speech_mute", _domain);
00803         }
00804     }
00805 
00806     // Save config file
00807     ConfMan.flushToDisk();
00808 }
00809 
00810 void OptionsDialog::close() {
00811     if (getResult())
00812         apply();
00813 
00814     Dialog::close();
00815 }
00816 
00817 void OptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
00818     switch (cmd) {
00819     case kMidiGainChanged:
00820         _midiGainLabel->setLabel(Common::String::format("%.2f", (double)_midiGainSlider->getValue() / 100.0));
00821         _midiGainLabel->markAsDirty();
00822         break;
00823     case kMusicVolumeChanged: {
00824         const int newValue = _musicVolumeSlider->getValue();
00825         _musicVolumeLabel->setValue(newValue);
00826         _musicVolumeLabel->markAsDirty();
00827 
00828         if (_guioptions.contains(GUIO_LINKMUSICTOSFX)) {
00829             updateSfxVolume(newValue);
00830 
00831             if (_guioptions.contains(GUIO_LINKSPEECHTOSFX)) {
00832                 updateSpeechVolume(newValue);
00833             }
00834         }
00835 
00836         break;
00837     }
00838     case kSfxVolumeChanged: {
00839         const int newValue = _sfxVolumeSlider->getValue();
00840         _sfxVolumeLabel->setValue(_sfxVolumeSlider->getValue());
00841         _sfxVolumeLabel->markAsDirty();
00842 
00843         if (_guioptions.contains(GUIO_LINKMUSICTOSFX)) {
00844             updateMusicVolume(newValue);
00845         }
00846 
00847         if (_guioptions.contains(GUIO_LINKSPEECHTOSFX)) {
00848             updateSpeechVolume(newValue);
00849         }
00850 
00851         break;
00852     }
00853     case kSpeechVolumeChanged: {
00854         const int newValue = _speechVolumeSlider->getValue();
00855         _speechVolumeLabel->setValue(newValue);
00856         _speechVolumeLabel->markAsDirty();
00857 
00858         if (_guioptions.contains(GUIO_LINKSPEECHTOSFX)) {
00859             updateSfxVolume(newValue);
00860 
00861             if (_guioptions.contains(GUIO_LINKMUSICTOSFX)) {
00862                 updateMusicVolume(newValue);
00863             }
00864         }
00865 
00866         break;
00867     }
00868     case kMuteAllChanged:
00869         // 'true' because if control is disabled then event do not pass
00870         setVolumeSettingsState(true);
00871         break;
00872     case kSubtitleToggle:
00873         // We update the slider settings here, when there are sliders, to
00874         // disable the speech volume in case we are in subtitle only mode.
00875         if (_musicVolumeSlider)
00876             setVolumeSettingsState(true);
00877         break;
00878     case kSubtitleSpeedChanged:
00879         _subSpeedLabel->setValue(_subSpeedSlider->getValue());
00880         _subSpeedLabel->markAsDirty();
00881         break;
00882     case kClearSoundFontCmd:
00883         _soundFont->setLabel(_c("None", "soundfont"));
00884         _soundFontClearButton->setEnabled(false);
00885         g_gui.scheduleTopDialogRedraw();
00886         break;
00887     case kKbdMouseSpeedChanged:
00888         _kbdMouseSpeedLabel->setLabel(_(kbdMouseSpeedLabels[_kbdMouseSpeedSlider->getValue()]));
00889         _kbdMouseSpeedLabel->markAsDirty();
00890         break;
00891     case kJoystickDeadzoneChanged:
00892         _joystickDeadzoneLabel->setValue(_joystickDeadzoneSlider->getValue());
00893         _joystickDeadzoneLabel->markAsDirty();
00894         break;
00895     case kGraphicsTabContainerReflowCmd:
00896         setupGraphicsTab();
00897         break;
00898     case kApplyCmd:
00899         apply();
00900         break;
00901     case kOKCmd:
00902         setResult(1);
00903         close();
00904         break;
00905     case kCloseCmd:
00906         close();
00907         break;
00908     default:
00909         Dialog::handleCommand(sender, cmd, data);
00910     }
00911 }
00912 
00913 void OptionsDialog::setGraphicSettingsState(bool enabled) {
00914     _enableGraphicSettings = enabled;
00915 
00916 #if 0 // ResidualVM specific
00917     _gfxPopUpDesc->setEnabled(enabled);
00918     _gfxPopUp->setEnabled(enabled);
00919     _renderModePopUpDesc->setEnabled(enabled);
00920     _renderModePopUp->setEnabled(enabled);
00921     _stretchPopUpDesc->setEnabled(enabled);
00922     _stretchPopUp->setEnabled(enabled);
00923     _filteringCheckbox->setEnabled(enabled);
00924 #endif
00925 #ifndef GUI_ENABLE_KEYSDIALOG
00926 #ifndef GUI_ONLY_FULLSCREEN
00927     _fullscreenCheckbox->setEnabled(enabled);
00928 #endif // !GUI_ONLY_FULLSCREEN
00929     if (_guioptions.contains(GUIO_NOASPECT))
00930         _aspectCheckbox->setEnabled(false);
00931     else
00932         _aspectCheckbox->setEnabled(enabled);
00933 #endif // !GUI_ENABLE_KEYSDIALOG
00934     // ResidualVM specific:
00935     _vsyncCheckbox->setEnabled(enabled);
00936     _rendererTypePopUp->setEnabled(enabled);
00937     _antiAliasPopUp->setEnabled(enabled);
00938 }
00939 
00940 void OptionsDialog::setAudioSettingsState(bool enabled) {
00941     return; // ResidualVM specific
00942     _enableAudioSettings = enabled;
00943     _midiPopUpDesc->setEnabled(enabled);
00944     _midiPopUp->setEnabled(enabled);
00945 
00946     const Common::String allFlags = MidiDriver::musicType2GUIO((uint32)-1);
00947     bool hasMidiDefined = (strpbrk(_guioptions.c_str(), allFlags.c_str()) != NULL);
00948 
00949     if (_domain != Common::ConfigManager::kApplicationDomain && // global dialog
00950         hasMidiDefined && // No flags are specified
00951         !(_guioptions.contains(GUIO_MIDIADLIB))) {
00952         _oplPopUpDesc->setEnabled(false);
00953         _oplPopUp->setEnabled(false);
00954     } else {
00955         _oplPopUpDesc->setEnabled(enabled);
00956         _oplPopUp->setEnabled(enabled);
00957     }
00958 }
00959 
00960 void OptionsDialog::setMIDISettingsState(bool enabled) {
00961     if (_guioptions.contains(GUIO_NOMIDI))
00962         enabled = false;
00963 
00964     _gmDevicePopUpDesc->setEnabled(_domain.equals(Common::ConfigManager::kApplicationDomain) ? enabled : false);
00965     _gmDevicePopUp->setEnabled(_domain.equals(Common::ConfigManager::kApplicationDomain) ? enabled : false);
00966 
00967     _enableMIDISettings = enabled;
00968 
00969     _soundFontButton->setEnabled(enabled);
00970     _soundFont->setEnabled(enabled);
00971 
00972     if (enabled && !_soundFont->getLabel().empty() && (_soundFont->getLabel() != _c("None", "soundfont")))
00973         _soundFontClearButton->setEnabled(enabled);
00974     else
00975         _soundFontClearButton->setEnabled(false);
00976 
00977     _multiMidiCheckbox->setEnabled(enabled);
00978     _midiGainDesc->setEnabled(enabled);
00979     _midiGainSlider->setEnabled(enabled);
00980     _midiGainLabel->setEnabled(enabled);
00981 }
00982 
00983 void OptionsDialog::setMT32SettingsState(bool enabled) {
00984     _enableMT32Settings = enabled;
00985 
00986     _mt32DevicePopUpDesc->setEnabled(_domain.equals(Common::ConfigManager::kApplicationDomain) ? enabled : false);
00987     _mt32DevicePopUp->setEnabled(_domain.equals(Common::ConfigManager::kApplicationDomain) ? enabled : false);
00988 
00989     _mt32Checkbox->setEnabled(enabled);
00990     _enableGSCheckbox->setEnabled(enabled);
00991 }
00992 
00993 void OptionsDialog::setVolumeSettingsState(bool enabled) {
00994     bool ena;
00995 
00996     _enableVolumeSettings = enabled;
00997 
00998     ena = enabled && !_muteCheckbox->getState();
00999     if (_guioptions.contains(GUIO_NOMUSIC))
01000         ena = false;
01001 
01002     _musicVolumeDesc->setEnabled(ena);
01003     _musicVolumeSlider->setEnabled(ena);
01004     _musicVolumeLabel->setEnabled(ena);
01005 
01006     ena = enabled && !_muteCheckbox->getState();
01007     if (_guioptions.contains(GUIO_NOSFX))
01008         ena = false;
01009 
01010     _sfxVolumeDesc->setEnabled(ena);
01011     _sfxVolumeSlider->setEnabled(ena);
01012     _sfxVolumeLabel->setEnabled(ena);
01013 
01014     ena = enabled && !_muteCheckbox->getState();
01015     // Disable speech volume slider, when we are in subtitle only mode.
01016     if (_subToggleGroup)
01017         ena = ena && _subToggleGroup->getValue() != kSubtitlesSubs;
01018     if (_guioptions.contains(GUIO_NOSPEECH) || _guioptions.contains(GUIO_NOSPEECHVOLUME))
01019         ena = false;
01020 
01021     _speechVolumeDesc->setEnabled(ena);
01022     _speechVolumeSlider->setEnabled(ena);
01023     _speechVolumeLabel->setEnabled(ena);
01024 
01025     _muteCheckbox->setEnabled(enabled);
01026 }
01027 
01028 void OptionsDialog::setSubtitleSettingsState(bool enabled) {
01029     bool ena;
01030     _enableSubtitleSettings = enabled;
01031 
01032     ena = enabled;
01033     if ((_guioptions.contains(GUIO_NOSUBTITLES)) || (_guioptions.contains(GUIO_NOSPEECH)))
01034         ena = false;
01035 
01036     _subToggleGroup->setEnabled(ena);
01037     _subToggleDesc->setEnabled(ena);
01038 
01039     ena = enabled;
01040     if (_guioptions.contains(GUIO_NOSUBTITLES))
01041         ena = false;
01042 
01043     _subSpeedDesc->setEnabled(ena);
01044     _subSpeedSlider->setEnabled(ena);
01045     _subSpeedLabel->setEnabled(ena);
01046 }
01047 
01048 void OptionsDialog::addControlControls(GuiObject *boss, const Common::String &prefix) {
01049     // Show On-Screen control
01050     if (g_system->hasFeature(OSystem::kFeatureOnScreenControl))
01051         _onscreenCheckbox = new CheckboxWidget(boss, prefix + "grOnScreenCheckbox", _("Show On-screen control"));
01052 
01053     // Touchpad Mouse mode
01054     if (g_system->hasFeature(OSystem::kFeatureTouchpadMode))
01055         _touchpadCheckbox = new CheckboxWidget(boss, prefix + "grTouchpadCheckbox", _("Touchpad mouse mode"));
01056 
01057     // Swap menu and back buttons
01058     if (g_system->hasFeature(OSystem::kFeatureSwapMenuAndBackButtons))
01059         _swapMenuAndBackBtnsCheckbox = new CheckboxWidget(boss, prefix + "grSwapMenuAndBackBtnsCheckbox", _("Swap Menu and Back buttons"));
01060 
01061     // Keyboard and joystick mouse speed
01062     if (g_system->hasFeature(OSystem::kFeatureKbdMouseSpeed)) {
01063         if (g_system->getOverlayWidth() > 320)
01064             _kbdMouseSpeedDesc = new StaticTextWidget(boss, prefix + "grKbdMouseSpeedDesc", _("Pointer Speed:"), _("Speed for keyboard/joystick mouse pointer control"));
01065         else
01066             _kbdMouseSpeedDesc = new StaticTextWidget(boss, prefix + "grKbdMouseSpeedDesc", _c("Pointer Speed:", "lowres"), _("Speed for keyboard/joystick mouse pointer control"));
01067         _kbdMouseSpeedSlider = new SliderWidget(boss, prefix + "grKbdMouseSpeedSlider", _("Speed for keyboard/joystick mouse pointer control"), kKbdMouseSpeedChanged);
01068         _kbdMouseSpeedLabel = new StaticTextWidget(boss, prefix + "grKbdMouseSpeedLabel", "  ");
01069         _kbdMouseSpeedSlider->setMinValue(0);
01070         _kbdMouseSpeedSlider->setMaxValue(7);
01071         _kbdMouseSpeedLabel->setFlags(WIDGET_CLEARBG);
01072     }
01073 
01074     // Joystick deadzone
01075     if (g_system->hasFeature(OSystem::kFeatureJoystickDeadzone)) {
01076         if (g_system->getOverlayWidth() > 320)
01077             _joystickDeadzoneDesc = new StaticTextWidget(boss, prefix + "grJoystickDeadzoneDesc", _("Joy Deadzone:"), _("Analog joystick Deadzone"));
01078         else
01079             _joystickDeadzoneDesc = new StaticTextWidget(boss, prefix + "grJoystickDeadzoneDesc", _c("Joy Deadzone:", "lowres"), _("Analog joystick Deadzone"));
01080         _joystickDeadzoneSlider = new SliderWidget(boss, prefix + "grJoystickDeadzoneSlider", _("Analog joystick Deadzone"), kJoystickDeadzoneChanged);
01081         _joystickDeadzoneLabel = new StaticTextWidget(boss, prefix + "grJoystickDeadzoneLabel", "  ");
01082         _joystickDeadzoneSlider->setMinValue(1);
01083         _joystickDeadzoneSlider->setMaxValue(10);
01084         _joystickDeadzoneLabel->setFlags(WIDGET_CLEARBG);
01085     }
01086     _enableControlSettings = true;
01087 }
01088 
01089 void OptionsDialog::addShaderControls(GuiObject *boss, const Common::String &prefix) {
01090     // Shader selector
01091     if (g_system->hasFeature(OSystem::kFeatureShader)) {
01092         if (g_system->getOverlayWidth() > 320)
01093             _shaderPopUpDesc = new StaticTextWidget(boss, prefix + "grShaderPopUpDesc", _("HW Shader:"), _("Different hardware shaders give different visual effects"));
01094         else
01095             _shaderPopUpDesc = new StaticTextWidget(boss, prefix + "grShaderPopUpDesc", _c("HW Shader:", "lowres"), _("Different hardware shaders give different visual effects"));
01096         _shaderPopUp = new PopUpWidget(boss, prefix + "grShaderPopUp", _("Different shaders give different visual effects"));
01097         const OSystem::GraphicsMode *p = g_system->getSupportedShaders();
01098         while (p->name) {
01099             _shaderPopUp->appendEntry(p->name, p->id);
01100             p++;
01101         }
01102     }
01103     _enableShaderSettings = true;
01104 }
01105 
01106 void OptionsDialog::addGraphicControls(GuiObject *boss, const Common::String &prefix) {
01107 #if 0 // ResidualVM specific
01108     const OSystem::GraphicsMode *gm = g_system->getSupportedGraphicsModes();
01109     Common::String context;
01110     if (g_system->getOverlayWidth() <= 320)
01111         context = "lowres";
01112 
01113     // The GFX mode popup
01114     _gfxPopUpDesc = new StaticTextWidget(boss, prefix + "grModePopupDesc", _("Graphics mode:"));
01115     _gfxPopUp = new PopUpWidget(boss, prefix + "grModePopup");
01116 
01117     _gfxPopUp->appendEntry(_("<default>"));
01118     _gfxPopUp->appendEntry("");
01119     while (gm->name) {
01120         _gfxPopUp->appendEntry(_c(gm->description, context), gm->id);
01121         gm++;
01122     }
01123 
01124     // RenderMode popup
01125     const Common::String allFlags = Common::allRenderModesGUIOs();
01126     bool renderingTypeDefined = (strpbrk(_guioptions.c_str(), allFlags.c_str()) != NULL);
01127 
01128     _renderModePopUpDesc = new StaticTextWidget(boss, prefix + "grRenderPopupDesc", _("Render mode:"), _("Special dithering modes supported by some games"));
01129     _renderModePopUp = new PopUpWidget(boss, prefix + "grRenderPopup", _("Special dithering modes supported by some games"));
01130     _renderModePopUp->appendEntry(_("<default>"), Common::kRenderDefault);
01131     _renderModePopUp->appendEntry("");
01132     const Common::RenderModeDescription *rm = Common::g_renderModes;
01133     for (; rm->code; ++rm) {
01134         Common::String renderGuiOption = Common::renderMode2GUIO(rm->id);
01135         if ((_domain == Common::ConfigManager::kApplicationDomain) || (_domain != Common::ConfigManager::kApplicationDomain && !renderingTypeDefined) || (_guioptions.contains(renderGuiOption)))
01136             _renderModePopUp->appendEntry(_c(rm->description, context), rm->id);
01137     }
01138 
01139     // The Stretch mode popup
01140     const OSystem::GraphicsMode *sm = g_system->getSupportedStretchModes();
01141     _stretchPopUpDesc = new StaticTextWidget(boss, prefix + "grStretchModePopupDesc", _("Stretch mode:"));
01142     _stretchPopUp = new PopUpWidget(boss, prefix + "grStretchModePopup");
01143 
01144     _stretchPopUp->appendEntry(_("<default>"));
01145     _stretchPopUp->appendEntry("");
01146     while (sm->name) {
01147         _stretchPopUp->appendEntry(_c(sm->description, context), sm->id);
01148         sm++;
01149 #endif
01150     // Fullscreen checkbox
01151     _fullscreenCheckbox = new CheckboxWidget(boss, prefix + "grFullscreenCheckbox", _("Fullscreen mode"), 0, kFullscreenToggled);
01152 
01153     // ResidualVM specific description
01154     _aspectCheckbox = new CheckboxWidget(boss, prefix + "grAspectCheckbox", _("Preserve aspect ratio"), _("Preserve the aspect ratio in fullscreen mode"));
01155 
01156     // ResidualVM specific -- Start
01157     _vsyncCheckbox = new CheckboxWidget(boss, prefix + "grVSyncCheckbox", _("V-Sync"), _("Wait for the vertical sync to refresh the screen"));
01158 
01159     _rendererTypePopUpDesc = new StaticTextWidget(boss, prefix + "grRendererTypePopupDesc", _("Game Renderer:"));
01160     _rendererTypePopUp = new PopUpWidget(boss, prefix + "grRendererTypePopup");
01161     _rendererTypePopUp->appendEntry(_("<default>"), Graphics::kRendererTypeDefault);
01162     _rendererTypePopUp->appendEntry("");
01163     const Graphics::RendererTypeDescription *rt = Graphics::listRendererTypes();
01164     for (; rt->code; ++rt) {
01165         _rendererTypePopUp->appendEntry(_(rt->description), rt->id);
01166     }
01167 
01168     _antiAliasPopUpDesc = new StaticTextWidget(boss, prefix + "grAntiAliasPopupDesc", _("Anti-aliasing:"));
01169     _antiAliasPopUp = new PopUpWidget(boss, prefix + "grAntiAliasPopup");
01170     _antiAliasPopUp->appendEntry(_("<default>"), -1);
01171     _antiAliasPopUp->appendEntry("");
01172     _antiAliasPopUp->appendEntry(_("Disabled"), 0);
01173     const Common::Array<uint> levels = g_system->getSupportedAntiAliasingLevels();
01174     for (uint i = 0; i < levels.size(); i++) {
01175         _antiAliasPopUp->appendEntry(Common::String::format("%dx", levels[i]), levels[i]);
01176     }
01177     if (levels.empty()) {
01178         // Don't show the anti-aliasing selection menu when it is not supported
01179         _antiAliasPopUpDesc->setVisible(false);
01180         _antiAliasPopUp->setVisible(false);
01181     }
01182     // ResidualVM specific -- End
01183 
01184     // Filtering checkbox
01185     _filteringCheckbox = new CheckboxWidget(boss, prefix + "grFilteringCheckbox", _("Filter graphics"), _("Use linear filtering when scaling graphics"));
01186 
01187     _enableGraphicSettings = true;
01188 }
01189 
01190 void OptionsDialog::addAudioControls(GuiObject *boss, const Common::String &prefix) {
01191     return; //ResidualVM: do not enable midi
01192     // The MIDI mode popup & a label
01193     if (g_system->getOverlayWidth() > 320)
01194         _midiPopUpDesc = new StaticTextWidget(boss, prefix + "auMidiPopupDesc", _domain == Common::ConfigManager::kApplicationDomain ? _("Preferred device:") : _("Music device:"), _domain == Common::ConfigManager::kApplicationDomain ? _("Specifies preferred sound device or sound card emulator") : _("Specifies output sound device or sound card emulator"));
01195     else
01196         _midiPopUpDesc = new StaticTextWidget(boss, prefix + "auMidiPopupDesc", _domain == Common::ConfigManager::kApplicationDomain ? _c("Preferred dev.:", "lowres") : _c("Music device:", "lowres"), _domain == Common::ConfigManager::kApplicationDomain ? _("Specifies preferred sound device or sound card emulator") : _("Specifies output sound device or sound card emulator"));
01197     _midiPopUp = new PopUpWidget(boss, prefix + "auMidiPopup", _("Specifies output sound device or sound card emulator"));
01198 
01199     // Populate it
01200     const Common::String allFlags = MidiDriver::musicType2GUIO((uint32)-1);
01201     bool hasMidiDefined = (strpbrk(_guioptions.c_str(), allFlags.c_str()) != NULL);
01202 
01203     const PluginList p = MusicMan.getPlugins();
01204     for (PluginList::const_iterator m = p.begin(); m != p.end(); ++m) {
01205         MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
01206         for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
01207             Common::String deviceGuiOption = MidiDriver::musicType2GUIO(d->getMusicType());
01208 
01209             if ((_domain == Common::ConfigManager::kApplicationDomain && d->getMusicType() != MT_TOWNS  // global dialog - skip useless FM-Towns, C64, Amiga, AppleIIGS options there
01210                  && d->getMusicType() != MT_C64 && d->getMusicType() != MT_AMIGA && d->getMusicType() != MT_APPLEIIGS && d->getMusicType() != MT_PC98)
01211                 || (_domain != Common::ConfigManager::kApplicationDomain && !hasMidiDefined) // No flags are specified
01212                 || (_guioptions.contains(deviceGuiOption)) // flag is present
01213                 // HACK/FIXME: For now we have to show GM devices, even when the game only has GUIO_MIDIMT32 set,
01214                 // else we would not show for example external devices connected via ALSA, since they are always
01215                 // marked as General MIDI device.
01216                 || (deviceGuiOption.contains(GUIO_MIDIGM) && (_guioptions.contains(GUIO_MIDIMT32)))
01217                 || d->getMusicDriverId() == "auto" || d->getMusicDriverId() == "null") // always add default and null device
01218                 _midiPopUp->appendEntry(d->getCompleteName(), d->getHandle());
01219         }
01220     }
01221 
01222 #if 0 // ResidualVM specific
01223     // The OPL emulator popup & a label
01224     _oplPopUpDesc = new StaticTextWidget(boss, prefix + "auOPLPopupDesc", _("AdLib emulator:"), _("AdLib is used for music in many games"));
01225     _oplPopUp = new PopUpWidget(boss, prefix + "auOPLPopup", _("AdLib is used for music in many games"));
01226 
01227     // Populate it
01228     const OPL::Config::EmulatorDescription *ed = OPL::Config::getAvailable();
01229     while (ed->name) {
01230         _oplPopUp->appendEntry(_(ed->description), ed->id);
01231         ++ed;
01232     }
01233 #endif
01234 
01235     _enableAudioSettings = true;
01236 }
01237 
01238 void OptionsDialog::addMIDIControls(GuiObject *boss, const Common::String &prefix) {
01239     return; //ResidualVM: do not enable midi
01240     _gmDevicePopUpDesc = new StaticTextWidget(boss, prefix + "auPrefGmPopupDesc", _("GM device:"), _("Specifies default sound device for General MIDI output"));
01241     _gmDevicePopUp = new PopUpWidget(boss, prefix + "auPrefGmPopup");
01242 
01243     // Populate
01244     const PluginList p = MusicMan.getPlugins();
01245     // Make sure the null device is the first one in the list to avoid undesired
01246     // auto detection for users who don't have a saved setting yet.
01247     for (PluginList::const_iterator m = p.begin(); m != p.end(); ++m) {
01248         MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
01249         for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
01250             if (d->getMusicDriverId() == "null")
01251                 _gmDevicePopUp->appendEntry(_("Don't use General MIDI music"), d->getHandle());
01252         }
01253     }
01254     // Now we add the other devices.
01255     for (PluginList::const_iterator m = p.begin(); m != p.end(); ++m) {
01256         MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
01257         for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
01258             if (d->getMusicType() >= MT_GM) {
01259                 if (d->getMusicType() != MT_MT32)
01260                     _gmDevicePopUp->appendEntry(d->getCompleteName(), d->getHandle());
01261             } else if (d->getMusicDriverId() == "auto") {
01262                 _gmDevicePopUp->appendEntry(_("Use first available device"), d->getHandle());
01263             }
01264         }
01265     }
01266 
01267     if (!_domain.equals(Common::ConfigManager::kApplicationDomain)) {
01268         _gmDevicePopUpDesc->setEnabled(false);
01269         _gmDevicePopUp->setEnabled(false);
01270     }
01271 
01272     // SoundFont
01273     if (g_system->getOverlayWidth() > 320)
01274         _soundFontButton = new ButtonWidget(boss, prefix + "mcFontButton", _("SoundFont:"), _("SoundFont is supported by some audio cards, FluidSynth and Timidity"), kChooseSoundFontCmd);
01275     else
01276         _soundFontButton = new ButtonWidget(boss, prefix + "mcFontButton", _c("SoundFont:", "lowres"), _("SoundFont is supported by some audio cards, FluidSynth and Timidity"), kChooseSoundFontCmd);
01277     _soundFont = new StaticTextWidget(boss, prefix + "mcFontPath", _c("None", "soundfont"), _("SoundFont is supported by some audio cards, FluidSynth and Timidity"));
01278 
01279     _soundFontClearButton = addClearButton(boss, prefix + "mcFontClearButton", kClearSoundFontCmd);
01280 
01281     // Multi midi setting
01282     _multiMidiCheckbox = new CheckboxWidget(boss, prefix + "mcMixedCheckbox", _("Mixed AdLib/MIDI mode"), _("Use both MIDI and AdLib sound generation"));
01283 
01284     // MIDI gain setting (FluidSynth uses this)
01285     _midiGainDesc = new StaticTextWidget(boss, prefix + "mcMidiGainText", _("MIDI gain:"));
01286     _midiGainSlider = new SliderWidget(boss, prefix + "mcMidiGainSlider", 0, kMidiGainChanged);
01287     _midiGainSlider->setMinValue(0);
01288     _midiGainSlider->setMaxValue(1000);
01289     _midiGainLabel = new StaticTextWidget(boss, prefix + "mcMidiGainLabel", "1.00");
01290 
01291     _enableMIDISettings = true;
01292 }
01293 
01294 void OptionsDialog::addMT32Controls(GuiObject *boss, const Common::String &prefix) {
01295     return; //ResidualVM: do not enable midi
01296     _mt32DevicePopUpDesc = new StaticTextWidget(boss, prefix + "auPrefMt32PopupDesc", _("MT-32 Device:"), _("Specifies default sound device for Roland MT-32/LAPC1/CM32l/CM64 output"));
01297     _mt32DevicePopUp = new PopUpWidget(boss, prefix + "auPrefMt32Popup");
01298 
01299     // Native mt32 setting
01300     if (g_system->getOverlayWidth() > 320)
01301         _mt32Checkbox = new CheckboxWidget(boss, prefix + "mcMt32Checkbox", _("True Roland MT-32 (disable GM emulation)"), _("Check if you want to use your real hardware Roland-compatible sound device connected to your computer"));
01302     else
01303         _mt32Checkbox = new CheckboxWidget(boss, prefix + "mcMt32Checkbox", _c("True Roland MT-32 (no GM emulation)", "lowres"), _("Check if you want to use your real hardware Roland-compatible sound device connected to your computer"));
01304 
01305     // GS Extensions setting
01306     _enableGSCheckbox = new CheckboxWidget(boss, prefix + "mcGSCheckbox", _("Roland GS device (enable MT-32 mappings)"), _("Check if you want to enable patch mappings to emulate an MT-32 on a Roland GS device"));
01307 
01308     const PluginList p = MusicMan.getPlugins();
01309     // Make sure the null device is the first one in the list to avoid undesired
01310     // auto detection for users who don't have a saved setting yet.
01311     for (PluginList::const_iterator m = p.begin(); m != p.end(); ++m) {
01312         MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
01313         for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
01314             if (d->getMusicDriverId() == "null")
01315                 _mt32DevicePopUp->appendEntry(_("Don't use Roland MT-32 music"), d->getHandle());
01316         }
01317     }
01318     // Now we add the other devices.
01319     for (PluginList::const_iterator m = p.begin(); m != p.end(); ++m) {
01320         MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
01321         for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
01322             if (d->getMusicType() >= MT_GM)
01323                 _mt32DevicePopUp->appendEntry(d->getCompleteName(), d->getHandle());
01324             else if (d->getMusicDriverId() == "auto")
01325                 _mt32DevicePopUp->appendEntry(_("Use first available device"), d->getHandle());
01326         }
01327     }
01328 
01329     if (!_domain.equals(Common::ConfigManager::kApplicationDomain)) {
01330         _mt32DevicePopUpDesc->setEnabled(false);
01331         _mt32DevicePopUp->setEnabled(false);
01332     }
01333 
01334     _enableMT32Settings = true;
01335 }
01336 
01337 // The function has an extra slider range parameter, since both the launcher and SCUMM engine
01338 // make use of the widgets. The launcher range is 0-255. SCUMM's 0-9
01339 void OptionsDialog::addSubtitleControls(GuiObject *boss, const Common::String &prefix, int maxSliderVal) {
01340 
01341     if (g_system->getOverlayWidth() > 320) {
01342         _subToggleDesc = new StaticTextWidget(boss, prefix + "subToggleDesc", _("Text and speech:"));
01343 
01344         _subToggleGroup = new RadiobuttonGroup(boss, kSubtitleToggle);
01345 
01346         _subToggleSpeechOnly = new RadiobuttonWidget(boss, prefix + "subToggleSpeechOnly", _subToggleGroup, kSubtitlesSpeech, _("Speech"));
01347         _subToggleSubOnly = new RadiobuttonWidget(boss, prefix + "subToggleSubOnly", _subToggleGroup, kSubtitlesSubs, _("Subtitles"));
01348         _subToggleSubBoth = new RadiobuttonWidget(boss, prefix + "subToggleSubBoth", _subToggleGroup, kSubtitlesBoth, _("Both"));
01349 
01350         _subSpeedDesc = new StaticTextWidget(boss, prefix + "subSubtitleSpeedDesc", _("Subtitle speed:"));
01351     } else {
01352         _subToggleDesc = new StaticTextWidget(boss, prefix + "subToggleDesc", _c("Text and speech:", "lowres"));
01353 
01354         _subToggleGroup = new RadiobuttonGroup(boss, kSubtitleToggle);
01355 
01356         _subToggleSpeechOnly = new RadiobuttonWidget(boss, prefix + "subToggleSpeechOnly", _subToggleGroup, kSubtitlesSpeech, _("Spch"), _("Speech"));
01357         _subToggleSubOnly = new RadiobuttonWidget(boss, prefix + "subToggleSubOnly", _subToggleGroup, kSubtitlesSubs, _("Subs"), _("Subtitles"));
01358         _subToggleSubBoth = new RadiobuttonWidget(boss, prefix + "subToggleSubBoth", _subToggleGroup, kSubtitlesBoth, _c("Both", "lowres"), _("Show subtitles and play speech"));
01359 
01360         _subSpeedDesc = new StaticTextWidget(boss, prefix + "subSubtitleSpeedDesc", _c("Subtitle speed:", "lowres"));
01361     }
01362 
01363     // Subtitle speed
01364     _subSpeedSlider = new SliderWidget(boss, prefix + "subSubtitleSpeedSlider", 0, kSubtitleSpeedChanged);
01365     _subSpeedLabel = new StaticTextWidget(boss, prefix + "subSubtitleSpeedLabel", "100%");
01366     _subSpeedSlider->setMinValue(0); _subSpeedSlider->setMaxValue(maxSliderVal);
01367     _subSpeedLabel->setFlags(WIDGET_CLEARBG);
01368 
01369     _enableSubtitleSettings = true;
01370 }
01371 
01372 void OptionsDialog::addVolumeControls(GuiObject *boss, const Common::String &prefix) {
01373 
01374     // Volume controllers
01375     if (g_system->getOverlayWidth() > 320)
01376         _musicVolumeDesc = new StaticTextWidget(boss, prefix + "vcMusicText", _("Music volume:"));
01377     else
01378         _musicVolumeDesc = new StaticTextWidget(boss, prefix + "vcMusicText", _c("Music volume:", "lowres"));
01379     _musicVolumeSlider = new SliderWidget(boss, prefix + "vcMusicSlider", 0, kMusicVolumeChanged);
01380     _musicVolumeLabel = new StaticTextWidget(boss, prefix + "vcMusicLabel", "100%");
01381     _musicVolumeSlider->setMinValue(0);
01382     _musicVolumeSlider->setMaxValue(Audio::Mixer::kMaxMixerVolume);
01383     _musicVolumeLabel->setFlags(WIDGET_CLEARBG);
01384 
01385     _muteCheckbox = new CheckboxWidget(boss, prefix + "vcMuteCheckbox", _("Mute all"), 0, kMuteAllChanged);
01386 
01387     if (g_system->getOverlayWidth() > 320)
01388         _sfxVolumeDesc = new StaticTextWidget(boss, prefix + "vcSfxText", _("SFX volume:"), _("Special sound effects volume"));
01389     else
01390         _sfxVolumeDesc = new StaticTextWidget(boss, prefix + "vcSfxText", _c("SFX volume:", "lowres"), _("Special sound effects volume"));
01391     _sfxVolumeSlider = new SliderWidget(boss, prefix + "vcSfxSlider", _("Special sound effects volume"), kSfxVolumeChanged);
01392     _sfxVolumeLabel = new StaticTextWidget(boss, prefix + "vcSfxLabel", "100%");
01393     _sfxVolumeSlider->setMinValue(0);
01394     _sfxVolumeSlider->setMaxValue(Audio::Mixer::kMaxMixerVolume);
01395     _sfxVolumeLabel->setFlags(WIDGET_CLEARBG);
01396 
01397     if (g_system->getOverlayWidth() > 320)
01398         _speechVolumeDesc = new StaticTextWidget(boss, prefix + "vcSpeechText" , _("Speech volume:"));
01399     else
01400         _speechVolumeDesc = new StaticTextWidget(boss, prefix + "vcSpeechText" , _c("Speech volume:", "lowres"));
01401     _speechVolumeSlider = new SliderWidget(boss, prefix + "vcSpeechSlider", 0, kSpeechVolumeChanged);
01402     _speechVolumeLabel = new StaticTextWidget(boss, prefix + "vcSpeechLabel", "100%");
01403     _speechVolumeSlider->setMinValue(0);
01404     _speechVolumeSlider->setMaxValue(Audio::Mixer::kMaxMixerVolume);
01405     _speechVolumeLabel->setFlags(WIDGET_CLEARBG);
01406 
01407     _enableVolumeSettings = true;
01408 }
01409 
01410 void OptionsDialog::addEngineControls(GuiObject *boss, const Common::String &prefix, const ExtraGuiOptions &engineOptions) {
01411     // Note: up to 7 engine options can currently fit on screen (the most that
01412     // can fit in a 320x200 screen with the classic theme).
01413     // TODO: Increase this number by including the checkboxes inside a scroll
01414     // widget. The appropriate number of checkboxes will need to be added to
01415     // the theme files.
01416 
01417     uint i = 1;
01418     ExtraGuiOptions::const_iterator iter;
01419     for (iter = engineOptions.begin(); iter != engineOptions.end(); ++iter, ++i) {
01420         Common::String id = Common::String::format("%d", i);
01421         _engineCheckboxes.push_back(new CheckboxWidget(boss,
01422             prefix + "customOption" + id + "Checkbox", _(iter->label), _(iter->tooltip)));
01423     }
01424 }
01425 
01426 bool OptionsDialog::loadMusicDeviceSetting(PopUpWidget *popup, Common::String setting, MusicType preferredType) {
01427     if (!popup || !popup->isEnabled())
01428         return true;
01429 
01430     if (_domain != Common::ConfigManager::kApplicationDomain || ConfMan.hasKey(setting, _domain) || preferredType) {
01431         const Common::String drv = ConfMan.get(setting, (_domain != Common::ConfigManager::kApplicationDomain && !ConfMan.hasKey(setting, _domain)) ? Common::ConfigManager::kApplicationDomain : _domain);
01432         const PluginList p = MusicMan.getPlugins();
01433 
01434         for (PluginList::const_iterator m = p.begin(); m != p.end(); ++m) {
01435             MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
01436             for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
01437                 if (setting.empty() ? (preferredType == d->getMusicType()) : (drv == d->getCompleteId())) {
01438                     popup->setSelectedTag(d->getHandle());
01439                     return popup->getSelected() != -1;
01440                 }
01441             }
01442         }
01443     }
01444 
01445     return false;
01446 }
01447 
01448 void OptionsDialog::saveMusicDeviceSetting(PopUpWidget *popup, Common::String setting) {
01449     if (!popup || !_enableAudioSettings)
01450         return;
01451 
01452     const PluginList p = MusicMan.getPlugins();
01453     bool found = false;
01454     for (PluginList::const_iterator m = p.begin(); m != p.end() && !found; ++m) {
01455         MusicDevices i = (*m)->get<MusicPluginObject>().getDevices();
01456         for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
01457             if (d->getHandle() == popup->getSelectedTag()) {
01458                 ConfMan.set(setting, d->getCompleteId(), _domain);
01459                 found = true;
01460                 break;
01461             }
01462         }
01463     }
01464 
01465     if (!found)
01466         ConfMan.removeKey(setting, _domain);
01467 }
01468 
01469 int OptionsDialog::getSubtitleMode(bool subtitles, bool speech_mute) {
01470     if (_guioptions.contains(GUIO_NOSUBTITLES))
01471         return kSubtitlesSpeech; // Speech only
01472     if (_guioptions.contains(GUIO_NOSPEECH))
01473         return kSubtitlesSubs; // Subtitles only
01474 
01475     if (!subtitles && !speech_mute) // Speech only
01476         return kSubtitlesSpeech;
01477     else if (subtitles && !speech_mute) // Speech and subtitles
01478         return kSubtitlesBoth;
01479     else if (subtitles && speech_mute) // Subtitles only
01480         return kSubtitlesSubs;
01481     else
01482         warning("Wrong configuration: Both subtitles and speech are off. Assuming subtitles only");
01483     return kSubtitlesSubs;
01484 }
01485 
01486 void OptionsDialog::updateMusicVolume(const int newValue) const {
01487     _musicVolumeLabel->setValue(newValue);
01488     _musicVolumeSlider->setValue(newValue);
01489     _musicVolumeLabel->markAsDirty();
01490     _musicVolumeSlider->markAsDirty();
01491 }
01492 
01493 void OptionsDialog::updateSfxVolume(const int newValue) const {
01494     _sfxVolumeLabel->setValue(newValue);
01495     _sfxVolumeSlider->setValue(newValue);
01496     _sfxVolumeLabel->markAsDirty();
01497     _sfxVolumeSlider->markAsDirty();
01498 }
01499 
01500 void OptionsDialog::updateSpeechVolume(const int newValue) const {
01501     _speechVolumeLabel->setValue(newValue);
01502     _speechVolumeSlider->setValue(newValue);
01503     _speechVolumeLabel->markAsDirty();
01504     _speechVolumeSlider->markAsDirty();
01505 }
01506 
01507 void OptionsDialog::reflowLayout() {
01508     if (_graphicsTabId != -1 && _tabWidget)
01509         _tabWidget->setTabTitle(_graphicsTabId, g_system->getOverlayWidth() > 320 ? _("Graphics") : _("GFX"));
01510 
01511     Dialog::reflowLayout();
01512     setupGraphicsTab();
01513 }
01514 
01515 void OptionsDialog::setupGraphicsTab() {
01516     if (!_fullscreenCheckbox)
01517         return;
01518 
01519 // ResidualVM: Commented out unused widgets
01520 // What is this function even doing?
01521 
01522 //  _gfxPopUpDesc->setVisible(true);
01523 //  _gfxPopUp->setVisible(true);
01524 //  if (g_system->hasFeature(OSystem::kFeatureStretchMode)) {
01525 //      _stretchPopUpDesc->setVisible(true);
01526 //      _stretchPopUp->setVisible(true);
01527 //  } else {
01528 //      _stretchPopUpDesc->setVisible(false);
01529 //      _stretchPopUp->setVisible(false);
01530 //  }
01531     _fullscreenCheckbox->setVisible(true);
01532 //  if (g_system->hasFeature(OSystem::kFeatureFilteringMode))
01533 //      _filteringCheckbox->setVisible(true);
01534 //  else
01535 //      _filteringCheckbox->setVisible(false);
01536     _aspectCheckbox->setVisible(true);
01537 //  _renderModePopUpDesc->setVisible(true);
01538 //  _renderModePopUp->setVisible(true);
01539 }
01540 
01541 #pragma mark -
01542 
01543 
01544 GlobalOptionsDialog::GlobalOptionsDialog(LauncherDialog *launcher)
01545     : OptionsDialog(Common::ConfigManager::kApplicationDomain, "GlobalOptions"), _launcher(launcher) {
01546 #ifdef GUI_ENABLE_KEYSDIALOG
01547     _keysDialog = 0;
01548 #endif
01549 #ifdef USE_FLUIDSYNTH
01550     _fluidSynthSettingsDialog = 0;
01551 #endif
01552     _savePath = 0;
01553     _savePathClearButton = 0;
01554     _themePath = 0;
01555     _themePathClearButton = 0;
01556     _extraPath = 0;
01557     _extraPathClearButton = 0;
01558 #ifdef DYNAMIC_MODULES
01559     _pluginsPath = 0;
01560 #endif
01561     _curTheme = 0;
01562     _rendererPopUpDesc = 0;
01563     _rendererPopUp = 0;
01564     _autosavePeriodPopUpDesc = 0;
01565     _autosavePeriodPopUp = 0;
01566     _guiLanguagePopUpDesc = 0;
01567     _guiLanguagePopUp = 0;
01568     _guiLanguageUseGameLanguageCheckbox = nullptr;
01569     _useSystemDialogsCheckbox = 0;
01570 #ifdef USE_UPDATES
01571     _updatesPopUpDesc = 0;
01572     _updatesPopUp = 0;
01573 #endif
01574 #ifdef USE_CLOUD
01575 #ifdef USE_LIBCURL
01576     _selectedStorageIndex = CloudMan.getStorageIndex();
01577 #else
01578     _selectedStorageIndex = 0;
01579 #endif
01580     _storagePopUpDesc = 0;
01581     _storagePopUp = 0;
01582     _storageUsernameDesc = 0;
01583     _storageUsername = 0;
01584     _storageUsedSpaceDesc = 0;
01585     _storageUsedSpace = 0;
01586     _storageLastSyncDesc = 0;
01587     _storageLastSync = 0;
01588     _storageConnectButton = 0;
01589     _storageRefreshButton = 0;
01590     _storageDownloadButton = 0;
01591     _runServerButton = 0;
01592     _serverInfoLabel = 0;
01593     _rootPathButton = 0;
01594     _rootPath = 0;
01595     _rootPathClearButton = 0;
01596     _serverPortDesc = 0;
01597     _serverPort = 0;
01598     _serverPortClearButton = 0;
01599     _redrawCloudTab = false;
01600 #ifdef USE_SDL_NET
01601     _serverWasRunning = false;
01602 #endif
01603 #endif
01604 }
01605 
01606 GlobalOptionsDialog::~GlobalOptionsDialog() {
01607 #ifdef GUI_ENABLE_KEYSDIALOG
01608     delete _keysDialog;
01609 #endif
01610 
01611 #ifdef USE_FLUIDSYNTH
01612     delete _fluidSynthSettingsDialog;
01613 #endif
01614 }
01615 
01616 void GlobalOptionsDialog::build() {
01617     // The tab widget
01618     TabWidget *tab = new TabWidget(this, "GlobalOptions.TabWidget");
01619 
01620     //
01621     // 1) The graphics tab
01622     //
01623     _graphicsTabId = tab->addTab(g_system->getOverlayWidth() > 320 ? _("Graphics") : _("GFX"));
01624     ScrollContainerWidget *graphicsContainer = new ScrollContainerWidget(tab, "GlobalOptions_Graphics.Container", kGraphicsTabContainerReflowCmd);
01625     graphicsContainer->setTarget(this);
01626     graphicsContainer->setBackgroundType(ThemeEngine::kDialogBackgroundNone);
01627     addGraphicControls(graphicsContainer, "GlobalOptions_Graphics_Container.");
01628 
01629     //
01630     // The shader tab (currently visible only for Vita platform), visibility checking by features
01631     //
01632 
01633     if (g_system->hasFeature(OSystem::kFeatureShader)) {
01634         tab->addTab(_("Shader"));
01635         addShaderControls(tab, "GlobalOptions_Shader.");
01636     }
01637 
01638     //
01639     // The control tab (currently visible only for AndroidSDL, SDL, and Vita platform, visibility checking by features
01640     //
01641     if (g_system->hasFeature(OSystem::kFeatureTouchpadMode) ||
01642         g_system->hasFeature(OSystem::kFeatureOnScreenControl) ||
01643         g_system->hasFeature(OSystem::kFeatureSwapMenuAndBackButtons) ||
01644         g_system->hasFeature(OSystem::kFeatureKbdMouseSpeed) ||
01645         g_system->hasFeature(OSystem::kFeatureJoystickDeadzone)) {
01646         tab->addTab(_("Control"));
01647         addControlControls(tab, "GlobalOptions_Control.");
01648     }
01649 
01650     //
01651     // 2) The audio tab
01652     //
01653     tab->addTab(_("Audio"));
01654     addAudioControls(tab, "GlobalOptions_Audio.");
01655     addSubtitleControls(tab, "GlobalOptions_Audio.");
01656 
01657     if (g_system->getOverlayWidth() > 320)
01658         tab->addTab(_("Volume"));
01659     else
01660         tab->addTab(_c("Volume", "lowres"));
01661     addVolumeControls(tab, "GlobalOptions_Volume.");
01662 
01663     // TODO: cd drive setting
01664 
01665 #if 0 // ResidualVM does not use it
01666     //
01667     // 3) The MIDI tab
01668     //
01669     _midiTabId = tab->addTab(_("MIDI"));
01670     addMIDIControls(tab, "GlobalOptions_MIDI.");
01671 
01672 #ifdef USE_FLUIDSYNTH
01673     new ButtonWidget(tab, "GlobalOptions_MIDI.mcFluidSynthSettings", _("FluidSynth Settings"), 0, kFluidSynthSettingsCmd);
01674 #endif
01675 
01676     //
01677     // 4) The MT-32 tab
01678     //
01679     tab->addTab(_("MT-32"));
01680     addMT32Controls(tab, "GlobalOptions_MT32.");
01681 #endif
01682 
01683     //
01684     // 5) The Paths tab
01685     //
01686     if (g_system->getOverlayWidth() > 320)
01687         _pathsTabId = tab->addTab(_("Paths"));
01688     else
01689         _pathsTabId = tab->addTab(_c("Paths", "lowres"));
01690 
01691 #if !defined(__DC__)
01692     // These two buttons have to be extra wide, or the text will be
01693     // truncated in the small version of the GUI.
01694 
01695     // Save game path
01696     if (g_system->getOverlayWidth() > 320)
01697         new ButtonWidget(tab, "GlobalOptions_Paths.SaveButton", _("Save Path:"), _("Specifies where your saved games are put"), kChooseSaveDirCmd);
01698     else
01699         new ButtonWidget(tab, "GlobalOptions_Paths.SaveButton", _c("Save Path:", "lowres"), _("Specifies where your saved games are put"), kChooseSaveDirCmd);
01700     _savePath = new StaticTextWidget(tab, "GlobalOptions_Paths.SavePath", "/foo/bar", _("Specifies where your saved games are put"));
01701 
01702     _savePathClearButton = addClearButton(tab, "GlobalOptions_Paths.SavePathClearButton", kSavePathClearCmd);
01703 
01704     if (g_system->getOverlayWidth() > 320)
01705         new ButtonWidget(tab, "GlobalOptions_Paths.ThemeButton", _("Theme Path:"), 0, kChooseThemeDirCmd);
01706     else
01707         new ButtonWidget(tab, "GlobalOptions_Paths.ThemeButton", _c("Theme Path:", "lowres"), 0, kChooseThemeDirCmd);
01708     _themePath = new StaticTextWidget(tab, "GlobalOptions_Paths.ThemePath", _c("None", "path"));
01709 
01710     _themePathClearButton = addClearButton(tab, "GlobalOptions_Paths.ThemePathClearButton", kThemePathClearCmd);
01711 
01712     if (g_system->getOverlayWidth() > 320)
01713         new ButtonWidget(tab, "GlobalOptions_Paths.ExtraButton", _("Extra Path:"), _("Specifies path to additional data used by all games or ScummVM"), kChooseExtraDirCmd);
01714     else
01715         new ButtonWidget(tab, "GlobalOptions_Paths.ExtraButton", _c("Extra Path:", "lowres"), _("Specifies path to additional data used by all games or ScummVM"), kChooseExtraDirCmd);
01716     _extraPath = new StaticTextWidget(tab, "GlobalOptions_Paths.ExtraPath", _c("None", "path"), _("Specifies path to additional data used by all games or ScummVM"));
01717 
01718     _extraPathClearButton = addClearButton(tab, "GlobalOptions_Paths.ExtraPathClearButton", kExtraPathClearCmd);
01719 
01720 #ifdef DYNAMIC_MODULES
01721     if (g_system->getOverlayWidth() > 320)
01722         new ButtonWidget(tab, "GlobalOptions_Paths.PluginsButton", _("Plugins Path:"), 0, kChoosePluginsDirCmd);
01723     else
01724         new ButtonWidget(tab, "GlobalOptions_Paths.PluginsButton", _c("Plugins Path:", "lowres"), 0, kChoosePluginsDirCmd);
01725     _pluginsPath = new StaticTextWidget(tab, "GlobalOptions_Paths.PluginsPath", _c("None", "path"));
01726 #endif
01727 #endif
01728 
01729     //
01730     // 6) The miscellaneous tab
01731     //
01732     if (g_system->getOverlayWidth() > 320)
01733         tab->addTab(_("Misc"));
01734     else
01735         tab->addTab(_c("Misc", "lowres"));
01736 
01737     new ButtonWidget(tab, "GlobalOptions_Misc.ThemeButton", _("Theme:"), 0, kChooseThemeCmd);
01738     _curTheme = new StaticTextWidget(tab, "GlobalOptions_Misc.CurTheme", g_gui.theme()->getThemeName());
01739 
01740 
01741     _rendererPopUpDesc = new StaticTextWidget(tab, "GlobalOptions_Misc.RendererPopupDesc", _("GUI renderer:"));
01742     _rendererPopUp = new PopUpWidget(tab, "GlobalOptions_Misc.RendererPopup");
01743 
01744     if (g_system->getOverlayWidth() > 320) {
01745         for (uint i = 1; i < GUI::ThemeEngine::_rendererModesSize; ++i)
01746             _rendererPopUp->appendEntry(_(GUI::ThemeEngine::_rendererModes[i].name), GUI::ThemeEngine::_rendererModes[i].mode);
01747     } else {
01748         for (uint i = 1; i < GUI::ThemeEngine::_rendererModesSize; ++i)
01749             _rendererPopUp->appendEntry(_(GUI::ThemeEngine::_rendererModes[i].shortname), GUI::ThemeEngine::_rendererModes[i].mode);
01750     }
01751 
01752     if (g_system->getOverlayWidth() > 320)
01753         _autosavePeriodPopUpDesc = new StaticTextWidget(tab, "GlobalOptions_Misc.AutosavePeriodPopupDesc", _("Autosave:"));
01754     else
01755         _autosavePeriodPopUpDesc = new StaticTextWidget(tab, "GlobalOptions_Misc.AutosavePeriodPopupDesc", _c("Autosave:", "lowres"));
01756     _autosavePeriodPopUp = new PopUpWidget(tab, "GlobalOptions_Misc.AutosavePeriodPopup");
01757 
01758     for (int i = 0; savePeriodLabels[i]; i++) {
01759         _autosavePeriodPopUp->appendEntry(_(savePeriodLabels[i]), savePeriodValues[i]);
01760     }
01761 
01762 #ifdef GUI_ENABLE_KEYSDIALOG
01763     new ButtonWidget(tab, "GlobalOptions_Misc.KeysButton", _("Keys"), 0, kChooseKeyMappingCmd);
01764 #endif
01765 
01766     // TODO: joystick setting
01767 
01768 
01769 #ifdef USE_TRANSLATION
01770     _guiLanguagePopUpDesc = new StaticTextWidget(tab, "GlobalOptions_Misc.GuiLanguagePopupDesc", _("GUI language:"), _("Language of ResidualVM GUI"));
01771     _guiLanguagePopUp = new PopUpWidget(tab, "GlobalOptions_Misc.GuiLanguagePopup");
01772 #ifdef USE_DETECTLANG
01773     _guiLanguagePopUp->appendEntry(_("<default>"), Common::kTranslationAutodetectId);
01774 #endif // USE_DETECTLANG
01775     _guiLanguagePopUp->appendEntry("English", Common::kTranslationBuiltinId);
01776     _guiLanguagePopUp->appendEntry("", 0);
01777     Common::TLangArray languages = TransMan.getSupportedLanguageNames();
01778     Common::TLangArray::iterator lang = languages.begin();
01779     while (lang != languages.end()) {
01780         _guiLanguagePopUp->appendEntry(lang->name, lang->id);
01781         lang++;
01782     }
01783 
01784     // Select the currently configured language or default/English if
01785     // nothing is specified.
01786     if (ConfMan.hasKey("gui_language") && !ConfMan.get("gui_language").empty())
01787         _guiLanguagePopUp->setSelectedTag(TransMan.parseLanguage(ConfMan.get("gui_language")));
01788     else
01789 #ifdef USE_DETECTLANG
01790         _guiLanguagePopUp->setSelectedTag(Common::kTranslationAutodetectId);
01791 #else // !USE_DETECTLANG
01792         _guiLanguagePopUp->setSelectedTag(Common::kTranslationBuiltinId);
01793 #endif // USE_DETECTLANG
01794 
01795     _guiLanguageUseGameLanguageCheckbox = new CheckboxWidget(tab, "GlobalOptions_Misc.GuiLanguageUseGameLanguage",
01796             _("Switch the GUI language to the game language"),
01797             _("When starting a game, change the GUI language to the game language."
01798             "That way, if a game uses the ResidualVM save and load dialogs, they are "
01799             "in the same language as the game.")
01800     );
01801 
01802     if (ConfMan.hasKey("gui_use_game_language")) {
01803         _guiLanguageUseGameLanguageCheckbox->setState(ConfMan.getBool("gui_use_game_language", _domain));
01804     }
01805 
01806 #endif // USE_TRANSLATION
01807 
01808     if (g_system->hasFeature(OSystem::kFeatureSystemBrowserDialog)) {
01809         _useSystemDialogsCheckbox = new CheckboxWidget(tab, "GlobalOptions_Misc.UseSystemDialogs",
01810             _("Use native system file browser"),
01811             _("Use the native system file browser instead of the ResidualVM one to select a file or directory.")
01812         );
01813 
01814         _useSystemDialogsCheckbox->setState(ConfMan.getBool("gui_browser_native", _domain));
01815     }
01816 
01817 #ifdef USE_UPDATES
01818     _updatesPopUpDesc = new StaticTextWidget(tab, "GlobalOptions_Misc.UpdatesPopupDesc", _("Update check:"), _("How often to check ResidualVM updates"));
01819     _updatesPopUp = new PopUpWidget(tab, "GlobalOptions_Misc.UpdatesPopup");
01820 
01821     const int *vals = Common::UpdateManager::getUpdateIntervals();
01822 
01823     while (*vals != -1) {
01824         _updatesPopUp->appendEntry(Common::UpdateManager::updateIntervalToString(*vals), *vals);
01825         vals++;
01826     }
01827 
01828     _updatesPopUp->setSelectedTag(Common::UpdateManager::normalizeInterval(ConfMan.getInt("updates_check")));
01829 
01830     new ButtonWidget(tab, "GlobalOptions_Misc.UpdatesCheckManuallyButton", _("Check now"), 0, kUpdatesCheckCmd);
01831 #endif
01832 
01833 #ifdef USE_CLOUD
01834     //
01835     // 7) The cloud tab
01836     //
01837     if (g_system->getOverlayWidth() > 320)
01838         tab->addTab(_("Cloud"));
01839     else
01840         tab->addTab(_c("Cloud", "lowres"));
01841 
01842     ScrollContainerWidget *container = new ScrollContainerWidget(tab, "GlobalOptions_Cloud.Container", kCloudTabContainerReflowCmd);
01843     container->setTarget(this);
01844     container->setBackgroundType(ThemeEngine::kDialogBackgroundNone);
01845 
01846     _storagePopUpDesc = new StaticTextWidget(container, "GlobalOptions_Cloud_Container.StoragePopupDesc", _("Storage:"), _("Active cloud storage"));
01847     _storagePopUp = new PopUpWidget(container, "GlobalOptions_Cloud_Container.StoragePopup");
01848 #ifdef USE_LIBCURL
01849     Common::StringArray list = CloudMan.listStorages();
01850     for (uint32 i = 0; i < list.size(); ++i)
01851         _storagePopUp->appendEntry(list[i], i);
01852 #else
01853     _storagePopUp->appendEntry(_("<none>"), 0);
01854 #endif
01855     _storagePopUp->setSelected(_selectedStorageIndex);
01856 
01857     _storageUsernameDesc = new StaticTextWidget(container, "GlobalOptions_Cloud_Container.StorageUsernameDesc", _("Username:"), _("Username used by this storage"));
01858     _storageUsername = new StaticTextWidget(container, "GlobalOptions_Cloud_Container.StorageUsernameLabel", "<none>");
01859 
01860     _storageUsedSpaceDesc = new StaticTextWidget(container, "GlobalOptions_Cloud_Container.StorageUsedSpaceDesc", _("Used space:"), _("Space used by ScummVM's saved games on this storage"));
01861     _storageUsedSpace = new StaticTextWidget(container, "GlobalOptions_Cloud_Container.StorageUsedSpaceLabel", "0 bytes");
01862 
01863     _storageLastSyncDesc = new StaticTextWidget(container, "GlobalOptions_Cloud_Container.StorageLastSyncDesc", _("Last sync time:"), _("When the last saved games sync for this storage occured"));
01864     _storageLastSync = new StaticTextWidget(container, "GlobalOptions_Cloud_Container.StorageLastSyncLabel", "<never>");
01865 
01866     _storageConnectButton = new ButtonWidget(container, "GlobalOptions_Cloud_Container.ConnectButton", _("Connect"), _("Open wizard dialog to connect your cloud storage account"), kConfigureStorageCmd);
01867     _storageRefreshButton = new ButtonWidget(container, "GlobalOptions_Cloud_Container.RefreshButton", _("Refresh"), _("Refresh current cloud storage information (username and usage)"), kRefreshStorageCmd);
01868     _storageDownloadButton = new ButtonWidget(container, "GlobalOptions_Cloud_Container.DownloadButton", _("Download"), _("Open downloads manager dialog"), kDownloadStorageCmd);
01869 
01870     _runServerButton = new ButtonWidget(container, "GlobalOptions_Cloud_Container.RunServerButton", _("Run server"), _("Run local webserver"), kRunServerCmd);
01871     _serverInfoLabel = new StaticTextWidget(container, "GlobalOptions_Cloud_Container.ServerInfoLabel", _("Not running"));
01872 
01873     // Root path
01874     if (g_system->getOverlayWidth() > 320)
01875         _rootPathButton = new ButtonWidget(container, "GlobalOptions_Cloud_Container.RootPathButton", _("/root/ Path:"), _("Specifies which directory the Files Manager can access"), kChooseRootDirCmd);
01876     else
01877         _rootPathButton = new ButtonWidget(container, "GlobalOptions_Cloud_Container.RootPathButton", _c("/root/ Path:", "lowres"), _("Specifies which directory the Files Manager can access"), kChooseRootDirCmd);
01878     _rootPath = new StaticTextWidget(container, "GlobalOptions_Cloud_Container.RootPath", "/foo/bar", _("Specifies which directory the Files Manager can access"));
01879 
01880     _rootPathClearButton = addClearButton(container, "GlobalOptions_Cloud_Container.RootPathClearButton", kRootPathClearCmd);
01881 
01882 #ifdef USE_SDL_NET
01883     uint32 port = Networking::LocalWebserver::getPort();
01884 #else
01885     uint32 port = 0; // the following widgets are hidden anyway
01886 #endif
01887     _serverPortDesc = new StaticTextWidget(container, "GlobalOptions_Cloud_Container.ServerPortDesc", _("Server's port:"), _("Which port is used by the server\nAuth with server is not available with non-default port"));
01888     _serverPort = new EditTextWidget(container, "GlobalOptions_Cloud_Container.ServerPortEditText", Common::String::format("%u", port), 0);
01889     _serverPortClearButton = addClearButton(container, "GlobalOptions_Cloud_Container.ServerPortClearButton", kServerPortClearCmd);
01890 
01891     setupCloudTab();
01892 #endif // USE_CLOUD
01893 
01894     // Activate the first tab
01895     tab->setActiveTab(0);
01896     _tabWidget = tab;
01897 
01898     // Add OK & Cancel buttons
01899     new ButtonWidget(this, "GlobalOptions.Cancel", _("Cancel"), 0, kCloseCmd);
01900     new ButtonWidget(this, "GlobalOptions.Apply", _("Apply"), 0, kApplyCmd);
01901     new ButtonWidget(this, "GlobalOptions.Ok", _("OK"), 0, kOKCmd);
01902 
01903 #ifdef GUI_ENABLE_KEYSDIALOG
01904     _keysDialog = new KeysDialog();
01905 #endif
01906 
01907 #ifdef USE_FLUIDSYNTH
01908     _fluidSynthSettingsDialog = new FluidSynthSettingsDialog();
01909 #endif
01910 
01911     OptionsDialog::build();
01912 
01913 #if !defined(__DC__)
01914     // Set _savePath to the current save path
01915     Common::String savePath(ConfMan.get("savepath", _domain));
01916     Common::String themePath(ConfMan.get("themepath", _domain));
01917     Common::String extraPath(ConfMan.get("extrapath", _domain));
01918 
01919     if (savePath.empty() || !ConfMan.hasKey("savepath", _domain)) {
01920         _savePath->setLabel(_("Default"));
01921     } else {
01922         _savePath->setLabel(savePath);
01923     }
01924 
01925     if (themePath.empty() || !ConfMan.hasKey("themepath", _domain)) {
01926         _themePath->setLabel(_c("None", "path"));
01927     } else {
01928         _themePath->setLabel(themePath);
01929     }
01930 
01931     if (extraPath.empty() || !ConfMan.hasKey("extrapath", _domain)) {
01932         _extraPath->setLabel(_c("None", "path"));
01933     } else {
01934         _extraPath->setLabel(extraPath);
01935     }
01936 
01937 #ifdef DYNAMIC_MODULES
01938     Common::String pluginsPath(ConfMan.get("pluginspath", _domain));
01939     if (pluginsPath.empty() || !ConfMan.hasKey("pluginspath", _domain)) {
01940         _pluginsPath->setLabel(_c("None", "path"));
01941     } else {
01942         _pluginsPath->setLabel(pluginsPath);
01943     }
01944 #endif
01945 #endif
01946 
01947     // Misc Tab
01948     _autosavePeriodPopUp->setSelected(1);
01949     int value = ConfMan.getInt("autosave_period");
01950     for (int i = 0; savePeriodLabels[i]; i++) {
01951         if (value == savePeriodValues[i])
01952             _autosavePeriodPopUp->setSelected(i);
01953     }
01954 
01955     ThemeEngine::GraphicsMode mode = ThemeEngine::findMode(ConfMan.get("gui_renderer"));
01956     if (mode == ThemeEngine::kGfxDisabled)
01957         mode = ThemeEngine::_defaultRendererMode;
01958     _rendererPopUp->setSelectedTag(mode);
01959 
01960 #ifdef USE_CLOUD
01961     Common::String rootPath(ConfMan.get("rootpath", "cloud"));
01962     if (rootPath.empty() || !ConfMan.hasKey("rootpath", "cloud")) {
01963         _rootPath->setLabel(_c("None", "path"));
01964     } else {
01965         _rootPath->setLabel(rootPath);
01966     }
01967 #endif
01968 }
01969 
01970 void GlobalOptionsDialog::clean() {
01971 #ifdef GUI_ENABLE_KEYSDIALOG
01972     delete _keysDialog;
01973     _keysDialog = 0;
01974 #endif
01975 
01976 #ifdef USE_FLUIDSYNTH
01977     delete _fluidSynthSettingsDialog;
01978     _fluidSynthSettingsDialog = 0;
01979 #endif
01980 
01981     OptionsDialog::clean();
01982 }
01983 
01984 void GlobalOptionsDialog::apply() {
01985     OptionsDialog::apply();
01986 
01987     bool isRebuildNeeded = false;
01988 
01989     Common::String savePath(_savePath->getLabel());
01990     if (!savePath.empty() && (savePath != _("Default")))
01991         ConfMan.set("savepath", savePath, _domain);
01992     else
01993         ConfMan.removeKey("savepath", _domain);
01994 
01995     Common::String themePath(_themePath->getLabel());
01996     if (!themePath.empty() && (themePath != _c("None", "path")))
01997         ConfMan.set("themepath", themePath, _domain);
01998     else
01999         ConfMan.removeKey("themepath", _domain);
02000 
02001     Common::String extraPath(_extraPath->getLabel());
02002     if (!extraPath.empty() && (extraPath != _c("None", "path")))
02003         ConfMan.set("extrapath", extraPath, _domain);
02004     else
02005         ConfMan.removeKey("extrapath", _domain);
02006 
02007 #ifdef DYNAMIC_MODULES
02008     Common::String pluginsPath(_pluginsPath->getLabel());
02009     if (!pluginsPath.empty() && (pluginsPath != _c("None", "path")))
02010         ConfMan.set("pluginspath", pluginsPath, _domain);
02011     else
02012         ConfMan.removeKey("pluginspath", _domain);
02013 #endif
02014 
02015 #ifdef USE_CLOUD
02016     Common::String rootPath(_rootPath->getLabel());
02017     if (!rootPath.empty() && (rootPath != _c("None", "path")))
02018         ConfMan.set("rootpath", rootPath, "cloud");
02019     else
02020         ConfMan.removeKey("rootpath", "cloud");
02021 #endif
02022 
02023     ConfMan.setInt("autosave_period", _autosavePeriodPopUp->getSelectedTag(), _domain);
02024 
02025 #ifdef USE_UPDATES
02026     ConfMan.setInt("updates_check", _updatesPopUp->getSelectedTag());
02027 
02028     if (g_system->getUpdateManager()) {
02029         if (_updatesPopUp->getSelectedTag() == Common::UpdateManager::kUpdateIntervalNotSupported) {
02030             g_system->getUpdateManager()->setAutomaticallyChecksForUpdates(Common::UpdateManager::kUpdateStateDisabled);
02031         } else {
02032             g_system->getUpdateManager()->setAutomaticallyChecksForUpdates(Common::UpdateManager::kUpdateStateEnabled);
02033             g_system->getUpdateManager()->setUpdateCheckInterval(_updatesPopUp->getSelectedTag());
02034         }
02035     }
02036 #endif
02037 
02038 #ifdef USE_CLOUD
02039 #ifdef USE_LIBCURL
02040     if (CloudMan.getStorageIndex() != _selectedStorageIndex) {
02041         if (!CloudMan.switchStorage(_selectedStorageIndex)) {
02042             bool anotherStorageIsWorking = CloudMan.isWorking();
02043             Common::String message = _("Failed to change cloud storage!");
02044             if (anotherStorageIsWorking) {
02045                 message += "\n";
02046                 message += _("Another cloud storage is already active.");
02047             }
02048             MessageDialog dialog(message);
02049             dialog.runModal();
02050         }
02051     }
02052 #endif // USE_LIBCURL
02053 
02054 #ifdef USE_SDL_NET
02055 #ifdef NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE
02056     // save server's port
02057     uint32 port = Networking::LocalWebserver::getPort();
02058     if (_serverPort) {
02059         uint64 contents = _serverPort->getEditString().asUint64();
02060         if (contents != 0)
02061             port = contents;
02062     }
02063     ConfMan.setInt("local_server_port", port);
02064 #endif // NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE
02065 #endif // USE_SDL_NET
02066 #endif // USE_CLOUD
02067 
02068     Common::String oldThemeId = g_gui.theme()->getThemeId();
02069     Common::String oldThemeName = g_gui.theme()->getThemeName();
02070     if (!_newTheme.empty()) {
02071         ConfMan.set("gui_theme", _newTheme);
02072     }
02073 
02074 #ifdef USE_TRANSLATION
02075     int selectedLang = _guiLanguagePopUp->getSelectedTag();
02076     Common::String oldLang = ConfMan.get("gui_language");
02077     Common::String newLang = TransMan.getLangById(selectedLang);
02078     Common::String newCharset;
02079     if (newLang != oldLang) {
02080         TransMan.setLanguage(newLang);
02081         ConfMan.set("gui_language", newLang);
02082         newCharset = TransMan.getCurrentCharset();
02083         isRebuildNeeded = true;
02084     }
02085 
02086     bool guiUseGameLanguage = _guiLanguageUseGameLanguageCheckbox->getState();
02087     ConfMan.setBool("gui_use_game_language", guiUseGameLanguage, _domain);
02088 #endif
02089 
02090     if (_useSystemDialogsCheckbox) {
02091         ConfMan.setBool("gui_browser_native", _useSystemDialogsCheckbox->getState(), _domain);
02092     }
02093 
02094     GUI::ThemeEngine::GraphicsMode gfxMode = (GUI::ThemeEngine::GraphicsMode)_rendererPopUp->getSelectedTag();
02095     Common::String oldGfxConfig = ConfMan.get("gui_renderer");
02096     Common::String newGfxConfig = GUI::ThemeEngine::findModeConfigName(gfxMode);
02097     if (newGfxConfig != oldGfxConfig) {
02098         ConfMan.set("gui_renderer", newGfxConfig, _domain);
02099     }
02100 
02101     if (_newTheme.empty())
02102         _newTheme = oldThemeId;
02103 
02104     if (!g_gui.loadNewTheme(_newTheme, gfxMode, true)) {
02105         Common::String errorMessage;
02106 
02107         _curTheme->setLabel(oldThemeName);
02108         _newTheme = oldThemeId;
02109         ConfMan.set("gui_theme", _newTheme);
02110         gfxMode = GUI::ThemeEngine::findMode(oldGfxConfig);
02111         _rendererPopUp->setSelectedTag(gfxMode);
02112         newGfxConfig = oldGfxConfig;
02113         ConfMan.set("gui_renderer", newGfxConfig, _domain);
02114 #ifdef USE_TRANSLATION
02115         bool isCharsetEqual = (newCharset == TransMan.getCurrentCharset());
02116         TransMan.setLanguage(oldLang);
02117         _guiLanguagePopUp->setSelectedTag(selectedLang);
02118         ConfMan.set("gui_language", oldLang);
02119 
02120         if (!isCharsetEqual)
02121             errorMessage = _("Theme does not support selected language!");
02122         else
02123 #endif
02124             errorMessage = _("Theme cannot be loaded!");
02125 
02126         g_gui.loadNewTheme(_newTheme, gfxMode, true);
02127         errorMessage += _("\nMisc settings will be restored.");
02128         MessageDialog error(errorMessage);
02129         error.runModal();
02130     }
02131 
02132     if (isRebuildNeeded) {
02133         rebuild();
02134         if (_launcher != 0)
02135             _launcher->rebuild();
02136     }
02137 
02138     _newTheme.clear();
02139 
02140     // Save config file
02141     ConfMan.flushToDisk();
02142 }
02143 
02144 void GlobalOptionsDialog::close() {
02145 #if defined(USE_CLOUD) && defined(USE_SDL_NET)
02146     if (LocalServer.isRunning()) {
02147         LocalServer.stop();
02148     }
02149 #endif
02150     OptionsDialog::close();
02151 }
02152 
02153 void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
02154     switch (cmd) {
02155     case kChooseSaveDirCmd: {
02156         BrowserDialog browser(_("Select directory for saved games"), true);
02157         if (browser.runModal() > 0) {
02158             // User made his choice...
02159             Common::FSNode dir(browser.getResult());
02160             if (dir.isWritable()) {
02161                 _savePath->setLabel(dir.getPath());
02162             } else {
02163                 MessageDialog error(_("The chosen directory cannot be written to. Please select another one."));
02164                 error.runModal();
02165                 return;
02166             }
02167             g_gui.scheduleTopDialogRedraw();
02168         }
02169         break;
02170     }
02171     case kChooseThemeDirCmd: {
02172         BrowserDialog browser(_("Select directory for GUI themes"), true);
02173         if (browser.runModal() > 0) {
02174             // User made his choice...
02175             Common::FSNode dir(browser.getResult());
02176             _themePath->setLabel(dir.getPath());
02177             g_gui.scheduleTopDialogRedraw();
02178         }
02179         break;
02180     }
02181     case kChooseExtraDirCmd: {
02182         BrowserDialog browser(_("Select directory for extra files"), true);
02183         if (browser.runModal() > 0) {
02184             // User made his choice...
02185             Common::FSNode dir(browser.getResult());
02186             _extraPath->setLabel(dir.getPath());
02187             g_gui.scheduleTopDialogRedraw();
02188         }
02189         break;
02190     }
02191 #ifdef DYNAMIC_MODULES
02192     case kChoosePluginsDirCmd: {
02193         BrowserDialog browser(_("Select directory for plugins"), true);
02194         if (browser.runModal() > 0) {
02195             // User made his choice...
02196             Common::FSNode dir(browser.getResult());
02197             _pluginsPath->setLabel(dir.getPath());
02198             g_gui.scheduleTopDialogRedraw();
02199         }
02200         break;
02201     }
02202 #endif
02203 #ifdef USE_CLOUD
02204     case kChooseRootDirCmd: {
02205         BrowserDialog browser(_("Select directory for Files Manager /root/"), true);
02206         if (browser.runModal() > 0) {
02207             // User made his choice...
02208             Common::FSNode dir(browser.getResult());
02209             Common::String path = dir.getPath();
02210             if (path.empty())
02211                 path = "/"; // absolute root
02212             _rootPath->setLabel(path);
02213             g_gui.scheduleTopDialogRedraw();
02214         }
02215         break;
02216     }
02217 #endif
02218     case kThemePathClearCmd:
02219         _themePath->setLabel(_c("None", "path"));
02220         break;
02221     case kExtraPathClearCmd:
02222         _extraPath->setLabel(_c("None", "path"));
02223         break;
02224     case kSavePathClearCmd:
02225         _savePath->setLabel(_("Default"));
02226         break;
02227 #ifdef USE_CLOUD
02228     case kRootPathClearCmd:
02229         _rootPath->setLabel(_c("None", "path"));
02230         break;
02231 #endif
02232     case kChooseSoundFontCmd: {
02233         BrowserDialog browser(_("Select SoundFont"), false);
02234         if (browser.runModal() > 0) {
02235             // User made his choice...
02236             Common::FSNode file(browser.getResult());
02237             _soundFont->setLabel(file.getPath());
02238 
02239             if (!file.getPath().empty() && (file.getPath() != _c("None", "path")))
02240                 _soundFontClearButton->setEnabled(true);
02241             else
02242                 _soundFontClearButton->setEnabled(false);
02243 
02244             g_gui.scheduleTopDialogRedraw();
02245         }
02246         break;
02247     }
02248     case kChooseThemeCmd:
02249     {
02250         ThemeBrowser browser;
02251         if (browser.runModal() > 0) {
02252             // User made his choice...
02253             _newTheme = browser.getSelected();
02254             _curTheme->setLabel(browser.getSelectedName());
02255         }
02256         break;
02257     }
02258 #ifdef USE_CLOUD
02259     case kCloudTabContainerReflowCmd:
02260         setupCloudTab();
02261         break;
02262 #ifdef USE_LIBCURL
02263     case kPopUpItemSelectedCmd:
02264     {
02265         // update container's scrollbar
02266         reflowLayout();
02267         break;
02268     }
02269     case kConfigureStorageCmd:
02270     {
02271 #ifdef NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE
02272         // save server's port
02273         uint32 port = Networking::LocalWebserver::getPort();
02274         if (_serverPort) {
02275             uint64 contents = _serverPort->getEditString().asUint64();
02276             if (contents != 0)
02277                 port = contents;
02278         }
02279         ConfMan.setInt("local_server_port", port);
02280         ConfMan.flushToDisk();
02281 #endif // NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE
02282         StorageWizardDialog dialog(_selectedStorageIndex);
02283         dialog.runModal();
02284         //update container's scrollbar
02285         reflowLayout();
02286         break;
02287     }
02288     case kRefreshStorageCmd:
02289     {
02290         CloudMan.info(
02291             new Common::Callback<GlobalOptionsDialog, Cloud::Storage::StorageInfoResponse>(this, &GlobalOptionsDialog::storageInfoCallback),
02292             new Common::Callback<GlobalOptionsDialog, Networking::ErrorResponse>(this, &GlobalOptionsDialog::storageErrorCallback)
02293         );
02294         Common::String dir = CloudMan.savesDirectoryPath();
02295         if (dir.lastChar() == '/')
02296             dir.deleteLastChar();
02297         CloudMan.listDirectory(
02298             dir,
02299             new Common::Callback<GlobalOptionsDialog, Cloud::Storage::ListDirectoryResponse>(this, &GlobalOptionsDialog::storageListDirectoryCallback),
02300             new Common::Callback<GlobalOptionsDialog, Networking::ErrorResponse>(this, &GlobalOptionsDialog::storageErrorCallback)
02301         );
02302         break;
02303     }
02304     case kDownloadStorageCmd:
02305         {
02306             DownloadDialog dialog(_selectedStorageIndex, _launcher);
02307             dialog.runModal();
02308             break;
02309         }
02310 #endif // USE_LIBCURL
02311 #ifdef USE_SDL_NET
02312     case kRunServerCmd:
02313         {
02314 #ifdef NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE
02315             // save server's port
02316             uint32 port = Networking::LocalWebserver::getPort();
02317             if (_serverPort) {
02318                 uint64 contents = _serverPort->getEditString().asUint64();
02319                 if (contents != 0)
02320                     port = contents;
02321             }
02322             ConfMan.setInt("local_server_port", port);
02323             ConfMan.flushToDisk();
02324 #endif // NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE
02325 
02326             if (LocalServer.isRunning())
02327                 LocalServer.stopOnIdle();
02328             else
02329                 LocalServer.start();
02330 
02331             break;
02332         }
02333 
02334     case kServerPortClearCmd: {
02335         if (_serverPort) {
02336             _serverPort->setEditString(Common::String::format("%u", Networking::LocalWebserver::DEFAULT_SERVER_PORT));
02337         }
02338         g_gui.scheduleTopDialogRedraw();
02339         break;
02340     }
02341 #endif // USE_SDL_NET
02342 #endif // USE_CLOUD
02343 #ifdef GUI_ENABLE_KEYSDIALOG
02344     case kChooseKeyMappingCmd:
02345         _keysDialog->runModal();
02346         break;
02347 #endif
02348 #ifdef USE_FLUIDSYNTH
02349     case kFluidSynthSettingsCmd:
02350         _fluidSynthSettingsDialog->runModal();
02351         break;
02352 #endif
02353 #ifdef USE_UPDATES
02354     case kUpdatesCheckCmd:
02355         if (g_system->getUpdateManager())
02356             g_system->getUpdateManager()->checkForUpdates();
02357         break;
02358 #endif
02359     default:
02360         OptionsDialog::handleCommand(sender, cmd, data);
02361     }
02362 }
02363 
02364 void GlobalOptionsDialog::handleTickle() {
02365     OptionsDialog::handleTickle();
02366 #ifdef USE_CLOUD
02367 #ifdef USE_SDL_NET
02368     if (LocalServer.isRunning() != _serverWasRunning) {
02369         _serverWasRunning = !_serverWasRunning;
02370         _redrawCloudTab = true;
02371     }
02372 #endif
02373     if (_redrawCloudTab) {
02374         setupCloudTab();
02375         g_gui.scheduleTopDialogRedraw();
02376         _redrawCloudTab = false;
02377     }
02378 #endif
02379 }
02380 
02381 void GlobalOptionsDialog::reflowLayout() {
02382     int firstVisible = _tabWidget->getFirstVisible();
02383     int activeTab = _tabWidget->getActiveTab();
02384 
02385 #if 0 // ResidualVM does not use it
02386     if (_midiTabId != -1) {
02387         _tabWidget->setActiveTab(_midiTabId);
02388 
02389         _tabWidget->removeWidget(_soundFontClearButton);
02390         _soundFontClearButton->setNext(0);
02391         delete _soundFontClearButton;
02392         _soundFontClearButton = addClearButton(_tabWidget, "GlobalOptions_MIDI.mcFontClearButton", kClearSoundFontCmd);
02393     }
02394 #endif
02395 
02396     if (_pathsTabId != -1) {
02397         _tabWidget->setActiveTab(_pathsTabId);
02398 
02399         _tabWidget->removeWidget(_savePathClearButton);
02400         _savePathClearButton->setNext(0);
02401         delete _savePathClearButton;
02402         _savePathClearButton = addClearButton(_tabWidget, "GlobalOptions_Paths.SavePathClearButton", kSavePathClearCmd);
02403 
02404         _tabWidget->removeWidget(_themePathClearButton);
02405         _themePathClearButton->setNext(0);
02406         delete _themePathClearButton;
02407         _themePathClearButton = addClearButton(_tabWidget, "GlobalOptions_Paths.ThemePathClearButton", kThemePathClearCmd);
02408 
02409         _tabWidget->removeWidget(_extraPathClearButton);
02410         _extraPathClearButton->setNext(0);
02411         delete _extraPathClearButton;
02412         _extraPathClearButton = addClearButton(_tabWidget, "GlobalOptions_Paths.ExtraPathClearButton", kExtraPathClearCmd);
02413     }
02414 
02415     _tabWidget->setActiveTab(activeTab);
02416     _tabWidget->setFirstVisible(firstVisible);
02417 
02418     OptionsDialog::reflowLayout();
02419 #ifdef USE_CLOUD
02420     setupCloudTab();
02421 #endif
02422 }
02423 
02424 #ifdef USE_CLOUD
02425 void GlobalOptionsDialog::setupCloudTab() {
02426     int serverLabelPosition = -1; //no override
02427 #ifdef USE_LIBCURL
02428     _selectedStorageIndex = (_storagePopUp ? _storagePopUp->getSelectedTag() : (uint32) Cloud::kStorageNoneId);
02429 
02430     if (_storagePopUpDesc) _storagePopUpDesc->setVisible(true);
02431     if (_storagePopUp) _storagePopUp->setVisible(true);
02432 
02433     bool shown = (_selectedStorageIndex != Cloud::kStorageNoneId);
02434     if (_storageUsernameDesc) _storageUsernameDesc->setVisible(shown);
02435     if (_storageUsername) {
02436         Common::String username = CloudMan.getStorageUsername(_selectedStorageIndex);
02437         if (username == "")
02438             username = _("<none>");
02439         _storageUsername->setLabel(username);
02440         _storageUsername->setVisible(shown);
02441     }
02442     if (_storageUsedSpaceDesc) _storageUsedSpaceDesc->setVisible(shown);
02443     if (_storageUsedSpace) {
02444         uint64 usedSpace = CloudMan.getStorageUsedSpace(_selectedStorageIndex);
02445         _storageUsedSpace->setLabel(Common::String::format(_("%llu bytes"), usedSpace));
02446         _storageUsedSpace->setVisible(shown);
02447     }
02448     if (_storageLastSyncDesc) _storageLastSyncDesc->setVisible(shown);
02449     if (_storageLastSync) {
02450         Common::String sync = CloudMan.getStorageLastSync(_selectedStorageIndex);
02451         if (sync == "") {
02452             if (_selectedStorageIndex == CloudMan.getStorageIndex() && CloudMan.isSyncing())
02453                 sync = _("<right now>");
02454             else
02455                 sync = _("<never>");
02456         }
02457         _storageLastSync->setLabel(sync);
02458         _storageLastSync->setVisible(shown);
02459     }
02460     if (_storageConnectButton)
02461         _storageConnectButton->setVisible(shown);
02462     if (_storageRefreshButton)
02463         _storageRefreshButton->setVisible(shown && _selectedStorageIndex == CloudMan.getStorageIndex());
02464     if (_storageDownloadButton)
02465         _storageDownloadButton->setVisible(shown && _selectedStorageIndex == CloudMan.getStorageIndex());
02466     if (!shown)
02467         serverLabelPosition = (_storageUsernameDesc ? _storageUsernameDesc->getRelY() : 0);
02468 #else // USE_LIBCURL
02469     _selectedStorageIndex = 0;
02470 
02471     if (_storagePopUpDesc)
02472         _storagePopUpDesc->setVisible(false);
02473     if (_storagePopUp)
02474         _storagePopUp->setVisible(false);
02475     if (_storageUsernameDesc)
02476         _storageUsernameDesc->setVisible(false);
02477     if (_storageUsernameDesc)
02478         _storageUsernameDesc->setVisible(false);
02479     if (_storageUsername)
02480         _storageUsername->setVisible(false);
02481     if (_storageUsedSpaceDesc)
02482         _storageUsedSpaceDesc->setVisible(false);
02483     if (_storageUsedSpace)
02484         _storageUsedSpace->setVisible(false);
02485     if (_storageLastSyncDesc)
02486         _storageLastSyncDesc->setVisible(false);
02487     if (_storageLastSync)
02488         _storageLastSync->setVisible(false);
02489     if (_storageConnectButton)
02490         _storageConnectButton->setVisible(false);
02491     if (_storageRefreshButton)
02492         _storageRefreshButton->setVisible(false);
02493     if (_storageDownloadButton)
02494         _storageDownloadButton->setVisible(false);
02495 
02496     serverLabelPosition = (_storagePopUpDesc ? _storagePopUpDesc->getRelY() : 0);
02497 #endif // USE_LIBCURL
02498 #ifdef USE_SDL_NET
02499     //determine original widget's positions
02500     int16 x, y;
02501     uint16 w, h;
02502     int serverButtonY, serverInfoY;
02503     int serverRootButtonY, serverRootY, serverRootClearButtonY;
02504     int serverPortDescY, serverPortY, serverPortClearButtonY;
02505     if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.RunServerButton", x, y, w, h))
02506         warning("GlobalOptions_Cloud_Container.RunServerButton's position is undefined");
02507     serverButtonY = y;
02508     if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.ServerInfoLabel", x, y, w, h))
02509         warning("GlobalOptions_Cloud_Container.ServerInfoLabel's position is undefined");
02510     serverInfoY = y;
02511 
02512     if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.RootPathButton", x, y, w, h))
02513         warning("GlobalOptions_Cloud_Container.RootPathButton's position is undefined");
02514     serverRootButtonY = y;
02515     if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.RootPath", x, y, w, h))
02516         warning("GlobalOptions_Cloud_Container.RootPath's position is undefined");
02517     serverRootY = y;
02518     if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.RootPathClearButton", x, y, w, h))
02519         warning("GlobalOptions_Cloud_Container.RootPathClearButton's position is undefined");
02520     serverRootClearButtonY = y;
02521 
02522     if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.ServerPortDesc", x, y, w, h))
02523         warning("GlobalOptions_Cloud_Container.ServerPortDesc's position is undefined");
02524     serverPortDescY = y;
02525     if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.ServerPortEditText", x, y, w, h))
02526         warning("GlobalOptions_Cloud_Container.ServerPortEditText's position is undefined");
02527     serverPortY = y;
02528     if (!g_gui.xmlEval()->getWidgetData("GlobalOptions_Cloud_Container.ServerPortClearButton", x, y, w, h))
02529         warning("GlobalOptions_Cloud_Container.ServerPortClearButton's position is undefined");
02530     serverPortClearButtonY = y;
02531 
02532     bool serverIsRunning = LocalServer.isRunning();
02533 
02534     if (serverLabelPosition < 0)
02535         serverLabelPosition = serverInfoY;
02536     if (_runServerButton) {
02537         _runServerButton->setVisible(true);
02538         _runServerButton->setPos(_runServerButton->getRelX(), serverLabelPosition + serverButtonY - serverInfoY);
02539         _runServerButton->setLabel(_(serverIsRunning ? "Stop server" : "Run server"));
02540         _runServerButton->setTooltip(_(serverIsRunning ? "Stop local webserver" : "Run local webserver"));
02541     }
02542     if (_serverInfoLabel) {
02543         _serverInfoLabel->setVisible(true);
02544         _serverInfoLabel->setPos(_serverInfoLabel->getRelX(), serverLabelPosition);
02545         if (serverIsRunning)
02546             _serverInfoLabel->setLabel(LocalServer.getAddress());
02547         else
02548             _serverInfoLabel->setLabel(_("Not running"));
02549     }
02550     if (_rootPathButton) {
02551         _rootPathButton->setVisible(true);
02552         _rootPathButton->setPos(_rootPathButton->getRelX(), serverLabelPosition + serverRootButtonY - serverInfoY);
02553     }
02554     if (_rootPath) {
02555         _rootPath->setVisible(true);
02556         _rootPath->setPos(_rootPath->getRelX(), serverLabelPosition + serverRootY - serverInfoY);
02557     }
02558     if (_rootPathClearButton) {
02559         _rootPathClearButton->setVisible(true);
02560         _rootPathClearButton->setPos(_rootPathClearButton->getRelX(), serverLabelPosition + serverRootClearButtonY - serverInfoY);
02561     }
02562 #ifdef NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE
02563     if (_serverPortDesc) {
02564         _serverPortDesc->setVisible(true);
02565         _serverPortDesc->setPos(_serverPortDesc->getRelX(), serverLabelPosition + serverPortDescY - serverInfoY);
02566         _serverPortDesc->setEnabled(!serverIsRunning);
02567     }
02568     if (_serverPort) {
02569         _serverPort->setVisible(true);
02570         _serverPort->setPos(_serverPort->getRelX(), serverLabelPosition + serverPortY - serverInfoY);
02571         _serverPort->setEnabled(!serverIsRunning);
02572     }
02573     if (_serverPortClearButton) {
02574         _serverPortClearButton->setVisible(true);
02575         _serverPortClearButton->setPos(_serverPortClearButton->getRelX(), serverLabelPosition + serverPortClearButtonY - serverInfoY);
02576         _serverPortClearButton->setEnabled(!serverIsRunning);
02577     }
02578 #else // NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE
02579     if (_serverPortDesc)
02580         _serverPortDesc->setVisible(false);
02581     if (_serverPort)
02582         _serverPort->setVisible(false);
02583     if (_serverPortClearButton)
02584         _serverPortClearButton->setVisible(false);
02585 #endif // NETWORKING_LOCALWEBSERVER_ENABLE_PORT_OVERRIDE
02586 #else // USE_SDL_NET
02587     if (_runServerButton)
02588         _runServerButton->setVisible(false);
02589     if (_serverInfoLabel) {
02590         _serverInfoLabel->setPos(_serverInfoLabel->getRelX(), serverLabelPosition); // Prevent compiler warning from serverLabelPosition being unused.
02591         _serverInfoLabel->setVisible(false);
02592     }
02593     if (_rootPathButton)
02594         _rootPathButton->setVisible(false);
02595     if (_rootPath)
02596         _rootPath->setVisible(false);
02597     if (_rootPathClearButton)
02598         _rootPathClearButton->setVisible(false);
02599     if (_serverPortDesc)
02600         _serverPortDesc->setVisible(false);
02601     if (_serverPort)
02602         _serverPort->setVisible(false);
02603     if (_serverPortClearButton)
02604         _serverPortClearButton->setVisible(false);
02605 #endif // USE_SDL_NET
02606 }
02607 
02608 #ifdef USE_LIBCURL
02609 void GlobalOptionsDialog::storageInfoCallback(Cloud::Storage::StorageInfoResponse response) {
02610     //we could've used response.value.email()
02611     //but Storage already notified CloudMan
02612     //so we just set the flag to redraw our cloud tab
02613     _redrawCloudTab = true;
02614 }
02615 
02616 void GlobalOptionsDialog::storageListDirectoryCallback(Cloud::Storage::ListDirectoryResponse response) {
02617     Common::Array<Cloud::StorageFile> &files = response.value;
02618     uint64 totalSize = 0;
02619     for (uint32 i = 0; i < files.size(); ++i)
02620         if (!files[i].isDirectory())
02621             totalSize += files[i].size();
02622     CloudMan.setStorageUsedSpace(CloudMan.getStorageIndex(), totalSize);
02623     _redrawCloudTab = true;
02624 }
02625 
02626 void GlobalOptionsDialog::storageErrorCallback(Networking::ErrorResponse response) {
02627     debug(9, "GlobalOptionsDialog: error response (%s, %ld):", (response.failed ? "failed" : "interrupted"), response.httpResponseCode);
02628     debug(9, "%s", response.response.c_str());
02629 
02630     if (!response.interrupted)
02631         g_system->displayMessageOnOSD(_("Request failed.\nCheck your Internet connection."));
02632 }
02633 #endif // USE_LIBCURL
02634 #endif // USE_CLOUD
02635 
02636 } // End of namespace GUI


Generated on Sat Dec 7 2019 05:00:43 for ResidualVM by doxygen 1.7.1
curved edge   curved edge