Config.h

Go to the documentation of this file.
00001 #ifndef BUFFY_CONFIG_H
00002 #define BUFFY_CONFIG_H
00003 
00004 #include <buffy/Exception.h>
00005 #include <buffy/MailProgram.h>
00006 #include <libxml++/libxml++.h>
00007 
00008 namespace buffy {
00009 
00010 class Config;
00011 
00016 class ConfigItem
00017 {
00018 protected:
00019     Config& m_config;
00020     std::string m_path;
00021 
00022     ConfigItem(Config& config, const std::string& path);
00023 
00024     /* Return the node pointed by this ConfigItem, creating it if it does not exist */
00025     xmlpp::Element* node();
00026 
00027     /* Return the node pointed by this ConfigItem, or 0 if it does not exist */
00028     xmlpp::Element* nodeIfExists();
00029 
00030 public:
00031     virtual ~ConfigItem() {};
00032 
00038     friend class Config;
00039 };
00040 
00041 class ConfigItemBool : public ConfigItem
00042 {
00043 private:
00044     bool m_def;
00045 
00046 protected:
00047     ConfigItemBool(Config& config, const std::string& path, bool def)
00048         : ConfigItem(config, path), m_def(def) {}
00049 
00050 public:
00051     bool get();
00052     void set(bool val);
00053 
00054     friend class Config;
00055 };
00056 
00057 class ConfigItemInt : public ConfigItem
00058 {
00059 private:
00060     int m_def;
00061 
00062 protected:
00063     ConfigItemInt(Config& config, const std::string& path, int def)
00064         : ConfigItem(config, path), m_def(def) {}
00065 
00066 public:
00067     int get();
00068     void set(int val);
00069 
00070     friend class Config;
00071 };
00072 
00073 class ConfigItemString : public ConfigItem
00074 {
00075 private:
00076     std::string m_def;
00077         
00078 protected:
00079     ConfigItemString(Config& config, const std::string& path, const std::string& def)
00080         : ConfigItem(config, path), m_def(def) {}
00081 
00082 public:
00083     std::string get();
00084     void set(const std::string& val);
00085 
00086     friend class Config;
00087     friend class ConfigItemDictionary;
00088 };
00089 
00090 class ConfigItemLocations : public ConfigItem
00091 {
00092 protected:
00093     ConfigItemLocations(Config& config, const std::string& path)
00094         : ConfigItem(config, path) {}
00095 
00096     std::vector<std::string> computeDefault();
00097 
00098 public:
00099     std::vector<std::string> get();
00100     void set(const std::vector<std::string>& val);
00101 
00102     friend class Config;
00103 };
00104 
00105 class ConfigItemMailPrograms : public ConfigItem
00106 {
00107 protected:
00108     ConfigItemMailPrograms(Config& config, const std::string& path)
00109         : ConfigItem(config, path) {}
00110 
00111     std::vector<MailProgram> computeDefault();
00112 
00113 public:
00114     std::vector<MailProgram> get();
00115     void set(const std::vector<MailProgram>& val);
00116 
00117     MailProgram selected();
00118 
00119     friend class Config;
00120 };
00121 
00122 class ConfigItemDictionary : public ConfigItem
00123 {
00124 protected:
00125     ConfigItemDictionary(Config& config, const std::string& path)
00126         : ConfigItem(config, path) {}
00127 
00128 public:
00129     ConfigItemString get(const std::string& key, const std::string& def);
00130 
00131     friend class Config;
00132 };
00133 
00134 
00135 class Config
00136 {
00137 protected:
00138     xmlpp::DomParser _xmlparser;
00139 
00140     // Cached elements
00141     xmlpp::Document* doc_conf;
00142 
00143     xmlpp::Element* m_el_root;
00144     ConfigItem* m_el_general;
00145     ConfigItem* m_el_view;
00146     ConfigItem* m_el_applications;
00147     ConfigItem* m_el_folders;
00148 
00149     // State directory
00150     std::string rcfile;
00151 
00152 #if 0
00153     ConfigItem& el_general() throw ();
00154     ConfigItem& el_view() throw ();
00155     ConfigItem& el_applications() throw ();
00156     ConfigItem& el_folders() throw ();
00157 #endif
00158 
00159     void loadConfiguration(const std::string& fname) throw (SystemException, ConsistencyCheckException);
00160 
00161     xmlpp::Element* getElement(const std::string& path);
00162     xmlpp::Element* getElement(xmlpp::Element* father, const std::string& path);
00163     xmlpp::Element* obtainElement(const std::string& path);
00164     xmlpp::Element* obtainElement(xmlpp::Element* father, const std::string& path);
00165 
00166     xmlpp::Element* obtainNamedElement(xmlpp::Element* father, const std::string& nodeName, const std::string& name) throw ();
00167 
00168 public:
00169     Config() throw (SystemException, ConsistencyCheckException);
00170     Config(const std::string& fname) throw (SystemException, ConsistencyCheckException);
00171     ~Config() throw ();
00172 
00173     ConfigItemBool view_empty() throw ();
00174     ConfigItemBool view_read() throw ();
00175     ConfigItemBool view_important() throw ();
00176     ConfigItemInt update_interval() throw ();
00177     ConfigItemLocations folder_locations() throw ();
00178     ConfigItemMailPrograms mail_programs() throw ();
00179     ConfigItemDictionary application(const std::string& name) throw ();
00180     ConfigItemDictionary folder(const MailFolder& folder) throw ()
00181     {
00182         return this->folder(folder.path());
00183     }
00184     ConfigItemDictionary folder(const std::string& folder) throw ();
00185 
00186     /*
00187     bool get_view_read(const MailFolder& mf) throw ();
00188     bool get_view_empty(const MailFolder& mf) throw ();
00189     bool get_view_important(const MailFolder& mf) throw ();
00190 
00191     void set_view_read(const MailFolder& mf, bool val) throw ();
00192     void set_view_empty(const MailFolder& mf, bool val) throw ();
00193     void set_view_important(const MailFolder& mf, bool val) throw ();
00194     */
00195 
00196     void save() throw (ConsistencyCheckException);
00197     void save(const std::string& file) throw (ConsistencyCheckException);
00198 
00199     friend class ConfigItem;
00200 };
00201 
00202 }
00203 
00204 // vim:set ts=4 sw=4:
00205 #endif

Generated on Wed Nov 30 18:18:30 2005 for libbuffy by  doxygen 1.4.5