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 375, 400, 375, 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;
177 ChannelEditWindow::~ChannelEditWindow()
179 if( thread->scan_thread )
180 thread->scan_thread->stop();
181 channel_list.remove_all_objects();
183 delete picture_thread;
184 delete scan_confirm_thread;
187 void ChannelEditWindow::create_objects()
189 lock_window("ChannelEditWindow::create_objects");
192 // Create channel list
193 for(int i = 0; i < thread->new_channels->size(); i++)
195 channel_list.append(new BC_ListBoxItem(thread->new_channels->get(i)->title));
198 add_subwindow(list_box = new ChannelEditList(this, x, y));
200 if(channel_picker->use_select())
202 add_subwindow(new ChannelEditSelect(this, x, y));
205 add_subwindow(new ChannelEditAdd(this, x, y));
207 add_subwindow(new ChannelEdit(this, x, y));
209 add_subwindow(new ChannelEditMoveUp(this, x, y));
211 add_subwindow(new ChannelEditMoveDown(this, x, y));
213 add_subwindow(new ChannelEditSort(this, x, y));
216 Channel *channel_usage = channel_picker->get_channel_usage();
217 if(channel_usage && channel_usage->has_scanning)
219 add_subwindow(new ChannelEditScan(this, x, y));
222 add_subwindow(new ChannelEditDel(this, x, y));
224 add_subwindow(new ChannelEditPicture(this, x, y));
227 add_subwindow(new BC_OKButton(this));
229 add_subwindow(new BC_CancelButton(this));
232 edit_thread = new ChannelEditEditThread(this, channel_picker);
233 picture_thread = new ChannelEditPictureThread(channel_picker);
238 int ChannelEditWindow::close_event()
240 if( thread->scan_thread )
241 thread->scan_thread->stop();
242 return BC_WindowBase::close_event();
245 int ChannelEditWindow::translation_event()
247 channel_picker->mwindow->session->channels_x = get_x();
248 channel_picker->mwindow->session->channels_y = get_y();
253 int ChannelEditWindow::add_channel()
255 Channel *new_channel;
256 Channel *prev_channel = 0;
258 // Create new channel
259 new_channel = new Channel;
261 // Reuse parameters from previous channel
262 if(thread->new_channels->size())
264 prev_channel = thread->new_channels->get(
265 thread->new_channels->size() - 1);
266 new_channel->copy_settings(prev_channel);
269 // Use default channel parameters
270 if(channel_picker->get_master_channel())
272 new_channel->copy_settings(channel_picker->get_master_channel());
275 // Copy device usage. Need the same thing for playback.
276 if(channel_picker->get_master_channel())
278 new_channel->copy_usage(channel_picker->get_master_channel());
281 // Add to channel table
282 channel_list.append(new BC_ListBoxItem(new_channel->title));
283 thread->new_channels->append(new_channel);
286 // Start common routing
287 edit_thread->edit_channel(new_channel, 0);
291 void ChannelEditWindow::update_list()
293 // Create channel list
294 channel_list.remove_all_objects();
295 for(int i = 0; i < thread->new_channels->size(); i++)
299 thread->new_channels->get(i)->title));
302 list_box->update(&channel_list, 0, 0, 1, list_box->get_yposition());
305 void ChannelEditWindow::update_list(Channel *channel)
308 for(i = 0; i < thread->new_channels->size(); i++)
309 if(thread->new_channels->get(i) == channel) break;
311 if(i < thread->new_channels->size())
313 channel_list.values[i]->set_text(channel->title);
320 void ChannelEditWindow::edit_channel()
322 if(list_box->get_selection_number(0, 0) > -1)
324 thread->current_channel = list_box->get_selection_number(0, 0);
325 edit_thread->edit_channel(
326 thread->new_channels->get(
327 list_box->get_selection_number(0, 0)),
332 void ChannelEditWindow::edit_picture()
334 picture_thread->edit_picture();
337 void ChannelEditWindow::scan_confirm()
339 channel_picker->load_scan_defaults(&thread->scan_params);
340 if(!scan_confirm_thread) scan_confirm_thread = new ConfirmScanThread(this);
342 scan_confirm_thread->start();
343 lock_window("ChannelEditWindow::scan_confirm");
346 void ChannelEditWindow::scan()
348 thread->new_channels->clear();
351 if( !thread->scan_thread )
352 thread->scan_thread = new ScanThread(thread);
353 thread->scan_thread->start();
357 void ChannelEditWindow::get_chan_num(Channel *channel, int &chan, int &stream)
359 const char *cp = channel->title;
360 int chn = 0, str = 0;
361 while( isdigit(*cp) ) chn = 10*chn + (*cp++ -'0');
362 if( chn != 0 && *cp != 0 ) {
364 while( isdigit(*cp) ) str = 10*str + (*cp++ -'0');
367 chan = chn; stream = str;
370 void ChannelEditWindow::sort()
375 for(int i = 0; i < thread->new_channels->size() - 1; i++) {
376 Channel *channel1 = thread->new_channels->get(i);
377 Channel *channel2 = thread->new_channels->get(i + 1);
378 int ch1, st1; get_chan_num(channel1, ch1, st1);
379 int ch2, st2; get_chan_num(channel2, ch2, st2);
380 if( (ch1 > 0 && ch2 > 0) ?
381 (ch1 > ch2 || (ch1 == ch2 && (st1 > st2 || (st1 == st2 &&
382 strcasecmp(channel2->title, channel1->title) < 0)))) :
383 strcasecmp(channel2->title, channel1->title) < 0) {
384 thread->new_channels->set(i, channel2);
385 thread->new_channels->set(i + 1, channel1);
394 void ChannelEditWindow::delete_channel(int number)
396 delete thread->new_channels->get(number);
397 channel_list.remove_number(number);
398 thread->new_channels->remove_number(number);
402 void ChannelEditWindow::delete_channel(Channel *channel)
405 for(i = 0; i < thread->new_channels->size(); i++)
407 if(thread->new_channels->get(i) == channel)
412 if(i < thread->new_channels->size()) delete_channel(i);
415 int ChannelEditWindow::move_channel_up()
417 if(list_box->get_selection_number(0, 0) > -1)
419 int number2 = list_box->get_selection_number(0, 0);
420 int number1 = number2 - 1;
422 BC_ListBoxItem *temp_text;
424 if(number1 < 0) number1 = thread->new_channels->size() - 1;
426 temp = thread->new_channels->get(number1);
427 thread->new_channels->set(number1, thread->new_channels->get(number2));
428 thread->new_channels->set(number2, temp);
430 temp_text = channel_list.values[number1];
431 channel_list.values[number1] = channel_list.values[number2];
432 channel_list.values[number2] = temp_text;
433 list_box->update(&channel_list,
437 list_box->get_xposition(),
438 list_box->get_yposition(),
445 int ChannelEditWindow::move_channel_down()
447 if(list_box->get_selection_number(0, 0) > -1)
449 int number2 = list_box->get_selection_number(0, 0);
450 int number1 = number2 + 1;
452 BC_ListBoxItem *temp_text;
454 if(number1 > thread->new_channels->size() - 1) number1 = 0;
456 temp = thread->new_channels->get(number1);
457 thread->new_channels->set(number1, thread->new_channels->get(number2));
458 thread->new_channels->set(number2, temp);
459 temp_text = channel_list.values[number1];
460 channel_list.values[number1] = channel_list.values[number2];
461 channel_list.values[number2] = temp_text;
462 list_box->update(&channel_list,
466 list_box->get_xposition(),
467 list_box->get_yposition(),
474 int ChannelEditWindow::change_channel_from_list(int channel_number)
476 if(channel_number > -1 && channel_number < thread->new_channels->size())
478 thread->current_channel = channel_number;
479 channel_picker->set_channel(thread->new_channels->get(channel_number));
484 ChannelEditSelect::ChannelEditSelect(ChannelEditWindow *window, int x, int y)
485 : BC_GenericButton(x, y, _("Select"))
487 this->window = window;
489 ChannelEditSelect::~ChannelEditSelect()
492 int ChannelEditSelect::handle_event()
494 window->change_channel_from_list(
495 window->list_box->get_selection_number(0, 0));
499 ChannelEditAdd::ChannelEditAdd(ChannelEditWindow *window, int x, int y)
500 : BC_GenericButton(x, y, _("Add..."))
502 this->window = window;
504 ChannelEditAdd::~ChannelEditAdd()
507 int ChannelEditAdd::handle_event()
509 window->add_channel();
513 ChannelEditList::ChannelEditList(ChannelEditWindow *window, int x, int y)
517 window->get_h() - BC_OKButton::calculate_h() - y - 10,
519 &(window->channel_list))
521 this->window = window;
523 ChannelEditList::~ChannelEditList()
526 int ChannelEditList::handle_event()
528 window->edit_channel();
532 ChannelEditMoveUp::ChannelEditMoveUp(ChannelEditWindow *window, int x, int y)
533 : BC_GenericButton(x, y, _("Move up"))
535 this->window = window;
537 ChannelEditMoveUp::~ChannelEditMoveUp()
540 int ChannelEditMoveUp::handle_event()
542 lock_window("ChannelEditMoveUp::handle_event");
543 window->move_channel_up();
548 ChannelEditMoveDown::ChannelEditMoveDown(ChannelEditWindow *window, int x, int y)
549 : BC_GenericButton(x, y, _("Move down"))
551 this->window = window;
553 ChannelEditMoveDown::~ChannelEditMoveDown()
556 int ChannelEditMoveDown::handle_event()
558 lock_window("ChannelEditMoveDown::handle_event");
559 window->move_channel_down();
564 ChannelEditSort::ChannelEditSort(ChannelEditWindow *window, int x, int y)
565 : BC_GenericButton(x, y, _("Sort"))
567 this->window = window;
569 int ChannelEditSort::handle_event()
571 lock_window("ChannelEditSort::handle_event");
577 ChannelEditScan::ChannelEditScan(ChannelEditWindow *window, int x, int y)
578 : BC_GenericButton(x, y, _("Scan"))
580 this->window = window;
582 int ChannelEditScan::handle_event()
584 window->scan_confirm();
588 ChannelEditDel::ChannelEditDel(ChannelEditWindow *window, int x, int y)
589 : BC_GenericButton(x, y, _("Delete"))
591 this->window = window;
593 ChannelEditDel::~ChannelEditDel()
596 int ChannelEditDel::handle_event()
598 if(window->list_box->get_selection_number(0, 0) > -1)
599 window->delete_channel(window->list_box->get_selection_number(0, 0));
603 ChannelEdit::ChannelEdit(ChannelEditWindow *window, int x, int y)
604 : BC_GenericButton(x, y, _("Edit..."))
606 this->window = window;
608 ChannelEdit::~ChannelEdit()
611 int ChannelEdit::handle_event()
613 window->edit_channel();
617 ChannelEditPicture::ChannelEditPicture(ChannelEditWindow *window, int x, int y)
618 : BC_GenericButton(x, y, _("Picture..."))
620 this->window = window;
622 ChannelEditPicture::~ChannelEditPicture()
625 int ChannelEditPicture::handle_event()
627 window->edit_picture();
632 // ========================= confirm overwrite by channel scanning
634 ConfirmScan::ConfirmScan(ChannelEditWindow *gui, int x, int y)
635 : BC_Window(_(PROGRAM_NAME ": Scan confirm"),
636 x, y, 350, BC_OKButton::calculate_h() + 130,
642 void ConfirmScan::create_objects()
644 lock_window("ConfirmScan::create_objects");
648 add_subwindow(title = new BC_Title(x, y, _("Set parameters for channel scanning.")));
649 y += title->get_h() + 10;
652 add_subwindow(title = new BC_Title(x, y, _("Frequency table:")));
654 y += BC_PopupMenu::calculate_h();
655 add_subwindow(title = new BC_Title(x, y, _("Norm:")));
656 x2 = MAX(x2, title->get_w());
657 y += BC_PopupMenu::calculate_h();
658 add_subwindow(title = new BC_Title(x, y, _("Input:")));
659 x2 = MAX(x2, title->get_w());
660 y += BC_PopupMenu::calculate_h();
665 ChannelEditEditFreqtable *table;
666 add_subwindow(table = new ChannelEditEditFreqtable(x,
671 y += table->get_h() + 10;
673 ChannelEditEditNorm *norm;
674 add_subwindow(norm = new ChannelEditEditNorm(x,
679 y += norm->get_h() + 10;
681 ChannelEditEditInput *input;
682 add_subwindow(input = new ChannelEditEditInput(x,
689 add_subwindow(new BC_OKButton(this));
690 add_subwindow(new BC_CancelButton(this));
695 ConfirmScanThread::ConfirmScanThread(ChannelEditWindow *gui)
701 void ConfirmScanThread::handle_done_event(int result)
703 gui->channel_picker->save_scan_defaults(&gui->thread->scan_params);
706 get_gui()->hide_window();
707 gui->lock_window("ConfirmScanThread::handle_done_event");
709 gui->unlock_window();
713 ConfirmScanThread::~ConfirmScanThread()
718 BC_Window* ConfirmScanThread::new_gui()
720 int x = gui->get_abs_cursor_x(1);
721 int y = gui->get_abs_cursor_y(1);
722 ConfirmScan *result = new ConfirmScan(gui, x, y);
723 result->create_objects();
732 ScanThread::ScanThread(ChannelEditThread *edit)
740 ScanThread::~ScanThread()
745 void ScanThread::stop()
747 // Cancel previous job
751 progress->stop_progress();
752 delete progress; progress = 0;
756 void ScanThread::start()
761 progress = new BC_ProgressBox(
762 edit->channel_picker->parent_window->get_abs_cursor_x(1),
763 edit->channel_picker->parent_window->get_abs_cursor_y(1),
765 chanlists[edit->scan_params.freqtable].count);
771 void ScanThread::run()
773 for(int i = 0; i < chanlists[edit->scan_params.freqtable].count &&
774 !interrupt && !progress->is_cancelled(); i++) {
775 edit->scan_params.entry = i;
776 char string[BCTEXTLEN];
777 sprintf(edit->scan_params.title, "%s",
778 chanlists[edit->scan_params.freqtable].list[i].name);
779 sprintf(string, _("Scanning %s"), edit->scan_params.title);
780 progress->update_title(string, 1);
781 progress->update(i, 1);
782 edit->channel_picker->set_channel(&edit->scan_params);
783 sleep(1); // has_signal should do whatever it takes
784 if( interrupt ) break;
785 int got_signal = edit->channel_picker->has_signal();
786 if( interrupt ) break;
787 if(!got_signal) continue;
788 if(edit->channel_picker->get_channel_usage()->has_subchan) {
789 ArrayList<Channel*> channels;
790 edit->channel_picker->create_channeldb(&channels);
791 if( channels.total ) {
792 edit->window->lock_window("ScanThread::run");
793 for( int i=0; i<channels.total; ++i ) {
794 Channel *new_channel = channels.values[i];
795 new_channel->copy_usage(&edit->scan_params);
796 edit->new_channels->append(new_channel);
798 edit->window->update_list();
799 edit->window->unlock_window();
803 Channel *new_channel = new Channel;
804 new_channel->copy_usage(&edit->scan_params);
805 new_channel->copy_settings(&edit->scan_params);
806 edit->window->lock_window("ScanThread::run");
807 edit->new_channels->append(new_channel);
808 edit->window->update_list();
809 edit->window->unlock_window();
811 edit->window->set_done(interrupt || progress->is_cancelled() ? 1 : 0);
820 // ================================= Edit a single channel
824 ChannelEditEditThread::ChannelEditEditThread(ChannelEditWindow *window,
825 ChannelPicker *channel_picker)
828 this->window = window;
829 this->channel_picker = channel_picker;
833 completion = new Condition(1, "ChannelEditEditThread::completion");
836 ChannelEditEditThread::~ChannelEditEditThread()
842 void ChannelEditEditThread::close_threads()
846 edit_window->set_done(1);
847 completion->lock("ChannelEditEditThread::close_threads");
848 completion->unlock();
852 int ChannelEditEditThread::edit_channel(Channel *channel, int editing)
856 edit_window->lock_window("ChannelEditEditThread::edit_channel");
857 edit_window->raise_window(1);
858 edit_window->unlock_window();
863 // Copy the channel to edit into a temporary
864 completion->lock("ChannelEditEditThread::edit_channel");
865 this->editing = editing;
866 this->output_channel = channel;
867 new_channel.copy_settings(output_channel);
868 new_channel.copy_usage(output_channel);
870 if(editing && new_channel.title[0])
880 void ChannelEditEditThread::set_device()
882 channel_picker->set_channel(&new_channel);
885 void ChannelEditEditThread::change_source(const char *source_name)
887 for(int i = 0; i < chanlists[new_channel.freqtable].count; i++)
889 if(!strcasecmp(chanlists[new_channel.freqtable].list[i].name, source_name))
891 new_channel.entry = i;
892 i = chanlists[new_channel.freqtable].count;
898 strcpy(new_channel.title, source_name);
899 if(edit_window->title_text)
901 edit_window->title_text->update(source_name);
906 void ChannelEditEditThread::source_up()
909 if(new_channel.entry > chanlists[new_channel.freqtable].count - 1) new_channel.entry = 0;
910 source_text->update(chanlists[new_channel.freqtable].list[new_channel.entry].name);
914 void ChannelEditEditThread::source_down()
917 if(new_channel.entry < 0) new_channel.entry = chanlists[new_channel.freqtable].count - 1;
918 source_text->update(chanlists[new_channel.freqtable].list[new_channel.entry].name);
922 void ChannelEditEditThread::set_input(int value)
924 new_channel.input = value;
928 void ChannelEditEditThread::set_norm(int value)
930 new_channel.norm = value;
934 void ChannelEditEditThread::set_freqtable(int value)
936 new_channel.freqtable = value;
937 if(new_channel.entry > chanlists[new_channel.freqtable].count - 1) new_channel.entry = 0;
938 source_text->update(chanlists[new_channel.freqtable].list[new_channel.entry].name);
942 void ChannelEditEditThread::run()
944 ChannelEditEditWindow edit_window(this, window, channel_picker);
945 edit_window.create_objects(&new_channel);
946 this->edit_window = &edit_window;
947 int result = edit_window.run_window();
948 this->edit_window = 0;
950 // Done editing channel. Keep channel.
953 output_channel->copy_settings(&new_channel);
954 window->lock_window();
955 window->update_list(output_channel);
956 window->unlock_window();
963 window->lock_window();
964 window->delete_channel(output_channel);
965 window->unlock_window();
969 completion->unlock();
973 ChannelEditEditWindow::ChannelEditEditWindow(ChannelEditEditThread *thread,
974 ChannelEditWindow *window,
975 ChannelPicker *channel_picker)
976 : BC_Window(_(PROGRAM_NAME ": Edit Channel"),
977 channel_picker->parent_window->get_abs_cursor_x(1),
978 channel_picker->parent_window->get_abs_cursor_y(1),
979 390, 300, 390, 300, 0, 0, 1)
981 this->channel_picker = channel_picker;
982 this->window = window;
983 this->thread = thread;
985 ChannelEditEditWindow::~ChannelEditEditWindow()
989 void ChannelEditEditWindow::create_objects(Channel *channel)
991 lock_window("ChannelEditEditWindow::create_objects");
992 this->new_channel = channel;
993 Channel *channel_usage = channel_picker->get_channel_usage();
997 // if(!channel_usage ||
998 // (!channel_usage->use_frequency &&
999 // !channel_usage->use_fine &&
1000 // !channel_usage->use_norm &&
1001 // !channel_usage->use_input))
1003 // add_subwindow(new BC_Title(x, y, MSG_NO_INP_SELECTION));
1008 add_subwindow(new BC_Title(x, y, _("Title:")));
1009 add_subwindow(title_text = new ChannelEditEditTitle(x, y + 20, thread));
1013 if(channel_usage && channel_usage->use_frequency)
1015 add_subwindow(new BC_Title(x, y, _("Channel:")));
1017 add_subwindow(thread->source_text = new ChannelEditEditSource(x, y, thread));
1018 add_subwindow(new ChannelEditEditSourceTumbler(x + 160, y, thread));
1021 add_subwindow(new BC_Title(x, y, _("Frequency table:")));
1022 ChannelEditEditFreqtable *table;
1023 add_subwindow(table = new ChannelEditEditFreqtable(x + 130,
1031 if(channel_usage && channel_usage->use_fine)
1033 add_subwindow(new BC_Title(x, y, _("Fine:")));
1034 add_subwindow(new ChannelEditEditFine(x + 130, y, thread));
1038 if(channel_usage && channel_usage->use_norm)
1040 add_subwindow(new BC_Title(x, y, _("Norm:")));
1041 ChannelEditEditNorm *norm;
1042 add_subwindow(norm = new ChannelEditEditNorm(x + 130,
1050 if( (channel_usage && channel_usage->use_input) ||
1053 add_subwindow(new BC_Title(x, y, _("Input:")));
1054 ChannelEditEditInput *input;
1055 add_subwindow(input = new ChannelEditEditInput(x + 130,
1063 add_subwindow(new BC_OKButton(this));
1065 add_subwindow(new BC_CancelButton(this));
1070 ChannelEditEditTitle::ChannelEditEditTitle(int x,
1072 ChannelEditEditThread *thread)
1073 : BC_TextBox(x, y, 150, 1, thread->new_channel.title)
1075 this->thread = thread;
1077 ChannelEditEditTitle::~ChannelEditEditTitle()
1080 int ChannelEditEditTitle::handle_event()
1082 if(strlen(get_text()) < 1024)
1084 strcpy(thread->new_channel.title, get_text());
1086 thread->user_title = get_text()[0] ? 1 : 0;
1091 ChannelEditEditSource::ChannelEditEditSource(int x, int y, ChannelEditEditThread *thread)
1092 : BC_TextBox(x, y, 150, 1, chanlists[thread->new_channel.freqtable].list[thread->new_channel.entry].name)
1094 this->thread = thread;
1097 ChannelEditEditSource::~ChannelEditEditSource()
1100 int ChannelEditEditSource::handle_event()
1102 thread->change_source(get_text());
1107 ChannelEditEditSourceTumbler::ChannelEditEditSourceTumbler(int x, int y, ChannelEditEditThread *thread)
1110 this->thread = thread;
1112 ChannelEditEditSourceTumbler::~ChannelEditEditSourceTumbler()
1115 int ChannelEditEditSourceTumbler::handle_up_event()
1117 thread->source_up();
1120 int ChannelEditEditSourceTumbler::handle_down_event()
1122 thread->source_down();
1126 ChannelEditEditInput::ChannelEditEditInput(int x,
1128 ChannelEditEditThread *thread,
1129 ChannelEditThread *edit)
1133 edit->value_to_input(thread ? thread->new_channel.input : edit->scan_params.input))
1135 this->thread = thread;
1138 ChannelEditEditInput::~ChannelEditEditInput()
1141 void ChannelEditEditInput::add_items()
1143 ArrayList<Channel*> *inputs;
1144 inputs = edit->channel_picker->get_video_inputs();
1148 for(int i = 0; i < inputs->total; i++)
1150 add_item(new ChannelEditEditInputItem(thread,
1152 inputs->values[i]->device_name,
1157 int ChannelEditEditInput::handle_event()
1162 ChannelEditEditInputItem::ChannelEditEditInputItem(ChannelEditEditThread *thread,
1163 ChannelEditThread *edit,
1168 this->thread = thread;
1170 this->value = value;
1172 ChannelEditEditInputItem::~ChannelEditEditInputItem()
1175 int ChannelEditEditInputItem::handle_event()
1177 get_popup_menu()->set_text(get_text());
1178 if(thread && !thread->user_title)
1180 strcpy(thread->new_channel.title, get_text());
1181 if(thread->edit_window->title_text)
1183 thread->edit_window->title_text->update(get_text());
1187 thread->set_input(value);
1189 edit->scan_params.input = value;
1193 ChannelEditEditNorm::ChannelEditEditNorm(int x,
1195 ChannelEditEditThread *thread,
1196 ChannelEditThread *edit)
1200 edit->value_to_norm(thread ? thread->new_channel.norm : edit->scan_params.norm))
1202 this->thread = thread;
1205 ChannelEditEditNorm::~ChannelEditEditNorm()
1208 void ChannelEditEditNorm::add_items()
1210 add_item(new ChannelEditEditNormItem(thread,
1212 edit->value_to_norm(NTSC), NTSC));
1213 add_item(new ChannelEditEditNormItem(thread,
1215 edit->value_to_norm(PAL), PAL));
1216 add_item(new ChannelEditEditNormItem(thread,
1218 edit->value_to_norm(SECAM), SECAM));
1222 ChannelEditEditNormItem::ChannelEditEditNormItem(ChannelEditEditThread *thread,
1223 ChannelEditThread *edit,
1228 this->value = value;
1230 this->thread = thread;
1232 ChannelEditEditNormItem::~ChannelEditEditNormItem()
1235 int ChannelEditEditNormItem::handle_event()
1237 get_popup_menu()->set_text(get_text());
1239 thread->set_norm(value);
1241 edit->scan_params.norm = value;
1246 ChannelEditEditFreqtable::ChannelEditEditFreqtable(int x,
1248 ChannelEditEditThread *thread,
1249 ChannelEditThread *edit)
1253 edit->value_to_freqtable(thread ? thread->new_channel.freqtable : edit->scan_params.freqtable))
1255 this->thread = thread;
1258 ChannelEditEditFreqtable::~ChannelEditEditFreqtable()
1261 void ChannelEditEditFreqtable::add_items()
1263 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_DVB), NTSC_DVB));
1264 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(CATV_DVB), CATV_DVB));
1265 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_BCAST), NTSC_BCAST));
1266 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_CABLE), NTSC_CABLE));
1267 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_HRC), NTSC_HRC));
1268 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_BCAST_JP), NTSC_BCAST_JP));
1269 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_CABLE_JP), NTSC_CABLE_JP));
1270 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_AUSTRALIA), PAL_AUSTRALIA));
1271 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_EUROPE), PAL_EUROPE));
1272 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_E_EUROPE), PAL_E_EUROPE));
1273 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_ITALY), PAL_ITALY));
1274 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_IRELAND), PAL_IRELAND));
1275 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_NEWZEALAND), PAL_NEWZEALAND));
1278 ChannelEditEditFreqItem::ChannelEditEditFreqItem(ChannelEditEditThread *thread,
1279 ChannelEditThread *edit,
1280 char *text, int value)
1283 this->value = value;
1285 this->thread = thread;
1287 ChannelEditEditFreqItem::~ChannelEditEditFreqItem()
1290 int ChannelEditEditFreqItem::handle_event()
1292 get_popup_menu()->set_text(get_text());
1294 thread->set_freqtable(value);
1296 edit->scan_params.freqtable = value;
1302 ChannelEditEditFine::ChannelEditEditFine(int x,
1304 ChannelEditEditThread *thread)
1312 thread->new_channel.fine_tune)
1314 this->thread = thread;
1316 ChannelEditEditFine::~ChannelEditEditFine()
1319 int ChannelEditEditFine::handle_event()
1323 int ChannelEditEditFine::button_release_event()
1325 if(BC_Slider::button_release_event())
1327 thread->new_channel.fine_tune = get_value();
1328 thread->set_device();
1335 // ========================== picture quality
1337 ChannelEditPictureThread::ChannelEditPictureThread(
1338 ChannelPicker *channel_picker)
1341 this->channel_picker = channel_picker;
1343 ChannelEditPictureThread::~ChannelEditPictureThread()
1347 void ChannelEditPictureThread::handle_done_event(int result)
1349 if(channel_picker->get_picture_usage())
1350 channel_picker->get_picture_usage()->save_defaults();
1353 BC_Window* ChannelEditPictureThread::new_gui()
1355 ChannelEditPictureWindow *edit_window = new ChannelEditPictureWindow(this,
1357 edit_window->create_objects();
1361 void ChannelEditPictureThread::edit_picture()
1367 ChannelEditPictureWindow::ChannelEditPictureWindow(ChannelEditPictureThread *thread,
1368 ChannelPicker *channel_picker)
1369 : BC_Window(_(PROGRAM_NAME ": Picture"),
1370 channel_picker->mwindow->session->picture_x,
1371 channel_picker->mwindow->session->picture_y,
1372 calculate_w(channel_picker), calculate_h(channel_picker),
1373 calculate_w(channel_picker), calculate_h(channel_picker))
1375 this->thread = thread;
1376 this->channel_picker = channel_picker;
1378 ChannelEditPictureWindow::~ChannelEditPictureWindow()
1382 int ChannelEditPictureWindow::calculate_h(ChannelPicker *channel_picker)
1384 PictureConfig *picture_usage = channel_picker->get_picture_usage();
1385 int pad = BC_Pot::calculate_h();
1386 int text_h = channel_picker->parent_window->get_text_height(MEDIUMFONT);
1387 int result = 20 + text_h + 5 + BC_OKButton::calculate_h();
1389 // Only used for Video4Linux 1
1390 if( !picture_usage || (
1391 !picture_usage->use_brightness &&
1392 !picture_usage->use_contrast &&
1393 !picture_usage->use_color &&
1394 !picture_usage->use_hue &&
1395 !picture_usage->use_whiteness &&
1396 !channel_picker->get_controls() ) ) {
1397 result += BC_Title::calculate_h(channel_picker->parent_window,
1398 MSG_NO_PIC_CONTROLS);
1402 if(picture_usage->use_brightness)
1404 if(picture_usage->use_contrast)
1406 if(picture_usage->use_color)
1408 if(picture_usage->use_hue)
1410 if(picture_usage->use_whiteness)
1414 result += channel_picker->get_controls() * pad;
1418 int ChannelEditPictureWindow::calculate_w(ChannelPicker *channel_picker)
1420 PictureConfig *picture_usage = channel_picker->get_picture_usage();
1421 int widget_border = ((Theme*)channel_picker->get_theme())->widget_border;
1422 int pad = BC_Pot::calculate_w() + 4 * widget_border;
1425 // Only used for Video4Linux 1
1426 if(!picture_usage ||
1427 (!picture_usage->use_brightness &&
1428 !picture_usage->use_contrast &&
1429 !picture_usage->use_color &&
1430 !picture_usage->use_hue &&
1431 !picture_usage->use_whiteness &&
1432 !channel_picker->get_controls()))
1434 result = BC_Title::calculate_w(channel_picker->parent_window,
1435 MSG_NO_PIC_CONTROLS) + 20;
1438 // Only used for Video4Linux 1
1441 if(picture_usage->use_brightness)
1443 int new_w = BC_Title::calculate_w(channel_picker->parent_window, _("Brightness:")) + pad;
1444 result = MAX(result, new_w);
1446 if(picture_usage->use_contrast)
1448 int new_w = BC_Title::calculate_w(channel_picker->parent_window, _("Contrast:")) + pad;
1449 result = MAX(result, new_w);
1451 if(picture_usage->use_color)
1453 int new_w = BC_Title::calculate_w(channel_picker->parent_window, _("Color:")) + pad;
1454 result = MAX(result, new_w);
1456 if(picture_usage->use_hue)
1458 int new_w = BC_Title::calculate_w(channel_picker->parent_window, _("Hue:")) + pad;
1459 result = MAX(result, new_w);
1461 if(picture_usage->use_whiteness)
1463 int new_w = BC_Title::calculate_w(channel_picker->parent_window, _("Whiteness:")) + pad;
1464 result = MAX(result, new_w);
1468 for(int i = 0; i < channel_picker->get_controls(); i++)
1470 int new_w = BC_Title::calculate_w(channel_picker->parent_window,
1471 channel_picker->get_control(i)->name) +
1473 result = MAX(result, new_w);
1480 void ChannelEditPictureWindow::create_objects()
1482 lock_window("ChannelEditPictureWindow::create_objects");
1484 int widget_border = ((Theme*)channel_picker->get_theme())->widget_border;
1485 int x1 = get_w() - BC_Pot::calculate_w() * 2 - widget_border * 2;
1486 int x2 = get_w() - BC_Pot::calculate_w() - widget_border;
1487 int pad = BC_Pot::calculate_h();
1489 #define SWAP_X x1 ^= x2; x2 ^= x1; x1 ^= x2;
1491 PictureConfig *picture_usage = channel_picker->get_picture_usage();
1493 // Only used for Video4Linux 1
1494 if(!picture_usage ||
1495 (!picture_usage->use_brightness &&
1496 !picture_usage->use_contrast &&
1497 !picture_usage->use_color &&
1498 !picture_usage->use_hue &&
1499 !picture_usage->use_whiteness &&
1500 !channel_picker->get_controls()))
1502 add_subwindow(new BC_Title(x, y, MSG_NO_PIC_CONTROLS));
1506 // Only used for Video4Linux 1
1507 if(picture_usage && picture_usage->use_brightness)
1509 add_subwindow(new BC_Title(x, y + 10, _("Brightness:")));
1510 add_subwindow(new ChannelEditBright(x1, y, channel_picker, channel_picker->get_brightness()));
1516 if(picture_usage && picture_usage->use_contrast)
1518 add_subwindow(new BC_Title(x, y + 10, _("Contrast:")));
1519 add_subwindow(new ChannelEditContrast(x1, y, channel_picker, channel_picker->get_contrast()));
1524 if(picture_usage && picture_usage->use_color)
1526 add_subwindow(new BC_Title(x, y + 10, _("Color:")));
1527 add_subwindow(new ChannelEditColor(x1, y, channel_picker, channel_picker->get_color()));
1532 if(picture_usage && picture_usage->use_hue)
1534 add_subwindow(new BC_Title(x, y + 10, _("Hue:")));
1535 add_subwindow(new ChannelEditHue(x1, y, channel_picker, channel_picker->get_hue()));
1540 if(picture_usage && picture_usage->use_whiteness)
1542 add_subwindow(new BC_Title(x, y + 10, _("Whiteness:")));
1543 add_subwindow(new ChannelEditWhiteness(x1, y, channel_picker, channel_picker->get_whiteness()));
1548 for(int i = 0; i < channel_picker->get_controls(); i++)
1551 add_subwindow(title = new BC_Title(x,
1553 _(channel_picker->get_control(i)->name)));
1556 if(x3 < title->get_x() + title->get_w() + widget_border)
1557 x3 = title->get_x() + title->get_w() + widget_border;
1559 add_subwindow(new ChannelEditCommon(x3,
1562 channel_picker->get_control(i)));
1569 add_subwindow(new BC_OKButton(this));
1574 int ChannelEditPictureWindow::translation_event()
1576 channel_picker->mwindow->session->picture_x = get_x();
1577 channel_picker->mwindow->session->picture_y = get_y();
1583 ChannelEditBright::ChannelEditBright(int x, int y, ChannelPicker *channel_picker, int value)
1590 this->channel_picker = channel_picker;
1592 ChannelEditBright::~ChannelEditBright() {}
1593 int ChannelEditBright::handle_event()
1597 int ChannelEditBright::button_release_event()
1599 if(BC_Pot::button_release_event())
1601 channel_picker->set_brightness(get_value());
1607 ChannelEditContrast::ChannelEditContrast(int x, int y, ChannelPicker *channel_picker, int value)
1614 this->channel_picker = channel_picker;
1616 ChannelEditContrast::~ChannelEditContrast() {}
1617 int ChannelEditContrast::handle_event()
1621 int ChannelEditContrast::button_release_event()
1623 if(BC_Pot::button_release_event())
1625 channel_picker->set_contrast(get_value());
1632 ChannelEditColor::ChannelEditColor(int x, int y, ChannelPicker *channel_picker, int value)
1639 this->channel_picker = channel_picker;
1641 ChannelEditColor::~ChannelEditColor() {}
1642 int ChannelEditColor::handle_event()
1646 int ChannelEditColor::button_release_event()
1648 if(BC_Pot::button_release_event())
1650 channel_picker->set_color(get_value());
1656 ChannelEditHue::ChannelEditHue(int x, int y, ChannelPicker *channel_picker, int value)
1663 this->channel_picker = channel_picker;
1665 ChannelEditHue::~ChannelEditHue() {}
1666 int ChannelEditHue::handle_event()
1670 int ChannelEditHue::button_release_event()
1672 if(BC_Pot::button_release_event())
1674 channel_picker->set_hue(get_value());
1680 ChannelEditWhiteness::ChannelEditWhiteness(int x, int y, ChannelPicker *channel_picker, int value)
1687 this->channel_picker = channel_picker;
1689 ChannelEditWhiteness::~ChannelEditWhiteness()
1692 int ChannelEditWhiteness::handle_event()
1696 int ChannelEditWhiteness::button_release_event()
1698 if(BC_Pot::button_release_event())
1700 channel_picker->set_whiteness(get_value());
1708 ChannelEditCommon::ChannelEditCommon(int x,
1710 ChannelPicker *channel_picker,
1718 this->channel_picker = channel_picker;
1719 this->device_id = item->device_id;
1722 ChannelEditCommon::~ChannelEditCommon()
1726 int ChannelEditCommon::handle_event()
1731 int ChannelEditCommon::button_release_event()
1733 if(BC_Pot::button_release_event())
1735 channel_picker->set_picture(device_id, get_value());
1741 int ChannelEditCommon::keypress_event()
1743 if(BC_Pot::keypress_event())
1745 channel_picker->set_picture(device_id, get_value());