4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #include "bcdisplayinfo.h"
23 #include "bcsignals.h"
25 #include "mainerror.h"
26 #include "mainsession.h"
35 MainError* MainError::main_error = 0;
42 MainErrorGUI::MainErrorGUI(MWindow *mwindow, MainError *thread, int x, int y)
43 : BC_Window(_(PROGRAM_NAME ": Errors"),
46 mwindow->session->ewindow_w,
47 mwindow->session->ewindow_h,
57 this->mwindow = mwindow;
58 this->thread = thread;
61 MainErrorGUI::~MainErrorGUI()
65 void MainErrorGUI::create_objects()
67 lock_window("MainErrorGUI::create_objects");
71 add_subwindow(button = new BC_OKButton(this));
74 add_subwindow(title = new BC_Title(x, y, _("The following errors occurred:")));
75 y += title->get_h() + 5;
77 add_subwindow(list = new BC_ListBox(x,
80 button->get_y() - y - 5,
81 LISTBOX_TEXT, // Display text list or icons
82 &thread->errors, // Each column has an ArrayList of BC_ListBoxItems.
83 0, // Titles for columns. Set to 0 for no titles
84 0, // width of each column
85 1, // Total columns. Only 1 in icon mode
86 0, // Pixel of top of window.
87 0, // If this listbox is a popup window with a button
88 LISTBOX_SINGLE, // Select one item or multiple items
89 ICON_LEFT, // Position of icon relative to text of each item
97 int MainErrorGUI::resize_event(int w, int h)
99 title->reposition_window(title->get_x(), title->get_y());
102 (get_h() - list->get_y() - list->get_h());
105 (get_w() - list->get_x() - list->get_w());
106 list->reposition_window(list->get_x(),
110 mwindow->session->ewindow_w = w;
111 mwindow->session->ewindow_h = h;
120 MainError::MainError(MWindow *mwindow)
123 this->mwindow = mwindow;
124 errors_lock = new Mutex("MainError::errors_lock");
128 MainError::~MainError()
134 BC_Window* MainError::new_gui()
136 BC_DisplayInfo display_info;
137 int x = display_info.get_abs_cursor_x();
138 int y = display_info.get_abs_cursor_y();
140 MainErrorGUI *gui = new MainErrorGUI(mwindow, this, x, y);
141 gui->create_objects();
145 void MainError::append_error(const char *string)
147 char *in_ptr = (char*)string;
148 char string2[BCTEXTLEN];
152 char *out_ptr = string2;
153 // Indent remaining lines
160 while(*in_ptr != '\n' &&
163 *out_ptr++ = *in_ptr++;
167 errors.append(new BC_ListBoxItem(string2));
177 void MainError::show_error_local(const char *string)
180 // assume user won't get to closing the GUI here
181 lock_window("MainError::show_error_local");
186 MainErrorGUI *gui = (MainErrorGUI*)get_gui();
187 gui->lock_window("MainError::show_error_local");
189 append_error(string);
191 gui->list->update(&errors,
195 gui->list->get_xposition(),
196 gui->list->get_yposition(),
197 gui->list->get_highlighted_item(), // Flat index of item cursor is over
198 0, // set all autoplace flags to 1
201 gui->unlock_window();
211 errors.remove_all_objects();
213 append_error(string);
221 void MainError::show_error(const char *string)
224 main_error->show_error_local(string);
227 printf("%s", string);
228 if(string[strlen(string) - 1] != '\n')