Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

channeldb.C

Go to the documentation of this file.
00001 #include "channel.h"
00002 #include "channeldb.h"
00003 #include "filesystem.h"
00004 #include "filexml.h"
00005 #include "preferences.inc"
00006 
00007 
00008 #include <stdio.h>
00009 
00010 ChannelDB::ChannelDB()
00011 {
00012 }
00013 
00014 ChannelDB::~ChannelDB()
00015 {
00016         channels.remove_all_objects();
00017 }
00018 
00019 char* ChannelDB::prefix_to_path(char *path, char *prefix)
00020 {
00021         FileSystem fs;
00022         char directory[BCTEXTLEN];
00023         sprintf(directory, BCASTDIR);
00024         fs.complete_path(directory);
00025         fs.join_names(path, directory, prefix);
00026         return path;
00027 }
00028 
00029 void ChannelDB::load(char *prefix)
00030 {
00031         FileXML file;
00032         char path[BCTEXTLEN];
00033 
00034         prefix_to_path(path, prefix);
00035         channels.remove_all_objects();
00036 
00037         int done = file.read_from_file(path, 1);
00038 
00039         channels.remove_all_objects();
00040 // Load channels
00041         while(!done)
00042         {
00043                 Channel *channel = new Channel;
00044                 if(!(done = channel->load(&file)))
00045                         channels.append(channel);
00046                 else
00047                 {
00048                         delete channel;
00049                 }
00050         }
00051 }
00052 
00053 void ChannelDB::save(char *prefix)
00054 {
00055         char path[BCTEXTLEN];
00056         FileXML file;
00057 
00058         prefix_to_path(path, prefix);
00059 
00060         if(channels.total)
00061         {
00062                 for(int i = 0; i < channels.total; i++)
00063                 {
00064 // Save channel here
00065                         channels.values[i]->save(&file);
00066                 }
00067                 file.terminate_string();
00068                 file.write_to_file(path);
00069         }
00070 }
00071 
00072 Channel* ChannelDB::get(int number)
00073 {
00074         if(number >= 0 && number < channels.total)
00075                 return channels.values[number];
00076         else
00077                 return 0;
00078 }
00079 
00080 void ChannelDB::copy_from(ChannelDB *src)
00081 {
00082         clear();
00083         for(int i = 0; i < src->size(); i++)
00084         {
00085                 Channel *dst = new Channel;
00086                 channels.append(dst);
00087                 dst->copy_settings(src->get(i));
00088         }
00089 }
00090 
00091 int ChannelDB::size()
00092 {
00093         return channels.total;
00094 }
00095 
00096 void ChannelDB::clear()
00097 {
00098         channels.remove_all_objects();
00099 }
00100 
00101 void ChannelDB::append(Channel *channel)
00102 {
00103         channels.append(channel);
00104 }
00105 
00106 void ChannelDB::remove_number(int number)
00107 {
00108         channels.remove_number(number);
00109 }
00110 
00111 void ChannelDB::set(int number, Channel *ptr)
00112 {
00113         channels.values[number] = ptr;
00114 }

Generated on Sun Jan 8 13:38:51 2006 for Cinelerra-svn by  doxygen 1.4.4