/* $Id$ */ /* * Cantus Tag Editor * Copyright © 2002-2004 by Samuel Abels * Copyright © 2007 by Tim Huetz * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see **/ #ifdef HAVE_CONFIG_H # include #endif #ifndef HAVE_CONFIGFILE_H #define HAVE_CONFIGFILE_H #include #include #include #include #include #include #include #include class ConfigFile : public sigc::trackable { public: ConfigFile(); ~ConfigFile(); /* Defines which file to read/write from. */ void set_filename(std::string newfilename); /* Check, whether or not the file exists and is read-/writable. * Returns 0 if the file is read/writeable. * -1 if no filename has been set yet or the file does not exist. * -2 if the file is not readable. * -3 if the file is not writeable. */ int check(void); /* This function opens the configfile and saves all option/value pairs in the * given map. Returns an errorcode, or 0 on success. */ int load(void); /* This function writes the configfile contents from the memory to the * configfile. Returns an errorcode, or 0 on success. */ int save(void); /* Clear the configfile content (only in the memory). */ void clear(void); /* Appends one key/value pair to the configfile (only in the memory). * Args passed to the method are: The key name, the value type (e.g. * G_TYPE_INT) and the value. * Returns always TRUE. */ bool append(std::string key, int type, void *value); /* Walks through all lines of the file, passing every option to the slot. * Args passed to the slot are: The key name, the value type (e.g. * G_TYPE_INT) and the value. */ void foreach_line(SigC::Slot3 slot); protected: /* Given one line of a file, this function returns the extracted key/value * pair. */ std::pair get_pair(const gchar *pline); /* Given one value string, this function extracts the value in the right data * type. */ std::pair grab_value(std::string value); std::list > content; // The file content. std::string filename; // The file name. }; #endif