<!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: settinggroup.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>settinggroup.cpp</h1><a href="settinggroup_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 <qstring.h></span> <a name="l00013"></a>00013 <span class="preprocessor">#include <qtextstream.h></span> <a name="l00014"></a>00014 <span class="preprocessor">#include <qdom.h></span> <a name="l00015"></a>00015 <a name="l00016"></a>00016 <span class="comment">//Projectwide includes</span> <a name="l00017"></a>00017 <span class="preprocessor">#include "<a class="code" href="settinggroup_8h.html">settinggroup.h</a>"</span> <a name="l00018"></a>00018 <span class="preprocessor">#include "<a class="code" href="setting_8h.html">setting.h</a>"</span> <a name="l00019"></a>00019 <a name="l00020"></a>00020 <span class="comment">//==============================================</span> <a name="l00021"></a><a class="code" href="classSettingGroup.html#b8fe7029585bf4b416b8537c49a2b676">00021</a> <a class="code" href="classSettingGroup.html#b8fe7029585bf4b416b8537c49a2b676" title="Creates configuration variables using default avlues.">SettingGroup::SettingGroup</a>(QString name) <a name="l00022"></a>00022 { <a name="l00023"></a>00023 this->name = name; <a name="l00024"></a>00024 <a class="code" href="classSettingGroup.html#fa3863356f975642e0d12b857a260683" title="pointer to first setting in group">firstSetting</a> = NULL; <a name="l00025"></a>00025 <a class="code" href="classSettingGroup.html#321c99478e10cf6789e66ede6b5126ec" title="pointer to last setting in group">lastSetting</a> = NULL; <a name="l00026"></a>00026 <a class="code" href="classSettingGroup.html#433a5e987ef682359dc794e349204448" title="pointer to next settingroup">next</a> = NULL; <a name="l00027"></a>00027 } <a name="l00028"></a>00028 <span class="comment">//==============================================</span> <a name="l00029"></a><a class="code" href="classSettingGroup.html#2e3e87fca1465744d24a356f1a66473c">00029</a> <a class="code" href="classSettingGroup.html#2e3e87fca1465744d24a356f1a66473c" title="Destructor.">SettingGroup::~SettingGroup</a>() <a name="l00030"></a>00030 { <a name="l00031"></a>00031 <a class="code" href="classSetting.html" title="Setting class, allows the setting and retrieval of setting values.">Setting</a>* cur = <a class="code" href="classSettingGroup.html#fa3863356f975642e0d12b857a260683" title="pointer to first setting in group">firstSetting</a>; <a name="l00032"></a>00032 <span class="keywordflow">while</span>(cur != NULL) <a name="l00033"></a>00033 { <a name="l00034"></a>00034 <a class="code" href="classSetting.html" title="Setting class, allows the setting and retrieval of setting values.">Setting</a>* t = cur-><a class="code" href="classSetting.html#368ad2c551ec7651704b50d933c091e4" title="gets a pointer to the next setting in the list">getNext</a>(); <a name="l00035"></a>00035 <span class="keyword">delete</span> cur; <a name="l00036"></a>00036 cur = t; <a name="l00037"></a>00037 } <a name="l00038"></a>00038 } <a name="l00039"></a>00039 <span class="comment">//==============================================</span> <a name="l00040"></a><a class="code" href="classSettingGroup.html#49ada5ca78c07434fe8f099550aea8a4">00040</a> QString <a class="code" href="classSettingGroup.html#49ada5ca78c07434fe8f099550aea8a4" title="Returns group&#39;s name.">SettingGroup::getName</a>() <a name="l00041"></a>00041 { <a name="l00042"></a>00042 <span class="keywordflow">return</span> <a class="code" href="classSettingGroup.html#20a8aa42c634b0447bd22c36b016f5d4" title="groups identifying name">name</a>; <a name="l00043"></a>00043 } <a name="l00044"></a>00044 <span class="comment">//==============================================</span> <a name="l00045"></a><a class="code" href="classSettingGroup.html#04d821f68b469eb67c255a261593dc54">00045</a> QString <a class="code" href="classSettingGroup.html#04d821f68b469eb67c255a261593dc54" title="Returns a setting value.">SettingGroup::getValue</a>(QString key) <a name="l00046"></a>00046 { <a name="l00047"></a>00047 <a class="code" href="classSetting.html" title="Setting class, allows the setting and retrieval of setting values.">Setting</a>* cur = <a class="code" href="classSettingGroup.html#fa3863356f975642e0d12b857a260683" title="pointer to first setting in group">firstSetting</a>; <a name="l00048"></a>00048 <span class="keywordflow">while</span>(cur != NULL) <a name="l00049"></a>00049 { <a name="l00050"></a>00050 <span class="keywordflow">if</span>(cur-><a class="code" href="classSetting.html#18aa160dfdff785d10d0e0352cbd1860">getKey</a>().compare(key) == 0) <a name="l00051"></a>00051 { <a name="l00052"></a>00052 <span class="keywordflow">return</span> cur-><a class="code" href="classSetting.html#88484910529421d1a925e71189b84f45">getValue</a>(); <a name="l00053"></a>00053 } <a name="l00054"></a>00054 cur = cur-><a class="code" href="classSetting.html#368ad2c551ec7651704b50d933c091e4" title="gets a pointer to the next setting in the list">getNext</a>(); <a name="l00055"></a>00055 } <a name="l00056"></a>00056 <span class="keywordflow">return</span> <span class="stringliteral">"-1"</span>; <a name="l00057"></a>00057 } <a name="l00058"></a>00058 <span class="comment">//==============================================</span> <a name="l00059"></a><a class="code" href="classSettingGroup.html#071f894d5629180bac1cc2429c55f94b">00059</a> <span class="keywordtype">void</span> <a class="code" href="classSettingGroup.html#071f894d5629180bac1cc2429c55f94b" title="resets a setting to its default value">SettingGroup::resetSetting</a>(QString key) <a name="l00060"></a>00060 { <a name="l00061"></a>00061 <a class="code" href="classSetting.html" title="Setting class, allows the setting and retrieval of setting values.">Setting</a>* cur = <a class="code" href="classSettingGroup.html#fa3863356f975642e0d12b857a260683" title="pointer to first setting in group">firstSetting</a>; <a name="l00062"></a>00062 <span class="keywordflow">while</span>(cur != NULL) <a name="l00063"></a>00063 { <a name="l00064"></a>00064 <span class="keywordflow">if</span>(cur-><a class="code" href="classSetting.html#18aa160dfdff785d10d0e0352cbd1860">getKey</a>().compare(key) == 0) <a name="l00065"></a>00065 { <a name="l00066"></a>00066 cur-><a class="code" href="classSetting.html#7a36eb5be1dd827812d4c3b32d257408" title="resets value to default">resetSetting</a>(); <a name="l00067"></a>00067 } <a name="l00068"></a>00068 cur = cur-><a class="code" href="classSetting.html#368ad2c551ec7651704b50d933c091e4" title="gets a pointer to the next setting in the list">getNext</a>(); <a name="l00069"></a>00069 } <a name="l00070"></a>00070 } <a name="l00071"></a>00071 <span class="comment">//==============================================</span> <a name="l00072"></a><a class="code" href="classSettingGroup.html#4884ce9828c936de787ccaf5024acd94">00072</a> <span class="keywordtype">void</span> <a class="code" href="classSettingGroup.html#4884ce9828c936de787ccaf5024acd94" title="Sets a setting value, create new setting if setting not found.">SettingGroup::setValue</a>(QString key, QString value) <a name="l00073"></a>00073 { <a name="l00074"></a>00074 <a class="code" href="classSetting.html" title="Setting class, allows the setting and retrieval of setting values.">Setting</a>* cur = <a class="code" href="classSettingGroup.html#fa3863356f975642e0d12b857a260683" title="pointer to first setting in group">firstSetting</a>; <a name="l00075"></a>00075 <span class="keywordflow">while</span>(cur != NULL) <a name="l00076"></a>00076 { <a name="l00077"></a>00077 <span class="keywordflow">if</span>(cur-><a class="code" href="classSetting.html#18aa160dfdff785d10d0e0352cbd1860">getKey</a>().compare(key) == 0) <a name="l00078"></a>00078 { <a name="l00079"></a>00079 cur-><a class="code" href="classSetting.html#79261ad03b18839e900561f23e499d49">setValue</a>(value); <a name="l00080"></a>00080 <span class="keywordflow">return</span>; <a name="l00081"></a>00081 } <a name="l00082"></a>00082 cur = cur-><a class="code" href="classSetting.html#368ad2c551ec7651704b50d933c091e4" title="gets a pointer to the next setting in the list">getNext</a>(); <a name="l00083"></a>00083 } <a name="l00084"></a>00084 <a name="l00085"></a>00085 <span class="comment">//setting not found, create new one and append to list</span> <a name="l00086"></a>00086 cur = <span class="keyword">new</span> <a class="code" href="classSetting.html" title="Setting class, allows the setting and retrieval of setting values.">Setting</a>(key, value); <a name="l00087"></a>00087 <span class="keywordflow">if</span>(<a class="code" href="classSettingGroup.html#fa3863356f975642e0d12b857a260683" title="pointer to first setting in group">firstSetting</a> == NULL) <a name="l00088"></a>00088 <a class="code" href="classSettingGroup.html#fa3863356f975642e0d12b857a260683" title="pointer to first setting in group">firstSetting</a> = cur; <a name="l00089"></a>00089 <span class="keywordflow">else</span> <a name="l00090"></a>00090 <a class="code" href="classSettingGroup.html#321c99478e10cf6789e66ede6b5126ec" title="pointer to last setting in group">lastSetting</a>-><a class="code" href="classSetting.html#8325c0b55e697bd220bdeffce7092a82" title="sets a pointer to the next setting in the list">setNext</a>(cur); <a name="l00091"></a>00091 <a class="code" href="classSettingGroup.html#321c99478e10cf6789e66ede6b5126ec" title="pointer to last setting in group">lastSetting</a> = cur; <a name="l00092"></a>00092 } <a name="l00093"></a>00093 <span class="comment">//==============================================</span> <a name="l00094"></a><a class="code" href="classSettingGroup.html#8e4f4cb1e014fe366c31a25b180a57db">00094</a> <a class="code" href="classSettingGroup.html" title="SettingGroup contains settings which are releated.">SettingGroup</a>* <a class="code" href="classSettingGroup.html#8e4f4cb1e014fe366c31a25b180a57db" title="returns the next groupsetting">SettingGroup::getNext</a>() <a name="l00095"></a>00095 { <a name="l00096"></a>00096 <span class="keywordflow">return</span> <a class="code" href="classSettingGroup.html#433a5e987ef682359dc794e349204448" title="pointer to next settingroup">next</a>; <a name="l00097"></a>00097 } <a name="l00098"></a>00098 <span class="comment">//==============================================</span> <a name="l00099"></a><a class="code" href="classSettingGroup.html#3944d4fc6f3ed30a0916395590dd0e2d">00099</a> <span class="keywordtype">void</span> <a class="code" href="classSettingGroup.html#3944d4fc6f3ed30a0916395590dd0e2d" title="sets the next group setting">SettingGroup::setNext</a>(<a class="code" href="classSettingGroup.html" title="SettingGroup contains settings which are releated.">SettingGroup</a>* next) <a name="l00100"></a>00100 { <a name="l00101"></a>00101 this->next = next; <a name="l00102"></a>00102 } <a name="l00103"></a>00103 <span class="comment">//==============================================</span> <a name="l00104"></a><a class="code" href="classSettingGroup.html#284af55757783b4cfaf752384e742afc">00104</a> <span class="keywordtype">void</span> <a class="code" href="classSettingGroup.html#284af55757783b4cfaf752384e742afc" title="writes out this group to file">SettingGroup::saveSettings</a>(QTextStream& stream) <a name="l00105"></a>00105 { <a name="l00106"></a>00106 stream << <span class="stringliteral">" <group name=\""</span> << <a class="code" href="classSettingGroup.html#49ada5ca78c07434fe8f099550aea8a4" title="Returns group&#39;s name.">getName</a>() << <span class="stringliteral">"\">\n"</span>; <a name="l00107"></a>00107 <a name="l00108"></a>00108 <span class="comment">//iterate over every setting</span> <a name="l00109"></a>00109 <a class="code" href="classSetting.html" title="Setting class, allows the setting and retrieval of setting values.">Setting</a>* cur = <a class="code" href="classSettingGroup.html#fa3863356f975642e0d12b857a260683" title="pointer to first setting in group">firstSetting</a>; <a name="l00110"></a>00110 <span class="keywordflow">while</span>(cur != NULL) <a name="l00111"></a>00111 { <a name="l00112"></a>00112 stream << <span class="stringliteral">" <setting key=\""</span> << cur-><a class="code" href="classSetting.html#18aa160dfdff785d10d0e0352cbd1860">getKey</a>() << <span class="stringliteral">"\" value=\""</span> << cur-><a class="code" href="classSetting.html#88484910529421d1a925e71189b84f45">getValue</a>() << <span class="stringliteral">"\"/>\n"</span>; <a name="l00113"></a>00113 cur = cur-><a class="code" href="classSetting.html#368ad2c551ec7651704b50d933c091e4" title="gets a pointer to the next setting in the list">getNext</a>(); <a name="l00114"></a>00114 } <a name="l00115"></a>00115 <a name="l00116"></a>00116 stream << <span class="stringliteral">" </group>\n"</span>; <a name="l00117"></a>00117 } <a name="l00118"></a>00118 <span class="comment">//==============================================</span> <a name="l00119"></a><a class="code" href="classSettingGroup.html#ed28a422e74301266cff9561c2833691">00119</a> <span class="keywordtype">void</span> <a class="code" href="classSettingGroup.html#ed28a422e74301266cff9561c2833691">SettingGroup::loadSettings</a>(QDomNode& root) <a name="l00120"></a>00120 { <a name="l00121"></a>00121 <span class="comment">//iterate over all children (Settings)</span> <a name="l00122"></a>00122 QDomNode node = root.firstChild(); <a name="l00123"></a>00123 QDomText val; <a name="l00124"></a>00124 <span class="keywordflow">while</span>( !node.isNull() ) <a name="l00125"></a>00125 { <a name="l00126"></a>00126 <span class="keywordflow">if</span>( node.isElement() && node.nodeName() == <span class="stringliteral">"setting"</span> ) <a name="l00127"></a>00127 { <a name="l00128"></a>00128 <span class="comment">//find key and value, if either is missing move on to next setting</span> <a name="l00129"></a>00129 QDomNamedNodeMap attributes = node.attributes(); <a name="l00130"></a>00130 <span class="keywordflow">if</span>(attributes.namedItem(<span class="stringliteral">"key"</span>).isNull() || attributes.namedItem(<span class="stringliteral">"value"</span>).isNull()) <a name="l00131"></a>00131 { <a name="l00132"></a>00132 node = node.nextSibling(); <a name="l00133"></a>00133 <span class="keywordflow">continue</span>; <a name="l00134"></a>00134 } <a name="l00135"></a>00135 <a name="l00136"></a>00136 <a name="l00137"></a>00137 QString k = attributes.namedItem(<span class="stringliteral">"key"</span>).nodeValue(); <a name="l00138"></a>00138 QString v = attributes.namedItem(<span class="stringliteral">"value"</span>).nodeValue(); <a name="l00139"></a>00139 <a name="l00140"></a>00140 <span class="comment">//key and value found -> add new setting</span> <a name="l00141"></a>00141 <a class="code" href="classSettingGroup.html#4884ce9828c936de787ccaf5024acd94" title="Sets a setting value, create new setting if setting not found.">setValue</a>( attributes.namedItem(<span class="stringliteral">"key"</span>).nodeValue(), <a name="l00142"></a>00142 attributes.namedItem(<span class="stringliteral">"value"</span>).nodeValue() ); <a name="l00143"></a>00143 } <a name="l00144"></a>00144 <a name="l00145"></a>00145 <span class="comment">//move on to next setting</span> <a name="l00146"></a>00146 node = node.nextSibling(); <a name="l00147"></a>00147 } <a name="l00148"></a>00148 } <a name="l00149"></a>00149 <span class="comment">//==============================================</span> </pre></div></div> <hr size="1"><address style="text-align: right;"><small>Generated on Sun Aug 23 02:34:27 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>