rework keyframe hide popup, keyframe auto render, textbox set_selection wide text
[goodguy/history.git] / cinelerra-5.1 / cinelerra / channeledit.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 "batch.h"
23 #include "bcprogressbox.h"
24 #include "bcsignals.h"
25 #include "channel.h"
26 #include "channeldb.h"
27 #include "channeledit.h"
28 #include "channelpicker.h"
29 #include "chantables.h"
30 #include "clip.h"
31 #include "condition.h"
32 #include "language.h"
33 #include "mainsession.h"
34 #include "mwindow.h"
35 #include "picture.h"
36 #include "theme.h"
37 #include "videodevice.h"
38 #include <ctype.h>
39 #include <string.h>
40 #include <unistd.h>
41
42
43 ChannelEditThread::ChannelEditThread(ChannelPicker *channel_picker,
44         ChannelDB *channeldb)
45  : Thread()
46 {
47         this->channel_picker = channel_picker;
48         this->channeldb = channeldb;
49         in_progress = 0;
50         this->window = 0;
51         new_channels = new ChannelDB;
52         completion = new Condition(1, "ChannelEditThread::completion");
53         scan_thread = 0;
54 }
55 ChannelEditThread::~ChannelEditThread()
56 {
57         close_threads();
58         delete scan_thread;
59         delete new_channels;
60         delete completion;
61 }
62
63 void ChannelEditThread::run()
64 {
65         if(in_progress)
66         {
67                 if(window)
68                 {
69                         window->lock_window("ChannelEditThread::run");
70                         window->raise_window(1);
71                         window->unlock_window();
72                 }
73                 return;
74         }
75         in_progress = 1;
76         completion->lock("ChannelEditThread::run");
77
78 // Copy master channel list to temporary.
79         new_channels->copy_from(channel_picker->channeldb);
80         Channel *channel = channel_picker->get_current_channel();
81         current_channel = channel_picker->channeldb->number_of(channel);
82 //printf("ChannelEditThread::run 1 %d\n", current_channel);
83
84 // Run the channel list window using the temporary list.
85         window = new ChannelEditWindow(this, channel_picker);
86         window->create_objects();
87         int result = window->run_window();
88         delete window;  window = 0;
89
90         if(!result) {
91 // Copy new channels to master list
92                 channel_picker->channeldb->clear();
93
94                 channel_picker->channeldb->copy_from(new_channels);
95                 channel_picker->update_channel_list();
96
97         }
98
99         channel_picker->handle_channel_edit(result);
100
101         completion->unlock();
102         in_progress = 0;
103
104 }
105
106 void ChannelEditThread::close_threads()
107 {
108         if(in_progress && window)
109         {
110                 window->set_done(1);
111                 completion->lock("ChannelEditThread::close_threads");
112                 completion->unlock();
113         }
114 }
115
116 char *ChannelEditThread::value_to_freqtable(int value)
117 {
118         switch(value)
119         {
120                 case NTSC_DVB: return _("NTSC_DVB");
121                 case CATV_DVB: return _("CATV_DVB");
122                 case NTSC_BCAST: return _("NTSC_BCAST");
123                 case NTSC_CABLE: return _("NTSC_CABLE");
124                 case NTSC_HRC: return _("NTSC_HRC");
125                 case NTSC_BCAST_JP: return _("NTSC_BCAST_JP");
126                 case NTSC_CABLE_JP: return _("NTSC_CABLE_JP");
127                 case PAL_AUSTRALIA: return _("PAL_AUSTRALIA");
128                 case PAL_EUROPE: return _("PAL_EUROPE");
129                 case PAL_E_EUROPE: return _("PAL_E_EUROPE");
130                 case PAL_ITALY: return _("PAL_ITALY");
131                 case PAL_IRELAND: return _("PAL_IRELAND");
132                 case PAL_NEWZEALAND: return _("PAL_NEWZEALAND");
133         }
134         return _("ERROR");
135 }
136
137 char* ChannelEditThread::value_to_norm(int value)
138 {
139         switch(value)
140         {
141                 case NTSC: return _("NTSC");
142                 case PAL: return _("PAL");
143                 case SECAM: return _("SECAM");
144         }
145         return _("ERROR");
146 }
147
148 char* ChannelEditThread::value_to_input(int value)
149 {
150         ArrayList<Channel*> *inputs = channel_picker->get_video_inputs();
151         return value >= inputs->total ? _("None") :
152                 inputs->values[value]->device_name;
153 }
154
155
156
157
158
159
160
161 ChannelEditWindow::ChannelEditWindow(ChannelEditThread *thread,
162         ChannelPicker *channel_picker)
163  : BC_Window(PROGRAM_NAME ": Channels",
164         channel_picker->mwindow->session->channels_x,
165         channel_picker->mwindow->session->channels_y,
166         350, 400, 350, 400, 0, 0, 1)
167 {
168         this->thread = thread;
169         this->channel_picker = channel_picker;
170         this->edit_thread = 0;
171         this->picture_thread = 0;
172         this->scan_confirm_thread = 0;
173 }
174
175 ChannelEditWindow::~ChannelEditWindow()
176 {
177         if( thread->scan_thread )
178                 thread->scan_thread->stop();
179         channel_list.remove_all_objects();
180         delete edit_thread;
181         delete picture_thread;
182         delete scan_confirm_thread;
183 }
184
185 void ChannelEditWindow::create_objects()
186 {
187         int x = 10, y = 10;
188
189 // Create channel list
190         for(int i = 0; i < thread->new_channels->size(); i++)
191         {
192                 channel_list.append(new BC_ListBoxItem(thread->new_channels->get(i)->title));
193         }
194
195         add_subwindow(list_box = new ChannelEditList(this, x, y));
196         x += 200;
197         if(channel_picker->use_select())
198         {
199                 add_subwindow(new ChannelEditSelect(this, x, y));
200                 y += 30;
201         }
202         add_subwindow(new ChannelEditAdd(this, x, y));
203         y += 30;
204         add_subwindow(new ChannelEdit(this, x, y));
205         y += 30;
206         add_subwindow(new ChannelEditMoveUp(this, x, y));
207         y += 30;
208         add_subwindow(new ChannelEditMoveDown(this, x, y));
209         y += 30;
210         add_subwindow(new ChannelEditSort(this, x, y));
211         y += 30;
212
213         Channel *channel_usage = channel_picker->get_channel_usage();
214         if(channel_usage && channel_usage->has_scanning)
215         {
216                 add_subwindow(new ChannelEditScan(this, x, y));
217                 y += 30;
218         }
219         add_subwindow(new ChannelEditDel(this, x, y));
220         y += 30;
221         add_subwindow(new ChannelEditPicture(this, x, y));
222         y += 100;
223         x = 10;
224         add_subwindow(new BC_OKButton(this));
225         x += 150;
226         add_subwindow(new BC_CancelButton(this));
227
228
229         edit_thread = new ChannelEditEditThread(this, channel_picker);
230         picture_thread = new ChannelEditPictureThread(channel_picker);
231         show_window();
232 }
233
234 int ChannelEditWindow::close_event()
235 {
236         if( thread->scan_thread )
237                 thread->scan_thread->stop();
238         return BC_WindowBase::close_event();
239 }
240
241 int ChannelEditWindow::translation_event()
242 {
243         channel_picker->mwindow->session->channels_x = get_x();
244         channel_picker->mwindow->session->channels_y = get_y();
245         return 0;
246 }
247
248
249 int ChannelEditWindow::add_channel()
250 {
251         Channel *new_channel;
252         Channel *prev_channel = 0;
253
254 // Create new channel
255         new_channel = new Channel;
256
257 // Reuse parameters from previous channel
258         if(thread->new_channels->size())
259         {
260                 prev_channel = thread->new_channels->get(
261                                 thread->new_channels->size() - 1);
262                 new_channel->copy_settings(prev_channel);
263         }
264         else
265 // Use default channel parameters
266         if(channel_picker->get_master_channel())
267         {
268                 new_channel->copy_settings(channel_picker->get_master_channel());
269         }
270
271 // Copy device usage.  Need the same thing for playback.
272         if(channel_picker->get_master_channel())
273         {
274                 new_channel->copy_usage(channel_picker->get_master_channel());
275         }
276
277 // Add to channel table
278         channel_list.append(new BC_ListBoxItem(new_channel->title));
279         thread->new_channels->append(new_channel);
280         update_list();
281
282 // Start common routing
283         edit_thread->edit_channel(new_channel, 0);
284         return 0;
285 }
286
287 void ChannelEditWindow::update_list()
288 {
289 // Create channel list
290         channel_list.remove_all_objects();
291         for(int i = 0; i < thread->new_channels->size(); i++)
292         {
293                 channel_list.append(
294                         new BC_ListBoxItem(
295                                 thread->new_channels->get(i)->title));
296         }
297
298         list_box->update(&channel_list, 0, 0, 1, list_box->get_yposition());
299 }
300
301 void ChannelEditWindow::update_list(Channel *channel)
302 {
303         int i;
304         for(i = 0; i < thread->new_channels->size(); i++)
305                 if(thread->new_channels->get(i) == channel) break;
306
307         if(i < thread->new_channels->size())
308         {
309                 channel_list.values[i]->set_text(channel->title);
310         }
311
312         update_list();
313 }
314
315
316 void ChannelEditWindow::edit_channel()
317 {
318         if(list_box->get_selection_number(0, 0) > -1)
319         {
320                 thread->current_channel = list_box->get_selection_number(0, 0);
321                 edit_thread->edit_channel(
322                         thread->new_channels->get(
323                                 list_box->get_selection_number(0, 0)),
324                         1);
325         }
326 }
327
328 void ChannelEditWindow::edit_picture()
329 {
330         picture_thread->edit_picture();
331 }
332
333 void ChannelEditWindow::scan_confirm()
334 {
335         channel_picker->load_scan_defaults(&thread->scan_params);
336         if(!scan_confirm_thread) scan_confirm_thread = new ConfirmScanThread(this);
337         unlock_window();
338         scan_confirm_thread->start();
339         lock_window("ChannelEditWindow::scan_confirm");
340 }
341
342 void ChannelEditWindow::scan()
343 {
344         thread->new_channels->clear();
345         update_list();
346
347         if( !thread->scan_thread )
348                 thread->scan_thread = new ScanThread(thread);
349         thread->scan_thread->start();
350 }
351
352
353 void ChannelEditWindow::get_chan_num(Channel *channel, int &chan, int &stream)
354 {
355         const char *cp = channel->title;
356         int chn = 0, str = 0;
357         while( isdigit(*cp) ) chn = 10*chn + (*cp++ -'0');
358         if( chn != 0 && *cp != 0 ) {
359                 if( *cp++ == '.' )
360                         while( isdigit(*cp) ) str = 10*str + (*cp++ -'0');
361                 if( !str ) chn = 0;
362         }
363         chan = chn;  stream = str;
364 }
365
366 void ChannelEditWindow::sort()
367 {
368         int done = 0;
369         while(!done) {
370                 done = 1;
371                 for(int i = 0; i < thread->new_channels->size() - 1; i++) {
372                         Channel *channel1 = thread->new_channels->get(i);
373                         Channel *channel2 = thread->new_channels->get(i + 1);
374                         int ch1, st1;  get_chan_num(channel1, ch1, st1);
375                         int ch2, st2;  get_chan_num(channel2, ch2, st2);
376                         if( (ch1 > 0 && ch2 > 0) ?
377                              (ch1 > ch2 || (ch1 == ch2 && (st1 > st2 || (st1 == st2 &&
378                                 strcasecmp(channel2->title, channel1->title) < 0)))) :
379                              strcasecmp(channel2->title, channel1->title) < 0) {
380                                 thread->new_channels->set(i, channel2);
381                                 thread->new_channels->set(i + 1, channel1);
382                                 done = 0;
383                         }
384                 }
385         }
386         update_list();
387 }
388
389
390 void ChannelEditWindow::delete_channel(int number)
391 {
392         delete thread->new_channels->get(number);
393         channel_list.remove_number(number);
394         thread->new_channels->remove_number(number);
395         update_list();
396 }
397
398 void ChannelEditWindow::delete_channel(Channel *channel)
399 {
400         int i;
401         for(i = 0; i < thread->new_channels->size(); i++)
402         {
403                 if(thread->new_channels->get(i) == channel)
404                 {
405                         break;
406                 }
407         }
408         if(i < thread->new_channels->size()) delete_channel(i);
409 }
410
411 int ChannelEditWindow::move_channel_up()
412 {
413         if(list_box->get_selection_number(0, 0) > -1)
414         {
415                 int number2 = list_box->get_selection_number(0, 0);
416                 int number1 = number2 - 1;
417                 Channel *temp;
418                 BC_ListBoxItem *temp_text;
419
420                 if(number1 < 0) number1 = thread->new_channels->size() - 1;
421
422                 temp = thread->new_channels->get(number1);
423                 thread->new_channels->set(number1, thread->new_channels->get(number2));
424                 thread->new_channels->set(number2, temp);
425
426                 temp_text = channel_list.values[number1];
427                 channel_list.values[number1] = channel_list.values[number2];
428                 channel_list.values[number2] = temp_text;
429                 list_box->update(&channel_list,
430                         0,
431                         0,
432                         1,
433                         list_box->get_xposition(),
434                         list_box->get_yposition(),
435                         number1,
436                         1);
437         }
438         return 0;
439 }
440
441 int ChannelEditWindow::move_channel_down()
442 {
443         if(list_box->get_selection_number(0, 0) > -1)
444         {
445                 int number2 = list_box->get_selection_number(0, 0);
446                 int number1 = number2 + 1;
447                 Channel *temp;
448                 BC_ListBoxItem *temp_text;
449
450                 if(number1 > thread->new_channels->size() - 1) number1 = 0;
451
452                 temp = thread->new_channels->get(number1);
453                 thread->new_channels->set(number1, thread->new_channels->get(number2));
454                 thread->new_channels->set(number2, temp);
455                 temp_text = channel_list.values[number1];
456                 channel_list.values[number1] = channel_list.values[number2];
457                 channel_list.values[number2] = temp_text;
458                 list_box->update(&channel_list,
459                         0,
460                         0,
461                         1,
462                         list_box->get_xposition(),
463                         list_box->get_yposition(),
464                         number1,
465                         1);
466         }
467         return 0;
468 }
469
470 int ChannelEditWindow::change_channel_from_list(int channel_number)
471 {
472         if(channel_number > -1 && channel_number < thread->new_channels->size())
473         {
474                 thread->current_channel = channel_number;
475                 channel_picker->set_channel(thread->new_channels->get(channel_number));
476         }
477         return 0;
478 }
479
480 ChannelEditSelect::ChannelEditSelect(ChannelEditWindow *window, int x, int y)
481  : BC_GenericButton(x, y, _("Select"))
482 {
483         this->window = window;
484 }
485 ChannelEditSelect::~ChannelEditSelect()
486 {
487 }
488 int ChannelEditSelect::handle_event()
489 {
490         window->change_channel_from_list(
491                 window->list_box->get_selection_number(0, 0));
492         return 1;
493 }
494
495 ChannelEditAdd::ChannelEditAdd(ChannelEditWindow *window, int x, int y)
496  : BC_GenericButton(x, y, _("Add..."))
497 {
498         this->window = window;
499 }
500 ChannelEditAdd::~ChannelEditAdd()
501 {
502 }
503 int ChannelEditAdd::handle_event()
504 {
505         window->add_channel();
506         return 1;
507 }
508
509 ChannelEditList::ChannelEditList(ChannelEditWindow *window, int x, int y)
510  : BC_ListBox(x,
511                         y,
512                         185,
513                         window->get_h() - BC_OKButton::calculate_h() - y - 10,
514                         LISTBOX_TEXT,
515                         &(window->channel_list))
516 {
517         this->window = window;
518 }
519 ChannelEditList::~ChannelEditList()
520 {
521 }
522 int ChannelEditList::handle_event()
523 {
524         window->edit_channel();
525         return 1;
526 }
527
528 ChannelEditMoveUp::ChannelEditMoveUp(ChannelEditWindow *window, int x, int y)
529  : BC_GenericButton(x, y, _("Move up"))
530 {
531         this->window = window;
532 }
533 ChannelEditMoveUp::~ChannelEditMoveUp()
534 {
535 }
536 int ChannelEditMoveUp::handle_event()
537 {
538         lock_window("ChannelEditMoveUp::handle_event");
539         window->move_channel_up();
540         unlock_window();
541         return 1;
542 }
543
544 ChannelEditMoveDown::ChannelEditMoveDown(ChannelEditWindow *window, int x, int y)
545  : BC_GenericButton(x, y, _("Move down"))
546 {
547         this->window = window;
548 }
549 ChannelEditMoveDown::~ChannelEditMoveDown()
550 {
551 }
552 int ChannelEditMoveDown::handle_event()
553 {
554         lock_window("ChannelEditMoveDown::handle_event");
555         window->move_channel_down();
556         unlock_window();
557         return 1;
558 }
559
560 ChannelEditSort::ChannelEditSort(ChannelEditWindow *window, int x, int y)
561  : BC_GenericButton(x, y, _("Sort"))
562 {
563         this->window = window;
564 }
565 int ChannelEditSort::handle_event()
566 {
567         lock_window("ChannelEditSort::handle_event");
568         window->sort();
569         unlock_window();
570         return 1;
571 }
572
573 ChannelEditScan::ChannelEditScan(ChannelEditWindow *window, int x, int y)
574  : BC_GenericButton(x, y, _("Scan"))
575 {
576         this->window = window;
577 }
578 int ChannelEditScan::handle_event()
579 {
580         window->scan_confirm();
581         return 1;
582 }
583
584 ChannelEditDel::ChannelEditDel(ChannelEditWindow *window, int x, int y)
585  : BC_GenericButton(x, y, _("Delete"))
586 {
587         this->window = window;
588 }
589 ChannelEditDel::~ChannelEditDel()
590 {
591 }
592 int ChannelEditDel::handle_event()
593 {
594         if(window->list_box->get_selection_number(0, 0) > -1)
595                 window->delete_channel(window->list_box->get_selection_number(0, 0));
596         return 1;
597 }
598
599 ChannelEdit::ChannelEdit(ChannelEditWindow *window, int x, int y)
600  : BC_GenericButton(x, y, _("Edit..."))
601 {
602         this->window = window;
603 }
604 ChannelEdit::~ChannelEdit()
605 {
606 }
607 int ChannelEdit::handle_event()
608 {
609         window->edit_channel();
610         return 1;
611 }
612
613 ChannelEditPicture::ChannelEditPicture(ChannelEditWindow *window, int x, int y)
614  : BC_GenericButton(x, y, _("Picture..."))
615 {
616         this->window = window;
617 }
618 ChannelEditPicture::~ChannelEditPicture()
619 {
620 }
621 int ChannelEditPicture::handle_event()
622 {
623         window->edit_picture();
624         return 1;
625 }
626
627
628
629
630
631
632
633
634
635
636
637
638 // ========================= confirm overwrite by channel scannin
639
640
641 ConfirmScan::ConfirmScan(ChannelEditWindow *gui, int x, int y)
642  : BC_Window(PROGRAM_NAME ": Scan confirm",
643         x,
644         y,
645         350,
646         BC_OKButton::calculate_h() + 130,
647         0,
648         0,
649         0,
650         0,
651         1)
652 {
653         this->gui = gui;
654 }
655
656 void ConfirmScan::create_objects()
657 {
658         int x = 10, y = 10;
659         int y2 = 0, x2 = 0;
660         BC_Title *title;
661         add_subwindow(title = new BC_Title(x, y, _("Set parameters for channel scanning.")));
662         y += title->get_h() + 10;
663         y2 = y;
664
665         add_subwindow(title = new BC_Title(x, y, _("Frequency table:")));
666         x2 = title->get_w();
667         y += BC_PopupMenu::calculate_h();
668         add_subwindow(title = new BC_Title(x, y, _("Norm:")));
669         x2 = MAX(x2, title->get_w());
670         y += BC_PopupMenu::calculate_h();
671         add_subwindow(title = new BC_Title(x, y, _("Input:")));
672         x2 = MAX(x2, title->get_w());
673         y += BC_PopupMenu::calculate_h();
674         x2 += x + 5;
675
676         y = y2;
677         x = x2;
678         ChannelEditEditFreqtable *table;
679         add_subwindow(table = new ChannelEditEditFreqtable(x,
680                 y,
681                 0,
682                 gui->thread));
683         table->add_items();
684         y += table->get_h() + 10;
685
686         ChannelEditEditNorm *norm;
687         add_subwindow(norm = new ChannelEditEditNorm(x,
688                 y,
689                 0,
690                 gui->thread));
691         norm->add_items();
692         y += norm->get_h() + 10;
693
694         ChannelEditEditInput *input;
695         add_subwindow(input = new ChannelEditEditInput(x,
696                 y,
697                 0,
698                 gui->thread));
699         input->add_items();
700
701
702         add_subwindow(new BC_OKButton(this));
703         add_subwindow(new BC_CancelButton(this));
704         show_window();
705 }
706
707
708
709
710
711
712
713 ConfirmScanThread::ConfirmScanThread(ChannelEditWindow *gui)
714  : BC_DialogThread()
715 {
716         this->gui = gui;
717 }
718
719 void ConfirmScanThread::handle_done_event(int result)
720 {
721         gui->channel_picker->save_scan_defaults(&gui->thread->scan_params);
722         if(!result)
723         {
724                 get_gui()->hide_window();
725                 gui->lock_window("ConfirmScanThread::handle_done_event");
726                 gui->scan();
727                 gui->unlock_window();
728         }
729 }
730
731 ConfirmScanThread::~ConfirmScanThread()
732 {
733         close_window();
734 }
735
736 BC_Window* ConfirmScanThread::new_gui()
737 {
738         int x = gui->get_abs_cursor_x(1);
739         int y = gui->get_abs_cursor_y(1);
740         ConfirmScan *result = new ConfirmScan(gui, x, y);
741         result->create_objects();
742         return result;
743 }
744
745
746
747
748
749
750 ScanThread::ScanThread(ChannelEditThread *edit)
751  : Thread(1, 0, 0)
752 {
753         this->edit = edit;
754         interrupt = 1;
755         progress = 0;
756 }
757
758 ScanThread::~ScanThread()
759 {
760         stop();
761 }
762
763 void ScanThread::stop()
764 {
765 // Cancel previous job
766         interrupt = 1;
767         Thread::join();
768         if( progress ) {
769                 progress->stop_progress();
770                 delete progress;  progress = 0;
771         }
772 }
773
774 void ScanThread::start()
775 {
776         stop();
777         interrupt = 0;
778
779         progress = new BC_ProgressBox(
780                 edit->channel_picker->parent_window->get_abs_cursor_x(1),
781                 edit->channel_picker->parent_window->get_abs_cursor_y(1),
782                 "Scanning",
783                 chanlists[edit->scan_params.freqtable].count);
784         progress->start();
785
786         Thread::start();
787 }
788
789 void ScanThread::run()
790 {
791         for(int i = 0; i < chanlists[edit->scan_params.freqtable].count &&
792                         !interrupt && !progress->is_cancelled(); i++) {
793                 edit->scan_params.entry = i;
794                 char string[BCTEXTLEN];
795                 sprintf(edit->scan_params.title, "%s",
796                         chanlists[edit->scan_params.freqtable].list[i].name);
797                 sprintf(string, "Scanning %s", edit->scan_params.title);
798                 progress->update_title(string, 1);
799                 progress->update(i, 1);
800                 edit->channel_picker->set_channel(&edit->scan_params);
801                 sleep(1); // has_signal should do whatever it takes
802                 if( interrupt ) break;
803                 int got_signal = edit->channel_picker->has_signal();
804                 if( interrupt ) break;
805                 if(!got_signal) continue;
806                 if(edit->channel_picker->get_channel_usage()->has_subchan) {
807                         ArrayList<Channel*> channels;
808                         edit->channel_picker->create_channeldb(&channels);
809                         if( channels.total ) {
810                                 edit->window->lock_window("ScanThread::run");
811                                 for( int i=0; i<channels.total; ++i ) {
812                                         Channel *new_channel = channels.values[i];
813                                         new_channel->copy_usage(&edit->scan_params);
814                                         edit->new_channels->append(new_channel);
815                                 }
816                                 edit->window->update_list();
817                                 edit->window->unlock_window();
818                                 continue;
819                         }
820                 }
821                 Channel *new_channel = new Channel;
822                 new_channel->copy_usage(&edit->scan_params);
823                 new_channel->copy_settings(&edit->scan_params);
824                 edit->window->lock_window("ScanThread::run");
825                 edit->new_channels->append(new_channel);
826                 edit->window->update_list();
827                 edit->window->unlock_window();
828         }
829 }
830
831
832
833
834
835
836
837 // ================================= Edit a single channel
838
839
840
841 ChannelEditEditThread::ChannelEditEditThread(ChannelEditWindow *window,
842         ChannelPicker *channel_picker)
843  : Thread()
844 {
845         this->window = window;
846         this->channel_picker = channel_picker;
847         in_progress = 0;
848         edit_window = 0;
849         editing = 0;
850         completion = new Condition(1, "ChannelEditEditThread::completion");
851 }
852
853 ChannelEditEditThread::~ChannelEditEditThread()
854 {
855         close_threads();
856         delete completion;
857 }
858
859 void ChannelEditEditThread::close_threads()
860 {
861         if(edit_window)
862         {
863                 edit_window->set_done(1);
864                 completion->lock("ChannelEditEditThread::close_threads");
865                 completion->unlock();
866         }
867 }
868
869 int ChannelEditEditThread::edit_channel(Channel *channel, int editing)
870 {
871         if(in_progress)
872         {
873                 edit_window->lock_window("ChannelEditEditThread::edit_channel");
874                 edit_window->raise_window(1);
875                 edit_window->unlock_window();
876                 return 1;
877         }
878         in_progress = 1;
879
880 // Copy the channel to edit into a temporary
881         completion->lock("ChannelEditEditThread::edit_channel");
882         this->editing = editing;
883         this->output_channel = channel;
884         new_channel.copy_settings(output_channel);
885         new_channel.copy_usage(output_channel);
886
887         if(editing && new_channel.title[0])
888                 user_title = 1;
889         else
890                 user_title = 0;
891         set_synchronous(0);
892         Thread::start();
893         return 0;
894 }
895
896
897 void ChannelEditEditThread::set_device()
898 {
899         channel_picker->set_channel(&new_channel);
900 }
901
902 void ChannelEditEditThread::change_source(const char *source_name)
903 {
904         for(int i = 0; i < chanlists[new_channel.freqtable].count; i++)
905         {
906                 if(!strcasecmp(chanlists[new_channel.freqtable].list[i].name, source_name))
907                 {
908                         new_channel.entry = i;
909                         i = chanlists[new_channel.freqtable].count;
910                         set_device();
911                 }
912         }
913         if(!user_title)
914         {
915                 strcpy(new_channel.title, source_name);
916                 if(edit_window->title_text)
917                 {
918                         edit_window->title_text->update(source_name);
919                 }
920         }
921 }
922
923 void ChannelEditEditThread::source_up()
924 {
925         new_channel.entry++;
926         if(new_channel.entry > chanlists[new_channel.freqtable].count - 1) new_channel.entry = 0;
927         source_text->update(chanlists[new_channel.freqtable].list[new_channel.entry].name);
928         set_device();
929 }
930
931 void ChannelEditEditThread::source_down()
932 {
933         new_channel.entry--;
934         if(new_channel.entry < 0) new_channel.entry = chanlists[new_channel.freqtable].count - 1;
935         source_text->update(chanlists[new_channel.freqtable].list[new_channel.entry].name);
936         set_device();
937 }
938
939 void ChannelEditEditThread::set_input(int value)
940 {
941         new_channel.input = value;
942         set_device();
943 }
944
945 void ChannelEditEditThread::set_norm(int value)
946 {
947         new_channel.norm = value;
948         set_device();
949 }
950
951 void ChannelEditEditThread::set_freqtable(int value)
952 {
953         new_channel.freqtable = value;
954         if(new_channel.entry > chanlists[new_channel.freqtable].count - 1) new_channel.entry = 0;
955         source_text->update(chanlists[new_channel.freqtable].list[new_channel.entry].name);
956         set_device();
957 }
958
959 void ChannelEditEditThread::run()
960 {
961         ChannelEditEditWindow edit_window(this, window, channel_picker);
962         edit_window.create_objects(&new_channel);
963         this->edit_window = &edit_window;
964         int result = edit_window.run_window();
965         this->edit_window = 0;
966
967 // Done editing channel.  Keep channel.
968         if(!result)
969         {
970                 output_channel->copy_settings(&new_channel);
971                 window->lock_window();
972                 window->update_list(output_channel);
973                 window->unlock_window();
974         }
975         else
976         {
977 // Discard channel.
978                 if(!editing)
979                 {
980                         window->lock_window();
981                         window->delete_channel(output_channel);
982                         window->unlock_window();
983                 }
984         }
985         editing = 0;
986         completion->unlock();
987         in_progress = 0;
988 }
989
990 ChannelEditEditWindow::ChannelEditEditWindow(ChannelEditEditThread *thread,
991         ChannelEditWindow *window,
992         ChannelPicker *channel_picker)
993  : BC_Window(PROGRAM_NAME ": Edit Channel",
994         channel_picker->parent_window->get_abs_cursor_x(1),
995         channel_picker->parent_window->get_abs_cursor_y(1),
996         390,
997         300,
998         390,
999         300,
1000         0,
1001         0,
1002         1)
1003 {
1004         this->channel_picker = channel_picker;
1005         this->window = window;
1006         this->thread = thread;
1007 }
1008 ChannelEditEditWindow::~ChannelEditEditWindow()
1009 {
1010 }
1011 void ChannelEditEditWindow::create_objects(Channel *channel)
1012 {
1013         this->new_channel = channel;
1014         Channel *channel_usage = channel_picker->get_channel_usage();
1015         title_text = 0;
1016
1017         int x = 10, y = 10;
1018 //      if(!channel_usage ||
1019 //              (!channel_usage->use_frequency &&
1020 //              !channel_usage->use_fine &&
1021 //              !channel_usage->use_norm &&
1022 //              !channel_usage->use_input))
1023 //      {
1024 //              add_subwindow(new BC_Title(x, y, "Device has no input selection."));
1025 //              y += 30;
1026 //      }
1027 //      else
1028 //      {
1029                 add_subwindow(new BC_Title(x, y, _("Title:")));
1030                 add_subwindow(title_text = new ChannelEditEditTitle(x, y + 20, thread));
1031                 y += 50;
1032 //      }
1033
1034         if(channel_usage && channel_usage->use_frequency)
1035         {
1036                 add_subwindow(new BC_Title(x, y, _("Channel:")));
1037                 y += 20;
1038                 add_subwindow(thread->source_text = new ChannelEditEditSource(x, y, thread));
1039                 add_subwindow(new ChannelEditEditSourceTumbler(x + 160, y, thread));
1040                 y += 40;
1041
1042                 add_subwindow(new BC_Title(x, y, _("Frequency table:")));
1043                 ChannelEditEditFreqtable *table;
1044                 add_subwindow(table = new ChannelEditEditFreqtable(x + 130,
1045                         y,
1046                         thread,
1047                         window->thread));
1048                 table->add_items();
1049                 y += 30;
1050         }
1051
1052         if(channel_usage && channel_usage->use_fine)
1053         {
1054                 add_subwindow(new BC_Title(x, y, _("Fine:")));
1055                 add_subwindow(new ChannelEditEditFine(x + 130, y, thread));
1056                 y += 30;
1057         }
1058
1059         if(channel_usage && channel_usage->use_norm)
1060         {
1061                 add_subwindow(new BC_Title(x, y, _("Norm:")));
1062                 ChannelEditEditNorm *norm;
1063                 add_subwindow(norm = new ChannelEditEditNorm(x + 130,
1064                         y,
1065                         thread,
1066                         window->thread));
1067                 norm->add_items();
1068                 y += 30;
1069         }
1070
1071         if( (channel_usage && channel_usage->use_input) ||
1072                 !channel_usage)
1073         {
1074                 add_subwindow(new BC_Title(x, y, _("Input:")));
1075                 ChannelEditEditInput *input;
1076                 add_subwindow(input = new ChannelEditEditInput(x + 130,
1077                         y,
1078                         thread,
1079                         window->thread));
1080                 input->add_items();
1081                 y += 30;
1082         }
1083
1084         add_subwindow(new BC_OKButton(this));
1085         x += 200;
1086         add_subwindow(new BC_CancelButton(this));
1087         show_window();
1088 }
1089
1090 ChannelEditEditTitle::ChannelEditEditTitle(int x,
1091         int y,
1092         ChannelEditEditThread *thread)
1093  : BC_TextBox(x, y, 150, 1, thread->new_channel.title)
1094 {
1095         this->thread = thread;
1096 }
1097 ChannelEditEditTitle::~ChannelEditEditTitle()
1098 {
1099 }
1100 int ChannelEditEditTitle::handle_event()
1101 {
1102         if(strlen(get_text()) < 1024)
1103         {
1104                 strcpy(thread->new_channel.title, get_text());
1105         }
1106         thread->user_title = get_text()[0] ? 1 : 0;
1107         return 1;
1108 }
1109
1110
1111 ChannelEditEditSource::ChannelEditEditSource(int x, int y, ChannelEditEditThread *thread)
1112  : BC_TextBox(x, y, 150, 1, chanlists[thread->new_channel.freqtable].list[thread->new_channel.entry].name)
1113 {
1114         this->thread = thread;
1115 }
1116
1117 ChannelEditEditSource::~ChannelEditEditSource()
1118 {
1119 }
1120 int ChannelEditEditSource::handle_event()
1121 {
1122         thread->change_source(get_text());
1123         return 1;
1124 }
1125
1126
1127 ChannelEditEditSourceTumbler::ChannelEditEditSourceTumbler(int x, int y, ChannelEditEditThread *thread)
1128  : BC_Tumbler(x, y)
1129 {
1130         this->thread = thread;
1131 }
1132 ChannelEditEditSourceTumbler::~ChannelEditEditSourceTumbler()
1133 {
1134 }
1135 int ChannelEditEditSourceTumbler::handle_up_event()
1136 {
1137         thread->source_up();
1138         return 1;
1139 }
1140 int ChannelEditEditSourceTumbler::handle_down_event()
1141 {
1142         thread->source_down();
1143         return 1;
1144 }
1145
1146 ChannelEditEditInput::ChannelEditEditInput(int x,
1147         int y,
1148         ChannelEditEditThread *thread,
1149         ChannelEditThread *edit)
1150  : BC_PopupMenu(x,
1151         y,
1152         150,
1153         edit->value_to_input(thread ? thread->new_channel.input : edit->scan_params.input))
1154 {
1155         this->thread = thread;
1156         this->edit = edit;
1157 }
1158 ChannelEditEditInput::~ChannelEditEditInput()
1159 {
1160 }
1161 void ChannelEditEditInput::add_items()
1162 {
1163         ArrayList<Channel*> *inputs;
1164         inputs = edit->channel_picker->get_video_inputs();
1165
1166         if(inputs)
1167         {
1168                 for(int i = 0; i < inputs->total; i++)
1169                 {
1170                         add_item(new ChannelEditEditInputItem(thread,
1171                                 edit,
1172                                 inputs->values[i]->device_name,
1173                                 i));
1174                 }
1175         }
1176 }
1177 int ChannelEditEditInput::handle_event()
1178 {
1179         return 0;
1180 }
1181
1182 ChannelEditEditInputItem::ChannelEditEditInputItem(ChannelEditEditThread *thread,
1183         ChannelEditThread *edit,
1184         char *text,
1185         int value)
1186  : BC_MenuItem(text)
1187 {
1188         this->thread = thread;
1189         this->edit = edit;
1190         this->value = value;
1191 }
1192 ChannelEditEditInputItem::~ChannelEditEditInputItem()
1193 {
1194 }
1195 int ChannelEditEditInputItem::handle_event()
1196 {
1197         get_popup_menu()->set_text(get_text());
1198         if(thread && !thread->user_title)
1199         {
1200                 strcpy(thread->new_channel.title, get_text());
1201                 if(thread->edit_window->title_text)
1202                 {
1203                         thread->edit_window->title_text->update(get_text());
1204                 }
1205         }
1206         if(thread)
1207                 thread->set_input(value);
1208         else
1209                 edit->scan_params.input = value;
1210         return 1;
1211 }
1212
1213 ChannelEditEditNorm::ChannelEditEditNorm(int x,
1214         int y,
1215         ChannelEditEditThread *thread,
1216         ChannelEditThread *edit)
1217  : BC_PopupMenu(x,
1218         y,
1219         100,
1220         edit->value_to_norm(thread ? thread->new_channel.norm : edit->scan_params.norm))
1221 {
1222         this->thread = thread;
1223         this->edit = edit;
1224 }
1225 ChannelEditEditNorm::~ChannelEditEditNorm()
1226 {
1227 }
1228 void ChannelEditEditNorm::add_items()
1229 {
1230         add_item(new ChannelEditEditNormItem(thread,
1231                 edit,
1232                 edit->value_to_norm(NTSC), NTSC));
1233         add_item(new ChannelEditEditNormItem(thread,
1234                 edit,
1235                 edit->value_to_norm(PAL), PAL));
1236         add_item(new ChannelEditEditNormItem(thread,
1237                 edit,
1238                 edit->value_to_norm(SECAM), SECAM));
1239 }
1240
1241
1242 ChannelEditEditNormItem::ChannelEditEditNormItem(ChannelEditEditThread *thread,
1243         ChannelEditThread *edit,
1244         char *text,
1245         int value)
1246  : BC_MenuItem(text)
1247 {
1248         this->value = value;
1249         this->edit = edit;
1250         this->thread = thread;
1251 }
1252 ChannelEditEditNormItem::~ChannelEditEditNormItem()
1253 {
1254 }
1255 int ChannelEditEditNormItem::handle_event()
1256 {
1257         get_popup_menu()->set_text(get_text());
1258         if(thread)
1259                 thread->set_norm(value);
1260         else
1261                 edit->scan_params.norm = value;
1262         return 1;
1263 }
1264
1265
1266 ChannelEditEditFreqtable::ChannelEditEditFreqtable(int x,
1267         int y,
1268         ChannelEditEditThread *thread,
1269         ChannelEditThread *edit)
1270  : BC_PopupMenu(x,
1271         y,
1272         150,
1273         edit->value_to_freqtable(thread ? thread->new_channel.freqtable : edit->scan_params.freqtable))
1274 {
1275         this->thread = thread;
1276         this->edit = edit;
1277 }
1278 ChannelEditEditFreqtable::~ChannelEditEditFreqtable()
1279 {
1280 }
1281 void ChannelEditEditFreqtable::add_items()
1282 {
1283         add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_DVB), NTSC_DVB));
1284         add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(CATV_DVB), CATV_DVB));
1285         add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_BCAST), NTSC_BCAST));
1286         add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_CABLE), NTSC_CABLE));
1287         add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_HRC), NTSC_HRC));
1288         add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_BCAST_JP), NTSC_BCAST_JP));
1289         add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_CABLE_JP), NTSC_CABLE_JP));
1290         add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_AUSTRALIA), PAL_AUSTRALIA));
1291         add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_EUROPE), PAL_EUROPE));
1292         add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_E_EUROPE), PAL_E_EUROPE));
1293         add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_ITALY), PAL_ITALY));
1294         add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_IRELAND), PAL_IRELAND));
1295         add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_NEWZEALAND), PAL_NEWZEALAND));
1296 }
1297
1298 ChannelEditEditFreqItem::ChannelEditEditFreqItem(ChannelEditEditThread *thread,
1299         ChannelEditThread *edit,
1300         char *text, int value)
1301  : BC_MenuItem(text)
1302 {
1303         this->value = value;
1304         this->edit = edit;
1305         this->thread = thread;
1306 }
1307 ChannelEditEditFreqItem::~ChannelEditEditFreqItem()
1308 {
1309 }
1310 int ChannelEditEditFreqItem::handle_event()
1311 {
1312         get_popup_menu()->set_text(get_text());
1313         if(thread)
1314                 thread->set_freqtable(value);
1315         else
1316                 edit->scan_params.freqtable = value;
1317         return 1;
1318 }
1319
1320
1321
1322 ChannelEditEditFine::ChannelEditEditFine(int x,
1323         int y,
1324         ChannelEditEditThread *thread)
1325  : BC_ISlider(x,
1326                 y,
1327                 0,
1328                 240,
1329                 240,
1330                 -100,
1331                 100,
1332                 thread->new_channel.fine_tune)
1333 {
1334         this->thread = thread;
1335 }
1336 ChannelEditEditFine::~ChannelEditEditFine()
1337 {
1338 }
1339 int ChannelEditEditFine::handle_event()
1340 {
1341         return 1;
1342 }
1343 int ChannelEditEditFine::button_release_event()
1344 {
1345         if(BC_Slider::button_release_event())
1346         {
1347                 thread->new_channel.fine_tune = get_value();
1348                 thread->set_device();
1349                 return 1;
1350         }
1351         return 0;
1352 }
1353
1354
1355 // ========================== picture quality
1356
1357 ChannelEditPictureThread::ChannelEditPictureThread(
1358         ChannelPicker *channel_picker)
1359  : BC_DialogThread()
1360 {
1361         this->channel_picker = channel_picker;
1362 }
1363 ChannelEditPictureThread::~ChannelEditPictureThread()
1364 {
1365 }
1366
1367 void ChannelEditPictureThread::handle_done_event(int result)
1368 {
1369         if(channel_picker->get_picture_usage())
1370                 channel_picker->get_picture_usage()->save_defaults();
1371 }
1372
1373 BC_Window* ChannelEditPictureThread::new_gui()
1374 {
1375         ChannelEditPictureWindow *edit_window = new ChannelEditPictureWindow(this,
1376                 channel_picker);
1377         edit_window->create_objects();
1378         return edit_window;
1379 }
1380
1381 void ChannelEditPictureThread::edit_picture()
1382 {
1383         start();
1384 }
1385
1386
1387 ChannelEditPictureWindow::ChannelEditPictureWindow(ChannelEditPictureThread *thread,
1388         ChannelPicker *channel_picker)
1389  : BC_Window(PROGRAM_NAME ": Picture",
1390         channel_picker->mwindow->session->picture_x,
1391         channel_picker->mwindow->session->picture_y,
1392         calculate_w(channel_picker),
1393         calculate_h(channel_picker),
1394         calculate_w(channel_picker),
1395         calculate_h(channel_picker))
1396 {
1397         this->thread = thread;
1398         this->channel_picker = channel_picker;
1399 }
1400 ChannelEditPictureWindow::~ChannelEditPictureWindow()
1401 {
1402 }
1403
1404 int ChannelEditPictureWindow::calculate_h(ChannelPicker *channel_picker)
1405 {
1406         PictureConfig *picture_usage = channel_picker->get_picture_usage();
1407         int pad = BC_Pot::calculate_h();
1408         int result = 20 +
1409                 channel_picker->parent_window->get_text_height(MEDIUMFONT) + 5 +
1410                 BC_OKButton::calculate_h();
1411
1412 // Only used for Video4Linux 1
1413         if(picture_usage)
1414         {
1415                 if(picture_usage->use_brightness)
1416                         result += pad;
1417                 if(picture_usage->use_contrast)
1418                         result += pad;
1419                 if(picture_usage->use_color)
1420                         result += pad;
1421                 if(picture_usage->use_hue)
1422                         result += pad;
1423                 if(picture_usage->use_whiteness)
1424                         result += pad;
1425         }
1426
1427         result += channel_picker->get_controls() * pad;
1428         return result;
1429 }
1430
1431 int ChannelEditPictureWindow::calculate_w(ChannelPicker *channel_picker)
1432 {
1433         PictureConfig *picture_usage = channel_picker->get_picture_usage();
1434         int widget_border = ((Theme*)channel_picker->get_theme())->widget_border;
1435         int pad = BC_Pot::calculate_w() + 4 * widget_border;
1436         int result = 0;
1437
1438 // Only used for Video4Linux 1
1439         if(!picture_usage ||
1440                 (!picture_usage->use_brightness &&
1441                 !picture_usage->use_contrast &&
1442                 !picture_usage->use_color &&
1443                 !picture_usage->use_hue &&
1444                 !picture_usage->use_whiteness &&
1445                 !channel_picker->get_controls()))
1446         {
1447                 result = BC_Title::calculate_w(channel_picker->parent_window,
1448                         "Device has no picture controls." +
1449                         2 * widget_border);
1450         }
1451
1452 // Only used for Video4Linux 1
1453         if(picture_usage)
1454         {
1455                 if(picture_usage->use_brightness)
1456                 {
1457                         int new_w = BC_Title::calculate_w(channel_picker->parent_window, "Brightness:") + pad;
1458                         result = MAX(result, new_w);
1459                 }
1460                 if(picture_usage->use_contrast)
1461                 {
1462                         int new_w = BC_Title::calculate_w(channel_picker->parent_window, "Contrast:") + pad;
1463                         result = MAX(result, new_w);
1464                 }
1465                 if(picture_usage->use_color)
1466                 {
1467                         int new_w = BC_Title::calculate_w(channel_picker->parent_window, "Color:") + pad;
1468                         result = MAX(result, new_w);
1469                 }
1470                 if(picture_usage->use_hue)
1471                 {
1472                         int new_w = BC_Title::calculate_w(channel_picker->parent_window, "Hue:") + pad;
1473                         result = MAX(result, new_w);
1474                 }
1475                 if(picture_usage->use_whiteness)
1476                 {
1477                         int new_w = BC_Title::calculate_w(channel_picker->parent_window, "Whiteness:") + pad;
1478                         result = MAX(result, new_w);
1479                 }
1480         }
1481
1482         for(int i = 0; i < channel_picker->get_controls(); i++)
1483         {
1484                 int new_w = BC_Title::calculate_w(channel_picker->parent_window,
1485                                 channel_picker->get_control(i)->name) +
1486                         pad;
1487                 result = MAX(result, new_w);
1488         }
1489
1490         return result;
1491 }
1492
1493
1494 void ChannelEditPictureWindow::create_objects()
1495 {
1496         int x = 10, y = 10;
1497         int widget_border = ((Theme*)channel_picker->get_theme())->widget_border;
1498         int x1 = get_w() - BC_Pot::calculate_w() * 2 - widget_border * 2;
1499         int x2 = get_w() - BC_Pot::calculate_w() - widget_border;
1500         int pad = BC_Pot::calculate_h();
1501
1502 #define SWAP_X x1 ^= x2; x2 ^= x1; x1 ^= x2;
1503
1504         PictureConfig *picture_usage = channel_picker->get_picture_usage();
1505
1506 // Only used for Video4Linux 1
1507         if(!picture_usage ||
1508                 (!picture_usage->use_brightness &&
1509                 !picture_usage->use_contrast &&
1510                 !picture_usage->use_color &&
1511                 !picture_usage->use_hue &&
1512                 !picture_usage->use_whiteness &&
1513                 !channel_picker->get_controls()))
1514         {
1515                 add_subwindow(new BC_Title(x, y, "Device has no picture controls."));
1516                 y += 50;
1517         }
1518
1519 // Only used for Video4Linux 1
1520         if(picture_usage && picture_usage->use_brightness)
1521         {
1522                 add_subwindow(new BC_Title(x, y + 10, _("Brightness:")));
1523                 add_subwindow(new ChannelEditBright(x1, y, channel_picker, channel_picker->get_brightness()));
1524                 y += pad;
1525                 SWAP_X
1526
1527         }
1528
1529         if(picture_usage && picture_usage->use_contrast)
1530         {
1531                 add_subwindow(new BC_Title(x, y + 10, _("Contrast:")));
1532                 add_subwindow(new ChannelEditContrast(x1, y, channel_picker, channel_picker->get_contrast()));
1533                 y += pad;
1534                 SWAP_X
1535         }
1536
1537         if(picture_usage && picture_usage->use_color)
1538         {
1539                 add_subwindow(new BC_Title(x, y + 10, _("Color:")));
1540                 add_subwindow(new ChannelEditColor(x1, y, channel_picker, channel_picker->get_color()));
1541                 y += pad;
1542                 SWAP_X
1543         }
1544
1545         if(picture_usage && picture_usage->use_hue)
1546         {
1547                 add_subwindow(new BC_Title(x, y + 10, _("Hue:")));
1548                 add_subwindow(new ChannelEditHue(x1, y, channel_picker, channel_picker->get_hue()));
1549                 y += pad;
1550                 SWAP_X
1551         }
1552
1553         if(picture_usage && picture_usage->use_whiteness)
1554         {
1555                 add_subwindow(new BC_Title(x, y + 10, _("Whiteness:")));
1556                 add_subwindow(new ChannelEditWhiteness(x1, y, channel_picker, channel_picker->get_whiteness()));
1557                 y += pad;
1558                 SWAP_X
1559         }
1560
1561         for(int i = 0; i < channel_picker->get_controls(); i++)
1562         {
1563                 BC_Title *title;
1564                 add_subwindow(title = new BC_Title(x,
1565                         y + 10,
1566                         _(channel_picker->get_control(i)->name)));
1567
1568                 int x3 = x1;
1569                 if(x3 < title->get_x() + title->get_w() + widget_border)
1570                         x3 = title->get_x() + title->get_w() + widget_border;
1571
1572                 add_subwindow(new ChannelEditCommon(x3,
1573                         y,
1574                         channel_picker,
1575                         channel_picker->get_control(i)));
1576                 y += pad;
1577                 SWAP_X
1578         }
1579
1580
1581         y += pad;
1582         add_subwindow(new BC_OKButton(this));
1583         show_window();
1584 }
1585
1586 int ChannelEditPictureWindow::translation_event()
1587 {
1588         channel_picker->mwindow->session->picture_x = get_x();
1589         channel_picker->mwindow->session->picture_y = get_y();
1590         return 0;
1591 }
1592
1593
1594
1595 ChannelEditBright::ChannelEditBright(int x, int y, ChannelPicker *channel_picker, int value)
1596  : BC_IPot(x,
1597                 y,
1598                 value,
1599                 -100,
1600                 100)
1601 {
1602         this->channel_picker = channel_picker;
1603 }
1604 ChannelEditBright::~ChannelEditBright() {}
1605 int ChannelEditBright::handle_event()
1606 {
1607         return 1;
1608 }
1609 int ChannelEditBright::button_release_event()
1610 {
1611         if(BC_Pot::button_release_event())
1612         {
1613                 channel_picker->set_brightness(get_value());
1614                 return 1;
1615         }
1616         return 0;
1617 }
1618
1619 ChannelEditContrast::ChannelEditContrast(int x, int y, ChannelPicker *channel_picker, int value)
1620  : BC_IPot(x,
1621                 y,
1622                 value,
1623                 -100,
1624                 100)
1625 {
1626         this->channel_picker = channel_picker;
1627 }
1628 ChannelEditContrast::~ChannelEditContrast() {}
1629 int ChannelEditContrast::handle_event()
1630 {
1631         return 1;
1632 }
1633 int ChannelEditContrast::button_release_event()
1634 {
1635         if(BC_Pot::button_release_event())
1636         {
1637                 channel_picker->set_contrast(get_value());
1638                 return 1;
1639         }
1640         return 0;
1641 }
1642
1643
1644 ChannelEditColor::ChannelEditColor(int x, int y, ChannelPicker *channel_picker, int value)
1645  : BC_IPot(x,
1646                 y,
1647                 value,
1648                 -100,
1649                 100)
1650 {
1651         this->channel_picker = channel_picker;
1652 }
1653 ChannelEditColor::~ChannelEditColor() {}
1654 int ChannelEditColor::handle_event()
1655 {
1656         return 1;
1657 }
1658 int ChannelEditColor::button_release_event()
1659 {
1660         if(BC_Pot::button_release_event())
1661         {
1662                 channel_picker->set_color(get_value());
1663                 return 1;
1664         }
1665         return 0;
1666 }
1667
1668 ChannelEditHue::ChannelEditHue(int x, int y, ChannelPicker *channel_picker, int value)
1669  : BC_IPot(x,
1670                 y,
1671                 value,
1672                 -100,
1673                 100)
1674 {
1675         this->channel_picker = channel_picker;
1676 }
1677 ChannelEditHue::~ChannelEditHue() {}
1678 int ChannelEditHue::handle_event()
1679 {
1680         return 1;
1681 }
1682 int ChannelEditHue::button_release_event()
1683 {
1684         if(BC_Pot::button_release_event())
1685         {
1686                 channel_picker->set_hue(get_value());
1687                 return 1;
1688         }
1689         return 0;
1690 }
1691
1692 ChannelEditWhiteness::ChannelEditWhiteness(int x, int y, ChannelPicker *channel_picker, int value)
1693  : BC_IPot(x,
1694                 y,
1695                 value,
1696                 -100,
1697                 100)
1698 {
1699         this->channel_picker = channel_picker;
1700 }
1701 ChannelEditWhiteness::~ChannelEditWhiteness()
1702 {
1703 }
1704 int ChannelEditWhiteness::handle_event()
1705 {
1706         return 1;
1707 }
1708 int ChannelEditWhiteness::button_release_event()
1709 {
1710         if(BC_Pot::button_release_event())
1711         {
1712                 channel_picker->set_whiteness(get_value());
1713                 return 1;
1714         }
1715         return 0;
1716 }
1717
1718
1719
1720 ChannelEditCommon::ChannelEditCommon(int x,
1721         int y,
1722         ChannelPicker *channel_picker,
1723         PictureItem *item)
1724  : BC_IPot(x,
1725                 y,
1726                 item->value,
1727                 item->min,
1728                 item->max)
1729 {
1730         this->channel_picker = channel_picker;
1731         this->device_id = item->device_id;
1732 }
1733
1734 ChannelEditCommon::~ChannelEditCommon()
1735 {
1736 }
1737
1738 int ChannelEditCommon::handle_event()
1739 {
1740         return 1;
1741 }
1742
1743 int ChannelEditCommon::button_release_event()
1744 {
1745         if(BC_Pot::button_release_event())
1746         {
1747                 channel_picker->set_picture(device_id, get_value());
1748                 return 1;
1749         }
1750         return 0;
1751 }
1752
1753 int ChannelEditCommon::keypress_event()
1754 {
1755         if(BC_Pot::keypress_event())
1756         {
1757                 channel_picker->set_picture(device_id, get_value());
1758                 return 1;
1759         }
1760         return 0;
1761 }
1762
1763
1764
1765
1766