switch move/swap tracks, add mv trk shortcut, update msg
[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 }
444
445 PreferencesWindow::~PreferencesWindow()
446 {
447         lock_window("PreferencesWindow::~PreferencesWindow");
448         delete category;
449         delete dialog;
450         delete confirm_dialog;
451         for(int i = 0; i < categories.total; i++)
452                 delete categories.values[i];
453         unlock_window();
454 }
455
456 void PreferencesWindow::create_objects()
457 {
458         BC_Button *button;
459
460         lock_window("PreferencesWindow::create_objects");
461         set_icon(mwindow->theme->get_image("mwindow_icon"));
462         mwindow->theme->draw_preferences_bg(this);
463         flash();
464
465         int x = mwindow->theme->preferencescategory_x;
466         int y = mwindow->theme->preferencescategory_y;
467         for(int i = 0; i < CATEGORIES; i++)
468         {
469                 add_subwindow(category_button[i] = new PreferencesButton(mwindow,
470                         thread, x, y, i, thread->category_to_text(i),
471                         (i == thread->current_dialog) ?
472                                 mwindow->theme->get_image_set("category_button_checked") :
473                                 mwindow->theme->get_image_set("category_button")));
474                 x += category_button[i]->get_w() -
475                         mwindow->theme->preferences_category_overlap;
476         }
477
478
479 //      for(int i = 0; i < CATEGORIES; i++)
480 //              categories.append(new BC_ListBoxItem(thread->category_to_text(i)));
481 //      category = new PreferencesCategory(mwindow,
482 //              thread,
483 //              mwindow->theme->preferencescategory_x,
484 //              mwindow->theme->preferencescategory_y);
485 //      category->create_objects();
486
487
488         add_subwindow(button = new PreferencesOK(mwindow, thread));
489         add_subwindow(new PreferencesApply(mwindow, thread));
490         add_subwindow(new PreferencesCancel(mwindow, thread));
491
492         set_current_dialog(thread->current_dialog);
493
494         show_window();
495         unlock_window();
496 }
497
498 int PreferencesWindow::update_framerate()
499 {
500         lock_window("PreferencesWindow::update_framerate");
501         if(thread->current_dialog < PreferencesThread::RECORD)
502         {
503                 dialog->draw_framerate(1);
504 //              flash();
505         }
506         unlock_window();
507         return 0;
508 }
509
510
511 void PreferencesWindow::update_rates()
512 {
513         lock_window("PreferencesWindow::update_rates");
514         if(thread->current_dialog == PreferencesThread::PERFORMANCE)
515         {
516                 dialog->update_rates();
517         }
518         unlock_window();
519 }
520
521 void PreferencesWindow::confirm_update(const char *reason, int close)
522 {
523         delete confirm_dialog;
524         confirm_dialog = new PreferencesConfirmDialog(thread, reason, close);
525         confirm_dialog->start();
526 }
527
528
529 int PreferencesWindow::set_current_dialog(int number)
530 {
531         if(dialog) delete dialog;
532         dialog = 0;
533         thread->current_dialog = number;
534
535 //PRINT_TRACE
536         PreferencesDialog *dialog2 = dialog;
537         dialog = 0;
538 //PRINT_TRACE
539
540 // Redraw category buttons
541         for(int i = 0; i < CATEGORIES; i++)
542         {
543                 if(i == number)
544                 {
545                         category_button[i]->set_images(
546                                 mwindow->theme->get_image_set("category_button_checked"));
547                 }
548                 else
549                 {
550                         category_button[i]->set_images(
551                                 mwindow->theme->get_image_set("category_button"));
552                 }
553                 category_button[i]->draw_face(0);
554
555 // Copy face to background for next button's overlap.
556 // Still can't do state changes right.
557         }
558
559
560 //PRINT_TRACE
561         PlaybackConfig *playback_config = thread->edl->session->playback_config;
562         switch(number)
563         {
564                 case PreferencesThread::PLAYBACK_A:
565                 case PreferencesThread::PLAYBACK_B:
566                         playback_config->load_defaults(mwindow->defaults,
567                                 number == PreferencesThread::PLAYBACK_A ? 0 : 1);
568                         add_subwindow(dialog = new PlaybackPrefs(mwindow, this, number));
569                         break;
570
571                 case PreferencesThread::RECORD:
572                         add_subwindow(dialog = new RecordPrefs(mwindow, this));
573                         break;
574
575                 case PreferencesThread::PERFORMANCE:
576                         add_subwindow(dialog = new PerformancePrefs(mwindow, this));
577                         break;
578
579                 case PreferencesThread::INTERFACE:
580                         add_subwindow(dialog = new InterfacePrefs(mwindow, this));
581                         break;
582
583                 case PreferencesThread::APPEARANCE:
584                         add_subwindow(dialog = new AppearancePrefs(mwindow, this));
585                         break;
586
587                 case PreferencesThread::ABOUT:
588                         add_subwindow(dialog = new AboutPrefs(mwindow, this));
589                         break;
590         }
591
592 //PRINT_TRACE
593         if(dialog)
594         {
595                 dialog->draw_top_background(this, 0, 0, dialog->get_w(), dialog->get_h());
596 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
597                 dialog->create_objects();
598 //printf("PreferencesWindow::set_current_dialog %d\n", __LINE__);
599                 dialog->lower_window();
600                 dialog->show_window(0);
601         }
602
603         if(dialog2)
604         {
605                 dialog2->hide_window(0);
606                 delete dialog2;
607         }
608
609         return 0;
610 }
611
612
613 PreferencesButton::PreferencesButton(MWindow *mwindow,
614         PreferencesThread *thread,
615         int x,
616         int y,
617         int category,
618         const char *text,
619         VFrame **images)
620  : BC_GenericButton(x, y, text, images)
621 {
622         this->mwindow = mwindow;
623         this->thread = thread;
624         this->category = category;
625 }
626
627 int PreferencesButton::handle_event()
628 {
629         thread->window->set_current_dialog(category);
630         return 1;
631 }
632
633
634 PreferencesDialog::PreferencesDialog(MWindow *mwindow,
635         PreferencesWindow *pwindow)
636  : BC_SubWindow(xS(10), yS(40),
637         pwindow->get_w() - xS(20),
638         pwindow->get_h() - BC_GenericButton::calculate_h() - yS(10 + 40))
639 {
640         this->pwindow = pwindow;
641         this->mwindow = mwindow;
642         preferences = pwindow->thread->preferences;
643 }
644
645 PreferencesDialog::~PreferencesDialog()
646 {
647 }
648
649
650 // ============================== category window
651
652 PreferencesApply::PreferencesApply(MWindow *mwindow, PreferencesThread *thread)
653  : BC_GenericButton(thread->window->get_w() / 2 - BC_GenericButton::calculate_w(thread->window, _("Apply")) / 2,
654         thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
655         _("Apply"))
656 {
657         this->mwindow = mwindow;
658         this->thread = thread;
659 }
660 int PreferencesApply::handle_event()
661 {
662         const char *reason = thread->busy();
663         if( reason )
664                 thread->window->confirm_update(reason, 0);
665         else {
666                 thread->apply_settings();
667                 mwindow->save_defaults();
668         }
669         return 1;
670 }
671 int PreferencesApply::resize_event(int w, int h)
672 {
673         reposition_window(w/2 - get_w()/2, h-get_h()-yS(10));
674         return 1;
675 }
676
677
678 PreferencesOK::PreferencesOK(MWindow *mwindow, PreferencesThread *thread)
679  : BC_GenericButton(xS(10),
680         thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
681         _("OK"))
682 {
683         this->mwindow = mwindow;
684         this->thread = thread;
685 }
686 PreferencesOK::~PreferencesOK()
687 {
688 }
689
690 int PreferencesOK::keypress_event()
691 {
692         if( get_keypress() == RETURN )
693                 return handle_event();
694         return 0;
695 }
696
697 int PreferencesOK::handle_event()
698 {
699         const char *reason = mwindow->restart() ? _("restart") : thread->busy();
700         if( reason )
701                 thread->window->confirm_update(reason, 1);
702         else
703                 thread->window->set_done(0);
704         return 1;
705 }
706 int PreferencesOK::resize_event(int w, int h)
707 {
708         reposition_window(xS(10), h-get_h()-yS(10));
709         return 1;
710 }
711
712
713 PreferencesConfirmDialog::PreferencesConfirmDialog(PreferencesThread *thread,
714                 const char *reason, int close)
715 {
716         this->thread = thread;
717         this->close = close;
718         sprintf(query, _("Busy: %s in progress. Are you sure?"), reason);
719 }
720 PreferencesConfirmDialog::~PreferencesConfirmDialog()
721 {
722         close_window();
723 }
724 BC_Window *PreferencesConfirmDialog::new_gui()
725 {
726         qwindow = new PreferencesConfirmWindow(this);
727         qwindow->create_objects(query, 0);
728         return qwindow;
729 }
730 void PreferencesConfirmDialog::handle_done_event(int result)
731 {
732         if( result != 2 ) return; // not yes
733         if( !close ) {
734                 thread->window->lock_window("PreferencesConfirmDialog::handle_done_event");
735                 thread->apply_settings();
736                 thread->mwindow->save_defaults();
737                 thread->window->unlock_window();
738         }
739         else
740                 thread->window->set_done(0);
741 }
742
743 PreferencesConfirmWindow::PreferencesConfirmWindow(PreferencesConfirmDialog *dialog)
744  : QuestionWindow(dialog->thread->mwindow)
745 {
746         this->dialog = dialog;
747 }
748 PreferencesConfirmWindow::~PreferencesConfirmWindow()
749 {
750 }
751
752
753 PreferencesCancel::PreferencesCancel(MWindow *mwindow, PreferencesThread *thread)
754  : BC_GenericButton(thread->window->get_w() - BC_GenericButton::calculate_w(thread->window, _("Cancel")) - xS(10),
755         thread->window->get_h() - BC_GenericButton::calculate_h() - yS(10),
756         _("Cancel"))
757 {
758         this->mwindow = mwindow;
759         this->thread = thread;
760 }
761 int PreferencesCancel::keypress_event()
762 {
763         if(get_keypress() == ESC)
764         {
765                 thread->window->set_done(1);
766                 return 1;
767         }
768         return 0;
769 }
770 int PreferencesCancel::handle_event()
771 {
772         thread->window->set_done(1);
773         return 1;
774 }
775 int PreferencesCancel::resize_event(int w, int h)
776 {
777         reposition_window(w-get_w()-xS(10), h-get_h()-yS(10));
778         return 1;
779 }
780
781
782 PreferencesCategory::PreferencesCategory(MWindow *mwindow, PreferencesThread *thread, int x, int y)
783  : BC_PopupTextBox(thread->window,
784                 &thread->window->categories,
785                 thread->category_to_text(thread->current_dialog),
786                 x, y, xS(200), yS(150))
787 {
788         this->mwindow = mwindow;
789         this->thread = thread;
790 }
791
792 PreferencesCategory::~PreferencesCategory()
793 {
794 }
795
796 int PreferencesCategory::handle_event()
797 {
798 SET_TRACE
799         thread->window->set_current_dialog(thread->text_to_category(get_text()));
800 SET_TRACE
801         return 1;
802 }