summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2005-05-25 12:31:59 +0000
committerdeva <deva>2005-05-25 12:31:59 +0000
commit30741368102da5e5a8e4f8b897f2502edfa0165b (patch)
tree173a266f2f444e76526c0ca940d002ede9863779
parent764d85a9a398cb37e7b5c3eb2e4e5bfc9ff26cd3 (diff)
Made info (error message system) work correctly.
-rw-r--r--ChangeLog1
-rw-r--r--etc/miav.conf2
-rw-r--r--src/info_gui.cc92
-rw-r--r--src/info_gui.h21
-rw-r--r--src/miav.cc9
5 files changed, 75 insertions, 50 deletions
diff --git a/ChangeLog b/ChangeLog
index b689b2b..9b95ea0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@ May 24 2005 - MIaV version 0.2.3
New Features:
-
Bug Fixes:
+ - Made info (error message system) work correctly.
- Free of NULL input queue removed.
- Name is overwritten with a message, if non-valid cpr is used.
- Error messagebox is now model with mainwindow as its parent.
diff --git a/etc/miav.conf b/etc/miav.conf
index 6eb33e1..8b700e7 100644
--- a/etc/miav.conf
+++ b/etc/miav.conf
@@ -17,7 +17,7 @@ pixel_width = 1024
pixel_height = 768
# How and where to connect to the miav server?
-server_addr = "127.0.0.1"
+server_addr = "192.168.0.10"
server_port = 18120
# Where top store the files recieved by the server
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*/
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 <pthread.h>
#include <semaphore.h>
+#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);