4 * Copyright (C) 2008 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
27 // Channel table entry for the TV tuner
34 Channel::Channel(Channel *channel)
36 copy_settings(channel);
74 printf("Channel::dump title=%s\n"
92 Channel& Channel::operator=(Channel &channel)
94 printf("Channel::operator= is not supported.\n");
98 bool Channel::operator==(Channel &channel)
100 if( this == &channel ) return true;
101 return this->entry != channel.entry ||
102 this->element != channel.element ||
103 this->freqtable != channel.freqtable ||
104 this->fine_tune != channel.fine_tune ||
105 this->input != channel.input ||
106 this->norm != channel.norm ||
107 this->device_index != channel.device_index ||
108 this->tuner != channel.tuner ||
109 this->audio_stream != channel.audio_stream ||
110 this->video_stream != channel.video_stream ||
111 this->audio_pid != channel.audio_pid ||
112 this->video_pid != channel.video_pid ? false : true;
115 bool Channel::operator!=(Channel &channel)
117 return *this == channel ? false : true;
120 void Channel::copy_settings(Channel *channel)
122 strcpy(this->title, channel->title);
123 this->entry = channel->entry;
124 this->element = channel->element;
125 this->freqtable = channel->freqtable;
126 this->fine_tune = channel->fine_tune;
127 this->input = channel->input;
128 this->norm = channel->norm;
129 this->device_index = channel->device_index;
130 this->tuner = channel->tuner;
131 this->audio_stream = channel->audio_stream;
132 this->video_stream = channel->video_stream;
133 this->audio_pid = channel->audio_pid;
134 this->video_pid = channel->video_pid;
137 void Channel::copy_usage(Channel *channel)
139 this->use_frequency = channel->use_frequency;
140 this->use_fine = channel->use_fine;
141 this->use_norm = channel->use_norm;
142 this->use_input = channel->use_input;
143 this->has_scanning = channel->has_scanning;
144 this->has_subchan = channel->has_subchan;
147 int Channel::load(FileXML *file)
155 done = file->read_tag();
158 if(file->tag.title_is("CHANNEL"))
160 entry = file->tag.get_property("ENTRY", entry);
161 element = file->tag.get_property("ELEMENT", element);
162 freqtable = file->tag.get_property("FREQTABLE", freqtable);
163 fine_tune = file->tag.get_property("FINE_TUNE", fine_tune);
164 input = file->tag.get_property("INPUT", input);
165 norm = file->tag.get_property("NORM", norm);
166 device_index = file->tag.get_property("DEVICE_INDEX", device_index);
167 tuner = file->tag.get_property("TUNER", tuner);
168 audio_stream = file->tag.get_property("AUDIO_STREAM", audio_pid);
169 video_stream = file->tag.get_property("VIDEO_STREAM", video_pid);
170 audio_pid = file->tag.get_property("AUDIO_PID", audio_pid);
171 video_pid = file->tag.get_property("VIDEO_PID", video_pid);
172 text = file->read_text();
176 if(file->tag.title_is("/CHANNEL"))
183 void Channel::save(FileXML *file)
185 file->tag.set_title("CHANNEL");
186 file->tag.set_property("ENTRY", entry);
187 file->tag.set_property("ELEMENT", element);
188 file->tag.set_property("FREQTABLE", freqtable);
189 file->tag.set_property("FINE_TUNE", fine_tune);
190 file->tag.set_property("INPUT", input);
191 file->tag.set_property("NORM", norm);
192 file->tag.set_property("DEVICE_INDEX", device_index);
193 file->tag.set_property("TUNER", tuner);
194 file->tag.set_property("AUDIO_STREAM", audio_stream);
195 file->tag.set_property("VIDEO_STREAM", video_stream);
196 file->tag.set_property("AUDIO_PID", audio_pid);
197 file->tag.set_property("VIDEO_PID", video_pid);
199 file->append_text(title);
200 file->tag.set_title("/CHANNEL");
202 file->append_newline();
207 void Channel::load_defaults(BC_Hash *defaults)
209 freqtable = defaults->get("SCAN_FREQTABLE", freqtable);
210 input = defaults->get("SCAN_INPUT", input);
211 norm = defaults->get("SCAN_NORM", norm);
214 void Channel::save_defaults(BC_Hash *defaults)
216 defaults->update("SCAN_FREQTABLE", freqtable);
217 defaults->update("SCAN_INPUT", input);
218 defaults->update("SCAN_NORM", norm);
221 static inline bool is_numeric(char c) { return (c>='0' && c<='9'); }
222 static inline bool is_separator(char c) { return (c=='.' || c=='-'); }
224 static inline void get_chan(const char *p, int &ch, int &sub)
226 while( *p == ' ' ) ++p;
227 for( ch=0,sub=1; is_numeric(*p); ++p ) ch = ch*10 + *p-'0';
228 if( !*p || !is_separator(*p) || !is_numeric(*++p) ) return;
229 for( sub=*p-'0'; is_numeric(*++p); ) sub = sub*10 + *p-'0';
232 int Channel::cstrcmp(const char *name)
234 if( !strcmp(name, title) ) return 0;
235 int ch1, sub1; get_chan(name, ch1, sub1);
236 int ch2, sub2; get_chan(title, ch2, sub2);
238 if( !ret ) ret = sub1 - sub2;