add shuttle udev rules to doc, fix still images drag handle
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / mainerror.C
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 #include "bcdisplayinfo.h"
23 #include "bcsignals.h"
24 #include "language.h"
25 #include "mainerror.h"
26 #include "mainsession.h"
27 #include "mutex.h"
28 #include "mwindow.h"
29
30 #include <string.h>
31
32
33
34
35 MainError* MainError::main_error = 0;
36
37
38
39
40
41
42 MainErrorGUI::MainErrorGUI(MWindow *mwindow, MainError *thread, int x, int y)
43  : BC_Window(_(PROGRAM_NAME ": Errors"),
44         x,
45         y,
46         mwindow->session->ewindow_w,
47         mwindow->session->ewindow_h,
48         50,
49         50,
50         1,
51         0,
52         1,
53         -1,
54         "",
55         1)
56 {
57         this->mwindow = mwindow;
58         this->thread = thread;
59 }
60
61 MainErrorGUI::~MainErrorGUI()
62 {
63 }
64
65 void MainErrorGUI::create_objects()
66 {
67         lock_window("MainErrorGUI::create_objects");
68         BC_Button *button;
69         add_subwindow(button = new BC_OKButton(this));
70         int x = 10, y = 10;
71         add_subwindow(title = new BC_Title(x, y, _("The following errors occurred:")));
72         y += title->get_h() + 5;
73         add_subwindow(list = new BC_ListBox(x, y,
74                 get_w() - 20, button->get_y() - y - 5,
75                 LISTBOX_TEXT,           // Display text list or icons
76                 &thread->errors,        // Each column has an ArrayList of BC_ListBoxItems.
77                 0,                      // Titles for columns.  Set to 0 for no titles
78                 0,                      // width of each column
79                 1,                      // Total columns.  Only 1 in icon mode
80                 0,                      // Pixel of top of window.
81                 0,                      // If this listbox is a popup window with a button
82                 LISTBOX_SINGLE,         // Select one item or multiple items
83                 ICON_LEFT,              // Position of icon relative to text of each item
84                 0));
85         show_window();
86         unlock_window();
87 }
88
89 int MainErrorGUI::resize_event(int w, int h)
90 {
91         title->reposition_window(title->get_x(), title->get_y());
92         int list_h = h -
93                 list->get_y() -
94                 (get_h() - list->get_y() - list->get_h());
95         int list_w = w -
96                 list->get_x() -
97                 (get_w() - list->get_x() - list->get_w());
98         list->reposition_window(list->get_x(),
99                 list->get_y(),
100                 list_w,
101                 list_h);
102         mwindow->session->ewindow_w = w;
103         mwindow->session->ewindow_h = h;
104         return 1;
105 }
106
107
108
109
110
111
112 MainError::MainError(MWindow *mwindow)
113  : BC_DialogThread()
114 {
115         this->mwindow = mwindow;
116         errors_lock = new Mutex("MainError::errors_lock");
117         main_error = this;
118 }
119
120 MainError::~MainError()
121 {
122         close_window();
123         errors.remove_all_objects();
124         delete errors_lock;
125 }
126
127 BC_Window* MainError::new_gui()
128 {
129         BC_DisplayInfo display_info;
130         int x = display_info.get_abs_cursor_x();
131         int y = display_info.get_abs_cursor_y();
132
133         MainErrorGUI *gui = new MainErrorGUI(mwindow, this, x, y);
134         gui->create_objects();
135         return gui;
136 }
137
138 void MainError::append_error(const char *string)
139 {
140         const char *in_ptr = string;
141         char string2[BCTEXTLEN];
142         int first_line = 1;
143         while(*in_ptr)
144         {
145                 char *out_ptr = string2;
146 // Indent remaining lines
147                 if( !first_line ) {
148                         *out_ptr++ = ' ';
149                         *out_ptr++ = ' ';
150                 }
151
152                 while(*in_ptr != '\n' &&
153                         *in_ptr)
154                 {
155                         *out_ptr++ = *in_ptr++;
156                 }
157                 *out_ptr++ = 0;
158
159                 errors.append(new BC_ListBoxItem(string2));
160
161                 if( *in_ptr == '\n' ) {
162                         in_ptr++;
163                         first_line = 0;
164                 }
165         }
166 }
167
168 void MainError::show_error_local(const char *string)
169 {
170 // assume user won't get to closing the GUI here
171         lock_window("MainError::show_error_local");
172         if( get_gui() ) {
173                 MainErrorGUI *gui = (MainErrorGUI*)get_gui();
174                 gui->lock_window("MainError::show_error_local");
175                 append_error(string);
176                 gui->list->update(&errors, 0, 0, 1,
177                         gui->list->get_xposition(), gui->list->get_yposition(),
178                         gui->list->get_highlighted_item(),  // Flat index of item cursor is over
179                         0,     // set all autoplace flags to 1
180                         1);
181                 gui->raise_window(1);
182                 gui->unlock_window();
183         }
184         else {
185                 errors.remove_all_objects();
186                 append_error(string);
187                 start();
188         }
189         unlock_window();
190 }
191
192
193 void MainError::show_error(const char *string)
194 {
195         if( main_error ) main_error->show_error_local(string);
196         int len = strlen(string);
197         printf("%s%s", string, len>0 && string[len-1] == '\n' ? "" : "\n");
198 }
199
200
201
202
203
204
205