File indexing completed on 2024-05-12 05:12:41
0001 /* 0002 Copyright (C) 2013 Jonathan Marten <jjm@keelhaul.me.uk> 0003 0004 This program is free software; you can redistribute it and/or modify 0005 it under the terms of the GNU General Public License as published by 0006 the Free Software Foundation; either version 2 of the License, or 0007 (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 GNU General Public License for more details. 0013 0014 You should have received a copy of the GNU General Public License along 0015 with this program; if not, write to the Free Software Foundation, Inc., 0016 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 0017 */ 0018 0019 #include "errorreporter.h" 0020 0021 #include <QString> 0022 #include <QCoreApplication> 0023 0024 #include <iostream> 0025 0026 0027 static bool runningApplication = false; 0028 0029 0030 void ErrorReporter::error(const QString &msg) 0031 { 0032 std::cerr << qPrintable(QCoreApplication::applicationName()) 0033 << " (error): " 0034 << qPrintable(msg) 0035 << std::endl; 0036 } 0037 0038 void ErrorReporter::warning(const QString &msg) 0039 { 0040 std::cerr << qPrintable(QCoreApplication::applicationName()) 0041 << " (warning): " 0042 << qPrintable(msg) 0043 << std::endl; 0044 } 0045 0046 void ErrorReporter::fatal(const QString &msg) 0047 { 0048 error(msg); 0049 0050 // If the QCoreApplication event loop has not been started yet, exit now 0051 if (!runningApplication) { 0052 exit(EXIT_FAILURE); 0053 } 0054 // Otherwise just tell the event loop to exit 0055 QCoreApplication::exit(EXIT_FAILURE); 0056 } 0057 0058 void ErrorReporter::progress(const QString &msg) 0059 { 0060 std::cout << "** " 0061 << qPrintable(msg) 0062 << std::endl; 0063 } 0064 0065 void ErrorReporter::setRunningApplication(bool running) 0066 { 0067 runningApplication = running; 0068 }