e5e5d4fbb180109f64ed10573b227b8adc285c74
[goodguy/history.git] / cinelerra-5.1 / cinelerra / mainerror.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef MAINERROR_H
23 #define MAINERROR_H
24
25
26 #include "bcdialog.h"
27 #include "mainerror.inc"
28 #include "mutex.inc"
29 #include "mwindow.inc"
30
31 // This is needed for errors which are too verbose to fit in the
32 // status bar.
33
34 // Once created, it accumulates errors in a listbox until it's closed.
35
36 // Macro to enable the simplest possible error output
37 //#define eprintf(format, ...) {char error_string[1024]; sprintf(sprintf(error_string, "%s: " format, __PRETTY_FUNCTION__, ## __VA_ARGS__); MainError::show_error(error_string); }
38 // We have to use longer version if we want to gettext error messages
39
40 #define eprintf(...) do { \
41   char err_msg[1024], *ep = err_msg; \
42   ep += sprintf(ep, "%s:\n", __PRETTY_FUNCTION__); \
43   sprintf(ep, __VA_ARGS__); (volatile void)MainError::show_error(err_msg); \
44 } while(0)
45
46
47 class MainErrorGUI : public BC_Window
48 {
49 public:
50         MainErrorGUI(MWindow *mwindow, MainError *thread, int x, int y);
51         ~MainErrorGUI();
52
53         void create_objects();
54         int resize_event(int w, int h);
55
56         MWindow *mwindow;
57         MainError *thread;
58         BC_ListBox *list;
59         BC_Title *title;
60 };
61
62
63 class MainError : public BC_DialogThread
64 {
65 public:
66         MainError(MWindow *mwindow);
67         ~MainError();
68
69         friend class MainErrorGUI;
70
71         BC_Window* new_gui();
72
73
74 // Display error message to command line or GUI, depending on what exists.
75         static void show_error(const char *string);
76         static void finit_error() {
77                 if( !main_error ) return;
78                 delete main_error;  main_error = 0;
79         }
80         static void init_error(MWindow *mwindow) {
81                 finit_error();
82                 main_error = new MainError(mwindow);
83         }
84
85 private:
86         void show_error_local(const char *string);
87
88 // Split errors into multiple lines based on carriage returns.
89         void append_error(const char *string);
90
91
92         MWindow *mwindow;
93         ArrayList<BC_ListBoxItem*> errors;
94         Mutex *errors_lock;
95
96 // Main error dialog.  Won't exist if no GUI.
97         static MainError *main_error;
98 };
99
100
101
102
103 #endif