#include <configuration.h>
Collaboration diagram for Configuration:

Definition at line 24 of file configuration.h.
Public Member Functions | |
| Configuration () | |
| Creates configuration variables using default values, then attempts to load settings from disk. | |
| ~Configuration () | |
| Destructor saves settings to disk. | |
| bool | loadSettings () |
| Loads settings. | |
| bool | saveSettings () |
| Saves settings. | |
| void | setString (QString group, QString key, QString value) |
| Sets a setting value, if group does not exist it is created, if setting does not exist it is also created. | |
| void | setBool (QString group, QString key, bool val) |
| Set bool setting. | |
| void | setInt (QString group, QString key, int val) |
| Set int setting. | |
| QString | getString (QString group, QString key) |
| Fetch string setting. | |
| bool | getBool (QString group, QString key) |
| Fetch bool setting. | |
| int | getInt (QString group, QString key) |
| Fetch int setting. | |
| float | getFloat (QString group, QString key) |
| Fetch float setting. | |
| double | getDouble (QString group, QString key) |
| Fetch double setting. | |
| void | resetSetting (QString group, QString key) |
| Resets a setting to it's default value. | |
| void | removeGroup (QString group) |
| Removes an entire group of settings. | |
Static Public Member Functions | |
| bool | constructSettingsDirectory () |
| Constructs any necessary directories for loading and saving user settings, returns false if unsuccessful. | |
Private Attributes | |
| QString | settingsFilename |
| Settings filename. | |
| SettingGroup * | firstGroup |
| pointer to first group | |
| SettingGroup * | lastGroup |
| pointer to last group | |
| SettingGroup * | curGroup |
| pointer to currently selected group | |
|
|
Creates configuration variables using default values, then attempts to load settings from disk.
Definition at line 68 of file configuration.cpp. References curGroup, firstGroup, lastGroup, and settingsFilename. 00069 {
00070 //-----------------------------
00071 //Determine settings filename
00072 //-----------------------------
00073
00074 //PLATFORM_SPECIFIC_CODE
00075
00076 //Mac OS X
00077 #if defined(Q_OS_MACX)
00078 settingsFilename = QDir::homeDirPath() + QString("/Library/Preferences/net.sourceforge.albumshaper.xml");
00079 //-----------------------------
00080 //Windows
00081 #elif defined(Q_OS_WIN)
00082 //attempt to get folder location using windows api, if this fails try hard coded path as a last resort
00083 QString tmp;
00084 if( !getWindowsFolderLocation(LOCAL_SETTINGS_APPLICATION_DATA, tmp) )
00085 {
00086 tmp = getenv("USERPROFILE") + QString("/Local Settings/Application Data");
00087 }
00088 settingsFilename = QDir::convertSeparators( tmp + "/Album Shaper/settings.xml" );
00089 //-----------------------------
00090 //Unix/Linux/BSD
00091 #else
00092 settingsFilename = QDir::homeDirPath() + QString("/.albumShaper/settings.xml");
00093 #endif
00094 //-----------------------------
00095
00096 //no groups by default
00097 firstGroup = NULL;
00098 lastGroup = NULL;
00099
00100 //no group selected by default
00101 curGroup = NULL;
00102 }
|
|
|
Destructor saves settings to disk.
Definition at line 104 of file configuration.cpp. References SettingGroup::getNext(). 00105 {
00106 //delete all setting groups
00107 SettingGroup* cur = firstGroup;
00108 while(cur != NULL)
00109 {
00110 SettingGroup* next = cur->getNext();
00111 delete cur;
00112 cur = next;
00113 }
00114 }
|
|
|
Constructs any necessary directories for loading and saving user settings, returns false if unsuccessful.
Definition at line 29 of file configuration.cpp. Referenced by main(). 00030 {
00031 //PLATFORM_SPECIFIC_CODE
00032
00033 //-----------------------------
00034 //Mac OSX requires no directories to be created
00035 #if defined(Q_OS_MACX)
00036 return true;
00037 //-----------------------------
00038 //Windows
00039 #elif defined(Q_OS_WIN)
00040 bool configDirMade = true;
00041
00042 //attempt to get folder location using windows api, if this fails try hard coded path as a last resort
00043 QString folderLoc;
00044 if( !getWindowsFolderLocation(LOCAL_SETTINGS_APPLICATION_DATA, folderLoc) )
00045 {
00046 folderLoc = getenv("USERPROFILE") + QString("/Local Settings/Application Data");
00047 }
00048 QDir dataDir( folderLoc );
00049 if(!dataDir.exists("Album Shaper"))
00050 {
00051 configDirMade = dataDir.mkdir("Album Shaper");
00052 }
00053 return configDirMade;
00054 //-----------------------------
00055 //Unix/Linux/BSD
00056 #else
00057 bool configDirMade = true;
00058 QDir homeDir( QDir::homeDirPath() );
00059 if(!homeDir.exists(".albumShaper"))
00060 {
00061 configDirMade = homeDir.mkdir(".albumShaper");
00062 }
00063 return configDirMade;
00064 #endif
00065 //-----------------------------
00066 }
|
|
||||||||||||
|
Fetch bool setting.
Definition at line 206 of file configuration.cpp. References getString(). Referenced by Window::closeEvent(), TitleWidget::loadAlbum(), LoadingSavingWidget::loadSettings(), LayoutSettingsWidget::loadSettings(), AlertsWidget::loadSettings(), main(), TitleWidget::newAlbum(), TitleWidget::proceedWithLoad(), TitleWidget::removeSelectedPhotoDesc(), TitleWidget::revertToSaved(), LayoutSettingsWidget::saveSettings(), and Window::Window(). 00207 {
00208 return ( getString(group,key).compare("1") == 0 );
00209 }
|
|
||||||||||||
|
Fetch double setting.
Definition at line 221 of file configuration.cpp. References getString(). 00222 {
00223 return getString(group,key).toDouble();
00224 }
|
|
||||||||||||
|
Fetch float setting.
Definition at line 216 of file configuration.cpp. References getString(). 00217 {
00218 return getString(group,key).toFloat();
00219 }
|
|
||||||||||||
|
Fetch int setting.
Definition at line 211 of file configuration.cpp. References getString(). Referenced by LayoutSettingsWidget::loadSettings(), and main(). 00212 {
00213 return getString(group,key).toInt();
00214 }
|
|
||||||||||||
|
|
Loads settings.
Definition at line 268 of file configuration.cpp. References curGroup, firstGroup, SettingGroup::getName(), SettingGroup::getNext(), lastGroup, SettingGroup::loadSettings(), SettingGroup::setNext(), and settingsFilename. Referenced by Window::Window(). 00269 {
00270 //-----------------------------------
00271 //attempt to load xml settings file and construct dom, if either action failes return false
00272 QFile settingsFile( settingsFilename );
00273 if( !settingsFile.open( IO_ReadOnly ) )
00274 return false;
00275
00276 QDomDocument DOM;
00277 if( !DOM.setContent( &settingsFile ) )
00278 return false;
00279
00280 settingsFile.close();
00281
00282 //-----------------------------------
00283 //walk though DOM and look for setting nodes.
00284 //for each setting fetch, type, key, and value
00285 //walk through list of settings and find previous setting
00286 //if previous setting found replace value, otherwise add new setting to list
00287 QDomElement root = DOM.documentElement();
00288 QDomNode node = root.firstChild();
00289
00290 while( !node.isNull() )
00291 {
00292 if( node.isElement() && node.nodeName() == "group" )
00293 {
00294 //find group name, if no name found then move on to next group
00295 QDomNamedNodeMap attributes = node.attributes();
00296 if(attributes.namedItem("name").isNull())
00297 {
00298 node = node.nextSibling();
00299 continue;
00300 }
00301
00302 //create group if it does not already exist
00303 SettingGroup* loadedGroup = NULL;
00304
00305 //last used group is the one we are looking for
00306 if(curGroup->getName().compare( attributes.namedItem("name").nodeValue()) == 0)
00307 loadedGroup = curGroup;
00308 //search list of groups
00309 else
00310 {
00311 SettingGroup* cur = firstGroup;
00312 while(cur != NULL)
00313 {
00314 //found it!
00315 if(cur->getName().compare( attributes.namedItem("name").nodeValue()) == 0)
00316 {
00317 loadedGroup = cur;
00318 break;
00319 }
00320 //nope, move on to next group
00321 cur = cur->getNext();
00322 }
00323 }
00324 //if group to be loaded is not found then create it
00325 if(loadedGroup == NULL)
00326 {
00327 loadedGroup = new SettingGroup( attributes.namedItem("name").nodeValue() );
00328 if(firstGroup == NULL)
00329 firstGroup = loadedGroup;
00330 else
00331 lastGroup->setNext(loadedGroup);
00332 lastGroup = loadedGroup;
00333 }
00334
00335 loadedGroup->loadSettings(node);
00336 }
00337 //move on to next setting
00338 node = node.nextSibling();
00339 }
00340 //-----------------------------------
00341 //loading of settingings was successful
00342 return true;
00343 }
|
|
|
Removes an entire group of settings.
Definition at line 226 of file configuration.cpp. References curGroup, firstGroup, SettingGroup::getName(), SettingGroup::getNext(), lastGroup, and SettingGroup::setNext(). Referenced by Window::~Window(). 00227 {
00228 //iterate through groups, remove group once found
00229 SettingGroup* prev = NULL;
00230 curGroup = firstGroup;
00231 while(curGroup != NULL)
00232 {
00233 //found
00234 if(curGroup->getName().compare(group) == 0)
00235 {
00236 //keep handle on group for deletion purposes
00237 SettingGroup* temp = curGroup;
00238
00239 //fix head if necessary
00240 if(curGroup == firstGroup)
00241 firstGroup = curGroup->getNext();
00242
00243 //fix tail if necessary
00244 if(lastGroup == curGroup)
00245 lastGroup = prev;
00246
00247 //splice out group
00248 if(prev != NULL)
00249 prev->setNext( curGroup->getNext() );
00250
00251 //update curGroup pointer so valid
00252 curGroup = curGroup->getNext();
00253
00254 //free group
00255 delete temp;
00256 temp = NULL;
00257
00258 //done
00259 return;
00260 }
00261
00262 //update prev and cur pointers and move along
00263 prev = curGroup;
00264 curGroup = curGroup->getNext();
00265 }
00266 }
|
|
||||||||||||
|
Resets a setting to it's default value.
Definition at line 182 of file configuration.cpp. References curGroup, SettingGroup::getName(), SettingGroup::getNext(), and SettingGroup::resetSetting(). Referenced by SubalbumWidget::addImageAction(), TitleWidget::createTmpDir(), TitleWidget::loadAlbum(), MosaicOptionsDialog::MosaicOptionsDialog(), and Window::Window(). 00183 {
00184 //check if cached group is correct group, if not find correct group
00185 if(curGroup == NULL || curGroup->getName().compare(group) != 0)
00186 {
00187 curGroup = firstGroup;
00188 while(curGroup != NULL)
00189 {
00190 if(curGroup->getName().compare(group) == 0)
00191 break;
00192 curGroup = curGroup->getNext();
00193 }
00194
00195 //if we have not found the group return error value (-1)
00196 if(curGroup == NULL)
00197 {
00198 return;
00199 }
00200 }
00201
00202 //return setting value from group
00203 curGroup->resetSetting(key);
00204 }
|
|
|
Saves settings.
Definition at line 345 of file configuration.cpp. References ALBUMSHAPER_VERSION, curGroup, SettingGroup::getNext(), SettingGroup::saveSettings(), and settingsFilename. Referenced by Window::~Window(). 00346 {
00347 //create/open html file
00348 QFile file( settingsFilename );
00349 if(file.open(IO_WriteOnly))
00350 {
00351 //-----
00352 QTextStream stream;
00353 stream.setDevice( &file );
00354 stream.setEncoding( QTextStream::UnicodeUTF8 );
00355
00356 //write header
00357 stream << "<settings app=\"Album Shaper\" version=\"" << ALBUMSHAPER_VERSION << "\">\n";
00358
00359 //iterate over every group
00360 curGroup = firstGroup;
00361 while(curGroup != NULL)
00362 {
00363 curGroup->saveSettings( stream );
00364 curGroup = curGroup->getNext();
00365 }
00366
00367 //end xml file
00368 stream << "</settings>\n";
00369
00370 //success saving settings!
00371 file.close();
00372 return true;
00373 }
00374
00375 //opening file for saving failed
00376 file.close();
00377 return false;
00378 }
|
|
||||||||||||||||
|
Set bool setting.
Definition at line 148 of file configuration.cpp. References setString(). Referenced by main(), LoadingSavingWidget::saveSettings(), LayoutSettingsWidget::saveSettings(), AlertsWidget::saveSettings(), MiscSettings::setDefaults(), LoadingSavingWidget::setDefaults(), LayoutSettingsWidget::setDefaults(), and AlertsWidget::setDefaults(). 00149 {
00150 setString( group, key, (val ? "1" : "0" ) );
00151 }
|
|
||||||||||||||||
|
Set int setting.
Definition at line 153 of file configuration.cpp. References setString(). Referenced by LayoutSettingsWidget::saveSettings(), MiscSettings::setDefaults(), LoadingSavingWidget::setDefaults(), LayoutSettingsWidget::setDefaults(), and Window::~Window(). 00154 {
00155 setString( group, key, QString("%1").arg(val) );
00156 }
|
|
||||||||||||||||
|
Sets a setting value, if group does not exist it is created, if setting does not exist it is also created.
Definition at line 116 of file configuration.cpp. References curGroup, firstGroup, SettingGroup::getName(), SettingGroup::getNext(), lastGroup, SettingGroup::setNext(), and SettingGroup::setValue(). Referenced by SubalbumWidget::addImageAction(), TitleWidget::loadAlbum(), TitleWidget::saveAlbum(), TitleWidget::saveAsAlbum(), LoadingSavingWidget::saveSettings(), setBool(), LoadingSavingWidget::setDefaults(), LayoutSettingsWidget::setDefaults(), AlertsWidget::setDefaults(), setInt(), and Window::~Window(). 00117 {
00118 //check if cached group has same name, if not find group, create it if group does not exist
00119 if(curGroup == NULL || curGroup->getName().compare(group) != 0)
00120 {
00121 curGroup = firstGroup;
00122 while(curGroup != NULL)
00123 {
00124 if(curGroup->getName().compare(group) == 0)
00125 break;
00126 curGroup = curGroup->getNext();
00127 }
00128
00129 //if we have not found the group create it and add to list
00130 if(curGroup == NULL)
00131 {
00132 //create new group
00133 curGroup = new SettingGroup(group);
00134
00135 //add group to list
00136 if(firstGroup == NULL)
00137 firstGroup = curGroup;
00138 else
00139 lastGroup->setNext(curGroup);
00140 lastGroup = curGroup;
00141 }
00142 }
00143
00144 //set setting value
00145 curGroup->setValue(key, value);
00146 }
|
|
|
pointer to currently selected group
Definition at line 84 of file configuration.h. Referenced by Configuration(), getString(), loadSettings(), removeGroup(), resetSetting(), saveSettings(), and setString(). |
|
|
pointer to first group
Definition at line 78 of file configuration.h. Referenced by Configuration(), loadSettings(), removeGroup(), and setString(). |
|
|
pointer to last group
Definition at line 81 of file configuration.h. Referenced by Configuration(), loadSettings(), removeGroup(), and setString(). |
|
|
Settings filename.
Definition at line 75 of file configuration.h. Referenced by Configuration(), loadSettings(), and saveSettings(). |
1.3.9.1