cut with active speed auto correction, add locale pref, mod prores dft profile to...
[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->locale, mwindow->preferences->locale) ||
241             strcmp(preferences->plugin_icons, mwindow->preferences->plugin_icons) ||
242             preferences->awindow_picon_h != mwindow->preferences->awindow_picon_h ||
243             preferences->layout_scale != mwindow->preferences->layout_scale ||
244             preferences->vicon_size != mwindow->preferences->vicon_size ||
245             preferences->vicon_color_mode != mwindow->preferences->vicon_color_mode )
246                 mwindow->restart_status = -1;  // reconstruct/restart program
247         if( strcmp(preferences->lv2_path, mwindow->preferences->lv2_path) != 0 )
248                 reload_plugins = 1;
249         if( reload_plugins ) {
250                 MWindow::remove_plugin_index();
251                 File::setenv_path("LV2_PATH", preferences->lv2_path, 1);
252                 mwindow->restart_status = -1;
253         }
254
255         if( mwindow->preferences->perpetual_session && !preferences->perpetual_session )
256                 mwindow->remove_undo_data();
257
258         mwindow->edl->copy_session(edl, 1);
259         mwindow->update_preferences(preferences);
260
261         BC_Signals::set_catch_segv(mwindow->preferences->trap_sigsegv);
262         BC_Signals::set_catch_intr(mwindow->preferences->trap_sigintr);
263         BC_WindowBase::get_resources()->popupmenu_btnup = mwindow->preferences->popupmenu_btnup;
264         BC_WindowBase::get_resources()->grab_input_focus = mwindow->preferences->grab_input_focus;
265         BC_WindowBase::get_resources()->textbox_focus_policy = mwindow->preferences->textbox_focus_policy;
266         if( mwindow->preferences->trap_sigsegv || mwindow->preferences->trap_sigintr ) {
267                 BC_Trace::enable_locks();
268         }
269         else {
270                 BC_Trace::disable_locks();
271         }
272
273         mwindow->reset_android_remote();
274         int ffmpeg_early_probe = mwindow->preferences->get_file_probe_armed("FFMPEG_Early");
275         mwindow->gui->ffmpeg_toggle->update(ffmpeg_early_probe);
276         mwindow->gui->ffmpeg_toggle->set_tooltip(ffmpeg_early_probe ?
277                 FFMPEG_EARLY_TIP : FFMPEG_LATE_TIP);
278         mwindow->gui->mainshbtns->load(mwindow->preferences);
279         mwindow->init_brender();
280
281 //edl->session->recording_format->dump();
282 //mwindow->edl->session->recording_format->dump();
283 #ifdef GLx4
284         if(((mwindow->edl->session->output_w % 4) ||
285                 (mwindow->edl->session->output_h % 4)) &&
286                 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
287         {
288                 MainError::show_error(
289                         _("This project's dimensions are not multiples of 4 so\n"
290                         "it can't be rendered by OpenGL."));
291         }
292 #endif
293
294         if(redraw_meters)
295         {
296                 mwindow->cwindow->gui->lock_window("PreferencesThread::apply_settings");
297                 mwindow->cwindow->gui->meters->change_format(edl->session->meter_format,
298                         edl->session->min_meter_db,
299                         edl->session->max_meter_db);
300                 mwindow->cwindow->gui->unlock_window();
301
302
303
304                 for(int i = 0; i < mwindow->vwindows.size(); i++) {
305                         VWindow *vwindow = mwindow->vwindows.get(i);
306                         if( !vwindow->is_running() ) continue;
307                         vwindow->gui->lock_window("PreferencesThread::apply_settings");
308                         vwindow->gui->meters->change_format(edl->session->meter_format,
309                                 edl->session->min_meter_db,
310                                 edl->session->max_meter_db);
311                         vwindow->gui->unlock_window();
312
313                 }
314
315
316                 mwindow->gui->lock_window("PreferencesThread::apply_settings 1");
317                 mwindow->gui->set_meter_format(edl->session->meter_format,
318                         edl->session->min_meter_db,
319                         edl->session->max_meter_db);
320                 mwindow->gui->unlock_window();
321
322
323
324                 mwindow->lwindow->gui->lock_window("PreferencesThread::apply_settings");
325                 mwindow->lwindow->gui->panel->change_format(edl->session->meter_format,
326                         edl->session->min_meter_db,
327                         edl->session->max_meter_db);
328                 mwindow->lwindow->gui->unlock_window();
329         }
330
331         if(redraw_overlays)
332         {
333                 mwindow->gui->lock_window("PreferencesThread::apply_settings 2");
334                 mwindow->gui->show_cursor(0);
335                 mwindow->gui->draw_overlays(1);
336                 mwindow->gui->unlock_window();
337         }
338
339         if(redraw_times)
340         {
341                 mwindow->gui->lock_window("PreferencesThread::apply_settings 3");
342                 mwindow->gui->update(0, NO_DRAW, 1, 0, 0, 1, 0);
343                 mwindow->gui->redraw_time_dependancies();
344                 mwindow->gui->unlock_window();
345         }
346
347         if(rerender)
348         {
349 //printf("PreferencesThread::apply_settings 1\n");
350 // This doesn't stop and restart, only reloads the assets before
351 // the next play command.
352                 mwindow->cwindow->refresh_frame(CHANGE_ALL, mwindow->edl);
353 //printf("PreferencesThread::apply_settings 10\n");
354         }
355
356         if(redraw_indexes)
357         {
358                 mwindow->gui->lock_window("PreferencesThread::apply_settings 4");
359                 mwindow->gui->draw_trackmovement();
360                 mwindow->gui->unlock_window();
361         }
362
363         if(redraw_times || redraw_overlays || redraw_indexes)
364         {
365                 mwindow->gui->lock_window("PreferencesThread::apply_settings 5");
366                 mwindow->gui->flush();
367                 mwindow->gui->unlock_window();
368         }
369
370         return 0;
371 }
372
373 const char *PreferencesThread::busy()
374 {
375         if( mwindow->render->thread->running() )
376                 return _("render");
377         Record *record = mwindow->gui->record;
378         if( record->capturing || record->recording || record->writing_file )
379                 return _("record");
380         return 0;
381 }
382
383 const char* PreferencesThread::category_to_text(int category)
384 {
385         PlaybackConfig *playback_config = edl->session->playback_config;
386         switch(category)
387         {
388                 case PLAYBACK_A:
389                         return playback_config->active_config==0 ?
390                                  _("*Playback A") : _("Playback A");
391                 case PLAYBACK_B:
392                         return playback_config->active_config==1 ?
393                                  _("*Playback B") : _("Playback B");
394                 case RECORD:
395                         return _("Recording");
396                 case PERFORMANCE:
397                         return _("Performance");
398                 case INTERFACE:
399                         return _("Interface");
400                 case APPEARANCE:
401                         return _("Appearance");
402                 case ABOUT:
403                         return _("About");
404         }
405         return "";
406 }
407
408 int PreferencesThread::text_to_category(const char *category)
409 {
410 SET_TRACE
411         int min_result = -1, result, result_num = 0;
412         for(int i = 0; i < CATEGORIES; i++)
413         {
414                 result = labs(strcmp(category_to_text(i), category));
415                 if(result < min_result || min_result < 0)
416                 {
417                         min_result = result;
418                         result_num = i;
419                 }
420         }
421 SET_TRACE
422         return result_num;
423 }
424
425
426 PreferencesWindow::PreferencesWindow(MWindow *mwindow,
427         PreferencesThread *thread, int x, int y, int w, int h)
428  : BC_Window(_(PROGRAM_NAME ": Preferences"), x,y, w,h,w,h, 1)
429 {
430         this->mwindow = mwindow;
431         this->thread = thread;
432         category = 0;
433         dialog = 0;
434         confirm_dialog = 0;
435 }
436
437 PreferencesWindow::~PreferencesWindow()
438 {
439         lock_window("PreferencesWindow::~PreferencesWindow");
440         delete category;
441         delete dialog;
442         delete confirm_dialog;
443         for(int i = 0; i < categories.total; i++)
444                 delete categories.values[i];
445         unlock_window();
446 }
447
448 void PreferencesWindow::create_objects()
449 {
450         BC_Button *button;
451
452         lock_window("PreferencesWindow::create_objects");
453         set_icon(mwindow->theme->get_image("mwindow_icon"));
454         mwindow->theme->draw_preferences_bg(this);
455         flash();
456
457         int x = mwindow->theme->preferencescategory_x;
458         int y = mwindow->theme->preferencescategory_y;
459         for(int i = 0; i < CATEGORIES; i++)
460         {
461                 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
462                         thread, x, y, i, thread->category_to_text(i),
463                         (i == thread->current_dialog) ?
464                                 mwindow->theme->get_image_set("category_button_checked") :
465                                 mwindow->theme->get_image_set("category_button")));
466                 x += category_button[i]->get_w() -
467                         mwindow->theme->preferences_category_overlap;
468         }
469
470
471 //      for(int i = 0; i < CATEGORIES; i++)
472 //              categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
473 //      category = new PreferencesCategory(mwindow,
474 //              thread,
475 //              mwindow->theme->preferencescategory_x,
476 //              mwindow->theme->preferencescategory_y);
477 //      category->create_objects();
478
479
480         add_subwindow(button = new PreferencesOK(mwindow, thread));
481         add_subwindow(new PreferencesApply(mwindow, thread));
482         add_subwindow(new PreferencesCancel(mwindow, thread));
483
484         set_current_dialog(thread->current_dialog);
485
486         show_window();
487         unlock_window();
488 }
489
490 int PreferencesWindow::update_framerate()
491 {
492         lock_window("PreferencesWindow::update_framerate");
493         if(thread->current_dialog < PreferencesThread::RECORD)
494         {
495                 dialog->draw_framerate(1);
496 //              flash();
497         }
498         unlock_window();
499         return 0;
500 }
501
502
503 void PreferencesWindow::update_rates()
504 {
505         lock_window("PreferencesWindow::update_rates");
506         if(thread->current_dialog == PreferencesThread::PERFORMANCE)
507         {
508                 dialog->update_rates();
509         }
510         unlock_window();
511 }
512
513 void PreferencesWindow::confirm_update(const char *reason, int close)
514 {
515         delete confirm_dialog;
516         confirm_dialog = new PreferencesConfirmDialog(thread, reason, close);
517         confirm_dialog->start();
518 }
519
520
521 int PreferencesWindow::set_current_dialog(int number)
522 {
523         if(dialog) delete dialog;
524         dialog = 0;
525         thread->current_dialog = number;
526
527 //PRINT_TRACE
528         PreferencesDialog *dialog2 = dialog;
529         dialog = 0;
530 //PRINT_TRACE
531
532 // Redraw category buttons
533         for(int i = 0; i < CATEGORIES; i++)
534         {
535                 if(i == number)
536                 {
537                         category_button[i]->set_images(
538                                 mwindow->theme->get_image_set("category_button_checked"));
539                 }
540                 else
541                 {
542                         category_button[i]->set_images(
543                                 mwindow->theme->get_image_set("category_button"));
544                 }
545                 category_button[i]->draw_face(0);
546
547 // Copy face to background for next button's overlap.
548 // Still can't do state changes right.
549         }
550
551
552 //PRINT_TRACE
553         PlaybackConfig *playback_config = thread->edl->session->playback_config;
554         switch(number)
555         {
556                 case PreferencesThread::PLAYBACK_A:
557                 case PreferencesThread::PLAYBACK_B:
558                         playback_config->load_defaults(mwindow->defaults,
559                                 number == PreferencesThread::PLAYBACK_A ? 0 : 1);
560                         add_subwindow(dialog = new PlaybackPrefs(mwindow, this, number));
561                         break;
562
563                 case PreferencesThread::RECORD:
564                         add_subwindow(dialog = new RecordPrefs(mwindow, this));
565                         break;
566
567                 case PreferencesThread::PERFORMANCE:
568                         add_subwindow(dialog = new PerformancePrefs(mwindow, this));
569                         break;
570
571                 case PreferencesThread::INTERFACE:
572                         add_subwindow(dialog = new InterfacePrefs(mwindow, this));
573                         break;
574
575                 case PreferencesThread::APPEARANCE:
576                         add_subwindow(dialog = new AppearancePrefs(mwindow, this));
577                         break;
578
579                 case PreferencesThread::ABOUT:
580                         add_subwindow(dialog = new AboutPrefs(mwindow, this));
581                         break;
582         }
583
584 //PRINT_TRACE
585         if(dialog)
586         {
587                 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
588 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
589                 dialog->create_objects();
590 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
591                 dialog->lower_window();
592                 dialog->show_window(0);
593         }
594
595         if(dialog2)
596         {
597                 dialog2->hide_window(0);
598                 delete dialog2;
599         }
600
601         return 0;
602 }
603
604
605 PreferencesButton::PreferencesButton(MWindow *mwindow,
606         PreferencesThread *thread,
607         int x,
608         int y,
609         int category,
610         const char *text,
611         VFrame **images)
612  : BC_GenericButton(x, y, text, images)
613 {
614         this->mwindow = mwindow;
615         this->thread = thread;
616         this->category = category;
617 }
618
619 int PreferencesButton::handle_event()
620 {
621         thread->window->set_current_dialog(category);
622         return 1;
623 }
624
625
626 PreferencesDialog::PreferencesDialog(MWindow *mwindow,
627         PreferencesWindow *pwindow)
628  : BC_SubWindow(xS(10), yS(40),
629         pwindow->get_w() - xS(20),
630         pwindow->get_h() - BC_GenericButton::calculate_h() - yS(10 + 40))
631 {
632         this->pwindow = pwindow;
633         this->mwindow = mwindow;
634         preferences = pwindow->thread->preferences;
635 }
636
637 PreferencesDialog::~PreferencesDialog()
638 {
639 }
640
641
642 // ============================== category window
643
644 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
645  : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
646         thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
647         _("Apply"))
648 {
649         this->mwindow = mwindow;
650         this->thread = thread;
651 }
652 int PreferencesApply::handle_event()
653 {
654         const char *reason = thread->busy();
655         if( reason )
656                 thread->window->confirm_update(reason, 0);
657         else {
658                 thread->apply_settings();
659                 mwindow->save_defaults();
660         }
661         return 1;
662 }
663 int PreferencesApply::resize_event(int w, int h)
664 {
665         reposition_window(w/2 - get_w()/2, h-get_h()-yS(10));
666         return 1;
667 }
668
669
670 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
671  : BC_GenericButton(xS(10),
672         thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
673         _("OK"))
674 {
675         this->mwindow = mwindow;
676         this->thread = thread;
677 }
678 PreferencesOK::~PreferencesOK()
679 {
680 }
681
682 int PreferencesOK::keypress_event()
683 {
684         if( get_keypress() == RETURN )
685                 return handle_event();
686         return 0;
687 }
688
689 int PreferencesOK::handle_event()
690 {
691         const char *reason = mwindow->restart() ? _("restart") : thread->busy();
692         if( reason )
693                 thread->window->confirm_update(reason, 1);
694         else
695                 thread->window->set_done(0);
696         return 1;
697 }
698 int PreferencesOK::resize_event(int w, int h)
699 {
700         reposition_window(xS(10), h-get_h()-yS(10));
701         return 1;
702 }
703
704
705 PreferencesConfirmDialog::PreferencesConfirmDialog(PreferencesThread *thread,
706                 const char *reason, int close)
707 {
708         this->thread = thread;
709         this->close = close;
710         sprintf(query, _("Busy: %s in progress. Are you sure?"), reason);
711 }
712 PreferencesConfirmDialog::~PreferencesConfirmDialog()
713 {
714         close_window();
715 }
716 BC_Window *PreferencesConfirmDialog::new_gui()
717 {
718         qwindow = new PreferencesConfirmWindow(this);
719         qwindow->create_objects(query, 0);
720         return qwindow;
721 }
722 void PreferencesConfirmDialog::handle_done_event(int result)
723 {
724         if( result != 2 ) return; // not yes
725         if( !close ) {
726                 thread->window->lock_window("PreferencesConfirmDialog::handle_done_event");
727                 thread->apply_settings();
728                 thread->mwindow->save_defaults();
729                 thread->window->unlock_window();
730         }
731         else
732                 thread->window->set_done(0);
733 }
734
735 PreferencesConfirmWindow::PreferencesConfirmWindow(PreferencesConfirmDialog *dialog)
736  : QuestionWindow(dialog->thread->mwindow)
737 {
738         this->dialog = dialog;
739 }
740 PreferencesConfirmWindow::~PreferencesConfirmWindow()
741 {
742 }
743
744
745 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
746  : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - xS(10),
747         thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
748         _("Cancel"))
749 {
750         this->mwindow = mwindow;
751         this->thread = thread;
752 }
753 int PreferencesCancel::keypress_event()
754 {
755         if(get_keypress() == ESC)
756         {
757                 thread->window->set_done(1);
758                 return 1;
759         }
760         return 0;
761 }
762 int PreferencesCancel::handle_event()
763 {
764         thread->window->set_done(1);
765         return 1;
766 }
767 int PreferencesCancel::resize_event(int w, int h)
768 {
769         reposition_window(w-get_w()-xS(10), h-get_h()-yS(10));
770         return 1;
771 }
772
773
774 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
775  : BC_PopupTextBox(thread->window,
776                 &thread->window->categories,
777                 thread->category_to_text(thread->current_dialog),
778                 x, y, xS(200), yS(150))
779 {
780         this->mwindow = mwindow;
781         this->thread = thread;
782 }
783
784 PreferencesCategory::~PreferencesCategory()
785 {
786 }
787
788 int PreferencesCategory::handle_event()
789 {
790 SET_TRACE
791         thread->window->set_current_dialog(thread->text_to_category(get_text()));
792 SET_TRACE
793         return 1;
794 }