4 * Copyright (C) 2011 Adam Williams <broadcast at earthling dot net>
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.
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.
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
23 #include "bcprogressbox.h"
24 #include "bcsignals.h"
26 #include "channeldb.h"
27 #include "channeledit.h"
28 #include "channelpicker.h"
29 #include "chantables.h"
31 #include "condition.h"
33 #include "mainsession.h"
37 #include "videodevice.h"
42 #define MSG_NO_PIC_CONTROLS _("Device has no picture controls.")
43 //#define MSG_NO_INP_SELECTION _("Device has no input selection.")
45 ChannelEditThread::ChannelEditThread(ChannelPicker *channel_picker,
49 this->channel_picker = channel_picker;
50 this->channeldb = channeldb;
53 new_channels = new ChannelDB;
54 completion = new Condition(1, "ChannelEditThread::completion");
57 ChannelEditThread::~ChannelEditThread()
65 void ChannelEditThread::run()
71 window->lock_window("ChannelEditThread::run");
72 window->raise_window(1);
73 window->unlock_window();
78 completion->lock("ChannelEditThread::run");
80 // Copy master channel list to temporary.
81 new_channels->copy_from(channel_picker->channeldb);
82 Channel *channel = channel_picker->get_current_channel();
83 current_channel = channel_picker->channeldb->number_of(channel);
84 //printf("ChannelEditThread::run 1 %d\n", current_channel);
86 // Run the channel list window using the temporary list.
87 window = new ChannelEditWindow(this, channel_picker);
88 window->create_objects();
89 int result = window->run_window();
90 delete window; window = 0;
93 // Copy new channels to master list
94 channel_picker->channeldb->clear();
96 channel_picker->channeldb->copy_from(new_channels);
97 channel_picker->update_channel_list();
101 channel_picker->handle_channel_edit(result);
103 completion->unlock();
108 void ChannelEditThread::close_threads()
110 if(in_progress && window)
113 completion->lock("ChannelEditThread::close_threads");
114 completion->unlock();
118 char *ChannelEditThread::value_to_freqtable(int value)
122 case NTSC_DVB: return _("NTSC_DVB");
123 case CATV_DVB: return _("CATV_DVB");
124 case NTSC_BCAST: return _("NTSC_BCAST");
125 case NTSC_CABLE: return _("NTSC_CABLE");
126 case NTSC_HRC: return _("NTSC_HRC");
127 case NTSC_BCAST_JP: return _("NTSC_BCAST_JP");
128 case NTSC_CABLE_JP: return _("NTSC_CABLE_JP");
129 case PAL_AUSTRALIA: return _("PAL_AUSTRALIA");
130 case PAL_EUROPE: return _("PAL_EUROPE");
131 case PAL_E_EUROPE: return _("PAL_E_EUROPE");
132 case PAL_ITALY: return _("PAL_ITALY");
133 case PAL_IRELAND: return _("PAL_IRELAND");
134 case PAL_NEWZEALAND: return _("PAL_NEWZEALAND");
139 char* ChannelEditThread::value_to_norm(int value)
143 case NTSC: return _("NTSC");
144 case PAL: return _("PAL");
145 case SECAM: return _("SECAM");
150 char* ChannelEditThread::value_to_input(int value)
152 ArrayList<Channel*> *inputs = channel_picker->get_video_inputs();
153 return value >= inputs->total ? _("None") :
154 inputs->values[value]->device_name;
163 ChannelEditWindow::ChannelEditWindow(ChannelEditThread *thread,
164 ChannelPicker *channel_picker)
165 : BC_Window(_(PROGRAM_NAME ": Channels"),
166 channel_picker->mwindow->session->channels_x,
167 channel_picker->mwindow->session->channels_y,
168 xS(375), yS(400), xS(375), yS(400), 0, 0, 1)
170 this->thread = thread;
171 this->channel_picker = channel_picker;
172 this->edit_thread = 0;
173 this->picture_thread = 0;
174 this->scan_confirm_thread = 0;
175 // *** CONTEXT_HELP ***
176 context_help_set_keyword("Initial Setup for DVB Capture");
179 ChannelEditWindow::~ChannelEditWindow()
181 if( thread->scan_thread )
182 thread->scan_thread->stop();
183 channel_list.remove_all_objects();
185 delete picture_thread;
186 delete scan_confirm_thread;
189 void ChannelEditWindow::create_objects()
191 int xs10 = xS(10), ys10 = yS(10), ys30 = yS(30);
192 lock_window("ChannelEditWindow::create_objects");
193 int x = xs10, y = ys10;
195 // Create channel list
196 for(int i = 0; i < thread->new_channels->size(); i++)
198 channel_list.append(new BC_ListBoxItem(thread->new_channels->get(i)->title));
201 add_subwindow(list_box = new ChannelEditList(this, x, y));
203 if(channel_picker->use_select())
205 add_subwindow(new ChannelEditSelect(this, x, y));
208 add_subwindow(new ChannelEditAdd(this, x, y));
210 add_subwindow(new ChannelEdit(this, x, y));
212 add_subwindow(new ChannelEditMoveUp(this, x, y));
214 add_subwindow(new ChannelEditMoveDown(this, x, y));
216 add_subwindow(new ChannelEditSort(this, x, y));
219 Channel *channel_usage = channel_picker->get_channel_usage();
220 if(channel_usage && channel_usage->has_scanning)
222 add_subwindow(new ChannelEditScan(this, x, y));
225 add_subwindow(new ChannelEditDel(this, x, y));
227 add_subwindow(new ChannelEditPicture(this, x, y));
230 add_subwindow(new BC_OKButton(this));
232 add_subwindow(new BC_CancelButton(this));
235 edit_thread = new ChannelEditEditThread(this, channel_picker);
236 picture_thread = new ChannelEditPictureThread(channel_picker);
241 int ChannelEditWindow::close_event()
243 if( thread->scan_thread )
244 thread->scan_thread->stop();
245 return BC_WindowBase::close_event();
248 int ChannelEditWindow::translation_event()
250 channel_picker->mwindow->session->channels_x = get_x();
251 channel_picker->mwindow->session->channels_y = get_y();
256 int ChannelEditWindow::add_channel()
258 Channel *new_channel;
259 Channel *prev_channel = 0;
261 // Create new channel
262 new_channel = new Channel;
264 // Reuse parameters from previous channel
265 if(thread->new_channels->size())
267 prev_channel = thread->new_channels->get(
268 thread->new_channels->size() - 1);
269 new_channel->copy_settings(prev_channel);
272 // Use default channel parameters
273 if(channel_picker->get_master_channel())
275 new_channel->copy_settings(channel_picker->get_master_channel());
278 // Copy device usage. Need the same thing for playback.
279 if(channel_picker->get_master_channel())
281 new_channel->copy_usage(channel_picker->get_master_channel());
284 // Add to channel table
285 channel_list.append(new BC_ListBoxItem(new_channel->title));
286 thread->new_channels->append(new_channel);
289 // Start common routing
290 edit_thread->edit_channel(new_channel, 0);
294 void ChannelEditWindow::update_list()
296 // Create channel list
297 channel_list.remove_all_objects();
298 for(int i = 0; i < thread->new_channels->size(); i++)
302 thread->new_channels->get(i)->title));
305 list_box->update(&channel_list, 0, 0, 1, list_box->get_yposition());
308 void ChannelEditWindow::update_list(Channel *channel)
311 for(i = 0; i < thread->new_channels->size(); i++)
312 if(thread->new_channels->get(i) == channel) break;
314 if(i < thread->new_channels->size())
316 channel_list.values[i]->set_text(channel->title);
323 void ChannelEditWindow::edit_channel()
325 if(list_box->get_selection_number(0, 0) > -1)
327 thread->current_channel = list_box->get_selection_number(0, 0);
328 edit_thread->edit_channel(
329 thread->new_channels->get(
330 list_box->get_selection_number(0, 0)),
335 void ChannelEditWindow::edit_picture()
337 picture_thread->edit_picture();
340 void ChannelEditWindow::scan_confirm()
342 channel_picker->load_scan_defaults(&thread->scan_params);
343 if(!scan_confirm_thread) scan_confirm_thread = new ConfirmScanThread(this);
345 scan_confirm_thread->start();
346 lock_window("ChannelEditWindow::scan_confirm");
349 void ChannelEditWindow::scan()
351 thread->new_channels->clear();
354 if( !thread->scan_thread )
355 thread->scan_thread = new ScanThread(thread);
356 thread->scan_thread->start();
360 void ChannelEditWindow::get_chan_num(Channel *channel, int &chan, int &stream)
362 const char *cp = channel->title;
363 int chn = 0, str = 0;
364 while( isdigit(*cp) ) chn = 10*chn + (*cp++ -'0');
365 if( chn != 0 && *cp != 0 ) {
367 while( isdigit(*cp) ) str = 10*str + (*cp++ -'0');
370 chan = chn; stream = str;
373 void ChannelEditWindow::sort()
378 for(int i = 0; i < thread->new_channels->size() - 1; i++) {
379 Channel *channel1 = thread->new_channels->get(i);
380 Channel *channel2 = thread->new_channels->get(i + 1);
381 int ch1, st1; get_chan_num(channel1, ch1, st1);
382 int ch2, st2; get_chan_num(channel2, ch2, st2);
383 if( (ch1 > 0 && ch2 > 0) ?
384 (ch1 > ch2 || (ch1 == ch2 && (st1 > st2 || (st1 == st2 &&
385 strcasecmp(channel2->title, channel1->title) < 0)))) :
386 strcasecmp(channel2->title, channel1->title) < 0) {
387 thread->new_channels->set(i, channel2);
388 thread->new_channels->set(i + 1, channel1);
397 void ChannelEditWindow::delete_channel(int number)
399 delete thread->new_channels->get(number);
400 channel_list.remove_number(number);
401 thread->new_channels->remove_number(number);
405 void ChannelEditWindow::delete_channel(Channel *channel)
408 for(i = 0; i < thread->new_channels->size(); i++)
410 if(thread->new_channels->get(i) == channel)
415 if(i < thread->new_channels->size()) delete_channel(i);
418 int ChannelEditWindow::move_channel_up()
420 if(list_box->get_selection_number(0, 0) > -1)
422 int number2 = list_box->get_selection_number(0, 0);
423 int number1 = number2 - 1;
425 BC_ListBoxItem *temp_text;
427 if(number1 < 0) number1 = thread->new_channels->size() - 1;
429 temp = thread->new_channels->get(number1);
430 thread->new_channels->set(number1, thread->new_channels->get(number2));
431 thread->new_channels->set(number2, temp);
433 temp_text = channel_list.values[number1];
434 channel_list.values[number1] = channel_list.values[number2];
435 channel_list.values[number2] = temp_text;
436 list_box->update(&channel_list, 0, 0, 1,
437 list_box->get_xposition(), list_box->get_yposition(),
443 int ChannelEditWindow::move_channel_down()
445 if(list_box->get_selection_number(0, 0) > -1)
447 int number2 = list_box->get_selection_number(0, 0);
448 int number1 = number2 + 1;
450 BC_ListBoxItem *temp_text;
452 if(number1 > thread->new_channels->size() - 1) number1 = 0;
454 temp = thread->new_channels->get(number1);
455 thread->new_channels->set(number1, thread->new_channels->get(number2));
456 thread->new_channels->set(number2, temp);
457 temp_text = channel_list.values[number1];
458 channel_list.values[number1] = channel_list.values[number2];
459 channel_list.values[number2] = temp_text;
460 list_box->update(&channel_list, 0, 0, 1,
461 list_box->get_xposition(), list_box->get_yposition(),
467 int ChannelEditWindow::change_channel_from_list(int channel_number)
469 if(channel_number > -1 && channel_number < thread->new_channels->size())
471 thread->current_channel = channel_number;
472 channel_picker->set_channel(thread->new_channels->get(channel_number));
477 ChannelEditSelect::ChannelEditSelect(ChannelEditWindow *window, int x, int y)
478 : BC_GenericButton(x, y, _("Select"))
480 this->window = window;
482 ChannelEditSelect::~ChannelEditSelect()
485 int ChannelEditSelect::handle_event()
487 window->change_channel_from_list(
488 window->list_box->get_selection_number(0, 0));
492 ChannelEditAdd::ChannelEditAdd(ChannelEditWindow *window, int x, int y)
493 : BC_GenericButton(x, y, _("Add..."))
495 this->window = window;
497 ChannelEditAdd::~ChannelEditAdd()
500 int ChannelEditAdd::handle_event()
502 window->add_channel();
506 ChannelEditList::ChannelEditList(ChannelEditWindow *window, int x, int y)
508 xS(185), window->get_h() - BC_OKButton::calculate_h() - y - yS(10),
509 LISTBOX_TEXT, &(window->channel_list))
511 this->window = window;
513 ChannelEditList::~ChannelEditList()
516 int ChannelEditList::handle_event()
518 window->edit_channel();
522 ChannelEditMoveUp::ChannelEditMoveUp(ChannelEditWindow *window, int x, int y)
523 : BC_GenericButton(x, y, _("Move up"))
525 this->window = window;
527 ChannelEditMoveUp::~ChannelEditMoveUp()
530 int ChannelEditMoveUp::handle_event()
532 lock_window("ChannelEditMoveUp::handle_event");
533 window->move_channel_up();
538 ChannelEditMoveDown::ChannelEditMoveDown(ChannelEditWindow *window, int x, int y)
539 : BC_GenericButton(x, y, _("Move down"))
541 this->window = window;
543 ChannelEditMoveDown::~ChannelEditMoveDown()
546 int ChannelEditMoveDown::handle_event()
548 lock_window("ChannelEditMoveDown::handle_event");
549 window->move_channel_down();
554 ChannelEditSort::ChannelEditSort(ChannelEditWindow *window, int x, int y)
555 : BC_GenericButton(x, y, _("Sort"))
557 this->window = window;
559 int ChannelEditSort::handle_event()
561 lock_window("ChannelEditSort::handle_event");
567 ChannelEditScan::ChannelEditScan(ChannelEditWindow *window, int x, int y)
568 : BC_GenericButton(x, y, _("Scan"))
570 this->window = window;
572 int ChannelEditScan::handle_event()
574 window->scan_confirm();
578 ChannelEditDel::ChannelEditDel(ChannelEditWindow *window, int x, int y)
579 : BC_GenericButton(x, y, _("Delete"))
581 this->window = window;
583 ChannelEditDel::~ChannelEditDel()
586 int ChannelEditDel::handle_event()
588 if(window->list_box->get_selection_number(0, 0) > -1)
589 window->delete_channel(window->list_box->get_selection_number(0, 0));
593 ChannelEdit::ChannelEdit(ChannelEditWindow *window, int x, int y)
594 : BC_GenericButton(x, y, _("Edit..."))
596 this->window = window;
598 ChannelEdit::~ChannelEdit()
601 int ChannelEdit::handle_event()
603 window->edit_channel();
607 ChannelEditPicture::ChannelEditPicture(ChannelEditWindow *window, int x, int y)
608 : BC_GenericButton(x, y, _("Picture..."))
610 this->window = window;
612 ChannelEditPicture::~ChannelEditPicture()
615 int ChannelEditPicture::handle_event()
617 window->edit_picture();
622 // ========================= confirm overwrite by channel scanning
624 ConfirmScan::ConfirmScan(ChannelEditWindow *gui, int x, int y)
625 : BC_Window(_(PROGRAM_NAME ": Scan confirm"),
626 x, y, xS(350), BC_OKButton::calculate_h() + yS(130),
630 // *** CONTEXT_HELP ***
631 context_help_set_keyword("Initial Setup for DVB Capture");
634 void ConfirmScan::create_objects()
636 int xs5 = xS(5), xs10 = xS(10);
638 lock_window("ConfirmScan::create_objects");
639 int x = xs10, y = ys10;
642 add_subwindow(title = new BC_Title(x, y, _("Set parameters for channel scanning.")));
643 y += title->get_h() + ys10;
646 add_subwindow(title = new BC_Title(x, y, _("Frequency table:")));
648 y += BC_PopupMenu::calculate_h();
649 add_subwindow(title = new BC_Title(x, y, _("Norm:")));
650 x2 = MAX(x2, title->get_w());
651 y += BC_PopupMenu::calculate_h();
652 add_subwindow(title = new BC_Title(x, y, _("Input:")));
653 x2 = MAX(x2, title->get_w());
654 y += BC_PopupMenu::calculate_h();
659 ChannelEditEditFreqtable *table;
660 add_subwindow(table = new ChannelEditEditFreqtable(x, y, 0, gui->thread));
662 y += table->get_h() + ys10;
664 ChannelEditEditNorm *norm;
665 add_subwindow(norm = new ChannelEditEditNorm(x, y, 0, gui->thread));
667 y += norm->get_h() + ys10;
669 ChannelEditEditInput *input;
670 add_subwindow(input = new ChannelEditEditInput(x, y, 0, gui->thread));
674 add_subwindow(new BC_OKButton(this));
675 add_subwindow(new BC_CancelButton(this));
680 ConfirmScanThread::ConfirmScanThread(ChannelEditWindow *gui)
686 void ConfirmScanThread::handle_done_event(int result)
688 gui->channel_picker->save_scan_defaults(&gui->thread->scan_params);
691 gui->lock_window("ConfirmScanThread::handle_done_event");
693 gui->unlock_window();
697 ConfirmScanThread::~ConfirmScanThread()
702 BC_Window* ConfirmScanThread::new_gui()
704 int x = gui->get_abs_cursor_x(1);
705 int y = gui->get_abs_cursor_y(1);
706 ConfirmScan *result = new ConfirmScan(gui, x, y);
707 result->create_objects();
716 ScanThread::ScanThread(ChannelEditThread *edit)
724 ScanThread::~ScanThread()
729 void ScanThread::stop()
731 // Cancel previous job
735 progress->stop_progress();
736 delete progress; progress = 0;
740 void ScanThread::start()
745 progress = new BC_ProgressBox(
746 edit->channel_picker->parent_window->get_abs_cursor_x(1),
747 edit->channel_picker->parent_window->get_abs_cursor_y(1),
749 chanlists[edit->scan_params.freqtable].count);
755 void ScanThread::run()
757 for(int i = 0; i < chanlists[edit->scan_params.freqtable].count &&
758 !interrupt && !progress->is_cancelled(); i++) {
759 edit->scan_params.entry = i;
760 char string[BCTEXTLEN];
761 sprintf(edit->scan_params.title, "%s",
762 chanlists[edit->scan_params.freqtable].list[i].name);
763 sprintf(string, _("Scanning %s"), edit->scan_params.title);
764 progress->update_title(string, 1);
765 progress->update(i, 1);
766 edit->channel_picker->set_channel(&edit->scan_params);
767 sleep(1); // has_signal should do whatever it takes
768 if( interrupt ) break;
769 int got_signal = edit->channel_picker->has_signal();
770 if( interrupt ) break;
771 if(!got_signal) continue;
772 if(edit->channel_picker->get_channel_usage()->has_subchan) {
773 ArrayList<Channel*> channels;
774 edit->channel_picker->create_channeldb(&channels);
775 if( channels.total ) {
776 edit->window->lock_window("ScanThread::run");
777 for( int i=0; i<channels.total; ++i ) {
778 Channel *new_channel = channels.values[i];
779 new_channel->copy_usage(&edit->scan_params);
780 edit->new_channels->append(new_channel);
782 edit->window->update_list();
783 edit->window->unlock_window();
787 Channel *new_channel = new Channel;
788 new_channel->copy_usage(&edit->scan_params);
789 new_channel->copy_settings(&edit->scan_params);
790 edit->window->lock_window("ScanThread::run");
791 edit->new_channels->append(new_channel);
792 edit->window->update_list();
793 edit->window->unlock_window();
795 edit->window->set_done(interrupt || progress->is_cancelled() ? 1 : 0);
804 // ================================= Edit a single channel
808 ChannelEditEditThread::ChannelEditEditThread(ChannelEditWindow *window,
809 ChannelPicker *channel_picker)
812 this->window = window;
813 this->channel_picker = channel_picker;
817 completion = new Condition(1, "ChannelEditEditThread::completion");
820 ChannelEditEditThread::~ChannelEditEditThread()
826 void ChannelEditEditThread::close_threads()
830 edit_window->set_done(1);
831 completion->lock("ChannelEditEditThread::close_threads");
832 completion->unlock();
836 int ChannelEditEditThread::edit_channel(Channel *channel, int editing)
840 edit_window->lock_window("ChannelEditEditThread::edit_channel");
841 edit_window->raise_window(1);
842 edit_window->unlock_window();
847 // Copy the channel to edit into a temporary
848 completion->lock("ChannelEditEditThread::edit_channel");
849 this->editing = editing;
850 this->output_channel = channel;
851 new_channel.copy_settings(output_channel);
852 new_channel.copy_usage(output_channel);
854 if(editing && new_channel.title[0])
864 void ChannelEditEditThread::set_device()
866 channel_picker->set_channel(&new_channel);
869 void ChannelEditEditThread::change_source(const char *source_name)
871 for(int i = 0; i < chanlists[new_channel.freqtable].count; i++)
873 if(!strcasecmp(chanlists[new_channel.freqtable].list[i].name, source_name))
875 new_channel.entry = i;
876 i = chanlists[new_channel.freqtable].count;
882 strcpy(new_channel.title, source_name);
883 if(edit_window->title_text)
885 edit_window->title_text->update(source_name);
890 void ChannelEditEditThread::source_up()
893 if(new_channel.entry > chanlists[new_channel.freqtable].count - 1) new_channel.entry = 0;
894 source_text->update(chanlists[new_channel.freqtable].list[new_channel.entry].name);
898 void ChannelEditEditThread::source_down()
901 if(new_channel.entry < 0) new_channel.entry = chanlists[new_channel.freqtable].count - 1;
902 source_text->update(chanlists[new_channel.freqtable].list[new_channel.entry].name);
906 void ChannelEditEditThread::set_input(int value)
908 new_channel.input = value;
912 void ChannelEditEditThread::set_norm(int value)
914 new_channel.norm = value;
918 void ChannelEditEditThread::set_freqtable(int value)
920 new_channel.freqtable = value;
921 if(new_channel.entry > chanlists[new_channel.freqtable].count - 1) new_channel.entry = 0;
922 source_text->update(chanlists[new_channel.freqtable].list[new_channel.entry].name);
926 void ChannelEditEditThread::run()
928 ChannelEditEditWindow edit_window(this, window, channel_picker);
929 edit_window.create_objects(&new_channel);
930 this->edit_window = &edit_window;
931 int result = edit_window.run_window();
932 this->edit_window = 0;
934 // Done editing channel. Keep channel.
937 output_channel->copy_settings(&new_channel);
938 window->lock_window();
939 window->update_list(output_channel);
940 window->unlock_window();
947 window->lock_window();
948 window->delete_channel(output_channel);
949 window->unlock_window();
953 completion->unlock();
957 ChannelEditEditWindow::ChannelEditEditWindow(ChannelEditEditThread *thread,
958 ChannelEditWindow *window,
959 ChannelPicker *channel_picker)
960 : BC_Window(_(PROGRAM_NAME ": Edit Channel"),
961 channel_picker->parent_window->get_abs_cursor_x(1),
962 channel_picker->parent_window->get_abs_cursor_y(1),
963 xS(390), yS(300), xS(390), yS(300), 0, 0, 1)
965 this->channel_picker = channel_picker;
966 this->window = window;
967 this->thread = thread;
968 // *** CONTEXT_HELP ***
969 context_help_set_keyword("Initial Setup for DVB Capture");
971 ChannelEditEditWindow::~ChannelEditEditWindow()
975 void ChannelEditEditWindow::create_objects(Channel *channel)
977 int xs10 = xS(10), xs130 = xS(130);
978 int ys10 = yS(10), ys20 = yS(20), ys30 = yS(30);
979 lock_window("ChannelEditEditWindow::create_objects");
980 this->new_channel = channel;
981 Channel *channel_usage = channel_picker->get_channel_usage();
984 int x = xs10, y = ys10;
985 // if(!channel_usage ||
986 // (!channel_usage->use_frequency &&
987 // !channel_usage->use_fine &&
988 // !channel_usage->use_norm &&
989 // !channel_usage->use_input))
991 // add_subwindow(new BC_Title(x, y, MSG_NO_INP_SELECTION));
996 add_subwindow(new BC_Title(x, y, _("Title:")));
997 add_subwindow(title_text = new ChannelEditEditTitle(x, y + ys20, thread));
1001 if(channel_usage && channel_usage->use_frequency)
1003 add_subwindow(new BC_Title(x, y, _("Channel:")));
1005 add_subwindow(thread->source_text = new ChannelEditEditSource(x, y, thread));
1006 add_subwindow(new ChannelEditEditSourceTumbler(x + xS(160), y, thread));
1009 add_subwindow(new BC_Title(x, y, _("Frequency table:")));
1010 ChannelEditEditFreqtable *table;
1011 add_subwindow(table = new ChannelEditEditFreqtable(x + xs130,
1012 y, thread, window->thread));
1017 if(channel_usage && channel_usage->use_fine)
1019 add_subwindow(new BC_Title(x, y, _("Fine:")));
1020 add_subwindow(new ChannelEditEditFine(x + xs130, y, thread));
1024 if(channel_usage && channel_usage->use_norm)
1026 add_subwindow(new BC_Title(x, y, _("Norm:")));
1027 ChannelEditEditNorm *norm;
1028 add_subwindow(norm = new ChannelEditEditNorm(x + xs130,
1029 y, thread, window->thread));
1034 if( (channel_usage && channel_usage->use_input) ||
1037 add_subwindow(new BC_Title(x, y, _("Input:")));
1038 ChannelEditEditInput *input;
1039 add_subwindow(input = new ChannelEditEditInput(x + xs130,
1040 y, thread, window->thread));
1045 add_subwindow(new BC_OKButton(this));
1047 add_subwindow(new BC_CancelButton(this));
1052 ChannelEditEditTitle::ChannelEditEditTitle(int x,
1054 ChannelEditEditThread *thread)
1055 : BC_TextBox(x, y, xS(150), 1, thread->new_channel.title)
1057 this->thread = thread;
1059 ChannelEditEditTitle::~ChannelEditEditTitle()
1062 int ChannelEditEditTitle::handle_event()
1064 if(strlen(get_text()) < 1024)
1066 strcpy(thread->new_channel.title, get_text());
1068 thread->user_title = get_text()[0] ? 1 : 0;
1073 ChannelEditEditSource::ChannelEditEditSource(int x, int y, ChannelEditEditThread *thread)
1074 : BC_TextBox(x, y, xS(150), 1, chanlists[thread->new_channel.freqtable].list[thread->new_channel.entry].name)
1076 this->thread = thread;
1079 ChannelEditEditSource::~ChannelEditEditSource()
1082 int ChannelEditEditSource::handle_event()
1084 thread->change_source(get_text());
1089 ChannelEditEditSourceTumbler::ChannelEditEditSourceTumbler(int x, int y, ChannelEditEditThread *thread)
1092 this->thread = thread;
1094 ChannelEditEditSourceTumbler::~ChannelEditEditSourceTumbler()
1097 int ChannelEditEditSourceTumbler::handle_up_event()
1099 thread->source_up();
1102 int ChannelEditEditSourceTumbler::handle_down_event()
1104 thread->source_down();
1108 ChannelEditEditInput::ChannelEditEditInput(int x,
1110 ChannelEditEditThread *thread,
1111 ChannelEditThread *edit)
1112 : BC_PopupMenu(x, y, xS(150),
1113 edit->value_to_input(thread ? thread->new_channel.input : edit->scan_params.input))
1115 this->thread = thread;
1118 ChannelEditEditInput::~ChannelEditEditInput()
1121 void ChannelEditEditInput::add_items()
1123 ArrayList<Channel*> *inputs;
1124 inputs = edit->channel_picker->get_video_inputs();
1128 for(int i = 0; i < inputs->total; i++)
1130 add_item(new ChannelEditEditInputItem(thread,
1132 inputs->values[i]->device_name,
1137 int ChannelEditEditInput::handle_event()
1142 ChannelEditEditInputItem::ChannelEditEditInputItem(ChannelEditEditThread *thread,
1143 ChannelEditThread *edit,
1148 this->thread = thread;
1150 this->value = value;
1152 ChannelEditEditInputItem::~ChannelEditEditInputItem()
1155 int ChannelEditEditInputItem::handle_event()
1157 get_popup_menu()->set_text(get_text());
1158 if(thread && !thread->user_title)
1160 strcpy(thread->new_channel.title, get_text());
1161 if(thread->edit_window->title_text)
1163 thread->edit_window->title_text->update(get_text());
1167 thread->set_input(value);
1169 edit->scan_params.input = value;
1173 ChannelEditEditNorm::ChannelEditEditNorm(int x,
1175 ChannelEditEditThread *thread,
1176 ChannelEditThread *edit)
1177 : BC_PopupMenu(x, y, xS(100),
1178 edit->value_to_norm(thread ? thread->new_channel.norm : edit->scan_params.norm))
1180 this->thread = thread;
1183 ChannelEditEditNorm::~ChannelEditEditNorm()
1186 void ChannelEditEditNorm::add_items()
1188 add_item(new ChannelEditEditNormItem(thread,
1190 edit->value_to_norm(NTSC), NTSC));
1191 add_item(new ChannelEditEditNormItem(thread,
1193 edit->value_to_norm(PAL), PAL));
1194 add_item(new ChannelEditEditNormItem(thread,
1196 edit->value_to_norm(SECAM), SECAM));
1200 ChannelEditEditNormItem::ChannelEditEditNormItem(ChannelEditEditThread *thread,
1201 ChannelEditThread *edit,
1206 this->value = value;
1208 this->thread = thread;
1210 ChannelEditEditNormItem::~ChannelEditEditNormItem()
1213 int ChannelEditEditNormItem::handle_event()
1215 get_popup_menu()->set_text(get_text());
1217 thread->set_norm(value);
1219 edit->scan_params.norm = value;
1224 ChannelEditEditFreqtable::ChannelEditEditFreqtable(int x,
1226 ChannelEditEditThread *thread,
1227 ChannelEditThread *edit)
1228 : BC_PopupMenu(x, y, xS(150),
1229 edit->value_to_freqtable(thread ? thread->new_channel.freqtable : edit->scan_params.freqtable))
1231 this->thread = thread;
1234 ChannelEditEditFreqtable::~ChannelEditEditFreqtable()
1237 void ChannelEditEditFreqtable::add_items()
1239 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_DVB), NTSC_DVB));
1240 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(CATV_DVB), CATV_DVB));
1241 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_BCAST), NTSC_BCAST));
1242 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_CABLE), NTSC_CABLE));
1243 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_HRC), NTSC_HRC));
1244 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_BCAST_JP), NTSC_BCAST_JP));
1245 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_CABLE_JP), NTSC_CABLE_JP));
1246 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_AUSTRALIA), PAL_AUSTRALIA));
1247 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_EUROPE), PAL_EUROPE));
1248 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_E_EUROPE), PAL_E_EUROPE));
1249 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_ITALY), PAL_ITALY));
1250 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_IRELAND), PAL_IRELAND));
1251 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_NEWZEALAND), PAL_NEWZEALAND));
1254 ChannelEditEditFreqItem::ChannelEditEditFreqItem(ChannelEditEditThread *thread,
1255 ChannelEditThread *edit,
1256 char *text, int value)
1259 this->value = value;
1261 this->thread = thread;
1263 ChannelEditEditFreqItem::~ChannelEditEditFreqItem()
1266 int ChannelEditEditFreqItem::handle_event()
1268 get_popup_menu()->set_text(get_text());
1270 thread->set_freqtable(value);
1272 edit->scan_params.freqtable = value;
1278 ChannelEditEditFine::ChannelEditEditFine(int x,
1280 ChannelEditEditThread *thread)
1281 : BC_ISlider(x, y, 0, xS(240), xS(240), -100, 100,
1282 thread->new_channel.fine_tune)
1284 this->thread = thread;
1286 ChannelEditEditFine::~ChannelEditEditFine()
1289 int ChannelEditEditFine::handle_event()
1293 int ChannelEditEditFine::button_release_event()
1295 if(BC_Slider::button_release_event())
1297 thread->new_channel.fine_tune = get_value();
1298 thread->set_device();
1305 // ========================== picture quality
1307 ChannelEditPictureThread::ChannelEditPictureThread(
1308 ChannelPicker *channel_picker)
1311 this->channel_picker = channel_picker;
1313 ChannelEditPictureThread::~ChannelEditPictureThread()
1317 void ChannelEditPictureThread::handle_done_event(int result)
1319 if(channel_picker->get_picture_usage())
1320 channel_picker->get_picture_usage()->save_defaults();
1323 BC_Window* ChannelEditPictureThread::new_gui()
1325 ChannelEditPictureWindow *edit_window = new ChannelEditPictureWindow(this,
1327 edit_window->create_objects();
1331 void ChannelEditPictureThread::edit_picture()
1337 ChannelEditPictureWindow::ChannelEditPictureWindow(ChannelEditPictureThread *thread,
1338 ChannelPicker *channel_picker)
1339 : BC_Window(_(PROGRAM_NAME ": Picture"),
1340 channel_picker->mwindow->session->picture_x,
1341 channel_picker->mwindow->session->picture_y,
1342 calculate_w(channel_picker), calculate_h(channel_picker),
1343 calculate_w(channel_picker), calculate_h(channel_picker))
1345 this->thread = thread;
1346 this->channel_picker = channel_picker;
1347 // *** CONTEXT_HELP ***
1348 context_help_set_keyword("Initial Setup for DVB Capture");
1350 ChannelEditPictureWindow::~ChannelEditPictureWindow()
1354 int ChannelEditPictureWindow::calculate_h(ChannelPicker *channel_picker)
1356 PictureConfig *picture_usage = channel_picker->get_picture_usage();
1357 int pad = BC_Pot::calculate_h();
1358 int text_h = channel_picker->parent_window->get_text_height(MEDIUMFONT);
1359 int result = yS(20+5) + text_h + BC_OKButton::calculate_h();
1361 // Only used for Video4Linux 1
1362 if( !picture_usage || (
1363 !picture_usage->use_brightness &&
1364 !picture_usage->use_contrast &&
1365 !picture_usage->use_color &&
1366 !picture_usage->use_hue &&
1367 !picture_usage->use_whiteness &&
1368 !channel_picker->get_controls() ) ) {
1369 result += BC_Title::calculate_h(channel_picker->parent_window,
1370 MSG_NO_PIC_CONTROLS);
1374 if(picture_usage->use_brightness)
1376 if(picture_usage->use_contrast)
1378 if(picture_usage->use_color)
1380 if(picture_usage->use_hue)
1382 if(picture_usage->use_whiteness)
1386 result += channel_picker->get_controls() * pad;
1390 int ChannelEditPictureWindow::calculate_w(ChannelPicker *channel_picker)
1392 PictureConfig *picture_usage = channel_picker->get_picture_usage();
1393 int widget_border = ((Theme*)channel_picker->get_theme())->widget_border;
1394 int pad = BC_Pot::calculate_w() + 4 * widget_border;
1397 // Only used for Video4Linux 1
1398 if(!picture_usage ||
1399 (!picture_usage->use_brightness &&
1400 !picture_usage->use_contrast &&
1401 !picture_usage->use_color &&
1402 !picture_usage->use_hue &&
1403 !picture_usage->use_whiteness &&
1404 !channel_picker->get_controls()))
1406 result = BC_Title::calculate_w(channel_picker->parent_window,
1407 MSG_NO_PIC_CONTROLS) + xS(20);
1410 // Only used for Video4Linux 1
1413 if(picture_usage->use_brightness)
1415 int new_w = BC_Title::calculate_w(channel_picker->parent_window, _("Brightness:")) + pad;
1416 result = MAX(result, new_w);
1418 if(picture_usage->use_contrast)
1420 int new_w = BC_Title::calculate_w(channel_picker->parent_window, _("Contrast:")) + pad;
1421 result = MAX(result, new_w);
1423 if(picture_usage->use_color)
1425 int new_w = BC_Title::calculate_w(channel_picker->parent_window, _("Color:")) + pad;
1426 result = MAX(result, new_w);
1428 if(picture_usage->use_hue)
1430 int new_w = BC_Title::calculate_w(channel_picker->parent_window, _("Hue:")) + pad;
1431 result = MAX(result, new_w);
1433 if(picture_usage->use_whiteness)
1435 int new_w = BC_Title::calculate_w(channel_picker->parent_window, _("Whiteness:")) + pad;
1436 result = MAX(result, new_w);
1440 for(int i = 0; i < channel_picker->get_controls(); i++)
1442 int new_w = BC_Title::calculate_w(channel_picker->parent_window,
1443 channel_picker->get_control(i)->name) +
1445 result = MAX(result, new_w);
1452 void ChannelEditPictureWindow::create_objects()
1454 int xs10 = xS(10), ys10 = yS(10);
1455 lock_window("ChannelEditPictureWindow::create_objects");
1456 int x = xs10, y = ys10;
1457 int widget_border = ((Theme*)channel_picker->get_theme())->widget_border;
1458 int x1 = get_w() - BC_Pot::calculate_w() * 2 - widget_border * 2;
1459 int x2 = get_w() - BC_Pot::calculate_w() - widget_border;
1460 int pad = BC_Pot::calculate_h();
1462 #define SWAP_X x1 ^= x2; x2 ^= x1; x1 ^= x2;
1464 PictureConfig *picture_usage = channel_picker->get_picture_usage();
1466 // Only used for Video4Linux 1
1467 if(!picture_usage ||
1468 (!picture_usage->use_brightness &&
1469 !picture_usage->use_contrast &&
1470 !picture_usage->use_color &&
1471 !picture_usage->use_hue &&
1472 !picture_usage->use_whiteness &&
1473 !channel_picker->get_controls()))
1475 add_subwindow(new BC_Title(x, y, MSG_NO_PIC_CONTROLS));
1479 // Only used for Video4Linux 1
1480 if(picture_usage && picture_usage->use_brightness)
1482 add_subwindow(new BC_Title(x, y + ys10, _("Brightness:")));
1483 add_subwindow(new ChannelEditBright(x1, y, channel_picker, channel_picker->get_brightness()));
1489 if(picture_usage && picture_usage->use_contrast)
1491 add_subwindow(new BC_Title(x, y + ys10, _("Contrast:")));
1492 add_subwindow(new ChannelEditContrast(x1, y, channel_picker, channel_picker->get_contrast()));
1497 if(picture_usage && picture_usage->use_color)
1499 add_subwindow(new BC_Title(x, y + ys10, _("Color:")));
1500 add_subwindow(new ChannelEditColor(x1, y, channel_picker, channel_picker->get_color()));
1505 if(picture_usage && picture_usage->use_hue)
1507 add_subwindow(new BC_Title(x, y + ys10, _("Hue:")));
1508 add_subwindow(new ChannelEditHue(x1, y, channel_picker, channel_picker->get_hue()));
1513 if(picture_usage && picture_usage->use_whiteness)
1515 add_subwindow(new BC_Title(x, y + ys10, _("Whiteness:")));
1516 add_subwindow(new ChannelEditWhiteness(x1, y, channel_picker, channel_picker->get_whiteness()));
1521 for(int i = 0; i < channel_picker->get_controls(); i++)
1524 add_subwindow(title = new BC_Title(x, y + ys10,
1525 _(channel_picker->get_control(i)->name)));
1528 if(x3 < title->get_x() + title->get_w() + widget_border)
1529 x3 = title->get_x() + title->get_w() + widget_border;
1531 add_subwindow(new ChannelEditCommon(x3,
1534 channel_picker->get_control(i)));
1541 add_subwindow(new BC_OKButton(this));
1546 int ChannelEditPictureWindow::translation_event()
1548 channel_picker->mwindow->session->picture_x = get_x();
1549 channel_picker->mwindow->session->picture_y = get_y();
1555 ChannelEditBright::ChannelEditBright(int x, int y, ChannelPicker *channel_picker, int value)
1556 : BC_IPot(x, y, value, -100, 100)
1558 this->channel_picker = channel_picker;
1560 ChannelEditBright::~ChannelEditBright() {}
1561 int ChannelEditBright::handle_event()
1565 int ChannelEditBright::button_release_event()
1567 if(BC_Pot::button_release_event())
1569 channel_picker->set_brightness(get_value());
1575 ChannelEditContrast::ChannelEditContrast(int x, int y, ChannelPicker *channel_picker, int value)
1576 : BC_IPot(x, y, value, -100, 100)
1578 this->channel_picker = channel_picker;
1580 ChannelEditContrast::~ChannelEditContrast() {}
1581 int ChannelEditContrast::handle_event()
1585 int ChannelEditContrast::button_release_event()
1587 if(BC_Pot::button_release_event())
1589 channel_picker->set_contrast(get_value());
1596 ChannelEditColor::ChannelEditColor(int x, int y, ChannelPicker *channel_picker, int value)
1597 : BC_IPot(x, y, value, -100, 100)
1599 this->channel_picker = channel_picker;
1601 ChannelEditColor::~ChannelEditColor() {}
1602 int ChannelEditColor::handle_event()
1606 int ChannelEditColor::button_release_event()
1608 if(BC_Pot::button_release_event())
1610 channel_picker->set_color(get_value());
1616 ChannelEditHue::ChannelEditHue(int x, int y, ChannelPicker *channel_picker, int value)
1617 : BC_IPot(x, y, value, -100, 100)
1619 this->channel_picker = channel_picker;
1621 ChannelEditHue::~ChannelEditHue() {}
1622 int ChannelEditHue::handle_event()
1626 int ChannelEditHue::button_release_event()
1628 if(BC_Pot::button_release_event())
1630 channel_picker->set_hue(get_value());
1636 ChannelEditWhiteness::ChannelEditWhiteness(int x, int y, ChannelPicker *channel_picker, int value)
1637 : BC_IPot(x, y, value, -100, 100)
1639 this->channel_picker = channel_picker;
1641 ChannelEditWhiteness::~ChannelEditWhiteness()
1644 int ChannelEditWhiteness::handle_event()
1648 int ChannelEditWhiteness::button_release_event()
1650 if(BC_Pot::button_release_event())
1652 channel_picker->set_whiteness(get_value());
1660 ChannelEditCommon::ChannelEditCommon(int x, int y,
1661 ChannelPicker *channel_picker, PictureItem *item)
1662 : BC_IPot(x, y, item->value, item->min, item->max)
1664 this->channel_picker = channel_picker;
1665 this->device_id = item->device_id;
1668 ChannelEditCommon::~ChannelEditCommon()
1672 int ChannelEditCommon::handle_event()
1677 int ChannelEditCommon::button_release_event()
1679 if(BC_Pot::button_release_event())
1681 channel_picker->set_picture(device_id, get_value());
1687 int ChannelEditCommon::keypress_event()
1689 if(BC_Pot::keypress_event())
1691 channel_picker->set_picture(device_id, get_value());
1694 return context_help_check_and_show();