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
23 #include "channeldb.h"
24 #include "filesystem.h"
26 #include "preferences.inc"
31 ChannelDB::ChannelDB()
35 ChannelDB::~ChannelDB()
37 channels.remove_all_objects();
40 char* ChannelDB::prefix_to_path(char *path, const char *filename)
43 char directory[BCTEXTLEN];
44 sprintf(directory, BCASTDIR);
45 fs.complete_path(directory);
46 fs.join_names(path, directory, filename);
50 void ChannelDB::load(const char *filename)
52 if( !filename ) return;
57 prefix_to_path(path, filename);
58 channels.remove_all_objects();
60 int done = file.read_from_file(path, 1);
62 channels.remove_all_objects();
66 Channel *channel = new Channel;
67 if(!(done = channel->load(&file)))
68 channels.append(channel);
76 void ChannelDB::save(const char *filename)
78 if( !filename ) return;
82 prefix_to_path(path, filename);
86 for(int i = 0; i < channels.total; i++)
89 channels.values[i]->save(&file);
91 file.terminate_string();
92 file.write_to_file(path);
96 Channel* ChannelDB::get(int number)
98 if(number >= 0 && number < channels.total)
99 return channels.values[number];
104 void ChannelDB::copy_from(ChannelDB *src)
107 for(int i = 0; i < src->size(); i++)
109 Channel *dst = new Channel;
110 channels.append(dst);
111 dst->copy_settings(src->get(i));
115 int ChannelDB::number_of(Channel *channel)
117 return channels.number_of(channel);
120 int ChannelDB::size()
122 return channels.total;
125 void ChannelDB::clear()
127 channels.remove_all_objects();
130 void ChannelDB::append(Channel *channel)
132 channels.append(channel);
135 void ChannelDB::remove_number(int number)
137 channels.remove_number(number);
140 void ChannelDB::set(int number, Channel *ptr)
142 channels.values[number] = ptr;