From 30741368102da5e5a8e4f8b897f2502edfa0165b Mon Sep 17 00:00:00 2001 From: deva Date: Wed, 25 May 2005 12:31:59 +0000 Subject: Made info (error message system) work correctly. --- src/info_gui.cc | 92 +++++++++++++++++++++++++++------------------------------ 1 file changed, 44 insertions(+), 48 deletions(-) (limited to 'src/info_gui.cc') diff --git a/src/info_gui.cc b/src/info_gui.cc index 52bfa5c..b084b00 100644 --- a/src/info_gui.cc +++ b/src/info_gui.cc @@ -41,12 +41,28 @@ #include #include -#include "messagebox.h" +#include + +bool InfoEventHandler::eventFilter( QObject *o, QEvent *e ) +{ + if ( e->type() == TYPE_SHOW_MESSAGEBOX ) { + fprintf(stderr, "Custom event!\n"); fflush(stderr); + MessageBox *msgbox = ((ShowMessageEvent*)e)->messagebox(); + msgbox->exec(); + delete msgbox; + return TRUE; // eat event + } else { + // standard event processing + return FALSE; + } +} InfoGui::InfoGui(QApplication *a, QWidget *p): Info() { qapp = a; parent = p; + + pthread_mutex_init (&mutex, NULL); } InfoGui::~InfoGui() @@ -54,11 +70,34 @@ InfoGui::~InfoGui() } void InfoGui::setParent(QWidget *p) +{ + parent = p; +} + +void InfoGui::showmsg(char *msg, char *title, msg_icon icon) { pthread_mutex_lock(&mutex); // Beginning of safezone - parent = p; + fprintf(stderr, "%s: %s\n", title, msg); fflush(stderr); + + while( !parent ) { + struct timespec ts; + + ts.tv_sec = 0; + ts.tv_nsec = 200000000L; // 200ms + nanosleep(&ts, NULL); + } + + MessageBox *msgbox = new MessageBox(parent, + title, + msg, + TYPE_OK, + icon); + + ShowMessageEvent *event = new ShowMessageEvent( msgbox ); + + qapp->postEvent(parent, event); // End of safezone pthread_mutex_unlock(&mutex); @@ -68,79 +107,36 @@ void InfoGui::error(char *fmt, ...) { char buf[1024]; - pthread_mutex_lock(&mutex); - // Beginning of safezone - va_list argp; va_start(argp, fmt); - fprintf(stderr, "Error: ["); vfprintf(stderr, fmt, argp); fprintf(stderr, "]\n"); fflush(stderr); vsprintf(buf, fmt, argp); va_end(argp); - fprintf(stderr, "lock(); - fprintf(stderr, "!"); fflush(stderr); - MessageBox(parent, - TXT_ERROR_TITLE, - buf, - TYPE_OK, - ICON_ERROR).exec(); - fprintf(stderr, "!"); fflush(stderr); - qapp->unlock(); - fprintf(stderr, "!>"); fflush(stderr); - - // End of safezone - pthread_mutex_unlock(&mutex); + showmsg(buf, TXT_ERROR_TITLE, ICON_ERROR); } void InfoGui::warn(char *fmt, ...) { char buf[1024]; - pthread_mutex_lock(&mutex); - // Beginning of safezone - va_list argp; va_start(argp, fmt); - fprintf(stderr, "Warning: ["); vfprintf(stderr, fmt, argp); fprintf(stderr, "]\n"); fflush(stderr); vsprintf(buf, fmt, argp); va_end(argp); - qapp->lock(); - MessageBox(parent, - TXT_WARNING_TITLE, - buf, - TYPE_OK, - ICON_WARNING).exec(); - qapp->unlock(); - - // End of safezone - pthread_mutex_unlock(&mutex); + showmsg(buf, TXT_WARNING_TITLE, ICON_WARNING); } void InfoGui::info(char *fmt, ...) { char buf[1024]; - pthread_mutex_lock(&mutex); - // Beginning of safezone - va_list argp; va_start(argp, fmt); - fprintf(stderr, "Info: ["); vfprintf(stderr, fmt, argp); fprintf(stderr, "]\n"); fflush(stderr); vsprintf(buf, fmt, argp); va_end(argp); - qapp->lock(); - MessageBox(parent, - TXT_INFO_TITLE, - buf, - TYPE_OK, - ICON_INFO).exec(); - qapp->unlock(); - - // End of safezone - pthread_mutex_unlock(&mutex); + showmsg(buf, TXT_INFO_TITLE, ICON_INFO); } #endif/*USE_GUI*/ -- cgit v1.2.3