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