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 +++++++++++++++++++++++++++------------------------------ src/info_gui.h | 21 +++++++++++++ src/miav.cc | 9 +++++- 3 files changed, 73 insertions(+), 49 deletions(-) (limited to 'src') 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*/ diff --git a/src/info_gui.h b/src/info_gui.h index 6547496..8df1985 100644 --- a/src/info_gui.h +++ b/src/info_gui.h @@ -51,6 +51,25 @@ #include #include +#include "messagebox.h" + +#define TYPE_SHOW_MESSAGEBOX 65432 + +class ShowMessageEvent : public QCustomEvent { +public: + ShowMessageEvent( MessageBox* msgbox ) + : QCustomEvent( TYPE_SHOW_MESSAGEBOX ), m( msgbox ) {} + MessageBox *messagebox() const { return m; } +private: + MessageBox *m;; +}; + +class InfoEventHandler : public QObject { +protected: + bool eventFilter( QObject *o, QEvent *e ); +}; + + class InfoGui: public Info { public: InfoGui(QApplication *a, QWidget *p); @@ -63,6 +82,8 @@ public: void setParent(QWidget *p); private: + void showmsg(char *msg, char *title, msg_icon icon); + QApplication *qapp; QWidget *parent; pthread_mutex_t mutex; diff --git a/src/miav.cc b/src/miav.cc index 12c63be..d1211f1 100644 --- a/src/miav.cc +++ b/src/miav.cc @@ -31,6 +31,10 @@ /* * $Log$ + * Revision 1.12 2005/05/25 12:31:59 deva + * + * Made info (error message system) work correctly. + * * Revision 1.11 2005/05/23 18:42:50 deva * Error message windows is now modal with mainwindow as its parent. * @@ -89,7 +93,10 @@ int grab(int argc, char *argv[]) { InfoGui info(&miav_grab, NULL); config = new MiavConfig(ETC"/miav.conf", &info); - MainWindow mainwindow(&miav_grab); + InfoEventHandler *eventhandler = new InfoEventHandler( ); + miav_grab.installEventFilter( eventhandler ); + + MainWindow mainwindow( &miav_grab ); miav_grab.setMainWidget( &mainwindow ); info.setParent(&mainwindow); -- cgit v1.2.3