00001 #include "bcdisplayinfo.h"
00002 #include "bcsignals.h"
00003 #include "language.h"
00004 #include "mainerror.h"
00005 #include "mainsession.h"
00006 #include "mutex.h"
00007 #include "mwindow.h"
00008
00009 #include <string.h>
00010
00011
00012
00013
00014 MainError* MainError::main_error = 0;
00015
00016
00017
00018
00019
00020
00021 MainErrorGUI::MainErrorGUI(MWindow *mwindow, MainError *thread, int x, int y)
00022 : BC_Window(PROGRAM_NAME ": Errors",
00023 x,
00024 y,
00025 mwindow->session->ewindow_w,
00026 mwindow->session->ewindow_h,
00027 50,
00028 50,
00029 1,
00030 0,
00031 1,
00032 -1,
00033 "",
00034 1)
00035 {
00036 this->mwindow = mwindow;
00037 this->thread = thread;
00038 }
00039
00040 MainErrorGUI::~MainErrorGUI()
00041 {
00042 }
00043
00044 void MainErrorGUI::create_objects()
00045 {
00046 SET_TRACE
00047
00048 BC_Button *button;
00049 add_subwindow(button = new BC_OKButton(this));
00050 int x = 10, y = 10;
00051 SET_TRACE
00052 add_subwindow(title = new BC_Title(x, y, _("The following errors occurred:")));
00053 y += title->get_h() + 5;
00054 SET_TRACE
00055 add_subwindow(list = new BC_ListBox(x,
00056 y,
00057 get_w() - 20,
00058 button->get_y() - y - 5,
00059 LISTBOX_TEXT,
00060 &thread->errors,
00061 0,
00062 0,
00063 1,
00064 0,
00065 0,
00066 LISTBOX_SINGLE,
00067 ICON_LEFT,
00068 0));
00069 SET_TRACE
00070 show_window();
00071 SET_TRACE
00072 }
00073
00074 int MainErrorGUI::resize_event(int w, int h)
00075 {
00076 title->reposition_window(title->get_x(), title->get_y());
00077 int list_h = h -
00078 list->get_y() -
00079 (get_h() - list->get_y() - list->get_h());
00080 int list_w = w -
00081 list->get_x() -
00082 (get_w() - list->get_x() - list->get_w());
00083 list->reposition_window(list->get_x(),
00084 list->get_y(),
00085 list_w,
00086 list_h);
00087 mwindow->session->ewindow_w = w;
00088 mwindow->session->ewindow_h = h;
00089 return 1;
00090 }
00091
00092
00093
00094
00095
00096
00097 MainError::MainError(MWindow *mwindow)
00098 : BC_DialogThread()
00099 {
00100 this->mwindow = mwindow;
00101 errors_lock = new Mutex("MainError::errors_lock");
00102 main_error = this;
00103 }
00104
00105 MainError::~MainError()
00106 {
00107 delete errors_lock;
00108 }
00109
00110 BC_Window* MainError::new_gui()
00111 {
00112 BC_DisplayInfo display_info;
00113 int x = display_info.get_abs_cursor_x();
00114 int y = display_info.get_abs_cursor_y();
00115
00116 MainErrorGUI *gui = new MainErrorGUI(mwindow, this, x, y);
00117 gui->create_objects();
00118 return gui;
00119 }
00120
00121 void MainError::append_error(char *string)
00122 {
00123 char *in_ptr = string;
00124 char string2[BCTEXTLEN];
00125 int first_line = 1;
00126 while(*in_ptr)
00127 {
00128 char *out_ptr = string2;
00129
00130 if(!first_line)
00131 {
00132 *out_ptr++ = ' ';
00133 *out_ptr++ = ' ';
00134 }
00135
00136 while(*in_ptr != '\n' &&
00137 *in_ptr)
00138 {
00139 *out_ptr++ = *in_ptr++;
00140 }
00141 *out_ptr++ = 0;
00142
00143 errors.append(new BC_ListBoxItem(string2));
00144
00145 if(*in_ptr == '\n')
00146 {
00147 in_ptr++;
00148 first_line = 0;
00149 }
00150 }
00151 }
00152
00153 void MainError::show_error_local(char *string)
00154 {
00155 SET_TRACE
00156
00157 lock_window("MainError::show_error_local");
00158 SET_TRACE
00159 if(get_gui())
00160 {
00161 SET_TRACE
00162 MainErrorGUI *gui = (MainErrorGUI*)get_gui();
00163 gui->lock_window("MainError::show_error_local");
00164 SET_TRACE
00165 append_error(string);
00166 SET_TRACE
00167 gui->list->update(&errors,
00168 0,
00169 0,
00170 1,
00171 gui->list->get_xposition(),
00172 gui->list->get_yposition(),
00173 gui->list->get_highlighted_item(),
00174 0,
00175 1);
00176 SET_TRACE
00177 gui->unlock_window();
00178 unlock_window();
00179 SET_TRACE
00180 start();
00181 SET_TRACE
00182 }
00183 else
00184 {
00185 unlock_window();
00186 SET_TRACE
00187 errors.remove_all_objects();
00188 SET_TRACE
00189 append_error(string);
00190 SET_TRACE
00191 start();
00192 SET_TRACE
00193 }
00194 }
00195
00196
00197 void MainError::show_error(char *string)
00198 {
00199 if(main_error)
00200 main_error->show_error_local(string);
00201 else
00202 {
00203 printf("%s", string);
00204 if(string[strlen(string) - 1] != '\n')
00205 printf("\n");
00206 }
00207 }
00208
00209
00210
00211
00212
00213
00214