d463fb24471ae67c8bd601275f5baf408d0a4b6d
[goodguy/history.git] / cinelerra-5.1 / cinelerra / interfaceprefs.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 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 "deleteallindexes.h"
23 #include "edl.h"
24 #include "edlsession.h"
25 #include "file.h"
26 #include "filesystem.h"
27 #include "language.h"
28 #include "mwindow.h"
29 #include "preferences.h"
30 #include "preferencesthread.h"
31 #include "probeprefs.h"
32 #include "interfaceprefs.h"
33 #include "shbtnprefs.h"
34 #include "theme.h"
35
36 #if 0
37 N_("Drag all following edits")
38 N_("Drag only one edit")
39 N_("Drag source only")
40 N_("No effect")
41 #endif
42
43 #define MOVE_ALL_EDITS_TITLE "Drag all following edits"
44 #define MOVE_ONE_EDIT_TITLE "Drag only one edit"
45 #define MOVE_NO_EDITS_TITLE "Drag source only"
46 #define MOVE_EDITS_DISABLED_TITLE "No effect"
47
48 InterfacePrefs::InterfacePrefs(MWindow *mwindow, PreferencesWindow *pwindow)
49  : PreferencesDialog(mwindow, pwindow)
50 {
51         min_db = 0;
52         max_db = 0;
53         shbtn_dialog = 0;
54         file_probe_dialog = 0;
55 }
56
57 InterfacePrefs::~InterfacePrefs()
58 {
59         delete min_db;
60         delete max_db;
61         delete shbtn_dialog;
62         delete file_probe_dialog;
63 }
64
65
66 void InterfacePrefs::create_objects()
67 {
68         BC_Resources *resources = BC_WindowBase::get_resources();
69         int margin = mwindow->theme->widget_border;
70         char string[BCTEXTLEN];
71         int x0 = mwindow->theme->preferencesoptions_x;
72         int y0 = mwindow->theme->preferencesoptions_y;
73         int x = x0, y = y0;
74
75         add_subwindow(new BC_Title(x, y, _("Editing:"), LARGEFONT,
76                 resources->text_default));
77         y += 35;
78
79         int x2 = get_w()/2, y2 = y;
80         x = x2;
81         BC_Title *title;
82         add_subwindow(title = new BC_Title(x, y, _("Keyframe reticle:")));
83         y += 25;
84         keyframe_reticle = new KeyframeReticle(x, y, &pwindow->thread->preferences->keyframe_reticle);
85         add_subwindow(keyframe_reticle);
86         keyframe_reticle->create_objects();
87
88         x = x0;  y = y2;
89         add_subwindow(new BC_Title(x, y, _("Clicking on edit boundaries does what:")));
90         y += 25;
91         add_subwindow(new BC_Title(x, y, _("Button 1:")));
92
93         int x1 = x + 100;
94         ViewBehaviourText *text;
95         add_subwindow(text = new ViewBehaviourText(x1, y - 5,
96                 behavior_to_text(pwindow->thread->edl->session->edit_handle_mode[0]),
97                         pwindow,
98                         &(pwindow->thread->edl->session->edit_handle_mode[0])));
99         text->create_objects();
100         y += 30;
101         add_subwindow(new BC_Title(x, y, _("Button 2:")));
102         add_subwindow(text = new ViewBehaviourText(x1,
103                 y - 5,
104                 behavior_to_text(pwindow->thread->edl->session->edit_handle_mode[1]),
105                         pwindow,
106                         &(pwindow->thread->edl->session->edit_handle_mode[1])));
107         text->create_objects();
108         y += 30;
109         add_subwindow(new BC_Title(x, y, _("Button 3:")));
110         add_subwindow(text = new ViewBehaviourText(x1, y - 5,
111                 behavior_to_text(pwindow->thread->edl->session->edit_handle_mode[2]),
112                         pwindow,
113                         &(pwindow->thread->edl->session->edit_handle_mode[2])));
114         text->create_objects();
115         y += text->get_h() + 30;
116
117         x = x0;
118         add_subwindow(new BC_Bar(5, y,  get_w() - 10));
119         y += 5;
120         add_subwindow(new BC_Title(x, y, _("Operation:"), LARGEFONT,
121                 resources->text_default));
122         y += 35;
123
124         int y1 = y;
125         AndroidRemote *android_remote = new AndroidRemote(pwindow, x2, y);
126         add_subwindow(android_remote);
127         y += android_remote->get_h() + 10;
128         add_subwindow(title = new BC_Title(x2, y, _("Port:")));
129         int x3 = x2 + title->get_w() + margin;
130         AndroidPort *android_port = new AndroidPort(pwindow, x3, y);
131         add_subwindow(android_port);
132         y += title->get_h() + 10;
133         add_subwindow(title = new BC_Title(x2, y, _("PIN:")));
134         AndroidPIN *android_pin = new AndroidPIN(pwindow, x3, y);
135         add_subwindow(android_pin);
136         y += title->get_h() + 30;
137
138         ShBtnPrefs *shbtn_prefs = new ShBtnPrefs(pwindow, this, x2, y);
139         add_subwindow(shbtn_prefs);
140         y += shbtn_prefs->get_h() + 30;
141
142         y2 = y;
143         x = x0;  y = y1;
144         add_subwindow(file_probes = new PrefsFileProbes(pwindow, this, x, y));
145         y += 30;
146
147         PrefsTrapSigSEGV *trap_segv = new PrefsTrapSigSEGV(this, x, y);
148         add_subwindow(trap_segv);
149         x1 = x + trap_segv->get_w() + 10;
150         add_subwindow(new BC_Title(x1, y, _("(must be root)"), MEDIUMFONT, RED));
151         y += 30;
152
153         PrefsTrapSigINTR *trap_intr = new PrefsTrapSigINTR(this, x, y);
154         add_subwindow(trap_intr);
155         add_subwindow(new BC_Title(x1, y, _("(must be root)"), MEDIUMFONT, RED));
156         y += 30;
157
158         yuv420p_dvdlace = new PrefsYUV420P_DVDlace(pwindow, this, x, y);
159         add_subwindow(yuv420p_dvdlace);
160         y += 30;
161
162         if( y2 > y ) y = y2;
163         add_subwindow(title = new BC_Title(x, y + 5, _("Min DB for meter:")));
164         x += title->get_w() + 10;
165         sprintf(string, "%d", pwindow->thread->edl->session->min_meter_db);
166         add_subwindow(min_db = new MeterMinDB(pwindow, string, x, y));
167         x += min_db->get_w() + 10;
168         add_subwindow(title = new BC_Title(x, y + 5, _("Max DB:")));
169         x += title->get_w() + 10;
170         sprintf(string, "%d", pwindow->thread->edl->session->max_meter_db);
171         add_subwindow(max_db = new MeterMaxDB(pwindow, string, x, y));
172         y += 30;
173
174         StillImageUseDuration *use_stduration = new StillImageUseDuration(pwindow,
175                 pwindow->thread->edl->session->si_useduration, x2, y2);
176         add_subwindow(use_stduration);
177         int tw = 0, th = 0;
178         BC_CheckBox::calculate_extents(this, &tw, &th, 0, 0);
179         x2 += tw + 3;
180         y2 += use_stduration->get_h() + 3;
181         StillImageDuration *stduration = new StillImageDuration(pwindow, x2, y2);
182         add_subwindow(stduration);
183         x2 += stduration->get_w() + 10;
184         y2 += 3;
185         add_subwindow(new BC_Title(x2, y2, _("Seconds")));
186         y2 += 30;
187
188         x = x0;  y = y2;
189         add_subwindow(new BC_Bar(5, y,  get_w() - 10));
190         y += 5;
191
192
193         add_subwindow(new BC_Title(x, y, _("Index files:"), LARGEFONT, resources->text_default));
194         y += 30;
195
196         add_subwindow(new BC_Title(x, y + 5,
197                 _("Index files go here:"), MEDIUMFONT, resources->text_default));
198         x1 = x + 230;
199         add_subwindow(ipathtext = new IndexPathText(x1, y, pwindow,
200                 pwindow->thread->preferences->index_directory));
201         x1 +=  ipathtext->get_w();
202         add_subwindow(ipath = new BrowseButton(mwindow->theme, this, ipathtext, x1, y,
203                 pwindow->thread->preferences->index_directory,
204                 _("Index Path"), _("Select the directory for index files"), 1));
205
206         y += 30;
207         add_subwindow(new BC_Title(x, y + 5, _("Size of index file:"),
208                 MEDIUMFONT, resources->text_default));
209         sprintf(string, "%jd", pwindow->thread->preferences->index_size);
210         add_subwindow(isize = new IndexSize(x + 230, y, pwindow, string));
211         add_subwindow(new ScanCommercials(pwindow, 400,y));
212
213         y += 30;
214         add_subwindow(new BC_Title(x, y + 5, _("Number of index files to keep:"),
215                 MEDIUMFONT, resources->text_default));
216         sprintf(string, "%ld", (long)pwindow->thread->preferences->index_count);
217         add_subwindow(icount = new IndexCount(x + 230, y, pwindow, string));
218         add_subwindow(deleteall = new DeleteAllIndexes(mwindow, pwindow, 400, y));
219         y += 30;
220         add_subwindow(ffmpeg_marker_files = new IndexFFMPEGMarkerFiles(this, x, y));
221         y += 35;
222 }
223
224 const char* InterfacePrefs::behavior_to_text(int mode)
225 {
226         switch(mode) {
227                 case MOVE_ALL_EDITS: return _(MOVE_ALL_EDITS_TITLE);
228                 case MOVE_ONE_EDIT:  return _(MOVE_ONE_EDIT_TITLE);
229                 case MOVE_NO_EDITS:  return _(MOVE_NO_EDITS_TITLE);
230                 case MOVE_EDITS_DISABLED: return _(MOVE_EDITS_DISABLED_TITLE);
231                 default: return "";
232         }
233 }
234
235 IndexPathText::IndexPathText(int x, int y, PreferencesWindow *pwindow, char *text)
236  : BC_TextBox(x, y, 240, 1, text)
237 {
238         this->pwindow = pwindow;
239 }
240
241 IndexPathText::~IndexPathText() {}
242
243 int IndexPathText::handle_event()
244 {
245         strcpy(pwindow->thread->preferences->index_directory, get_text());
246         return 1;
247 }
248
249
250
251
252 IndexSize::IndexSize(int x, int y, PreferencesWindow *pwindow, char *text)
253  : BC_TextBox(x, y, 100, 1, text)
254 {
255         this->pwindow = pwindow;
256 }
257
258 int IndexSize::handle_event()
259 {
260         long result;
261
262         result = atol(get_text());
263         if(result < 64000) result = 64000;
264         //if(result < 500000) result = 500000;
265         pwindow->thread->preferences->index_size = result;
266         return 0;
267 }
268
269
270
271 IndexCount::IndexCount(int x, int y, PreferencesWindow *pwindow, char *text)
272  : BC_TextBox(x, y, 100, 1, text)
273 {
274         this->pwindow = pwindow;
275 }
276
277 int IndexCount::handle_event()
278 {
279         long result;
280
281         result = atol(get_text());
282         if(result < 1) result = 1;
283         pwindow->thread->preferences->index_count = result;
284         return 0;
285 }
286
287
288
289 IndexFFMPEGMarkerFiles::IndexFFMPEGMarkerFiles(InterfacePrefs *iface_prefs, int x, int y)
290  : BC_CheckBox(x, y,
291         iface_prefs->pwindow->thread->preferences->ffmpeg_marker_indexes,
292         _("build ffmpeg marker indexes"))
293 {
294         this->iface_prefs = iface_prefs;
295 }
296 IndexFFMPEGMarkerFiles::~IndexFFMPEGMarkerFiles()
297 {
298 }
299
300 int IndexFFMPEGMarkerFiles::handle_event()
301 {
302         iface_prefs->pwindow->thread->preferences->ffmpeg_marker_indexes = get_value();
303         return 1;
304 }
305
306
307 ViewBehaviourText::ViewBehaviourText(int x, int y, const char *text, PreferencesWindow *pwindow,
308         int *output)
309  : BC_PopupMenu(x, y, 200, text)
310 {
311         this->output = output;
312 }
313
314 ViewBehaviourText::~ViewBehaviourText()
315 {
316 }
317
318 int ViewBehaviourText::handle_event()
319 {
320         return 0;
321 }
322
323 void ViewBehaviourText::create_objects()
324 {
325         add_item(new ViewBehaviourItem(this, _(MOVE_ALL_EDITS_TITLE), MOVE_ALL_EDITS));
326         add_item(new ViewBehaviourItem(this, _(MOVE_ONE_EDIT_TITLE), MOVE_ONE_EDIT));
327         add_item(new ViewBehaviourItem(this, _(MOVE_NO_EDITS_TITLE), MOVE_NO_EDITS));
328         add_item(new ViewBehaviourItem(this, _(MOVE_EDITS_DISABLED_TITLE), MOVE_EDITS_DISABLED));
329 }
330
331
332 ViewBehaviourItem::ViewBehaviourItem(ViewBehaviourText *popup, char *text, int behaviour)
333  : BC_MenuItem(text)
334 {
335         this->popup = popup;
336         this->behaviour = behaviour;
337 }
338
339 ViewBehaviourItem::~ViewBehaviourItem()
340 {
341 }
342
343 int ViewBehaviourItem::handle_event()
344 {
345         popup->set_text(get_text());
346         *(popup->output) = behaviour;
347         return 1;
348 }
349
350
351 MeterMinDB::MeterMinDB(PreferencesWindow *pwindow, char *text, int x, int y)
352  : BC_TextBox(x, y, 50, 1, text)
353 {
354         this->pwindow = pwindow;
355 }
356
357 int MeterMinDB::handle_event()
358 {
359         pwindow->thread->redraw_meters = 1;
360         pwindow->thread->edl->session->min_meter_db = atol(get_text());
361         return 0;
362 }
363
364
365 MeterMaxDB::MeterMaxDB(PreferencesWindow *pwindow, char *text, int x, int y)
366  : BC_TextBox(x, y, 50, 1, text)
367 {
368         this->pwindow = pwindow;
369 }
370
371 int MeterMaxDB::handle_event()
372 {
373         pwindow->thread->redraw_meters = 1;
374         pwindow->thread->edl->session->max_meter_db = atol(get_text());
375         return 0;
376 }
377
378
379 ScanCommercials::ScanCommercials(PreferencesWindow *pwindow, int x, int y)
380  : BC_CheckBox(x,
381         y,
382         pwindow->thread->preferences->scan_commercials,
383         _("Scan for commercials during toc build"))
384 {
385         this->pwindow = pwindow;
386 }
387 int ScanCommercials::handle_event()
388 {
389         pwindow->thread->preferences->scan_commercials = get_value();
390         return 1;
391 }
392
393
394 AndroidRemote::AndroidRemote(PreferencesWindow *pwindow, int x, int y)
395  : BC_CheckBox(x, y,
396         pwindow->thread->preferences->android_remote,
397         _("Android Remote Control"))
398 {
399         this->pwindow = pwindow;
400 }
401 int AndroidRemote::handle_event()
402 {
403         pwindow->thread->preferences->android_remote = get_value();
404         return 1;
405 }
406
407 AndroidPIN::AndroidPIN(PreferencesWindow *pwindow, int x, int y)
408  : BC_TextBox(x, y, 240, 1, pwindow->thread->preferences->android_pin)
409 {
410         this->pwindow = pwindow;
411 }
412
413 int AndroidPIN::handle_event()
414 {
415         char *txt = pwindow->thread->preferences->android_pin;
416         int len = sizeof(pwindow->thread->preferences->android_pin);
417         strncpy(txt, get_text(), len);
418         return 1;
419 }
420
421
422 AndroidPort::AndroidPort(PreferencesWindow *pwindow, int x, int y)
423  : BC_TextBox(x, y, 72, 1, pwindow->thread->preferences->android_port)
424 {
425         this->pwindow = pwindow;
426 }
427
428 int AndroidPort::handle_event()
429 {
430         unsigned short port = atoi(get_text());
431         if( port < 1024 ) port = 1024;
432         pwindow->thread->preferences->android_port = port;
433         char str[BCSTRLEN];
434         sprintf(str,"%u",port);
435         update(str);
436         return 1;
437 }
438
439 int InterfacePrefs::start_shbtn_dialog()
440 {
441         if( !shbtn_dialog )
442                 shbtn_dialog = new ShBtnEditDialog(pwindow);
443         shbtn_dialog->start();
444         return 1;
445 }
446
447 ShBtnPrefs::ShBtnPrefs(PreferencesWindow *pwindow, InterfacePrefs *iface_prefs, int x, int y)
448  : BC_GenericButton(x, y, _("Shell Commands"))
449 {
450         this->pwindow = pwindow;
451         this->iface_prefs = iface_prefs;
452         set_tooltip(_("Main Menu Shell Commands"));
453 }
454
455 int ShBtnPrefs::handle_event()
456 {
457         return iface_prefs->start_shbtn_dialog();
458 }
459
460
461 StillImageUseDuration::StillImageUseDuration(PreferencesWindow *pwindow, int value, int x, int y)
462  : BC_CheckBox(x, y, value, _("Import images with a duration of"))
463 {
464         this->pwindow = pwindow;
465 }
466
467 int StillImageUseDuration::handle_event()
468 {
469         pwindow->thread->edl->session->si_useduration = get_value();
470         return 1;
471 }
472
473 StillImageDuration::StillImageDuration(PreferencesWindow *pwindow, int x, int y)
474  : BC_TextBox(x, y, 70, 1, pwindow->thread->edl->session->si_duration)
475 {
476         this->pwindow = pwindow;
477 }
478 int StillImageDuration::handle_event()
479 {
480         pwindow->thread->edl->session->si_duration = atof(get_text());
481         return 1;
482 }
483
484
485 HairlineItem::HairlineItem(KeyframeReticle *popup, int hairline)
486  : BC_MenuItem(popup->hairline_to_string(hairline))
487 {
488         this->popup = popup;
489         this->hairline = hairline;
490 }
491
492 HairlineItem::~HairlineItem()
493 {
494 }
495
496 int HairlineItem::handle_event()
497 {
498         popup->set_text(get_text());
499         *(popup->output) = hairline;
500         return 1;
501 }
502
503
504 KeyframeReticle::KeyframeReticle(int x, int y, int *output)
505  : BC_PopupMenu(x, y, 175, hairline_to_string(*output))
506 {
507         this->output = output;
508 }
509
510 KeyframeReticle::~KeyframeReticle()
511 {
512 }
513
514 const char *KeyframeReticle::hairline_to_string(int type)
515 {
516         switch( type ) {
517         case HAIRLINE_NEVER:    return _("Never");
518         case HAIRLINE_DRAGGING: return _("Dragging");
519         case HAIRLINE_ALWAYS:   return _("Always");
520         }
521         return _("Unknown");
522 }
523
524 void KeyframeReticle::create_objects()
525 {
526         add_item(new HairlineItem(this, HAIRLINE_NEVER));
527         add_item(new HairlineItem(this, HAIRLINE_DRAGGING));
528         add_item(new HairlineItem(this, HAIRLINE_ALWAYS));
529 }
530
531 PrefsTrapSigSEGV::PrefsTrapSigSEGV(InterfacePrefs *subwindow, int x, int y)
532  : BC_CheckBox(x, y,
533         subwindow->pwindow->thread->preferences->trap_sigsegv,
534         _("trap sigSEGV"))
535 {
536         this->subwindow = subwindow;
537 }
538 PrefsTrapSigSEGV::~PrefsTrapSigSEGV()
539 {
540 }
541 int PrefsTrapSigSEGV::handle_event()
542 {
543         subwindow->pwindow->thread->preferences->trap_sigsegv = get_value();
544         return 1;
545 }
546
547 PrefsTrapSigINTR::PrefsTrapSigINTR(InterfacePrefs *subwindow, int x, int y)
548  : BC_CheckBox(x, y,
549         subwindow->pwindow->thread->preferences->trap_sigintr,
550         _("trap sigINT"))
551 {
552         this->subwindow = subwindow;
553 }
554 PrefsTrapSigINTR::~PrefsTrapSigINTR()
555 {
556 }
557 int PrefsTrapSigINTR::handle_event()
558 {
559         subwindow->pwindow->thread->preferences->trap_sigintr = get_value();
560         return 1;
561 }
562
563
564 void InterfacePrefs::start_probe_dialog()
565 {
566         if( !file_probe_dialog )
567                 file_probe_dialog = new FileProbeDialog(pwindow);
568         file_probe_dialog->start();
569 }
570
571 PrefsFileProbes::PrefsFileProbes(PreferencesWindow *pwindow,
572                 InterfacePrefs *subwindow, int x, int y)
573  : BC_GenericButton(x, y, _("Probe Order"))
574 {
575         this->pwindow = pwindow;
576         this->subwindow = subwindow;
577         set_tooltip(_("File Open Probe Ordering"));
578 }
579
580 int PrefsFileProbes::handle_event()
581 {
582         subwindow->start_probe_dialog();
583         return 1;
584 }
585
586
587 PrefsYUV420P_DVDlace::PrefsYUV420P_DVDlace(PreferencesWindow *pwindow,
588         InterfacePrefs *subwindow, int x, int y)
589  : BC_CheckBox(x, y, pwindow->thread->preferences->dvd_yuv420p_interlace,
590         _("Use yuv420p dvd interlace format"))
591 {
592         this->pwindow = pwindow;
593         this->subwindow = subwindow;
594 }
595
596 int PrefsYUV420P_DVDlace::handle_event()
597 {
598         pwindow->thread->preferences->dvd_yuv420p_interlace = get_value();
599         return 1;
600 }
601