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


Generated on Sat Mar 16 2019 05:01:49 for ResidualVM by doxygen 1.7.1
curved edge   curved edge