raDIYo 0.4
raDIYo.cpp
1/***************************************************************************
2
3 source::worx raDIYo
4 Copyright © 2020-2022 c.holzheuer
5 c.holzheuer@sourceworx.org
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12***************************************************************************/
13
14#include <QFile>
15#include <QDebug>
16#include <QTextStream>
17#include <qapplication.h>
18#include <stdio.h>
19#include <stdlib.h>
20#include <raDIYo.h>
21
28QString readResource( const QString& fileName )
29{
30 QFile resourceFile( fileName );
31 //qDebug() << "res file: " << fileName;
32 if( !resourceFile.open( QFile::ReadOnly | QFile::Text) )
33 return resourceFile.errorString();
34
35 QTextStream in( &resourceFile );
36 QString text = in.readAll();
37 resourceFile.close();
38
39 return text;
40
41}
42
43
51void swMessageOutput( QtMsgType type, const QMessageLogContext &context, const QString &msg)
52{
53 QByteArray localMsg = msg.toLocal8Bit();
54 const char *file = context.file ? context.file : "";
55 const char *function = context.function ? context.function : "";
56 switch (type) {
57 case QtDebugMsg:
58 fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
59 break;
60 case QtInfoMsg:
61 fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
62 break;
63 case QtWarningMsg:
64 fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
65 break;
66 case QtCriticalMsg:
67 fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
68 break;
69 case QtFatalMsg:
70 fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
71 break;
72 }
73}
74
75
76