[Scummvm-cvs-logs] CVS: scummvm/gui browser.cpp,1.21,1.22 browser.h,1.13,1.14 launcher.cpp,1.100,1.101 options.cpp,1.60,1.61
Max Horn
fingolfin at users.sourceforge.net
Sat Nov 20 13:36:15 CET 2004
Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32450/gui
Modified Files:
browser.cpp browser.h launcher.cpp options.cpp
Log Message:
Changed the FilesystemNode implementation to make it easier to use (client code doesn't have to worry about the memory managment anymore, it's all 'automatic' now). May have introduced a mem leak or two, please check :-)
Index: browser.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/browser.cpp,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- browser.cpp 17 Mar 2004 00:18:07 -0000 1.21
+++ browser.cpp 20 Nov 2004 21:35:49 -0000 1.22
@@ -34,12 +34,10 @@
BrowserDialog::BrowserDialog(const char *title)
: Dialog(20, 10, 320 -2 * 20, 200 - 2 * 10) {
- _choice = NULL;
_titleRef = CFStringCreateWithCString(0, title, CFStringGetSystemEncoding());
}
BrowserDialog::~BrowserDialog() {
- delete _choice;
CFRelease(_titleRef);
}
@@ -50,9 +48,7 @@
NavUserAction result;
NavReplyRecord reply;
OSStatus err;
-
- delete _choice;
- _choice = 0;
+ bool choiceMade = false;
// If in fullscreen mode, switch to windowed mode
bool wasFullscreen = g_system->getFeatureState(OSystem::kFeatureFullscreenMode);
@@ -97,7 +93,8 @@
err = FSRefMakePath(&ref, (UInt8*)buf, sizeof(buf)-1);
assert(err == noErr);
- _choice = FilesystemNode::getNodeForPath(buf);
+ _choice = FilesystemNode(buf);
+ choiceMade = true;
}
err = NavDisposeReply(&reply);
@@ -110,7 +107,7 @@
if (wasFullscreen)
g_system->setFeatureState(OSystem::kFeatureFullscreenMode, true);
- return (_choice != 0);
+ return choiceMade;
}
#else
@@ -127,14 +124,11 @@
};
BrowserDialog::BrowserDialog(const char *title)
- : Dialog(20, 10, 320 -2 * 20, 200 - 2 * 10),
- _node(0), _nodeContent(0) {
+ : Dialog(20, 10, 320 -2 * 20, 200 - 2 * 10)
+ {
_fileList = NULL;
_currentPath = NULL;
- _node = NULL;
- _nodeContent = NULL;
- _choice = NULL;
// Headline - TODO: should be customizable during creation time
new StaticTextWidget(this, 10, 8, _w - 2 * 10, kLineHeight, title, kTextAlignCenter);
@@ -153,67 +147,41 @@
addButton(_w - (kButtonWidth+10), _h - 24, "Choose", kChooseCmd, 0);
}
-BrowserDialog::~BrowserDialog() {
- delete _node;
- delete _nodeContent;
- delete _choice;
-}
-
void BrowserDialog::open() {
// If no node has been set, or the last used one is now invalid,
// go back to the root/default dir.
- if (_node == NULL || !_node->isValid()) {
- delete _node;
- _node = FilesystemNode::getRoot();
- assert(_node != NULL);
+ if (!_node.isValid()) {
+ _node = FilesystemNode();
}
// Alway refresh file list
updateListing();
-
- // Nothing chosen by default
- delete _choice;
- _choice = 0;
// Call super implementation
Dialog::open();
}
-void BrowserDialog::close() {
- delete _nodeContent;
- _nodeContent = 0;
-
- // Call super implementation
- Dialog::close();
-}
-
void BrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
- FilesystemNode *tmp;
-
switch (cmd) {
case kChooseCmd: {
// If nothing is selected in the list widget, choose the current dir.
// Else, choose the dir that is selected.
int selection = _fileList->getSelected();
if (selection >= 0) {
- _choice = (*_nodeContent)[selection].clone();
+ _choice = _nodeContent[selection];
} else {
- _choice = _node->clone();
+ _choice = _node;
}
setResult(1);
close();
}
break;
case kGoUpCmd:
- tmp = _node->parent();
- delete _node;
- _node = tmp;
+ _node = _node.getParent();
updateListing();
break;
case kListItemDoubleClickedCmd:
- tmp = (*_nodeContent)[data].clone();
- delete _node;
- _node = tmp;
+ _node = _nodeContent[data];
updateListing();
break;
default:
@@ -222,21 +190,17 @@
}
void BrowserDialog::updateListing() {
- assert(_node != NULL);
-
// Update the path display
- _currentPath->setLabel(_node->path());
+ _currentPath->setLabel(_node.path());
// Read in the data from the file system
- delete _nodeContent;
- _nodeContent = _node->listDir();
- assert(_nodeContent != NULL);
+ _nodeContent = _node.listDir();
// Populate the ListWidget
Common::StringList list;
- int size = _nodeContent->size();
+ int size = _nodeContent.size();
for (int i = 0; i < size; i++) {
- list.push_back((*_nodeContent)[i].displayName());
+ list.push_back(_nodeContent[i].displayName());
}
_fileList->setList(list);
_fileList->scrollTo(0);
Index: browser.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/browser.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- browser.h 5 Feb 2004 00:19:54 -0000 1.13
+++ browser.h 20 Nov 2004 21:35:49 -0000 1.14
@@ -23,14 +23,12 @@
#include "gui/dialog.h"
#include "common/str.h"
+#include "backends/fs/fs.h"
#ifdef MACOSX
#include <Carbon/Carbon.h>
#endif
-class FilesystemNode;
-class FSList;
-
namespace GUI {
class ListWidget;
@@ -41,17 +39,16 @@
typedef Common::StringList StringList;
public:
BrowserDialog(const char *title);
- virtual ~BrowserDialog();
#ifdef MACOSX
+ ~BrowserDialog();
virtual int runModal();
#else
virtual void open();
- virtual void close();
virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
#endif
- FilesystemNode *getResult() { return _choice; };
+ const FilesystemNode &getResult() { return _choice; };
protected:
@@ -60,10 +57,10 @@
#else
ListWidget *_fileList;
StaticTextWidget*_currentPath;
- FilesystemNode *_node;
- FSList *_nodeContent;
+ FilesystemNode _node;
+ FSList _nodeContent;
#endif
- FilesystemNode *_choice;
+ FilesystemNode _choice;
#ifndef MACOSX
void updateListing();
Index: launcher.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/launcher.cpp,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -d -r1.100 -r1.101
--- launcher.cpp 1 Oct 2004 21:12:18 -0000 1.100
+++ launcher.cpp 20 Nov 2004 21:35:49 -0000 1.101
@@ -330,15 +330,15 @@
// Change path for the game
case kCmdGameBrowser: {
BrowserDialog *_browser = new BrowserDialog("Select additional game directory");
- if (_browser->runModal() > 0) {
- // User made his choice...
- FilesystemNode *dir = _browser->getResult();
+ if (_browser->runModal() > 0) {
+ // User made his choice...
+ FilesystemNode dir(_browser->getResult());
// TODO: Verify the game can be found in the new directory... Best
// done with optional specific gameid to pluginmgr detectgames?
- // FSList *files = dir->listDir(FilesystemNode::kListFilesOnly);
+ // FSList files = dir.listDir(FilesystemNode::kListFilesOnly);
- _gamePathWidget->setLabel(dir->path());
+ _gamePathWidget->setLabel(dir.path());
}
draw();
break;
@@ -347,10 +347,10 @@
// Change path for extra game data (eg, using sword cutscenes when playing via CD)
case kCmdExtraBrowser: {
BrowserDialog *_browser = new BrowserDialog("Select additional game directory");
- if (_browser->runModal() > 0) {
- // User made his choice...
- FilesystemNode *dir = _browser->getResult();
- _extraPathWidget->setLabel(dir->path());
+ if (_browser->runModal() > 0) {
+ // User made his choice...
+ FilesystemNode dir(_browser->getResult());
+ _extraPathWidget->setLabel(dir.path());
}
draw();
break;
@@ -358,10 +358,10 @@
// Change path for stored save game (perm and temp) data
case kCmdSaveBrowser: {
BrowserDialog *_browser = new BrowserDialog("Select directory for saved games");
- if (_browser->runModal() > 0) {
- // User made his choice...
- FilesystemNode *dir = _browser->getResult();
- _savePathWidget->setLabel(dir->path());
+ if (_browser->runModal() > 0) {
+ // User made his choice...
+ FilesystemNode dir(_browser->getResult());
+ _savePathWidget->setLabel(dir.path());
}
draw();
break;
@@ -505,16 +505,13 @@
if (_browser->runModal() > 0) {
// User made his choice...
- FilesystemNode *dir = _browser->getResult();
- FSList *files = dir->listDir(FilesystemNode::kListFilesOnly);
+ FilesystemNode dir(_browser->getResult());
+ FSList files = dir.listDir(FilesystemNode::kListFilesOnly);
// ...so let's determine a list of candidates, games that
// could be contained in the specified directory.
- DetectedGameList candidates(PluginManager::instance().detectGames(*files));
+ DetectedGameList candidates(PluginManager::instance().detectGames(files));
- delete files;
- files = 0;
-
int idx;
if (candidates.isEmpty()) {
// No game was found in the specified directory
@@ -553,7 +550,7 @@
ConfMan.set("gameid", result.name, domain);
ConfMan.set("description", result.description, domain);
}
- ConfMan.set("path", dir->path(), domain);
+ ConfMan.set("path", dir.path(), domain);
const bool customLanguage = (result.language != Common::UNK_LANG);
const bool customPlatform = (result.platform != Common::kPlatformUnknown);
Index: options.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/options.cpp,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- options.cpp 15 Nov 2004 04:41:50 -0000 1.60
+++ options.cpp 20 Nov 2004 21:35:49 -0000 1.61
@@ -476,16 +476,16 @@
case kChooseSaveDirCmd:
if (_browser->runModal() > 0) {
// User made his choice...
- FilesystemNode *dir = _browser->getResult();
- _savePath->setLabel(dir->path());
+ FilesystemNode dir(_browser->getResult());
+ _savePath->setLabel(dir.path());
// TODO - we should check if the directory is writeable before accepting it
}
break;
case kChooseExtraDirCmd:
if (_browser->runModal() > 0) {
// User made his choice...
- FilesystemNode *dir = _browser->getResult();
- _extraPath->setLabel(dir->path());
+ FilesystemNode dir(_browser->getResult());
+ _extraPath->setLabel(dir.path());
}
break;
default:
More information about the Scummvm-git-logs
mailing list