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

saveload.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 "common/config-manager.h"
00024 #include "common/system.h"
00025 
00026 #include "gui/saveload.h"
00027 #include "gui/saveload-dialog.h"
00028 
00029 #include "engines/metaengine.h"
00030 
00031 namespace GUI {
00032 
00033 SaveLoadChooser::SaveLoadChooser(const String &title, const String &buttonLabel, bool saveMode)
00034     : _impl(0), _title(title), _buttonLabel(buttonLabel), _saveMode(saveMode) {
00035 }
00036 
00037 SaveLoadChooser::~SaveLoadChooser() {
00038     delete _impl;
00039     _impl = 0;
00040 }
00041 
00042 void SaveLoadChooser::selectChooser(const MetaEngine &engine) {
00043 #ifndef DISABLE_SAVELOADCHOOSER_GRID
00044     const SaveLoadChooserType requestedType = getRequestedSaveLoadDialog(engine);
00045     if (!_impl || _impl->getType() != requestedType) {
00046         delete _impl;
00047         _impl = 0;
00048 
00049         switch (requestedType) {
00050         case kSaveLoadDialogGrid:
00051             _impl = new SaveLoadChooserGrid(_title, _saveMode);
00052             break;
00053 
00054         case kSaveLoadDialogList:
00055 #endif // !DISABLE_SAVELOADCHOOSER_GRID
00056             _impl = new SaveLoadChooserSimple(_title, _buttonLabel, _saveMode);
00057 #ifndef DISABLE_SAVELOADCHOOSER_GRID
00058             break;
00059         }
00060     }
00061 #endif // !DISABLE_SAVELOADCHOOSER_GRID
00062 }
00063 
00064 Common::String SaveLoadChooser::createDefaultSaveDescription(const int slot) const {
00065 #if defined(USE_SAVEGAME_TIMESTAMP)
00066     TimeDate curTime;
00067     g_system->getTimeAndDate(curTime);
00068     curTime.tm_year += 1900; // fixup year
00069     curTime.tm_mon++; // fixup month
00070     return Common::String::format("%04d-%02d-%02d / %02d:%02d:%02d", curTime.tm_year, curTime.tm_mon, curTime.tm_mday, curTime.tm_hour, curTime.tm_min, curTime.tm_sec);
00071 #else
00072     return Common::String::format("Save %d", slot + 1);
00073 #endif
00074 }
00075 
00076 int SaveLoadChooser::runModalWithCurrentTarget() {
00077     const Common::String gameId = ConfMan.get("gameid");
00078 
00079     const Plugin *plugin = 0;
00080     EngineMan.findGame(gameId, &plugin);
00081 
00082     return runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
00083 }
00084 
00085 int SaveLoadChooser::runModalWithPluginAndTarget(const Plugin *plugin, const String &target) {
00086     selectChooser(plugin->get<MetaEngine>());
00087     if (!_impl)
00088         return -1;
00089 
00090 #if defined(USE_CLOUD) && defined(USE_LIBCURL)
00091     _impl->runSaveSync(ConfMan.hasKey("savepath", target));
00092 #endif
00093 
00094     // Set up the game domain as newly active domain, so
00095     // target specific savepath will be checked
00096     String oldDomain = ConfMan.getActiveDomainName();
00097     ConfMan.setActiveDomain(target);
00098 
00099     int ret;
00100     do {
00101         ret = _impl->run(target, &plugin->get<MetaEngine>());
00102 #ifndef DISABLE_SAVELOADCHOOSER_GRID
00103         if (ret == kSwitchSaveLoadDialog) {
00104             selectChooser(plugin->get<MetaEngine>());
00105         }
00106 #endif // !DISABLE_SAVELOADCHOOSER_GRID
00107     } while (ret < -1);
00108 
00109     // Revert to the old active domain
00110     ConfMan.setActiveDomain(oldDomain);
00111 
00112     return ret;
00113 }
00114 
00115 const Common::String &SaveLoadChooser::getResultString() const {
00116     assert(_impl);
00117     return _impl->getResultString();
00118 }
00119 
00120 } // End of namespace GUI


Generated on Sat Mar 23 2019 05:02:07 for ResidualVM by doxygen 1.7.1
curved edge   curved edge