fix segv for plugin render_gui when plugin moved up/dn, opencv build fixes, opts...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / preferencesthread.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2011 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 "aboutprefs.h"
23 #include "appearanceprefs.h"
24 #include "asset.h"
25 #include "audiodevice.inc"
26 #include "bcsignals.h"
27 #include "bctrace.h"
28 #include "cache.h"
29 #include "cplayback.h"
30 #include "cwindow.h"
31 #include "cwindowgui.h"
32 #include "bchash.h"
33 #include "edl.h"
34 #include "edlsession.h"
35 #include "file.h"
36 #include "filesystem.h"
37 #include "fonts.h"
38 #include "interfaceprefs.h"
39 #include "keys.h"
40 #include "language.h"
41 #include "levelwindow.h"
42 #include "levelwindowgui.h"
43 #include "mainclock.h"
44 #include "mainerror.h"
45 #include "mbuttons.h"
46 #include "meterpanel.h"
47 #include "mutex.h"
48 #include "mwindow.h"
49 #include "mwindowgui.h"
50 #include "patchbay.h"
51 #include "performanceprefs.h"
52 #include "playbackengine.h"
53 #include "playbackprefs.h"
54 #include "preferences.h"
55 #include "record.h"
56 #include "recordprefs.h"
57 #include "render.h"
58 #include "shbtnprefs.h"
59 #include "theme.h"
60 #include "trackcanvas.h"
61 #include "transportque.h"
62 #include "vwindow.h"
63 #include "vwindowgui.h"
64
65 #include <string.h>
66
67
68
69 #define WIDTH xS(860)
70 #define HEIGHT yS(700)
71
72
73 PreferencesMenuitem::PreferencesMenuitem(MWindow *mwindow)
74  : BC_MenuItem(_("Preferences..."), _("Shift-P"), 'P')
75 {
76         this->mwindow = mwindow;
77
78         set_shift(1);
79         thread = new PreferencesThread(mwindow);
80 }
81
82 PreferencesMenuitem::~PreferencesMenuitem()
83 {
84         delete thread;
85 }
86
87
88 int PreferencesMenuitem::handle_event()
89 {
90         mwindow->gui->unlock_window();
91         thread->start();
92         mwindow->gui->lock_window("PreferencesMenuitem::handle_event");
93         return 1;
94 }
95
96
97
98
99 PreferencesThread::PreferencesThread(MWindow *mwindow)
100  : BC_DialogThread()
101 {
102         this->mwindow = mwindow;
103         window = 0;
104         thread_running = 0;
105 }
106
107 PreferencesThread::~PreferencesThread()
108 {
109         close_window();
110 }
111
112 BC_Window* PreferencesThread::new_gui()
113 {
114
115         preferences = new Preferences;
116         edl = new EDL;
117         edl->create_objects();
118         current_dialog = mwindow->defaults->get("DEFAULTPREF", 0);
119         preferences->copy_from(mwindow->preferences);
120         edl->copy_session(mwindow->edl);
121         redraw_indexes = 0;
122         redraw_meters = 0;
123         redraw_times = 0;
124         redraw_overlays = 0;
125         close_assets = 0;
126         reload_plugins = 0;
127         //int need_new_indexes = 0;
128         rerender = 0;
129
130         mwindow->gui->lock_window("NewThread::new_gui");
131         int scr_x = mwindow->gui->get_screen_x(0, -1);
132         int scr_w = mwindow->gui->get_screen_w(0, -1);
133         int scr_h = mwindow->gui->get_screen_h(0, -1);
134
135         int w = WIDTH, h = HEIGHT;
136         int min_w = mwindow->theme->preferencescategory_x;
137         for(int i = 0; i < CATEGORIES; i++) {
138                 min_w += PreferencesButton::calculate_w(mwindow->gui, category_to_text(i)) -
139                         mwindow->theme->preferences_category_overlap;
140         }
141         if( w < min_w ) w = min_w;
142         int x = scr_x + scr_w / 2 - w / 2;
143         int y = scr_h / 2 - h / 2;
144
145         window = new PreferencesWindow(mwindow, this, x, y, w, h);
146         window->create_objects();
147         mwindow->gui->unlock_window();
148
149         thread_running = 1;
150         return window;
151 }
152
153 void PreferencesThread::handle_close_event(int result)
154 {
155         thread_running = 0;
156         if(!result)
157         {
158                 apply_settings();
159                 mwindow->save_defaults();
160         }
161
162         window = 0;
163         delete preferences;
164         edl->Garbage::remove_user();
165         preferences = 0;
166         edl = 0;
167
168         mwindow->defaults->update("DEFAULTPREF", current_dialog);
169         if( mwindow->restart() )
170                 mwindow->gui->set_done(0);
171 }
172
173
174
175 int PreferencesThread::update_framerate()
176 {
177         if(thread_running)
178         {
179                 lock_dialog("PreferencesThread::update_framerate");
180                 PreferencesWindow *window = (PreferencesWindow*)get_gui();
181                 if(window) window->update_framerate();
182                 unlock_dialog();
183         }
184         return 0;
185 }
186
187
188 void PreferencesThread::update_rates()
189 {
190         if(thread_running)
191         {
192                 lock_dialog("PreferencesThread::update_framerate");
193                 PreferencesWindow *window = (PreferencesWindow*)get_gui();
194                 if(window) window->update_rates();
195                 unlock_dialog();
196         }
197 }
198
199 int PreferencesThread::apply_settings()
200 {
201 // Compare sessions
202
203         PlaybackConfig *this_playback_config = edl->session->playback_config;
204         AudioOutConfig *this_aconfig = this_playback_config->aconfig;
205         VideoOutConfig *this_vconfig = this_playback_config->vconfig;
206         PlaybackConfig *playback_config = mwindow->edl->session->playback_config;
207         AudioOutConfig *aconfig = playback_config->aconfig;
208         VideoOutConfig *vconfig = playback_config->vconfig;
209
210         rerender =
211                 edl->session->need_rerender(mwindow->edl->session) ||
212                 (preferences->force_uniprocessor != mwindow->preferences->force_uniprocessor) ||
213                 this_playback_config->active_config != playback_config->active_config ||
214                 (*this_aconfig != *aconfig) || (*this_vconfig != *vconfig) ||
215                 !preferences->brender_asset->equivalent(*mwindow->preferences->brender_asset, 0, 1, edl);
216
217         if( preferences->autocolor_assets != mwindow->preferences->autocolor_assets )
218                 redraw_indexes = 1;
219
220         if( preferences->yuv_color_space != mwindow->preferences->yuv_color_space ||
221             preferences->yuv_color_range != mwindow->preferences->yuv_color_range ) {
222                 YUV::yuv.yuv_set_colors(
223                         preferences->yuv_color_space,
224                         preferences->yuv_color_range);
225                 rerender = 1;
226         }
227
228         if( preferences->highlight_inverse != mwindow->preferences->highlight_inverse ) {
229                 mwindow->gui->lock_window("PreferencesThread::apply_settings 0");
230                 mwindow->gui->hide_cursor(0);
231                 mwindow->gui->unlock_window();
232                 redraw_overlays = 1;
233         }
234         PreferencesWindow *window = (PreferencesWindow*)get_gui();
235         if( window ) window->unlock_window();
236         mwindow->stop_brender();
237         if( window ) window->lock_window("PreferencesThread::apply_settings 5");
238
239         if( strcmp(preferences->theme, mwindow->preferences->theme) ||
240             strcmp(preferences->plugin_icons, mwindow->preferences->plugin_icons) ||
241             preferences->awindow_picon_h != mwindow->preferences->awindow_picon_h ||
242             preferences->layout_scale != mwindow->preferences->layout_scale ||
243             preferences->vicon_size != mwindow->preferences->vicon_size ||
244             preferences->vicon_color_mode != mwindow->preferences->vicon_color_mode )
245                 mwindow->restart_status = -1;  // reconstruct/restart program
246         if( strcmp(preferences->lv2_path, mwindow->preferences->lv2_path) != 0 )
247                 reload_plugins = 1;
248         if( reload_plugins ) {
249                 MWindow::remove_plugin_index();
250                 File::setenv_path("LV2_PATH", preferences->lv2_path, 1);
251                 mwindow->restart_status = -1;
252         }
253
254         mwindow->edl->copy_session(edl, 1);
255         mwindow->preferences->copy_from(preferences);
256
257         BC_Signals::set_catch_segv(mwindow->preferences->trap_sigsegv);
258         BC_Signals::set_catch_intr(mwindow->preferences->trap_sigintr);
259         BC_WindowBase::get_resources()->popupmenu_btnup = mwindow->preferences->popupmenu_btnup;
260         BC_WindowBase::get_resources()->grab_input_focus = mwindow->preferences->grab_input_focus;
261         BC_WindowBase::get_resources()->textbox_focus_policy = mwindow->preferences->textbox_focus_policy;
262         if( mwindow->preferences->trap_sigsegv || mwindow->preferences->trap_sigintr ) {
263                 BC_Trace::enable_locks();
264         }
265         else {
266                 BC_Trace::disable_locks();
267         }
268
269         mwindow->reset_android_remote();
270         int ffmpeg_early_probe = mwindow->preferences->get_file_probe_armed("FFMPEG_Early");
271         mwindow->gui->ffmpeg_toggle->update(ffmpeg_early_probe);
272         mwindow->gui->ffmpeg_toggle->set_tooltip(ffmpeg_early_probe ?
273                 FFMPEG_EARLY_TIP : FFMPEG_LATE_TIP);
274         mwindow->gui->mainshbtns->load(mwindow->preferences);
275         mwindow->init_brender();
276
277 //edl->session->recording_format->dump();
278 //mwindow->edl->session->recording_format->dump();
279 #ifdef GLx4
280         if(((mwindow->edl->session->output_w % 4) ||
281                 (mwindow->edl->session->output_h % 4)) &&
282                 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
283         {
284                 MainError::show_error(
285                         _("This project's dimensions are not multiples of 4 so\n"
286                         "it can't be rendered by OpenGL."));
287         }
288 #endif
289
290         if(redraw_meters)
291         {
292                 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
293                 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
294                         edl->session->min_meter_db,
295                         edl->session->max_meter_db);
296                 mwindow->cwindow->gui->unlock_window();
297
298
299
300                 for(int i = 0; i < mwindow->vwindows.size(); i++) {
301                         VWindow *vwindow = mwindow->vwindows.get(i);
302                         if( !vwindow->is_running() ) continue;
303                         vwindow->gui->lock_window("PreferencesThread::apply_settings");
304                         vwindow->gui->meters->change_format(edl->session->meter_format,
305                                 edl->session->min_meter_db,
306                                 edl->session->max_meter_db);
307                         vwindow->gui->unlock_window();
308
309                 }
310
311
312                 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
313                 mwindow->gui->set_meter_format(edl->session->meter_format,
314                         edl->session->min_meter_db,
315                         edl->session->max_meter_db);
316                 mwindow->gui->unlock_window();
317
318
319
320                 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
321                 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
322                         edl->session->min_meter_db,
323                         edl->session->max_meter_db);
324                 mwindow->lwindow->gui->unlock_window();
325         }
326
327         if(redraw_overlays)
328         {
329                 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
330                 mwindow->gui->show_cursor(0);
331                 mwindow->gui->draw_overlays(1);
332                 mwindow->gui->unlock_window();
333         }
334
335         if(redraw_times)
336         {
337                 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
338                 mwindow->gui->update(0, NO_DRAW, 1, 0, 0, 1, 0);
339                 mwindow->gui->redraw_time_dependancies();
340                 mwindow->gui->unlock_window();
341         }
342
343         if(rerender)
344         {
345 //printf("PreferencesThread::apply_settings 1\n");
346 // This doesn't stop and restart, only reloads the assets before
347 // the next play command.
348                 mwindow->cwindow->refresh_frame(CHANGE_ALL, mwindow->edl);
349 //printf("PreferencesThread::apply_settings 10\n");
350         }
351
352         if(redraw_indexes)
353         {
354                 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
355                 mwindow->gui->draw_trackmovement();
356                 mwindow->gui->unlock_window();
357         }
358
359         if(redraw_times || redraw_overlays || redraw_indexes)
360         {
361                 mwindow->gui->lock_window("PreferencesThread::apply_settings 5");
362                 mwindow->gui->flush();
363                 mwindow->gui->unlock_window();
364         }
365
366         return 0;
367 }
368
369 const char *PreferencesThread::busy()
370 {
371         if( mwindow->render->thread->running() )
372                 return _("render");
373         Record *record = mwindow->gui->record;
374         if( record->capturing || record->recording || record->writing_file )
375                 return _("record");
376         return 0;
377 }
378
379 const char* PreferencesThread::category_to_text(int category)
380 {
381         PlaybackConfig *playback_config = edl->session->playback_config;
382         switch(category)
383         {
384                 case PLAYBACK_A:
385                         return playback_config->active_config==0 ?
386                                  _("*Playback A") : _("Playback A");
387                 case PLAYBACK_B:
388                         return playback_config->active_config==1 ?
389                                  _("*Playback B") : _("Playback B");
390                 case RECORD:
391                         return _("Recording");
392                 case PERFORMANCE:
393                         return _("Performance");
394                 case INTERFACE:
395                         return _("Interface");
396                 case APPEARANCE:
397                         return _("Appearance");
398                 case ABOUT:
399                         return _("About");
400         }
401         return "";
402 }
403
404 int PreferencesThread::text_to_category(const char *category)
405 {
406 SET_TRACE
407         int min_result = -1, result, result_num = 0;
408         for(int i = 0; i < CATEGORIES; i++)
409         {
410                 result = labs(strcmp(category_to_text(i), category));
411                 if(result < min_result || min_result < 0)
412                 {
413                         min_result = result;
414                         result_num = i;
415                 }
416         }
417 SET_TRACE
418         return result_num;
419 }
420
421
422 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
423         PreferencesThread *thread, int x, int y, int w, int h)
424  : BC_Window(_(PROGRAM_NAME ": Preferences"), x,y, w,h,w,h, 1)
425 {
426         this->mwindow = mwindow;
427         this->thread = thread;
428         category = 0;
429         dialog = 0;
430         confirm_dialog = 0;
431 }
432
433 PreferencesWindow::~PreferencesWindow()
434 {
435         lock_window("PreferencesWindow::~PreferencesWindow");
436         delete category;
437         delete dialog;
438         delete confirm_dialog;
439         for(int i = 0; i < categories.total; i++)
440                 delete categories.values[i];
441         unlock_window();
442 }
443
444 void PreferencesWindow::create_objects()
445 {
446         BC_Button *button;
447
448         lock_window("PreferencesWindow::create_objects");
449         set_icon(mwindow->theme->get_image("mwindow_icon"));
450         mwindow->theme->draw_preferences_bg(this);
451         flash();
452
453         int x = mwindow->theme->preferencescategory_x;
454         int y = mwindow->theme->preferencescategory_y;
455         for(int i = 0; i < CATEGORIES; i++)
456         {
457                 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
458                         thread, x, y, i, thread->category_to_text(i),
459                         (i == thread->current_dialog) ?
460                                 mwindow->theme->get_image_set("category_button_checked") :
461                                 mwindow->theme->get_image_set("category_button")));
462                 x += category_button[i]->get_w() -
463                         mwindow->theme->preferences_category_overlap;
464         }
465
466
467 //      for(int i = 0; i < CATEGORIES; i++)
468 //              categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
469 //      category = new PreferencesCategory(mwindow,
470 //              thread,
471 //              mwindow->theme->preferencescategory_x,
472 //              mwindow->theme->preferencescategory_y);
473 //      category->create_objects();
474
475
476         add_subwindow(button = new PreferencesOK(mwindow, thread));
477         add_subwindow(new PreferencesApply(mwindow, thread));
478         add_subwindow(new PreferencesCancel(mwindow, thread));
479
480         set_current_dialog(thread->current_dialog);
481
482         show_window();
483         unlock_window();
484 }
485
486 int PreferencesWindow::update_framerate()
487 {
488         lock_window("PreferencesWindow::update_framerate");
489         if(thread->current_dialog < PreferencesThread::RECORD)
490         {
491                 dialog->draw_framerate(1);
492 //              flash();
493         }
494         unlock_window();
495         return 0;
496 }
497
498
499 void PreferencesWindow::update_rates()
500 {
501         lock_window("PreferencesWindow::update_rates");
502         if(thread->current_dialog == PreferencesThread::PERFORMANCE)
503         {
504                 dialog->update_rates();
505         }
506         unlock_window();
507 }
508
509 void PreferencesWindow::confirm_update(const char *reason, int close)
510 {
511         delete confirm_dialog;
512         confirm_dialog = new PreferencesConfirmDialog(thread, reason, close);
513         confirm_dialog->start();
514 }
515
516
517 int PreferencesWindow::set_current_dialog(int number)
518 {
519         if(dialog) delete dialog;
520         dialog = 0;
521         thread->current_dialog = number;
522
523 //PRINT_TRACE
524         PreferencesDialog *dialog2 = dialog;
525         dialog = 0;
526 //PRINT_TRACE
527
528 // Redraw category buttons
529         for(int i = 0; i < CATEGORIES; i++)
530         {
531                 if(i == number)
532                 {
533                         category_button[i]->set_images(
534                                 mwindow->theme->get_image_set("category_button_checked"));
535                 }
536                 else
537                 {
538                         category_button[i]->set_images(
539                                 mwindow->theme->get_image_set("category_button"));
540                 }
541                 category_button[i]->draw_face(0);
542
543 // Copy face to background for next button's overlap.
544 // Still can't do state changes right.
545         }
546
547
548 //PRINT_TRACE
549         PlaybackConfig *playback_config = thread->edl->session->playback_config;
550         switch(number)
551         {
552                 case PreferencesThread::PLAYBACK_A:
553                 case PreferencesThread::PLAYBACK_B:
554                         playback_config->load_defaults(mwindow->defaults,
555                                 number == PreferencesThread::PLAYBACK_A ? 0 : 1);
556                         add_subwindow(dialog = new PlaybackPrefs(mwindow, this, number));
557                         break;
558
559                 case PreferencesThread::RECORD:
560                         add_subwindow(dialog = new RecordPrefs(mwindow, this));
561                         break;
562
563                 case PreferencesThread::PERFORMANCE:
564                         add_subwindow(dialog = new PerformancePrefs(mwindow, this));
565                         break;
566
567                 case PreferencesThread::INTERFACE:
568                         add_subwindow(dialog = new InterfacePrefs(mwindow, this));
569                         break;
570
571                 case PreferencesThread::APPEARANCE:
572                         add_subwindow(dialog = new AppearancePrefs(mwindow, this));
573                         break;
574
575                 case PreferencesThread::ABOUT:
576                         add_subwindow(dialog = new AboutPrefs(mwindow, this));
577                         break;
578         }
579
580 //PRINT_TRACE
581         if(dialog)
582         {
583                 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
584 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
585                 dialog->create_objects();
586 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
587                 dialog->lower_window();
588                 dialog->show_window(0);
589         }
590
591         if(dialog2)
592         {
593                 dialog2->hide_window(0);
594                 delete dialog2;
595         }
596
597         return 0;
598 }
599
600
601 PreferencesButton::PreferencesButton(MWindow *mwindow,
602         PreferencesThread *thread,
603         int x,
604         int y,
605         int category,
606         const char *text,
607         VFrame **images)
608  : BC_GenericButton(x, y, text, images)
609 {
610         this->mwindow = mwindow;
611         this->thread = thread;
612         this->category = category;
613 }
614
615 int PreferencesButton::handle_event()
616 {
617         thread->window->set_current_dialog(category);
618         return 1;
619 }
620
621
622 PreferencesDialog::PreferencesDialog(MWindow *mwindow,
623         PreferencesWindow *pwindow)
624  : BC_SubWindow(xS(10), yS(40),
625         pwindow->get_w() - xS(20),
626         pwindow->get_h() - BC_GenericButton::calculate_h() - yS(10 + 40))
627 {
628         this->pwindow = pwindow;
629         this->mwindow = mwindow;
630         preferences = pwindow->thread->preferences;
631 }
632
633 PreferencesDialog::~PreferencesDialog()
634 {
635 }
636
637
638 // ============================== category window
639
640 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
641  : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
642         thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
643         _("Apply"))
644 {
645         this->mwindow = mwindow;
646         this->thread = thread;
647 }
648 int PreferencesApply::handle_event()
649 {
650         const char *reason = thread->busy();
651         if( reason )
652                 thread->window->confirm_update(reason, 0);
653         else {
654                 thread->apply_settings();
655                 mwindow->save_defaults();
656         }
657         return 1;
658 }
659 int PreferencesApply::resize_event(int w, int h)
660 {
661         reposition_window(w/2 - get_w()/2, h-get_h()-yS(10));
662         return 1;
663 }
664
665
666 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
667  : BC_GenericButton(xS(10),
668         thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
669         _("OK"))
670 {
671         this->mwindow = mwindow;
672         this->thread = thread;
673 }
674 PreferencesOK::~PreferencesOK()
675 {
676 }
677
678 int PreferencesOK::keypress_event()
679 {
680         if( get_keypress() == RETURN )
681                 return handle_event();
682         return 0;
683 }
684
685 int PreferencesOK::handle_event()
686 {
687         const char *reason = mwindow->restart() ? _("restart") : thread->busy();
688         if( reason )
689                 thread->window->confirm_update(reason, 1);
690         else
691                 thread->window->set_done(0);
692         return 1;
693 }
694 int PreferencesOK::resize_event(int w, int h)
695 {
696         reposition_window(xS(10), h-get_h()-yS(10));
697         return 1;
698 }
699
700
701 PreferencesConfirmDialog::PreferencesConfirmDialog(PreferencesThread *thread,
702                 const char *reason, int close)
703 {
704         this->thread = thread;
705         this->close = close;
706         sprintf(query, _("Busy: %s in progress. Are you sure?"), reason);
707 }
708 PreferencesConfirmDialog::~PreferencesConfirmDialog()
709 {
710         close_window();
711 }
712 BC_Window *PreferencesConfirmDialog::new_gui()
713 {
714         qwindow = new PreferencesConfirmWindow(this);
715         qwindow->create_objects(query, 0);
716         return qwindow;
717 }
718 void PreferencesConfirmDialog::handle_done_event(int result)
719 {
720         if( result != 2 ) return; // not yes
721         if( !close ) {
722                 thread->window->lock_window("PreferencesConfirmDialog::handle_done_event");
723                 thread->apply_settings();
724                 thread->mwindow->save_defaults();
725                 thread->window->unlock_window();
726         }
727         else
728                 thread->window->set_done(0);
729 }
730
731 PreferencesConfirmWindow::PreferencesConfirmWindow(PreferencesConfirmDialog *dialog)
732  : QuestionWindow(dialog->thread->mwindow)
733 {
734         this->dialog = dialog;
735 }
736 PreferencesConfirmWindow::~PreferencesConfirmWindow()
737 {
738 }
739
740
741 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
742  : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - xS(10),
743         thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
744         _("Cancel"))
745 {
746         this->mwindow = mwindow;
747         this->thread = thread;
748 }
749 int PreferencesCancel::keypress_event()
750 {
751         if(get_keypress() == ESC)
752         {
753                 thread->window->set_done(1);
754                 return 1;
755         }
756         return 0;
757 }
758 int PreferencesCancel::handle_event()
759 {
760         thread->window->set_done(1);
761         return 1;
762 }
763 int PreferencesCancel::resize_event(int w, int h)
764 {
765         reposition_window(w-get_w()-xS(10), h-get_h()-yS(10));
766         return 1;
767 }
768
769
770 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
771  : BC_PopupTextBox(thread->window,
772                 &thread->window->categories,
773                 thread->category_to_text(thread->current_dialog),
774                 x, y, xS(200), yS(150))
775 {
776         this->mwindow = mwindow;
777         this->thread = thread;
778 }
779
780 PreferencesCategory::~PreferencesCategory()
781 {
782 }
783
784 int PreferencesCategory::handle_event()
785 {
786 SET_TRACE
787         thread->window->set_current_dialog(thread->text_to_category(get_text()));
788 SET_TRACE
789         return 1;
790 }