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"
43 ChannelEditThread::ChannelEditThread(ChannelPicker *channel_picker,
47 this->channel_picker = channel_picker;
48 this->channeldb = channeldb;
51 new_channels = new ChannelDB;
52 completion = new Condition(1, "ChannelEditThread::completion");
55 ChannelEditThread::~ChannelEditThread()
63 void ChannelEditThread::run()
69 window->lock_window("ChannelEditThread::run");
70 window->raise_window(1);
71 window->unlock_window();
76 completion->lock("ChannelEditThread::run");
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);
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;
91 // Copy new channels to master list
92 channel_picker->channeldb->clear();
94 channel_picker->channeldb->copy_from(new_channels);
95 channel_picker->update_channel_list();
99 channel_picker->handle_channel_edit(result);
101 completion->unlock();
106 void ChannelEditThread::close_threads()
108 if(in_progress && window)
111 completion->lock("ChannelEditThread::close_threads");
112 completion->unlock();
116 char *ChannelEditThread::value_to_freqtable(int value)
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");
137 char* ChannelEditThread::value_to_norm(int value)
141 case NTSC: return _("NTSC");
142 case PAL: return _("PAL");
143 case SECAM: return _("SECAM");
148 char* ChannelEditThread::value_to_input(int value)
150 ArrayList<Channel*> *inputs = channel_picker->get_video_inputs();
151 return value >= inputs->total ? _("None") :
152 inputs->values[value]->device_name;
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)
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;
175 ChannelEditWindow::~ChannelEditWindow()
177 if( thread->scan_thread )
178 thread->scan_thread->stop();
179 channel_list.remove_all_objects();
181 delete picture_thread;
182 delete scan_confirm_thread;
185 void ChannelEditWindow::create_objects()
189 // Create channel list
190 for(int i = 0; i < thread->new_channels->size(); i++)
192 channel_list.append(new BC_ListBoxItem(thread->new_channels->get(i)->title));
195 add_subwindow(list_box = new ChannelEditList(this, x, y));
197 if(channel_picker->use_select())
199 add_subwindow(new ChannelEditSelect(this, x, y));
202 add_subwindow(new ChannelEditAdd(this, x, y));
204 add_subwindow(new ChannelEdit(this, x, y));
206 add_subwindow(new ChannelEditMoveUp(this, x, y));
208 add_subwindow(new ChannelEditMoveDown(this, x, y));
210 add_subwindow(new ChannelEditSort(this, x, y));
213 Channel *channel_usage = channel_picker->get_channel_usage();
214 if(channel_usage && channel_usage->has_scanning)
216 add_subwindow(new ChannelEditScan(this, x, y));
219 add_subwindow(new ChannelEditDel(this, x, y));
221 add_subwindow(new ChannelEditPicture(this, x, y));
224 add_subwindow(new BC_OKButton(this));
226 add_subwindow(new BC_CancelButton(this));
229 edit_thread = new ChannelEditEditThread(this, channel_picker);
230 picture_thread = new ChannelEditPictureThread(channel_picker);
234 int ChannelEditWindow::close_event()
236 if( thread->scan_thread )
237 thread->scan_thread->stop();
238 return BC_WindowBase::close_event();
241 int ChannelEditWindow::translation_event()
243 channel_picker->mwindow->session->channels_x = get_x();
244 channel_picker->mwindow->session->channels_y = get_y();
249 int ChannelEditWindow::add_channel()
251 Channel *new_channel;
252 Channel *prev_channel = 0;
254 // Create new channel
255 new_channel = new Channel;
257 // Reuse parameters from previous channel
258 if(thread->new_channels->size())
260 prev_channel = thread->new_channels->get(
261 thread->new_channels->size() - 1);
262 new_channel->copy_settings(prev_channel);
265 // Use default channel parameters
266 if(channel_picker->get_master_channel())
268 new_channel->copy_settings(channel_picker->get_master_channel());
271 // Copy device usage. Need the same thing for playback.
272 if(channel_picker->get_master_channel())
274 new_channel->copy_usage(channel_picker->get_master_channel());
277 // Add to channel table
278 channel_list.append(new BC_ListBoxItem(new_channel->title));
279 thread->new_channels->append(new_channel);
282 // Start common routing
283 edit_thread->edit_channel(new_channel, 0);
287 void ChannelEditWindow::update_list()
289 // Create channel list
290 channel_list.remove_all_objects();
291 for(int i = 0; i < thread->new_channels->size(); i++)
295 thread->new_channels->get(i)->title));
298 list_box->update(&channel_list, 0, 0, 1, list_box->get_yposition());
301 void ChannelEditWindow::update_list(Channel *channel)
304 for(i = 0; i < thread->new_channels->size(); i++)
305 if(thread->new_channels->get(i) == channel) break;
307 if(i < thread->new_channels->size())
309 channel_list.values[i]->set_text(channel->title);
316 void ChannelEditWindow::edit_channel()
318 if(list_box->get_selection_number(0, 0) > -1)
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)),
328 void ChannelEditWindow::edit_picture()
330 picture_thread->edit_picture();
333 void ChannelEditWindow::scan_confirm()
335 channel_picker->load_scan_defaults(&thread->scan_params);
336 if(!scan_confirm_thread) scan_confirm_thread = new ConfirmScanThread(this);
338 scan_confirm_thread->start();
339 lock_window("ChannelEditWindow::scan_confirm");
342 void ChannelEditWindow::scan()
344 thread->new_channels->clear();
347 if( !thread->scan_thread )
348 thread->scan_thread = new ScanThread(thread);
349 thread->scan_thread->start();
353 void ChannelEditWindow::get_chan_num(Channel *channel, int &chan, int &stream)
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 ) {
360 while( isdigit(*cp) ) str = 10*str + (*cp++ -'0');
363 chan = chn; stream = str;
366 void ChannelEditWindow::sort()
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);
390 void ChannelEditWindow::delete_channel(int number)
392 delete thread->new_channels->get(number);
393 channel_list.remove_number(number);
394 thread->new_channels->remove_number(number);
398 void ChannelEditWindow::delete_channel(Channel *channel)
401 for(i = 0; i < thread->new_channels->size(); i++)
403 if(thread->new_channels->get(i) == channel)
408 if(i < thread->new_channels->size()) delete_channel(i);
411 int ChannelEditWindow::move_channel_up()
413 if(list_box->get_selection_number(0, 0) > -1)
415 int number2 = list_box->get_selection_number(0, 0);
416 int number1 = number2 - 1;
418 BC_ListBoxItem *temp_text;
420 if(number1 < 0) number1 = thread->new_channels->size() - 1;
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);
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,
433 list_box->get_xposition(),
434 list_box->get_yposition(),
441 int ChannelEditWindow::move_channel_down()
443 if(list_box->get_selection_number(0, 0) > -1)
445 int number2 = list_box->get_selection_number(0, 0);
446 int number1 = number2 + 1;
448 BC_ListBoxItem *temp_text;
450 if(number1 > thread->new_channels->size() - 1) number1 = 0;
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,
462 list_box->get_xposition(),
463 list_box->get_yposition(),
470 int ChannelEditWindow::change_channel_from_list(int channel_number)
472 if(channel_number > -1 && channel_number < thread->new_channels->size())
474 thread->current_channel = channel_number;
475 channel_picker->set_channel(thread->new_channels->get(channel_number));
480 ChannelEditSelect::ChannelEditSelect(ChannelEditWindow *window, int x, int y)
481 : BC_GenericButton(x, y, _("Select"))
483 this->window = window;
485 ChannelEditSelect::~ChannelEditSelect()
488 int ChannelEditSelect::handle_event()
490 window->change_channel_from_list(
491 window->list_box->get_selection_number(0, 0));
495 ChannelEditAdd::ChannelEditAdd(ChannelEditWindow *window, int x, int y)
496 : BC_GenericButton(x, y, _("Add..."))
498 this->window = window;
500 ChannelEditAdd::~ChannelEditAdd()
503 int ChannelEditAdd::handle_event()
505 window->add_channel();
509 ChannelEditList::ChannelEditList(ChannelEditWindow *window, int x, int y)
513 window->get_h() - BC_OKButton::calculate_h() - y - 10,
515 &(window->channel_list))
517 this->window = window;
519 ChannelEditList::~ChannelEditList()
522 int ChannelEditList::handle_event()
524 window->edit_channel();
528 ChannelEditMoveUp::ChannelEditMoveUp(ChannelEditWindow *window, int x, int y)
529 : BC_GenericButton(x, y, _("Move up"))
531 this->window = window;
533 ChannelEditMoveUp::~ChannelEditMoveUp()
536 int ChannelEditMoveUp::handle_event()
538 lock_window("ChannelEditMoveUp::handle_event");
539 window->move_channel_up();
544 ChannelEditMoveDown::ChannelEditMoveDown(ChannelEditWindow *window, int x, int y)
545 : BC_GenericButton(x, y, _("Move down"))
547 this->window = window;
549 ChannelEditMoveDown::~ChannelEditMoveDown()
552 int ChannelEditMoveDown::handle_event()
554 lock_window("ChannelEditMoveDown::handle_event");
555 window->move_channel_down();
560 ChannelEditSort::ChannelEditSort(ChannelEditWindow *window, int x, int y)
561 : BC_GenericButton(x, y, _("Sort"))
563 this->window = window;
565 int ChannelEditSort::handle_event()
567 lock_window("ChannelEditSort::handle_event");
573 ChannelEditScan::ChannelEditScan(ChannelEditWindow *window, int x, int y)
574 : BC_GenericButton(x, y, _("Scan"))
576 this->window = window;
578 int ChannelEditScan::handle_event()
580 window->scan_confirm();
584 ChannelEditDel::ChannelEditDel(ChannelEditWindow *window, int x, int y)
585 : BC_GenericButton(x, y, _("Delete"))
587 this->window = window;
589 ChannelEditDel::~ChannelEditDel()
592 int ChannelEditDel::handle_event()
594 if(window->list_box->get_selection_number(0, 0) > -1)
595 window->delete_channel(window->list_box->get_selection_number(0, 0));
599 ChannelEdit::ChannelEdit(ChannelEditWindow *window, int x, int y)
600 : BC_GenericButton(x, y, _("Edit..."))
602 this->window = window;
604 ChannelEdit::~ChannelEdit()
607 int ChannelEdit::handle_event()
609 window->edit_channel();
613 ChannelEditPicture::ChannelEditPicture(ChannelEditWindow *window, int x, int y)
614 : BC_GenericButton(x, y, _("Picture..."))
616 this->window = window;
618 ChannelEditPicture::~ChannelEditPicture()
621 int ChannelEditPicture::handle_event()
623 window->edit_picture();
638 // ========================= confirm overwrite by channel scannin
641 ConfirmScan::ConfirmScan(ChannelEditWindow *gui, int x, int y)
642 : BC_Window(PROGRAM_NAME ": Scan confirm",
646 BC_OKButton::calculate_h() + 130,
656 void ConfirmScan::create_objects()
661 add_subwindow(title = new BC_Title(x, y, _("Set parameters for channel scanning.")));
662 y += title->get_h() + 10;
665 add_subwindow(title = new BC_Title(x, y, _("Frequency table:")));
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();
678 ChannelEditEditFreqtable *table;
679 add_subwindow(table = new ChannelEditEditFreqtable(x,
684 y += table->get_h() + 10;
686 ChannelEditEditNorm *norm;
687 add_subwindow(norm = new ChannelEditEditNorm(x,
692 y += norm->get_h() + 10;
694 ChannelEditEditInput *input;
695 add_subwindow(input = new ChannelEditEditInput(x,
702 add_subwindow(new BC_OKButton(this));
703 add_subwindow(new BC_CancelButton(this));
713 ConfirmScanThread::ConfirmScanThread(ChannelEditWindow *gui)
719 void ConfirmScanThread::handle_done_event(int result)
721 gui->channel_picker->save_scan_defaults(&gui->thread->scan_params);
724 get_gui()->hide_window();
725 gui->lock_window("ConfirmScanThread::handle_done_event");
727 gui->unlock_window();
731 ConfirmScanThread::~ConfirmScanThread()
736 BC_Window* ConfirmScanThread::new_gui()
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();
750 ScanThread::ScanThread(ChannelEditThread *edit)
758 ScanThread::~ScanThread()
763 void ScanThread::stop()
766 // Cancel previous job
771 progress->stop_progress();
772 delete progress; progress = 0;
776 void ScanThread::start()
781 progress = new BC_ProgressBox(
782 edit->channel_picker->parent_window->get_abs_cursor_x(1),
783 edit->channel_picker->parent_window->get_abs_cursor_y(1),
785 chanlists[edit->scan_params.freqtable].count);
791 void ScanThread::run()
793 for(int i = 0; i < chanlists[edit->scan_params.freqtable].count &&
794 !interrupt && !progress->is_cancelled(); i++) {
795 edit->scan_params.entry = i;
796 char string[BCTEXTLEN];
797 sprintf(edit->scan_params.title, "%s",
798 chanlists[edit->scan_params.freqtable].list[i].name);
799 sprintf(string, "Scanning %s", edit->scan_params.title);
800 progress->update_title(string, 1);
801 progress->update(i, 1);
802 edit->channel_picker->set_channel(&edit->scan_params);
803 sleep(1); // has_signal should do whatever it takes
804 if( interrupt ) break;
805 int got_signal = edit->channel_picker->has_signal();
806 if( interrupt ) break;
807 if(!got_signal) continue;
808 if(edit->channel_picker->get_channel_usage()->has_subchan) {
809 ArrayList<Channel*> channels;
810 edit->channel_picker->create_channeldb(&channels);
811 if( channels.total ) {
812 edit->window->lock_window("ScanThread::run");
813 for( int i=0; i<channels.total; ++i ) {
814 Channel *new_channel = channels.values[i];
815 new_channel->copy_usage(&edit->scan_params);
816 edit->new_channels->append(new_channel);
818 edit->window->update_list();
819 edit->window->unlock_window();
823 Channel *new_channel = new Channel;
824 new_channel->copy_usage(&edit->scan_params);
825 new_channel->copy_settings(&edit->scan_params);
826 edit->window->lock_window("ScanThread::run");
827 edit->new_channels->append(new_channel);
828 edit->window->update_list();
829 edit->window->unlock_window();
839 // ================================= Edit a single channel
843 ChannelEditEditThread::ChannelEditEditThread(ChannelEditWindow *window,
844 ChannelPicker *channel_picker)
847 this->window = window;
848 this->channel_picker = channel_picker;
852 completion = new Condition(1, "ChannelEditEditThread::completion");
855 ChannelEditEditThread::~ChannelEditEditThread()
861 void ChannelEditEditThread::close_threads()
865 edit_window->set_done(1);
866 completion->lock("ChannelEditEditThread::close_threads");
867 completion->unlock();
871 int ChannelEditEditThread::edit_channel(Channel *channel, int editing)
875 edit_window->lock_window("ChannelEditEditThread::edit_channel");
876 edit_window->raise_window(1);
877 edit_window->unlock_window();
882 // Copy the channel to edit into a temporary
883 completion->lock("ChannelEditEditThread::edit_channel");
884 this->editing = editing;
885 this->output_channel = channel;
886 new_channel.copy_settings(output_channel);
887 new_channel.copy_usage(output_channel);
889 if(editing && new_channel.title[0])
899 void ChannelEditEditThread::set_device()
901 channel_picker->set_channel(&new_channel);
904 void ChannelEditEditThread::change_source(const char *source_name)
906 for(int i = 0; i < chanlists[new_channel.freqtable].count; i++)
908 if(!strcasecmp(chanlists[new_channel.freqtable].list[i].name, source_name))
910 new_channel.entry = i;
911 i = chanlists[new_channel.freqtable].count;
917 strcpy(new_channel.title, source_name);
918 if(edit_window->title_text)
920 edit_window->title_text->update(source_name);
925 void ChannelEditEditThread::source_up()
928 if(new_channel.entry > chanlists[new_channel.freqtable].count - 1) new_channel.entry = 0;
929 source_text->update(chanlists[new_channel.freqtable].list[new_channel.entry].name);
933 void ChannelEditEditThread::source_down()
936 if(new_channel.entry < 0) new_channel.entry = chanlists[new_channel.freqtable].count - 1;
937 source_text->update(chanlists[new_channel.freqtable].list[new_channel.entry].name);
941 void ChannelEditEditThread::set_input(int value)
943 new_channel.input = value;
947 void ChannelEditEditThread::set_norm(int value)
949 new_channel.norm = value;
953 void ChannelEditEditThread::set_freqtable(int value)
955 new_channel.freqtable = value;
956 if(new_channel.entry > chanlists[new_channel.freqtable].count - 1) new_channel.entry = 0;
957 source_text->update(chanlists[new_channel.freqtable].list[new_channel.entry].name);
961 void ChannelEditEditThread::run()
963 ChannelEditEditWindow edit_window(this, window, channel_picker);
964 edit_window.create_objects(&new_channel);
965 this->edit_window = &edit_window;
966 int result = edit_window.run_window();
967 this->edit_window = 0;
969 // Done editing channel. Keep channel.
972 output_channel->copy_settings(&new_channel);
973 window->lock_window();
974 window->update_list(output_channel);
975 window->unlock_window();
982 window->lock_window();
983 window->delete_channel(output_channel);
984 window->unlock_window();
988 completion->unlock();
992 ChannelEditEditWindow::ChannelEditEditWindow(ChannelEditEditThread *thread,
993 ChannelEditWindow *window,
994 ChannelPicker *channel_picker)
995 : BC_Window(PROGRAM_NAME ": Edit Channel",
996 channel_picker->parent_window->get_abs_cursor_x(1),
997 channel_picker->parent_window->get_abs_cursor_y(1),
1006 this->channel_picker = channel_picker;
1007 this->window = window;
1008 this->thread = thread;
1010 ChannelEditEditWindow::~ChannelEditEditWindow()
1013 void ChannelEditEditWindow::create_objects(Channel *channel)
1015 this->new_channel = channel;
1016 Channel *channel_usage = channel_picker->get_channel_usage();
1020 // if(!channel_usage ||
1021 // (!channel_usage->use_frequency &&
1022 // !channel_usage->use_fine &&
1023 // !channel_usage->use_norm &&
1024 // !channel_usage->use_input))
1026 // add_subwindow(new BC_Title(x, y, "Device has no input selection."));
1031 add_subwindow(new BC_Title(x, y, _("Title:")));
1032 add_subwindow(title_text = new ChannelEditEditTitle(x, y + 20, thread));
1036 if(channel_usage && channel_usage->use_frequency)
1038 add_subwindow(new BC_Title(x, y, _("Channel:")));
1040 add_subwindow(thread->source_text = new ChannelEditEditSource(x, y, thread));
1041 add_subwindow(new ChannelEditEditSourceTumbler(x + 160, y, thread));
1044 add_subwindow(new BC_Title(x, y, _("Frequency table:")));
1045 ChannelEditEditFreqtable *table;
1046 add_subwindow(table = new ChannelEditEditFreqtable(x + 130,
1054 if(channel_usage && channel_usage->use_fine)
1056 add_subwindow(new BC_Title(x, y, _("Fine:")));
1057 add_subwindow(new ChannelEditEditFine(x + 130, y, thread));
1061 if(channel_usage && channel_usage->use_norm)
1063 add_subwindow(new BC_Title(x, y, _("Norm:")));
1064 ChannelEditEditNorm *norm;
1065 add_subwindow(norm = new ChannelEditEditNorm(x + 130,
1073 if( (channel_usage && channel_usage->use_input) ||
1076 add_subwindow(new BC_Title(x, y, _("Input:")));
1077 ChannelEditEditInput *input;
1078 add_subwindow(input = new ChannelEditEditInput(x + 130,
1086 add_subwindow(new BC_OKButton(this));
1088 add_subwindow(new BC_CancelButton(this));
1092 ChannelEditEditTitle::ChannelEditEditTitle(int x,
1094 ChannelEditEditThread *thread)
1095 : BC_TextBox(x, y, 150, 1, thread->new_channel.title)
1097 this->thread = thread;
1099 ChannelEditEditTitle::~ChannelEditEditTitle()
1102 int ChannelEditEditTitle::handle_event()
1104 if(strlen(get_text()) < 1024)
1106 strcpy(thread->new_channel.title, get_text());
1108 thread->user_title = get_text()[0] ? 1 : 0;
1113 ChannelEditEditSource::ChannelEditEditSource(int x, int y, ChannelEditEditThread *thread)
1114 : BC_TextBox(x, y, 150, 1, chanlists[thread->new_channel.freqtable].list[thread->new_channel.entry].name)
1116 this->thread = thread;
1119 ChannelEditEditSource::~ChannelEditEditSource()
1122 int ChannelEditEditSource::handle_event()
1124 thread->change_source(get_text());
1129 ChannelEditEditSourceTumbler::ChannelEditEditSourceTumbler(int x, int y, ChannelEditEditThread *thread)
1132 this->thread = thread;
1134 ChannelEditEditSourceTumbler::~ChannelEditEditSourceTumbler()
1137 int ChannelEditEditSourceTumbler::handle_up_event()
1139 thread->source_up();
1142 int ChannelEditEditSourceTumbler::handle_down_event()
1144 thread->source_down();
1148 ChannelEditEditInput::ChannelEditEditInput(int x,
1150 ChannelEditEditThread *thread,
1151 ChannelEditThread *edit)
1155 edit->value_to_input(thread ? thread->new_channel.input : edit->scan_params.input))
1157 this->thread = thread;
1160 ChannelEditEditInput::~ChannelEditEditInput()
1163 void ChannelEditEditInput::add_items()
1165 ArrayList<Channel*> *inputs;
1166 inputs = edit->channel_picker->get_video_inputs();
1170 for(int i = 0; i < inputs->total; i++)
1172 add_item(new ChannelEditEditInputItem(thread,
1174 inputs->values[i]->device_name,
1179 int ChannelEditEditInput::handle_event()
1184 ChannelEditEditInputItem::ChannelEditEditInputItem(ChannelEditEditThread *thread,
1185 ChannelEditThread *edit,
1190 this->thread = thread;
1192 this->value = value;
1194 ChannelEditEditInputItem::~ChannelEditEditInputItem()
1197 int ChannelEditEditInputItem::handle_event()
1199 get_popup_menu()->set_text(get_text());
1200 if(thread && !thread->user_title)
1202 strcpy(thread->new_channel.title, get_text());
1203 if(thread->edit_window->title_text)
1205 thread->edit_window->title_text->update(get_text());
1209 thread->set_input(value);
1211 edit->scan_params.input = value;
1215 ChannelEditEditNorm::ChannelEditEditNorm(int x,
1217 ChannelEditEditThread *thread,
1218 ChannelEditThread *edit)
1222 edit->value_to_norm(thread ? thread->new_channel.norm : edit->scan_params.norm))
1224 this->thread = thread;
1227 ChannelEditEditNorm::~ChannelEditEditNorm()
1230 void ChannelEditEditNorm::add_items()
1232 add_item(new ChannelEditEditNormItem(thread,
1234 edit->value_to_norm(NTSC), NTSC));
1235 add_item(new ChannelEditEditNormItem(thread,
1237 edit->value_to_norm(PAL), PAL));
1238 add_item(new ChannelEditEditNormItem(thread,
1240 edit->value_to_norm(SECAM), SECAM));
1244 ChannelEditEditNormItem::ChannelEditEditNormItem(ChannelEditEditThread *thread,
1245 ChannelEditThread *edit,
1250 this->value = value;
1252 this->thread = thread;
1254 ChannelEditEditNormItem::~ChannelEditEditNormItem()
1257 int ChannelEditEditNormItem::handle_event()
1259 get_popup_menu()->set_text(get_text());
1261 thread->set_norm(value);
1263 edit->scan_params.norm = value;
1268 ChannelEditEditFreqtable::ChannelEditEditFreqtable(int x,
1270 ChannelEditEditThread *thread,
1271 ChannelEditThread *edit)
1275 edit->value_to_freqtable(thread ? thread->new_channel.freqtable : edit->scan_params.freqtable))
1277 this->thread = thread;
1280 ChannelEditEditFreqtable::~ChannelEditEditFreqtable()
1283 void ChannelEditEditFreqtable::add_items()
1285 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_DVB), NTSC_DVB));
1286 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(CATV_DVB), CATV_DVB));
1287 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_BCAST), NTSC_BCAST));
1288 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_CABLE), NTSC_CABLE));
1289 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_HRC), NTSC_HRC));
1290 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_BCAST_JP), NTSC_BCAST_JP));
1291 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_CABLE_JP), NTSC_CABLE_JP));
1292 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_AUSTRALIA), PAL_AUSTRALIA));
1293 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_EUROPE), PAL_EUROPE));
1294 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_E_EUROPE), PAL_E_EUROPE));
1295 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_ITALY), PAL_ITALY));
1296 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_IRELAND), PAL_IRELAND));
1297 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_NEWZEALAND), PAL_NEWZEALAND));
1300 ChannelEditEditFreqItem::ChannelEditEditFreqItem(ChannelEditEditThread *thread,
1301 ChannelEditThread *edit,
1302 char *text, int value)
1305 this->value = value;
1307 this->thread = thread;
1309 ChannelEditEditFreqItem::~ChannelEditEditFreqItem()
1312 int ChannelEditEditFreqItem::handle_event()
1314 get_popup_menu()->set_text(get_text());
1316 thread->set_freqtable(value);
1318 edit->scan_params.freqtable = value;
1324 ChannelEditEditFine::ChannelEditEditFine(int x,
1326 ChannelEditEditThread *thread)
1334 thread->new_channel.fine_tune)
1336 this->thread = thread;
1338 ChannelEditEditFine::~ChannelEditEditFine()
1341 int ChannelEditEditFine::handle_event()
1345 int ChannelEditEditFine::button_release_event()
1347 if(BC_Slider::button_release_event())
1349 thread->new_channel.fine_tune = get_value();
1350 thread->set_device();
1357 // ========================== picture quality
1359 ChannelEditPictureThread::ChannelEditPictureThread(
1360 ChannelPicker *channel_picker)
1363 this->channel_picker = channel_picker;
1365 ChannelEditPictureThread::~ChannelEditPictureThread()
1369 void ChannelEditPictureThread::handle_done_event(int result)
1371 if(channel_picker->get_picture_usage())
1372 channel_picker->get_picture_usage()->save_defaults();
1375 BC_Window* ChannelEditPictureThread::new_gui()
1377 ChannelEditPictureWindow *edit_window = new ChannelEditPictureWindow(this,
1379 edit_window->create_objects();
1383 void ChannelEditPictureThread::edit_picture()
1389 ChannelEditPictureWindow::ChannelEditPictureWindow(ChannelEditPictureThread *thread,
1390 ChannelPicker *channel_picker)
1391 : BC_Window(PROGRAM_NAME ": Picture",
1392 channel_picker->mwindow->session->picture_x,
1393 channel_picker->mwindow->session->picture_y,
1394 calculate_w(channel_picker),
1395 calculate_h(channel_picker),
1396 calculate_w(channel_picker),
1397 calculate_h(channel_picker))
1399 this->thread = thread;
1400 this->channel_picker = channel_picker;
1402 ChannelEditPictureWindow::~ChannelEditPictureWindow()
1406 int ChannelEditPictureWindow::calculate_h(ChannelPicker *channel_picker)
1408 PictureConfig *picture_usage = channel_picker->get_picture_usage();
1409 int pad = BC_Pot::calculate_h();
1411 channel_picker->parent_window->get_text_height(MEDIUMFONT) + 5 +
1412 BC_OKButton::calculate_h();
1414 // Only used for Video4Linux 1
1417 if(picture_usage->use_brightness)
1419 if(picture_usage->use_contrast)
1421 if(picture_usage->use_color)
1423 if(picture_usage->use_hue)
1425 if(picture_usage->use_whiteness)
1429 result += channel_picker->get_controls() * pad;
1433 int ChannelEditPictureWindow::calculate_w(ChannelPicker *channel_picker)
1435 PictureConfig *picture_usage = channel_picker->get_picture_usage();
1436 int widget_border = ((Theme*)channel_picker->get_theme())->widget_border;
1437 int pad = BC_Pot::calculate_w() + 4 * widget_border;
1440 // Only used for Video4Linux 1
1441 if(!picture_usage ||
1442 (!picture_usage->use_brightness &&
1443 !picture_usage->use_contrast &&
1444 !picture_usage->use_color &&
1445 !picture_usage->use_hue &&
1446 !picture_usage->use_whiteness &&
1447 !channel_picker->get_controls()))
1449 result = BC_Title::calculate_w(channel_picker->parent_window,
1450 "Device has no picture controls." +
1454 // Only used for Video4Linux 1
1457 if(picture_usage->use_brightness)
1459 int new_w = BC_Title::calculate_w(channel_picker->parent_window, "Brightness:") + pad;
1460 result = MAX(result, new_w);
1462 if(picture_usage->use_contrast)
1464 int new_w = BC_Title::calculate_w(channel_picker->parent_window, "Contrast:") + pad;
1465 result = MAX(result, new_w);
1467 if(picture_usage->use_color)
1469 int new_w = BC_Title::calculate_w(channel_picker->parent_window, "Color:") + pad;
1470 result = MAX(result, new_w);
1472 if(picture_usage->use_hue)
1474 int new_w = BC_Title::calculate_w(channel_picker->parent_window, "Hue:") + pad;
1475 result = MAX(result, new_w);
1477 if(picture_usage->use_whiteness)
1479 int new_w = BC_Title::calculate_w(channel_picker->parent_window, "Whiteness:") + pad;
1480 result = MAX(result, new_w);
1484 for(int i = 0; i < channel_picker->get_controls(); i++)
1486 int new_w = BC_Title::calculate_w(channel_picker->parent_window,
1487 channel_picker->get_control(i)->name) +
1489 result = MAX(result, new_w);
1496 void ChannelEditPictureWindow::create_objects()
1499 int widget_border = ((Theme*)channel_picker->get_theme())->widget_border;
1500 int x1 = get_w() - BC_Pot::calculate_w() * 2 - widget_border * 2;
1501 int x2 = get_w() - BC_Pot::calculate_w() - widget_border;
1502 int pad = BC_Pot::calculate_h();
1504 #define SWAP_X x1 ^= x2; x2 ^= x1; x1 ^= x2;
1506 PictureConfig *picture_usage = channel_picker->get_picture_usage();
1508 // Only used for Video4Linux 1
1509 if(!picture_usage ||
1510 (!picture_usage->use_brightness &&
1511 !picture_usage->use_contrast &&
1512 !picture_usage->use_color &&
1513 !picture_usage->use_hue &&
1514 !picture_usage->use_whiteness &&
1515 !channel_picker->get_controls()))
1517 add_subwindow(new BC_Title(x, y, "Device has no picture controls."));
1521 // Only used for Video4Linux 1
1522 if(picture_usage && picture_usage->use_brightness)
1524 add_subwindow(new BC_Title(x, y + 10, _("Brightness:")));
1525 add_subwindow(new ChannelEditBright(x1, y, channel_picker, channel_picker->get_brightness()));
1531 if(picture_usage && picture_usage->use_contrast)
1533 add_subwindow(new BC_Title(x, y + 10, _("Contrast:")));
1534 add_subwindow(new ChannelEditContrast(x1, y, channel_picker, channel_picker->get_contrast()));
1539 if(picture_usage && picture_usage->use_color)
1541 add_subwindow(new BC_Title(x, y + 10, _("Color:")));
1542 add_subwindow(new ChannelEditColor(x1, y, channel_picker, channel_picker->get_color()));
1547 if(picture_usage && picture_usage->use_hue)
1549 add_subwindow(new BC_Title(x, y + 10, _("Hue:")));
1550 add_subwindow(new ChannelEditHue(x1, y, channel_picker, channel_picker->get_hue()));
1555 if(picture_usage && picture_usage->use_whiteness)
1557 add_subwindow(new BC_Title(x, y + 10, _("Whiteness:")));
1558 add_subwindow(new ChannelEditWhiteness(x1, y, channel_picker, channel_picker->get_whiteness()));
1563 for(int i = 0; i < channel_picker->get_controls(); i++)
1566 add_subwindow(title = new BC_Title(x,
1568 _(channel_picker->get_control(i)->name)));
1571 if(x3 < title->get_x() + title->get_w() + widget_border)
1572 x3 = title->get_x() + title->get_w() + widget_border;
1574 add_subwindow(new ChannelEditCommon(x3,
1577 channel_picker->get_control(i)));
1584 add_subwindow(new BC_OKButton(this));
1588 int ChannelEditPictureWindow::translation_event()
1590 channel_picker->mwindow->session->picture_x = get_x();
1591 channel_picker->mwindow->session->picture_y = get_y();
1597 ChannelEditBright::ChannelEditBright(int x, int y, ChannelPicker *channel_picker, int value)
1604 this->channel_picker = channel_picker;
1606 ChannelEditBright::~ChannelEditBright() {}
1607 int ChannelEditBright::handle_event()
1611 int ChannelEditBright::button_release_event()
1613 if(BC_Pot::button_release_event())
1615 channel_picker->set_brightness(get_value());
1621 ChannelEditContrast::ChannelEditContrast(int x, int y, ChannelPicker *channel_picker, int value)
1628 this->channel_picker = channel_picker;
1630 ChannelEditContrast::~ChannelEditContrast() {}
1631 int ChannelEditContrast::handle_event()
1635 int ChannelEditContrast::button_release_event()
1637 if(BC_Pot::button_release_event())
1639 channel_picker->set_contrast(get_value());
1646 ChannelEditColor::ChannelEditColor(int x, int y, ChannelPicker *channel_picker, int value)
1653 this->channel_picker = channel_picker;
1655 ChannelEditColor::~ChannelEditColor() {}
1656 int ChannelEditColor::handle_event()
1660 int ChannelEditColor::button_release_event()
1662 if(BC_Pot::button_release_event())
1664 channel_picker->set_color(get_value());
1670 ChannelEditHue::ChannelEditHue(int x, int y, ChannelPicker *channel_picker, int value)
1677 this->channel_picker = channel_picker;
1679 ChannelEditHue::~ChannelEditHue() {}
1680 int ChannelEditHue::handle_event()
1684 int ChannelEditHue::button_release_event()
1686 if(BC_Pot::button_release_event())
1688 channel_picker->set_hue(get_value());
1694 ChannelEditWhiteness::ChannelEditWhiteness(int x, int y, ChannelPicker *channel_picker, int value)
1701 this->channel_picker = channel_picker;
1703 ChannelEditWhiteness::~ChannelEditWhiteness()
1706 int ChannelEditWhiteness::handle_event()
1710 int ChannelEditWhiteness::button_release_event()
1712 if(BC_Pot::button_release_event())
1714 channel_picker->set_whiteness(get_value());
1722 ChannelEditCommon::ChannelEditCommon(int x,
1724 ChannelPicker *channel_picker,
1732 this->channel_picker = channel_picker;
1733 this->device_id = item->device_id;
1736 ChannelEditCommon::~ChannelEditCommon()
1740 int ChannelEditCommon::handle_event()
1745 int ChannelEditCommon::button_release_event()
1747 if(BC_Pot::button_release_event())
1749 channel_picker->set_picture(device_id, get_value());
1755 int ChannelEditCommon::keypress_event()
1757 if(BC_Pot::keypress_event())
1759 channel_picker->set_picture(device_id, get_value());