initial commit
[goodguy/cinelerra.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 class MainErrorGUI : public BC_Window
37 {
38 public:
39         MainErrorGUI(MWindow *mwindow, MainError *thread, int x, int y);
40         ~MainErrorGUI();
41
42         void create_objects();
43         int resize_event(int w, int h);
44
45         MWindow *mwindow;
46         MainError *thread;
47         BC_ListBox *list;
48         BC_Title *title;
49 };
50
51
52 class MainError : public BC_DialogThread
53 {
54 public:
55         MainError(MWindow *mwindow);
56         ~MainError();
57
58         friend class MainErrorGUI;
59
60         BC_Window* new_gui();
61
62
63 // Display error message to command line or GUI, depending on what exists.
64         static void show_error(const char *string);
65         static void finit_error() {
66                 if( !main_error ) return;
67                 delete main_error;  main_error = 0;
68         }
69         static void init_error(MWindow *mwindow) {
70                 finit_error();
71                 main_error = new MainError(mwindow);
72         }
73
74 private:
75         void show_error_local(const char *string);
76
77 // Split errors into multiple lines based on carriage returns.
78         void append_error(const char *string);
79
80
81         MWindow *mwindow;
82         ArrayList<BC_ListBoxItem*> errors;
83         Mutex *errors_lock;
84
85 // Main error dialog.  Won't exist if no GUI.
86         static MainError *main_error;
87 };
88
89
90 // format text to error dialog listbox
91
92 static inline void eprint1(const char *func, const char *fmt, ...)
93 {
94         char err_msg[1024], *cp = err_msg, *ep = cp + sizeof(err_msg)-1;
95         va_list va;
96         va_start(va, fmt);
97         cp += snprintf(cp, ep-cp, "%s:\n", func);
98         cp += vsnprintf(cp, ep-cp, fmt, va);
99         *cp = 0;
100         va_end(va);
101         MainError::show_error(err_msg); \
102 }
103
104 #define eprintf(s...) eprint1(__PRETTY_FUNCTION__, s)
105
106 #endif