initial commit
[goodguy/history.git] / cinelerra-5.0 / 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 "format.inc"
26 #include "language.h"
27 #include "mwindow.h"
28 #include "preferences.h"
29 #include "preferencesthread.h"
30 #include "interfaceprefs.h"
31 #include "theme.h"
32
33 #if 0
34 N_("Drag all following edits")
35 N_("Drag only one edit")
36 N_("Drag source only")
37 N_("No effect")
38 #endif
39
40 #define MOVE_ALL_EDITS_TITLE "Drag all following edits"
41 #define MOVE_ONE_EDIT_TITLE "Drag only one edit"
42 #define MOVE_NO_EDITS_TITLE "Drag source only"
43 #define MOVE_EDITS_DISABLED_TITLE "No effect"
44
45 InterfacePrefs::InterfacePrefs(MWindow *mwindow, PreferencesWindow *pwindow)
46  : PreferencesDialog(mwindow, pwindow)
47 {
48 }
49
50 void InterfacePrefs::create_objects()
51 {
52         int x, y;
53         BC_Resources *resources = BC_WindowBase::get_resources();
54         int margin = mwindow->theme->widget_border;
55         char string[BCTEXTLEN];
56         x = mwindow->theme->preferencesoptions_x;
57         y = mwindow->theme->preferencesoptions_y;
58
59         add_subwindow(new BC_Title(x, y, 
60                 _("Time Format"), 
61                 LARGEFONT, 
62                 resources->text_default));
63
64         y += get_text_height(LARGEFONT) + 5;
65
66
67         add_subwindow(hms = new TimeFormatHMS(pwindow, this, 
68                 pwindow->thread->edl->session->time_format == TIME_HMS, 
69                 x, y));
70         y += 20;
71         add_subwindow(hmsf = new TimeFormatHMSF(pwindow, this, 
72                 pwindow->thread->edl->session->time_format == TIME_HMSF, 
73                 x, y));
74         y += 20;
75         add_subwindow(samples = new TimeFormatSamples(pwindow, this, 
76                 pwindow->thread->edl->session->time_format == TIME_SAMPLES, 
77                 x, y));
78         y += 20;
79         add_subwindow(hex = new TimeFormatHex(pwindow, this, 
80                 pwindow->thread->edl->session->time_format == TIME_SAMPLES_HEX, 
81                 x, y));
82         y += 20;
83         add_subwindow(frames = new TimeFormatFrames(pwindow, this, 
84                 pwindow->thread->edl->session->time_format == TIME_FRAMES, 
85                 x, y));
86         y += 20;
87         int x1 = x;
88         add_subwindow(feet = new TimeFormatFeet(pwindow, this, 
89                 pwindow->thread->edl->session->time_format == TIME_FEET_FRAMES, 
90                 x1, y));
91         x1 += feet->get_w() + margin;
92         BC_Title *title;
93         add_subwindow(title = new BC_Title(x1, y, _("Frames per foot:")));
94         x1 += title->get_w() + margin;
95         sprintf(string, "%0.2f", pwindow->thread->edl->session->frames_per_foot);
96         add_subwindow(new TimeFormatFeetSetting(pwindow, 
97                 x1, y - 5,      string));
98         y += 20;
99         add_subwindow(seconds = new TimeFormatSeconds(pwindow, this, 
100                 pwindow->thread->edl->session->time_format == TIME_SECONDS, 
101                 x, y));
102
103         y += 35;
104         add_subwindow(new UseTipWindow(pwindow, x, y));
105
106         y += 35;
107         add_subwindow(new BC_Bar(5, y,  get_w() - 10));
108         y += 5;
109
110         add_subwindow(new BC_Title(x, y, _("Index files"), LARGEFONT, resources->text_default));
111
112
113         y += 25;
114         add_subwindow(new BC_Title(x, y + 5, 
115                 _("Index files go here:"), MEDIUMFONT, resources->text_default));
116         add_subwindow(ipathtext = new IndexPathText(x + 230, y, 
117                 pwindow, 
118                 pwindow->thread->preferences->index_directory));
119         add_subwindow(ipath = new BrowseButton(mwindow, this,
120                 ipathtext, 
121                 x + 230 + ipathtext->get_w(), y, 
122                 pwindow->thread->preferences->index_directory,
123                 _("Index Path"), 
124                 _("Select the directory for index files"),
125                 1));
126
127         y += 30;
128         add_subwindow(new BC_Title(x, y + 5, 
129                 _("Size of index file:"), 
130                 MEDIUMFONT, 
131                 resources->text_default));
132         sprintf(string, "" _LD "", pwindow->thread->preferences->index_size);
133         x1 = x + 230;
134         add_subwindow(isize = new IndexSize(x + 230, y, pwindow, string));
135         add_subwindow(new ScanCommercials(pwindow, 350,y));
136         y += 30;
137         add_subwindow(new BC_Title(x, y + 5, _("Number of index files to keep:"), MEDIUMFONT, resources->text_default));
138         sprintf(string, "%ld", (long)pwindow->thread->preferences->index_count);
139         add_subwindow(icount = new IndexCount(x + 230, y, pwindow, string));
140         add_subwindow(deleteall = new DeleteAllIndexes(mwindow, pwindow, 350, y));
141
142
143
144
145
146         y += 35;
147         add_subwindow(new BC_Bar(5, y,  get_w() - 10));
148         y += 5;
149
150         add_subwindow(new BC_Title(x, y, _("Editing"), LARGEFONT, resources->text_default));
151
152         y += 35;
153
154         add_subwindow(thumbnails = new ViewThumbnails(x, y, pwindow));
155
156         int x2 = x + 320, y2 = y;
157         AndroidRemote *android_remote = new AndroidRemote(pwindow, x2, y2);
158         add_subwindow(android_remote);
159         y2 += android_remote->get_h() + 10;
160         add_subwindow(title = new BC_Title(x2, y2, _("Port:")));
161         int x3 = x2 + title->get_w() + margin;
162         AndroidPort *android_port = new AndroidPort(pwindow, x3, y2);
163         add_subwindow(android_port);
164         y2 += title->get_h() + 10;
165         add_subwindow(title = new BC_Title(x2, y2, _("PIN:")));
166         AndroidPIN *android_pin = new AndroidPIN(pwindow, x3, y2);
167         add_subwindow(android_pin);
168
169         y += 35;
170         add_subwindow(new BC_Title(x, y, _("Clicking on edit boundaries does what:")));
171         y += 25;
172         add_subwindow(new BC_Title(x, y, _("Button 1:")));
173         
174         ViewBehaviourText *text;
175         add_subwindow(text = new ViewBehaviourText(80, y - 5, 
176                 behavior_to_text(pwindow->thread->edl->session->edit_handle_mode[0]), 
177                         pwindow, 
178                         &(pwindow->thread->edl->session->edit_handle_mode[0])));
179         text->create_objects();
180         y += 30;
181         add_subwindow(new BC_Title(x, y, _("Button 2:")));
182         add_subwindow(text = new ViewBehaviourText(80, 
183                 y - 5, 
184                 behavior_to_text(pwindow->thread->edl->session->edit_handle_mode[1]), 
185                         pwindow, 
186                         &(pwindow->thread->edl->session->edit_handle_mode[1])));
187         text->create_objects();
188         y += 30;
189         add_subwindow(new BC_Title(x, y, _("Button 3:")));
190         add_subwindow(text = new ViewBehaviourText(80, 
191                 y - 5, 
192                 behavior_to_text(pwindow->thread->edl->session->edit_handle_mode[2]), 
193                         pwindow, 
194                         &(pwindow->thread->edl->session->edit_handle_mode[2])));
195         text->create_objects();
196
197         y += 40;
198         x1 = x;
199         add_subwindow(title = new BC_Title(x, y + 5, _("Min DB for meter:")));
200         x += title->get_w() + 10;
201         sprintf(string, "%d", pwindow->thread->edl->session->min_meter_db);
202         add_subwindow(min_db = new MeterMinDB(pwindow, string, x, y));
203
204         x += min_db->get_w() + 10;
205         add_subwindow(title = new BC_Title(x, y + 5, _("Max DB:")));
206         x += title->get_w() + 10;
207         sprintf(string, "%d", pwindow->thread->edl->session->max_meter_db);
208         add_subwindow(max_db = new MeterMaxDB(pwindow, string, x, y));
209
210         x = x1;
211         y += 30;
212         ViewTheme *theme;
213         add_subwindow(new BC_Title(x, y, _("Theme:")));
214         x += 60;
215         add_subwindow(theme = new ViewTheme(x, y, pwindow));
216         theme->create_objects();
217
218 }
219
220 const char* InterfacePrefs::behavior_to_text(int mode)
221 {
222         switch(mode)
223         {
224                 case MOVE_ALL_EDITS:
225                         return _(MOVE_ALL_EDITS_TITLE);
226                         break;
227                 case MOVE_ONE_EDIT:
228                         return _(MOVE_ONE_EDIT_TITLE);
229                         break;
230                 case MOVE_NO_EDITS:
231                         return _(MOVE_NO_EDITS_TITLE);
232                         break;
233                 case MOVE_EDITS_DISABLED:
234                         return _(MOVE_EDITS_DISABLED_TITLE);
235                         break;
236                 default:
237                         return "";
238                         break;
239         }
240 }
241
242 int InterfacePrefs::update(int new_value)
243 {
244         pwindow->thread->redraw_times = 1;
245         pwindow->thread->edl->session->time_format = new_value;
246         hms->update(new_value == TIME_HMS);
247         hmsf->update(new_value == TIME_HMSF);
248         samples->update(new_value == TIME_SAMPLES);
249         hex->update(new_value == TIME_SAMPLES_HEX);
250         frames->update(new_value == TIME_FRAMES);
251         feet->update(new_value == TIME_FEET_FRAMES);
252         seconds->update(new_value == TIME_SECONDS);
253         return 0;
254 }
255
256 InterfacePrefs::~InterfacePrefs()
257 {
258         delete hms;
259         delete hmsf;
260         delete samples;
261         delete frames;
262         delete hex;
263         delete feet;
264         delete min_db;
265         delete max_db;
266 //      delete vu_db;
267 //      delete vu_int;
268         delete thumbnails;
269 }
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286 IndexPathText::IndexPathText(int x, 
287         int y, 
288         PreferencesWindow *pwindow, 
289         char *text)
290  : BC_TextBox(x, y, 240, 1, text)
291 {
292         this->pwindow = pwindow; 
293 }
294
295 IndexPathText::~IndexPathText() {}
296
297 int IndexPathText::handle_event()
298 {
299         strcpy(pwindow->thread->preferences->index_directory, get_text());
300         return 1;
301 }
302
303
304
305
306 IndexSize::IndexSize(int x, 
307         int y, 
308         PreferencesWindow *pwindow, 
309         char *text)
310  : BC_TextBox(x, y, 100, 1, text)
311
312         this->pwindow = pwindow; 
313 }
314
315 int IndexSize::handle_event()
316 {
317         long result;
318
319         result = atol(get_text());
320         if(result < 64000) result = 64000;
321         //if(result < 500000) result = 500000;
322         pwindow->thread->preferences->index_size = result;
323         return 0;
324 }
325
326
327
328 IndexCount::IndexCount(int x, 
329         int y, 
330         PreferencesWindow *pwindow, 
331         char *text)
332  : BC_TextBox(x, y, 100, 1, text)
333
334         this->pwindow = pwindow; 
335 }
336
337 int IndexCount::handle_event()
338 {
339         long result;
340
341         result = atol(get_text());
342         if(result < 1) result = 1;
343         pwindow->thread->preferences->index_count = result;
344         return 0;
345 }
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361 TimeFormatHMS::TimeFormatHMS(PreferencesWindow *pwindow, InterfacePrefs *tfwindow, int value, int x, int y)
362  : BC_Radial(x, y, value, TIME_HMS_TEXT)
363 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
364
365 int TimeFormatHMS::handle_event()
366 {
367         tfwindow->update(TIME_HMS);
368         return 1;
369 }
370
371 TimeFormatHMSF::TimeFormatHMSF(PreferencesWindow *pwindow, InterfacePrefs *tfwindow, int value, int x, int y)
372  : BC_Radial(x, y, value, TIME_HMSF_TEXT)
373 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
374
375 int TimeFormatHMSF::handle_event()
376 {
377         tfwindow->update(TIME_HMSF);
378         return 1;
379 }
380
381 TimeFormatSamples::TimeFormatSamples(PreferencesWindow *pwindow, InterfacePrefs *tfwindow, int value, int x, int y)
382  : BC_Radial(x, y, value, TIME_SAMPLES_TEXT)
383 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
384
385 int TimeFormatSamples::handle_event()
386 {
387         tfwindow->update(TIME_SAMPLES);
388         return 1;
389 }
390
391 TimeFormatFrames::TimeFormatFrames(PreferencesWindow *pwindow, InterfacePrefs *tfwindow, int value, int x, int y)
392  : BC_Radial(x, y, value, TIME_FRAMES_TEXT)
393 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
394
395 int TimeFormatFrames::handle_event()
396 {
397         tfwindow->update(TIME_FRAMES);
398         return 1;
399 }
400
401 TimeFormatHex::TimeFormatHex(PreferencesWindow *pwindow, InterfacePrefs *tfwindow, int value, int x, int y)
402  : BC_Radial(x, y, value, TIME_SAMPLES_HEX_TEXT)
403 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
404
405 int TimeFormatHex::handle_event()
406 {
407         tfwindow->update(TIME_SAMPLES_HEX);
408         return 1;
409 }
410
411 TimeFormatSeconds::TimeFormatSeconds(PreferencesWindow *pwindow, InterfacePrefs *tfwindow, int value, int x, int y)
412  : BC_Radial(x, y, value, TIME_SECONDS_TEXT)
413
414         this->pwindow = pwindow; 
415         this->tfwindow = tfwindow; 
416 }
417
418 int TimeFormatSeconds::handle_event()
419 {
420         tfwindow->update(TIME_SECONDS);
421         return 1;
422 }
423
424 TimeFormatFeet::TimeFormatFeet(PreferencesWindow *pwindow, InterfacePrefs *tfwindow, int value, int x, int y)
425  : BC_Radial(x, y, value, TIME_FEET_FRAMES_TEXT)
426 { this->pwindow = pwindow; this->tfwindow = tfwindow; }
427
428 int TimeFormatFeet::handle_event()
429 {
430         tfwindow->update(TIME_FEET_FRAMES);
431         return 1;
432 }
433
434 TimeFormatFeetSetting::TimeFormatFeetSetting(PreferencesWindow *pwindow, int x, int y, char *string)
435  : BC_TextBox(x, y, 90, 1, string)
436 { this->pwindow = pwindow; }
437
438 int TimeFormatFeetSetting::handle_event()
439 {
440         pwindow->thread->edl->session->frames_per_foot = atof(get_text());
441         if(pwindow->thread->edl->session->frames_per_foot < 1) pwindow->thread->edl->session->frames_per_foot = 1;
442         return 0;
443 }
444
445
446
447
448 ViewBehaviourText::ViewBehaviourText(int x, 
449         int y, 
450         const char *text, 
451         PreferencesWindow *pwindow, 
452         int *output)
453  : BC_PopupMenu(x, y, 200, text)
454 {
455         this->output = output;
456 }
457
458 ViewBehaviourText::~ViewBehaviourText()
459 {
460 }
461
462 int ViewBehaviourText::handle_event()
463 {
464         return 0;
465 }
466
467 void ViewBehaviourText::create_objects()
468 {
469 // Video4linux versions are automatically detected
470         add_item(new ViewBehaviourItem(this, _(MOVE_ALL_EDITS_TITLE), MOVE_ALL_EDITS));
471         add_item(new ViewBehaviourItem(this, _(MOVE_ONE_EDIT_TITLE), MOVE_ONE_EDIT));
472         add_item(new ViewBehaviourItem(this, _(MOVE_NO_EDITS_TITLE), MOVE_NO_EDITS));
473         add_item(new ViewBehaviourItem(this, _(MOVE_EDITS_DISABLED_TITLE), MOVE_EDITS_DISABLED));
474 }
475
476
477 ViewBehaviourItem::ViewBehaviourItem(ViewBehaviourText *popup, char *text, int behaviour)
478  : BC_MenuItem(text)
479 {
480         this->popup = popup;
481         this->behaviour = behaviour;
482 }
483
484 ViewBehaviourItem::~ViewBehaviourItem()
485 {
486 }
487
488 int ViewBehaviourItem::handle_event()
489 {
490         popup->set_text(get_text());
491         *(popup->output) = behaviour;
492         return 1;
493 }
494
495
496
497
498 MeterMinDB::MeterMinDB(PreferencesWindow *pwindow, char *text, int x, int y)
499  : BC_TextBox(x, y, 50, 1, text)
500
501         this->pwindow = pwindow; 
502 }
503
504 int MeterMinDB::handle_event()
505
506         pwindow->thread->redraw_meters = 1;
507         pwindow->thread->edl->session->min_meter_db = atol(get_text()); 
508         return 0;
509 }
510
511
512
513
514 MeterMaxDB::MeterMaxDB(PreferencesWindow *pwindow, char *text, int x, int y)
515  : BC_TextBox(x, y, 50, 1, text)
516
517         this->pwindow = pwindow; 
518 }
519
520 int MeterMaxDB::handle_event()
521
522         pwindow->thread->redraw_meters = 1;
523         pwindow->thread->edl->session->max_meter_db = atol(get_text()); 
524         return 0;
525 }
526
527
528
529
530
531 MeterVUDB::MeterVUDB(PreferencesWindow *pwindow, char *text, int y)
532  : BC_Radial(145, y, pwindow->thread->edl->session->meter_format == METER_DB, text)
533
534         this->pwindow = pwindow; 
535 }
536
537 int MeterVUDB::handle_event() 
538
539         pwindow->thread->redraw_meters = 1;
540 //      vu_int->update(0); 
541         pwindow->thread->edl->session->meter_format = METER_DB; 
542         return 1;
543 }
544
545 MeterVUInt::MeterVUInt(PreferencesWindow *pwindow, char *text, int y)
546  : BC_Radial(205, y, pwindow->thread->edl->session->meter_format == METER_INT, text)
547
548         this->pwindow = pwindow; 
549 }
550
551 int MeterVUInt::handle_event() 
552
553         pwindow->thread->redraw_meters = 1;
554         vu_db->update(0); 
555         pwindow->thread->edl->session->meter_format = METER_INT; 
556         return 1;
557 }
558
559
560
561
562 ViewTheme::ViewTheme(int x, int y, PreferencesWindow *pwindow)
563  : BC_PopupMenu(x, y, 200, pwindow->thread->preferences->theme, 1)
564 {
565         this->pwindow = pwindow;
566 }
567 ViewTheme::~ViewTheme()
568 {
569 }
570
571 void ViewTheme::create_objects()
572 {
573         ArrayList<PluginServer*> themes;
574         MWindow::search_plugindb(0, 
575                 0, 
576                 0, 
577                 0,
578                 1,
579                 themes);
580
581         for(int i = 0; i < themes.total; i++)
582         {
583                 add_item(new ViewThemeItem(this, themes.values[i]->title));
584         }
585 }
586
587 int ViewTheme::handle_event()
588 {
589         return 1;
590 }
591
592
593
594
595
596 ViewThemeItem::ViewThemeItem(ViewTheme *popup, char *text)
597  : BC_MenuItem(text)
598 {
599         this->popup = popup;
600 }
601
602 int ViewThemeItem::handle_event()
603 {
604         popup->set_text(get_text());
605         strcpy(popup->pwindow->thread->preferences->theme, get_text());
606         popup->handle_event();
607         return 1;
608 }
609
610 ViewThumbnails::ViewThumbnails(int x, 
611         int y, 
612         PreferencesWindow *pwindow)
613  : BC_CheckBox(x, 
614         y, 
615         pwindow->thread->preferences->use_thumbnails, _("Use thumbnails in resource window"))
616 {
617         this->pwindow = pwindow;
618 }
619
620 int ViewThumbnails::handle_event()
621 {
622         pwindow->thread->preferences->use_thumbnails = get_value();
623         return 1;
624 }
625
626
627
628 UseTipWindow::UseTipWindow(PreferencesWindow *pwindow, int x, int y)
629  : BC_CheckBox(x, 
630         y, 
631         pwindow->thread->preferences->use_tipwindow, 
632         _("Show tip of the day"))
633 {
634         this->pwindow = pwindow;
635 }
636 int UseTipWindow::handle_event()
637 {
638         pwindow->thread->preferences->use_tipwindow = get_value();
639         return 1;
640 }
641
642
643
644 ScanCommercials::ScanCommercials(PreferencesWindow *pwindow, int x, int y)
645  : BC_CheckBox(x, 
646         y, 
647         pwindow->thread->preferences->scan_commercials, 
648         _("Scan for commercials during toc build"))
649 {
650         this->pwindow = pwindow;
651 }
652 int ScanCommercials::handle_event()
653 {
654         pwindow->thread->preferences->scan_commercials = get_value();
655         return 1;
656 }
657
658
659 AndroidRemote::AndroidRemote(PreferencesWindow *pwindow, int x, int y)
660  : BC_CheckBox(x, y, 
661         pwindow->thread->preferences->android_remote, 
662         _("Android Remote Control"))
663 {
664         this->pwindow = pwindow;
665 }
666 int AndroidRemote::handle_event()
667 {
668         pwindow->thread->preferences->android_remote = get_value();
669         return 1;
670 }
671
672
673 AndroidPIN::AndroidPIN(PreferencesWindow *pwindow, int x, int y)
674  : BC_TextBox(x, y, 240, 1, pwindow->thread->preferences->android_pin)
675 {
676         this->pwindow = pwindow;
677 }
678
679 int AndroidPIN::handle_event()
680 {
681         char *txt = pwindow->thread->preferences->android_pin;
682         int len = sizeof(pwindow->thread->preferences->android_pin);
683         strncpy(txt, get_text(), len);
684         return 1;
685 }
686
687
688 AndroidPort::AndroidPort(PreferencesWindow *pwindow, int x, int y)
689  : BC_TextBox(x, y, 72, 1, pwindow->thread->preferences->android_port)
690 {
691         this->pwindow = pwindow;
692 }
693
694 int AndroidPort::handle_event()
695 {
696         unsigned short port = atoi(get_text());
697         if( port < 1024 ) port = 1024;
698         pwindow->thread->preferences->android_port = port;
699         char str[BCSTRLEN];
700         sprintf(str,"%u",port);
701         update(str);
702         return 1;
703 }
704