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()
191 // Create channel list
192 for(int i = 0; i < thread->new_channels->size(); i++)
194 channel_list.append(new BC_ListBoxItem(thread->new_channels->get(i)->title));
197 add_subwindow(list_box = new ChannelEditList(this, x, y));
199 if(channel_picker->use_select())
201 add_subwindow(new ChannelEditSelect(this, x, y));
204 add_subwindow(new ChannelEditAdd(this, x, y));
206 add_subwindow(new ChannelEdit(this, x, y));
208 add_subwindow(new ChannelEditMoveUp(this, x, y));
210 add_subwindow(new ChannelEditMoveDown(this, x, y));
212 add_subwindow(new ChannelEditSort(this, x, y));
215 Channel *channel_usage = channel_picker->get_channel_usage();
216 if(channel_usage && channel_usage->has_scanning)
218 add_subwindow(new ChannelEditScan(this, x, y));
221 add_subwindow(new ChannelEditDel(this, x, y));
223 add_subwindow(new ChannelEditPicture(this, x, y));
226 add_subwindow(new BC_OKButton(this));
228 add_subwindow(new BC_CancelButton(this));
231 edit_thread = new ChannelEditEditThread(this, channel_picker);
232 picture_thread = new ChannelEditPictureThread(channel_picker);
236 int ChannelEditWindow::close_event()
238 if( thread->scan_thread )
239 thread->scan_thread->stop();
240 return BC_WindowBase::close_event();
243 int ChannelEditWindow::translation_event()
245 channel_picker->mwindow->session->channels_x = get_x();
246 channel_picker->mwindow->session->channels_y = get_y();
251 int ChannelEditWindow::add_channel()
253 Channel *new_channel;
254 Channel *prev_channel = 0;
256 // Create new channel
257 new_channel = new Channel;
259 // Reuse parameters from previous channel
260 if(thread->new_channels->size())
262 prev_channel = thread->new_channels->get(
263 thread->new_channels->size() - 1);
264 new_channel->copy_settings(prev_channel);
267 // Use default channel parameters
268 if(channel_picker->get_master_channel())
270 new_channel->copy_settings(channel_picker->get_master_channel());
273 // Copy device usage. Need the same thing for playback.
274 if(channel_picker->get_master_channel())
276 new_channel->copy_usage(channel_picker->get_master_channel());
279 // Add to channel table
280 channel_list.append(new BC_ListBoxItem(new_channel->title));
281 thread->new_channels->append(new_channel);
284 // Start common routing
285 edit_thread->edit_channel(new_channel, 0);
289 void ChannelEditWindow::update_list()
291 // Create channel list
292 channel_list.remove_all_objects();
293 for(int i = 0; i < thread->new_channels->size(); i++)
297 thread->new_channels->get(i)->title));
300 list_box->update(&channel_list, 0, 0, 1, list_box->get_yposition());
303 void ChannelEditWindow::update_list(Channel *channel)
306 for(i = 0; i < thread->new_channels->size(); i++)
307 if(thread->new_channels->get(i) == channel) break;
309 if(i < thread->new_channels->size())
311 channel_list.values[i]->set_text(channel->title);
318 void ChannelEditWindow::edit_channel()
320 if(list_box->get_selection_number(0, 0) > -1)
322 thread->current_channel = list_box->get_selection_number(0, 0);
323 edit_thread->edit_channel(
324 thread->new_channels->get(
325 list_box->get_selection_number(0, 0)),
330 void ChannelEditWindow::edit_picture()
332 picture_thread->edit_picture();
335 void ChannelEditWindow::scan_confirm()
337 channel_picker->load_scan_defaults(&thread->scan_params);
338 if(!scan_confirm_thread) scan_confirm_thread = new ConfirmScanThread(this);
340 scan_confirm_thread->start();
341 lock_window("ChannelEditWindow::scan_confirm");
344 void ChannelEditWindow::scan()
346 thread->new_channels->clear();
349 if( !thread->scan_thread )
350 thread->scan_thread = new ScanThread(thread);
351 thread->scan_thread->start();
355 void ChannelEditWindow::get_chan_num(Channel *channel, int &chan, int &stream)
357 const char *cp = channel->title;
358 int chn = 0, str = 0;
359 while( isdigit(*cp) ) chn = 10*chn + (*cp++ -'0');
360 if( chn != 0 && *cp != 0 ) {
362 while( isdigit(*cp) ) str = 10*str + (*cp++ -'0');
365 chan = chn; stream = str;
368 void ChannelEditWindow::sort()
373 for(int i = 0; i < thread->new_channels->size() - 1; i++) {
374 Channel *channel1 = thread->new_channels->get(i);
375 Channel *channel2 = thread->new_channels->get(i + 1);
376 int ch1, st1; get_chan_num(channel1, ch1, st1);
377 int ch2, st2; get_chan_num(channel2, ch2, st2);
378 if( (ch1 > 0 && ch2 > 0) ?
379 (ch1 > ch2 || (ch1 == ch2 && (st1 > st2 || (st1 == st2 &&
380 strcasecmp(channel2->title, channel1->title) < 0)))) :
381 strcasecmp(channel2->title, channel1->title) < 0) {
382 thread->new_channels->set(i, channel2);
383 thread->new_channels->set(i + 1, channel1);
392 void ChannelEditWindow::delete_channel(int number)
394 delete thread->new_channels->get(number);
395 channel_list.remove_number(number);
396 thread->new_channels->remove_number(number);
400 void ChannelEditWindow::delete_channel(Channel *channel)
403 for(i = 0; i < thread->new_channels->size(); i++)
405 if(thread->new_channels->get(i) == channel)
410 if(i < thread->new_channels->size()) delete_channel(i);
413 int ChannelEditWindow::move_channel_up()
415 if(list_box->get_selection_number(0, 0) > -1)
417 int number2 = list_box->get_selection_number(0, 0);
418 int number1 = number2 - 1;
420 BC_ListBoxItem *temp_text;
422 if(number1 < 0) number1 = thread->new_channels->size() - 1;
424 temp = thread->new_channels->get(number1);
425 thread->new_channels->set(number1, thread->new_channels->get(number2));
426 thread->new_channels->set(number2, temp);
428 temp_text = channel_list.values[number1];
429 channel_list.values[number1] = channel_list.values[number2];
430 channel_list.values[number2] = temp_text;
431 list_box->update(&channel_list,
435 list_box->get_xposition(),
436 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,
464 list_box->get_xposition(),
465 list_box->get_yposition(),
472 int ChannelEditWindow::change_channel_from_list(int channel_number)
474 if(channel_number > -1 && channel_number < thread->new_channels->size())
476 thread->current_channel = channel_number;
477 channel_picker->set_channel(thread->new_channels->get(channel_number));
482 ChannelEditSelect::ChannelEditSelect(ChannelEditWindow *window, int x, int y)
483 : BC_GenericButton(x, y, _("Select"))
485 this->window = window;
487 ChannelEditSelect::~ChannelEditSelect()
490 int ChannelEditSelect::handle_event()
492 window->change_channel_from_list(
493 window->list_box->get_selection_number(0, 0));
497 ChannelEditAdd::ChannelEditAdd(ChannelEditWindow *window, int x, int y)
498 : BC_GenericButton(x, y, _("Add..."))
500 this->window = window;
502 ChannelEditAdd::~ChannelEditAdd()
505 int ChannelEditAdd::handle_event()
507 window->add_channel();
511 ChannelEditList::ChannelEditList(ChannelEditWindow *window, int x, int y)
515 window->get_h() - BC_OKButton::calculate_h() - y - 10,
517 &(window->channel_list))
519 this->window = window;
521 ChannelEditList::~ChannelEditList()
524 int ChannelEditList::handle_event()
526 window->edit_channel();
530 ChannelEditMoveUp::ChannelEditMoveUp(ChannelEditWindow *window, int x, int y)
531 : BC_GenericButton(x, y, _("Move up"))
533 this->window = window;
535 ChannelEditMoveUp::~ChannelEditMoveUp()
538 int ChannelEditMoveUp::handle_event()
540 lock_window("ChannelEditMoveUp::handle_event");
541 window->move_channel_up();
546 ChannelEditMoveDown::ChannelEditMoveDown(ChannelEditWindow *window, int x, int y)
547 : BC_GenericButton(x, y, _("Move down"))
549 this->window = window;
551 ChannelEditMoveDown::~ChannelEditMoveDown()
554 int ChannelEditMoveDown::handle_event()
556 lock_window("ChannelEditMoveDown::handle_event");
557 window->move_channel_down();
562 ChannelEditSort::ChannelEditSort(ChannelEditWindow *window, int x, int y)
563 : BC_GenericButton(x, y, _("Sort"))
565 this->window = window;
567 int ChannelEditSort::handle_event()
569 lock_window("ChannelEditSort::handle_event");
575 ChannelEditScan::ChannelEditScan(ChannelEditWindow *window, int x, int y)
576 : BC_GenericButton(x, y, _("Scan"))
578 this->window = window;
580 int ChannelEditScan::handle_event()
582 window->scan_confirm();
586 ChannelEditDel::ChannelEditDel(ChannelEditWindow *window, int x, int y)
587 : BC_GenericButton(x, y, _("Delete"))
589 this->window = window;
591 ChannelEditDel::~ChannelEditDel()
594 int ChannelEditDel::handle_event()
596 if(window->list_box->get_selection_number(0, 0) > -1)
597 window->delete_channel(window->list_box->get_selection_number(0, 0));
601 ChannelEdit::ChannelEdit(ChannelEditWindow *window, int x, int y)
602 : BC_GenericButton(x, y, _("Edit..."))
604 this->window = window;
606 ChannelEdit::~ChannelEdit()
609 int ChannelEdit::handle_event()
611 window->edit_channel();
615 ChannelEditPicture::ChannelEditPicture(ChannelEditWindow *window, int x, int y)
616 : BC_GenericButton(x, y, _("Picture..."))
618 this->window = window;
620 ChannelEditPicture::~ChannelEditPicture()
623 int ChannelEditPicture::handle_event()
625 window->edit_picture();
640 // ========================= confirm overwrite by channel scannin
643 ConfirmScan::ConfirmScan(ChannelEditWindow *gui, int x, int y)
644 : BC_Window(_(PROGRAM_NAME ": Scan confirm"),
648 BC_OKButton::calculate_h() + 130,
658 void ConfirmScan::create_objects()
663 add_subwindow(title = new BC_Title(x, y, _("Set parameters for channel scanning.")));
664 y += title->get_h() + 10;
667 add_subwindow(title = new BC_Title(x, y, _("Frequency table:")));
669 y += BC_PopupMenu::calculate_h();
670 add_subwindow(title = new BC_Title(x, y, _("Norm:")));
671 x2 = MAX(x2, title->get_w());
672 y += BC_PopupMenu::calculate_h();
673 add_subwindow(title = new BC_Title(x, y, _("Input:")));
674 x2 = MAX(x2, title->get_w());
675 y += BC_PopupMenu::calculate_h();
680 ChannelEditEditFreqtable *table;
681 add_subwindow(table = new ChannelEditEditFreqtable(x,
686 y += table->get_h() + 10;
688 ChannelEditEditNorm *norm;
689 add_subwindow(norm = new ChannelEditEditNorm(x,
694 y += norm->get_h() + 10;
696 ChannelEditEditInput *input;
697 add_subwindow(input = new ChannelEditEditInput(x,
704 add_subwindow(new BC_OKButton(this));
705 add_subwindow(new BC_CancelButton(this));
715 ConfirmScanThread::ConfirmScanThread(ChannelEditWindow *gui)
721 void ConfirmScanThread::handle_done_event(int result)
723 gui->channel_picker->save_scan_defaults(&gui->thread->scan_params);
726 get_gui()->hide_window();
727 gui->lock_window("ConfirmScanThread::handle_done_event");
729 gui->unlock_window();
733 ConfirmScanThread::~ConfirmScanThread()
738 BC_Window* ConfirmScanThread::new_gui()
740 int x = gui->get_abs_cursor_x(1);
741 int y = gui->get_abs_cursor_y(1);
742 ConfirmScan *result = new ConfirmScan(gui, x, y);
743 result->create_objects();
752 ScanThread::ScanThread(ChannelEditThread *edit)
760 ScanThread::~ScanThread()
765 void ScanThread::stop()
767 // 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();
831 edit->window->set_done(interrupt || progress->is_cancelled() ? 1 : 0);
840 // ================================= Edit a single channel
844 ChannelEditEditThread::ChannelEditEditThread(ChannelEditWindow *window,
845 ChannelPicker *channel_picker)
848 this->window = window;
849 this->channel_picker = channel_picker;
853 completion = new Condition(1, "ChannelEditEditThread::completion");
856 ChannelEditEditThread::~ChannelEditEditThread()
862 void ChannelEditEditThread::close_threads()
866 edit_window->set_done(1);
867 completion->lock("ChannelEditEditThread::close_threads");
868 completion->unlock();
872 int ChannelEditEditThread::edit_channel(Channel *channel, int editing)
876 edit_window->lock_window("ChannelEditEditThread::edit_channel");
877 edit_window->raise_window(1);
878 edit_window->unlock_window();
883 // Copy the channel to edit into a temporary
884 completion->lock("ChannelEditEditThread::edit_channel");
885 this->editing = editing;
886 this->output_channel = channel;
887 new_channel.copy_settings(output_channel);
888 new_channel.copy_usage(output_channel);
890 if(editing && new_channel.title[0])
900 void ChannelEditEditThread::set_device()
902 channel_picker->set_channel(&new_channel);
905 void ChannelEditEditThread::change_source(const char *source_name)
907 for(int i = 0; i < chanlists[new_channel.freqtable].count; i++)
909 if(!strcasecmp(chanlists[new_channel.freqtable].list[i].name, source_name))
911 new_channel.entry = i;
912 i = chanlists[new_channel.freqtable].count;
918 strcpy(new_channel.title, source_name);
919 if(edit_window->title_text)
921 edit_window->title_text->update(source_name);
926 void ChannelEditEditThread::source_up()
929 if(new_channel.entry > chanlists[new_channel.freqtable].count - 1) new_channel.entry = 0;
930 source_text->update(chanlists[new_channel.freqtable].list[new_channel.entry].name);
934 void ChannelEditEditThread::source_down()
937 if(new_channel.entry < 0) new_channel.entry = chanlists[new_channel.freqtable].count - 1;
938 source_text->update(chanlists[new_channel.freqtable].list[new_channel.entry].name);
942 void ChannelEditEditThread::set_input(int value)
944 new_channel.input = value;
948 void ChannelEditEditThread::set_norm(int value)
950 new_channel.norm = value;
954 void ChannelEditEditThread::set_freqtable(int value)
956 new_channel.freqtable = value;
957 if(new_channel.entry > chanlists[new_channel.freqtable].count - 1) new_channel.entry = 0;
958 source_text->update(chanlists[new_channel.freqtable].list[new_channel.entry].name);
962 void ChannelEditEditThread::run()
964 ChannelEditEditWindow edit_window(this, window, channel_picker);
965 edit_window.create_objects(&new_channel);
966 this->edit_window = &edit_window;
967 int result = edit_window.run_window();
968 this->edit_window = 0;
970 // Done editing channel. Keep channel.
973 output_channel->copy_settings(&new_channel);
974 window->lock_window();
975 window->update_list(output_channel);
976 window->unlock_window();
983 window->lock_window();
984 window->delete_channel(output_channel);
985 window->unlock_window();
989 completion->unlock();
993 ChannelEditEditWindow::ChannelEditEditWindow(ChannelEditEditThread *thread,
994 ChannelEditWindow *window,
995 ChannelPicker *channel_picker)
996 : BC_Window(_(PROGRAM_NAME ": Edit Channel"),
997 channel_picker->parent_window->get_abs_cursor_x(1),
998 channel_picker->parent_window->get_abs_cursor_y(1),
1007 this->channel_picker = channel_picker;
1008 this->window = window;
1009 this->thread = thread;
1011 ChannelEditEditWindow::~ChannelEditEditWindow()
1014 void ChannelEditEditWindow::create_objects(Channel *channel)
1016 this->new_channel = channel;
1017 Channel *channel_usage = channel_picker->get_channel_usage();
1021 // if(!channel_usage ||
1022 // (!channel_usage->use_frequency &&
1023 // !channel_usage->use_fine &&
1024 // !channel_usage->use_norm &&
1025 // !channel_usage->use_input))
1027 // add_subwindow(new BC_Title(x, y, MSG_NO_INP_SELECTION));
1032 add_subwindow(new BC_Title(x, y, _("Title:")));
1033 add_subwindow(title_text = new ChannelEditEditTitle(x, y + 20, thread));
1037 if(channel_usage && channel_usage->use_frequency)
1039 add_subwindow(new BC_Title(x, y, _("Channel:")));
1041 add_subwindow(thread->source_text = new ChannelEditEditSource(x, y, thread));
1042 add_subwindow(new ChannelEditEditSourceTumbler(x + 160, y, thread));
1045 add_subwindow(new BC_Title(x, y, _("Frequency table:")));
1046 ChannelEditEditFreqtable *table;
1047 add_subwindow(table = new ChannelEditEditFreqtable(x + 130,
1055 if(channel_usage && channel_usage->use_fine)
1057 add_subwindow(new BC_Title(x, y, _("Fine:")));
1058 add_subwindow(new ChannelEditEditFine(x + 130, y, thread));
1062 if(channel_usage && channel_usage->use_norm)
1064 add_subwindow(new BC_Title(x, y, _("Norm:")));
1065 ChannelEditEditNorm *norm;
1066 add_subwindow(norm = new ChannelEditEditNorm(x + 130,
1074 if( (channel_usage && channel_usage->use_input) ||
1077 add_subwindow(new BC_Title(x, y, _("Input:")));
1078 ChannelEditEditInput *input;
1079 add_subwindow(input = new ChannelEditEditInput(x + 130,
1087 add_subwindow(new BC_OKButton(this));
1089 add_subwindow(new BC_CancelButton(this));
1093 ChannelEditEditTitle::ChannelEditEditTitle(int x,
1095 ChannelEditEditThread *thread)
1096 : BC_TextBox(x, y, 150, 1, thread->new_channel.title)
1098 this->thread = thread;
1100 ChannelEditEditTitle::~ChannelEditEditTitle()
1103 int ChannelEditEditTitle::handle_event()
1105 if(strlen(get_text()) < 1024)
1107 strcpy(thread->new_channel.title, get_text());
1109 thread->user_title = get_text()[0] ? 1 : 0;
1114 ChannelEditEditSource::ChannelEditEditSource(int x, int y, ChannelEditEditThread *thread)
1115 : BC_TextBox(x, y, 150, 1, chanlists[thread->new_channel.freqtable].list[thread->new_channel.entry].name)
1117 this->thread = thread;
1120 ChannelEditEditSource::~ChannelEditEditSource()
1123 int ChannelEditEditSource::handle_event()
1125 thread->change_source(get_text());
1130 ChannelEditEditSourceTumbler::ChannelEditEditSourceTumbler(int x, int y, ChannelEditEditThread *thread)
1133 this->thread = thread;
1135 ChannelEditEditSourceTumbler::~ChannelEditEditSourceTumbler()
1138 int ChannelEditEditSourceTumbler::handle_up_event()
1140 thread->source_up();
1143 int ChannelEditEditSourceTumbler::handle_down_event()
1145 thread->source_down();
1149 ChannelEditEditInput::ChannelEditEditInput(int x,
1151 ChannelEditEditThread *thread,
1152 ChannelEditThread *edit)
1156 edit->value_to_input(thread ? thread->new_channel.input : edit->scan_params.input))
1158 this->thread = thread;
1161 ChannelEditEditInput::~ChannelEditEditInput()
1164 void ChannelEditEditInput::add_items()
1166 ArrayList<Channel*> *inputs;
1167 inputs = edit->channel_picker->get_video_inputs();
1171 for(int i = 0; i < inputs->total; i++)
1173 add_item(new ChannelEditEditInputItem(thread,
1175 inputs->values[i]->device_name,
1180 int ChannelEditEditInput::handle_event()
1185 ChannelEditEditInputItem::ChannelEditEditInputItem(ChannelEditEditThread *thread,
1186 ChannelEditThread *edit,
1191 this->thread = thread;
1193 this->value = value;
1195 ChannelEditEditInputItem::~ChannelEditEditInputItem()
1198 int ChannelEditEditInputItem::handle_event()
1200 get_popup_menu()->set_text(get_text());
1201 if(thread && !thread->user_title)
1203 strcpy(thread->new_channel.title, get_text());
1204 if(thread->edit_window->title_text)
1206 thread->edit_window->title_text->update(get_text());
1210 thread->set_input(value);
1212 edit->scan_params.input = value;
1216 ChannelEditEditNorm::ChannelEditEditNorm(int x,
1218 ChannelEditEditThread *thread,
1219 ChannelEditThread *edit)
1223 edit->value_to_norm(thread ? thread->new_channel.norm : edit->scan_params.norm))
1225 this->thread = thread;
1228 ChannelEditEditNorm::~ChannelEditEditNorm()
1231 void ChannelEditEditNorm::add_items()
1233 add_item(new ChannelEditEditNormItem(thread,
1235 edit->value_to_norm(NTSC), NTSC));
1236 add_item(new ChannelEditEditNormItem(thread,
1238 edit->value_to_norm(PAL), PAL));
1239 add_item(new ChannelEditEditNormItem(thread,
1241 edit->value_to_norm(SECAM), SECAM));
1245 ChannelEditEditNormItem::ChannelEditEditNormItem(ChannelEditEditThread *thread,
1246 ChannelEditThread *edit,
1251 this->value = value;
1253 this->thread = thread;
1255 ChannelEditEditNormItem::~ChannelEditEditNormItem()
1258 int ChannelEditEditNormItem::handle_event()
1260 get_popup_menu()->set_text(get_text());
1262 thread->set_norm(value);
1264 edit->scan_params.norm = value;
1269 ChannelEditEditFreqtable::ChannelEditEditFreqtable(int x,
1271 ChannelEditEditThread *thread,
1272 ChannelEditThread *edit)
1276 edit->value_to_freqtable(thread ? thread->new_channel.freqtable : edit->scan_params.freqtable))
1278 this->thread = thread;
1281 ChannelEditEditFreqtable::~ChannelEditEditFreqtable()
1284 void ChannelEditEditFreqtable::add_items()
1286 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_DVB), NTSC_DVB));
1287 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(CATV_DVB), CATV_DVB));
1288 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_BCAST), NTSC_BCAST));
1289 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_CABLE), NTSC_CABLE));
1290 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_HRC), NTSC_HRC));
1291 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_BCAST_JP), NTSC_BCAST_JP));
1292 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(NTSC_CABLE_JP), NTSC_CABLE_JP));
1293 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_AUSTRALIA), PAL_AUSTRALIA));
1294 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_EUROPE), PAL_EUROPE));
1295 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_E_EUROPE), PAL_E_EUROPE));
1296 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_ITALY), PAL_ITALY));
1297 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_IRELAND), PAL_IRELAND));
1298 add_item(new ChannelEditEditFreqItem(thread, edit, edit->value_to_freqtable(PAL_NEWZEALAND), PAL_NEWZEALAND));
1301 ChannelEditEditFreqItem::ChannelEditEditFreqItem(ChannelEditEditThread *thread,
1302 ChannelEditThread *edit,
1303 char *text, int value)
1306 this->value = value;
1308 this->thread = thread;
1310 ChannelEditEditFreqItem::~ChannelEditEditFreqItem()
1313 int ChannelEditEditFreqItem::handle_event()
1315 get_popup_menu()->set_text(get_text());
1317 thread->set_freqtable(value);
1319 edit->scan_params.freqtable = value;
1325 ChannelEditEditFine::ChannelEditEditFine(int x,
1327 ChannelEditEditThread *thread)
1335 thread->new_channel.fine_tune)
1337 this->thread = thread;
1339 ChannelEditEditFine::~ChannelEditEditFine()
1342 int ChannelEditEditFine::handle_event()
1346 int ChannelEditEditFine::button_release_event()
1348 if(BC_Slider::button_release_event())
1350 thread->new_channel.fine_tune = get_value();
1351 thread->set_device();
1358 // ========================== picture quality
1360 ChannelEditPictureThread::ChannelEditPictureThread(
1361 ChannelPicker *channel_picker)
1364 this->channel_picker = channel_picker;
1366 ChannelEditPictureThread::~ChannelEditPictureThread()
1370 void ChannelEditPictureThread::handle_done_event(int result)
1372 if(channel_picker->get_picture_usage())
1373 channel_picker->get_picture_usage()->save_defaults();
1376 BC_Window* ChannelEditPictureThread::new_gui()
1378 ChannelEditPictureWindow *edit_window = new ChannelEditPictureWindow(this,
1380 edit_window->create_objects();
1384 void ChannelEditPictureThread::edit_picture()
1390 ChannelEditPictureWindow::ChannelEditPictureWindow(ChannelEditPictureThread *thread,
1391 ChannelPicker *channel_picker)
1392 : BC_Window(_(PROGRAM_NAME ": Picture"),
1393 channel_picker->mwindow->session->picture_x,
1394 channel_picker->mwindow->session->picture_y,
1395 calculate_w(channel_picker),
1396 calculate_h(channel_picker),
1397 calculate_w(channel_picker),
1398 calculate_h(channel_picker))
1400 this->thread = thread;
1401 this->channel_picker = channel_picker;
1403 ChannelEditPictureWindow::~ChannelEditPictureWindow()
1407 int ChannelEditPictureWindow::calculate_h(ChannelPicker *channel_picker)
1409 PictureConfig *picture_usage = channel_picker->get_picture_usage();
1410 int pad = BC_Pot::calculate_h();
1411 int text_h = channel_picker->parent_window->get_text_height(MEDIUMFONT);
1412 int result = 20 + text_h + 5 + BC_OKButton::calculate_h();
1414 // Only used for Video4Linux 1
1415 if( !picture_usage || (
1416 !picture_usage->use_brightness &&
1417 !picture_usage->use_contrast &&
1418 !picture_usage->use_color &&
1419 !picture_usage->use_hue &&
1420 !picture_usage->use_whiteness &&
1421 !channel_picker->get_controls() ) ) {
1422 result += BC_Title::calculate_h(channel_picker->parent_window,
1423 MSG_NO_PIC_CONTROLS);
1427 if(picture_usage->use_brightness)
1429 if(picture_usage->use_contrast)
1431 if(picture_usage->use_color)
1433 if(picture_usage->use_hue)
1435 if(picture_usage->use_whiteness)
1439 result += channel_picker->get_controls() * pad;
1443 int ChannelEditPictureWindow::calculate_w(ChannelPicker *channel_picker)
1445 PictureConfig *picture_usage = channel_picker->get_picture_usage();
1446 int widget_border = ((Theme*)channel_picker->get_theme())->widget_border;
1447 int pad = BC_Pot::calculate_w() + 4 * widget_border;
1450 // Only used for Video4Linux 1
1451 if(!picture_usage ||
1452 (!picture_usage->use_brightness &&
1453 !picture_usage->use_contrast &&
1454 !picture_usage->use_color &&
1455 !picture_usage->use_hue &&
1456 !picture_usage->use_whiteness &&
1457 !channel_picker->get_controls()))
1459 result = BC_Title::calculate_w(channel_picker->parent_window,
1460 MSG_NO_PIC_CONTROLS) + 20;
1463 // Only used for Video4Linux 1
1466 if(picture_usage->use_brightness)
1468 int new_w = BC_Title::calculate_w(channel_picker->parent_window, _("Brightness:")) + pad;
1469 result = MAX(result, new_w);
1471 if(picture_usage->use_contrast)
1473 int new_w = BC_Title::calculate_w(channel_picker->parent_window, _("Contrast:")) + pad;
1474 result = MAX(result, new_w);
1476 if(picture_usage->use_color)
1478 int new_w = BC_Title::calculate_w(channel_picker->parent_window, _("Color:")) + pad;
1479 result = MAX(result, new_w);
1481 if(picture_usage->use_hue)
1483 int new_w = BC_Title::calculate_w(channel_picker->parent_window, _("Hue:")) + pad;
1484 result = MAX(result, new_w);
1486 if(picture_usage->use_whiteness)
1488 int new_w = BC_Title::calculate_w(channel_picker->parent_window, _("Whiteness:")) + pad;
1489 result = MAX(result, new_w);
1493 for(int i = 0; i < channel_picker->get_controls(); i++)
1495 int new_w = BC_Title::calculate_w(channel_picker->parent_window,
1496 channel_picker->get_control(i)->name) +
1498 result = MAX(result, new_w);
1505 void ChannelEditPictureWindow::create_objects()
1508 int widget_border = ((Theme*)channel_picker->get_theme())->widget_border;
1509 int x1 = get_w() - BC_Pot::calculate_w() * 2 - widget_border * 2;
1510 int x2 = get_w() - BC_Pot::calculate_w() - widget_border;
1511 int pad = BC_Pot::calculate_h();
1513 #define SWAP_X x1 ^= x2; x2 ^= x1; x1 ^= x2;
1515 PictureConfig *picture_usage = channel_picker->get_picture_usage();
1517 // Only used for Video4Linux 1
1518 if(!picture_usage ||
1519 (!picture_usage->use_brightness &&
1520 !picture_usage->use_contrast &&
1521 !picture_usage->use_color &&
1522 !picture_usage->use_hue &&
1523 !picture_usage->use_whiteness &&
1524 !channel_picker->get_controls()))
1526 add_subwindow(new BC_Title(x, y, MSG_NO_PIC_CONTROLS));
1530 // Only used for Video4Linux 1
1531 if(picture_usage && picture_usage->use_brightness)
1533 add_subwindow(new BC_Title(x, y + 10, _("Brightness:")));
1534 add_subwindow(new ChannelEditBright(x1, y, channel_picker, channel_picker->get_brightness()));
1540 if(picture_usage && picture_usage->use_contrast)
1542 add_subwindow(new BC_Title(x, y + 10, _("Contrast:")));
1543 add_subwindow(new ChannelEditContrast(x1, y, channel_picker, channel_picker->get_contrast()));
1548 if(picture_usage && picture_usage->use_color)
1550 add_subwindow(new BC_Title(x, y + 10, _("Color:")));
1551 add_subwindow(new ChannelEditColor(x1, y, channel_picker, channel_picker->get_color()));
1556 if(picture_usage && picture_usage->use_hue)
1558 add_subwindow(new BC_Title(x, y + 10, _("Hue:")));
1559 add_subwindow(new ChannelEditHue(x1, y, channel_picker, channel_picker->get_hue()));
1564 if(picture_usage && picture_usage->use_whiteness)
1566 add_subwindow(new BC_Title(x, y + 10, _("Whiteness:")));
1567 add_subwindow(new ChannelEditWhiteness(x1, y, channel_picker, channel_picker->get_whiteness()));
1572 for(int i = 0; i < channel_picker->get_controls(); i++)
1575 add_subwindow(title = new BC_Title(x,
1577 _(channel_picker->get_control(i)->name)));
1580 if(x3 < title->get_x() + title->get_w() + widget_border)
1581 x3 = title->get_x() + title->get_w() + widget_border;
1583 add_subwindow(new ChannelEditCommon(x3,
1586 channel_picker->get_control(i)));
1593 add_subwindow(new BC_OKButton(this));
1597 int ChannelEditPictureWindow::translation_event()
1599 channel_picker->mwindow->session->picture_x = get_x();
1600 channel_picker->mwindow->session->picture_y = get_y();
1606 ChannelEditBright::ChannelEditBright(int x, int y, ChannelPicker *channel_picker, int value)
1613 this->channel_picker = channel_picker;
1615 ChannelEditBright::~ChannelEditBright() {}
1616 int ChannelEditBright::handle_event()
1620 int ChannelEditBright::button_release_event()
1622 if(BC_Pot::button_release_event())
1624 channel_picker->set_brightness(get_value());
1630 ChannelEditContrast::ChannelEditContrast(int x, int y, ChannelPicker *channel_picker, int value)
1637 this->channel_picker = channel_picker;
1639 ChannelEditContrast::~ChannelEditContrast() {}
1640 int ChannelEditContrast::handle_event()
1644 int ChannelEditContrast::button_release_event()
1646 if(BC_Pot::button_release_event())
1648 channel_picker->set_contrast(get_value());
1655 ChannelEditColor::ChannelEditColor(int x, int y, ChannelPicker *channel_picker, int value)
1662 this->channel_picker = channel_picker;
1664 ChannelEditColor::~ChannelEditColor() {}
1665 int ChannelEditColor::handle_event()
1669 int ChannelEditColor::button_release_event()
1671 if(BC_Pot::button_release_event())
1673 channel_picker->set_color(get_value());
1679 ChannelEditHue::ChannelEditHue(int x, int y, ChannelPicker *channel_picker, int value)
1686 this->channel_picker = channel_picker;
1688 ChannelEditHue::~ChannelEditHue() {}
1689 int ChannelEditHue::handle_event()
1693 int ChannelEditHue::button_release_event()
1695 if(BC_Pot::button_release_event())
1697 channel_picker->set_hue(get_value());
1703 ChannelEditWhiteness::ChannelEditWhiteness(int x, int y, ChannelPicker *channel_picker, int value)
1710 this->channel_picker = channel_picker;
1712 ChannelEditWhiteness::~ChannelEditWhiteness()
1715 int ChannelEditWhiteness::handle_event()
1719 int ChannelEditWhiteness::button_release_event()
1721 if(BC_Pot::button_release_event())
1723 channel_picker->set_whiteness(get_value());
1731 ChannelEditCommon::ChannelEditCommon(int x,
1733 ChannelPicker *channel_picker,
1741 this->channel_picker = channel_picker;
1742 this->device_id = item->device_id;
1745 ChannelEditCommon::~ChannelEditCommon()
1749 int ChannelEditCommon::handle_event()
1754 int ChannelEditCommon::button_release_event()
1756 if(BC_Pot::button_release_event())
1758 channel_picker->set_picture(device_id, get_value());
1764 int ChannelEditCommon::keypress_event()
1766 if(BC_Pot::keypress_event())
1768 channel_picker->set_picture(device_id, get_value());