--- a/src/config.cpp Wed Aug 21 11:09:39 2013 +0300 +++ b/src/config.cpp Wed Aug 21 14:07:02 2013 +0300 @@ -14,6 +14,12 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. + * ===================================================================== + * + * config.cpp: Configuration management. I don't like how unsafe QSettings + * is so this implements a type-safer and idenitifer-safer wrapping system of + * configuration variables. QSettings is used underlyingly, this is a matter + * of interface. */ #include <errno.h> @@ -30,6 +36,8 @@ static ushort g_cfgPointerCursor = 0; // ============================================================================= +// Get the QSettings object. A portable build refers to a file in the current +// directory, a non-portable build to ~/.config/LDForge or to registry. // ----------------------------------------------------------------------------- static QSettings* getSettingsObject() { #ifdef PORTABLE @@ -48,11 +56,11 @@ name (name), m_defstring (defstring) {} // ============================================================================= +// Load the configuration from file // ----------------------------------------------------------------------------- -// Load the configuration from file bool Config::load() { QSettings* settings = getSettingsObject(); - print ("config::load: Loading configuration file from %1...\n", settings->fileName()); + print ("config::load: Loading configuration file from %1\n", settings->fileName()); for (Config* cfg : g_configPointers) { if (!cfg) @@ -67,8 +75,8 @@ } // ============================================================================= +// Save the configuration to disk // ----------------------------------------------------------------------------- -// Save the configuration to disk bool Config::save() { QSettings* settings = getSettingsObject(); print ("Saving configuration to %1...\n", settings->fileName()); @@ -89,6 +97,7 @@ } // ============================================================================= +// Reset configuration defaults. // ----------------------------------------------------------------------------- void Config::reset() { for (Config* cfg : g_configPointers) { @@ -100,12 +109,15 @@ } // ============================================================================= +// Where is the configuration file located at? Note that the Windows build uses +// the registry so only use this with PORTABLE code. // ----------------------------------------------------------------------------- str Config::filepath (str file) { return Config::dirpath() + DIRSLASH + file; } // ============================================================================= +// Directory of the configuration file. PORTABLE code here as well. // ----------------------------------------------------------------------------- str Config::dirpath() { QSettings* cfg = getSettingsObject(); @@ -113,21 +125,6 @@ } // ============================================================================= -// ----------------------------------------------------------------------------- -str Config::defaultString() const { - str defstring = m_defstring; - - // String types inevitably get extra quotes in their default string due to - // preprocessing stuff. We can only remove them now... - if (getType() == String) { - defstring.remove (0, 1); - defstring.chop (1); - } - - return defstring; -} - -// ============================================================================= // We cannot just add config objects to a list or vector because that would rely // on the vector's c-tor being called before the configs' c-tors. With global // variables we cannot assume that!! Therefore we need to use a C-style array here.