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