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 "bcsignals.h"
25 #include "channeldb.h"
26 #include "channeledit.h"
27 #include "channelpicker.h"
28 #include "chantables.h"
31 #include "edlsession.h"
36 #include "playbackconfig.h"
37 #include "preferencesthread.h"
39 #include "recordgui.h"
40 #include "recordmonitor.h"
42 #include "vdeviceprefs.h"
43 #include "videodevice.h"
45 RecordChannelPicker::RecordChannelPicker(MWindow *mwindow,
47 RecordMonitor *record_monitor,
48 BC_WindowBase *parent_window,
52 : ChannelPicker(mwindow,
58 this->record = record;
59 this->record_monitor = record_monitor;
62 RecordChannelPicker::~RecordChannelPicker()
66 int RecordChannelPicker::use_select()
71 Channel* RecordChannelPicker::get_master_channel()
73 return record->master_channel;
76 void RecordChannelPicker::handle_channel_edit(int result)
80 record->record_gui->lock_window("RecordChannelPicker::handle_channel_edit 1");
81 record->record_gui->update_batch_sources();
82 record->set_channel(get_master_channel());
83 record->record_gui->unlock_window();
84 record->save_defaults();
85 VideoDevice::save_channeldb(record->channeldb,
86 mwindow->edl->session->vconfig_in);
90 record->record_gui->lock_window("RecordChannelPicker::handle_channel_edit 2");
91 record->set_channel(record->get_current_channel());
92 record->record_gui->unlock_window();
95 mwindow->save_defaults();
98 void RecordChannelPicker::load_scan_defaults(Channel *scan_params)
100 scan_params->load_defaults(mwindow->defaults);
103 void RecordChannelPicker::save_scan_defaults(Channel *scan_params)
105 scan_params->save_defaults(mwindow->defaults);
108 BC_Theme* RecordChannelPicker::get_theme()
110 return mwindow->theme;
114 Channel* RecordChannelPicker::get_current_channel()
116 return record->get_current_channel();
119 Channel *RecordChannelPicker::get_editing_channel()
121 return record->get_editing_channel();
124 ArrayList<Channel*>* RecordChannelPicker::get_video_inputs()
126 return record->get_video_inputs();
129 Channel* RecordChannelPicker::get_channel_usage()
131 return record->master_channel;
134 void RecordChannelPicker::set_channel_number(int number)
136 if( number < 0 || number >= channeldb->size() ) return;
137 Channel *channel = channeldb->get(number);
138 if( channel ) record->set_channel(channel);
141 void RecordChannelPicker::set_brightness(int value)
145 record->picture->brightness = value;
146 record->set_video_picture();
150 void RecordChannelPicker::set_hue(int value)
154 record->picture->hue = value;
155 record->set_video_picture();
159 void RecordChannelPicker::set_color(int value)
163 record->picture->color = value;
164 record->set_video_picture();
168 void RecordChannelPicker::set_contrast(int value)
172 record->picture->contrast = value;
173 record->set_video_picture();
177 void RecordChannelPicker::set_whiteness(int value)
181 record->picture->whiteness = value;
182 record->set_video_picture();
186 int RecordChannelPicker::set_picture(int device_id, int value)
190 if(record->picture->set_item(device_id, value))
191 record->set_video_picture();
197 int RecordChannelPicker::get_brightness()
199 if(record) return record->picture->brightness;
203 int RecordChannelPicker::get_hue()
205 if(record) return record->picture->hue;
209 int RecordChannelPicker::get_color()
211 if(record) return record->picture->color;
215 int RecordChannelPicker::get_contrast()
217 if(record) return record->picture->contrast;
221 int RecordChannelPicker::get_whiteness()
223 if(record) return record->picture->whiteness;
227 int RecordChannelPicker::get_controls()
229 if(record) return record->picture->controls.total;
233 PictureItem* RecordChannelPicker::get_control(int i)
235 if(record) return record->picture->controls.values[i];
239 PictureConfig* RecordChannelPicker::get_picture_usage()
241 if(record) return record->picture;
247 void RecordChannelPicker::set_channel(Channel *channel)
249 record->set_channel(channel);
252 int RecordChannelPicker::has_signal()
254 return record->has_signal();
257 int RecordChannelPicker::create_channeldb(ArrayList<Channel*> *channeldb)
259 return record->create_channeldb(channeldb);
270 PrefsChannelPicker::PrefsChannelPicker(MWindow *mwindow,
272 ChannelDB *channeldb,
275 : ChannelPicker(mwindow,
281 // printf("PrefsChannelPicker::PrefsChannelPicker 1\n");
285 PrefsChannelPicker::~PrefsChannelPicker()
287 input_sources.remove_all_objects();
290 void PrefsChannelPicker::load_scan_defaults(Channel *scan_params)
292 scan_params->load_defaults(mwindow->defaults);
295 void PrefsChannelPicker::save_scan_defaults(Channel *scan_params)
297 scan_params->save_defaults(mwindow->defaults);
300 void PrefsChannelPicker::handle_channel_edit(int result)
302 mwindow->save_defaults();
305 BC_Theme* PrefsChannelPicker::get_theme()
307 return mwindow->theme;
311 ArrayList<Channel*>* PrefsChannelPicker::get_video_inputs()
313 return &input_sources;
316 Channel* PrefsChannelPicker::get_channel_usage()
322 void PrefsChannelPicker::set_channel(Channel *channel)
325 channel_text->update(channel->title);
328 Channel *PrefsChannelPicker::get_current_channel()
330 int number = prefs->out_config->out_channel;
331 return channeldb->get(number);
334 void PrefsChannelPicker::set_channel_number(int number)
336 CLAMP(number, 0, channeldb->size() - 1);
337 prefs->out_config->out_channel = number;
338 set_channel(get_current_channel());
341 int PrefsChannelPicker::has_signal()
346 void PrefsChannelPicker::set_brightness(int value)
348 prefs->out_config->brightness = value;
351 void PrefsChannelPicker::set_hue(int value)
353 prefs->out_config->hue = value;
356 void PrefsChannelPicker::set_color(int value)
358 prefs->out_config->color = value;
361 void PrefsChannelPicker::set_contrast(int value)
363 prefs->out_config->contrast = value;
366 void PrefsChannelPicker::set_whiteness(int value)
368 prefs->out_config->whiteness = value;
371 int PrefsChannelPicker::get_brightness()
373 return prefs->out_config->brightness;
376 int PrefsChannelPicker::get_hue()
378 return prefs->out_config->hue;
381 int PrefsChannelPicker::get_color()
383 return prefs->out_config->color;
386 int PrefsChannelPicker::get_contrast()
388 return prefs->out_config->contrast;
391 int PrefsChannelPicker::get_whiteness()
393 return prefs->out_config->whiteness;
401 ChannelPicker::ChannelPicker(MWindow *mwindow,
402 ChannelDB *channeldb,
405 BC_WindowBase *parent_window)
407 this->mwindow = mwindow;
408 this->parent_window = parent_window;
411 this->channeldb = channeldb;
415 update_channel_list();
418 ChannelPicker::~ChannelPicker()
421 delete channel_select;
422 delete channel_button;
423 channel_listitems.remove_all_objects();
426 void ChannelPicker::update_channel_list()
428 channel_listitems.remove_all_objects();
429 for(int i = 0; i < channeldb->size(); i++)
431 channel_listitems.append(new BC_ListBoxItem(channeldb->get(i)->title));
435 channel_text->update_list(&channel_listitems);
438 int ChannelPicker::get_w()
440 return channel_text->get_w() +
441 channel_select->get_w() +
442 channel_button->get_w() +
443 picture_button->get_w() +
444 ((Theme*)get_theme())->widget_border * 4;
452 BC_WindowBase* ChannelPicker::get_subwindow()
454 return parent_window;
464 void ChannelPicker::create_objects()
467 update_channel_list();
470 channel_text = new ChannelText(this, x, y);
471 channel_text->create_objects();
474 x += channel_text->get_w() + ((Theme*)get_theme())->widget_border;
475 get_subwindow()->add_subwindow(channel_select = new ChannelTumbler(this,
480 x += channel_select->get_w() + ((Theme*)get_theme())->widget_border;
481 get_subwindow()->add_subwindow(channel_button = new ChannelButton(this,
486 x += channel_button->get_w() + ((Theme*)get_theme())->widget_border;
487 get_subwindow()->add_subwindow(picture_button = new PictureButton(this,
494 int ChannelPicker::reposition()
496 channel_text->reposition_window(channel_text->get_x(),
497 channel_text->get_y());
498 channel_select->reposition_window(channel_select->get_x(),
499 channel_select->get_y());
500 channel_button->reposition_window(channel_button->get_x(),
501 channel_button->get_y());
505 void ChannelPicker::close_threads()
507 channel_button->thread->close_threads();
510 const char* ChannelPicker::get_source_name(Channel *channel)
512 if(channel->entry < chanlists[channel->freqtable].count)
513 return chanlists[channel->freqtable].list[channel->entry].name;
515 return chanlists[channel->freqtable].list[0].name;
518 const char* ChannelPicker::current_channel_name()
520 if(get_current_channel())
521 return get_current_channel()->title;
525 int ChannelPicker::channel_down()
527 Channel *channel = get_current_channel();
528 if( !channel ) return 1;
529 int number = channeldb->number_of(channel);
530 if( number < 0 ) return 1;
531 if( --number < 0 ) number = 0;
532 set_channel_number(number);
536 int ChannelPicker::channel_up()
538 Channel *channel = get_current_channel();
539 if( !channel ) return 1;
540 int number = channeldb->number_of(channel);
541 if( number < 0 ) return 1;
542 if( ++number >= channeldb->size() ) number = channeldb->size()-1;
543 set_channel_number(number);
551 PictureButton::PictureButton(ChannelPicker *channel_picker, int x, int y)
554 channel_picker->get_theme() ?
555 channel_picker->get_theme()->get_image_set("picture") :
558 this->channel_picker = channel_picker;
559 thread = new ChannelEditPictureThread(channel_picker);
560 set_tooltip(_("Edit picture"));
563 PictureButton::~PictureButton()
565 //printf("PictureButton::PictureButton %d\n", __LINE__);
567 //printf("PictureButton::PictureButton %d\n", __LINE__);
570 int PictureButton::handle_event()
573 thread->edit_picture();
574 lock_window("PictureButton::handle_event");
581 ChannelButton::ChannelButton(ChannelPicker *channel_picker, int x, int y)
582 : BC_Button(x, y, channel_picker->get_theme() ?
583 channel_picker->get_theme()->get_image_set("channel") :
586 this->channel_picker = channel_picker;
587 thread = new ChannelEditThread(channel_picker,
588 channel_picker->channeldb);
589 set_tooltip(_("Edit channels"));
590 // *** CONTEXT_HELP ***
591 context_help_set_keyword("Initial Setup for DVB Capture");
594 ChannelButton::~ChannelButton()
599 int ChannelButton::handle_event()
606 ChannelText::ChannelText(ChannelPicker *channel_picker, int x, int y)
607 : BC_PopupTextBox(channel_picker->get_subwindow(),
608 &channel_picker->channel_listitems,
609 channel_picker->current_channel_name(),
612 this->channel_picker = channel_picker;
615 ChannelText::~ChannelText()
619 int ChannelText::handle_event()
621 channel_picker->set_channel_number(get_number());
628 ChannelList::ChannelList(ChannelPicker *channel_picker, int x, int y)
629 : BC_ListBox(x, y, 100, 200,
630 LISTBOX_TEXT, // Display text list or icons
631 &channel_picker->channel_listitems, // Each column has an ArrayList of BC_ListBoxItems.
632 0, // Titles for columns. Set to 0 for no titles
633 0, // width of each column
635 0, // Pixel of top of window.
636 1) // If this listbox is a popup window
638 this->channel_picker = channel_picker;
641 ChannelList::~ChannelList()
645 int ChannelList::handle_event()
652 ChannelTumbler::ChannelTumbler(ChannelPicker *channel_picker,
657 this->channel_picker = channel_picker;
658 // *** CONTEXT_HELP ***
659 context_help_set_keyword("Initial Setup for DVB Capture");
661 ChannelTumbler::~ChannelTumbler()
664 int ChannelTumbler::handle_up_event()
666 channel_picker->channel_up();
669 int ChannelTumbler::handle_down_event()
671 channel_picker->channel_down();
674 int ChannelTumbler::keypress_event()
676 if(get_keypress() == PGUP)
682 if(get_keypress() == PGDN)
688 return context_help_check_and_show();