[Scummvm-cvs-logs] SF.net SVN: scummvm:[48627] scummvm/trunk
fingolfin at users.sourceforge.net
fingolfin at users.sourceforge.net
Sun Apr 11 21:04:02 CEST 2010
Revision: 48627
http://scummvm.svn.sourceforge.net/scummvm/?rev=48627&view=rev
Author: fingolfin
Date: 2010-04-11 19:04:02 +0000 (Sun, 11 Apr 2010)
Log Message:
-----------
Rest of patch #2982224: GSoC: Added unit test and unified error message display
Modified Paths:
--------------
scummvm/trunk/base/main.cpp
scummvm/trunk/common/error.h
scummvm/trunk/common/module.mk
scummvm/trunk/gui/module.mk
Added Paths:
-----------
scummvm/trunk/common/error.cpp
scummvm/trunk/gui/error.cpp
scummvm/trunk/gui/error.h
Modified: scummvm/trunk/base/main.cpp
===================================================================
--- scummvm/trunk/base/main.cpp 2010-04-11 18:30:42 UTC (rev 48626)
+++ scummvm/trunk/base/main.cpp 2010-04-11 19:04:02 UTC (rev 48627)
@@ -49,6 +49,7 @@
#include "gui/GuiManager.h"
#include "gui/message.h"
+#include "gui/error.h"
#include "sound/audiocd.h"
@@ -134,22 +135,13 @@
// Check for errors
if (!engine || err != Common::kNoError) {
- // TODO: Show an error dialog or so?
- // TODO: Also take 'err' into consideration...
- //GUI::MessageDialog alert("ScummVM could not find any game in the specified directory!");
- //alert.runModal();
- const char *errMsg = 0;
- switch (err) {
- case Common::kInvalidPathError:
- errMsg = "Invalid game path";
- break;
- case Common::kNoGameDataFoundError:
- errMsg = "Unable to locate game data";
- break;
- default:
- errMsg = "Unknown error";
- }
+ // TODO: An errorDialog for this and engine related errors is displayed already in the scummvm_main function
+ // Is a separate dialog here still required?
+
+ //GUI::displayErrorDialog("ScummVM could not find any game in the specified directory!");
+ const char *errMsg = Common::errorToString(err);
+
warning("%s failed to instantiate engine: %s (target '%s', path '%s')",
plugin->getName(),
errMsg,
@@ -391,7 +383,8 @@
// Did an error occur ?
if (result != Common::kNoError) {
- // TODO: Show an informative error dialog if starting the selected game failed.
+ // Shows an informative error dialog if starting the selected game failed.
+ GUI::displayErrorDialog(result, "Error running game:");
}
// Quit unless an error occurred, or Return to launcher was requested
@@ -418,6 +411,7 @@
// A dialog would be nicer, but we don't have any
// screen to draw on yet.
warning("Could not find any engine capable of running the selected game");
+ GUI::displayErrorDialog("Could not find any engine capable of running the selected game");
}
// We will destroy the AudioCDManager singleton here to save some memory.
Added: scummvm/trunk/common/error.cpp
===================================================================
--- scummvm/trunk/common/error.cpp (rev 0)
+++ scummvm/trunk/common/error.cpp 2010-04-11 19:04:02 UTC (rev 48627)
@@ -0,0 +1,72 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/error.h"
+#include "common/util.h"
+
+namespace Common {
+
+/**
+ * Error Table: Maps error codes to their default descriptions
+ */
+
+struct ErrorMessage {
+ Error error;
+ const char *errMsg;
+};
+
+static const ErrorMessage _errMsgTable[] = {
+ { kInvalidPathError, "Invalid Path" },
+ { kNoGameDataFoundError, "Game Data not found" },
+ { kUnsupportedGameidError, "Game Id not supported" },
+ { kUnsupportedColorMode, "Unsupported Color Mode" },
+
+ { kReadPermissionDenied, "Read permission denied" },
+ { kWritePermissionDenied, "Write permission denied" },
+
+ // The following three overlap a bit with kInvalidPathError and each other. Which to keep?
+ { kPathDoesNotExist, "Path not exists" },
+ { kPathNotDirectory, "Path not a directory" },
+ { kPathNotFile, "Path not a file" },
+
+ { kCreatingFileFailed, "Cannot create file" },
+ { kReadingFailed, "Reading failed" },
+ { kWritingFailed, "Writing data failed" },
+
+ { kUnknownError, "Unknown Error" }
+};
+
+const char *errorToString(Error error) {
+
+ for (int i = 0; i < ARRAYSIZE(_errMsgTable); i++) {
+ if (error == _errMsgTable[i].error) {
+ return _errMsgTable[i].errMsg;
+ }
+ }
+
+ return "Unknown Error";
+}
+
+} // End of namespace Common
Property changes on: scummvm/trunk/common/error.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Modified: scummvm/trunk/common/error.h
===================================================================
--- scummvm/trunk/common/error.h 2010-04-11 18:30:42 UTC (rev 48626)
+++ scummvm/trunk/common/error.h 2010-04-11 19:04:02 UTC (rev 48627)
@@ -66,6 +66,14 @@
kUnknownError ///< Catch-all error, used if no other error code matches
};
+/**
+ * Maps an error code to equivalent string description.
+ *
+ * @param error error code to be converted
+ * @return a pointer to string description of the error
+ */
+const char *errorToString(Error error);
+
} // End of namespace Common
#endif //COMMON_ERROR_H
Modified: scummvm/trunk/common/module.mk
===================================================================
--- scummvm/trunk/common/module.mk 2010-04-11 18:30:42 UTC (rev 48626)
+++ scummvm/trunk/common/module.mk 2010-04-11 19:04:02 UTC (rev 48627)
@@ -5,6 +5,7 @@
config-file.o \
config-manager.o \
debug.o \
+ error.o \
EventDispatcher.o \
EventRecorder.o \
file.o \
Added: scummvm/trunk/gui/error.cpp
===================================================================
--- scummvm/trunk/gui/error.cpp (rev 0)
+++ scummvm/trunk/gui/error.cpp 2010-04-11 19:04:02 UTC (rev 48627)
@@ -0,0 +1,45 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "common/error.h"
+#include "gui/message.h"
+#include "gui/error.h"
+
+namespace GUI {
+
+void displayErrorDialog(const char *text) {
+ GUI::MessageDialog alert(text);
+ alert.runModal();
+}
+
+void displayErrorDialog(Common::Error error, const char *extraText) {
+ Common::String errorText(extraText);
+ errorText += " ";
+ errorText += Common::errorToString(error);
+ GUI::MessageDialog alert(errorText);
+ alert.runModal();
+}
+
+} // End of namespace GUI
Property changes on: scummvm/trunk/gui/error.cpp
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Added: scummvm/trunk/gui/error.h
===================================================================
--- scummvm/trunk/gui/error.h (rev 0)
+++ scummvm/trunk/gui/error.h 2010-04-11 19:04:02 UTC (rev 48627)
@@ -0,0 +1,50 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef GUI_ERROR_H
+#define GUI_ERROR_H
+
+#include "common/error.h"
+
+namespace GUI {
+
+/**
+ * Displays an error dialog for some error code.
+ *
+ * @param error error code
+ * @param extraText extra text to be displayed in addition to default string description(optional)
+ */
+void displayErrorDialog(Common::Error error, const char *extraText = "");
+
+/**
+ * Displays an error dialog for a given message.
+ *
+ * @param text message to be displayed
+ */
+void displayErrorDialog(const char *text);
+
+} // End of namespace GUI
+
+#endif //GUI_ERROR_H
Property changes on: scummvm/trunk/gui/error.h
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:keywords
+ Date Rev Author URL Id
Added: svn:eol-style
+ native
Modified: scummvm/trunk/gui/module.mk
===================================================================
--- scummvm/trunk/gui/module.mk 2010-04-11 18:30:42 UTC (rev 48626)
+++ scummvm/trunk/gui/module.mk 2010-04-11 19:04:02 UTC (rev 48627)
@@ -7,6 +7,7 @@
debugger.o \
dialog.o \
editable.o \
+ error.o \
EditTextWidget.o \
GuiManager.o \
launcher.o \
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list