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