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