[Scummvm-cvs-logs] CVS: scummvm/gui launcher.cpp,1.51,1.52 options.cpp,1.24,1.25 options.h,1.5,1.6

Max Horn fingolfin at users.sourceforge.net
Wed Oct 8 15:01:08 CEST 2003


Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv6106/gui

Modified Files:
	launcher.cpp options.cpp options.h 
Log Message:
new config manager. not everything is completed, and some things will still be changed, but it seems to work well enough to put it into CVS

Index: launcher.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/launcher.cpp,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- launcher.cpp	5 Oct 2003 14:03:07 -0000	1.51
+++ launcher.cpp	8 Oct 2003 21:59:22 -0000	1.52
@@ -32,11 +32,13 @@
 
 #include "backends/fs/fs.h"
 
+#include "base/engine.h"
 #include "base/gameDetector.h"
 #include "base/plugins.h"
 
-#include "common/config-file.h"
-#include "base/engine.h"
+#include "common/config-manager.h"
+
+using Common::ConfigManager;
 
 enum {
 	kStartCmd = 'STRT',
@@ -83,7 +85,6 @@
 	virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
 
 protected:
-	Config &_config;
 	const String &_domain;
 	EditTextWidget *_descriptionWidget;
 	EditTextWidget *_domainWidget;
@@ -92,10 +93,11 @@
 };
 
 EditGameDialog::EditGameDialog(NewGui *gui, const String &domain, const TargetSettings *target)
