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"
25 #include "filesystem.h"
27 #include "preferences.inc"
32 ChannelDB::ChannelDB()
36 ChannelDB::~ChannelDB()
38 channels.remove_all_objects();
41 char* ChannelDB::prefix_to_path(char *path, const char *filename)
44 char directory[BCTEXTLEN];
45 sprintf(directory, "%s/", File::get_config_path());
46 fs.complete_path(directory);
47 fs.join_names(path, directory, filename);
51 void ChannelDB::load(const char *filename)
53 if( !filename ) return;
58 prefix_to_path(path, filename);
59 channels.remove_all_objects();
61 int done = file.read_from_file(path, 1);
63 channels.remove_all_objects();
67 Channel *channel = new Channel;
68 if(!(done = channel->load(&file)))
69 channels.append(channel);
77 void ChannelDB::save(const char *filename)
79 if( !filename ) return;
83 prefix_to_path(path, filename);
87 for(int i = 0; i < channels.total; i++)
90 channels.values[i]->save(&file);
92 file.terminate_string();
93 file.write_to_file(path);
97 Channel* ChannelDB::get(int number)
99 if(number >= 0 && number < channels.total)
100 return channels.values[number];
105 void ChannelDB::copy_from(ChannelDB *src)
108 for(int i = 0; i < src->size(); i++)
110 Channel *dst = new Channel;
111 channels.append(dst);
112 dst->copy_settings(src->get(i));
116 int ChannelDB::number_of(Channel *channel)
118 return channels.number_of(channel);
121 int ChannelDB::size()
123 return channels.total;
126 void ChannelDB::clear()
128 channels.remove_all_objects();
131 void ChannelDB::append(Channel *channel)
133 channels.append(channel);
136 void ChannelDB::remove_number(int number)
138 channels.remove_number(number);
141 void ChannelDB::set(int number, Channel *ptr)
143 channels.values[number] = ptr;