add Autosave continuous backups by Andras Reuss and Andrew-R
[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 ": Messages"),
44         x, y, mwindow->session->ewindow_w, mwindow->session->ewindow_h,
45         xS(50), yS(50), 1, 0, 1, -1, "", 1)
46 {
47         this->mwindow = mwindow;
48         this->thread = thread;
49 }
50
51 MainErrorGUI::~MainErrorGUI()
52 {
53 }
54
55 void MainErrorGUI::create_objects()
56 {
57         lock_window("MainErrorGUI::create_objects");
58         BC_Button *button;
59         add_subwindow(button = new BC_OKButton(this));
60         int x = xS(10), y = yS(10);
61         add_subwindow(title = new BC_Title(x, y, _("Message log:")));
62         y += title->get_h() + yS(5);
63         add_subwindow(list = new BC_ListBox(x, y,
64                 get_w() - xS(20), button->get_y() - y - yS(5),
65                 LISTBOX_TEXT,           // Display text list or icons
66                 &thread->errors,        // Each column has an ArrayList of BC_ListBoxItems.
67                 0,                      // Titles for columns.  Set to 0 for no titles
68                 0,                      // width of each column
69                 1,                      // Total columns.  Only 1 in icon mode
70                 0,                      // Pixel of top of window.
71                 0,                      // If this listbox is a popup window with a button
72                 LISTBOX_SINGLE,         // Select one item or multiple items
73                 ICON_LEFT,              // Position of icon relative to text of each item
74                 0));
75         show_window();
76         unlock_window();
77 }
78
79 int MainErrorGUI::resize_event(int w, int h)
80 {
81         title->reposition_window(title->get_x(), title->get_y());
82         int list_h = h -
83                 list->get_y() -
84                 (get_h() - list->get_y() - list->get_h());
85         int list_w = w -
86                 list->get_x() -
87                 (get_w() - list->get_x() - list->get_w());
88         list->reposition_window(list->get_x(),
89                 list->get_y(),
90                 list_w,
91                 list_h);
92         mwindow->session->ewindow_w = w;
93         mwindow->session->ewindow_h = h;
94         return 1;
95 }
96
97
98 MainError::MainError(MWindow *mwindow)
99  : BC_DialogThread()
100 {
101         this->mwindow = mwindow;
102         errors_lock = new Mutex("MainError::errors_lock");
103         main_error = this;
104 }
105
106 MainError::~MainError()
107 {
108         close_window();
109         errors.remove_all_objects();
110         delete errors_lock;
111 }
112
113 BC_Window* MainError::new_gui()
114 {
115         BC_DisplayInfo display_info;
116         int x = display_info.get_abs_cursor_x();
117         int y = display_info.get_abs_cursor_y();
118
119         MainErrorGUI *gui = new MainErrorGUI(mwindow, this, x, y);
120         gui->create_objects();
121         return gui;
122 }
123
124 void MainError::append_error(const char *string)
125 {
126         const char *in_ptr = string;
127         char string2[BCTEXTLEN];
128         int first_line = 1;
129         while(*in_ptr)
130         {
131                 char *out_ptr = string2;
132 // Indent remaining lines
133                 if( !first_line ) {
134                         *out_ptr++ = ' ';
135                         *out_ptr++ = ' ';
136                 }
137
138                 while(*in_ptr != '\n' &&
139                         *in_ptr)
140                 {
141                         *out_ptr++ = *in_ptr++;
142                 }
143                 *out_ptr++ = 0;
144
145                 errors.append(new BC_ListBoxItem(string2));
146
147                 if( *in_ptr == '\n' ) {
148                         in_ptr++;
149                         first_line = 0;
150                 }
151         }
152 }
153
154 void MainError::show_error_local(const char *string)
155 {
156 // assume user won't get to closing the GUI here
157         lock_dialog("MainError::show_error_local");
158         if( get_gui() ) {
159                 MainErrorGUI *gui = (MainErrorGUI*)get_gui();
160                 gui->lock_window("MainError::show_error_local");
161                 append_error(string);
162                 gui->list->update(&errors, 0, 0, 1,
163                         gui->list->get_xposition(), gui->list->get_yposition(),
164                         gui->list->get_highlighted_item(),  // Flat index of item cursor is over
165                         0,     // set all autoplace flags to 1
166                         1);
167                 gui->raise_window(1);
168                 gui->unlock_window();
169         }
170         else {
171                 errors.remove_all_objects();
172                 append_error(string);
173                 start();
174         }
175         unlock_dialog();
176 }
177
178
179 void MainError::show_error(const char *string)
180 {
181         if( main_error ) main_error->show_error_local(string);
182         int len = strlen(string);
183         printf("%s%s", string, len>0 && string[len-1] == '\n' ? "" : "\n");
184 }
185