diff options
Diffstat (limited to 'src/info_gui.cc')
-rw-r--r-- | src/info_gui.cc | 92 |
1 files changed, 44 insertions, 48 deletions
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 <stdio.h> #include <stdarg.h> -#include "messagebox.h" +#include <time.h> + +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() @@ -55,10 +71,33 @@ 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, "<!"); fflush(stderr); - qapp->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*/ |