diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-02-05 15:59:17 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-02-05 15:59:17 +0100 |
commit | 3405b046701e9c08972c1e622259164fc88ac487 (patch) | |
tree | 5ecc642c6bf67a9875d2850337b31f9715733c54 /src | |
parent | adb3ae667df8a3d1b4235a98605685af0f0c1805 (diff) | |
download | mana-3405b046701e9c08972c1e622259164fc88ac487.tar.gz mana-3405b046701e9c08972c1e622259164fc88ac487.tar.bz2 mana-3405b046701e9c08972c1e622259164fc88ac487.tar.xz mana-3405b046701e9c08972c1e622259164fc88ac487.zip |
Use SDL2 to show a simple message box on error
Replacing the various OS-specific ways implemented for macOS, Windows
and Linux (based on xmessage).
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/log.cpp | 18 | ||||
-rw-r--r-- | src/log.h | 5 | ||||
-rw-r--r-- | src/log.mm | 36 |
4 files changed, 5 insertions, 55 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 750c83bc..f2ba1221 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -623,7 +623,6 @@ ENDIF (WIN32) IF (APPLE) SET(SRCS ${SRCS} - log.mm SDLMain.h SDLMain.m ) diff --git a/src/log.cpp b/src/log.cpp index 1a37abae..47fe5e0f 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -21,18 +21,13 @@ #include "log.h" -#ifdef _WIN32 -#include <windows.h> -#elif __APPLE__ -void MacDialogBox(const std::string &error); -#endif +#include <SDL.h> #include <sys/time.h> #include <iostream> #include <sstream> #include <cstdarg> #include <cstdio> -#include <cstdlib> Logger::Logger(): mLogToStandardOut(true) @@ -106,16 +101,7 @@ void Logger::log(const char *log_text, ...) void Logger::error(const std::string &error_text) { log("Error: %s", error_text.c_str()); -#ifdef _WIN32 - MessageBox(NULL, error_text.c_str(), "Error", MB_ICONERROR | MB_OK); -#elif defined __APPLE__ - MacDialogBox(error_text); -#elif defined __linux__ || __linux std::cerr << "Error: " << error_text << std::endl; - std::string msg="xmessage \"" + error_text + "\""; - system(msg.c_str()); -#else - std::cerr << "Error: " << error_text << std::endl; -#endif + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", error_text.c_str(), NULL); exit(1); } @@ -57,9 +57,10 @@ class Logger ; /** - * Log an error and quit. The error will pop-up on Windows and Mac, and - * will be printed to standard error everywhere else. + * Log an error and quit. The error will be printed to standard error + * and showm in a simple message box. */ + __attribute__((noreturn)) void error(const std::string &error_text); private: diff --git a/src/log.mm b/src/log.mm deleted file mode 100644 index ae241c59..00000000 --- a/src/log.mm +++ /dev/null @@ -1,36 +0,0 @@ -/* - * The Mana Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2012 The Mana Developers - * - * This file is part of The Mana Client. - * - * 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 - * 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, see <http://www.gnu.org/licenses/>. - */ - -#import <AppKit/AppKit.h> -#include <string> - -void MacDialogBox(const std::string &error) -{ - NSString *errorMessage = [NSString stringWithCString:error.c_str() - encoding:[NSString defaultCStringEncoding]]; - NSAlert *alert = [NSAlert alertWithMessageText:errorMessage - defaultButton:@"OK" - alternateButton:nil - otherButton:nil - informativeTextWithFormat:@""]; - - [alert runModal]; -} |