37 #include <QApplication> 38 #include <QMessageBox> 50 static FILE *klf_qt_msg_fp = NULL;
53 static FILE *klf_fp_tty = NULL;
54 static bool klf_fp_tty_failed =
false;
62 static void ensure_tty_fp()
65 if (klf_fp_tty == NULL && !klf_fp_tty_failed) {
66 if ( !(klf_fp_tty = fopen(
"/dev/tty",
"w")) ) {
67 klf_fp_tty_failed =
true;
71 Q_UNUSED(klf_fp_tty_failed) ;
97 return klf_fp_tty_failed;
106 FILE *fout = klf_qt_msg_fp;
110 "-------------------------------------------------\n" 111 " KLATEXFORMULA DEBUG OUTPUT\n" 112 "-------------------------------------------------\n" 113 "Redirected on %s\n\n",
120 return klf_qt_msg_warnings_buffer;
135 if (klf_qt_msg_fp != NULL) {
136 fout = klf_qt_msg_fp;
147 fprintf(fout,
"D: %s\n", msg);
152 fprintf(fout,
"Warning: %s\n", msg);
155 klf_qt_msg_warnings_buffer +=
QByteArray(
"Warning: ") + msg +
"\n";
159 fprintf(klf_fp_tty,
"Warning: %s\n", msg);
162 #if defined KLF_WS_WIN && defined KLF_DEBUG 163 # define SAFECOUNTER_NUM 10 165 if (qApp != NULL && qApp->inherits(
"QApplication")) {
166 static int safecounter = SAFECOUNTER_NUM;
168 if (safecounter-- >= 0) {
169 QMessageBox::warning(0,
"Warning",
170 QString(
"KLatexFormula System Warning:\n%1")
174 if (safecounter == -1) {
175 QMessageBox::information(0,
"Information",
176 QString(
"Shown %1 system warnings. Will stop displaying them.").arg(SAFECOUNTER_NUM));
179 if (safecounter < -2) safecounter = -2;
184 fprintf(fout,
"Error: %s\n", msg);
187 klf_qt_msg_warnings_buffer +=
QByteArray(
"Error: ") + msg +
"\n";
202 fprintf(fout,
"Fatal: %s\n", msg);
205 if (qApp != NULL && qApp->inherits(
"QApplication")) {
206 QMessageBox::critical(0,
QObject::tr(
"FATAL ERROR",
207 "[[KLF's Qt Message Handler: dialog title]]"),
208 QObject::tr(
"KLatexFormula System FATAL ERROR:\n%1",
209 "[[KLF's Qt Message Handler: dialog text]]")
215 fprintf(fout,
"?????: %s\n", msg);
Base declarations for klatexformula and some utilities.
KLF_EXPORT bool klf_qt_msg_tty_fp_failed()
returns true if an attempt to open the tty fp failed.
KLF_EXPORT void klf_qt_msg_handle(QtMsgType type, const QMessageLogContext &, const QString &msgstr)
a template handler function for Qt debugging/warning/critical messages etc.
QString tr(const char *sourceText, const char *disambiguation, int n)
QString fromLocal8Bit(const char *str, int size)
KLF_EXPORT QByteArray klf_qt_msg_get_warnings_buffer()
returns the contents of the warnings buffer.
const char * constData() const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
KLF_EXPORT FILE * klf_qt_msg_get_tty_fp()
get the TTY file pointer.
QDateTime currentDateTime()
QByteArray toLatin1() const
KLF_EXPORT void klf_qt_msg_set_fp(FILE *fp)
redirect all debug/warning messages to a given file pointer
KLF_EXPORT void klf_qt_msg_clear_warnings_buffer()