Ticket #9160: gui_changes.patch

File gui_changes.patch, 8.6 KB (added by SF/sud03r, 14 years ago)

Separated error dialog functions to gui/error.h, added scummvm header,removed spaces/tabs.

  • gui/module.mk

     
    77        debugger.o \
    88        dialog.o \
    99        editable.o \
     10        error.o \
    1011        EditTextWidget.o \
    1112        GuiManager.o \
    1213        launcher.o \
  • gui/error.h

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 */
     22
     23#ifndef GUI_ERROR_H
     24#define GUI_ERROR_H
     25
     26#include "common/error.h"
     27
     28namespace GUI {
     29
     30/**
     31 * Displays an error dialog for some error code.
     32 *
     33 * @param error error code
     34 * @param extraText extra text to be displayed in addition to default string description(optional)
     35 */
     36void displayErrorDialog(Common::Error error, const char *extraText = "");
     37
     38/**
     39 * Displays an error dialog for a given message.
     40 *
     41 * @param text message to be displayed
     42 */
     43void displayErrorDialog(const char *text);
     44
     45} // End of namespace GUI
     46
     47#endif //GUI_ERROR_H
  • gui/error.cpp

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 */
     22
     23#include "common/error.h"
     24#include "gui/message.h"
     25#include "gui/error.h"
     26
     27namespace GUI {
     28
     29void displayErrorDialog(const char *text) {
     30        GUI::MessageDialog alert(text);
     31        alert.runModal();
     32}
     33
     34void displayErrorDialog(Common::Error error, const char *extraText) {
     35        Common::String errorText(extraText);
     36        errorText += " ";
     37        errorText += Common::errorToString(error);
     38        GUI::MessageDialog alert(errorText);
     39        alert.runModal();
     40}
     41
     42} // end of namespace GUI
  • common/error.h

     
    6666        kUnknownError                           ///< Catch-all error, used if no other error code matches
    6767};
    6868
     69/**
     70 * Maps an error code to equivalent string description.
     71 *
     72 * @param error error code to be converted
     73 * @return a pointer to string description of the error
     74 */
     75const char *errorToString(Error error);
     76
    6977} // End of namespace Common
    7078
    7179#endif //COMMON_ERROR_H
  • common/error.cpp

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 */
     22
     23#include "common/error.h"
     24#include "common/util.h"
     25
     26namespace Common {
     27
     28/**
     29 * Error Table: Maps error codes to their default descriptions
     30 */
     31
     32struct ErrorMessage {
     33        Error error;
     34        const char *errMsg;
     35};
     36
     37static const ErrorMessage _errMsgTable[] = {
     38        { kInvalidPathError, "Invalid Path" },
     39        { kNoGameDataFoundError, "Game Data not found" },
     40        { kUnsupportedGameidError, "Game Id not supported" },
     41        { kUnsupportedColorMode, "Unsupported Color Mode" },
     42
     43        { kReadPermissionDenied, "Read permission denied" },
     44        { kWritePermissionDenied, "Write permission denied" },
     45
     46        // The following three overlap a bit with kInvalidPathError and each other. Which to keep?
     47        { kPathDoesNotExist, "Path not exists" },
     48        { kPathNotDirectory, "Path not a directory" },
     49        { kPathNotFile, "Path not a file" },
     50
     51        { kCreatingFileFailed, "Cannot create file" },
     52        { kReadingFailed, "Reading failed" },
     53        { kWritingFailed, "Writing data failed" },
     54
     55        { kUnknownError, "Unknown Error" }
     56};
     57
     58const char *errorToString(Error error) {
     59
     60        for (int i = 0; i < ARRAYSIZE(_errMsgTable); i++) {
     61                if (error == _errMsgTable[i].error) {
     62                        return _errMsgTable[i].errMsg;
     63                }
     64        }
     65
     66        return "Unknown Error";
     67}
     68
     69} // End of namespace Common
  • common/module.mk

     
    55        config-file.o \
    66        config-manager.o \
    77        debug.o \
     8        error.o \
    89        EventDispatcher.o \
    910        EventRecorder.o \
    1011        file.o \
  • base/main.cpp

     
    4949
    5050#include "gui/GuiManager.h"
    5151#include "gui/message.h"
     52#include "gui/error.h"
    5253
    5354#include "sound/audiocd.h"
    5455
     
    134135
    135136        // Check for errors
    136137        if (!engine || err != Common::kNoError) {
    137                 // TODO: Show an error dialog or so?
    138                 // TODO: Also take 'err' into consideration...
    139                 //GUI::MessageDialog alert("ScummVM could not find any game in the specified directory!");
    140                 //alert.runModal();
    141                 const char *errMsg = 0;
    142                 switch (err) {
    143                 case Common::kInvalidPathError:
    144                         errMsg = "Invalid game path";
    145                         break;
    146                 case Common::kNoGameDataFoundError:
    147                         errMsg = "Unable to locate game data";
    148                         break;
    149                 default:
    150                         errMsg = "Unknown error";
    151                 }
     138               
     139                // TODO: An errorDialog for this and engine related errors is displayed already in the scummvm_main function
     140                // Is a separate dialog here still required?
     141               
     142                //GUI::displayErrorDialog("ScummVM could not find any game in the specified directory!");
     143                const char *errMsg = Common::errorToString(err);
    152144
    153145                warning("%s failed to instantiate engine: %s (target '%s', path '%s')",
    154146                        plugin->getName(),
     
    391383
    392384                        // Did an error occur ?
    393385                        if (result != Common::kNoError) {
    394                                 // TODO: Show an informative error dialog if starting the selected game failed.
     386                                // Shows an informative error dialog if starting the selected game failed.
     387                                GUI::displayErrorDialog(result, "Error running game:");
    395388                        }
    396389
    397390                        // Quit unless an error occurred, or Return to launcher was requested
     
    418411                        // A dialog would be nicer, but we don't have any
    419412                        // screen to draw on yet.
    420413                        warning("Could not find any engine capable of running the selected game");
     414                        GUI::displayErrorDialog("Could not find any engine capable of running the selected game");
    421415                }
    422416
    423417                // We will destroy the AudioCDManager singleton here to save some memory.