<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>AlbumShaper: configuration.cpp Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.5.9 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <h1>configuration.cpp</h1><a href="configuration_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">//==============================================</span> <a name="l00002"></a>00002 <span class="comment">// copyright : (C) 2003-2005 by Will Stokes</span> <a name="l00003"></a>00003 <span class="comment">//==============================================</span> <a name="l00004"></a>00004 <span class="comment">// This program is free software; you can redistribute it</span> <a name="l00005"></a>00005 <span class="comment">// and/or modify it under the terms of the GNU General</span> <a name="l00006"></a>00006 <span class="comment">// Public License as published by the Free Software</span> <a name="l00007"></a>00007 <span class="comment">// Foundation; either version 2 of the License, or</span> <a name="l00008"></a>00008 <span class="comment">// (at your option) any later version.</span> <a name="l00009"></a>00009 <span class="comment">//==============================================</span> <a name="l00010"></a>00010 <a name="l00011"></a>00011 <span class="comment">//Systemwide includes</span> <a name="l00012"></a>00012 <span class="preprocessor">#include <qdir.h></span> <a name="l00013"></a>00013 <span class="preprocessor">#include <qfile.h></span> <a name="l00014"></a>00014 <span class="preprocessor">#include <qstring.h></span> <a name="l00015"></a>00015 <span class="preprocessor">#include <qtextstream.h></span> <a name="l00016"></a>00016 <span class="preprocessor">#include <qdom.h></span> <a name="l00017"></a>00017 <a name="l00018"></a>00018 <span class="preprocessor">#if defined(Q_OS_WIN)</span> <a name="l00019"></a>00019 <span class="preprocessor"></span><span class="preprocessor">#include <stdlib.h></span> <a name="l00020"></a>00020 <span class="preprocessor">#endif</span> <a name="l00021"></a>00021 <span class="preprocessor"></span> <a name="l00022"></a>00022 <span class="comment">//Projectwide includes</span> <a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="configuration_8h.html">configuration.h</a>"</span> <a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="settinggroup_8h.html">settinggroup.h</a>"</span> <a name="l00025"></a>00025 <span class="preprocessor">#include "../config.h"</span> <a name="l00026"></a>00026 <span class="preprocessor">#include "../backend/tools/xmlTools.h"</span> <a name="l00027"></a>00027 <span class="preprocessor">#include "../backend/tools/fileTools.h"</span> <a name="l00028"></a>00028 <span class="comment">//==============================================</span> <a name="l00029"></a><a class="code" href="classConfiguration.html#f1a925453f6440cea68e5f216cfa62b7">00029</a> <span class="keywordtype">bool</span> <a class="code" href="classConfiguration.html#f1a925453f6440cea68e5f216cfa62b7" title="Constructs any necessary directories for loading and saving user settings, returns...">Configuration::constructSettingsDirectory</a>() <a name="l00030"></a>00030 { <a name="l00031"></a>00031 <span class="comment">//PLATFORM_SPECIFIC_CODE</span> <a name="l00032"></a>00032 <a name="l00033"></a>00033 <span class="comment">//-----------------------------</span> <a name="l00034"></a>00034 <span class="comment">//Mac OSX requires no directories to be created</span> <a name="l00035"></a>00035 <span class="preprocessor"> #if defined(Q_OS_MACX)</span> <a name="l00036"></a>00036 <span class="preprocessor"></span> <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00037"></a>00037 <span class="comment">//-----------------------------</span> <a name="l00038"></a>00038 <span class="comment">//Windows</span> <a name="l00039"></a>00039 <span class="preprocessor"> #elif defined(Q_OS_WIN)</span> <a name="l00040"></a>00040 <span class="preprocessor"></span> <span class="keywordtype">bool</span> configDirMade = <span class="keyword">true</span>; <a name="l00041"></a>00041 <a name="l00042"></a>00042 <span class="comment">//attempt to get folder location using windows api, if this fails try hard coded path as a last resort</span> <a name="l00043"></a>00043 QString folderLoc; <a name="l00044"></a>00044 <span class="keywordflow">if</span>( !getWindowsFolderLocation(LOCAL_SETTINGS_APPLICATION_DATA, folderLoc) ) <a name="l00045"></a>00045 { <a name="l00046"></a>00046 folderLoc = getenv(<span class="stringliteral">"USERPROFILE"</span>) + QString(<span class="stringliteral">"/Local Settings/Application Data"</span>); <a name="l00047"></a>00047 } <a name="l00048"></a>00048 QDir dataDir( folderLoc ); <a name="l00049"></a>00049 <span class="keywordflow">if</span>(!dataDir.exists(<span class="stringliteral">"Album Shaper"</span>)) <a name="l00050"></a>00050 { <a name="l00051"></a>00051 configDirMade = dataDir.mkdir(<span class="stringliteral">"Album Shaper"</span>); <a name="l00052"></a>00052 } <a name="l00053"></a>00053 <span class="keywordflow">return</span> configDirMade; <a name="l00054"></a>00054 <span class="comment">//-----------------------------</span> <a name="l00055"></a>00055 <span class="comment">//Unix/Linux/BSD</span> <a name="l00056"></a>00056 <span class="preprocessor"> #else</span> <a name="l00057"></a>00057 <span class="preprocessor"></span> <span class="keywordtype">bool</span> configDirMade = <span class="keyword">true</span>; <a name="l00058"></a>00058 QDir homeDir( QDir::homeDirPath() ); <a name="l00059"></a>00059 <span class="keywordflow">if</span>(!homeDir.exists(<span class="stringliteral">".albumShaper"</span>)) <a name="l00060"></a>00060 { <a name="l00061"></a>00061 configDirMade = homeDir.mkdir(<span class="stringliteral">".albumShaper"</span>); <a name="l00062"></a>00062 } <a name="l00063"></a>00063 <span class="keywordflow">return</span> configDirMade; <a name="l00064"></a>00064 <span class="preprocessor"> #endif </span> <a name="l00065"></a>00065 <span class="preprocessor"></span> <span class="comment">//-----------------------------</span> <a name="l00066"></a>00066 } <a name="l00067"></a>00067 <span class="comment">//==============================================</span> <a name="l00068"></a><a class="code" href="classConfiguration.html#779947337bf652f0e773cb29f37f14ba">00068</a> <a class="code" href="classConfiguration.html#779947337bf652f0e773cb29f37f14ba" title="Creates configuration variables using default values, then attempts to load settings...">Configuration::Configuration</a>() <a name="l00069"></a>00069 { <a name="l00070"></a>00070 <span class="comment">//-----------------------------</span> <a name="l00071"></a>00071 <span class="comment">//Determine settings filename</span> <a name="l00072"></a>00072 <span class="comment">//-----------------------------</span> <a name="l00073"></a>00073 <a name="l00074"></a>00074 <span class="comment">//PLATFORM_SPECIFIC_CODE</span> <a name="l00075"></a>00075 <a name="l00076"></a>00076 <span class="comment">//Mac OS X</span> <a name="l00077"></a>00077 <span class="preprocessor"> #if defined(Q_OS_MACX)</span> <a name="l00078"></a>00078 <span class="preprocessor"></span> <a class="code" href="classConfiguration.html#1a06238e940a01be7d9598519eec5590" title="Settings filename.">settingsFilename</a> = QDir::homeDirPath() + QString(<span class="stringliteral">"/Library/Preferences/net.sourceforge.albumshaper.xml"</span>); <a name="l00079"></a>00079 <span class="comment">//----------------------------- </span> <a name="l00080"></a>00080 <span class="comment">//Windows</span> <a name="l00081"></a>00081 <span class="preprocessor"> #elif defined(Q_OS_WIN)</span> <a name="l00082"></a>00082 <span class="preprocessor"></span> <span class="comment">//attempt to get folder location using windows api, if this fails try hard coded path as a last resort</span> <a name="l00083"></a>00083 QString tmp; <a name="l00084"></a>00084 <span class="keywordflow">if</span>( !getWindowsFolderLocation(LOCAL_SETTINGS_APPLICATION_DATA, tmp) ) <a name="l00085"></a>00085 { <a name="l00086"></a>00086 tmp = getenv(<span class="stringliteral">"USERPROFILE"</span>) + QString(<span class="stringliteral">"/Local Settings/Application Data"</span>); <a name="l00087"></a>00087 } <a name="l00088"></a>00088 <a class="code" href="classConfiguration.html#1a06238e940a01be7d9598519eec5590" title="Settings filename.">settingsFilename</a> = QDir::convertSeparators( tmp + <span class="stringliteral">"/Album Shaper/settings.xml"</span> ); <a name="l00089"></a>00089 <span class="comment">//-----------------------------</span> <a name="l00090"></a>00090 <span class="comment">//Unix/Linux/BSD</span> <a name="l00091"></a>00091 <span class="preprocessor"> #else</span> <a name="l00092"></a>00092 <span class="preprocessor"></span> <a class="code" href="classConfiguration.html#1a06238e940a01be7d9598519eec5590" title="Settings filename.">settingsFilename</a> = QDir::homeDirPath() + QString(<span class="stringliteral">"/.albumShaper/settings.xml"</span>); <a name="l00093"></a>00093 <span class="preprocessor"> #endif</span> <a name="l00094"></a>00094 <span class="preprocessor"></span> <span class="comment">//-----------------------------</span> <a name="l00095"></a>00095 <a name="l00096"></a>00096 <span class="comment">//no groups by default</span> <a name="l00097"></a>00097 <a class="code" href="classConfiguration.html#86704265c21603679342da13c7d19d02" title="pointer to first group">firstGroup</a> = NULL; <a name="l00098"></a>00098 <a class="code" href="classConfiguration.html#4724462b21a48e877d05ff57ae6d8cea" title="pointer to last group">lastGroup</a> = NULL; <a name="l00099"></a>00099 <a name="l00100"></a>00100 <span class="comment">//no group selected by default</span> <a name="l00101"></a>00101 <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> = NULL; <a name="l00102"></a>00102 } <a name="l00103"></a>00103 <span class="comment">//==============================================</span> <a name="l00104"></a><a class="code" href="classConfiguration.html#0dd0fa189e239f4c9a036303f641441e">00104</a> <a class="code" href="classConfiguration.html#0dd0fa189e239f4c9a036303f641441e" title="Destructor saves settings to disk.">Configuration::~Configuration</a>() <a name="l00105"></a>00105 { <a name="l00106"></a>00106 <span class="comment">//delete all setting groups</span> <a name="l00107"></a>00107 <a class="code" href="classSettingGroup.html" title="SettingGroup contains settings which are releated.">SettingGroup</a>* cur = <a class="code" href="classConfiguration.html#86704265c21603679342da13c7d19d02" title="pointer to first group">firstGroup</a>; <a name="l00108"></a>00108 <span class="keywordflow">while</span>(cur != NULL) <a name="l00109"></a>00109 { <a name="l00110"></a>00110 <a class="code" href="classSettingGroup.html" title="SettingGroup contains settings which are releated.">SettingGroup</a>* next = cur-><a class="code" href="classSettingGroup.html#8e4f4cb1e014fe366c31a25b180a57db" title="returns the next groupsetting">getNext</a>(); <a name="l00111"></a>00111 <span class="keyword">delete</span> cur; <a name="l00112"></a>00112 cur = next; <a name="l00113"></a>00113 } <a name="l00114"></a>00114 } <a name="l00115"></a>00115 <span class="comment">//==============================================</span> <a name="l00116"></a><a class="code" href="classConfiguration.html#cc6935858bf26f6d44c78401fc93d975">00116</a> <span class="keywordtype">void</span> <a class="code" href="classConfiguration.html#cc6935858bf26f6d44c78401fc93d975" title="Sets a setting value, if group does not exist it is created, if setting does not...">Configuration::setString</a>( QString group, QString key, QString value) <a name="l00117"></a>00117 { <a name="l00118"></a>00118 <span class="comment">//check if cached group has same name, if not find group, create it if group does not exist</span> <a name="l00119"></a>00119 <span class="keywordflow">if</span>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> == NULL || <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#49ada5ca78c07434fe8f099550aea8a4" title="Returns group&#39;s name.">getName</a>().compare(group) != 0) <a name="l00120"></a>00120 { <a name="l00121"></a>00121 <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> = <a class="code" href="classConfiguration.html#86704265c21603679342da13c7d19d02" title="pointer to first group">firstGroup</a>; <a name="l00122"></a>00122 <span class="keywordflow">while</span>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> != NULL) <a name="l00123"></a>00123 { <a name="l00124"></a>00124 <span class="keywordflow">if</span>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#49ada5ca78c07434fe8f099550aea8a4" title="Returns group&#39;s name.">getName</a>().compare(group) == 0) <a name="l00125"></a>00125 <span class="keywordflow">break</span>; <a name="l00126"></a>00126 <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> = <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#8e4f4cb1e014fe366c31a25b180a57db" title="returns the next groupsetting">getNext</a>(); <a name="l00127"></a>00127 } <a name="l00128"></a>00128 <a name="l00129"></a>00129 <span class="comment">//if we have not found the group create it and add to list</span> <a name="l00130"></a>00130 <span class="keywordflow">if</span>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> == NULL) <a name="l00131"></a>00131 { <a name="l00132"></a>00132 <span class="comment">//create new group</span> <a name="l00133"></a>00133 <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> = <span class="keyword">new</span> <a class="code" href="classSettingGroup.html" title="SettingGroup contains settings which are releated.">SettingGroup</a>(group); <a name="l00134"></a>00134 <a name="l00135"></a>00135 <span class="comment">//add group to list</span> <a name="l00136"></a>00136 <span class="keywordflow">if</span>(<a class="code" href="classConfiguration.html#86704265c21603679342da13c7d19d02" title="pointer to first group">firstGroup</a> == NULL) <a name="l00137"></a>00137 <a class="code" href="classConfiguration.html#86704265c21603679342da13c7d19d02" title="pointer to first group">firstGroup</a> = <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>; <a name="l00138"></a>00138 <span class="keywordflow">else</span> <a name="l00139"></a>00139 <a class="code" href="classConfiguration.html#4724462b21a48e877d05ff57ae6d8cea" title="pointer to last group">lastGroup</a>-><a class="code" href="classSettingGroup.html#3944d4fc6f3ed30a0916395590dd0e2d" title="sets the next group setting">setNext</a>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>); <a name="l00140"></a>00140 <a class="code" href="classConfiguration.html#4724462b21a48e877d05ff57ae6d8cea" title="pointer to last group">lastGroup</a> = <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>; <a name="l00141"></a>00141 } <a name="l00142"></a>00142 } <a name="l00143"></a>00143 <a name="l00144"></a>00144 <span class="comment">//set setting value</span> <a name="l00145"></a>00145 <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#4884ce9828c936de787ccaf5024acd94" title="Sets a setting value, create new setting if setting not found.">setValue</a>(key, value); <a name="l00146"></a>00146 } <a name="l00147"></a>00147 <span class="comment">//==============================================</span> <a name="l00148"></a><a class="code" href="classConfiguration.html#9dd8bba47dda7f0964567656f9514852">00148</a> <span class="keywordtype">void</span> <a class="code" href="classConfiguration.html#9dd8bba47dda7f0964567656f9514852" title="Set bool setting.">Configuration::setBool</a>( QString group, QString key, <span class="keywordtype">bool</span> val ) <a name="l00149"></a>00149 { <a name="l00150"></a>00150 <a class="code" href="classConfiguration.html#cc6935858bf26f6d44c78401fc93d975" title="Sets a setting value, if group does not exist it is created, if setting does not...">setString</a>( group, key, (val ? <span class="stringliteral">"1"</span> : <span class="stringliteral">"0"</span> ) ); <a name="l00151"></a>00151 } <a name="l00152"></a>00152 <span class="comment">//==============================================</span> <a name="l00153"></a><a class="code" href="classConfiguration.html#735d3e91a3a767567371e8ccd940b6e3">00153</a> <span class="keywordtype">void</span> <a class="code" href="classConfiguration.html#735d3e91a3a767567371e8ccd940b6e3" title="Set int setting.">Configuration::setInt</a>( QString group, QString key, <span class="keywordtype">int</span> val ) <a name="l00154"></a>00154 { <a name="l00155"></a>00155 <a class="code" href="classConfiguration.html#cc6935858bf26f6d44c78401fc93d975" title="Sets a setting value, if group does not exist it is created, if setting does not...">setString</a>( group, key, QString(<span class="stringliteral">"%1"</span>).arg(val) ); <a name="l00156"></a>00156 } <a name="l00157"></a>00157 <span class="comment">//==============================================</span> <a name="l00158"></a><a class="code" href="classConfiguration.html#f39a96d2cd773570ef1aecf502a3cc90">00158</a> QString <a class="code" href="classConfiguration.html#f39a96d2cd773570ef1aecf502a3cc90" title="Fetch string setting.">Configuration::getString</a>(QString group, QString key) <a name="l00159"></a>00159 { <a name="l00160"></a>00160 <span class="comment">//check if cached group is correct group, if not find correct group</span> <a name="l00161"></a>00161 <span class="keywordflow">if</span>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> == NULL || <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#49ada5ca78c07434fe8f099550aea8a4" title="Returns group&#39;s name.">getName</a>().compare(group) != 0) <a name="l00162"></a>00162 { <a name="l00163"></a>00163 <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> = <a class="code" href="classConfiguration.html#86704265c21603679342da13c7d19d02" title="pointer to first group">firstGroup</a>; <a name="l00164"></a>00164 <span class="keywordflow">while</span>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> != NULL) <a name="l00165"></a>00165 { <a name="l00166"></a>00166 <span class="keywordflow">if</span>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#49ada5ca78c07434fe8f099550aea8a4" title="Returns group&#39;s name.">getName</a>().compare(group) == 0) <a name="l00167"></a>00167 <span class="keywordflow">break</span>; <a name="l00168"></a>00168 <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> = <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#8e4f4cb1e014fe366c31a25b180a57db" title="returns the next groupsetting">getNext</a>(); <a name="l00169"></a>00169 } <a name="l00170"></a>00170 <a name="l00171"></a>00171 <span class="comment">//if we have not found the group return error value (-1)</span> <a name="l00172"></a>00172 <span class="keywordflow">if</span>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> == NULL) <a name="l00173"></a>00173 { <a name="l00174"></a>00174 <span class="keywordflow">return</span> <span class="stringliteral">"-1"</span>; <a name="l00175"></a>00175 } <a name="l00176"></a>00176 } <a name="l00177"></a>00177 <a name="l00178"></a>00178 <span class="comment">//return setting value from group</span> <a name="l00179"></a>00179 <span class="keywordflow">return</span> <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#04d821f68b469eb67c255a261593dc54" title="Returns a setting value.">getValue</a>(key); <a name="l00180"></a>00180 } <a name="l00181"></a>00181 <span class="comment">//==============================================</span> <a name="l00182"></a><a class="code" href="classConfiguration.html#ea454423722c57c7c47a2703c5fac88f">00182</a> <span class="keywordtype">void</span> <a class="code" href="classConfiguration.html#ea454423722c57c7c47a2703c5fac88f" title="Resets a setting to it&#39;s default value.">Configuration::resetSetting</a>(QString group, QString key) <a name="l00183"></a>00183 { <a name="l00184"></a>00184 <span class="comment">//check if cached group is correct group, if not find correct group</span> <a name="l00185"></a>00185 <span class="keywordflow">if</span>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> == NULL || <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#49ada5ca78c07434fe8f099550aea8a4" title="Returns group&#39;s name.">getName</a>().compare(group) != 0) <a name="l00186"></a>00186 { <a name="l00187"></a>00187 <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> = <a class="code" href="classConfiguration.html#86704265c21603679342da13c7d19d02" title="pointer to first group">firstGroup</a>; <a name="l00188"></a>00188 <span class="keywordflow">while</span>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> != NULL) <a name="l00189"></a>00189 { <a name="l00190"></a>00190 <span class="keywordflow">if</span>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#49ada5ca78c07434fe8f099550aea8a4" title="Returns group&#39;s name.">getName</a>().compare(group) == 0) <a name="l00191"></a>00191 <span class="keywordflow">break</span>; <a name="l00192"></a>00192 <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> = <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#8e4f4cb1e014fe366c31a25b180a57db" title="returns the next groupsetting">getNext</a>(); <a name="l00193"></a>00193 } <a name="l00194"></a>00194 <a name="l00195"></a>00195 <span class="comment">//if we have not found the group return error value (-1)</span> <a name="l00196"></a>00196 <span class="keywordflow">if</span>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> == NULL) <a name="l00197"></a>00197 { <a name="l00198"></a>00198 <span class="keywordflow">return</span>; <a name="l00199"></a>00199 } <a name="l00200"></a>00200 } <a name="l00201"></a>00201 <a name="l00202"></a>00202 <span class="comment">//return setting value from group</span> <a name="l00203"></a>00203 <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#071f894d5629180bac1cc2429c55f94b" title="resets a setting to its default value">resetSetting</a>(key); <a name="l00204"></a>00204 } <a name="l00205"></a>00205 <span class="comment">//==============================================</span> <a name="l00206"></a><a class="code" href="classConfiguration.html#0d92de22ace3b90de4d73b6b32468a42">00206</a> <span class="keywordtype">bool</span> <a class="code" href="classConfiguration.html#0d92de22ace3b90de4d73b6b32468a42" title="Fetch bool setting.">Configuration::getBool</a>(QString group, QString key) <a name="l00207"></a>00207 { <a name="l00208"></a>00208 <span class="keywordflow">return</span> ( <a class="code" href="classConfiguration.html#f39a96d2cd773570ef1aecf502a3cc90" title="Fetch string setting.">getString</a>(group,key).compare(<span class="stringliteral">"1"</span>) == 0 ); <a name="l00209"></a>00209 } <a name="l00210"></a>00210 <span class="comment">//==============================================</span> <a name="l00211"></a><a class="code" href="classConfiguration.html#f4e92490c6799dddb0eb0c69ead27a0a">00211</a> <span class="keywordtype">int</span> <a class="code" href="classConfiguration.html#f4e92490c6799dddb0eb0c69ead27a0a" title="Fetch int setting.">Configuration::getInt</a>(QString group, QString key) <a name="l00212"></a>00212 { <a name="l00213"></a>00213 <span class="keywordflow">return</span> <a class="code" href="classConfiguration.html#f39a96d2cd773570ef1aecf502a3cc90" title="Fetch string setting.">getString</a>(group,key).toInt(); <a name="l00214"></a>00214 } <a name="l00215"></a>00215 <span class="comment">//==============================================</span> <a name="l00216"></a><a class="code" href="classConfiguration.html#5afd4af338faec431ddd3dbcfe65be7a">00216</a> <span class="keywordtype">float</span> <a class="code" href="classConfiguration.html#5afd4af338faec431ddd3dbcfe65be7a" title="Fetch float setting.">Configuration::getFloat</a>(QString group, QString key) <a name="l00217"></a>00217 { <a name="l00218"></a>00218 <span class="keywordflow">return</span> <a class="code" href="classConfiguration.html#f39a96d2cd773570ef1aecf502a3cc90" title="Fetch string setting.">getString</a>(group,key).toFloat(); <a name="l00219"></a>00219 } <a name="l00220"></a>00220 <span class="comment">//==============================================</span> <a name="l00221"></a><a class="code" href="classConfiguration.html#27afbac38256b03f5ee37359cb3f687c">00221</a> <span class="keywordtype">double</span> <a class="code" href="classConfiguration.html#27afbac38256b03f5ee37359cb3f687c" title="Fetch double setting.">Configuration::getDouble</a>(QString group, QString key) <a name="l00222"></a>00222 { <a name="l00223"></a>00223 <span class="keywordflow">return</span> <a class="code" href="classConfiguration.html#f39a96d2cd773570ef1aecf502a3cc90" title="Fetch string setting.">getString</a>(group,key).toDouble(); <a name="l00224"></a>00224 } <a name="l00225"></a>00225 <span class="comment">//==============================================</span> <a name="l00226"></a><a class="code" href="classConfiguration.html#38d952550fafd2bc05317cad18a9c24e">00226</a> <span class="keywordtype">void</span> <a class="code" href="classConfiguration.html#38d952550fafd2bc05317cad18a9c24e" title="Removes an entire group of settings.">Configuration::removeGroup</a>(QString group) <a name="l00227"></a>00227 { <a name="l00228"></a>00228 <span class="comment">//iterate through groups, remove group once found</span> <a name="l00229"></a>00229 <a class="code" href="classSettingGroup.html" title="SettingGroup contains settings which are releated.">SettingGroup</a>* prev = NULL; <a name="l00230"></a>00230 <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> = <a class="code" href="classConfiguration.html#86704265c21603679342da13c7d19d02" title="pointer to first group">firstGroup</a>; <a name="l00231"></a>00231 <span class="keywordflow">while</span>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> != NULL) <a name="l00232"></a>00232 { <a name="l00233"></a>00233 <span class="comment">//found</span> <a name="l00234"></a>00234 <span class="keywordflow">if</span>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#49ada5ca78c07434fe8f099550aea8a4" title="Returns group&#39;s name.">getName</a>().compare(group) == 0) <a name="l00235"></a>00235 { <a name="l00236"></a>00236 <span class="comment">//keep handle on group for deletion purposes</span> <a name="l00237"></a>00237 <a class="code" href="classSettingGroup.html" title="SettingGroup contains settings which are releated.">SettingGroup</a>* temp = <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>; <a name="l00238"></a>00238 <a name="l00239"></a>00239 <span class="comment">//fix head if necessary</span> <a name="l00240"></a>00240 <span class="keywordflow">if</span>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> == <a class="code" href="classConfiguration.html#86704265c21603679342da13c7d19d02" title="pointer to first group">firstGroup</a>) <a name="l00241"></a>00241 <a class="code" href="classConfiguration.html#86704265c21603679342da13c7d19d02" title="pointer to first group">firstGroup</a> = <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#8e4f4cb1e014fe366c31a25b180a57db" title="returns the next groupsetting">getNext</a>(); <a name="l00242"></a>00242 <a name="l00243"></a>00243 <span class="comment">//fix tail if necessary</span> <a name="l00244"></a>00244 <span class="keywordflow">if</span>(<a class="code" href="classConfiguration.html#4724462b21a48e877d05ff57ae6d8cea" title="pointer to last group">lastGroup</a> == <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>) <a name="l00245"></a>00245 <a class="code" href="classConfiguration.html#4724462b21a48e877d05ff57ae6d8cea" title="pointer to last group">lastGroup</a> = prev; <a name="l00246"></a>00246 <a name="l00247"></a>00247 <span class="comment">//splice out group</span> <a name="l00248"></a>00248 <span class="keywordflow">if</span>(prev != NULL) <a name="l00249"></a>00249 prev-><a class="code" href="classSettingGroup.html#3944d4fc6f3ed30a0916395590dd0e2d" title="sets the next group setting">setNext</a>( <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#8e4f4cb1e014fe366c31a25b180a57db" title="returns the next groupsetting">getNext</a>() ); <a name="l00250"></a>00250 <a name="l00251"></a>00251 <span class="comment">//update curGroup pointer so valid</span> <a name="l00252"></a>00252 <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> = <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#8e4f4cb1e014fe366c31a25b180a57db" title="returns the next groupsetting">getNext</a>(); <a name="l00253"></a>00253 <a name="l00254"></a>00254 <span class="comment">//free group</span> <a name="l00255"></a>00255 <span class="keyword">delete</span> temp; <a name="l00256"></a>00256 temp = NULL; <a name="l00257"></a>00257 <a name="l00258"></a>00258 <span class="comment">//done </span> <a name="l00259"></a>00259 <span class="keywordflow">return</span>; <a name="l00260"></a>00260 } <a name="l00261"></a>00261 <a name="l00262"></a>00262 <span class="comment">//update prev and cur pointers and move along</span> <a name="l00263"></a>00263 prev = <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>; <a name="l00264"></a>00264 <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> = <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#8e4f4cb1e014fe366c31a25b180a57db" title="returns the next groupsetting">getNext</a>(); <a name="l00265"></a>00265 } <a name="l00266"></a>00266 } <a name="l00267"></a>00267 <span class="comment">//==============================================</span> <a name="l00268"></a><a class="code" href="classConfiguration.html#a944e4bdd70019c53598af97cff052a9">00268</a> <span class="keywordtype">bool</span> <a class="code" href="classConfiguration.html#a944e4bdd70019c53598af97cff052a9" title="Loads settings.">Configuration::loadSettings</a>() <a name="l00269"></a>00269 { <a name="l00270"></a>00270 <span class="comment">//-----------------------------------</span> <a name="l00271"></a>00271 <span class="comment">//attempt to load xml settings file and construct dom, if either action failes return false</span> <a name="l00272"></a>00272 QFile settingsFile( <a class="code" href="classConfiguration.html#1a06238e940a01be7d9598519eec5590" title="Settings filename.">settingsFilename</a> ); <a name="l00273"></a>00273 <span class="keywordflow">if</span>( !settingsFile.open( IO_ReadOnly ) ) <a name="l00274"></a>00274 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00275"></a>00275 <a name="l00276"></a>00276 QDomDocument DOM; <a name="l00277"></a>00277 <span class="keywordflow">if</span>( !DOM.setContent( &settingsFile ) ) <a name="l00278"></a>00278 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00279"></a>00279 <a name="l00280"></a>00280 settingsFile.close(); <a name="l00281"></a>00281 <a name="l00282"></a>00282 <span class="comment">//-----------------------------------</span> <a name="l00283"></a>00283 <span class="comment">//walk though DOM and look for setting nodes.</span> <a name="l00284"></a>00284 <span class="comment">//for each setting fetch, type, key, and value</span> <a name="l00285"></a>00285 <span class="comment">//walk through list of settings and find previous setting</span> <a name="l00286"></a>00286 <span class="comment">//if previous setting found replace value, otherwise add new setting to list</span> <a name="l00287"></a>00287 QDomElement root = DOM.documentElement(); <a name="l00288"></a>00288 QDomNode node = root.firstChild(); <a name="l00289"></a>00289 <a name="l00290"></a>00290 <span class="keywordflow">while</span>( !node.isNull() ) <a name="l00291"></a>00291 { <a name="l00292"></a>00292 <span class="keywordflow">if</span>( node.isElement() && node.nodeName() == <span class="stringliteral">"group"</span> ) <a name="l00293"></a>00293 { <a name="l00294"></a>00294 <span class="comment">//find group name, if no name found then move on to next group</span> <a name="l00295"></a>00295 QDomNamedNodeMap attributes = node.attributes(); <a name="l00296"></a>00296 <span class="keywordflow">if</span>(attributes.namedItem(<span class="stringliteral">"name"</span>).isNull()) <a name="l00297"></a>00297 { <a name="l00298"></a>00298 node = node.nextSibling(); <a name="l00299"></a>00299 <span class="keywordflow">continue</span>; <a name="l00300"></a>00300 } <a name="l00301"></a>00301 <a name="l00302"></a>00302 <span class="comment">//create group if it does not already exist</span> <a name="l00303"></a>00303 <a class="code" href="classSettingGroup.html" title="SettingGroup contains settings which are releated.">SettingGroup</a>* loadedGroup = NULL; <a name="l00304"></a>00304 <a name="l00305"></a>00305 <span class="comment">//last used group is the one we are looking for</span> <a name="l00306"></a>00306 <span class="keywordflow">if</span>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#49ada5ca78c07434fe8f099550aea8a4" title="Returns group&#39;s name.">getName</a>().compare( attributes.namedItem(<span class="stringliteral">"name"</span>).nodeValue()) == 0) <a name="l00307"></a>00307 loadedGroup = <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>; <a name="l00308"></a>00308 <span class="comment">//search list of groups</span> <a name="l00309"></a>00309 <span class="keywordflow">else</span> <a name="l00310"></a>00310 { <a name="l00311"></a>00311 <a class="code" href="classSettingGroup.html" title="SettingGroup contains settings which are releated.">SettingGroup</a>* cur = <a class="code" href="classConfiguration.html#86704265c21603679342da13c7d19d02" title="pointer to first group">firstGroup</a>; <a name="l00312"></a>00312 <span class="keywordflow">while</span>(cur != NULL) <a name="l00313"></a>00313 { <a name="l00314"></a>00314 <span class="comment">//found it!</span> <a name="l00315"></a>00315 <span class="keywordflow">if</span>(cur-><a class="code" href="classSettingGroup.html#49ada5ca78c07434fe8f099550aea8a4" title="Returns group&#39;s name.">getName</a>().compare( attributes.namedItem(<span class="stringliteral">"name"</span>).nodeValue()) == 0) <a name="l00316"></a>00316 { <a name="l00317"></a>00317 loadedGroup = cur; <a name="l00318"></a>00318 <span class="keywordflow">break</span>; <a name="l00319"></a>00319 } <a name="l00320"></a>00320 <span class="comment">//nope, move on to next group</span> <a name="l00321"></a>00321 cur = cur-><a class="code" href="classSettingGroup.html#8e4f4cb1e014fe366c31a25b180a57db" title="returns the next groupsetting">getNext</a>(); <a name="l00322"></a>00322 } <a name="l00323"></a>00323 } <a name="l00324"></a>00324 <span class="comment">//if group to be loaded is not found then create it</span> <a name="l00325"></a>00325 <span class="keywordflow">if</span>(loadedGroup == NULL) <a name="l00326"></a>00326 { <a name="l00327"></a>00327 loadedGroup = <span class="keyword">new</span> <a class="code" href="classSettingGroup.html" title="SettingGroup contains settings which are releated.">SettingGroup</a>( attributes.namedItem(<span class="stringliteral">"name"</span>).nodeValue() ); <a name="l00328"></a>00328 <span class="keywordflow">if</span>(<a class="code" href="classConfiguration.html#86704265c21603679342da13c7d19d02" title="pointer to first group">firstGroup</a> == NULL) <a name="l00329"></a>00329 <a class="code" href="classConfiguration.html#86704265c21603679342da13c7d19d02" title="pointer to first group">firstGroup</a> = loadedGroup; <a name="l00330"></a>00330 <span class="keywordflow">else</span> <a name="l00331"></a>00331 <a class="code" href="classConfiguration.html#4724462b21a48e877d05ff57ae6d8cea" title="pointer to last group">lastGroup</a>-><a class="code" href="classSettingGroup.html#3944d4fc6f3ed30a0916395590dd0e2d" title="sets the next group setting">setNext</a>(loadedGroup); <a name="l00332"></a>00332 <a class="code" href="classConfiguration.html#4724462b21a48e877d05ff57ae6d8cea" title="pointer to last group">lastGroup</a> = loadedGroup; <a name="l00333"></a>00333 } <a name="l00334"></a>00334 <a name="l00335"></a>00335 loadedGroup-><a class="code" href="classSettingGroup.html#ed28a422e74301266cff9561c2833691">loadSettings</a>(node); <a name="l00336"></a>00336 } <a name="l00337"></a>00337 <span class="comment">//move on to next setting</span> <a name="l00338"></a>00338 node = node.nextSibling(); <a name="l00339"></a>00339 } <a name="l00340"></a>00340 <span class="comment">//-----------------------------------</span> <a name="l00341"></a>00341 <span class="comment">//loading of settingings was successful</span> <a name="l00342"></a>00342 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00343"></a>00343 } <a name="l00344"></a>00344 <span class="comment">//==============================================</span> <a name="l00345"></a><a class="code" href="classConfiguration.html#c50b64311aca702f82bb6b5aabba7d2c">00345</a> <span class="keywordtype">bool</span> <a class="code" href="classConfiguration.html#c50b64311aca702f82bb6b5aabba7d2c" title="Saves settings.">Configuration::saveSettings</a>() <a name="l00346"></a>00346 { <a name="l00347"></a>00347 <span class="comment">//create/open html file</span> <a name="l00348"></a>00348 QFile file( <a class="code" href="classConfiguration.html#1a06238e940a01be7d9598519eec5590" title="Settings filename.">settingsFilename</a> ); <a name="l00349"></a>00349 <span class="keywordflow">if</span>(file.open(IO_WriteOnly)) <a name="l00350"></a>00350 { <a name="l00351"></a>00351 <span class="comment">//-----</span> <a name="l00352"></a>00352 QTextStream stream; <a name="l00353"></a>00353 stream.setDevice( &file ); <a name="l00354"></a>00354 stream.setEncoding( QTextStream::UnicodeUTF8 ); <a name="l00355"></a>00355 <a name="l00356"></a>00356 <span class="comment">//write header</span> <a name="l00357"></a>00357 stream << <span class="stringliteral">"<settings app=\"Album Shaper\" version=\""</span> << <a class="code" href="config_8h.html#bb92ba64f4db628dfcc469f96f3af746">ALBUMSHAPER_VERSION</a> << <span class="stringliteral">"\">\n"</span>; <a name="l00358"></a>00358 <a name="l00359"></a>00359 <span class="comment">//iterate over every group</span> <a name="l00360"></a>00360 <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> = <a class="code" href="classConfiguration.html#86704265c21603679342da13c7d19d02" title="pointer to first group">firstGroup</a>; <a name="l00361"></a>00361 <span class="keywordflow">while</span>(<a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> != NULL) <a name="l00362"></a>00362 { <a name="l00363"></a>00363 <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#284af55757783b4cfaf752384e742afc" title="writes out this group to file">saveSettings</a>( stream ); <a name="l00364"></a>00364 <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a> = <a class="code" href="classConfiguration.html#3c3b9a46b753f80b74125d37e8d5fd5f" title="pointer to currently selected group">curGroup</a>-><a class="code" href="classSettingGroup.html#8e4f4cb1e014fe366c31a25b180a57db" title="returns the next groupsetting">getNext</a>(); <a name="l00365"></a>00365 } <a name="l00366"></a>00366 <a name="l00367"></a>00367 <span class="comment">//end xml file</span> <a name="l00368"></a>00368 stream << <span class="stringliteral">"</settings>\n"</span>; <a name="l00369"></a>00369 <a name="l00370"></a>00370 <span class="comment">//success saving settings!</span> <a name="l00371"></a>00371 file.close(); <a name="l00372"></a>00372 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00373"></a>00373 } <a name="l00374"></a>00374 <a name="l00375"></a>00375 <span class="comment">//opening file for saving failed</span> <a name="l00376"></a>00376 file.close(); <a name="l00377"></a>00377 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00378"></a>00378 } <a name="l00379"></a>00379 <span class="comment">//==============================================</span> </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Sun Aug 23 02:34:25 2009 for AlbumShaper by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address> </body> </html>