-	: Dialog(gui, 8, 50, 320 - 2 * 8, 200 - 2 * 40), _config(*g_config), _domain(domain) {
+	: Dialog(gui, 8, 50, 320 - 2 * 8, 200 - 2 * 40),
+	  _domain(domain) {
 
 	// Determine the description string
-	String description(_config.get("description", _domain));
+	String description(ConfMan.get("description", domain));
 	if (description.isEmpty()) {
 		description = target->description;
 	}
@@ -116,18 +118,18 @@
 		new EditTextWidget(this, 50, 26, _w - 50 - 10, kLineHeight, description);
 
 	// Path to game data (view only)
-	String path(_config.get("path", _domain));
+	String path(ConfMan.get("path", _domain));
 	new StaticTextWidget(this, 10, 42, 40, kLineHeight, "Path: ", kTextAlignRight);
 	new StaticTextWidget(this, 50, 42, _w - 50 - 10, kLineHeight, path, kTextAlignLeft);
 
 	// Full screen checkbox
 	_fullscreenCheckbox = new CheckboxWidget(this, 15, 62, 200, 16, "Use Fullscreen Mode", 0, 'F');
-	_fullscreenCheckbox->setState(_config.getBool("fullscreen", false, _domain));
+	_fullscreenCheckbox->setState(ConfMan.getBool("fullscreen", _domain));
 
 	// Display 'Amiga' checkbox, but only for Scumm games.
 	if (isScumm) {
 		_amigaCheckbox = new CheckboxWidget(this, 15, 82, 200, 16, "Amiga Version", 0, 'A');
-		_amigaCheckbox->setState(_config.getBool("amiga", false, _domain));
+		_amigaCheckbox->setState(ConfMan.getBool("amiga", _domain));
 	} else {
 		_amigaCheckbox = 0;
 	}
@@ -142,17 +144,17 @@
 		// Write back changes made to config object
 		String newDomain(_domainWidget->getLabel());
 		if (newDomain != _domain) {
-			if (newDomain.isEmpty() || _config.has_domain(newDomain)) {
+			if (newDomain.isEmpty() || ConfMan.hasGameDomain(newDomain)) {
 				MessageDialog alert(_gui, "This game ID is already taken. Please choose another one.");
 				alert.runModal();
 				return;
 			}
-			_config.rename_domain(_domain, newDomain);
+			ConfMan.renameGameDomain(_domain, newDomain);
 		}
-		_config.set("description", _descriptionWidget->getLabel(), newDomain);
+		ConfMan.set("description", _descriptionWidget->getLabel(), newDomain);
 		if (_amigaCheckbox)
-			_config.setBool("amiga", _amigaCheckbox->getState(), newDomain);
-		_config.setBool("fullscreen", _fullscreenCheckbox->getState(), newDomain);
+			ConfMan.set("amiga", _amigaCheckbox->getState(), newDomain);
+		ConfMan.set("fullscreen", _fullscreenCheckbox->getState(), newDomain);
 		setResult(1);
 		close();
 	} else {
@@ -218,12 +220,16 @@
 
 void LauncherDialog::open() {
 	Dialog::open();
+/* FIXME / TODO: config rewrite
 	g_config->set_writing(true);
+*/
 }
 
 void LauncherDialog::close() {
-	g_config->flush();
+	ConfMan.flushToDisk();
+/* FIXME / TODO: config rewrite
 	g_config->set_writing(false);
+*/
 	Dialog::close();
 }
 
@@ -232,16 +238,16 @@
 
 	// Retrieve a list of all games defined in the config file
 	_domains.clear();
-	StringList domains = g_config->get_domains();
-	StringList::ConstIterator iter = domains.begin();
+	const ConfigManager::DomainMap &domains = ConfMan.getGameDomains();
+	ConfigManager::DomainMap::ConstIterator iter = domains.begin();
 	for (iter = domains.begin(); iter != domains.end(); ++iter) {
-		String name(g_config->get("gameid", *iter));
-		String description(g_config->get("description", *iter));
+		String name(iter->_value.get("gameid"));
+		String description(iter->_value.get("description"));
 
 		if (name.isEmpty())
-			name = *iter;
+			name = iter->_key;
 		if (description.isEmpty()) {
-			const TargetSettings *v = _detector.findTarget(name.c_str());
+			const TargetSettings *v = _detector.findTarget(name);
 			if (v && v->description)
 				description = v->description;
 		} 
@@ -253,7 +259,7 @@
 			while (pos < size && (description > l[pos]))
 				pos++;
 			l.insert_at(pos, description);
-			_domains.insert_at(pos, *iter);
+			_domains.insert_at(pos, iter->_key);
 		}
 	}
 
@@ -372,18 +378,18 @@
 				// Pick a domain name which does not yet exist (after all, we
 				// are *adding* a game to the config, not replacing).
 				String domain(v->targetName);
-				if (g_config->has_domain(domain)) {
+				if (ConfMan.hasGameDomain(domain)) {
 					char suffix = 'a';
 					domain += suffix;
-					while (g_config->has_domain(domain)) {
+					while (ConfMan.hasGameDomain(domain)) {
 						domain.deleteLastChar();
 						suffix++;
 						domain += suffix;
 					}
-					g_config->set("gameid", v->targetName, domain);
-					g_config->set("description", v->description, domain);
+					ConfMan.set("gameid", v->targetName, domain);
+					ConfMan.set("description", v->description, domain);
 				}
-				g_config->set("path", dir->path(), domain);
+				ConfMan.set("path", dir->path(), domain);
 				
 				// Display edit dialog for the new entry
 				EditGameDialog editDialog(_gui, domain, v);
@@ -391,14 +397,14 @@
 					// User pressed OK, so make changes permanent
 
 					// Write config to disk
-					g_config->flush();
+					ConfMan.flushToDisk();
 					
 					// Update the ListWidget and force a redraw
 					updateListing();
 					draw();
 				} else {
 					// User aborted, remove the the new domain again
-					g_config->delete_domain(domain);
+					ConfMan.removeGameDomain(domain);
 				}
 			}
 		}
@@ -406,10 +412,10 @@
 	case kRemoveGameCmd:
 		// Remove the currently selected game from the list
 		assert(item >= 0);
-		g_config->delete_domain(_domains[item]);
+		ConfMan.removeGameDomain(_domains[item]);
 
 		// Write config to disk
-		g_config->flush();
+		ConfMan.flushToDisk();
 		
 		// Update the ListWidget and force a redraw
 		updateListing();
@@ -423,15 +429,15 @@
 		// This is useful because e.g. MonkeyVGA needs Adlib music to have decent
 		// music support etc.
 		assert(item >= 0);
-		const char *gameId = g_config->get("gameid", _domains[item]);
-		if (!gameId)
-			gameId = _domains[item].c_str();
+		String gameId(ConfMan.get("gameid", _domains[item]));
+		if (gameId.isEmpty())
+			gameId = _domains[item];
 		EditGameDialog editDialog(_gui, _domains[item], _detector.findTarget(gameId));
 		if (editDialog.runModal()) {
 			// User pressed OK, so make changes permanent
 
 			// Write config to disk
-			g_config->flush();
+			ConfMan.flushToDisk();
 			
 			// Update the ListWidget and force a redraw
 			updateListing();

Index: options.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/options.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- options.cpp	2 Oct 2003 22:52:56 -0000	1.24
+++ options.cpp	8 Oct 2003 21:59:22 -0000	1.25
@@ -27,7 +27,7 @@
 
 #include "backends/fs/fs.h"
 #include "base/gameDetector.h"
-#include "common/config-file.h"
+#include "common/config-manager.h"
 #include "sound/mididrv.h"
 
 #if (!( defined(__DC__) || defined(__GP32__)) && !defined(_MSC_VER))
@@ -61,7 +61,7 @@
 };
 
 GlobalOptionsDialog::GlobalOptionsDialog(NewGui *gui, GameDetector &detector)
-	: Dialog(gui, 10, 15, 320 - 2 * 10, 200 - 2 * 15), _detector(detector) {
+	: Dialog(gui, 10, 15, 320 - 2 * 10, 200 - 2 * 15) {
 	// The GFX mode popup & a label
 	// TODO - add an API to query the list of available GFX modes, and to get/set the mode
 	new StaticTextWidget(this, 5, 10+1, 100, kLineHeight, "Graphics mode: ", kTextAlignRight);
@@ -94,7 +94,7 @@
 	const MidiDriverDescription *md = getAvailableMidiDrivers();
 	while (md->name) {
 		_midiPopUp->appendEntry(md->description, md->id);
-		if (md->id == _detector._midi_driver)
+		if (md->id == detector._midi_driver)
 			midiSelected = i;
 		i++;
 		md++;
@@ -134,10 +134,9 @@
 	_savePath = new StaticTextWidget(this, 105, 106, 180, kLineHeight, "/foo/bar", kTextAlignLeft);
 	new ButtonWidget(this, 105, 120, 64, 16, "Choose...", kChooseSaveDirCmd, 0);
 	
-// TODO: set _savePath to the current save path, i.e. as obtained via
-	const char *dir = NULL;
-	dir = g_config->get("savepath", "scummvm");
-	if (dir) {
+// TODO: set _savePath to the current save path
+	Common::String dir(ConfMan.get("savepath"));
+	if (!dir.isEmpty()) {
 		_savePath->setLabel(dir);
 	} else {
 		// Default to the current directory...
@@ -164,9 +163,9 @@
 void GlobalOptionsDialog::open() {
 	Dialog::open();
 
-	_soundVolumeMaster = _detector._master_volume;
-	_soundVolumeMusic = _detector._music_volume;
-	_soundVolumeSfx = _detector._sfx_volume;
+	_soundVolumeMaster = ConfMan.getInt("master_volume");
+	_soundVolumeMusic = ConfMan.getInt("music_volume");
+	_soundVolumeSfx = ConfMan.getInt("sfx_volume");
 
 	_masterVolumeSlider->setValue(_soundVolumeMaster);
 	_musicVolumeSlider->setValue(_soundVolumeMusic);
@@ -184,7 +183,7 @@
 			// User made his choice...
 			FilesystemNode *dir = _browser->getResult();
 			_savePath->setLabel(dir->path());
-			// TODO - we should check if the director is writeable before accepting it
+			// TODO - we should check if the directory is writeable before accepting it
 		}
 		break;
 	case kMasterVolumeChanged:
@@ -207,18 +206,17 @@
 			const MidiDriverDescription *md = getAvailableMidiDrivers();
 			for (; md->name; md++) {
 				if (md->id == (int) data) {
-					g_config->set ("music_driver", md->name, "_USER_OVERRIDES");
+					ConfMan.set("music_driver", md->name);
 					break;
 				}
 			}
 		}
 		break;
 	case kOKCmd:
-		// TODO Write back changes made to config object
 		setResult(1);
-		_detector._master_volume = _soundVolumeMaster;
-		_detector._music_volume = _soundVolumeMusic;
-		_detector._sfx_volume = _soundVolumeSfx;
+		ConfMan.set("master_volume", _soundVolumeMaster);
+		ConfMan.set("music_volume", _soundVolumeMusic);
+		ConfMan.set("sfx_volume", _soundVolumeSfx);
 		close();
 		break;
 	default:

Index: options.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/options.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- options.h	2 Oct 2003 17:43:02 -0000	1.5
+++ options.h	8 Oct 2003 21:59:22 -0000	1.6
@@ -40,8 +40,6 @@
 	void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
 
 protected:
-	GameDetector 	&_detector;
-
 	BrowserDialog	*_browser;
 	StaticTextWidget*_savePath;
 





More information about the Scummvm-git-logs mailing list